/// <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;
        }
        private void AddComponent(string typeId, bool forceTypeIDAsName, bool addToUndoStack, bool allowNamingDialog)
        {
            // generate an unique id and show this id in the naming dialogue or using this id when using automatic placement
            int counter = 0;
            String suggestID = null;
            Asterics.ACS2.componentTypesComponentType componentToAdd = (Asterics.ACS2.componentTypesComponentType)componentList[typeId];

            // check, if component is singleton
            bool canBeAdded = true;

            if (((Asterics.ACS2.componentTypesComponentType)componentList[typeId]).singleton) {
                List<string> componentTypeList = new List<string>();
                foreach (componentType comp in deploymentComponentList.Values) {
                    componentTypeList.Add(comp.type_id);
                }
                canBeAdded = !componentTypeList.Contains(componentToAdd.id);
            }

            if (canBeAdded) {
                if (forceTypeIDAsName == false) {
                    do {
                        counter++;
                        suggestID = componentToAdd.id + "." + counter;
                        suggestID = TrimComponentName(suggestID);
                    } while (deploymentComponentList.ContainsKey(suggestID));
                }
                else
                    suggestID = typeId;
                String newComponentId = null;

                // Show the naming dialog box only when set to do so in the options dialog
                if (showNamingDialogOnComponentInsert && allowNamingDialog) {
                    newComponentId = SetNameForComponentOnCanvas(suggestID);
                }
                else {
                    newComponentId = suggestID;
                }
                componentType selectedComponent;
                if (newComponentId != "") {
                    selectedComponent = componentType.CopyFromBundleModel(componentToAdd, newComponentId);

                    // adding the property changed listener to component properties
                    foreach (propertyType p in selectedComponent.PropertyArrayList) {
                        p.PropertyChanged += ComponentPropertyChanged;
                        p.PropertyChangeError += ComponentPropertyChangeError;
                    }
                    // adding the property changed listener to port properties
                    foreach (object port in selectedComponent.PortsList.Values) {
                        if (port is inputPortType) {
                            ((inputPortType)port).PropertyChanged += InputPortIntPropertyChanged;
                            foreach (propertyType p in ((inputPortType)port).PropertyArrayList) {
                                p.PropertyChanged += InPortPropertyChanged;
                                p.PropertyChangeError += ComponentPropertyChangeError;
                            }
                        }
                        else {
                            // update the alias for group ports via property changed listener
                            ((outputPortType)port).PropertyChanged += OutputPortIntPropertyChanged;
                            foreach (propertyType p in ((outputPortType)port).PropertyArrayList) {
                                p.PropertyChanged += OutPortPropertyChanged;
                                p.PropertyChangeError += ComponentPropertyChangeError;
                            }
                        }
                    }

                    int[] pos = ProperComponentCoordinates(40, 40);
                    int positionX = pos[0];
                    if (positionX < 0)
                        positionX = 0;
                    else if (positionX + selectedComponent.ComponentCanvas.Width > canvas.RenderSize.Width)
                        positionX = (int)(canvas.RenderSize.Width - selectedComponent.ComponentCanvas.Width);
                    int positionY = pos[1];
                    if (positionY < 0)
                        positionY = 0;
                    else if (positionY + selectedComponent.ComponentCanvas.Height > canvas.RenderSize.Height)
                        positionY = (int)(canvas.RenderSize.Height - selectedComponent.ComponentCanvas.Height);
                    selectedComponent.layout.posX = Convert.ToString(positionX);
                    selectedComponent.layout.posY = Convert.ToString(positionY);
                    focusedComponent = selectedComponent;

                    this.ClearAndAddSelectedComponent(selectedComponent);

                    AddComponent(selectedComponent);
                    if (addToUndoStack) {
                        CommandObject co = new CommandObject("Delete", selectedComponent);
                        undoStack.Push(co);
                        redoStack.Clear();
                    }

                    // Check, if component has GUI-elements and if, setting it on the GUI-editor
                    // check, if component has a gui component, and load the gui component

                    if (componentToAdd.gui != null) {
                        selectedComponent.gui = new guiType();
                        selectedComponent.gui.height = componentToAdd.gui.height;
                        selectedComponent.gui.width = componentToAdd.gui.width;
                        selectedComponent.gui.posX = "0";
                        selectedComponent.gui.posY = "0";
                        if (componentToAdd.gui.IsExternalGUIElementSpecified && componentToAdd.gui.IsExternalGUIElement) {
                            selectedComponent.gui.IsExternalGUIElement = true;
                        } else {
                            selectedComponent.gui.IsExternalGUIElement = false;
                        }
                        AddGUIComponent(selectedComponent);
                    }
                    //Keyboard.Focus(selectedComponent.ComponentCanvas);
                }
            }
            else {
                MessageBox.Show(Properties.Resources.SingletonErrorHeaderFormat(typeId), Properties.Resources.SingletonErrorDialogHeader, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        /// <summary>
        /// Function called, if the left mouse button is pressed down on the canvas. This can cause several actions: move the component, draw a channel between ports or 
        /// draw an event channel between two event ports
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnLeftDown(object sender, MouseEventArgs args)
        {
            if (hiddenChannels) {
                SetAllChannelsVisible();
                hiddenChannels = false;
            }
            // four possibe actions:
            // select a component to move
            // connect the start point of a channel to an out-port
            // connect the end point of a channel to an in-port
            // fix a component after movement
            Point clickPoint = args.GetPosition(canvas);
            mouseMoveComponentX = (int)clickPoint.X;
            mouseMoveComponentY = (int)clickPoint.Y;

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

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

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

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

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

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

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

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

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

                    }
                    else {
                        // connect
                        Polygon p = (Polygon)args.Source;
                        Canvas tempCanvas = (Canvas)p.Parent;
                        if (tempCanvas.Name == "EventListenerPort") {
                            foreach (componentType tempComponent in deploymentComponentList.Values) {
                                if (tempComponent.ComponentCanvas == (Canvas)tempCanvas.Parent) {
                                    eventChannelToConnect.ListenerComponentId = tempComponent.id;
                                    break;
                                }
                            }
                            eventChannelToConnect.Line.X2 = Canvas.GetLeft((Canvas)tempCanvas.Parent) + Canvas.GetLeft(tempCanvas) + tempCanvas.ActualWidth / 2 + 2;
                            eventChannelToConnect.Line.Y2 = Canvas.GetTop((Canvas)tempCanvas.Parent) + Canvas.GetTop(tempCanvas) + tempCanvas.Height;
                            connectedChannelLastClick = true;
                            CommandObject co = new CommandObject("Delete", eventChannelToConnect);
                            undoStack.Push(co);
                            redoStack.Clear();
                            AddEventChannelCommand(eventChannelToConnect, true);
                            eventChannelToConnect = null;
                            newEventChannelRibbonButton.IsChecked = false;
                            ////dockManager.ActiveContent = dockableEventsTab;
                        }
                    }
                }
                else { // drop the eventChannelLine
                    if (eventChannelToConnect != null) {
                        canvas.Children.Remove(eventChannelToConnect.Line);
                        eventChannelToConnect = null;
                        newEventChannelRibbonButton.IsChecked = false;
                    }
                }
            }
            else if ((newEventChannelRibbonButton.IsChecked == false) && (eventChannelToConnect != null)) {
                // click on the empty canvas, eventChannel will be deleted instead of connected
                canvas.Children.Remove(eventChannelToConnect.Line);
                eventChannelToConnect = null;
                newEventChannelRibbonButton.IsChecked = false;
            }
        }
 /// <summary>
 /// Adding the ARE window to the GUI editor
 /// </summary>
 private void AddAREGUIComponent()
 {
     modelCompGUIARE = new componentType();
     modelCompGUIARE.id = "ARE_GUI_WINDOW";
     modelCompGUIARE.gui = new guiType();
     if (deploymentModel.modelGUI == null) {
         NewAREGUIWindow();
     }
     modelCompGUIARE.gui.width = deploymentModel.modelGUI.AREGUIWindow.width;
     modelCompGUIARE.gui.height = deploymentModel.modelGUI.AREGUIWindow.height;
     modelCompGUIARE.gui.posX = deploymentModel.modelGUI.AREGUIWindow.posX;
     modelCompGUIARE.gui.posY = deploymentModel.modelGUI.AREGUIWindow.posY;
     AddGUIComponent(modelCompGUIARE);
     guiProp.Decoration = deploymentModel.modelGUI.Decoration;
     guiProp.Fullscreen = deploymentModel.modelGUI.Fullscreen;
     guiProp.AlwaysOnTop = deploymentModel.modelGUI.AlwaysOnTop;
     guiProp.ToSystemTray = deploymentModel.modelGUI.ToSystemTray;
     guiProp.ShowControlPanel = deploymentModel.modelGUI.ShopControlPanel;
 }
        /// <summary>
        /// Left mouse button down on the GUICanvas
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnLeftDownGUI(object sender, MouseEventArgs args)
        {
            if (args.Source is Rectangle) {
                guiSelectedCanvas = (Canvas)((Rectangle)args.Source).Parent;
            }
            else if (args.Source is TextBlock) {
                guiSelectedCanvas = (Canvas)((TextBlock)args.Source).Parent;
            }
            else if (args.Source is Polygon) {
                guiSelectedCanvas = (Canvas)((Polygon)args.Source).Parent;
                guiElementResize = true;
            }
            if (guiSelectedCanvas != null) {
                // special condition, if mouse is pressed over the ARE element
                if (guiSelectedCanvas.Name.Equals("guiCanvasARE")) {
                    guiSelectedModelComponent = modelCompGUIARE;
                    foreach (UIElement uie in guiSelectedCanvas.Children) {
                        if (uie is Rectangle) {
                            guiSelectedRectangle = (Rectangle)uie;
                            break;
                        }
                    }
                }
                else {
                    // search the rectangle, selected when mouse button is pressed
                    foreach (componentType tempComponent in deploymentComponentList.Values) {
                        if ((tempComponent.gui != null) && (tempComponent.gui.GuiElementCanvas == guiSelectedCanvas)) {
                            guiSelectedModelComponent = tempComponent;
                            foreach (UIElement uie in guiSelectedCanvas.Children) {
                                if (uie is Rectangle) {
                                    guiSelectedRectangle = (Rectangle)uie;
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }

                guiOffsetX = (int)args.GetPosition(guiSelectedCanvas).X;
                guiOffsetY = (int)args.GetPosition(guiSelectedCanvas).Y;

                if (guiCanvas.Children.Count > 0) {
                    Keyboard.Focus(guiCanvas.Children[0]);
                }
            }
        }
        /// <summary>
        /// Set the property editors and the tabs in the property dock
        /// </summary>
        /// <param name="tempComponent">The component, which will be displayed</param>
        private void SetPropertyDock(componentType tempComponent)
        {
            if (tempComponent != null) {
                backupIdForPropertyEditor = tempComponent.id;
                WPG.PropertyGrid pe = new WPG.PropertyGrid();
                pe.Instance = tempComponent;
                pe.DisplayName = tempComponent.id;
                pe.ShowPreview = false;

                if (dockableComponentProperties.ContainerPane.ActualWidth > 15) {
                    pe.Width = dockableComponentProperties.ContainerPane.ActualWidth - 15;
                }
                if (dockableComponentProperties.ContainerPane.ActualHeight > 48) {
                    pe.Height = dockableComponentProperties.ContainerPane.ActualHeight - 48;
                }
                propertyDockScrollViewer.Content = pe;

                pe.GotKeyboardFocus += new KeyboardFocusChangedEventHandler(PropertyEditor_GotKeyboardFocus);
                KeyboardNavigation.SetTabNavigation(dockableInportsList, KeyboardNavigationMode.Continue);
                // Keyboard navigation within the list has to be done with the arrow-keys. A better solution might be here:
                // http://social.msdn.microsoft.com/Forums/en/wpf/thread/daca7b71-2893-4564-8379-097aabcdd553

                dockableInportsList.Items.Clear();
                dockableOutportsList.Items.Clear();

                foreach (object o in tempComponent.PortsList.Values) {
                    WPG.PropertyGrid pe2 = new WPG.PropertyGrid();
                    pe2.Instance = o;
                    pe2.ShowPreview = false;
                    pe2.IsTabStop = true;
                    //KeyboardNavigation.SetTabNavigation(pe2, KeyboardNavigationMode.Continue);
                    pe2.Margin = new Thickness(-35, 0, 0, 0);
                    if (dockableComponentProperties.ContainerPane.ActualWidth > 15) {
                        pe2.Width = dockableComponentProperties.ContainerPane.ActualWidth - 15;
                    }
                    //pe2.BorderBrush = new SolidColorBrush(Colors.Black);
                    //pe2.BorderThickness = new Thickness(1, 1, 1, 1);

                    if (o is inputPortType) {
                        dockableInportsList.Items.Add(new TreeViewItem() {
                            Header = ((inputPortType)o).portTypeID , IsTabStop = true, IsExpanded = true
                        });
                        pe2.DisplayName = ((inputPortType)o).portTypeID;
                        ((TreeViewItem)dockableInportsList.Items[dockableInportsList.Items.Count - 1]).Items.Add(pe2);
                        pe2.TabIndex = dockableInportsList.Items.Count + 58;
                    }
                    else {
                        dockableOutportsList.Items.Add(new TreeViewItem() {
                            Header = ((outputPortType)o).portTypeID, IsTabStop = true, IsExpanded = true
                        });
                        pe2.DisplayName = ((outputPortType)o).portTypeID;
                        ((TreeViewItem)dockableOutportsList.Items[dockableOutportsList.Items.Count - 1]).Items.Add(pe2);
                    }
                }
                dockableComponentProperties.Visibility = Visibility.Visible;
                // Tab 'Input Ports' just available, if the component has input ports
                if (dockableInportsList.Items.Count == 0) {
                    dockableInportsTab.Visibility = Visibility.Collapsed;
                }
                else {
                    dockableInportsTab.Visibility = Visibility.Visible;
                }
                // Tab 'Output Ports' just available, if the component has output ports
                if (dockableOutportsList.Items.Count == 0) {
                    dockableOutportsTab.Visibility = Visibility.Collapsed;
                }
                else {
                    dockableOutportsTab.Visibility = Visibility.Visible;
                }

                // Tab 'Event Listeners' just available, if the component has event listeners
                if (tempComponent.EventListenerList.Count == 0) {
                    dockableEventListenerTab.Visibility = Visibility.Collapsed;
                }
                else {
                    eventListenerDockScrollViewer.Content = SetListnerTriggerList(true, tempComponent);
                    dockableEventListenerTab.Visibility = Visibility.Visible;
                }
                // Tab 'Event Triggers' just available, if the component has event triggers
                if (tempComponent.EventTriggerList.Count == 0) {
                    dockableEventTriggerTab.Visibility = Visibility.Collapsed;
                }
                else {
                    eventTriggerDockScrollViewer.Content = SetListnerTriggerList(false, tempComponent);
                    dockableEventTriggerTab.Visibility = Visibility.Visible;
                }

                dockableEventsTab.Visibility = Visibility.Collapsed;
                dockManager.ActiveDocument = dockableComponentProperties;
            }
        }
 /// <summary>
 /// Removing one element from the GUI canvas
 /// </summary>
 /// <param name="modelComp">Component which contains the GUI element that should be removed</param>
 private void RemoveGUIComponent(componentType modelComp)
 {
     guiCanvas.Children.Remove(modelComp.gui.GuiElementCanvas);
     CalcMaxXandYofGUI();
 }
        /// <summary>
        /// The 'move' functionality, called from the component context menu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ComponentContextMenuItemMove_Click(object sender, RoutedEventArgs e)
        {
            // Check, if context menu was called from a rectangel
            if (((ContextMenu)((MenuItem)e.Source).Parent).PlacementTarget is Rectangle) {
                Rectangle r = (Rectangle)((ContextMenu)((MenuItem)e.Source).Parent).PlacementTarget;
                foreach (componentType tempComponent in deploymentComponentList.Values) {
                    if ((tempComponent.MainRectangle == r) || (tempComponent.TopRectangle == r)) {
                        componentToMove = tempComponent;
                        //CommandObject co = CreateMoveCommandObject();
                        //undoStack.Push(co);
                        //redoStack.Clear();
                        break;
                    }
                }
                // Check, if context menu was called from a grid (the name field at the top of a component)
            }
            else if (((ContextMenu)((MenuItem)e.Source).Parent).PlacementTarget is Grid) {
                Grid g = (Grid)((ContextMenu)((MenuItem)e.Source).Parent).PlacementTarget;
                foreach (componentType tempComponent in deploymentComponentList.Values) {
                    if (tempComponent.TopGrid == g) {
                        componentToMove = tempComponent;
                        //CommandObject co = CreateMoveCommandObject();
                        //undoStack.Push(co);
                        //redoStack.Clear();
                        break;
                    }
                }
            }

            moveComponentRibbonButton.IsChecked = true;
        }
        /// <summary>
        /// Key event on a component. The following actions are possible: open context menu,
        /// move component, end move operation, tab to next element, delete component
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Component_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space) { // || e.Key == Key.Apps)
                e.Handled = true;
                if (Keyboard.Modifiers == ModifierKeys.Control) {
                    if (selectedComponentList.Contains(focusedComponent)) {
                        ClearBorderOfSelectedComponents();
                        selectedComponentList.Remove(focusedComponent);
                        UpdateSelectedComponents();
                    }
                    else
                        AddSelectedComponent(focusedComponent);

                }
                else {
                    if (!selectedComponentList.Contains(focusedComponent)) {
                        ClearSelectedComponentList();
                        ClearSelectedChannelList();
                        ClearSelectedEventChannelList();
                        AddSelectedComponent(focusedComponent);
                    }
                }
            }
            else if (e.Key == Key.Up) {
                if (componentToMove != null) {
                    e.Handled = true;
                    //MoveComponent(componentToMove, (int)Canvas.GetLeft(componentToMove.ComponentCanvas) + offsetX, (int)Canvas.GetTop(componentToMove.ComponentCanvas) - 2 + offsetY );
                    foreach (componentType mc in selectedComponentList)
                        MoveComponent(mc, (int)Canvas.GetLeft(mc.ComponentCanvas) + offsetX, (int)Canvas.GetTop(mc.ComponentCanvas) - 2 + offsetY);
                }
            }
            else if (e.Key == Key.Down) {
                if (componentToMove != null) {
                    e.Handled = true;
                    //MoveComponent(componentToMove, (int)Canvas.GetLeft(componentToMove.ComponentCanvas) + offsetX, (int)Canvas.GetTop(componentToMove.ComponentCanvas) + 2 + offsetY);
                    foreach (componentType mc in selectedComponentList)
                        MoveComponent(mc, (int)Canvas.GetLeft(mc.ComponentCanvas) + offsetX, (int)Canvas.GetTop(mc.ComponentCanvas) + 2 + offsetY);
                }
            }
            else if (e.Key == Key.Left) {
                if (componentToMove != null) {
                    e.Handled = true;
                    //MoveComponent(componentToMove, (int)Canvas.GetLeft(componentToMove.ComponentCanvas) - 2 + offsetX, (int)Canvas.GetTop(componentToMove.ComponentCanvas) + offsetY);
                    foreach (componentType mc in selectedComponentList)
                        MoveComponent(mc, (int)Canvas.GetLeft(mc.ComponentCanvas) - 2 + offsetX, (int)Canvas.GetTop(mc.ComponentCanvas) + offsetY);

                }
            }
            else if (e.Key == Key.Right) {
                if (componentToMove != null) {
                    e.Handled = true;
                    //MoveComponent(componentToMove, (int)Canvas.GetLeft(componentToMove.ComponentCanvas) + 2 + offsetX, (int)Canvas.GetTop(componentToMove.ComponentCanvas) + offsetY);
                    foreach (componentType mc in selectedComponentList)
                        MoveComponent(mc, (int)Canvas.GetLeft(mc.ComponentCanvas) + 2 + offsetX, (int)Canvas.GetTop(mc.ComponentCanvas) + offsetY);
                }
            }
            else if (e.Key == Key.Enter) {
                if (componentToMove != null) {
                    componentToMove = null;
                    moveComponentRibbonButton.IsChecked = false;
                }
            }
            else if (e.Key == Key.Tab) {
                if (componentToMove != null) {
                    componentToMove = null;
                }
                //} else if (e.Key == Key.Delete) {
                //    e.Handled = true;
                //    DeleteSelectedComponents();
                //} else if (e.Key == Key.C) {
                //    if (ModifierKeys.Control == e.KeyboardDevice.Modifiers)
                //        CopySelectedCommand();
                //} else if (e.Key == Key.V) {
                //    if (ModifierKeys.Control == e.KeyboardDevice.Modifiers) {
                //        model tmpModel = CopyModel(copyModel);
                //        PasteCopiedModel();
                //        copyModel = tmpModel;
                //        e.Handled = true;
                //    }
                //} else if (e.Key == Key.A && ModifierKeys.Control == e.KeyboardDevice.Modifiers) {
                //    SelectAll();
            }
        }
Example #10
0
        /// <summary>
        /// A component got the focus. Several functions are triggerd in that case:
        /// 1. Dashed line around the component canvas
        /// 2. Activate several buttons in the ribbon menu (move, delete, properties)
        /// 3. Set the property editors in the property-dock (by calling SetPropertyDock(modelComponent tempComponent))
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ComponentCanvas_GotKeyboardFocus(object sender, KeyboardEventArgs e)
        {
            Canvas focusCanvas = (Canvas)sender;
            bool abort = false;
            foreach (UIElement uie in focusCanvas.Children) {
                if ((uie is Rectangle) && (((Rectangle)uie).Name.Equals("keyboardFocusRectangle"))) {
                    abort = true;
                    break;
                }
            }
            if (!abort) {
                double canvasX = Canvas.GetLeft(focusCanvas);
                double canvasY = Canvas.GetTop(focusCanvas);
                //focusCanvas.Background = new SolidColorBrush(Colors.Red);

                Rectangle cr = new Rectangle();
                cr.Stroke = new SolidColorBrush(Colors.Blue);
                cr.StrokeThickness = 2;
                /*DoubleCollection dashes = new DoubleCollection();
                dashes.Add(1.0000001);
                dashes.Add(2.0000001);
                cr.StrokeDashArray = dashes;*/
                cr.Width = focusCanvas.Width;
                cr.Height = focusCanvas.Height;
                focusCanvas.Children.Add(cr);
                Canvas.SetTop(cr, 0);
                Canvas.SetLeft(cr, 0);
                cr.Name = "keyboardFocusRectangle";
                cr.RadiusX = 4;
                cr.RadiusY = 4;
            }
            Canvas.SetZIndex(focusCanvas, Canvas.GetZIndex(focusCanvas) + 3000);

            moveComponentRibbonButton.IsEnabled = true;
            //deleteComponentRibbonButton.IsEnabled = true;
            componentPropertiesRibbonButton.IsEnabled = true;

            componentType tempComponent = null;
            foreach (componentType tempComponent2 in deploymentComponentList.Values) {
                if (tempComponent2.ComponentCanvas == (Canvas)sender) {
                    tempComponent = tempComponent2;
                    break;
                }
            }
            focusedComponent = tempComponent;
            SetPropertyDock(tempComponent);
        }
Example #11
0
 // Function, when a component lost the focus
 /// <summary>
 /// A component lost the focus. Two functions are triggerd in that case:
 /// 1. Remove dashed line around the component canvas
 /// 2. Deactivate several buttons in the ribbon menu (move, delete, properties)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void ComponentCanvas_LostKeyboardFocus(object sender, KeyboardEventArgs e)
 {
     Canvas focusCanvas = (Canvas)sender;
     Canvas.SetZIndex(focusCanvas, Canvas.GetZIndex(focusCanvas) - 3000);
     focusedComponent = null;
     foreach (UIElement uie in focusCanvas.Children) {
         if ((uie is Rectangle) && (((Rectangle)uie).Name.Equals("keyboardFocusRectangle"))) {
             focusCanvas.Children.Remove((Rectangle)uie);
             moveComponentRibbonButton.IsEnabled = false;
             //deleteComponentRibbonButton.IsEnabled = false;
             componentPropertiesRibbonButton.IsEnabled = false;
             moveComponentRibbonButton.IsChecked = false;
             break;
         }
     }
 }
Example #12
0
 /// <summary>
 /// Deselects all components which are selected and only selects the given component
 /// </summary>
 /// <param name="mc">Component to select</param>
 private void ClearAndAddSelectedComponent(componentType mc)
 {
     ClearSelectedComponentList();
     if (!selectedComponentList.Contains(mc))
         selectedComponentList.AddLast(mc);
     UpdateSelectedComponents();
 }
Example #13
0
 /// <summary>
 /// Additionally select the given component
 /// </summary>
 /// <param name="mc">Component to select</param>
 private void AddSelectedComponent(componentType mc)
 {
     if (!selectedComponentList.Contains(mc))
         selectedComponentList.AddLast(mc);
     if (mc.ComponentType == ACS2.componentTypeDataTypes.group) {
         groupComponent gc = null;
         if (groupsList.ContainsKey(mc.id)) {
             gc = groupsList[mc.id];
             foreach (componentType ct in gc.AddedComponentList) {
                 AddSelectedComponent(ct);
             }
             foreach (channel c in gc.AddedChannelsList) {
                 AddSelectedChannel(c);
             }
             foreach (eventChannelLine ec in gc.AddedEventChannelsList) {
                 AddSelectedEventChannel(ec);
             }
         }
     }
     UpdateSelectedComponents();
 }
Example #14
0
        /// <summary>
        /// Add a component to the canvas and the data model.
        /// </summary>
        /// <param name="newComponent"></param>
        private void AddComponent(componentType newComponent)
        {
            canvas.Children.Add(newComponent.ComponentCanvas);

            Canvas.SetLeft(newComponent.ComponentCanvas, Int32.Parse(newComponent.layout.posX));
            Canvas.SetTop(newComponent.ComponentCanvas, Int32.Parse(newComponent.layout.posY));

            // adding the context menu
            newComponent.MainRectangle.ContextMenu = componentContextMenu;
            newComponent.TopGrid.ContextMenu = componentContextMenu;
            newComponent.TopRectangle.ContextMenu = componentContextMenu;
            // adding keyboard focus listener
            newComponent.ComponentCanvas.KeyDown += Component_KeyDown;
            newComponent.ComponentCanvas.KeyUp += Component_KeyUp;
            newComponent.ComponentCanvas.Focusable = true;

            // adding property changed listener
            newComponent.PropertyChanged += ComponentIntPropertyChanged;
            newComponent.ComponentCanvas.GotKeyboardFocus += ComponentCanvas_GotKeyboardFocus;
            newComponent.ComponentCanvas.LostKeyboardFocus += ComponentCanvas_LostKeyboardFocus;
            // add the new component to the ArrayList (which will be used for faster internal access and manipulation)
            deploymentComponentList.Add(newComponent.id, newComponent);
            // adding the new component to the components-array (required for the schema consistency)
            deploymentModel.components = deploymentComponentList.Values.ToArray();
            //FocusManager.SetIsFocusScope(newComponent.ComponentCanvas, true);
            Keyboard.Focus(newComponent.ComponentCanvas);
            KeyboardNavigation.SetTabIndex(newComponent.ComponentCanvas, canvas.Children.Count + 1);
            ClearSelectedEventChannelList();
            ClearSelectedComponentList();
            ClearSelectedChannelList();
            AddSelectedComponent(newComponent);
            modelHasBeenEdited = true;
            if (newComponent.gui != null) {
                if (((Asterics.ACS2.componentTypesComponentType)componentList[newComponent.type_id]).gui.IsExternalGUIElementSpecified && ((Asterics.ACS2.componentTypesComponentType)componentList[newComponent.type_id]).gui.IsExternalGUIElement) {
                    newComponent.gui.IsExternalGUIElement = true;
                } else {
                    newComponent.gui.IsExternalGUIElement = false;
                }
                AddGUIComponent(newComponent);
            }
        }
Example #15
0
        /// <summary>
        /// Set the event tab (and the event lists) in the property dock
        /// </summary>
        /// <param name="sourceComponent">The component with the event triggers</param>
        /// <param name="targetComponent">The component with the event listeners</param>
        private void SetEventPropertyDock(componentType sourceComponent, componentType targetComponent)
        {
            ArrayList eventTriggers = sourceComponent.EventTriggerList;
            ArrayList eventListeners = targetComponent.EventListenerList;

            // workaround: when dockable event tab is active and will be selected again, the tab is
            // "some kind of" unselected
            dockableComponentProperties.Visibility = Visibility.Visible;
            dockManager.ActiveDocument = dockableComponentProperties;

            // Tab for Events
            dockableComponentProperties.Visibility = Visibility.Collapsed;
            dockableInportsTab.Visibility = Visibility.Collapsed;
            dockableOutportsTab.Visibility = Visibility.Collapsed;
            dockableEventListenerTab.Visibility = Visibility.Collapsed;
            dockableEventTriggerTab.Visibility = Visibility.Collapsed;
            if (eventTriggers.Count > 0 || eventListeners.Count > 0) {
                dockableEventsTab.Visibility = Visibility.Visible;
                // ActiveContent moves focus to dockManager, ActiveDocument just set the selected tab
                dockManager.ActiveDocument = dockableEventsTab;
            }
            else {
                dockableEventsTab.Visibility = Visibility.Collapsed;
            }
            GridLengthConverter glc = new GridLengthConverter();
            dockEventGrid.Children.Clear();
            dockEventGrid.RowDefinitions.Clear();
            dockEventGrid.Width = dockableComponentProperties.ContainerPane.ActualWidth - 15;

            // Setting the heading for the events Tab
            BrushConverter bc = new BrushConverter();
            dockEventGrid.RowDefinitions.Add(new RowDefinition() {
                Height = (GridLength)glc.ConvertFromString("28")
            });
            TextBox headingListener = new TextBox() {
                Text = targetComponent.id,
                Margin = new Thickness(0, 0, 0, 0),
                FontWeight = FontWeights.Bold,
                FontSize = 12,
                FontFamily = new FontFamily("Segoe UI"),
                IsReadOnly = true,
                Background = (Brush)bc.ConvertFrom("#FFE9ECFA")
            };
            TextBox headingTrigger = new TextBox() {
                Text = sourceComponent.id,
                Margin = new Thickness(0, 0, 0, 0),
                FontWeight = FontWeights.Bold,
                FontSize = 12,
                FontFamily = new FontFamily("Segoe UI"),
                IsReadOnly = true,
                Background = (Brush)bc.ConvertFrom("#FFE9ECFA")
            };
            Grid.SetRow(headingListener, 0);
            Grid.SetColumn(headingListener, 0);
            Grid.SetRow(headingTrigger, 0);
            Grid.SetColumn(headingTrigger, 1);
            dockEventGrid.Children.Add(headingTrigger);
            dockEventGrid.Children.Add(headingListener);
            Border headline = new Border();
            Grid.SetColumn(headline, 0);
            Grid.SetRow(headline, 0);
            Grid.SetColumnSpan(headline, 2);
            headline.BorderBrush = (Brush)bc.ConvertFrom("#FFE9ECFA");
            //headline.BorderBrush = Brushes.Black;
            headline.BorderThickness = new Thickness(1);
            dockEventGrid.Children.Add(headline);

            int eventListenerIndex = 0;
            int rowCounter = 1;
            ArrayList settedEvents = (ArrayList)eventChannelList.Clone();
            while (eventListenerIndex < eventListeners.Count) {
                EventListenerPort eventListener = (EventListenerPort)eventListeners[eventListenerIndex];
                eventListenerIndex++;
                dockEventGrid.RowDefinitions.Add(new RowDefinition() {
                    Height = (GridLength)glc.ConvertFromString("22")
                });
                TextBox l = new TextBox() {
                    Text = eventListener.EventListenerId,
                    Margin = new Thickness(0, 0, 0, 0),
                    FontSize = 12,
                    FontFamily = new FontFamily("Segoe UI"),
                    IsReadOnly = true,
                    ToolTip = eventListener.EventDescription
                };
                ComboBox eventCombobox = new ComboBox();
                eventCombobox.Name = "eventCombobox" + (eventListenerIndex - 1);//+ rowCounter;

                // original code, without tooltip
                // eventCombobox.Items.Add("---");

                // new code for tooltips
                // several changes in EventCombobox_SelectionChanged also needed
                eventCombobox.Items.Add(new ComboBoxItem() { Content = "---" });

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

                    // original code, without tooltip
                    // eventCombobox.Items.Add(eventTrigger.EventTriggerId);
                }

                // original code, without tooltip
                //eventCombobox.SelectedItem = "---";

                // new code for tooltips
                eventCombobox.SelectedItem = eventCombobox.Items[0];

                eventCombobox.KeyDown += EventCombobox_KeyDown;
                eventChannel eventToRemove = null;
                // load events and connect them
                foreach (eventChannel eventCh in settedEvents) {
                    if ((eventCh.sources.source.component.id == sourceComponent.id) && (eventCh.targets.target.component.id == targetComponent.id)
                            && (eventCh.targets.target.eventPort.id == eventListener.EventListenerId)) {

                        // new code for tooltips
                        foreach (ComboBoxItem cbi in eventCombobox.Items) {
                            if ((string)cbi.Content == eventCh.sources.source.eventPort.id) {
                                eventCombobox.SelectedItem = cbi;
                                eventCombobox.ToolTip = cbi.ToolTip;
                                break;
                            }
                        }

                        // original code, without tooltip
                        // eventCombobox.SelectedItem = eventCh.sources.source.eventPort.id;

                        eventListenerIndex--;
                        eventToRemove = eventCh;
                        break;
                    }
                }
                if (eventToRemove != null) {
                    settedEvents.Remove(eventToRemove);
                    eventToRemove = null;
                }

                eventCombobox.SelectionChanged += EventCombobox_SelectionChanged;
                Grid.SetRow(l, rowCounter);
                Grid.SetColumn(l, 0);
                Grid.SetRow(eventCombobox, rowCounter);
                Grid.SetColumn(eventCombobox, 1);
                GridSplitter mySimpleGridSplitter = new GridSplitter();
                mySimpleGridSplitter.Background = Brushes.DarkGray;
                mySimpleGridSplitter.HorizontalAlignment = HorizontalAlignment.Right;
                mySimpleGridSplitter.VerticalAlignment = VerticalAlignment.Stretch;
                mySimpleGridSplitter.Width = 1;
                Grid.SetColumn(mySimpleGridSplitter, 0);
                Grid.SetRow(mySimpleGridSplitter, rowCounter);
                dockEventGrid.Children.Add(l);
                dockEventGrid.Children.Add(eventCombobox);
                if (!newEventChannelRibbonButton.IsEnabled) // was editeventribbongroup
                {
                    eventCombobox.IsEnabled = false;
                }
                dockEventGrid.Children.Add(mySimpleGridSplitter);

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

                rowCounter++;
            }
        }
Example #16
0
        /// <summary>
        /// Delete a component from the canvas and the data model
        /// </summary>
        /// <param name="deleteComponent"></param>
        private void DeleteComponent(componentType deleteComponent)
        {
            // delete the component

            canvas.Children.Remove(deleteComponent.ComponentCanvas);
            if (deleteComponent.gui != null) {
                RemoveGUIComponent(deleteComponent);
            }
            if (deleteComponent.ComponentType == ACS2.componentTypeDataTypes.group) {
                LinkedList<group> deploymentGroups = new LinkedList<group>();
                foreach (group g in deploymentModel.groups) {
                    if (g.id.Equals(deleteComponent.id) == false) {
                        deploymentGroups.AddLast(g);
                    }
                }
                deploymentModel.groups = deploymentGroups.ToArray();
                groupsList.Remove(deleteComponent.id);
            }
            deploymentComponentList.Remove(deleteComponent.id);
            // set the array with the new amount of components
            deploymentModel.components = deploymentComponentList.Values.ToArray();
            // set the array with the new amount of channels, in the case, any channels have been deleted
            deploymentModel.channels = deploymentChannelList.Values.ToArray();
            deleteComponent.ComponentCanvas.KeyDown -= Component_KeyDown;
            deleteComponent.ComponentCanvas.KeyUp -= Component_KeyUp;

            deleteComponent.PropertyChanged -= ComponentIntPropertyChanged;
            deleteComponent.ComponentCanvas.GotKeyboardFocus -= ComponentCanvas_GotKeyboardFocus;
            deleteComponent.ComponentCanvas.LostKeyboardFocus -= ComponentCanvas_LostKeyboardFocus;

            modelHasBeenEdited = true;
        }
Example #17
0
        /// <summary>
        /// Sets up a grid with a list of event listeners or triggers, belonging to one component
        /// </summary>
        /// <param name="isListener">True, is list is of event listeners, otherwise event triggers</param>
        /// <param name="modelComp">The component, of thich the events should be listed</param>
        /// <returns></returns>
        private Grid SetListnerTriggerList(bool isListener, componentType modelComp)
        {
            Grid eventGrid = new Grid();

            eventGrid.MinWidth = 200;
            eventGrid.Background = new SolidColorBrush(Colors.White);
            ColumnDefinition labelListenerColDef = new ColumnDefinition();
            ColumnDefinition comboListenerColDef = new ColumnDefinition();
            eventGrid.ColumnDefinitions.Add(labelListenerColDef);
            eventGrid.ColumnDefinitions.Add(comboListenerColDef);
            eventGrid.HorizontalAlignment = HorizontalAlignment.Left;
            eventGrid.VerticalAlignment = VerticalAlignment.Top;
            eventGrid.Margin = new Thickness(4, 4, 4, 4);

            GridLengthConverter glc = new GridLengthConverter();
            if (dockableComponentProperties.ContainerPane.ActualWidth > 15) {
                eventGrid.Width = dockableComponentProperties.ContainerPane.ActualWidth - 15;
            }

            // Setting the heading for the events Tab
            BrushConverter bc = new BrushConverter();
            eventGrid.RowDefinitions.Add(new RowDefinition() {
                Height = (GridLength)glc.ConvertFromString("28")
            });
            TextBox headingListener = new TextBox() {
                Margin = new Thickness(0, 0, 0, 0),
                FontWeight = FontWeights.Bold,
                FontSize = 12,
                FontFamily = new FontFamily("Segoe UI"),
                IsReadOnly = true,
                Background = (Brush)bc.ConvertFrom("#FFE9ECFA")
            };
            if (isListener) {
                headingListener.Text = Properties.Resources.PropertyDockEventListenerHeader;
            }
            else {
                headingListener.Text = Properties.Resources.PropertyDockEventTriggerHeader;
            }

            TextBox headingTrigger = new TextBox() {
                Text = Properties.Resources.PropertyDockEventDescriptionHeader,
                Margin = new Thickness(0, 0, 0, 0),
                FontWeight = FontWeights.Bold,
                FontSize = 12,
                FontFamily = new FontFamily("Segoe UI"),
                IsReadOnly = true,
                Background = (Brush)bc.ConvertFrom("#FFE9ECFA")
            };
            Grid.SetRow(headingListener, 0);
            Grid.SetColumn(headingListener, 0);
            Grid.SetRow(headingTrigger, 0);
            Grid.SetColumn(headingTrigger, 1);
            eventGrid.Children.Add(headingTrigger);
            eventGrid.Children.Add(headingListener);
            Border headline = new Border();
            Grid.SetColumn(headline, 0);
            Grid.SetRow(headline, 0);
            Grid.SetColumnSpan(headline, 2);
            headline.BorderBrush = (Brush)bc.ConvertFrom("#FFE9ECFA");
            //headline.BorderBrush = Brushes.Black;
            headline.BorderThickness = new Thickness(1);
            eventGrid.Children.Add(headline);
            ArrayList events;
            if (isListener) {
                events = modelComp.EventListenerList;
            }
            else {
                events = modelComp.EventTriggerList;
            }
            int rowCounter = 1;
            foreach (object o in events) {
                eventGrid.RowDefinitions.Add(new RowDefinition() {
                    Height = (GridLength)glc.ConvertFromString("22")
                });
                TextBox elpName = new TextBox() {
                    Margin = new Thickness(0, 0, 0, 0),
                    FontSize = 12,
                    FontFamily = new FontFamily("Segoe UI"),
                    IsReadOnlyCaretVisible = true
                };
                TextBox elpDesc = new TextBox() {
                    Margin = new Thickness(0, 0, 0, 0),
                    FontSize = 12,
                    FontFamily = new FontFamily("Segoe UI"),
                    IsReadOnlyCaretVisible = true
                };
                if (isListener) {
                    elpName.Text = ((EventListenerPort)o).EventListenerId;
                    elpDesc.Text = ((EventListenerPort)o).EventDescription;
                }
                else {
                    elpName.Text = ((EventTriggerPort)o).EventTriggerId;
                    elpDesc.Text = ((EventTriggerPort)o).EventDescription;
                }
                Grid.SetRow(elpName, rowCounter);
                Grid.SetColumn(elpName, 0);
                Grid.SetRow(elpDesc, rowCounter);
                Grid.SetColumn(elpDesc, 1);
                GridSplitter mySimpleGridSplitter = new GridSplitter();
                mySimpleGridSplitter.Background = Brushes.DarkGray;
                mySimpleGridSplitter.HorizontalAlignment = HorizontalAlignment.Right;
                mySimpleGridSplitter.VerticalAlignment = VerticalAlignment.Stretch;
                mySimpleGridSplitter.Width = 1;
                Grid.SetColumn(mySimpleGridSplitter, 0);
                Grid.SetRow(mySimpleGridSplitter, rowCounter);
                eventGrid.Children.Add(elpName);
                eventGrid.Children.Add(elpDesc);
                eventGrid.Children.Add(mySimpleGridSplitter);

                Border top = new Border();
                Grid.SetColumn(top, 0);
                Grid.SetRow(top, rowCounter);
                Grid.SetColumnSpan(top, 2);
                top.BorderBrush = Brushes.DarkGray;
                top.BorderThickness = new Thickness(1);
                eventGrid.Children.Add(top);

                rowCounter++;
            }
            return eventGrid;
        }
Example #18
0
        /// <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();
        }
