!include pumla_global_cfg.puml
!include pumla_internal.puml

!$PUMVarShowDescr = %true()
!$PUMVarShowInterfaces = %true()
!$PUMVarShowBody = %true()
!$PUMVarShowBodyInternals = %true()
!$PUMVarShowBodyInternalsDyn = %true()
!$PUMVarShowTaggedValues = %true()
!$PUMVarShowInstantiationRel = %true()
!$PUMVarShowConnections = %true()
!$PUMTaggedValuesNoteToElementAlignment = right

!$internal_finalize_string = ""
!$internal_relations_on_diagram = ""

!$pum_global_element_filter_out_type = ""
!$pum_global_element_filter_in_type = ""

!$pum_global_element_filter_out_stereotype = ""
!$pum_global_element_filter_in_stereotype = ""

!$pum_global_element_filter_out_instclass = ""
!$pum_global_element_filter_in_instclass = ""

!$pum_global_element_filter_out_tv_tag = ""
!$pum_global_element_filter_in_tv_tag = ""

!$pum_global_element_filter_out_tv_value = ""
!$pum_global_element_filter_in_tv_value = ""

!$pum_global_element_filter_out_static = %false()
!$pum_global_element_filter_in_static = %false()

!$pum_global_element_filter_out_dynamic = %false()
!$pum_global_element_filter_in_dynamic = %false()

!$pum_global_current_rua_alias = ""
!$pum_global_current_rua_internals = ""
!$pum_global_current_rua_tvnote = ""
!$pum_global_current_rua_descr = ""

!$pum_global_instance_adder = ""

!$pum_global_error_cnt = 1

' --------------------------------------------
' put an element referenced by path and filename
' by including its file
'
!unquoted procedure _PUMPutElement($folderpath,$filename)
!include $allelems.modelrepopath/%substr($folderpath,2)/$filename
!endprocedure

' --------------------------------------------
' put an element referenced by path and filename
' by including its file using Filters
'
!unquoted procedure _PUMPutElementFiltered($folderpath,$filename)
!if ((_PUMLACheckFilterOutShowElement($el)) && (_PUMLACheckFilterInShowElement($el)))
    !include $allelems.modelrepopath/%substr($folderpath,2)/$filename
!endif
!endprocedure

' --------------------------------------------
' put an element referenced by path and filename
' by including its file
'
!unquoted function _PUMElement($folderpath,$filename)
!$retval = "!include " + $allelems.modelrepopath + "/" + %substr($folderpath,2) + $filename
!return $retval
!endfunction

' ---------------------------------------------


' ############################################
' ---------------------------------------------
' inject child elements for the referenced
' parent element
'
!unquoted procedure PUMLAInjectChildElements($parentalias)
!foreach $el in $allelems.elements
    !if ($el.parent == $parentalias)
        !include $allelems.modelrepopath/%substr($el.path,2)/$el.filename
    !endif
!endfor
!endprocedure

' ############################################
' ---------------------------------------------
' check filter type conditions for the given element.
' return true if the element shall not be
' shown but filtered out.
'
!unquoted function _PUMLACheckFilterOutElementTypeShow($elem)
!local $internal_retval = %false()
!if ($pum_global_element_filter_out_type != "")
    !if ($elem.type == $pum_global_element_filter_out_type)
        !$internal_retval = %true()
    !endif
!endif
!return $internal_retval
!endfunction

' ############################################
' ---------------------------------------------
' check filter stereotype conditions for the given element.
' return true if the element shall not be
' shown but filtered out.
'
!unquoted function _PUMLACheckFilterOutElementStereotypeShow($elem)
!local $internal_retval = %false()
!if ($pum_global_element_filter_out_stereotype != "")
    !foreach $st in $elem.stereotypes
    !if ($st == $pum_global_element_filter_out_stereotype)
        !$internal_retval = %true()
    !endif
    !endfor
!endif
!return $internal_retval
!endfunction

' ############################################
' ---------------------------------------------
' check filter conditions for the given element.
' return false if the element shall not be
' shown but filtered out.
'
!unquoted function _PUMLACheckFilterOutShowElement($elem)
!local $internal_retval = %true()

!if ((_PUMLACheckFilterOutElementTypeShow($elem)) || (_PUMLACheckFilterOutElementStereotypeShow($elem)))
    !$internal_retval = %false()
