Nevron .NET Vision
Diagram for .NET / User's Guide / Conceptual Overview / Diagram Services

In This Topic
    Diagram Services
    In This Topic
    In Nevron Diagram for .NET the functionality of nodes, which depends on the context in which a node reside is implemented by services. Services are one of the fundamental Nevron DOM objects. Nodes can store references to one or more services of certain type, which they obtained from the first ancestor in the hierarchy, which implements the INServiceProvider interface.
    In the Nevron Diagram for .NET the core implementation of the INServiceProvider interface can be found in the base NDocument and NView classes. They both expose an instance of the  NServiceManager class, which can be obtained from the ServiceManager property. The service manager is used to maintain a list of the available services.

    See the Services topic for more information about the Nevron DOM services. Following is a brief explanation of the services currently available in the diagram framework:

     Event sink services

    Event sink services (or simply event sinks) are services, which provide centralized event handling. All NDiagramNode instances try to connect to an instance of the NDiagramEventSinkService (derived from NNodeEventSinkService - see Node Event Sink Service for more information). 

    Currently there are two instancable event sink services:

    • NDocumentEventSinkService  - represents the event sink used by NDocument instances. It exposes additional, document specific events, related to connections, views, document modification etc.
    • NViewEventSinkService  - represents the event sink used by NView instances. It exposes additional, view specific events, related to the view transformations, tools, selection etc.

    The following code example shows how to intercept common document and view events. 

    C#
    Copy Code
    using Nevron.Dom;
    ...
    nDrawingDocument1.EventSinkService.NodeBoundsChanged += new Nevron.Dom.NodeEventHandler(EventSinkService_NodeBoundsChanged);
    nDrawingView1.EventSinkService.NodeSelected += new Nevron.Dom.NodeEventHandler(EventSinkService_NodeSelected);
    ...
    
    private void EventSinkService_NodeBoundsChanged(NNodeEventArgs args)
    {
        MessageBox.Show("Node: " + args.Node.ToString() + " bounds changed");
    }
    
    private void EventSinkService_NodeSelected(NNodeEventArgs args)
    {
        MessageBox.Show("Node: " + args.Node.ToString() + " selected");
    }
    
    Visual Basic
    Copy Code
    Imports Nevron.Dom
    ...
    AddHandler NDrawingDocument1.EventSinkService.NodeBoundsChanged, AddressOf EventSinkService_NodeBoundsChanged
    AddHandler NDrawingView1.EventSinkService.NodeSelected, AddressOf EventSinkService_NodeSelected
    ...
    Private Sub EventSinkService_NodeBoundsChanged(ByVal args As NNodeEventArgs)
        MessageBox.Show("Node: " + CType(args.Node, Object).ToString() + " bounds changed")
    End Sub
    
    Private Sub EventSinkService_NodeSelected(ByVal args As NNodeEventArgs)
        MessageBox.Show("Node: " + CType(args.Node, Object).ToString() + " selected")
    End Sub
    
     Smart paint services

    Smart paint services provide nodes, with the means to request a repaint of the area on which they are displayed by calling the respective "Invalidate" method of this service. The actual "Invalidate" method called depends on the object geometry, but from a user's point of view it is enough to call the Invalidate method of the node to request a repaint. For example:

    C#
    Copy Code
    // invalidate a guideline - this will call the InvalidateSceneInfiniteLine method of the service
    guideline.Invalidate();
    
    // invalidate a rectangle - this will call the InvalidateSceneRect method of the service
    rectangle.Invalidate();
    
    Visual Basic
    Copy Code
    ' invalidate a guideline - this will call the InvalidateSceneInfiniteLine method of the service
    guideline.Invalidate()
    
    ' invalidate a rectangle - this will call the InvalidateSceneRect method of the service
    rectangle.Invalidate()
    

    Since services can be derived, this provides nodes with a transparent way to repaint themselves, regardless of the scene in which they currently reside. For example: if an element is hosted in a document, calling its Invalidate method will invalidate the projection of the element dirty area in all registered views, while if the same element is hosted in a view, calling the same method will only repaint the element dirty area in this view. 

    The Refresh method of a smart paint service will cause the entire view area to be repainted.

    The SmartRefresh method will perform a repaint only of the currently accumulated dirty area.

    All smart paint services derive from the base NDiagramSmartPaintService abstract class. Currently there are three instancable event sink services:

     History services

    History services provide elements and their attributes with consistent support for Undo and Redo. Nevron Diagram for .NET exposes only one instancable history service - NDocumentHistoryService (derived from NElementHistoryService - see the Element History Service topic for more information).

    The NDocumentHistoryService is by default registered in each NDocument instance. NDiagramElement instances connect to a service of this type and use it to record user and programmable actions. Since only  NDiagramElement instances connect to this service, no history is recorded when they are previewed in views, because NView does not provide a history service.

     Creating custom services
    You can create your own services - the only requirement is that they must implement the INService interface. Subclassed nodes can then connect to them either by finding the first ancestor node, which implements the INServiceProvider interface and asking it to provide a service of this type or by using reference integrity (see Reference Integrity for more information).
     Subclassing existing services

    You can also subclass the currently existing services.  To do so use the following guidelines:

    1. Create your own service class and derive if from the service you want to subclass
    2. Remove the current service of this type from the service manager
    3. Add an instance of your service to the service manager
    4. Update the references of the service manager container (with the help of the UpdateReferences method).
     Related Examples
    Windows Forms: Document Object Model - Document - History
    See Also