/// <summary>
        /// Init the graphical elements of a component includs
        /// the drawing on the ports and event ports
        /// </summary>
        /// <param name="id">The id of the component</param>
        public void InitGraphLayout(String id)
        {
            componentCanvas.Width = ACS.LayoutConstants.COMPONENTCANVASWIDTH;
            componentCanvas.Height = ACS.LayoutConstants.COMPONENTCANVASHEIGHT;
            componentCanvas.FocusVisualStyle = null;
            mainRectangle.Height = ACS.LayoutConstants.MAINRECTANGLEHEIGHT;
            mainRectangle.Width = ACS.LayoutConstants.MAINRECTANGLEWIDTH;
            mainRectangle.Stroke = new SolidColorBrush(Colors.Black);
            BrushConverter bc = new BrushConverter();
            String bodyColor = ini.IniReadValue("Layout", "bodycolor");
            if (bodyColor.Equals("")) bodyColor = ACS.LayoutConstants.MAINRECTANGLECOLOR;
            mainRectangle.Fill = (Brush)bc.ConvertFrom(bodyColor);
            mainRectangle.RadiusX = 4;
            mainRectangle.RadiusY = 4;

            componentCanvas.Children.Add(mainRectangle);
            Canvas.SetLeft(mainRectangle, ACS.LayoutConstants.MAINRECTANGLEOFFSETX);
            Canvas.SetTop(mainRectangle, ACS.LayoutConstants.MAINRECTANGLEOFFSETY);
            InitLabeling();

            label.Text = id;

            int counterIn = 0;
            int counterOut = 0;
            // set the portRectangels on the componentCanvas
            foreach (Object o in this.portsList.Values) {
                if (o is inputPortType) {
                    inputPortType pIn = (inputPortType)o;

                    pIn.PortLabel.Text = pIn.portTypeID;
                    componentCanvas.Children.Add(pIn.PortLabel);
                    Canvas.SetLeft(pIn.PortLabel, ACS.LayoutConstants.INPORTRECTANGLEOFFSETX + ACS.LayoutConstants.INPORTRECTANGLEWIDTH + 2);
                    Canvas.SetTop(pIn.PortLabel, ACS.LayoutConstants.INPORTRECTANGLEOFFSETY + counterIn * ACS.LayoutConstants.INPORTDISTANCE - 2);

                    componentCanvas.Children.Add(pIn.PortRectangle);
                    Canvas.SetLeft(pIn.PortRectangle, ACS.LayoutConstants.INPORTRECTANGLEOFFSETX);
                    Canvas.SetTop(pIn.PortRectangle, ACS.LayoutConstants.INPORTRECTANGLEOFFSETY + counterIn * ACS.LayoutConstants.INPORTDISTANCE);
                    counterIn++;
                    pIn.ComponentId = this.id;
                } else {
                    outputPortType pOut = (outputPortType)o;

                    pOut.PortLabel.Text = pOut.portTypeID;
                    componentCanvas.Children.Add(pOut.PortLabel);
                    Canvas.SetLeft(pOut.PortLabel, ACS.LayoutConstants.OUTPORTRECTANGLEOFFSETX - 2 - pOut.PortLabel.Width);
                    Canvas.SetTop(pOut.PortLabel, ACS.LayoutConstants.OUTPORTRECTANGLEOFFSETY + counterOut * ACS.LayoutConstants.OUTPORTDISTANCE - 2);

                    componentCanvas.Children.Add(pOut.PortRectangle);
                    Canvas.SetLeft(pOut.PortRectangle, ACS.LayoutConstants.OUTPORTRECTANGLEOFFSETX);
                    Canvas.SetTop(pOut.PortRectangle, ACS.LayoutConstants.OUTPORTRECTANGLEOFFSETY + counterOut * ACS.LayoutConstants.OUTPORTDISTANCE);
                    counterOut++;
                    pOut.ComponentId = this.id;
                }
            }

            // Draw the event listener port and the event trigger port, if listeners or triggers are defined
            if (EventListenerList.Count > 0) {
                EventListenerPolygon inputEventPolygon = new EventListenerPolygon();
                this.EventListenerPolygon = inputEventPolygon;
                componentCanvas.Children.Add(inputEventPolygon.InputEventPortCanvas);
                Canvas.SetLeft(inputEventPolygon.InputEventPortCanvas, ACS.LayoutConstants.EVENTINPORTCANVASOFFSETX);
                Canvas.SetTop(inputEventPolygon.InputEventPortCanvas, ACS.LayoutConstants.EVENTINPORTCANVASOFFSETY);
            }
            if (EventTriggerList.Count > 0) {
                EventTriggerPolygon outputEventPolygon = new EventTriggerPolygon();
                this.EventTriggerPolygon = outputEventPolygon;
                componentCanvas.Children.Add(outputEventPolygon.OutputEventPortCanvas);
                Canvas.SetLeft(outputEventPolygon.OutputEventPortCanvas, ACS.LayoutConstants.EVENTOUTPORTCANVASOFFSETX);
                Canvas.SetTop(outputEventPolygon.OutputEventPortCanvas, ACS.LayoutConstants.EVENTOUTPORTCANVASOFFSETY);
            }
        }
        // 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;
        }