gobravedave / Enterprise-Architect

scripts and other code snippets to extend Sparxs Enterprise Architect
BSD 2-Clause "Simplified" License
51 stars 12 forks source link

Bug in PlantUML source where indenting within an alt or loop block reverses the direction of the arrow. #11

Closed Takashi-K-TakaTech closed 1 year ago

Takashi-K-TakaTech commented 2 years ago

Occurs in the following PlantUML sources:

@startuml
main ->> job : test1 cmd
alt wait response
job ->> main : complete test1
end
main ->> job : test2 cmd
alt wait response
   job ->> main : complete test2
end
@enduml

Arrow direction reversed in 'complete test2'.

The problem was avoided by adding a Trim function before parsing a single line to remove whitespace before and after, thereby ignoring indentation.

Fixed code for now: CreateSequenceDiagram subroutine in PlantUML's Create-Sequence-Diagram

sub CreateSequenceDiagram ()
    call LOGInfo("Create Sequence Diagram script activated")

    dim PlantUML
    dim word

    'check current diagram.. if nothing.. then this script has not been called properly

    'the following check is not really required..
    if not theSelectedElement is nothing _
    and theSelectedElement.ObjectType = otElement _
    and theSelectedElement.Type = "Note" then
        'split note..
        'call LOGDebug( "PlantUML")
        dim i
        dim linestr
        left=30                     'set initial 
        fragment_level=0
        PlantUML = Split(theSelectedElement.Notes,vbcrlf,-1,0)
        for i = 0 to Ubound(PlantUML)
            linestr = Trim(PlantUML(i))
            'call LOGDebug ( "Processing: " & linestr )
            if not linestr = "" then
                if not Asc(linestr) = 39  then
                    if multiline_note = True then
                        process_note(linestr)                                           'process note
                    else
                        word=split(linestr)
                        select case ucase(word(0))
                            case "@STARTUML"    'call LOGDebug ( "skip: " & linestr )       'ignore
                            case "AUTONUMBER"   autonumber = True
                            case "AUTOACTIVATE" 'call LOGDebug ( "skip: " & linestr )       'ignore
                            case "TITLE"        create_title(linestr)
                            case "ACTOR"        create_timeline(linestr)
                            case "PARTICIPANT"  create_timeline(linestr)
                            case "BOUNDARY"     create_timeline(linestr)
                            case "CONTROL"      create_timeline(linestr)
                            case "ENTITY"       create_timeline(linestr)
                            case "COLLECTIONS"  create_timeline(linestr)
                            case "DATABASE"     create_timeline(linestr)
                            case "BOX"          create_timeline(linestr)
                            case "END"          resize_diagramObject(linestr)           'box or a partition
                            case "ACTIVATE"     'call LOGDebug ( "skip: " & linestr )       'ignore
                            case "DEACTIVATE"   'call LOGDebug ( "skip: " & linestr )       'ignore
                            case "ALT"          create_fragment(linestr)                'add fragment
                            case "OPT"          create_fragment(linestr)                'add fragment
                            case "BREAK"        create_fragment(linestr)                'add fragment
                            case "LOOP"         create_fragment(linestr)                'add fragment
                            case "CRITICAL"     create_fragment(linestr)                'add fragment
                            case "=="           create_fragment(linestr)                'add seq fragment as divider                        
                            case "ELSE"         add_partition(linestr)                  'add partition to fragment
                            case "NOTE"         process_note(linestr)                   'process note
                            case "@ENDUML"      'call LOGDebug ( "skip: " & linestr )       'ignore
                            case else           create_sequence(linestr)                'replace with a regex expression to make sure sctipt line si indeed a sequence
                        end select
                    end if
                end if
            end if
        next

        call LOGDebug( "**Timeline Array**" )
        Call PrintArray (timeline_array,0,t-1)

        call layout_objects()                           'set relative coordinates of seqeunces & fragments

        call LOGDebug( "**Layout Array**" )
        Call PrintArray (layout_array,0,l-1)

        ReloadDiagram(currentDiagram.DiagramID)

        call LOGInfo ( "Create Sequence Diagram Script Complete" )
    else
        call LOGError("problem calling the sub routine")
    end if
end sub
Takashi-K-TakaTech commented 2 years ago

For the following reasons I have not followed up to the cause of the arrow reversal.

  1. removing whitespace at the beginning of a line eliminates the bug factor.
  2. another issue also fixes the response message determination.
gobravedave commented 1 year ago

Hi @Takashi-K-TakaTech i have added the trim as per your advise.. and it is working.. thanks for your assistance. David.