Skip to content

Commit

Permalink
Merge pull request #501 from gaphor/gaphas-3
Browse files Browse the repository at this point in the history
Gaphas 3 support
  • Loading branch information
amolenaar committed Dec 19, 2020
2 parents 49d02fa + ed88c06 commit 2e046f5
Show file tree
Hide file tree
Showing 128 changed files with 1,528 additions and 1,125 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
timeout-minutes: 10
if: "!contains(github.event.head_commit.message, 'skip ci')"
steps:
Expand All @@ -24,7 +24,7 @@ jobs:

linux:
needs: lint
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
timeout-minutes: 30
if: "!contains(github.event.head_commit.message, 'skip ci')"
steps:
Expand All @@ -37,8 +37,7 @@ jobs:
uses: actions/cache@v2.1.3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: ${{ runner.os }}-poetry-
key: ${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-20.04
- name: Install Dependencies
run: >
sudo apt-get update -q && sudo apt-get install
Expand Down
5 changes: 3 additions & 2 deletions docs/conf.py
Expand Up @@ -14,6 +14,7 @@
import sys
from datetime import date
from pathlib import Path
from typing import Dict, List

from recommonmark.transform import AutoStructify
from tomlkit import parse
Expand Down Expand Up @@ -102,7 +103,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = []
html_static_path: List[str] = []

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -123,7 +124,7 @@

# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
latex_elements: Dict[str, str] = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
Expand Down
4 changes: 2 additions & 2 deletions gaphor/SysML/blocks/block.py
Expand Up @@ -28,8 +28,8 @@

@represents(Block)
class BlockItem(ElementPresentation[Block], Classified):
def __init__(self, id=None, model=None):
super().__init__(id, model)
def __init__(self, connections, id=None, model=None):
super().__init__(connections, id, model)

self.watch("show_stereotypes", self.update_shapes).watch(
"show_parts", self.update_shapes
Expand Down
14 changes: 7 additions & 7 deletions gaphor/SysML/blocks/blockstoolbox.py
Expand Up @@ -5,7 +5,7 @@
from gaphor import UML
from gaphor.core import gettext
from gaphor.diagram.diagramtoolbox import ToolDef, ToolSection, namespace_config
from gaphor.diagram.diagramtools import PlacementTool
from gaphor.diagram.diagramtools import new_item_factory
from gaphor.SysML import diagramitems as sysml_items
from gaphor.SysML import sysml
from gaphor.UML import diagramitems as uml_items
Expand All @@ -22,7 +22,7 @@
gettext("Block"),
"gaphor-block-symbolic",
"l",
item_factory=PlacementTool.new_item_factory(
new_item_factory(
sysml_items.BlockItem, sysml.Block, config_func=namespace_config
),
handle_index=SE,
Expand All @@ -32,7 +32,7 @@
gettext("Package"),
"gaphor-package-symbolic",
"p",
PlacementTool.new_item_factory(
new_item_factory(
uml_items.PackageItem,
UML.Package,
config_func=namespace_config,
Expand All @@ -44,7 +44,7 @@
gettext("Composite Association"),
"gaphor-composite-association-symbolic",
"<Shift>Z",
PlacementTool.new_item_factory(
new_item_factory(
uml_items.AssociationItem,
UML.Association,
config_func=composite_association_config,
Expand All @@ -55,7 +55,7 @@
gettext("Shared Association"),
"gaphor-shared-association-symbolic",
"<Shift>Q",
PlacementTool.new_item_factory(
new_item_factory(
uml_items.AssociationItem,
UML.Association,
config_func=shared_association_config,
Expand All @@ -66,14 +66,14 @@
gettext("Association"),
"gaphor-association-symbolic",
"<Shift>A",
PlacementTool.new_item_factory(uml_items.AssociationItem),
new_item_factory(uml_items.AssociationItem),
),
ToolDef(
"toolbox-generalization",
gettext("Generalization"),
"gaphor-generalization-symbolic",
"<Shift>G",
PlacementTool.new_item_factory(uml_items.GeneralizationItem),
new_item_factory(uml_items.GeneralizationItem),
),
),
)
4 changes: 2 additions & 2 deletions gaphor/SysML/blocks/property.py
Expand Up @@ -14,8 +14,8 @@

@represents(UML.Property)
class PropertyItem(ElementPresentation[UML.Property], Named):
def __init__(self, id=None, model=None):
super().__init__(id, model)
def __init__(self, connections, id=None, model=None):
super().__init__(connections, id, model)

self.watch("show_stereotypes", self.update_shapes)
self.watch("subject[Property].name")
Expand Down
62 changes: 40 additions & 22 deletions gaphor/SysML/blocks/proxyport.py
Expand Up @@ -3,7 +3,7 @@

from gaphas.connector import Handle, LinePort, Position
from gaphas.geometry import Rectangle, distance_rectangle_point
from gaphas.item import Item
from gaphas.matrix import Matrix

from gaphor.core.modeling import Presentation
from gaphor.diagram.presentation import Named, postload_connect
Expand Down Expand Up @@ -33,26 +33,45 @@ def text_position(position):


@represents(sysml.ProxyPort)
class ProxyPortItem(Presentation[sysml.ProxyPort], Item, Named):
def __init__(self, id=None, model=None):
super().__init__(id, model)
class ProxyPortItem(Presentation[sysml.ProxyPort], Named):
def __init__(self, connections, id=None, model=None):
super().__init__(id=id, model=model)
self._matrix = Matrix()
self._matrix_i2c = Matrix()
self._connections = connections

h1 = Handle(connectable=True)
self._handles.append(h1)
self._handles = [h1]

d = self.dimensions()
top_left = Position((d.x, d.y))
top_right = Position((d.x1, d.y))
bottom_right = Position((d.x1, d.y1))
bottom_left = Position((d.x, d.y1))
self._ports.append(LinePort(top_left, top_right))
self._ports.append(LinePort(top_right, bottom_right))
self._ports.append(LinePort(bottom_right, bottom_left))
self._ports.append(LinePort(bottom_left, top_left))
top_left = Position(d.x, d.y)
top_right = Position(d.x1, d.y)
bottom_right = Position(d.x1, d.y1)
bottom_left = Position(d.x, d.y1)
self._ports = [
LinePort(top_left, top_right),
LinePort(top_right, bottom_right),
LinePort(bottom_right, bottom_left),
LinePort(bottom_left, top_left),
]

self._last_connected_side = None
self.watch("subject[NamedElement].name")

@property
def matrix(self) -> Matrix:
return self._matrix

@property
def matrix_i2c(self) -> Matrix:
return self._matrix_i2c

def handles(self):
return self._handles

def ports(self):
return self._ports

def update_shapes(self):
self.shape = IconBox(
Box(style={"background-color": (1, 1, 1, 1)}, draw=draw_border),
Expand All @@ -63,18 +82,15 @@ def update_shapes(self):
self.request_update()

def connected_side(self) -> Optional[str]:
if not self.canvas:
return None

cinfo = self.canvas.get_connection(self._handles[0])
cinfo = self._connections.get_connection(self._handles[0])

return cinfo.connected.port_side(cinfo.port) if cinfo else None

def dimensions(self):
return Rectangle(-8, -8, 16, 16)

def point(self, pos):
return distance_rectangle_point(self.dimensions(), pos)
def point(self, x, y):
return distance_rectangle_point(self.dimensions(), (x, y))

def setup_canvas(self):
super().setup_canvas()
Expand All @@ -89,16 +105,15 @@ def teardown_canvas(self):
def save(self, save_func):
save_func("matrix", tuple(self.matrix))

assert self.canvas
c = self.canvas.get_connection(self.handles()[0])
c = self._connections.get_connection(self.handles()[0])
if c:
save_func("connection", c.connected)

super().save(save_func)

def load(self, name, value):
if name == "matrix":
self.matrix = ast.literal_eval(value)
self.matrix.set(*ast.literal_eval(value))
elif name == "connection":
self._load_connection = value
else:
Expand All @@ -120,5 +135,8 @@ def pre_update(self, context):

self.shape.size(context)

def post_update(self, context):
pass

def draw(self, context):
self.shape.draw(context, self.dimensions())
16 changes: 16 additions & 0 deletions gaphor/SysML/blocks/tests/test_proxy_port.py
@@ -0,0 +1,16 @@
import pytest
from gaphas import Item
from gaphas.connections import Connections

from gaphor.SysML.blocks.proxyport import ProxyPortItem


@pytest.fixture
def connections():
return Connections()


def test_proxy_port_item_conforms_to_item_protocol(connections):
item = ProxyPortItem(connections)

assert isinstance(item, Item)
4 changes: 2 additions & 2 deletions gaphor/SysML/requirements/relationships.py
Expand Up @@ -9,8 +9,8 @@ class DirectedRelationshipPropertyPathItem(LinePresentation, Named):

relation_type = ""

def __init__(self, id=None, model=None):
super().__init__(id, model, style={"dash-style": (7.0, 5.0)})
def __init__(self, connections, id=None, model=None):
super().__init__(connections, id, model, style={"dash-style": (7.0, 5.0)})

self.shape_middle = Box(
Text(
Expand Down
4 changes: 2 additions & 2 deletions gaphor/SysML/requirements/requirement.py
Expand Up @@ -29,8 +29,8 @@

@represents(Requirement)
class RequirementItem(ElementPresentation[Requirement], Classified):
def __init__(self, id=None, model=None):
super().__init__(id, model)
def __init__(self, connections, id=None, model=None):
super().__init__(connections, id, model)

self.watch("show_stereotypes", self.update_shapes).watch(
"show_attributes", self.update_shapes
Expand Down
14 changes: 7 additions & 7 deletions gaphor/SysML/requirements/requirementstoolbox.py
Expand Up @@ -4,7 +4,7 @@

from gaphor.core import gettext
from gaphor.diagram.diagramtoolbox import ToolDef, ToolSection, namespace_config
from gaphor.diagram.diagramtools import PlacementTool
from gaphor.diagram.diagramtools import new_item_factory
from gaphor.SysML import diagramitems as sysml_items
from gaphor.SysML import sysml

Expand All @@ -16,7 +16,7 @@
gettext("Requirement"),
"gaphor-requirement-symbolic",
"r",
item_factory=PlacementTool.new_item_factory(
new_item_factory(
sysml_items.RequirementItem,
sysml.Requirement,
config_func=namespace_config,
Expand All @@ -28,35 +28,35 @@
gettext("Satisfy"),
"gaphor-satisfy-symbolic",
"<Shift>I",
PlacementTool.new_item_factory(sysml_items.SatisfyItem),
new_item_factory(sysml_items.SatisfyItem),
),
ToolDef(
"toolbox-derive-reqt-dependency",
gettext("Derive Reqt"),
"gaphor-derive-symbolic",
"<Shift>D",
PlacementTool.new_item_factory(sysml_items.DeriveReqtItem),
new_item_factory(sysml_items.DeriveReqtItem),
),
ToolDef(
"toolbox-trace-dependency",
gettext("Trace"),
"gaphor-trace-symbolic",
"<Shift>E",
PlacementTool.new_item_factory(sysml_items.TraceItem),
new_item_factory(sysml_items.TraceItem),
),
ToolDef(
"toolbox-refine-dependency",
gettext("Refine"),
"gaphor-refine-symbolic",
"<Shift>N",
PlacementTool.new_item_factory(sysml_items.RefineItem),
new_item_factory(sysml_items.RefineItem),
),
ToolDef(
"toolbox-verify-dependency",
gettext("Verify"),
"gaphor-verify-symbolic",
"<Shift>V",
PlacementTool.new_item_factory(sysml_items.VerifyItem),
new_item_factory(sysml_items.VerifyItem),
),
),
)
8 changes: 4 additions & 4 deletions gaphor/SysML/toolbox.py
Expand Up @@ -9,7 +9,7 @@
general_tools,
namespace_config,
)
from gaphor.diagram.diagramtools import PlacementTool
from gaphor.diagram.diagramtools import new_item_factory
from gaphor.SysML import diagramitems as sysml_items
from gaphor.SysML.blocks.blockstoolbox import blocks
from gaphor.SysML.requirements.requirementstoolbox import requirements
Expand All @@ -27,14 +27,14 @@
gettext("Connector"),
"gaphor-connector-symbolic",
"<Shift>C",
PlacementTool.new_item_factory(uml_items.ConnectorItem),
new_item_factory(uml_items.ConnectorItem),
),
ToolDef(
"toolbox-property",
gettext("Property"),
"gaphor-property-symbolic",
"o",
PlacementTool.new_item_factory(
new_item_factory(
sysml_items.PropertyItem, UML.Property, config_func=namespace_config
),
),
Expand All @@ -43,7 +43,7 @@
gettext("Proxy Port"),
"gaphor-proxyport-symbolic",
"x",
PlacementTool.new_item_factory(sysml_items.ProxyPortItem),
new_item_factory(sysml_items.ProxyPortItem),
),
),
)
Expand Down

0 comments on commit 2e046f5

Please sign in to comment.