!endif

!return $internal_retval
!endfunction

' ############################################
' ---------------------------------------------
' check filter conditions for the given element.
' return false if the element shall not be
' shown but filtered out.
'
!unquoted function _PUMLACheckFilterInShowElement($elem)
!local $internal_retval = %true()
!if ($pum_global_element_filter_in_type != "")
    !if ($elem.type != $pum_global_element_filter_in_type)
        !$internal_retval = %false()
    !endif
!endif
!return $internal_retval
!endfunction

' ############################################
' ---------------------------------------------
' put the referenced element onto the diagram
'
!unquoted procedure PUMLAPutElement($elemalias)
!$int_suc = %false()
!foreach $el in $allelems.elements
    !if ($el.alias == $elemalias)
        !if ((_PUMLACheckFilterOutShowElement($el)) && (_PUMLACheckFilterInShowElement($el)))
                _PUMPutElement($el.path,$el.filename)
                !$int_suc = %true()
        !endif
    !endif
!endfor
PUMLAPutElementErrorCheck($int_suc, $elemalias)
!endprocedure


' ############################################
' ---------------------------------------------
' put the referenced element onto the diagram
'
!unquoted procedure PUMLAPutClassElementToCompDiagram($folderpath,$filename)
!if ($el.type == "class")
    !$fn = "NN_" + %substr($el.filename, 0, %strlen($el.filename)-5)
    !if (%not(%variable_exists($fn)))
        !$nn = "NN_" + $fn
        note as $nn #white
        {{
        !include $allelems.modelrepopath/%substr($el.path,2)/$el.filename
        }}
        end note
        %set_variable_value($fn, "%true()")
    !endif
!else
    !include $allelems.modelrepopath/%substr($folderpath,2)/$filename
!endif

!endprocedure

' ############################################

' ---------------------------------------------
' put all static elements within the model repo onto
' the diagram. Mixing of class & component elements
' is enabled by wrapping class elements into notes.
!unquoted procedure PUMLAPutAllElementsMix()
!foreach $el in $allelems.elements
!if ($el.kind == "static")
    !if ($el.type == "class")
        !$fn = "NN_" + %substr($el.filename, 0, %strlen($el.filename)-5)
        !if (%not(%variable_exists($fn)))
            !$nn = "NN_" + $fn
            note as $nn #white
            {{
            !include $allelems.modelrepopath/%substr($el.path,2)/$el.filename
            }}
            end note
            %set_variable_value($fn, "%true()")
        !endif
    !else
        _PUMPutElement($el.path,$el.filename)
    !endif
!endif
!endfor
!endprocedure

' ---------------------------------------------
' put all static elements within the model repo onto
' the diagram. in order to allow class and component
' elements, component elements like [ds] cannot be shown
' therefore, internals are deactivated.
!unquoted procedure PUMLAPutAllElements()
!$old_sbi = %get_variable_value("$PUMVarShowBodyInternals")
!$PUMVarShowBodyInternals = %false()
allowmixing
!foreach $el in $allelems.elements
!if ($el.kind == "static")
    _PUMPutElementFiltered($el.path,$el.filename)
!endif
!endfor
!$PUMVarShowBodyInternals = $old_sbi
!endprocedure

' ---------------------------------------------
' put all classes within the model repo onto
' the diagram
!unquoted procedure PUMLAPutAllClasses()
!foreach $el in $allelems.elements
    !if ($el.type == "class")
        _PUMPutElement($el.path,$el.filename)
    !endif
!endfor
!endprocedure

' ---------------------------------------------
' put all static elements within the model repo onto
' the diagram, that have the given stereotype
!unquoted procedure PUMLAPutAllElementsOfStereotype($st)
!foreach $el in $allelems.elements
!if ($el.kind == "static")
    !foreach $s in $el.stereotypes
        !if ($s == $st)
            _PUMPutElement($el.path,$el.filename)
        !endif
    !endfor
!endif
!endfor
!endprocedure

