Sparx Systems Enterprise Architect + SQL : Interpretation der Linkdarstellung / Link Layout eines Diagrams über das relationale EA Datenmodell

Problem

Über das relationale Datenmodell des Enterprise Architects soll die Geometrie von Links auf Diagrammen rekonstruiert werden. Die nötigen Felder sind in den Tiefen der Datenstrukturen aus Tabellen und Attributen in einem Memo-/Freitext-Feld versteckt.

Ich entwickle zur Zeit eine eigene Interpretation des EA-Renderers mit GoJS, wo ich auf das Problem gestoßen bin, dass ich aufgrund der unterschiedlichen Connectorstyles, welche für einen Link auf unterschiedlichen Diagrammen eine andere Geometrie vorweisen kann, den Endpunkt nicht ermitteln kann. Eine Lösung hierzu möchte ich hier ausarbeiten.

Analyse

Relationen

Ein Link/Connector (Tabelle „t_connector„) kann auf mehreren Diagrammen unterschiedliche Darstellungen haben. Die Geometrie des Links auf einem Diagramm wird über das Attribut „Geometry“ der Tabelle „t_diagramlinks“ bestimmt. Das Attribut „Geometry“ ist ein Langtext-/Memo-Feld und wird im folgenden einer Analyse unterzogen, da sich im Internet nur sehr spärlich Informationen über den Aufbau und die Bedeutung des Doppelpunkt-separierten Strings finden.

Die Tabelle „t_diagramlinks“

“ A DiagramLink is an object that holds display information on a connector between two elements in a specific diagram. It includes, for example, the custom points and display appearance. It can be accessed from the Diagram DiagramLinks collection. “

https://sparxsystems.com/enterprise_architect_user_guide/
14.0/automation/diagramlinks.html
AttributeRemarks

ConnectorID
Long
Notes: Read/Write
The ID of the associated connector.

DiagramID
Long
Notes: Read/Write
The local ID for the associated diagram.

Geometry
String (Memo-Field)
Notes: Read/Write
The geometry associated with the current connector in this diagram.

HiddenLabels
Boolean
Notes: Indicates if this connector’s labels are hidden on the diagram.

InstanceID
Long
Notes: Read only
The connector identifier for the current model.

IsHidden
Boolean
Notes: Read/Write
Indicates if this item is hidden or not.

LineColor
Long
Notes: Sets the line color of the connector.
Set to -1 to reset to the default color in the model.

LineStyle
Long
Notes: Sets the line style of the connector.
1 = Direct
2 = Auto Routing
3 = Custom Line
4 = Tree Vertical
5 = Tree Horizontal
6 = Lateral Vertical
7 = Lateral Horizontal
8 = Orthogonal Square
9 = Orthogonal Rounded

LineWidth

Long
Notes: Sets the line width of the connector.

ObjectType
ObjectType
Notes: Read only
Distinguishes objects referenced through a Dispatch interface.

Path
String
Notes: Read/Write
The path of the connector in this diagram.

SourceInstanceUID
String
Notes: Read only
Returns the Unique Identifier of the source object.

SuppressSegment
Boolean
Notes: Indicates whether the connector segments are suppressed.

Style
String
Notes: Read/Write
Additional style information; for example, color or thickness.

TargetInstanceUID
String
Notes: Read only
Returns the Unique Identifier of the target object.
Der String „Geometry“ wird in MDB Viewer Plus als (MEMO) dargestellt, das MemoFeld kann allerdings rechts eingeblendet werden. Dort tauchen einige weitere versteckte Attribute für die Geometry der Linie auf, welche im nachfolgendem Analysiert werden
Die Auswahl des LineStyles für einen Connector, wie oben im Screenshot dargestellt, bestimmt die Darstellung.
Die LineStyles werden in der Tabelle [t_diagramlinks] und über Mode={1,2,3} und dem optionalen Zusatz TREE={V,H,OS,OR,LV,LH}:Mode=3 für Mode „3“ gespeichert.
Das Hauptproblem: Das Datenmodell besitzt nicht die Information, an welcher Seite der End-Knoten/das Ziel-Rechteck geschnitten wird. Lediglich über das Attribut t_diagrammlinks.Geometry lässt sich über den CSV-Value „Edge“ die Startseite des Startknotens bestimmen.

Fremdmeinungen einholen – ein Ausflug in die Forenwelt

