Example #1
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);
                }
            }
        }
        /// <summary>
        /// Copy alle Components of the copyModel to the actual model
        /// </summary>
        private void PasteCopiedModel(model modelToPaste, bool namesAreValid, bool addToUndoStack)
        {
            CommandObject co = new CommandObject("Delete");
            if (modelToPaste == null)
                return;
            // loading the components
            /*
             *  Create a list of lists which contain all elements which should be within a group
             *  after the paste method finishes
             */
            ArrayList groupComps = new ArrayList();
            ArrayList groups = new ArrayList();
            ArrayList groupNames = new ArrayList();
            foreach (componentType ct in modelToPaste.components) {
                if (ct.ComponentType != ACS2.componentTypeDataTypes.group)
                    continue;
                groups.Add(ct);
                groupComponent gc = groupsList[ct.id];
                ArrayList groupElems = new ArrayList();
                foreach (componentType child in gc.AddedComponentList) {
                    foreach (componentType child1 in modelToPaste.components) {
                        if (child1.id.Equals(child.id)) {
                            groupElems.Add(child1);
                        }
                    }
                }
                if (groupElems.Count > 0) {
                    groupComps.Add(groupElems);
                    bool namevalid = namesAreValid;
                    int i = 1;
                    while (namevalid == false) {
                        string modelID = ct.id + "." + i;
                        if (!deploymentComponentList.ContainsKey(modelID)) {
                            namevalid = true;
                            groupNames.Add(modelID);
                        }
                        else
                            i++;
                    }
                }
            }

            // Rename components and update all channels
            Dictionary<string, string> changedComponents = new Dictionary<string, string>();
            foreach (object o in modelToPaste.components) {
                componentType modelComp = (componentType)o;
                if (modelComp.ComponentType == ACS2.componentTypeDataTypes.group)
                    continue;
                // change id
                bool namevalid = namesAreValid;
                int i = 1;
                while (namevalid == false) {
                    string modelID = modelComp.id + "." + i;
                    if (!deploymentComponentList.ContainsKey(modelID)) {
                        if (modelToPaste.channels != null) {
                            foreach (channel c in modelToPaste.channels) {
                                if (c.source.component.id == modelComp.id)
                                    c.source.component.id = modelID;
                                if (c.target.component.id == modelComp.id)
                                    c.target.component.id = modelID;
                            }
                        }
                        if (modelToPaste.eventChannels != null) {
                            foreach (eventChannel ec in modelToPaste.eventChannels) {
                                if (ec.sources.source.component.id == modelComp.id)
                                    ec.sources.source.component.id = modelID;
                                if (ec.targets.target.component.id == modelComp.id)
                                    ec.targets.target.component.id = modelID;
                            }
                        }
                        changedComponents.Add(modelComp.id,modelID);
                        modelComp.id = modelID;
                        namevalid = true;
                    }
                    else
                        i++;
                }
                // check, if bundle is available
                if (componentList.ContainsKey(modelComp.type_id)) {

                    // init the ArrayLists containing the ports. Used for easier and faster access
                    modelComp.InitArrayLists();

                    foreach (propertyType p in modelComp.properties) {
                        modelComp.PropertyArrayList.Add(p);
                    }

                    // copy the property datatype and description from bundle_description
                    // also copy the port datatypes form the bundle_description
                    // works only, if bundle and deployment fits to each other

                    try {
                        // search for bundle component
                        Asterics.ACS2.componentTypesComponentType bundleComponent = (Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id];

                        // copy the ComponentType of the component
                        modelComp.ComponentType = bundleComponent.type.Value;

                        if (modelComp.properties != null) {
                            foreach (propertyType deploymentProperty in modelComp.properties) {
                                int index = 0;
                                // searching for the right component property
                                while (deploymentProperty.name != bundleComponent.properties[index].name) {
                                    index++;
                                }
                                // copy the properties of the component
                                deploymentProperty.DataType = bundleComponent.properties[index].type;

                                // check, if the property is a dynamic property
                                if (bundleComponent.properties[index].getStringList) {
                                    deploymentProperty.GetStringList = true;
                                } else {
                                    deploymentProperty.GetStringList = false;
                                }

                                // check the value fitting to the datatype
                                if (!CheckPropertyDatatype(deploymentProperty.value, deploymentProperty.DataType)) {
                                    throw new LoadPropertiesException();
                                }

                                deploymentProperty.Description = bundleComponent.properties[index].description;
                                if (bundleComponent.properties[index].combobox != null) {
                                    deploymentProperty.ComboBoxStrings = bundleComponent.properties[index].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                }
                                deploymentProperty.PropertyChanged += ComponentPropertyChanged;
                                deploymentProperty.PropertyChangeError += ComponentPropertyChangeError;
                            }
                            // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                            if ((bundleComponent.properties == null) && (modelComp.properties.Length != 0)) {
                                throw new LoadPropertiesException();
                            }
                            else if ((bundleComponent.properties != null) && (modelComp.properties.Length != bundleComponent.properties.Length)) {
                                throw new LoadPropertiesException();
                            }
                        }

                        foreach (object portObj in modelComp.PortsList.Values) {
                            // searching for the inPorts
                            if (portObj is inputPortType) {
                                int index = 0;
                                inputPortType deploymentInPort = (inputPortType)portObj;
                                ArrayList helperListInPort = new ArrayList(); // a list with all InPorts of a component for the bundel_description
                                foreach (object bundleInPort in bundleComponent.ports) {
                                    if (bundleInPort is ACS2.inputPortType) {
                                        helperListInPort.Add(bundleInPort);
                                    }
                                }
                                while (deploymentInPort.portTypeID != ((ACS2.inputPortType)helperListInPort[index]).id) {
                                    index++; // searching for the right input port
                                }
                                // copy the dataType of the port
                                deploymentInPort.PortDataType = ((Asterics.ACS2.inputPortType)helperListInPort[index]).dataType;
                                deploymentInPort.MustBeConnected = ((Asterics.ACS2.inputPortType)helperListInPort[index]).mustBeConnected;
                                deploymentInPort.Description = ((Asterics.ACS2.inputPortType)helperListInPort[index]).description;
                                deploymentInPort.ComponentId = ((Asterics.ACS2.inputPortType)helperListInPort[index]).ComponentId;
                                deploymentInPort.ComponentTypeId = ((Asterics.ACS2.inputPortType)helperListInPort[index]).id;

                                // update the alias for group ports via property changed listener
                                deploymentInPort.PropertyChanged += InputPortIntPropertyChanged;

                                ACS2.propertyType[] sourceProperties = ((Asterics.ACS2.inputPortType)helperListInPort[index]).properties;
                                if ((sourceProperties != null) && (sourceProperties.Length > 0)) {
                                    //if (deploymentInPort.PropertyArrayList.Count > 0) {
                                    foreach (propertyType deploymentProperty in deploymentInPort.properties) {
                                        int inPortIndex = 0;
                                        while (deploymentProperty.name != sourceProperties[inPortIndex].name) {
                                            inPortIndex++;
                                        }
                                        // copy the properties of the inPort
                                        deploymentProperty.DataType = sourceProperties[inPortIndex].type;
                                        deploymentProperty.Description = sourceProperties[inPortIndex].description;
                                        if (sourceProperties[inPortIndex].combobox != null) {
                                            deploymentProperty.ComboBoxStrings = sourceProperties[inPortIndex].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                        }
                                        deploymentProperty.PropertyChanged += InPortPropertyChanged;
                                        deploymentProperty.PropertyChangeError += ComponentPropertyChangeError;
                                    }
                                    // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                                    if (deploymentInPort.properties.Length != sourceProperties.Length) {
                                        throw new Exception();
                                    }
                                }
                                deploymentInPort.properties = (propertyType[])deploymentInPort.PropertyArrayList.ToArray(typeof(propertyType));
                            }
                            else {
                                // comparing all outPports
                                int index = 0;
                                outputPortType outPort = (outputPortType)portObj;
                                ArrayList helperListOutPort = new ArrayList();
                                foreach (object origOutPort in bundleComponent.ports) {
                                    if (origOutPort is ACS2.outputPortType) {
                                        helperListOutPort.Add(origOutPort);
                                    }
                                }
                                while (outPort.portTypeID != ((Asterics.ACS2.outputPortType)helperListOutPort[index]).id) {
                                    index++;
                                }
                                // copy the dataType of the port
                                outPort.PortDataType = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).dataType;
                                outPort.Description = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).description;
                                outPort.ComponentId = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).ComponentId;
                                outPort.ComponentTypeId = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).id;

                                // update the alias for group ports via property changed listener
                                outPort.PropertyChanged += OutputPortIntPropertyChanged;

                                ACS2.propertyType[] sourceProperties = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).properties;
                                if ((sourceProperties != null) && (sourceProperties.Length > 0)) {
                                    //if (outPort.PropertyArrayList.Count > 0) {
                                    foreach (propertyType compProperty in outPort.properties) {
                                        int outPortIndex = 0;
                                        while (compProperty.name != sourceProperties[outPortIndex].name) {
                                            outPortIndex++;
                                        }
                                        // copy the properties of the outPort
                                        compProperty.DataType = sourceProperties[outPortIndex].type;
                                        compProperty.Description = sourceProperties[outPortIndex].description;
                                        if (sourceProperties[outPortIndex].combobox != null) {
                                            compProperty.ComboBoxStrings = sourceProperties[outPortIndex].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                        }
                                        compProperty.PropertyChanged += OutPortPropertyChanged;
                                        compProperty.PropertyChangeError += ComponentPropertyChangeError;
                                    }
                                    // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                                    if (outPort.properties.Length != sourceProperties.Length) {
                                        throw new Exception();
                                    }
                                }
                                outPort.properties = (propertyType[])outPort.PropertyArrayList.ToArray(typeof(propertyType));
                            }
                        }
                    }
                    catch (Exception ex) {
                        MessageBox.Show(Properties.Resources.CopyPropertiesErrorTextFormat(modelComp.id), Properties.Resources.CopyPropertiesErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                        traceSource.TraceEvent(TraceEventType.Error, 3, ex.Message);

                        //versionconflict
                        int posX;
                        int posY;
                        // set coordinates for the component in case there are not already set
                        if ((modelComp.layout.posX == null) || (modelComp.layout.posX == "") || (modelComp.layout.posY == null) || (modelComp.layout.posY == "")) {
                            posX = 40;
                            posY = 40;
                        }
                        else {
                            posX = Int32.Parse(modelComp.layout.posX);
                            posY = Int32.Parse(modelComp.layout.posY);
                        }

                        // backup component to load properties
                        componentType backupComp = modelComp;

                        modelComp = componentType.CopyFromBundleModel((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id], modelComp.id);
                        modelComp.layout.posX = Convert.ToString(posX);
                        modelComp.layout.posY = Convert.ToString(posY);
                        // HasVersionConflict indicates a version conflict between the component in a stored model and
                        // the component in the bundle descriptor
                        modelComp.HasVersionConflict = true;
                        modelComp.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                        //break;

                        // new code, copy property values from invalid (version conflict) component
                        foreach (propertyType deploymentProperty in modelComp.properties) {
                            foreach (propertyType backupProperty in backupComp.properties) {
                                if (deploymentProperty.name == backupProperty.name) {
                                    if (CheckPropertyDatatype(backupProperty.value, deploymentProperty.DataType)) {
                                        deploymentProperty.value = backupProperty.value; // try-parse is missing
                                    }
                                    break;
                                }
                            }
                        }

                    } // end of exception

                    // set coordinates for the component in case there are not already set
                    if ((modelComp.layout.posX == null) || (modelComp.layout.posX == "") || (modelComp.layout.posY == null) || (modelComp.layout.posY == "")) {
                        int[] pos = ProperComponentCoordinates(40, 40);
                        modelComp.layout.posX = Convert.ToString(pos[0]);
                        modelComp.layout.posY = Convert.ToString(pos[1]);
                    }

                    // Searching for the event triggers and event listeners of a component
                    Asterics.ACS2.componentTypesComponentType bundleComponentEvents = (Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id];
                    // If component has version conflict, the events are already set by 'CopyFromBundleModel'
                    if ((bundleComponentEvents.events != null) && (bundleComponentEvents.events != null) && !modelComp.HasVersionConflict) {
                        foreach (object eventO in bundleComponentEvents.events) {
                            if (eventO is ACS2.eventsTypeEventListenerPortType) {
                                ACS2.eventsTypeEventListenerPortType compEl = (ACS2.eventsTypeEventListenerPortType)eventO;
                                EventListenerPort el = new EventListenerPort();
                                el.EventListenerId = compEl.id;
                                el.ComponentId = modelComp.id;
                                el.EventDescription = compEl.description;
                                modelComp.EventListenerList.Add(el);
                            }
                            else if (eventO is ACS2.eventsTypeEventTriggererPortType) {
                                ACS2.eventsTypeEventTriggererPortType compEl = (ACS2.eventsTypeEventTriggererPortType)eventO;
                                EventTriggerPort el = new EventTriggerPort();
                                el.EventTriggerId = compEl.id;
                                el.ComponentId = modelComp.id;
                                el.EventDescription = compEl.description;
                                modelComp.EventTriggerList.Add(el);
                            }
                        }
                    }

                    // if the component has no version conflict, it will be pasted on the layout, otherwise, it is already on the
                    // canvas (done by 'CopyFromBundleModel')
                    if (!modelComp.HasVersionConflict) {
                        modelComp.InitGraphLayout(modelComp.id);
                    }
                    else {
                        //deploymentModel.components = deploymentComponentList.Values.ToArray();
                    }
                    canvas.Children.Add(modelComp.ComponentCanvas);
                    KeyboardNavigation.SetTabIndex(modelComp.ComponentCanvas, canvas.Children.Count + 1);

                    modelComp.Label.Text = modelComp.id;
                    double positionX = (Int32.Parse(modelComp.layout.posX) + copyXOffset * copyOffsetMulti);
                    if (positionX + modelComp.ComponentCanvas.Width > canvas.RenderSize.Width)
                        positionX = canvas.RenderSize.Width - modelComp.ComponentCanvas.Width;
                    double positionY = (Int32.Parse(modelComp.layout.posY) + copyYOffset * copyOffsetMulti);
                    if (positionY + modelComp.ComponentCanvas.Height > canvas.RenderSize.Height)
                        positionY = canvas.RenderSize.Height - modelComp.ComponentCanvas.Height;
                    modelComp.layout.posX = positionX.ToString();
                    modelComp.layout.posY = positionY.ToString();
                    deploymentComponentList.Add(modelComp.id, modelComp);
                    //componentList.Add(modelComp.id, modelComp);
                    // adding context menu
                    modelComp.MainRectangle.ContextMenu = componentContextMenu;
                    // adding keyboard focus listener
                    modelComp.ComponentCanvas.KeyDown += Component_KeyDown;
                    modelComp.ComponentCanvas.KeyUp += Component_KeyUp;
                    modelComp.ComponentCanvas.Focusable = true;
                    modelComp.ComponentCanvas.GotKeyboardFocus += ComponentCanvas_GotKeyboardFocus;
                    modelComp.ComponentCanvas.LostKeyboardFocus += ComponentCanvas_LostKeyboardFocus;

                    // adding property changed listener
                    modelComp.PropertyChanged += ComponentIntPropertyChanged;
                    modelComp.TopGrid.ContextMenu = componentContextMenu;
                    modelComp.TopRectangle.ContextMenu = componentContextMenu;
                    // set position of component on the canvas
                    Canvas.SetLeft(modelComp.ComponentCanvas, Int32.Parse(modelComp.layout.posX));
                    Canvas.SetTop(modelComp.ComponentCanvas, Int32.Parse(modelComp.layout.posY));

                    // Adapt the size of MainRectangle, if more then MAINRECTANGLENUMBEROFPORTS are in a component
                    int numInPorts = 0;
                    int numOutPorts = 0;
                    foreach (object objPort in modelComp.PortsList.Values) {
                        if (objPort is inputPortType) {
                            numInPorts++;
                        }
                        else {
                            numOutPorts++;
                        }
                    }
                    if (numOutPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                        modelComp.MainRectangle.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE);
                        modelComp.ComponentCanvas.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE);
                    }
                    else if (numInPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                        modelComp.MainRectangle.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
                        modelComp.ComponentCanvas.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
                    }
                    // Adapt the position of event trigger and event listener port, if the component has more input/output ports
                    if (modelComp.EventListenerList.Count > 0) {
                        Canvas.SetTop(modelComp.EventListenerPolygon.InputEventPortCanvas, modelComp.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
                    }
                    if (modelComp.EventTriggerList.Count > 0) {
                        Canvas.SetTop(modelComp.EventTriggerPolygon.OutputEventPortCanvas, modelComp.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
                    }

                }
                else {
                    MessageBox.Show(Properties.Resources.LoadComponentNotFoundFormat(modelComp.type_id), Properties.Resources.CopyPropertiesErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                }

                // check, if component has a gui component, and load the gui component
                if (modelComp.gui != null) {
                    AddGUIComponent(modelComp);
                }
            }
            deploymentModel.components = deploymentComponentList.Values.ToArray();

            // loading the channels
            if (modelToPaste.channels != null) {
                foreach (object o in modelToPaste.channels) {
                    channel modChannel = (channel)o;
                    // check versionconflict: add only channels to components without a conflict
                    if ((deploymentComponentList.ContainsKey(modChannel.source.component.id)) && (deploymentComponentList.ContainsKey(modChannel.target.component.id))) {

                        // one of the channels component has a conflict. Check, if port is available and datatype fits together
                        componentType tempCompOut = (componentType)deploymentComponentList[modChannel.source.component.id];
                        componentType tempCompIn = (componentType)deploymentComponentList[modChannel.target.component.id];
                        // try, if the ports are still available

                        if ((tempCompOut.PortsList.Contains(modChannel.source.port.id)) && (tempCompIn.PortsList.Contains(modChannel.target.port.id))) {
                            // check the datatypes of the ports, for the case, that they have been changed
                            //if (CheckInteroperabilityOfPorts(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortDataType, ((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortDataType)) {
                                modChannel.id = NewIdForChannel();
                                AddChannel(modChannel);
                                modChannel.Line.Y1 = Canvas.GetTop(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortRectangle) + Canvas.GetTop(tempCompOut.ComponentCanvas) + 5;
                                modChannel.Line.X1 = Canvas.GetLeft(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortRectangle) + Canvas.GetLeft(tempCompOut.ComponentCanvas) + 20;

                                modChannel.Line.Y2 = Canvas.GetTop(((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortRectangle) + Canvas.GetTop(tempCompIn.ComponentCanvas) + 5;
                                modChannel.Line.X2 = Canvas.GetLeft(((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortRectangle) + Canvas.GetLeft(tempCompIn.ComponentCanvas);
                                Canvas.SetZIndex(modChannel.Line, Canvas.GetZIndex(modChannel.Line) + 1000);
                            //}
                            //else {
                            //    // if no event listener Port can be found, the component has a version conflict
                            //    MessageBox.Show(Properties.Resources.CopyChannelsErrorTextFormat(tempCompOut.id, tempCompIn.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                            //    tempCompIn.ComponentCanvas.Background = new SolidColorBrush(Colors.Red);
                            //    tempCompIn.HasVersionConflict = true;
                            //    tempCompOut.ComponentCanvas.Background = new SolidColorBrush(Colors.Red);
                            //    tempCompOut.HasVersionConflict = true;
                            //}
                        }
                        else {
                            if (!tempCompOut.PortsList.Contains(modChannel.source.port.id)) {
                                MessageBox.Show(Properties.Resources.CopyChannelErrorNotFoundFormat(tempCompOut.id, tempCompIn.id, modChannel.source.port.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                tempCompOut.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompOut.HasVersionConflict = true;
                            }
                            else {
                                MessageBox.Show(Properties.Resources.CopyChannelErrorNotFoundFormat(tempCompOut.id, tempCompIn.id, modChannel.source.port.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                tempCompIn.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompIn.HasVersionConflict = true;
                            }
                        }

                    }
                }
            }
            // Loading the events and drawing the lines between the event ports
            if (modelToPaste.eventChannels != null) {
                bool foundLine = false;
                foreach (object o in modelToPaste.eventChannels) {
                    eventChannel evChannel = (eventChannel)o;
                    bool foundTriggerPort = false;
                    bool foundListenerPort = false;
                    try {
                        foreach (EventTriggerPort checkEvent in ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).EventTriggerList) {
                            if (checkEvent.ComponentId == evChannel.sources.source.component.id && checkEvent.EventTriggerId == evChannel.sources.source.eventPort.id) {
                                foundTriggerPort = true;
                                break;
                            }
                        }
                        if (foundTriggerPort) {
                            foreach (EventListenerPort checkEvent in ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).EventListenerList) {
                                if (checkEvent.ComponentId == evChannel.targets.target.component.id && checkEvent.EventListenerId == evChannel.targets.target.eventPort.id) {
                                    foundListenerPort = true;
                                    break;
                                }
                            }
                            if (foundListenerPort) {
                                foreach (eventChannelLine channelLine in eventChannelLinesList) {
                                    if ((evChannel.sources.source.component.id == channelLine.TriggerComponentId) && (evChannel.targets.target.component.id == channelLine.ListenerComponentId)) {
                                        foundLine = true;
                                        break;
                                    }
                                }
                                if (!foundLine) {
                                    eventChannelLine eCL = new eventChannelLine();

                                    eCL.Line.X1 = Canvas.GetLeft(((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
                                    //eCL.Line.Y1 = Canvas.GetTop(((modelComponent)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
                                    eCL.Line.Y1 = Canvas.GetTop(((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) +
                                        ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).MainRectangle.Height + LayoutConstants.EVENTPORTHEIGHT + LayoutConstants.MAINRECTANGLEOFFSETY - 7;
                                    eCL.Line.X2 = Canvas.GetLeft(((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
                                    //eCL.Line.Y2 = Canvas.GetTop(((modelComponent)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
                                    eCL.Line.Y2 = Canvas.GetTop(((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) +
                                        ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).MainRectangle.Height + LayoutConstants.EVENTPORTHEIGHT + LayoutConstants.MAINRECTANGLEOFFSETY - 7;

                                    eCL.Line.Focusable = true;
                                    eCL.ListenerComponentId = evChannel.targets.target.component.id;
                                    eCL.TriggerComponentId = evChannel.sources.source.component.id;
                                    eCL.Line.GotKeyboardFocus += EventChannel_GotKeyboardFocus;
                                    eCL.Line.LostKeyboardFocus += EventChannel_LostKeyboardFocus;
                                    eCL.Line.KeyDown += EventChannel_KeyDown;
                                    eCL.Line.ContextMenu = eventChannelContextMenu;
                                    eventChannelLinesList.Add(eCL);
                                    canvas.Children.Add(eCL.Line);
                                    KeyboardNavigation.SetTabIndex(eCL.Line, canvas.Children.Count + 1);
                                    Canvas.SetZIndex(eCL.Line, Canvas.GetZIndex(eCL.Line) + 2000);
                                }
                                eventChannelList.Add(o);
                                foundLine = false;
                            }
                            else {
                                // if no event listener Port can be found, the component has a version conflict
                                MessageBox.Show(Properties.Resources.CopyEventsErrorTextFormat(evChannel.targets.target.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).HasVersionConflict = true;
                            }
                        }
                        else {
                            // if no event trigger Port can be found, the component has a version conflict
                            MessageBox.Show(Properties.Resources.CopyEventsErrorTextFormat(evChannel.sources.source.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                            ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                            ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).HasVersionConflict = true;
                        }
                    }
                    catch (Exception) {
                        MessageBox.Show(Properties.Resources.CopyEventsExceptionTextFormat(evChannel.sources.source.component.id, evChannel.sources.source.eventPort.id,
                            evChannel.targets.target.component.id, evChannel.targets.target.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
            }

            // focus the first element
            if (canvas.Children.Count > 0) {
                Keyboard.Focus(canvas.Children[0]);
            }
            else {
                Keyboard.Focus(canvas);
            }
            copyOffsetMulti++;
            ClearSelectedChannelList();
            if (modelToPaste.channels != null) {
                foreach (channel c in modelToPaste.channels) {
                    selectedChannelList.AddLast(c);
                    co.InvolvedObjects.Add(c);
                }
            }
            UpdateSelectedChannels();
            ClearSelectedEventChannelList();
            LinkedList<eventChannelLine> selEventChannels = new LinkedList<eventChannelLine>();
            foreach (eventChannelLine ecl in eventChannelLinesList) {
                if (modelToPaste.eventChannels != null) {
                    foreach (eventChannel ech in modelToPaste.eventChannels) {
                        if (ecl.ListenerComponentId == ech.targets.target.component.id ||
                            ecl.TriggerComponentId == ech.sources.source.component.id) {
                            selEventChannels.AddLast(ecl);
                            break;
                        }
                    }
                }
            }
            foreach (eventChannelLine ecl in selEventChannels) {
                selectedEventChannelList.AddLast(ecl);
                co.InvolvedObjects.Add(ecl);
            }
            UpdateSelectedEventChannels();
            // select all inserted components
            ClearSelectedComponentList();
            foreach (componentType mc in modelToPaste.components) {
                selectedComponentList.AddLast(mc);
                co.InvolvedObjects.Add(mc);
            }
            UpdateSelectedComponents();
            if (addToUndoStack) {
                undoStack.Push(co);
                redoStack.Clear();
            }
            SetKeyboardFocus();
            int groupIndex = 0;
            AddDummyToModel(copyDummyName);
            foreach (ArrayList group in groupComps) {
                ClearSelectedChannelList();
                ClearSelectedComponentList();
                ClearSelectedEventChannelList();
                foreach (componentType ct in group) {
                    AddSelectedComponent(ct);
                }
                componentType groupComponent = (componentType) groups[groupIndex];
                // add dummy channels to retain all ports of the copied group element
                foreach (object o in groupComponent.ports) {
                    if (o is inputPortType) {
                        inputPortType inPort = (inputPortType) o;

                        string targetComponent = inPort.refs.componentID;
                        componentType newTarget = null;
                        foreach (componentType ct in group) {
                            if (ct.id.StartsWith(targetComponent)) {
                                if (newTarget == null)
                                    newTarget = ct;
                                else {
                                    if (newTarget.id.Length < ct.id.Length)
                                        newTarget = ct;
                                }
                            }
                        }
                        if (newTarget == null)
                            continue;

                        // check if an channel already exists for this inputporttype
                        bool duplicate = false;
                        foreach (channel c in deploymentChannelList.Values) {
                            if (c.target.component.id.Equals(newTarget.id) &&
                                c.target.port.id.Equals(inPort.portTypeID.Substring(targetComponent.Length + 1))) {
                                    duplicate = true;
                            }
                        }
                        if (duplicate)
                            continue;

                        // add dummy channel
                        channel groupChannel = new channel();

                        groupChannel.id = NewIdForChannel();
                        groupChannel.target.component.id = newTarget.id;
                        groupChannel.target.port.id = inPort.refs.portID;
                        groupChannel.source.component.id = copyDummyName;
                        groupChannel.source.port.id = "out";
                        if (!ChannelExists(groupChannel))
                            AddChannel(groupChannel);
                    } else if (o is outputPortType) {
                        outputPortType outPort = (outputPortType) o;
                        string sourceComponent = outPort.refs.componentID;
                        componentType newSource = null;
                        foreach (componentType ct in group) {
                            if (ct.id.StartsWith(sourceComponent)) {
                                if (newSource == null)
                                    newSource = ct;
                                else {
                                    if (newSource.id.Length < ct.id.Length)
                                        newSource = ct;
                                }
                            }
                        }
                        if (newSource == null)
                            continue;

                        // add dummy channel
                        channel groupChannel = new channel();

                        groupChannel.id = NewIdForChannel();
                        groupChannel.source.component.id = newSource.id;
                        groupChannel.source.port.id = outPort.refs.portID;
                        groupChannel.target.component.id = copyDummyName;
                        groupChannel.target.port.id = "in";
                        if (!ChannelExists(groupChannel))
                            AddChannel(groupChannel);
                    }

                }
                // add dummy eventchannels to retain all eventchannel ports of the copied group

                foreach (ArrayList echList in copyGroupEventChannels) {
                    foreach (eventChannel ech in echList) {
                        componentType source = null;
                        componentType target = null;
                        foreach (componentType ct in group) {
                            if (ct.id.StartsWith(ech.sources.source.component.id)) {
                                if (source == null)
                                    source = ct;
                                else if (ct.id.Length > source.id.Length)
                                    source = ct;
                            }
                            if (ct.id.StartsWith(ech.targets.target.component.id)) {
                                if (target == null)
                                    target = ct;
                                else if (ct.id.Length > target.id.Length)
                                    target = ct;
                            }
                        }
                        if (source != null)
                            ech.sources.source.component.id = source.id;
                        if (target != null) {
                            ech.targets.target.component.id = target.id;
                            ech.id = target.id + "_" + ech.sources.source.eventPort.id + "_" + ech.targets.target.eventPort.id;
                        }
                        if (source != null || target != null)
                            eventChannelList.Add(ech);
                    }
                }

                LinkedList<portAlias> newPortAlias = new LinkedList<portAlias>();
                group originalGroup = null;
                foreach (object o in groups) {
                   // groups.Add(ct);
                    groupComponent gc = groupsList[((componentType)o).id];
                    // adapting the alias to the new group port names

                    foreach (group gr in deploymentModel.groups) {
                        if (gr.id == ((componentType)o).id) {
                            originalGroup = gr;
                            break;
                        }
                    }

                    if (originalGroup != null && originalGroup.portAlias != null) {
                        foreach (portAlias alias in originalGroup.portAlias) {
                            foreach (string oldCompName in changedComponents.Keys) {
                                if (alias.portId.Contains(oldCompName)) {
                                    portAlias pAlias = new portAlias();
                                    pAlias.portId = alias.portId.Replace(oldCompName, changedComponents[oldCompName]);
                                    pAlias.portAlias1 = alias.portAlias1;
                                    newPortAlias.AddLast(pAlias);
                                    break;
                                }
                            }
                        }
                    }
                }

                DoGrouping((string) groupNames[groupIndex], false, true);
                group groupToUpdate = null;
                foreach (group gr in deploymentModel.groups) {
                    if (gr.id == (string)groupNames[groupIndex]) {
                        gr.portAlias = newPortAlias.ToArray();
                        groupToUpdate = gr;
                        break;
                    }
                }
                if (groupToUpdate.portAlias != null) {
                    foreach (portAlias alias in groupToUpdate.portAlias) {
                        componentType groupComponentToUpdate = deploymentComponentList[groupToUpdate.id];
                        groupComponentToUpdate.description = originalGroup.description;
                        foreach (object port in groupComponentToUpdate.ports) {
                            if ((port is inputPortType) && (((inputPortType)port).portTypeID == alias.portId)) {
                                ((inputPortType)port).PortAliasForGroups = alias.portAlias1;
                                ((inputPortType)port).PortLabel.Text = alias.portAlias1;
                                break;
                            } else if ((port is outputPortType) && (((outputPortType)port).portTypeID == alias.portId)) {
                                ((outputPortType)port).PortAliasForGroups = alias.portAlias1;
                                ((outputPortType)port).PortLabel.Text = alias.portAlias1;
                                break;
                            }
                        }
                    }
                }
                groupToUpdate.description = originalGroup.description;
                groupIndex++;
            }
            RemoveDummyFromModel(copyDummyName);
            DeleteDanglingChannels();
            DeleteDanglingEventChannels();

            // select the copied elements after paste
            selectedComponentList.Clear();
            foreach (componentType mc in modelToPaste.components) {
                selectedComponentList.AddLast(mc);
            }
            UpdateSelectedComponents();
        }
 /// <summary>
 /// Hide the eventchannels between the components on the canvas
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void showEventsRibbonButton_Unchecked(object sender, RoutedEventArgs e)
 {
     newChannelRibbonButton.IsChecked = false;
     // set visibility to "hidden" in the deploymentmodel
     foreach (UIElement elem in canvas.Children) {
         if (elem is Canvas) {
             Canvas cElem = (Canvas)elem;
             foreach (UIElement elem2 in cElem.Children) {
                 if (elem2 is Canvas) {
                     Canvas cElem2 = (Canvas)elem2;
                     if (cElem2.Name.Equals("EventListenerPort") || cElem2.Name.Equals("EventTriggerPort")) {
                         cElem2.Visibility = Visibility.Hidden;
                     }
                 }
             }
         }
         else if (elem is Line) {
             Line tempLine = (Line)elem;
             if (tempLine.Name == "EventChannelLine") {
                 tempLine.Visibility = Visibility.Hidden;
             }
         }
     }
     // set the ribbon buttons inactive
     newEventChannelRibbonButton.IsChecked = false;
     newEventChannelRibbonButton.IsEnabled = false;
     //deleteEventChannelRibbonButton.IsEnabled = false;
     if (eventChannelToConnect != null) {
         canvas.Children.Remove(eventChannelToConnect.Line);
         eventChannelToConnect = null;
     }
 }
        /// <summary>
        /// Additionally select the given Eventchannel
        /// </summary>
        /// <param name="ech">EventChannel to select</param>
        private void AddSelectedEventChannel(eventChannelLine ech)
        {
            if (!selectedEventChannelList.Contains(ech)) {
                selectedEventChannelList.AddLast(ech);
                if (!ech.HasGroupSource && !ech.HasGroupTarget) {
                    UpdateSelectedEventChannels();
                    return;
                }
                if (ech.HasGroupSource) {
                    groupComponent gc = groupsList[ech.TriggerComponentId];
                    foreach (componentType ct in gc.AddedComponentList) {
                        foreach (eventChannelLine ecl in eventChannelLinesList) {
                            if (ecl.TriggerComponentId.Equals(ct.id) && ecl.ListenerComponentId.Equals(ech.ListenerComponentId)) {
                                AddSelectedEventChannel(ecl);
                            }
                        }
                    }
                }
                if (ech.HasGroupTarget) {
                    groupComponent gc = groupsList[ech.ListenerComponentId];
                    foreach (componentType ct in gc.AddedComponentList) {
                        foreach (eventChannelLine ecl in eventChannelLinesList) {
                            if (ecl.ListenerComponentId.Equals(ct.id) && ecl.TriggerComponentId.Equals(ech.TriggerComponentId)) {
                                AddSelectedEventChannel(ecl);
                            }
                        }
                    }
                }
                if (ech.HasGroupTarget && ech.HasGroupSource) {
                    groupComponent target = groupsList[ech.ListenerComponentId];
                    groupComponent source = groupsList[ech.TriggerComponentId];
                    foreach (componentType ct in source.AddedComponentList) {
                        foreach (eventChannelLine ecl in eventChannelLinesList) {
                            if (ecl.TriggerComponentId.Equals(ct.id) && ecl.ListenerComponentId.Equals(target.ID)) {
                                AddSelectedEventChannel(ecl);
                            }
                        }
                    }

                    foreach (componentType ct in target.AddedComponentList) {
                        foreach (eventChannelLine ecl in eventChannelLinesList) {
                            if (ecl.ListenerComponentId.Equals(ct.id) && ecl.TriggerComponentId.Equals(source.ID)) {
                                AddSelectedEventChannel(ecl);
                            }
                        }
                    }
                }
            }
            UpdateSelectedEventChannels();
        }
        /// <summary>
        /// Function called, when the left mouse button will be released. If the release will be done over a channel or an event channel, the channel will get the focus
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnLeftUp(object sender, MouseEventArgs args)
        {
            // reset mouseMove Coordinates
            mouseMoveComponentX = -1;
            mouseMoveComponentY = -1;
            // when on the LeftDown Event a channel docked to a component all Selected Items should get deselected
            if (connectedChannelLastClick == true) {
                connectedChannelLastClick = false;
                ClearSelectedChannelList();
                ClearSelectedComponentList();
                ClearSelectedEventChannelList();
                return;
            }
            // left up on an event channel. set event channel as focused event channel
            if (args.Source is Line) {
                if (((Line)args.Source).Name == "EventChannelLine") {
                    foreach (eventChannelLine tempLine in eventChannelLinesList) {
                        if (tempLine.Line == (Line)args.Source) {
                            focusedEventChannel = tempLine;
                            Keyboard.Focus(focusedEventChannel.Line);
                            if (!selectedEventChannelList.Contains(tempLine)) {
                                if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                                    ClearSelectedChannelList();
                                    ClearSelectedComponentList();
                                    ClearSelectedEventChannelList();
                                }
                                AddSelectedEventChannel(tempLine);
                            }
                            else {
                                if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) {
                                    ClearColorOfSelectedEventChannels();
                                    selectedEventChannelList.Remove(tempLine);
                                    UpdateSelectedEventChannels();
                                }
                            }
                            break;
                        }
                    }
                }
                else { // left up on a channel. set channel as focused channel
                    foreach (channel tempChannel in deploymentChannelList.Values) {
                        if (tempChannel.Line == (Line)args.Source) {
                            focusedChannel = tempChannel;
                            Keyboard.Focus(focusedChannel.Line);
                            if (!selectedChannelList.Contains(tempChannel)) {
                                if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                                    ClearSelectedChannelList();
                                    ClearSelectedComponentList();
                                    ClearSelectedEventChannelList();
                                }
                                this.AddSelectedChannel(tempChannel);
                                Console.WriteLine(tempChannel.id + ": " + tempChannel.source.component.id + " --> " + tempChannel.target.component.id);

                            }
                            else {
                                if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) {
                                    ClearColorOfSelectedChannels();
                                    selectedChannelList.Remove(tempChannel);
                                    UpdateSelectedChannels();
                                }
                            }
                            break;
                        }
                    }
                }
            }
            else if (args.Source is Rectangle) {
                //modelComponent tempComponent = null;
                moveTracking = false;
                foreach (componentType tempComponent in deploymentComponentList.Values) {
                    if ((tempComponent.MainRectangle == (Rectangle)args.Source) || (tempComponent.TopRectangle == (Rectangle)args.Source)) {
                        focusedComponent = tempComponent;
                        Keyboard.Focus(focusedComponent.ComponentCanvas);
                        if (!selectedComponentList.Contains(tempComponent)) {
                            if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                                ClearSelectedComponentList();
                                ClearSelectedChannelList();
                                ClearSelectedEventChannelList();
                            }
                            AddSelectedComponent(tempComponent);
                        }
                        else {
                            if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) {
                                ClearBorderOfSelectedComponents();
                                selectedComponentList.Remove(tempComponent);
                                UpdateSelectedComponents();
                            }
                        }
                        break;
                    }
                    else {
                        if (newChannelRibbonButton.IsEnabled) // was editchannelribbongroup
                        {
                            foreach (object o in tempComponent.PortsList.Values) {
                                if (o is outputPortType) {
                                    if (((outputPortType)o).PortRectangle == (Rectangle)args.Source) {
                                        //focusedComponent = tempComponent;
                                        //Keyboard.Focus(focusedComponent.ComponentCanvas);
                                        newChannelRibbonButton.IsChecked = true;
                                        break;
                                    }
                                }
                                else if (o is inputPortType) {
                                    if (((inputPortType)o).PortRectangle == (Rectangle)args.Source) {
                                        if (!selectedComponentList.Contains(tempComponent)) {
                                            if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                                                ClearSelectedComponentList();
                                                ClearSelectedChannelList();
                                                ClearSelectedEventChannelList();
                                            }
                                            AddSelectedComponent(tempComponent);
                                        }
                                        else {
                                            if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) {
                                                ClearBorderOfSelectedComponents();
                                                selectedComponentList.Remove(tempComponent);
                                                UpdateSelectedComponents();
                                            }
                                        }
                                        focusedComponent = tempComponent;
                                        Keyboard.Focus(tempComponent.ComponentCanvas);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (args.Source is TextBlock) {
                foreach (componentType tempComponent in deploymentComponentList.Values) {
                    if (tempComponent.Label == (TextBlock)args.Source) {
                        focusedComponent = tempComponent;
                        Keyboard.Focus(focusedComponent.ComponentCanvas);
                        if (!selectedComponentList.Contains(tempComponent)) {
                            if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                                ClearSelectedComponentList();
                                ClearSelectedChannelList();
                                ClearSelectedEventChannelList();
                            }
                            AddSelectedComponent(tempComponent);
                        }
                        else {
                            if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) {
                                ClearBorderOfSelectedComponents();
                                selectedComponentList.Remove(tempComponent);
                                UpdateSelectedComponents();
                            }
                        }
                        break;
                    }
                    else {
                        foreach (object o in tempComponent.PortsList.Values) {
                            if (o is inputPortType) {
                                if (((inputPortType)o).PortLabel == (TextBlock)args.Source) {
                                    focusedComponent = tempComponent;
                                    Keyboard.Focus(focusedComponent.ComponentCanvas);
                                    if (!selectedComponentList.Contains(tempComponent)) {
                                        if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                                            ClearSelectedComponentList();
                                            ClearSelectedChannelList();
                                            ClearSelectedEventChannelList();
                                        }
                                        AddSelectedComponent(tempComponent);
                                    }
                                    else {
                                        if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) {
                                            ClearBorderOfSelectedComponents();
                                            selectedComponentList.Remove(tempComponent);
                                            UpdateSelectedComponents();
                                        }
                                    }
                                    break;
                                }
                            }
                            else if (o is outputPortType) {
                                if (((outputPortType)o).PortLabel == (TextBlock)args.Source) {
                                    focusedComponent = tempComponent;
                                    Keyboard.Focus(focusedComponent.ComponentCanvas);
                                    if (!selectedComponentList.Contains(tempComponent)) {
                                        if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                                            ClearSelectedComponentList();
                                            ClearSelectedChannelList();
                                            ClearSelectedEventChannelList();
                                        }
                                        AddSelectedComponent(tempComponent);
                                    }
                                    else {
                                        if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) {
                                            ClearBorderOfSelectedComponents();
                                            selectedComponentList.Remove(tempComponent);
                                            UpdateSelectedComponents();
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else if (args.Source is Polygon) {
                if (newEventChannelRibbonButton.IsEnabled) // was editeventribbongroup
                {
                    if (!((Polygon)args.Source).Name.Equals("EventTriggerPortPolygon")) {
                        foreach (componentType tempComponent in deploymentComponentList.Values) {
                            Canvas tempCanvas = (Canvas)((Polygon)args.Source).Parent;
                            if (tempComponent.ComponentCanvas == tempCanvas.Parent) {
                                if (!selectedComponentList.Contains(tempComponent)) {
                                    if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                                        ClearSelectedComponentList();
                                        ClearSelectedChannelList();
                                        ClearSelectedEventChannelList();
                                    }
                                    AddSelectedComponent(tempComponent);
                                    focusedComponent = tempComponent;
                                    Keyboard.Focus(focusedComponent.ComponentCanvas);
                                }
                                else {
                                    if ((Keyboard.Modifiers & ModifierKeys.Control) > 0) {
                                        ClearBorderOfSelectedComponents();
                                        selectedComponentList.Remove(tempComponent);
                                        UpdateSelectedComponents();
                                    }
                                    else {
                                        focusedComponent = tempComponent;
                                        Keyboard.Focus(tempComponent.ComponentCanvas);
                                    }
                                }
                                break;
                            }

                        }
                    }
                }
            }
            if (selectionRectangle != null) {
                //select all objects of the canvas which collide with this rectangle
                this.selectObjectsFromRectangle(selectionRectangle);
                canvas.Children.Remove(selectionRectangle);
                selectionRectangle = null;
            }
            if (componentToMove != null) {
                focusedComponent = componentToMove;
                Keyboard.Focus(focusedComponent.ComponentCanvas);
                Canvas.SetZIndex(focusedComponent.ComponentCanvas, Canvas.GetZIndex(focusedComponent.ComponentCanvas) - 3000);
                componentToMove = null;
            }
            offsetX = 0;
            offsetY = 0;
        }
Example #6
0
 /// <summary>
 /// Check if the source of the eventchannelline exists
 /// </summary>
 /// <param name="ecl">eventchannelline to check</param>
 /// <returns>true if the source of the given eventchannelline exists, false otherise</returns>
 private bool EventChannelLineTriggerExists(eventChannelLine ecl)
 {
     return deploymentComponentList.ContainsKey(ecl.TriggerComponentId);
 }
Example #7
0
 /// <summary>
 /// Returns a list of all eventchannels which correspond to the given eventchannelline
 /// </summary>
 /// <param name="ecl">eventchannelline for which the eventchannels should be searched</param>
 /// <returns>A list of all eventchannels within the given eventchannelline</returns>
 private List<eventChannel> GetEventChannelsFromLine(eventChannelLine ecl)
 {
     List<eventChannel> ecList = new List<eventChannel>();
     foreach (eventChannel ec in eventChannelList) {
         string source = ec.sources.source.component.id;
         string target = ec.targets.target.component.id;
         if (ecl.ListenerComponentId.Equals(target) && ecl.TriggerComponentId.Equals(source))
             ecList.Add(ec);
     }
     return ecList;
 }
        /// <summary>
        /// Deletes all selected components, channels and eventchannels
        /// </summary>
        private void DeleteSelectedComponents()
        {
            if (selectedComponentList.Count == 0 &&
                selectedChannelList.Count == 0 &&
                selectedEventChannelList.Count == 0)
                return;
            CommandObject co = new CommandObject("Add");

            foreach (componentType mc in selectedComponentList) {
                if (mc.ComponentType != ACS2.componentTypeDataTypes.group)
                    co.InvolvedObjects.Add(mc);
                else {
                    if (groupsList.ContainsKey(mc.id))
                        co.InvolvedObjects.Add(groupsList[mc.id]);
                }
            }
            // delete all selected channels
            foreach (channel ch in selectedChannelList) {
                DeleteChannel(ch);
                co.InvolvedObjects.Add(ch);
            }

            // delete all selected eventchannels
            if (focusedEventChannel != null) {

                focusedEventChannel = null;
                ResetPropertyDock();
            }
            foreach (eventChannelLine ech in selectedEventChannelList) {
                co.InvolvedObjects.Add(ech);
                foreach (eventChannel eventCh in eventChannelList) {
                    foreach (object o in co.InvolvedObjects) {
                        if (!(o is eventChannelLine))
                            continue;
                        if ((eventCh.sources.source.component.id == ((eventChannelLine)o).TriggerComponentId) && (eventCh.targets.target.component.id == ((eventChannelLine)o).ListenerComponentId)) {
                            co.Parameter.Add(eventCh);
                        }
                    }
                }
                DeleteEventChannelCommand(ech);
            }

            foreach (componentType mc in selectedComponentList) {
                // delete all eventchannels from the mc
                // delete the eventChannels and therefore the events
                eventChannelLine eCL;
                for (int index = eventChannelLinesList.Count - 1; index >= 0; index--) {
                    eCL = (eventChannelLine)eventChannelLinesList[index];
                    if ((eCL.TriggerComponentId == mc.id) || (eCL.ListenerComponentId == mc.id)) {
                        focusedEventChannel = eCL;
                        // Ask a question, if component and therefore all events should be deleted. Causes some problems, if no is selected
                        // if (MessageBox.Show(Properties.Resources.DeleteEventChannelConfirmTextFormat(focusedEventChannel.TriggerComponentId, focusedEventChannel.ListernerComponentId),
                        //    Properties.Resources.DeleteEventChannelConfirmHeader, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) {
                        co.InvolvedObjects.Add(focusedEventChannel);
                        foreach (eventChannel eventCh in eventChannelList) {
                            foreach (object o in co.InvolvedObjects) {
                                if (!(o is eventChannelLine))
                                    continue;
                                if ((eventCh.sources.source.component.id == ((eventChannelLine)o).TriggerComponentId) &&
                                    (eventCh.targets.target.component.id == ((eventChannelLine)o).ListenerComponentId)) {
                                    co.Parameter.Add(eventCh);
                                }
                            }
                        }
                        DeleteEventChannelCommand(focusedEventChannel);
                        focusedEventChannel = null;
                    }
                }
                focusedEventChannel = null;

                // delete all channels from the mc
                if (mc.ports != null && mc.PortsList != null && mc.PortsList.Values != null) {
                    foreach (Object o in mc.PortsList.Values) {
                        if (o is inputPortType) {
                            inputPortType pIn = (inputPortType)o;
                            if (pIn.ChannelId != "") {
                                channel tempChannel = deploymentChannelList[pIn.ChannelId];
                                DeleteChannel(tempChannel);
                                co.InvolvedObjects.Add(tempChannel);
                            }
                        }
                        else if (o is outputPortType) {
                            outputPortType pOut = (outputPortType)o;
                            while (pOut.ChannelIds.Count > 0) {
                                channel tempChannel = deploymentChannelList[pOut.ChannelIds[0].ToString()];
                                DeleteChannel(tempChannel);
                                co.InvolvedObjects.Add(tempChannel);
                            }
                        }
                    }
                }
                ArrayList channelToDelete = new ArrayList();
                foreach (channel c in deploymentChannelList.Values) {
                    if (c.target.component.id.Equals(mc.id))
                        channelToDelete.Add(c);
                }
                foreach (channel c in channelToDelete) {
                    DeleteChannel(c);
                }

                if (canvas.Children.Count > 0) {
                    Keyboard.Focus(canvas.Children[0]);
                }
                else {
                    Keyboard.Focus(canvas);
                }
                if (focusedComponent == mc)
                    focusedComponent = null;
                DeleteComponent(mc);
            }
            undoStack.Push(co);
            redoStack.Clear();
            DeleteDanglineLines();
            ClearSelectedChannelList();
            ClearSelectedComponentList();
            ClearSelectedEventChannelList();
            ResetPropertyDock();
        }
 /// <summary>
 /// An eventchannel got the focus, content in property dock will be set by SetEventPropertyDock(modelComponent sourceComponent, modelComponent targetComponent)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void EventChannel_GotKeyboardFocus(object sender, RoutedEventArgs args)
 {
     DoubleCollection dashes = new DoubleCollection();
     dashes.Add(1);
     dashes.Add(1);
     ((Line)sender).StrokeDashArray = dashes;
     //deleteEventChannelRibbonButton.IsEnabled = true;
     ResetPropertyDock();
     foreach (eventChannelLine tempChannel in eventChannelLinesList) {
         if ((Line)sender == tempChannel.Line) {
             focusedEventChannel = tempChannel;
             break;
         }
     }
     SetEventPropertyDock(deploymentComponentList[focusedEventChannel.TriggerComponentId], deploymentComponentList[focusedEventChannel.ListenerComponentId]);
 }
Example #10
0
        /// <summary>
        /// Drop an event channel from the component context menu. This will be used, if an event channel was created, but should not be connected to an event listner port
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ComponentContextMenuItemDropEvent_Click(object sender, RoutedEventArgs e)
        {
            eventChannelToConnect = null;
            newEventChannelRibbonButton.IsChecked = false;

            componentContextMenuItemAddEventChannel.IsEnabled = true;
            componentContextMenuItemConnectEventChannel.IsEnabled = false;
            componentContextMenuItemDropEventChannel.IsEnabled = false;
        }
Example #11
0
        /// <summary>
        /// Delete an event channel line between two components and delete all events
        /// between the two components
        /// </summary>
        /// <param name="eventChannelToDelete"></param>
        private void DeleteEventChannelCommand(eventChannelLine eventChannelToDelete)
        {
            eventChannel eventCh;
            for (int index = eventChannelList.Count - 1; index >= 0; index--) {
                eventCh = (eventChannel)eventChannelList[index];
                if ((eventCh.sources.source.component.id == eventChannelToDelete.TriggerComponentId) && (eventCh.targets.target.component.id == eventChannelToDelete.ListenerComponentId)) {
                    eventChannelList.RemoveAt(index);
                }
                foreach (groupComponent gc in groupsList.Values) {
                    gc.AddedEventChannelsList.Remove(eventChannelToDelete);
                }
            }

            canvas.Children.Remove(eventChannelToDelete.Line);
            eventChannelLinesList.Remove(eventChannelToDelete);
            eventChannelToDelete.Line.GotKeyboardFocus -= EventChannel_GotKeyboardFocus;
            eventChannelToDelete.Line.LostKeyboardFocus -= EventChannel_LostKeyboardFocus;
            eventChannelToDelete.Line.KeyDown -= EventChannel_KeyDown;
            Canvas.SetZIndex(eventChannelToDelete.Line, Canvas.GetZIndex(eventChannelToDelete.Line) - 2000);
            //focusedEventChannel = null;
            //deleteEventChannelRibbonButton.IsEnabled = false;
            deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
            ResetPropertyDock();
            modelHasBeenEdited = true;
        }
Example #12
0
        /// <summary>
        /// Connect an event channel to the event listener port. Called from the component context menu. 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ComponentContextMenuItemConnectEvent_Click(object sender, RoutedEventArgs e)
        {
            Rectangle r = (Rectangle)((ContextMenu)((MenuItem)e.Source).Parent).PlacementTarget;
            componentType componentWithFocus = null;
            foreach (componentType tempComponent in deploymentComponentList.Values) {
                if ((tempComponent.MainRectangle == r) || (tempComponent.TopRectangle == r)) {
                    componentWithFocus = tempComponent;
                    break;
                }
            }
            canvas.Children.Add(eventChannelToConnect.Line);
            eventChannelToConnect.ListenerComponentId = componentWithFocus.id;
            eventChannelToConnect.Line.X2 = Canvas.GetLeft(componentWithFocus.ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
            eventChannelToConnect.Line.Y2 = Canvas.GetTop(componentWithFocus.ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
            CommandObject co = new CommandObject("Delete", eventChannelToConnect);
            undoStack.Push(co);
            redoStack.Clear();
            AddEventChannelCommand(eventChannelToConnect, true);

            eventChannelToConnect = null;
            ////dockManager.ActiveContent = dockableEventsTab;

            componentContextMenuItemAddEventChannel.IsEnabled = true;
            componentContextMenuItemConnectEventChannel.IsEnabled = false;
            componentContextMenuItemDropEventChannel.IsEnabled = false;
        }
Example #13
0
        /// <summary>
        /// Prepare an event channel from the component context menu and connect it to the event trigger port
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ComponentContextMenuItemAddEvent_Click(object sender, RoutedEventArgs e)
        {
            Rectangle r = (Rectangle)((ContextMenu)((MenuItem)e.Source).Parent).PlacementTarget;
            componentType componentWithFocus = null;
            foreach (componentType tempComponent in deploymentComponentList.Values) {
                if ((tempComponent.MainRectangle == r) || (tempComponent.TopRectangle == r)) {
                    componentWithFocus = tempComponent;
                    break;
                }
            }
            eventChannelToConnect = new eventChannelLine();
            eventChannelToConnect.TriggerComponentId = componentWithFocus.id;
            eventChannelToConnect.Line.X1 = Canvas.GetLeft(componentWithFocus.ComponentCanvas) + +LayoutConstants.EVENTOUTPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
            eventChannelToConnect.Line.Y1 = Canvas.GetTop(componentWithFocus.ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;

            componentContextMenuItemAddEventChannel.IsEnabled = false;
            componentContextMenuItemConnectEventChannel.IsEnabled = true;
            componentContextMenuItemDropEventChannel.IsEnabled = true;
        }
Example #14
0
 /// <summary>
 /// Deselect all EventChannels and select the given one
 /// </summary>
 /// <param name="ech">EventChannel to select</param>
 private void ClearAndAddSelectedEventChannel(eventChannelLine ech)
 {
     ClearSelectedEventChannelList();
     if (!selectedEventChannelList.Contains(ech))
         selectedEventChannelList.AddLast(ech);
     UpdateSelectedEventChannels();
 }
Example #15
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 #16
0
        /// <summary>
        /// Global keyboard listener within the application. Used to handle 'Esc'-key, F-keys, Zoom and Shortcuts for avalon-windows
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Global_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape) {
                if (channelToConnect != null) {
                    canvas.Children.Remove(channelToConnect.Line);
                    channelToConnect = null;
                }
                if (eventChannelToConnect != null) {
                    canvas.Children.Remove(eventChannelToConnect.Line);
                    eventChannelToConnect = null;
                }
            }

            if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.P)) {
                Keyboard.Focus(dockableComponentProperties);
            }
            else if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.E)) {
                Keyboard.Focus(dockableEventsTab);
            }
            else if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.D)) {
                Keyboard.Focus(scrollCanvars);

                // Timer is setting the focus to the first element. Otherwise, the system is still changing the tabs
                // and the focus will not be set, as the elements are not visible
                TimerCallback tcbFocus = this.DoFocusTimer;
                statusTimer = new Timer(tcbFocus, canvas, 300, Timeout.Infinite);
            }
            else if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.G)) {
                Keyboard.Focus(GUIEditorCanvas);

                // Timer is setting the focus to the first element. Otherwise, the system is still changing the tabs
                // and the focus will not be set, as the elements are not visible
                TimerCallback tcbFocus = this.DoFocusTimer;
                statusTimer = new Timer(tcbFocus, guiCanvas, 300, Timeout.Infinite);
            }
            else if ((Keyboard.Modifiers == ModifierKeys.Control) && ((e.Key == Key.Add) || (e.Key == Key.OemPlus))) {
                if (zoomSlider.Value < zoomSlider.Maximum) {
                    zoomSlider.Value += zoomSlider.SmallChange;
                }
            }
            else if ((Keyboard.Modifiers == ModifierKeys.Control) && ((e.Key == Key.Subtract) || (e.Key == Key.OemMinus))) {
                if (zoomSlider.Value > zoomSlider.Minimum) {
                    zoomSlider.Value -= zoomSlider.SmallChange;
                }
            }
            else if (e.Key == Key.F1) {
                Help_Click(sender, null);
            }
            else if (e.Key == Key.F5) {
                if (runModelButton.IsEnabled) {
                    StartModel_Click(null, null);
                }
            }
            else if (e.Key == Key.F6) {
                if (pauseModelButton.IsEnabled) {
                    PauseModel_Click(null, null);
                }
            }
            else if (e.Key == Key.F7) {
                if (stopModelButton.IsEnabled) {
                    StopModel_Click(null, null);
                }
            }
            else if (e.Key == Key.A && ModifierKeys.Control == e.KeyboardDevice.Modifiers) {
                SelectAll();
            }
            else if (e.Key == Key.C && ModifierKeys.Control == e.KeyboardDevice.Modifiers) {
                if (!((areStatus.Status == AREStatus.ConnectionStatus.Running) || (areStatus.Status == AREStatus.ConnectionStatus.Pause))) {
                    CopySelectedCommand();
                    e.Handled = true;
                    pasteRibbonButton.IsEnabled = true;
                }
            }
            else if (e.Key == Key.V && ModifierKeys.Control == e.KeyboardDevice.Modifiers) {
                if (!((areStatus.Status == AREStatus.ConnectionStatus.Running) || (areStatus.Status == AREStatus.ConnectionStatus.Pause))) {
                    model tmpModel = CopyModel(copyModel);
                    PasteCopiedModel(copyModel, false,true);
                    copyModel = tmpModel;
                }
            }
            else if (e.Key == Key.X && ModifierKeys.Control == e.KeyboardDevice.Modifiers) {
                if (!((areStatus.Status == AREStatus.ConnectionStatus.Running) || (areStatus.Status == AREStatus.ConnectionStatus.Pause))) {
                    CopySelectedCommand();
                    DeleteSelectedComponents();
                    pasteRibbonButton.IsEnabled = true;
                }
            } else if (e.Key == Key.Delete) {
                if (!((areStatus.Status == AREStatus.ConnectionStatus.Running) || (areStatus.Status == AREStatus.ConnectionStatus.Pause))) {
                    DeleteSelectedComponents();
                }
            } else if (e.Key == Key.Z && ModifierKeys.Control == e.KeyboardDevice.Modifiers) {
                if (undoButton.IsEnabled) {
                    Undo_Click(sender, e);
                }
            } else if (e.Key == Key.Y && ModifierKeys.Control == e.KeyboardDevice.Modifiers) {
                if (redoButton.IsEnabled) {
                    Redo_Click(sender, e);
                }
            } else if (e.Key == Key.S && ModifierKeys.Control == e.KeyboardDevice.Modifiers) {
                // If a property has been edited and the focus has not been set to another element, the property will not be set.
                // Clicking ribbon elments did not remove focus from property editor, so the property will
                // not be set. Causes problems, saving, uplaoding, ... the model
                if (canvas.Children.Count > 0) {
                    Keyboard.Focus(canvas.Children[0]);
                } else {
                    Keyboard.Focus(canvas);
                }
                String mustBeConnectedError = MustBeConnectedChecker();
                if (mustBeConnectedError != "") {
                    MessageBox.Show(mustBeConnectedError, Properties.Resources.MustBeConnectedCheckerHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                } else {
                    // if no file for saving is defined yet, show the saveas-dialog
                    if (saveFile != null) {
                        SaveLocalCommand(false);
                    } else {
                        SaveLocalCommand(true);
                    }
                }
            }
        }
Example #17
0
 /// <summary>
 /// Check if the given eventchannelline has a group as target
 /// </summary>
 /// <param name="ec">eventchannelline for which the existence of a group target should get checked</param>
 /// <returns>true if the target of the given eventchannelline is a group, false otherwise</returns>
 private bool EventChannelLineHasGroupTarget(eventChannelLine ecl)
 {
     foreach (groupComponent gc in groupsList.Values) {
         if (gc.ID.Equals(ecl.ListenerComponentId))
             return true;
     }
     return false;
 }
Example #18
0
        private void LoadComponentsCommand()
        {
            // reset component list, channel list and canvas
            deploymentComponentList.Clear();
            canvas.Children.Clear();
            deploymentChannelList.Clear();
            eventChannelLinesList.Clear();
            eventChannelList.Clear();
            groupsList.Clear();
            CleanGUICanvas();
            copyModel = null;

            // loading the components
            foreach (object o in deploymentModel.components) {
                componentType modelComp = (componentType)o;
                // check, if bundle is available
                if (componentList.ContainsKey(modelComp.type_id)) {

                    // init the ArrayLists containing the ports. Used for easier and faster access
                    modelComp.InitArrayLists();

                    foreach (propertyType p in modelComp.properties) {
                        modelComp.PropertyArrayList.Add(p);
                    }

                    // copy the property datatype and description from bundle_description
                    // also copy the port datatypes form the bundle_description
                    // works only, if bundle and deployment fits to each other

                    try {
                        // search for bundle component
                        Asterics.ACS2.componentTypesComponentType bundleComponent = (Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id];

                        // copy the ComponentType of the component
                        modelComp.ComponentType = bundleComponent.type.Value;

                        if (modelComp.properties != null) {
                            foreach (propertyType deploymentProperty in modelComp.properties) {
                                int index = 0;
                                // searching for the right component property
                                while (deploymentProperty.name != bundleComponent.properties[index].name) {
                                    index++;
                                }
                                // copy the properties of the component
                                deploymentProperty.DataType = bundleComponent.properties[index].type;

                                // check, if the property is a dynamic property
                                if (bundleComponent.properties[index].getStringList) {
                                    deploymentProperty.GetStringList = true;
                                }
                                else {
                                    deploymentProperty.GetStringList = false;
                                }

                                // check the value fitting to the datatype
                                if (!CheckPropertyDatatype(deploymentProperty.value, deploymentProperty.DataType)) {
                                    throw new LoadPropertiesException();
                                }

                                deploymentProperty.Description = bundleComponent.properties[index].description;
                                if (bundleComponent.properties[index].combobox != null) {
                                    deploymentProperty.ComboBoxStrings = bundleComponent.properties[index].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                }
                                deploymentProperty.PropertyChanged += ComponentPropertyChanged;
                                deploymentProperty.PropertyChangeError += ComponentPropertyChangeError;
                            }
                            // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                            if ((bundleComponent.properties == null) && (modelComp.properties.Length != 0)) {
                                throw new LoadPropertiesException();
                            }
                            else if ((bundleComponent.properties != null) && (modelComp.properties.Length != bundleComponent.properties.Length)) {
                                throw new LoadPropertiesException();
                            }
                        }

                        foreach (object portObj in modelComp.PortsList.Values) {
                            // searching for the inPorts
                            if (portObj is inputPortType) {
                                int index = 0;
                                inputPortType deploymentInPort = (inputPortType)portObj;
                                ArrayList helperListInPort = new ArrayList(); // a list with all InPorts of a component for the bundel_description
                                foreach (object bundleInPort in bundleComponent.ports) {
                                    if (bundleInPort is ACS2.inputPortType) {
                                        helperListInPort.Add(bundleInPort);
                                    }
                                }
                                while (deploymentInPort.portTypeID != ((ACS2.inputPortType)helperListInPort[index]).id) {
                                    index++; // searching for the right input port
                                }
                                // copy the dataType of the port
                                deploymentInPort.PortDataType = ((Asterics.ACS2.inputPortType)helperListInPort[index]).dataType;
                                deploymentInPort.MustBeConnected = ((Asterics.ACS2.inputPortType)helperListInPort[index]).mustBeConnected;
                                deploymentInPort.Description = ((Asterics.ACS2.inputPortType)helperListInPort[index]).description;
                                deploymentInPort.ComponentId = ((Asterics.ACS2.inputPortType)helperListInPort[index]).ComponentId;
                                deploymentInPort.ComponentTypeId = ((Asterics.ACS2.inputPortType)helperListInPort[index]).id;

                                // update the alias for group ports via property changed listener
                                deploymentInPort.PropertyChanged += InputPortIntPropertyChanged;

                                ACS2.propertyType[] sourceProperties = ((Asterics.ACS2.inputPortType)helperListInPort[index]).properties;
                                if ((sourceProperties != null) && (sourceProperties.Length > 0)) {
                                    //if (deploymentInPort.PropertyArrayList.Count > 0) {
                                    foreach (propertyType deploymentProperty in deploymentInPort.properties) {
                                        int inPortIndex = 0;
                                        while (deploymentProperty.name != sourceProperties[inPortIndex].name) {
                                            inPortIndex++;
                                        }
                                        // copy the properties of the inPort
                                        deploymentProperty.DataType = sourceProperties[inPortIndex].type;
                                        deploymentProperty.Description = sourceProperties[inPortIndex].description;
                                        if (sourceProperties[inPortIndex].combobox != null) {
                                            deploymentProperty.ComboBoxStrings = sourceProperties[inPortIndex].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                        }
                                        deploymentProperty.PropertyChanged += InPortPropertyChanged;
                                        deploymentProperty.PropertyChangeError += ComponentPropertyChangeError;
                                    }
                                    // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                                    if (deploymentInPort.properties.Length != sourceProperties.Length) {
                                        throw new LoadPropertiesException();
                                    }
                                }
                                deploymentInPort.properties = (propertyType[])deploymentInPort.PropertyArrayList.ToArray(typeof(propertyType));
                            }
                            else {
                                // comparing all outPports
                                int index = 0;
                                outputPortType outPort = (outputPortType)portObj;
                                ArrayList helperListOutPort = new ArrayList();
                                foreach (object origOutPort in bundleComponent.ports) {
                                    if (origOutPort is ACS2.outputPortType) {
                                        helperListOutPort.Add(origOutPort);
                                    }
                                }
                                while (outPort.portTypeID != ((Asterics.ACS2.outputPortType)helperListOutPort[index]).id) {
                                    index++;
                                }
                                // copy the dataType of the port
                                outPort.PortDataType = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).dataType;
                                outPort.Description = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).description;
                                outPort.ComponentId = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).ComponentId;
                                outPort.ComponentTypeId = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).id;

                                // update the alias for group ports via property changed listener
                                outPort.PropertyChanged += OutputPortIntPropertyChanged;

                                ACS2.propertyType[] sourceProperties = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).properties;
                                if ((sourceProperties != null) && (sourceProperties.Length > 0)) {
                                    //if (outPort.PropertyArrayList.Count > 0) {
                                    foreach (propertyType compProperty in outPort.properties) {
                                        int outPortIndex = 0;
                                        while (compProperty.name != sourceProperties[outPortIndex].name) {
                                            outPortIndex++;
                                        }
                                        // copy the properties of the outPort
                                        compProperty.DataType = sourceProperties[outPortIndex].type;
                                        compProperty.Description = sourceProperties[outPortIndex].description;
                                        if (sourceProperties[outPortIndex].combobox != null) {
                                            compProperty.ComboBoxStrings = sourceProperties[outPortIndex].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                        }
                                        compProperty.PropertyChanged += OutPortPropertyChanged;
                                        compProperty.PropertyChangeError += ComponentPropertyChangeError;
                                    }
                                    // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                                    if (outPort.properties.Length != sourceProperties.Length) {
                                        throw new LoadPropertiesException();
                                    }
                                }
                                outPort.properties = (propertyType[])outPort.PropertyArrayList.ToArray(typeof(propertyType));
                            }
                        }
                        // check if the amount of ports is equal to the amount of ports in the bundle
                        foreach (object origPort in bundleComponent.ports) {
                            if (origPort is ACS2.outputPortType) {
                                if (!modelComp.PortsList.Contains(((ACS2.outputPortType)origPort).id)) {
                                    outputPortType outPort = new outputPortType();
                                    outPort.PortDataType = ((Asterics.ACS2.outputPortType)origPort).dataType;
                                    outPort.Description = ((Asterics.ACS2.outputPortType)origPort).description;
                                    outPort.ComponentId = ((Asterics.ACS2.outputPortType)origPort).ComponentId;
                                    outPort.ComponentTypeId = ((Asterics.ACS2.outputPortType)origPort).id;
                                    outPort.portTypeID = ((Asterics.ACS2.outputPortType)origPort).id;
                                    modelComp.PortsList.Add(outPort.portTypeID, outPort);
                                    modelComp.ports = new object[modelComp.PortsList.Count];
                                    modelComp.PortsList.Values.CopyTo(modelComp.ports, 0);
                                    throw new LoadPortsException(outPort.portTypeID);
                                }
                            } else if (origPort is ACS2.inputPortType) {
                                if (!modelComp.PortsList.Contains(((ACS2.inputPortType)origPort).id)) {
                                    inputPortType inPort = new inputPortType();
                                    inPort.PortDataType = ((Asterics.ACS2.inputPortType)origPort).dataType;
                                    inPort.MustBeConnected = ((Asterics.ACS2.inputPortType)origPort).mustBeConnected;
                                    inPort.Description = ((Asterics.ACS2.inputPortType)origPort).description;
                                    inPort.ComponentId = ((Asterics.ACS2.inputPortType)origPort).ComponentId;
                                    inPort.ComponentTypeId = ((Asterics.ACS2.inputPortType)origPort).id;
                                    inPort.portTypeID = ((Asterics.ACS2.inputPortType)origPort).id;
                                    modelComp.PortsList.Add(inPort.portTypeID, inPort);
                                    modelComp.ports = new object[modelComp.PortsList.Count];
                                    modelComp.PortsList.Values.CopyTo(modelComp.ports, 0);
                                    throw new LoadPortsException(inPort.portTypeID);
                                }
                            }
                        }

                    }
                    catch (LoadPortsException lPortEx) {
                        // HasVersionConflict indicates a version conflict between the component in a stored model and
                        // the component in the bundle descriptor
                        //modelComp.HasVersionConflict = true;
                        modelComp.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                        MessageBox.Show(Properties.Resources.CopyPortsErrorTextFormat(lPortEx.Message, modelComp.id), Properties.Resources.CopyPortsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                        traceSource.TraceEvent(TraceEventType.Error, 3, lPortEx.Message);

                    } catch (Exception lPropEx) { //LoadPropertiesException
                        MessageBox.Show(Properties.Resources.CopyPropertiesErrorTextFormat(modelComp.id), Properties.Resources.CopyPropertiesErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                        traceSource.TraceEvent(TraceEventType.Error, 3, lPropEx.Message);

                        //versionconflict
                        int posX;
                        int posY;
                        // set coordinates for the component in case there are not already set
                        if ((modelComp.layout.posX == null) || (modelComp.layout.posX == "") || (modelComp.layout.posY == null) || (modelComp.layout.posY == "")) {
                            posX = 40;
                            posY = 40;
                        }
                        else {
                            posX = Int32.Parse(modelComp.layout.posX);
                            posY = Int32.Parse(modelComp.layout.posY);
                        }

                        // backup component to load properties
                        componentType backupComp = modelComp;

                        modelComp = componentType.CopyFromBundleModel((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id], modelComp.id);
                        modelComp.layout.posX = Convert.ToString(posX);
                        modelComp.layout.posY = Convert.ToString(posY);

                        //reload the GUIElemens form the backup
                        if (backupComp.gui != null) {
                            modelComp.gui = backupComp.gui;
                        }
                        // HasVersionConflict indicates a version conflict between the component in a stored model and
                        // the component in the bundle descriptor
                        modelComp.HasVersionConflict = true;
                        modelComp.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                        //break;

                        // new code, copy property values from invalid (version conflict) component
                        foreach (propertyType deploymentProperty in modelComp.properties) {
                            foreach (propertyType backupProperty in backupComp.properties) {
                                if (deploymentProperty.name == backupProperty.name) {
                                    if (CheckPropertyDatatype(backupProperty.value, deploymentProperty.DataType)) {
                                        deploymentProperty.value = backupProperty.value; // try-parse is missing
                                    }
                                    break;
                                }
                            }
                        }

                    } // end of LoadPropertiesException

                    // set coordinates for the component in case there are not already set
                    if ((modelComp.layout.posX == null) || (modelComp.layout.posX == "") || (modelComp.layout.posY == null) || (modelComp.layout.posY == "")) {
                        int[] pos = ProperComponentCoordinates(40, 40);
                        modelComp.layout.posX = Convert.ToString(pos[0]);
                        modelComp.layout.posY = Convert.ToString(pos[1]);
                    }

                    // Searching for the event triggers and event listeners of a component
                    Asterics.ACS2.componentTypesComponentType bundleComponentEvents = (Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id];
                    // If component has version conflict, the events are already set by 'CopyFromBundleModel'
                    if ((bundleComponentEvents.events != null) && !modelComp.HasVersionConflict) {
                        foreach (object eventO in bundleComponentEvents.events) {
                            if (eventO is ACS2.eventsTypeEventListenerPortType) {
                                ACS2.eventsTypeEventListenerPortType compEl = (ACS2.eventsTypeEventListenerPortType)eventO;
                                EventListenerPort el = new EventListenerPort();
                                el.EventListenerId = compEl.id;
                                el.ComponentId = modelComp.id;
                                el.EventDescription = compEl.description;
                                modelComp.EventListenerList.Add(el);
                            }
                            else if (eventO is ACS2.eventsTypeEventTriggererPortType) {
                                ACS2.eventsTypeEventTriggererPortType compEl = (ACS2.eventsTypeEventTriggererPortType)eventO;
                                EventTriggerPort el = new EventTriggerPort();
                                el.EventTriggerId = compEl.id;
                                el.ComponentId = modelComp.id;
                                el.EventDescription = compEl.description;
                                modelComp.EventTriggerList.Add(el);
                            }
                        }
                    }

                    // if the component has no version conflict, it will be pasted on the layout, otherwise, it is already on the
                    // canvas (done by 'CopyFromBundleModel')
                    if (!modelComp.HasVersionConflict) {
                        // setting the mainRectangle and the portRectangles on the canvas
                        modelComp.InitGraphLayout(modelComp.id);
                    }
                    else {
                        //deploymentModel.components = deploymentComponentList.Values.ToArray();
                    }

                    // check, if the component has a confilct marker, but the VersionConflict is not set. This happens,
                    // if the version conflict occurs bacause of new ports
                    if (!modelComp.HasVersionConflict && modelComp.ComponentCanvas.Background != null) {
                        modelComp.HasVersionConflict = true;
                    }

                    canvas.Children.Add(modelComp.ComponentCanvas);
                    KeyboardNavigation.SetTabIndex(modelComp.ComponentCanvas, canvas.Children.Count + 1);
                    deploymentComponentList.Add(modelComp.id, modelComp);
                    // adding context menu
                    modelComp.MainRectangle.ContextMenu = componentContextMenu;
                    // adding keyboard focus listener
                    modelComp.ComponentCanvas.KeyDown += Component_KeyDown;
                    modelComp.ComponentCanvas.KeyUp += Component_KeyUp;
                    modelComp.ComponentCanvas.Focusable = true;
                    modelComp.ComponentCanvas.GotKeyboardFocus += ComponentCanvas_GotKeyboardFocus;
                    modelComp.ComponentCanvas.LostKeyboardFocus += ComponentCanvas_LostKeyboardFocus;

                    // adding property changed listener
                    modelComp.PropertyChanged += ComponentIntPropertyChanged;
                    modelComp.TopGrid.ContextMenu = componentContextMenu;
                    modelComp.TopRectangle.ContextMenu = componentContextMenu;
                    // set position of component on the canvas
                    Canvas.SetLeft(modelComp.ComponentCanvas, Int32.Parse(modelComp.layout.posX));
                    Canvas.SetTop(modelComp.ComponentCanvas, Int32.Parse(modelComp.layout.posY));

                    // Adapt the size of MainRectangle, if more then MAINRECTANGLENUMBEROFPORTS are in a component
                    int numInPorts = 0;
                    int numOutPorts = 0;
                    foreach (object objPort in modelComp.PortsList.Values) {
                        if (objPort is inputPortType) {
                            numInPorts++;
                        }
                        else {
                            numOutPorts++;
                        }
                    }
                    if (numOutPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                        modelComp.MainRectangle.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE);
                        modelComp.ComponentCanvas.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE);
                    }
                    else if (numInPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                        modelComp.MainRectangle.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
                        modelComp.ComponentCanvas.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
                    }
                    // Adapt the position of event trigger and event listener port, if the component has more input/output ports
                    if (modelComp.EventListenerList.Count > 0) {
                        Canvas.SetTop(modelComp.EventListenerPolygon.InputEventPortCanvas, modelComp.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
                    }
                    if (modelComp.EventTriggerList.Count > 0) {
                        Canvas.SetTop(modelComp.EventTriggerPolygon.OutputEventPortCanvas, modelComp.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
                    }
                }
                else {
                    MessageBox.Show(Properties.Resources.LoadComponentNotFoundFormat(modelComp.type_id), Properties.Resources.CopyPropertiesErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                    // removing the channels
                    if (deploymentModel.channels != null) {
                        List<channel> tempChannelList = deploymentModel.channels.ToList();
                        foreach (object oChannel in deploymentModel.channels) {
                            channel modChannel = (channel)oChannel;
                            if ((modChannel.source.component.id == modelComp.id) || (modChannel.target.component.id == modelComp.id)) {
                                tempChannelList.Remove(modChannel);
                            }
                        }
                        deploymentModel.channels = tempChannelList.ToArray();
                    }
                    // removing the eventchannels
                    if (deploymentModel.eventChannels != null) {
                        List<eventChannel> tempEventChannelList = deploymentModel.eventChannels.ToList();
                        foreach (object oEventChannel in deploymentModel.eventChannels) {
                            eventChannel modEventChannel = (eventChannel)oEventChannel;
                            if ((modEventChannel.sources.source.component.id == modelComp.id) || (modEventChannel.targets.target.component.id == modelComp.id)) {
                                tempEventChannelList.Remove(modEventChannel);
                            }
                        }
                        deploymentModel.eventChannels = tempEventChannelList.ToArray();
                    }
                }

                // check, if component has a gui component, and load the gui component
                if (modelComp.gui != null && ((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id]) != null) {
                    if (((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id]).gui.IsExternalGUIElementSpecified && ((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id]).gui.IsExternalGUIElement) {
                        modelComp.gui.IsExternalGUIElement = true;
                    } else {
                        modelComp.gui.IsExternalGUIElement = false;
                    }
                    AddGUIComponent(modelComp);
                }
            }
            deploymentModel.components = deploymentComponentList.Values.ToArray();

            // loading the channels
            if (deploymentModel.channels != null) {
                foreach (object o in deploymentModel.channels) {
                    channel modChannel = (channel)o;
                    // check versionconflict: add only channels to components without a conflict
                    if ((deploymentComponentList.ContainsKey(modChannel.source.component.id)) && (deploymentComponentList.ContainsKey(modChannel.target.component.id))) {

                        // one of the channels component has a conflict. Check, if port is available and datatype fits together
                        componentType tempCompOut = (componentType)deploymentComponentList[modChannel.source.component.id];
                        componentType tempCompIn = (componentType)deploymentComponentList[modChannel.target.component.id];
                        // try, if the ports are still available
                        if ((tempCompOut.PortsList.Contains(modChannel.source.port.id)) && (tempCompIn.PortsList.Contains(modChannel.target.port.id))) {
                            // check the datatypes of the ports, for the case, that they have been changed
                            if (CheckInteroperabilityOfPorts(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortDataType, ((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortDataType)) {
                                AddChannel(modChannel);
                                modChannel.Line.Y1 = Canvas.GetTop(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortRectangle) + Canvas.GetTop(tempCompOut.ComponentCanvas) + 5;
                                modChannel.Line.X1 = Canvas.GetLeft(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortRectangle) + Canvas.GetLeft(tempCompOut.ComponentCanvas) + 20;

                                modChannel.Line.Y2 = Canvas.GetTop(((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortRectangle) + Canvas.GetTop(tempCompIn.ComponentCanvas) + 5;
                                modChannel.Line.X2 = Canvas.GetLeft(((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortRectangle) + Canvas.GetLeft(tempCompIn.ComponentCanvas);
                                Canvas.SetZIndex(modChannel.Line, Canvas.GetZIndex(modChannel.Line) + 1000);
                            }
                            else {
                                // if no event listener Port can be found, the component has a version conflict
                                MessageBox.Show(Properties.Resources.CopyChannelsErrorTextFormat(tempCompOut.id, tempCompIn.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                tempCompIn.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompIn.HasVersionConflict = true;
                                tempCompOut.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompOut.HasVersionConflict = true;
                            }
                        }
                        else {
                            if (!tempCompOut.PortsList.Contains(modChannel.source.port.id)) {
                                MessageBox.Show(Properties.Resources.CopyChannelErrorNotFoundFormat(tempCompOut.id, tempCompIn.id, modChannel.source.port.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                tempCompOut.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompOut.HasVersionConflict = true;
                            }
                            else {
                                MessageBox.Show(Properties.Resources.CopyChannelErrorNotFoundFormat(tempCompOut.id, tempCompIn.id, modChannel.source.port.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                tempCompIn.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompIn.HasVersionConflict = true;
                            }
                        }

                    }
                }
            }

            // Loading the events and drawing the lines between the event ports
            if (deploymentModel.eventChannels != null) {
                bool foundLine = false;
                foreach (object o in deploymentModel.eventChannels) {
                    eventChannel evChannel = (eventChannel)o;
                    //if (!(((modelComponent)deploymentComponentList[evChannel.sources.source[0].component.id]).HasVersionConflict) && !(((modelComponent)deploymentComponentList[evChannel.targets.target[0].component.id]).HasVersionConflict)) {
                    bool foundTriggerPort = false;
                    bool foundListenerPort = false;
                    try {
                        foreach (EventTriggerPort checkEvent in ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).EventTriggerList) {
                            if (checkEvent.ComponentId == evChannel.sources.source.component.id && checkEvent.EventTriggerId == evChannel.sources.source.eventPort.id) {
                                foundTriggerPort = true;
                                break;
                            }
                        }
                        if (foundTriggerPort) {
                            foreach (EventListenerPort checkEvent in ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).EventListenerList) {
                                if (checkEvent.ComponentId == evChannel.targets.target.component.id && checkEvent.EventListenerId == evChannel.targets.target.eventPort.id) {
                                    foundListenerPort = true;
                                    break;
                                }
                            }
                            if (foundListenerPort) {
                                foreach (eventChannelLine channelLine in eventChannelLinesList) {
                                    if ((evChannel.sources.source.component.id == channelLine.TriggerComponentId) && (evChannel.targets.target.component.id == channelLine.ListenerComponentId)) {
                                        foundLine = true;
                                        break;
                                    }
                                }
                                if (!foundLine) {
                                    eventChannelLine eCL = new eventChannelLine();

                                    eCL.Line.X1 = Canvas.GetLeft(((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
                                    //eCL.Line.Y1 = Canvas.GetTop(((modelComponent)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
                                    eCL.Line.Y1 = Canvas.GetTop(((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) +
                                        ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).MainRectangle.Height + LayoutConstants.EVENTPORTHEIGHT + LayoutConstants.MAINRECTANGLEOFFSETY - 7;
                                    eCL.Line.X2 = Canvas.GetLeft(((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
                                    //eCL.Line.Y2 = Canvas.GetTop(((modelComponent)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
                                    eCL.Line.Y2 = Canvas.GetTop(((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) +
                                        ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).MainRectangle.Height + LayoutConstants.EVENTPORTHEIGHT + LayoutConstants.MAINRECTANGLEOFFSETY - 7;

                                    eCL.Line.Focusable = true;
                                    eCL.ListenerComponentId = evChannel.targets.target.component.id;
                                    eCL.TriggerComponentId = evChannel.sources.source.component.id;
                                    eCL.Line.GotKeyboardFocus += EventChannel_GotKeyboardFocus;
                                    eCL.Line.LostKeyboardFocus += EventChannel_LostKeyboardFocus;
                                    eCL.Line.KeyDown += EventChannel_KeyDown;
                                    eCL.Line.ContextMenu = eventChannelContextMenu;
                                    eventChannelLinesList.Add(eCL);
                                    canvas.Children.Add(eCL.Line);
                                    KeyboardNavigation.SetTabIndex(eCL.Line, canvas.Children.Count + 1);
                                    Canvas.SetZIndex(eCL.Line, Canvas.GetZIndex(eCL.Line) + 2000);
                                }
                                eventChannelList.Add(o);
                                foundLine = false;
                            }
                            else {
                                // if no event listener Port can be found, the component has a version conflict
                                MessageBox.Show(Properties.Resources.CopyEventsErrorTextFormat(evChannel.targets.target.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).HasVersionConflict = true;
                            }
                        }
                        else {
                            // if no event trigger Port can be found, the component has a version conflict
                            MessageBox.Show(Properties.Resources.CopyEventsErrorTextFormat(evChannel.sources.source.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                            ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                            ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).HasVersionConflict = true;
                        }
                    }
                    catch (Exception) {
                        MessageBox.Show(Properties.Resources.CopyEventsExceptionTextFormat(evChannel.sources.source.component.id, evChannel.sources.source.eventPort.id,
                            evChannel.targets.target.component.id, evChannel.targets.target.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
            }

            ClearSelectedChannelList();
            ClearSelectedEventChannelList();
            ClearSelectedComponentList();
            // loading the groups
            if (deploymentModel.groups != null) {
                foreach (group makeGroup in deploymentModel.groups) {
                    foreach (string id in makeGroup.componentId) {
                        AddSelectedComponent(deploymentComponentList[id]);
                    }
                    string groupName = DoGrouping(null, false, false);
                    componentType ct = deploymentComponentList[groupName];
                    backupIdForPropertyEditor = groupName;
                    ct.id = makeGroup.id;
                    // set the alias
                    if (makeGroup.portAlias != null) {
                        foreach (portAlias alias in makeGroup.portAlias) {
                            componentType groupToUpdate = deploymentComponentList[makeGroup.id];
                            foreach (object port in groupToUpdate.ports) {
                                if ((port is inputPortType) && (((inputPortType)port).portTypeID == alias.portId)) {
                                    ((inputPortType)port).PortAliasForGroups = alias.portAlias1;
                                    ((inputPortType)port).PortLabel.Text = alias.portAlias1;
                                    break;
                                }
                                else if ((port is outputPortType) && (((outputPortType)port).portTypeID == alias.portId)) {
                                    ((outputPortType)port).PortAliasForGroups = alias.portAlias1;
                                    ((outputPortType)port).PortLabel.Text = alias.portAlias1;
                                    break;
                                }
                            }
                        }
                    }
                    if (makeGroup.description != null) {
                        deploymentComponentList[makeGroup.id].description = makeGroup.description;
                    }
                    ClearSelectedChannelList();
                    ClearSelectedEventChannelList();
                    ClearSelectedComponentList();
                }
            }

            // clear the undo/redo stack
            undoStack.Clear();
            redoStack.Clear();

            // focus the first element
            if (canvas.Children.Count > 0) {
                Keyboard.Focus(canvas.Children[0]);
            }
            else {
                Keyboard.Focus(canvas);
            }
        }
Example #19
0
 /// <summary>
 /// Returns the target component of the given eventchannelline
 /// </summary>
 /// <param name="ec">Eventchannelline of which the target should be returned</param>
 /// <returns>Target of the given eventchannel</returns>
 private componentType GetEventChannelLineTarget(eventChannelLine ec)
 {
     foreach (componentType ct in deploymentComponentList.Values)
         if (ct.id.Equals(ec.ListenerComponentId))
             return ct;
     return null;
 }
Example #20
0
        /// <summary>
        /// Function called, if the left mouse button is pressed down on the canvas. This can cause several actions: move the component, draw a channel between ports or 
        /// draw an event channel between two event ports
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnLeftDown(object sender, MouseEventArgs args)
        {
            if (hiddenChannels) {
                SetAllChannelsVisible();
                hiddenChannels = false;
            }
            // four possibe actions:
            // select a component to move
            // connect the start point of a channel to an out-port
            // connect the end point of a channel to an in-port
            // fix a component after movement
            Point clickPoint = args.GetPosition(canvas);
            mouseMoveComponentX = (int)clickPoint.X;
            mouseMoveComponentY = (int)clickPoint.Y;

            connectedChannelLastClick = false;
            // sets a component to a new position
            // Line uncomment, to allow the drawing of channels just by clicking on the output port or the event trigger port
            //if ((newChannelRibbonButton.IsChecked == false) && (newEventChannelRibbonButton.IsChecked == false)) {
            if (args.Source is Canvas && ((Canvas)args.Source) == canvas && ModifierKeys.Control != Keyboard.Modifiers) {
                // whenever the user leaves the canvas with the mouse pointer, and stops holding the mousebutton, the mouseup
                // event will not get fired in this class. In this case the rectangle should not get modified
                // and work as before the user moved the mouse cursor outside the canvas.
                if (selectionRectangle == null) {
                    ClearSelectedComponentList();
                    ClearSelectedChannelList();
                    ClearSelectedEventChannelList();
                    ResetPropertyDock();
                    selectionRectangle = new Rectangle();
                    Canvas.SetZIndex(selectionRectangle, selRectZIndex);
                    selectionRectangle.Fill = new SolidColorBrush(Color.FromArgb(15, 0, 0, 255));
                    DoubleCollection dashes = new DoubleCollection();
                    dashes.Add(1.0000001);
                    dashes.Add(2.0000001);
                    selectionRectangle.StrokeDashArray = dashes;
                    selectionRectangle.Stroke = new SolidColorBrush(Colors.Black);
                    selectionRectangle.Width = 1;
                    selectionRectangle.Height = 1;
                    selRectStartPoint = args.GetPosition(canvas);
                    Canvas.SetLeft(selectionRectangle, selRectStartPoint.X);
                    Canvas.SetTop(selectionRectangle, selRectStartPoint.Y);
                    canvas.Children.Add(selectionRectangle);
                }
            }
            else if (args.Source is Rectangle) {
                //modelComponent tempComponent = null;
                if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                    foreach (componentType tempComponent in deploymentComponentList.Values) {
                        if ((tempComponent.MainRectangle == (Rectangle)args.Source) || (tempComponent.TopRectangle == (Rectangle)args.Source)) {
                            focusedComponent = tempComponent;
                            Keyboard.Focus(focusedComponent.ComponentCanvas);
                            if (!selectedComponentList.Contains(tempComponent)) {
                                ClearSelectedComponentList();
                                ClearSelectedChannelList();
                                ClearSelectedEventChannelList();
                                this.AddSelectedComponent(tempComponent);
                                moveComponentRibbonButton.IsChecked = true;
                                moveTracking = false;
                            }
                            break;
                        }
                        else {
                            if (newChannelRibbonButton.IsEnabled) // was editchannelribbongroup
                            {
                                foreach (object o in tempComponent.PortsList.Values) {
                                    if (o is outputPortType) {
                                        if (((outputPortType)o).PortRectangle == (Rectangle)args.Source) {
                                            //focusedComponent = tempComponent;
                                            //Keyboard.Focus(focusedComponent.ComponentCanvas);
                                            newChannelRibbonButton.IsChecked = true;
                                            //disable mouse move
                                            mouseMoveComponentX = -1;
                                            mouseMoveComponentY = -1;
                                            ClearSelectedChannelList();
                                            ClearSelectedComponentList();
                                            ClearSelectedEventChannelList();
                                            break;
                                        }
                                    }
                                    else if (o is inputPortType) {
                                        if (((inputPortType)o).PortRectangle == (Rectangle)args.Source) {
                                            //disable mouse move
                                            if (!selectedComponentList.Contains(tempComponent) && channelToConnect == null) {
                                                ClearSelectedComponentList();
                                                ClearSelectedChannelList();
                                                ClearSelectedEventChannelList();
                                                this.AddSelectedComponent(tempComponent);
                                                moveComponentRibbonButton.IsChecked = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (args.Source is TextBlock) {
                if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                    foreach (componentType tempComponent in deploymentComponentList.Values) {
                        if (tempComponent.Label == (TextBlock)args.Source) {
                            focusedComponent = tempComponent;
                            Keyboard.Focus(focusedComponent.ComponentCanvas);
                            if (!selectedComponentList.Contains(tempComponent)) {
                                ClearSelectedComponentList();
                                ClearSelectedChannelList();
                                ClearSelectedEventChannelList();
                                this.AddSelectedComponent(tempComponent);
                                moveComponentRibbonButton.IsChecked = true;
                            }
                            break;
                        }
                        else {
                            foreach (object o in tempComponent.PortsList.Values) {
                                if (o is inputPortType) {
                                    if (((inputPortType)o).PortLabel == (TextBlock)args.Source) {
                                        focusedComponent = tempComponent;
                                        Keyboard.Focus(focusedComponent.ComponentCanvas);
                                        if (!selectedComponentList.Contains(tempComponent)) {
                                            ClearSelectedComponentList();
                                            ClearSelectedChannelList();
                                            ClearSelectedEventChannelList();
                                            this.AddSelectedComponent(tempComponent);
                                            moveComponentRibbonButton.IsChecked = true;
                                        }
                                        break;
                                    }
                                }
                                else if (o is outputPortType) {
                                    if (((outputPortType)o).PortLabel == (TextBlock)args.Source) {
                                        focusedComponent = tempComponent;
                                        Keyboard.Focus(focusedComponent.ComponentCanvas);
                                        if (!selectedComponentList.Contains(tempComponent)) {
                                            ClearSelectedComponentList();
                                            ClearSelectedChannelList();
                                            ClearSelectedEventChannelList();
                                            this.AddSelectedComponent(tempComponent);
                                            moveComponentRibbonButton.IsChecked = true;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (args.Source is Polygon) {
                if (newEventChannelRibbonButton.IsEnabled) // was editeventribbongroup
                {
                    if (((Polygon)args.Source).Name == "EventTriggerPortPolygon") {
                        newEventChannelRibbonButton.IsChecked = true;
                        ClearSelectedEventChannelList();
                        ClearSelectedComponentList();
                        ClearSelectedChannelList();
                    }
                    else {
                        if (newEventChannelRibbonButton.IsChecked == false) { // mouse down on an event channel input, not in connect mode
                            if ((Keyboard.Modifiers & ModifierKeys.Control) == 0) {
                                foreach (componentType tempComponent in deploymentComponentList.Values) {
                                    Canvas tempCanvas = (Canvas)((Polygon)args.Source).Parent;
                                    if (tempComponent.ComponentCanvas == tempCanvas.Parent) {
                                        focusedComponent = tempComponent;
                                        Keyboard.Focus(focusedComponent.ComponentCanvas);
                                        if (!selectedComponentList.Contains(tempComponent)) {
                                            ClearSelectedComponentList();
                                            ClearSelectedChannelList();
                                            ClearSelectedEventChannelList();
                                            this.AddSelectedComponent(tempComponent);
                                            moveComponentRibbonButton.IsChecked = true;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (focusedComponent != null) {
                Canvas.SetZIndex(focusedComponent.ComponentCanvas, Canvas.GetZIndex(focusedComponent.ComponentCanvas) + 3000);
            }

            if (componentToMove == null && focusedComponent != null) {
                if (args.Source is Rectangle) {
                    if ((focusedComponent.MainRectangle == (Rectangle)args.Source) || (focusedComponent.TopRectangle == (Rectangle)args.Source)) {
                        componentToMove = focusedComponent;
                        offsetX = (int)args.GetPosition(canvas).X - (int)Canvas.GetLeft(focusedComponent.ComponentCanvas);
                        offsetY = (int)args.GetPosition(canvas).Y - (int)Canvas.GetTop(focusedComponent.ComponentCanvas);

                    }
                }
                else if (args.Source is TextBlock) {
                    if ((focusedComponent.ComponentCanvas == ((TextBlock)args.Source).Parent) || (focusedComponent.Label) == (TextBlock)args.Source) {
                        componentToMove = focusedComponent;
                        offsetX = (int)args.GetPosition(canvas).X - (int)Canvas.GetLeft(focusedComponent.ComponentCanvas);
                        offsetY = (int)args.GetPosition(canvas).Y - (int)Canvas.GetTop(focusedComponent.ComponentCanvas);
                    }
                }
                //MoveComponent(componentToMove, (int)args.GetPosition(canvas).X, (int)args.GetPosition(canvas).Y);
                //componentToMove = null;
            }
            //}
            if ((newChannelRibbonButton.IsChecked == true) && (newChannelRibbonButton.IsEnabled)) // was editchannelribbongroup
            {
                // outport has been found, component channel has been created, now searching for inport and make all connections/settings

                if (channelToConnect != null) {
                    if (args.Source is Rectangle) {
                        Rectangle r = (Rectangle)args.Source;
                        Canvas tempCanvas = (Canvas)r.Parent;
                        foreach (componentType tempComponent in deploymentComponentList.Values) {
                            if (tempComponent.ComponentCanvas == tempCanvas) {
                                bool portfound = false;
                                if (tempComponent.ports != null) {
                                    foreach (object o in tempComponent.ports) {
                                        if (o is inputPortType) {
                                            inputPortType inPort = (inputPortType)o;
                                            if ((inPort.PortRectangle == r) && (inPort.ChannelId == "")) {
                                                outputPortType outPort = (outputPortType)((componentType)deploymentComponentList[channelToConnect.source.component.id]).PortsList[channelToConnect.source.port.id];
                                                //outputPortType outPort = (outputPortType)((modelComponent)deploymentComponentList[channelToConnect.source.component.id]).ports.PortsList[]
                                                if (CheckInteroperabilityOfPorts(outPort.PortDataType, inPort.PortDataType)) {
                                                    channelToConnect.target.component.id = tempComponent.id;
                                                    channelToConnect.target.port.id = inPort.portTypeID;
                                                    channelToConnect.Line.X2 = Canvas.GetLeft(r) + Canvas.GetLeft(tempCanvas);
                                                    channelToConnect.Line.Y2 = Canvas.GetTop(r) + r.ActualHeight - r.ActualHeight / 2 + Canvas.GetTop(tempCanvas);
                                                    inPort.ChannelId = channelToConnect.id;
                                                    AddChannel(channelToConnect);
                                                    portfound = true;
                                                    Canvas.SetZIndex(channelToConnect.Line, Canvas.GetZIndex(channelToConnect.Line) + 1000);
                                                    CommandObject co = new CommandObject("Delete", channelToConnect);
                                                    undoStack.Push(co);
                                                    redoStack.Clear();
                                                    channelToConnect = null;
                                                    newChannelRibbonButton.IsChecked = false;
                                                    connectedChannelLastClick = true;
                                                    ChangeChannelVisibility(outPort.PortDataType, false, true, false);
                                                    break;
                                                }
                                                else {
                                                    MessageBox.Show(Properties.Resources.PortConnectingDatyTypeErrorFormat(outPort.PortDataType, inPort.PortDataType),
                                                        Properties.Resources.PortConnectingDatyTypeErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (portfound == false) {
                                    // click on a component while trying to connect a channel
                                    ClearSelectedChannelList();
                                    ClearSelectedComponentList();
                                    ClearSelectedEventChannelList();
                                    AddSelectedComponent(tempComponent);
                                    canvas.Children.Remove(channelToConnect.Line);
                                    channelToConnect = null;
                                    newChannelRibbonButton.IsChecked = false;
                                    //TODO: restore visibility of ports
                                }
                                break;
                            }
                        }
                        // click on the empty canvas, componentChannel will be deleted instead of connected
                    }
                    else {
                        canvas.Children.Remove(channelToConnect.Line);
                        channelToConnect = null;
                        newChannelRibbonButton.IsChecked = false;
                    }
                }

                 // searching an out-port for a new channel
                else if (args.Source is Rectangle) {
                    Rectangle r = (Rectangle)args.Source;

                    Canvas tempCanvas = (Canvas)r.Parent;
                    foreach (componentType tempComponent in deploymentComponentList.Values) {
                        if (tempComponent.ComponentCanvas == tempCanvas) {
                            foreach (object o in tempComponent.ports) {
                                if (o is outputPortType) {
                                    outputPortType outPort = (outputPortType)o;
                                    if (outPort.PortRectangle == r) {
                                        channelToConnect = new channel();
                                        channelToConnect.id = NewIdForChannel();
                                        channelToConnect.source.component.id = tempComponent.id;
                                        channelToConnect.source.port.id = outPort.portTypeID;
                                        //outPort.ChannelId = channelToConnect.id;
                                        channelToConnect.Line.X1 = Canvas.GetLeft(r) + r.ActualWidth + Canvas.GetLeft(tempCanvas);
                                        channelToConnect.Line.Y1 = Canvas.GetTop(r) + r.ActualHeight - r.ActualHeight / 2 + Canvas.GetTop(tempCanvas); // -5

                                        channelToConnect.Line.X2 = args.GetPosition(canvas).X;
                                        channelToConnect.Line.Y2 = args.GetPosition(canvas).Y;
                                        canvas.Children.Add(channelToConnect.Line);
                                        ChangeChannelVisibility(outPort.PortDataType, true, false, true);
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            else if ((newChannelRibbonButton.IsChecked == false) && (channelToConnect != null)) {
                // click on the empty canvas, componentChannel will be deleted instead of connected
                canvas.Children.Remove(channelToConnect.Line);
                channelToConnect = null;
                newChannelRibbonButton.IsChecked = false;
            }

            if ((newEventChannelRibbonButton.IsChecked == true) && (newEventChannelRibbonButton.IsEnabled)) // was editeventribbongroup
            {
                if (args.Source is Polygon) {
                    if (eventChannelToConnect == null) {
                        Polygon p = (Polygon)args.Source;
                        Canvas tempCanvas = (Canvas)p.Parent;
                        if (tempCanvas.Name == "EventTriggerPort") {
                            eventChannelToConnect = new eventChannelLine();
                            foreach (componentType tempComponent in deploymentComponentList.Values) {
                                if (tempComponent.ComponentCanvas == (Canvas)tempCanvas.Parent) {
                                    eventChannelToConnect.TriggerComponentId = tempComponent.id;
                                    break;
                                }
                            }
                            eventChannelToConnect.Line.X1 = Canvas.GetLeft((Canvas)tempCanvas.Parent) + Canvas.GetLeft(tempCanvas) + tempCanvas.Width / 2 + 2;
                            eventChannelToConnect.Line.Y1 = Canvas.GetTop((Canvas)tempCanvas.Parent) + Canvas.GetTop(tempCanvas) + tempCanvas.Height;

                            eventChannelToConnect.Line.X2 = args.GetPosition(canvas).X;
                            eventChannelToConnect.Line.Y2 = args.GetPosition(canvas).Y;
                            canvas.Children.Add(eventChannelToConnect.Line);
                        }

                    }
                    else {
                        // connect
                        Polygon p = (Polygon)args.Source;
                        Canvas tempCanvas = (Canvas)p.Parent;
                        if (tempCanvas.Name == "EventListenerPort") {
                            foreach (componentType tempComponent in deploymentComponentList.Values) {
                                if (tempComponent.ComponentCanvas == (Canvas)tempCanvas.Parent) {
                                    eventChannelToConnect.ListenerComponentId = tempComponent.id;
                                    break;
                                }
                            }
                            eventChannelToConnect.Line.X2 = Canvas.GetLeft((Canvas)tempCanvas.Parent) + Canvas.GetLeft(tempCanvas) + tempCanvas.ActualWidth / 2 + 2;
                            eventChannelToConnect.Line.Y2 = Canvas.GetTop((Canvas)tempCanvas.Parent) + Canvas.GetTop(tempCanvas) + tempCanvas.Height;
                            connectedChannelLastClick = true;
                            CommandObject co = new CommandObject("Delete", eventChannelToConnect);
                            undoStack.Push(co);
                            redoStack.Clear();
                            AddEventChannelCommand(eventChannelToConnect, true);
                            eventChannelToConnect = null;
                            newEventChannelRibbonButton.IsChecked = false;
                            ////dockManager.ActiveContent = dockableEventsTab;
                        }
                    }
                }
                else { // drop the eventChannelLine
                    if (eventChannelToConnect != null) {
                        canvas.Children.Remove(eventChannelToConnect.Line);
                        eventChannelToConnect = null;
                        newEventChannelRibbonButton.IsChecked = false;
                    }
                }
            }
            else if ((newEventChannelRibbonButton.IsChecked == false) && (eventChannelToConnect != null)) {
                // click on the empty canvas, eventChannel will be deleted instead of connected
                canvas.Children.Remove(eventChannelToConnect.Line);
                eventChannelToConnect = null;
                newEventChannelRibbonButton.IsChecked = false;
            }
        }
Example #21
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 #22
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);
        }