/// <summary>
 /// Creates an instance of an ArrowElement
 /// </summary>
 /// <param name="sourceElement">The element the arrow starts at</param>
 /// <param name="destElement">the element the arrow ends at</param>
 /// <param name="modelElements">A list of all the elements in the model</param>
 public ArrowElement(ModelElement sourceElement, ModelElement destElement, List<ModelElement> modelElements)
     : base(modelElements)
 {
     _startElement = sourceElement;
     _stopElement = destElement;
     UpdateDimentions();
     Shape = ModelShape.Arrow;
     Location = _startElement.Location;
 }
Exemple #2
0
 /// <summary>
 /// Removes a specific element from the model clearing any links it has to other elements
 /// </summary>
 /// <param name="element">The element to remove</param>
 private void DeleteElement(ModelElement element)
 {
     if (element as ToolElement != null)
     {
         ToolElement te = element as ToolElement;
         if (_modelElements.Contains(te))
             _modelElements.Remove(te);
     }
     else if (element as DataElement != null)
     {
         DataElement de = element as DataElement;
         if (_modelElements.Contains(de))
             _modelElements.Remove(de);
     }
     else if (element as ArrowElement != null)
     {
         ArrowElement ae = element as ArrowElement;
         if (_modelElements.Contains(ae))
             _modelElements.Remove(ae);
     }
     else if (element as BlankElement != null)
     {
         if (_modelElements.Contains(element))
             _modelElements.Remove(element);
     }
 }
Exemple #3
0
 /// <summary>
 /// Removes the specified element from the _selectedElements list
 /// </summary>
 /// <param name="element"></param>
 private void RemoveSelectedElement(ModelElement element)
 {
     if (_modelElementsSelected.Contains(element))
     {
         _modelElementsSelected.Remove(element);
         element.Highlighted(false);
         IsInitialized = false;
     }
 }
Exemple #4
0
        /// <summary>
        /// Adds an element to the _modelElementsSelected Array and highlights it
        /// </summary>
        /// <param name="element"></param>
        private void AddSelectedElement(ModelElement element)
        {
            _modelElementsSelected.Insert(0, element);
            element.Highlighted(true);

            //We check if the element has any arrows connected to it and if it does we select them too
            foreach (ModelElement me in _modelElements)
            {
                if (me as ArrowElement != null)
                {
                    ArrowElement ae = me as ArrowElement;
                    if (ae.StartElement == element || ae.StopElement == element)
                    {
                        _modelElementsSelected.Add(ae);
                        ae.Highlighted(true);
                    }
                }
            }

            IsInitialized = false;
        }
Exemple #5
0
 /// <summary>
 /// Adds an arrow element given a source and destination element
 /// </summary>
 /// <param name="sourceElement"></param>
 /// <param name="destElement"></param>
 private ArrowElement AddArrow(ModelElement sourceElement, ModelElement destElement)
 {
     ArrowElement ae = new ArrowElement(sourceElement, destElement, _modelElements)
                           {
                               Color = _arrowColor,
                               Name = sourceElement.Name + "_" + destElement.Name
                           };
     AddElement(ae, ae.Location);
     return ae;
 }
Exemple #6
0
        /// <summary>
        /// Adds a element to the model
        /// </summary>
        /// <param name="element">The new model Element to add to the model form</param>
        /// <param name="location">A point representing the virtual location of the element</param>
        private void AddElement(ModelElement element, Point location)
        {
            List<string> elementNames = new List<string>();
            foreach (ModelElement mEle in _modelElements)
                elementNames.Add(mEle.Name);

            string tempName = element.Name;
            int i = 1;
            while (elementNames.Contains(tempName))
            {
                tempName = element.Name + "_" + i;
                i++;
            }

            element.Name = tempName;
            _modelElements.Add(element);
            element.Location = location;
            IsInitialized = false;
        }