Example #19
0
 /// <summary>
 /// Checks if the given componentType is a member of a group. If this is the case the groupComponent will be returned
 /// otherwise null will be returned.
 /// </summary>
 /// <param name="ct">Componenttype to check if it's a member of a group</param>
 /// <returns>groupcomponent where the given componenttype is a member of</returns>
 private groupComponent GetParentGroup(componentType ct)
 {
     foreach (groupComponent gc in groupsList.Values) {
         if (gc.AddedComponentList.Contains(ct))
             return gc;
     }
     return null;
 }
Example #20
0
        /// <summary>
        /// Move a component on the canvas
        /// </summary>
        /// <param name="moveComponent">The component to move</param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        private void MoveComponent(componentType moveComponent, int xPos, int yPos)
        {
            int leftVal = xPos - offsetX;
            int topVal = yPos - offsetY;
            Size csize = canvas.RenderSize;
            if (moveComponent.ComponentCanvas.Visibility == System.Windows.Visibility.Visible) {
                if (leftVal + moveComponent.ComponentCanvas.Width > csize.Width)
                    leftVal = (int)(csize.Width - moveComponent.ComponentCanvas.Width);
                else if (leftVal < 0)
                    leftVal = 0;
                if (topVal + moveComponent.ComponentCanvas.Height > csize.Height)
                    topVal = (int)(csize.Height - moveComponent.ComponentCanvas.Height);
                else if (topVal < 0)
                    topVal = 0;
            } else {
                leftVal = xPos - offsetX;
                topVal = yPos - offsetY;
            }
            Canvas.SetLeft(moveComponent.ComponentCanvas, leftVal);
            Canvas.SetTop(moveComponent.ComponentCanvas, topVal);

            moveComponent.layout.posX = (leftVal).ToString();
            moveComponent.layout.posY = (topVal).ToString();
            int counterIn = 0;
            int counterOut = 0;

            // also move all channels which are virtually connected over groups
            foreach (channel c in deploymentChannelList.Values) {
                if (c.target.component.id.Equals(moveComponent.id)) {
                    c.Line.X2 = xPos + LayoutConstants.INPORTRECTANGLEOFFSETX - offsetX;
                    c.Line.Y2 = yPos + (LayoutConstants.INPORTRECTANGLEOFFSETY + LayoutConstants.INPORTRECTANGLEHEIGHT / 2) +
                            counterIn * LayoutConstants.INPORTDISTANCE - offsetY;
                }
            }

            // all connected channels also have to move
            foreach (Object o in moveComponent.PortsList.Values) {
                if (o is inputPortType) {
                    inputPortType pIn = (inputPortType)o;
                    if (pIn.ChannelId != "") {
                        deploymentChannelList[pIn.ChannelId].Line.X2 = xPos + LayoutConstants.INPORTRECTANGLEOFFSETX - offsetX;
                        deploymentChannelList[pIn.ChannelId].Line.Y2 = yPos + (LayoutConstants.INPORTRECTANGLEOFFSETY + LayoutConstants.INPORTRECTANGLEHEIGHT / 2) +
                            counterIn * LayoutConstants.INPORTDISTANCE - offsetY;
                    }
                    counterIn++;
                }
                else if (o is outputPortType) {
                    outputPortType pOut = (outputPortType)o;
                    if (pOut.ChannelIds.Count > 0) {
                        foreach (string s in pOut.ChannelIds) {
                            deploymentChannelList[s].Line.X1 = xPos + (LayoutConstants.MAINRECTANGLEOFFSETX + LayoutConstants.MAINRECTANGLEWIDTH + LayoutConstants.OUTPORTRECTANGLEWIDTH / 2) - offsetX;
                            deploymentChannelList[s].Line.Y1 = yPos + (LayoutConstants.OUTPORTRECTANGLEOFFSETY + LayoutConstants.OUTPORTRECTANGLEHEIGHT / 2) +
                                counterOut * LayoutConstants.OUTPORTDISTANCE - offsetY;
                        }
                    }
                    counterOut++;
                }
            }
            // move the event channels
            if (moveComponent.EventListenerList.Count > 0) {
                foreach (eventChannelLine line in eventChannelLinesList) {
                    if (line.ListenerComponentId == moveComponent.id) {
                        line.Line.X2 = xPos - offsetX + LayoutConstants.EVENTINPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
                        //line.Line.Y2 = yPos - offsetY + LayoutConstants.EVENTINPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
                        line.Line.Y2 = yPos - offsetY + moveComponent.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10 + LayoutConstants.EVENTPORTHEIGHT + 3;
                    }
                }
            }
            if (moveComponent.EventTriggerList.Count > 0) {
                foreach (eventChannelLine line in eventChannelLinesList) {
                    if (line.TriggerComponentId == moveComponent.id) {
                        line.Line.X1 = xPos - offsetX + LayoutConstants.EVENTOUTPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
                        //line.Line.Y1 = yPos - offsetY + LayoutConstants.EVENTOUTPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
                        line.Line.Y1 = yPos - offsetY + moveComponent.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10 + LayoutConstants.EVENTPORTHEIGHT + 3;
                    }
                }
            }
            modelHasBeenEdited = true;
        }
        /// <summary>
        /// Creating a new GUI element and placing it on the GUI canvas
        /// GUI elements are positioned and measured in percentage, not in pixel
        /// </summary>
        /// <param name="modelComp">Component, which is represented by the GUI element</param>
        public void AddGUIComponent(componentType modelComp)
        {
            Canvas guiComponentCanvas = new Canvas();
            Rectangle guiComponent = new Rectangle();
            guiComponentCanvas.Width = guiCanvas.Width * int.Parse(modelComp.gui.width) / 10000;
            guiComponentCanvas.Height = guiCanvas.Height * int.Parse(modelComp.gui.height) / 10000;
            guiComponentCanvas.Name = "guiCanvas";

            guiCanvas.Children.Add(guiComponentCanvas);
            KeyboardNavigation.SetTabIndex(guiComponentCanvas, guiCanvas.Children.Count + 1);

            guiComponent.Height = guiComponentCanvas.Height;
            guiComponent.Width = guiComponentCanvas.Width;
            guiComponentCanvas.Focusable = true;
            KeyboardNavigation.SetIsTabStop(guiComponentCanvas, true);
            //KeyboardNavigation.SetTabNavigation(guiComponentCanvas, KeyboardNavigationMode.Cycle);

            guiComponentCanvas.GotKeyboardFocus += guiComponentCanvas_GotKeyboardFocus;
            guiComponentCanvas.LostKeyboardFocus += guiComponentCanvas_LostKeyboardFocus;
            guiComponentCanvas.Children.Add(guiComponent);

            guiComponent.Stroke = Brushes.Black;
            BrushConverter bc = new BrushConverter();
            if (modelComp.gui.IsExternalGUIElement) {
                guiComponent.Fill = (Brush)bc.ConvertFrom("#99084ECC"); // External GUI Element: blue
            }
            else {
                guiComponent.Fill = (Brush)bc.ConvertFrom("#99E21616"); // Internal GUI Elment: red     gray: #12121212
            }
            //guiComponent.Focusable = true;
            guiComponent.RadiusX = 2;
            guiComponent.RadiusY = 2;
            Canvas.SetLeft(guiComponentCanvas, guiCanvas.Width * int.Parse(modelComp.gui.posX) / 10000);
            Canvas.SetTop(guiComponentCanvas, guiCanvas.Height * int.Parse(modelComp.gui.posY) / 10000);
            Canvas.SetLeft(guiComponent, 0);
            Canvas.SetTop(guiComponent, 0);
            TextBlock textblockLabel = new TextBlock();
            textblockLabel.Text = modelComp.id;
            textblockLabel.Width = guiComponentCanvas.Width;
            textblockLabel.TextAlignment = System.Windows.TextAlignment.Center;
            textblockLabel.TextWrapping = System.Windows.TextWrapping.Wrap;
            guiComponentCanvas.Children.Add(textblockLabel);
            Canvas.SetLeft(textblockLabel, 5);
            Canvas.SetTop(textblockLabel, guiComponentCanvas.Height / 2 - 10);
            modelComp.gui.GuiElementCanvas = guiComponentCanvas;

            if (modelComp.id.Equals(modelCompGUIARE.id)) {
                // add Right Control area
                controlRect = new Rectangle();
                SolidColorBrush scb = new SolidColorBrush();
                scb.Color = Color.FromArgb(128, 120, 120, 120);
                controlRect.Fill = scb;
                controlRect.Width = 38;

                controlRect.Height = guiComponentCanvas.Height;
                Canvas.SetRight(controlRect, 0);
                modelCompGUIARE.gui.GuiElementCanvas.Children.Add(controlRect);

                controlTextBlock = new TextBlock();
                controlTextBlock.Text = "Control";
                controlTextBlock.FontSize = 9;
                Canvas.SetRight(controlTextBlock, 4);
                Canvas.SetTop(controlTextBlock, guiComponentCanvas.Height / 2);

                modelCompGUIARE.gui.GuiElementCanvas.Children.Add(controlTextBlock);

                decorationCanvas = new Rectangle();
                ImageBrush ib = new ImageBrush();
                try {
                    if (System.IO.File.Exists(@"images\are_deco.png")) {
                        Uri uri = new Uri(@"images\are_deco.png", UriKind.Relative);
                        ib.ImageSource = new BitmapImage(uri);
                        decorationCanvas.Fill = ib;
                    }

                }
                catch (Exception e) {
                }
                decorationCanvas.Width = guiComponentCanvas.Width-2;
                decorationCanvas.Height = decorationHeight;
                modelCompGUIARE.gui.GuiElementCanvas.Children.Add(decorationCanvas);
                Canvas.SetLeft(decorationCanvas, 1);
                Canvas.SetTop(decorationCanvas, 1);
            }

            // Small black rectangle, indicating the resize possibility of a component
            Polygon moveSizeTriangle = new Polygon();
            PointCollection trianglePointCollection = new PointCollection();
            trianglePointCollection.Add(new Point(0, 15));
            trianglePointCollection.Add(new Point(15, 15));
            trianglePointCollection.Add(new Point(15, 0));
            moveSizeTriangle.Points = trianglePointCollection;
            moveSizeTriangle.Fill = Brushes.Black;
            moveSizeTriangle.MouseEnter += moveSizeTriangle_MouseEnter;
            moveSizeTriangle.MouseLeave += moveSizeTriangle_MouseLeave;
            guiComponentCanvas.Children.Add(moveSizeTriangle);
            Canvas.SetRight(moveSizeTriangle, 1);
            Canvas.SetBottom(moveSizeTriangle, 1);
            guiComponentCanvas.ContextMenu = gUIComponentContextMenu;
            guiComponentCanvas.KeyDown += guiComponent_KeyDown;
            guiComponentCanvas.KeyUp += guiComponent_KeyUp;

            // special condition for the ARE GUI window
            if (modelComp.id.Equals(modelCompGUIARE.id)) {
                textblockLabel.Text = "ARE";
                guiComponentCanvas.Name = "guiCanvasARE";
                guiComponent.Fill = (Brush)bc.ConvertFrom("#88E2E6E6");
            }
            else {
                // post new GUI element within the ARE window, if it is not an independent GUI window (like the webcam window)
                // this code will only be executed, if the canvas has the cooridinates (0,0), meaning it is a new element and not loaded
                if ((deploymentModel.modelGUI != null) && !modelComp.gui.IsExternalGUIElement && (Canvas.GetLeft(guiComponentCanvas) == 0) && (Canvas.GetTop(guiComponentCanvas) == 0)) {
                    Canvas.SetLeft(guiComponentCanvas, Canvas.GetLeft(modelCompGUIARE.gui.GuiElementCanvas));
                    if (guiProp.Decoration) {
                        Canvas.SetTop(guiComponentCanvas, Canvas.GetTop(modelCompGUIARE.gui.GuiElementCanvas) + decorationHeight);
                        modelComp.gui.posY = Convert.ToInt16((Canvas.GetTop(guiComponentCanvas)) / guiCanvas.Height * 10000).ToString();
                    }
                    else
                        Canvas.SetTop(guiComponentCanvas, Canvas.GetTop(modelCompGUIARE.gui.GuiElementCanvas));

                    if (modelCompGUIARE.gui.GuiElementCanvas.Width <= (guiComponentCanvas.Width - areRightMargin)) {
                        guiComponentCanvas.Width = modelCompGUIARE.gui.GuiElementCanvas.Width - areRightMargin;
                        ((Rectangle)modelComp.gui.GuiElementCanvas.Children[0]).Width = guiComponentCanvas.Width;
                    }
                    if (modelCompGUIARE.gui.GuiElementCanvas.Height <= (guiComponentCanvas.Height + areBottomMargin)) {
                        guiComponentCanvas.Height = modelCompGUIARE.gui.GuiElementCanvas.Height - areBottomMargin;
                        ((Rectangle)modelComp.gui.GuiElementCanvas.Children[0]).Height = guiComponentCanvas.Height;
                    }
                    Canvas.SetLeft(textblockLabel, 5);
                    Canvas.SetTop(textblockLabel, (guiComponentCanvas.Height / 2 - 10));
                }
            }
            CalcMaxXandYofGUI();
        }
