Class ModelView
- Namespace
- CADability
- Assembly
- CADability.dll
The ModelView is the three-dimensional presentation of a single Model.
public class ModelView : IShowPropertyImpl, IShowProperty, IPropertyEntry, ICommandHandler, IView
- Inheritance
-
ModelView
- Implements
- Inherited Members
Constructors
ModelView(Project)
Creates a view for the provided project. The view is not usable until its ProjectedModel has been set, which determines the model and the projection; GetStandardModelView(Model) does both. To show the view, add it to the frame (AddView(IView)) and make it the ActiveView. The flags AllowDrag, AllowDrop and AllowContextMenu are initialized from the global settings.
public ModelView(Project project)
Parameters
projectProjectThe project that contains the model and the layer list
Properties
AllowContextMenu
Gets or sets a flag which controls the context menu when a right mouse click in this view happens.
public bool AllowContextMenu { get; set; }
Property Value
AllowDrag
Gets or sets a flag which controls the dragging from this view, whether this view may be a source to DragAndDrop.
public bool AllowDrag { get; set; }
Property Value
AllowDrop
Gets or sets a flag which controls whether a dragged object may be dropped on this view.
public bool AllowDrop { get; set; }
Property Value
BackgroundColor
The color with which the canvas is cleared before the model is painted. Unless set explicitly, it is the color setting "Colors.Background" of the frame (or of the global settings), and it follows changes of that setting. Setting it does not repaint; call Invalidate().
public Color BackgroundColor { get; set; }
Property Value
ContextMenu
Overrides ContextMenu, returns the context menu with the id "MenuId.ModelView". (see LoadMenuDefinition(string, bool, ICommandHandler))
public override MenuWithHandler[] ContextMenu { get; }
Property Value
DisplayRectangle
The rectangle of the canvas in pixels in which the view is displayed (the ClientRectangle). Actions use it e.g. as the default area for a pick space. The LayoutView returns an empty rectangle while it is not connected to a canvas.
public Rectangle DisplayRectangle { get; }
Property Value
Distance
The distance of the viewer from the FixPoint for a perspective projection; 0.0 (the default) means parallel projection. Setting a value greater than 0 marks the view direction as modified, so that the perspective projection is applied when the projection properties in the property page lose the focus. The value is stored with the ProjectedModel.
public double Distance { get; set; }
Property Value
EntryType
Overrides EntryType, returns GroupTitle.
public override ShowPropertyEntryType EntryType { get; }
Property Value
FixPoint
The point in world coordinates around which the view is rotated when the view direction is changed with the mouse, and the point the viewer looks at in a perspective projection (see Distance). The user sets it with Ctrl+Shift+middle mouse button on an object; setting it here also sets FixPointValid. The value is stored with the ProjectedModel.
public GeoPoint FixPoint { get; set; }
Property Value
FixPointValid
Whether FixPoint holds a valid point. If true, rotating the view with the mouse turns the model around the fix point; otherwise the rotation takes place around the point in the center of the view (the object there, or else the point on the drawing plane).
public bool FixPointValid { get; set; }
Property Value
IsShading
If true, the faces of the model are displayed shaded (filled and lit); if false only the edges and curves are drawn (wire frame). This is ShowFaces of the projection of this view. Setting it rebuilds the display lists and repaints.
public bool IsShading { get; set; }
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; }
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
LineWidthMode
If true, all curves are displayed with thin lines regardless of their line width attribute; if false (the default, from the global setting "View.UseLineWidth") the line widths are shown. Setting it rebuilds the display lists and refreshes the property page, but does not repaint by itself.
public bool LineWidthMode { get; set; }
Property Value
Model
The Model shown by this view. Setting a different model creates a new ProjectedModel for it, keeping the projection and the name of the current one (a view without projected model gets a projection from the top), rebuilds the display lists and repaints.
public Model Model { get; set; }
Property Value
Name
The name of the view, which is the name of its ProjectedModel. It is shown as the label of the view in the property page and must be unique among the model views of the project. Setting it does not check for duplicates; the property page renames a view through the project.
public string Name { get; set; }
Property Value
ProjectedModel
The ProjectedModel shown by this view, which holds the model, the projection, the visible layers and the display lists. Setting it replaces the previous one: the view disconnects from the old projected model, registers for the repaint and projection changed events of the new one, applies the grid settings of the global settings to its projection, makes all layers of the project visible if the projected model has no visible layers yet, takes over its fix point and distance and refreshes the property page. The entry with the same name in the list of projected models of the project is replaced as well.
public ProjectedModel ProjectedModel { get; set; }
Property Value
Projection
The Projection of the view: view direction, scaling, placement and drawing plane. It is the projection of the ProjectedModel and null as long as no projected model is set. Setting it replaces the projection of the projected model (which keeps a clone); the view is not repainted by itself.
public Projection Projection { get; set; }
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
SupressAutoRegeneration
If true, the display lists are not regenerated automatically when the user zooms in and a finer triangulation would be needed; the model is displayed with the precision of the existing display lists. Use it to keep the display responsive with large models. Setting it repaints the view.
public bool SupressAutoRegeneration { get; set; }
Property Value
ZAxisUp
If true (the default), the view is kept upright when it is rotated with the mouse: the z-axis of the world always points up or down on the screen, never sideways. Setting it to true immediately turns a parallel projection into that orientation, rotating around the point in the center of the view. For a perspective projection (Distance greater than 0) the z-axis is always vertical.
public bool ZAxisUp { get; set; }
Property Value
Methods
Added(IPropertyPage)
Implementation of Added(IPropertyPage): memorizes the property page in propertyPage. Unlike Added(IPropertyTreeView) it does not raise the state changed event. Override it to subscribe to events while the entry is displayed, and call the base implementation.
public override void Added(IPropertyPage page)
Parameters
pageIPropertyPage
DoDragDrop(GeoObjectList, DragDropEffects)
Starts a drag and drop operation with the provided objects as the data on the canvas of this view, see DoDragDrop(GeoObjectList, DragDropEffects). The view must be connected to a canvas.
public DragDropEffects DoDragDrop(GeoObjectList dragList, DragDropEffects all)
Parameters
dragListGeoObjectListThe objects to drag
allDragDropEffectsThe effects (copy, move, link) the source allows
Returns
- DragDropEffects
The effect that was performed by the drop target
EndEdit(bool, bool, string)
Implementation of EndEdit(bool, bool, string): does nothing. An entry with an editable value or label overrides it to take over (or, when aborted, discard) the text that was entered.
public override void EndEdit(bool aborted, bool modified, string newValue)
Parameters
abortedbooltrue: the edit was aborted (Escape), false: it ended normally
modifiedbooltrue: the text was changed while editing
newValuestringthe text as it was when editing ended
~ModelView()
Finalizer without effect; the view does not own unmanaged resources.
protected ~ModelView()
ForceInvalidateAll()
Marks the display lists of the ProjectedModel as dirty and recalculates them. Call it when the projection or the display mode changed in a way that invalidates the cached display lists. The canvas is not invalidated, call Invalidate() as well. To only record the display lists again, e.g. after the graphics device was lost, InvalidateDisplayLists() is enough.
public void ForceInvalidateAll()
GetContentsAsBitmap()
Not implemented: always returns null. Kept for compatibility with earlier versions.
public Bitmap GetContentsAsBitmap()
Returns
- Bitmap
null
GetVisibleBoundingRect()
Returns the area of the view plane that is currently visible in the canvas.
public BoundingRect GetVisibleBoundingRect()
Returns
- BoundingRect
The visible rectangle in the 2d coordinate system of the projection (the same system ZoomToRect(BoundingRect) expects)
GetVisibleLayers()
Returns the layers whose objects are shown in this view.
public Layer[] GetVisibleLayers()
Returns
- Layer[]
The visible layers
Invalidate()
Requests a repaint of the whole view. Nothing happens while the view is not connected to a canvas.
public void Invalidate()
IsLayerVisible(Layer)
Checks whether the objects of the provided layer are shown in this view.
public bool IsLayerVisible(Layer l)
Parameters
lLayerThe layer
Returns
- bool
True if the layer is visible in this view
LabelChanged(string)
Implementation of LabelChanged(string). Override if LabelType is Editable.
public override void LabelChanged(string NewText)
Parameters
NewTextstringthe new text
MakeEverythingTranparent(bool)
Intended to display the model transparent while an action shows its feedback inside the model; currently it only repaints the view.
public void MakeEverythingTranparent(bool transparent)
Parameters
transparentboolNot evaluated
OnDragEnter(DragEventArgs)
Called by the canvas when a drag and drop operation enters its client area. The ModelView and the GDI2DView extract the dragged objects and show them following the mouse until they are dropped or the drag leaves the view; the other views ignore it.
public void OnDragEnter(DragEventArgs drgevent)
Parameters
drgeventDragEventArgsThe drag event with the data, the screen position and the allowed effects
OnDragOver(DragEventArgs)
Called by the canvas while a drag and drop operation moves over its client area. The preview of the dragged objects is moved to the current mouse position and the effect (move or copy) is set according to the allowed effects and the modifier keys.
public void OnDragOver(DragEventArgs drgevent)
Parameters
drgeventDragEventArgsThe drag event with the screen position and the allowed effects
Recalc()
Updates the scroll position after the view direction has been changed. The frame calls it after a menu command has changed the view direction. The projected model has no quadtree of its own any more which it would have to recalculate here.
public void Recalc()
RecalcScrollPosition()
Computes the visible fraction and the scroll position of the current display extent (the extent of the projected model, enlarged by 10%) and raises ScrollPositionChangedEvent with these values, so that the host can update its scroll bars. Nothing happens when the extent or the display rectangle is empty.
public void RecalcScrollPosition()
RefreshBackground()
Repaints the view (the same as Invalidate()). The name stems from the former display, where the background was kept in its own bitmap.
public void RefreshBackground()
Removed(IPropertyPage)
Overrides Removed(IPropertyPage)
public override void Removed(IPropertyPage page)
Parameters
pageIPropertyPagethe IPropertyTreeView from which it was removed
Scroll(int, int)
Scrolls the view by the provided number of pixels (as panning with the middle mouse button does), shows the "SizeAll" cursor, repaints and raises DisplayChangedEvent.
public void Scroll(int HScrollOffset, int VScrollOffset)
Parameters
HScrollOffsetintHorizontal offset in pixels, positive moves the model to the right
VScrollOffsetintVertical offset in pixels, positive moves the model down
SetAdditionalExtent(BoundingCube)
Enlarges the extent that is used to set up the depth range (near and far clipping planes) of the projection by the provided cube. Actions call it with the extent of the object they are constructing, so that feedback objects outside the model are not clipped. Passing an empty cube clears the additional extent.
public void SetAdditionalExtent(BoundingCube bc)
Parameters
bcBoundingCubeThe cube to include, or EmptyBoundingCube to reset
SetDisplayPrecision(double)
Sets the precision for the display of non linear entities (e.g. arcs). Choose a small value for high precision.
public void SetDisplayPrecision(double precision)
Parameters
precisiondoubleMaximum deviation from exact position
SetLayerVisibility(Layer, bool)
Shows or hides the objects of a layer in this view. The visibility of layers is a property of the view (its ProjectedModel), not of the model; see also IsLayerVisible(Layer) and GetVisibleLayers().
public void SetLayerVisibility(Layer l, bool visible)
Parameters
SetProjection(GeoVector, GeoPoint, double)
Set the direction of the view, the center and the scaling factor
public void SetProjection(GeoVector direction, GeoPoint center, double scalingFactor)
Parameters
directionGeoVectorThe direction
centerGeoPointThe center in worldcoordinates
scalingFactordoubleWorld units to pixel
SetViewDirection(ModOp, GeoPoint, bool)
Sets the unscaled projection (the rotation part of the view, see UnscaledProjection) and scrolls the
view so that fixPoint keeps its position on the screen, then the view is repainted. Used by
the interactive rotation of the view with the mouse and by the view point action.
public void SetViewDirection(ModOp project, GeoPoint fixPoint, bool mouseIsDown)
Parameters
projectModOpThe new unscaled projection: the rotation (and mirroring) of the world coordinate system into the view coordinate system
fixPointGeoPointThe point in world coordinates that keeps its position on the screen
mouseIsDownboolTrue while the mouse is still rotating: only the view is repainted, which is all a new view direction needs, because the display lists do not depend on it. When false, the projected model collects its display lists again and the scroll position is updated. A caller that passes true must make sure that the scroll position is updated when the rotation ends, as the view itself does with the next mouse move after it.
SetViewPosition(Point, Point)
Rotates the view direction according to a mouse movement, as the view does itself when the mouse is moved with Ctrl and the middle button: 5 pixels of horizontal or vertical movement rotate by one degree around the vertical or horizontal axis of the screen. ZAxisUp is respected, the rotation takes place around the FixPoint (if valid) or the point in the center of the view, and the cursor shows the direction of the movement. Use it to implement a custom view rotation, e.g. from a mouse filter.
public void SetViewPosition(Point lastMousePosition, Point currentMousePosition)
Parameters
lastMousePositionPointPrevious mouse position in client coordinates of the canvas
currentMousePositionPointCurrent mouse position in client coordinates of the canvas
ZoomToModelExtent(Rectangle, double)
DEPRECATED, use ZoomTotal(double) instead.
public void ZoomToModelExtent(Rectangle ClientRect, double Factor)
Parameters
ZoomToRect(BoundingRect)
public void ZoomToRect(BoundingRect visibleRect)
Parameters
visibleRectBoundingRect
ZoomTotal(double)
Zoom to the extent of the displayed model. Use 1.1 as a factor to leave some small amound of border area blank. Use 1.0 to exactely fit into the window
public void ZoomTotal(double Factor)
Parameters
FactordoubleAdditional scaling factor
ZoomTotal(Rectangle, double)
DEPRECATED, use ZoomTotal(double) instead.
public void ZoomTotal(Rectangle ClientRect, double Factor)
Parameters
Events
DisplayChangedEvent
Raised when the visible part of the model changes by scrolling, zooming with the mouse wheel or rotating the view with the mouse. The DisplayChangeArg tells the reason. Actions use it to update feedback that depends on the current view.
public event ModelView.DisplayChangedDelegate DisplayChangedEvent
Event Type
MouseDoubleClick
Provide an event handler for the mouse double click message here if you want to manipulate the mouse input to this ModelView
public event MouseFilterDelegate MouseDoubleClick
Event Type
MouseDown
Provide an event handler for the mouse down message here if you want to manipulate the mouse input to this ModelView
public event MouseFilterDelegate MouseDown
Event Type
MouseMove
Provide an event handler for the mouse move message here if you want to manipulate the mouse input to this ModelView
public event MouseFilterDelegate MouseMove
Event Type
MouseUp
Provide an event handler for the mouse up message here if you want to manipulate the mouse input to this ModelView
public event MouseFilterDelegate MouseUp
Event Type
MouseWheel
Provide an event handler for the mouse wheel message here if you want to manipulate the mouse input to this ModelView
public event MouseFilterDelegate MouseWheel
Event Type
PaintBackgroundEvent
Raised during each paint cycle after the model and the background (grid, drawing plane, coordinate cross) have been painted and before the selection and feedback handlers are called. The z-buffer is switched off at this point, so whatever the handler draws appears in front of the model. Handlers are registered with SetPaintHandler(DrawingAspect, PaintView) for Background.
public event PaintView PaintBackgroundEvent
Event Type
PaintClearEvent
Raised at the very beginning of each paint cycle, right after the canvas has been cleared with the BackgroundColor and before the projection is set and the model is painted. Use it to draw a custom background (e.g. a gradient or an image) behind the model.
public event PaintView PaintClearEvent
Event Type
PrePaintBackground
Event to modify backgroung painting
public event ModelView.PaintBackgroundDelegate PrePaintBackground
Event Type
ProjectionChangedEvent
Event for notification of view position and direction changes
public event ModelView.ProjectionChangedDelegate ProjectionChangedEvent
Event Type
ScrollPositionChangedEvent
Raised when the visible part of the display extent changes (zoom, scroll, resize), so that the host can update its scroll bars. See ScrollPositionChanged for the meaning of the parameters. Only the ModelView and the GDI2DView raise it; the LayoutView does not implement it.
public event ScrollPositionChanged ScrollPositionChangedEvent