Table of Contents

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

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

Properties

AllDrives

Returns the list of all dirves of this model. Only used in connection with AnimatedView.

public DriveList AllDrives { get; }

Property Value

DriveList

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

GeoObjectList

AllSchedules

Returns the list of all Schedules of this model. Only used in connection with AnimatedView.

public ScheduleList AllSchedules { get; }

Property Value

ScheduleList

ContextMenu

Implementation of ContextMenu: the default returns null. An entry whose LabelType contains ContextMenu must override it.

public override MenuWithHandler[] ContextMenu { get; }

Property Value

MenuWithHandler[]

Count

Returns the count of GeoObjects in this model.

public int Count { get; }

Property Value

int

EntryType

Overrides EntryType, returns GroupTitle.

public override ShowPropertyEntryType EntryType { get; }

Property Value

ShowPropertyEntryType

Extent

Returns the extent of the model, i.e. a bounding cube enclosing all objects.

public BoundingCube Extent { get; set; }

Property Value

BoundingCube

this[int]

Indexer to access the GeoObjects owned by this model by index.

public IGeoObject this[int Index] { get; }

Parameters

Index int

Index of the required GeoObject

Property Value

IGeoObject

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

string

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

ShowPropertyLabelFlags

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

BoundingCube

Name

The name of the model.

public string Name { get; set; }

Property Value

string

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

bool

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

OctTree<IGeoObject>

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

IShowProperty[]

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

int

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

UndoRedoSystem

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

UserData

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

ListToAdd GeoObjectList

List 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

ObjectToAdd IGeoObject

The GeoObject to add

Add(IGeoObject[])

Adds all objects of the array to this model, same as Add(GeoObjectList).

public void Add(IGeoObject[] ListToAdd)

Parameters

ListToAdd IGeoObject[]

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

spf SnapPointFinder

Point to be adjusted and mode how to adjust

projection Projection

Projection

visibleLayers HashSet<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

spf SnapPointFinder

SnapPointFinder class which contains the snap mode and the mouse position

visibleLayers HashSet<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

pr Projection

The projection to be applied to the GeoObjects

Returns

BoundingRect

GetObjectsFromBox(BoundingCube)

Returns all objects of the model that are inside ore close to the provided box.

public GeoObjectList GetObjectsFromBox(BoundingCube box)

Parameters

box BoundingCube

Box 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

pickrect BoundingRect

Area that specifies which objects are beeing tested

projection Projection

The projection in which the pickrect is defined

visibleLayers HashSet<Layer>

Set of layers which are visible (and hence should be used for the test)

pickMode PickMode

Single or multiple objects

filterList FilterList

List 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

area Projection.PickArea

Area that specifies which objects are beeing tested

visibleLayers HashSet<Layer>

Set of layers which are visible (and hence should be used for the test)

pickMode PickMode

Single or multiple objects

filterList FilterList

List of conditions

toAvoid GeoObjectList

List 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

viewDirection Projection.PickArea
visibleLayers HashSet<Layer>

Returns

double

IsAttributeUsed(object)

Determins whether an attribute (e.g. Layer, LinePattern) is used by any GeoObjects of this model.

public bool IsAttributeUsed(object Attribute)

Parameters

Attribute object

Attribut 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

NewText string

the 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

iGeoObject IGeoObject

The 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

iGeoObject IGeoObject

The 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

precision double

The 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

ToRemove GeoObjectList

List 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

ToRemove IGeoObject

GeoObject 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

ToRemove IGeoObject[]

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

HToRemove HashSet<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

solid Solid

the solid to remove

onlySameLayer bool

if true: check only with solids on the same layer

Returns

bool

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

precision double

The 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

solid Solid

the solid to unite

onlySameLayer bool

if true: check only with solids on the same layer

Returns

bool

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

Model.AddingGeoObject

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

Model.AddingGeoObjects

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

Model.CalculateExtentForZoomTotalDelegate

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

Model.ExtentChangedDelegate

GeoObjectAddedEvent

This event will be fired when an object is added to this model.

public event Model.GeoObjectAdded GeoObjectAddedEvent

Event Type

Model.GeoObjectAdded

GeoObjectDidChangeEvent

This event will be fired when an object contained in this model did change.

public event ChangeDelegate GeoObjectDidChangeEvent

Event Type

ChangeDelegate

GeoObjectRemovedEvent

This event will be fired when an object is removed from this model.

public event Model.GeoObjectRemoved GeoObjectRemovedEvent

Event Type

Model.GeoObjectRemoved

GeoObjectWillChangeEvent

This event will be fired when an object contained in this model is about to change.

public event ChangeDelegate GeoObjectWillChangeEvent

Event Type

ChangeDelegate

GeoObjectsAddedEvent

This event will be fired after multiple GeoObjects have been added, AddingGeoObjectsEvent has been fired before.

public event Model.GeoObjectsAdded GeoObjectsAddedEvent

Event Type

Model.GeoObjectsAdded

GeoObjectsRemovedEvent

This event will be fired when removing multiple objects from this model is finished.

public event Model.GeoObjectsRemoved GeoObjectsRemovedEvent

Event Type

Model.GeoObjectsRemoved

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

Model.ImportingObjectsDelegate

NameChangedEvent

This event will be fired when the name of the model changed.

public event Model.NameChangedDelegate NameChangedEvent

Event Type

Model.NameChangedDelegate

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

Model.RemovingGeoObject

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

Event Type

Model.RemovingGeoObjects