' ---------------------------------------------
' put all static elements within the model repo onto
' the diagram, that have the given tag/value
!unquoted procedure PUMLAPutAllElementsWithTagValue($tag, $value="")
!foreach $el in $allelems.elements
!if ($el.kind == "static")
    !foreach $tvs in $el.taggedvalues
        !$tv_found = "NO"

        !if ($tvs.tag == $tag)
            !if ($value != "")
                !foreach $v in $tvs.values
                    !if ($v == $value)
                        !$tv_found = "YES"
                    !endif
                !endfor
            !else
                !$tv_found = "YES"
            !endif
            !if ($tv_found == "YES")
                PUMLAPutClassElementToCompDiagram($el.path,$el.filename)
            !endif
        !endif
    !endfor
!endif
!endfor
!endprocedure

' ---------------------------------------------
' remove all instances, meaning elements with
' stereotype instance
!unquoted procedure PUMLARemoveAllElementsOfStereotype($st)
!foreach $el in $allelems.elements
    !foreach $s in $el.stereotypes
        !if ($s == $st)
            remove $el.alias
        !endif
    !endfor
!endfor
!endprocedure

' ---------------------------------------------
' remove all instances, meaning elements with
' stereotype instance
!unquoted procedure PUMLARemoveAllInstances()
PUMLARemoveAllElementsOfStereotype("instance")
!endprocedure

' ############################################
' ---------------------------------------------
' put all relations of the model repo
' onto the diagram
!unquoted procedure PUMLAPutAllRelations()
!foreach $el in $allrelations.relations
    PUMLAPutRelation($el.id)
!endfor
!endprocedure

!unquoted function _PUMIsStatic($elemalias)
!$retval = %true()
!foreach $el in $allelems.elements
    !if ($el.alias == $elemalias)
        !if ($el.kind == "dynamic")
            !$retval = %false()
        !endif
    !endif
!endfor
!return $retval
!endfunction

' ############################################
' ---------------------------------------------
' put all relations of the model repo
' onto the diagram
!unquoted procedure PUMLAPutAllStaticRelations()
!foreach $er in $allrelations.relations
!if _PUMIsStatic($er.start) && _PUMIsStatic($er.end)
    PUMLAPutRelation($er.id)
!endif
!endfor
!endprocedure

' ############################################

' ---------------------------------------------
' put all connections of the model repo
' onto the diagram
!unquoted procedure PUMLAPutAllConnections()
!foreach $el in $allconnections.connections
    PUMLAPutConnection($el.id)
!endfor
!endprocedure

' ############################################
' ---------------------------------------------
' create an instance of an element that exists
' in the json model repo. Internal txt creation.
!unquoted function _PUMLACreateInstanceOf($elemalias, $instalias, $instname)
!$retval = "ERROR"
!foreach $el in $allelems.elements
    !if ($el.alias == $elemalias)
        !if ($PUMVarShowInstantiationRel)
            !$iname = $instname
        !else
            !$iname = $instname + "::" + $el.name
        !endif
        $elt = "ERROR - no valid type"
        !if (($el.type  == "-") || ($el.type  == ""))
            !$elt = "rectangle"
        !else
            !$elt = $el.type
        !endif
        !$sts = ""
        !foreach $st in $el.stereotypes
            !$sts = $sts + " <<" + $st + ">>"
        !endfor
        !$retval = $elt + ' "' + $iname + '" as ' + $instalias + ' <<instance>> ' + $sts
    !endif
!endfor
!return $retval
!endfunction


' ############################################
' ---------------------------------------------
' create an instance of an element that exists
' in the json model repo and put it onto
' the diagram.
!unquoted procedure PUMLACreateAndPutInstanceOf($elemalias, $instalias, $instname="")
!if ($instname == "")
!$instname = $instalias
!endif
!$inst = _PUMLACreateInstanceOf($elemalias,$instalias, $instname)
!if ($inst == ERROR)
PUMLACreateInstanceError($elemalias)
!else
$inst
!if ($PUMVarShowInstantiationRel)
PUMLAPutElement($elemalias)
$instalias ..> $elemalias : instance of
!endif
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' create an instance of an element that exists
' in the json model repo.
!unquoted procedure PUMLAInstanceOf($elemalias, $instalias, $instname="")
!if ($instname == "")
!$instname = $instalias
!endif
!if ($PUMVarShowBody)
'_PUMLACreateInstanceOf($elemalias,$instalias, $instname)
!$inst = _PUMLACreateInstanceOf($elemalias,$instalias, $instname)
!if ($inst == ERROR)
PUMLACreateInstanceError($elemalias)
!else
$inst
!endif
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' this commands gives you an overview
' on the contents of the model repository
' along with the alias names that you can
' use to access/re-use the elements.
!unquoted procedure PUMLACheatSheet()
note as PUMLAUPCheatSheet
    **PUMLA Cheat Sheet**

    **Model Repository contents:**
    |= name |= alias |
