//DIAGRAM CONTENT
        public void Generate_otDiagram_content(EA.Repository m_Repository, string TOI_GUID, string SP_BaseURL,
                                               out List <string> listOfElements,
                                               out List <string> listOfElementsNames,
                                               out List <string> listOfLinks,
                                               out List <string> listOfLinkNames,
                                               out Dictionary <string, string> DiagramDictionary)
        {
            listOfElements      = new List <string>();
            listOfElementsNames = new List <string>();
            listOfLinks         = new List <string>();
            listOfLinkNames     = new List <string>();

            EA.Diagram DiagramToShow = (EA.Diagram)m_Repository.GetDiagramByGuid(TOI_GUID);



            //STORE DIAGRAM ELEMENTS
            for (short iDO = 0; iDO < DiagramToShow.DiagramObjects.Count; iDO++)
            {
                EA.DiagramObject MyDO = (EA.DiagramObject)DiagramToShow.DiagramObjects.GetAt(iDO);
                int        ID         = m_Repository.GetElementByID(MyDO.ElementID).ElementID;
                EA.Element MyEle      = (EA.Element)m_Repository.GetElementByID(ID);
                listOfElements.Add(MyEle.Name + "|" + MyEle.ObjectType + "|" + MyEle.ElementGUID);
                listOfElementsNames.Add(MyEle.Name);
            }



            //STORE DIAGRAM LINKS
            for (short iDO = 0; iDO < DiagramToShow.DiagramLinks.Count; iDO++)
            {
                EA.DiagramLink MyLink = (EA.DiagramLink)DiagramToShow.DiagramLinks.GetAt(iDO);
                int            ID     = m_Repository.GetConnectorByID(MyLink.ConnectorID).ConnectorID;

                EA.Connector con;

                try //Try and get the connector object from the repository
                {
                    con = (EA.Connector)m_Repository.GetConnectorByID(ID);
                    listOfLinks.Add(con.Name + "|" + con.ObjectType + "|" + con.ConnectorGUID);
                    listOfLinkNames.Add(con.Name);
                }
                catch { }
            }



            //JSON Content
            string DiagramURL = SP_BaseURL + "/" + DiagramToShow.Name + "|otDiagram|" + TOI_GUID;


            DiagramDictionary = new Dictionary <string, string>();
            DiagramDictionary.Add("Diagram Name", DiagramToShow.Name);
            DiagramDictionary.Add("Created Data", DiagramToShow.CreatedDate.ToString());
            DiagramDictionary.Add("Meta Type", DiagramToShow.MetaType);
            DiagramDictionary.Add("Notes", DiagramToShow.Notes);
            DiagramDictionary.Add("Package ID", DiagramToShow.PackageID.ToString());
            DiagramDictionary.Add("Big Preview", DiagramURL + "/BigPreview");
            DiagramDictionary.Add("Small Preview", DiagramURL + "/SmallPreview");
        }
        public SpecIfMetadata CreateMetaDataForDiagramLink(EAAPI.DiagramLink diagramLink,
                                                           EAAPI.Connector connector,
                                                           EAAPI.DiagramObject sourceDiagramObject,
                                                           EAAPI.DiagramObject targetDiagramObject,
                                                           EAAPI.Element sourceElement,
                                                           EAAPI.Element targetElement)

        {
            SpecIfMetadata result = new SpecIfMetadata();

            EAAPI.Element srcElement  = sourceElement;
            EAAPI.Element trgtElement = targetElement;

            string directionAttribute = null; // unspecified

            if (connector.Direction == "Source -> Destination")
            {
                directionAttribute = "unidirectional";
            }
            else if (connector.Direction == "Destination -> Source")
            {
                srcElement         = targetElement;
                trgtElement        = sourceElement;
                directionAttribute = "unidirectional";
            }
            else if (connector.Direction == "Bi-Directional")
            {
                directionAttribute = "bidirectional";
            }

            Edge edge = new Edge
            {
                Waypoints  = new List <Waypoint>(),
                References = new List <SpecIfReferenceBase>(),
                SourceResourceReference = new ResourceReference
                {
                    IdReference       = EaSpecIfGuidConverter.ConvertEaGuidToSpecIfGuid(srcElement.ElementGUID),
                    RevisionReference = EaDateToRevisionConverter.ConvertDateToRevision(srcElement.Modified)
                },
                TargetResourceReference = new ResourceReference
                {
                    IdReference       = EaSpecIfGuidConverter.ConvertEaGuidToSpecIfGuid(trgtElement.ElementGUID),
                    RevisionReference = EaDateToRevisionConverter.ConvertDateToRevision(trgtElement.Modified)
                },
                Direction = directionAttribute
            };

            edge.Waypoints = CalculateWaypointsForDiagramLink(diagramLink, sourceDiagramObject, targetDiagramObject);

            result.Edge = edge;

            return(result);
        }
        private List <Waypoint> CalculateWaypointsForDiagramLink(EAAPI.DiagramLink diagramLink,
                                                                 EAAPI.DiagramObject sourceDiagramObject,
                                                                 EAAPI.DiagramObject targetDiagramObject)
        {
            List <Waypoint> result = new List <Waypoint>();

            int startX;
            int endX;
            int startY;
            int endY;

            List <Point> linkPathPoints = ParseEaLinkPath(diagramLink.Path);

            // horizontal coordinates calculation
            if (linkPathPoints.Count == 0) // direct line
            {
                // horizontal calculation
                // source --> target
                if (sourceDiagramObject.right < targetDiagramObject.left)
                {
                    startX = sourceDiagramObject.right;
                    endX   = targetDiagramObject.left;
                }
                else if (sourceDiagramObject.left > targetDiagramObject.right) // target <-- source
                {
                    startX = sourceDiagramObject.left;
                    endX   = targetDiagramObject.right;
                }
                else
                {
                    startX = sourceDiagramObject.left + (sourceDiagramObject.right - sourceDiagramObject.left) / 2;
                    endX   = startX;
                }
            }
            else // bended line
            {
                // start of path

                // horizontal calculation
                // source --> target
                if (sourceDiagramObject.right < linkPathPoints[0].X)
                {
                    startX = sourceDiagramObject.right;
                }
                else if (sourceDiagramObject.left > linkPathPoints[0].X) // target <-- source
                {
                    startX = sourceDiagramObject.left;
                }
                else
                {
                    startX = linkPathPoints[0].X;
                }

                // end of path

                // horizontal calculation
                // target <-- last path
                if (targetDiagramObject.right < linkPathPoints[linkPathPoints.Count - 1].X)
                {
                    endX = targetDiagramObject.right;
                }
                else if (targetDiagramObject.left > linkPathPoints[linkPathPoints.Count - 1].X) // target --> last path
                {
                    endX = targetDiagramObject.left;
                }
                else
                {
                    endX = linkPathPoints[linkPathPoints.Count - 1].X;
                }
            }

            // vertical coordinates calculation
            if (linkPathPoints.Count == 0)
            {
                // vertical calculation
                // source above target, vertical
                if (-sourceDiagramObject.bottom < -targetDiagramObject.top)
                {
                    startY = -sourceDiagramObject.bottom;
                    endY   = -targetDiagramObject.top;
                }
                // source below target, vertival
                else if (-sourceDiagramObject.top > -targetDiagramObject.bottom)
                {
                    startY = -sourceDiagramObject.top;
                    endY   = -targetDiagramObject.bottom;
                }
                else
                {
                    startY = -sourceDiagramObject.top + (-sourceDiagramObject.bottom + sourceDiagramObject.top) / 2;
                    endY   = startY;
                }
            }
            else
            {
                // source above target, vertical
                if (-sourceDiagramObject.bottom < linkPathPoints[0].Y)
                {
                    startY = -sourceDiagramObject.bottom;
                }
                // source below target, vertival
                else if (-sourceDiagramObject.top > linkPathPoints[0].Y)
                {
                    startY = -sourceDiagramObject.top;
                }
                else
                {
                    startY = linkPathPoints[0].Y; // -sourceDiagramObject.top + (-sourceDiagramObject.bottom + sourceDiagramObject.top) / 2;
                }

                // source above target, vertical
                if (-targetDiagramObject.top > linkPathPoints[linkPathPoints.Count - 1].Y)
                {
                    endY = -targetDiagramObject.top;
                }
                // source below target, vertival
                else if (-targetDiagramObject.bottom < linkPathPoints[linkPathPoints.Count - 1].Y)
                {
                    endY = -targetDiagramObject.bottom;
                }
                else
                {
                    endY = linkPathPoints[linkPathPoints.Count - 1].Y; //-targetDiagramObject.top + (-targetDiagramObject.bottom + targetDiagramObject.top) / 2;
                }
            }

            result.Add(new Waypoint
            {
                X = startX,
                Y = startY
            });

            foreach (Point bendPoint in linkPathPoints)
            {
                result.Add(new Waypoint
                {
                    X = bendPoint.X,
                    Y = bendPoint.Y
                });
            }

            result.Add(new Waypoint
            {
                X = endX,
                Y = endY
            });


            return(result);
        }