// 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> /// 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); }
/// <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, Package pkgSrc, Element elClass) { // create a package with the name of the operation Package pkgTrg = (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 HoUtil.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 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.Sequence = 1; actObj.Update(); HoUtil.SetSequenceNumber(rep, actDia, actObj, "1"); actDia.DiagramObjects.Refresh(); // add default nodes (init/final) CreateDefaultElementsForActivity(rep, actDia, act); if (ActivityIsSimple == false) { // Add Heading to diagram HoUtil.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(); HoUtil.SetSequenceNumber(rep, actDia, noteObj, "1"); } pkgTrg.Elements.Refresh(); actDia.DiagramObjects.Refresh(); // Link Operation to activity HoUtil.SetBehaviorForOperation(rep, m, act); // Set show behavior HoUtil.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; } HoUtil.VisualizePortForDiagramobject(rep, pos, actDia, actObj, actPar, null); pos = pos + 1; } if (ActivityIsSimple == false) { // link Overview frame to diagram HoUtil.SetFrameLinksToDiagram(rep, frm, actDia); frm.Update(); } // select operation rep.ShowInProjectView(m); }
//------------------------------------------------------------------------------ // 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); }