Class ProjectedModel
- Namespace
- CADability
- Assembly
- CADability.dll
The projection of a Model with a certain Projection for the display in a ModelView. It keeps display lists of the model's objects per layer, the set of visible layers and the 2d extent of the projected model, and it follows changes of the model so that the display lists are updated. It also provides the hit testing and the intersection queries (e.g. for trimming and extending curves) that the actions need on the projected objects.
public class ProjectedModel : ISerializable, IDeserializationCallback, IJsonSerialize
- Inheritance
-
ProjectedModel
- Implements
- Inherited Members
Constructors
ProjectedModel()
Empty constructor for the JSON deserialization (IJsonSerialize); the data is set by SetObjectData(IJsonReadData).
protected ProjectedModel()
ProjectedModel(Model, Projection)
Creates the projection of the given model with the given projection. The projected model registers itself with the model to follow its changes and collects all objects of the model. If the precision of the projection (Precision) is 0, it is set to a thousandth of the size of the model's extent. Usually a ProjectedModel is created by the Project (AddProjectedModel(string, Model, Projection)) or by a ModelView, not directly.
public ProjectedModel(Model m, Projection pr)
Parameters
mModelThe model to display
prProjectionThe projection; it is used as is (not cloned) and is modified by the zoom, scroll and view direction methods
ProjectedModel(SerializationInfo, StreamingContext)
Constructor for the binary deserialization (ISerializable) of projects in the old file format. The visible layers are completed in the deserialization callback. Files are written in JSON format now.
protected ProjectedModel(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoThe serialized data
contextStreamingContextThe source of the serialization
Properties
Model
The model that is displayed. Setting it only exchanges the reference: the display data is not rebuilt and the events of the previous model are not unregistered, so create a new ProjectedModel to show another model.
public Model Model { get; set; }
Property Value
Name
The name of this projected model, which is also the name of the ModelView that shows it. It is unique within the project (see AddProjectedModel(string, Model, Projection)) and saved with the project.
public string Name { get; set; }
Property Value
Projection
The projection with which the model is displayed: view direction, parallel or perspective, drawing plane, grid and the placement (zoom and scroll position). The getter returns the object itself, which the zoom, scroll and view direction methods modify in place; the setter stores a clone of the given projection. Call ForceRecalc() after setting a different projection.
public Projection Projection { get; set; }
Property Value
UseLineWidth
Whether curves are to be displayed with their line width or all as thin lines. The initial value comes from the global setting "View.UseLineWidth". The value is only stored here; the display uses the corresponding flag of the Projection, which ModelView sets together with this one (context menu of the view).
public bool UseLineWidth { get; set; }
Property Value
Methods
AddVisibleLayer(Layer)
Marks the given Layer as visible in the context of this ProjectedModel.
public void AddVisibleLayer(Layer l)
Parameters
lLayerThe layer
AdjustPoint(SnapPointFinder)
Finds the snap point for the mouse position described by the SnapPointFinder: all visible objects in
the pick area are asked for their snap points (FindSnapPoint(SnapPointFinder)), then the
intersection points of curves in the pick area, the orthogonal position relative to the base point, the grid
points and the global and local origin are checked, as far as the snap modes of spf ask for
them. The result (the best point, the object that caused it and the kind of snap) is left in
spf, see SnapPoint, BestObject and
DidSnap. The views call it when an action needs a snapped point.
public void AdjustPoint(SnapPointFinder spf)
Parameters
spfSnapPointFinderThe initialized snap point finder, receives the result
Connect(IPaintTo3D)
Connects this projected model with the paint interface of a canvas; ModelView calls it when it gets its canvas. On the first connection the projected model registers itself with the model to follow its changes, sets the precision of the projection if it is 0 and collects all objects of the model. The display lists are built on the next paint. Pair it with Disconnect(IPaintTo3D).
public void Connect(IPaintTo3D paintTo3D)
Parameters
paintTo3DIPaintTo3DThe paint interface of the canvas
Connect(PaintBuffer)
Obsolete, does nothing. It remains from the former GDI based display via a PaintBuffer; the current display is connected with Connect(IPaintTo3D).
public void Connect(PaintBuffer paintBuffer)
Parameters
paintBufferPaintBufferNot used
Disconnect(IPaintTo3D)
Releases the display lists this projected model holds in the paint interface and forgets the paint interface. The display lists are rebuilt when the projected model is connected again. ModelView calls it when it loses its canvas.
public void Disconnect(IPaintTo3D paintTo3D)
Parameters
paintTo3DIPaintTo3DThe paint interface passed to Connect(IPaintTo3D)
Disconnect(PaintBuffer)
Obsolete counterpart of Connect(PaintBuffer), it only unsubscribes from the global settings.
public void Disconnect(PaintBuffer paintBuffer)
Parameters
paintBufferPaintBufferNot used
~ProjectedModel()
Finalizer. It does nothing; the display lists are released by Disconnect(IPaintTo3D).
protected ~ProjectedModel()
ForceExtentTo(BoundingRect)
Replaces the extent of the projected model (GetWorldExtent()) by the given rectangle, e.g. to define a working area that "zoom total" (ZoomTotal(Rectangle, double)) shows regardless of the objects. The value is not saved and is lost when the extent is recalculated after a change of the model or the projection.
public void ForceExtentTo(BoundingRect newVal)
Parameters
newValBoundingRectThe extent in the 2d coordinates of the projection plane
ForceRecalc()
Marks the display lists of this projected model as invalid, so that the next paint collects them again from the model, and discards the cached extent. Call it after changes the projected model does not notice by itself, e.g. after setting Projection or UseLineWidth; ForceInvalidateAll() calls it.
public void ForceRecalc()
GetDeviceExtent(IGeoObject)
Returns the extent of the given object projected with the current projection in device (pixel) coordinates, i.e. GetDisplayExtent(IGeoObject) converted with the placement of the projection (DeviceRect(BoundingRect)).
public Rectangle GetDeviceExtent(IGeoObject geoObject)
Parameters
geoObjectIGeoObjectThe object
Returns
- Rectangle
The rectangle in pixels
GetDisplayExtent()
Returns the extent of the whole projected model (GetWorldExtent()) in device (pixel) coordinates according to the current placement of the projection. Empty for an empty model.
public BoundingRect GetDisplayExtent()
Returns
- BoundingRect
The extent in pixels
GetDisplayExtent(GeoObjectList)
Returns the common extent of the given objects projected with the current projection, in the 2d coordinates of the projection plane (see GetDisplayExtent(IGeoObject)). Empty for an empty list.
public BoundingRect GetDisplayExtent(GeoObjectList list)
Parameters
listGeoObjectListThe objects
Returns
- BoundingRect
The 2d extent of the projected objects
GetDisplayExtent(IGeoObject)
Returns the extent of the given object projected with the current projection, in the 2d coordinates of the projection plane. The raw extent (Raw) is used, which may be somewhat larger than the exact one.
public BoundingRect GetDisplayExtent(IGeoObject geoObject)
Parameters
geoObjectIGeoObjectThe object
Returns
- BoundingRect
The 2d extent of the projected object
GetIntersectionParameters(ICurve, IntersectionMode)
Returns the parameters for all intersection point of this curve with other
curves in the model. The curve must be planar. To get the 3D intersection point
call PointAt(double). Depending on mode, there will also be
intersection parameters in the extension of the curve (if the curve can extend)
public double[] GetIntersectionParameters(ICurve Curve, ProjectedModel.IntersectionMode mode)
Parameters
CurveICurveCurve to test for intersection points
modeProjectedModel.IntersectionModeSpecifies whether only intersections inside the curve, intersections in the extensions (at the start, at the end or both) or also self intersections are returned
Returns
- double[]
Array of parameters
GetIntersectionParameters(ICurve, IntersectionMode, out ICurve[])
Like GetIntersectionParameters(ICurve, IntersectionMode), and additionally returns for each parameter
the curve of the model that intersects there. Only curves on layers visible in this projected model are considered.
Intersections with faces are returned with a null target curve, self intersections with the curve itself. The
parameters are sorted ascending. If the curve cannot be projected, an empty array is returned and
targetCurves is null.
public double[] GetIntersectionParameters(ICurve Curve, ProjectedModel.IntersectionMode mode, out ICurve[] targetCurves)
Parameters
CurveICurveCurve to test for intersection points, must be planar
modeProjectedModel.IntersectionModeWhich intersections to return, see ProjectedModel.IntersectionMode
targetCurvesICurve[]Receives the intersecting curve for each parameter (null for a face)
Returns
- double[]
The parameters on
Curveof the intersection points, ascending
GetObjectData(IJsonWriteData)
Implements GetObjectData(IJsonWriteData): writes the name, the model, the projection, the visible layers and the fix point and distance of the perspective view.
public void GetObjectData(IJsonWriteData data)
Parameters
dataIJsonWriteDataReceives the data
GetObjectsFromRect(BoundingRect, IGeoObject)
Returns all GeoObjects that coincide with the given BoundingRect in the projection
of this ProjectedModel. If parameter childOfThis is null, this function
will return the topmost parents of the objects else it will return direct children
of "childOfthis".
public GeoObjectList GetObjectsFromRect(BoundingRect pickrect, IGeoObject childOfThis)
Parameters
pickrectBoundingRectbounding rectangle in this projection
childOfThisIGeoObjectif null returns topmost parent else return directchild of this
Returns
- GeoObjectList
GeoObjects found
GetObjectsFromRect(BoundingRect, PickMode, FilterList)
Returns the objects of the model that are hit by the given rectangle under the current projection, using the
octtree of the model. Invisible objects, objects on layers that are not visible in this projected model (when a
layer filter is active) and objects rejected by filterList are left out;
pickMode decides whether top level objects, a single object, edges or faces are returned
(see PickMode). Returns an empty list if the model has no octtree yet.
public GeoObjectList GetObjectsFromRect(BoundingRect pickrect, PickMode pickMode, FilterList filterList)
Parameters
pickrectBoundingRectThe pick rectangle in the 2d coordinates of the projection plane
pickModePickModeWhat to pick
filterListFilterListAdditional filter for the objects, may be null
Returns
- GeoObjectList
The objects that were hit, each only once
GetObjectsNearRect(BoundingRect)
Get all GeoObjects that coincide with the given BoundingRect or are close to it. This method is faster than GetObjectsFromRect but does not check the overlap of the ractangle and the GeoObject
public GeoObjectList GetObjectsNearRect(BoundingRect pickrect)
Parameters
pickrectBoundingRectthe BoundingRect
Returns
- GeoObjectList
List of all GeoObjects close to the BoundingRect
GetVisibleLayers()
Returns the layers that are marked visible in this projected model (see AddVisibleLayer(Layer)). An empty array is treated as "no layer filter" by the picking methods, i.e. all objects are visible; a ModelView marks all layers of the project visible when it gets a projected model without visible layers. Objects without a layer are always visible.
public Layer[] GetVisibleLayers()
Returns
- Layer[]
A copy of the set of visible layers
GetWorldExtent()
Returns the extent of all objects of the model projected with the current projection, as a rectangle in the 2d coordinates of the projection plane (unscaled, not in pixels). The value is cached until the model or the projection changes. Empty for an empty model.
public BoundingRect GetWorldExtent()
Returns
- BoundingRect
The 2d extent of the projected model
HitTest(IGeoObject, BoundingRect)
Tests whether the given object, projected with the current projection, touches the given rectangle (HitTest(Projection, BoundingRect, bool) with onlyInside false).
public bool HitTest(IGeoObject go, BoundingRect rect)
Parameters
goIGeoObjectThe object to test
rectBoundingRectThe rectangle in the 2d coordinates of the projection plane
Returns
- bool
true if the object is hit
InvalidateDisplayLists()
Makes this projected model and all other projected models of the same Model record their display lists again with the next paint, and requests a repaint. Use it when the display lists are no longer valid, e.g. after the graphics device was lost or the renderer was switched (together with ClearFontCache()). Unlike ForceRecalc(), which only makes this projected model collect the existing display lists again, it makes the model record them anew; the extent is kept.
public void InvalidateDisplayLists()
IsLayerVisible(Layer)
Determins whether the given Layer is marked visible in the context of this ProjectedModel.
public bool IsLayerVisible(Layer l)
Parameters
lLayerThe layer
Returns
RemoveVisibleLayer(Layer)
Marks the given Layer as invisible in the context of this ProjectedModel.
public void RemoveVisibleLayer(Layer l)
Parameters
lLayerThe layer
Scroll(double, double)
Moves the placement of the projection, i.e. scrolls the displayed image by the given offsets in pixels (MovePlacement(double, double)). The display is not invalidated by this call.
public void Scroll(double dx, double dy)
Parameters
SetObjectData(IJsonReadData)
Implements SetObjectData(IJsonReadData): reads the data written by GetObjectData(IJsonWriteData) and marks the display lists as invalid.
public void SetObjectData(IJsonReadData data)
Parameters
dataIJsonReadDataThe data to read from
SetTopViewProjection()
Replaces the projection by a new standard projection from top (FromTop) and discards the cached extent. Note that other holders of the previous projection object (e.g. the ModelView) are not informed, and the display lists are not recalculated. Not used by CADability itself.
public void SetTopViewProjection()
SetViewDirection(GeoPoint, GeoVector, GeoPoint, bool)
Makes the projection a perspective projection with the viewer at fromHere looking in
direction; fixPoint keeps its position on the screen. The cached extent is
discarded, the display lists are kept.
public void SetViewDirection(GeoPoint fromHere, GeoVector direction, GeoPoint fixPoint, bool temporary)
Parameters
fromHereGeoPointThe position of the viewer (eye point)
directionGeoVectorThe view direction
fixPointGeoPointThe point that stays at its place on the screen
temporaryboolNot used any more, see SetViewDirection(GeoVector, bool)
SetViewDirection(GeoVector, bool)
Sets the view direction of the (parallel) projection so that the z axis of the world points upwards on the screen (the y axis when looking along the z axis). The cached extent is discarded; the display lists do not depend on the view direction and are kept.
public void SetViewDirection(GeoVector dir, bool temporary)
Parameters
dirGeoVectorThe new view direction (from the viewer into the scene)
temporaryboolNot used any more: there is nothing to postpone while the user rotates the view. It is kept for compatibility
SetViewDirection(ModOp, bool)
Sets the unscaled projection (the transformation from world coordinates to the 2d coordinates of the projection plane, UnscaledProjection) directly; the projection becomes a parallel projection. SetViewDirection(ModOp, GeoPoint, bool) uses it when the user rotates the view and then scrolls so that the fix point stays at its place. The cached extent is discarded, the display lists are kept.
public void SetViewDirection(ModOp p, bool temporary)
Parameters
pModOpThe new unscaled projection
temporaryboolNot used any more, see SetViewDirection(GeoVector, bool)
ZoomToModelExtent(Rectangle, double)
Sets the projection to display the Extent inside the given rectangle
public void ZoomToModelExtent(Rectangle ClientRect, double Factor)
Parameters
ClientRectRectangleThe client rectangle of the CondorControl
FactordoubleAdditional Factor to show more or less
ZoomToRect(Rectangle, BoundingRect)
Sets the placement (scaling and offset) of the projection so that the given rectangle of the projection plane fills the client rectangle (SetPlacement(Rectangle, BoundingRect)). The display is not invalidated by this call; ZoomToRect(BoundingRect) does that.
public void ZoomToRect(Rectangle ClientRect, BoundingRect visibleRect)
Parameters
ClientRectRectangleThe client rectangle of the canvas in pixels
visibleRectBoundingRectThe rectangle in the 2d coordinates of the projection plane that should become visible
ZoomTotal(Rectangle, double)
Sets the placement of the projection so that the whole projected model (GetWorldExtent()), enlarged by
Factor, fills the client rectangle. For an empty model (or one without a 2d extent) a cube of
100 units at the origin is shown instead. The display is not invalidated by this call.
public void ZoomTotal(Rectangle ClientRect, double Factor)