Ich habe mich aus Gründen der Kollaboration entschieden, die Analysen in Stackoverflow und EA fortzuführen. Hier finden sich die Links zu meinem Beitrag:

https://stackoverflow.com/questions/55341368/enterprise-architect-how-to-get-the-edge-of-the-end-node-using-a-sql-query-on

https://www.sparxsystems.com/forums/smf/index.php/topic,42536.0.html

https://matheplanet.de/matheplanet/nuke/html/viewtopic.php?topic=241211

Fazit: Obwohl mir kein Forum eine nutzbare Lösung angeboten hat, lohnt es sich sich neue Anregungen zu dem Problem einzuholen

Lösung für das Problem mit der fehlenden Ecke des Zielknoten (Target Edge) – Rechteckschnitt

Im Datenmodell wird die Mouse-Release Position über Geometry EX/EY (Geometry) gespeichert, was allerdings nicht der Schnittpunkt mit dem Rechteck ist.

Mit 4 Geraden lässt sich das Rechteck bestimmen (obgleich natürlich auch Punkte existieren, die nicht auf dem Rechteck liegen).

Seite 1 der Lösung
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Erzeuge eine eigene Link-Klasse für das Routing der Pfeile, die von Hand gezogen wurden 
// und über spezielle Attribute in der EAP-Datei definiert werden
// Ruft die Superklasse von go.Link im Konstruktor auf
function MultiNodePathLink() {
    go.Link.call(this);
}
go.Diagram.inherit(MultiNodePathLink, go.Link); // Erben von go.Link