!foreach $el in $allelems.elements
    | $el.name | $el.alias |
!endfor
end note
!endprocedure

' ############################################
' ---------------------------------------------
' this commands gives you an overview
' on the contents of the model repository.
' It puts all elements with all attributes into
' a table to help you manage your architecture
' artefacts.
!unquoted procedure PUMLACheatSheetAllAttributes()
note as PUMLAUPCheatSheetAllAttributes
    **PUMLA Cheat Sheet with all attributes**

    Model Repository Path: $allelems.modelrepopath
    Model Repository File: $allelems.modelrepofile

    **Model Repository contents:**
    |= name |= alias |= type |= stereotypes |= parent |= instclass |= kind |= filename |= path |
!foreach $el in $allelems.elements
    !$sts = ""
    !$lmax = 0
    !foreach $st in $el.stereotypes
        !$lmax = $lmax + 1
    !endfor
    !$l = 0
    !foreach $st in $el.stereotypes
        !$sts = $sts + $st
        !$l = $l + 1
        !if ($l < $lmax)
            !$sts = $sts + ", "
        !endif
    !endfor
    !if ($sts=="")
        !$sts="-"
    !endif
    | $el.name | $el.alias | $el.type | $sts | $el.parent | $el.instclassalias | $el.kind | $el.filename | $el.path |
!endfor
end note
!endprocedure

' ############################################
' ---------------------------------------------
' this commands gives you an overview
' on the contents of the relations repository.
' It puts all elements with all attributes into
' a table to help you manage your architecture
' artefacts.
!unquoted procedure PUMLARelCheatSheetAllAttributes()
note as PUMLAUPRelCheatSheetAllAttributes
    **PUMLA Relations Cheat Sheet with all attributes**

    Model Repository Path: $allrelations.modelrelationrepopath
    Model Repository File: $allrelations.modelrelationrepofile

    **Model Relations Repository contents:**
    |= alias |= start |= type |= end |= text |= filename |= path |
!foreach $el in $allrelations.relations
    | $el.id | $el.start | $el.reltype | $el.end | $el.reltxt | $el.filename | $el.path |
!endfor
end note
!endprocedure

' ############################################
' ---------------------------------------------
' this commands gives you an overview
' on the contents of the connections repository.
' It puts all elements with all attributes into
' a table to help you manage your architecture
' artefacts.
!unquoted procedure PUMLAConCheatSheetAllAttributes()
note as PUMLAUPConCheatSheetAllAttributes
    **PUMLA Connections Cheat Sheet with all attributes**

    Model Repository Path: $allconnections.modelconnectionrepopath
    Model Repository File: $allconnections.modelconnectionrepofile

    **Model Connections Repository contents:**
    |= alias |= start |= type |= end |= text |= filename |= path |
!foreach $el in $allconnections.connections
    | $el.id | $el.start | $el.contype | $el.end | $el.contxt | $el.filename | $el.path |
!endfor
end note
!endprocedure

' ############################################
' ---------------------------------------------
' default footer with pumla git repo reference.
' can be overwritten or turned off with the
' global variable.
!if ($PUMVarShowPUMLAFooterNote)
center footer created with help of **pumla**: https://github.com/DrMarkusVoss/pumla
!endif

' ############################################
' ---------------------------------------------
' internal use of an existing model repo element.
!unquoted procedure PUMLAPutInternalElement($elemalias)
!if ($PUMVarShowBodyInternals)
PUMLAPutElement($elemalias)
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' define a re-usable Connection
!unquoted procedure PUMLAConnection($startalias, $contype, $endalias, $contxt="", $conid="")
' empty by intention... the macro name will only be parsed
' by the pumla.py script and the connection then put into
' the model repo. The PlantUML code comes when you put
' a connection from the repo to a diagram.
!endprocedure