Example #22
0
 /// <summary>
 /// Delete a channel, called by the ribbon menu
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 //private void DeleteChannelRibbonButton_Click(object sender, RoutedEventArgs e) {
 //    newChannelRibbonButton.IsChecked = false;
 //    if (focusedChannel != null) {
 //        CommandObject co = new CommandObject("Add", focusedChannel);
 //        undoStack.Push(co);
 //        redoStack.Clear();
 //        DeleteChannel(focusedChannel);
 //        focusedChannel = null;
 //        //deleteChannelRibbonButton.IsEnabled = false;
 //    }
 //}
 /// <summary>
 /// Delete an event channel, called by the ribbon menu
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 //private void DeleteEventChannelRibbonButton_Click(object sender, RoutedEventArgs e) {
 //    newEventChannelRibbonButton.IsChecked = false;
 //    if (focusedEventChannel != null) {
 //        //if (MessageBox.Show(Properties.Resources.DeleteEventChannelConfirmTextFormat(focusedEventChannel.TriggerComponentId,focusedEventChannel.ListernerComponentId),
 //        //        Properties.Resources.DeleteEventChannelConfirmHeader, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) {
 //        // uncomment if-condition to activate "delete eventchannel?" question
 //        if (true) {
 //            /*CommandObject co = new CommandObject("addEventChannel", focusedEventChannel);
 //            foreach (eventChannel eventCh in eventChannelList) {
 //                if ((eventCh.sources.source.component.id == ((eventChannelLine)co.InvolvedObject).TriggerComponentId) && (eventCh.targets.target.component.id == ((eventChannelLine)co.InvolvedObject).ListernerComponentId)) {
 //                    co.Parameter.Add(eventCh);
 //                }
 //            }
 //            undoStack.Push(co);
 //            redoStack.Clear();
 //            DeleteEventChannelCommand(focusedEventChannel);*/
 //            focusedEventChannel = null;
 //        }
 //    }
 //    foreach (eventChannelLine ech in selectedEventChannelList) {
 //        CommandObject co = new CommandObject("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).ListernerComponentId)) {
 //                    co.Parameter.Add(eventCh);
 //                }
 //            }
 //        }
 //        undoStack.Push(co);
 //        redoStack.Clear();
 //        DeleteEventChannelCommand(ech);
 //    }
 //}
 /// <summary>
 /// Move a Component on the canvas. As long as the ribbon button is checked, the 
 /// component can be moved with the arrow keys
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void moveComponentRibbonButton_Checked(object sender, RoutedEventArgs e)
 {
     newChannelRibbonButton.IsChecked = false;
     if (Keyboard.FocusedElement is Canvas) {
         Canvas canvasWithFocus = (Canvas)Keyboard.FocusedElement;
         foreach (componentType tempComponent in deploymentComponentList.Values) {
             if (tempComponent.ComponentCanvas == canvasWithFocus) {
                 componentToMove = tempComponent;
                 break;
             }
         }
         //componentToMove = null;
         //CommandObject co = CreateMoveCommandObject();
         //undoStack.Push(co);
         //redoStack.Clear();
     }
 }
        /// <summary>
        /// Keyboard listner to react on the 'App'-key
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void guiComponent_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Apps) {

                e.Handled = true;
                Canvas selectedGUIElement = (Canvas)sender;

                foreach (componentType tempComponent in deploymentComponentList.Values) {
                    if ((tempComponent.gui != null) && (tempComponent.gui.GuiElementCanvas == selectedGUIElement)) {
                        guiSelectedModelComponent = tempComponent;
                        break;
                    }
                }

                selectedGUIElement.ContextMenu.PlacementTarget = selectedGUIElement.Children[0];
                selectedGUIElement.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Center;
                selectedGUIElement.ContextMenu.IsOpen = true;
            }
        }
