/// <summary> /// Creates a group of all selected components. /// For each eventchannelline connected to the selected components, events will also be visible in the group element /// For each channel connected to the selected components, an in or outputport will be added to the group component /// </summary> /// <param name="idForGroup">The id (name) of the group</param> /// <param name="addToUndoStack">Desition, if the undo-operation should be put on the undo-stack</param> /// <param name="storeGroup">Desition, if the group will be part of the model (stored in the deployment model)</param> /// <returns></returns> private String DoGrouping(String idForGroup, bool addToUndoStack, bool storeGroup) { Boolean noGroupInSelection = true; ArrayList selectedGroupChannelList = new ArrayList(); ArrayList selectedGroupComponentList = new ArrayList(); ArrayList selectedGroupEventChannelList = new ArrayList(); ArrayList selectedGroupEdgeListenerEventChannelList = new ArrayList(); ArrayList selectedGroupEdgeTriggerEventChannelList = new ArrayList(); if (selectedComponentList.Count == 0) { MessageBox.Show(Properties.Resources.GroupingNoItemsSelected, Properties.Resources.GroupingNoItemsSelectedHeader, MessageBoxButton.OK, MessageBoxImage.Error); return ""; } // search for a group in the selection foreach (componentType mc in selectedComponentList) { if (mc.ComponentType == ACS2.componentTypeDataTypes.group) { noGroupInSelection = false; MessageBox.Show(Properties.Resources.GroupingWithSelectedGroups, Properties.Resources.GroupingWithSelectedGroupsHeader, MessageBoxButton.OK, MessageBoxImage.Error); break; } } if (noGroupInSelection == false) return ""; groupComponent newGroup = new groupComponent(); // building a "new" model Asterics.ACS2.componentTypesComponentType newGroupForBundle = new ACS2.componentTypesComponentType(); newGroupForBundle.type = new ACS2.componentType(); newGroupForBundle.type.Value = ACS2.componentTypeDataTypes.group; int counter = 0; string suggestID = ""; /*do { counter++; suggestID = "group" + counter; } while (componentList.ContainsKey(suggestID));*/ bool gExists; do { gExists = false; foreach (componentType ct in deploymentComponentList.Values) { if (ct.id.StartsWith(suggestID)) { counter++; gExists = true; } suggestID = "group" + counter; } } while (gExists); Console.WriteLine("SuggestID is " + suggestID); if (idForGroup != null && idForGroup != "") newGroupForBundle.id = idForGroup; else newGroupForBundle.id = suggestID; // adding the channels and the eventchannels here object[] ports = new object[0]; newGroupForBundle.ports = ports; // find lowest and higest cooridantes to place new group component in the middle int lowestX = 2000; int lowestY = 2000; int highestX = 0; int highestY = 0; if (selectedComponentList.Count > 0) { lowestX = highestX = (Int32)Canvas.GetLeft(selectedComponentList.First().ComponentCanvas); lowestY = highestY = (Int32)Canvas.GetTop(selectedComponentList.First().ComponentCanvas); } // remove selected components from canvas and add to group element foreach (componentType mc in selectedComponentList) { selectedGroupComponentList.Add(mc); if (Canvas.GetLeft(mc.ComponentCanvas) < lowestX) { lowestX = (Int32)Canvas.GetLeft(mc.ComponentCanvas); } else if (Canvas.GetLeft(mc.ComponentCanvas) > highestX) { highestX = (Int32)Canvas.GetLeft(mc.ComponentCanvas); } if (Canvas.GetTop(mc.ComponentCanvas) < lowestY) { lowestY = (Int32)Canvas.GetTop(mc.ComponentCanvas); } else if (Canvas.GetTop(mc.ComponentCanvas) > highestY) { highestY = (Int32)Canvas.GetTop(mc.ComponentCanvas); } // new with grouping rework mc.ComponentCanvas.Visibility = System.Windows.Visibility.Hidden; newGroup.AddedComponentList.AddLast(mc); } /* * search channels which are connected to components which will become a member of the group */ ArrayList foundInsideChannels = new ArrayList(); ArrayList foundEdgeSourceChannels = new ArrayList(); ArrayList foundEdgeTargetChannels = new ArrayList(); foreach (channel ch in deploymentChannelList.Values) { bool sourceSelected = selectedComponentList.Contains(deploymentComponentList[ch.source.component.id]); bool targetSelected = selectedComponentList.Contains(deploymentComponentList[ch.target.component.id]); if (sourceSelected && targetSelected) { foundInsideChannels.Add(ch); } else if (sourceSelected && !targetSelected) { foundEdgeSourceChannels.Add(ch); } else if (!sourceSelected && targetSelected) { foundEdgeTargetChannels.Add(ch); } } foreach (channel ch in foundInsideChannels) { if (canvas.Children.Contains(ch.Line)) { ch.Line.Visibility = System.Windows.Visibility.Hidden; newGroup.AddedChannelsList.AddLast(ch); } } foreach (channel ch in foundEdgeSourceChannels) { if (canvas.Children.Contains(ch.Line)) { ch.Line.Visibility = System.Windows.Visibility.Hidden; newGroup.AddedChannelsList.AddLast(ch); } // Add out Port to the component componentType source = deploymentComponentList[ch.source.component.id]; outputPortType outp = null; foreach (object o in source.PortsList.Values) { if (o is outputPortType) { outputPortType outp1 = (outputPortType)o; if (outp1.portTypeID.Equals(ch.source.port.id)) { outp = outp1; } } } if (outp == null) continue; Asterics.ACS2.outputPortType outPort = new ACS2.outputPortType(); outPort.id = ch.source.component.id + "_" + ch.source.port.id; outPort.description = outp.Description; outPort.dataType = outp.PortDataType; refType refT = new refType(); refT.componentID = ch.source.component.id; refT.portID = ch.source.port.id; outPort.RefPort = refT; if (!newGroupForBundle.PortsList.Contains(outPort.id)) { newGroupForBundle.PortsList.Add(outPort.id, outPort); } } foreach (channel ch in foundEdgeTargetChannels) { if (canvas.Children.Contains(ch.Line)) { ch.Line.Visibility = System.Windows.Visibility.Hidden; newGroup.AddedChannelsList.AddLast(ch); } // Add in Port to the component componentType target = deploymentComponentList[ch.target.component.id]; inputPortType inp = null; foreach (object o in target.PortsList.Values) { if (o is inputPortType) { inputPortType inp1 = (inputPortType)o; if (inp1.portTypeID.Equals(ch.target.port.id)) { inp = inp1; } } } if (inp == null) continue; Asterics.ACS2.inputPortType inPort = new ACS2.inputPortType(); inPort.id = ch.target.component.id + "_" + ch.target.port.id; inPort.description = inp.Description; inPort.dataType = inp.PortDataType; inPort.mustBeConnected = inp.MustBeConnected; refType refT = new refType(); refT.componentID = ch.target.component.id; refT.portID = ch.target.port.id; inPort.RefPort = refT; if (!newGroupForBundle.PortsList.Contains(inPort.id)) { newGroupForBundle.PortsList.Add(inPort.id, inPort); } } /* * search eventchannels which are connected to components which will become a member of the group */ ArrayList foundEdgeListenerEvents = new ArrayList(); ArrayList foundEdgeTriggerEvents = new ArrayList(); foreach (eventChannel ec in eventChannelList) { // search for each event channel on the edge of the group element if (!selectedComponentList.Contains(deploymentComponentList[ec.targets.target.component.id]) && selectedComponentList.Contains(deploymentComponentList[ec.sources.source.component.id])) { foreach (EventTriggerPort etp in deploymentComponentList[ec.sources.source.component.id].EventTriggerList) { ACS2.eventsTypeEventTriggererPortType foundTrigger = new ACS2.eventsTypeEventTriggererPortType(); foundTrigger.id = ec.sources.source.component.id + "_" + etp.EventTriggerId; foundTrigger.description = etp.EventDescription; bool contains = false; foreach (ACS2.eventsTypeEventTriggererPortType etel in foundEdgeTriggerEvents) { if (etel.id.Equals(foundTrigger.id)) { contains = true; break; } } if (!contains) foundEdgeTriggerEvents.Add(foundTrigger); } // search for lines, being connected to an edge of the group foreach (eventChannelLine ecl in eventChannelLinesList) { if (ecl.Line.Visibility == System.Windows.Visibility.Visible && ecl.ListenerComponentId == ec.targets.target.component.id && ecl.TriggerComponentId == ec.sources.source.component.id) { //selectedEventChannelList.AddFirst(ecl); if (!selectedGroupEdgeTriggerEventChannelList.Contains(ecl)) selectedGroupEdgeTriggerEventChannelList.Add(ecl); break; } } // search for each event channel on the edge of the group element } else if (selectedComponentList.Contains(deploymentComponentList[ec.targets.target.component.id]) && !selectedComponentList.Contains(deploymentComponentList[ec.sources.source.component.id])) { foreach (EventListenerPort elp in deploymentComponentList[ec.targets.target.component.id].EventListenerList) { ACS2.eventsTypeEventListenerPortType foundListener = new ACS2.eventsTypeEventListenerPortType(); foundListener.id = ec.targets.target.component.id + "_" + elp.EventListenerId; foundListener.description = elp.EventDescription; bool contains = false; foreach (ACS2.eventsTypeEventListenerPortType etel in foundEdgeListenerEvents) { if (etel.id.Equals(foundListener.id)) { contains = true; break; } } if (!contains) foundEdgeListenerEvents.Add(foundListener); } // search for lines, being connected to an edge of the group foreach (eventChannelLine ecl in eventChannelLinesList) { if (ecl.Line.Visibility == System.Windows.Visibility.Visible && ecl.ListenerComponentId == ec.targets.target.component.id && ecl.TriggerComponentId == ec.sources.source.component.id) { //selectedEventChannelList.AddFirst(ecl); if (!selectedGroupEdgeListenerEventChannelList.Contains(ecl)) selectedGroupEdgeListenerEventChannelList.Add(ecl); break; } } // search for each event channel in the group element } else if (selectedComponentList.Contains(deploymentComponentList[ec.targets.target.component.id]) && selectedComponentList.Contains(deploymentComponentList[ec.sources.source.component.id])) { // search for lines, being between two selected components, but not selected foreach (eventChannelLine ecl in eventChannelLinesList) { if (ecl.Line.Visibility == System.Windows.Visibility.Visible && ecl.ListenerComponentId == ec.targets.target.component.id && ecl.TriggerComponentId == ec.sources.source.component.id) { if (!selectedGroupEventChannelList.Contains(ecl)) selectedGroupEventChannelList.Add(ecl); break; } } } } ArrayList emptyEventChannelLines = new ArrayList(); foreach (eventChannelLine ecl in eventChannelLinesList) { // only check eventchannelLine that correspond to group components bool found = false; foreach (eventChannel ech in eventChannelList) { string source = ech.sources.source.component.id; string target = ech.targets.target.component.id; if (ecl.ListenerComponentId.Equals(target) && ecl.TriggerComponentId.Equals(source)) { found = true; break; } } if (!found) emptyEventChannelLines.Add(ecl); } foreach (eventChannelLine ecl in emptyEventChannelLines) { DeleteEventChannelCommand(ecl); } int eventCount = foundEdgeTriggerEvents.Count + foundEdgeListenerEvents.Count; if (eventCount > 0) { newGroupForBundle.events = new object[eventCount]; foundEdgeListenerEvents.CopyTo(newGroupForBundle.events, 0); foundEdgeTriggerEvents.CopyTo(newGroupForBundle.events, foundEdgeListenerEvents.Count); } // adding the final "new" model to the list of all components (bundles) newGroupForBundle.ports = new object[newGroupForBundle.PortsList.Values.Count]; newGroupForBundle.PortsList.Values.CopyTo(newGroupForBundle.ports, 0); newGroupForBundle.PortsList.Clear(); newGroupForBundle.ComponentCanvas.Children.Clear(); foreach (componentType ct in selectedComponentList) { if (!componentList.ContainsKey(ct.id)) continue; ACS2.componentTypesComponentType ctct = (ACS2.componentTypesComponentType) componentList[ct.id]; if (ctct.singleton) { newGroupForBundle.singleton = true; break; } } if (idForGroup != null && idForGroup != "") newGroupForBundle.InitGraphPorts(idForGroup); else newGroupForBundle.InitGraphPorts(suggestID); // generate the id of the group in the acs string compName = suggestID; counter = 0; if (idForGroup == "" || idForGroup == null) { do { counter++; compName = suggestID + "." + counter; compName = TrimComponentName(compName); } while (deploymentComponentList.ContainsKey(compName)); } else { compName = idForGroup; } BrushConverter bc = new BrushConverter(); if (idForGroup != null && idForGroup != "") { if (componentList.ContainsKey(idForGroup)) componentList.Remove(idForGroup); componentList.Add(idForGroup, newGroupForBundle); AddComponent(idForGroup, true,false,false); } else { if (componentList.ContainsKey(suggestID)) componentList.Remove(suggestID); componentList.Add(suggestID, newGroupForBundle); AddComponent(suggestID, false, false,false); } // find the id of the just added group componentType componentAsGroupElement = null; string searchName; if (idForGroup == "" || idForGroup == null) searchName = suggestID; else searchName = idForGroup; ArrayList longestNameComp = new ArrayList(); componentType longestComp = null; foreach (componentType mc in deploymentComponentList.Values) { if (mc.id.StartsWith(searchName)) longestNameComp.Add(mc); } if (longestNameComp.Count == 1) longestComp = (componentType) longestNameComp[0]; else if (longestNameComp.Count > 1) { foreach (componentType ct in longestNameComp) { if (longestComp == null) longestComp = ct; else if (longestComp.id.Length < ct.id.Length) longestComp = ct; } } if (longestComp != null) { newGroup.GroupID = longestComp.type_id; newGroup.ID = longestComp.id; componentAsGroupElement = longestComp; groupsList.Add(newGroup.ID, newGroup); MoveComponent(longestComp, lowestX + (highestX - lowestX) / 2, lowestY + (highestY - lowestY) / 2); String groupColor = ini.IniReadValue("Layout", "groupcolor"); if (groupColor.Equals("")) groupColor = ACS.LayoutConstants.GROUPRECTANGLECOLOR; longestComp.TopRectangle.Fill = (Brush)bc.ConvertFrom(groupColor); } if (addToUndoStack) { CommandObject co = new CommandObject("Ungroup", componentAsGroupElement); undoStack.Push(co); redoStack.Clear(); } /* * Process Channels where the source becomes a member of a group */ foreach (channel ch in foundEdgeSourceChannels) { outputPortType outPort = null; foreach (object o in componentAsGroupElement.PortsList.Values) { if ((o is outputPortType) && (((outputPortType)o).refs.componentID == ch.source.component.id) && (((outputPortType)o).refs.portID == ch.source.port.id)) { outPort = (outputPortType)o; } } if (outPort == null) continue; /* * add channel with source = newgroup and old target */ channel groupChannel = new channel(); groupChannel.id = NewIdForGroupChannel(); groupChannel.source.component.id = outPort.ComponentId; groupChannel.source.port.id = ch.source.component.id + "_" + ch.source.port.id; groupChannel.target.component.id = ch.target.component.id; groupChannel.target.port.id = ch.target.port.id; if (!ChannelExists(groupChannel)) AddChannel(groupChannel); groupChannel.Line.Y1 = 100; groupChannel.Line.X1 = 100; groupChannel.Line.Y1 = Canvas.GetTop(((outputPortType)(deploymentComponentList[groupChannel.source.component.id]).PortsList[groupChannel.source.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[groupChannel.source.component.id]).ComponentCanvas) + 5; groupChannel.Line.X1 = Canvas.GetLeft(((outputPortType)(deploymentComponentList[groupChannel.source.component.id]).PortsList[groupChannel.source.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[groupChannel.source.component.id]).ComponentCanvas) + 20; groupChannel.Line.Y2 = Canvas.GetTop(((inputPortType)(deploymentComponentList[ch.target.component.id]).PortsList[ch.target.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[ch.target.component.id]).ComponentCanvas) + 5; groupChannel.Line.X2 = Canvas.GetLeft(((inputPortType)(deploymentComponentList[ch.target.component.id]).PortsList[ch.target.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[ch.target.component.id]).ComponentCanvas); Canvas.SetZIndex(groupChannel.Line, Canvas.GetZIndex(groupChannel.Line) + 1000); /* * add channel with source = newgroup and old target */ if (ch.GroupOriginalTarget == null) continue; /* * add channel with source = newgroup and targets group original */ channel groupChannel1 = new channel(); groupChannel1.id = NewIdForGroupChannel(); groupChannel1.source.component.id = outPort.ComponentId; groupChannel1.source.port.id = ch.source.component.id + "_" + ch.source.port.id; groupChannel1.target.component.id = ch.target.component.id; groupChannel1.target.port.id = ch.target.port.id; if (!ChannelExists(groupChannel)) AddChannel(groupChannel1); groupChannel1.Line.Y1 = 100; groupChannel1.Line.X1 = 100; groupChannel1.Line.Y1 = Canvas.GetTop(((outputPortType)(deploymentComponentList[groupChannel1.source.component.id]).PortsList[groupChannel1.source.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[groupChannel1.source.component.id]).ComponentCanvas) + 5; groupChannel1.Line.X1 = Canvas.GetLeft(((outputPortType)(deploymentComponentList[groupChannel1.source.component.id]).PortsList[groupChannel1.source.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[groupChannel1.source.component.id]).ComponentCanvas) + 20; groupChannel1.Line.Y2 = Canvas.GetTop(((inputPortType)(deploymentComponentList[ch.target.component.id]).PortsList[ch.target.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[ch.target.component.id]).ComponentCanvas) + 5; groupChannel1.Line.X2 = Canvas.GetLeft(((inputPortType)(deploymentComponentList[ch.target.component.id]).PortsList[ch.target.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[ch.target.component.id]).ComponentCanvas); Canvas.SetZIndex(groupChannel1.Line, Canvas.GetZIndex(groupChannel1.Line) + 1000); } // Sort Portslist /* * Process Channels where the target becomes a member of a group */ foreach (channel ch in foundEdgeTargetChannels) { inputPortType inPort = null; foreach (object o in componentAsGroupElement.PortsList.Values) { if ((o is inputPortType) && (((inputPortType)o).refs.componentID == ch.target.component.id) && (((inputPortType)o).refs.portID == ch.target.port.id)) { inPort = (inputPortType)o; } } if (inPort == null) continue; /* * add channel with source = newgroup and old target */ channel groupChannel = new channel(); groupChannel.id = NewIdForGroupChannel(); groupChannel.source.component.id = ch.source.component.id; groupChannel.source.port.id = ch.source.port.id; groupChannel.target.component.id = inPort.ComponentId; groupChannel.target.port.id = ch.target.component.id + "_" + ch.target.port.id; if (!ChannelExists(groupChannel)) AddChannel(groupChannel); groupChannel.Line.Y1 = 100; groupChannel.Line.X1 = 100; groupChannel.Line.Y1 = Canvas.GetTop(((outputPortType)(deploymentComponentList[ch.source.component.id]).PortsList[ch.source.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[ch.source.component.id]).ComponentCanvas) + 5; groupChannel.Line.X1 = Canvas.GetLeft(((outputPortType)(deploymentComponentList[ch.source.component.id]).PortsList[ch.source.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[ch.source.component.id]).ComponentCanvas) + 20; groupChannel.Line.Y2 = Canvas.GetTop(((inputPortType)(deploymentComponentList[groupChannel.target.component.id]).PortsList[groupChannel.target.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[groupChannel.target.component.id]).ComponentCanvas) + 5; groupChannel.Line.X2 = Canvas.GetLeft(((inputPortType)(deploymentComponentList[groupChannel.target.component.id]).PortsList[groupChannel.target.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[groupChannel.target.component.id]).ComponentCanvas); Canvas.SetZIndex(groupChannel.Line, Canvas.GetZIndex(groupChannel.Line) + 1000); /* * add channel with source = newgroup and old target */ if (ch.GroupOriginalSource == null) continue; /* * add channel with source = newgroup and targets group original */ channel groupChannel1 = new channel(); groupChannel1.id = NewIdForGroupChannel(); groupChannel1.source.component.id = ch.source.component.id; groupChannel1.source.port.id = ch.source.port.id; groupChannel1.target.component.id = inPort.ComponentId; groupChannel1.target.port.id = ch.target.component.id + "_" + ch.target.port.id; if (!ChannelExists(groupChannel)) AddChannel(groupChannel1); groupChannel1.Line.Y1 = Canvas.GetTop(((outputPortType)(deploymentComponentList[ch.source.component.id]).PortsList[ch.source.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[ch.source.component.id]).ComponentCanvas) + 5; groupChannel1.Line.X1 = Canvas.GetLeft(((outputPortType)(deploymentComponentList[ch.source.component.id]).PortsList[ch.source.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[ch.source.component.id]).ComponentCanvas); groupChannel1.Line.Y2 = Canvas.GetTop(((inputPortType)(deploymentComponentList[groupChannel1.target.component.id]).PortsList[groupChannel1.target.port.id]).PortRectangle) + Canvas.GetTop((deploymentComponentList[groupChannel1.target.component.id]).ComponentCanvas) + 5; groupChannel1.Line.X2 = Canvas.GetLeft(((inputPortType)(deploymentComponentList[groupChannel1.target.component.id]).PortsList[groupChannel1.target.port.id]).PortRectangle) + Canvas.GetLeft((deploymentComponentList[groupChannel1.target.component.id]).ComponentCanvas) + 20; Canvas.SetZIndex(groupChannel1.Line, Canvas.GetZIndex(groupChannel1.Line) + 1000); } // hide the eventchannels within a group foreach (eventChannelLine ecl in selectedGroupEventChannelList) { ecl.Line.Visibility = System.Windows.Visibility.Hidden; newGroup.AddedEventChannelsList.AddLast(ecl); } // hide all eventchannels where the group is a listener foreach (eventChannelLine ecl in selectedGroupEdgeListenerEventChannelList) { ecl.Line.Visibility = System.Windows.Visibility.Hidden; newGroup.AddedEventChannelsList.AddLast(ecl); } // hide all eventchannels where the group is a trigger foreach (eventChannelLine ecl in selectedGroupEdgeTriggerEventChannelList) { ecl.Line.Visibility = System.Windows.Visibility.Hidden; newGroup.AddedEventChannelsList.AddLast(ecl); } // Targets foreach (eventChannelLine ecl in selectedGroupEdgeListenerEventChannelList) { List<eventChannel> ecList = GetEventChannelsFromLine(ecl); foreach (eventChannel ec in ecList) { string targetEvent = ec.targets.target.component.id + "_" + ec.targets.target.eventPort.id; if (eventChannelExists(compName, targetEvent, ecl.TriggerComponentId, ec.sources.source.eventPort.id)) continue; eventChannel tmpEC = new eventChannel(); tmpEC.sources.source.component.id = ecl.TriggerComponentId; tmpEC.sources.source.eventPort.id = ec.sources.source.eventPort.id; tmpEC.targets.target.component.id = compName; tmpEC.targets.target.eventPort.id = targetEvent; tmpEC.id = compName + "_" + ecl.TriggerComponentId + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id; tmpEC.GroupOriginalTarget = ec.targets.target; if (EventChannelHasGroupSource(ec)) tmpEC.GroupOriginalSource = ec.GroupOriginalSource; eventChannelList.Add(tmpEC); } if (eventChannelLineExists(compName, ecl.TriggerComponentId)) continue; eventChannelLine groupEC = new eventChannelLine(); double x = lowestX + (highestX - lowestX) / 2; double y = lowestY + (highestY - lowestY) / 2; groupEC.Line.X1 = ecl.Line.X1; groupEC.Line.Y1 = ecl.Line.Y1; groupEC.Line.X2 = x + componentAsGroupElement.ComponentCanvas.Width / 2 - 18; groupEC.Line.Y2 = y + componentAsGroupElement.ComponentCanvas.Height - 4; Canvas.SetZIndex(groupEC.Line, -1001); groupEC.TriggerComponentId = ecl.TriggerComponentId; groupEC.ListenerComponentId = compName; groupEC.HasGroupTarget = true; groupEC.HasGroupSource = EventChannelLineHasGroupSource(ecl); AddEventChannelCommand(groupEC, false); canvas.Children.Add(groupEC.Line); } // Sources foreach (eventChannelLine ecl in selectedGroupEdgeTriggerEventChannelList) { //Copy eventChannels List<eventChannel> ecList = GetEventChannelsFromLine(ecl); foreach (eventChannel ec in ecList) { eventChannel tmpEC = new eventChannel(); Console.WriteLine("compName"); tmpEC.sources.source.component.id = compName; tmpEC.sources.source.eventPort.id = ec.sources.source.component.id + "_" + ec.sources.source.eventPort.id; tmpEC.targets.target.component.id = ecl.ListenerComponentId; tmpEC.targets.target.eventPort.id = ec.targets.target.eventPort.id; tmpEC.id = compName + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id; tmpEC.GroupOriginalSource = ec.sources.source; if (EventChannelHasGroupTarget(ec)) tmpEC.GroupOriginalTarget = ec.GroupOriginalTarget; eventChannelList.Add(tmpEC); } if (eventChannelLineExists(ecl.ListenerComponentId, compName)) continue; // Add EventchannelLine eventChannelLine groupEC = new eventChannelLine(); double x = lowestX + (highestX - lowestX) / 2; double y = lowestY + (highestY - lowestY) / 2; groupEC.Line.X1 = x + componentAsGroupElement.ComponentCanvas.Width / 2 + 18; groupEC.Line.Y1 = y + componentAsGroupElement.ComponentCanvas.Height - 4; groupEC.Line.X2 = ecl.Line.X2; groupEC.Line.Y2 = ecl.Line.Y2; Canvas.SetZIndex(groupEC.Line, -1001); groupEC.TriggerComponentId = compName; groupEC.ListenerComponentId = ecl.ListenerComponentId; groupEC.HasGroupSource = true; groupEC.HasGroupTarget = EventChannelLineHasGroupTarget(ecl); AddEventChannelCommand(groupEC, false); canvas.Children.Add(groupEC.Line); } DeleteDanglingChannels(); HideGroupChannels(); // Delete all Eventchannels where either the source or the target does not exist anymore DeleteDanglingEventChannelLines(); DeleteDanglingEventChannels(); deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel)); // store the group in the deployment model if (storeGroup) { group[] tempGroups = deploymentModel.groups; if (tempGroups == null) { tempGroups = new group[1]; } else { Array.Resize(ref tempGroups, deploymentModel.groups.Count() + 1); } deploymentModel.groups = tempGroups; group groupForDeployment = new group(); groupForDeployment.id = compName; groupForDeployment.componentId = new string[selectedGroupComponentList.Count]; for (int i = 0; i < selectedGroupComponentList.Count; i++) { groupForDeployment.componentId[i] = ((componentType)selectedGroupComponentList[i]).id; } deploymentModel.groups[deploymentModel.groups.Count() - 1] = groupForDeployment; } ClearSelectedComponentList(); ClearSelectedChannelList(); ClearSelectedEventChannelList(); //AddSelectedComponent(deploymentComponentList[compName]); Console.WriteLine("Compname is:" + compName); return compName; }
/// <summary> /// Copy alle Components of the copyModel to the actual model /// </summary> private void PasteCopiedModel(model modelToPaste, bool namesAreValid, bool addToUndoStack) { CommandObject co = new CommandObject("Delete"); if (modelToPaste == null) return; // loading the components /* * Create a list of lists which contain all elements which should be within a group * after the paste method finishes */ ArrayList groupComps = new ArrayList(); ArrayList groups = new ArrayList(); ArrayList groupNames = new ArrayList(); foreach (componentType ct in modelToPaste.components) { if (ct.ComponentType != ACS2.componentTypeDataTypes.group) continue; groups.Add(ct); groupComponent gc = groupsList[ct.id]; ArrayList groupElems = new ArrayList(); foreach (componentType child in gc.AddedComponentList) { foreach (componentType child1 in modelToPaste.components) { if (child1.id.Equals(child.id)) { groupElems.Add(child1); } } } if (groupElems.Count > 0) { groupComps.Add(groupElems); bool namevalid = namesAreValid; int i = 1; while (namevalid == false) { string modelID = ct.id + "." + i; if (!deploymentComponentList.ContainsKey(modelID)) { namevalid = true; groupNames.Add(modelID); } else i++; } } } // Rename components and update all channels Dictionary<string, string> changedComponents = new Dictionary<string, string>(); foreach (object o in modelToPaste.components) { componentType modelComp = (componentType)o; if (modelComp.ComponentType == ACS2.componentTypeDataTypes.group) continue; // change id bool namevalid = namesAreValid; int i = 1; while (namevalid == false) { string modelID = modelComp.id + "." + i; if (!deploymentComponentList.ContainsKey(modelID)) { if (modelToPaste.channels != null) { foreach (channel c in modelToPaste.channels) { if (c.source.component.id == modelComp.id) c.source.component.id = modelID; if (c.target.component.id == modelComp.id) c.target.component.id = modelID; } } if (modelToPaste.eventChannels != null) { foreach (eventChannel ec in modelToPaste.eventChannels) { if (ec.sources.source.component.id == modelComp.id) ec.sources.source.component.id = modelID; if (ec.targets.target.component.id == modelComp.id) ec.targets.target.component.id = modelID; } } changedComponents.Add(modelComp.id,modelID); modelComp.id = modelID; namevalid = true; } else i++; } // check, if bundle is available if (componentList.ContainsKey(modelComp.type_id)) { // init the ArrayLists containing the ports. Used for easier and faster access modelComp.InitArrayLists(); foreach (propertyType p in modelComp.properties) { modelComp.PropertyArrayList.Add(p); } // copy the property datatype and description from bundle_description // also copy the port datatypes form the bundle_description // works only, if bundle and deployment fits to each other try { // search for bundle component Asterics.ACS2.componentTypesComponentType bundleComponent = (Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id]; // copy the ComponentType of the component modelComp.ComponentType = bundleComponent.type.Value; if (modelComp.properties != null) { foreach (propertyType deploymentProperty in modelComp.properties) { int index = 0; // searching for the right component property while (deploymentProperty.name != bundleComponent.properties[index].name) { index++; } // copy the properties of the component deploymentProperty.DataType = bundleComponent.properties[index].type; // check, if the property is a dynamic property if (bundleComponent.properties[index].getStringList) { deploymentProperty.GetStringList = true; } else { deploymentProperty.GetStringList = false; } // check the value fitting to the datatype if (!CheckPropertyDatatype(deploymentProperty.value, deploymentProperty.DataType)) { throw new LoadPropertiesException(); } deploymentProperty.Description = bundleComponent.properties[index].description; if (bundleComponent.properties[index].combobox != null) { deploymentProperty.ComboBoxStrings = bundleComponent.properties[index].combobox.Split(new String[] { "//" }, StringSplitOptions.None); } deploymentProperty.PropertyChanged += ComponentPropertyChanged; deploymentProperty.PropertyChangeError += ComponentPropertyChangeError; } // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment if ((bundleComponent.properties == null) && (modelComp.properties.Length != 0)) { throw new LoadPropertiesException(); } else if ((bundleComponent.properties != null) && (modelComp.properties.Length != bundleComponent.properties.Length)) { throw new LoadPropertiesException(); } } foreach (object portObj in modelComp.PortsList.Values) { // searching for the inPorts if (portObj is inputPortType) { int index = 0; inputPortType deploymentInPort = (inputPortType)portObj; ArrayList helperListInPort = new ArrayList(); // a list with all InPorts of a component for the bundel_description foreach (object bundleInPort in bundleComponent.ports) { if (bundleInPort is ACS2.inputPortType) { helperListInPort.Add(bundleInPort); } } while (deploymentInPort.portTypeID != ((ACS2.inputPortType)helperListInPort[index]).id) { index++; // searching for the right input port } // copy the dataType of the port deploymentInPort.PortDataType = ((Asterics.ACS2.inputPortType)helperListInPort[index]).dataType; deploymentInPort.MustBeConnected = ((Asterics.ACS2.inputPortType)helperListInPort[index]).mustBeConnected; deploymentInPort.Description = ((Asterics.ACS2.inputPortType)helperListInPort[index]).description; deploymentInPort.ComponentId = ((Asterics.ACS2.inputPortType)helperListInPort[index]).ComponentId; deploymentInPort.ComponentTypeId = ((Asterics.ACS2.inputPortType)helperListInPort[index]).id; // update the alias for group ports via property changed listener deploymentInPort.PropertyChanged += InputPortIntPropertyChanged; ACS2.propertyType[] sourceProperties = ((Asterics.ACS2.inputPortType)helperListInPort[index]).properties; if ((sourceProperties != null) && (sourceProperties.Length > 0)) { //if (deploymentInPort.PropertyArrayList.Count > 0) { foreach (propertyType deploymentProperty in deploymentInPort.properties) { int inPortIndex = 0; while (deploymentProperty.name != sourceProperties[inPortIndex].name) { inPortIndex++; } // copy the properties of the inPort deploymentProperty.DataType = sourceProperties[inPortIndex].type; deploymentProperty.Description = sourceProperties[inPortIndex].description; if (sourceProperties[inPortIndex].combobox != null) { deploymentProperty.ComboBoxStrings = sourceProperties[inPortIndex].combobox.Split(new String[] { "//" }, StringSplitOptions.None); } deploymentProperty.PropertyChanged += InPortPropertyChanged; deploymentProperty.PropertyChangeError += ComponentPropertyChangeError; } // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment if (deploymentInPort.properties.Length != sourceProperties.Length) { throw new Exception(); } } deploymentInPort.properties = (propertyType[])deploymentInPort.PropertyArrayList.ToArray(typeof(propertyType)); } else { // comparing all outPports int index = 0; outputPortType outPort = (outputPortType)portObj; ArrayList helperListOutPort = new ArrayList(); foreach (object origOutPort in bundleComponent.ports) { if (origOutPort is ACS2.outputPortType) { helperListOutPort.Add(origOutPort); } } while (outPort.portTypeID != ((Asterics.ACS2.outputPortType)helperListOutPort[index]).id) { index++; } // copy the dataType of the port outPort.PortDataType = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).dataType; outPort.Description = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).description; outPort.ComponentId = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).ComponentId; outPort.ComponentTypeId = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).id; // update the alias for group ports via property changed listener outPort.PropertyChanged += OutputPortIntPropertyChanged; ACS2.propertyType[] sourceProperties = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).properties; if ((sourceProperties != null) && (sourceProperties.Length > 0)) { //if (outPort.PropertyArrayList.Count > 0) { foreach (propertyType compProperty in outPort.properties) { int outPortIndex = 0; while (compProperty.name != sourceProperties[outPortIndex].name) { outPortIndex++; } // copy the properties of the outPort compProperty.DataType = sourceProperties[outPortIndex].type; compProperty.Description = sourceProperties[outPortIndex].description; if (sourceProperties[outPortIndex].combobox != null) { compProperty.ComboBoxStrings = sourceProperties[outPortIndex].combobox.Split(new String[] { "//" }, StringSplitOptions.None); } compProperty.PropertyChanged += OutPortPropertyChanged; compProperty.PropertyChangeError += ComponentPropertyChangeError; } // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment if (outPort.properties.Length != sourceProperties.Length) { throw new Exception(); } } outPort.properties = (propertyType[])outPort.PropertyArrayList.ToArray(typeof(propertyType)); } } } catch (Exception ex) { MessageBox.Show(Properties.Resources.CopyPropertiesErrorTextFormat(modelComp.id), Properties.Resources.CopyPropertiesErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, ex.Message); //versionconflict int posX; int posY; // set coordinates for the component in case there are not already set if ((modelComp.layout.posX == null) || (modelComp.layout.posX == "") || (modelComp.layout.posY == null) || (modelComp.layout.posY == "")) { posX = 40; posY = 40; } else { posX = Int32.Parse(modelComp.layout.posX); posY = Int32.Parse(modelComp.layout.posY); } // backup component to load properties componentType backupComp = modelComp; modelComp = componentType.CopyFromBundleModel((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id], modelComp.id); modelComp.layout.posX = Convert.ToString(posX); modelComp.layout.posY = Convert.ToString(posY); // HasVersionConflict indicates a version conflict between the component in a stored model and // the component in the bundle descriptor modelComp.HasVersionConflict = true; modelComp.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange); //break; // new code, copy property values from invalid (version conflict) component foreach (propertyType deploymentProperty in modelComp.properties) { foreach (propertyType backupProperty in backupComp.properties) { if (deploymentProperty.name == backupProperty.name) { if (CheckPropertyDatatype(backupProperty.value, deploymentProperty.DataType)) { deploymentProperty.value = backupProperty.value; // try-parse is missing } break; } } } } // end of exception // set coordinates for the component in case there are not already set if ((modelComp.layout.posX == null) || (modelComp.layout.posX == "") || (modelComp.layout.posY == null) || (modelComp.layout.posY == "")) { int[] pos = ProperComponentCoordinates(40, 40); modelComp.layout.posX = Convert.ToString(pos[0]); modelComp.layout.posY = Convert.ToString(pos[1]); } // Searching for the event triggers and event listeners of a component Asterics.ACS2.componentTypesComponentType bundleComponentEvents = (Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id]; // If component has version conflict, the events are already set by 'CopyFromBundleModel' if ((bundleComponentEvents.events != null) && (bundleComponentEvents.events != null) && !modelComp.HasVersionConflict) { foreach (object eventO in bundleComponentEvents.events) { if (eventO is ACS2.eventsTypeEventListenerPortType) { ACS2.eventsTypeEventListenerPortType compEl = (ACS2.eventsTypeEventListenerPortType)eventO; EventListenerPort el = new EventListenerPort(); el.EventListenerId = compEl.id; el.ComponentId = modelComp.id; el.EventDescription = compEl.description; modelComp.EventListenerList.Add(el); } else if (eventO is ACS2.eventsTypeEventTriggererPortType) { ACS2.eventsTypeEventTriggererPortType compEl = (ACS2.eventsTypeEventTriggererPortType)eventO; EventTriggerPort el = new EventTriggerPort(); el.EventTriggerId = compEl.id; el.ComponentId = modelComp.id; el.EventDescription = compEl.description; modelComp.EventTriggerList.Add(el); } } } // if the component has no version conflict, it will be pasted on the layout, otherwise, it is already on the // canvas (done by 'CopyFromBundleModel') if (!modelComp.HasVersionConflict) { modelComp.InitGraphLayout(modelComp.id); } else { //deploymentModel.components = deploymentComponentList.Values.ToArray(); } canvas.Children.Add(modelComp.ComponentCanvas); KeyboardNavigation.SetTabIndex(modelComp.ComponentCanvas, canvas.Children.Count + 1); modelComp.Label.Text = modelComp.id; double positionX = (Int32.Parse(modelComp.layout.posX) + copyXOffset * copyOffsetMulti); if (positionX + modelComp.ComponentCanvas.Width > canvas.RenderSize.Width) positionX = canvas.RenderSize.Width - modelComp.ComponentCanvas.Width; double positionY = (Int32.Parse(modelComp.layout.posY) + copyYOffset * copyOffsetMulti); if (positionY + modelComp.ComponentCanvas.Height > canvas.RenderSize.Height) positionY = canvas.RenderSize.Height - modelComp.ComponentCanvas.Height; modelComp.layout.posX = positionX.ToString(); modelComp.layout.posY = positionY.ToString(); deploymentComponentList.Add(modelComp.id, modelComp); //componentList.Add(modelComp.id, modelComp); // adding context menu modelComp.MainRectangle.ContextMenu = componentContextMenu; // adding keyboard focus listener modelComp.ComponentCanvas.KeyDown += Component_KeyDown; modelComp.ComponentCanvas.KeyUp += Component_KeyUp; modelComp.ComponentCanvas.Focusable = true; modelComp.ComponentCanvas.GotKeyboardFocus += ComponentCanvas_GotKeyboardFocus; modelComp.ComponentCanvas.LostKeyboardFocus += ComponentCanvas_LostKeyboardFocus; // adding property changed listener modelComp.PropertyChanged += ComponentIntPropertyChanged; modelComp.TopGrid.ContextMenu = componentContextMenu; modelComp.TopRectangle.ContextMenu = componentContextMenu; // set position of component on the canvas Canvas.SetLeft(modelComp.ComponentCanvas, Int32.Parse(modelComp.layout.posX)); Canvas.SetTop(modelComp.ComponentCanvas, Int32.Parse(modelComp.layout.posY)); // Adapt the size of MainRectangle, if more then MAINRECTANGLENUMBEROFPORTS are in a component int numInPorts = 0; int numOutPorts = 0; foreach (object objPort in modelComp.PortsList.Values) { if (objPort is inputPortType) { numInPorts++; } else { numOutPorts++; } } if (numOutPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) { modelComp.MainRectangle.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE); modelComp.ComponentCanvas.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE); } else if (numInPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) { modelComp.MainRectangle.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE); modelComp.ComponentCanvas.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE); } // Adapt the position of event trigger and event listener port, if the component has more input/output ports if (modelComp.EventListenerList.Count > 0) { Canvas.SetTop(modelComp.EventListenerPolygon.InputEventPortCanvas, modelComp.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10); } if (modelComp.EventTriggerList.Count > 0) { Canvas.SetTop(modelComp.EventTriggerPolygon.OutputEventPortCanvas, modelComp.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10); } } else { MessageBox.Show(Properties.Resources.LoadComponentNotFoundFormat(modelComp.type_id), Properties.Resources.CopyPropertiesErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); } // check, if component has a gui component, and load the gui component if (modelComp.gui != null) { AddGUIComponent(modelComp); } } deploymentModel.components = deploymentComponentList.Values.ToArray(); // loading the channels if (modelToPaste.channels != null) { foreach (object o in modelToPaste.channels) { channel modChannel = (channel)o; // check versionconflict: add only channels to components without a conflict if ((deploymentComponentList.ContainsKey(modChannel.source.component.id)) && (deploymentComponentList.ContainsKey(modChannel.target.component.id))) { // one of the channels component has a conflict. Check, if port is available and datatype fits together componentType tempCompOut = (componentType)deploymentComponentList[modChannel.source.component.id]; componentType tempCompIn = (componentType)deploymentComponentList[modChannel.target.component.id]; // try, if the ports are still available if ((tempCompOut.PortsList.Contains(modChannel.source.port.id)) && (tempCompIn.PortsList.Contains(modChannel.target.port.id))) { // check the datatypes of the ports, for the case, that they have been changed //if (CheckInteroperabilityOfPorts(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortDataType, ((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortDataType)) { modChannel.id = NewIdForChannel(); AddChannel(modChannel); modChannel.Line.Y1 = Canvas.GetTop(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortRectangle) + Canvas.GetTop(tempCompOut.ComponentCanvas) + 5; modChannel.Line.X1 = Canvas.GetLeft(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortRectangle) + Canvas.GetLeft(tempCompOut.ComponentCanvas) + 20; modChannel.Line.Y2 = Canvas.GetTop(((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortRectangle) + Canvas.GetTop(tempCompIn.ComponentCanvas) + 5; modChannel.Line.X2 = Canvas.GetLeft(((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortRectangle) + Canvas.GetLeft(tempCompIn.ComponentCanvas); Canvas.SetZIndex(modChannel.Line, Canvas.GetZIndex(modChannel.Line) + 1000); //} //else { // // if no event listener Port can be found, the component has a version conflict // MessageBox.Show(Properties.Resources.CopyChannelsErrorTextFormat(tempCompOut.id, tempCompIn.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); // tempCompIn.ComponentCanvas.Background = new SolidColorBrush(Colors.Red); // tempCompIn.HasVersionConflict = true; // tempCompOut.ComponentCanvas.Background = new SolidColorBrush(Colors.Red); // tempCompOut.HasVersionConflict = true; //} } else { if (!tempCompOut.PortsList.Contains(modChannel.source.port.id)) { MessageBox.Show(Properties.Resources.CopyChannelErrorNotFoundFormat(tempCompOut.id, tempCompIn.id, modChannel.source.port.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); tempCompOut.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange); tempCompOut.HasVersionConflict = true; } else { MessageBox.Show(Properties.Resources.CopyChannelErrorNotFoundFormat(tempCompOut.id, tempCompIn.id, modChannel.source.port.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); tempCompIn.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange); tempCompIn.HasVersionConflict = true; } } } } } // Loading the events and drawing the lines between the event ports if (modelToPaste.eventChannels != null) { bool foundLine = false; foreach (object o in modelToPaste.eventChannels) { eventChannel evChannel = (eventChannel)o; bool foundTriggerPort = false; bool foundListenerPort = false; try { foreach (EventTriggerPort checkEvent in ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).EventTriggerList) { if (checkEvent.ComponentId == evChannel.sources.source.component.id && checkEvent.EventTriggerId == evChannel.sources.source.eventPort.id) { foundTriggerPort = true; break; } } if (foundTriggerPort) { foreach (EventListenerPort checkEvent in ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).EventListenerList) { if (checkEvent.ComponentId == evChannel.targets.target.component.id && checkEvent.EventListenerId == evChannel.targets.target.eventPort.id) { foundListenerPort = true; break; } } if (foundListenerPort) { foreach (eventChannelLine channelLine in eventChannelLinesList) { if ((evChannel.sources.source.component.id == channelLine.TriggerComponentId) && (evChannel.targets.target.component.id == channelLine.ListenerComponentId)) { foundLine = true; break; } } if (!foundLine) { eventChannelLine eCL = new eventChannelLine(); eCL.Line.X1 = Canvas.GetLeft(((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5; //eCL.Line.Y1 = Canvas.GetTop(((modelComponent)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3; eCL.Line.Y1 = Canvas.GetTop(((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).MainRectangle.Height + LayoutConstants.EVENTPORTHEIGHT + LayoutConstants.MAINRECTANGLEOFFSETY - 7; eCL.Line.X2 = Canvas.GetLeft(((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5; //eCL.Line.Y2 = Canvas.GetTop(((modelComponent)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3; eCL.Line.Y2 = Canvas.GetTop(((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).MainRectangle.Height + LayoutConstants.EVENTPORTHEIGHT + LayoutConstants.MAINRECTANGLEOFFSETY - 7; eCL.Line.Focusable = true; eCL.ListenerComponentId = evChannel.targets.target.component.id; eCL.TriggerComponentId = evChannel.sources.source.component.id; eCL.Line.GotKeyboardFocus += EventChannel_GotKeyboardFocus; eCL.Line.LostKeyboardFocus += EventChannel_LostKeyboardFocus; eCL.Line.KeyDown += EventChannel_KeyDown; eCL.Line.ContextMenu = eventChannelContextMenu; eventChannelLinesList.Add(eCL); canvas.Children.Add(eCL.Line); KeyboardNavigation.SetTabIndex(eCL.Line, canvas.Children.Count + 1); Canvas.SetZIndex(eCL.Line, Canvas.GetZIndex(eCL.Line) + 2000); } eventChannelList.Add(o); foundLine = false; } else { // if no event listener Port can be found, the component has a version conflict MessageBox.Show(Properties.Resources.CopyEventsErrorTextFormat(evChannel.targets.target.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas.Background = new SolidColorBrush(Colors.Orange); ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).HasVersionConflict = true; } } else { // if no event trigger Port can be found, the component has a version conflict MessageBox.Show(Properties.Resources.CopyEventsErrorTextFormat(evChannel.sources.source.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas.Background = new SolidColorBrush(Colors.Orange); ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).HasVersionConflict = true; } } catch (Exception) { MessageBox.Show(Properties.Resources.CopyEventsExceptionTextFormat(evChannel.sources.source.component.id, evChannel.sources.source.eventPort.id, evChannel.targets.target.component.id, evChannel.targets.target.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); } } deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel)); } // focus the first element if (canvas.Children.Count > 0) { Keyboard.Focus(canvas.Children[0]); } else { Keyboard.Focus(canvas); } copyOffsetMulti++; ClearSelectedChannelList(); if (modelToPaste.channels != null) { foreach (channel c in modelToPaste.channels) { selectedChannelList.AddLast(c); co.InvolvedObjects.Add(c); } } UpdateSelectedChannels(); ClearSelectedEventChannelList(); LinkedList<eventChannelLine> selEventChannels = new LinkedList<eventChannelLine>(); foreach (eventChannelLine ecl in eventChannelLinesList) { if (modelToPaste.eventChannels != null) { foreach (eventChannel ech in modelToPaste.eventChannels) { if (ecl.ListenerComponentId == ech.targets.target.component.id || ecl.TriggerComponentId == ech.sources.source.component.id) { selEventChannels.AddLast(ecl); break; } } } } foreach (eventChannelLine ecl in selEventChannels) { selectedEventChannelList.AddLast(ecl); co.InvolvedObjects.Add(ecl); } UpdateSelectedEventChannels(); // select all inserted components ClearSelectedComponentList(); foreach (componentType mc in modelToPaste.components) { selectedComponentList.AddLast(mc); co.InvolvedObjects.Add(mc); } UpdateSelectedComponents(); if (addToUndoStack) { undoStack.Push(co); redoStack.Clear(); } SetKeyboardFocus(); int groupIndex = 0; AddDummyToModel(copyDummyName); foreach (ArrayList group in groupComps) { ClearSelectedChannelList(); ClearSelectedComponentList(); ClearSelectedEventChannelList(); foreach (componentType ct in group) { AddSelectedComponent(ct); } componentType groupComponent = (componentType) groups[groupIndex]; // add dummy channels to retain all ports of the copied group element foreach (object o in groupComponent.ports) { if (o is inputPortType) { inputPortType inPort = (inputPortType) o; string targetComponent = inPort.refs.componentID; componentType newTarget = null; foreach (componentType ct in group) { if (ct.id.StartsWith(targetComponent)) { if (newTarget == null) newTarget = ct; else { if (newTarget.id.Length < ct.id.Length) newTarget = ct; } } } if (newTarget == null) continue; // check if an channel already exists for this inputporttype bool duplicate = false; foreach (channel c in deploymentChannelList.Values) { if (c.target.component.id.Equals(newTarget.id) && c.target.port.id.Equals(inPort.portTypeID.Substring(targetComponent.Length + 1))) { duplicate = true; } } if (duplicate) continue; // add dummy channel channel groupChannel = new channel(); groupChannel.id = NewIdForChannel(); groupChannel.target.component.id = newTarget.id; groupChannel.target.port.id = inPort.refs.portID; groupChannel.source.component.id = copyDummyName; groupChannel.source.port.id = "out"; if (!ChannelExists(groupChannel)) AddChannel(groupChannel); } else if (o is outputPortType) { outputPortType outPort = (outputPortType) o; string sourceComponent = outPort.refs.componentID; componentType newSource = null; foreach (componentType ct in group) { if (ct.id.StartsWith(sourceComponent)) { if (newSource == null) newSource = ct; else { if (newSource.id.Length < ct.id.Length) newSource = ct; } } } if (newSource == null) continue; // add dummy channel channel groupChannel = new channel(); groupChannel.id = NewIdForChannel(); groupChannel.source.component.id = newSource.id; groupChannel.source.port.id = outPort.refs.portID; groupChannel.target.component.id = copyDummyName; groupChannel.target.port.id = "in"; if (!ChannelExists(groupChannel)) AddChannel(groupChannel); } } // add dummy eventchannels to retain all eventchannel ports of the copied group foreach (ArrayList echList in copyGroupEventChannels) { foreach (eventChannel ech in echList) { componentType source = null; componentType target = null; foreach (componentType ct in group) { if (ct.id.StartsWith(ech.sources.source.component.id)) { if (source == null) source = ct; else if (ct.id.Length > source.id.Length) source = ct; } if (ct.id.StartsWith(ech.targets.target.component.id)) { if (target == null) target = ct; else if (ct.id.Length > target.id.Length) target = ct; } } if (source != null) ech.sources.source.component.id = source.id; if (target != null) { ech.targets.target.component.id = target.id; ech.id = target.id + "_" + ech.sources.source.eventPort.id + "_" + ech.targets.target.eventPort.id; } if (source != null || target != null) eventChannelList.Add(ech); } } LinkedList<portAlias> newPortAlias = new LinkedList<portAlias>(); group originalGroup = null; foreach (object o in groups) { // groups.Add(ct); groupComponent gc = groupsList[((componentType)o).id]; // adapting the alias to the new group port names foreach (group gr in deploymentModel.groups) { if (gr.id == ((componentType)o).id) { originalGroup = gr; break; } } if (originalGroup != null && originalGroup.portAlias != null) { foreach (portAlias alias in originalGroup.portAlias) { foreach (string oldCompName in changedComponents.Keys) { if (alias.portId.Contains(oldCompName)) { portAlias pAlias = new portAlias(); pAlias.portId = alias.portId.Replace(oldCompName, changedComponents[oldCompName]); pAlias.portAlias1 = alias.portAlias1; newPortAlias.AddLast(pAlias); break; } } } } } DoGrouping((string) groupNames[groupIndex], false, true); group groupToUpdate = null; foreach (group gr in deploymentModel.groups) { if (gr.id == (string)groupNames[groupIndex]) { gr.portAlias = newPortAlias.ToArray(); groupToUpdate = gr; break; } } if (groupToUpdate.portAlias != null) { foreach (portAlias alias in groupToUpdate.portAlias) { componentType groupComponentToUpdate = deploymentComponentList[groupToUpdate.id]; groupComponentToUpdate.description = originalGroup.description; foreach (object port in groupComponentToUpdate.ports) { if ((port is inputPortType) && (((inputPortType)port).portTypeID == alias.portId)) { ((inputPortType)port).PortAliasForGroups = alias.portAlias1; ((inputPortType)port).PortLabel.Text = alias.portAlias1; break; } else if ((port is outputPortType) && (((outputPortType)port).portTypeID == alias.portId)) { ((outputPortType)port).PortAliasForGroups = alias.portAlias1; ((outputPortType)port).PortLabel.Text = alias.portAlias1; break; } } } } groupToUpdate.description = originalGroup.description; groupIndex++; } RemoveDummyFromModel(copyDummyName); DeleteDanglingChannels(); DeleteDanglingEventChannels(); // select the copied elements after paste selectedComponentList.Clear(); foreach (componentType mc in modelToPaste.components) { selectedComponentList.AddLast(mc); } UpdateSelectedComponents(); }
/// <summary> /// Ungrouping of the selected group /// </summary> /// <param name="addToUndoStack">Desition, if the undo-operation should be put on the undo-stack</param> private void DoUngrouping(bool addToUndoStack) { ArrayList componentsToRemove = new ArrayList(); ArrayList groups = new ArrayList(); ArrayList groupNames = new ArrayList(); foreach (componentType mc in selectedComponentList) { if (mc.ComponentType == ACS2.componentTypeDataTypes.group) { groupComponent undoGroup = groupsList[mc.id]; groupNames.Add(mc.id); groups.Add(undoGroup.AddedComponentList); foreach (channel unhideChannel in undoGroup.AddedChannelsList) { if (unhideChannel.Line.Visibility == System.Windows.Visibility.Hidden) unhideChannel.Line.Visibility = System.Windows.Visibility.Visible; } foreach (eventChannelLine unhideEventChannel in undoGroup.AddedEventChannelsList) { componentType source = GetEventChannelLineSource(unhideEventChannel); componentType target = GetEventChannelLineTarget(unhideEventChannel); if (source != null && target != null) { if (source.ComponentCanvas.Visibility != System.Windows.Visibility.Visible) { groupComponent gc = GetParentGroup(source); componentType groupCt = GetGroupComponent(gc); // Add EventchannelLine // copy eventchannels List<eventChannel> ecList = GetEventChannelsFromLine(unhideEventChannel); foreach (eventChannel ec in ecList) { eventChannel tmpEC = new eventChannel(); if (eventChannelExists(ec.targets.target.component.id, ec.targets.target.eventPort.id, groupCt.id, ec.sources.source.component.id + "_" + ec.sources.source.eventPort.id)) continue; tmpEC.sources.source.component.id = groupCt.id; tmpEC.sources.source.eventPort.id = ec.sources.source.component.id + "_" + ec.sources.source.eventPort.id; tmpEC.targets.target.component.id = ec.targets.target.component.id; tmpEC.targets.target.eventPort.id = ec.targets.target.eventPort.id; tmpEC.id = groupCt.id + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id; if (EventChannelHasGroupSource(ec)) tmpEC.GroupOriginalSource = ec.sources.source; if (EventChannelHasGroupTarget(ec)) tmpEC.GroupOriginalTarget = ec.GroupOriginalTarget; eventChannelList.Add(tmpEC); } if (!eventChannelLineExists(unhideEventChannel.ListenerComponentId, gc.ID)) { eventChannelLine groupEC = new eventChannelLine(); componentType sourceComp = deploymentComponentList[groupCt.id]; componentType targetComp = deploymentComponentList[unhideEventChannel.ListenerComponentId]; groupEC.Line.X1 = Canvas.GetLeft(sourceComp.ComponentCanvas) + sourceComp.ComponentCanvas.Width / 2 + 18; groupEC.Line.Y1 = Canvas.GetTop(sourceComp.ComponentCanvas) + sourceComp.ComponentCanvas.Height - 4; groupEC.Line.X2 = Canvas.GetLeft(targetComp.ComponentCanvas) + targetComp.ComponentCanvas.Width / 2 - 18; groupEC.Line.Y2 = Canvas.GetTop(targetComp.ComponentCanvas) + targetComp.ComponentCanvas.Height - 4; Canvas.SetZIndex(groupEC.Line, -1001); groupEC.TriggerComponentId = gc.ID; groupEC.ListenerComponentId = unhideEventChannel.ListenerComponentId; groupEC.HasGroupSource = EventChannelLineHasGroupSource(unhideEventChannel); groupEC.HasGroupTarget = EventChannelLineHasGroupTarget(unhideEventChannel); AddEventChannelCommand(groupEC, false); canvas.Children.Add(groupEC.Line); } } if (target.ComponentCanvas.Visibility != System.Windows.Visibility.Visible) { groupComponent gc = GetParentGroup(target); componentType groupCt = GetGroupComponent(gc); // Add EventchannelLine // copy eventchannels List<eventChannel> ecList = GetEventChannelsFromLine(unhideEventChannel); foreach (eventChannel ec in ecList) { if (eventChannelExists(groupCt.id, ec.targets.target.component.id + "_" + ec.targets.target.eventPort.id, ec.sources.source.component.id, ec.sources.source.eventPort.id)) continue; eventChannel tmpEC = new eventChannel(); tmpEC.sources.source.component.id = ec.sources.source.component.id; tmpEC.sources.source.eventPort.id = ec.sources.source.eventPort.id; tmpEC.targets.target.component.id = groupCt.id; tmpEC.targets.target.eventPort.id = ec.targets.target.component.id + "_" + ec.targets.target.eventPort.id; tmpEC.id = groupCt.id + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id; if (EventChannelHasGroupSource(ec)) tmpEC.GroupOriginalSource = ec.sources.source; if (EventChannelHasGroupTarget(ec)) tmpEC.GroupOriginalTarget = ec.GroupOriginalTarget; eventChannelList.Add(tmpEC); } if (!eventChannelLineExists(gc.ID, unhideEventChannel.TriggerComponentId)) { eventChannelLine groupEC = new eventChannelLine(); componentType sourceComp = deploymentComponentList[unhideEventChannel.TriggerComponentId]; componentType targetComp = deploymentComponentList[groupCt.id]; groupEC.Line.X1 = Canvas.GetLeft(sourceComp.ComponentCanvas) + sourceComp.ComponentCanvas.Width / 2 + 18; groupEC.Line.Y1 = Canvas.GetTop(sourceComp.ComponentCanvas) + sourceComp.ComponentCanvas.Height - 4; groupEC.Line.X2 = Canvas.GetLeft(targetComp.ComponentCanvas) + targetComp.ComponentCanvas.Width / 2 - 18; groupEC.Line.Y2 = Canvas.GetTop(targetComp.ComponentCanvas) + targetComp.ComponentCanvas.Height - 4; Canvas.SetZIndex(groupEC.Line, -1001); groupEC.TriggerComponentId = unhideEventChannel.TriggerComponentId; groupEC.ListenerComponentId = gc.ID; groupEC.HasGroupSource = EventChannelLineHasGroupSource(unhideEventChannel); groupEC.HasGroupTarget = EventChannelLineHasGroupTarget(unhideEventChannel); AddEventChannelCommand(groupEC, false); canvas.Children.Add(groupEC.Line); } } if (target.ComponentCanvas.Visibility == System.Windows.Visibility.Visible && source.ComponentCanvas.Visibility == System.Windows.Visibility.Visible) unhideEventChannel.Line.Visibility = System.Windows.Visibility.Visible; continue; } } foreach (componentType unhideComponent in undoGroup.AddedComponentList) { unhideComponent.ComponentCanvas.Visibility = System.Windows.Visibility.Visible; } componentsToRemove.Add(mc); groupsList.Remove(undoGroup.ID); // remove group from deployment List<group> groupsInDeployment = deploymentModel.groups.ToList(); group groupToRemove = null; foreach (group gr in groupsInDeployment) { if (gr.id == undoGroup.ID) { groupToRemove = gr; break; } } groupsInDeployment.Remove(groupToRemove); deploymentModel.groups = groupsInDeployment.ToArray(); } } double maxLeftOut = 0; double maxRightOut = 0; double maxTopOut = 0; double maxBottomOut = 0; Size renderSize = canvas.RenderSize; foreach (componentType ct in selectedComponentList) { if (ct.ComponentType == ACS2.componentTypeDataTypes.group) continue; double leftPos = Canvas.GetLeft(ct.ComponentCanvas); if (leftPos < 0) if (leftPos < maxLeftOut) maxLeftOut = leftPos; double topPos = Canvas.GetTop(ct.ComponentCanvas); if (topPos < 0) if (topPos < maxTopOut) maxTopOut = topPos; double rightPos = Canvas.GetLeft(ct.ComponentCanvas) + ct.ComponentCanvas.Width; if (rightPos > renderSize.Width) if (rightPos > maxRightOut) maxRightOut = rightPos; double bottomPos = Canvas.GetTop(ct.ComponentCanvas) + ct.ComponentCanvas.Height; if (bottomPos > renderSize.Height) if (bottomPos > maxBottomOut) maxBottomOut = bottomPos; } if (maxLeftOut != 0 && maxRightOut == 0) { // one component is left out //move all components to the right foreach (componentType ct in selectedComponentList) { if (ct.ComponentType == ACS2.componentTypeDataTypes.group) continue; MoveComponent(ct, (int)Canvas.GetLeft(ct.ComponentCanvas) - (int)maxLeftOut, (int)Canvas.GetTop(ct.ComponentCanvas)); } } if (maxRightOut != 0 && maxLeftOut == 0) { // one component is left out //move all components to the right foreach (componentType ct in selectedComponentList) { if (ct.ComponentType == ACS2.componentTypeDataTypes.group) continue; MoveComponent(ct, (int)Canvas.GetLeft(ct.ComponentCanvas) - (int) (maxRightOut - canvas.RenderSize.Width), (int)Canvas.GetTop(ct.ComponentCanvas)); } } if (maxBottomOut != 0 && maxTopOut == 0) { // one component is left out //move all components to the right foreach (componentType ct in selectedComponentList) { if (ct.ComponentType == ACS2.componentTypeDataTypes.group) continue; MoveComponent(ct, (int) Canvas.GetLeft(ct.ComponentCanvas) , (int)Canvas.GetTop(ct.ComponentCanvas) - (int)(maxBottomOut - canvas.RenderSize.Height)); } } if (maxTopOut != 0 && maxBottomOut == 0) { // one component is left out //move all components to the right foreach (componentType ct in selectedComponentList) { if (ct.ComponentType == ACS2.componentTypeDataTypes.group) continue; MoveComponent(ct, (int)Canvas.GetLeft(ct.ComponentCanvas), (int)Canvas.GetTop(ct.ComponentCanvas) - (int)maxTopOut); } } foreach (eventChannelLine ecl in eventChannelLinesList) { if (ecl.Line.Visibility != System.Windows.Visibility.Visible) { componentType source = GetEventChannelLineSource(ecl); componentType target = GetEventChannelLineTarget(ecl); if (source == null || target == null) continue; if (source.ComponentCanvas.Visibility == System.Windows.Visibility.Visible && target.ComponentCanvas.Visibility == System.Windows.Visibility.Visible) ecl.Line.Visibility = System.Windows.Visibility.Visible; } } foreach (channel ch in deploymentChannelList.Values) { if (ch.Line.Visibility != System.Windows.Visibility.Visible) { if (ch.Line.Visibility == System.Windows.Visibility.Collapsed) continue; bool sourceVisible = false; bool targetVisible = false; if (deploymentComponentList.ContainsKey(ch.source.component.id)) { componentType source = deploymentComponentList[ch.source.component.id]; sourceVisible = source.ComponentCanvas.Visibility == System.Windows.Visibility.Visible; } if (deploymentComponentList.ContainsKey(ch.target.component.id)) { componentType target = deploymentComponentList[ch.target.component.id]; targetVisible = target.ComponentCanvas.Visibility == System.Windows.Visibility.Visible; } if (!sourceVisible || !targetVisible) continue; ch.Line.Visibility = System.Windows.Visibility.Visible; } } foreach (componentType mc in componentsToRemove) { DeleteComponent(mc); componentList.Remove(mc.type_id); selectedComponentList.Remove(mc); } HideGroupChannels(); DeleteDanglingChannels(); DeleteDanglingEventChannelLines(); DeleteDanglingEventChannels(); AddMissingEventChannels(); if (addToUndoStack) { CommandObject co = new CommandObject("Group", groups); foreach (string name in groupNames) { co.Parameter.Add(name); } undoStack.Push(co); redoStack.Clear(); } ClearSelectedChannelList(); ClearSelectedEventChannelList(); ClearSelectedComponentList(); foreach (LinkedList<componentType> ct in groups) { foreach (componentType c in ct) { if (c.ComponentType != ACS2.componentTypeDataTypes.group) AddSelectedComponent(c); } } }
/// <summary> /// Deletes all selected components, channels and eventchannels /// </summary> private void DeleteSelectedComponents() { if (selectedComponentList.Count == 0 && selectedChannelList.Count == 0 && selectedEventChannelList.Count == 0) return; CommandObject co = new CommandObject("Add"); foreach (componentType mc in selectedComponentList) { if (mc.ComponentType != ACS2.componentTypeDataTypes.group) co.InvolvedObjects.Add(mc); else { if (groupsList.ContainsKey(mc.id)) co.InvolvedObjects.Add(groupsList[mc.id]); } } // delete all selected channels foreach (channel ch in selectedChannelList) { DeleteChannel(ch); co.InvolvedObjects.Add(ch); } // delete all selected eventchannels if (focusedEventChannel != null) { focusedEventChannel = null; ResetPropertyDock(); } foreach (eventChannelLine ech in selectedEventChannelList) { co.InvolvedObjects.Add(ech); foreach (eventChannel eventCh in eventChannelList) { foreach (object o in co.InvolvedObjects) { if (!(o is eventChannelLine)) continue; if ((eventCh.sources.source.component.id == ((eventChannelLine)o).TriggerComponentId) && (eventCh.targets.target.component.id == ((eventChannelLine)o).ListenerComponentId)) { co.Parameter.Add(eventCh); } } } DeleteEventChannelCommand(ech); } foreach (componentType mc in selectedComponentList) { // delete all eventchannels from the mc // delete the eventChannels and therefore the events eventChannelLine eCL; for (int index = eventChannelLinesList.Count - 1; index >= 0; index--) { eCL = (eventChannelLine)eventChannelLinesList[index]; if ((eCL.TriggerComponentId == mc.id) || (eCL.ListenerComponentId == mc.id)) { focusedEventChannel = eCL; // Ask a question, if component and therefore all events should be deleted. Causes some problems, if no is selected // if (MessageBox.Show(Properties.Resources.DeleteEventChannelConfirmTextFormat(focusedEventChannel.TriggerComponentId, focusedEventChannel.ListernerComponentId), // Properties.Resources.DeleteEventChannelConfirmHeader, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { co.InvolvedObjects.Add(focusedEventChannel); foreach (eventChannel eventCh in eventChannelList) { foreach (object o in co.InvolvedObjects) { if (!(o is eventChannelLine)) continue; if ((eventCh.sources.source.component.id == ((eventChannelLine)o).TriggerComponentId) && (eventCh.targets.target.component.id == ((eventChannelLine)o).ListenerComponentId)) { co.Parameter.Add(eventCh); } } } DeleteEventChannelCommand(focusedEventChannel); focusedEventChannel = null; } } focusedEventChannel = null; // delete all channels from the mc if (mc.ports != null && mc.PortsList != null && mc.PortsList.Values != null) { foreach (Object o in mc.PortsList.Values) { if (o is inputPortType) { inputPortType pIn = (inputPortType)o; if (pIn.ChannelId != "") { channel tempChannel = deploymentChannelList[pIn.ChannelId]; DeleteChannel(tempChannel); co.InvolvedObjects.Add(tempChannel); } } else if (o is outputPortType) { outputPortType pOut = (outputPortType)o; while (pOut.ChannelIds.Count > 0) { channel tempChannel = deploymentChannelList[pOut.ChannelIds[0].ToString()]; DeleteChannel(tempChannel); co.InvolvedObjects.Add(tempChannel); } } } } ArrayList channelToDelete = new ArrayList(); foreach (channel c in deploymentChannelList.Values) { if (c.target.component.id.Equals(mc.id)) channelToDelete.Add(c); } foreach (channel c in channelToDelete) { DeleteChannel(c); } if (canvas.Children.Count > 0) { Keyboard.Focus(canvas.Children[0]); } else { Keyboard.Focus(canvas); } if (focusedComponent == mc) focusedComponent = null; DeleteComponent(mc); } undoStack.Push(co); redoStack.Clear(); DeleteDanglineLines(); ClearSelectedChannelList(); ClearSelectedComponentList(); ClearSelectedEventChannelList(); ResetPropertyDock(); }
/// <summary> /// Function called, if the left mouse button is pressed down on the canvas. This can cause several actions: move the component, draw a channel between ports or /// draw an event channel between two event ports /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnLeftDown(object sender, MouseEventArgs args) { if (hiddenChannels) { SetAllChannelsVisible(); hiddenChannels = false; } // four possibe actions: // select a component to move // connect the start point of a channel to an out-port // connect the end point of a channel to an in-port // fix a component after movement Point clickPoint = args.GetPosition(canvas); mouseMoveComponentX = (int)clickPoint.X; mouseMoveComponentY = (int)clickPoint.Y; connectedChannelLastClick = false; // sets a component to a new position // Line uncomment, to allow the drawing of channels just by clicking on the output port or the event trigger port //if ((newChannelRibbonButton.IsChecked == false) && (newEventChannelRibbonButton.IsChecked == false)) { if (args.Source is Canvas && ((Canvas)args.Source) == canvas && ModifierKeys.Control != Keyboard.Modifiers) { // whenever the user leaves the canvas with the mouse pointer, and stops holding the mousebutton, the mouseup // event will not get fired in this class. In this case the rectangle should not get modified // and work as before the user moved the mouse cursor outside the canvas. if (selectionRectangle == null) { ClearSelectedComponentList(); ClearSelectedChannelList(); ClearSelectedEventChannelList(); ResetPropertyDock(); selectionRectangle = new Rectangle(); Canvas.SetZIndex(selectionRectangle, selRectZIndex); selectionRectangle.Fill = new SolidColorBrush(Color.FromArgb(15, 0, 0, 255)); DoubleCollection dashes = new DoubleCollection(); dashes.Add(1.0000001); dashes.Add(2.0000001); selectionRectangle.StrokeDashArray = dashes; selectionRectangle.Stroke = new SolidColorBrush(Colors.Black); selectionRectangle.Width = 1; selectionRectangle.Height = 1; selRectStartPoint = args.GetPosition(canvas); Canvas.SetLeft(selectionRectangle, selRectStartPoint.X); Canvas.SetTop(selectionRectangle, selRectStartPoint.Y); canvas.Children.Add(selectionRectangle); } } else if (args.Source is Rectangle) { //modelComponent tempComponent = null; if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) { foreach (componentType tempComponent in deploymentComponentList.Values) { if ((tempComponent.MainRectangle == (Rectangle)args.Source) || (tempComponent.TopRectangle == (Rectangle)args.Source)) { focusedComponent = tempComponent; Keyboard.Focus(focusedComponent.ComponentCanvas); if (!selectedComponentList.Contains(tempComponent)) { ClearSelectedComponentList(); ClearSelectedChannelList(); ClearSelectedEventChannelList(); this.AddSelectedComponent(tempComponent); moveComponentRibbonButton.IsChecked = true; moveTracking = false; } break; } else { if (newChannelRibbonButton.IsEnabled) // was editchannelribbongroup { foreach (object o in tempComponent.PortsList.Values) { if (o is outputPortType) { if (((outputPortType)o).PortRectangle == (Rectangle)args.Source) { //focusedComponent = tempComponent; //Keyboard.Focus(focusedComponent.ComponentCanvas); newChannelRibbonButton.IsChecked = true; //disable mouse move mouseMoveComponentX = -1; mouseMoveComponentY = -1; ClearSelectedChannelList(); ClearSelectedComponentList(); ClearSelectedEventChannelList(); break; } } else if (o is inputPortType) { if (((inputPortType)o).PortRectangle == (Rectangle)args.Source) { //disable mouse move if (!selectedComponentList.Contains(tempComponent) && channelToConnect == null) { ClearSelectedComponentList(); ClearSelectedChannelList(); ClearSelectedEventChannelList(); this.AddSelectedComponent(tempComponent); moveComponentRibbonButton.IsChecked = true; } } } } } } } } } else if (args.Source is TextBlock) { if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) { foreach (componentType tempComponent in deploymentComponentList.Values) { if (tempComponent.Label == (TextBlock)args.Source) { focusedComponent = tempComponent; Keyboard.Focus(focusedComponent.ComponentCanvas); if (!selectedComponentList.Contains(tempComponent)) { ClearSelectedComponentList(); ClearSelectedChannelList(); ClearSelectedEventChannelList(); this.AddSelectedComponent(tempComponent); moveComponentRibbonButton.IsChecked = true; } break; } else { foreach (object o in tempComponent.PortsList.Values) { if (o is inputPortType) { if (((inputPortType)o).PortLabel == (TextBlock)args.Source) { focusedComponent = tempComponent; Keyboard.Focus(focusedComponent.ComponentCanvas); if (!selectedComponentList.Contains(tempComponent)) { ClearSelectedComponentList(); ClearSelectedChannelList(); ClearSelectedEventChannelList(); this.AddSelectedComponent(tempComponent); moveComponentRibbonButton.IsChecked = true; } break; } } else if (o is outputPortType) { if (((outputPortType)o).PortLabel == (TextBlock)args.Source) { focusedComponent = tempComponent; Keyboard.Focus(focusedComponent.ComponentCanvas); if (!selectedComponentList.Contains(tempComponent)) { ClearSelectedComponentList(); ClearSelectedChannelList(); ClearSelectedEventChannelList(); this.AddSelectedComponent(tempComponent); moveComponentRibbonButton.IsChecked = true; } break; } } } } } } } else if (args.Source is Polygon) { if (newEventChannelRibbonButton.IsEnabled) // was editeventribbongroup { if (((Polygon)args.Source).Name == "EventTriggerPortPolygon") { newEventChannelRibbonButton.IsChecked = true; ClearSelectedEventChannelList(); ClearSelectedComponentList(); ClearSelectedChannelList(); } else { if (newEventChannelRibbonButton.IsChecked == false) { // mouse down on an event channel input, not in connect mode if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) { foreach (componentType tempComponent in deploymentComponentList.Values) { Canvas tempCanvas = (Canvas)((Polygon)args.Source).Parent; if (tempComponent.ComponentCanvas == tempCanvas.Parent) { focusedComponent = tempComponent; Keyboard.Focus(focusedComponent.ComponentCanvas); if (!selectedComponentList.Contains(tempComponent)) { ClearSelectedComponentList(); ClearSelectedChannelList(); ClearSelectedEventChannelList(); this.AddSelectedComponent(tempComponent); moveComponentRibbonButton.IsChecked = true; } break; } } } } } } } if (focusedComponent != null) { Canvas.SetZIndex(focusedComponent.ComponentCanvas, Canvas.GetZIndex(focusedComponent.ComponentCanvas) + 3000); } if (componentToMove == null && focusedComponent != null) { if (args.Source is Rectangle) { if ((focusedComponent.MainRectangle == (Rectangle)args.Source) || (focusedComponent.TopRectangle == (Rectangle)args.Source)) { componentToMove = focusedComponent; offsetX = (int)args.GetPosition(canvas).X - (int)Canvas.GetLeft(focusedComponent.ComponentCanvas); offsetY = (int)args.GetPosition(canvas).Y - (int)Canvas.GetTop(focusedComponent.ComponentCanvas); } } else if (args.Source is TextBlock) { if ((focusedComponent.ComponentCanvas == ((TextBlock)args.Source).Parent) || (focusedComponent.Label) == (TextBlock)args.Source) { componentToMove = focusedComponent; offsetX = (int)args.GetPosition(canvas).X - (int)Canvas.GetLeft(focusedComponent.ComponentCanvas); offsetY = (int)args.GetPosition(canvas).Y - (int)Canvas.GetTop(focusedComponent.ComponentCanvas); } } //MoveComponent(componentToMove, (int)args.GetPosition(canvas).X, (int)args.GetPosition(canvas).Y); //componentToMove = null; } //} if ((newChannelRibbonButton.IsChecked == true) && (newChannelRibbonButton.IsEnabled)) // was editchannelribbongroup { // outport has been found, component channel has been created, now searching for inport and make all connections/settings if (channelToConnect != null) { if (args.Source is Rectangle) { Rectangle r = (Rectangle)args.Source; Canvas tempCanvas = (Canvas)r.Parent; foreach (componentType tempComponent in deploymentComponentList.Values) { if (tempComponent.ComponentCanvas == tempCanvas) { bool portfound = false; if (tempComponent.ports != null) { foreach (object o in tempComponent.ports) { if (o is inputPortType) { inputPortType inPort = (inputPortType)o; if ((inPort.PortRectangle == r) && (inPort.ChannelId == "")) { outputPortType outPort = (outputPortType)((componentType)deploymentComponentList[channelToConnect.source.component.id]).PortsList[channelToConnect.source.port.id]; //outputPortType outPort = (outputPortType)((modelComponent)deploymentComponentList[channelToConnect.source.component.id]).ports.PortsList[] if (CheckInteroperabilityOfPorts(outPort.PortDataType, inPort.PortDataType)) { channelToConnect.target.component.id = tempComponent.id; channelToConnect.target.port.id = inPort.portTypeID; channelToConnect.Line.X2 = Canvas.GetLeft(r) + Canvas.GetLeft(tempCanvas); channelToConnect.Line.Y2 = Canvas.GetTop(r) + r.ActualHeight - r.ActualHeight / 2 + Canvas.GetTop(tempCanvas); inPort.ChannelId = channelToConnect.id; AddChannel(channelToConnect); portfound = true; Canvas.SetZIndex(channelToConnect.Line, Canvas.GetZIndex(channelToConnect.Line) + 1000); CommandObject co = new CommandObject("Delete", channelToConnect); undoStack.Push(co); redoStack.Clear(); channelToConnect = null; newChannelRibbonButton.IsChecked = false; connectedChannelLastClick = true; ChangeChannelVisibility(outPort.PortDataType, false, true, false); break; } else { MessageBox.Show(Properties.Resources.PortConnectingDatyTypeErrorFormat(outPort.PortDataType, inPort.PortDataType), Properties.Resources.PortConnectingDatyTypeErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); } } } } } if (portfound == false) { // click on a component while trying to connect a channel ClearSelectedChannelList(); ClearSelectedComponentList(); ClearSelectedEventChannelList(); AddSelectedComponent(tempComponent); canvas.Children.Remove(channelToConnect.Line); channelToConnect = null; newChannelRibbonButton.IsChecked = false; //TODO: restore visibility of ports } break; } } // click on the empty canvas, componentChannel will be deleted instead of connected } else { canvas.Children.Remove(channelToConnect.Line); channelToConnect = null; newChannelRibbonButton.IsChecked = false; } } // searching an out-port for a new channel else if (args.Source is Rectangle) { Rectangle r = (Rectangle)args.Source; Canvas tempCanvas = (Canvas)r.Parent; foreach (componentType tempComponent in deploymentComponentList.Values) { if (tempComponent.ComponentCanvas == tempCanvas) { foreach (object o in tempComponent.ports) { if (o is outputPortType) { outputPortType outPort = (outputPortType)o; if (outPort.PortRectangle == r) { channelToConnect = new channel(); channelToConnect.id = NewIdForChannel(); channelToConnect.source.component.id = tempComponent.id; channelToConnect.source.port.id = outPort.portTypeID; //outPort.ChannelId = channelToConnect.id; channelToConnect.Line.X1 = Canvas.GetLeft(r) + r.ActualWidth + Canvas.GetLeft(tempCanvas); channelToConnect.Line.Y1 = Canvas.GetTop(r) + r.ActualHeight - r.ActualHeight / 2 + Canvas.GetTop(tempCanvas); // -5 channelToConnect.Line.X2 = args.GetPosition(canvas).X; channelToConnect.Line.Y2 = args.GetPosition(canvas).Y; canvas.Children.Add(channelToConnect.Line); ChangeChannelVisibility(outPort.PortDataType, true, false, true); break; } } } break; } } } } else if ((newChannelRibbonButton.IsChecked == false) && (channelToConnect != null)) { // click on the empty canvas, componentChannel will be deleted instead of connected canvas.Children.Remove(channelToConnect.Line); channelToConnect = null; newChannelRibbonButton.IsChecked = false; } if ((newEventChannelRibbonButton.IsChecked == true) && (newEventChannelRibbonButton.IsEnabled)) // was editeventribbongroup { if (args.Source is Polygon) { if (eventChannelToConnect == null) { Polygon p = (Polygon)args.Source; Canvas tempCanvas = (Canvas)p.Parent; if (tempCanvas.Name == "EventTriggerPort") { eventChannelToConnect = new eventChannelLine(); foreach (componentType tempComponent in deploymentComponentList.Values) { if (tempComponent.ComponentCanvas == (Canvas)tempCanvas.Parent) { eventChannelToConnect.TriggerComponentId = tempComponent.id; break; } } eventChannelToConnect.Line.X1 = Canvas.GetLeft((Canvas)tempCanvas.Parent) + Canvas.GetLeft(tempCanvas) + tempCanvas.Width / 2 + 2; eventChannelToConnect.Line.Y1 = Canvas.GetTop((Canvas)tempCanvas.Parent) + Canvas.GetTop(tempCanvas) + tempCanvas.Height; eventChannelToConnect.Line.X2 = args.GetPosition(canvas).X; eventChannelToConnect.Line.Y2 = args.GetPosition(canvas).Y; canvas.Children.Add(eventChannelToConnect.Line); } } else { // connect Polygon p = (Polygon)args.Source; Canvas tempCanvas = (Canvas)p.Parent; if (tempCanvas.Name == "EventListenerPort") { foreach (componentType tempComponent in deploymentComponentList.Values) { if (tempComponent.ComponentCanvas == (Canvas)tempCanvas.Parent) { eventChannelToConnect.ListenerComponentId = tempComponent.id; break; } } eventChannelToConnect.Line.X2 = Canvas.GetLeft((Canvas)tempCanvas.Parent) + Canvas.GetLeft(tempCanvas) + tempCanvas.ActualWidth / 2 + 2; eventChannelToConnect.Line.Y2 = Canvas.GetTop((Canvas)tempCanvas.Parent) + Canvas.GetTop(tempCanvas) + tempCanvas.Height; connectedChannelLastClick = true; CommandObject co = new CommandObject("Delete", eventChannelToConnect); undoStack.Push(co); redoStack.Clear(); AddEventChannelCommand(eventChannelToConnect, true); eventChannelToConnect = null; newEventChannelRibbonButton.IsChecked = false; ////dockManager.ActiveContent = dockableEventsTab; } } } else { // drop the eventChannelLine if (eventChannelToConnect != null) { canvas.Children.Remove(eventChannelToConnect.Line); eventChannelToConnect = null; newEventChannelRibbonButton.IsChecked = false; } } } else if ((newEventChannelRibbonButton.IsChecked == false) && (eventChannelToConnect != null)) { // click on the empty canvas, eventChannel will be deleted instead of connected canvas.Children.Remove(eventChannelToConnect.Line); eventChannelToConnect = null; newEventChannelRibbonButton.IsChecked = false; } }
/// <summary> /// Creates a CommandObject containing the coordinates of all /// selected components /// </summary> private CommandObject CreateMoveCommandObject() { CommandObject co = new CommandObject("moveComponent", selectedComponentList.ToArray()); for (int i = 0; i < selectedComponentList.Count; i++) { componentType mc = selectedComponentList.ElementAt(i); co.Parameter.Add(int.Parse(mc.layout.posX)); co.Parameter.Add(int.Parse(mc.layout.posY)); } return co; }
/// <summary> /// Connect an event channel to the event listener port. Called from the component context menu. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ComponentContextMenuItemConnectEvent_Click(object sender, RoutedEventArgs e) { Rectangle r = (Rectangle)((ContextMenu)((MenuItem)e.Source).Parent).PlacementTarget; componentType componentWithFocus = null; foreach (componentType tempComponent in deploymentComponentList.Values) { if ((tempComponent.MainRectangle == r) || (tempComponent.TopRectangle == r)) { componentWithFocus = tempComponent; break; } } canvas.Children.Add(eventChannelToConnect.Line); eventChannelToConnect.ListenerComponentId = componentWithFocus.id; eventChannelToConnect.Line.X2 = Canvas.GetLeft(componentWithFocus.ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5; eventChannelToConnect.Line.Y2 = Canvas.GetTop(componentWithFocus.ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3; CommandObject co = new CommandObject("Delete", eventChannelToConnect); undoStack.Push(co); redoStack.Clear(); AddEventChannelCommand(eventChannelToConnect, true); eventChannelToConnect = null; ////dockManager.ActiveContent = dockableEventsTab; componentContextMenuItemAddEventChannel.IsEnabled = true; componentContextMenuItemConnectEventChannel.IsEnabled = false; componentContextMenuItemDropEventChannel.IsEnabled = false; }
/// <summary> /// Connect channel from the component context menu - needed to make the ACS fully keyboard accessible /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ComponentContextMenuConnectChannel_Click(object sender, RoutedEventArgs e) { componentType componentWithFocus = null; // Check, if context menu was called from a rectangel if (((ContextMenu)((MenuItem)((MenuItem)e.Source).Parent).Parent).PlacementTarget is Rectangle) { Rectangle r = (Rectangle)((ContextMenu)((MenuItem)((MenuItem)e.Source).Parent).Parent).PlacementTarget; foreach (componentType tempComponent in deploymentComponentList.Values) { if ((tempComponent.MainRectangle == r) || (tempComponent.TopRectangle == r)) { componentWithFocus = tempComponent; break; } } // Check, if context menu was called from a grid (the name field at the top of a component) } else if (((ContextMenu)((MenuItem)((MenuItem)e.Source).Parent).Parent).PlacementTarget is Grid) { Grid g = (Grid)((ContextMenu)((MenuItem)((MenuItem)e.Source).Parent).Parent).PlacementTarget; foreach (componentType tempComponent in deploymentComponentList.Values) { if (tempComponent.TopGrid == g) { componentWithFocus = tempComponent; break; } } } // if no channel is prepared to be connected, a new channel will be prepared if (channelToConnect == null) { channelToConnect = new channel(); channelToConnect.id = NewIdForChannel(); channelToConnect.source.component.id = componentWithFocus.id; channelToConnect.source.port.id = ((MenuItem)e.Source).Header.ToString(); Rectangle portRectangle = ((outputPortType)componentWithFocus.PortsList[channelToConnect.source.port.id]).PortRectangle; channelToConnect.Line.X1 = Canvas.GetLeft(portRectangle) + portRectangle.ActualWidth + Canvas.GetLeft(componentWithFocus.ComponentCanvas); channelToConnect.Line.Y1 = Canvas.GetTop(portRectangle) + portRectangle.ActualHeight - 5 + Canvas.GetTop(componentWithFocus.ComponentCanvas); newChannelRibbonButton.IsChecked = true; componentContextMenuItemAddChannel.IsEnabled = false; componentContextMenuItemConnectChannel.IsEnabled = true; componentContextMenuItemDropChannel.IsEnabled = true; // if a channel is prepared, it will tried to connect it } else { outputPortType outPort = (outputPortType)((componentType)deploymentComponentList[channelToConnect.source.component.id]).PortsList[channelToConnect.source.port.id]; channelToConnect.target.component.id = componentWithFocus.id; channelToConnect.target.port.id = ((MenuItem)e.Source).Header.ToString(); // check, if the datatypes of the port fits to each other if (CheckInteroperabilityOfPorts(outPort.PortDataType, ((inputPortType)componentWithFocus.PortsList[channelToConnect.target.port.id]).PortDataType)) { Rectangle portRectangle = ((inputPortType)componentWithFocus.PortsList[channelToConnect.target.port.id]).PortRectangle; channelToConnect.Line.X2 = Canvas.GetLeft(portRectangle) + Canvas.GetLeft(componentWithFocus.ComponentCanvas); channelToConnect.Line.Y2 = Canvas.GetTop(portRectangle) + portRectangle.ActualHeight - 5 + Canvas.GetTop(componentWithFocus.ComponentCanvas); AddChannel(channelToConnect); Canvas.SetZIndex(channelToConnect.Line, Canvas.GetZIndex(channelToConnect.Line) + 1000); CommandObject co = new CommandObject("Delete", channelToConnect); undoStack.Push(co); redoStack.Clear(); channelToConnect = null; newChannelRibbonButton.IsChecked = false; componentContextMenuItemAddChannel.IsEnabled = true; componentContextMenuItemConnectChannel.IsEnabled = false; componentContextMenuItemDropChannel.IsEnabled = false; } else { MessageBox.Show(Properties.Resources.PortConnectingDatyTypeErrorFormat(outPort.PortDataType, ((inputPortType)componentWithFocus.PortsList[channelToConnect.target.port.id]).PortDataType), Properties.Resources.PortConnectingDatyTypeErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); channelToConnect.target.component.id = null; channelToConnect.target.port.id = null; } } }
/// <summary> /// Creating (drawing) a new, presaved group out of a menu selection (RibbonDropDown) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddGroupFromRibbonMenu(object sender, RoutedEventArgs e) { MenuItem mi = (MenuItem)e.Source; // check if the file is valid against the deployment_schema try { String xmlError; XmlValidation xv = new XmlValidation(); xmlError = xv.validateXml((string)mi.CommandParameter, ini.IniReadValue("model", "deployment_schema")); if (xmlError.Equals("")) { XmlSerializer ser2 = new XmlSerializer(typeof(model)); StreamReader sr2 = new StreamReader((string)mi.CommandParameter); model groupToPaste = (model)ser2.Deserialize(sr2); sr2.Close(); foreach (componentType ct in groupToPaste.components) { bool found = false; if (((Asterics.ACS2.componentTypesComponentType)componentList[ct.type_id]).singleton) { foreach (componentType ct1 in deploymentComponentList.Values) { if (ct1.type_id == ct.type_id) { found = true; break; } } if (found) { MessageBox.Show(Properties.Resources.SingletonErrorHeaderFormat(ct.type_id), Properties.Resources.SingletonErrorDialogHeader, MessageBoxButton.OK, MessageBoxImage.Warning); return; } } } if (groupToPaste.groups == null) { throw new Exception("group element missing"); } // adapt names in the component, so they can be added without renaming in the PasteCopiedModel method // change id Dictionary<string, string> changedComponents = new Dictionary<string, string>(); foreach (componentType modelComp in groupToPaste.components) { bool namevalid = false; int i = 1; while (namevalid == false) { string modelID = modelComp.id + "." + i; bool foundInPasteGroup = false; foreach (componentType ct in groupToPaste.components) { if (ct.id == modelID) { foundInPasteGroup = true; break; } } if (!deploymentComponentList.ContainsKey(modelID) && !foundInPasteGroup) { if (groupToPaste.channels != null) { foreach (channel c in groupToPaste.channels) { if (c.source.component.id == modelComp.id) { c.source.component.id = modelID; } if (c.target.component.id == modelComp.id) { c.target.component.id = modelID; } } } if (groupToPaste.eventChannels != null) { foreach (eventChannel ec in groupToPaste.eventChannels) { if (ec.sources.source.component.id == modelComp.id) ec.sources.source.component.id = modelID; if (ec.targets.target.component.id == modelComp.id) ec.targets.target.component.id = modelID; } } changedComponents.Add(modelComp.id, modelID); modelComp.id = modelID; namevalid = true; } else i++; } } // adapting the alias to the new group port names if (groupToPaste.groups[0].portAlias != null) { foreach (portAlias alias in groupToPaste.groups[0].portAlias) { foreach (string oldCompName in changedComponents.Keys) { if (alias.portId.Contains(oldCompName)) { alias.portId = alias.portId.Replace(oldCompName, changedComponents[oldCompName]); break; } } } } //group[] backupGroups = groupToPaste.groups; //groupToPaste.groups = null; // add dummy element AddDummyToModel(pasteDummyName); PasteCopiedModel(groupToPaste, true,false); ClearSelectedComponentList(); foreach (string compId in changedComponents.Values) { AddSelectedComponent(deploymentComponentList[compId]); } // generate ID for new group int counter = 0; string compName = ""; do { counter++; compName = groupToPaste.groups[0].id + "." + counter; compName = TrimComponentName(compName); } while (deploymentComponentList.ContainsKey(compName)); string newGroupID = DoGrouping(compName, false, true); RemoveDummyFromModel(pasteDummyName); if (groupsList.ContainsKey(newGroupID)) { CommandObject co = new CommandObject(); co.Command = "Delete"; co.InvolvedObjects.Add(groupsList[newGroupID]); undoStack.Push(co); redoStack.Clear(); } componentType groupToUpdate = deploymentComponentList[compName]; // set the alias if (groupToPaste.groups[0].portAlias != null) { foreach (portAlias alias in groupToPaste.groups[0].portAlias) { foreach (object port in groupToUpdate.ports) { if ((port is inputPortType) && (((inputPortType)port).portTypeID == alias.portId)) { ((inputPortType)port).PortAliasForGroups = alias.portAlias1; ((inputPortType)port).PortLabel.Text = alias.portAlias1; break; } else if ((port is outputPortType) && (((outputPortType)port).portTypeID == alias.portId)) { ((outputPortType)port).PortAliasForGroups = alias.portAlias1; ((outputPortType)port).PortLabel.Text = alias.portAlias1; break; } } } } groupToUpdate.description = groupToPaste.groups[0].description; // store the group in the model /* group[] tempGroups = deploymentModel.groups; if (tempGroups == null) { tempGroups = new group[1]; } else { Array.Resize(ref tempGroups, deploymentModel.groups.Count() + 1); } deploymentModel.groups = tempGroups; //groupToPaste.groups[0].id = compName; //deploymentModel.groups[deploymentModel.groups.Count() - 1] = groupToPaste.groups[0]; group groupForDeployment = new group(); groupForDeployment.id = compName; groupForDeployment.componentId = new string[changedComponents.Count]; int i2 = 0; foreach (string key in changedComponents.Values) { groupForDeployment.componentId[i2] = key; i2++; } groupForDeployment.portAlias = groupToPaste.groups[0].portAlias; deploymentModel.groups[deploymentModel.groups.Count() - 1] = groupForDeployment; */ } else { throw new Exception("group element missing"); } } catch (Exception ex) { MessageBox.Show(Properties.Resources.GroupingErrorReadingGroupFile, Properties.Resources.GroupingErrorReadingGroupHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, ex.Message); } }
private void AddComponent(string typeId, bool forceTypeIDAsName, bool addToUndoStack, bool allowNamingDialog) { // generate an unique id and show this id in the naming dialogue or using this id when using automatic placement int counter = 0; String suggestID = null; Asterics.ACS2.componentTypesComponentType componentToAdd = (Asterics.ACS2.componentTypesComponentType)componentList[typeId]; // check, if component is singleton bool canBeAdded = true; if (((Asterics.ACS2.componentTypesComponentType)componentList[typeId]).singleton) { List<string> componentTypeList = new List<string>(); foreach (componentType comp in deploymentComponentList.Values) { componentTypeList.Add(comp.type_id); } canBeAdded = !componentTypeList.Contains(componentToAdd.id); } if (canBeAdded) { if (forceTypeIDAsName == false) { do { counter++; suggestID = componentToAdd.id + "." + counter; suggestID = TrimComponentName(suggestID); } while (deploymentComponentList.ContainsKey(suggestID)); } else suggestID = typeId; String newComponentId = null; // Show the naming dialog box only when set to do so in the options dialog if (showNamingDialogOnComponentInsert && allowNamingDialog) { newComponentId = SetNameForComponentOnCanvas(suggestID); } else { newComponentId = suggestID; } componentType selectedComponent; if (newComponentId != "") { selectedComponent = componentType.CopyFromBundleModel(componentToAdd, newComponentId); // adding the property changed listener to component properties foreach (propertyType p in selectedComponent.PropertyArrayList) { p.PropertyChanged += ComponentPropertyChanged; p.PropertyChangeError += ComponentPropertyChangeError; } // adding the property changed listener to port properties foreach (object port in selectedComponent.PortsList.Values) { if (port is inputPortType) { ((inputPortType)port).PropertyChanged += InputPortIntPropertyChanged; foreach (propertyType p in ((inputPortType)port).PropertyArrayList) { p.PropertyChanged += InPortPropertyChanged; p.PropertyChangeError += ComponentPropertyChangeError; } } else { // update the alias for group ports via property changed listener ((outputPortType)port).PropertyChanged += OutputPortIntPropertyChanged; foreach (propertyType p in ((outputPortType)port).PropertyArrayList) { p.PropertyChanged += OutPortPropertyChanged; p.PropertyChangeError += ComponentPropertyChangeError; } } } int[] pos = ProperComponentCoordinates(40, 40); int positionX = pos[0]; if (positionX < 0) positionX = 0; else if (positionX + selectedComponent.ComponentCanvas.Width > canvas.RenderSize.Width) positionX = (int)(canvas.RenderSize.Width - selectedComponent.ComponentCanvas.Width); int positionY = pos[1]; if (positionY < 0) positionY = 0; else if (positionY + selectedComponent.ComponentCanvas.Height > canvas.RenderSize.Height) positionY = (int)(canvas.RenderSize.Height - selectedComponent.ComponentCanvas.Height); selectedComponent.layout.posX = Convert.ToString(positionX); selectedComponent.layout.posY = Convert.ToString(positionY); focusedComponent = selectedComponent; this.ClearAndAddSelectedComponent(selectedComponent); AddComponent(selectedComponent); if (addToUndoStack) { CommandObject co = new CommandObject("Delete", selectedComponent); undoStack.Push(co); redoStack.Clear(); } // Check, if component has GUI-elements and if, setting it on the GUI-editor // check, if component has a gui component, and load the gui component if (componentToAdd.gui != null) { selectedComponent.gui = new guiType(); selectedComponent.gui.height = componentToAdd.gui.height; selectedComponent.gui.width = componentToAdd.gui.width; selectedComponent.gui.posX = "0"; selectedComponent.gui.posY = "0"; if (componentToAdd.gui.IsExternalGUIElementSpecified && componentToAdd.gui.IsExternalGUIElement) { selectedComponent.gui.IsExternalGUIElement = true; } else { selectedComponent.gui.IsExternalGUIElement = false; } AddGUIComponent(selectedComponent); } //Keyboard.Focus(selectedComponent.ComponentCanvas); } } else { MessageBox.Show(Properties.Resources.SingletonErrorHeaderFormat(typeId), Properties.Resources.SingletonErrorDialogHeader, MessageBoxButton.OK, MessageBoxImage.Warning); } }