Skip to content

Commit

Permalink
first steps towards implementing issue #22. PUMLA macros are now ther…
Browse files Browse the repository at this point in the history
…e for typed interfaces and ports. Tagged values can be applied to ports and interfaces.

TODO:
- extend python parser to read the typed interfaces and ports into the modelrepo, considering also their tagged values.
- adopt user's guide
- adopt modelling guideline with hints to typed interfaces and best practices for dealing with interface variance
- document layout problems of PlantUML for ports
- setup new examples for typed interfaces and ports
  • Loading branch information
DrMarkusVoss committed Feb 23, 2023
1 parent be2d1a2 commit f93f045
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 34 deletions.
63 changes: 63 additions & 0 deletions pumla_macros_global.puml
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ interface "$ifname" as $ifalias
$ifalias $constr $elemalias
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' define a re-usable interface for a re-usable
Expand All @@ -568,6 +569,68 @@ $ifalias $constr $elemalias
PUMLAInterface($ifname, $ifalias, $pum_global_current_rua_alias, $type)
!endprocedure

' ############################################
' ---------------------------------------------
' define a re-usable typed interface and put it on
' the diagram.
!unquoted procedure PUMLATypedInterface($ifname, $iftype, $ifalias, $elemalias, $type="")
!if ($PUMVarShowInterfaces)
!if ($type=="")
!$constr = "--"
!elseif ($type=="in")
!$constr = ")-->"
!elseif ($type=="out")
!$constr = "<--"
!elseif ($type=="inout")
!$constr = "<-->"
!else
!$constr= "--"
!endif
!$typedif_name = $ifname+"\n(" + $iftype + ")"
interface "$typedif_name" as $ifalias
$ifalias $constr $elemalias
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' define a re-usable typed interface for a re-usable
' asset with the given and put it on
' the diagram.
!unquoted procedure PUMLARUATypedInterface($ifname, $iftype, $ifalias, $type="")
PUMLATypedInterface($ifname, $iftype, $ifalias, $pum_global_current_rua_alias, $type)
!endprocedure

' ############################################
' ---------------------------------------------
' define a re-usable input port (needs to be inside an element)
!unquoted procedure PUMLAPortIn($portname, $porttype, $portalias)
!if ($PUMVarShowInterfaces)
!$typedport_name = $portname+"\n(" + $porttype + ")"
portin "$typedport_name" as $portalias
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' define a re-usable output port (needs to be inside an element)
!unquoted procedure PUMLAPortOut($portname, $porttype, $portalias)
!if ($PUMVarShowInterfaces)
!$typedport_name = $portname+"\n(" + $porttype + ")"
portout "$typedport_name" as $portalias
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' define a re-usable port (needs to be inside an element)
!unquoted procedure PUMLAPort($portname, $porttype, $portalias)
!if ($PUMVarShowInterfaces)
!$typedport_name = $portname+"\n(" + $porttype + ")"
port "$typedport_name" as $portalias
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' DEPRECATION: DO NOT USE THIS FUNCTION ANYMORE
Expand Down
12 changes: 11 additions & 1 deletion pumla_tagged_values.puml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PUMLAPutTaggedValues($pum_global_current_rua_alias)
!endprocedure

' put the tagged value table as note to a class
!unquoted procedure PUMLAPutTaggedValuesAsNoteToElement($elalias)
!unquoted procedure PUMLARUAPutTaggedValuesAsNoteToElement($elalias)
!if ($PUMVarShowTaggedValues)
!$nn = "NN_" + $elalias + "_TV"
!global $pum_global_current_rua_tvnote = $nn
Expand All @@ -53,3 +53,13 @@ _TaggedValuesTable($elalias)
end note
!endif
!endprocedure

' put the tagged value table as note to a class
!unquoted procedure PUMLAPutTaggedValuesAsNoteToElement($elalias)
!if ($PUMVarShowTaggedValues)
!$nn = "NN_" + $elalias + "_TV"
note $PUMTaggedValuesNoteToElementAlignment of $elalias #$PUMColorTaggedValues
_TaggedValuesTable($elalias)
end note
!endif
!endprocedure
40 changes: 20 additions & 20 deletions src/pumla/control/cmd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
c4_dynamic_keywords = ["Rel", "Rel_Back", "Rel_Neighbor", "Rel_Back_Neighbor"]

# this is the PlantUML JAR file that will be downloaded to use it for diagram generation
plantuml_jar_download_destiniation = "https://github.com/plantuml/plantuml/releases/download/v1.2022.13/plantuml-1.2022.13.jar"
plantuml_jar_download_destiniation = "https://github.com/plantuml/plantuml/releases/download/v1.2023.1/plantuml-1.2023.1.jar"