Example #24
0
 /// <summary>
 /// Stop the moving capability of a component
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void moveComponentRibbonButton_Unchecked(object sender, RoutedEventArgs e)
 {
     componentToMove = null;
 }
 /// <summary>
 /// Left mouse button up on the GUICanvas
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnLeftUpGUI(object sender, MouseEventArgs args)
 {
     if (guiSelectedModelComponent != null && guiSelectedCanvas != null) {
         foreach (UIElement uie in guiSelectedCanvas.Children) {
             if (uie is TextBlock) {
                 ((TextBlock)uie).Width = guiSelectedCanvas.Width;
                 Canvas.SetTop(uie, guiSelectedCanvas.Height / 2 - 10);
                 break;
             }
         }
         guiSelectedModelComponent = null;
         guiSelectedCanvas = null;
         guiElementResize = false;
     }
     CalcMaxXandYofGUI();
 }
        // copy all relevant properties of an eventport
        //private void CopyEventPort(Canvas source, Canvas target) {
        //    target.Width = source.Width;
        //    target.Height = source.Height;
        //    PointCollection eventPortPointCollection = new PointCollection();
        //    Polygon eventPortPolygon = new Polygon();
        //    foreach (Polygon pg in source.Children) {
        //        foreach (Point p in pg.Points) {
        //            eventPortPointCollection.Add(new Point(p.X, p.Y));
        //        }
        //        eventPortPolygon.Points = eventPortPointCollection;
        //        eventPortPolygon.Fill = pg.Fill;
        //        eventPortPolygon.Stroke = pg.Stroke;
        //    }
        //    target.Children.Add(eventPortPolygon);
        //}
        /// <summary>
        /// Generate a new deployment component form a bundle component, deep copy
        /// </summary>
        /// <param name="component">The bundle component, which should be copied</param>
        /// <param name="id">The id of the new component</param>
        /// <returns>A new model component based on the bundle component</returns>
        public static componentType CopyFromBundleModel(Asterics.ACS2.componentTypesComponentType component, String id)
        {
            componentType mComponent = new componentType();
            //int portIndex = 0;

            mComponent.id = id;
            mComponent.componentTypeDataType = component.type.Value;
            //mComponent.componentId = component.id;
            mComponent.type_id = component.id;
            mComponent.description = component.description;

            // copy the graphical elements
            mComponent.ComponentCanvas.Height = component.ComponentCanvas.Height;
            mComponent.ComponentCanvas.Width = component.ComponentCanvas.Width;
            mComponent.ComponentCanvas.FocusVisualStyle = null;
            mComponent.CopyRectangel(component.MainRectangle, mComponent.MainRectangle);
            mComponent.ComponentCanvas.Children.Add(mComponent.MainRectangle);
            Canvas.SetLeft(mComponent.MainRectangle, Canvas.GetLeft(component.MainRectangle));
            Canvas.SetTop(mComponent.MainRectangle, Canvas.GetTop(component.MainRectangle));
            mComponent.Label.Text = id;

            mComponent.InitLabeling();

            // copy the properties
            if (component.properties != null) {
                foreach (Asterics.ACS2.propertyType compProperty in component.properties) {
                    propertyType property = new propertyType();
                    property.name = compProperty.name;
                    property.DataType = compProperty.type;
                    property.Description = compProperty.description;
                    property.value = compProperty.value;
                    if (compProperty.combobox != null) {
                        property.ComboBoxStrings = compProperty.combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                    }
                    if (compProperty.getStringList) {
                        property.GetStringList = true;
                    } else {
                        property.GetStringList = false;
                    }
                    mComponent.PropertyArrayList.Add(property);
                }
            }
            mComponent.propertiesField = new propertyType[mComponent.PropertyArrayList.Count];
            mComponent.PropertyArrayList.CopyTo(mComponent.propertiesField);

            // copy the ports

            if (component.ports != null) {
                foreach (object o in component.ports) {
                    // copy the inports
                    if (o is Asterics.ACS2.inputPortType) {
                        Asterics.ACS2.inputPortType compInPort = (Asterics.ACS2.inputPortType)o;
                        inputPortType inPort = new inputPortType();
                        inPort.portTypeID = compInPort.id;
                        inPort.ComponentId = id;
                        inPort.Description = compInPort.description;
                        inPort.MustBeConnected = compInPort.mustBeConnected;
                        inPort.PortDataType = compInPort.dataType;
                        inPort.ComponentTypeId = component.id;

                        inPort.PortLabel.Text = compInPort.id;
                        mComponent.componentCanvas.Children.Add(inPort.PortLabel);
                        Canvas.SetLeft(inPort.PortLabel, Canvas.GetLeft(compInPort.PortRectangle) + ACS.LayoutConstants.INPORTRECTANGLEWIDTH + 2);
                        Canvas.SetTop(inPort.PortLabel, Canvas.GetTop(compInPort.PortRectangle) - 2 );

                        mComponent.CopyRectangel(compInPort.PortRectangle, inPort.PortRectangle);
                        mComponent.ComponentCanvas.Children.Add(inPort.PortRectangle);
                        Canvas.SetLeft(inPort.PortRectangle, Canvas.GetLeft(compInPort.PortRectangle));
                        Canvas.SetTop(inPort.PortRectangle, Canvas.GetTop(compInPort.PortRectangle));

                        // copy the properties of the inports
                        if (compInPort.properties != null) {
                            foreach (Asterics.ACS2.propertyType portProperty in compInPort.properties) {
                                propertyType property = new propertyType();
                                property.name = portProperty.name;
                                property.DataType = portProperty.type;
                                property.Description = portProperty.description;
                                property.value = portProperty.value;
                                if (portProperty.combobox != null) {
                                    property.ComboBoxStrings = portProperty.combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                }
                                inPort.PropertyArrayList.Add(property);
                            }
                            inPort.properties = new propertyType[inPort.PropertyArrayList.Count];
                            inPort.PropertyArrayList.CopyTo(inPort.properties);
                        }

                        // copy the reference to another port (only available, if it is a group element)
                        if (compInPort.RefPort != null) {
                            inPort.refs = compInPort.RefPort;
                        }

                        mComponent.PortsList.Add(inPort.portTypeID,inPort);

                    // copy the outports
                    } else if (o is Asterics.ACS2.outputPortType) {
                        Asterics.ACS2.outputPortType compOutPort = (Asterics.ACS2.outputPortType)o;
                        outputPortType outPort = new outputPortType();
                        outPort.portTypeID = compOutPort.id;
                        outPort.ComponentId = id;
                        outPort.Description = compOutPort.description;
                        outPort.PortDataType = compOutPort.dataType;
                        outPort.ComponentTypeId = component.id;

                        outPort.PortLabel.Text = compOutPort.id;
                        mComponent.componentCanvas.Children.Add(outPort.PortLabel);
                        Canvas.SetLeft(outPort.PortLabel, Canvas.GetLeft(compOutPort.PortRectangle) - ACS.LayoutConstants.OUTPORTLABELWIDTH - 2);
                        Canvas.SetTop(outPort.PortLabel, Canvas.GetTop(compOutPort.PortRectangle) - 2);

                        mComponent.CopyRectangel(compOutPort.PortRectangle, outPort.PortRectangle);
                        mComponent.ComponentCanvas.Children.Add(outPort.PortRectangle);
                        Canvas.SetLeft(outPort.PortRectangle, Canvas.GetLeft(compOutPort.PortRectangle));
                        Canvas.SetTop(outPort.PortRectangle, Canvas.GetTop(compOutPort.PortRectangle));

                        // copy the properties of the outports
                        if (compOutPort.properties != null) {
                            foreach (Asterics.ACS2.propertyType portProperty in compOutPort.properties) {
                                propertyType property = new propertyType();
                                property.name = portProperty.name;
                                property.DataType = portProperty.type;
                                property.Description = portProperty.description;
                                property.value = portProperty.value;
                                if (portProperty.combobox != null) {
                                    property.ComboBoxStrings = portProperty.combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                }
                                outPort.PropertyArrayList.Add(property);
                            }
                            outPort.properties = new propertyType[outPort.PropertyArrayList.Count];
                            outPort.PropertyArrayList.CopyTo(outPort.properties);
                        }

                        // copy the reference to another port (only available, if it is a group element)
                        if (compOutPort.RefPort != null) {
                            outPort.refs = compOutPort.RefPort;
                        }

                        mComponent.PortsList.Add(outPort.portTypeID,outPort);
                    }

                }
                mComponent.ports = new object[mComponent.PortsList.Count];
                mComponent.PortsList.Values.CopyTo(mComponent.ports, 0);
            }

            // Searching for event listeners and event triggers and saving them in arrays
            if ((component.events != null)&&(component.events != null)) {
                foreach (object eventO in component.events) {
                    if (eventO is ACS2.eventsTypeEventListenerPortType) {
                        ACS2.eventsTypeEventListenerPortType compEl = (ACS2.eventsTypeEventListenerPortType)eventO;
                        EventListenerPort el = new EventListenerPort();
                        el.EventListenerId = compEl.id;
                        el.EventDescription = compEl.description;
                        el.ComponentId = id;
                        mComponent.EventListenerList.Add(el);
                    } else if (eventO is ACS2.eventsTypeEventTriggererPortType) {
                        ACS2.eventsTypeEventTriggererPortType compEl = (ACS2.eventsTypeEventTriggererPortType)eventO;
                        EventTriggerPort et = new EventTriggerPort();
                        et.EventTriggerId = compEl.id;
                        et.EventDescription = compEl.description;
                        et.ComponentId = id;
                        mComponent.EventTriggerList.Add(et);
                    }
                }
            }

            // Adapt the size of MainRectangle, if more then MAINRECTANGLENUMBEROFPORTS are in a component
            int numInPorts = 0;
            int numOutPorts = 0;
            foreach (object o in mComponent.PortsList.Values) {
                if (o is inputPortType) {
                    numInPorts++;
                } else {
                    numOutPorts++;
                }
            }
            if (numOutPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                mComponent.MainRectangle.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE );
                mComponent.ComponentCanvas.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE);
            } else if (numInPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                mComponent.MainRectangle.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
                mComponent.ComponentCanvas.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
            }

            // Drawing the event listener and event trigger port, if events are available
            if (mComponent.EventListenerList.Count > 0) {
                EventListenerPolygon inputEventPolygon = new EventListenerPolygon();
                mComponent.EventListenerPolygon = inputEventPolygon;
                mComponent.componentCanvas.Children.Add(inputEventPolygon.InputEventPortCanvas);
                Canvas.SetLeft(inputEventPolygon.InputEventPortCanvas, ACS.LayoutConstants.EVENTINPORTCANVASOFFSETX);
                //Canvas.SetTop(inputEventPolygon.InputEventPortCanvas, ACS.LayoutConstants.EVENTINPORTCANVASOFFSETY);
                Canvas.SetTop(inputEventPolygon.InputEventPortCanvas, mComponent.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
            }
            if (mComponent.EventTriggerList.Count > 0) {
                EventTriggerPolygon outputEventPolygon = new EventTriggerPolygon();
                mComponent.EventTriggerPolygon = outputEventPolygon;
                mComponent.componentCanvas.Children.Add(outputEventPolygon.OutputEventPortCanvas);
                Canvas.SetLeft(outputEventPolygon.OutputEventPortCanvas, ACS.LayoutConstants.EVENTOUTPORTCANVASOFFSETX);
                //Canvas.SetTop(outputEventPolygon.OutputEventPortCanvas, ACS.LayoutConstants.EVENTOUTPORTCANVASOFFSETY);
                Canvas.SetTop(outputEventPolygon.OutputEventPortCanvas, mComponent.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
            }

            return mComponent;
        }