Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_with_attribute(self):
self.class_ = self.element_factory.create(UML.Class)
self.attribute = self.element_factory.create(UML.Property)
self.class_.ownedAttribute = self.attribute
profiles = element_factory.lselect(lambda e: e.isKindOf(UML.Profile))
p.Parse(f)
print(p)
try:
self._root_package = self.element_factory.lselect(
lambda e: isinstance(e, UML.Package) and not e.namespace
)[0]
except IndexError:
pass # running as test?
for m in p.modulemethods:
print("ModuleMethod:", m)
# Step 0: create a diagram to put the newly created elements on
self.diagram = self.element_factory.create(UML.Diagram)
self.diagram.name = "New classes"
self.diagram.package = self._root_package
# Step 1: create the classes
for name, clazz in list(p.classlist.items()):
print(type(clazz), dir(clazz))
self._create_class(clazz, name)
# Create generalization relationships:
for name, clazz in list(p.classlist.items()):
self._create_generalization(clazz)
# Create attributes (and associations) on the classes
for name, clazz in list(p.classlist.items()):
self._create_attributes(clazz)
def group(self):
assert self.item.canvas
p = self.parent.subject
model = self.item.model
sp = model.create(UML.ActivityPartition)
self.item.subject = sp
sp.name = "Swimlane"
if p:
p.subpartition = sp
for k in self.item.canvas.get_children(self.item):
sp.subpartition = k.subject
def disconnect(self, handle):
opposite = self.line.opposite(handle)
oct = self.get_connected(opposite)
hct = self.get_connected(handle)
if hct and oct:
logger.debug(f"Disconnecting {hct} and {oct}")
try:
if hct.subject and isinstance(oct.subject, UML.Comment):
del oct.subject.annotatedElement[hct.subject]
elif hct.subject and oct.subject:
del hct.subject.annotatedElement[oct.subject]
except ValueError:
logger.debug(
"Invoked CommentLineElementConnect.disconnect() for nonexistent relationship"
)
super().disconnect(handle)
stock_id = 'gaphor-flow-final-node'
name = 'FlowFinalNode'
type = items.FlowFinalNodeItem
subject_type = UML.FlowFinalNode
register_action(FlowFinalNodePlacementAction)
class DecisionNodePlacementAction(PlacementAction):
id = 'InsertDecisionNode'
label = 'Decision/Merge Node'
tooltip = 'Create a new decision/merge node'
stock_id = 'gaphor-decision-node'
name = 'DecisionNode'
type = items.DecisionNodeItem
subject_type = UML.DecisionNode
register_action(DecisionNodePlacementAction)
class ForkNodePlacementAction(PlacementAction):
id = 'InsertForkNode'
label = 'Fork/Join Node'
tooltip = 'Create a new fork/join node'
stock_id = 'gaphor-fork-node'
name = 'ForkNode'
type = items.ForkNodeItem
# subject_type = UML.ForkNode
subject_type = UML.JoinNode
register_action(ForkNodePlacementAction)
"subject.appliedStereotype", self.update_shapes
).watch(
"subject.appliedStereotype.classifier.name"
).watch(
"subject.appliedStereotype.slot", self.update_shapes
).watch(
"subject.appliedStereotype.slot.definingFeature.name"
).watch(
"subject.appliedStereotype.slot.value", self.update_shapes
).watch(
"subject[Classifier].isAbstract", self.update_shapes
)
attribute_watches(self, "Class")
operation_watches(self, "Class")
show_stereotypes = UML.properties.attribute("show_stereotypes", int)
show_attributes = UML.properties.attribute("show_attributes", int, default=True)
show_operations = UML.properties.attribute("show_operations", int, default=True)
def update_shapes(self, event=None):
def additional_stereotypes():
if isinstance(self.subject, UML.Stereotype):
return ["stereotype"]
elif UML.model.is_metaclass(self.subject):
return ["metaclass"]
else:
return ()
self.shape = Box(
Box(
def update_stereotype(self):
"""
Update the stereotype definitions (text) of this item.
Note, that this method is also called from
ExtensionItem.confirm_connect_handle method.
"""
# by default no stereotype, however check for __stereotype__
# attribute to assign some static stereotype see interfaces,
# use case relationships, package or class for examples
stereotype = getattr(self, "__stereotype__", ())
if stereotype:
stereotype = self.parse_stereotype(stereotype)
# Phew! :] :P
stereotype = UML.model.stereotypes_str(self.subject, stereotype)
self.set_stereotype(stereotype)
# Switch class for self.element Join/Fork depending on the number
# of incoming/outgoing edges.
self.combine_nodes()
def disconnect_subject(self, handle):
super().disconnect_subject(handle)
if self.element.combined:
self.decombine_nodes()
@IConnect.register(ForkNodeItem, FlowItem)
class FlowForkNodeConnect(FlowForkDecisionNodeConnect):
"""Connect Flow to a ForkNode."""
fork_node_cls = UML.ForkNode
join_node_cls = UML.JoinNode
@IConnect.register(DecisionNodeItem, FlowItem)
class FlowDecisionNodeConnect(FlowForkDecisionNodeConnect):
"""Connect Flow to a DecisionNode."""
fork_node_cls = UML.DecisionNode
join_node_cls = UML.MergeNode