def _PyutLink2xml(self, pyutLink: PyutLink): """ Convert a PyutLink to an miniDom Element Args: pyutLink: Returns: An XML element """ # adding links in dictionary if pyutLink in self.__savedLinks: return None self.__savedLinks[pyutLink] = 1 root = Element('Link') # link name root.setAttribute('name', pyutLink.getName()) # link type root.setAttribute('type', str(pyutLink.getType())) # link cardinality source root.setAttribute('cardSrc', pyutLink.sourceCardinality) # link cardinality destination # root.setAttribute('cardDestination', pyutLink.getDestinationCardinality()) root.setAttribute('cardDestination', pyutLink.destinationCardinality) # link bidir root.setAttribute('bidir', str(pyutLink.getBidir())) # link destination root.setAttribute('destination', pyutLink.getDestination().getName()) return root
def _pyutLinkToXml(self, pyutLink: PyutLink, xmlDoc: Document) -> Element: """ Exporting a PyutLink to a miniDom Element. Args: pyutLink: Link to save xmlDoc: xml document Returns: A new minidom element """ root: Element = xmlDoc.createElement( PyutXmlConstants.ELEMENT_MODEL_LINK) root.setAttribute(PyutXmlConstants.ATTR_NAME, pyutLink.getName()) root.setAttribute(PyutXmlConstants.ATTR_TYPE, pyutLink.getType().name) root.setAttribute(PyutXmlConstants.ATTR_CARDINALITY_SOURCE, pyutLink.sourceCardinality) root.setAttribute(PyutXmlConstants.ATTR_CARDINALITY_DESTINATION, pyutLink.destinationCardinality) root.setAttribute(PyutXmlConstants.ATTR_BIDIRECTIONAL, str(pyutLink.getBidir())) srcLinkId: int = self._idFactory.getID(pyutLink.getSource()) destLinkId: int = self._idFactory.getID(pyutLink.getDestination()) root.setAttribute(PyutXmlConstants.ATTR_SOURCE_ID, str(srcLinkId)) root.setAttribute(PyutXmlConstants.ATTR_DESTINATION_ID, str(destLinkId)) return root
def _PyutLink2xml(self, pyutLink: PyutLink): """ Exporting an PyutLink to an miniDom Element @since 2.0 @Deve Roux <*****@*****.**> @param pyutLink @return Element """ # hadding links in dictionnary if pyutLink in self.__savedLinks: return None self.__savedLinks[pyutLink] = 1 root = Element('Link') # link name root.setAttribute('name', pyutLink.getName()) # link type root.setAttribute('type', str(pyutLink.getType())) # link cardinality source root.setAttribute('cardSrc', pyutLink.sourceCardinality) # link cardinality destination # root.setAttribute('cardDestination', pyutLink.getDestinationCardinality()) root.setAttribute('cardDestination', pyutLink.destinationCardinality) # link bidir root.setAttribute('bidir', str(pyutLink.getBidir())) # link destination root.setAttribute('destination', pyutLink.getDestination().getName()) return root
def _PyutLink2xml(self, pyutLink: PyutLink, xmlDoc): """ Exporting an PyutLink to a miniDom Element. @param PyutLink pyutLink : Link to save @param xmlDoc : xml document @return Element : XML Node """ root = xmlDoc.createElement('Link') # link name root.setAttribute('name', pyutLink.getName()) # link type root.setAttribute('type', str(pyutLink.getType().value)) # link cardinality source # root.setAttribute('cardSrc', pyutLink.getSourceCardinality()) root.setAttribute('cardSrc', pyutLink.sourceCardinality) # link cardinality destination # root.setAttribute('cardDestination', pyutLink.getDestinationCardinality()) root.setAttribute('cardDestination', pyutLink.destinationCardinality) # link bidir root.setAttribute('bidir', str(pyutLink.getBidir())) # link source srcLinkId = self._idFactory.getID(pyutLink.getSource()) root.setAttribute('sourceId', str(srcLinkId)) # link destination destLinkId = self._idFactory.getID(pyutLink.getDestination()) root.setAttribute('destId', str(destLinkId)) return root
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)