From 29b3e895fb9ec4fe7d0d6451b875ce7a8e62bc7c Mon Sep 17 00:00:00 2001 From: LL Date: Sun, 22 Mar 2020 20:29:18 +0100 Subject: [PATCH] Facet nodes import/export bug solved #79 solved --- eddy/core/exporters/graphol_iri.py | 7 +++++-- eddy/core/items/nodes/common/base.py | 4 ++-- eddy/core/items/nodes/facet_iri.py | 2 +- eddy/core/loaders/graphol_iri.py | 23 +++++++++-------------- eddy/core/owl.py | 2 +- eddy/ui/iri.py | 12 +++++++++--- eddy/ui/session.py | 2 +- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/eddy/core/exporters/graphol_iri.py b/eddy/core/exporters/graphol_iri.py index 7fee67e8..89187069 100644 --- a/eddy/core/exporters/graphol_iri.py +++ b/eddy/core/exporters/graphol_iri.py @@ -410,6 +410,8 @@ def exportFacetNode(self, node): :rtype: QDomElement """ #TODO + nodeEl = self.getNodeDomElement(node) + position = node.mapToScene(node.textPos()) label = self.document.createElement('label') label.setAttribute('height', node.labelA.height()) @@ -417,9 +419,10 @@ def exportFacetNode(self, node): label.setAttribute('x', position.x()) label.setAttribute('y', position.y()) label.appendChild(self.document.createTextNode(node.text())) + nodeEl.appendChild(label) element = self.getFacetDomElement(node) - element.appendChild(label) - return element + nodeEl.appendChild(element) + return nodeEl def exportIndividualNode(self, node): """ diff --git a/eddy/core/items/nodes/common/base.py b/eddy/core/items/nodes/common/base.py index efcd7818..d78fd0a2 100644 --- a/eddy/core/items/nodes/common/base.py +++ b/eddy/core/items/nodes/common/base.py @@ -823,8 +823,8 @@ def doUpdateNodeLabel(self): self.renderByLabel() elif rendering == IRIRender.SIMPLE_NAME.value or rendering == IRIRender.SIMPLE_NAME: self.renderBySimpleName() - self.updateTextPos() - self.updateNode() + #self.updateTextPos() + #self.updateNode() def renderByFullIRI(self): self.setText(str(self.iri)) diff --git a/eddy/core/items/nodes/facet_iri.py b/eddy/core/items/nodes/facet_iri.py index 1cccf22c..1641850b 100644 --- a/eddy/core/items/nodes/facet_iri.py +++ b/eddy/core/items/nodes/facet_iri.py @@ -133,7 +133,7 @@ def doUpdateNodeLabel(self): literal = self.facet.literal self.labelB.setText(str(literal)) - self.updateNode() + #self.updateNode() ############################################# diff --git a/eddy/core/loaders/graphol_iri.py b/eddy/core/loaders/graphol_iri.py index f64de1ac..5dc976b1 100644 --- a/eddy/core/loaders/graphol_iri.py +++ b/eddy/core/loaders/graphol_iri.py @@ -1378,20 +1378,14 @@ def importLiteralNode(self, diagram, nodeElement): return node def importFacetNode(self, diagram, nodeElement): - labelElement = nodeElement.firstChildElement('label') - labelText = labelElement.text() - firstQuote = labelText.find('"') - secondQuote = labelText.rfind('"') - lexForm = labelText[firstQuote + 1:secondQuote] - literal = Literal(lexForm) - typeIndex = labelText.find('^') - prefixedType = labelText[:typeIndex] - colonIndex = prefixedType.find(':') - prefix = prefixedType[:colonIndex] - ns = prefixedType[colonIndex + 1:] - iriString = '{}{}'.format(self.nproject.getPrefixResolution(prefix), ns) - conFacetIRI = self.nproject.getIRI(iriString) - facet = Facet(conFacetIRI, literal) + facetEl = nodeElement.firstChildElement('facet') + constrFacetEl = facetEl.firstChildElement('constrainingFacet') + constrFacetIRI = self.nproject.getIRI(constrFacetEl.text()) + literalEl = facetEl.firstChildElement('literal') + lexForm = literalEl.firstChildElement('lexicalForm').text() + datatypeIRI = self.nproject.getIRI(literalEl.firstChildElement('datatype').text()) + literal = Literal(lexForm,datatypeIRI) + facet = Facet(constrFacetIRI, literal) geometryElement = nodeElement.firstChildElement('geometry') node = diagram.factory.create(Item.FacetIRINode, **{ 'id': nodeElement.attribute('id'), @@ -1401,6 +1395,7 @@ def importFacetNode(self, diagram, nodeElement): }) node.setPos(QtCore.QPointF(int(geometryElement.attribute('x')), int(geometryElement.attribute('y')))) node.doUpdateNodeLabel() + labelElement = nodeElement.firstChildElement('label') node.setTextPos( node.mapFromScene(QtCore.QPointF(int(labelElement.attribute('x')), int(labelElement.attribute('y'))))) return node diff --git a/eddy/core/owl.py b/eddy/core/owl.py index ccdf6bc6..76f614bb 100644 --- a/eddy/core/owl.py +++ b/eddy/core/owl.py @@ -349,7 +349,7 @@ def __init__(self, namespace,suffix=None, functional=False, invFuctional=False, """ super().__init__(parent) if not IRI.isValidNamespace(namespace): - raise IllegalNamespaceError(namespace) + raise IllegalNamespaceError('The inserted string "{}" is not a legal namespace'.format(namespace)) self._namespace = str(namespace) self._suffix = suffix self._isFunctional = functional diff --git a/eddy/ui/iri.py b/eddy/ui/iri.py index 5c9a0410..522aa627 100644 --- a/eddy/ui/iri.py +++ b/eddy/ui/iri.py @@ -13,7 +13,8 @@ from eddy.core.common import HasWidgetSystem -from eddy.core.owl import IRI, IllegalNamespaceError, AnnotationAssertion, Facet, Literal, IllegalLiteralError +from eddy.core.owl import IRI, IllegalNamespaceError, AnnotationAssertion, Facet, Literal, IllegalLiteralError, \ + OWL2Datatype from eddy.core.functions.signals import connect from eddy.ui.fields import ComboBox, StringField, CheckBox @@ -975,8 +976,13 @@ def accept(self): lexForm = str(self.widget('lexical_form_area').toPlainText()) if not lexForm: raise RuntimeError('Please insert a constraining value') - currDataType = str(self.widget('datatype_switch').currentText()) - literal = Literal(lexForm, self.project.getIRI(currDataType)) + currDataTypeStr = str(self.widget('datatype_switch').currentText()) + currDataType = None + if currDataTypeStr==self.emptyString: + currDataType = OWL2Datatype.PlainLiteral.value + else: + currDataType = self.project.getIRI(currDataTypeStr) + literal = Literal(lexForm, currDataType) facet = Facet(self.project.getIRI(currConstrFacet), literal) if self.facet: command = CommandChangeFacetOfNode(self.project, self.node, facet, self.facet) diff --git a/eddy/ui/session.py b/eddy/ui/session.py index f892e611..a5635b6f 100644 --- a/eddy/ui/session.py +++ b/eddy/ui/session.py @@ -855,7 +855,7 @@ def initActions(self): triggered=self.doOpenIRIPropsBuilder)) self.addAction(QtWidgets.QAction( - QtGui.QIcon(':/icons/24/ic_label_outline_black'), + QtGui.QIcon(':/icons/24/ic_create_black'), 'Annotations', self, objectName='iri_annotations_refactor', triggered=self.doOpenIRIPropsAnnotationBuilder))