1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
|
[DllImport(vtkCommonEL_dll, EntryPoint = "vtkObject_Print")]
static extern string vtkObject_Print(HandleRef pThis);
/// <summary>
/// Returns the result of calling vtkObject::Print as a C# string.
/// </summary>
public override string ToString()
{
string rv = vtkObject_Print(this.GetCppThis());
return rv;
}
/// <summary>
/// Generic signature for all vtkObject events.
/// </summary>
public delegate void vtkObjectEventHandler(vtkObject sender, vtkObjectEventArgs e);
@vtkObject_EventFragments_CODE@ /// <summary>
/// Call RemoveAllHandlers on each non-null vtkObjectEventRelay.
/// TODO: This method needs to get called by the generated Dispose.
/// Make that happen...
/// </summary>
public void RemoveAllHandlersForAllEvents()
{
@vtkObject_RemoveEvents_CODE@ }
} // End class vtkObject
//----------------------------------------------------------------------------
/// <summary>
/// The sender of each ActiViz.NET event passes itself as its "sender"
/// parameter and an instance of vtkObjectEventArgs as its "e" parameter.
/// </summary>
public class vtkObjectEventArgs : System.EventArgs
{
/// <summary>
/// Each ActiViz.NET event automatically constructs a vtkObjectEventArgs to
/// pass to its handlers. Client ActiViz.NET applications do not need to
/// call this vtkObjectEventArgs constructor.
/// </summary>
public vtkObjectEventArgs(Kitware.VTK.vtkObject caller, uint eventId, IntPtr callData)
{
this.m_Caller = caller;
this.m_EventId = eventId;
this.m_CallData = callData;
}
/// <summary>
/// Caller is the object that invoked the event. Usually it is the same
/// object as the event handler's "sender" parameter.
/// </summary>
public Kitware.VTK.vtkObject Caller
{
get
{
return this.m_Caller;
}
}
/// <summary>
/// EventId is usually a value in the vtkCommand.EventIds enum. It is
/// primarily useful for handlers of the "Any" event. The "Any" event
/// fires whenever any other event is invoked from a given vtkObject. In
/// that case, the EventId passed with the event indicates the actual
/// event that was invoked.
///
/// It is also useful in the case of user defined events, where the event
/// id value is outside the pre-defined range of vtkCommand.EventIds.
/// </summary>
public uint EventId
{
get
{
return this.m_EventId;
}
}
/// <summary>
/// CallData varies based on what event is firing. It is frequently
/// IntPtr.Zero (NULL from C++)... If non-zero, see the documentation
/// of the specific event for the type of the data.
/// </summary>
public IntPtr CallData
{
get
{
return this.m_CallData;
}
}
private Kitware.VTK.vtkObject m_Caller;
private uint m_EventId;
private IntPtr m_CallData;
} // End class vtkObjectEventArgs
//----------------------------------------------------------------------------
/// <summary>
/// Implement a relay handler for VTK events. This is a class
/// that receives events directly from the VTK object sender and
/// transforms them into calls to .NET delegates.
/// </summary>
public class vtkObjectEventRelay : WrappedObject
{
/// <summary>
/// Type registration mechanics.
/// </summary>
public new static readonly string MRClassNameKey = "class vtkObjectEventRelay";
/// <summary>
/// Type registration mechanics.
/// </summary>
public new const string MRFullTypeName = "Kitware.VTK.vtkObjectEventRelay";
/// <summary>
/// Type registration mechanics.
/// </summary>
static vtkObjectEventRelay()
{
Kitware.mummy.Runtime.Methods.RegisterType(
System.Reflection.Assembly.GetExecutingAssembly(),
MRClassNameKey,
System.Type.GetType(MRFullTypeName)
);
}
/// <summary>
/// Automatically generated constructor - called from generated code.
/// DO NOT call directly.
/// </summary>
public vtkObjectEventRelay(IntPtr rawCppThis, bool callDisposalMethod, bool strong) :
base(rawCppThis, callDisposalMethod, strong)
{
}
[DllImport(vtkCommonEL_dll, EntryPoint = "vtkObjectEventRelay_New")]
internal static extern IntPtr vtkObjectEventRelay_New(ref uint mteStatus, ref uint mteIndex, ref uint rawRefCount);
/// <summary>
/// Construct a vtkObjectEventRelay object that will call "handler" when its
/// Execute method gets called. Typically, it is not necessary to create
/// instances of vtkObjectEventRelay from client applications. Usually, clients
/// will just connect to ActiViz.NET events, which use vtkObjectEventRelay
/// internally. However, vtkObjectEventRelay is suitable for use as the
/// vtkCommand parameter to AddObserver calls.
/// </summary>
public vtkObjectEventRelay(Kitware.VTK.vtkObject sender, uint eventId)
: base(IntPtr.Zero, true, false)
{
// mummy generated default C# constructor
uint mteStatus = 0;
uint mteIndex = UInt32.MaxValue;
uint rawRefCount = 0;
IntPtr rawCppThis = vtkObjectEventRelay_New(ref mteStatus, ref mteIndex, ref rawRefCount);
this.SetCppThis(rawCppThis, true, (0==mteStatus || rawRefCount<2 ? false : true));
this.Sender = sender;
this.EventId = eventId;
}
[DllImport(vtkCommonEL_dll, EntryPoint = "vtkObjectEventRelay_Delete")]
internal static extern void vtkObjectEventRelay_Delete(HandleRef pThis);
/// <summary>
/// Automatically generated protected Dispose method - called from
/// public Dispose or the C# destructor. DO NOT call directly.
/// </summary>
protected override void Dispose(bool disposing)
{
try
{
if (this.GetCallDisposalMethod())
{
vtkObjectEventRelay_Delete(this.GetCppThis());
this.ClearCppThis();
}
}
finally
{
base.Dispose(disposing);
}
}
private Kitware.VTK.vtkObject Sender;
private uint EventId;
private Kitware.VTK.vtkObject.vtkObjectEventHandler EventImpl;
private uint ObserverId;
/// <summary>
/// Signature for method that vtkObject can call for VTK events.
/// </summary>
public delegate void RelayHandler(
IntPtr caller, uint eventId, IntPtr callData);
private RelayHandler RelayHandlerDelegate;
[DllImport(vtkCommonEL_dll, EntryPoint = "vtkObjectEventRelay_AddObserver")]
internal static extern uint vtkObjectEventRelay_AddObserver(
HandleRef pThis, HandleRef sender, uint eventid, RelayHandler handler, float priority);
private uint AddObserver()
{
if (null == this.RelayHandlerDelegate)
{
this.RelayHandlerDelegate = new RelayHandler(this.Execute);
}
uint rv = vtkObjectEventRelay_AddObserver(this.GetCppThis(),
this.Sender == null ? new HandleRef() : this.Sender.GetCppThis(),
this.EventId, this.RelayHandlerDelegate, 0.0f);
return rv;
}
[DllImport(vtkCommonEL_dll, EntryPoint = "vtkObjectEventRelay_RemoveObserver")]
internal static extern uint vtkObjectEventRelay_RemoveObserver(
HandleRef pThis, uint observerId);
private void RemoveObserver(uint observerId)
{
vtkObjectEventRelay_RemoveObserver(this.GetCppThis(), observerId);
}
private void CallAddObserver()
{
if (0 == this.ObserverId && null != this.Sender && IntPtr.Zero != this.Sender.GetCppThis().Handle)
{
this.ObserverId = this.AddObserver();
}
}
private void CallRemoveObserver()
{
if (0 != this.ObserverId && null != this.Sender && IntPtr.Zero != this.Sender.GetCppThis().Handle)
{
this.RemoveObserver(this.ObserverId);
this.ObserverId = 0;
}
}
/// <summary>
/// Do not call directly. This method is called from VTK library code when
/// InvokeEvent is called on a vtkObject.
/// </summary>
public void Execute(
IntPtr caller, uint eventId, IntPtr callData)
{
if (null != this.EventImpl)
{
// "Create" the object via the mummy Runtime method:
//
bool created;
vtkObject vo = (vtkObject) Kitware.mummy.Runtime.Methods.CreateWrappedObject(
0, System.UInt32.MaxValue, 0xFFFFFFA8, caller, true, out created);
this.EventImpl(this.Sender,
new vtkObjectEventArgs(vo, eventId, callData));
}
}
/// <summary>
/// AddHandler adds a managed/.NET event handler to this event relay object.
/// If this is the first time a handler is being added, we call AddObserver
/// so that the underlying VTK object will invoke the event from now on.
/// </summary>
public void AddHandler(Kitware.VTK.vtkObject.vtkObjectEventHandler handler)
{
if (null == this.EventImpl)
{
this.CallAddObserver();
}
this.EventImpl += handler;
}
/// <summary>
/// RemoveHandler removes a managed/.NET event handler previously added to
/// this event relay object.
/// If this is the last handler being removed, we call RemoveObserver
/// so that the underlying VTK object will no longer send the event to us.
/// </summary>
public void RemoveHandler(Kitware.VTK.vtkObject.vtkObjectEventHandler handler)
{
this.EventImpl -= handler;
if (null == this.EventImpl)
{
this.CallRemoveObserver();
}
}
/// <summary>
/// HasHandlers returns true if this event presently has any managed/.NET
/// handlers.
/// </summary>
public bool HasHandlers()
{
return (null != this.EventImpl);
}
/// <summary>
/// RemoveAllHandlers forcibly removes all existing handlers from its list.
/// Sender should call this method from its Dispose if it has one.
/// </summary>
public void RemoveAllHandlers()
{
this.CallRemoveObserver();
this.EventImpl = null;
this.Sender = null;
}
} // End class vtkObjectEventRelay
/// <summary>
/// Custom marshaller for conversion to/from a System.IntPtr.
/// </summary>
public class vtkObjectMarshaler : ICustomMarshaler
{
#region ICustomMarshaler Members
void ICustomMarshaler.CleanUpManagedData(object ManagedObj)
{
// Intentional no-op...
}
void ICustomMarshaler.CleanUpNativeData(IntPtr pNativeData)
{
// Intentional no-op...
}
int ICustomMarshaler.GetNativeDataSize()
{
return IntPtr.Size; // native data is just a C++ this pointer...
}
IntPtr ICustomMarshaler.MarshalManagedToNative(object ManagedObj)
{
return ((vtkObject)ManagedObj).GetCppThis().Handle;
}
object ICustomMarshaler.MarshalNativeToManaged(IntPtr pNativeData)
{
// "Create" the object via the mummy Runtime method:
//
bool created;
object o = Kitware.mummy.Runtime.Methods.CreateWrappedObject(
0, System.UInt32.MaxValue, 0xFFFFFFA8, pNativeData, true, out created);
if (o == null)
{
System.Console.Error.WriteLine("error: *DID NOT FIND* o in MarshalNativeToManaged");
// Since the object is not presently in the mummy Runtime table, we
// have no way of knowing its actual type. Just make a generic
// vtkObject and hope for the best?
//
o = new vtkObject(pNativeData, false, false);
}
return o;
}
#endregion
private static ICustomMarshaler TheInstance = new vtkObjectMarshaler();
/// <summary>
/// Get the custom marshaller for vtkObject objects.
/// </summary>
public static ICustomMarshaler GetInstance(String cookie)
{
return TheInstance;
}
|