Пример #1
0
        /// <summary>
        /// Adds a tool to the Modeler
        /// </summary>
        /// <param name="tool">the tool to add to the modeler</param>
        /// <param name="modelName"></param>
        /// <param name="location">A point representing the virtual location of the tool</param>
        private ToolElement AddTool(ITool tool, string modelName, Point location)
        {
            if (tool == null)
                return null;

            ToolElement te = new ToolElement(tool, _modelElements)
                                 {
                                     Font = _toolFont,
                                     Color = _toolColor,
                                     Shape = _toolShape,
                                     Name = modelName
                                 };
            AddElement(te, location);
            int j = 0;
            foreach (Parameter par in te.Tool.OutputParameters)
            {
                Point newLocation = new Point(te.Location.X + Convert.ToInt32(te.Width * 1.1), te.Location.Y + Convert.ToInt32(j * te.Height * 1.1));
                DataElement de = AddData(par, newLocation);
                par.GenerateDefaultOutput(Path.GetDirectoryName(ModelFilename));
                AddArrow(te, de);
                j++;
            }
            return te;
        }
Пример #2
0
        /// <summary>
        /// When the user double clicks on the model this event fires
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDoubleClick(EventArgs e)
        {
            base.OnDoubleClick(e);

            MouseEventArgs mouseE = e as MouseEventArgs;

            //If the user left clicked on a selected element we do nothing
            if (mouseE == null) return;
            Point virPt = PixelToVirtual(mouseE.X, mouseE.Y);
            foreach (ModelElement me in _modelElementsSelected)
            {
                //Point pt = new Point(virPt.X - me.Location.X, virPt.Y - me.Location.Y);
                if (me.PointInElement(virPt))
                {
                    //We create a new instance if its a toolelement
                    ToolElement meAsTool = me as ToolElement;
                    if (meAsTool != null)
                    {
                        //All of the parameters are copied from the original one
                        ITool newToolCopy = ToolManager.GetTool(meAsTool.Tool.AssemblyQualifiedName);
                        for (int i = 0; i < (meAsTool.Tool.InputParameters.Length); i++)
                            if (newToolCopy.InputParameters[i] != null) newToolCopy.InputParameters[i] = meAsTool.Tool.InputParameters[i].Copy();
                        for (int i = 0; i < (meAsTool.Tool.OutputParameters.Length); i++)
                            if (newToolCopy.OutputParameters[i] != null) newToolCopy.OutputParameters[i] = meAsTool.Tool.OutputParameters[i].Copy();

                        //This code ensures that no children are passed into the tool
                        List<ModelElement> tempList = new List<ModelElement>();
                        foreach (ModelElement mEle in _modelElements)
                        {
                            if (mEle.IsDownstreamOf(meAsTool)) continue;
                            tempList.Add(mEle);
                        }
                        ToolElement tempTool = new ToolElement(newToolCopy, tempList);

                        //If the user hits ok we dispose of the saved copy if they don't we restore the old values
                        if (tempTool.DoubleClick())
                        {
                            for (int i = 0; i < (meAsTool.Tool.InputParameters.Length); i++)
                                if (meAsTool.Tool.InputParameters[i] != null) meAsTool.Tool.InputParameters[i] = tempTool.Tool.InputParameters[i];
                            for (int i = 0; i < (meAsTool.Tool.OutputParameters.Length); i++)
                            {
                                if (tempTool.Tool.OutputParameters[i] != null)
                                {
                                    if (tempTool.Tool.OutputParameters[i].DefaultSpecified)
                                    {
                                        meAsTool.Tool.OutputParameters[i].ModelName = tempTool.Tool.OutputParameters[i].ModelName;
                                        meAsTool.Tool.OutputParameters[i].Value = tempTool.Tool.OutputParameters[i].Value;
                                    }
                                }
                            }

                            //First we clear all the arrows linking to the current tool (We use a temporary array since we will be removing items from the list)
                            ModelElement[] tempArray = new ModelElement[_modelElements.Count];
                            _modelElements.CopyTo(tempArray);
                            foreach (ModelElement mele in tempArray)
                            {
                                ArrowElement ae = mele as ArrowElement;
                                if (ae != null)
                                {
                                    if (ae.StopElement == meAsTool)
                                        DeleteElement(ae);
                                }
                            }

                            //We go through each parameters of the tool to the model if they haven't been added already
                            int j = 0;
                            foreach (Parameter par in meAsTool.Tool.InputParameters)
                            {
                                if (par == null) continue;

                                //If its not supposed to be visible we ignore it.
                                if (par.ParamVisible == ShowParamInModel.No)
                                    continue;

                                //If no default has been specified continue
                                if (par.DefaultSpecified == false)
                                    continue;

                                //If the parameter has not been assigned a model name we add the data to the model
                                bool addParam = true;
                                foreach (ModelElement modElem in _modelElements)
                                {
                                    DataElement dataElem = modElem as DataElement;
                                    if (dataElem == null) continue;
                                    if (dataElem.Parameter.Value == par.Value) { addParam = false; break; }
                                }
                                if (addParam)
                                {
                                    Point newLocation = new Point(meAsTool.Location.X - Convert.ToInt32(meAsTool.Width * 1.1), meAsTool.Location.Y + Convert.ToInt32(j * meAsTool.Height * 1.1));
                                    AddArrow(AddData(par, newLocation), meAsTool);
                                    j++;
                                }
                                else
                                {
                                    //If the parameter has already been added we make sure that we have linked to it properly
                                    tempArray = new ModelElement[_modelElements.Count];
                                    _modelElements.CopyTo(tempArray);
                                    foreach (ModelElement mele in tempArray)
                                    {
                                        DataElement de = mele as DataElement;
                                        if (de != null)
                                        {
                                            if (par.ModelName == de.Parameter.ModelName)
                                            {
                                                AddArrow(mele, meAsTool);
                                            }
                                        }
                                    }
                                }
                            }
                            //This updates the status light
                            meAsTool.UpdateStatus();
                        }
                    }
                    else
                    {
                        me.DoubleClick();
                    }
                    Invalidate();
                    return;
                }
            }
        }