def gendiagram(mainpath, inputpuml, outputname, picformat):
pumljar_filename = mainpath + "plantuml-jar/plantuml.jar"
Expand Down Expand Up @@ -383,28 +383,28 @@ def findElementNameAndTypeInText(lines, alias):
# return the found element name
return elem_name, elem_type, elem_stereotypes

def findRelations_old(lines, path, filename):
""" find PUMLA relation definitions in given lines. """
ret_rels = []
for e in lines:
if "PUMLARelation" in e:
s1 = e.replace("PUMLARelation", "")
s2 = s1.strip("()")
s3 = s2.split(",")
s4 = [ix.strip() for ix in s3]
s5 = [ix.strip('"') for ix in s4]

if len(s4)>4:
pr = PUMLARelation(s5[4], s5[0], s5[1], s5[2], s5[3])
pr.setPath(path)
pr.setFilename(filename)
ret_rels.append(pr)

return ret_rels
# def findRelations_old(lines, path, filename):
# """ find PUMLA relation definitions in given lines. """
# ret_rels = []
# for e in lines:
# if "PUMLARelation" in e:
# s1 = e.replace("PUMLARelation", "")
# s2 = s1.strip("()")
# s3 = s2.split(",")
# s4 = [ix.strip() for ix in s3]
# s5 = [ix.strip('"') for ix in s4]
#
# if len(s4)>4:
# pr = PUMLARelation(s5[4], s5[0], s5[1], s5[2], s5[3])
# pr.setPath(path)
# pr.setFilename(filename)
# ret_rels.append(pr)
#
# return ret_rels

def findRelations(lines, path, filename):
""" find PUMLA relation definitions in given lines. """
pattern_pumlarel= r'PUMLARelation\(\s*\"?(\w+)\"?\s*,\s*\"[-<>\.]+\"\s*,\s*\"?(\w+)\"?\s*,\s*\"?(\w+)\"?\s*,\s*\"?(\w+)\"?\s*,\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*\)'
pattern_pumlarel = r'PUMLARelation\(\s*\"?(\w+)\"?\s*,\s*\"[-<>\.]+\"\s*,\s*\"?(\w+)\"?\s*,\s*\"?(\w+)\"?\s*,\s*\"?(\w+)\"?\s*,\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*\)'
pattern_pumlac4rel_gen = r'PUMLAC4Rel(_[UDLR])?\(\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*,\s*\"?(\w+)\"?\s*,\s*\"?(\w+)\"?\s*,\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*(,\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*)?\)'
pattern_pumlac4rel_spec = r'PUMLAC4Rel(_\w+)\(\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*,\s*\"?(\w+)\"?\s*,\s*\"?(\w+)\"?\s*,\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*(,\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*)?\)'
pattern_pumlac4birel_neigh = r'PUMLAC4BiRel_Neighbor\(\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*,\s*\"?(\w+)\"?\s*,\s*\"?(\w+)\"?\s*,\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*(,\s*\"?([\w\s\(\),.;:#/\*\+\[\]\{\}]+)\"?\s*)?\)'
Expand Down
2 changes: 1 addition & 1 deletion test/examples/WeatherStation/CWeather/CWeather.puml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PUMLAFullyInstantiableClass(CWeather, "<<Python>>")

PUMLARUAAddTaggedValue("Vendor", "C Ltd.")

PUMLAPutTaggedValuesAsNoteToElement(CWeather)
PUMLARUAPutTaggedValuesAsNoteToElement(CWeather)

note as ndescr_CWeather
A class managing weather data.
Expand Down
6 changes: 5 additions & 1 deletion test/examples/WeatherStation/cheatSheet.puml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ title Cheat Sheet Example
' on the contents of the model repository
' along with the alias names that you can
' use to access/re-use the elements.
PUMLACheatSheet()
'PUMLACheatSheet()

' there is also a variant showing the
' related tagged values.
PUMLACheatSheetTaggedValues()

' ahh... now I know that the element I need
' has the alias "wirelessUnit"...
Expand Down
6 changes: 5 additions & 1 deletion test/examples/WeatherStation/displayTemp/displayTemp.puml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

