Example #1
0
        /// <summary>
        /// Save the selected group to a file, so that it can be reused
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveGroupButton_Click(object sender, RoutedEventArgs e)
        {
            groupComponent groupToSave = null;
            foreach (componentType mc in selectedComponentList) {
                if (mc.ComponentType == ACS2.componentTypeDataTypes.group) {
                    groupToSave = groupsList[mc.id];
                    break;
                }
            }
            if (groupToSave != null) {
                storageDialog = new StorageDialog();

                string[] filesInGroupsFolder;
                if (ini.IniReadValue("Options", "useAppDataFolder").Equals("true")) {
                    filesInGroupsFolder = Directory.GetFiles(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\groups\\", "*.agr");
                } else {
                    filesInGroupsFolder = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\groups\\", "*.agr");
                }
                foreach (string s in filesInGroupsFolder) {
                    storageDialog.filenameListbox.Items.Add(s.Substring(s.LastIndexOf('\\') + 1));
                }
                storageDialog.filenameListbox.SelectionChanged += filenameListbox_SelectionChanged;
                storageDialog.Title = Properties.Resources.GroupStoreDialogTitle;
                storageDialog.listLabel.Content = Properties.Resources.GroupStoreDialogListLabel;
                storageDialog.filenameTextbox.Text = "NewGroup.agr";

                storageDialog.modelNameLabel.Content = Properties.Resources.GroupStoreDialogGroupName;

                storageDialog.Owner = this;
                storageDialog.ShowDialog();

                if (storageDialog.filenameTextbox.Text != null && storageDialog.filenameTextbox.Text != "") {
                    try {
                        model groupModelToSave;
                        if (groupToSave != null) {
                            ClearSelectedChannelList();
                            ClearSelectedEventChannelList();
                            ClearSelectedComponentList();

                            foreach (componentType componentInGroup in groupToSave.AddedComponentList) {
                                AddSelectedComponent(deploymentComponentList[componentInGroup.id]);
                            }

                            // make a submodel, containing all grouging relevant data

                            groupModelToSave = new model();
                            groupModelToSave.modelName = groupToSave.GroupID;
                            // insert all selected components to the model
                            LinkedList<componentType> t = new LinkedList<componentType>();
                            for (int i = 0; i < selectedComponentList.Count; i++) {
                                componentType ct = selectedComponentList.ElementAt(i);
                                t.AddLast(ct);
                            }
                            groupModelToSave.components = t.ToArray();
                            // adding a group element to save the aliases
                            groupModelToSave.groups = new group[1];
                            foreach (group groupToAdd in deploymentModel.groups) {
                                if (groupToAdd.id == groupToSave.ID) {
                                    groupModelToSave.groups[0] = groupToAdd;
                                    break;
                                }
                            }

                            //get all selected channels where the source and target components
                            //are also selected
                            LinkedList<channel> copyChannels = new LinkedList<channel>();
                            foreach (channel c in groupToSave.AddedChannelsList) {
                                bool sourceFound, targetFound;
                                sourceFound = targetFound = false;
                                foreach (componentType mc in groupModelToSave.components) {
                                    if (mc.id == c.source.component.id)
                                        sourceFound = true;
                                    if (mc.id == c.target.component.id)
                                        targetFound = true;
                                    if (sourceFound && targetFound)
                                        break;
                                }
                                if (sourceFound && targetFound)
                                    copyChannels.AddLast(c);
                            }

                            // Adding dummy channels to make the input and output ports of the group visible

                            componentType groupComponent = deploymentComponentList[groupToSave.ID];
                            int index = 0;
                            foreach (object o in groupComponent.ports) {
                                channel c = new channel();
                                c.id = "bindingveigl." + index;
                                if (o is inputPortType) {
                                    c.source.component.id = pasteDummyName;
                                    c.source.port.id = "out";
                                    c.target.component.id = ((inputPortType)o).refs.componentID;
                                    c.target.port.id = ((inputPortType)o).refs.portID;
                                } else {
                                    c.source.component.id = ((outputPortType)o).refs.componentID;
                                    c.source.port.id = ((outputPortType)o).refs.portID;
                                    c.target.component.id = pasteDummyName;
                                    c.target.port.id = "in";
                                }
                                copyChannels.AddLast(c);
                                index++;
                            }

                            groupModelToSave.channels = new channel[copyChannels.Count];
                            for (int i = 0; i < copyChannels.Count; i++)
                                groupModelToSave.channels[i] = copyChannels.ElementAt(i);

                            // get all selected Eventchannels

                            index = 0;
                            LinkedList<eventChannel> copyEventChannels = new LinkedList<eventChannel>();
                            LinkedList<EventListenerPort> foundEdgeListenerEvents = new LinkedList<EventListenerPort>();
                            LinkedList<EventTriggerPort> foundEdgeTriggerEvents = new LinkedList<EventTriggerPort>();
                            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])) {
                                    eventChannel newEc = new eventChannel();
                                    newEc.id = "eventbindingveigl." + index;
                                    newEc.sources.source.component.id = ec.sources.source.component.id;
                                    newEc.sources.source.eventPort.id = ec.sources.source.eventPort.id;
                                    newEc.targets.target.component.id = pasteDummyName;
                                    newEc.targets.target.eventPort.id = "eventlistener";
                                    index++;
                                    copyEventChannels.AddLast(newEc);
                                    // 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])) {
                                    eventChannel newEc = new eventChannel();
                                    newEc.id = "eventbindingveigl." + index;
                                    newEc.sources.source.component.id = pasteDummyName;
                                    newEc.sources.source.eventPort.id = "eventtrigger";
                                    newEc.targets.target.component.id = ec.targets.target.component.id;
                                    newEc.targets.target.eventPort.id = ec.targets.target.eventPort.id;
                                    index++;
                                    copyEventChannels.AddLast(newEc);
                                } else if ((selectedComponentList.Contains(deploymentComponentList[ec.targets.target.component.id]) && selectedComponentList.Contains(deploymentComponentList[ec.sources.source.component.id]))) {
                                    copyEventChannels.AddFirst(ec);
                                }
                            }

                            // Adding dummy eventchannels to make the input and output ports of the group visible
                            foreach (EventListenerPort elp in groupComponent. EventListenerList) {
                                eventChannel newEc = new eventChannel();
                                foreach (componentType mc in groupModelToSave.components) {
                                    if (elp.EventListenerId.StartsWith(mc.id)) {
                                        newEc.targets.target.component.id = mc.id;
                                        newEc.targets.target.eventPort.id = ((EventListenerPort)mc.EventListenerList[0]).EventListenerId;
                                        newEc.id = "eventbindingveigl." + index;
                                        newEc.sources.source.component.id = pasteDummyName;
                                        newEc.sources.source.eventPort.id = "eventtrigger";

                                        index++;
                                        copyEventChannels.AddLast(newEc);
                                        break;
                                    }
                                }

                            }
                            foreach (EventTriggerPort etp in groupComponent.EventTriggerList) {
                                eventChannel newEc = new eventChannel();
                                foreach (componentType mc in groupModelToSave.components) {
                                    if (etp.EventTriggerId.StartsWith(mc.id)) {
                                        newEc.id = "eventbindingveigl." + index;
                                        newEc.sources.source.component.id = mc.id;
                                        newEc.sources.source.eventPort.id = ((EventTriggerPort)mc.EventTriggerList[0]).EventTriggerId;
                                        newEc.targets.target.component.id = pasteDummyName;
                                        newEc.targets.target.eventPort.id = "eventlistener";
                                        index++;
                                        copyEventChannels.AddLast(newEc);
                                        break;
                                    }
                                }
                            }

                            if (copyEventChannels.Count == 0) {
                                groupModelToSave.eventChannels = null;
                            } else {
                                groupModelToSave.eventChannels = copyEventChannels.ToArray();
                            }
                            groupModelToSave = CopyModel(groupModelToSave);

                            // write group stream
                            XmlSerializer x = new XmlSerializer(groupModelToSave.GetType());
                            string filename;
                            if (ini.IniReadValue("Options", "useAppDataFolder").Equals("true")) {
                                filename = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\groups\\" + storageDialog.filenameTextbox.Text;
                            } else {
                                filename = AppDomain.CurrentDomain.BaseDirectory + "\\groups\\" + storageDialog.filenameTextbox.Text;
                            }
                            if (!filename.EndsWith(".agr")) {
                                filename += ".agr";
                            }
                            FileStream str = new FileStream(filename, FileMode.Create);
                            x.Serialize(str, groupModelToSave);
                            str.Close();

                            // add new group to list of groups
                            bool alreadyInMenu = false;
                            foreach (RibbonApplicationSplitMenuItem i in groupDropDown.Items) {
                                if (((string)i.CommandParameter) == filename) {
                                    alreadyInMenu = true;
                                    break;
                                }
                            }
                            if (!alreadyInMenu) {
                                RibbonApplicationSplitMenuItem i = new RibbonApplicationSplitMenuItem();
                                string header = filename.Substring(filename.LastIndexOf('\\') + 1);
                                i.Header = header.Substring(0, header.LastIndexOf('.'));
                                i.Click += AddGroupFromRibbonMenu;
                                i.CommandParameter = filename;
                                groupDropDown.Items.Add(i);

                            }

                        }
                    } catch (Exception ex) {
                        MessageBox.Show(Properties.Resources.StoreModelOnAREError, Properties.Resources.GroupStoreErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                        traceSource.TraceEvent(TraceEventType.Error, 3, ex.Message);
                    }
                }
            } else {
                MessageBox.Show(Properties.Resources.GroupStoreNoGroupSelected, Properties.Resources.GroupStoreErrorHeader, MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Example #2
0
        /// <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;
        }
Example #3
0
 /// <summary>
 /// Returns the source component of the given eventchannel
 /// </summary>
 /// <param name="ec">Eventchannel of which the source should be returned</param>
 /// <returns>Source of the given eventchannel</returns>
 private componentType GetEventChannelSource(eventChannel ec)
 {
     foreach (componentType ct in deploymentComponentList.Values)
         if (ct.id.Equals(ec.sources.source.component.id))
             return ct;
     return null;
 }
Example #4
0
 /// <summary>
 /// Returns the target component of the given eventchannel
 /// </summary>
 /// <param name="ec">Eventchannel of which the target should be returned</param>
 /// <returns>Target of the given eventchannel</returns>
 private componentType GetEventChannelTarget(eventChannel ec)
 {
     foreach (componentType ct in deploymentComponentList.Values)
         if (ct.id.Equals(ec.targets.target.component.id))
             return ct;
     return null;
 }
Example #5
0
 /// <summary>
 /// Check if the source of the eventchannel exists
 /// </summary>
 /// <param name="ecl">eventchannel to check</param>
 /// <returns>true if the source of the given eventchannel exists, false otherise</returns>
 private bool EventChannelListenerExists(eventChannel ecl)
 {
     return deploymentComponentList.ContainsKey(ecl.targets.target.component.id);
 }
Example #6
0
 /// <summary>
 /// Check if the target of the eventchannel exists
 /// </summary>
 /// <param name="ecl">eventchannel to check</param>
 /// <returns>true if the target of the given eventchannel exists, false otherise</returns>
 private bool EventChannelTriggerExists(eventChannel ecl)
 {
     return deploymentComponentList.ContainsKey(ecl.sources.source.component.id);
 }
Example #7
0
 /// <summary>
 /// Check if the given eventchannel has a group as target
 /// </summary>
 /// <param name="ec">eventchannel for which the existence of a group target should get checked</param>
 /// <returns>true if the target of the given eventchannel is a group, false otherwise</returns>
 private bool EventChannelLineHasGroupSource(eventChannel ecl)
 {
     foreach (groupComponent gc in groupsList.Values) {
         if (gc.ID.Equals(ecl.sources.source.component.id))
             return true;
     }
     return false;
 }
Example #8
0
 /// <summary>
 /// Check if the given eventchannel has a group as target
 /// </summary>
 /// <param name="ec">eventchannel for which the existence of a group target should get checked</param>
 /// <returns>true if the target of the given eventchannel is a group, false otherwise</returns>
 private bool EventChannelLineHasGroupTarget(eventChannel ecl)
 {
     foreach (groupComponent gc in groupsList.Values) {
         if (gc.ID.Equals(ecl.targets.target.component.id))
             return true;
     }
     return false;
 }
Example #9
0
        /// <summary>
        /// Whenever eventchannels are connected to groups, new eventchannels have to be added to the model
        /// to all components which correspond to that new eventchannel
        /// 
        /// Case 1:
        ///   Channel between Group (source) and Component (target):
        ///     --> a new channel has to be added to the groups source component and the target component.
        /// Case 2:
        ///   Channel between Component (source) and Group (target):
        ///     --> a new channel has to be added to the source and the groups source component.
        /// Case 3:
        ///   Channel between Group1 (source) and Group2 (source):
        ///     --> a new channel has to be added to the group1 original source and group2
        ///     --> a new channel has to be added to the group1 and the group2 original source
        ///     --> a new channel has to be added to the group1 original source and group2 original source
        /// </summary>
        private void AddMissingEventChannels()
        {
            ArrayList eventChannelsToAdd = new ArrayList();
            foreach (eventChannel ec in eventChannelList) {
                componentType source = GetEventChannelSource(ec);
                componentType target = GetEventChannelTarget(ec);
                // check normal case
                if (!eventChannelLineExists(target.id, source.id)) {

                    if (source.ComponentCanvas.Visibility == System.Windows.Visibility.Visible &&
                        target.ComponentCanvas.Visibility == System.Windows.Visibility.Visible) {
                        eventChannelLine groupEC = new eventChannelLine();
                        Canvas.SetZIndex(groupEC.Line, -1001);

                        groupEC.Line.X1 = Canvas.GetLeft(source.ComponentCanvas) + source.ComponentCanvas.Width / 2 + 18;
                        groupEC.Line.Y1 = Canvas.GetTop(source.ComponentCanvas) + +source.ComponentCanvas.Height - 4;

                        groupEC.Line.X2 = Canvas.GetLeft(target.ComponentCanvas) + target.ComponentCanvas.Width / 2 - 18;
                        groupEC.Line.Y2 = Canvas.GetTop(target.ComponentCanvas) + +target.ComponentCanvas.Height - 4;

                        groupEC.TriggerComponentId = source.id;
                        groupEC.ListenerComponentId = target.id;
                        groupEC.HasGroupSource = EventChannelLineHasGroupSource(ec);
                        groupEC.HasGroupTarget = EventChannelLineHasGroupTarget(ec);
                        AddEventChannelCommand(groupEC, false);
                        canvas.Children.Add(groupEC.Line);
                    }
                }
                // check if the source is within a group which needs an eventchannel
                groupComponent sourceGroup = GetParentGroup(source);
                if (sourceGroup != null) {

                    componentType groupComp = deploymentComponentList[sourceGroup.ID];
                    if (target.ComponentCanvas.Visibility == System.Windows.Visibility.Visible &&
                        groupComp.ComponentCanvas.Visibility == System.Windows.Visibility.Visible) {
                        if (!eventChannelLineExists(target.id, sourceGroup.ID)) {
                            eventChannelLine groupEC = new eventChannelLine();
                            Canvas.SetZIndex(groupEC.Line, -1001);

                            groupEC.Line.X1 = Canvas.GetLeft(groupComp.ComponentCanvas) + groupComp.ComponentCanvas.Width / 2 + 18;
                            groupEC.Line.Y1 = Canvas.GetTop(groupComp.ComponentCanvas) + +groupComp.ComponentCanvas.Height - 4;

                            groupEC.Line.X2 = Canvas.GetLeft(target.ComponentCanvas) + target.ComponentCanvas.Width / 2 - 18;
                            groupEC.Line.Y2 = Canvas.GetTop(target.ComponentCanvas) + target.ComponentCanvas.Height - 4;

                            groupEC.TriggerComponentId = sourceGroup.ID;
                            groupEC.ListenerComponentId = target.id;
                            groupEC.HasGroupSource = EventChannelLineHasGroupSource(ec);
                            groupEC.HasGroupTarget = EventChannelLineHasGroupTarget(ec);
                            AddEventChannelCommand(groupEC, false);
                            canvas.Children.Add(groupEC.Line);
                        }

                        if (!eventChannelExists(target.id, ec.targets.target.eventPort.id, groupComp.id, ec.sources.source.component.id + "_" + ec.sources.source.eventPort.id)) {
                            eventChannel tmpEC = new eventChannel();

                            tmpEC.sources.source.component.id = groupComp.id;
                            tmpEC.sources.source.eventPort.id = ec.sources.source.component.id + "_" + ec.sources.source.eventPort.id;

                            tmpEC.targets.target.component.id = target.id;
                            tmpEC.targets.target.eventPort.id = ec.targets.target.eventPort.id;

                            tmpEC.id = groupComp.id + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id;
                            tmpEC.GroupOriginalSource = ec.sources.source;
                            eventChannelsToAdd.Add(tmpEC);
                        }
                    }
                }
                // check if the target is within a group which needs an eventchannel
                groupComponent targetGroup = GetParentGroup(target);
                if (targetGroup != null) {
                    componentType groupComp = deploymentComponentList[targetGroup.ID];
                    if (source.ComponentCanvas.Visibility == System.Windows.Visibility.Visible &&
                        groupComp.ComponentCanvas.Visibility == System.Windows.Visibility.Visible) {
                        if (!eventChannelLineExists(targetGroup.ID, source.id)) {
                            eventChannelLine groupEC = new eventChannelLine();
                            Canvas.SetZIndex(groupEC.Line, -1001);

                            groupEC.Line.X2 = Canvas.GetLeft(groupComp.ComponentCanvas) + groupComp.ComponentCanvas.Width / 2 - 18;
                            groupEC.Line.Y2 = Canvas.GetTop(groupComp.ComponentCanvas) + +groupComp.ComponentCanvas.Height - 4;

                            groupEC.Line.X1 = Canvas.GetLeft(source.ComponentCanvas) + source.ComponentCanvas.Width / 2 + 18;
                            groupEC.Line.Y1 = Canvas.GetTop(source.ComponentCanvas) + source.ComponentCanvas.Height - 4;

                            groupEC.TriggerComponentId = source.id;
                            groupEC.ListenerComponentId = targetGroup.ID;
                            groupEC.HasGroupSource = EventChannelLineHasGroupSource(ec);
                            groupEC.HasGroupTarget = EventChannelLineHasGroupTarget(ec);
                            AddEventChannelCommand(groupEC, false);
                            canvas.Children.Add(groupEC.Line);
                        }
                        if (!eventChannelExists(target.id, ec.targets.target.eventPort.id, groupComp.id, ec.sources.source.component.id + "_" + ec.sources.source.eventPort.id)) {
                            eventChannel tmpEC = new eventChannel();

                            tmpEC.sources.source.component.id = source.id;
                            tmpEC.sources.source.eventPort.id = ec.sources.source.eventPort.id;
                            //tmpEC.sources.source.eventPort.id = ec.sources.source.component.id + "_" + ec.sources.source.eventPort.id;

                            tmpEC.targets.target.component.id = targetGroup.ID;
                            tmpEC.targets.target.eventPort.id = ec.targets.target.component.id + "_" + ec.targets.target.eventPort.id;

                            tmpEC.id = groupComp.id + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id;
                            tmpEC.GroupOriginalTarget = ec.targets.target;
                            tmpEC.GroupOriginalSource = ec.GroupOriginalSource;
                            eventChannelsToAdd.Add(tmpEC);
                        }
                    }
                }
            }
            foreach (eventChannel ec in eventChannelsToAdd) {
                eventChannelList.Add(ec);
            }
        }
Example #10
0
        /// <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);
                }
            }
        }
