Exemple #1
0
 private bool IsDownstreamOf(ModelElement potentialUpstream, ModelElement child)
 {
     foreach (ModelElement mEl in ModelElements)
     {
         ArrowElement mAr = mEl as ArrowElement;
         if (mAr != null)
         {
             if (mAr.StopElement == null)
             {
                 continue;
             }
             if (mAr.StopElement == child)
             {
                 if (mAr.StartElement == null)
                 {
                     continue;
                 }
                 if (mAr.StartElement == potentialUpstream)
                 {
                     return(true);
                 }
                 foreach (ModelElement parents in GetParents(mAr.StartElement))
                 {
                     if (IsDownstreamOf(potentialUpstream, parents))
                     {
                         return(true);
                     }
                 }
                 return(false);
             }
         }
     }
     return(false);
 }
 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 #3
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 && mAr.StartElement != null && mAr.StartElement == parent)
                {
                    listChildren.Add(mAr.StopElement);
                }
            }
            return(listChildren);
        }
Exemple #4
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 && mAr.StopElement != null && mAr.StopElement == child)
                {
                    listParents.Add(mAr.StartElement);
                }
            }
            return(listParents);
        }
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>
        /// 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 #7
0
        /// <summary>
        /// When the users clicks the mouse this event fires
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            _mouseDownOnElement = false;
            _mouseMoved = false;
            Point virPt = PixelToVirtual(e.Location);
            _mouseOldPoint = MousePosition;

            //Deals with left clicks when the model is in link mode
            if (e.Button == MouseButtons.Left && _enableLinking)
            {
                //figure out if the user click on a element
                foreach (ModelElement me in _modelElements)
                {
                    if (me.PointInElement(virPt))
                    {
                        DataElement de = me as DataElement;
                        if (de != null)
                        {
                            BlankElement linkDestination = new BlankElement(_modelElements);
                            AddElement(linkDestination, virPt);
                            _linkArrow = AddArrow(de, linkDestination);
                            AddSelectedElement(linkDestination);
                            return;
                        }
                    }
                }
                _linkArrow = null;
                return;
            }

            //Deals with left clicks when the model is not in link mode
            if (e.Button == MouseButtons.Left)
            {
                //If the user left clicked on a selected element we do nothing
                foreach (ModelElement me in _modelElementsSelected)
                {
                    //Point pt = new Point(virPt.X - me.Location.X, virPt.Y - me.Location.Y);
                    if (me.PointInElement(virPt))
                    {
                        if (ModifierKeys == Keys.Control)
                        {
                            RemoveSelectedElement(me);
                            _mouseDownOnElement = false;
                        }
                        _mouseDownOnElement = true;
                        return;
                    }
                }

                //If the user left clicked on a unselected element we clear the selected list and highlight the new element
                foreach (ModelElement me in _modelElements)
                {
                    if (_modelElementsSelected.Contains(me))
                        continue;
                    // Point pt = new Point(virPt.X - me.Location.X, virPt.Y - me.Location.Y);
                    if (me.PointInElement(virPt))
                    {
                        if (ModifierKeys != Keys.Control)
                        {
                            ClearSelectedElements();
                        }
                        _mouseDownOnElement = true;
                        AddSelectedElement(me);
                        break;
                    }
                }
                //If the mouse is clicked on a white area we draw a box
                if (_mouseDownOnElement == false)
                {
                    ClearSelectedElements();
                    _selectBoxDraw = true;
                    _selectBoxPt = e.Location;
                    _selectBox = new Rectangle(virPt.X, virPt.Y, 0, 0);
                }
            }
        }