-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from iriusrisk/feature/OPT-780
[feature/OPT-780] to dev
- Loading branch information
Showing
31 changed files
with
888 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .strategies.connector.impl import connector_identifier_by_connects, create_connector_by_connects, \ | ||
create_connector_by_line_coordinates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from vsdx import Shape | ||
|
||
from slp_visio.slp_visio.load.strategies.connector.connector_identifier_strategy import ConnectorIdentifierStrategy | ||
|
||
|
||
class ConnectorIdentifier: | ||
|
||
@staticmethod | ||
def is_connector(shape: Shape) -> bool: | ||
for strategy in ConnectorIdentifierStrategy.get_strategies(): | ||
if strategy.is_connector(shape): | ||
return True | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
slp_visio/slp_visio/load/strategies/connector/connector_identifier_strategy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import abc | ||
|
||
from vsdx import Shape | ||
|
||
from slp_visio.slp_visio.load.strategies.strategy import Strategy | ||
|
||
|
||
class ConnectorIdentifierStrategy(Strategy): | ||
""" | ||
Formal Interface to check if a shape is a connector | ||
""" | ||
|
||
@classmethod | ||
def __subclasshook__(cls, subclass): | ||
return ( | ||
hasattr(subclass, 'is_connector') and callable(subclass.process) | ||
or NotImplemented) | ||
|
||
@abc.abstractmethod | ||
def is_connector(self, shape: Shape) -> bool: | ||
"""return True if the Shape is a connector""" | ||
raise NotImplementedError |
24 changes: 24 additions & 0 deletions
24
slp_visio/slp_visio/load/strategies/connector/create_connector_strategy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import abc | ||
from typing import Optional | ||
|
||
from vsdx import Shape | ||
|
||
from slp_visio.slp_visio.load.objects.diagram_objects import DiagramConnector | ||
from slp_visio.slp_visio.load.strategies.strategy import Strategy | ||
|
||
|
||
class CreateConnectorStrategy(Strategy): | ||
""" | ||
Formal Interface to create an OTM Dataflow from a vsdx shape | ||
""" | ||
|
||
@classmethod | ||
def __subclasshook__(cls, subclass): | ||
return ( | ||
hasattr(subclass, 'create_connector') and callable(subclass.process) | ||
or NotImplemented) | ||
|
||
@abc.abstractmethod | ||
def create_connector(self, shape: Shape, components=None) -> Optional[DiagramConnector]: | ||
"""creates the OTM Dataflow from the vsdx shape""" | ||
raise NotImplementedError |
16 changes: 16 additions & 0 deletions
16
slp_visio/slp_visio/load/strategies/connector/impl/connector_identifier_by_connects.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from vsdx import Shape | ||
|
||
from slp_visio.slp_visio.load.strategies.connector.connector_identifier_strategy import ConnectorIdentifierStrategy | ||
|
||
|
||
class ConnectorIdentifierByConnects(ConnectorIdentifierStrategy): | ||
""" | ||
Strategy to know if a shape is a connector | ||
The shape must have connects and each connector_shape_id must match with the shape id | ||
""" | ||
|
||
def is_connector(self, shape: Shape) -> bool: | ||
for connect in shape.connects: | ||
if shape.ID == connect.connector_shape_id: | ||
return True | ||
return False |
56 changes: 56 additions & 0 deletions
56
slp_visio/slp_visio/load/strategies/connector/impl/create_connector_by_connects.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from typing import Optional | ||
|
||
from vsdx import Shape | ||
|
||
from slp_visio.slp_visio.load.objects.diagram_objects import DiagramConnector | ||
from slp_visio.slp_visio.load.strategies.connector.create_connector_strategy import CreateConnectorStrategy | ||
|
||
|
||
class CreateConnectorByConnects(CreateConnectorStrategy): | ||
""" | ||
Strategy to create a connector from the shape connects | ||
""" | ||
|
||
def create_connector(self, shape: Shape, components=None) -> Optional[DiagramConnector]: | ||
connected_shapes = shape.connects | ||
if not self.are_two_different_shapes(connected_shapes): | ||
return None | ||
|
||
if self.is_bidirectional_connector(shape): | ||
return DiagramConnector(shape.ID, connected_shapes[0].shape_id, connected_shapes[1].shape_id, True) | ||
|
||
has_arrow_in_origin = self.connector_has_arrow_in_origin(shape) | ||
|
||
if (not has_arrow_in_origin and self.is_created_from(connected_shapes[0])) \ | ||
or (has_arrow_in_origin and self.is_created_from(connected_shapes[1])): | ||
return DiagramConnector(shape.ID, connected_shapes[0].shape_id, connected_shapes[1].shape_id) | ||
else: | ||
return DiagramConnector(shape.ID, connected_shapes[1].shape_id, connected_shapes[0].shape_id) | ||
|
||
# if it has two shapes connected and is not pointing itself | ||
@staticmethod | ||
def are_two_different_shapes(connected_shapes) -> bool: | ||
if len(connected_shapes) < 2: | ||
return False | ||
if connected_shapes[0].shape_id == connected_shapes[1].shape_id: | ||
return False | ||
return True | ||
|
||
# if its master name includes 'Double Arrow' or has arrows defined in both ends | ||
@staticmethod | ||
def is_bidirectional_connector(shape) -> bool: | ||
if shape.master_page.name is not None and 'Double Arrow' in shape.master_page.name: | ||
return True | ||
for arrow_value in [shape.cell_value(att) for att in ['BeginArrow', 'EndArrow']]: | ||
if arrow_value is None or not str(arrow_value).isnumeric() or arrow_value == '0': | ||
return False | ||
return True | ||
|
||
@staticmethod | ||
def connector_has_arrow_in_origin(shape) -> bool: | ||
begin_arrow_value = shape.cell_value('BeginArrow') | ||
return begin_arrow_value is not None and str(begin_arrow_value).isnumeric() and begin_arrow_value != '0' | ||
|
||
@staticmethod | ||
def is_created_from(connector) -> bool: | ||
return connector.from_rel == 'BeginX' |
47 changes: 47 additions & 0 deletions
47
slp_visio/slp_visio/load/strategies/connector/impl/create_connector_by_line_coordinates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Optional | ||
|
||
from shapely.geometry import Point | ||
from vsdx import Shape | ||
|
||
from slp_visio.slp_visio.load.objects.diagram_objects import DiagramConnector | ||
from slp_visio.slp_visio.load.representation.simple_component_representer import SimpleComponentRepresenter | ||
from slp_visio.slp_visio.load.strategies.connector.create_connector_strategy import CreateConnectorStrategy | ||
|
||
|
||
class CreateConnectorByLineCoordinates(CreateConnectorStrategy): | ||
""" | ||
Strategy to create a connector from the shape begin and end coordinates | ||
We search a component shape that touch the beginning line coordinates of the given shape connector | ||
We search a component shape that touch the ending line coordinates of the given shape connector | ||
If we find both shapes at the end and at the beginning of the line, we create the connector | ||
""" | ||
|
||
def __init__(self): | ||
self.tolerance = 0.09 | ||
self.representer: SimpleComponentRepresenter() = SimpleComponentRepresenter() | ||
|
||
def create_connector(self, shape: Shape, components=None) -> Optional[DiagramConnector]: | ||
if not shape.begin_x or not shape.begin_y or not shape.end_x or not shape.end_y: | ||
return None | ||
begin_line = Point(shape.begin_x, shape.begin_y) | ||
end_line = Point(shape.end_x, shape.end_y) | ||
if not begin_line or not end_line: | ||
return None | ||
|
||
if not components: | ||
return None | ||
origin = self.__match_component(begin_line, components) | ||
target = self.__match_component(end_line, components) | ||
|
||
if not origin or not target: | ||
return None | ||
|
||
return DiagramConnector(shape.ID, origin, target, name=shape.text) | ||
|
||
def __match_component(self, point, components): | ||
for component in components: | ||
polygon = self.representer.build_representation(component) | ||
distance = polygon.exterior.distance(point) | ||
if round(distance, 2) <= self.tolerance: | ||
return component.ID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import abc | ||
|
||
|
||
class Strategy(metaclass=abc.ABCMeta): | ||
""" | ||
Formal Interface to build a strategy | ||
""" | ||
|
||
@classmethod | ||
def get_strategies(cls): | ||
return [obj() for obj in cls.__get_subclasses()] | ||
|
||
@classmethod | ||
def __get_subclasses(cls): | ||
for subclass in cls.__subclasses__(): | ||
yield subclass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .strategies.connector.impl import connector_identifier_by_lucid_line_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Oops, something went wrong.