PUMLAReUsableAsset("displayTemp", displayTemp, component, "<<block>>") {

PUMLAPort("tempDc", "tempinterface", porttempdc) #orange

PUMLARUAPutTaggedValues()

PUMLARUAInternals() {
Expand All @@ -18,9 +20,11 @@ PUMLAReUsableAsset("displayTemp", displayTemp, component, "<<block>>") {
PUMLAAddTaggedValue(displayTemp, "Vendor", "C Ltd.")
PUMLAAddTaggedValue(displayTemp, "Brightness", "300 Nits")
PUMLAAddTaggedValue(displayTemp, "Arch Level", "1")
PUMLAAddTaggedValue(porttempdc, "Vendor", "C Ltd.")
PUMLAPutTaggedValuesAsNoteToElement(porttempdc)


PUMLAInterface("temp_dC", temp_dC_displayTemp, displayTemp, "in")
PUMLATypedInterface("temp_dC", "hello", temp_dC_displayTemp, displayTemp, "in")

PUMLAInterface("temp_dF", temp_dF_displayTemp, displayTemp, "in")

Expand Down
3 changes: 1 addition & 2 deletions test/examples/WeatherStation/modelrepo_json.puml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
{"name": "**Internal Sequence**", "alias": "internalSequence", "type": "participant", "stereotypes": [], "kind": "dynamic", "parent": "tempSensorA", "instclassalias": "-", "path": "./tempSensorA/", "filename": "internalSequence.puml"},
{"name": "Temperature Sensor B (dC)", "alias": "tempSensorBdC", "type": "component", "stereotypes": ["block"], "kind": "static", "parent": "tempSys", "instclassalias": "-", "path": "./tempSensorBdC/", "filename": "tempSensorBdC.puml", "taggedvalues": [{"tag": "Vendor", "values": ["C Ltd."]},
{"tag": "Arch Level", "values": ["1"]}]},
{"name": "displayTemp", "alias": "displayTemp", "type": "component", "stereotypes": ["block"], "kind": "static", "parent": "tempSys", "instclassalias": "-", "path": "./displayTemp/", "filename": "displayTemp.puml", "taggedvalues": [{"tag": "Vendor", "values": ["C Ltd."]},
{"tag": "Brightness", "values": ["300 Nits"]},
{"name": "displayTemp", "alias": "displayTemp", "type": "component", "stereotypes": ["block"], "kind": "static", "parent": "tempSys", "instclassalias": "-", "path": "./displayTemp/", "filename": "displayTemp.puml", "taggedvalues": [{"tag": "Brightness", "values": ["300 Nits"]},
{"tag": "Arch Level", "values": ["1"]}]},
{"name": "Temp. Converter", "alias": "tempConverter", "type": "component", "stereotypes": ["block"], "kind": "static", "parent": "tempSys", "instclassalias": "-", "path": "./tempConv/", "filename": "tempConverter.puml", "taggedvalues": [{"tag": "Vendor", "values": ["C Ltd."]},
{"tag": "Arch Level", "values": ["1"]}]}]}
Expand Down
2 changes: 1 addition & 1 deletion test/examples/WeatherStation/playground.puml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@startuml
'!include <c4/C4_Container.puml>
!include <c4/C4_Container.puml>
!include pumla_macros.puml

AddElementTag("v1.0", $borderColor="#d73027")
Expand Down
5 changes: 2 additions & 3 deletions test/examples/simple/ports/display/displayTemp.puml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

PUMLAReUsableAsset("displayTemp", displayTemp, component, "<<block>>") {

portin "temp_dC " as temp_dC_displayTemp
portin "temp_dF " as temp_dF_displayTemp
portin "temp_dC\n(hello)" as temp_dC_displayTemp
portin "temp_dF" as temp_dF_displayTemp

PUMLARUAPutTaggedValues()

Expand All @@ -21,7 +21,6 @@ PUMLAReUsableAsset("displayTemp", displayTemp, component, "<<block>>") {
}
}


PUMLAAddTaggedValue(displayTemp, "Vendor", "C Ltd.")
PUMLAAddTaggedValue(displayTemp, "Brightness", "300 Nits")
PUMLAAddTaggedValue(displayTemp, "Arch Level", "1")
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/examples/simple/ports/layout_issues_with_ports_simple1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

@startuml
'left to right direction
left to right direction

component "displayTemp" as displayTemp <<block>> {

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/examples/simple/ports/processing/tempProcessing.puml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
PUMLAReUsableAsset("Temperature Processing", tempProcessing, component, "<<block>>") {
PUMLARUAPutTaggedValues()

portin "temp_dK_raw " as tempProcessing_temp_dK_raw_in
portout "temp_dC_filtered " as tempProcessing_temp_dC_filtered_out
portin "temp_dK_raw" as tempProcessing_temp_dK_raw_in
portout "temp_dC_filtered" as tempProcessing_temp_dC_filtered_out



Expand Down
2 changes: 1 addition & 1 deletion test/examples/simple/ports/sensor/tempSensor.puml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

PUMLAReUsableAsset("Temperature Sensor", tempSensor, component, "<<block>>") {
PUMLARUAPutTaggedValues()
portout "temp_dK_raw " as tempSensor_temp_dK_raw
portout "temp_dK_raw" as tempSensor_temp_dK_raw



Expand Down

0 comments on commit f93f045

Please sign in to comment.