' ############################################
' ---------------------------------------------
' put a re-usable connection onto the diagram.
' connections only exist between interfaces.
' otherwise it is a relation, not a connection.
' therefore, if interfaces are not shown, also
' the connections cannot be shown.
!unquoted procedure PUMLAPutConnection($conid)
!foreach $el in $allconnections.connections
    !if ($el.id == $conid)
        !if (%not(%variable_exists($$el.id)))
            !if ($PUMVarShowInterfaces)
            !if ($PUMVarShowConnections)
            !if ($el.contxt=="")
                !$conadr = ""
            !else
                !$conadr = " : " $el.contxt
            !endif
            !if ($PUMVarShowTaggedValues)
                !$tvs = ""
                !$cma = ""
                !foreach $tv in $el.taggedvalues
                    !$tvs = $tvs + "[" + $tv.tag + ": " + $tv.values + "]"
                !endfor
                !if ($tvs!= "")
                    !if ($conadr == "")
                        !$conadr = " : "
                    !endif
                    !$conadr = $conadr + "\n{" +  $tvs + "}"
                !endif
            !endif
            $el.start $el.contype $el.end $conadr
            ' set global variable to indicate that the connection
            ' is already put onto the diagram
            %set_variable_value($$el.id, "%true()")
            !endif
            !endif
        !endif
    !endif
!endfor
!endprocedure

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

' ############################################
' ---------------------------------------------
' DEPRECATION: DO NOT USE THIS FUNCTION ANYMORE
' USE INSTEAD: PUMLAInterface
!unquoted procedure PUMLAPutInterface($ifname, $ifalias, $elemalias, $type="")
PUMLAInterface($ifname, $ifalias, $elemalias, $type="")
!endprocedure

' ############################################
' ---------------------------------------------
' define a re-usable relation
!unquoted procedure PUMLARelation($startalias, $reltype, $endalias, $reltxt="", $relid="")
' empty by intention... the macro name will only be parsed
' by the pumla.py script and the relation then put into
' the model repo. The PlantUML code comes when you put
' a relation from the repo to a diagram.
!endprocedure

' ############################################
' ---------------------------------------------
' put a relation with given id onto the diagram
!unquoted procedure PUMLAPutRelation($relid)
!foreach $el in $allrelations.relations
    !if ($el.id == $relid)
        !if (%not(%variable_exists($$el.id)))
            !$reladr = ""
            !if ((%not($el.reltxt == "instance of")) || ($PUMVarShowInstantiationRel))
               !if ($PUMVarShowTaggedValues)
                !$tvs = ""
                !$cma = ""
                !foreach $tv in $el.taggedvalues
                    !$tvs = $tvs + "[" + $tv.tag + ": " + $tv.values + "]"
                !endfor

                !if ($tvs!= "")
                    !$reladr = "\n{" +  $tvs + "}"
                !endif
               !endif
            $el.start $el.reltype $el.end : $el.reltxt $reladr
            ' set global variable to indicate that the relation
            ' is already put onto the diagram
            %set_variable_value($$el.id, "%true()")
            !endif
        !endif
    !endif
!endfor
!endprocedure

' ############################################
' ---------------------------------------------
' put all relations related to given element alias
' to the diagram
!unquoted procedure PUMLAPutRelationsForElement($elemalias, $reltype="", $tag="", $value="")
!foreach $el in $allrelations.relations
    !if ($reltype == "")
        !$reltype = $el.reltype
    !endif

    !foreach $tvs in $el.taggedvalues
        !$tv_found = "NO"

        !if ($tvs.tag == $tag)
            !if ($value != "")
                !foreach $v in $tvs.values
                    !if ($v == $value)
                        !$tv_found = "YES"
                    !endif
                !endfor
            !else
                !$tv_found = "YES"
            !endif

        !endif
    !endfor

    !if ((($el.start == $elemalias) || ($el.end == $elemalias)) && ($el.reltype  == $reltype))
        ' make sure to not put the same relation twice
        !if (%not(%variable_exists($$el.id)))
            !if ((%not($el.reltxt == "instance of")) || ($PUMVarShowInstantiationRel))
                !$reladr=""
                !if ($PUMVarShowTaggedValues)
                !$tvs = ""
                !$cma = ""
                !foreach $tv in $el.taggedvalues
                    !$tvs = $tvs + "[" + $tv.tag + ": " + $tv.values + "]"
                !endfor

                !if ($tvs!= "")
                    !$reladr = "\n{" +  $tvs + "}"
                !endif
                !endif
                !if ($tag == "")
                    $el.start $el.reltype $el.end : $el.reltxt $reladr
                !else
                    !if ($tv_found == "YES")
                        $el.start $el.reltype $el.end : $el.reltxt $reladr
                    !endif
                !endif
                ' set global variable to indicate that the relation
                ' is already put onto the diagram
                %set_variable_value($$el.id, "%true()")
            !endif
        !endif
    !endif
