本文整理汇总了C#中Repository.SaveDiagram方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.SaveDiagram方法的具体用法?C# Repository.SaveDiagram怎么用?C# Repository.SaveDiagram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository.SaveDiagram方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowEmbeddedElementsGui
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);
}
示例2: AddDiagramNote
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);
}
}
示例3: GenerateComponentPorts
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);
}
示例4: MoveEmbeddedUpGui
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;
}
}
}
示例5: MakeNested
// 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();
}
}
示例6: DeleteInvisibleUseRealizationDependencies
// 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);
}
}
}
}
}
示例7: JoinDiagramObjectsToLastSelected
// 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());
}
示例8: SplitAllDiagramObjectsToLastSelected
// 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());
}
示例9: CreateTypeDefStructFromText
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();
//.........这里部分代码省略.........
示例10: InsertDiagramElementAndConnect
/// <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());
//.........这里部分代码省略.........
示例11: CreateOperationsFromText
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();
}
示例12: UpdateActivityParameter
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);
}
}
示例13: AddElementNote
/// <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);
}
}
示例14: InsertInterface
// 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();
}
示例15: CreateDiagramObjectFromContext
//----------------------------------------------------------------------------------------
// 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;
//.........这里部分代码省略.........