def initTest(self): diagramFrame: Diagram = self._diagramFrame.GetDiagram() pointShape: PointShape = PointShape(50, 50) diagramFrame.AddShape(pointShape) for x in range(10): for y in range(3): pointShape: PointShape = PointShape(300 + x * 50, 300 + y * 50) diagramFrame.AddShape(pointShape) rectShape: RectangleShape = RectangleShape(100, 50, 130, 80) rectShape.SetDraggable(True) diagramFrame.AddShape(rectShape) anchor1 = AnchorPoint(50, 100) anchor1.SetDraggable(True) anchor2 = AnchorPoint(200, 300) anchor2.SetDraggable(True) lineShape: LineShape = LineShape(anchor1, anchor2) lineShape.SetDrawArrow(False) lineShape.SetDraggable(True) lineShape.SetSpline(False) controlPoint: ControlPoint = ControlPoint(50, 150) lineShape.AddControl(controlPoint) controlPoint = ControlPoint(200, 150) lineShape.AddControl(controlPoint) diagramFrame.AddShape(lineShape) self.drawLollipops()
def fixControlPoints(self): """ Fix a graphical path with control points. @author Nicolas Dubois """ # Clear the actual control points of the link (not the anchor points) self.removeAllControlPoints() # Current x coordinate of the link x = self.getSrcAnchorPos()[0] # For all virtual nodes, add control points to pass through for vnode in self.__virtualNodes: # ~ print "Virtual node" (xvnode, yvnode) = vnode.getPosition() # If link goes to up-left if x > xvnode: # Find the first real node on the right of the virtual node neighbor = vnode.getRightNode() # # Don't like embedded imports, but need to avoid cyclical dependency from org.pyut.plugins.sugiyama.VirtualSugiyamaNode import VirtualSugiyamaNode while isinstance(neighbor, VirtualSugiyamaNode) and neighbor is not None: # Try next neighbor neighbor = neighbor.getRightNode() # If real node found if neighbor is not None: ctrlPoint = ControlPoint(xvnode, neighbor.getPosition()[1] + neighbor.getSize()[1]) self.addControlPoint(ctrlPoint) else: # If link goes to up-right # Don't like embedded imports, but need to avoid cyclical dependency from org.pyut.plugins.sugiyama.VirtualSugiyamaNode import VirtualSugiyamaNode # Find the first real node on the left of the virtual node neighbor = vnode.getLeftNode() while isinstance(neighbor, VirtualSugiyamaNode) and neighbor is not None: # Try next neighbor neighbor = neighbor.getLeftNode() # If real node found if neighbor is not None: ctrlPoint = ControlPoint(xvnode, neighbor.getPosition()[1] + neighbor.getSize()[1]) self.addControlPoint(ctrlPoint) ctrlPoint = ControlPoint(xvnode, yvnode) self.addControlPoint(ctrlPoint)
def _createControlPoints(self) -> ControlPoints: """ Create a list of control points between the two mock shapes Returns: """ cp1: ControlPoint = ControlPoint(x=100, y=200) cp2: ControlPoint = ControlPoint(x=200, y=200) cp3: ControlPoint = ControlPoint(x=300, y=300) cp4: ControlPoint = ControlPoint(x=400, y=400) controlPoints: ControlPoints = cast(ControlPoints, [cp1, cp2, cp3, cp4]) return controlPoints
def AddControl(self, control: ControlPoint, after: Union[ControlPoint, LinePoint] = None): """ Add a control point to the line. The control point can be appended (last before the destination anchor) or inserted after a given control point. Args: control: control point to add after: This can be a control point after which to insert. This can also be the source of destination anchors. If it's the destination anchor, the point will be inserted BEFORE it. """ if after is not None: if after is self._srcAnchor: self._controls.insert(0, control) elif after is self._dstAnchor: self._controls.append(control) else: i = self._controls.index(after) self._controls.insert(i+1, control) else: self._controls.append(control) control.AddLine(self) # add the point to the diagram so that it can be selected if self._diagram is not None: self._diagram.AddShape(control)
def _addBend(self, clickPoint: Tuple[int, int]): OglLink.clsLogger.debug(f'Add a bend. {clickPoint=}') x = clickPoint[0] y = clickPoint[1] cp = ControlPoint(x, y) cp.SetVisible(True) # # Add it either before the destinationAnchor or the sourceAnchor # lp: LinePoint = self.GetSource() self.AddControl(control=cp, after=lp) frame = self._diagram.GetPanel() frame.GetDiagram().AddShape(cp) frame.Refresh()
def _generateControlPoints(self, link: Element) -> ControlPoints: controlPoints: ControlPoints = cast(ControlPoints, []) for controlPoint in link.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_CONTROL_POINT): x = PyutUtils.strFloatToInt(controlPoint.getAttribute(PyutXmlConstants.ATTR_X)) y = PyutUtils.strFloatToInt(controlPoint.getAttribute(PyutXmlConstants.ATTR_Y)) controlPoints.append(ControlPoint(x, y)) return controlPoints
def insertSelectedShape(self): umlFrame = self._treeNotebookHandler.getCurrentFrame() if umlFrame is None: return selected = umlFrame.GetSelectedShapes() if len(selected) != 1: return selected = selected.pop() if isinstance(selected, LinePoint): px, py = selected.GetPosition() # add a control point and make it child of the shape if it's a # self link line = selected.GetLines()[0] if line.GetSource().GetParent() is line.GetDestination().GetParent( ): cp = ControlPoint(0, 0, line.GetSource().GetParent()) cp.SetPosition(px + 20, py + 20) else: cp = ControlPoint(px + 20, py + 20) line.AddControl(cp, selected) umlFrame.GetDiagram().AddShape(cp) umlFrame.Refresh()
def _getOglLinks(self, xmlOglLinks, dicoOglObjects, dicoLink, dicoFather, umlFrame): """ To extract the links from an OGL object. """ def secure_float(floatX): if floatX is not None: return float(floatX) return 0.0 def secure_spline_int(splineX): if splineX is None: return 0 elif splineX == "_DeprecatedNonBool: False" or splineX == "False": return 0 elif splineX == "_DeprecatedNonBool: True" or splineX == "True": return 1 else: return int(splineX) for link in xmlOglLinks: # src and dst anchor position sx = secure_float(link.getAttribute("srcX")) sy = secure_float(link.getAttribute("srcY")) dx = secure_float(link.getAttribute("dstX")) dy = secure_float(link.getAttribute("dstY")) spline = secure_spline_int(link.getAttribute("spline")) # create a list of ControlPoints ctrlpts = [] for ctrlpt in link.getElementsByTagName("ControlPoint"): x = secure_float(ctrlpt.getAttribute("x")) y = secure_float(ctrlpt.getAttribute("y")) ctrlpts.append(ControlPoint(x, y)) # get the associated PyutLink srcId, dstId, pyutLink = self._getPyutLink(link) # CD 20060218 src = dicoOglObjects[srcId] dst = dicoOglObjects[dstId] linkType = pyutLink.getType() pyutLink = PyutLink("", linkType=linkType, source=src.getPyutObject(), destination=dst.getPyutObject()) oglLinkFactory = getOglLinkFactory() oglLink = oglLinkFactory.getOglLink(src, pyutLink, dst, linkType) src.addLink(oglLink) dst.addLink(oglLink) umlFrame.GetDiagram().AddShape(oglLink, withModelUpdate=False) # create the OglLink oglLink.SetSpline(spline) # give it the PyutLink newPyutLink = pyutLink # copy the good information from the read link newPyutLink.setBidir(pyutLink.getBidir()) # newPyutLink.setDestinationCardinality(pyutLink.getDestinationCardinality()) # newPyutLink.setSourceCardinality(pyutLink.getSourceCardinality()) newPyutLink.destinationCardinality = pyutLink.destinationCardinality newPyutLink.sourceCardinality = pyutLink.sourceCardinality newPyutLink.setName(pyutLink.getName()) # put the anchors at the right position srcAnchor = oglLink.GetSource() dstAnchor = oglLink.GetDestination() srcAnchor.SetPosition(sx, sy) dstAnchor.SetPosition(dx, dy) # add the control points to the line line = srcAnchor.GetLines()[0] # only 1 line per anchor in pyut parent = line.GetSource().GetParent() selfLink = parent is line.GetDestination().GetParent() for ctrl in ctrlpts: line.AddControl(ctrl) if selfLink: x, y = ctrl.GetPosition() ctrl.SetParent(parent) ctrl.SetPosition(x, y) if isinstance(oglLink, OglAssociation): # center = oglLink.getLabels()[CENTER] # src = oglLink.getLabels()[SRC_CARD] # dst = oglLink.getLabels()[DEST_CARD] label = link.getElementsByTagName("LabelCenter")[0] x = float(label.getAttribute("x")) y = float(label.getAttribute("y")) # center.SetPosition(x, y) oglLink.centerLabel.oglPosition.x = x oglLink.centerLabel.oglPosition.y = y label = link.getElementsByTagName("LabelSrc")[0] x = float(label.getAttribute("x")) y = float(label.getAttribute("y")) # src.SetPosition(x, y) oglLink.sourceCardinality.oglPosition.x = x oglLink.sourceCardinality.oglPosition.y = y label = link.getElementsByTagName("LabelDst")[0] x = float(label.getAttribute("x")) y = float(label.getAttribute("y")) dst.SetPosition(x, y)