diff --git a/eddy/plugins/ontology-importer/ontology_importer.py b/eddy/plugins/ontology-importer/ontology_importer.py index 92bf9332..9fd53749 100644 --- a/eddy/plugins/ontology-importer/ontology_importer.py +++ b/eddy/plugins/ontology-importer/ontology_importer.py @@ -46,18 +46,20 @@ from eddy.core.commands.common import CommandItemsRemove from eddy.core.commands.diagram import CommandDiagramResize, CommandDiagramAdd -from eddy.core.commands.edges import CommandEdgeAdd, CommandEdgeBreakpointAdd +from eddy.core.commands.edges import CommandEdgeAdd, CommandEdgeBreakpointAdd, \ + CommandEdgeBreakpointMove, CommandEdgeBreakpointRemove from eddy.core.commands.iri import CommandChangeIRIOfNode from eddy.core.commands.iri import CommandIRIAddAnnotationAssertion -from eddy.core.commands.nodes import CommandNodeAdd +from eddy.core.commands.nodes import CommandNodeAdd, CommandNodeSetDepth from eddy.core.commands.project import CommandProjectAddAnnotationProperty, CommandProjectAddPrefix from eddy.core.common import HasWidgetSystem from eddy.core.datatypes.graphol import Item +from eddy.core.datatypes.misc import DiagramMode from eddy.core.datatypes.qt import Font from eddy.core.datatypes.system import File from eddy.core.diagram import Diagram from eddy.core.functions.fsystem import fremove -from eddy.core.functions.misc import snapF +from eddy.core.functions.misc import snapF, first from eddy.core.functions.path import expandPath from eddy.core.functions.signals import connect, disconnect from eddy.core.items.nodes.attribute import AttributeNode @@ -216,7 +218,8 @@ def printISA(self, source_iri, target_iri, diagram): self.session.undostack.push(CommandEdgeAdd(diagram, isa)) if source_node.pos().x() != target_node.pos().x(): - y = source_node.pos().y() + (target_node.pos().y() - source_node.pos().y())/2 + #y = source_node.pos().y() + (target_node.pos().y() - source_node.pos().y())/2 + y = target_node.pos().y() + 40 bp1 = QtCore.QPointF(source_node.pos().x(), y) b1 = CommandEdgeBreakpointAdd(diagram, isa, 0, bp1) @@ -2557,11 +2560,13 @@ def drawAxioms(self, dict): # draw on the activeOne diag = self.session.mdi.activeDiagram() if diag: - n = self.draw(axiom, diag) + res = self.draw(axiom, diag) + n = res[0] else: project_diagrams = list(self.project.diagrams()) diag = project_diagrams[0] - n = self.draw(axiom, diag) + res = self.draw(axiom, diag) + n = res[0] if len(diagrams) == 1: # if only one diagram involved: @@ -2572,7 +2577,8 @@ def drawAxioms(self, dict): if d.name == diag: diagram = d break - n = self.draw(axiom, diagram) + res = self.draw(axiom, diagram) + n = res[0] if len(diagrams) > 1: # if more than one diagram involved: @@ -2581,7 +2587,8 @@ def drawAxioms(self, dict): if diag: if diag.name in diagrams: - n = self.draw(axiom, diag) + res = self.draw(axiom, diag) + n = res[0] # else draw on any of the involved ones else: diag = diagrams[0] @@ -2590,7 +2597,8 @@ def drawAxioms(self, dict): if d.name == diag: diagram = d break - n = self.draw(axiom, diagram) + res = self.draw(axiom, diagram) + n = res[0] # snap to grid # self.session.doSnapTopGrid() @@ -2684,20 +2692,22 @@ def drawPropertyExpression(self, axiom, diagram, x, y): propNode = self.findNode(propIRI, diagram) if self.findNode(propIRI, diagram) != 'null' else self.createNode(prop, diagram, x, y) else: - propNode = self.draw(prop, diagram, x, y) + res = self.draw(prop, diagram, x, y) + propNode = res[0] edges = propNode.edges inputEdges = [e for e in edges if e.type() is Item.InputEdge] for e in inputEdges: if e.target.type() is Item.RoleInverseNode: - return e.target + return [e.target] + inv = RoleInverseNode(diagram=diagram) - x = propNode.pos().x()+150 + x = propNode.pos().x() + propNode.width() + 50 y = propNode.pos().y() starting_y = y while not self.isEmpty(x, y, diagram): - y = y - 30 + y = y - 50 if abs(starting_y - y) >1000: y = starting_y break @@ -2710,7 +2720,19 @@ def drawPropertyExpression(self, axiom, diagram, x, y): inv.addEdge(input) self.session.undostack.push(CommandEdgeAdd(diagram, input)) - return inv + if propNode.pos().y() != inv.pos().y(): + + x = propNode.pos().x() + 68 + y1 = propNode.pos().y() + y2 = inv.pos().y() + + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp2)) + + return [inv] def drawDatatypeRestriction(self, datatype, facets, diagram, x, y): @@ -2729,7 +2751,7 @@ def drawDatatypeRestriction(self, datatype, facets, diagram, x, y): dataNode = DatatypeRestrictionNode(diagram=diagram) starting_y = y while not self.isEmpty(x, y, diagram): - y = y - 30 + y = y - 50 if abs(starting_y - y) > 1000: y = starting_y break @@ -2737,10 +2759,11 @@ def drawDatatypeRestriction(self, datatype, facets, diagram, x, y): self.session.undostack.push(CommandNodeAdd(diagram, dataNode)) if not self.isAtomic(datatype): - dNode = self.draw(datatype, x+150, y) + res = self.draw(datatype, x+180, y) + dNode = res[0] else: - dNode = self.createNode(datatype, diagram, x+150, y) + dNode = self.createNode(datatype, diagram, x+180, y) input = diagram.factory.create(Item.InputEdge, source=dNode, target=dataNode) dNode.addEdge(input) @@ -2763,11 +2786,12 @@ def drawDatatypeRestriction(self, datatype, facets, diagram, x, y): fNode = FacetNode(facet=facet, diagram=diagram) - x = x +150 - y = y + 150 + x = x + 180 + y = y + 125 starting_y = y while not self.isEmpty(x, y, diagram): - y = y - 30 + y = y - 50 + if abs(starting_y - y) > 1000: y = starting_y break @@ -2780,7 +2804,13 @@ def drawDatatypeRestriction(self, datatype, facets, diagram, x, y): dataNode.addEdge(inp) self.session.undostack.push(CommandEdgeAdd(diagram, inp)) - return dataNode + x1 = fNode.pos().x() + y1 = dataNode.pos().y() + + bp = QtCore.QPointF(x1, y1) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, inp, 0, bp)) + + return [dataNode] def drawExpression(self, ex, diagram, x, y): @@ -2817,27 +2847,41 @@ def drawExpression(self, ex, diagram, x, y): n = self.drawObjIntersectionOf(operands, diagram, x, y) return n - if ex_type == 'ObjectSomeValuesFrom' or ex_type == 'DataSomeValuesFrom': + if ex_type == 'ObjectSomeValuesFrom': property = ex.getProperty() ce = ex.getFiller() n = self.drawObjSomeValuesFrom(property, ce, diagram, x, y) return n - if ex_type == 'ObjectAllValuesFrom' or ex_type == 'DataAllValuesFrom': + if ex_type == 'DataSomeValuesFrom': + + property = ex.getProperty() + ce = ex.getFiller() + n = self.drawDataSomeValuesFrom(property, ce, diagram, x, y) + return n + + if ex_type == 'ObjectAllValuesFrom': property = ex.getProperty() ce = ex.getFiller() n = self.drawObjAllValuesFrom(property, ce, diagram, x, y) return n + if ex_type == 'DataAllValuesFrom': + + property = ex.getProperty() + ce = ex.getFiller() + n = self.drawDataAllValuesFrom(property, ce, diagram, x, y) + return n + if ex_type == 'ObjectComplementOf': operand = ex.getOperand() n = self.drawObjComplementOf(operand, diagram, x, y) return n - if ex_type == 'ObjectMinCardinality' or ex_type == 'DataMinCardinality': + if ex_type == 'ObjectMinCardinality': card = ex.getCardinality() property = ex.getProperty() @@ -2845,7 +2889,15 @@ def drawExpression(self, ex, diagram, x, y): n = self.drawObjMinCardinality(card, property, ce, diagram, x, y) return n - if ex_type == 'ObjectMaxCardinality' or ex_type == 'DataMaxCardinality': + if ex_type == 'DataMinCardinality': + + card = ex.getCardinality() + property = ex.getProperty() + ce = ex.getFiller() + n = self.drawDataMinCardinality(card, property, ce, diagram, x, y) + return n + + if ex_type == 'ObjectMaxCardinality': card = ex.getCardinality() property = ex.getProperty() @@ -2853,7 +2905,15 @@ def drawExpression(self, ex, diagram, x, y): n = self.drawObjMaxCardinality(card, property, ce, diagram, x, y) return n - if ex_type == 'ObjectExactCardinality' or ex_type == 'DataExactCardinality': + if ex_type == 'DataMaxCardinality': + + card = ex.getCardinality() + property = ex.getProperty() + ce = ex.getFiller() + n = self.drawDataMaxCardinality(card, property, ce, diagram, x, y) + return n + + if ex_type == 'ObjectExactCardinality': card = ex.getCardinality() property = ex.getProperty() @@ -2861,13 +2921,21 @@ def drawExpression(self, ex, diagram, x, y): n = self.drawObjExactCardinality(card, property, ce, diagram, x, y) return n + if ex_type == 'DataExactCardinality': + + card = ex.getCardinality() + property = ex.getProperty() + ce = ex.getFiller() + n = self.drawDataExactCardinality(card, property, ce, diagram, x, y) + return n + if ex_type == 'ObjectHasSelf': property = ex.getProperty() n = self.drawObjHasSelf(property, diagram, x, y) return n - if ex_type == 'ObjectHasValue' or ex_type == 'DataHasValue': + if ex_type == 'ObjectHasValue': ex = ex.asSomeValuesFrom() property = ex.getProperty() @@ -2875,6 +2943,14 @@ def drawExpression(self, ex, diagram, x, y): n = self.drawObjSomeValuesFrom(property, ce, diagram, x, y) return n + if ex_type == 'DataHasValue': + + ex = ex.asSomeValuesFrom() + property = ex.getProperty() + ce = ex.getFiller() + n = self.drawDataSomeValuesFrom(property, ce, diagram, x, y) + return n + def drawAxiom(self, axiom, diagram, x, y): QtCore.QCoreApplication.processEvents() if isinstance(axiom, self.Axiom): @@ -3094,18 +3170,32 @@ def drawAxiom(self, axiom, diagram, x, y): return n - if ax_type == 'DataPropertyDomain' or ax_type == 'ObjectPropertyDomain': + if ax_type == 'DataPropertyDomain': + + domain = axiom.getDomain() + property = axiom.getProperty() + n = self.drawDataPropertyDomain(property, domain, diagram, x, y) + return n + + if ax_type == 'ObjectPropertyDomain': domain = axiom.getDomain() property = axiom.getProperty() - n = self.drawPropertyDomain(property, domain, diagram, x, y) + n = self.drawObjPropertyDomain(property, domain, diagram, x, y) + return n + + if ax_type == 'DataPropertyRange': + + range = axiom.getRange() + property = axiom.getProperty() + n = self.drawDataPropertyRange(property, range, diagram, x, y) return n - if ax_type == 'DataPropertyRange' or ax_type == 'ObjectPropertyRange': + if ax_type == 'ObjectPropertyRange': range = axiom.getRange() property = axiom.getProperty() - n = self.drawPropertyRange(property, range, diagram, x, y) + n = self.drawObjPropertyRange(property, range, diagram, x, y) return n if ax_type == 'SubPropertyChainOf': @@ -3113,7 +3203,7 @@ def drawAxiom(self, axiom, diagram, x, y): chain = axiom.getPropertyChain() property = axiom.getSuperProperty() - n = self.drawChain(chain, property, diagram, x, y) + n = self.drawChain(chain, property, diagram, x, y)[0] return n if ax_type == 'SubClassOf': @@ -3124,6 +3214,7 @@ def drawAxiom(self, axiom, diagram, x, y): subDrawn = False supDrawn = False found = None + propNode = None if self.isAtomic(sub): @@ -3176,7 +3267,7 @@ def drawAxiom(self, axiom, diagram, x, y): else: x = supNode.pos().x() - y = supNode.pos().y() + 150 + y = supNode.pos().y() if self.isAtomic(sub): subNode = self.createNode(sub, diagram, x, y) @@ -3184,7 +3275,12 @@ def drawAxiom(self, axiom, diagram, x, y): else: - subNode = self.draw(sub, diagram, x, y) + res = self.draw(sub, diagram, x, y) + if len(res) > 1: + subNode = res[0] + propNode = res[1] + else: + subNode = res[0] subDrawn = True cl = supNode @@ -3230,7 +3326,7 @@ def drawAxiom(self, axiom, diagram, x, y): if subDrawn: x = subNode.pos().x() - y = subNode.pos().y() - 150 + y = subNode.pos().y() if self.isAtomic(sup): supNode = self.createNode(sup, diagram, x, y) @@ -3238,7 +3334,12 @@ def drawAxiom(self, axiom, diagram, x, y): else: - supNode = self.draw(sup, diagram, x, y) + res = self.draw(sup, diagram, x, y) + if len(res) > 1: + supNode = res[0] + propNode = res[1] + else: + supNode = res[0] supDrawn = True cl = subNode @@ -3289,11 +3390,16 @@ def drawAxiom(self, axiom, diagram, x, y): else: - supNode = self.draw(sup, diagram, x, y) + res = self.draw(sup, diagram, x, y) + if len(res) > 1: + supNode = res[0] + propNode = res[1] + else: + supNode = res[0] supDrawn = True x = supNode.pos().x() - y = supNode.pos().y() + 150 + y = supNode.pos().y() if self.isAtomic(sub): subNode = self.createNode(sub, diagram, x, y) @@ -3301,7 +3407,12 @@ def drawAxiom(self, axiom, diagram, x, y): else: - subNode = self.draw(sub, diagram, x, y) + res = self.draw(sub, diagram, x, y) + if len(res) > 1: + subNode = res[0] + propNode = res[1] + else: + subNode = res[0] subDrawn = True if found: @@ -3313,21 +3424,38 @@ def drawAxiom(self, axiom, diagram, x, y): for e in found.edges: if e.type() is Item.InclusionEdge: if e.source is supNode: + breakpoints = e.breakpoints self.session.undostack.push(CommandItemsRemove(diagram, [e])) isa = diagram.factory.create(Item.EquivalenceEdge, - source=found, + source=subNode, target=supNode) found.addEdge(isa) supNode.addEdge(isa) self.session.undostack.push(CommandEdgeAdd(diagram, isa)) + i = 0 + breakpoints.reverse() + for b in breakpoints: + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, i, b)) + i = i +1 + elif e.target is supNode: isa = e else: isa = diagram.factory.create(Item.InclusionEdge, source=subNode, target=supNode) self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - return isa + if propNode: + bps = self.addBreakpoints(diagram, propNode, supNode, subNode, None) + bps.reverse() + + i = len(isa.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, isa, i, b)) + i = i + 1 + + return [isa] # DRAW CLASS EXPRESSIONS # @@ -3340,7 +3468,8 @@ def drawObjHasSelf(self, property, diagram, x, y): else: - propNode = self.draw(property, diagram) + res = self.draw(property, diagram, x, y+125) + propNode = res[0] if propNode.type() == Item.RoleInverseNode: @@ -3357,7 +3486,9 @@ def drawObjHasSelf(self, property, diagram, x, y): n = DomainRestrictionNode(diagram=diagram) n.setText('self') - n.setPos(propNode.pos().x()+50, propNode.pos().y() +50) + + pos = self.restrictionPos(n, propNode, diagram) + n.setPos(pos) self.session.undostack.push(CommandNodeAdd(diagram, n)) input = diagram.factory.create(Item.InputEdge, source=propNode, target=n) @@ -3366,9 +3497,9 @@ def drawObjHasSelf(self, property, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, input)) - return n + return [n, propNode] - def drawObjMinCardinality(self, card, property, ce, diagram, x, y): + def drawDataMinCardinality(self, card, property, ce, diagram, x, y): propDrawn = False ceDrawn = False @@ -3378,9 +3509,11 @@ def drawObjMinCardinality(self, card, property, ce, diagram, x, y): propIri = property.getIRI() propNode = self.findNode(propIri, diagram) if propNode != 'null': + propDrawn = True if self.isAtomic(ce): + ceIri = ce.getIRI() isLiteral = False if str(ceIri) == 'rdfs:Literal': @@ -3394,10 +3527,9 @@ def drawObjMinCardinality(self, card, property, ce, diagram, x, y): if propDrawn: if ceDrawn: - if self.isIsolated(ceNode): - x_tomove = propNode.pos().x() + 200 + x_tomove = propNode.pos().x() - 180 y_tomove = propNode.pos().y() while not self.isEmpty(x_tomove, y_tomove, diagram): @@ -3410,68 +3542,82 @@ def drawObjMinCardinality(self, card, property, ce, diagram, x, y): pass else: + if self.isAtomic(ce): if not ce.isTopEntity() and not isLiteral: - x = propNode.pos().x() + 200 + + x = propNode.pos().x() - 180 y = propNode.pos().y() ceNode = self.createNode(ce, diagram, x, y) ceDrawn = True else: - x = propNode.pos().x() + 200 + x = propNode.pos().x() -180 y = propNode.pos().y() - - ceNode = self.draw(ce, diagram, x, y) + res = self.draw(ce, diagram, x, y) + ceNode = res[0] ceDrawn = True else: if ceDrawn: + if self.isIsolated(ceNode): + ceNode.setPos(x, y) + if self.isAtomic(property): - x = ceNode.pos().x() - 200 + x = ceNode.pos().x() + 180 y = ceNode.pos().y() propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - x = ceNode.pos().x() - 200 + + x = ceNode.pos().x() + 180 y = ceNode.pos().y() - propNode = self.draw(property, diagram, x, y) + + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True else: if self.isAtomic(ce): if not ce.isTopEntity() and not isLiteral: + x = x y = y ceNode = self.createNode(ce, diagram, x, y) ceDrawn = True else: - ceNode = self.draw(ce, diagram, x, y) + res = self.draw(ce, diagram, x, y) + ceNode = res[0] ceDrawn = True - x = x - 100 - y = y + #x = x - 100 + #y = y if ceDrawn: - x = ceNode.pos().x() - 200 + x = ceNode.pos().x() + 180 y = ceNode.pos().y() + else: + x = x -180 + y = y if self.isAtomic(property): propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True if ceDrawn and propDrawn: - offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 70, Diagram.GridSize), snapF(+propNode.height() / 2 + 70, Diagram.GridSize)) + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 50, Diagram.GridSize), snapF(+propNode.height() / 2 + 50, Diagram.GridSize)) pos = ceNode.pos() + offset while not self.isEmpty(pos.x(), pos.y(), diagram): - diff = QtCore.QPointF(0, snapF(+70, Diagram.GridSize)) + diff = QtCore.QPointF(0, snapF(+50, Diagram.GridSize)) pos = pos + diff if abs(pos.y() - ceNode.pos().y()) > 1000: break @@ -3493,7 +3639,7 @@ def drawObjMinCardinality(self, card, property, ce, diagram, x, y): n = DomainRestrictionNode(diagram=diagram) card = str(card) - n.setText('('+card+' , -)') + n.setText('(' + card + ' , -)') pos = self.restrictionPos(n, propNode, diagram) n.setPos(pos) @@ -3512,9 +3658,18 @@ def drawObjMinCardinality(self, card, property, ce, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, input2)) - return n + bps = self.addBreakpoints(diagram, propNode, n, ceNode, None) + bps.reverse() - def drawObjMaxCardinality(self, card, property, ce, diagram, x, y): + i = len(input2.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, input2, i, b)) + i = i + 1 + + return [n, propNode] + + def drawObjMinCardinality(self, card, property, ce, diagram, x, y): propDrawn = False ceDrawn = False @@ -3527,9 +3682,11 @@ def drawObjMaxCardinality(self, card, property, ce, diagram, x, y): propDrawn = True if self.isAtomic(ce): + ceIri = ce.getIRI() isLiteral = False if str(ceIri) == 'rdfs:Literal': + isLiteral = True if not ce.isTopEntity() and not isLiteral: @@ -3542,7 +3699,7 @@ def drawObjMaxCardinality(self, card, property, ce, diagram, x, y): if ceDrawn: if self.isIsolated(ceNode): - x_tomove = propNode.pos().x() + 200 + x_tomove = propNode.pos().x() - 180 y_tomove = propNode.pos().y() while not self.isEmpty(x_tomove, y_tomove, diagram): @@ -3555,17 +3712,20 @@ def drawObjMaxCardinality(self, card, property, ce, diagram, x, y): pass else: + # DRAW CE if self.isAtomic(ce): if not ce.isTopEntity() and not isLiteral: - x = propNode.pos().x() + 200 + + x = propNode.pos().x() -180 y = propNode.pos().y() ceNode = self.createNode(ce, diagram, x, y) ceDrawn = True else: - x = propNode.pos().x() + 200 + x = propNode.pos().x() -180 y = propNode.pos().y() - ceNode = self.draw(ce, diagram, x, y) + res = self.draw(ce, diagram, x, y) + ceNode = res[0] ceDrawn = True else: @@ -3573,47 +3733,53 @@ def drawObjMaxCardinality(self, card, property, ce, diagram, x, y): if ceDrawn: if self.isIsolated(ceNode): - ceNode.setPos(x, y) + ceNode.setPos(x - 180, y) if self.isAtomic(property): - x = ceNode.pos().x() - 200 - y = ceNode.pos().y() + x = x + y = y + 125 propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - x = ceNode.pos().x() - 200 - y = ceNode.pos().y() - propNode = self.draw(property, diagram, x, y) + + x = x + y = y + 125 + + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True else: if self.isAtomic(ce): if not ce.isTopEntity() and not isLiteral: - x = x + + x = x + 180 y = y ceNode = self.createNode(ce, diagram, x, y) ceDrawn = True else: - ceNode = self.draw(ce, diagram, x, y) + res = self.draw(ce, diagram, x, y) + ceNode = res[0] ceDrawn = True - x = x - 100 - y = y + if ceDrawn: - x = ceNode.pos().x() - 200 - y = ceNode.pos().y() + x = x + y = y + 125 + if self.isAtomic(property): propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True - + ''' if ceDrawn and propDrawn: offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 70, Diagram.GridSize), snapF(+propNode.height() / 2 + 70, Diagram.GridSize)) pos = ceNode.pos() + offset @@ -3625,13 +3791,14 @@ def drawObjMaxCardinality(self, card, property, ce, diagram, x, y): break propNode.setPos(pos) - + ''' if propNode.type() == Item.RoleInverseNode: edges = propNode.edges inputEdges = [e for e in edges if e.type() is Item.InputEdge] for e in inputEdges: if e.source.type() is Item.RoleNode: + self.session.undostack.push(CommandItemsRemove(diagram, [propNode, e])) propNode = e.source n = RangeRestrictionNode(diagram=diagram) @@ -3641,7 +3808,7 @@ def drawObjMaxCardinality(self, card, property, ce, diagram, x, y): n = DomainRestrictionNode(diagram=diagram) card = str(card) - n.setText('(- , '+card+')') + n.setText('(' + card + ' , -)') pos = self.restrictionPos(n, propNode, diagram) n.setPos(pos) @@ -3660,9 +3827,18 @@ def drawObjMaxCardinality(self, card, property, ce, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, input2)) - return n + bps = self.addBreakpoints(diagram, propNode, n, ceNode, None) + bps.reverse() - def drawObjExactCardinality(self, card, property, ce, diagram, x, y): + i = len(input2.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, input2, i, b)) + i = i + 1 + + return [n, propNode] + + def drawDataMaxCardinality(self, card, property, ce, diagram, x, y): propDrawn = False ceDrawn = False @@ -3672,9 +3848,11 @@ def drawObjExactCardinality(self, card, property, ce, diagram, x, y): propIri = property.getIRI() propNode = self.findNode(propIri, diagram) if propNode != 'null': + propDrawn = True if self.isAtomic(ce): + ceIri = ce.getIRI() isLiteral = False if str(ceIri) == 'rdfs:Literal': @@ -3690,7 +3868,7 @@ def drawObjExactCardinality(self, card, property, ce, diagram, x, y): if ceDrawn: if self.isIsolated(ceNode): - x_tomove = propNode.pos().x() + 200 + x_tomove = propNode.pos().x() - 180 y_tomove = propNode.pos().y() while not self.isEmpty(x_tomove, y_tomove, diagram): @@ -3703,17 +3881,19 @@ def drawObjExactCardinality(self, card, property, ce, diagram, x, y): pass else: + if self.isAtomic(ce): if not ce.isTopEntity() and not isLiteral: - x = propNode.pos().x() + 200 + + x = propNode.pos().x() - 180 y = propNode.pos().y() ceNode = self.createNode(ce, diagram, x, y) ceDrawn = True else: - x = propNode.pos().x() + 200 + x = propNode.pos().x() -180 y = propNode.pos().y() - - ceNode = self.draw(ce, diagram, x, y) + res = self.draw(ce, diagram, x, y) + ceNode = res[0] ceDrawn = True else: @@ -3725,49 +3905,58 @@ def drawObjExactCardinality(self, card, property, ce, diagram, x, y): if self.isAtomic(property): - x = ceNode.pos().x() - 200 + x = ceNode.pos().x() + 180 y = ceNode.pos().y() propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - x = ceNode.pos().x() - 200 + + x = ceNode.pos().x() + 180 y = ceNode.pos().y() - propNode = self.draw(property, diagram, x, y) + + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True else: if self.isAtomic(ce): if not ce.isTopEntity() and not isLiteral: + x = x y = y ceNode = self.createNode(ce, diagram, x, y) ceDrawn = True else: - ceNode = self.draw(ce, diagram, x, y) + res = self.draw(ce, diagram, x, y) + ceNode = res[0] ceDrawn = True - x = x - 100 - y = y + #x = x - 100 + #y = y if ceDrawn: - x = ceNode.pos().x() - 200 + x = ceNode.pos().x() + 180 y = ceNode.pos().y() + else: + x = x -180 + y = y if self.isAtomic(property): propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True if ceDrawn and propDrawn: - offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 70, Diagram.GridSize), snapF(+propNode.height() / 2 + 70, Diagram.GridSize)) + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 50, Diagram.GridSize), snapF(+propNode.height() / 2 + 50, Diagram.GridSize)) pos = ceNode.pos() + offset while not self.isEmpty(pos.x(), pos.y(), diagram): - diff = QtCore.QPointF(0, snapF(+70, Diagram.GridSize)) + diff = QtCore.QPointF(0, snapF(+50, Diagram.GridSize)) pos = pos + diff if abs(pos.y() - ceNode.pos().y()) > 1000: break @@ -3789,7 +3978,7 @@ def drawObjExactCardinality(self, card, property, ce, diagram, x, y): n = DomainRestrictionNode(diagram=diagram) card = str(card) - n.setText('('+card+' , '+card+')') + n.setText('(- , ' + card + ')') pos = self.restrictionPos(n, propNode, diagram) n.setPos(pos) @@ -3808,50 +3997,18 @@ def drawObjExactCardinality(self, card, property, ce, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, input2)) - return n - - def drawObjComplementOf(self, operand, diagram, x, y): - - if self.isAtomic(operand): - - iri = operand.getIRI() - node = self.findNode(iri, diagram) if self.findNode(iri, diagram) !='null' else self.createNode(operand, diagram, x, y) - - else: - - node = self.draw(operand, diagram) - - notDrawn = False - edges = node.edges - inputEdges = [e for e in edges if e.type() is Item.InputEdge] - for e in inputEdges: - if e.target.type() is Item.ComplementNode: - notNode = e.target - notDrawn = True - - if not notDrawn: - - notNode = ComplementNode(diagram=diagram) - x = node.pos().x()+50 - y = node.pos().y() - starting_y = y - while not self.isEmpty(x, y, diagram): - y = y - 30 - if abs(starting_y - y) > 1000: - y = starting_y - break - notNode.setPos(x, y) - self.session.undostack.push(CommandNodeAdd(diagram, notNode)) - - input = diagram.factory.create(Item.InputEdge, source=node, target=notNode) - node.addEdge(input) - notNode.addEdge(input) + bps = self.addBreakpoints(diagram, propNode, n, ceNode, None) + bps.reverse() - self.session.undostack.push(CommandEdgeAdd(diagram, input)) + i = len(input2.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, input2, i, b)) + i = i + 1 - return notNode + return [n, propNode] - def drawObjSomeValuesFrom(self, property, ce, diagram, x, y): + def drawObjMaxCardinality(self, card, property, ce, diagram, x, y): propDrawn = False ceDrawn = False @@ -3881,7 +4038,7 @@ def drawObjSomeValuesFrom(self, property, ce, diagram, x, y): if ceDrawn: if self.isIsolated(ceNode): - x_tomove = propNode.pos().x() + 200 + x_tomove = propNode.pos().x() - 180 y_tomove = propNode.pos().y() while not self.isEmpty(x_tomove, y_tomove, diagram): @@ -3898,15 +4055,16 @@ def drawObjSomeValuesFrom(self, property, ce, diagram, x, y): if self.isAtomic(ce): if not ce.isTopEntity() and not isLiteral: - x = propNode.pos().x() + 200 + x = propNode.pos().x() -180 y = propNode.pos().y() ceNode = self.createNode(ce, diagram, x, y) ceDrawn = True else: - x = propNode.pos().x() + 200 + x = propNode.pos().x() -180 y = propNode.pos().y() - ceNode = self.draw(ce, diagram, x, y) + res = self.draw(ce, diagram, x, y) + ceNode = res[0] ceDrawn = True else: @@ -3914,20 +4072,21 @@ def drawObjSomeValuesFrom(self, property, ce, diagram, x, y): if ceDrawn: if self.isIsolated(ceNode): - ceNode.setPos(x, y) + ceNode.setPos(x - 180, y) if self.isAtomic(property): - x = ceNode.pos().x() - 200 - y = ceNode.pos().y() + x = x + y = y + 125 propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - x = ceNode.pos().x() - 200 - y = ceNode.pos().y() + x = x + y = y + 125 - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True else: @@ -3935,21 +4094,20 @@ def drawObjSomeValuesFrom(self, property, ce, diagram, x, y): if self.isAtomic(ce): if not ce.isTopEntity() and not isLiteral: - x = x + x = x + 180 y = y ceNode = self.createNode(ce, diagram, x, y) ceDrawn = True else: - ceNode = self.draw(ce, diagram, x, y) + res = self.draw(ce, diagram, x, y) + ceNode = res[0] ceDrawn = True - x = x - 100 - y = y if ceDrawn: - x = ceNode.pos().x() - 200 - y = ceNode.pos().y() + x = x + y = y + 125 if self.isAtomic(property): @@ -3957,9 +4115,10 @@ def drawObjSomeValuesFrom(self, property, ce, diagram, x, y): propDrawn = True else: - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True - + ''' if ceDrawn and propDrawn: offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 70, Diagram.GridSize), snapF(+propNode.height() / 2 + 70, Diagram.GridSize)) pos = ceNode.pos() + offset @@ -3971,7 +4130,7 @@ def drawObjSomeValuesFrom(self, property, ce, diagram, x, y): break propNode.setPos(pos) - + ''' if propNode.type() == Item.RoleInverseNode: edges = propNode.edges @@ -3987,6 +4146,9 @@ def drawObjSomeValuesFrom(self, property, ce, diagram, x, y): n = DomainRestrictionNode(diagram=diagram) + card = str(card) + n.setText('(- , ' + card + ')') + pos = self.restrictionPos(n, propNode, diagram) n.setPos(pos) self.session.undostack.push(CommandNodeAdd(diagram, n)) @@ -4004,9 +4166,18 @@ def drawObjSomeValuesFrom(self, property, ce, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, input2)) - return n + bps = self.addBreakpoints(diagram, propNode, n, ceNode, None) + bps.reverse() - def drawObjAllValuesFrom(self, property, ce, diagram, x, y): + i = len(input2.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, input2, i, b)) + i = i + 1 + + return [n, propNode] + + def drawDataExactCardinality(self, card, property, ce, diagram, x, y): propDrawn = False ceDrawn = False @@ -4036,7 +4207,7 @@ def drawObjAllValuesFrom(self, property, ce, diagram, x, y): if ceDrawn: if self.isIsolated(ceNode): - x_tomove = propNode.pos().x() + 200 + x_tomove = propNode.pos().x() - 180 y_tomove = propNode.pos().y() while not self.isEmpty(x_tomove, y_tomove, diagram): @@ -4053,14 +4224,15 @@ def drawObjAllValuesFrom(self, property, ce, diagram, x, y): if self.isAtomic(ce): if not ce.isTopEntity() and not isLiteral: - x = propNode.pos().x() + 200 + x = propNode.pos().x() - 180 y = propNode.pos().y() ceNode = self.createNode(ce, diagram, x, y) ceDrawn = True else: - x = propNode.pos().x() + 200 + x = propNode.pos().x() -180 y = propNode.pos().y() - ceNode = self.draw(ce, diagram, x, y) + res = self.draw(ce, diagram, x, y) + ceNode = res[0] ceDrawn = True else: @@ -4072,16 +4244,17 @@ def drawObjAllValuesFrom(self, property, ce, diagram, x, y): if self.isAtomic(property): - x = ceNode.pos().x() - 200 + x = ceNode.pos().x() + 180 y = ceNode.pos().y() propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - x = ceNode.pos().x() - 200 + x = ceNode.pos().x() + 180 y = ceNode.pos().y() - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True else: @@ -4095,29 +4268,34 @@ def drawObjAllValuesFrom(self, property, ce, diagram, x, y): ceDrawn = True else: - ceNode = self.draw(ce, diagram, x, y) + res = self.draw(ce, diagram, x, y) + ceNode = res[0] ceDrawn = True - x = x - 100 - y = y + #x = x - 100 + #y = y if ceDrawn: - x = ceNode.pos().x() - 200 + x = ceNode.pos().x() + 180 y = ceNode.pos().y() + else: + x = x -180 + y = y if self.isAtomic(property): propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True if ceDrawn and propDrawn: - offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 70, Diagram.GridSize), snapF(+propNode.height() / 2 + 70, Diagram.GridSize)) + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 50, Diagram.GridSize), snapF(+propNode.height() / 2 + 50, Diagram.GridSize)) pos = ceNode.pos() + offset while not self.isEmpty(pos.x(), pos.y(), diagram): - diff = QtCore.QPointF(0, snapF(+70, Diagram.GridSize)) + diff = QtCore.QPointF(0, snapF(+50, Diagram.GridSize)) pos = pos + diff if abs(pos.y() - ceNode.pos().y()) > 1000: break @@ -4138,7 +4316,8 @@ def drawObjAllValuesFrom(self, property, ce, diagram, x, y): n = DomainRestrictionNode(diagram=diagram) - n.setText('forall') + card = str(card) + n.setText('(' + card + ' , ' + card + ')') pos = self.restrictionPos(n, propNode, diagram) n.setPos(pos) @@ -4157,70 +4336,975 @@ def drawObjAllValuesFrom(self, property, ce, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, input2)) - return n - - def drawObjUnionOf(self, operands, diagram, x, y): + bps = self.addBreakpoints(diagram, propNode, n, ceNode, None) + bps.reverse() - nodes = [] - xPos = [] - yPos = [] + i = len(input2.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, input2, i, b)) + i = i + 1 - for e in operands: + return [n, propNode] - if self.isAtomic(e) and not isinstance(e, self.OWLLiteral): + def drawObjExactCardinality(self, card, property, ce, diagram, x, y): - iri = e.getIRI() - node = self.findNode(iri, diagram) - if node != 'null': + propDrawn = False + ceDrawn = False - nodes.append(node) - xPos.append(node.pos().x()) - yPos.append(node.pos().y()) + if self.isAtomic(property): - if len(nodes) == 0: + propIri = property.getIRI() + propNode = self.findNode(propIri, diagram) + if propNode != 'null': + propDrawn = True - starting_x = x - 150 - starting_y = y + if self.isAtomic(ce): - if len(nodes) > 0: + ceIri = ce.getIRI() + isLiteral = False + if str(ceIri) == 'rdfs:Literal': - starting_x = min(xPos) - starting_y = min(yPos) + isLiteral = True + if not ce.isTopEntity() and not isLiteral: - for op in operands: + ceNode = self.findNode(ceIri, diagram) + if ceNode != 'null': + ceDrawn = True - if self.isAtomic(op): + if propDrawn: - nIri = op.getIRI() - if self.findNode(nIri, diagram) == 'null': - x = starting_x + 150 - y = starting_y + if ceDrawn: + if self.isIsolated(ceNode): - starting_x = x - starting_y = y + x_tomove = propNode.pos().x() - 180 + y_tomove = propNode.pos().y() + while not self.isEmpty(x_tomove, y_tomove, diagram): - n = self.createNode(op, diagram, x, y) + y_tomove = y_tomove + 70 + if abs(propNode.pos().y() - y_tomove) > 1000: + y_tomove = propNode.pos().y() + break + ceNode.setPos(x_tomove, y_tomove) + else: + pass - nodes.append(n) - xPos.append(n.pos().x()) - yPos.append(n.pos().y()) else: - x = starting_x + 150 - y = starting_y - - starting_x = x - starting_y = y + # DRAW CE + if self.isAtomic(ce): + if not ce.isTopEntity() and not isLiteral: - n = self.draw(op, diagram, x, y) - nodes.append(n) + x = propNode.pos().x() -180 + y = propNode.pos().y() + ceNode = self.createNode(ce, diagram, x, y) + ceDrawn = True + else: + x = propNode.pos().x() -180 + y = propNode.pos().y() + + res = self.draw(ce, diagram, x, y) + ceNode = res[0] + ceDrawn = True + + else: + + if ceDrawn: + + if self.isIsolated(ceNode): + ceNode.setPos(x - 180, y) + + if self.isAtomic(property): + + x = x + y = y + 125 + propNode = self.createNode(property, diagram, x, y) + propDrawn = True + else: + + x = x + y = y + 125 + + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True + + else: + + if self.isAtomic(ce): + if not ce.isTopEntity() and not isLiteral: + + x = x + 180 + y = y + ceNode = self.createNode(ce, diagram, x, y) + ceDrawn = True + else: + + res = self.draw(ce, diagram, x, y) + ceNode = res[0] + ceDrawn = True + + + if ceDrawn: + x = x + y = y + 125 + + if self.isAtomic(property): + + propNode = self.createNode(property, diagram, x, y) + propDrawn = True + else: + + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True + ''' + if ceDrawn and propDrawn: + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 70, Diagram.GridSize), snapF(+propNode.height() / 2 + 70, Diagram.GridSize)) + pos = ceNode.pos() + offset + + while not self.isEmpty(pos.x(), pos.y(), diagram): + diff = QtCore.QPointF(0, snapF(+70, Diagram.GridSize)) + pos = pos + diff + if abs(pos.y() - ceNode.pos().y()) > 1000: + break + + propNode.setPos(pos) + ''' + if propNode.type() == Item.RoleInverseNode: + + edges = propNode.edges + inputEdges = [e for e in edges if e.type() is Item.InputEdge] + for e in inputEdges: + if e.source.type() is Item.RoleNode: + + self.session.undostack.push(CommandItemsRemove(diagram, [propNode, e])) + propNode = e.source + n = RangeRestrictionNode(diagram=diagram) + + else: + + n = DomainRestrictionNode(diagram=diagram) + + card = str(card) + n.setText('(' + card + ' , ' + card + ')') + + pos = self.restrictionPos(n, propNode, diagram) + n.setPos(pos) + self.session.undostack.push(CommandNodeAdd(diagram, n)) + + input = diagram.factory.create(Item.InputEdge, source=propNode, target=n) + n.addEdge(input) + propNode.addEdge(input) + + self.session.undostack.push(CommandEdgeAdd(diagram, input)) + + if ceDrawn: + input2 = diagram.factory.create(Item.InputEdge, source=ceNode, target=n) + n.addEdge(input2) + ceNode.addEdge(input2) + + self.session.undostack.push(CommandEdgeAdd(diagram, input2)) + + bps = self.addBreakpoints(diagram, propNode, n, ceNode, None) + bps.reverse() + + i = len(input2.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, input2, i, b)) + i = i + 1 + + return [n, propNode] + + def drawObjComplementOf(self, operand, diagram, x, y): + + if self.isAtomic(operand): + + iri = operand.getIRI() + node = self.findNode(iri, diagram) if self.findNode(iri, diagram) !='null' else self.createNode(operand, diagram, x, y) + + else: + + res = self.draw(operand, diagram) + node = res[0] + + notDrawn = False + edges = node.edges + inputEdges = [e for e in edges if e.type() is Item.InputEdge] + for e in inputEdges: + if e.target.type() is Item.ComplementNode: + notNode = e.target + notDrawn = True + + if not notDrawn: + + notNode = ComplementNode(diagram=diagram) + x = node.pos().x()+70 + y = node.pos().y() + starting_y = y + while not self.isEmpty(x, y, diagram): + y = y - 50 + if abs(starting_y - y) > 1000: + y = starting_y + break + notNode.setPos(x, y) + self.session.undostack.push(CommandNodeAdd(diagram, notNode)) + + input = diagram.factory.create(Item.InputEdge, source=node, target=notNode) + node.addEdge(input) + notNode.addEdge(input) + + self.session.undostack.push(CommandEdgeAdd(diagram, input)) + + if notNode.pos().y() != node.pos().y(): + x1 = node.pos().x() + 60 + y1 = node.pos().y() + y2 = notNode.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x1, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp2)) + + return [notNode] + + def drawObjSomeValuesFrom(self, property, ce, diagram, x, y): + + propDrawn = False + ceDrawn = False + + if self.isAtomic(property): + + propIri = property.getIRI() + propNode = self.findNode(propIri, diagram) + if propNode != 'null': + propDrawn = True + + if self.isAtomic(ce): + + ceIri = ce.getIRI() + isLiteral = False + if str(ceIri) == 'rdfs:Literal': + + isLiteral = True + if not ce.isTopEntity() and not isLiteral: + + ceNode = self.findNode(ceIri, diagram) + if ceNode != 'null': + ceDrawn = True + + if propDrawn: + + if ceDrawn: + if self.isIsolated(ceNode): + + x_tomove = propNode.pos().x() - 180 + y_tomove = propNode.pos().y() + while not self.isEmpty(x_tomove, y_tomove, diagram): + + y_tomove = y_tomove + 70 + if abs(propNode.pos().y() - y_tomove) > 1000: + y_tomove = propNode.pos().y() + break + ceNode.setPos(x_tomove, y_tomove) + else: + pass + + else: + # DRAW CE + if self.isAtomic(ce): + if not ce.isTopEntity() and not isLiteral: + + x = propNode.pos().x() -180 + y = propNode.pos().y() + ceNode = self.createNode(ce, diagram, x, y) + ceDrawn = True + else: + x = propNode.pos().x() -180 + y = propNode.pos().y() + + res = self.draw(ce, diagram, x, y) + ceNode = res[0] + ceDrawn = True + + else: + + if ceDrawn: + + if self.isIsolated(ceNode): + ceNode.setPos(x - 180, y) + + if self.isAtomic(property): + + x = x + y = y + 125 + propNode = self.createNode(property, diagram, x, y) + propDrawn = True + else: + + x = x + y = y + 125 + + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True + + else: + + if self.isAtomic(ce): + if not ce.isTopEntity() and not isLiteral: + + x = x + 180 + y = y + ceNode = self.createNode(ce, diagram, x, y) + ceDrawn = True + else: + + res = self.draw(ce, diagram, x, y) + ceNode = res[0] + ceDrawn = True + + + if ceDrawn: + x = x + y = y + 125 + + if self.isAtomic(property): + + propNode = self.createNode(property, diagram, x, y) + propDrawn = True + else: + + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True + ''' + if ceDrawn and propDrawn: + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 70, Diagram.GridSize), snapF(+propNode.height() / 2 + 70, Diagram.GridSize)) + pos = ceNode.pos() + offset + + while not self.isEmpty(pos.x(), pos.y(), diagram): + diff = QtCore.QPointF(0, snapF(+70, Diagram.GridSize)) + pos = pos + diff + if abs(pos.y() - ceNode.pos().y()) > 1000: + break + + propNode.setPos(pos) + ''' + if propNode.type() == Item.RoleInverseNode: + + edges = propNode.edges + inputEdges = [e for e in edges if e.type() is Item.InputEdge] + for e in inputEdges: + if e.source.type() is Item.RoleNode: + + self.session.undostack.push(CommandItemsRemove(diagram, [propNode, e])) + propNode = e.source + n = RangeRestrictionNode(diagram=diagram) + + else: + + n = DomainRestrictionNode(diagram=diagram) + + pos = self.restrictionPos(n, propNode, diagram) + n.setPos(pos) + self.session.undostack.push(CommandNodeAdd(diagram, n)) + + input = diagram.factory.create(Item.InputEdge, source=propNode, target=n) + n.addEdge(input) + propNode.addEdge(input) + + self.session.undostack.push(CommandEdgeAdd(diagram, input)) + + if ceDrawn: + input2 = diagram.factory.create(Item.InputEdge, source=ceNode, target=n) + n.addEdge(input2) + ceNode.addEdge(input2) + + self.session.undostack.push(CommandEdgeAdd(diagram, input2)) + + bps = self.addBreakpoints(diagram, propNode, n, ceNode, None) + bps.reverse() + + i = len(input2.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, input2, i, b)) + i = i + 1 + + return [n, propNode] + + def drawDataSomeValuesFrom(self, property, ce, diagram, x, y): + + propDrawn = False + ceDrawn = False + + if self.isAtomic(property): + + propIri = property.getIRI() + propNode = self.findNode(propIri, diagram) + if propNode != 'null': + + propDrawn = True + + if self.isAtomic(ce): + + ceIri = ce.getIRI() + isLiteral = False + if str(ceIri) == 'rdfs:Literal': + isLiteral = True + if not ce.isTopEntity() and not isLiteral: + + ceNode = self.findNode(ceIri, diagram) + if ceNode != 'null': + ceDrawn = True + + if propDrawn: + + if ceDrawn: + if self.isIsolated(ceNode): + + x_tomove = propNode.pos().x() - 180 + y_tomove = propNode.pos().y() + while not self.isEmpty(x_tomove, y_tomove, diagram): + + y_tomove = y_tomove + 70 + if abs(propNode.pos().y() - y_tomove) > 1000: + y_tomove = propNode.pos().y() + break + ceNode.setPos(x_tomove, y_tomove) + else: + pass + + else: + + if self.isAtomic(ce): + if not ce.isTopEntity() and not isLiteral: + + x = propNode.pos().x() - 180 + y = propNode.pos().y() + ceNode = self.createNode(ce, diagram, x, y) + ceDrawn = True + else: + x = propNode.pos().x() - 180 + y = propNode.pos().y() + res = self.draw(ce, diagram, x, y) + ceNode = res[0] + ceDrawn = True + + else: + + if ceDrawn: + + if self.isIsolated(ceNode): + ceNode.setPos(x, y) + + if self.isAtomic(property): + + x = ceNode.pos().x() + 180 + y = ceNode.pos().y() + propNode = self.createNode(property, diagram, x, y) + propDrawn = True + else: + + x = ceNode.pos().x() + 180 + y = ceNode.pos().y() + + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True + + else: + + if self.isAtomic(ce): + if not ce.isTopEntity() and not isLiteral: + + x = x + y = y + ceNode = self.createNode(ce, diagram, x, y) + ceDrawn = True + else: + + res = self.draw(ce, diagram, x, y) + ceNode = res[0] + ceDrawn = True + + #x = x - 100 + #y = y + if ceDrawn: + x = ceNode.pos().x() + 180 + y = ceNode.pos().y() + else: + x = x -180 + y = y + if self.isAtomic(property): + + propNode = self.createNode(property, diagram, x, y) + propDrawn = True + else: + + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True + ''' + if ceDrawn and propDrawn: + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 50, Diagram.GridSize), snapF(+propNode.height() / 2 + 50, Diagram.GridSize)) + pos = ceNode.pos() + offset + + while not self.isEmpty(pos.x(), pos.y(), diagram): + diff = QtCore.QPointF(0, snapF(+50, Diagram.GridSize)) + pos = pos + diff + if abs(pos.y() - ceNode.pos().y()) > 1000: + break + + propNode.setPos(pos) + ''' + if propNode.type() == Item.RoleInverseNode: + + edges = propNode.edges + inputEdges = [e for e in edges if e.type() is Item.InputEdge] + for e in inputEdges: + if e.source.type() is Item.RoleNode: + self.session.undostack.push(CommandItemsRemove(diagram, [propNode, e])) + propNode = e.source + n = RangeRestrictionNode(diagram=diagram) + + else: + + n = DomainRestrictionNode(diagram=diagram) + + pos = self.restrictionPos(n, propNode, diagram) + n.setPos(pos) + self.session.undostack.push(CommandNodeAdd(diagram, n)) + + input = diagram.factory.create(Item.InputEdge, source=propNode, target=n) + n.addEdge(input) + propNode.addEdge(input) + + self.session.undostack.push(CommandEdgeAdd(diagram, input)) + + if ceDrawn: + input2 = diagram.factory.create(Item.InputEdge, source=ceNode, target=n) + n.addEdge(input2) + ceNode.addEdge(input2) + + self.session.undostack.push(CommandEdgeAdd(diagram, input2)) + + bps = self.addBreakpoints(diagram, propNode, n, ceNode, None) + bps.reverse() + + i = len(input2.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, input2, i, b)) + i = i + 1 + + return [n, propNode] + + def drawObjAllValuesFrom(self, property, ce, diagram, x, y): + + propDrawn = False + ceDrawn = False + + if self.isAtomic(property): + + propIri = property.getIRI() + propNode = self.findNode(propIri, diagram) + if propNode != 'null': + propDrawn = True + + if self.isAtomic(ce): + + ceIri = ce.getIRI() + isLiteral = False + if str(ceIri) == 'rdfs:Literal': + + isLiteral = True + if not ce.isTopEntity() and not isLiteral: + + ceNode = self.findNode(ceIri, diagram) + if ceNode != 'null': + ceDrawn = True + + if propDrawn: + + if ceDrawn: + if self.isIsolated(ceNode): + + x_tomove = propNode.pos().x() - 180 + y_tomove = propNode.pos().y() + while not self.isEmpty(x_tomove, y_tomove, diagram): + + y_tomove = y_tomove + 70 + if abs(propNode.pos().y() - y_tomove) > 1000: + y_tomove = propNode.pos().y() + break + ceNode.setPos(x_tomove, y_tomove) + else: + pass + + else: + # DRAW CE + if self.isAtomic(ce): + if not ce.isTopEntity() and not isLiteral: + + x = propNode.pos().x() -180 + y = propNode.pos().y() + ceNode = self.createNode(ce, diagram, x, y) + ceDrawn = True + else: + x = propNode.pos().x() -180 + y = propNode.pos().y() + + res = self.draw(ce, diagram, x, y) + ceNode = res[0] + ceDrawn = True + + else: + + if ceDrawn: + + if self.isIsolated(ceNode): + ceNode.setPos(x - 180, y) + + if self.isAtomic(property): + + x = x + y = y + 125 + propNode = self.createNode(property, diagram, x, y) + propDrawn = True + else: + + x = x + y = y + 125 + + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True + + else: + + if self.isAtomic(ce): + if not ce.isTopEntity() and not isLiteral: + + x = x + 180 + y = y + ceNode = self.createNode(ce, diagram, x, y) + ceDrawn = True + else: + + res = self.draw(ce, diagram, x, y) + ceNode = res[0] + ceDrawn = True + + + if ceDrawn: + x = x + y = y + 125 + + if self.isAtomic(property): + + propNode = self.createNode(property, diagram, x, y) + propDrawn = True + else: + + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True + ''' + if ceDrawn and propDrawn: + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 70, Diagram.GridSize), snapF(+propNode.height() / 2 + 70, Diagram.GridSize)) + pos = ceNode.pos() + offset + + while not self.isEmpty(pos.x(), pos.y(), diagram): + diff = QtCore.QPointF(0, snapF(+70, Diagram.GridSize)) + pos = pos + diff + if abs(pos.y() - ceNode.pos().y()) > 1000: + break + + propNode.setPos(pos) + ''' + if propNode.type() == Item.RoleInverseNode: + + edges = propNode.edges + inputEdges = [e for e in edges if e.type() is Item.InputEdge] + for e in inputEdges: + if e.source.type() is Item.RoleNode: + + self.session.undostack.push(CommandItemsRemove(diagram, [propNode, e])) + propNode = e.source + n = RangeRestrictionNode(diagram=diagram) + + else: + + n = DomainRestrictionNode(diagram=diagram) + + n.setText('forall') + + pos = self.restrictionPos(n, propNode, diagram) + n.setPos(pos) + self.session.undostack.push(CommandNodeAdd(diagram, n)) + + input = diagram.factory.create(Item.InputEdge, source=propNode, target=n) + n.addEdge(input) + propNode.addEdge(input) + + self.session.undostack.push(CommandEdgeAdd(diagram, input)) + + if ceDrawn: + input2 = diagram.factory.create(Item.InputEdge, source=ceNode, target=n) + n.addEdge(input2) + ceNode.addEdge(input2) + + self.session.undostack.push(CommandEdgeAdd(diagram, input2)) + + bps = self.addBreakpoints(diagram, propNode, n, ceNode, None) + bps.reverse() + + i = len(input2.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, input2, i, b)) + i = i + 1 + + return [n, propNode] + + def drawDataAllValuesFrom(self, property, ce, diagram, x, y): + + propDrawn = False + ceDrawn = False + + if self.isAtomic(property): + + propIri = property.getIRI() + propNode = self.findNode(propIri, diagram) + if propNode != 'null': + + propDrawn = True + + if self.isAtomic(ce): + + ceIri = ce.getIRI() + isLiteral = False + if str(ceIri) == 'rdfs:Literal': + isLiteral = True + if not ce.isTopEntity() and not isLiteral: + + ceNode = self.findNode(ceIri, diagram) + if ceNode != 'null': + ceDrawn = True + + if propDrawn: + + if ceDrawn: + if self.isIsolated(ceNode): + + x_tomove = propNode.pos().x() - 180 + y_tomove = propNode.pos().y() + while not self.isEmpty(x_tomove, y_tomove, diagram): + + y_tomove = y_tomove + 70 + if abs(propNode.pos().y() - y_tomove) > 1000: + y_tomove = propNode.pos().y() + break + ceNode.setPos(x_tomove, y_tomove) + else: + pass + + else: + + if self.isAtomic(ce): + if not ce.isTopEntity() and not isLiteral: + + x = propNode.pos().x() - 180 + y = propNode.pos().y() + ceNode = self.createNode(ce, diagram, x, y) + ceDrawn = True + else: + x = propNode.pos().x() -180 + y = propNode.pos().y() + res = self.draw(ce, diagram, x, y) + ceNode = res[0] + ceDrawn = True + + else: + + if ceDrawn: + + if self.isIsolated(ceNode): + ceNode.setPos(x, y) + + if self.isAtomic(property): + + x = ceNode.pos().x() + 180 + y = ceNode.pos().y() + propNode = self.createNode(property, diagram, x, y) + propDrawn = True + else: + + x = ceNode.pos().x() + 180 + y = ceNode.pos().y() + + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True + + else: + + if self.isAtomic(ce): + if not ce.isTopEntity() and not isLiteral: + + x = x + y = y + ceNode = self.createNode(ce, diagram, x, y) + ceDrawn = True + else: + + res = self.draw(ce, diagram, x, y) + ceNode = res[0] + ceDrawn = True + + #x = x - 100 + #y = y + if ceDrawn: + x = ceNode.pos().x() + 180 + y = ceNode.pos().y() + + else: + x = x -180 + y = y + if self.isAtomic(property): + + propNode = self.createNode(property, diagram, x, y) + propDrawn = True + else: + + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True + + if ceDrawn and propDrawn: + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 50, Diagram.GridSize), snapF(+propNode.height() / 2 + 50, Diagram.GridSize)) + pos = ceNode.pos() + offset + + while not self.isEmpty(pos.x(), pos.y(), diagram): + diff = QtCore.QPointF(0, snapF(+50, Diagram.GridSize)) + pos = pos + diff + if abs(pos.y() - ceNode.pos().y()) > 1000: + break + + propNode.setPos(pos) + + if propNode.type() == Item.RoleInverseNode: + + edges = propNode.edges + inputEdges = [e for e in edges if e.type() is Item.InputEdge] + for e in inputEdges: + if e.source.type() is Item.RoleNode: + self.session.undostack.push(CommandItemsRemove(diagram, [propNode, e])) + propNode = e.source + n = RangeRestrictionNode(diagram=diagram) + + else: + + n = DomainRestrictionNode(diagram=diagram) + + n.setText('forall') + + pos = self.restrictionPos(n, propNode, diagram) + n.setPos(pos) + self.session.undostack.push(CommandNodeAdd(diagram, n)) + + input = diagram.factory.create(Item.InputEdge, source=propNode, target=n) + n.addEdge(input) + propNode.addEdge(input) + + self.session.undostack.push(CommandEdgeAdd(diagram, input)) + + if ceDrawn: + input2 = diagram.factory.create(Item.InputEdge, source=ceNode, target=n) + n.addEdge(input2) + ceNode.addEdge(input2) + + self.session.undostack.push(CommandEdgeAdd(diagram, input2)) + + bps = self.addBreakpoints(diagram, propNode, n, ceNode, None) + bps.reverse() + + i = len(input2.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, input2, i, b)) + i = i + 1 + + return [n, propNode] + + def drawObjUnionOf(self, operands, diagram, x, y): + + nodes = [] + xPos = [] + yPos = [] + original_x = x + for e in operands: + + if self.isAtomic(e) and not isinstance(e, self.OWLLiteral): + + iri = e.getIRI() + node = self.findNode(iri, diagram) + if node != 'null': + + nodes.append(node) + xPos.append(node.pos().x()) + yPos.append(node.pos().y()) + + if len(nodes) == 0: + + starting_x = x - 150 + starting_y = y + + if len(nodes) > 0: + + starting_x = min(xPos) + starting_y = min(yPos) + + for op in operands: + + if self.isAtomic(op): + + nIri = op.getIRI() + if self.findNode(nIri, diagram) == 'null': + x = starting_x + 150 + y = starting_y + + starting_x = x + starting_y = y + + n = self.createNode(op, diagram, x, y) + + nodes.append(n) + xPos.append(n.pos().x()) + yPos.append(n.pos().y()) + else: + x = starting_x + 150 + y = starting_y + + starting_x = x + starting_y = y + + res = self.draw(op, diagram, x, y) + n = res[0] + nodes.append(n) xPos.append(n.pos().x()) yPos.append(n.pos().y()) - x_med = (max(xPos) + min(xPos)) / 2 - y_med = (max(yPos) + min(yPos)) / 2 - 100 + #x_med = (max(xPos) + min(xPos)) / 2 + x_med = original_x + 130 + #y_med = (max(yPos) + min(yPos)) / 2 - 100 + y_med = max(yPos) - 50 starting_y = y_med while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 + y_med = y_med - 50 if abs(starting_y - y_med) > 1000: y_med = starting_y break @@ -4235,26 +5319,66 @@ def drawObjUnionOf(self, operands, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, input)) - return union_node + if n.pos().x() != union_node.pos().x(): + + if n.pos().x() > union_node.pos().x(): + x1 = union_node.pos().x() + 60 + x3 = n.pos().x() - 70 + + else: + x1 = union_node.pos().x() - 60 + x3 = n.pos().x() + 70 + + y1 = union_node.pos().y() + x2 = x1 + y2 = union_node.pos().y() + 12 + y3 = y2 + x4 = x3 + y4 = n.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp4)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 2, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 3, bp1)) + + return [union_node] def drawDataUnionOf(self, operands, diagram, x, y): + x_med = x + 130 + # y_med = (max(yPos) + min(yPos)) / 2 - 100 + y_med = max(y) - 50 + starting_y = y_med + while not self.isEmpty(x_med, y_med, diagram): + y_med = y_med - 50 + if abs(starting_y - y_med) > 1000: + y_med = starting_y + break + union_node = UnionNode(diagram=diagram) + union_node.setPos(x_med, y_med) + self.session.undostack.push(CommandNodeAdd(diagram, union_node)) + nodes = [] xPos = [] yPos = [] - starting_x = x - 150 - starting_y = y + starting_x = union_node.pos().x() + 130 + starting_y = union_node.pos().y() for op in operands: if self.isAtomic(op): - x = starting_x + 150 + x = starting_x y = starting_y starting_x = x - starting_y = y + starting_y = y + 50 n = self.createNode(op, diagram, x, y) @@ -4263,28 +5387,18 @@ def drawDataUnionOf(self, operands, diagram, x, y): yPos.append(n.pos().y()) else: - x = starting_x + 150 + x = starting_x y = starting_y starting_x = x - starting_y = y + starting_y = y + 50 - n = self.draw(op, diagram, x, y) + res = self.draw(op, diagram, x, y) + n = res[0] nodes.append(n) xPos.append(n.pos().x()) yPos.append(n.pos().y()) - x_med = (max(xPos) + min(xPos)) / 2 - y_med = (max(yPos) + min(yPos)) / 2 - 100 - starting_y = y_med - while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 - if abs(starting_y - y_med) > 1000: - y_med = starting_y - break - union_node = UnionNode(diagram=diagram) - union_node.setPos(x_med, y_med) - self.session.undostack.push(CommandNodeAdd(diagram, union_node)) for n in nodes: input = diagram.factory.create(Item.InputEdge, source=n, target=union_node) @@ -4293,10 +5407,34 @@ def drawDataUnionOf(self, operands, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, input)) - return union_node + x = union_node.pos().x() + 60 + y2 = union_node.pos().y() + y1 = n.pos().y() + if y1 != y2: + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp2)) + + return [union_node] def drawObjOneOf(self, operands, diagram, x, y): + oneof_node = EnumerationNode(diagram=diagram) + one_x = x +120 + one_y = y +125 + + starting_y = one_y + while not self.isEmpty(one_x, one_y, diagram): + one_y = one_y + 50 + if abs(starting_y - one_y) > 1000: + one_y = starting_y + break + + oneof_node.setPos(one_x, one_y) + self.session.undostack.push(CommandNodeAdd(diagram, oneof_node)) + nodes = [] xPos = [] yPos = [] @@ -4323,6 +5461,9 @@ def drawObjOneOf(self, operands, diagram, x, y): starting_x = min(xPos) starting_y = min(yPos) + starting_x = oneof_node.pos().x() + 130 + starting_y = oneof_node.pos().y() + for op in operands: if self.isAtomic(op): @@ -4330,6 +5471,197 @@ def drawObjOneOf(self, operands, diagram, x, y): nIri = op.getIRI() if self.findNode(nIri, diagram) == 'null': + x = starting_x + y = starting_y + + starting_x = x + starting_y = y + 75 + + n = self.createNode(op, diagram, x, y) + + nodes.append(n) + xPos.append(n.pos().x()) + yPos.append(n.pos().y()) + + else: + + x = starting_x + 150 + y = starting_y + + starting_x = x + starting_y = y + + res = self.draw(op, diagram, x, y) + n = res[0] + nodes.append(n) + xPos.append(n.pos().x()) + yPos.append(n.pos().y()) + + + for n in nodes: + input = diagram.factory.create(Item.InputEdge, source=n, target=oneof_node) + n.addEdge(input) + oneof_node.addEdge(input) + + self.session.undostack.push(CommandEdgeAdd(diagram, input)) + + x = oneof_node.pos().x() + 60 + y2 = oneof_node.pos().y() + y1 = n.pos().y() + if y1 != y2: + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp2)) + + + return [oneof_node] + + def drawDataOneOf(self, operands, diagram, x, y): + + oneof_node = EnumerationNode(diagram=diagram) + one_x = x +120 + one_y = y +125 + + starting_y = one_y + while not self.isEmpty(one_x, one_y, diagram): + one_y = one_y + 50 + if abs(starting_y - one_y) > 1000: + one_y = starting_y + break + + oneof_node.setPos(one_x, one_y) + self.session.undostack.push(CommandNodeAdd(diagram, oneof_node)) + + nodes = [] + xPos = [] + yPos = [] + + for e in operands: + + if self.isAtomic(e) and not isinstance(e, self.OWLLiteral): + + iri = e.getIRI() + node = self.findNode(iri, diagram) + if node != 'null': + + nodes.append(node) + xPos.append(node.pos().x()) + yPos.append(node.pos().y()) + + if len(nodes) == 0: + + starting_x = x - 150 + starting_y = y + + if len(nodes) > 0: + + starting_x = min(xPos) + starting_y = min(yPos) + + starting_x = oneof_node.pos().x() + 130 + starting_y = oneof_node.pos().y() + + for op in operands: + + if isinstance(op, self.OWLLiteral): + + x = starting_x + y = starting_y + + starting_x = x + starting_y = y + 75 + + n = self.createNode(op, diagram, x, y) + + nodes.append(n) + xPos.append(n.pos().x()) + yPos.append(n.pos().y()) + + elif self.isAtomic(op): + + nIri = op.getIRI() + if self.findNode(nIri, diagram) == 'null': + + x = starting_x + y = starting_y + + starting_x = x + starting_y = y + 75 + + n = self.createNode(op, diagram, x, y) + + nodes.append(n) + xPos.append(n.pos().x()) + yPos.append(n.pos().y()) + + else: + + x = starting_x + 150 + y = starting_y + + starting_x = x + starting_y = y + + res = self.draw(op, diagram, x, y) + n = res[0] + nodes.append(n) + xPos.append(n.pos().x()) + yPos.append(n.pos().y()) + + + for n in nodes: + input = diagram.factory.create(Item.InputEdge, source=n, target=oneof_node) + n.addEdge(input) + oneof_node.addEdge(input) + + self.session.undostack.push(CommandEdgeAdd(diagram, input)) + + x = oneof_node.pos().x() + 60 + y2 = oneof_node.pos().y() + y1 = n.pos().y() + if y1 != y2: + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp2)) + + + return [oneof_node] + + def drawObjIntersectionOf(self, operands, diagram, x, y): + + nodes = [] + xPos = [] + yPos = [] + original_x = x + for e in operands: + + if self.isAtomic(e) and not isinstance(e, self.OWLLiteral): + + iri = e.getIRI() + node = self.findNode(iri, diagram) + if node != 'null': + nodes.append(node) + xPos.append(node.pos().x()) + yPos.append(node.pos().y()) + + if len(nodes) == 0: + starting_x = x - 150 + starting_y = y + + if len(nodes) > 0: + starting_x = min(xPos) + starting_y = min(yPos) + + for op in operands: + + if self.isAtomic(op): + + nIri = op.getIRI() + if self.findNode(nIri, diagram) == 'null': x = starting_x + 150 y = starting_y @@ -4341,418 +5673,660 @@ def drawObjOneOf(self, operands, diagram, x, y): nodes.append(n) xPos.append(n.pos().x()) yPos.append(n.pos().y()) - else: + x = starting_x + 150 + y = starting_y + + starting_x = x + starting_y = y + + res = self.draw(op, diagram, x, y) + n = res[0] + nodes.append(n) + xPos.append(n.pos().x()) + yPos.append(n.pos().y()) + + # x_med = (max(xPos) + min(xPos)) / 2 + x_med = original_x + 130 + # y_med = (max(yPos) + min(yPos)) / 2 - 100 + y_med = max(yPos) - 50 + starting_y = y_med + while not self.isEmpty(x_med, y_med, diagram): + y_med = y_med - 50 + if abs(starting_y - y_med) > 1000: + y_med = starting_y + break + intersect_node = IntersectionNode(diagram=diagram) + intersect_node.setPos(x_med, y_med) + self.session.undostack.push(CommandNodeAdd(diagram, intersect_node)) + + for n in nodes: + input = diagram.factory.create(Item.InputEdge, source=n, target=intersect_node) + n.addEdge(input) + intersect_node.addEdge(input) + + self.session.undostack.push(CommandEdgeAdd(diagram, input)) + + if n.pos().x() != intersect_node.pos().x(): + + if n.pos().x() > intersect_node.pos().x(): + x1 = intersect_node.pos().x() + 60 + x3 = n.pos().x() - 70 + + else: + x1 = intersect_node.pos().x() - 60 + x3 = n.pos().x() + 70 + + y1 = intersect_node.pos().y() + x2 = x1 + y2 = intersect_node.pos().y() + 12 + y3 = y2 + x4 = x3 + y4 = n.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp4)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 2, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 3, bp1)) + + + return [intersect_node] + + # DRAW AXIOMS # + + def drawHasKey(self, ce, keys, diagram, x, y): + + nodes = [] + x_positions = [] + y_positions = [] - x = starting_x + 150 - y = starting_y + for e in keys: - starting_x = x - starting_y = y + if self.isAtomic(e): - n = self.draw(op, diagram, x, y) - nodes.append(n) - xPos.append(n.pos().x()) - yPos.append(n.pos().y()) + iri = e.getIRI() + node = self.findNode(iri, diagram) + if node != 'null': + nodes.append(node) + x_positions.append(node.pos().x()) + y_positions.append(node.pos().y()) - x_med = (max(xPos) + min(xPos)) / 2 - y_med = (max(yPos) + min(yPos)) / 2 - 100 - starting_y = y_med - while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 - if abs(starting_y - y_med) > 1000: - y_med = starting_y - break - oneof_node = EnumerationNode(diagram=diagram) - oneof_node.setPos(x_med, y_med) - self.session.undostack.push(CommandNodeAdd(diagram, oneof_node)) + if len(nodes) == 0: - for n in nodes: - input = diagram.factory.create(Item.InputEdge, source=n, target=oneof_node) - n.addEdge(input) - oneof_node.addEdge(input) + starting_x = x - 150 + starting_y = y - self.session.undostack.push(CommandEdgeAdd(diagram, input)) + if self.isAtomic(ce): - return oneof_node + cIRI = ce.getIRI() + cNode = self.findNode(cIRI, diagram) - def drawDataOneOf(self, operands, diagram, x, y): + if cNode != 'null': + starting_x = cNode.pos().x() - (125 * len(keys)/2) + starting_y = cNode.pos().y() + 125 - nodes = [] - xPos = [] - yPos = [] - starting_x = x - 150 - starting_y = y + if len(nodes) > 0: + starting_x = min(x_positions) + starting_y = min(y_positions) - for op in operands: + for c in keys: - if self.isAtomic(op): + if not self.isAtomic(c): - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x starting_y = y - n = self.createNode(op, diagram, x, y) - + res = self.draw(c, diagram, x, y) + n = res[0] nodes.append(n) - xPos.append(n.pos().x()) - yPos.append(n.pos().y()) + + xN = n.pos().x() + x_positions.append(xN) + + yN = n.pos().y() + y_positions.append(yN) else: + if self.isAtomic(c): - x = starting_x + 150 - y = starting_y + iri = c.getIRI() + node = self.findNode(iri, diagram) - starting_x = x - starting_y = y + if node == 'null': - n = self.draw(op, diagram, x, y) - nodes.append(n) - xPos.append(n.pos().x()) - yPos.append(n.pos().y()) + x = starting_x + 125 + y = starting_y + + starting_x = x + starting_y = y + + node = self.createNode(c, diagram, x, y) + nodes.append(node) + + x = node.pos().x() + x_positions.append(x) + + y = node.pos().y() + y_positions.append(y) - x_med = (max(xPos) + min(xPos)) / 2 - y_med = (max(yPos) + min(yPos)) / 2 - 100 + # x_med = sum(x_positions) / len(x_positions) + maxX = max(x_positions) + minX = min(x_positions) + x_med = (maxX + minX) / 2 + # y_med = sum(y_positions) / len(y_positions) -100 + maxY = max(y_positions) + minY = min(y_positions) + y_med = (maxY + minY) / 2 starting_y = y_med while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 + y_med = y_med + 50 if abs(starting_y - y_med) > 1000: y_med = starting_y break - oneof_node = EnumerationNode(diagram=diagram) - oneof_node.setPos(x_med, y_med) - self.session.undostack.push(CommandNodeAdd(diagram, oneof_node)) + key_node = HasKeyNode(diagram=diagram) + key_node.setPos(x_med, y_med) + self.session.undostack.push(CommandNodeAdd(diagram, key_node)) for n in nodes: - input = diagram.factory.create(Item.InputEdge, source=n, target=oneof_node) + + input = diagram.factory.create(Item.InputEdge, source=n, target=key_node) n.addEdge(input) - oneof_node.addEdge(input) + key_node.addEdge(input) self.session.undostack.push(CommandEdgeAdd(diagram, input)) - return oneof_node + x = n.pos().x() + y = key_node.pos().y() + bp = QtCore.QPointF(x, y) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp)) - def drawObjIntersectionOf(self, operands, diagram, x, y): + if self.isAtomic(ce): + + cIri = ce.getIRI() + cNode = self.findNode(cIri, diagram) if self.findNode(cIri, diagram) != 'null' else self.createNode(ce, diagram, x_med, y_med-75) + + if self.isIsolated(cNode): + cNode.setPos(x_med, y_med-75) + + else: + + res = self.draw(ce, diagram) + cNode = res[0] + + in2 = diagram.factory.create(Item.InputEdge, source=cNode, target=key_node) + self.session.undostack.push(CommandEdgeAdd(diagram, in2)) + + return [key_node] + + def drawChain(self, chain, property, diagram, x, y): nodes = [] - xPos = [] - yPos = [] + x_positions = [] + y_positions = [] - for e in operands: + for e in chain: - if self.isAtomic(e) and not isinstance(e, self.OWLLiteral): + if self.isAtomic(e): iri = e.getIRI() node = self.findNode(iri, diagram) if node != 'null': - nodes.append(node) - xPos.append(node.pos().x()) - yPos.append(node.pos().y()) + x_positions.append(node.pos().x()) + y_positions.append(node.pos().y()) if len(nodes) == 0: - starting_x = x - 150 + starting_x = x - 125 starting_y = y + if self.isAtomic(property): - if len(nodes) > 0: - - starting_x = min(xPos) - starting_y = min(yPos) + cIRI = property.getIRI() + cNode = self.findNode(cIRI, diagram) - for op in operands: + if cNode != 'null': - if self.isAtomic(op): + starting_x = cNode.pos().x() - (125*len(chain)/2) + starting_y = cNode.pos().x() + 125 - nIri = op.getIRI() - if self.findNode(nIri, diagram) == 'null': - x = starting_x + 150 - y = starting_y + if len(nodes) > 0: - starting_x = x - starting_y = y + starting_x = min(x_positions) + starting_y = min(y_positions) - n = self.createNode(op, diagram, x, y) + for prop in chain: - nodes.append(n) - xPos.append(n.pos().x()) - yPos.append(n.pos().y()) + #if not prop.isType(self.EntityType.OBJECT_PROPERTY): + if not self.isAtomic(prop): - else: - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x starting_y = y - n = self.draw(op, diagram, x, y) + res = self.draw(prop, diagram, x, y) + n = res[0] nodes.append(n) - xPos.append(n.pos().x()) - yPos.append(n.pos().y()) - x_med = (max(xPos)+min(xPos)) / 2 - y_med = (max(yPos)+min(yPos)) / 2 - 100 + xN = n.pos().x() + x_positions.append(xN) + + yN = n.pos().y() + y_positions.append(yN) + + else: + + iri = prop.getIRI() + node = self.findNode(iri, diagram) + + if node == 'null': + + x = starting_x + 125 + y = starting_y + + starting_x = x + starting_y = y + + node = self.createNode(prop, diagram, x, y) + nodes.append(node) + + x = node.pos().x() + x_positions.append(x) + + y = node.pos().y() + y_positions.append(y) + + x_med = (max(x_positions) + min(x_positions)) / 2 + y_med = ((max(y_positions) + min(y_positions)) / 2) - 100 starting_y = y_med while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 + y_med = y_med + 50 if abs(starting_y - y_med) > 1000: y_med = starting_y break - intersect_node = IntersectionNode(diagram=diagram) - intersect_node.setPos(x_med, y_med) - self.session.undostack.push(CommandNodeAdd(diagram, intersect_node)) + chain_node = RoleChainNode(diagram=diagram) + chain_node.setPos(x_med, y_med) + self.session.undostack.push(CommandNodeAdd(diagram, chain_node)) for n in nodes: - input = diagram.factory.create(Item.InputEdge, source=n, target=intersect_node) + input = diagram.factory.create(Item.InputEdge, source=n, target=chain_node) n.addEdge(input) - intersect_node.addEdge(input) + chain_node.addEdge(input) self.session.undostack.push(CommandEdgeAdd(diagram, input)) - return intersect_node + x = n.pos().x() + y = chain_node.pos().y() + bp = QtCore.QPointF(x, y) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp)) - # DRAW AXIOMS # + if self.isAtomic(property): + pIri = property.getIRI() + pNode = self.findNode(pIri, diagram) if self.findNode(pIri, + diagram) != 'null' else self.createNode( + property, diagram, x_med, y_med - 75) - def drawHasKey(self, ce, keys, diagram, x, y): + else: + res = self.draw(property, diagram) + pNode = res[0] - nodes = [] - x_positions = [] - y_positions = [] + isa = diagram.factory.create(Item.InclusionEdge, source=chain_node, target=pNode) + self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - for e in keys: + return [chain_node] + + def drawObjPropertyRange(self, property, rang, diagram, x, y): + + propDrawn = False + domDrawn = False + + if self.isAtomic(property): + + iri = property.getIRI() + propNode = self.findNode(iri, diagram) + + if propNode != 'null': + propDrawn = True + + if self.isAtomic(rang) and not isinstance(rang, self.OWLLiteral): + + iri = rang.getIRI() + domainNode = self.findNode(iri, diagram) + + if domainNode != 'null': + domDrawn = True + + if propDrawn: + + if domDrawn: + + edges = propNode.edges + inputEdges = [e for e in edges if e.type() is Item.InputEdge] + for e in inputEdges: + if e.source is propNode and e.target.type() is Item.RangeRestrictionNode: + node = e.target + inputEdges = [e for e in node.edges if e.type() is Item.InputEdge] + if len(inputEdges) == 1: + for e in node.edges: + if e.target is domainNode or e.source is domainNode and e.type() is Item.EquivalenceEdge: + return [node] + elif e.target is domainNode and e.type() is Item.InclusionEdge: + return [node] + elif e.source is domainNode and e.type() is Item.InclusionEdge: + e_breakpoints = e.breakpoints + command = CommandItemsRemove(diagram, [e]) + self.session.undostack.push(command) + equiv = diagram.factory.create(Item.EquivalenceEdge, + source=node, + target=domainNode) + domainNode.addEdge(equiv) + node.addEdge(equiv) + self.session.undostack.push(CommandEdgeAdd(diagram, equiv)) + i = len(equiv.breakpoints) + for b in e_breakpoints: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, equiv, i, b)) + i = i + 1 + + return [node] + else: + pass - if self.isAtomic(e): + if self.isIsolated(domainNode): - iri = e.getIRI() - node = self.findNode(iri, diagram) - if node != 'null': - nodes.append(node) - x_positions.append(node.pos().x()) - y_positions.append(node.pos().y()) + x_tomove = propNode.pos().x() - 180 + y_tomove = propNode.pos().y() + while not self.isEmpty(x_tomove, y_tomove, diagram): - if len(nodes) == 0: + y_tomove = y_tomove + 70 + if abs(propNode.pos().y() - y_tomove) > 1000: + y_tomove = propNode.pos().y() + break + domainNode.setPos(x_tomove, y_tomove) - starting_x = x - 150 - starting_y = y + else: - if self.isAtomic(ce): + if self.isAtomic(rang): - cIRI = ce.getIRI() - cNode = self.findNode(cIRI, diagram) + x = propNode.pos().x() + y = propNode.pos().y() - 125 + domainNode = self.createNode(rang, diagram, x, y) + domDrawn = True - if cNode != 'null': - starting_x = cNode.pos().x() - (150 * len(keys)) - starting_y = cNode.pos().y() + 150 + else: + x = propNode.pos().x() + y = propNode.pos().y() - 125 + res = self.draw(rang, diagram, x, y) + domainNode = res[0] + domDrawn = True - if len(nodes) > 0: - starting_x = min(x_positions) - starting_y = min(y_positions) + else: - for c in keys: + if domDrawn: - if not self.isAtomic(c): + if self.isAtomic(property): - x = starting_x + 150 - y = starting_y + x = domainNode.pos().x() + y = domainNode.pos().y() + 125 + propNode = self.createNode(property, diagram, x, y) + propDrawn = True - starting_x = x - starting_y = y + else: + x = domainNode.pos().x() + y = domainNode.pos().y() + 125 - n = self.draw(c, diagram, x, y) - nodes.append(n) + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True - xN = n.pos().x() - x_positions.append(xN) + else: - yN = n.pos().y() - y_positions.append(yN) + if self.isAtomic(rang): - else: - if self.isAtomic(c): + x = x + y = y + domainNode = self.createNode(rang, diagram, x, y) + domDrawn = True - iri = c.getIRI() - node = self.findNode(iri, diagram) + else: + res = self.draw(rang, diagram, x, y) + domainNode = res[0] + domDrawn = True - if node == 'null': + if self.isAtomic(property): - x = starting_x + 150 - y = starting_y + x = domainNode.pos().x() + y = domainNode.pos().y() + 125 + propNode = self.createNode(property, diagram, x, y) + propDrawn = True - starting_x = x - starting_y = y + else: + x = domainNode.pos().x() + y = domainNode.pos().y() + 125 - node = self.createNode(c, diagram, x, y) - nodes.append(node) + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True - x = node.pos().x() - x_positions.append(x) + ''' + if domDrawn and propDrawn: + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 50, Diagram.GridSize), snapF(+propNode.height() / 2 + 50, Diagram.GridSize)) + pos = domainNode.pos() + offset - y = node.pos().y() - y_positions.append(y) + while not self.isEmpty(pos.x(), pos.y(), diagram): + diff = QtCore.QPointF(0, snapF(+50, Diagram.GridSize)) + pos = pos + diff + if abs(pos.y() - domainNode.pos().y()) > 1000: + break - # x_med = sum(x_positions) / len(x_positions) - maxX = max(x_positions) - minX = min(x_positions) - x_med = (maxX + minX) / 2 - # y_med = sum(y_positions) / len(y_positions) -100 - maxY = max(y_positions) - minY = min(y_positions) - y_med = (maxY + minY) / 2 - starting_y = y_med - while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 - if abs(starting_y - y_med) > 1000: - y_med = starting_y - break - key_node = HasKeyNode(diagram=diagram) - key_node.setPos(x_med, y_med) - self.session.undostack.push(CommandNodeAdd(diagram, key_node)) + propNode.setPos(pos) + ''' - for n in nodes: + restrNode = RangeRestrictionNode(diagram=diagram) + pos = self.restrictionPos(restrNode, propNode, diagram) + restrNode.setPos(pos) - input = diagram.factory.create(Item.InputEdge, source=n, target=key_node) - n.addEdge(input) - key_node.addEdge(input) + self.session.undostack.push(CommandNodeAdd(diagram, restrNode)) - self.session.undostack.push(CommandEdgeAdd(diagram, input)) + input1 = diagram.factory.create(Item.InputEdge, source=propNode, target=restrNode) + propNode.addEdge(input1) + restrNode.addEdge(input1) + self.session.undostack.push(CommandEdgeAdd(diagram, input1)) - if self.isAtomic(ce): + isa = diagram.factory.create(Item.InclusionEdge, source=restrNode, target=domainNode) + domainNode.addEdge(isa) + restrNode.addEdge(isa) + self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - cIri = ce.getIRI() - cNode = self.findNode(cIri, diagram) if self.findNode(cIri, diagram) != 'null' else self.createNode(ce, diagram, x_med, y_med-100) + self.addBreakpoints(diagram, propNode, restrNode, domainNode, isa) - if self.isIsolated(cNode): - cNode.setPos(x_med, y_med-100) + return [restrNode] - else: + def drawDataPropertyRange(self, property, range, diagram, x, y): - cNode = self.draw(ce, diagram) + propDrawn = False + domDrawn = False - in2 = diagram.factory.create(Item.InputEdge, source=cNode, target=key_node) - self.session.undostack.push(CommandEdgeAdd(diagram, in2)) + if self.isAtomic(property): - return key_node + iri = property.getIRI() + propNode = self.findNode(iri, diagram) - def drawChain(self, chain, property, diagram, x, y): + if propNode != 'null': + propDrawn = True - nodes = [] - x_positions = [] - y_positions = [] + if self.isAtomic(range) and not isinstance(range, self.OWLLiteral): - for e in chain: + iri = range.getIRI() + domainNode = self.findNode(iri, diagram) - if self.isAtomic(e): + if domainNode != 'null': + domDrawn = True - iri = e.getIRI() - node = self.findNode(iri, diagram) - if node != 'null': - nodes.append(node) - x_positions.append(node.pos().x()) - y_positions.append(node.pos().y()) + if propDrawn: - if len(nodes) == 0: + if domDrawn: - starting_x = x - 150 - starting_y = y - if self.isAtomic(property): + edges = propNode.edges + inputEdges = [e for e in edges if e.type() is Item.InputEdge] + for e in inputEdges: + if e.source is propNode and e.target.type() is Item.RangeRestrictionNode: + node = e.target + inputEdges = [e for e in node.edges if e.type() is Item.InputEdge] + if len(inputEdges) == 1: + for e in node.edges: + if e.target is domainNode or e.source is domainNode and e.type() is Item.EquivalenceEdge: + return [node] + elif e.target is domainNode and e.type() is Item.InclusionEdge: + return [node] + elif e.source is domainNode and e.type() is Item.InclusionEdge: + e_breakpoints = e.breakpoints + command = CommandItemsRemove(diagram, [e]) + self.session.undostack.push(command) + equiv = diagram.factory.create(Item.EquivalenceEdge, + source=node, + target=domainNode) + domainNode.addEdge(equiv) + node.addEdge(equiv) + self.session.undostack.push(CommandEdgeAdd(diagram, equiv)) + i = len(equiv.breakpoints) + for b in e_breakpoints: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, equiv, i, b)) + i = i + 1 + return [node] + else: + pass - cIRI = property.getIRI() - cNode = self.findNode(cIRI, diagram) + if self.isIsolated(domainNode): - if cNode != 'null': + x_tomove = propNode.pos().x() - 180 + y_tomove = propNode.pos().y() + while not self.isEmpty(x_tomove, y_tomove, diagram): - starting_x = cNode.pos().x() - (150*len(chain)) - starting_y = cNode.pos().x() + 150 + y_tomove = y_tomove + 70 + if abs(propNode.pos().y() - y_tomove) > 1000: + y_tomove = propNode.pos().y() + break + domainNode.setPos(x_tomove, y_tomove) + else: + if self.isAtomic(range): - if len(nodes) > 0: + x = propNode.pos().x() - 180 + y = propNode.pos().y() + domainNode = self.createNode(range, diagram, x, y) + domDrawn = True - starting_x = min(x_positions) - starting_y = min(y_positions) + else: + x = propNode.pos().x() - 180 + y = propNode.pos().y() - for prop in chain: + res = self.draw(range, diagram, x, y) + domainNode = res[0] + domDrawn = True - #if not prop.isType(self.EntityType.OBJECT_PROPERTY): - if not self.isAtomic(prop): + else: - x = starting_x + 150 - y = starting_y + if domDrawn: - starting_x = x - starting_y = y + if self.isAtomic(property): - n = self.draw(prop, diagram, x, y) - nodes.append(n) + x = domainNode.pos().x() + 180 + y = domainNode.pos().y() + propNode = self.createNode(property, diagram, x, y) + propDrawn = True - xN = n.pos().x() - x_positions.append(xN) + else: + x = domainNode.pos().x() + 180 + y = domainNode.pos().y() - yN = n.pos().y() - y_positions.append(yN) + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True else: - iri = prop.getIRI() - node = self.findNode(iri, diagram) + if self.isAtomic(range): - if node == 'null': + x = x + y = y + domainNode = self.createNode(range, diagram, x, y) + domDrawn = True - x = starting_x + 150 - y = starting_y + else: + res = self.draw(range, diagram, x, y) + domainNode = res[0] + domDrawn = True - starting_x = x - starting_y = y + if self.isAtomic(property): - node = self.createNode(prop, diagram, x, y) - nodes.append(node) + x = domainNode.pos().x() + 180 + y = domainNode.pos().y() + propNode = self.createNode(property, diagram, x, y) + propDrawn = True - x = node.pos().x() - x_positions.append(x) + else: + x = domainNode.pos().x() + 180 + y = domainNode.pos().y() - y = node.pos().y() - y_positions.append(y) + res = self.draw(property, diagram, x, y) + propNode = res[0] + propDrawn = True - x_med = (max(x_positions) + min(x_positions)) / 2 - y_med = ((max(y_positions) + min(y_positions)) / 2) - 100 - starting_y = y_med - while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 - if abs(starting_y - y_med) > 1000: - y_med = starting_y - break - chain_node = RoleChainNode(diagram=diagram) - chain_node.setPos(x_med, y_med) - self.session.undostack.push(CommandNodeAdd(diagram, chain_node)) + if domDrawn and propDrawn: + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 50, Diagram.GridSize), snapF(+propNode.height() / 2 + 50, Diagram.GridSize)) + pos = domainNode.pos() + offset + + while not self.isEmpty(pos.x(), pos.y(), diagram): + diff = QtCore.QPointF(0, snapF(+50, Diagram.GridSize)) + pos = pos + diff + if abs(pos.y() - domainNode.pos().y()) > 1000: + break - for n in nodes: - input = diagram.factory.create(Item.InputEdge, source=n, target=chain_node) - n.addEdge(input) - chain_node.addEdge(input) + propNode.setPos(pos) - self.session.undostack.push(CommandEdgeAdd(diagram, input)) + restrNode = RangeRestrictionNode(diagram=diagram) + pos = self.restrictionPos(restrNode, propNode, diagram) + restrNode.setPos(pos) - if self.isAtomic(property): - pIri = property.getIRI() - pNode = self.findNode(pIri, diagram) if self.findNode(pIri, - diagram) != 'null' else self.createNode( - property, diagram, x_med, y_med - 100) + self.session.undostack.push(CommandNodeAdd(diagram, restrNode)) - else: - pNode = self.draw(property, diagram) + input1 = diagram.factory.create(Item.InputEdge, source=propNode, target=restrNode) + propNode.addEdge(input1) + restrNode.addEdge(input1) + self.session.undostack.push(CommandEdgeAdd(diagram, input1)) - isa = diagram.factory.create(Item.InclusionEdge, source=chain_node, target=pNode) + isa = diagram.factory.create(Item.InclusionEdge, source=restrNode, target=domainNode) + domainNode.addEdge(isa) + restrNode.addEdge(isa) self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - return chain_node + if domainNode.pos().x() != restrNode.pos().x() and domainNode.pos().y() != restrNode.pos().y(): + + bp1 = QtCore.QPointF(domainNode.pos().x() + 50, restrNode.pos().y()) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + + bp2 = QtCore.QPointF(domainNode.pos().x() + 50, domainNode.pos().y()) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) - def drawPropertyRange(self, property, range, diagram, x, y): + return [restrNode] + + def drawObjPropertyDomain(self, property, domain, diagram, x, y): propDrawn = False domDrawn = False @@ -4765,12 +6339,13 @@ def drawPropertyRange(self, property, range, diagram, x, y): if propNode != 'null': propDrawn = True - if self.isAtomic(range) and not isinstance(range, self.OWLLiteral): + if self.isAtomic(domain) and not isinstance(domain, self.OWLLiteral): - iri = range.getIRI() + iri = domain.getIRI() domainNode = self.findNode(iri, diagram) if domainNode != 'null': + domDrawn = True if propDrawn: @@ -4780,31 +6355,37 @@ def drawPropertyRange(self, property, range, diagram, x, y): edges = propNode.edges inputEdges = [e for e in edges if e.type() is Item.InputEdge] for e in inputEdges: - if e.source is propNode and e.target.type() is Item.RangeRestrictionNode: + if e.source is propNode and e.target.type() is Item.DomainRestrictionNode: node = e.target inputEdges = [e for e in node.edges if e.type() is Item.InputEdge] if len(inputEdges) == 1: - for e in node.edges: + for e in node.edges: if e.target is domainNode or e.source is domainNode and e.type() is Item.EquivalenceEdge: - return node + return [node] elif e.target is domainNode and e.type() is Item.InclusionEdge: - return node + return [node] elif e.source is domainNode and e.type() is Item.InclusionEdge: + e_breakpoints = e.breakpoints command = CommandItemsRemove(diagram, [e]) self.session.undostack.push(command) equiv = diagram.factory.create(Item.EquivalenceEdge, - source=node, - target=domainNode) + source=node, + target=domainNode) domainNode.addEdge(equiv) node.addEdge(equiv) self.session.undostack.push(CommandEdgeAdd(diagram, equiv)) - return node + i = len(equiv.breakpoints) + for b in e_breakpoints: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, equiv, i, b)) + i = i + 1 + return [node] else: pass if self.isIsolated(domainNode): - x_tomove = propNode.pos().x() - 200 + x_tomove = propNode.pos().x() + 200 y_tomove = propNode.pos().y() while not self.isEmpty(x_tomove, y_tomove, diagram): @@ -4816,18 +6397,19 @@ def drawPropertyRange(self, property, range, diagram, x, y): else: - if self.isAtomic(range): + if self.isAtomic(domain): - x = propNode.pos().x() - 200 - y = propNode.pos().y() - domainNode = self.createNode(range, diagram, x, y) + x = propNode.pos().x() + y = propNode.pos().y() - 125 + domainNode = self.createNode(domain, diagram, x, y) domDrawn = True else: - x = propNode.pos().x() - 200 - y = propNode.pos().y() + x = propNode.pos().x() + y = propNode.pos().y() - 125 - domainNode = self.draw(range, diagram, x, y) + res = self.draw(domain, diagram, x, y) + domainNode = res[0] domDrawn = True else: @@ -4836,61 +6418,68 @@ def drawPropertyRange(self, property, range, diagram, x, y): if self.isAtomic(property): - x = domainNode.pos().x() + 200 - y = domainNode.pos().y() + x = domainNode.pos().x() + y = domainNode.pos().y() + 125 + propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - x = domainNode.pos().x() + 200 - y = domainNode.pos().y() + x = domainNode.pos().x() + y = domainNode.pos().y() + 125 - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True else: - if self.isAtomic(range): + if self.isAtomic(domain): x = x y = y - domainNode = self.createNode(range, diagram, x, y) + domainNode = self.createNode(domain, diagram, x, y) domDrawn = True else: - domainNode = self.draw(range, diagram, x, y) + + res = self.draw(domain, diagram, x, y) + domainNode = res[0] domDrawn = True if self.isAtomic(property): - x = domainNode.pos().x() + 200 - y = domainNode.pos().y() + x = domainNode.pos().x() + y = domainNode.pos().y() + 125 propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - x = domainNode.pos().x() + 200 - y = domainNode.pos().y() + x = domainNode.pos().x() + y = domainNode.pos().y() + 125 - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True - + ''' if domDrawn and propDrawn: - offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 70, Diagram.GridSize), snapF(+propNode.height() / 2 + 70, Diagram.GridSize)) + offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 50, Diagram.GridSize), snapF(+propNode.height() / 2 + 50, Diagram.GridSize)) pos = domainNode.pos() + offset while not self.isEmpty(pos.x(), pos.y(), diagram): - diff = QtCore.QPointF(0, snapF(+70, Diagram.GridSize)) + diff = QtCore.QPointF(0, snapF(+50, Diagram.GridSize)) pos = pos + diff if abs(pos.y() - domainNode.pos().y()) > 1000: break propNode.setPos(pos) + ''' - restrNode = RangeRestrictionNode(diagram=diagram) + restrNode = DomainRestrictionNode(diagram=diagram) pos = self.restrictionPos(restrNode, propNode, diagram) restrNode.setPos(pos) + self.session.undostack.push(CommandNodeAdd(diagram, restrNode)) input1 = diagram.factory.create(Item.InputEdge, source=propNode, target=restrNode) @@ -4903,9 +6492,11 @@ def drawPropertyRange(self, property, range, diagram, x, y): restrNode.addEdge(isa) self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - return restrNode + self.addBreakpoints(diagram, propNode, restrNode, domainNode, isa) + + return [restrNode] - def drawPropertyDomain(self, property, domain, diagram, x, y): + def drawDataPropertyDomain(self, property, domain, diagram, x, y): propDrawn = False domDrawn = False @@ -4940,10 +6531,11 @@ def drawPropertyDomain(self, property, domain, diagram, x, y): if len(inputEdges) == 1: for e in node.edges: if e.target is domainNode or e.source is domainNode and e.type() is Item.EquivalenceEdge: - return node + return [node] elif e.target is domainNode and e.type() is Item.InclusionEdge: - return node + return [node] elif e.source is domainNode and e.type() is Item.InclusionEdge: + e_breakpoints = e.breakpoints command = CommandItemsRemove(diagram, [e]) self.session.undostack.push(command) equiv = diagram.factory.create(Item.EquivalenceEdge, @@ -4952,13 +6544,18 @@ def drawPropertyDomain(self, property, domain, diagram, x, y): domainNode.addEdge(equiv) node.addEdge(equiv) self.session.undostack.push(CommandEdgeAdd(diagram, equiv)) - return node + i = len(equiv.breakpoints) + for b in e_breakpoints: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, equiv, i, b)) + i = i + 1 + return [node] else: pass if self.isIsolated(domainNode): - x_tomove = propNode.pos().x() + 200 + x_tomove = propNode.pos().x() + 180 y_tomove = propNode.pos().y() while not self.isEmpty(x_tomove, y_tomove, diagram): @@ -4972,16 +6569,17 @@ def drawPropertyDomain(self, property, domain, diagram, x, y): if self.isAtomic(domain): - x = propNode.pos().x() + 200 + x = propNode.pos().x() + 180 y = propNode.pos().y() domainNode = self.createNode(domain, diagram, x, y) domDrawn = True else: - x = propNode.pos().x() + 200 + x = propNode.pos().x() + 180 y = propNode.pos().y() - domainNode = self.draw(domain, diagram, x, y) + res = self.draw(domain, diagram, x, y) + domainNode = res[0] domDrawn = True else: @@ -4990,17 +6588,18 @@ def drawPropertyDomain(self, property, domain, diagram, x, y): if self.isAtomic(property): - x = domainNode.pos().x() - 200 + x = domainNode.pos().x() - 180 y = domainNode.pos().y() propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - x = domainNode.pos().x() - 200 + x = domainNode.pos().x() - 180 y = domainNode.pos().y() - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True else: @@ -5014,23 +6613,25 @@ def drawPropertyDomain(self, property, domain, diagram, x, y): else: - domainNode = self.draw(domain, diagram, x, y) + res = self.draw(domain, diagram, x, y) + domainNode = res[0] domDrawn = True if self.isAtomic(property): - x = domainNode.pos().x() - 200 + x = domainNode.pos().x() - 180 y = domainNode.pos().y() propNode = self.createNode(property, diagram, x, y) propDrawn = True else: - x = domainNode.pos().x() - 200 + x = domainNode.pos().x() - 180 y = domainNode.pos().y() - propNode = self.draw(property, diagram, x, y) + res = self.draw(property, diagram, x, y) + propNode = res[0] propDrawn = True - + ''' if domDrawn and propDrawn: offset = QtCore.QPointF(snapF(-propNode.width() / 2 - 70, Diagram.GridSize), snapF(+propNode.height() / 2 + 70, Diagram.GridSize)) pos = domainNode.pos() + offset @@ -5042,6 +6643,7 @@ def drawPropertyDomain(self, property, domain, diagram, x, y): break propNode.setPos(pos) + ''' restrNode = DomainRestrictionNode(diagram=diagram) pos = self.restrictionPos(restrNode, propNode, diagram) @@ -5060,7 +6662,16 @@ def drawPropertyDomain(self, property, domain, diagram, x, y): restrNode.addEdge(isa) self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - return restrNode + if domainNode.pos().x() != restrNode.pos().x() and domainNode.pos().y() != restrNode.pos().y(): + + bp1 = QtCore.QPointF(domainNode.pos().x() - 70, restrNode.pos().y()) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + + bp2 = QtCore.QPointF(domainNode.pos().x() - 70, domainNode.pos().y()) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + + + return [restrNode] def drawInverseObjProperties(self, first, second, diagram, x, y): @@ -5093,17 +6704,18 @@ def drawInverseObjProperties(self, first, second, diagram, x, y): if self.isAtomic(second): - x = firstNode.pos().x() + 300 + x = firstNode.pos().x() + 125 y = firstNode.pos().y() secondNode = self.createNode(second, diagram, x, y) secondDrawn = True else: - x = firstNode.pos().x() + 300 + x = firstNode.pos().x() + 125 y = firstNode.pos().y() - secondNode = self.draw(second, diagram, x, y) + res = self.draw(second, diagram, x, y) + secondNode = res[0] secondDrawn = True else: @@ -5112,67 +6724,130 @@ def drawInverseObjProperties(self, first, second, diagram, x, y): if self.isAtomic(first): - x = secondNode.pos().x() - 300 + x = secondNode.pos().x() - 125 y = secondNode.pos().y() firstNode = self.createNode(first, diagram, x, y) firstDrawn = True else: - x = secondNode.pos().x() - 300 + x = secondNode.pos().x() - 125 y = secondNode.pos().y() - firstNode = self.draw(second, diagram, x, y) + res = self.draw(second, diagram, x, y) + firstNode = res[0] firstDrawn = True else: if self.isAtomic(first): - x = x + 300 - y = y + 300 + x = x + 125 + y = y firstNode = self.createNode(first, diagram, x, y) firstDrawn = True else: - firstNode = self.draw(second, diagram, x+300, y+300) + res = self.draw(second, diagram, x+125, y) + firstNode = res[0] firstDrawn = True if self.isAtomic(second): - x = firstNode.pos().x() + 300 + x = firstNode.pos().x() + 125 y = firstNode.pos().y() secondNode = self.createNode(second, diagram, x, y) secondDrawn = True else: - x = firstNode.pos().x() + 300 + x = firstNode.pos().x() + 125 y = firstNode.pos().y() - secondNode = self.draw(second, diagram, x, y) + res = self.draw(second, diagram, x, y) + secondNode = res[0] secondDrawn = True inv = RoleInverseNode(diagram=diagram) - x = (firstNode.pos().x() + secondNode.pos().x()) /2 - y = (firstNode.pos().y() + secondNode.pos().y()) /2 + #x = (firstNode.pos().x() + secondNode.pos().x()) /2 + x = firstNode.pos().x() + 125 + #y = (firstNode.pos().y() + secondNode.pos().y()) /2 + y = firstNode.pos().y() starting_y = y while not self.isEmpty(x, y, diagram): - y = y - 30 + y = y - 50 if abs(starting_y - y) > 1000: y = starting_y break inv.setPos(x, y) self.session.undostack.push(CommandNodeAdd(diagram, inv)) + equiv = diagram.factory.create(Item.EquivalenceEdge, source=firstNode, target=inv) + inv.addEdge(equiv) + firstNode.addEdge(equiv) + self.session.undostack.push(CommandEdgeAdd(diagram, equiv)) + + if inv.pos().y() != firstNode.pos().y(): + x = firstNode.pos().x() + 70 + y1 = firstNode.pos().y() + y2 = inv.pos().y() + + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equiv, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equiv, 1, bp2)) + input = diagram.factory.create(Item.InputEdge, source=secondNode, target=inv) secondNode.addEdge(input) inv.addEdge(input) self.session.undostack.push(CommandEdgeAdd(diagram, input)) - equiv = diagram.factory.create(Item.EquivalenceEdge, source=inv, target=firstNode) - inv.addEdge(equiv) - firstNode.addEdge(equiv) - self.session.undostack.push(CommandEdgeAdd(diagram, equiv)) + x1 = inv.pos().x() + 65 + y1 = inv.pos().y() + bp1 = QtCore.QPointF(x1, y1) + + if inv.pos().y() == secondNode.pos().y(): + x2 = x1 + y2 = inv.pos().y() - 30 + + y3 = y2 + x3 = secondNode.pos().x() - 70 + + x4 = x3 + y4 = secondNode.pos().y() + + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp4)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 2, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 3, bp1)) + + elif secondNode.pos().x() == firstNode.pos().x(): + + x2 = x1 + y2 = secondNode.pos().y() + bp2 = QtCore.QPointF(x2, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp1)) + + else: + + x2 = x1 + y2 = secondNode.pos().y() + 40 + + x3 = secondNode.pos().x() + y3 = y2 + + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) - return inv + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 2, bp1)) + + return [inv] def drawSubProperty(self, sub, sup, diagram, x, y): @@ -5204,14 +6879,15 @@ def drawSubProperty(self, sub, sup, diagram, x, y): if self.isAtomic(sup): x = node0.pos().x() - y = node0.pos().y() - 150 + y = node0.pos().y() - 250 node1 = self.createNode(sup, diagram, x, y) supDrawn = True else: x = node0.pos().x() - y = node0.pos().y() - 150 - node1 = self.draw(sup, diagram, x, y) + y = node0.pos().y() - 250 + res = self.draw(sup, diagram, x, y) + node1 = res[0] supDrawn = True else: @@ -5221,14 +6897,15 @@ def drawSubProperty(self, sub, sup, diagram, x, y): if self.isAtomic(sub): x = node1.pos().x() - y = node1.pos().y() + 150 + y = node1.pos().y() + 250 node0 = self.createNode(sub, diagram, x, y) subDrawn = True else: x = node1.pos().x() - y = node1.pos().y() + 150 - node0 = self.draw(sub, diagram, x, y) + y = node1.pos().y() + 250 + res = self.draw(sub, diagram, x, y) + node0 = res[0] subDrawn = True else: @@ -5242,20 +6919,22 @@ def drawSubProperty(self, sub, sup, diagram, x, y): else: - node1 = self.draw(sup, diagram, x, y) + res = self.draw(sup, diagram, x, y) + node1 = res[0] supDrawn = True if self.isAtomic(sub): x = node1.pos().x() - y = node1.pos().y() + 150 + y = node1.pos().y() + 250 node0 = self.createNode(sub, diagram, x, y) subDrawn = True else: x = node1.pos().x() - y = node1.pos().y() + 150 - node0 = self.draw(sub, diagram, x, y) + y = node1.pos().y() + 250 + res = self.draw(sub, diagram, x, y) + node0 = res[0] subDrawn = True isa = diagram.factory.create(Item.InclusionEdge, source=node0, target=node1) @@ -5264,13 +6943,99 @@ def drawSubProperty(self, sub, sup, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - return isa + if node0.type() is Item.RoleNode: + if node0.pos().y() == node1.pos().y() and abs(node0.pos().x() - node1.pos().x()) < 130: + pass + + elif node0.pos().x() == node1.pos().x(): + + x1 = node0.pos().x() - 70 + y1 = node0.pos().y() + y2 = node1.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x1, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + + elif node0.pos().y() == node1.pos().y(): + + x1 = node0.pos().x() - 40 + y1 = node0.pos().y() + x2 = x1 + y2 = node0.pos().y() - 35 + x3 = node1.pos().x() + 40 + y3 = y2 + x4 = x3 + y4 = node1.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 2, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 3, bp4)) + + else: + + x1 = node0.pos().x() - 70 + y1 = node0.pos().y() + x2 = x1 + y2 = node1.pos().y() + 35 + x3 = node1.pos().x() + y3 = y2 + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 2, bp3)) + + else: + if node0.pos().x() == node1.pos().x(): + + x1 = node0.pos().x() + 30 + y1 = node0.pos().y() + x2 = x1 + y2 = node1.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + + + else: + x1 = node0.pos().x() + 30 + y1 = node0.pos().y() + x2 = node1.pos().x() + 30 + y2 = y1 + x3 = x2 + y3 = node1.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 2, bp3)) + + return [isa] def drawEquivalentClasses(self, expressions, diagram, x, y): nodes = [] singletons = [] found = None + propNode = None for e in expressions: if self.isAtomic(e): @@ -5282,24 +7047,28 @@ def drawEquivalentClasses(self, expressions, diagram, x, y): singletons.append(node) if len(nodes) == 0: - starting_x = x - 150 + starting_x = x - 125 starting_y = y if len(nodes) > 0: - starting_x = nodes[0].pos().x() - 150 - starting_y = nodes[0].pos().y() + 150 + starting_x = nodes[0].pos().x() - 125 + starting_y = nodes[0].pos().y() + 125 for ex in expressions: if not self.isAtomic(ex): - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x starting_y = y - n = self.draw(ex, diagram, x, y) + res = self.draw(ex, diagram, x, y) + n = res[0] + if len(res) > 1: + restrNode = res[0] + propNode = res[1] if nodes: cl = nodes[0] @@ -5346,7 +7115,7 @@ def drawEquivalentClasses(self, expressions, diagram, x, y): if node == 'null': - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x @@ -5355,8 +7124,8 @@ def drawEquivalentClasses(self, expressions, diagram, x, y): node = self.createNode(ex, diagram, x, y) nodes.append(node) - node0 = nodes[0] - node1 = nodes[1] + node0 = nodes[1] if nodes[0].type() == Item.ConceptNode else nodes[0] + node1 = nodes[1] if node0 != nodes[1] else nodes[0] if singletons: @@ -5364,31 +7133,37 @@ def drawEquivalentClasses(self, expressions, diagram, x, y): fixed = node0 if node0 != toMove else node1 x_tomove = fixed.pos().x() - y_tomove = fixed.pos().y() -100 + y_tomove = fixed.pos().y() - 125 while not self.isEmpty(x_tomove, y_tomove, diagram): - x_tomove = x_tomove + 70 - if abs(fixed.pos().x() - x_tomove) > 1000: + y_tomove = y_tomove + 125 + if abs(fixed.pos().y() - y_tomove) > 1000: - x_tomove = fixed.pos().x() + y_tomove = fixed.pos().y() break toMove.setPos(x_tomove, y_tomove) + breakpoints = None if found: eqEdges = [e for e in found.edges if e.type() is Item.EquivalenceEdge] if eqEdges: - return eqEdges[0] + return [eqEdges[0]] else: for e in found.edges: if e.type() is Item.InclusionEdge and (e.source is cl or e.target is cl): self.session.undostack.push(CommandItemsRemove(diagram, [e])) - equivalence = diagram.factory.create(Item.EquivalenceEdge, source=found, - target=cl) - found.addEdge(equivalence) - cl.addEdge(equivalence) + breakpoints = e.breakpoints + equivalence = diagram.factory.create(Item.EquivalenceEdge, source=node0, + target=node1) + node0.addEdge(equivalence) + node1.addEdge(equivalence) self.session.undostack.push(CommandEdgeAdd(diagram, equivalence)) + i = 0 + for b in breakpoints: + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, i, b)) + i = i + 1 else: @@ -5398,11 +7173,87 @@ def drawEquivalentClasses(self, expressions, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, equivalence)) - return equivalence + if not breakpoints: + if propNode: + if propNode.type() is Item.RoleNode: + bps = self.addBreakpoints(diagram, propNode, restrNode, node1, None) + + #bps.reverse() + + i = len(equivalence.breakpoints) + for b in bps: + self.session.undostack.push( + CommandEdgeBreakpointAdd(diagram, equivalence, i, b)) + i = i + 1 + else: + if node1.pos().x() != restrNode.pos().x() and node1.pos().y() != restrNode.pos().y(): + bp1 = QtCore.QPointF(node1.pos().x() - 70, restrNode.pos().y()) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 0, bp1)) + + bp2 = QtCore.QPointF(node1.pos().x() - 70, node1.pos().y()) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 1, bp2)) + + else: + if node0.pos().y() == node1.pos().y() and abs(node0.pos().x() - node1.pos().x()) < 130: + pass + + elif node0.pos().x() == node1.pos().x(): + + x1 = node0.pos().x() + 68 + y1 = node0.pos().y() + y2 = node1.pos().y() + + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x1, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 1, bp2)) + + elif node0.pos().y() == node1.pos().y(): + + x1 = node0.pos().x() + 68 + y1 = node0.pos().y() + x2 = x1 + y2 = node0.pos().y() - 35 + x3 = node1.pos().x() - 70 + y3 = y2 + x4 = x3 + y4 = node1.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 2, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 3, bp4)) + + else: + + x1 = node0.pos().x() + 68 + y1 = node0.pos().y() + x2 = x1 + y2 = node1.pos().y() + 40 + x3 = node1.pos().x() + y3 = y2 + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 2, bp3)) + + return [equivalence] def drawEquivalentProperties(self, expressions, diagram, x, y): nodes = [] + propNode = None for e in expressions: if self.isAtomic(e): @@ -5412,7 +7263,7 @@ def drawEquivalentProperties(self, expressions, diagram, x, y): nodes.append(node) if len(nodes) == 0: - starting_x = x - 150 + starting_x = x - 125 starting_y = y if len(nodes) > 0: @@ -5423,12 +7274,13 @@ def drawEquivalentProperties(self, expressions, diagram, x, y): if not self.isAtomic(ex): - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x starting_y = y - n = self.draw(ex, diagram, x, y) + res = self.draw(ex, diagram, x, y) + n = res[0] nodes.append(n) else: @@ -5440,7 +7292,7 @@ def drawEquivalentProperties(self, expressions, diagram, x, y): if node == 'null': - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x @@ -5458,7 +7310,93 @@ def drawEquivalentProperties(self, expressions, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, equivalence)) - return equivalence + if node0.type() is Item.RoleNode: + if node0.pos().y() == node1.pos().y() and abs(node0.pos().x() - node1.pos().x()) < 130: + pass + + elif node0.pos().x() == node1.pos().x(): + + x1 = node0.pos().x() - 70 + y1 = node0.pos().y() + y2 = node1.pos().y() + + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x1, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 1, bp2)) + + elif node0.pos().y() == node1.pos().y(): + + x1 = node0.pos().x() - 40 + y1 = node0.pos().y() + x2 = x1 + y2 = node0.pos().y() - 35 + x3 = node1.pos().x() + 40 + y3 = y2 + x4 = x3 + y4 = node1.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 2, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 3, bp4)) + + else: + + x1 = node0.pos().x() - 70 + y1 = node0.pos().y() + x2 = x1 + y2 = node1.pos().y() + 35 + x3 = node1.pos().x() + y3 = y2 + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 2, bp3)) + + else: + if node0.pos().x() == node1.pos().x(): + + x1 = node0.pos().x() + 30 + y1 = node0.pos().y() + x2 = x1 + y2 = node1.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 1, bp2)) + + + else: + x1 = node0.pos().x() + 30 + y1 = node0.pos().y() + x2 = node1.pos().x() + 30 + y2 = y1 + x3 = x2 + y3 = node1.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, equivalence, 2, bp3)) + + return [equivalence] def drawClassAssertion(self, indiv, classs, diagram, x, y): @@ -5488,12 +7426,12 @@ def drawClassAssertion(self, indiv, classs, diagram, x, y): if self.isIsolated(node0): x_tomove = node1.pos().x() - y_tomove = node1.pos().y() + 100 + y_tomove = node1.pos().y() + 125 while not self.isEmpty(x_tomove, y_tomove, diagram): - x_tomove = x_tomove + 100 - if abs(node1.pos().x() - x_tomove) > 1000: - x_tomove = node1.pos().x() + y_tomove = y_tomove + 125 + if abs(node1.pos().y() - y_tomove) > 1000: + y_tomove = node1.pos().y() break node0.setPos(x_tomove, y_tomove) @@ -5505,12 +7443,12 @@ def drawClassAssertion(self, indiv, classs, diagram, x, y): if self.isIsolated(node1): x_tomove = node0.pos().x() - y_tomove = node0.pos().y() - 100 + y_tomove = node0.pos().y() - 125 while not self.isEmpty(x_tomove, y_tomove, diagram): - x_tomove = x_tomove + 100 - if abs(node0.pos().x() - x_tomove) > 1000: - x_tomove = node0.pos().x() + y_tomove = y_tomove + 125 + if abs(node0.pos().y() - y_tomove) > 1000: + y_tomove = node0.pos().y() break node1.setPos(x_tomove, y_tomove) @@ -5523,14 +7461,15 @@ def drawClassAssertion(self, indiv, classs, diagram, x, y): if self.isAtomic(indiv): x = node1.pos().x() - y = node1.pos().y() + 150 + y = node1.pos().y() + 125 node0 = self.createNode(indiv, diagram, x, y) indivDrawn = True else: x = node1.pos().x() - y = node1.pos().y() + 150 - node0 = self.draw(indiv, diagram, x, y) + y = node1.pos().y() + 125 + res = self.draw(indiv, diagram, x, y) + node0 = res[0] indivDrawn = True else: @@ -5540,15 +7479,16 @@ def drawClassAssertion(self, indiv, classs, diagram, x, y): if self.isAtomic(classs): x = node0.pos().x() - y = node0.pos().y() - 150 + y = node0.pos().y() - 125 node1 = self.createNode(classs, diagram, x, y) classDrawn = True else: x = node0.pos().x() - y = node0.pos().y() - 150 - node1 = self.draw(classs, diagram, x, y) + y = node0.pos().y() - 125 + res = self.draw(classs, diagram, x, y) + node1 = res[0] classDrawn = True else: @@ -5562,21 +7502,23 @@ def drawClassAssertion(self, indiv, classs, diagram, x, y): else: - node1 = self.draw(classs, diagram, x, y) + res = self.draw(classs, diagram, x, y) + node1 = res[0] classDrawn = True if self.isAtomic(indiv): x = node1.pos().x() - y = node1.pos().y() + 150 + y = node1.pos().y() + 125 node0 = self.createNode(indiv, diagram, x, y) indivDrawn = True else: x = node1.pos().x() - y = node1.pos().y() + 150 + y = node1.pos().y() + 125 - node0 = self.draw(indiv, diagram, x, y) + res = self.draw(indiv, diagram, x, y) + node0 = res[0] indivDrawn = True isa = diagram.factory.create(Item.MembershipEdge, source=node0, target=node1) @@ -5585,7 +7527,18 @@ def drawClassAssertion(self, indiv, classs, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - return isa + x = node0.pos().x() + 68 + y1 = node0.pos().y() + y2 = node1.pos().y() + + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + + + return [isa] def drawPropertyAssertion(self, prop, indiv, value, diagram, x, y): @@ -5630,15 +7583,16 @@ def drawPropertyAssertion(self, prop, indiv, value, diagram, x, y): if self.isAtomic(value): - x = indivNode.pos().x() - y = indivNode.pos().y() - 150 + x = propNode.pos().x() + propNode.width()/2 + 50 + y = propNode.pos().y() + propNode.height()/2 + 50 valueNode = self.createNode(value, diagram, x, y) valueDrawn = True else: - x = indivNode.pos().x() - y = indivNode.pos().y() - 150 - valueNode = self.draw(value, diagram, x, y) + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(value, diagram, x, y) + valueNode = res[0] valueDrawn = True else: @@ -5647,45 +7601,47 @@ def drawPropertyAssertion(self, prop, indiv, value, diagram, x, y): if self.isAtomic(indiv): - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 indivNode = self.createNode(indiv, diagram, x, y) indivDrawn = True else: - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 - indivNode = self.draw(indiv, diagram, x, y) + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(indiv, diagram, x, y) + indivNode = res[0] indivDrawn = True else: if self.isAtomic(value): - x = propNode.pos().x() - 150 - y = propNode.pos().y() - 150 + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 valueNode = self.createNode(value, diagram, x, y) valueDrawn = True else: - x = propNode.pos().x() - 150 - y = propNode.pos().y() - 150 - - valueNode = self.draw(value, diagram, x, y) + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(value, diagram, x, y) + valueNode = res[0] valueDrawn = True if self.isAtomic(indiv): - x = propNode.pos().x() - y = propNode.pos().y() - 150 + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 indivNode = self.createNode(indiv, diagram, x, y) indivDrawn = True else: - x = propNode.pos().x() - y = propNode.pos().y() - 150 - indivNode = self.draw(indiv, diagram, x, y) + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(indiv, diagram, x, y) + indivNode = res[0] indivDrawn = True else: @@ -5697,13 +7653,20 @@ def drawPropertyAssertion(self, prop, indiv, value, diagram, x, y): y = indivNode.pos().y() + 150 propNode = self.createNode(prop, diagram, x, y) propDrawn = True + x = indivNode.pos().x() + propNode.width()/2 + 50 + y = indivNode.pos().y() - propNode.height()/2 - 50 + propNode.setPos(x, y) else: x = indivNode.pos().x() y = indivNode.pos().y() + 150 - propNode = self.draw(prop, diagram, x, y) + res = self.draw(prop, diagram, x, y) + propNode = res[0] propDrawn = True + x = indivNode.pos().x() + propNode.width() / 2 + 50 + y = indivNode.pos().y() - propNode.height() / 2 - 50 + propNode.setPos(x, y) if valueDrawn: @@ -5713,99 +7676,110 @@ def drawPropertyAssertion(self, prop, indiv, value, diagram, x, y): if self.isAtomic(value): - x = indivNode.pos().x() - y = indivNode.pos().y() - 150 + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 valueNode = self.createNode(value, diagram, x, y) valueDrawn = True else: - x = indivNode.pos().x() - y = indivNode.pos().y() - 150 - valueNode = self.draw(value, diagram, x, y) + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(value, diagram, x, y) + valueNode = res[0] valueDrawn = True else: if valueDrawn: + if self.isAtomic(prop): + + x = indivNode.pos().x() + y = indivNode.pos().y() + 150 + propNode = self.createNode(prop, diagram, x, y) + propDrawn = True + x = valueNode.pos().x() - propNode.width() / 2 - 50 + y = valueNode.pos().y() - propNode.height() / 2 - 50 + propNode.setPos(x, y) + + else: + + x = indivNode.pos().x() + y = indivNode.pos().y() + 150 + res = self.draw(prop, diagram, x, y) + propNode = res[0] + x = valueNode.pos().x() - propNode.width() / 2 - 50 + y = valueNode.pos().y() - propNode.height() / 2 - 50 + propNode.setPos(x, y) + if self.isAtomic(indiv): - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 indivNode = self.createNode(indiv, diagram, x, y) indivDrawn = True else: - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 - indivNode = self.draw(indiv, diagram, x, y) + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(indiv, diagram, x, y) + indivNode = res[0] indivDrawn = True + + else: + if self.isAtomic(prop): - x = indivNode.pos().x() - y = indivNode.pos().y() + 150 + x = x + y = y propNode = self.createNode(prop, diagram, x, y) + #print(propNode) propDrawn = True else: - x = indivNode.pos().x() - y = indivNode.pos().y() + 150 - propNode = self.draw(prop, diagram, x, y) - - else: + x = x + y = y + res = self.draw(prop, diagram, x, y) + propNode = res[0] + propDrawn = True if self.isAtomic(value): - x = x - y = y - #print(value) + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 valueNode = self.createNode(value, diagram, x, y) valueDrawn = True else: - - valueNode = self.draw(value, diagram, x, y) + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(value, diagram, x, y) + valueNode = res[0] valueDrawn = True if self.isAtomic(indiv): - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 indivNode = self.createNode(indiv, diagram, x, y) #print(indivNode) indivDrawn = True else: - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 - - indivNode = self.draw(indiv, diagram, x, y) + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(indiv, diagram, x, y) + indivNode = res[0] indivDrawn = True - if self.isAtomic(prop): - - x = indivNode.pos().x() - y = indivNode.pos().y() + 150 - propNode = self.createNode(prop, diagram, x, y) - #print(propNode) - propDrawn = True - - else: - - x = indivNode.pos().x() - y = indivNode.pos().y() + 150 - propNode = self.draw(prop, diagram, x, y) - propDrawn = True - - instanceNode = PropertyAssertionNode(diagram=diagram) - x = (indivNode.pos().x() + propNode.pos().x()) / 2 - y = propNode.pos().y() + x = propNode.pos().x() + y = propNode.pos().y() + propNode.width()/2 + 50 starting_y = y while not self.isEmpty(x, y, diagram): - y = y - 30 + y = y + 125 if abs(starting_y - y) > 1000: y = starting_y break @@ -5829,40 +7803,72 @@ def drawPropertyAssertion(self, prop, indiv, value, diagram, x, y): propNode.addEdge(isa) self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - return instanceNode + x = propNode.pos().x() + 68 + y1 = instanceNode.pos().y() + y2 = propNode.pos().y() + + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + + x1 = instanceNode.pos().x() + y1 = instanceNode.pos().y() - 40 + x2 = instanceNode.pos().x() + 70 + y2 = y1 + x3 = x2 + y3 = indivNode.pos().y() + + bp3 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp1 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input1, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input1, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input1, 2, bp3)) + + x1 = instanceNode.pos().x() + y1 = instanceNode.pos().y() - 40 + x2 = instanceNode.pos().x() - 70 + y2 = y1 + x3 = x2 + y3 = valueNode.pos().y() + + bp3 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp1 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input2, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input2, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input2, 2, bp3)) + + return [instanceNode] def drawNegativePropertyAssertion(self, prop, indiv, value, diagram, x, y): propDrawn = False - notDrawn = False indivDrawn = False valueDrawn = False - if self.isAtomic(prop): + if self.isAtomic(prop): propIri = prop.getIRI() propNode = self.findNode(propIri, diagram) if propNode != 'null': propDrawn = True - edges = propNode.edges - inputEdges = [e for e in edges if e.type() is Item.InputEdge] - for e in inputEdges: - if e.target.type() is Item.ComplementNode: - - notNode = e.target - notDrawn = True - if self.isAtomic(indiv): - indvIri = prop.getIRI() + indvIri = indiv.getIRI() indivNode = self.findNode(indvIri, diagram) if indivNode != 'null': indivDrawn = True if self.isAtomic(value): - if value.isType(self.EntityType.NAMED_INDIVIDUAL): + + if isinstance(value, self.OWLNamedIndividual): valueIri = value.getIRI() valueNode = self.findNode(valueIri, diagram) @@ -5872,16 +7878,6 @@ def drawNegativePropertyAssertion(self, prop, indiv, value, diagram, x, y): if propDrawn: - if notDrawn: - pass - - else: - - x = propNode.pos().x() + 50 - y = propNode.pos().y() + 50 - notNode = self.drawObjComplementOf(prop, diagram, x, y) - notDrawn = True - if indivDrawn: if valueDrawn: @@ -5892,14 +7888,16 @@ def drawNegativePropertyAssertion(self, prop, indiv, value, diagram, x, y): if self.isAtomic(value): - x = indivNode.pos().x() - y = indivNode.pos().y() - 150 + x = propNode.pos().x() + propNode.width()/2 + 50 + y = propNode.pos().y() + propNode.height()/2 + 50 valueNode = self.createNode(value, diagram, x, y) valueDrawn = True + else: - x = indivNode.pos().x() - y = indivNode.pos().y() - 150 - valueNode = self.draw(value, diagram) + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(value, diagram, x, y) + valueNode = res[0] valueDrawn = True else: @@ -5908,43 +7906,47 @@ def drawNegativePropertyAssertion(self, prop, indiv, value, diagram, x, y): if self.isAtomic(indiv): - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 indivNode = self.createNode(indiv, diagram, x, y) indivDrawn = True else: - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 - indivNode = self.draw(indiv, diagram, x, y) + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(indiv, diagram, x, y) + indivNode = res[0] indivDrawn = True else: if self.isAtomic(value): - x = propNode.pos().x() - 150 - y = propNode.pos().y() - 150 + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 valueNode = self.createNode(value, diagram, x, y) valueDrawn = True + else: - x = propNode.pos().x() - 150 - y = propNode.pos().y() - 150 - valueNode = self.draw(value, diagram, x, y) + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(value, diagram, x, y) + valueNode = res[0] valueDrawn = True if self.isAtomic(indiv): - x = propNode.pos().x() - y = propNode.pos().y() - 150 + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 indivNode = self.createNode(indiv, diagram, x, y) indivDrawn = True else: - x = propNode.pos().x() - y = propNode.pos().y() - 150 - indivNode = self.draw(indiv, diagram, x, y) + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(indiv, diagram, x, y) + indivNode = res[0] indivDrawn = True else: @@ -5956,16 +7958,20 @@ def drawNegativePropertyAssertion(self, prop, indiv, value, diagram, x, y): y = indivNode.pos().y() + 150 propNode = self.createNode(prop, diagram, x, y) propDrawn = True - - notNode = self.drawObjComplementOf(prop, diagram, x+50, y+50) - notDrawn = True + x = indivNode.pos().x() + propNode.width()/2 + 50 + y = indivNode.pos().y() - propNode.height()/2 - 50 + propNode.setPos(x, y) else: - propNode = self.draw(prop, diagram, x, y) - propDrawn = True - notNode = self.drawObjComplementOf(prop, diagram, x+50, y+50) - notDrawn = True + x = indivNode.pos().x() + y = indivNode.pos().y() + 150 + res = self.draw(prop, diagram, x, y) + propNode = res[0] + propDrawn = True + x = indivNode.pos().x() + propNode.width() / 2 + 50 + y = indivNode.pos().y() - propNode.height() / 2 - 50 + propNode.setPos(x, y) if valueDrawn: @@ -5975,109 +7981,112 @@ def drawNegativePropertyAssertion(self, prop, indiv, value, diagram, x, y): if self.isAtomic(value): - x = indivNode.pos().x() - y = indivNode.pos().y() - 150 + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 valueNode = self.createNode(value, diagram, x, y) valueDrawn = True else: - - x = indivNode.pos().x() - y = indivNode.pos().y() - 150 - valueNode = self.draw(value, diagram, x, y) + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(value, diagram, x, y) + valueNode = res[0] valueDrawn = True else: if valueDrawn: + if self.isAtomic(prop): + + x = indivNode.pos().x() + y = indivNode.pos().y() + 150 + propNode = self.createNode(prop, diagram, x, y) + propDrawn = True + x = valueNode.pos().x() - propNode.width() / 2 - 50 + y = valueNode.pos().y() - propNode.height() / 2 - 50 + propNode.setPos(x, y) + + else: + + x = indivNode.pos().x() + y = indivNode.pos().y() + 150 + res = self.draw(prop, diagram, x, y) + propNode = res[0] + x = valueNode.pos().x() - propNode.width() / 2 - 50 + y = valueNode.pos().y() - propNode.height() / 2 - 50 + propNode.setPos(x, y) + if self.isAtomic(indiv): - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 indivNode = self.createNode(indiv, diagram, x, y) indivDrawn = True else: + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(indiv, diagram, x, y) + indivNode = res[0] + indivDrawn = True - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 - indivNode = self.draw(indiv, diagram, x, y) - indivDrawn = True + else: if self.isAtomic(prop): - x = indivNode.pos().x() - y = indivNode.pos().y() + 150 + x = x + y = y propNode = self.createNode(prop, diagram, x, y) + #print(propNode) propDrawn = True - notNode = self.drawObjComplementOf(prop, diagram, x+50, y+50) - notDrawn = True - else: - x = indivNode.pos().x() - y = indivNode.pos().y() + 150 - propNode = self.draw(prop, diagram, x, y) - notNode = self.drawObjComplementOf(prop, diagram, x+50, y+50) - notDrawn = True - - else: + x = x + y = y + res = self.draw(prop, diagram, x, y) + propNode = res[0] + propDrawn = True if self.isAtomic(value): - x = x - y = y + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 valueNode = self.createNode(value, diagram, x, y) valueDrawn = True else: - x = x - y = y - valueNode = self.draw(value, diagram, x, y) + x = propNode.pos().x() + propNode.width() / 2 + 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(value, diagram, x, y) + valueNode = res[0] valueDrawn = True if self.isAtomic(indiv): - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 indivNode = self.createNode(indiv, diagram, x, y) + #print(indivNode) indivDrawn = True else: - x = valueNode.pos().x() - y = valueNode.pos().y() - 150 - indivNode = self.draw(indiv, diagram, x, y) + x = propNode.pos().x() - propNode.width() / 2 - 50 + y = propNode.pos().y() + propNode.height() / 2 + 50 + res = self.draw(indiv, diagram, x, y) + indivNode = res[0] indivDrawn = True - if self.isAtomic(prop): - - x = indivNode.pos().x() - y = indivNode.pos().y() + 150 - propNode = self.createNode(prop, diagram, x, y) - propDrawn = True - - notNode = self.drawObjComplementOf(prop, diagram, x+50, y+50) - notDrawn = True - - else: - - x = indivNode.pos().x() - y = indivNode.pos().y() + 150 - propNode = self.draw(prop, diagram, x, y) - propDrawn = True - - notNode = self.drawObjComplementOf(prop, diagram, x+50, y+50) - notDrawn = True + notNode = self.drawObjComplementOf(propNode, diagram, propNode.x(), propNode.y()) instanceNode = PropertyAssertionNode(diagram=diagram) - x = (indivNode.pos().x() + propNode.pos().x()) / 2 - y = propNode.pos().x() + x = propNode.pos().x() + y = propNode.pos().y() + propNode.width()/2 + 50 starting_y = y while not self.isEmpty(x, y, diagram): - y = y - 30 + y = y + 125 if abs(starting_y - y) > 1000: y = starting_y break @@ -6095,18 +8104,57 @@ def drawNegativePropertyAssertion(self, prop, indiv, value, diagram, x, y): instanceNode.addEdge(input2) self.session.undostack.push(CommandEdgeAdd(diagram, input2)) + input3 = diagram.factory.create(Item.InputEdge, source=propNode, target=notNode) + propNode.addEdge(input3) + notNode.addEdge(input3) + self.session.undostack.push(CommandEdgeAdd(diagram, input3)) isa = diagram.factory.create(Item.MembershipEdge, source=instanceNode, target=notNode) instanceNode.addEdge(isa) - notNode.addEdge(isa) + propNode.addEdge(isa) self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - input3 = diagram.factory.create(Item.InputEdge, source=propNode, target=notNode) - propNode.addEdge(input3) - notNode.addEdge(input3) - self.session.undostack.push(CommandEdgeAdd(diagram, input3)) + x = propNode.pos().x() + 65 + y1 = instanceNode.pos().y() + y2 = propNode.pos().y() + + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + + x1 = instanceNode.pos().x() + y1 = instanceNode.pos().y() - 40 + x2 = indivNode.pos().x() + 70 + y2 = y1 + x3 = x2 + y3 = indivNode.pos().y() - return instanceNode + bp3 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp1 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input1, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input1, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input1, 2, bp3)) + + x1 = instanceNode.pos().x() + y1 = instanceNode.pos().y() - 40 + x2 = valueNode.pos().x() - 70 + y2 = y1 + x3 = x2 + y3 = valueNode.pos().y() + + bp3 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp1 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input2, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input2, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input2, 2, bp3)) + + return [instanceNode] def drawDiffIndiv(self, individuals, diagram, x, y): @@ -6121,7 +8169,7 @@ def drawDiffIndiv(self, individuals, diagram, x, y): nodes.append(node) if len(nodes) == 0: - starting_x = x - 150 + starting_x = x - 125 starting_y = y if len(nodes) > 0: @@ -6133,13 +8181,14 @@ def drawDiffIndiv(self, individuals, diagram, x, y): # if not i.isType(self.EntityType.NAMED_INDIVIDUAL): if not self.isAtomic(i): - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x starting_y = y - n = self.draw(i, diagram, x, y) + res = self.draw(i, diagram, x, y) + n = res[0] nodes.append(n) else: @@ -6149,7 +8198,7 @@ def drawDiffIndiv(self, individuals, diagram, x, y): node = self.findNode(iri, diagram) if node == 'null': - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x @@ -6168,7 +8217,61 @@ def drawDiffIndiv(self, individuals, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, different)) - return different + if node0.pos().y() == node1.pos().y() and abs(node0.pos().x() - node1.pos().x()) < 130: + pass + + elif node0.pos().x() == node1.pos().x(): + + x1 = node0.pos().x() + 70 + y1 = node0.pos().y() + y2 = node1.pos().y() + + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x1, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, different, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, different, 1, bp2)) + + elif node0.pos().y() == node1.pos().y(): + + x1 = node0.pos().x() + 68 + y1 = node0.pos().y() + x2 = x1 + y2 = node0.pos().y() - 35 + x3 = node1.pos().x() - 70 + y3 = y2 + x4 = x3 + y4 = node1.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, different, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, different, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, different, 2, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, different, 3, bp4)) + + else: + + x1 = node0.pos().x() + 68 + y1 = node0.pos().y() + x2 = x1 + y2 = node1.pos().y() + 35 + x3 = node1.pos().x() + y3 = y2 + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, different, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, different, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, different, 2, bp3)) + + return [different] def drawSameIndiv(self, individuals, diagram, x, y): @@ -6184,7 +8287,7 @@ def drawSameIndiv(self, individuals, diagram, x, y): if len(nodes) == 0: - starting_x = x - 150 + starting_x = x - 125 starting_y = y if len(nodes) > 0: @@ -6196,13 +8299,14 @@ def drawSameIndiv(self, individuals, diagram, x, y): if not self.isAtomic(i): - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x starting_y = y - n = self.draw(i, diagram, x, y) + res = self.draw(i, diagram, x, y) + n = res[0] nodes.append(n) else: @@ -6213,7 +8317,7 @@ def drawSameIndiv(self, individuals, diagram, x, y): if node == 'null': - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x @@ -6232,7 +8336,61 @@ def drawSameIndiv(self, individuals, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, same)) - return same + if node0.pos().y() == node1.pos().y() and abs(node0.pos().x() - node1.pos().x()) < 130: + pass + + elif node0.pos().x() == node1.pos().x(): + + x1 = node0.pos().x() + 70 + y1 = node0.pos().y() + y2 = node1.pos().y() + + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x1, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, same, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, same, 1, bp2)) + + elif node0.pos().y() == node1.pos().y(): + + x1 = node0.pos().x() + 68 + y1 = node0.pos().y() + x2 = x1 + y2 = node0.pos().y() - 35 + x3 = node1.pos().x() - 70 + y3 = y2 + x4 = x3 + y4 = node1.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, same, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, same, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, same, 2, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, same, 3, bp4)) + + else: + + x1 = node0.pos().x() + 68 + y1 = node0.pos().y() + x2 = x1 + y2 = node1.pos().y() + 35 + x3 = node1.pos().x() + y3 = y2 + + bp1 = QtCore.QPointF(x1, y1) + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, same, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, same, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, same, 2, bp3)) + + return [same] def drawDisjointClasses(self, expressions, diagram, x, y): @@ -6256,7 +8414,7 @@ def drawDisjointClasses(self, expressions, diagram, x, y): if len(nodes) == 0: - starting_x = x - 150 + starting_x = x - 125 starting_y = y if len(nodes) > 0: @@ -6268,13 +8426,14 @@ def drawDisjointClasses(self, expressions, diagram, x, y): if not self.isAtomic(ex): - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x starting_y = y - n = self.draw(ex, diagram, x, y) + res = self.draw(ex, diagram, x, y) + n = res[0] nodes.append(n) else: @@ -6286,7 +8445,7 @@ def drawDisjointClasses(self, expressions, diagram, x, y): if node == 'null': - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x @@ -6295,17 +8454,17 @@ def drawDisjointClasses(self, expressions, diagram, x, y): node = self.createNode(ex, diagram, x, y) nodes.append(node) - + fixed = nodes[0] if singletons: toMove = singletons[0] fixed = nodes[0] if nodes[0] != toMove else nodes[1] x_tomove = fixed.pos().x() - y_tomove = fixed.pos().y() -100 + y_tomove = fixed.pos().y() - 125 while not self.isEmpty(x_tomove, y_tomove, diagram): - x_tomove = x_tomove + 100 + x_tomove = x_tomove + 125 if abs(fixed.pos().x() - x_tomove) > 1000: x_tomove = fixed.pos().x() @@ -6316,17 +8475,19 @@ def drawDisjointClasses(self, expressions, diagram, x, y): x_positions = [n.pos().x() for n in nodes] y_positions = [n.pos().y() for n in nodes] - # x_med = sum(x_positions) / len(x_positions) + #x_med = sum(x_positions) / len(x_positions) maxX = max(x_positions) minX = min(x_positions) - x_med = (maxX + minX) / 2 + #x_med = (maxX + minX) / 2 + x_med = fixed.pos().x() + 125 # y_med = sum(y_positions) / len(y_positions) maxY = max(y_positions) minY = min(y_positions) - y_med = (maxY + minY) / 2 + #y_med = (maxY + minY) / 2 + y_med = fixed.pos().y() starting_y = y_med while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 + y_med = y_med - 50 if abs(starting_y - y_med) > 1000: y_med = starting_y break @@ -6342,6 +8503,18 @@ def drawDisjointClasses(self, expressions, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, isa)) + if dis_node.pos().y() != node0.pos().y(): + x = node0.pos().x() + 70 + y1 = node0.pos().y() + y2 = dis_node.pos().y() + + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + + node1 = nodes[1] input = diagram.factory.create(Item.InputEdge, source=node1, target=dis_node) @@ -6349,7 +8522,55 @@ def drawDisjointClasses(self, expressions, diagram, x, y): dis_node.addEdge(input) self.session.undostack.push(CommandEdgeAdd(diagram, input)) - return dis_node + + x1 = dis_node.pos().x() + 65 + y1 = dis_node.pos().y() + bp1 = QtCore.QPointF(x1, y1) + + if dis_node.pos().y() == node1.pos().y(): + x2 = x1 + y2 = dis_node.pos().y() - 30 + + y3 = y2 + x3 = node1.pos().x() - 70 + + x4 = x3 + y4 = node1.pos().y() + + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp4)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 2, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 3, bp1)) + + elif node1.pos().x() == node0.pos().x(): + + x2 = x1 + y2 = node1.pos().y() + bp2 = QtCore.QPointF(x2, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp1)) + + else: + + x2 = x1 + y2 = node1.pos().y() + 40 + + x3 = node1.pos().x() + y3 = y2 + + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 2, bp1)) + + return [dis_node] def drawDisjointUnion(self, classes, classs, diagram, x, y): @@ -6399,7 +8620,8 @@ def drawDisjointUnion(self, classes, classs, diagram, x, y): starting_x = x starting_y = y - n = self.draw(c, diagram, x, y) + res = self.draw(c, diagram, x, y) + n = res[0] nodes.append(n) xN = n.pos().x() @@ -6485,11 +8707,15 @@ def drawDisjointUnion(self, classes, classs, diagram, x, y): else: - cNode = self.draw(classs, diagram) + res = self.draw(classs, diagram) + cNode = res[0] + + x_med = cNode.pos().x() + y_med = cNode.pos().y() + 40 starting_y = y_med while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 + y_med = y_med - 50 if abs(starting_y - y_med) > 1000: y_med = starting_y break @@ -6504,10 +8730,17 @@ def drawDisjointUnion(self, classes, classs, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, input)) + y = dis_node.pos().y() + + bp1 = QtCore.QPointF(n.pos().x(), y) + b1 = CommandEdgeBreakpointAdd(diagram, input, 0, bp1) + + self.session.undostack.push(b1) + equiv = diagram.factory.create(Item.EquivalenceEdge, source=cNode, target=dis_node) self.session.undostack.push(CommandEdgeAdd(diagram, equiv)) - return dis_node + return [dis_node] def drawDisjointDataProperties(self, expressions, diagram, x, y): @@ -6526,8 +8759,8 @@ def drawDisjointDataProperties(self, expressions, diagram, x, y): if len(nodes) == 0: - starting_x = x - 150 - starting_y = y + starting_x = x + starting_y = y - 50 if len(nodes) > 0: @@ -6538,13 +8771,14 @@ def drawDisjointDataProperties(self, expressions, diagram, x, y): if not self.isAtomic(ex): - x = starting_x + 150 - y = starting_y + x = starting_x + y = starting_y + 50 starting_x = x starting_y = y - n = self.draw(ex, diagram, x, y) + res = self.draw(ex, diagram, x, y) + n = res[0] nodes.append(n) xN = n.pos().x() @@ -6560,8 +8794,8 @@ def drawDisjointDataProperties(self, expressions, diagram, x, y): if node == 'null': - x = starting_x + 150 - y = starting_y + x = starting_x + y = starting_y + 50 starting_x = x starting_y = y @@ -6574,41 +8808,89 @@ def drawDisjointDataProperties(self, expressions, diagram, x, y): y = node.pos().y() y_positions.append(y) - # x_med = sum(x_positions) / len(x_positions) - maxX = max(x_positions) - minX = min(x_positions) - x_med = (maxX - minX) / 2 - # y_med = sum(y_positions) / len(y_positions) - maxY = max(y_positions) - minY = min(y_positions) - y_med = (maxY - minY) / 2 - starting_y = y_med - while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 - if abs(starting_y - y_med) > 1000: - y_med = starting_y - break - dis_node = ComplementNode(diagram=diagram) - dis_node.setPos(x_med, y_med) - self.session.undostack.push(CommandNodeAdd(diagram, dis_node)) + fixed = nodes[0] + # x_med = sum(x_positions) / len(x_positions) + maxX = max(x_positions) + minX = min(x_positions) + # x_med = (maxX + minX) / 2 + x_med = fixed.pos().x() - 180 + # y_med = sum(y_positions) / len(y_positions) + maxY = max(y_positions) + minY = min(y_positions) + # y_med = (maxY + minY) / 2 + y_med = fixed.pos().y() + starting_y = y_med + while not self.isEmpty(x_med, y_med, diagram): + y_med = y_med - 50 + if abs(starting_y - y_med) > 1000: + y_med = starting_y + break + dis_node = ComplementNode(diagram=diagram) + dis_node.setPos(x_med, y_med) + self.session.undostack.push(CommandNodeAdd(diagram, dis_node)) - node0 = nodes[0] + node0 = nodes[0] - isa = diagram.factory.create(Item.InclusionEdge, source=node0, target=dis_node) - node0.addEdge(isa) - dis_node.addEdge(isa) + isa = diagram.factory.create(Item.InclusionEdge, source=node0, target=dis_node) + node0.addEdge(isa) + dis_node.addEdge(isa) - self.session.undostack.push(CommandEdgeAdd(diagram, isa)) + self.session.undostack.push(CommandEdgeAdd(diagram, isa)) - node1 = nodes[1] + if dis_node.pos().y() != node0.pos().y(): + x = node0.pos().x() - 12 + y1 = node0.pos().y() + y2 = dis_node.pos().y() - input = diagram.factory.create(Item.InputEdge, source=node1, target=dis_node) - node1.addEdge(input) - dis_node.addEdge(input) + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) - self.session.undostack.push(CommandEdgeAdd(diagram, input)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + + node1 = nodes[1] + + input = diagram.factory.create(Item.InputEdge, source=node1, target=dis_node) + node1.addEdge(input) + dis_node.addEdge(input) + + self.session.undostack.push(CommandEdgeAdd(diagram, input)) + + x1 = dis_node.pos().x() + 30 + y1 = dis_node.pos().y() + bp1 = QtCore.QPointF(x1, y1) + + + if node1.pos().x() == node0.pos().x(): - return dis_node + x2 = x1 + y2 = node1.pos().y() + bp2 = QtCore.QPointF(x2, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp1)) + + else: + + x2 = x1 + y2 = node1.pos().y() + 40 + + x3 = node1.pos().x() - 12 + y3 = y2 + + x4 = x3 + y4 = node1.pos().y() + + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp4)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 2, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 3, bp1)) + + return [dis_node] def drawDisjointObjectProperties(self, expressions, diagram, x, y): @@ -6627,7 +8909,7 @@ def drawDisjointObjectProperties(self, expressions, diagram, x, y): if len(nodes) == 0: - starting_x = x - 150 + starting_x = x - 125 starting_y = y if len(nodes) > 0: @@ -6640,9 +8922,10 @@ def drawDisjointObjectProperties(self, expressions, diagram, x, y): if not self.isAtomic(ex): - n = self.draw(ex, diagram, starting_x+150, starting_y) + res = self.draw(ex, diagram, starting_x+125, starting_y) + n = res[0] - starting_x = starting_x+150 + starting_x = starting_x+125 nodes.append(n) @@ -6660,7 +8943,7 @@ def drawDisjointObjectProperties(self, expressions, diagram, x, y): if node == 'null': - x = starting_x + 150 + x = starting_x + 125 y = starting_y starting_x = x @@ -6675,18 +8958,20 @@ def drawDisjointObjectProperties(self, expressions, diagram, x, y): y = node.pos().y() y_positions.append(y) - - #x_med = sum(x_positions) / len(x_positions) + fixed = nodes[0] + # x_med = sum(x_positions) / len(x_positions) maxX = max(x_positions) minX = min(x_positions) - x_med = (maxX - minX) / 2 - #y_med = sum(y_positions) / len(y_positions) + # x_med = (maxX + minX) / 2 + x_med = fixed.pos().x() + 125 + # y_med = sum(y_positions) / len(y_positions) maxY = max(y_positions) minY = min(y_positions) - y_med = (maxY - minY) / 2 + # y_med = (maxY + minY) / 2 + y_med = fixed.pos().y() starting_y = y_med while not self.isEmpty(x_med, y_med, diagram): - y_med = y_med - 30 + y_med = y_med - 50 if abs(starting_y - y_med) > 1000: y_med = starting_y break @@ -6702,6 +8987,17 @@ def drawDisjointObjectProperties(self, expressions, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, isa)) + if dis_node.pos().y() != node0.pos().y(): + x = node0.pos().x() + 70 + y1 = node0.pos().y() + y2 = dis_node.pos().y() + + bp1 = QtCore.QPointF(x, y1) + bp2 = QtCore.QPointF(x, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + node1 = nodes[1] input = diagram.factory.create(Item.InputEdge, source=node1, target=dis_node) @@ -6710,18 +9006,73 @@ def drawDisjointObjectProperties(self, expressions, diagram, x, y): self.session.undostack.push(CommandEdgeAdd(diagram, input)) - return dis_node + x1 = dis_node.pos().x() + 65 + y1 = dis_node.pos().y() + bp1 = QtCore.QPointF(x1, y1) + + if dis_node.pos().y() == node1.pos().y(): + x2 = x1 + y2 = dis_node.pos().y() - 30 + + y3 = y2 + x3 = node1.pos().x() - 70 + + x4 = x3 + y4 = node1.pos().y() + + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + bp4 = QtCore.QPointF(x4, y4) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp4)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 2, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 3, bp1)) + + elif node1.pos().x() == node0.pos().x(): + + x2 = x1 + y2 = node1.pos().y() + bp2 = QtCore.QPointF(x2, y2) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp1)) + + else: + + x2 = x1 + y2 = node1.pos().y() + 40 + + x3 = node1.pos().x() + y3 = y2 + + bp2 = QtCore.QPointF(x2, y2) + bp3 = QtCore.QPointF(x3, y3) + + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 0, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, input, 2, bp1)) + + return [dis_node] # ATOMIC OPERATIONS # def createNode(self, ex, diagram, x, y): # create atomic node: Class, Attribute, Role, Individual, Literal, Datatype # - + move = 70 + if isinstance(ex, self.OWLLiteral): + move = 50 + elif ex.isType(self.EntityType.DATA_PROPERTY): + move = -50 + elif ex.isType(self.EntityType.OBJECT_PROPERTY) or ex.isType(self.EntityType.NAMED_INDIVIDUAL): + move = 125 + elif ex.isType(self.EntityType.CLASS): + move = 250 starting_y = y while not self.isEmpty(x, y, diagram): - y = y + 70 + y = y + move if abs(starting_y - y) > 1000: y = starting_y @@ -7098,18 +9449,18 @@ def restrictionPos(self, restriction, source, scene): size = Diagram.GridSize offsets = ( - QtCore.QPointF(snapF(+source.width() / 2 + 70, size), 0), - QtCore.QPointF(snapF(-source.width() / 2 - 70, size), 0), - QtCore.QPointF(0, snapF(-source.height() / 2 - 70, size)), - QtCore.QPointF(0, snapF(+source.height() / 2 + 70, size)), - QtCore.QPointF(snapF(-source.width() / 2 - 70, size), - snapF(-source.height() / 2 - 70, size)), - QtCore.QPointF(snapF(+source.width() / 2 + 70, size), - snapF(-source.height() / 2 - 70, size)), - QtCore.QPointF(snapF(-source.width() / 2 - 70, size), - snapF(+source.height() / 2 + 70, size)), - QtCore.QPointF(snapF(+source.width() / 2 + 70, size), - snapF(+source.height() / 2 + 70, size)), + QtCore.QPointF(snapF(+source.width() / 2 + 50, size), 0), + QtCore.QPointF(snapF(-source.width() / 2 - 50, size), 0), + QtCore.QPointF(0, snapF(-source.height() / 2 - 50, size)), + QtCore.QPointF(0, snapF(+source.height() / 2 + 50, size)), + QtCore.QPointF(snapF(-source.width() / 2 - 50, size), + snapF(-source.height() / 2 - 50, size)), + QtCore.QPointF(snapF(+source.width() / 2 + 50, size), + snapF(-source.height() / 2 - 50, size)), + QtCore.QPointF(snapF(-source.width() / 2 - 50, size), + snapF(+source.height() / 2 + 50, size)), + QtCore.QPointF(snapF(+source.width() / 2 + 50, size), + snapF(+source.height() / 2 + 50, size)), ) pos = source.pos() + offsets[0] num = sys.maxsize @@ -7229,6 +9580,101 @@ def addAnnotationAssertions(self, iri): self.session.undostack.push( CommandIRIAddAnnotationAssertion(self.project, iri, annotationAss)) + def addBreakpoints(self, diagram, propNode, restrNode, domainNode, isa): + + bps = [] + + if propNode.pos().x() == domainNode.pos().x(): + if restrNode.pos().x() > domainNode.pos().x(): + # x = restrNode.pos().x() + 40 + x = domainNode.pos().x() + 68 + else: + # x = restrNode.pos().x() - 40 + x = domainNode.pos().x() - 68 + + y1 = restrNode.pos().y() + y2 = domainNode.pos().y() + + bp1 = QtCore.QPointF(x, y1) + bps.append(bp1) + + bp2 = QtCore.QPointF(x, y2) + bps.append(bp2) + + if isa: + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + + elif restrNode.pos().y() == domainNode.pos().y(): + + if restrNode.pos().x() > domainNode.pos().x(): + # x = restrNode.pos().x() + 40 + x = restrNode.pos().x() + 30 + else: + # x = restrNode.pos().x() - 40 + x = restrNode.pos().x() - 30 + + y1 = restrNode.pos().y() + y2 = restrNode.pos().y() - 40 + x3 = domainNode.pos().x() + y3 = y2 + + bp1 = QtCore.QPointF(x, y1) + bps.append(bp1) + + bp2 = QtCore.QPointF(x, y2) + bps.append(bp2) + + bp3 = QtCore.QPointF(x3, y3) + bps.append(bp3) + + if isa: + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 2, bp3)) + + elif propNode.pos().x() != domainNode.pos().x() and restrNode.pos().y() != domainNode.pos().y(): + + if restrNode.pos().x() > propNode.pos().x(): + x1 = restrNode.pos().x() + 30 + + else: + x1 = restrNode.pos().x() - 30 + + y1 = restrNode.pos().y() + x2 = x1 + # y2 = restrNode.pos().y() - 28 + y2 = restrNode.pos().y() - 40 + if restrNode.pos().y() != propNode.pos().y(): + if restrNode.pos().y() > propNode.pos().y(): + y2 = restrNode.pos().y() - 30 + else: + y2 = restrNode.pos().y() + 40 + x3 = domainNode.pos().x() + 70 + y3 = y2 + x4 = x3 + y4 = domainNode.pos().y() + + bp1 = QtCore.QPointF(x1, y1) + bps.append(bp1) + + bp2 = QtCore.QPointF(x2, y2) + bps.append(bp2) + + bp3 = QtCore.QPointF(x3, y3) + bps.append(bp3) + + bp4 = QtCore.QPointF(x4, y4) + bps.append(bp4) + + if isa: + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 0, bp1)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 1, bp2)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 2, bp3)) + self.session.undostack.push(CommandEdgeBreakpointAdd(diagram, isa, 3, bp4)) + + return bps + class DiagramPropertiesForm(NewDiagramForm): """