Nevron .NET Vision Documentation
Drawing Views

Drawing views are represented by the NDrawingView class, which derives from NView class. This is the most widely used type of view, since it can display and edit a drawing document. Drawing views are controls, which appear in the Visual Studio toolbox. They are represented by the following item:

Document

The drawing document displayed by the drawing view is specified by the Document property. In order to be functional the drawing view has to be connected to a drawing document:

C#
Copy Code
// attach the view to a document
drawingView.Document = drawingDocument;
Visual Basic
Copy Code
' attach the view to a document
drawingView.Document = drawingDocument
Trackers

The drawing view content layer is populated with trackers. Trackers are interactive editors with handles, which the user can drag. Trackers are used to modify different aspects of the currently selected shapes. The types of trackers displayed for a particular shape depend on the shape interaction style (see Shapes for more information).  

All types of trackers derive from the base NTracker class. Trackers are managed from an instance of the NTrackersManager, which is accessible from the TrackersManager property of the drawing view.

Components

The drawing view exposes three visual components, which can help you better position and align edited document content. Common for them all is that they have a measurement unit, which can be different from the measurement unit of the currently edited document, but can also be configured to synchronize it with the document measurement unit. The root class for all view components is the NViewComponent abstract class. Following is a brief summary of the instancable view components:

Scaling and Zooming

Besides the basic view abilities to scroll and pan, drawing views also add support for scaling and zooming of the scene displayed by them. This is achieved by modifying the World to View transformation of the document, which is a standard GDI+ transformation passed in the Graphics Transform property (see Coordinate Systems  for more information).

To be more precise the World to View transformation of the drawing document depends on the values of three properties: ScaleX, ScaleY and ViewportOrigin. You may also find useful the Zoom methods, which help you apply a centric based magnification of the drawing view. For example:

C#
Copy Code
// scale the document with factor 2 in the X dimension
// and with factor 3 in the Y dimension (irregular view scale)
drawingView.ScaleX = 2;
drawingViewiew.ScaleY = 3;
  
// zoom in the document to 200% and make the document scene point
// with coordinates 100, 100 the center of the viewport
drawingView.Zoom(2, new NPointF(100, 100));

// zoom the document to 300% and preserve the current viewport center
drawingView.Zoom(3);
Visual Basic
Copy Code
' scale the document with factor 2 in the X dimension
' and with factor 3 in the Y dimension (irregular view scale)
drawingView.ScaleX = 2
drawingView.ScaleY = 3

' zoom in the document to 200% and make the document scene point
' with coordinates 100, 100 the center of the viewport
drawingView.Zoom(2, New NPointF(100, 100))

' zoom the document to 300% and preserve the current viewport center
drawingView.Zoom(3)
Transformations

For your convenience the view exposes a set of useful transform properties, which can be used to convert coordinates between the different coordinate systems as well as to obtain the current scale factors between the different coordinate systems. Following is a brief summary:

Transformation Description
SceneToDevice Obtains the current scene to device transformation (identical for the document and the view scene).
SceneScaleToPixelsX Obtains the current X scaling of scene units to pixels (identical for the document and the view scene)
SceneScaleToPixelsY Obtains the current Y scaling of scene units to pixels (identical for the document and the view scene)
DocumentSceneToWorld Obtains the current scene to world transformation of the document.
DocumentWorldToView Obtains the current world to view transformation of the document.
DocumentWorldToDevice Obtains the current world to device transformation of the document.
DocumentWorldScaleToPixelsX Obtains the current X scaling of document world units to pixels
DocumentWorldScaleToPixelsY Obtains the current Y scaling of document world units to pixels

The following code converts a point from view device coordinates to document scene coordinates:

C#
Copy Code
// convert a point from device (client) coordinates to scene coordinates
NPointF docScenePoint = drawingView.SceneToDevice.InvertPoint(viewDevicePoint);
Visual Basic
Copy Code
' convert a point from device (client) coordinates to scene coordinates
Dim docScenePoint As NPointF = drawingView.SceneToDevice.InvertPoint(viewDevicePoint)
Layout

The positioning of the drawing relative to the view window is called view layout. The current view layout is specified by the ViewLayout property. The view will automatically enforce the current view layout when it is resized. Currently the following layouts are supported:

By default the view layout is set to Normal. The following code enables the Fit layout:

C#
Copy Code
// enable the fit layout
drawingView.ViewLayout = ViewLayout.Fit;
Visual Basic
Copy Code
' enable the fit layout
drawingView.ViewLayout = ViewLayout.Fit
Painting

Since the drawing view is responsible not only for the display of the drawing document, but also for the display of it's scene, it paints itself in the following sequence:

Interactive Appearance

Optionally the drawing view can override the appearance of selected and highlighted DOM elements. This feature is called interactive appearance and its aspects can be controlled by an instance of the NInteractiveAppearance class, accessible from the InteractiveAppearance property. The following code will change the appearance of all selected nodes:

C#
Copy Code
// make all selected nodes with blue border and yellow solid color filling
drawingView.InteractiveAppearance.SelectedAppearanceChangeMode = AppearanceChangeMode.Appearance;
drawingView.InteractiveAppearance.SelectedFillStyle = new NColorFillStyle(Color.Yellow);
drawingView.InteractiveAppearance.SelectedStrokeStyle = new NStrokeStyle(1, Color.Blue);
Visual Basic
Copy Code
' make all selected nodes with blue border and yellow solid color filling
drawingView.InteractiveAppearance.SelectedAppearanceChangeMode = AppearanceChangeMode.Appearance
drawingView.InteractiveAppearance.SelectedFillStyle = New NColorFillStyle(Color.Yellow)
drawingView.InteractiveAppearance.SelectedStrokeStyle = New NStrokeStyle(1, Color.Blue)
Preview Manager

The previews generated by the drawing view are managed by an instance of the NDrawingPreviewManager class, which is accessible from the PreviewManager property of the drawing view. 

You can optionally specify whether the previews use the original node style, or the style of the view context with the help of the PreviewWithOriginalStyle property of the preview manager. Originally it is set to false, which means that they use the style provided by the view context. The following code will cause all node previews to use the style of their document context:

C#
Copy Code
// force all node previews to use the style of their document context
drawingView.PreviewManager.PreviewWithOriginalStyle = true;
Visual Basic
Copy Code
' force all node previews to use the style of their document context
drawingView.PreviewManager.PreviewWithOriginalStyle = True

Large entity previews can sometimes be time consuming to generate and slow to drag around. You can control the maximum number of nodes previewed at one time with the help of the MaxPreviewNodesCount property. When the count of previewed nodes exceeds this value only a frame will be displayed around the previewed entity.

C#
Copy Code
// do not allow more than 10 nodes to be previewed at one time (for example translated)
drawingView.PreviewManager.MaxPreviewNodesCount = 10;
Visual Basic
Copy Code
' do not allow more than 10 nodes to be previewed at one time (for example translated)
drawingView.PreviewManager.MaxPreviewNodesCount = 10
Hit tests

Besides the standard set of hit test operations declared in NView, drawing views provide the following types of hit tests:

Snapping
Drawing views add powerful support for coordinate, point and angle snapping, which is wrapped in an instance of the NSnapManager class, which can be obtained from the SnapManager property. See Snapping for more information.
Related Examples
Windows Forms: Drawing View folder
See Also

 

 


©2017. Nevron Software LLC.

Send Feedback