Beispiel #1
0
def applyLayout(self):

    for nodetype in self.ASGroot.nodeTypes:
        for node in self.ASGroot.listNodes[nodetype]:

            if (isEntityNode(node.graphObject_)):

                # Move the nodes around
                currPos = node.graphObject_.getCenterCoord()
                newPos = [randint(0, 640), randint(0, 480)]
                node.graphObject_.Move(-currPos[0], -currPos[1],
                                       False)  # Go back to the origin
                node.graphObject_.Move(newPos[0], newPos[1],
                                       False)  # Move to random location

            else:

                # Move the links around
                currPos = node.graphObject_.getCenterCoord()
                newPos = [randint(0, 640), randint(0, 480)]
                node.graphObject_.Move(-currPos[0],
                                       -currPos[1])  # Go back to the origin
                node.graphObject_.Move(newPos[0],
                                       newPos[1])  # Move to random location

    selectAllVisibleObjects(self)
    optimizeLinks(self.cb)
    """
Beispiel #2
0
    def main(self, selection):

        setSmooth = self.__optionsDatabase.get(self.USE_SPLINE_OPTIMIZATION)
        setCurvature = self.__optionsDatabase.get(self.ARROW_CURVATURE)

        if (selection):
            optimizeLinks(self.cb,
                          setSmooth,
                          setCurvature,
                          selectedLinks=selection)
        else:
            optimizeLinks(self.cb, setSmooth, setCurvature)
Beispiel #3
0
 def main( self, selection ): 
   
   setSmooth    = self.__optionsDatabase.get('Spline optimization')   
   setCurvature = self.__optionsDatabase.get('Arrow curvature') 
       
   entityNodeList = self.__getEntityList(selection)
   if(len(entityNodeList) == 0):
     return
   self.__positionNodes(entityNodeList)
   
   optimizeLinks( self.cb, setSmooth, setCurvature, 
                 selectedLinks=self.__getLinkList(entityNodeList) )
Beispiel #4
0
    def main(self, selection):

        setSmooth = self.__optionsDatabase.get('Spline optimization')
        setCurvature = self.__optionsDatabase.get('Arrow curvature')
        doManualCycles = self.__optionsDatabase.get('Manual Cycles')
        doStartAtOrigin = self.__optionsDatabase.get('Origin')

        # Get all entity nodes (semantic objects)
        entityNodeList = self.__getEntityList(selection)
        if (len(entityNodeList) == 0):
            return

        # Get all root nodes (cycle in children possible), pure cycles will remain
        rootNodes = []
        for node in entityNodeList:
            if (node._treeVisit == False and len(node.in_connections_) == 0):
                node._treeVisit = True
                rootNodes.append(node)
                self.__markChildrenNodesBFS(node, [])

        # Gather all the cycle nodes
        cycleNodes = []
        for node in entityNodeList:
            if (node._treeVisit == False):
                cycleNodes.append(node)

        # Node cycle breakers --> choice of nodes as root to break the cycle
        if (doManualCycles):
            rootNodes = self.__getCycleRootsManually(cycleNodes, rootNodes)
        else:
            rootNodes = self.__getCycleRootsAuto(cycleNodes, rootNodes)

        #self.debugTree(rootNodes) # DFS printer

        # This does the actual moving around of nodes
        if (doStartAtOrigin):
            self.__layoutRoots(rootNodes, (0, 0))
        else:
            self.__layoutRoots(
                rootNodes, self.__getMaxUpperLeftCoordinate(entityNodeList))

        # Clean up
        for node in entityNodeList:
            del node._treeVisit
            del node._treeChildren

        # Re-wire the links to take into account the new node positions
        optimizeLinks(
            self.cb,
            setSmooth,
            setCurvature,
            selectedLinks=self.__getLinkListfromEntityList(entityNodeList))
Beispiel #5
0
    def main(self, selection):

        setSmooth = self.__optionsDatabase.get('Spline optimization')
        setCurvature = self.__optionsDatabase.get('Arrow curvature')

        entityNodeList = self.__getEntityList(selection)
        if (len(entityNodeList) == 0):
            return
        self.__positionNodes(entityNodeList)

        optimizeLinks(self.cb,
                      setSmooth,
                      setCurvature,
                      selectedLinks=self.__getLinkList(entityNodeList))
Beispiel #6
0
 def main( self, selection ): 
   
   setSmooth    = self.__optionsDatabase.get('Spline optimization')   
   setCurvature = self.__optionsDatabase.get('Arrow curvature') 
   doManualCycles = self.__optionsDatabase.get('Manual Cycles') 
   doStartAtOrigin = self.__optionsDatabase.get('Origin') 
    
   # Get all entity nodes (semantic objects)
   entityNodeList = self.__getEntityList(selection)    
   if(len(entityNodeList) == 0):
     return
   
   # Get all root nodes (cycle in children possible), pure cycles will remain
   rootNodes = []
   for node in entityNodeList:
     if(node._treeVisit == False and len(node.in_connections_) == 0):
       node._treeVisit = True
       rootNodes.append(node)
       self.__markChildrenNodesBFS(node, [])
       
   # Gather all the cycle nodes
   cycleNodes = []
   for node in entityNodeList:
     if(node._treeVisit == False):
       cycleNodes.append(node)
   
   # Node cycle breakers --> choice of nodes as root to break the cycle
   if(doManualCycles):
     rootNodes = self.__getCycleRootsManually(cycleNodes, rootNodes)
   else:
     rootNodes = self.__getCycleRootsAuto(cycleNodes, rootNodes)
           
   #self.debugTree(rootNodes) # DFS printer
   
   # This does the actual moving around of nodes
   if(doStartAtOrigin):
     self.__layoutRoots(rootNodes, (0, 0))
   else:
     self.__layoutRoots(rootNodes, 
                        self.__getMaxUpperLeftCoordinate(entityNodeList))
   
   # Clean up
   for node in entityNodeList:
     del node._treeVisit 
     del node._treeChildren 
   
   # Re-wire the links to take into account the new node positions
   optimizeLinks(self.cb, setSmooth, setCurvature, 
            selectedLinks=self.__getLinkListfromEntityList(entityNodeList))
Beispiel #7
0
  def __drawNodes(self, levelDictionary, linkNodeDict, topLeft):
    """ 
    Takes size of nodes into account to translate grid positions into actual
    canvas coordinates
    """
    setSmooth    = self.__optionsDatabase.get('Spline optimization')   
    setCurvature = self.__optionsDatabase.get('Arrow curvature') 
    minOffsetY = self.__optionsDatabase.get('yOffset') 
    minOffsetX = self.__optionsDatabase.get('xOffset') 
    giveExtraSpaceForLinks = self.__optionsDatabase.get('addEdgeObjHeight') 

    # Caclulate x, y offsets
    offsetX = 0
    levelInt2offsetY = dict()
    for levelInt in levelDictionary.keys():
      currentLevel = levelDictionary[levelInt]
      levelInt2offsetY[levelInt] = 0
      
      # Calculate maximum node size on a per level basis (X is for all levels)
      # Then add minimum seperation distance between nodes
      for node in currentLevel:
        # getSize returns node width, and height of the node & child link icon
        x, y = node.getSize(giveExtraSpaceForLinks)
        offsetX = max(offsetX, x)
        levelInt2offsetY[levelInt] = max(levelInt2offsetY[levelInt], y) 
                                     
        
    maxOffsetX = offsetX + minOffsetX
    halfOffsetX = offsetX / 2
        
    # Send nodes to their final destination, assign final pos to dummy edges
    x, y = topLeft
    for levelInt in levelDictionary.keys():
      currentLevel = levelDictionary[levelInt]      
      longEdgeOffset = [halfOffsetX, levelInt2offsetY[levelInt] / 3]
                    
      # Move each node in the level (Dummy edges save the pos but don't move)
      for node in currentLevel:
        node.moveTo(x + node.getGridPosition() * maxOffsetX, y, longEdgeOffset)
        
      # Increment y for the next iteration
      y += levelInt2offsetY[levelInt] + minOffsetY
      
    # Self-looping edges (Must move these manually into position)
    for selfLoopedEdge in NodeWrapper.SelfLoopList: 
      x, y = selfLoopedEdge.getEdgePosition()
      obj = selfLoopedEdge.getASGNode().graphObject_
      obj.moveTo(x, y)

    # Re-doing links can take a while, lets show something in meanwhile...
    self.atom3i.parent.update()
     
    # Re-wire the links to take into account the new node positions
    selectedLinks = []
    for obj in linkNodeDict.values():
      selectedLinks.append(obj)
    optimizeLinks(self.cb, setSmooth, setCurvature, 
                  selectedLinks=selectedLinks)
    
    # Re-doing links can take a while, lets show something in meanwhile...
    self.atom3i.parent.update()
    
    # Route multi-layer edges
    self.__edgeRouter()
Beispiel #8
0
    def __drawNodes(self, levelDictionary, linkNodeDict, topLeft):
        """ 
    Takes size of nodes into account to translate grid positions into actual
    canvas coordinates
    """
        setSmooth = self.__optionsDatabase.get('Spline optimization')
        setCurvature = self.__optionsDatabase.get('Arrow curvature')
        minOffsetY = self.__optionsDatabase.get('yOffset')
        minOffsetX = self.__optionsDatabase.get('xOffset')
        giveExtraSpaceForLinks = self.__optionsDatabase.get('addEdgeObjHeight')

        # Caclulate x, y offsets
        offsetX = 0
        levelInt2offsetY = dict()
        for levelInt in levelDictionary.keys():
            currentLevel = levelDictionary[levelInt]
            levelInt2offsetY[levelInt] = 0

            # Calculate maximum node size on a per level basis (X is for all levels)
            # Then add minimum seperation distance between nodes
            for node in currentLevel:
                # getSize returns node width, and height of the node & child link icon
                x, y = node.getSize(giveExtraSpaceForLinks)
                offsetX = max(offsetX, x)
                levelInt2offsetY[levelInt] = max(levelInt2offsetY[levelInt], y)

        maxOffsetX = offsetX + minOffsetX
        halfOffsetX = offsetX / 2

        # Send nodes to their final destination, assign final pos to dummy edges
        x, y = topLeft
        for levelInt in levelDictionary.keys():
            currentLevel = levelDictionary[levelInt]
            longEdgeOffset = [halfOffsetX, levelInt2offsetY[levelInt] / 3]

            # Move each node in the level (Dummy edges save the pos but don't move)
            for node in currentLevel:
                node.moveTo(x + node.getGridPosition() * maxOffsetX, y,
                            longEdgeOffset)

            # Increment y for the next iteration
            y += levelInt2offsetY[levelInt] + minOffsetY

        # Self-looping edges (Must move these manually into position)
        for selfLoopedEdge in NodeWrapper.SelfLoopList:
            x, y = selfLoopedEdge.getEdgePosition()
            obj = selfLoopedEdge.getASGNode().graphObject_
            obj.moveTo(x, y)

        # Re-doing links can take a while, lets show something in meanwhile...
        self.atom3i.parent.update()

        # Re-wire the links to take into account the new node positions
        selectedLinks = []
        for obj in linkNodeDict.values():
            selectedLinks.append(obj)
        optimizeLinks(self.cb,
                      setSmooth,
                      setCurvature,
                      selectedLinks=selectedLinks)

        # Re-doing links can take a while, lets show something in meanwhile...
        self.atom3i.parent.update()

        # Route multi-layer edges
        self.__edgeRouter()
Beispiel #9
0
  def main(self, selection):

    if( not selection ): return
    
    atom3i = self.atom3i
    nodeObject.nodeList = []
    edgeObject.edgeList = []
    edgeObject.dc       = self.dc   
       
    #------------------------- INFORMATION GATHERING -------------------------
       
    # Generate a datastructure for the Nodes and Edges in the diagram, containing
    # only the information needed by this algorithm.
    edgeList   = []
    nodeDict   = dict()
    self.sourceTargetDict = dict()
    for obj in selection:
        
        if( isConnectionLink( obj ) ):  
          # Edge!
          edgeList.append( obj.getSemanticObject() )                    
        else:
          # Node
          pos = obj.getCenterCoord()
          boundBox = obj.getbbox()
          if( self.__stickyBoundary ):
            boundary = self.atom3i.CANVAS_SIZE_TUPLE
          else:
            boundary = None
          n = nodeObject( obj, pos, boundBox, self.__chargeStrength, boundary )
          nodeDict.update( { obj : n } )
           
    # Now lets go through the "node" edges...
    for node in edgeList:
      # Source object
      key = node.in_connections_[0].graphObject_
      if( not nodeDict.has_key( key ) ): continue
      source = nodeDict[ key ]
      
      # Target object
      key = node.out_connections_[0].graphObject_
      if( not nodeDict.has_key( key ) ): continue
      target = nodeDict[ key ]
      
      # Make the edge object with the info...         
      edgeObject(node, source, target)
      self.sourceTargetDict[ source ] = target
      
      # These nodes have edges...
      source.setHasEdgeTrue()
      target.setHasEdgeTrue()
      
    # Count the beans...
    self.__totalNodes = len( nodeObject.nodeList )
    if( self.__totalNodes <= 1 ):  return                          
                              
    #-------------------------- MAIN SIMULATION LOOP -------------------------
    
    # Initial card shuffling :D
    if( self.__randomness ):
      self.__shakeThingsUp( self.__randomness )

    i = 0
    while( i < self.__maxIterations ):
      
      # Calculate the powers that be
      self.__calculateRepulsiveForces()
      self.__calculateAttractiveForces()
        
      # Move move move!
      for node in nodeObject.nodeList:
        node.commitMove()  
          
      # Force a screen update every x calculation
      if( i % self.__animationUpdates == 0 ):
        self.dc.update_idletasks()

      i+=1
          
    #--------------------------- FINAL OPTIMIZATIONS -------------------------

    # Optimize the arrows to use the nearest connectors
    optimizeLinks( self.atom3i.cb, self.__splineArrows, self.__arrowCurvature )
    
    # Make sure the canvas is updated
    self.dc.update_idletasks()
Beispiel #10
0
    def main(self, selection):

        if (not selection): return

        atom3i = self.atom3i
        nodeObject.nodeList = []
        edgeObject.edgeList = []
        edgeObject.dc = self.dc

        #------------------------- INFORMATION GATHERING -------------------------

        # Generate a datastructure for the Nodes and Edges in the diagram, containing
        # only the information needed by this algorithm.
        edgeList = []
        nodeDict = dict()
        self.sourceTargetDict = dict()
        for obj in selection:

            if (isConnectionLink(obj)):
                # Edge!
                edgeList.append(obj.getSemanticObject())
            else:
                # Node
                pos = obj.getCenterCoord()
                boundBox = obj.getbbox()
                if (self.__stickyBoundary):
                    boundary = self.atom3i.CANVAS_SIZE_TUPLE
                else:
                    boundary = None
                n = nodeObject(obj, pos, boundBox, self.__chargeStrength,
                               boundary)
                nodeDict.update({obj: n})

        # Now lets go through the "node" edges...
        for node in edgeList:
            # Source object
            key = node.in_connections_[0].graphObject_
            if (not nodeDict.has_key(key)): continue
            source = nodeDict[key]

            # Target object
            key = node.out_connections_[0].graphObject_
            if (not nodeDict.has_key(key)): continue
            target = nodeDict[key]

            # Make the edge object with the info...
            edgeObject(node, source, target)
            self.sourceTargetDict[source] = target

            # These nodes have edges...
            source.setHasEdgeTrue()
            target.setHasEdgeTrue()

        # Count the beans...
        self.__totalNodes = len(nodeObject.nodeList)
        if (self.__totalNodes <= 1): return

        #-------------------------- MAIN SIMULATION LOOP -------------------------

        # Initial card shuffling :D
        if (self.__randomness):
            self.__shakeThingsUp(self.__randomness)

        i = 0
        while (i < self.__maxIterations):

            # Calculate the powers that be
            self.__calculateRepulsiveForces()
            self.__calculateAttractiveForces()

            # Move move move!
            for node in nodeObject.nodeList:
                node.commitMove()

            # Force a screen update every x calculation
            if (i % self.__animationUpdates == 0):
                self.dc.update_idletasks()

            i += 1

        #--------------------------- FINAL OPTIMIZATIONS -------------------------

        # Optimize the arrows to use the nearest connectors
        optimizeLinks(self.atom3i.cb, self.__splineArrows,
                      self.__arrowCurvature)

        # Make sure the canvas is updated
        self.dc.update_idletasks()
Beispiel #11
0
   def updateGraphicalAttributes(self, parent, homGraphTuple, realGraph, 
                                 newNodes, moveEntities, 
                                 newSemanticConnections):
      """
         Updates graphical attributes once the replacement has been done.
      """
      idHomGraph, homGraph = homGraphTuple                                              # unwrap subraph id and subgraph node list
      for node in homGraph:             						# for each mapped node...
         if node in newNodes:           						# ey! new node!
            # get RHS node to obtain coordinates
            #RHSnode = self.getMatched(idHomGraph, node)
            #x, y = RHSnode.graphObject_.x, RHSnode.graphObject_.y
            x, y = self.positionNode(node, idHomGraph)
            node.graphObject_ = node.graphClass_(x, y,node)                                # create new graphical object!
            node.graphObject_.DrawObject(parent.UMLmodel)				# draw it
            parent.UMLmodel.addtag_withtag(node.getClass(), node.graphObject_.tag)	# add appropriate tags to canvas
         elif moveEntities:                                                             # Not new, but update position (if moveEntities != None)...
            LHSNode = self.getMatched( idHomGraph, node)                                # get LHS node...
            RHSNode = self.getMatched( idHomGraph, self.getMatched( idHomGraph, node))  # get RHS node...
            dx = LHSNode.graphObject_.x-RHSNode.graphObject_.x                          # begin to calculate displacement to apply
            dy = LHSNode.graphObject_.y-RHSNode.graphObject_.y
            parent.UMLmodel.addtag_withtag( "selected", node.graphObject_.tag )         # select the node we want to move...
            if (node.graphObject_.x+dx < 200) and (node.graphObject_.x+dx > 0) and (node.graphObject_.y+dy < 200) and (node.graphObject_.y+dy > 0):
               parent.initDragX = dx
               parent.initDragY = dy
               parent.moveBox(node.graphObject_.x+dx, node.graphObject_.y+dy)           # if inside canvas coords, move it!
            parent.UMLmodel.dtag(ALL, "selected")                                       # delete the selected tag from the items

 
      # Grab the current position of the graphical connections
      parent.ASGroot.destroyNodes()							
      for ntype in parent.ASGroot.listNodes.keys():
         # Iterate only on the homomorphic graph nodes!
         for node in parent.ASGroot.listNodes[ntype]:					
            node.graphObject_.deleteGraphicalConnections()
   
      # This will magically make the new/modified connections happen
      parent.ASGroot.writeContents(parent, 1, 0)

      # Iterate only on the homomorphic graph nodes!
      for node in homGraph:						
         for visualAttr in node.graphObject_.attr_display.keys():
            # Modify the graphical attributes appearance!
            node.graphObject_.ModifyAttribute(visualAttr, 
                                     node.__dict__[visualAttr].toString(16,5))

      # now, execute Post-Conditions on EDIT!
      for node in homGraph:						# iterate only on the homomorphic graph nodes!
        node.graphObject_.postCondition(ASG.EDIT)
        
        
      # Some basic layout for the new connections
      if(newSemanticConnections):
        
        # Get the graphical objects
        selectedLinks = []
        for newLink in newSemanticConnections:
          selectedLinks.append(newLink.graphObject_)
          
        # Optimize the new arrows  
        from Utilities import optimizeLinks
        optimizeLinks( parent.cb, True, 9, selectedLinks  )
Beispiel #12
0
    def updateGraphicalAttributes(self, parent, homGraphTuple, realGraph,
                                  newNodes, moveEntities,
                                  newSemanticConnections):
        """
         Updates graphical attributes once the replacement has been done.
      """
        idHomGraph, homGraph = homGraphTuple  # unwrap subraph id and subgraph node list
        for node in homGraph:  # for each mapped node...
            if node in newNodes:  # ey! new node!
                # get RHS node to obtain coordinates
                #RHSnode = self.getMatched(idHomGraph, node)
                #x, y = RHSnode.graphObject_.x, RHSnode.graphObject_.y
                x, y = self.positionNode(node, idHomGraph)
                node.graphObject_ = node.graphClass_(
                    x, y, node)  # create new graphical object!
                node.graphObject_.DrawObject(parent.UMLmodel)  # draw it
                parent.UMLmodel.addtag_withtag(
                    node.getClass(),
                    node.graphObject_.tag)  # add appropriate tags to canvas
            elif moveEntities:  # Not new, but update position (if moveEntities != None)...
                LHSNode = self.getMatched(idHomGraph, node)  # get LHS node...
                RHSNode = self.getMatched(
                    idHomGraph, self.getMatched(idHomGraph,
                                                node))  # get RHS node...
                dx = LHSNode.graphObject_.x - RHSNode.graphObject_.x  # begin to calculate displacement to apply
                dy = LHSNode.graphObject_.y - RHSNode.graphObject_.y
                parent.UMLmodel.addtag_withtag(
                    "selected", node.graphObject_.tag
                )  # select the node we want to move...
                if (node.graphObject_.x + dx <
                        200) and (node.graphObject_.x + dx >
                                  0) and (node.graphObject_.y + dy < 200) and (
                                      node.graphObject_.y + dy > 0):
                    parent.initDragX = dx
                    parent.initDragY = dy
                    parent.moveBox(node.graphObject_.x + dx,
                                   node.graphObject_.y +
                                   dy)  # if inside canvas coords, move it!
                parent.UMLmodel.dtag(
                    ALL, "selected")  # delete the selected tag from the items

        # grab the current position of the graphical connections
        parent.ASGroot.destroyNodes()
        for ntype in parent.ASGroot.listNodes.keys():
            # iterate only on the homomorphic graph nodes!
            for node in parent.ASGroot.listNodes[ntype]:
                node.graphObject_.deleteGraphicalConnections()

        # This will magically make the new/modified connections happen
        parent.ASGroot.writeContents(parent, 1, 0)

        # modify the graphical attributes appearance!
        for node in homGraph:  # iterate only on the homomorphic graph nodes!
            for visualAttr in node.graphObject_.attr_display.keys():
                node.graphObject_.ModifyAttribute(
                    visualAttr, node.__dict__[visualAttr].toString(16, 5))

        # now, execute Post-Conditions on EDIT!
        for node in homGraph:  # iterate only on the homomorphic graph nodes!
            node.graphObject_.postCondition(ASG.EDIT)

        # Some layout...
        if (newSemanticConnections):
            selectedLinks = []
            for newLink in newSemanticConnections:
                selectedLinks.append(newLink.graphObject_)
            from Utilities import optimizeLinks
            optimizeLinks(parent.cb, True, 9, selectedLinks)