Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if version_lower_than(gaphor_version, (0, 14, 99)):
stereotypes = {}
profile = None
for e in elements.values():
if hasattr(e, 'taggedvalue'):
if not profile:
profile = factory.create(uml2.Profile)
profile.name = 'version 0.15 conversion'
update_elements(profile)
st = stereotypes.get(e.type)
if not st:
st = stereotypes[e.type] = factory.create(uml2.Stereotype)
st.name = 'Tagged'
st.package = profile
update_elements(st)
cl = factory.create(uml2.Class)
cl.name = str(e.type)
cl.package = profile
update_elements(cl)
ext = modelfactory.extend_with_stereotype(factory, cl, st)
update_elements(ext)
for me in ext.memberEnd:
update_elements(me)
# Create instance specification for the stereotype:
instspec = modelfactory.apply_stereotype(factory, e.element, st)
update_elements(instspec)
def create_slot(key, val):
for attr in st.ownedAttribute:
if attr.name == key:
break
else:
class DependencyItem(DiagramLine):
"""
Dependency item represents several types of dependencies, i.e. normal
dependency or usage.
Usually a dependency looks like a dashed line with an arrow head.
The dependency can have a stereotype attached to it, stating the kind of
dependency we're dealing with.
In case of usage dependency connected to folded interface, the line is
drawn as solid line without arrow head.
"""
__uml__ = uml2.Dependency
# do not use issubclass, because issubclass(uml2.Implementation, uml2.Realization)
# we need to be very strict here
__stereotype__ = {
'use': lambda self: self._dependency_type == uml2.Usage,
'realize': lambda self: self._dependency_type == uml2.Realization,
'implements': lambda self: self._dependency_type == uml2.Implementation,
}
def __init__(self, id=None):
DiagramLine.__init__(self, id)
self._dependency_type = uml2.Dependency
self.auto_dependency = True
self._solid = False
'use': lambda self: self._dependency_type == uml2.Usage,
'realize': lambda self: self._dependency_type == uml2.Realization,
def render(self):
"""Render the OperationItem."""
return '{}'.format(self.subject) or ''
class ClassItem(ClassifierItem):
"""This item visualizes a Class instance.
A ClassItem contains two compartments (Compartment): one for
attributes and one for operations. To add and remove such features
the ClassItem implements the CanvasGroupable interface.
Items can be added by callling class.add() and class.remove().
This is used to handle CanvasItems, not UML objects!"""
__uml__ = uml2.Class, uml2.Stereotype
__stereotype__ = {
'stereotype': uml2.Stereotype,
'metaclass': lambda self: (not isinstance(self.subject, uml2.Stereotype)) and hasattr(self.subject, 'extension') and self.subject.extension,
}
__style__ = {
'extra-space': 'compartment',
'abstract-feature-font': 'sans italic 10',
}
def __init__(self, id=None):
"""Constructor. Initialize the ClassItem. This will also call the
ClassifierItem constructor.
The drawing style is set here as well. The class item will create
"""
Canvas is a read gaphas.Canvas, items is a list of parser.canvasitem's
"""
for item in canvasitems:
cls = getattr(items, item.type)
item.element = diagram.create_as(cls, item.id)
canvas.add(item.element, parent=parent)
assert canvas.get_parent(item.element) is parent
create_canvasitems(canvas, item.canvasitems, parent=item.element)
for id, elem in elements.items():
st = update_status_queue()
if st:
yield st
if isinstance(elem, parser.element):
cls = getattr(uml2, elem.type)
# log.debug('Creating UML element for %s (%s)' % (elem, elem.id))
elem.element = factory.create_as(cls, id)
if elem.canvas:
elem.element.canvas.block_updates = True
create_canvasitems(elem.element.canvas, elem.canvas.canvasitems)
elif not isinstance(elem, parser.canvasitem):
raise ValueError('Item with id "%s" and type %s can not be instantiated' % (id, type(elem)))
# load attributes and create references:
for id, elem in elements.items():
st = update_status_queue()
if st:
yield st
# Ensure that all elements have their element instance ready...
assert hasattr(elem, 'element')
@format.register(UML.Slot)
def format_slot(el):
return f'{el.definingFeature.name} = "{el.value}"'
def _create_methods(self, clazz):
for adef in clazz.defs:
op = self.element_factory.create(uml2.Operation)
op.name = adef
clazz.gaphor_class.ownedOperation = op
subset_properties = element_factory.select(lambda e: e.isKindOf(uml2.Property) and e.name in subsets)
(isinstance(value, (list, tuple)) and reference):
save_collection(name, value)
elif reference:
save_reference(name, value)
elif isinstance(value, gaphas.Item):
writer.startElement('item', {'id': value.id,
'type': value.__class__.__name__})
value.save(save_canvasitem)
# save subitems
for child in value.canvas.get_children(value):
save_canvasitem(None, child)
writer.endElement('item')
elif isinstance(value, uml2.Element):
save_reference(name, value)
else:
save_value(name, value)
#
# You should have received a copy of the GNU Library General Public
# along with Gaphor. If not, see .
"""
Action diagram item.
"""
from __future__ import absolute_import
from math import pi
from gaphor.UML import uml2
from gaphor.diagram.nameditem import NamedItem
from gaphor.diagram.style import ALIGN_CENTER, ALIGN_MIDDLE
class ActionItem(NamedItem):
__uml__ = uml2.Action
__style__ = {
'min-size': (50, 30),
'name-align': (ALIGN_CENTER, ALIGN_MIDDLE),
}
def draw(self, context):
"""
Draw action symbol.
"""
super(ActionItem, self).draw(context)
c = context.cairo
d = 15