/// <summary> /// Set DiagramObject properties. You can use 'style' and/or 'properties'. 'style' can be 'none' to not use the style. /// First set style (overwrite all styles or none) than update styles by properties. /// style: set according to style (overwrite everything) /// properties: set the EA properties (only the chosen properties) /// /// </summary> /// <param name="rep"></param> /// <param name="diaObject"></param> /// <param name="style">Either style or properties</param> /// <param name="properties"></param> public static void SetDiagramObjectStyle(Repository rep, EA.DiagramObject diaObject, string style, string properties) { if (!String.IsNullOrEmpty(style)) { // only use style if not 'none' if (style.ToLower() != "none") { // preserve DUID Diagram Unit Identifier string s = (string)diaObject.Style; Match match = Regex.Match(s, @"DUID=[A-Z0-9a-z]+;"); string duid = ""; if (match.Success) { duid = match.Groups[0].Value; } s = duid + style.Replace(",", ";").Replace(" ", "").Replace(" ", "") .Replace(" ", "") .Trim(); // ensure string ends with ";" if (s.Trim() != "" & (!s.EndsWith(";"))) { s = s + ";"; } diaObject.Style = s; try { diaObject.Update(); } catch (Exception e) { // Probably style is to long to contain all features MessageBox.Show($@"EA has a restriction of the length of the Database field. {e} ", @"Style is to long, make it shorter!"); } } } // always use properties if (!String.IsNullOrEmpty(properties)) { // Check if there is a DiagramObject property to use properties = properties.Replace(",", ";").Replace(" ", "").Replace(" ", "").Replace(" ", "").Trim(); foreach (var property in properties.Split(';')) { SetDiagramObjectStyle(rep, diaObject, property.Trim()); } diaObject.Update(); } }
private void UpdateElementOnDiagram( EAAPI.Diagram lifeCycleDiagram, int elementID, String backgroundColor) { // Parse out the old BCol and add the new. if (!String.IsNullOrEmpty(backgroundColor)) { EAAPI.DiagramObject obj = null; for (short nIndex = 0; nIndex < lifeCycleDiagram.DiagramObjects.Count; nIndex++) { obj = (EAAPI.DiagramObject)lifeCycleDiagram.DiagramObjects.GetAt(nIndex); if (obj.ElementID == elementID) { break; } } if (null != obj) { String styleString = obj.Style.ToString(); String[] styleList = styleString.Split(';'); for (int nIndex = 0; nIndex < styleList.Count(); nIndex++) { if (true == styleList[nIndex].Contains("BCol")) { styleList[nIndex] = backgroundColor; } } styleString = String.Join(";", styleList); obj.Style = styleString; obj.Update(); } } }
private void FixDiagramObjectsSequence(EAAPI.Diagram lifeCycleDiagram, Dictionary <String, EAAPI.Element> elements) { // Get a list of the diagram elements that are actually on the diagram in the repository. String resultString = eaRepo.SQLQuery( "Select DO.Diagram_ID, DO.Object_ID, DO.Sequence, O.Alias from t_diagramobjects DO, t_object O where DO.Object_ID = o.Object_ID and DO.Diagram_ID = " + lifeCycleDiagram.DiagramID.ToString()); List <Utility.EA.Sequence.SequenceRow> sequenceRows = Utility.EA.Sequence.DeSerialiseEASQLQueryResult.DeSerialiseAsDiagramRow(resultString); EAAPI.DiagramObject diagramObject = null; Utility.EA.Sequence.SequenceRow sequenceRow; int nAliasIndex; int maxSequence = diagramConfig.Elements.Element.Count(); int oldSequence; // Build a list of aliases List <String> elementAliases = new List <string>(); foreach (Element elementName in diagramConfig.Elements.Element) { elementAliases.Add(FormatDiagramElementAlias(lifeCycleDiagram.DiagramID, elementName.Name)); } for (int nIndex = 0; nIndex < sequenceRows.Count; nIndex++) { sequenceRow = sequenceRows[nIndex]; // Is it one of our aliases? if (elementAliases.Contains(sequenceRow.Alias)) { nAliasIndex = elementAliases.IndexOf(sequenceRow.Alias); diagramObject = (EAAPI.DiagramObject)lifeCycleDiagram.GetDiagramObjectByID(SafeToInt(sequenceRow.Object_ID, 0), null); diagramObject.Sequence = maxSequence - nAliasIndex; // EA goes backwards putting the last element to draw first. diagramObject.Update(); } else { oldSequence = diagramObject.Sequence; if (EA_ELEMENT_NOT_SEQUENCED != oldSequence && oldSequence <= maxSequence) { diagramObject = (EAAPI.DiagramObject)lifeCycleDiagram.GetDiagramObjectByID(SafeToInt(sequenceRow.Object_ID, 0), null); diagramObject.Sequence = oldSequence + (maxSequence - oldSequence) + 1; // EA goes backwards putting the last element to draw first. diagramObject.Update(); } } } }
/// <summary> /// Update Diagram Object /// </summary> private void Update() { try { _diaObj.Update(); } catch (Exception e) { MessageBox.Show($"Style is possibly to long for DB field\r\n\r\n{e}", "Cant write Diagram Styles!"); } }
private static void ChangeLabel(DiagramObject portObj, string from, string to) { var style = (string)portObj.Style; Match match = Regex.Match(style, from); if (match.Success) { style = style.Replace(match.Value, to); portObj.Style = style; portObj.Update(); } }
public static void VisualizePortForDiagramobject(int pos, EA.Diagram dia, EA.DiagramObject diaObjSource, EA.Element port, EA.Element interf) { // check if port already exists foreach (EA.DiagramObject diaObj in dia.DiagramObjects) { if (diaObj.ElementID == port.ElementID) { return; } } // visualize ports int length = 6; // calculate target position int left = diaObjSource.right - length / 2; int right = left + length; int top = diaObjSource.top; top = top - 10 - pos * 10; var bottom = top - length; string position = $"l={left};r={right};t={top};b={bottom};"; EA.DiagramObject diaObject = (EA.DiagramObject)dia.DiagramObjects.AddNew(position, ""); dia.Update(); if (port.Type.Equals("Port")) { // not showing label diaObject.Style = "LBL=CX=97:CY=13:OX=0:OY=0:HDN=1:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;"; } else { // not showing label diaObject.Style = "LBL=CX=97:CY=13:OX=39:OY=3:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;"; } diaObject.ElementID = port.ElementID; diaObject.Update(); if (interf == null) { return; } // visualize interface EA.DiagramObject diaObject2 = (EA.DiagramObject)dia.DiagramObjects.AddNew(position, ""); dia.Update(); diaObject.Style = "LBL=CX=69:CY=13:OX=-69:OY=0:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;"; diaObject2.ElementID = interf.ElementID; diaObject2.Update(); }
// subtype=100 init node // subtype=101 final node public static EA.DiagramObject CreateInitFinalNode(EA.Repository rep, EA.Diagram dia, EA.Element act, int subType, string position) { EA.Element initNode = (EA.Element)act.Elements.AddNew("", "StateNode"); initNode.Subtype = subType; initNode.Update(); if (dia != null) { HoUtil.AddSequenceNumber(rep, dia); EA.DiagramObject initDiaNode = (EA.DiagramObject)dia.DiagramObjects.AddNew(position, ""); initDiaNode.ElementID = initNode.ElementID; initDiaNode.Sequence = 1; initDiaNode.Update(); HoUtil.SetSequenceNumber(rep, dia, initDiaNode, "1"); return(initDiaNode); } return(null); }
/// <summary> /// Change Style of a DiagramObject. /// </summary> /// <param name="portObj"></param> /// <param name="from"></param> /// <param name="to"></param> private static void ChangeDiagramObjectStyle(DiagramObject portObj, string from, string to) { var style = (string)portObj.Style; Match match = Regex.Match(style, from); if (match.Success) { style = style.Replace(match.Value, to); } else // Empty style, just add new style { style = style.Replace($"{to};", "");// delete possible new value style = style + $" {to};";// insert new value } // update style portObj.Style = style; portObj.Update(); }
private void AddElementToDiagram( EAAPI.Diagram lifeCycleDiagram, int elementID, String type, int left, int right, int top, int bottom, String font, String backgroundColor) { String size = String.Format("l={0};r={1};t={2};b={3};", left, right, top, bottom); EAAPI.DiagramObject obj = (EAAPI.DiagramObject)lifeCycleDiagram.DiagramObjects.AddNew(size, type); obj.ElementID = elementID; if (!String.IsNullOrEmpty(font)) { obj.Style = obj.Style + ";" + font; } if (!String.IsNullOrEmpty(backgroundColor)) { obj.Style = obj.Style + ";" + backgroundColor; } obj.Update(); }
/// <summary> /// Create an Activity diagram beneath selected Activity. /// </summary> /// <param name="rep"></param> /// <param name="act"></param> /// <returns></returns> public static Diagram CreateActivityCompositeDiagram(Repository rep, EA.Element act) { // create activity diagram beneath Activity EA.Diagram actDia = (Diagram)act.Diagrams.AddNew(act.Name, "Activity"); // update diagram properties actDia.ShowDetails = 0; // hide details // scale page to din A4 if (actDia.StyleEx.Length > 0) { actDia.StyleEx = actDia.StyleEx.Replace("HideQuals=0", "HideQuals=1"); // hide qualifier } else { actDia.StyleEx = "HideQuals=1;"; } // Hide Qualifier if (actDia.ExtendedStyle.Length > 0) { actDia.ExtendedStyle = actDia.ExtendedStyle.Replace("ScalePI=0", "ScalePI=1"); } else { actDia.ExtendedStyle = "ScalePI=1;"; } actDia.Update(); act.Diagrams.Refresh(); // put the activity on the diagram HoUtil.AddSequenceNumber(rep, actDia); EA.DiagramObject actObj = (EA.DiagramObject)actDia.DiagramObjects.AddNew("l=30;r=780;t=30;b=1120", ""); actObj.ElementID = act.ElementID; actObj.Update(); actDia.DiagramObjects.Refresh(); // add default nodes (init/final) CreateDefaultElementsForActivity(rep, actDia, act); act.Elements.Refresh(); actDia.DiagramObjects.Refresh(); return(actDia); }
private EA.Element createNewCorrespondenceLink(EA.Package tggOutermostePackage, out EA.Connector connectorToSource, out EA.Connector connectorToTarget) { EA.Element tggLink = tggOutermostePackage.Elements.AddNew(textBoxLinkName.Text, Main.EAClassType) as EA.Element; tggLink.StereotypeEx = TGGModelingMain.TggCorrespondenceTypeStereotype; tggLink.Update(); TGGCorrespondenceType correspondenceType = new TGGCorrespondenceType(sqlRepository.GetElementByID(tggLink.ElementID), sqlRepository); correspondenceType.saveTreeToEATaggedValue(false); connectorToSource = tggLink.Connectors.AddNew("", ECOREModelingMain.EReferenceConnectorType) as EA.Connector; connectorToSource.SupplierID = clientClassifier.ElementID; connectorToSource.Direction = Main.EASourceTargetDirection; connectorToSource.SupplierEnd.Role = "source"; connectorToSource.SupplierEnd.Navigable = "Navigable"; connectorToSource.SupplierEnd.Cardinality = "1"; connectorToSource.SupplierEnd.IsNavigable = true; connectorToSource.Update(); EReference refToSource = new EReference(sqlRepository.GetConnectorByID(connectorToSource.ConnectorID), sqlRepository); refToSource.saveTreeToEATaggedValue(true); tggLink.Connectors.Refresh(); connectorToTarget = tggLink.Connectors.AddNew("", ECOREModelingMain.EReferenceConnectorType) as EA.Connector; connectorToTarget.SupplierID = supplierClassifier.ElementID; connectorToTarget.Direction = Main.EASourceTargetDirection; connectorToTarget.SupplierEnd.Role = "target"; connectorToTarget.SupplierEnd.Cardinality = "1"; connectorToTarget.SupplierEnd.Navigable = "Navigable"; connectorToTarget.SupplierEnd.IsNavigable = true; connectorToTarget.Update(); EReference refToTarget = new EReference(sqlRepository.GetConnectorByID(connectorToTarget.ConnectorID), sqlRepository); refToTarget.saveTreeToEATaggedValue(true); selectedCorrespondenceLinkId = tggLink.ElementID; EA.Diagram curDiagram = null; EA.DiagramObject sourceDiagObj = null; EA.DiagramObject targetDiagObj = null; foreach (EA.Diagram diag in tggOutermostePackage.Diagrams) { foreach (EA.DiagramObject diagObj in diag.DiagramObjects) { if (diagObj.ElementID == clientClassifier.ElementID) { sourceDiagObj = diagObj; } else if (diagObj.ElementID == supplierClassifier.ElementID) { targetDiagObj = diagObj; } if (sourceDiagObj != null && targetDiagObj != null) { curDiagram = diag; } } } if (curDiagram != null) { sqlRepository.SaveDiagram(curDiagram.DiagramID); int sourceLeft = (sourceDiagObj == null) ? 0 : sourceDiagObj.left; int sourceRight = (sourceDiagObj == null) ? 0 : sourceDiagObj.right; int sourceBottom = (sourceDiagObj == null) ? 0 : sourceDiagObj.bottom; int sourceTop = (sourceDiagObj == null) ? 0 : sourceDiagObj.top; int targetLeft = (targetDiagObj == null) ? 0 : targetDiagObj.left; int targetRight = (targetDiagObj == null) ? 0 : targetDiagObj.right; int targetBottom = (targetDiagObj == null) ? 0 : targetDiagObj.bottom; int targetTop = (targetDiagObj == null) ? 0 : targetDiagObj.top; EA.DiagramObject tggLinkDiagObj = curDiagram.DiagramObjects.AddNew("", "") as EA.DiagramObject; tggLinkDiagObj.ElementID = tggLink.ElementID; tggLinkDiagObj.Update(); tggLinkDiagObj.left = (sourceLeft + targetLeft) / 2; tggLinkDiagObj.right = (sourceRight + targetRight) / 2; tggLinkDiagObj.bottom = (sourceBottom + targetBottom) / 2; tggLinkDiagObj.top = (sourceTop + targetTop) / 2; tggLinkDiagObj.Update(); curDiagram.DiagramObjects.Refresh(); sqlRepository.ReloadDiagram(curDiagram.DiagramID); tggOutermostePackage.Elements.Refresh(); } return(tggLink); }
/// <summary> /// Create Activity for operation /// </summary> /// <param name="rep"></param> /// <param name="m"></param> /// <param name="treePos"></param> /// <param name="pkgSrc"></param> /// <param name="elClass"></param> private static void CreateActivityFromOperation(Repository rep, Method m, int treePos, EA.Package pkgSrc, EA.Element elClass) { // create a package with the name of the operation EA.Package pkgTrg = (EA.Package)pkgSrc.Packages.AddNew(m.Name, ""); pkgTrg.TreePos = treePos; pkgTrg.Update(); pkgSrc.Packages.Refresh(); EA.Element frm = null; // frame beneath package if (ActivityIsSimple == false) { // create Class Activity Diagram in target package EA.Diagram pkgActDia = (EA.Diagram)pkgTrg.Diagrams.AddNew("Operation:" + m.Name + " Content", "Activity"); pkgActDia.Update(); pkgTrg.Diagrams.Refresh(); // prevent information loss Util.SetDiagramStyleFitToPage(pkgActDia); // after save diagram! // add frame in Activity diagram EA.DiagramObject frmObj = (EA.DiagramObject)pkgActDia.DiagramObjects.AddNew("l=100;r=400;t=25;b=50", ""); frm = (EA.Element)pkgTrg.Elements.AddNew(m.Name, "UMLDiagram"); frm.Update(); frmObj.ElementID = frm.ElementID; //frmObj.Style = "fontsz=200;pitch=34;DUID=265D32D5;font=Arial Narrow;bold=0;italic=0;ul=0;charset=0;"; frmObj.Update(); pkgTrg.Elements.Refresh(); pkgActDia.DiagramObjects.Refresh(); } // create activity with the name of the operation EA.Element act = (EA.Element)pkgTrg.Elements.AddNew(m.Name, "Activity"); if (ActivityIsSimple == false) { act.Notes = "Generated from Operation:\r\n" + m.Visibility + " " + m.Name + ":" + m.ReturnType + ";\r\nDetails see Operation definition!!"; } act.StereotypeEx = m.StereotypeEx; act.Update(); pkgTrg.Elements.Refresh(); // create activity diagram beneath Activity EA.Diagram actDia = (EA.Diagram)act.Diagrams.AddNew(m.Name, "Activity"); // update diagram properties actDia.ShowDetails = 0; // hide details // scale page to din A4 if (actDia.StyleEx.Length > 0) { actDia.StyleEx = actDia.StyleEx.Replace("HideQuals=0", "HideQuals=1"); // hide qualifier } else { actDia.StyleEx = "HideQuals=1;"; } // Hide Qualifier if (actDia.ExtendedStyle.Length > 0) { actDia.ExtendedStyle = actDia.ExtendedStyle.Replace("ScalePI=0", "ScalePI=1"); } else { actDia.ExtendedStyle = "ScalePI=1;"; } actDia.Update(); act.Diagrams.Refresh(); // put the activity on the diagram Util.AddSequenceNumber(rep, actDia); EA.DiagramObject actObj = (EA.DiagramObject)actDia.DiagramObjects.AddNew("l=30;r=780;t=30;b=1120", ""); actObj.ElementID = act.ElementID; actObj.Sequence = 1; actObj.Update(); Util.SetSequenceNumber(rep, actDia, actObj, "1"); actDia.DiagramObjects.Refresh(); // add default nodes (init/final) CreateDefaultElementsForActivity(rep, actDia, act); if (ActivityIsSimple == false) { // Add Heading to diagram Util.AddSequenceNumber(rep, actDia); EA.DiagramObject noteObj = (EA.DiagramObject)actDia.DiagramObjects.AddNew("l=40;r=700;t=25;b=50", ""); EA.Element note = (EA.Element)pkgTrg.Elements.AddNew("Text", "Text"); note.Notes = m.Visibility + " " + elClass.Name + "_" + m.Name + ":" + m.ReturnType; note.Update(); noteObj.ElementID = note.ElementID; noteObj.Style = "fontsz=200;pitch=34;DUID=265D32D5;font=Arial Narrow;bold=0;italic=0;ul=0;charset=0;"; noteObj.Sequence = 1; noteObj.Update(); Util.SetSequenceNumber(rep, actDia, noteObj, "1"); } pkgTrg.Elements.Refresh(); actDia.DiagramObjects.Refresh(); // Link Operation to activity Util.SetBehaviorForOperation(rep, m, act); // Set show behavior Util.SetShowBehaviorInDiagram(rep, m); // add parameters to activity UpdateParameterFromOperation(rep, act, m); int pos = 0; foreach (EA.Element actPar in act.EmbeddedElements) { if (!actPar.Type.Equals("ActivityParameter")) { continue; } Util.VisualizePortForDiagramobject(rep, pos, actDia, actObj, actPar, null); pos = pos + 1; } if (ActivityIsSimple == false) { // link Overview frame to diagram Util.SetFrameLinksToDiagram(rep, frm, actDia); frm.Update(); } // select operation rep.ShowInProjectView(m); }
public static bool CreateInteractionForOperation(EA.Repository rep, EA.Method m) { // get class EA.Element elClass = rep.GetElementByID(m.ParentID); Package pkgSrc = rep.GetPackageByID(elClass.PackageID); // create a package with the name of the operation Package pkgTrg = (Package)pkgSrc.Packages.AddNew(m.Name, ""); pkgTrg.Update(); pkgSrc.Packages.Refresh(); // create Class Sequence Diagram in target package EA.Diagram pkgSeqDia = (EA.Diagram)pkgTrg.Diagrams.AddNew("Operation:" + m.Name + " Content", "Sequence"); pkgSeqDia.Update(); pkgTrg.Diagrams.Refresh(); // add frame in Sequence diagram EA.DiagramObject frmObj = (EA.DiagramObject)pkgSeqDia.DiagramObjects.AddNew("l=100;r=400;t=25;b=50", ""); EA.Element frm = (EA.Element)pkgTrg.Elements.AddNew(m.Name, "UMLDiagram"); frm.Update(); frmObj.ElementID = frm.ElementID; //frmObj.Style = "fontsz=200;pitch=34;DUID=265D32D5;font=Arial Narrow;bold=0;italic=0;ul=0;charset=0;"; frmObj.Update(); pkgTrg.Elements.Refresh(); pkgSeqDia.DiagramObjects.Refresh(); // create Interaction with the name of the operation EA.Element seq = (EA.Element)pkgTrg.Elements.AddNew(m.Name, "Interaction"); seq.Notes = "Generated from Operation:\r\n" + m.Visibility + " " + m.Name + ":" + m.ReturnType + ";\r\nDetails see Operation definition!!"; seq.Update(); pkgTrg.Elements.Refresh(); // create sequence diagram beneath Interaction EA.Diagram seqDia = (EA.Diagram)seq.Diagrams.AddNew(m.Name, "Sequence"); seqDia.Update(); seq.Diagrams.Refresh(); // create instance from class beneath Interaction EA.Element obj = (EA.Element)seq.Elements.AddNew("", "Object"); seq.Elements.Refresh(); obj.ClassfierID = elClass.ElementID; obj.Update(); // add node object to Sequence Diagram EA.DiagramObject node = (EA.DiagramObject)seqDia.DiagramObjects.AddNew("l=100;r=180;t=50;b=70", ""); node.ElementID = obj.ElementID; node.Update(); // Add Heading to diagram EA.DiagramObject noteObj = (EA.DiagramObject)seqDia.DiagramObjects.AddNew("l=40;r=700;t=10;b=25", ""); EA.Element note = (EA.Element)pkgTrg.Elements.AddNew("Text", "Text"); note.Notes = m.Visibility + " " + elClass.Name + "_" + m.Name + ":" + m.ReturnType; note.Update(); noteObj.ElementID = note.ElementID; noteObj.Style = "fontsz=200;pitch=34;DUID=265D32D5;font=Arial Narrow;bold=0;italic=0;ul=0;charset=0;"; noteObj.Update(); pkgTrg.Elements.Refresh(); seqDia.DiagramObjects.Refresh(); // Link Operation to activity HoUtil.SetBehaviorForOperation(rep, m, seq); // Set show behavior HoUtil.SetShowBehaviorInDiagram(rep, m); HoUtil.SetFrameLinksToDiagram(rep, frm, seqDia); // link Overview frame to diagram frm.Update(); //rep.ReloadDiagram(actDia.DiagramID); return(true); }
//----------------------------------------------------------------------------------------- // Create StateMachine for Operation //---------------------------------------------------------------------------------- public static bool CreateStateMachineForOperation(EA.Repository rep, EA.Method m) { // get class EA.Element elClass = rep.GetElementByID(m.ParentID); EA.Package pkgSrc = rep.GetPackageByID(elClass.PackageID); // create a package with the name of the operation EA.Package pkgTrg = (Package)pkgSrc.Packages.AddNew(m.Name, ""); pkgTrg.Update(); pkgSrc.Packages.Refresh(); // create Class StateMachine Diagram in target package EA.Diagram pkgSeqDia = (EA.Diagram)pkgTrg.Diagrams.AddNew("Operation:" + m.Name + " Content", "Statechart"); pkgSeqDia.Update(); pkgTrg.Diagrams.Refresh(); // add frame in StateMachine diagram EA.DiagramObject frmObj = (EA.DiagramObject)pkgSeqDia.DiagramObjects.AddNew("l=100;r=400;t=25;b=50", ""); EA.Element frm = (EA.Element)pkgTrg.Elements.AddNew(m.Name, "UMLDiagram"); frm.Update(); frmObj.ElementID = frm.ElementID; //frmObj.Style = "fontsz=200;pitch=34;DUID=265D32D5;font=Arial Narrow;bold=0;italic=0;ul=0;charset=0;"; frmObj.Update(); pkgTrg.Elements.Refresh(); pkgSeqDia.DiagramObjects.Refresh(); // create StateMachine with the name of the operation EA.Element stateMachine = (EA.Element)pkgTrg.Elements.AddNew(m.Name, "StateMachine"); stateMachine.Notes = "Generated from Operation:\r\n" + m.Visibility + " " + m.Name + ":" + m.ReturnType + ";\r\nDetails see Operation definition!!"; stateMachine.Update(); pkgTrg.Elements.Refresh(); // create Statechart diagram beneath State Machine EA.Diagram chartDia = (EA.Diagram)stateMachine.Diagrams.AddNew(m.Name, "Statechart"); chartDia.Update(); stateMachine.Diagrams.Refresh(); // put the state machine on the diagram EA.DiagramObject chartObj = (EA.DiagramObject)chartDia.DiagramObjects.AddNew("l=50;r=600;t=100;b=800", ""); chartObj.ElementID = stateMachine.ElementID; chartObj.Update(); chartDia.DiagramObjects.Refresh(); // add default nodes (init/final) CreateDefaultElementsForStateDiagram(rep, chartDia, stateMachine); // Add Heading to diagram EA.DiagramObject noteObj = (EA.DiagramObject)chartDia.DiagramObjects.AddNew("l=40;r=700;t=10;b=25", ""); EA.Element note = (EA.Element)pkgTrg.Elements.AddNew("Text", "Text"); note.Notes = m.Visibility + " " + elClass.Name + "_" + m.Name + ":" + m.ReturnType; note.Update(); noteObj.ElementID = note.ElementID; noteObj.Style = "fontsz=200;pitch=34;DUID=265D32D5;font=Arial Narrow;bold=0;italic=0;ul=0;charset=0;"; noteObj.Update(); pkgTrg.Elements.Refresh(); chartDia.DiagramObjects.Refresh(); // Link Operation to StateMachine HoUtil.SetBehaviorForOperation(rep, m, stateMachine); // Set show behavior HoUtil.SetShowBehaviorInDiagram(rep, m); HoUtil.SetFrameLinksToDiagram(rep, frm, chartDia); // link Overview frame to diagram frm.Update(); //rep.ReloadDiagram(actDia.DiagramID); return(true); }
//------------------------------------------------------------------------------ // Create default Elements for Statemachine //------------------------------------------------------------------------------ // // init // state 'State1' // final // transition from init to 'State1' public static bool CreateDefaultElementsForStateDiagram(Repository rep, EA.Diagram dia, EA.Element stateChart) { // check if init and final node are available bool init = false; bool final = false; foreach (EA.Element node in stateChart.Elements) { if (node.Type == "StateNode" & node.Subtype == 100) { init = true; } if (node.Type == "StateNode" & node.Subtype == 101) { final = true; } } EA.Element initNode = null; if (!init) { initNode = (EA.Element)stateChart.Elements.AddNew("", "StateNode"); initNode.Subtype = 3; initNode.ParentID = stateChart.ElementID; initNode.Update(); if (dia != null) { HoUtil.AddSequenceNumber(rep, dia); EA.DiagramObject initDiaNode = (EA.DiagramObject)dia.DiagramObjects.AddNew("l=295;r=315;t=125;b=135;", ""); initDiaNode.Sequence = 1; initDiaNode.ElementID = initNode.ElementID; initDiaNode.Update(); HoUtil.SetSequenceNumber(rep, dia, initDiaNode, "1"); } } EA.Element finalNode = null; // create final node if (!final) { finalNode = (EA.Element)stateChart.Elements.AddNew("", "StateNode"); finalNode.Subtype = 4; finalNode.ParentID = stateChart.ElementID; finalNode.Update(); if (dia != null) { HoUtil.AddSequenceNumber(rep, dia); EA.DiagramObject finalDiaNode = (EA.DiagramObject)dia.DiagramObjects.AddNew("l=285;r=305;t=745;b=765;", ""); finalDiaNode.Sequence = 1; finalDiaNode.ElementID = finalNode.ElementID; finalDiaNode.Update(); HoUtil.SetSequenceNumber(rep, dia, finalDiaNode, "1"); } } // create state node EA.Element stateNode = (EA.Element)stateChart.Elements.AddNew("", "State"); stateNode.Subtype = 0; // state stateNode.Name = "State1"; stateNode.ParentID = stateChart.ElementID; stateNode.Update(); if (dia != null) { HoUtil.AddSequenceNumber(rep, dia); string pos = "l=300;r=400;t=-400;b=-470"; EA.DiagramObject stateDiaNode = (EA.DiagramObject)dia.DiagramObjects.AddNew(pos, ""); stateDiaNode.Sequence = 1; stateDiaNode.ElementID = stateNode.ElementID; stateDiaNode.Update(); HoUtil.SetSequenceNumber(rep, dia, stateDiaNode, "1"); // draw a transition EA.Connector con = (EA.Connector)finalNode.Connectors.AddNew("", "StateFlow"); con.SupplierID = stateNode.ElementID; con.ClientID = initNode.ElementID; con.Update(); finalNode.Connectors.Refresh(); stateChart.Elements.Refresh(); dia.DiagramObjects.Refresh(); dia.Update(); rep.ReloadDiagram(dia.DiagramID); } return(true); }