Example #11
0
        /// <summary>
        /// Listener for the componentComboBox in the property dock. This compobox is available, when the
        /// ACS is in 'run'-status
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void ComponentsComboBox_SelectionChanged(object sender, EventArgs e) {
        //    ComboBoxItem cbi = (ComboBoxItem)componentsComboBox.SelectedItem;
        //    if (cbi != null) {
        //        SetPropertyDock(deploymentComponentList[cbi.Content.ToString()]);
        //        focusedComponent = deploymentComponentList[cbi.Content.ToString()];
        //    }
        //}
        /// <summary>
        /// Listener for the componentComboBox in the event dock. Will set events delete or add lines in the event dock
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EventCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox cb = (ComboBox)sender;
            // original code, without tooltips
            // String selection = cb.SelectedItem.ToString();

            // new code, with tooltips
            String selection = ((ComboBoxItem)cb.SelectedItem).Content.ToString();
            cb.ToolTip = ((ComboBoxItem)cb.SelectedItem).ToolTip;

            int key = int.Parse(cb.Name.Replace("eventCombobox", ""));

            if (areStatus.Status.Equals(AREStatus.ConnectionStatus.Synchronised)) {
                areStatus.Status = AREStatus.ConnectionStatus.Connected;
            }
            modelHasBeenEdited = true;

            // Add a new line into the grid:
            if (!selection.Equals("---")) {
                bool duplicated = false;
                // check, if a triggerable event is once or several times in the list
                // only, if the successor is different to the selected event, a new line should be added
                foreach (UIElement element in dockEventGrid.Children) {
                    if ((Grid.GetRow(element) == Grid.GetRow(cb) + 1) && (element is ComboBox)) {
                        if (cb.Name == ((ComboBox)element).Name) {
                            duplicated = true;
                            break;
                        }
                    }
                }

                if (!duplicated) {
                    TextBox l = new TextBox() {
                        Text = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId,
                        Margin = new Thickness(0, 0, 0, 0),
                        FontSize = 12,
                        FontFamily = new FontFamily("Segoe UI"),
                        IsReadOnly = true,
                        ToolTip = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventDescription
                    };
                    dockEventGrid.RowDefinitions.Insert(Grid.GetRow(cb) + 1, new RowDefinition() {
                        // Height = (GridLength)glc.ConvertFromString("22")
                    });
                    foreach (UIElement element in dockEventGrid.Children) {
                        if (Grid.GetRow(element) > Grid.GetRow(cb)) {
                            Grid.SetRow(element, Grid.GetRow(element) + 1);
                        }
                    }
                    ComboBox eventCombobox = new ComboBox();
                    eventCombobox.Name = "eventCombobox" + key;

                    eventCombobox.Items.Add(new ComboBoxItem() {
                        Content = "---"
                    });

                    foreach (EventTriggerPort eventTrigger in deploymentComponentList[focusedEventChannel.TriggerComponentId].EventTriggerList) {
                        // Uncomment, to enable tooltips for the combobox-elements.
                        ComboBoxItem cbi = new ComboBoxItem();
                        cbi.Content = eventTrigger.EventTriggerId;
                        cbi.ToolTip = eventTrigger.EventDescription;
                        eventCombobox.Items.Add(cbi);

                    }

                    eventCombobox.SelectedItem = eventCombobox.Items[0];

                    eventCombobox.SelectionChanged += EventCombobox_SelectionChanged;

                    Grid.SetRow(l, Grid.GetRow(cb) + 1);
                    Grid.SetColumn(l, 0);
                    Grid.SetRow(eventCombobox, Grid.GetRow(cb) + 1);
                    Grid.SetColumn(eventCombobox, 1);
                    GridSplitter mySimpleGridSplitter = new GridSplitter();
                    mySimpleGridSplitter.Background = Brushes.DarkGray;
                    mySimpleGridSplitter.HorizontalAlignment = HorizontalAlignment.Right;
                    mySimpleGridSplitter.VerticalAlignment = VerticalAlignment.Stretch;
                    mySimpleGridSplitter.Width = 1;
                    Grid.SetColumn(mySimpleGridSplitter, 0);
                    Grid.SetRow(mySimpleGridSplitter, Grid.GetRow(cb) + 1);
                    dockEventGrid.Children.Add(l);
                    dockEventGrid.Children.Add(eventCombobox);
                    dockEventGrid.Children.Add(mySimpleGridSplitter);

                    Border top = new Border();
                    Grid.SetColumn(top, 0);
                    Grid.SetRow(top, Grid.GetRow(cb) + 1);
                    Grid.SetColumnSpan(top, 2);
                    top.BorderBrush = Brushes.DarkGray;
                    top.BorderThickness = new Thickness(1);
                    dockEventGrid.Children.Add(top);
                }

                if (((ComboBoxItem)e.RemovedItems[e.RemovedItems.Count - 1]).Content.Equals("---")) {
                    // write data to deployment model
                    eventChannel addEventChannel = new eventChannel();

                    addEventChannel.sources.source.component.id = focusedEventChannel.TriggerComponentId;
                    addEventChannel.sources.source.eventPort.id = selection;
                    addEventChannel.targets.target.component.id = focusedEventChannel.ListenerComponentId;
                    addEventChannel.targets.target.eventPort.id = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId;
                    addEventChannel.id = addEventChannel.sources.source.eventPort.id + "_" + addEventChannel.targets.target.eventPort.id;

                    if (EventChannelHasGroupSource(addEventChannel)) {
                        eventEdge ee = new eventEdge();
                        componentType source = GetComponentTypeFromEventString(selection);
                        ee.component.id = source.id;
                        ee.eventPort.id = selection.Substring(source.id.Length + 1);
                        addEventChannel.GroupOriginalSource = ee;

                        // new for bugfixing 29.01.2013
                        focusedEventChannel.HasGroupSource = true;
                    }
                    if (EventChannelHasGroupTarget(addEventChannel)) {
                        eventEdge ee = new eventEdge();
                        string targetEventString = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId;
                        componentType target = GetComponentTypeFromEventString(targetEventString);
                        ee.component.id = target.id;
                        ee.eventPort.id = targetEventString.Substring(target.id.Length + 1);
                        addEventChannel.GroupOriginalTarget = ee;

                        // new for bugfixing 29.01.2013
                        focusedEventChannel.HasGroupTarget = true;
                    }

                    eventChannelList.Add(addEventChannel);
                    deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));

                    // check if the eventchannel was added to a group
                    // if this is the case the eventchannel has to be added also to the original source and target

                    if (focusedEventChannel.HasGroupTarget && focusedEventChannel.HasGroupSource) {
                        EventListenerPort elp = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]);
                        componentType target = GetComponentTypeFromEventString(elp.EventListenerId);
                        componentType source = GetComponentTypeFromEventString(selection);

                        eventChannel baseEventChannel = new eventChannel();
                        baseEventChannel.sources.source.component.id = source.id;
                        baseEventChannel.sources.source.eventPort.id = selection.Substring(source.id.Length + 1);
                        baseEventChannel.targets.target.component.id = target.id;
                        baseEventChannel.targets.target.eventPort.id = elp.EventListenerId.Substring(target.id.Length + 1);
                        baseEventChannel.id = baseEventChannel.sources.source.eventPort.id + "_" + baseEventChannel.targets.target.eventPort.id;

                        eventChannelList.Add(baseEventChannel);

                        baseEventChannel = new eventChannel();
                        baseEventChannel.sources.source.component.id = focusedEventChannel.TriggerComponentId;
                        baseEventChannel.sources.source.eventPort.id = selection;
                        baseEventChannel.targets.target.component.id = target.id;
                        baseEventChannel.targets.target.eventPort.id = elp.EventListenerId.Substring(target.id.Length + 1);
                        baseEventChannel.id = baseEventChannel.sources.source.eventPort.id + "_" + baseEventChannel.targets.target.eventPort.id;

                        eventChannelList.Add(baseEventChannel);

                        baseEventChannel = new eventChannel();
                        baseEventChannel.sources.source.component.id = source.id;
                        baseEventChannel.sources.source.eventPort.id = selection.Substring(source.id.Length + 1);
                        baseEventChannel.targets.target.component.id = focusedEventChannel.ListenerComponentId;
                        baseEventChannel.targets.target.eventPort.id = elp.EventListenerId;
                        baseEventChannel.id = baseEventChannel.sources.source.eventPort.id + "_" + baseEventChannel.targets.target.eventPort.id;

                        eventChannelList.Add(baseEventChannel);

                        deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
                    }
                    else if (focusedEventChannel.HasGroupTarget && !focusedEventChannel.HasGroupSource) {
                        EventListenerPort elp = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]);
                        componentType target = GetComponentTypeFromEventString(elp.EventListenerId);

                        eventChannel baseEventChannel = new eventChannel();
                        baseEventChannel.sources.source.component.id = focusedEventChannel.TriggerComponentId;
                        baseEventChannel.sources.source.eventPort.id = selection;
                        baseEventChannel.targets.target.component.id = target.id;
                        baseEventChannel.targets.target.eventPort.id = elp.EventListenerId.Substring(target.id.Length + 1);
                        baseEventChannel.id = baseEventChannel.sources.source.eventPort.id + "_" + baseEventChannel.targets.target.eventPort.id;

                        eventChannelList.Add(baseEventChannel);
                        deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
                    }
                    else if (focusedEventChannel.HasGroupSource && !focusedEventChannel.HasGroupTarget) {
                        componentType source = GetComponentTypeFromEventString(selection);
                        EventListenerPort elp = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]);

                        eventChannel baseEventChannel = new eventChannel();
                        baseEventChannel.sources.source.component.id = source.id;
                        baseEventChannel.sources.source.eventPort.id = selection.Substring(source.id.Length + 1);
                        baseEventChannel.targets.target.component.id = focusedEventChannel.ListenerComponentId;
                        baseEventChannel.targets.target.eventPort.id = elp.EventListenerId;
                        baseEventChannel.id = baseEventChannel.sources.source.eventPort.id + "_" + baseEventChannel.targets.target.eventPort.id;

                        eventChannelList.Add(baseEventChannel);
                        deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
                    }
                }
                else {
                    // update data of an existing event
                    eventChannel updateEventChannel = new eventChannel();
                    updateEventChannel.sources.source.component.id = focusedEventChannel.TriggerComponentId;

                    updateEventChannel.sources.source.eventPort.id = (string)((ComboBoxItem)e.RemovedItems[e.RemovedItems.Count - 1]).Content;

                    updateEventChannel.targets.target.component.id = focusedEventChannel.ListenerComponentId;
                    updateEventChannel.targets.target.eventPort.id = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId;
                    foreach (eventChannel updateEvent in eventChannelList) {
                        if ((updateEvent.sources.source.component.id == updateEventChannel.sources.source.component.id) &&
                            (updateEvent.sources.source.eventPort.id == updateEventChannel.sources.source.eventPort.id) &&
                            (updateEvent.targets.target.component.id == updateEventChannel.targets.target.component.id) &&
                            (updateEvent.targets.target.eventPort.id == updateEventChannel.targets.target.eventPort.id)) {
                            updateEvent.sources.source.eventPort.id = selection;
                            //deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
                            break;
                        }
                    }
                }

            }
            else {
                // remove a line
                ArrayList elements = new ArrayList();
                foreach (UIElement element in dockEventGrid.Children) {
                    if (element is TextBox) {
                        if (!elements.Contains(((TextBox)element).Text)) {
                            elements.Add(((TextBox)element).Text);
                        }
                        else if ((((TextBox)element).Text == ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId) &&
                          (Grid.GetRow(element) == Grid.GetRow(cb) + 1)) {
                            // remove one row
                            dockEventGrid.Children.Remove(element);
                            dockEventGrid.Children.Remove(cb);

                            // move the other elements one line up
                            foreach (UIElement element2 in dockEventGrid.Children) {
                                if (Grid.GetRow(element2) > Grid.GetRow(cb)) {
                                    Grid.SetRow(element2, Grid.GetRow(element2) - 1);
                                }
                            }

                            dockEventGrid.RowDefinitions.RemoveAt(dockEventGrid.RowDefinitions.Count - 1);
                            break;
                        }
                    }
                }
                // remove event from deployment model
                eventChannel deleteEventChannel = new eventChannel();
                deleteEventChannel.sources.source.component.id = focusedEventChannel.TriggerComponentId;

                deleteEventChannel.sources.source.eventPort.id = (string)((ComboBoxItem)e.RemovedItems[e.RemovedItems.Count - 1]).Content;
                deleteEventChannel.targets.target.component.id = focusedEventChannel.ListenerComponentId;
                deleteEventChannel.targets.target.eventPort.id = ((EventListenerPort)deploymentComponentList[focusedEventChannel.ListenerComponentId].EventListenerList[key]).EventListenerId;
                ArrayList evChannelsToDelete = new ArrayList();

                foreach (eventChannel delEvent in eventChannelList) {
                    string source = deleteEventChannel.sources.source.component.id;
                    string sourceEvent = deleteEventChannel.sources.source.eventPort.id;
                    string target = deleteEventChannel.targets.target.component.id;
                    string targetEvent = deleteEventChannel.targets.target.eventPort.id;

                    eventChannel targetChannel = null;

                    // delete the deselected eventChannel
                    if (delEvent.sources.source.component.id.Equals(source) &&
                        delEvent.sources.source.eventPort.id.Equals(sourceEvent) &&
                        delEvent.targets.target.component.id.Equals(target) &&
                        delEvent.targets.target.eventPort.id.Equals(targetEvent))
                        targetChannel = delEvent;
                    if (targetChannel == null)
                        continue;

                    evChannelsToDelete.Add(targetChannel);

                    string source1 = null;
                    string sourceEvent1 = null;
                    string target1 = null;
                    string targetEvent1 = null;

                    if (targetChannel.GroupOriginalSource != null) {
                        source1 = targetChannel.GroupOriginalSource.component.id;
                        sourceEvent1 = targetChannel.GroupOriginalSource.eventPort.id;
                    }
                    if (targetChannel.GroupOriginalTarget != null) {
                        target1 = targetChannel.GroupOriginalTarget.component.id;
                        targetEvent1 = targetChannel.GroupOriginalTarget.eventPort.id;
                    }

                    if (source1 != null && sourceEvent1 != null) {
                        // Delete eventchannels with sourc1 && source1event && target && targetEvent
                        foreach (eventChannel delEvent1 in eventChannelList) {
                            if (delEvent1.sources.source.component.id.Equals(source1) &&
                            delEvent1.sources.source.eventPort.id.Equals(sourceEvent1) &&
                            delEvent1.targets.target.component.id.Equals(target) &&
                            delEvent1.targets.target.eventPort.id.Equals(targetEvent))
                                evChannelsToDelete.Add(delEvent1);
                        }
                    }
                    if (target1 != null && targetEvent1 != null) {
                        // Delete eventchannels with target1 && targetEvent1 && source && sourceEvent
                        foreach (eventChannel delEvent1 in eventChannelList) {
                            if (delEvent1.sources.source.component.id.Equals(source) &&
                            delEvent1.sources.source.eventPort.id.Equals(sourceEvent) &&
                            delEvent1.targets.target.component.id.Equals(target1) &&
                            delEvent1.targets.target.eventPort.id.Equals(targetEvent1))
                                evChannelsToDelete.Add(delEvent1);
                        }
                    }
                    if (source1 != null && sourceEvent1 != null && target1 != null && targetEvent1 != null) {
                        // delete eventchannels with source1 && sourceEvent1 && target1 && targetEvent1
                        foreach (eventChannel delEvent1 in eventChannelList) {
                            if (delEvent1.sources.source.component.id.Equals(source1) &&
                            delEvent1.sources.source.eventPort.id.Equals(sourceEvent1) &&
                            delEvent1.targets.target.component.id.Equals(target1) &&
                            delEvent1.targets.target.eventPort.id.Equals(targetEvent1))
                                evChannelsToDelete.Add(delEvent1);
                        }
                    }
                }
                foreach (eventChannel ec in evChannelsToDelete)
                    eventChannelList.Remove(ec);
                deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
            }
        }
