Skip to content

Commit

Permalink
modularized package contents
Browse files Browse the repository at this point in the history
  • Loading branch information
capsulecorplab committed Jan 21, 2019
1 parent c2e0709 commit fbfd43a
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 224 deletions.
2 changes: 1 addition & 1 deletion sysml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sysml.element import *
from sysml.elements import *
from sysml.system import *

__version__ = "0.1.0"
4 changes: 4 additions & 0 deletions sysml/elements/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from sysml.elements.structure import *
from sysml.elements.behavior import *
from sysml.elements.requirements import *
from sysml.elements.parametrics import *
85 changes: 85 additions & 0 deletions sysml/elements/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""
The `element.py` module contains all model elements that are valid for use by
the `model` class
---------
Model elements are the building blocks that make up SysML
"""

import uuid as _uuid
from abc import ABC as _ABC
from abc import abstractproperty as _abstractproperty
from typing import Optional


class ModelElement(_ABC):
"""Abstract base class for all model elements"""

def __init__(self, name: Optional[str] = ""):
if type(name) is str:
self._name = name
else:
raise TypeError

self._uuid = _uuid.uuid1()

def __repr__(self):
return "<{}('{}')>".format(self.__class__.__name__, self.name)

@_abstractproperty
def name(self):
"""Modeler-defined name of model element"""
pass

@property
def stereotype(self):
return "".join(
[
"\xab",
self.__class__.__name__[0].lower(),
self.__class__.__name__[1:],
"\xbb",
]
)

@property
def uuid(self):
return self._uuid


class Dependency(ModelElement):
"""A dependency relationship can be applied between models elements to
indicate that a change in one element, the client, may result in a change
in the other element, the supplier.
Parameters
----------
client : ModelElement
supplier : ModelElement
"""

def __init__(self, client, supplier):
self._client = client
self._supplier = supplier

if not isinstance(client, ModelElement):
raise TypeError
if not isinstance(supplier, ModelElement):
raise TypeError

super().__init__()

@property
def name(self):
return self._name

@property
def supplier(self):
return self._supplier

@property
def client(self):
return self._client
69 changes: 69 additions & 0 deletions sysml/elements/behavior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
The `element.py` module contains all model elements that are valid for use by
the `model` class
---------
Model elements are the building blocks that make up SysML
"""

from sysml.elements.base import ModelElement
from sysml.elements.structure import Block
from collections import OrderedDict as _OrderedDict
from collections import Iterable
from typing import Dict, List, Optional, Union


class StateMachine(ModelElement):
"""This class defines a state"""

def __init__(self):
super().__init__(name)

@property
def name(self):
return self._name


class Activity(ModelElement):
"""This class defines a activity"""

def __init__(self):
super().__init__(name)

@property
def name(self):
return self._name


class Interaction(ModelElement):
"""This class defines an interaction"""

def __init__(
self,
name: Optional[str],
lifelines: Optional[List["Block"]],
messages: Optional["ModelElement"],
):
super().__init__(name)

self._lifelines: "_OrderedDict" = _OrderedDict()
if lifelines is None:
pass
if isinstance(lifelines, Iterable):
for lifeline in lifelines:
if isinstance(lifeline, Block):
self._lifelines[lifeline.name] = lifeline
else:
raise TypeError

@property
def name(self):
return self._name

def add_lifeline(self, lifeline):
if isinstance(lifeline, Block):
self._lifelines[lifeline.name] = lifeline

def remove_lifeline(self, lifeline):
self._lifelines.pop(lifeline.name)
56 changes: 56 additions & 0 deletions sysml/elements/parametrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Parametric are used to express how one or more constraints — specifically,
equations and inequalities — are bound to the properties of a system.
Parametrics support engineering analyses, including performance, reliability,
availability, power, mass, and cost. Parametrics can also be used to support
trade studies of candidate physical architectures.
"""

from sysml.elements.base import ModelElement
from pint import UnitRegistry as _UnitRegistry
from typing import Optional
from pint import UnitRegistry as _UnitRegistry

_u = _UnitRegistry()


class ValueType(ModelElement):
"""This class defines a value type
Parameters
----------
units : str, default None
Notes
-----
String parameter for units must be defined in the UnitRegistry
Example
-------
>>> kesselrun = 12*sysml.ValueType('parsecs')
>>> kesselrun
<ValueType(12, 'parsecs')>
>>> kesselrun.magnitude
12
>>> kesselrun.units
<Unit('parsec')>
>>> kesselrun.to('lightyear')
<ValueType(39.138799173399406, 'light_year')>
"""

def __init__(self, units: Optional["ModelElement"]):
# TODO: Needs to be redesigned to inherit methods of a UnitRegistry
# object while also inheriting from ModelElement

super().__init__(self.name)

@property
def name(self):
return self._name


class ConstraintBlock(ModelElement):
"""This class defines a constraint"""

def __init__(self, name: str = ""):
super().__init__(name)
32 changes: 32 additions & 0 deletions sysml/elements/requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
The `element.py` module contains all model elements that are valid for use by
the `model` class
---------
Model elements are the building blocks that make up SysML
"""

from sysml.elements.base import ModelElement
from typing import Dict, List, Optional, Union


class Requirement(ModelElement):
"""This class defines a requirement"""

def __init__(self, name="", txt="", id=""):
super().__init__(name)

if type(txt) is str:
self.txt = txt
else:
raise TypeError

if type(id) is str:
self._id = id
else:
raise TypeError

@property
def name(self):
return self._name
Loading

0 comments on commit fbfd43a

Please sign in to comment.