Class AbstractDiagramLayouter

    • Field Detail

      • optionId

        private final java.lang.String optionId
      • selectedElementCache

        @CheckForNull
        private java.util.Set<PresentationElement> selectedElementCache
      • anchoredShape

        @CheckForNull
        private PresentationElement anchoredShape
        The shape element that should be anchored while layouting. This is related to Display Related Elements action.
      • anchoredDefaultPreferred

        private boolean anchoredDefaultPreferred
      • diagramLayouterAbortHandler

        private com.nomagic.magicdraw.uml.symbols.layout.DiagramLayouterAbortHandler diagramLayouterAbortHandler
      • layoutParameters

        private java.util.Map<java.lang.String,​java.lang.Object> layoutParameters
    • Constructor Detail

      • AbstractDiagramLayouter

        @OpenApi
        protected AbstractDiagramLayouter​(java.lang.String optionId,
                                          boolean nodes,
                                          boolean paths)
        Constructor
        Parameters:
        optionId - layouter options id
        nodes - true if should layout nodes
        paths - true if should layout edges
      • AbstractDiagramLayouter

        @OpenApi
        @Deprecated
        protected AbstractDiagramLayouter​(java.lang.String optionId,
                                          boolean nodes,
                                          boolean paths,
                                          boolean supportsSubgraph)
        Deprecated.
        supportsSubgraph has no effect
      • AbstractDiagramLayouter

        @OpenApi
        protected AbstractDiagramLayouter​(java.lang.String optionId)
        Constructor
        Parameters:
        optionId - layouter options id
      • AbstractDiagramLayouter

        @OpenApi
        @Deprecated
        protected AbstractDiagramLayouter​(java.lang.String optionId,
                                          boolean supportsSubgraph)
        Deprecated.
        supportsSubgraph has no effect
        Parameters:
        optionId - layouter options id
    • Method Detail

      • createLayoutParameters

        protected void createLayoutParameters()
      • hasOnlyNonLayoutableSelectedSymbols

        private boolean hasOnlyNonLayoutableSelectedSymbols​(DiagramPresentationElement dpe)
        Checks if no possible layoutable symbols are among selected symbols(that could be a label, or a swimlane cell etc.)
        Parameters:
        dpe - diagram
        Returns:
        true if has layoutable symbols
      • checkHasSameParent

        private boolean checkHasSameParent​(DiagramPresentationElement dpe)
        Checks if selected elements have same parent. Only then they can be layouted.
        Parameters:
        dpe - layouted diagram
        Returns:
        true if has same parent, false otherwise.
      • setupDrawResultAction

        private void setupDrawResultAction​(UMLGraph graph)
      • clearOldRectangles

        protected void clearOldRectangles​(UMLGraph graph)
        Clears old rectangles for shapes. The old rectangle is used for link placement in movePath, MoveManager.
        Parameters:
        graph - layouted graph
      • minimiseSwimlaneHeaders

        private static void minimiseSwimlaneHeaders​(UMLGraph graph,
                                                    @CheckForNull
                                                    com.nomagic.magicdraw.commands.MacroCommand mc)
        Updates swimlane header views.
      • containsSelectedFromTheSameParent

        protected boolean containsSelectedFromTheSameParent​(DiagramPresentationElement dpe)
        Checks if selected elements have the same parent. if nothing is selected return true
      • createCommands

        protected void createCommands​(@CheckForNull
                                      com.nomagic.magicdraw.commands.MacroCommand mc,
                                      UMLGraph graph)
        Draws the graph shapes on diagram frame
        Parameters:
        mc - macro command to store commands in
        graph - this graph will be taken as data for elements
      • placeLegendAndInfo

        protected void placeLegendAndInfo​(DiagramPresentationElement diagram,
                                          UMLGraph graph)
        Places diagram legends and infos.
        Parameters:
        diagram - diagram
      • postprocessing

        protected void postprocessing​(UMLGraph graph,
                                      @CheckForNull
                                      com.nomagic.magicdraw.commands.MacroCommand mc)
        Does some post processing after layout. Moves the graph, layouts swimlanes.
        Parameters:
        graph - the graph data for post processing
      • collectEdgesBySelectedPaths

        private static y.base.EdgeList collectEdgesBySelectedPaths​(UMLGraph graph,
                                                                   y.base.EdgeCursor allEdges)
        Collects all edges to a edge list whose corresponding path elements are selected in diagram.
        Parameters:
        graph - current graph
        allEdges - edge cursor from graph
        Returns:
        a new list of edges
      • collectNodesBySelectedShapes

        private static y.base.NodeList collectNodesBySelectedShapes​(UMLGraph graph,
                                                                    y.base.NodeCursor allNodes)
        Collects all nodes to a node list whose corresponding shape elements are selected in diagram.
        Parameters:
        graph - current graph
        allNodes - node cursor from graph
        Returns:
        a new list of nodes
      • moveBBToBB

        private static void moveBBToBB​(UMLGraph graph,
                                       DiagramPresentationElement diagram)
        Calculates the bounding of selected elements, the bounding box of those elements after layout and places the new bounding box at the position (x,y) of the old bounding box. This action might(mostly will) move elements , but will be close to the original point.
        Parameters:
        graph - the graph where all elements reside
        diagram - the layouted diagram
      • getSelected

        @OpenApi
        protected java.util.Set<PresentationElement> getSelected​(DiagramPresentationElement diagramView)
        Collects a set of selected layoutable presentation elements in a diagram
        Parameters:
        diagramView - the diagram that elements were selected in
        Returns:
        a set of selected layoutable presentation elements in a diagram. Empty if whole diagram is layouted.
      • resizeFrameIfNecessary

        protected void resizeFrameIfNecessary​(DiagramPresentationElement dpe,
                                              UMLGraph graph,
                                              @CheckForNull
                                              com.nomagic.magicdraw.commands.MacroCommand mc)
        Resizes diagram frame if there are no elements selected.
        Parameters:
        dpe - diagram
        mc - macro command
      • calculateFrameLayers

        private static java.awt.Dimension calculateFrameLayers​(DiagramPresentationElement dpe)
        Calculates the amount of pixels diagram frame should be extended regarding elements that are on bottom and right edge.
        Returns:
        dimension of maximum width and height for bottom and right side
      • isTypeSupported

        @OpenApi
        public boolean isTypeSupported​(DiagramType type)
        Test the given type is supported.
        Parameters:
        type - The given type.
        Returns:
        true, if diagram type is supported
      • setAnchoredPresentationElement

        public void setAnchoredPresentationElement​(PresentationElement shape,
                                                   boolean makePreferred)
        Sets a shape element that should be anchored to, and saves the set preferred option, so that is can be restored after layout.
        Parameters:
        shape - the shape that should be anchored while layouting.
        makePreferred - sets make preferred size option. For related elements should be set to false.
      • resetAnchoredShape

        private void resetAnchoredShape()
        Sets anchored shape element to null. Sets back the makePreferredSize option to what it was before.
      • getAnchoredPresentationElement

        @CheckForNull
        public PresentationElement getAnchoredPresentationElement()
        Returns:
        the shape that should be anchored and not moved anywhere after layout. Returns null if shape was not set.
      • getDiagramLayouterAbortHandler

        public com.nomagic.magicdraw.uml.symbols.layout.DiagramLayouterAbortHandler getDiagramLayouterAbortHandler()
      • setLayoutParameter

        public void setLayoutParameter​(java.lang.String key,
                                       java.lang.Object value)
        The need to reset the values back must be taken into consideration if a layouter is reused in few places
      • getLayoutParameter

        @CheckForNull
        public java.lang.Object getLayoutParameter​(java.lang.String key)