Class Model
- Namespace
- CADability
- Assembly
- CADability.dll
A model is the container for the geometric objects (IGeoObject) of a Project. It owns the objects (see IGeoObjectOwner), keeps track of their extent, raises events when objects are added, removed or modified, maintains the display lists used by the views and knows the units of its world coordinate system. A project may contain several models; each ModelView shows one of them with a certain Projection.
public class Model : IShowPropertyImpl, IShowProperty, IPropertyEntry, ISerializable, IGeoObjectOwner, IEnumerable, ICommandHandler, ICategorizedDislayLists, IDeserializationCallback, IJsonSerialize, IJsonSerializeDone
- Inheritance
-
Model
- Implements
- Inherited Members
Constructors
Model()
Creates an empty model.
public Model()
Model(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected Model(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Properties
AllDrives
Returns the list of all dirves of this model. Only used in connection with AnimatedView.
public DriveList AllDrives { get; }
Property Value
AllObjects
Returns a list of all objects owned by this model. Removing or adding objects from or to the returned list doesn't remove or add the objects from or to the model.
public GeoObjectList AllObjects { get; }
Property Value
AllSchedules
Returns the list of all Schedules of this model. Only used in connection with AnimatedView.
public ScheduleList AllSchedules { get; }
Property Value
ContextMenu
Implementation of ContextMenu: the default returns null. An entry whose LabelType contains ContextMenu must override it.
public override MenuWithHandler[] ContextMenu { get; }
Property Value
Count
Returns the count of GeoObjects in this model.
public int Count { get; }
Property Value
EntryType
Overrides EntryType, returns GroupTitle.
public override ShowPropertyEntryType EntryType { get; }
Property Value
Extent
Returns the extent of the model, i.e. a bounding cube enclosing all objects.
public BoundingCube Extent { get; set; }
Property Value
this[int]
Indexer to access the GeoObjects owned by this model by index.
public IGeoObject this[int Index] { get; }
Parameters
IndexintIndex of the required GeoObject
Property Value
LabelText
Implementation of LabelText, returns either labelTextInternal (if not null) or GetString(string)(resourceId+".Label") Whe set, labelTextInternal is set.
public override string LabelText { get; set; }
Property Value
LabelType
How the label of this entry behaves (see ShowPropertyLabelFlags): whether it can be selected or edited, is bold or has a context menu. The default implementation returns Selectable.
public override ShowPropertyLabelFlags LabelType { get; }
Property Value
MinExtend
A minimal extend of the Model. This will be the extend of the Model if the Model is empty. This is also used in other circumstances (e.g. dieplay of the grid)
public BoundingCube MinExtend { get; set; }
Property Value
Name
The name of the model.
public string Name { get; set; }
Property Value
NoSingleAddEvents
Set to true, if you don't want AddingGeoObjectEvent rsp. GeoObjectAddedEvent beeing fired after AddingGeoObjectsEvent rsp. GeoObjectsAddedEvent has been called. False is the default value.
public bool NoSingleAddEvents { set; }
Property Value
OctTree
Access to the OctTree containing all geometrical objects of the model. Do not modify the octTree to avoid inconsistencies between model and octTree. Use the octTree for fast access to the objects in the model from geometrical constraints.
public OctTree<IGeoObject> OctTree { get; }
Property Value
SubEntries
The sub entries shown below this entry when it is opened in the property page. The default implementation has none and returns an empty array.
public override IShowProperty[] SubEntries { get; }
Property Value
SubEntriesCount
The number of SubEntries, 0 for an entry that cannot be opened. The default implementation returns 0.
public override int SubEntriesCount { get; }
Property Value
Undo
Gets or sets the undo-system. Usually this is the undosystem of the Project containing this model.
public UndoRedoSystem Undo { get; set; }
Property Value
UserData
The UserData of this model: a container in which any kind of data can be attached to the model under a string key. Serializable data objects are saved together with the model (i.e. in the project file). The container is created on first access, so the property is never null.
public UserData UserData { get; }
Property Value
Methods
Add(GeoObjectList)
Adds all objects of the list to this model. Objects that belong to another owner (a model or a block) are removed from it first. Like Add(IGeoObject) this adds objects even when HasValidData() returns false. The whole list is one undo step. AddingGeoObjectsEvent and GeoObjectsAddedEvent are raised once for the list, GeoObjectAddedEvent for each object unless NoSingleAddEvents is set; AddingGeoObjectEvent is not raised, so a handler of it cannot reject objects added this way.
public void Add(GeoObjectList ListToAdd)
Parameters
ListToAddGeoObjectListList of the GeoObjects to add
Add(IGeoObject)
Adds an object to this model. If the model is beeing displayed the object will appear in the view immediately. The object is added even if HasValidData() returns false, like with the other overloads, so that e.g. imported data can be repaired later. Check it before adding, if invalid objects are not wanted. The object is only rejected by a handler of AddingGeoObjectEvent.
public void Add(IGeoObject ObjectToAdd)
Parameters
ObjectToAddIGeoObjectThe GeoObject to add
Add(IGeoObject[])
Adds all objects of the array to this model, same as Add(GeoObjectList).
public void Add(IGeoObject[] ListToAdd)
Parameters
ListToAddIGeoObject[]Array of the GeoObjects to add
AdjustPoint(SnapPointFinder, Projection, HashSet<Layer>)
Adjusts the point defined by spf (SourcePoint and Projection)
according to the settings of spf (SnapPointFinder.SnapModes and other properties)
by checking all objects in the visibleLayers.
As a result SnapPoint and DidSnap will be set.
public void AdjustPoint(SnapPointFinder spf, Projection projection, HashSet<Layer> visibleLayers)
Parameters
spfSnapPointFinderPoint to be adjusted and mode how to adjust
projectionProjectionProjection
visibleLayersHashSet<Layer>Visible layers to consider
AdjustPoint(SnapPointFinder, HashSet<Layer>)
Searches for the best point in this model which corresponds to the mouse position and the
active snap modes. Mouse position and snap modes are contained in the spf
parameter, where also the result is returned
public void AdjustPoint(SnapPointFinder spf, HashSet<Layer> visibleLayers)
Parameters
spfSnapPointFinderSnapPointFinder class which contains the snap mode and the mouse position
visibleLayersHashSet<Layer>Layers to be included in the search
ClearDisplayLists()
Deprecated, still public for legacy reasons.
public void ClearDisplayLists()
~Model()
Finalizer. It does nothing; a model holds no unmanaged resources.
protected ~Model()
GetExtent(Projection)
Returns a 2 dimensional bounding rctangle enclosing the projection of all GeoObjects of the model.
public BoundingRect GetExtent(Projection pr)
Parameters
prProjectionThe projection to be applied to the GeoObjects
Returns
GetObjectsFromBox(BoundingCube)
Returns all objects of the model that are inside ore close to the provided box.
public GeoObjectList GetObjectsFromBox(BoundingCube box)
Parameters
boxBoundingCubeBox from which to seek objects
Returns
- GeoObjectList
List of objects in or close to the box
GetObjectsFromRect(BoundingRect, Projection, HashSet<Layer>, PickMode, FilterList)
Returns all objects of the model that are touched by the pickrect, whos layers are in the
visibleLayers set and which are accepted by the filterList.
public GeoObjectList GetObjectsFromRect(BoundingRect pickrect, Projection projection, HashSet<Layer> visibleLayers, PickMode pickMode, FilterList filterList)
Parameters
pickrectBoundingRectArea that specifies which objects are beeing tested
projectionProjectionThe projection in which the pickrect is defined
visibleLayersHashSet<Layer>Set of layers which are visible (and hence should be used for the test)
pickModePickModeSingle or multiple objects
filterListFilterListList of conditions
Returns
- GeoObjectList
List of objects that fulfill all conditions
GetObjectsFromRect(PickArea, HashSet<Layer>, PickMode, FilterList, GeoObjectList)
Returns all objects of the model that are touched by the area, whos layers are in the
visibleLayers set and which are accepted by the filterList.
public GeoObjectList GetObjectsFromRect(Projection.PickArea area, HashSet<Layer> visibleLayers, PickMode pickMode, FilterList filterList, GeoObjectList toAvoid = null)
Parameters
areaProjection.PickAreaArea that specifies which objects are beeing tested
visibleLayersHashSet<Layer>Set of layers which are visible (and hence should be used for the test)
pickModePickModeSingle or multiple objects
filterListFilterListList of conditions
toAvoidGeoObjectListList of objects not to select
Returns
- GeoObjectList
List of objects that fulfill all conditions
GetPickDistance(PickArea, HashSet<Layer>)
Returns the minimal distance in viewDirection of any visible objects in the model. Returns double.MaxValue when there is nothing in the viewDirection
public double GetPickDistance(Projection.PickArea viewDirection, HashSet<Layer> visibleLayers)
Parameters
viewDirectionProjection.PickAreavisibleLayersHashSet<Layer>
Returns
IsAttributeUsed(object)
Determins whether an attribute (e.g. Layer, LinePattern) is used by any GeoObjects of this model.
public bool IsAttributeUsed(object Attribute)
Parameters
AttributeobjectAttribut to test
Returns
- bool
True, if attribute is used, false otherwise.
LabelChanged(string)
Implementation of LabelChanged(string). Override if LabelType is Editable.
public override void LabelChanged(string NewText)
Parameters
NewTextstringthe new text
MoveToBack(IGeoObject)
Moves the given object to the beginning of the list of objects of this model, so that all other objects are drawn after (i.e. over) it in views that draw the objects in list order. The object must belong to this model. This is not undoable and raises no change events. See also MoveToFront(IGeoObject).
public void MoveToBack(IGeoObject iGeoObject)
Parameters
iGeoObjectIGeoObjectThe object to move to the back
MoveToFront(IGeoObject)
Moves the given object to the end of the list of objects of this model. The list order is the drawing order in views that draw the objects one after the other (e.g. the 2d views), so the object then appears in front of all others. The object must belong to this model. This is not undoable and raises no change events.
public void MoveToFront(IGeoObject iGeoObject)
Parameters
iGeoObjectIGeoObjectThe object to move to the front
ParallelTriangulation(double)
Triangulates the faces of all solids, shells, faces and blocks of this model with the given precision, using several threads. The triangulation is needed for the display and for hit tests; computing it in advance avoids the delays when it is made on demand, e.g. after a file has been imported. Faces whose triangulation fails are skipped, objects of other types are ignored. See also SerialTriangulation(double).
public void ParallelTriangulation(double precision)
Parameters
precisiondoubleThe maximum deviation of the triangles from the surfaces in world units, typically the size of a pixel in world units of the view that will show the model
Remove(GeoObjectList)
Removes a list of GeoObjects from this model. Objects that dont belong to the model will be ignored.
public void Remove(GeoObjectList ToRemove)
Parameters
ToRemoveGeoObjectListList of GeoObjects to be removed
Remove(IGeoObject)
Removes a GeoObject from the model. If the GeoObject doesnt belong to this model it will be ignored.
public void Remove(IGeoObject ToRemove)
Parameters
ToRemoveIGeoObjectGeoObject to remove
Remove(IGeoObject[])
Removes an array of GeoObjects from this model. Objects that dont belong to the model will be ignored.
public void Remove(IGeoObject[] ToRemove)
Parameters
ToRemoveIGeoObject[]Array of geoObjects to remove
Remove(HashSet<IGeoObject>)
Removes all objects of the given set from this model in one step; objects that do not belong to the model are ignored. The removal is one undo step. RemovingGeoObjectsEvent is raised before and GeoObjectsRemovedEvent after the removal, the events for single objects are not raised. A running background calculation of the display lists is aborted first.
public void Remove(HashSet<IGeoObject> HToRemove)
Parameters
HToRemoveHashSet<IGeoObject>The objects to remove
RemoveAll()
Remove all objects from this model.
public void RemoveAll()
RemoveSolid(Solid, bool)
Removes the given solid from all other solids in the model. If there are no solids in the model or this solid is disjoint with all other solids in the model there will be no effect.
public bool RemoveSolid(Solid solid, bool onlySameLayer)
Parameters
solidSolidthe solid to remove
onlySameLayerboolif true: check only with solids on the same layer
Returns
SerialTriangulation(double)
Triangulates the faces of all solids, shells, faces and blocks of this model with the given precision, like ParallelTriangulation(double) but in the calling thread. Mainly useful for debugging.
public void SerialTriangulation(double precision)
Parameters
precisiondoubleThe maximum deviation of the triangles from the surfaces in world units
UniteSolid(Solid, bool)
Unites the given solid with all other solids in the model. If there are no other solids or the solid is disjoint with all other solids this solid will simply bee added.
public bool UniteSolid(Solid solid, bool onlySameLayer)
Parameters
Returns
Events
AddingGeoObjectEvent
This event will be fired before an object is added to this model. The event handler can prevent the object beeing added to the model
public event Model.AddingGeoObject AddingGeoObjectEvent
Event Type
AddingGeoObjectsEvent
This event will be fired before multiple objects are beeing added. There is no sense in modifying the provided array of objects. There will be an additional call to AddingGeoObjectEvent and GeoObjectAddedEvent for each objects (where you can prevent the object beeing added) and a final call to GeoObjectsAddedEvent.
public event Model.AddingGeoObjects AddingGeoObjectsEvent
Event Type
CalculateExtentForZoomTotalEvent
Raised when a view needs the extent to show for "zoom total" (ZoomTotal(double) and the corresponding menu commands). If a handler is attached, its result is used instead of the extent of all objects of the model projected with the given projection. Use it to zoom to a fixed working area or to exclude auxiliary objects from the zoom.
public event Model.CalculateExtentForZoomTotalDelegate CalculateExtentForZoomTotalEvent
Event Type
ExtentChangedEvent
This event will be fired when objects have been added, removed or modified which resulted in a different extent (of the bounding box) of the model.
public event Model.ExtentChangedDelegate ExtentChangedEvent
Event Type
GeoObjectAddedEvent
This event will be fired when an object is added to this model.
public event Model.GeoObjectAdded GeoObjectAddedEvent
Event Type
GeoObjectDidChangeEvent
This event will be fired when an object contained in this model did change.
public event ChangeDelegate GeoObjectDidChangeEvent
Event Type
GeoObjectRemovedEvent
This event will be fired when an object is removed from this model.
public event Model.GeoObjectRemoved GeoObjectRemovedEvent
Event Type
GeoObjectWillChangeEvent
This event will be fired when an object contained in this model is about to change.
public event ChangeDelegate GeoObjectWillChangeEvent
Event Type
GeoObjectsAddedEvent
This event will be fired after multiple GeoObjects have been added, AddingGeoObjectsEvent has been fired before.
public event Model.GeoObjectsAdded GeoObjectsAddedEvent
Event Type
GeoObjectsRemovedEvent
This event will be fired when removing multiple objects from this model is finished.
public event Model.GeoObjectsRemoved GeoObjectsRemovedEvent
Event Type
ImportingObjectsEvent
This event will be fired when objects imported from another file are added to the model. The event handler can modify the list of objects, e.g. add or remove objects or combine the objects to a Block.
public event Model.ImportingObjectsDelegate ImportingObjectsEvent
Event Type
NameChangedEvent
This event will be fired when the name of the model changed.
public event Model.NameChangedDelegate NameChangedEvent
Event Type
RemovingGeoObjectEvent
This event will be fired before an object is removed from this model. The event handler can prevent the object beeing added to the model
public event Model.RemovingGeoObject RemovingGeoObjectEvent
Event Type
RemovingGeoObjectsEvent
This event will be fired before multiple objects are beeing removed. There is no sense in modifying the provided array of objects. There will be an additional call to RemovingGeoObjectEvent and GeoObjectRemovedEvent for each objects (where you can prevent the object beeing added) and a final call to GeoObjectsRemovedEvent.
public event Model.RemovingGeoObjects RemovingGeoObjectsEvent