Class IGeoObjectImpl
- Namespace
- CADability.GeoObject
- Assembly
- CADability.dll
This class helps to implement IGeoObject by implementing some IGeoObject methods in a default way and by offering some helper methods.
public abstract class IGeoObjectImpl : IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, ISerializable, IFeedBack, ICloneable
- Inheritance
-
IGeoObjectImpl
- Implements
- Derived
- Inherited Members
Constructors
IGeoObjectImpl()
Constructor that initializes some members. Must always be called
protected IGeoObjectImpl()
IGeoObjectImpl(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected IGeoObjectImpl(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
IGeoObjectImpl(StreamingContext)
Constructor for derived classes that read the legacy binary serialization themselves by enumerating the SerializationInfo, which is faster than looking up each value by name. They call this constructor instead of IGeoObjectImpl(SerializationInfo, StreamingContext) and pass the entries that belong to this base class to SetSerializationValue(string, object).
protected IGeoObjectImpl(StreamingContext context)
Parameters
contextStreamingContextthe context of the deserialization
Fields
isChanging
Each call to FireWillChange(GeoObjectChange) increments this value, each call to FireDidChange(GeoObjectChange) decrements this value. If isChanging is 0 then the object is in a stable state.
protected int isChanging
Field Value
isModifyingWithMouse
depreciated
protected bool isModifyingWithMouse
Field Value
Properties
Actuator
Sets or gets the drive assiziated with this GeoObject
public virtual IDrive Actuator { get; set; }
Property Value
Attributes
Implements Attributes. Returns a collection af all CADability attributes used by this GeoObject. Non CADability attributes must be handled by your code.
public INamedAttribute[] Attributes { get; }
Property Value
CustomAttributeKeys
The keys of the user defined attributes attached to this object with SetNamedAttribute(string, INamedAttribute) (the CADability attributes like layer and color are not included); an empty array when there are none. Derived classes add the keys of attributes of their own, e.g. Point adds "PointSymbol".
public virtual string[] CustomAttributeKeys { get; }
Property Value
- string[]
Description
Returns a textual description of the GeoObject. Mainly used for debugging purposes
public virtual string Description { get; }
Property Value
IsVisible
Reads or writes the visible flag. Invisible objects ar not displayed.
public virtual bool IsVisible { get; set; }
Property Value
Layer
Fully implements Layer. Stores the layer in a private member. Setting raises the WillChangeEvent and DidChangeEvent.
public virtual Layer Layer { get; set; }
Property Value
NumChildren
Overrides NumChildren. The default implementation returns 0.
public virtual int NumChildren { get; }
Property Value
OwnedItems
Returns an array of objects owned by this object. E.g. a face is owned by a shell.
public virtual IGeoObject[] OwnedItems { get; }
Property Value
Owner
Overrides Owner. Fully implements set and get property and saves the value in a private member.
public virtual IGeoObjectOwner Owner { get; set; }
Property Value
PreferredStyle
Returns the preferred style for this objects, see Style.EDefaultFor.
public virtual Style.EDefaultFor PreferredStyle { get; }
Property Value
Style
Fully implements Style. Stores the style in a private member. Setting raises the WillChangeEvent and DidChangeEvent.
public virtual Style Style { get; set; }
Property Value
StyleIsValid
Returns true, if the setting of the style of this object is identical to the setting of the individual attributes, false otherwise
public bool StyleIsValid { get; }
Property Value
UniqueId
A number that is unique among all GeoObjects of this process. It is assigned when the object is constructed and is not saved. It orders objects in CompareTo(object) and identifies them, e.g. as keys in dictionaries and in display lists.
public int UniqueId { get; }
Property Value
UserData
Fully implements UserData. No need to override.
public virtual UserData UserData { get; }
Property Value
Methods
AttributeChanged(INamedAttribute)
Overrides AttributeChanged(INamedAttribute). Checks all CADability attributes. Checking your own attributes is left to your code.
public virtual bool AttributeChanged(INamedAttribute attribute)
Parameters
attributeINamedAttribute
Returns
ChangingUserData(IGeoObject, string, object)
Wraps a change of an entry of the UserData of involved: the returned object
raises WillChangeEvent at once and DidChangeEvent when it is disposed, both as a change
of an attribute only (OnlyAttributeChanged) and without an undo step.
key and oldValue are not evaluated yet, so the change cannot be undone.
public static IDisposable ChangingUserData(IGeoObject involved, string key, object oldValue)
Parameters
involvedIGeoObjectthe object whose user data changes; must be an IGeoObjectImpl
keystringthe key of the user data entry that changes
oldValueobjectthe value of the entry before the change
Returns
- IDisposable
the object to dispose when the change is done
ChangingUserData(IGeoObject, string, object, bool)
Same as ChangingUserData(IGeoObject, string, object), but onlyAttribute decides
whether the change is reported as a change of an attribute only or as a change of the geometry.
public static IDisposable ChangingUserData(IGeoObject involved, string key, object oldValue, bool onlyAttribute)
Parameters
involvedIGeoObjectthe object whose user data changes; must be an IGeoObjectImpl
keystringthe key of the user data entry that changes
oldValueobjectthe value of the entry before the change
onlyAttributebooltrue to report the change with OnlyAttributeChanged set, false to report it as a change of the geometry
Returns
- IDisposable
the object to dispose when the change is done
Child(int)
Overrides Child(int). The default implementation throws a GeoObjectException NoChildren.
public virtual IGeoObject Child(int Index)
Parameters
Indexint
Returns
Clone()
Clones this GeoObject.
public abstract IGeoObject Clone()
Returns
- IGeoObject
the cloned GeoObject
CopyAttributes(IGeoObject)
Implements CopyAttributes(IGeoObject). The default implementation handles all CADability attributes and leaves the handling of non CADability attributes to your code.
public virtual void CopyAttributes(IGeoObject ToCopyFrom)
Parameters
ToCopyFromIGeoObjectGeoObject to copy attribute data from
CopyGeometry(IGeoObject)
Copies the geometrical aspects of the given GeoObject to this GeoObject. Both objects must be of the same type. The attributes are not copied.
public abstract void CopyGeometry(IGeoObject ToCopyFrom)
Parameters
ToCopyFromIGeoObjectGeoObject to copy from
Decompose()
Decomposes the object into simpler objects, see Decompose(). The default implementation returns null: the object cannot be decomposed.
public virtual GeoObjectList Decompose()
Returns
- GeoObjectList
the parts, or null
FindSnapPoint(SnapPointFinder)
Asks the object to add its snap points (end points, centres, intersections...) of the kinds that
spf asks for. The default implementation adds none; objects with geometry override it.
public virtual void FindSnapPoint(SnapPointFinder spf)
Parameters
spfSnapPointFinderdefinition and collection of the snap points
FireDidChange(GeoObjectChange)
Helper method to raise the DidChangeEvent.
protected void FireDidChange(GeoObjectChange Change)
Parameters
ChangeGeoObjectChangetype of chage that did happen
FireWillChange(GeoObjectChange)
Helper method to rais the WillChangeEvent.
protected void FireWillChange(GeoObjectChange Change)
Parameters
ChangeGeoObjectChangetype of chage that is about to happen
GetAttributeProperties(IFrame)
Implements GetAttributeProperties(IFrame). The default implementation returns ShowProperties for all CADability attributes.
public virtual IPropertyEntry[] GetAttributeProperties(IFrame Frame)
Parameters
FrameIFramethe frame of the view
Returns
- IPropertyEntry[]
list of IPropertyEntry
GetBoundingCube()
Returns a bounding cube of the object. The object must fir into this cube. There may be a smaller cube that contains the object if it is to expensive to calculate the exact cube.
public abstract BoundingCube GetBoundingCube()
Returns
- BoundingCube
the bounding cube
GetExtent(IGeoObject, Projection, bool)
Returns the bounding rectangle of the GeoObject with respect to a specified projection
public static BoundingRect GetExtent(IGeoObject go, Projection projection, bool regardLineWidth)
Parameters
goIGeoObjectthe GeoObject
projectionProjectionthe projection
regardLineWidthboolregard line with
Returns
- BoundingRect
the bounding rectangle
GetExtent(Projection, ExtentPrecision)
Returns the 2d extent of the object as it appears in the given projection, in the coordinates of the projection's plane (not in pixels).
public abstract BoundingRect GetExtent(Projection projection, ExtentPrecision extentPrecision)
Parameters
projectionProjectionthe projection
extentPrecisionExtentPrecisionExact for the exact extent, Raw for a quick estimate that may be larger
Returns
- BoundingRect
the extent in the projection's 2d coordinates
GetExtent(double)
Gets the 3-dimensional extent of an object
public abstract BoundingCube GetExtent(double precision)
Parameters
precisiondoublePrecision of the test
Returns
- BoundingCube
The minmax cube
GetNamedAttribute(string)
Implements GetNamedAttribute(string). The default implementation handles all CADability attributes and leaves the handling of non CADability attributes to your code.
public virtual INamedAttribute GetNamedAttribute(string key)
Parameters
keystringkey or typename of attribute to set
Returns
- INamedAttribute
the named attribute
GetObjectData(IJsonWriteData)
Writes the data of this base class (user data, layer, style, user attributes and actuator) for the JSON serialization (IJsonSerialize). Derived classes override it, call the base implementation and add their own properties.
public virtual void GetObjectData(IJsonWriteData data)
Parameters
dataIJsonWriteDatareceives the data
GetObjectData(SerializationInfo, StreamingContext)
Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read. The base implementation saves UserData, Layer and Style; a derived class saves its own data and calls the base implementation.
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
GetQuadTreeItem(Projection, ExtentPrecision)
Returns an item for a 2d quad tree of the projected objects, used for hit tests in a projection: it knows the 2d extent of the object, whether a 2d rectangle hits it, and the depth (z position) of the object at a 2d point. Composite objects (blocks, solids, paths) return a collection of the items of their parts.
public abstract IQuadTreeInsertableZ GetQuadTreeItem(Projection projection, ExtentPrecision extentPrecision)
Parameters
projectionProjectionthe projection
extentPrecisionExtentPrecisionprecision of the extent, see GetExtent(Projection, ExtentPrecision)
Returns
- IQuadTreeInsertableZ
the item for the quad tree
GetShowProperties(IFrame)
Should be overridden and return a IPropertyEntry derived object that handles the display and modification of the properties of the IGeoObject derived object. Default implementation return null.
public virtual IPropertyEntry GetShowProperties(IFrame Frame)
Parameters
FrameIFrame
Returns
HasChildren()
Overrides HasChildren(). The deafult implementation returns false.
public virtual bool HasChildren()
Returns
HasValidData()
Default implementation of IGeoObject.HasValidData. Returns true. Override if the derived object can decide itself.
public virtual bool HasValidData()
Returns
- bool
true
HitTest(ref BoundingCube, double)
Tests whether an object is touched by the provided cube
public abstract bool HitTest(ref BoundingCube cube, double precision)
Parameters
cubeBoundingCubeTo test with
precisiondoubleRequired precision
Returns
- bool
true if the object strikes the cube
HitTest(Projection, BoundingRect, bool)
Tests whether an object is inside or touched by the rectangle when projected with the provided projection
public abstract bool HitTest(Projection projection, BoundingRect rect, bool onlyInside)
Parameters
projectionProjectionThe projection for the test
rectBoundingRectThe rectangle to test the position
onlyInsidebooltrue: the object must be totaly inside the rectangle, false: the object must be totaly or partially inside the rectangle
Returns
- bool
true when the test succeedes, false otherwise
HitTest(PickArea, bool)
Tests whether an object is inside or touched by the provided area
public abstract bool HitTest(Projection.PickArea area, bool onlyInside)
Parameters
areaProjection.PickAreaThe area to check for
onlyInsidebooltrue: the object must be totaly inside the area, false: the object must be totaly or partially inside the area
Returns
- bool
true when the test succeedes, false otherwise
IsAttributeUsed(object)
/// Overrides IsAttributeUsed(object). The default implementation recursively calls IsAttributeUsed for all children (if any) and then checks the usage for all attributes implemented by CADability. No checks are performed for non CADability attributes. So you can override this method to handle your own attributes and call the base implementation for CADability attributes.
public virtual bool IsAttributeUsed(object attribute)
Parameters
attributeobjectattribut to check
Returns
- bool
true if used by this GeoObject
IsOwnedByBlockRef(IGeoObject)
Checks whether the GeoObject is owned by a BlockRef object.
public static bool IsOwnedByBlockRef(IGeoObject toTest)
Parameters
toTestIGeoObject
Returns
JsonSerializationDone()
Not implemented: throws a NotImplementedException and is not called anywhere. An object that needs a callback when the JSON deserialization is complete implements IJsonSerializeDone instead.
protected void JsonSerializationDone()
MakeChange(IGeoObjectImpl, string)
Wraps a change of the property propertyName of geoObject for code outside
the class of the object: the returned object raises WillChangeEvent at once, with the current value
of the property (read by reflection) as the value to restore on undo, and raises DidChangeEvent when
it is disposed. Not used within CADability itself.
public static IDisposable MakeChange(IGeoObjectImpl geoObject, string propertyName)
Parameters
geoObjectIGeoObjectImplthe object to change
propertyNamestringthe name of a public property of the object that has a getter and a setter
Returns
- IDisposable
the object to dispose when the change is done
Modify(ModOp)
Modifies this GeoObject with the given modification operation (includes moving, rotating, reflecting, scaling etc.).
public abstract void Modify(ModOp m)
Parameters
mModOpOperation to be applied
ModifyInverse(ModOp)
Modify with the inverse modification. Calls Modify(m.GetInverse());
public virtual void ModifyInverse(ModOp m)
Parameters
mModOp
ModifyWithMouse(object, string, bool)
depreciated
public virtual bool ModifyWithMouse(object sender, string propertyName, bool startModify)
Parameters
Returns
PaintTo3D(IPaintTo3D)
Paints the object with the methods of paintTo3D: lines, triangles, text... The views implement
IPaintTo3D (with OpenGL or GDI) and collect what the object paints in a display list, so this is
called rarely, after PrepareDisplayList(double) has done the expensive work (triangulation, approximation).
public abstract void PaintTo3D(IPaintTo3D paintTo3D)
Parameters
paintTo3DIPaintTo3Dwhere to paint
PaintTo3DList(IPaintTo3D, ICategorizedDislayLists)
Adds this object as a whole to the display lists, in the category of its layer. Suitable for simple objects like curves and text; composite objects (solids, shells, blocks) override it and add their parts by category.
public virtual void PaintTo3DList(IPaintTo3D paintTo3D, ICategorizedDislayLists lists)
Parameters
paintTo3DIPaintTo3Dthe paint interface of the view
listsICategorizedDislayListsthe display lists to add to
Position(GeoPoint, GeoVector, double)
Returns the smallest parameter value (l) where the provided line hits the object so that the point
fromHere + l * direction is on or close to the object. The result may be negative.
Return double.MaxValue if there is no such point.
public abstract double Position(GeoPoint fromHere, GeoVector direction, double precision)
Parameters
fromHereGeoPointStartpoint of the line
directionGeoVectorDirection of the line
precisiondoublePrecision for the test
Returns
- double
Position on the line
PrePaintTo3D(IPaintTo3D)
Called before PaintTo3D(IPaintTo3D), outside of the display list that collects what PaintTo3D paints. Override it for work that must not go into that list, e.g. painting that needs a display list of its own. The default implementation does nothing.
public virtual void PrePaintTo3D(IPaintTo3D paintTo3D)
Parameters
paintTo3DIPaintTo3Dthe paint interface of the view
PrepareDisplayList(double)
Called before PaintTo3D(IPaintTo3D) is called, should implement the time consuming work for the display (like calculationg the triangulation of Faces or Polylines of Curves). Not normally used by user code.
public abstract void PrepareDisplayList(double precision)
Parameters
precisiondoubleRequired precision
PropagateAttributes(Layer, ColorDef)
Sets the provided layer and color to this object and propagates these attributes to the owned objects.
public virtual void PropagateAttributes(Layer layer, ColorDef colorDef)
Parameters
SetColorDef(ref ColorDef, ColorDef)
Helper for the implementation of ColorDef: sets the colour and raises the WillChangeEvent and DidChangeEvent events, so that the change is displayed and can be undone.
protected void SetColorDef(ref ColorDef color, ColorDef c)
Parameters
colorColorDefreference to the field that holds the colour
cColorDefthe new colour; null is ignored
SetNamedAttribute(string, INamedAttribute)
Implements SetNamedAttribute(string, INamedAttribute). The default implementation handles all CADability attributes and leaves the handling of non CADability attributes to your code.
public void SetNamedAttribute(string key, INamedAttribute toSet)
Parameters
keystringkey or typename of attribute to set
toSetINamedAttributeattribute
SetObjectData(IJsonReadData)
Reads the data written by GetObjectData(IJsonWriteData) back from the JSON serialization. Derived classes override it, call the base implementation and read their own properties. Objects referenced by the data may still be incomplete at this time, see IJsonSerializeDone.
public virtual void SetObjectData(IJsonReadData data)
Parameters
dataIJsonReadDataprovides the data
SetSerializationValue(string, object)
Stores one entry of the legacy binary serialization that belongs to this base class ("UserData", "Layer", "Style", "UserAttributes" or "Actuator"); entries with other names are ignored. Called by derived classes that enumerate the SerializationInfo themselves, see IGeoObjectImpl(StreamingContext).
protected void SetSerializationValue(string Name, object Value)
Parameters
UpdateAttributes(IAttributeListContainer)
Implements UpdateAttributes(IAttributeListContainer) for all CADability attributes. Non CADability attributes are not handled and must be handled if there are any.
public virtual void UpdateAttributes(IAttributeListContainer alc)
Parameters
Events
DidChangeEvent
Event that is raised when the GeoObject did change.
public event ChangeDelegate DidChangeEvent
Event Type
FeedBackChangedEvent
Raised after every change of this object, together with DidChangeEvent, but without the details of the change. Implements FeedBackChangedEvent, so that any GeoObject can serve as the feedback object of an Action, which repaints the feedback when the event is raised.
public event FeedBackChangedDelegate FeedBackChangedEvent
Event Type
GetAdditionalContextMenueEvent
Raised for any GeoObject when the context menu of its entry in the property grid is built. An application can return the id of a menu definition of its own to add commands for the object; the items are loaded with LoadMenuDefinition(string, bool, ICommandHandler) and appended to the menu. The event is static, so one handler serves all objects.
public static event IGeoObjectImpl.GetAdditionalContextMenueDelegate GetAdditionalContextMenueEvent
Event Type
WillChangeEvent
Event that is raised when the GeoObject is about to change.
public event ChangeDelegate WillChangeEvent