!endfor
!endprocedure

' ############################################
' ---------------------------------------------
' put all connections related to given element alias
' to the diagram
!unquoted procedure PUMLAPutConnectionsForElement($elemalias)
!foreach $el in $allconnections.connections
    !if ($el.contxt == "")
        !$conadder = ""
    !else
        !$conadder = " : " + $el.contxt
    !endif
    !if ((%strpos($el.start, $elemalias) > 0) || (%strpos($el.end, $elemalias) >0))
        ' make sure to not put the same relation twice
        !if (%not(%variable_exists($$el.id)))
            $el.start $el.contype $el.end $conadder
            ' set global variable to indicate that the relation
            ' is already put onto the diagram
            %set_variable_value($$el.id, "%true()")
        !endif
    !endif
!endfor
!endprocedure

' ############################################
' ---------------------------------------------
' put a dynamic element (like state) into a
' static element (like component)
!unquoted procedure PUMLAPutDynamicElement($elemalias)
!foreach $el in $allelems.elements
!if ($el.alias == $elemalias)
!$felpath = $el.path
!$felfn = $el.filename
!$felname = $el.name
!$feltype = $el.type
!endif
!endfor
!if ($feltype == "state")
rectangle "$felname" <<state>> as $elemalias
!elseif ($feltype == "participant")
rectangle "$felname" <<sequence>> as $elemalias
!else
rectangle "$felname" as $elemalias
!endif
!if ($PUMVarShowBodyInternalsDyn)
note bottom of $elemalias #white
{{
    _PUMPutElement($felpath, $felfn)
}}
end note
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' put an internal dynamic element (like state) into a
' static element (like component)
!unquoted procedure PUMLAPutInternalDynElement($elemalias)
!if ($PUMVarShowBodyInternalsDyn)
PUMLAPutDynamicElement($elemalias)
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' add a tagged value to to element referenced by its alias
!unquoted procedure PUMLAAddTaggedValue($elemalias, $tag, $value)
' empty by intention. will be handled by the pumla command
' line tool.
!endprocedure

' ############################################
' ---------------------------------------------
' add a tagged value to to element referenced by its alias
!unquoted procedure PUMLARUAAddTaggedValue($tag, $value)
' empty by intention. will be handled by the pumla command
' line tool.
!endprocedure

' ############################################
' ---------------------------------------------
' add a tagged value to to element referenced by its alias
!unquoted procedure PUMLATestNewTVs($elemalias)
!$notestr = "-"
!foreach $el in $allelems.elements
    !if ($el.alias == $elemalias)
        !foreach $tv in $el.taggedvalues
            !$notestr = $notestr + " \n" + "tag=" + $tv.tag + "; values = " + $tv.values
        !endfor
        note as n987
            $notestr
        end note
    !endif
!endfor
!endprocedure

' ############################################
' ---------------------------------------------
' small helper to enforce the diagram to be a
' component diagram. This should be executed first
' after the title.
!unquoted procedure PUMLASetAsComponentDiagram()
[comp_193242153453236632191729533452]
remove comp_193242153453236632191729533452
!endprocedure

' ############################################
' ---------------------------------------------
' set the internal element filter with values
!unquoted procedure PUMLASetElementFilterOutType($type)
!$pum_global_element_filter_out_type = $type
!endprocedure

' ############################################
' ---------------------------------------------
' set the internal element filter with values
!unquoted procedure PUMLASetElementFilterInType($type)
!$pum_global_element_filter_in_type = $type
!endprocedure

