/// <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.isDownstreamOf(te)) //If the tool is the data sets parent { MessageBox.Show(MessageStrings.linkErrorCircle, MessageStrings.linkError, MessageBoxButtons.OK, MessageBoxIcon.Information); break; } bool showError = true; for (int i = 0; i < te.Tool.InputParameters.Length; i++) { DataElement linkStart = _linkArrow.StartElement as DataElement; if (te.Tool.InputParameters[i].DefaultSpecified == false && te.Tool.InputParameters[i].ParamType == linkStart.Parameter.ParamType) { AddArrow(linkStart, te); te.Tool.InputParameters[i].Value = linkStart.Parameter.Value; te.Tool.InputParameters[i].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; }
/// <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); ae.Color = _arrowColor; ae.Name = sourceElement.Name + "_" + destElement.Name; AddElement(ae, ae.Location); return ae; }
/// <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) == true) { if (Control.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) == true) { if (Control.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); } } }