public int DoCopyPortsGui() { Diagram dia = _rep.GetCurrentDiagram(); if (dia == null) { return(0); } int count = dia.SelectedObjects.Count; if (count < 2) { return(0); } _rep.SaveDiagram(dia.DiagramID); // target object/element var trgEl = (Element)_rep.GetContextObject(); if (trgEl.Type != "Class" && trgEl.Type != "Component") { MessageBox.Show($"Target Element is '{trgEl.Type}'", @"Target element for copy Port has to be Class or Component"); return(0); } // over all selected DiagramObjects for (int i = 0; i < count; i = i + 1) { var srcObj = (DiagramObject)dia.SelectedObjects.GetAt((short)i); var srcEl = _rep.GetElementByID(srcObj.ElementID); if (srcEl.ElementID == trgEl.ElementID) { continue; } if (srcEl.Type == "Port") { // selected element was port CopyPort(_rep, srcEl, trgEl); _count += 1; } else { // selected element was "Port" foreach (Element p in srcEl.EmbeddedElements) { if (srcEl.ElementID == trgEl.ElementID) { continue; } if (p.Type == "Port") { CopyPort(_rep, p, trgEl); _count += 1; } } } } return(_count); //_rep.ReloadDiagram(dia.DiagramID); }
/// <summary> /// Set Diagram styles in PDATA and StyleEx. /// /// HideQuals=1 HideQualifiers: /// OpParams=2 Show full Operation Parameter /// ScalePI=1 Scale to fit page /// Theme=:119 Set the diagram theme and the used features of the theme (here 119, see StyleEx of t_diagram) /// /// par[0] contains the values as a semicolon/comma separated Style /// par[1] contains the values as a semicolon/comma separated PDATA /// par[2] contains the values as a semicolon/comma separated properties /// par[3] contains the possible diagram types /// </summary> /// <param name="rep"></param> /// <param name="dia"></param> /// <param name="par">par[] </param> private static void SetDiagramStyle(Repository rep, EA.Diagram dia, string[] par) { EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: false); if (eaDia.Dia == null) { return; } rep.SaveDiagram(eaDia.Dia.DiagramID); string styles = par[0].Replace(",", ";"); string pdatas = par[1].Replace(",", ";"); string properties = par[2].Replace(",", ";"); string types = par[3]; var diagramStyle = new DiagramStyle(rep, dia, types, styles, pdatas, properties); if (diagramStyle.IsToProcess()) { diagramStyle.UpdateStyles(); diagramStyle.SetProperties(withSql: false); diagramStyle.SetProperties(withSql: true); } eaDia.ReloadSelectedObjectsAndConnector(saveDiagram: false); }
/// <summary> /// Generates the diagram. /// </summary> /// <param name="repository">The repository.</param> /// <param name="package">The package.</param> public static void GenerateDiagram(Repository repository, Package package) { chkPackage = package; pRepository = repository; ProgressInfo.Info = Resources.stateGenDiagram; DiagramObjects dobjs = new DiagramObjects(); Package newPackage = Manipulation.AddPackage(chkPackage, "Package Dependencies"); object objDiagram = newPackage.Diagrams.AddNew(chkPackage.Name + " - " + appSettings.Stereotype, appSettings.Type); if (!Equals(objDiagram, null)) { Diagram pdDiagram = (Diagram)objDiagram; pdDiagram.Stereotype = "generated"; if (pdDiagram.Update()) { ProgressInfo.Info = Resources.stateSearchCurDep; DependingPackageList currentDependency = CurrentDependencies(chkPackage); IEnumerator enumCurrent = currentDependency.GetEnumerator(); enumCurrent.Reset(); ProgressInfo.Reset(Resources.stateCreateDiagram, 0, currentDependency.Count); while (enumCurrent.MoveNext()) { ProgressInfo.Next(); DependingPackages dp = (DependingPackages)enumCurrent.Current; if (dp != null && !dobjs.IsInList(dp.Element1.ElementID)) { object objDObj = pdDiagram.DiagramObjects.AddNew("", ""); if (!Equals(objDObj, null)) { dobjs.Add(AddElementToDiagram(pdDiagram, dp.Element1)); } } if (dp != null && !dobjs.IsInList(dp.Element2.ElementID)) { object objDObj = pdDiagram.DiagramObjects.AddNew("", ""); if (!Equals(objDObj, null)) { dobjs.Add(AddElementToDiagram(pdDiagram, dp.Element2)); } } } pRepository.OpenDiagram(pdDiagram.DiagramID); pRepository.App.Project.LayoutDiagram(pdDiagram.DiagramGUID, 0); pRepository.SaveDiagram(pdDiagram.DiagramID); ProgressInfo.Info = Resources.stateFinished; } } }
/// <summary> /// Wrapper to change DiagramLink style /// </summary> /// <param name="rep"></param> /// <param name="type"></param> /// <param name="style"></param> /// <param name="property"></param> /// <param name="changeScope"></param> public static void DiagramLinkStyleWrapper(Repository rep, string type, string style, string property, ChangeScope changeScope) { EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: false); // Handle selected diagram and its selected items (connector/objects) if (eaDia.Dia != null) { rep.SaveDiagram(eaDia.Dia.DiagramID); // over all links foreach (var link in eaDia.GetSelectedLinks()) { var linkStyle = new DiagramLinkStyle(rep, link, type, style, property); if (linkStyle.IsToProcess()) { linkStyle.UpdateStyles(); linkStyle.SetProperties(); linkStyle.SetEaLayoutStyles(); } } eaDia.ReloadSelectedObjectsAndConnector(saveDiagram: false); } else { var liParameter = new string[4]; liParameter[0] = type; liParameter[1] = style; liParameter[2] = property; switch (rep.GetContextItemType()) { case EA.ObjectType.otPackage: EA.Package pkg = (EA.Package)rep.GetContextObject(); RecursivePackages.DoRecursivePkg(rep, pkg, null, null, SetDiagramLinkStyle, liParameter, changeScope); break; case EA.ObjectType.otElement: EA.Element el = (EA.Element)rep.GetContextObject(); RecursivePackages.DoRecursiveEl(rep, el, null, SetDiagramLinkStyle, liParameter, changeScope); break; } } }
/// <summary> /// Wrapper to change DiagramObject style /// - Selected Diagramobjects /// - Package (Diagrams and their DiagramObjects in package and below Elements) /// - Element (Diagrams and their DiagramObjects below Elements) /// </summary> /// <param name="rep"></param> /// <param name="type"></param> /// <param name="style"></param> /// <param name="property"></param> /// <param name="changeScope"></param> public static void DiagramObjectStyleWrapper(Repository rep, string type, string style, string property, ChangeScope changeScope) { EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: true); if (eaDia.Dia != null) { rep.SaveDiagram(eaDia.Dia.DiagramID); foreach (var diaObj in eaDia.SelObjects) { var a = new DiagramObjectStyle(rep, diaObj, type, style, property); var objectStyle = new DiagramObjectStyle(rep, diaObj, type, style, property); if (objectStyle.IsToProcess()) { objectStyle.UpdateStyles(); objectStyle.SetProperties(); objectStyle.SetEaLayoutStyles(); objectStyle.SetCompleteNessMarker(); } } eaDia.ReloadSelectedObjectsAndConnector(saveDiagram: false); } else { var liParameter = new string[4]; liParameter[0] = type; liParameter[1] = style; liParameter[2] = property; switch (rep.GetContextItemType()) { case ObjectType.otPackage: Package pkg = (Package)rep.GetContextObject(); RecursivePackages.DoRecursivePkg(rep, pkg, null, null, SetDiagramObjectStyle, liParameter, changeScope); break; case ObjectType.otElement: Element el = (Element)rep.GetContextObject(); RecursivePackages.DoRecursiveEl(rep, el, null, SetDiagramObjectStyle, liParameter, changeScope); break; } } }
/// <summary> /// Implements IEADiagram.RemoveElement(IEAElement element) /// </summary> /// <param name="element"></param> public void RemoveElement(IEAElement element) { for (short i = 0; i < _native.DiagramObjects.Count; i++) { DiagramObject obj = _native.DiagramObjects.GetAt(i); if (obj.ElementID.Equals(element.ID)) { _native.DiagramObjects.Delete(i); _native.DiagramObjects.Refresh(); Repository nativeRepository = EARepository.Instance.Native; nativeRepository.ReloadDiagram(_native.DiagramID); nativeRepository.SaveDiagram(_native.DiagramID); break; } } }
/// <summary> /// Implements IEADiagram.AddElement(IEAElement element) /// </summary> /// <param name="element"></param> public void AddElement(IEAElement element) { //check if element already exists on diagram if (null != GetElements().FirstOrDefault(dobj => dobj.ElementID.Equals(element.ID))) { return; } DiagramObject diaObj = _native.DiagramObjects.AddNew("l=10;r=110;t=-20;b=-80", ""); diaObj.ElementID = element.ID; diaObj.Update(); _native.DiagramObjects.Refresh(); _native.Update(); Repository nativeRepository = EARepository.Instance.Native; nativeRepository.ReloadDiagram(_native.DiagramID); nativeRepository.SaveDiagram(_native.DiagramID); }
/// <summary> /// Update all DiagramLinks of diagram /// - liParameter[0] = type; /// - liParameter[1] = style;</summary> /// - liParameter[2] = property; /// <param name="rep"></param> /// <param name="dia"></param> /// <param name="liParameter"></param> private static void SetDiagramLinkStyle(Repository rep, Diagram dia, string[] liParameter) { rep.SaveDiagram(dia.DiagramID); string types = liParameter[0]; string styles = liParameter[1]; string properties = liParameter[2]; foreach (DiagramLink link in dia.DiagramLinks) { var linkStyle = new DiagramLinkStyle(rep, link, types, styles, properties); if (linkStyle.IsToProcess()) { linkStyle.UpdateStyles(); linkStyle.SetProperties(); linkStyle.SetEaLayoutStyles(); } } rep.ReloadDiagram(dia.DiagramID); }
/// <summary> /// Update all DiagramObjects of diagram /// - liParameter[0] = type; /// - liParameter[1] = style; /// - liParameter[2] = property; /// </summary> /// <param name="rep"></param> /// <param name="dia"></param> /// <param name="liParameter"></param> private static void SetDiagramObjectStyle(Repository rep, Diagram dia, string[] liParameter) { rep.SaveDiagram(dia.DiagramID); string types = liParameter[0]; string styles = liParameter[1]; string properties = liParameter[2]; foreach (DiagramObject obj in dia.DiagramObjects) { var objStyle = new DiagramObjectStyle(rep, obj, types, styles, properties); if (objStyle.IsToProcess()) { objStyle.UpdateStyles(); objStyle.SetProperties(); objStyle.SetEaLayoutStyles(); objStyle.SetCompleteNessMarker(); } } rep.ReloadDiagram(dia.DiagramID); }
/// <summary> /// Updates the diagrams of a package. /// </summary> /// <param name="package">The package.</param> private static void UpdateDiagrams(Package package) { IEnumerator enumDiagrams = package.Diagrams.GetEnumerator(); enumDiagrams.Reset(); while (enumDiagrams.MoveNext()) { Diagram diagram = (Diagram)enumDiagrams.Current; if (diagram != null) { pRepository.SaveDiagram(diagram.DiagramID); pRepository.ReloadDiagram(diagram.DiagramID); } } IEnumerator enumPackage = package.Packages.GetEnumerator(); enumPackage.Reset(); while (enumPackage.MoveNext()) { Package subPackage = (Package)enumPackage.Current; UpdateDiagrams(subPackage); } }
public static void AddDiagramNote(Repository rep) { ObjectType oType = rep.GetContextItemType(); if (oType.Equals(ObjectType.otDiagram)) { Diagram dia = rep.GetCurrentDiagram(); if (dia == null) return; Package pkg = rep.GetPackageByID(dia.PackageID); if (pkg.IsProtected || dia.IsLocked) return; // save diagram rep.SaveDiagram(dia.DiagramID); Element elNote; try { elNote = (Element) pkg.Elements.AddNew("", "Note"); elNote.Update(); pkg.Update(); } catch { return; } // add element to diagram // "l=200;r=400;t=200;b=600;" // get the position of the Element int left = (dia.cx/2) - 100; int right = left + 200; int top = dia.cy - 150; int bottom = top + 120; //int right = diaObj.right + 2 * (diaObj.right - diaObj.left); string position = "l=" + left + ";r=" + right + ";t=" + top + ";b=" + bottom + ";"; var diaObject = (DiagramObject) dia.DiagramObjects.AddNew(position, ""); dia.Update(); diaObject.ElementID = elNote.ElementID; diaObject.Update(); pkg.Elements.Refresh(); Util.SetDiagramHasAttchaedLink(rep, elNote); rep.ReloadDiagram(dia.DiagramID); } }
public static void ShowEmbeddedElementsGui( Repository rep, string embeddedElementType = "Port Pin Parameter", bool isOptimizePortLayout = false) { var dia = rep.GetCurrentDiagram(); if (dia == null) return; rep.SaveDiagram(dia.DiagramID); var sqlUtil = new UtilSql(rep); // over all selected elements foreach (DiagramObject diaObj in dia.SelectedObjects) { var elSource = rep.GetElementByID(diaObj.ElementID); if (!"Class Component Activity".Contains(elSource.Type)) continue; // find object on Diagram var diaObjSource = Util.GetDiagramObjectById(rep, dia, elSource.ElementID); //diaObjSource = dia.GetDiagramObjectByID(elSource.ElementID, ""); if (diaObjSource == null) return; string[] portTypes = {"left", "right"}; foreach (string portBoundTo in portTypes) { // arrange sequence of ports if (isOptimizePortLayout == false && portBoundTo == "left") continue; int pos = 0; List<int> lPorts; if (isOptimizePortLayout == false) { lPorts = sqlUtil.GetAndSortEmbeddedElements(elSource, "", "", ""); } else { if (portBoundTo == "left") lPorts = sqlUtil.GetAndSortEmbeddedElements(elSource, "Port", "'Server', 'Receiver' ", "DESC"); else lPorts = sqlUtil.GetAndSortEmbeddedElements(elSource, "Port", "'Client', 'Sender' ", ""); } // over all sorted ports string oldStereotype = ""; foreach (int i in lPorts) { Element portEmbedded = rep.GetElementByID(i); if (embeddedElementType == "" | embeddedElementType.Contains(portEmbedded.Type)) { // only ports / parameters (port has no further embedded elements if (portEmbedded.Type == "ActivityParameter" | portEmbedded.EmbeddedElements.Count == 0) { if (isOptimizePortLayout) { if (portBoundTo == "left") { if ("Sender Client".Contains(portEmbedded.Stereotype)) continue; } else { if ("Receiver Server".Contains(portEmbedded.Stereotype)) continue; } } // Make a gap between different stereotypes if (pos == 0 && "Sender Receiver".Contains(portEmbedded.Stereotype)) oldStereotype = portEmbedded.Stereotype; if (pos > 0 && "Sender Receiver".Contains(oldStereotype) && oldStereotype != portEmbedded.Stereotype) { pos = pos + 1; // make a gap oldStereotype = portEmbedded.Stereotype; } Util.VisualizePortForDiagramobject(pos, dia, diaObjSource, portEmbedded, null, portBoundTo); pos = pos + 1; } else { // Port: Visualize Port + Interface foreach (Element interf in portEmbedded.EmbeddedElements) { Util.VisualizePortForDiagramobject(pos, dia, diaObjSource, portEmbedded, interf); pos = pos + 1; } } } } } } rep.ReloadDiagram(dia.DiagramID); }
public static void MoveEmbeddedUpGui(Repository rep) { Diagram dia = rep.GetCurrentDiagram(); if (dia == null) return; int selCount = dia.SelectedObjects.Count; if (selCount == 0) return; rep.SaveDiagram(dia.DiagramID); // check if port,.. var objPort0 = (DiagramObject) dia.SelectedObjects.GetAt(0); Element port = rep.GetElementByID(objPort0.ElementID); if (!EmbeddedElementTypes.Contains(port.Type)) return; // get parent of embedded element Element el = rep.GetElementByID(port.ParentID); DiagramObject obj = Util.GetDiagramObjectById(rep, dia, el.ElementID); //EA.DiagramObject obj = dia.GetDiagramObjectByID(el.ElementID, ""); // check if upper limit element is crossed int upLimit = obj.top - 10; // limit cross over upper bool isUpperLimitCrossed = false; foreach (DiagramObject objPort in dia.SelectedObjects) { if (objPort.top > upLimit) { isUpperLimitCrossed = true; break; } } // move all to left upper corner of element int startValueTop = obj.top + 8; int startValueLeft = obj.left + 8; int pos = 0; foreach (DiagramObject objPort in dia.SelectedObjects) { if (!isUpperLimitCrossed) { // move to top objPort.top = objPort.top + 10; objPort.Update(); } else { // move from left to right objPort.top = startValueTop; objPort.left = startValueLeft + pos*20; objPort.Update(); pos = pos + 1; } } }
static void GenerateComponentPorts(Repository rep) { int pos = 0; Diagram dia = rep.GetCurrentDiagram(); if (dia == null) return; if (!rep.GetContextItemType().Equals(ObjectType.otElement)) return; var elSource = (Element) rep.GetContextObject(); if (elSource.Type != "Component") return; Util.GetDiagramObjectById(rep, dia, elSource.ElementID); //diaObjSource = dia.GetDiagramObjectByID(elSource.ElementID, ""); rep.SaveDiagram(dia.DiagramID); foreach (DiagramObject obj in dia.DiagramObjects) { var elTarget = rep.GetElementByID(obj.ElementID); if (!("Class Interface".Contains(elTarget.Type))) continue; if (!(elTarget.Name.EndsWith("_i", StringComparison.Ordinal))) { AddPortToComponent(elSource, elTarget); pos = pos + 1; } if ("Interface Class".Contains(elTarget.Type)) { List<Element> lEl = GetIncludedHeaderFiles(rep, elTarget); foreach (Element el in lEl) { if (el == null) continue; if (!(el.Name.EndsWith("_i", StringComparison.Ordinal))) { AddPortToComponent(elSource, el); pos = pos + 1; } } } } ShowEmbeddedElementsGui(rep); }
// ReSharper disable once UnusedMember.Local static void DeleteInvisibleUseRealizationDependencies(Repository rep) { Connector con; var dia = rep.GetCurrentDiagram(); if (dia == null) return; if (!rep.GetContextItemType().Equals(ObjectType.otElement)) return; // only one diagram object selected as source if (dia.SelectedObjects.Count != 1) return; rep.SaveDiagram(dia.DiagramID); var diaObjSource = (DiagramObject) dia.SelectedObjects.GetAt(0); var elSource = rep.GetElementByID(diaObjSource.ElementID); var elSourceId = elSource.ElementID; if (!("Interface Class".Contains(elSource.Type))) return; // list of all connectorIDs var lInternalId = new List<int>(); foreach (DiagramLink link in dia.DiagramLinks) { con = rep.GetConnectorByID(link.ConnectorID); if (con.ClientID != elSourceId) continue; if (!("Usage Realisation".Contains(con.Type))) continue; lInternalId.Add(con.ConnectorID); } for (int i = elSource.Connectors.Count - 1; i >= 0; i = i - 1) { con = (Connector) elSource.Connectors.GetAt((short) i); var conType = con.Type; if ("Usage Realisation".Contains(conType)) { // check if target is.. var elTarget = rep.GetElementByID(con.SupplierID); if (elTarget.Type == "Interface") { if (lInternalId.BinarySearch(con.ConnectorID) < 0) { elSource.Connectors.DeleteAt((short) i, true); } } } } }
//---------------------------------------------------------------------------------------- // type: "Action", "Activity","Decision", "MergeNode","StateNode" // extension: "CallOperation" ,"101"=StateNode, Final, "no"= else/no Merge // comp=yes: Activity with composite Diagram //---------------------------------------------------------------------------------------- private static DiagramObject CreateDiagramObjectFromContext(Repository rep, string name, string type, string extension, int offsetHorizental = 0, int offsetVertical = 0, string guardString = "", Element srcEl = null) { int widthPerCharacter = 60; // filter out linefeed, tab name = Regex.Replace(name, @"(\n|\r|\t)", "", RegexOptions.Singleline); if (name.Length > 255) { MessageBox.Show($"{type}: '{name}' has more than 255 characters.", @"Name is to long"); return null; } Element elSource; Element elParent = null; Element elTarget; string basicType = type; if (type == "CallOperation") basicType = "Action"; Diagram dia = rep.GetCurrentDiagram(); if (dia == null) return null; rep.SaveDiagram(dia.DiagramID); // only one diagram object selected as source if (srcEl == null) elSource = Util.GetElementFromContextObject(rep); else elSource = srcEl; if (elSource == null) return null; var diaObjSource = Util.GetDiagramObjectById(rep, dia, elSource.ElementID); //diaObjSource = dia.GetDiagramObjectByID(elSource.ElementID, ""); string noValifTypes = "Note, Constraint, Boundary, Text, UMLDiagram, DiagramFrame"; if (noValifTypes.Contains(elSource.Type)) return null; if (elSource.ParentID != 0) { Util.GetDiagramObjectById(rep, dia, elSource.ParentID); //diaObjParent = dia.GetDiagramObjectByID(elSource.ParentID, ""); } try { if (elSource.ParentID > 0) { elParent = rep.GetElementByID(elSource.ParentID); elTarget = (Element) elParent.Elements.AddNew(name, basicType); if (basicType == "StateNode") elTarget.Subtype = Convert.ToInt32(extension); elParent.Elements.Refresh(); } else { var pkg = rep.GetPackageByID(elSource.PackageID); elTarget = (Element) pkg.Elements.AddNew(name, basicType); if (basicType == "StateNode") elTarget.Subtype = Convert.ToInt32(extension); pkg.Elements.Refresh(); } elTarget.ParentID = elSource.ParentID; elTarget.Update(); if (basicType == "Activity" & extension.ToLower() == "comp=yes") { Diagram actDia = ActivityPar.CreateActivityCompositeDiagram(rep, elTarget); Util.SetActivityCompositeDiagram(rep, elTarget, actDia.DiagramID.ToString()); //elTarget. } } catch { return null; } int left = diaObjSource.left + offsetHorizental; int right = diaObjSource.right + offsetHorizental; int top = diaObjSource.top + offsetVertical; int bottom = diaObjSource.bottom + offsetVertical; int length; if (basicType == "StateNode") { left = left - 10 + (right - left)/2; right = left + 20; top = bottom - 20; bottom = top - 20; } if ((basicType == "Decision") | (basicType == "MergeNode")) { if (guardString == "no") { if (elSource.Type == "Decision") left = left + (right - left) + 200; else left = left + (right - left) + 50; bottom = bottom - 5; } left = left - 15 + (right - left)/2; right = left + 30; top = bottom - 20; bottom = top - 40; } if (basicType == "Action" | basicType == "Activity") { length = name.Length*widthPerCharacter/10; if (extension.ToLower() == "comp=no") { /* Activity ind diagram */ if (length < 500) length = 500; left = left + ((right - left)/2) - (length/2); right = left + length; top = bottom - 20; bottom = top - 200; if (basicType == "Activity") bottom = top - 400; } else if (extension.ToLower() == "comp=yes") { if (length < 220) length = 220; left = left + ((right - left)/2) - (length/2); right = left + length; top = bottom - 40; bottom = top - 40; } else { if (length < 220) length = 220; left = left + ((right - left)/2) - (length/2); right = left + length; top = bottom - 20; bottom = top - 20; } } // limit values if (left < 5) left = 5; string position = "l=" + left + ";r=" + right + ";t=" + top + ";b=" + bottom + ";"; // end note if (elParent != null && elParent.Type == "Activity" && extension == "101") { DiagramObject diaObj = Util.GetDiagramObjectById(rep, dia, elParent.ElementID); //EA.DiagramObject diaObj = dia.GetDiagramObjectByID(elParent.ElementID,""); if (diaObj != null) { diaObj.bottom = bottom - 40; diaObj.Update(); } } Util.AddSequenceNumber(rep, dia); var diaObjTarget = (DiagramObject) dia.DiagramObjects.AddNew(position, ""); diaObjTarget.ElementID = elTarget.ElementID; diaObjTarget.Sequence = 1; diaObjTarget.Update(); Util.SetSequenceNumber(rep, dia, diaObjTarget, "1"); // position the label: // LBL=CX=180: length of label // CY=13: hight of label // OX=26: x-position of label (relative object) // CY=13: y-position of label (relative object) if (basicType == "Decision" & name.Length > 0) { if (name.Length > 25) length = 25*widthPerCharacter/10; else length = name.Length*widthPerCharacter/10; // string s = "DUID=E2352ABC;LBL=CX=180:CY=13:OX=29:OY=-4:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;;"; string s = "DUID=E2352ABC;LBL=CX=180:CY=13:OX=-" + length + ":OY=-4:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;;"; Util.SetDiagramObjectLabel(rep, diaObjTarget.ElementID, diaObjTarget.DiagramID, diaObjTarget.InstanceID, s); } if (extension == "Comp=no") { /* Activity ind diagram */ // place an init int initLeft = left + ((right - left)/2) - 10; int initRight = initLeft + 20; int initTop = top - 25; int initBottom = initTop - 20; string initPosition = "l=" + initLeft + ";r=" + initRight + ";t=" + initTop + ";b=" + initBottom + ";"; ActivityPar.CreateInitFinalNode(rep, dia, elTarget, 100, initPosition); } // draw a Control Flow var con = (Connector) elSource.Connectors.AddNew("", "ControlFlow"); con.SupplierID = elTarget.ElementID; con.Update(); elSource.Connectors.Refresh(); // set line style LV foreach (DiagramLink link in dia.DiagramLinks) { if (link.ConnectorID == con.ConnectorID) { if (guardString != "no") { link.Geometry = "EDGE=3;$LLB=;LLT=;LMT=;LMB=CX=21:CY=13:OX=-20:OY=-19:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:DIR=0:ROT=0;LRT=;LRB=;IRHS=;ILHS=;"; } // in case of switch case line style = LH string style = "LV"; if ((elSource.Type == "Action" | elSource.Type == "Activity") & guardString == "no") style = "LH"; if (Regex.IsMatch(elSource.Name, @"switch[\s]*\(")) style = "OS"; Util.SetLineStyleForDiagramLink(style, link); break; } } // set Guard if (guardString != "") { if (guardString == "no" && elSource.Type != "Decision") { // mo GUARD } else { // GUARD Util.SetConnectorGuard(rep, con.ConnectorID, guardString); } } else if (elSource.Type.Equals("Decision") & !elSource.Name.Trim().Equals("")) { if (guardString == "no") { Util.SetConnectorGuard(rep, con.ConnectorID, "no"); } else { Util.SetConnectorGuard(rep, con.ConnectorID, "yes"); } } // handle subtypes of action if (type == "CallOperation") { Method method = CallOperationAction.GetMethodFromMethodName(rep, extension); if (method != null) { CallOperationAction.CreateCallAction(rep, elTarget, method); } } rep.ReloadDiagram(dia.DiagramID); // set selected object dia.SelectedObjects.AddNew(diaObjTarget.ElementID.ToString(), diaObjTarget.ObjectType.ToString()); dia.SelectedObjects.Refresh(); return diaObjTarget; }
public void SaveDiagram(int DiagramID) { repo.SaveDiagram(DiagramID); }
static void CreateTypeDefStructFromText(Repository rep, Diagram dia, Package pkg, Element el, string txt) { Element elTypedef = null; // delete comment txt = DeleteComment(txt); bool update = false; bool isStruct = true; string elType = "Class"; // find start string regex = @"[\s]*typedef[\s]+(struct|enum)[\s]*([^{]*){"; Match match = Regex.Match(txt, regex); if (!match.Success) return; if (txt.Contains(" enum")) { elType = "Enumeration"; isStruct = false; } txt = txt.Replace(match.Value, ""); // find name regex = @"}[\s]*([^;]*);"; match = Regex.Match(txt, regex); if (!match.Success) return; string name = match.Groups[1].Value.Trim(); if (name == "") return; txt = txt.Remove(match.Index, match.Length); // check if typedef already exists int targetId = Util.GetTypeId(rep, name); if (targetId != 0) { elTypedef = rep.GetElementByID(targetId); update = true; for (int i = elTypedef.Attributes.Count - 1; i > -1; i = i - 1) { elTypedef.Attributes.DeleteAt((short) i, true); } } // create typedef if (update == false) { if (el != null) { // create class below element if ("Interface Class Component".Contains(el.Type)) { elTypedef = (Element) el.Elements.AddNew(name, elType); el.Elements.Refresh(); } else { MessageBox.Show(@"Can't create element below selected Element"); } } else // create class in package { elTypedef = (Element) pkg.Elements.AddNew(name, elType); pkg.Elements.Refresh(); } } if (isStruct) { elTypedef.Stereotype = @"struct"; EA.TaggedValue tag = TaggedValue.AddTaggedValue(elTypedef, "typedef"); tag.Value = "true"; tag.Update(); } if (update == false) { elTypedef.Name = name; elTypedef.Update(); } // add elements if (isStruct) CreateClassAttributesFromText(rep, elTypedef, txt); else CreateEnumerationAttributesFromText(rep, elTypedef, txt); if (update) { rep.RefreshModelView(elTypedef.PackageID); rep.ShowInProjectView(elTypedef); } else { // put diagram object on diagram int left = 0; int right = left + 200; int top = 0; int bottom = top + 100; //int right = diaObj.right + 2 * (diaObj.right - diaObj.left); rep.SaveDiagram(dia.DiagramID); string position = "l=" + left + ";r=" + right + ";t=" + top + ";b=" + bottom + ";"; var diaObj = (DiagramObject) dia.DiagramObjects.AddNew(position, ""); dia.DiagramObjects.Refresh(); diaObj.ElementID = elTypedef.ElementID; diaObj.Update(); } rep.ReloadDiagram(dia.DiagramID); dia.SelectedObjects.AddNew(elTypedef.ElementID.ToString(), elTypedef.ObjectType.ToString()); dia.SelectedObjects.Refresh(); }
private static void CreateOperationsFromText(Repository rep, string txt) { Diagram dia = rep.GetCurrentDiagram(); Element el = Util.GetElementFromContextObject(rep); if (el == null) return; if (dia != null && dia.SelectedObjects.Count != 1) { dia = null; } if (dia != null) rep.SaveDiagram(dia.DiagramID); // delete comment txt = DeleteComment(txt); txt = DeleteCurleyBrackets(txt); txt = txt.Replace(";", " "); // delete macros txt = Regex.Replace(txt, @"^[\s]*#[^\n]*\n", "", RegexOptions.Multiline); string[] lTxt = Regex.Split(txt, @"\)[\s]*\r\n"); for (int i = 0; i < lTxt.Length; i++) { txt = lTxt[i].Trim(); if (!txt.Equals("")) { if (!txt.EndsWith(")", StringComparison.Ordinal)) txt = txt + ")"; CreateOperationFromText(rep, el, txt); } } if (dia != null) rep.ReloadDiagram(dia.DiagramID); dia.SelectedObjects.AddNew(el.ElementID.ToString(), el.ObjectType.ToString()); dia.SelectedObjects.Refresh(); }
public static void UpdateActivityParameter(Repository rep) { ObjectType oType = rep.GetContextItemType(); if (oType.Equals(ObjectType.otElement)) { var el = (Element) rep.GetContextObject(); if (el.Type.Equals("Activity")) { // get the associated operation Method m = Util.GetOperationFromBrehavior(rep, el); if (el.Locked) return; if (m == null) return; ActivityPar.UpdateParameterFromOperation(rep, el, m); // get parameters from Operation for Activity Diagram dia = rep.GetCurrentDiagram(); if (dia == null) return; DiagramObject diaObj = Util.GetDiagramObjectById(rep, dia, el.ElementID); //EA.DiagramObject diaObj = dia.GetDiagramObjectByID(el.ElementID,""); if (diaObj == null) return; int pos = 0; rep.SaveDiagram(dia.DiagramID); foreach (Element actPar in el.EmbeddedElements) { if (!actPar.Type.Equals("ActivityParameter")) continue; Util.VisualizePortForDiagramobject(pos, dia, diaObj, actPar, null); pos = pos + 1; } rep.ReloadDiagram(dia.DiagramID); } if (el.Type.Equals("Class") | el.Type.Equals("Interface")) { UpdateActivityParameterForElement(rep, el); } } if (oType.Equals(ObjectType.otMethod)) { var m = (Method) rep.GetContextObject(); Element act = Appl.GetBehaviorForOperation(rep, m); if (act == null) return; if (act.Locked) return; ActivityPar.UpdateParameterFromOperation(rep, act, m); // get parameters from Operation for Activity } if (oType.Equals(ObjectType.otPackage)) { var pkg = (Package) rep.GetContextObject(); UpdateActivityParameterForPackage(rep, pkg); } }
/// <summary> /// Add Element note for diagram Object from:<para/> /// Element, Attribute, Operation, Package /// /// </summary> /// <param name="rep"></param> /// <param name="diaObj"></param> public static void AddElementNote(Repository rep, DiagramObject diaObj) { Element el = rep.GetElementByID(diaObj.ElementID); if (el != null) { Diagram dia = rep.GetCurrentDiagram(); Package pkg = rep.GetPackageByID(el.PackageID); if (pkg.IsProtected || dia.IsLocked || el.Locked) return; // save diagram;// rep.SaveDiagram(dia.DiagramID); Element elNote; try { elNote = (Element) pkg.Elements.AddNew("", "Note"); elNote.Update(); pkg.Update(); } catch { return; } // add element to diagram // "l=200;r=400;t=200;b=600;" int left = diaObj.right + 50; int right = left + 100; int top = diaObj.top; int bottom = top - 100; string position = "l=" + left + ";r=" + right + ";t=" + top + ";b=" + bottom + ";"; var diaObject = (DiagramObject) dia.DiagramObjects.AddNew(position, ""); dia.Update(); diaObject.ElementID = elNote.ElementID; diaObject.Sequence = 1; // put element to top diaObject.Update(); pkg.Elements.Refresh(); // make a connector var con = (Connector) el.Connectors.AddNew("test", "NoteLink"); con.SupplierID = elNote.ElementID; con.Update(); el.Connectors.Refresh(); Util.SetElementHasAttchaedLink(rep, el, elNote); rep.ReloadDiagram(dia.DiagramID); } }
// ReSharper disable once UnusedMember.Local static void InsertInterface(Repository rep, Diagram dia, string text) { bool isComponent = false; Package pkg = rep.GetPackageByID(dia.PackageID); int pos = 0; // only one diagram object selected as source if (dia.SelectedObjects.Count != 1) return; // save selected object DiagramObject objSelected = null; if (!(dia == null && dia.SelectedObjects.Count > 0)) { objSelected = (DiagramObject) dia.SelectedObjects.GetAt(0); } rep.SaveDiagram(dia.DiagramID); var diaObjSource = (DiagramObject) dia.SelectedObjects.GetAt(0); var elSource = rep.GetElementByID(diaObjSource.ElementID); isComponent |= elSource.Type == "Component"; // remember selected object List<Element> ifList = GetInterfacesFromText(rep, pkg, text); foreach (Element elTarget in ifList) { if (elSource.Locked) { MessageBox.Show($"Source '{elSource.Name}' is locked", @"Element locked"); continue; } if (isComponent) { AddPortToComponent(elSource, elTarget); } else { AddInterfaceToElement(rep, pos, elSource, elTarget, dia, diaObjSource); } pos = pos + 1; } // visualize ports if (isComponent) { dia.SelectedObjects.AddNew(diaObjSource.ElementID.ToString(), ObjectType.otElement.ToString()); dia.SelectedObjects.Refresh(); ShowEmbeddedElementsGui(rep); } // reload selected object if (objSelected != null) { dia.SelectedObjects.AddNew(elSource.ElementID.ToString(), elSource.ObjectType.ToString()); dia.SelectedObjects.Refresh(); } rep.ReloadDiagram(dia.DiagramID); dia.SelectedObjects.AddNew(elSource.ElementID.ToString(), elSource.ObjectType.ToString()); dia.SelectedObjects.Refresh(); }
// ReSharper disable once UnusedMember.Global // dynamical usage as configurable service by reflection public static void SplitAllDiagramObjectsToLastSelected(Repository rep) { Diagram dia = rep.GetCurrentDiagram(); if (dia == null) return; int count = dia.SelectedObjects.Count; if (count == 0) return; rep.SaveDiagram(dia.DiagramID); // target object/element ObjectType objType = rep.GetContextItemType(); if (!(objType.Equals(ObjectType.otElement))) return; var trgEl = (Element) rep.GetContextObject(); foreach (DiagramObject srcObj in dia.DiagramObjects) { var srcEl = rep.GetElementByID(srcObj.ElementID); if (srcEl.ElementID == trgEl.ElementID) continue; SplitElementsByConnectorType(srcEl, trgEl); } rep.ReloadDiagram(dia.DiagramID); dia.SelectedObjects.AddNew(trgEl.ElementID.ToString(), trgEl.ObjectType.ToString()); }
// ReSharper disable once UnusedMember.Local private static void MakeNested(Repository rep) { Diagram dia = rep.GetCurrentDiagram(); if (dia == null) return; int count = dia.SelectedObjects.Count; if (count < 2) return; rep.SaveDiagram(dia.DiagramID); // target object/element ObjectType objType = rep.GetContextItemType(); if (!(objType.Equals(ObjectType.otElement))) return; var trgEl = (Element) rep.GetContextObject(); if (!(trgEl.Type.Equals("Activity"))) { MessageBox.Show($"Target '{trgEl.Name}:{trgEl.Type}' isn't an Activity", @" Only move below Activity is allowed"); return; } for (int i = 0; i < count; i = i + 1) { var srcObj = (DiagramObject) dia.SelectedObjects.GetAt((short) i); var srcEl = rep.GetElementByID(srcObj.ElementID); if (srcEl.ElementID == trgEl.ElementID) continue; srcEl.ParentID = trgEl.ElementID; srcEl.Update(); } }
/// <summary>insertDiagramElement insert a diagram element and connects it to all selected diagramobject /// <para>type: type of the node like "Action", Activity", "MergeNode"</para> /// MergeNode may have the subType "no" to draw a transition with a "no" guard. /// <para>subTyp: subType of the node: /// StateNode: 100=ActivityInitial, 101 ActivityFinal /// </para>guardString of the connector "","yes","no",.. /// if "yes" or "" it will locate the node under the last selected element /// </summary> // ReSharper disable once UnusedMember.Global public static void InsertDiagramElementAndConnect(Repository rep, string type, string subType, string guardString = "") { Diagram dia = rep.GetCurrentDiagram(); if (dia == null) return; if (dia.Type != "Activity") return; int count = dia.SelectedObjects.Count; if (count == 0) return; rep.SaveDiagram(dia.DiagramID); var oldCollection = new List<DiagramObject>(); // get context element (last selected element) Element originalSrcEl = Util.GetElementFromContextObject(rep); if (originalSrcEl == null) return; int originalSrcId = originalSrcEl.ElementID; for (int i = count - 1; i > -1; i = i - 1) { oldCollection.Add((DiagramObject) dia.SelectedObjects.GetAt((short) i)); // keep last selected element //if (i > 0) dia.SelectedObjects.DeleteAt((short)i, true); } Util.GetDiagramObjectById(rep, dia, originalSrcId); //EA.DiagramObject originalSrcObj = dia.GetDiagramObjectByID(originalSrcID, ""); DiagramObject trgObj = CreateDiagramObjectFromContext(rep, "", type, subType, 0, 0, guardString, originalSrcEl); Element trgtEl = rep.GetElementByID(trgObj.ElementID); // if connection to more than one element make sure the new element is on the deepest position int offset = 50; if (guardString == "yes") offset = 0; int bottom = 1000; int diff = trgObj.top - trgObj.bottom; foreach (DiagramObject diaObj in oldCollection) { Element srcEl = rep.GetElementByID(diaObj.ElementID); // don't connect two times if (originalSrcId != diaObj.ElementID) { var con = (Connector) srcEl.Connectors.AddNew("", "ControlFlow"); con.SupplierID = trgObj.ElementID; if (type == "MergeNode" && guardString == "no" && srcEl.Type == "Decision") con.TransitionGuard = "no"; con.Update(); srcEl.Connectors.Refresh(); dia.DiagramLinks.Refresh(); //trgtEl.Connectors.Refresh(); // set line style string style = "LV"; if ((srcEl.Type == "Action" | srcEl.Type == "Activity") & guardString == "no") style = "LH"; var link = GetDiagramLinkForConnector(dia, con.ConnectorID); if (link != null) Util.SetLineStyleForDiagramLink(style, link); } // set new high/bottom_Position var srcObj = Util.GetDiagramObjectById(rep, dia, srcEl.ElementID); //srcObj = dia.GetDiagramObjectByID(srcEl.ElementID, ""); if (srcObj.bottom < bottom) bottom = srcObj.bottom; } if (oldCollection.Count > 1) { // set bottom/high of target trgObj.top = bottom + diff - offset; trgObj.bottom = bottom - offset; trgObj.Sequence = 1; trgObj.Update(); // final if (subType == "101" && trgtEl.ParentID > 0) { Element parEl = rep.GetElementByID(trgtEl.ParentID); if (parEl.Type == "Activity") { DiagramObject parObj = Util.GetDiagramObjectById(rep, dia, parEl.ElementID); //EA.DiagramObject parObj = dia.GetDiagramObjectByID(parEl.ElementID, ""); if (parObj != null) { parObj.bottom = trgObj.bottom - 30; parObj.Update(); } } } } rep.ReloadDiagram(dia.DiagramID); dia.SelectedObjects.AddNew(trgtEl.ElementID.ToString(), trgtEl.ObjectType.ToString()); }
// ReSharper disable once MemberCanBePrivate.Global public void Save() { _rep.SaveDiagram(_dia.DiagramID); }
/// <summary> /// Set Diagram styles in PDATA and StyleEx. It simply updates the parameters in both field. /// /// HideQuals=1 HideQualifiers: /// OpParams=2 Show full Operation Parameter /// ScalePI=1 Scale to fit page /// Theme=:119 Set the diagram theme and the used features of the theme (here 119, see StyleEx of t_diagram) /// </summary> /// <param name="rep"></param> /// <param name="dia"></param> /// <param name="par">par[0] contains the values as a semicolon/comma separated types</param> /// <param name="par">par[1] contains the values as a semicolon/comma separated properties</param> /// <param name="par">par[2] contains the possible diagram types</param> public static void SetDiagramStyleDeleteMe(Repository rep, EA.Diagram dia, string[] par) { // Make '; as delimiter for types string styles = par[0].Replace(",", ";"); string properties = par[1].Replace(",", ";"); string dStyles = par[2].Replace(",", ";"); string[] styleEx = styles.Split(';'); string diaStyle = dia.StyleEx; string diaExtendedStyle = dia.ExtendedStyle.Trim(); if (!DiagramIsToChange(dia, dStyles)) { return; } // no distinguishing between StyleEx and ExtendedStayle, may cause of trouble if (dia.StyleEx == "") { diaStyle = dStyles + ";"; } if (dia.ExtendedStyle == "") { diaExtendedStyle = dStyles + ";"; } // find: Name=value Regex rx = new Regex(@"([^=]*)=(.*)"); rep.SaveDiagram(dia.DiagramID); // update the ExtendedStyle, StyleEX with PDATA1, StyleEX // Steps of update: // 1. StyleEx, ExtendedStyleEx // 2. Properties which represents EA Properties // 3. Properties which are set by SQL // Don't change order, Update() foreach (string style in styleEx) { if (style.Trim() == "") { continue; } Match match = rx.Match(style.Trim()); if (!match.Success) { continue; } string patternFind = $@"{match.Groups[1].Value}=[^;]*;"; diaStyle = Regex.Replace(diaStyle, patternFind, $@"{style};"); diaExtendedStyle = Regex.Replace(diaExtendedStyle, patternFind, $@"{style};"); // advanced styles //SetAdvancedStyle(rep, dia, match.Groups[1].Value, match.Groups[2].Value); //var schowForeign0 = rep.GetStringsBySql($@"select ShowForeign from t_diagram where Diagram_ID = {dia.DiagramID}"); } // delete spaces to avoid sql exception (string to long) dia.ExtendedStyle = diaExtendedStyle.Replace("; ", ";").Replace("; ", ";").Replace("; ", ";").Trim(); dia.StyleEx = diaStyle.Replace("; ", ";").Replace("; ", ";").Replace("; ", ";").Trim(); dia.Update(); // update non SQL Diagram properties foreach (string property in properties.Split(';')) { if (property.Trim() == "") { continue; } Match match = rx.Match(property.Trim()); if (!match.Success) { continue; } // advanced styles SetDiagramProperty(rep, dia, match.Groups[1].Value, match.Groups[2].Value, withSql: false); } dia.Update(); // update SQL Diagram properties foreach (string property in properties.Split(';')) { if (property.Trim() == "") { continue; } Match match = rx.Match(property.Trim()); if (!match.Success) { continue; } // advanced styles SetDiagramProperty(rep, dia, match.Groups[1].Value, match.Groups[2].Value, withSql: true); } rep.ReloadDiagram(dia.DiagramID); }
// ReSharper disable once UnusedMember.Global // dynamical usage as configurable service by reflection public static void JoinDiagramObjectsToLastSelected(Repository rep) { Diagram dia = rep.GetCurrentDiagram(); if (dia == null) return; int count = dia.SelectedObjects.Count; if (count < 2) return; rep.SaveDiagram(dia.DiagramID); // target object/element var trgEl = (Element) rep.GetContextObject(); for (int i = 0; i < count; i = i + 1) { var srcObj = (DiagramObject) dia.SelectedObjects.GetAt((short) i); var srcEl = rep.GetElementByID(srcObj.ElementID); if (srcEl.ElementID == trgEl.ElementID) continue; Connectors.Connector connector = GetConnectionDefault(); var con = (Connector) srcEl.Connectors.AddNew("", connector.Type); con.SupplierID = trgEl.ElementID; con.Stereotype = connector.Stereotype; con.Update(); srcEl.Connectors.Refresh(); trgEl.Connectors.Refresh(); dia.DiagramLinks.Refresh(); // set line style DiagramLink link = GetDiagramLinkForConnector(dia, con.ConnectorID); if (link != null) Util.SetLineStyleForDiagramLink("LV", link); } rep.ReloadDiagram(dia.DiagramID); dia.SelectedObjects.AddNew(trgEl.ElementID.ToString(), trgEl.ObjectType.ToString()); }