' ############################################
' ---------------------------------------------
' set the internal element filter with values
!unquoted procedure PUMLASetElementFilterOutStereotype($stereotype)
!$pum_global_element_filter_out_stereotype = $stereotype
!endprocedure

' ############################################
' ---------------------------------------------
' set the internal element filter with values
!unquoted procedure PUMLASetElementFilterInStereotype($stereotype)
!$pum_global_element_filter_in_stereotype = $stereotype
!endprocedure

' ############################################
' ---------------------------------------------
' define re-usable asset
!unquoted procedure PUMLAReUsableAsset($name, $alias, $type, $stereotypes)
!global $pum_global_current_rua_alias = $alias
%set_variable_value("$pum_global_rua_elem_" + $alias + "_alias", "%true()")
$type "$name" as $alias $stereotypes
!endprocedure

' ############################################
' ---------------------------------------------
' define re-usable asset
!unquoted procedure PUMLAReUsableClass($name_alias, $stereotypes)
!global $pum_global_current_rua_alias = $name_alias
class $name_alias $stereotypes
!endprocedure

' ############################################
' ---------------------------------------------
' define re-usable asset description note
!unquoted procedure PUMLAReUsableAssetDescr($alias_descr)
!global $pum_global_current_rua_descr = $alias_descr
!if (%not($PUMVarShowDescr))
    remove $alias_descr
!else
    $pum_global_current_rua_alias .d. $alias_descr
!endif
!endprocedure

' ############################################
' ---------------------------------------------
' define re-usable asset internal items
!unquoted procedure PUMLAReUsableAssetInternals()
!$body_internals = $pum_global_current_rua_alias + "_internals"
!global $pum_global_current_rua_internals = $body_internals
rectangle "Internals" as $body_internals
!endprocedure

' ############################################
' ---------------------------------------------
' define re-usable asset internal items
!unquoted procedure PUMLAReUsableAssetClassInternals()
!$body_internals = $pum_global_current_rua_alias + "_internals"
!global $pum_global_current_rua_internals = $body_internals
rectangle "Internals" as $body_internals
!endprocedure

' ############################################
' ---------------------------------------------
' this has to be called at the end of a
' re-usable asset definition (file).
!unquoted procedure PUMLAReUsableAssetFinalize()
!$body_internals = $pum_global_current_rua_alias + "_internals"
!if (%not($PUMVarShowBodyInternals))
    remove $body_internals
!endif

!if (($pum_global_current_rua_tvnote != "") && ($pum_global_current_rua_internals != ""))
    !$tvnote = $pum_global_current_rua_tvnote
    !$ints = $pum_global_current_rua_internals
    $tvnote .[hidden]d. $ints
!endif
!$pum_global_current_rua_alias = ""
!$pum_global_current_rua_tvnote = ""
!$pum_global_current_rua_descr = ""
!$pum_global_current_rua_internals = ""
!$pum_global_instance_adder = ""

!endprocedure



' ############################################
' ---------------------------------------------
' define a re-usable class that can be instantiated,
' with the instances getting automatically all
' class attributes.
!unquoted procedure PUMLAFullyInstantiatableClass($classname, $stereotypes)
!if ($classname_instancename == "$classname_instancename")
    !$alias = $classname
    !$classname_i = $classname
!else
    !$alias = $classname_instancename
    !$classname_i = $classname_instancename + " (" + $classname + ")"
!endif
!$stereotyps = $pum_global_instance_adder + "" + $stereotypes
PUMLAReUsableAsset($classname_i, $alias, class, $stereotyps)
!endprocedure

' ############################################
' ---------------------------------------------
' define a re-usable class that can be instantiated,
' with the instances getting automatically all
' class attributes defined in the RUA class body.
!unquoted procedure PUMLAFullInstanceOf($classalias, $instalias)
!$int_suc = %false()
!$pum_global_instance_adder = "<<instance>>"
%set_variable_value("$classname_instancename", $instalias)

'!$classname_instancename = $instalias
!foreach $el in $allelems.elements
    !if ($el.alias==$classalias)
        !includesub $allelems.modelrepopath/%substr($el.path,2)/$el.filename!BODY
        !$int_suc = %true()
    !endif
!endfor
!if %not($int_suc)
PUMLACreateInstanceError($classalias)
!endif
%set_variable_value("$classname_instancename", "$classname_instancename")
!endprocedure