Exemple #7
0
        /// <summary>
        /// When the user mouses up after a single click this event fires
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            Point virPt = PixelToVirtual(e.Location);

            //If we are in link mode we run this
            if (_linkArrow != null)
            {
                ClearSelectedElements();
                ModelElement[] tempElements = new ModelElement[_modelElements.Count];
                _modelElements.CopyTo(tempElements);
                foreach (ModelElement me in tempElements)
                {
                    if (me.PointInElement(virPt) && me != _linkArrow.StartElement)
                    {
                        ToolElement te = me as ToolElement;
                        if (te != null)
                        {
                            //If the user let go over a tool we try to link to to, assuming it doesn't create a loop
                            if (_linkArrow.StartElement != null)
                            {
                                if (_linkArrow.StartElement.IsDownstreamOf(te))
                                {
                                    //If the tool is the data sets parent
                                    MessageBox.Show(MessageStrings.linkErrorCircle, MessageStrings.linkError, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    break;
                                }
                            }
                            bool showError = true;
                            foreach (Parameter t in te.Tool.InputParameters)
                            {
                                DataElement linkStart = _linkArrow.StartElement as DataElement;
                                if (linkStart != null)
                                {
                                    if (t.DefaultSpecified == false && t.ParamType == linkStart.Parameter.ParamType)
                                    {
                                        AddArrow(linkStart, te);
                                        t.Value = linkStart.Parameter.Value;
                                        t.ModelName = linkStart.Parameter.ModelName;
                                        showError = false;
                                        te.UpdateStatus();
                                        break;
                                    }
                                }
                            }
                            if (showError) MessageBox.Show(MessageStrings.linkNoFreeInput, MessageStrings.linkError, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;
                        }
                        MessageBox.Show(MessageStrings.linkErrorToData, MessageStrings.linkError, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                    }
                }
                DeleteElement(_linkArrow.StopElement);
                DeleteElement(_linkArrow);
                _linkArrow = null;
                IsInitialized = false;
                Invalidate();
                Application.DoEvents();
                return;
            }

            //If we detect the user clicked on a element and didn't move the mouse we select that element and clear the others
            if (_mouseMoved == false && _mouseDownOnElement)
            {
                if (ModifierKeys != Keys.Control)
                {
                    ClearSelectedElements();
                    foreach (ModelElement me in _modelElements)
                    {
                        if (_modelElementsSelected.Contains(me))
                            continue;
                        if (me.PointInElement(virPt))
                        {
                            if (ModifierKeys == Keys.Control)
                            {
                                RemoveSelectedElement(me);
                                _mouseDownOnElement = false;
                            }
                            AddSelectedElement(me);
                            _mouseDownOnElement = false;
                            return;
                        }
                    }
                }
            }

            //When the user lets go of the select box we find out which elements it selected
            if (_selectBoxDraw && _mouseMoved)
            {
                ClearSelectedElements();
                List<ModelElement> elementBox = new List<ModelElement>();
                foreach (ModelElement me in _modelElements)
                {
                    if (_modelElementsSelected.Contains(me))
                        continue;
                    if (me.ElementInRectangle(PixelRectToVirtualRect(_selectBox)))
                    {
                        elementBox.Add(me);
                    }
                }
                for (int i = elementBox.Count - 1; i >= 0; i--)
                {
                    AddSelectedElement(elementBox[i]);
                }
            }

            //After a mouse up we reset the mouse variables
            _selectBoxDraw = false;
            Invalidate(_selectBox);
            _mouseDownOnElement = false;
            _mouseMoved = false;
        }
Exemple #8
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;
                }
            }
        }
Exemple #9
0
 private List<ModelElement> GetChildren(ModelElement parent)
 {
     List<ModelElement> listChildren = new List<ModelElement>();
     foreach (ModelElement mEl in _modelElements)
     {
         ArrowElement mAr = mEl as ArrowElement;
         if (mAr != null)
             if (mAr.StartElement != null)
                 if (mAr.StartElement == parent) listChildren.Add(mAr.StopElement);
     }
     return listChildren;
 }
Exemple #10
0
 private bool IsUpstreamOf(ModelElement potentialDownstream, ModelElement parent)
 {
     foreach (ModelElement mEl in _modelElements)
     {
         ArrowElement mAr = mEl as ArrowElement;
         if (mAr != null)
         {
             if (mAr.StartElement == null) continue;
             if (mAr.StartElement == parent)
             {
                 if (mAr.StopElement == null) continue;
                 if (mAr.StopElement == potentialDownstream) return true;
                 foreach (ModelElement children in GetChildren(mAr.StartElement))
                 {
                     if (IsUpstreamOf(potentialDownstream, children)) return true;
                 }
                 return false;
             }
         }
     }
     return false;
 }
Exemple #11
0
 /// <summary>
 /// Returns true if this model element is downstream of the potentialUpstream element
 /// </summary>
 /// <param name="potentialDownstream"></param>
 /// <returns></returns>
 public bool IsUpstreamOf(ModelElement potentialDownstream)
 { return IsUpstreamOf(potentialDownstream, this); }
Exemple #12
0
 private List<ModelElement> GetParents(ModelElement child)
 {
     List<ModelElement> listParents = new List<ModelElement>();
     foreach (ModelElement mEl in _modelElements)
     {
         ArrowElement mAr = mEl as ArrowElement;
         if (mAr != null)
             if (mAr.StopElement != null)
                 if (mAr.StopElement == child) listParents.Add(mAr.StartElement);
     }
     return listParents;
 }
Exemple #13
0
 /// <summary>
 /// Returns true if this model element is downstream of the potentialUpstream element
 /// </summary>
 /// <param name="potentialDownstream"></param>
 /// <returns></returns>
 public bool IsUpstreamOf(ModelElement potentialDownstream)
 {
     return(IsUpstreamOf(potentialDownstream, this));
 }