/// <summary> /// Get all transitions of the desired diagram adjusting the initial and final insertion points using <paramref name="t"/> /// </summary> /// <param name="model">The model where the diagram is</param> /// <param name="t">the transation with hyperlink</param> /// <param name="tp">the side where the hyperlink is (source or target)</param> /// <returns>a list of the transitions</returns> private List <UmlTransition> GetTransitionsOfDiagram(UmlModel model, ref UmlTransition t, hyperLinkType tp) { List <UmlTransition> subTransitions; UmlElement s; String hyperlink = ""; int c = 0; if (tp == hyperLinkType.Source) { if (t.Source.TaggedValues.ContainsKey("cycles")) { c = Convert.ToInt32(t.Source.GetTaggedValue("cycles")); } hyperlink = t.Source.TaggedValues["jude.hyperlink"]; } else { if (t.Target.TaggedValues.ContainsKey("cycles")) { c = Convert.ToInt32(t.Target.GetTaggedValue("cycles")); } hyperlink = t.Target.TaggedValues["jude.hyperlink"]; } UmlActivityDiagram subDiagram = model.Diagrams.OfType <UmlActivityDiagram> () .Where(y => y.Name.Equals(hyperlink)) .FirstOrDefault(); if (subDiagram == null) { throw new Exception("Could not find any Activity Diagram named " + hyperlink); } subTransitions = subDiagram.UmlObjects.OfType <UmlTransition> ().ToList(); List <UmlTransition> fs = null; UmlTransition f = null; if (tp == hyperLinkType.Source) { fs = subTransitions.Where(x => x.Target is UmlFinalState).ToList(); f = fs.ElementAt(0); } else { f = subTransitions.Single(x => x.Source is UmlInitialState); } if (f != null) { if (tp == hyperLinkType.Source) { s = f.Source; for (int i = 1; i < fs.Count; i++) { UmlTransition temp = fs.ElementAt(i); temp.Target = t.Target; foreach (KeyValuePair <string, string> tag in t.TaggedValues) { if (!temp.TaggedValues.ContainsKey(tag.Key)) { temp.TaggedValues.Add(tag.Key, tag.Value); } } } } else { s = f.Target; } foreach (KeyValuePair <string, string> tag in f.TaggedValues) { if (!t.TaggedValues.ContainsKey(tag.Key)) { t.TaggedValues.Add(tag.Key, tag.Value); } } //subTransitions.Remove(f); } else if (tp == hyperLinkType.Source) { s = subDiagram.UmlObjects.OfType <UmlFinalState> ().FirstOrDefault(); } else { s = subDiagram.UmlObjects.OfType <UmlInitialState> ().FirstOrDefault(); } UmlTransition initialT = subTransitions.SingleOrDefault(x => x.Source is UmlInitialState); subTransitions.RemoveAll(x => x.Target is UmlFinalState); subTransitions.RemoveAll(x => x.Source is UmlInitialState); if (tp == hyperLinkType.Source) { t.Source = s; } else { t.Target = s; } #region cycles List <UmlTransition> hyperlinkTrans2 = new List <UmlTransition> (); if (c > 1) { List <UmlTransition> temp = subTransitions; UmlElement firstFirstState = null; UmlElement prevLastState = null; UmlElement lastSate = null; UmlTransition lastTran = null; for (int i = 0; i < c; i++) { UmlElement currFirstState = null; foreach (UmlTransition trans in temp) { UmlTransition cycleTran = new UmlTransition(); UmlElement src = (UmlElement)Activator.CreateInstance(trans.Source.GetType()); UmlElement targ = (UmlElement)Activator.CreateInstance(trans.Target.GetType()); if (i != 0) { src.Name = trans.Source.Name + "_" + i; targ.Name = trans.Target.Name + "_" + i; } else { src.Name = trans.Source.Name; targ.Name = trans.Target.Name; } src.Id = trans.Source.Id; //src.Id = Guid.NewGuid().ToString(); //targ.Name = trans.Target.Name + "_" + i; targ.Id = trans.Target.Id; //targ.Id = Guid.NewGuid().ToString(); foreach (KeyValuePair <String, String> tag in trans.TaggedValues) { cycleTran.SetTaggedValue(tag.Key, tag.Value + "$@#ITERATION@#" + i); } cycleTran.SetTaggedValue("TDCYCLETRAN", "true"); cycleTran.Source = src; cycleTran.Target = targ; hyperlinkTrans2.Add(cycleTran); lastTran = cycleTran; if (currFirstState == null) { currFirstState = src; } lastSate = targ; } if (prevLastState != null) { UmlTransition cycleTran = new UmlTransition(); if (initialT != null) { foreach (KeyValuePair <String, String> tag in initialT.TaggedValues) { // cycleTran.SetTaggedValue(tag.Key, tag.Value + ". Iteration " + i); cycleTran.SetTaggedValue(tag.Key, tag.Value + "$@#ITERATION@#" + i); } cycleTran.SetTaggedValue("TDCYCLETRAN", "true"); cycleTran.SetTaggedValue("TDLASTCYCLETRANS", "true"); } cycleTran.Source = prevLastState; cycleTran.Target = currFirstState; if (cycleTran.TaggedValues.Count > 0) { hyperlinkTrans2.Add(cycleTran); lastTran = cycleTran; } } if (currFirstState != null) { if (firstFirstState == null) { firstFirstState = currFirstState; } } prevLastState = lastSate; } if (tp == hyperLinkType.Source) { t.Source = lastSate; t.SetTaggedValue("TDLASTCYCLETRANS", "true"); } else { t.Target = firstFirstState; } t.SetTaggedValue("TDCYCLETRAN", "true"); subTransitions = hyperlinkTrans2; } #endregion return(subTransitions); }
/// <summary> /// Get all transitions of the desired diagram adjusting the initial and final insertion points using <paramref name="t"/> /// </summary> /// <param name="model">The model where the diagram is</param> /// <param name="t">the transation with hyperlink</param> /// <param name="tp">the side where the hyperlink is (source or target)</param> /// <returns>a list of the transitions</returns> private static List <UmlTransition> GetTransitionsOfDiagram(UmlModel model, ref UmlTransition t, hyperLinkType tp) { List <UmlTransition> subTransitions; UmlElement s; String hyperlink = ""; if (tp == hyperLinkType.Source) { hyperlink = t.Source.TaggedValues["jude.hyperlink"]; } else { hyperlink = t.Target.TaggedValues["jude.hyperlink"]; } UmlActivityDiagram subDiagram = model.Diagrams.OfType <UmlActivityDiagram>() .Where(y => y.Name.Equals(hyperlink)) .FirstOrDefault(); if (subDiagram == null) { throw new Exception("Could not find any Activity Diagram named " + hyperlink); } subTransitions = subDiagram.UmlObjects.OfType <UmlTransition>().ToList(); List <UmlTransition> fs = null; UmlTransition f = null; if (tp == hyperLinkType.Source) { fs = subTransitions.Where(x => x.Target is UmlFinalState).ToList(); f = fs.ElementAt(0); } else { f = subTransitions.Single(x => x.Source is UmlInitialState); } if (f != null) { if (tp == hyperLinkType.Source) { s = f.Source; for (int i = 1; i < fs.Count; i++) { UmlTransition temp = fs.ElementAt(i); temp.Target = t.Target; foreach (KeyValuePair <string, string> tag in t.TaggedValues) { if (!temp.TaggedValues.ContainsKey(tag.Key)) { temp.TaggedValues.Add(tag.Key, tag.Value); } } } } else { s = f.Target; } foreach (KeyValuePair <string, string> tag in f.TaggedValues) { if (!t.TaggedValues.ContainsKey(tag.Key)) { t.TaggedValues.Add(tag.Key, tag.Value); } } subTransitions.Remove(f); } else if (tp == hyperLinkType.Source) { s = subDiagram.UmlObjects.OfType <UmlFinalState>().FirstOrDefault(); } else { s = subDiagram.UmlObjects.OfType <UmlInitialState>().FirstOrDefault(); } subTransitions.RemoveAll(x => x.Target is UmlFinalState); subTransitions.RemoveAll(x => x.Source is UmlInitialState); if (tp == hyperLinkType.Source) { t.Source = s; } else { t.Target = s; } return(subTransitions); }
/// <summary> /// Get all transitions of the desired diagram adjusting the initial and final insertion points using <paramref name="t"/> /// </summary> /// <param name="model">The model where the diagram is</param> /// <param name="t">the transation with hyperlink</param> /// <param name="tp">the side where the hyperlink is (source or target)</param> /// <returns>a list of the transitions</returns> private List <UmlTransition> GetTransitionsOfDiagram(UmlModel model, ref UmlTransition t, hyperLinkType tp) { List <UmlTransition> subTransitions; UmlElement s; String hyperlink = ""; int c = 0; Boolean paramcycle = false; if (tp == hyperLinkType.Source) { /* * if (t.Source.TaggedValues.ContainsKey("cycles")) * { * c = Convert.ToInt32(t.Source.GetTaggedValue("cycles")); * paramcycle = true; * }*/ hyperlink = t.Source.TaggedValues["jude.hyperlink"]; } else { /* * if (t.Target.TaggedValues.ContainsKey("cycles")) * { * c = Convert.ToInt32(t.Target.GetTaggedValue("cycles")); * paramcycle = true; * }*/ hyperlink = t.Target.TaggedValues["jude.hyperlink"]; } //recupera o subdiagrama que foi atribuido a variavel hyperlink UmlActivityDiagram subDiagram = model.Diagrams.OfType <UmlActivityDiagram> () .Where(y => y.Name.Equals(hyperlink)) .FirstOrDefault(); if (subDiagram == null) { throw new Exception("Could not find any Activity Diagram named " + hyperlink); } //recupera a primeira transicao para buscar o valor de marcacao que deve ser atribuido subTransitions = subDiagram.UmlObjects.OfType <UmlTransition> ().ToList(); foreach (UmlTransition tran in subTransitions) { if (tran.End1.Name.Equals("InitialNode0")) { paramcycle = tran.TaggedValues.ContainsKey("TDITERATIONS"); try { c = Convert.ToInt32(tran.GetTaggedValue("TDITERATIONS")); } catch (FormatException) { c = 0; } } } if (paramcycle) { foreach (UmlTransition subTransition in subTransitions) { if (!subTransition.TaggedValues.ContainsKey("paramcycle")) { subTransition.TaggedValues.Add("paramcycle", c.ToString()); //subTransition.TaggedValues.Add("paramcycle", "exists"); } } } List <UmlTransition> fs = null; UmlTransition f = null; if (tp == hyperLinkType.Source) { fs = subTransitions.Where(x => x.Target is UmlFinalState).ToList(); f = fs.ElementAt(0); } else { f = subTransitions.Single(x => x.Source is UmlInitialState); } if (f != null) { if (tp == hyperLinkType.Source) { s = f.Source; for (int i = 1; i < fs.Count; i++) { UmlTransition temp = fs.ElementAt(i); temp.Target = t.Target; foreach (KeyValuePair <string, string> tag in t.TaggedValues) { if (!temp.TaggedValues.ContainsKey(tag.Key)) { temp.TaggedValues.Add(tag.Key, tag.Value); } } } } else { s = f.Target; } foreach (KeyValuePair <string, string> tag in f.TaggedValues) { if (!t.TaggedValues.ContainsKey(tag.Key)) { t.TaggedValues.Add(tag.Key, tag.Value); } } //subTransitions.Remove(f); } else { if (tp == hyperLinkType.Source) { s = subDiagram.UmlObjects.OfType <UmlFinalState> ().FirstOrDefault(); } else { s = subDiagram.UmlObjects.OfType <UmlInitialState> ().FirstOrDefault(); } } UmlTransition initialT = subTransitions.SingleOrDefault(x => x.Source is UmlInitialState); subTransitions.RemoveAll(x => x.Target is UmlFinalState); subTransitions.RemoveAll(x => x.Source is UmlInitialState); if (tp == hyperLinkType.Source) { t.Source = s; } else { t.Target = s; } #region cycles //List<UmlTransition> hyperlinkTrans2 = new List<UmlTransition>(); //if (c > 1) //{ // List<UmlTransition> temp = subTransitions; // UmlElement firstFirstState = null; // UmlElement prevLastState = null; // UmlElement lastSate = null; // UmlTransition lastTran = null; // for (int i = 0; i < c; i++) // { // UmlElement currFirstState = null; // foreach (UmlTransition trans in temp) // { // UmlTransition cycleTran = new UmlTransition(); // UmlElement src = (UmlElement)Activator.CreateInstance(trans.Source.GetType()); // UmlElement targ = (UmlElement)Activator.CreateInstance(trans.Target.GetType()); // if (i != 0) // { // src.Name = trans.Source.Name + "_" + (i); // targ.Name = trans.Target.Name + "_" + (i); // } // else // { // src.Name = trans.Source.Name; // targ.Name = trans.Target.Name; // } // src.Id = trans.Source.Id; // targ.Id = trans.Target.Id; // foreach (KeyValuePair<String, String> tag in trans.TaggedValues) // { // cycleTran.SetTaggedValue(tag.Key, tag.Value + "$@#ITERATION@#" + i); // } // cycleTran.SetTaggedValue("TDCYCLETRAN", "true"); // cycleTran.Source = src; // cycleTran.Target = targ; // hyperlinkTrans2.Add(cycleTran); // lastTran = cycleTran; // if (currFirstState == null) // currFirstState = src; // lastSate = targ; // } // if (prevLastState != null) // { // UmlTransition cycleTran = new UmlTransition(); // if (initialT != null) // { // foreach (KeyValuePair<String, String> tag in initialT.TaggedValues) // { // cycleTran.SetTaggedValue(tag.Key, tag.Value + "$@#ITERATION@#" + i); // } // cycleTran.SetTaggedValue("TDCYCLETRAN", "true"); // cycleTran.SetTaggedValue("TDLASTCYCLETRANS", "true"); // } // cycleTran.Source = prevLastState; // cycleTran.Target = currFirstState; // if (cycleTran.TaggedValues.Count > 0) // { // hyperlinkTrans2.Add(cycleTran); // lastTran = cycleTran; // } // } // if (currFirstState != null) // if (firstFirstState == null) // firstFirstState = currFirstState; // prevLastState = lastSate; // } // if (tp == hyperLinkType.Source) // { // t.Source = lastSate; // t.SetTaggedValue("TDLASTCYCLETRANS", "true"); // } // else // { // t.Target = firstFirstState; // } // t.SetTaggedValue("TDCYCLETRAN", "true"); // subTransitions = hyperlinkTrans2; //} #endregion return(subTransitions); }