// ignores this.routing, this.adjusting, this.corner, this.smoothness, this.curviness
/** @override */
MultiNodePathLink.prototype.computePoints = function () {

    // Die this Referenz ist hier ist ein geerbter ein go.Link. der bei Links
    var startNode = this.fromNode;
    var startNodeX = startNode.location.M;  // X-Koordinate vom Startknoten
    var startNodeY = startNode.location.N; // Y-Koordinate vom Startknoten

    var endNode = this.toNode;
    var endNodeX = endNode.location.M;  // X-Koordinate vom Startknoten
    var endNodeY = endNode.location.N; // Y-Koordinate vom Startknoten
   
    var startNodeData = startNode.data; // Das sind die Daten
    var endNodeData = endNode.data; // Das sind die Daten

    // Die Link-Daten
    var linkProperties = this.data;
    //** Das Feld Style in [t_diagramlink] bestimmt die Connector-Darstellung  **/
    // https://www.capri-soft.de/blog/?p=2904
    /*
     *  1 = Direct                    Mode=1
     *  2 = Auto Routing              Mode=2
     *  3 = Custom Line               Mode=3
     *  4 = Tree Vertical             Mode=3;TREE=V
     *  5 = Tree Horizontal           Mode=3;TREE=H
     *  6 = Lateral Vertical          Mode=3;TREE=LV
     *  7 = Lateral Horizontal        Mode=3;TREE=LH
     *  8 = Orthogonal Square         Mode=3;TREE=OS
     *  9 = Orthogonal Rounded        Mode=3;TREE=OR
     */
    var styleStringArray = linkProperties.style.split(";");
    var mode = -1;
    var tree = '';
    for (var i = 0; i < styleStringArray.length; i++) {
        if (styleStringArray[i].trim().indexOf('Mode=') > -1) {
            mode = styleStringArray[i].replace('Mode=', '');
        }

        if (styleStringArray[i].trim().indexOf('TREE=') > -1) {
            tree = styleStringArray[i].replace('TREE=', '');
        }
    }



    // In der Tabelle t_diagramlinks in der Freitextspalte "Geometry" wird in einem CSV-String 
    // gespeichert, wie der Link letztendlich auf dem Diagram gezogen wurde
    var geometryString = linkProperties.geometry.split(";");
    var sx, sy, ex, ey, edge;
    for (var i = 0; i < geometryString.length; i++) {
        // SX and SY are relative to the centre of the start object 
        if (geometryString[i].trim().indexOf('SX=') > -1) sx = geometryString[i].replace('SX=', '');
        if (geometryString[i].trim().indexOf('SY=') > -1) sy = geometryString[i].replace('SY=', '');

        // EX and EY are relative to the centre of the end object
        if (geometryString[i].trim().indexOf('EX=') > -1) ex = geometryString[i].replace('EX=', '');
        if (geometryString[i].trim().indexOf('EY=') > -1) ey = geometryString[i].replace('EY=', '');

        // EDGE ranges in value from 1-4, with 1=Top, 2=Right, 3=Bottom, 4=Left (Outgoing Point of the Start Object)
        if (geometryString[i].trim().indexOf('EDGE=') > -1) edge = geometryString[i].replace('EDGE=', '');
    }
    


    // Hier beginnt das Custom-Routing
    if (typeof (sx) === "undefined" || typeof (sy) === "undefined" || typeof (ex) === "undefined" || typeof (ey) === "undefined" || typeof (edge) === "undefined") {
        return;
    }
       
    this.clearPoints();

    if (linkProperties.start_object_name == 'System Verification Test Reports' && linkProperties.end_object_name == 'System test specifications') {
        var test = 'irrsinn';
    }
    // Hier werden die Wege definiert für das gecustomizte Link Routing
    // Geht der Link nach oben oder unten wird die Y-Koordinate des Startknotens genutzt (Weil Orthogonales Routing)
    var startConnX = null;
    var startConnY = null;
    if (edge == 1) { // Ecke oben
        startConnX = Math.abs(startNodeX) + Math.abs((startNode.actualBounds.width / 2) + new Number(sx));
        startConnY = Math.abs(startNodeY);
    }
    else if (edge == 3) { // Ecke unten
        startConnX = Math.abs(startNodeX) + Math.abs((startNode.actualBounds.width / 2) + new Number(sx));
        startConnY = Math.abs(startNodeY) + new Number(startNode.actualBounds.height);
    }
    else if (edge == 2) { // Ecke rechts
        startConnX = Math.abs(startNodeX) + startNode.actualBounds.width;
        startConnY = Math.abs(startNodeY) + Math.abs((startNode.actualBounds.height / 2) - new Number(sy));
    }
    else if (edge == 4) { // Ecke links
        startConnX = new Number(Math.abs(startNodeX));
        startConnY = Math.round(startNodeY) + Math.round((startNode.actualBounds.height / 2) - new Number(sy));
    }
    else {
        alert('Die Edge konnte nicht entdeckt werden! Ist der Geometry String in der EAP Datei richtig?');
    }

    this.addPoint(new go.Point(Math.round(startConnX), Math.round(startConnY)));

    // Abfrage: Gibt es einen letzten Path Punkt?
    var lastPathPunkt=false;
    var lastPathPunktX, lastPathPunktY;

    if (mode != 1)
    {
        // Routing über die Zwischenwege
        if (typeof linkProperties.conn_path !== "undefined" && linkProperties.conn_path !== "") {
            var splittedArray = linkProperties.conn_path.split(";");
            if (splittedArray.length > 1) {
                // Hier ist mindestens ein Wert vorhanden da auch der erste mit Semikolon abgeschlossen wird im Path vom EA
                for (var i = 0; i < splittedArray.length - 1; i++) {
                    var einMittelPunkt = splittedArray[i];
                    var mittelPunktArray = einMittelPunkt.split(":");
                    this.addPoint(new go.Point(Math.abs(new Number(mittelPunktArray[0])), Math.abs(new Number(mittelPunktArray[1]))))
                    lastPathPunktX = Math.abs(new Number(mittelPunktArray[0]));
                    lastPathPunktY = Math.abs(new Number(mittelPunktArray[1]));
                    lastPathPunkt = true;
                }
            }
        }
    }

    // Wenn es keinen Pfad gab,muss der letzte Punkt mit dem Startknoten identisch sein
    if (lastPathPunkt == false) {
        lastPathPunktX = Math.abs(Math.round(startConnX));
        lastPathPunktY = Math.abs(Math.round(startConnY));
    }

    // End-Routing
    // Der Endpunkt in EA in Document Coordinates
    var endConnX = Math.abs(endNodeX) + Math.abs((endNode.actualBounds.width / 2) + new Number(ex));
    var endConnY = Math.abs(endNodeY) + Math.abs((endNode.actualBounds.height / 2) - new Number(ey));

    // Spezialfälle bei horizontalen und vertikalen Linien:
    if (endConnX == lastPathPunktX) {
        // Es liegt eine vertikale Gerade (z.B. von oben nach unten) vor
        this.addPoint(new go.Point(Math.round(lastPathPunktX), Math.round(lastPathPunktY)));
        this.addPoint(new go.Point(Math.round(endConnX), Math.round(endConnY)));

    } else if (endConnY == lastPathPunktY) {
        // Es liegt eine horizontale Gerade (z.B. von rechts nach links) vor
        this.addPoint(new go.Point(Math.round(lastPathPunktX), Math.round(lastPathPunktY)));
        this.addPoint(new go.Point(Math.round(endConnX), Math.round(endConnY)));
    } else {
        // Es ist keine Gerade sondern ein Gerade, die mit y=m*x+b beschrieben werden kann

        // 1.) Gerade zwischen Start- und Endpunkt ermittelnhn
        //      Ye-Ys
        //  m = -----    b=Ys-m*Xs oder b=Ye-m*Xe
        //      Xe-Xs
        var m = (endConnY - lastPathPunktY) / (endConnX - lastPathPunktX);
        var b = lastPathPunktY - m * lastPathPunktX

        // 2.) Ermittlung der horizontalen und vertikalen Geraden des Rechteckes und dem Schnittpunkten
        // Die Geraden, die das Rechteck definieren:
        var rY1 = endNodeY;
        var rY2 = endNodeY + endNode.actualBounds.height;
        var rX1 = endNodeX;
        var rX2 = endNodeX + endNode.actualBounds.width;
        // (rX1, rY1) -zu-> (rX2, rY2)
        
        // Horizontale Geraden: 
        //     y - b
        // x = -----
        //       m


        var lengthToPoint = [];

        var sX1 = (rY1 - b) / m; // S1(sX1|rY1)
        if (sX1 >= rX1 && sX1 <= rX2) {
            // Der Schnittpunkt sX1 ist am Rechteck
            // Distanz: d=SQRT((y2-y1)^2+(x2-x1)^2)
            var dS1 = Math.sqrt(Math.pow(rY1 - lastPathPunktY, 2) + Math.pow(sX1 - lastPathPunktX, 2));

            lengthToPoint.push({
                "distanz": dS1,
                "x": sX1,
                "y": rY1
            });

        }

        var sX2 = (rY2 - b) / m; // S2(sX2|rY2)
        if (sX2 >= rX1 && sX2 <= rX2) {
            // Der Schnittpunkt sX2 ist am Rechteck
            // Distanz: d=SQRT((y2-y1)^2+(x2-x1)^2)
            var dS2 = Math.sqrt(Math.pow(rY2 - lastPathPunktY, 2) + Math.pow(sX2 - lastPathPunktX, 2));

            lengthToPoint.push({
                "distanz": dS2,
                "x": sX2,
                "y": rY2
            });
        }

        // Vertikale Geraden:
        //
        // y = m*x + b

        var sY1 = m * rX1 + b; // S3(rX1|sY1)
        if (sY1 >= rY1 && sY1 <= rY2) {
            // Der Schnittpunkt sY1 ist am Rechteck
            // Distanz: d=SQRT((y2-y1)^2+(x2-x1)^2)
            var dS3 = Math.sqrt(Math.pow(sY1 - lastPathPunktY, 2) + Math.pow(rX1 - lastPathPunktX, 2));

            lengthToPoint.push({
                "distanz": dS3,
                "x": rX1,
                "y": sY1
            });
        }

        var sY2 = m * rX2 + b; // S4(rX2|sY2)
        if (sY2 >= rY1 && sY2 <= rY2) {
            // Der Schnittpunkt sY2 ist am Rechteck
            // Distanz: d=SQRT((y2-y1)^2+(x2-x1)^2)
            var dS4 = Math.sqrt(Math.pow(sY2 - lastPathPunktY, 2) + Math.pow(rX2 - lastPathPunktX, 2));

            lengthToPoint.push({
                "distanz": dS4,
                "x": rX2,
                "y": sY2
            });
        }

        // Sortiere alle Punkte nach Distanz - der mit der kleinsten Entfernung isses
        lengthToPoint.sort(function (a, b) { return a.distanz - b.distanz });

        if (lengthToPoint.length > 0)
        {
            this.addPoint(new go.Point(Math.round(lengthToPoint[0].x), Math.round(lengthToPoint[0].y)));
        }
        else
        {
            this.addPoint(new go.Point(Math.round(lastPathPunktX), Math.round(lastPathPunktY)));
        }

        
    }

    return true;
};
// end MultiNodePathLink class