Example #12
0
        /// <summary>
        /// Copy selected Items into the copyModel
        /// </summary>
        private void CopySelectedCommand()
        {
            copyOffsetMulti = 1;
            copyModel = new model();
            copyModel.modelName = "copy";
            // insert all selected components to the model
            LinkedList<componentType> t = new LinkedList<componentType>();
            for (int i = 0; i < selectedComponentList.Count; i++) {
                componentType ct = selectedComponentList.ElementAt(i);
                if (!((Asterics.ACS2.componentTypesComponentType)componentList[ct.type_id]).singleton) {
                    t.AddLast(ct);
                }
                else {
                    //if (ct.ComponentCanvas.Visibility == System.Windows.Visibility.Visible)
                        MessageBox.Show(Properties.Resources.SingletonErrorHeaderFormat(ct.type_id), Properties.Resources.SingletonErrorDialogHeader, MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            copyModel.components = t.ToArray();
            //get all selected channels where the source and target components
            //are selected
            LinkedList<channel> copyChannels = new LinkedList<channel>();
            foreach (channel c in selectedChannelList) {
                bool sourceFound, targetFound;
                sourceFound = targetFound = false;
                foreach (componentType mc in copyModel.components) {
                    if (mc.ComponentType == ACS2.componentTypeDataTypes.group)
                        continue;
                    if (mc.id == c.source.component.id)
                        sourceFound = true;
                    if (mc.id == c.target.component.id)
                        targetFound = true;
                    if (sourceFound && targetFound) {
                        break;
                    }
                }
                if (sourceFound && targetFound)
                    copyChannels.AddLast(c);
            }
            copyModel.channels = new channel[copyChannels.Count];
            for (int i = 0; i < copyChannels.Count; i++)
                copyModel.channels[i] = copyChannels.ElementAt(i);

            // get all selected Eventchannels
            LinkedList<eventChannel> selEventChannels = new LinkedList<eventChannel>();
            foreach (eventChannelLine ecl in selectedEventChannelList) {
                //bool eventfound = false;
                foreach (eventChannel ech in eventChannelList) {
                    if (ecl.ListenerComponentId == ech.targets.target.component.id &&
                        ecl.TriggerComponentId == ech.sources.source.component.id) {
                        selEventChannels.AddLast(ech);

                    }
                }
            }
            LinkedList<eventChannel> copyEventChannels = new LinkedList<eventChannel>();
            // get all selected eventchannels with a selected source and target
            foreach (eventChannel ech in selEventChannels) {
                bool sourceFound, targetFound;
                sourceFound = targetFound = false;
                foreach (componentType mc in copyModel.components) {
                    if (mc.id == ech.sources.source.component.id) {
                        if (mc.ComponentType != ACS2.componentTypeDataTypes.group)
                            sourceFound = true;
                    }
                    else if (mc.id == ech.targets.target.component.id) {
                        if (mc.ComponentType != ACS2.componentTypeDataTypes.group)
                            targetFound = true;
                    }
                    if (sourceFound && targetFound)
                        break;
                }
                if (sourceFound && targetFound)
                    copyEventChannels.AddLast(ech);
            }

            /*
             * Check all groups if they have docked EventListeners and EventTriggers
             * and add dummy lines to the model to retain these eventports in the pasted
             * model
             *
             */
            copyGroupEventChannels = new ArrayList();
            foreach (componentType ct in copyModel.components) {
                if (ct.ComponentType != ACS2.componentTypeDataTypes.group)
                    continue;
                ArrayList echannels = new ArrayList();
                foreach (EventListenerPort elp in ct.EventListenerList) {
                    componentType target = null;
                    foreach (componentType tmpct in copyModel.components) {
                        if (elp.EventListenerId.StartsWith(tmpct.id)) {
                            if (target == null) {
                                target = tmpct;
                            } else if (tmpct.id.Length > target.id.Length)
                                target = tmpct;
                        }
                    }
                    if (target == null)
                        continue;
                    eventChannel tmpEC = new eventChannel();
                    tmpEC.sources.source.component.id = copyDummyName;
                    tmpEC.sources.source.eventPort.id = "eventtrigger";
                    tmpEC.targets.target.component.id = target.id;
                    tmpEC.targets.target.eventPort.id = elp.EventListenerId.Substring(target.id.Length+1);
                    tmpEC.id = target.id + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id;
                    tmpEC.GroupOriginalSource = null;
                    tmpEC.GroupOriginalTarget = null;

                    bool found = false;
                    foreach (eventChannel ech in copyEventChannels) {
                        if (ech.sources.source.component.id.Equals(copyDummyName) &&
                            ech.targets.target.component.id.Equals(target.id)) {
                                found = true;
                                break;
                        }
                    }
                    if (!found)
                        echannels.Add(tmpEC);
                }

                foreach (EventTriggerPort etp in ct.EventTriggerList) {
                    componentType source = null;
                    foreach (componentType tmpct in copyModel.components) {
                        if (etp.EventTriggerId.StartsWith(tmpct.id)) {
                            if (source == null) {
                                source = tmpct;
                            }
                            else if (tmpct.id.Length > source.id.Length)
                                source = tmpct;
                        }
                    }
                    if (source == null)
                        continue;
                    eventChannel tmpEC = new eventChannel();
                    tmpEC.sources.source.component.id = source.id;
                    tmpEC.sources.source.eventPort.id = etp.EventTriggerId.Substring(source.id.Length + 1);
                    tmpEC.targets.target.component.id = copyDummyName;
                    tmpEC.targets.target.eventPort.id = "eventlistener";
                    tmpEC.id = source.id + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id;
                    tmpEC.GroupOriginalSource = null;
                    tmpEC.GroupOriginalTarget = null;

                    bool found = false;
                    foreach (eventChannel ech in copyEventChannels) {
                        if (ech.sources.source.component.id.Equals(copyDummyName) &&
                            ech.targets.target.component.id.Equals(source.id)) {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                        echannels.Add(tmpEC);
                }

                copyGroupEventChannels.Add(echannels);
            }

            copyModel.eventChannels = copyEventChannels.ToArray();
            copyModel = CopyModel(copyModel);
        }
Example #13
0
        /// <summary>
        /// Add a new event channel between two components. No events are established between the components at this moment
        /// </summary>
        /// <param name="addEventChannel">The new event channel</param>
        /// <param name="showDialog">Switch, to deactivate the "Connect Events" dialog</param>
        private void AddEventChannelCommand(eventChannelLine addEventChannel, bool showDialog)
        {
            addEventChannel.Line.Focusable = true;
            KeyboardNavigation.SetTabIndex(addEventChannel.Line, canvas.Children.Count + 1);
            addEventChannel.Line.GotKeyboardFocus += EventChannel_GotKeyboardFocus;
            addEventChannel.Line.LostKeyboardFocus += EventChannel_LostKeyboardFocus;
            addEventChannel.Line.KeyDown += EventChannel_KeyDown;
            addEventChannel.Line.ContextMenu = eventChannelContextMenu;
            Canvas.SetZIndex(addEventChannel.Line, Canvas.GetZIndex(addEventChannel.Line) + 2000);
            eventChannelLinesList.Add(addEventChannel);

            if (showEventChannelConnectMessage && showDialog) {
                CustomMessageBox messageBox = new CustomMessageBox(Properties.Resources.AddEventChannelInfo, Properties.Resources.AddEventChannelInfoHeader, CustomMessageBox.messageType.Info, CustomMessageBox.resultType.OK);
                messageBox.Owner = this;
                messageBox.showCheckbox.IsChecked = showEventChannelConnectMessage;
                messageBox.ShowDialog();

                showEventChannelConnectMessage = (bool)messageBox.showCheckbox.IsChecked;
                if (showEventChannelConnectMessage) {
                    ini.IniWriteValue("Options", "showEventChannelConnectMessage", "true");
                }
                else {
                    ini.IniWriteValue("Options", "showEventChannelConnectMessage", "false");
                }
            }
            //MessageBox.Show(Properties.Resources.AddEventChannelInfo, Properties.Resources.AddEventChannelInfoHeader, MessageBoxButton.OK, MessageBoxImage.Information);
            if (deploymentComponentList.ContainsKey(addEventChannel.TriggerComponentId) && deploymentComponentList.ContainsKey(addEventChannel.ListenerComponentId)) {
                SetEventPropertyDock(deploymentComponentList[addEventChannel.TriggerComponentId], deploymentComponentList[addEventChannel.ListenerComponentId]);
            }
            focusedEventChannel = addEventChannel;
            ClearSelectedEventChannelList();
            AddSelectedEventChannel(addEventChannel);
            eventChannel ec = new eventChannel();
            ec.sources.source.component.id = addEventChannel.TriggerComponentId;
            //canvas.Children.Add(addEventChannel.Line);
        }