/// <summary> /// Initializes a new Instance of <see cref="T:Dataweb.NShape.WinFormsUI.ExportDiagramDialog" />. /// </summary> public ExportDiagramDialog(IDiagramPresenter diagramPresenter) { InitializeComponent(); Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath); if (diagramPresenter == null) throw new ArgumentNullException("diagramPresenter"); this.diagramPresenter = diagramPresenter; InitializeDialog(); }
/// <summary> /// Creates a new instance of Dataweb.NShape.WinFormsUI.InPlaceTextBox. /// </summary> public InPlaceTextBox(IDiagramPresenter owner, ICaptionedShape shape, int captionIndex, string currentText, string newText) { Construct(owner, shape, captionIndex, currentText, newText); // Set Text originalText = currentText; if (string.IsNullOrEmpty(newText)) { // Preselect the whole text if the user has not started typing yet base.Text = currentText; SelectAll(); } else { // Set the types text and place the cursor at the end of the text base.Text = newText; SelectionStart = Text.Length; } }
/// <override></override> public override bool ProcessMouseEvent(IDiagramPresenter diagramPresenter, MouseEventArgsDg e) { if (diagramPresenter == null) throw new ArgumentNullException("diagramPresenter"); bool result = false; MouseState newMouseState = MouseState.Empty; newMouseState.Buttons = e.Buttons; newMouseState.Modifiers = e.Modifiers; diagramPresenter.ControlToDiagram(e.Position, out newMouseState.Position); diagramPresenter.SuspendUpdate(); try { switch (e.EventType) { case MouseEventType.MouseDown: timer.Stop(); break; case MouseEventType.MouseMove: if (CurrentMouseState.Position != newMouseState.Position) { if (newMouseState.IsButtonDown(MouseButtonsDg.Left) && diagramPresenter.Project.SecurityManager.IsGranted(Permission.Insert)) { diagramPresenter.ControlToDiagram(e.Position, out p); currentStroke.Add(p.X, p.Y); } diagramPresenter.SetCursor(penCursorId); } Invalidate(diagramPresenter); break; case MouseEventType.MouseUp: if (newMouseState.IsButtonDown(MouseButtonsDg.Left) && diagramPresenter.Project.SecurityManager.IsGranted(Permission.Insert)) { StartToolAction(diagramPresenter, 0, newMouseState, false); strokeSet.Add(currentStroke); currentStroke = new Stroke(); timer.Start(); } break; default: throw new NShapeUnsupportedValueException(e.EventType); } } finally { diagramPresenter.ResumeUpdate(); } base.ProcessMouseEvent(diagramPresenter, e); return result; }
public override bool ProcessMouseEvent(IDiagramPresenter diagramPresenter, MouseEventArgsDg e) { if (diagramPresenter == null) throw new ArgumentNullException("diagramPresenter"); bool result = false; // get new mouse state MouseState newMouseState = MouseState.Empty; newMouseState.Buttons = e.Buttons; newMouseState.Modifiers = e.Modifiers; diagramPresenter.ControlToDiagram(e.Position, out newMouseState.Position); diagramPresenter.SuspendUpdate(); try { // Only process mouse action if the position of the mouse or a mouse button state changed //if (e.EventType != MouseEventType.MouseMove || newMouseState.Position != CurrentMouseState.Position) { // Process the mouse event switch (e.EventType) { case MouseEventType.MouseDown: // Start drag action such as drawing a SelectionFrame or moving selectedShapes/shape handles result = ProcessMouseDown(diagramPresenter, newMouseState); break; case MouseEventType.MouseMove: // Set cursors depending on HotSpots or draw moving/resizing preview result = ProcessMouseMove(diagramPresenter, newMouseState); break; case MouseEventType.MouseUp: // perform selection/moving/resizing result = ProcessMouseUp(diagramPresenter, newMouseState); break; default: throw new NShapeUnsupportedValueException(e.EventType); } //} } finally { diagramPresenter.ResumeUpdate(); } base.ProcessMouseEvent(diagramPresenter, e); return result; }
public override bool ProcessKeyEvent(IDiagramPresenter diagramPresenter, KeyEventArgsDg e) { if (diagramPresenter == null) throw new ArgumentNullException("diagramPresenter"); // if the keyPress was not handled by the base class, try to handle it here bool result = false; switch (e.EventType) { case KeyEventType.PreviewKeyDown: case KeyEventType.KeyPress: // do nothing break; case KeyEventType.KeyDown: case KeyEventType.KeyUp: if ((KeysDg) e.KeyCode == KeysDg.Delete) { // Update selected shape unter the mouse cursor because it was propably deleted if (!selectedShapeAtCursorInfo.IsEmpty && !diagramPresenter.SelectedShapes.Contains(selectedShapeAtCursorInfo.Shape)) { SetSelectedShapeAtCursor(diagramPresenter, CurrentMouseState.X, CurrentMouseState.Y, diagramPresenter.ZoomedGripSize, ControlPointCapabilities.All); Invalidate(diagramPresenter); } } // Update Cursor when modifier keys are pressed or released if (((KeysDg) e.KeyCode & KeysDg.Shift) == KeysDg.Shift || ((KeysDg) e.KeyCode & KeysDg.ShiftKey) == KeysDg.ShiftKey || ((KeysDg) e.KeyCode & KeysDg.Control) == KeysDg.Control || ((KeysDg) e.KeyCode & KeysDg.ControlKey) == KeysDg.ControlKey || ((KeysDg) e.KeyCode & KeysDg.Alt) == KeysDg.Alt) { MouseState mouseState = CurrentMouseState; mouseState.Modifiers = (KeysDg) e.Modifiers; int cursorId = DetermineCursor(diagramPresenter, mouseState); diagramPresenter.SetCursor(cursorId); } break; default: throw new NShapeUnsupportedValueException(e.EventType); } if (base.ProcessKeyEvent(diagramPresenter, e)) result = true; return result; }
private void IdentifyFigure(IDiagramPresenter diagramPresenter) { // Das ShapeSet berechnen Figure shapeSet = shaper.IdentifyShapes(strokeSet); // FeedBack foreach (FigureShape s in shapeSet.Shapes) { if (s == null) { Console.WriteLine("NotSupported"); } else { Console.WriteLine(s.Description); } } Console.Write("=> "); Figure figure = shaper.FindFigure(shapeSet); List <string> figureNames = new List <string>(); if (figure != null) { figureNames.AddRange(shaper.GetFigureNames(figure)); Console.WriteLine(figureNames.ToString()); } else { Console.Write("No idea" + Environment.NewLine); } if (diagramPresenter != null && figureNames.Count > 0) { if (diagramPresenter.Project.Repository == null) { throw new NullReferenceException("Unable to access repository of current ownerDisplay."); } matchingTemplates.Clear(); foreach (Template t in diagramPresenter.Project.Repository.GetTemplates()) { foreach (string figName in figureNames) { if (t.Shape.Type.FullName == figName) { matchingTemplates.Add(t); } } } if (matchingTemplates.Count == 1) { CreateShape(diagramPresenter, matchingTemplates[0]); } else if (matchingTemplates.Count > 1) { // ToDo: Create "CreateShapeFromTemplateAction" and build the ContextMenu from actions here // show context menu with matching templates // ToDo: Find a solution for displaying a context menu in the display //contextMenu.Items.Clear(); //foreach (Template t in matchingTemplates) { // ToolStripMenuItem item = new ToolStripMenuItem(t.Name, t.CreateThumbnail(16, 2), ContextMenuItem_Click); // item.Tag = t; // contextMenu.Items.Add(item); //} //int x, y, width, height; //this.GetStrokeSetBounds(out x, out y, out width, out height); //contextMenu.Show(x, y); } } Invalidate(diagramPresenter); strokeSet.Clear(); currentStroke.Clear(); OnToolExecuted(ExecutedEventArgs); }
public override void Invalidate(IDiagramPresenter diagramPresenter) { // Nothing to do }
public override void Draw(IDiagramPresenter diagramPresenter) { Shape shape = null; if (diagramPresenter.Diagram != null && diagramPresenter.Diagram.Shapes.Count > 0) shape = diagramPresenter.Diagram.Shapes.TopMost; if (shape != null) { diagramPresenter.ResetTransformation(); try { foreach (ControlPointId id in shape.GetControlPointIds(ControlPointCapabilities.All)) { if (id == ControlPointId.Reference) continue; IndicatorDrawMode drawMode = (SelectedPointId == id) ? IndicatorDrawMode.Highlighted : IndicatorDrawMode.Normal; if (shape.HasControlPointCapability(id, ControlPointCapabilities.Resize)) diagramPresenter.DrawResizeGrip(drawMode, shape, id); if (shape.HasControlPointCapability(id, ControlPointCapabilities.Connect | ControlPointCapabilities.Glue)) diagramPresenter.DrawConnectionPoint(drawMode, shape, id); if (shape.HasControlPointCapability(id, ControlPointCapabilities.Rotate)) diagramPresenter.DrawRotateGrip(drawMode, shape, id); } } finally { diagramPresenter.RestoreTransformation(); } } }
// prepare drawing preview of resize action private void PrepareMoveHandlePreview(IDiagramPresenter diagramPresenter, MouseState mouseState) { InvalidateConnectionTargets(diagramPresenter, CurrentMouseState.X, CurrentMouseState.Y); int distanceX = mouseState.X - ActionStartMouseState.X; int distanceY = mouseState.Y - ActionStartMouseState.Y; // calculate "Snap to Grid/ControlPoint" offset snapDeltaX = snapDeltaY = 0; if (selectedShapeAtCursorInfo.IsCursorAtGluePoint) { ControlPointId targetPtId; Shape targetShape = FindNearestControlPoint(diagramPresenter, selectedShapeAtCursorInfo.Shape, selectedShapeAtCursorInfo.ControlPointId, ControlPointCapabilities.Connect, distanceX, distanceY, out snapDeltaX, out snapDeltaY, out targetPtId); } else FindNearestSnapPoint(diagramPresenter, selectedShapeAtCursorInfo.Shape, selectedShapeAtCursorInfo.ControlPointId, distanceX, distanceY, out snapDeltaX, out snapDeltaY); distanceX += snapDeltaX; distanceY += snapDeltaY; // Reset all preview shapes to start values ResetPreviewShapes(diagramPresenter); // Move selected shapes ResizeModifiers resizeModifier = GetResizeModifier(mouseState); Point originalPtPos = Point.Empty; foreach (Shape selectedShape in diagramPresenter.SelectedShapes) { Shape previewShape = FindPreviewOfShape(selectedShape); // Perform movement if (previewShape.HasControlPointCapability(selectedShapeAtCursorInfo.ControlPointId, ControlPointCapabilities.Resize)) previewShape.MoveControlPointBy(selectedShapeAtCursorInfo.ControlPointId, distanceX, distanceY, resizeModifier); } InvalidateConnectionTargets(diagramPresenter, mouseState.X, mouseState.Y); }
// prepare drawing preview of move action private void PrepareMoveShapePreview(IDiagramPresenter diagramPresenter, MouseState mouseState) { // calculate the movement int distanceX = mouseState.X - ActionStartMouseState.X; int distanceY = mouseState.Y - ActionStartMouseState.Y; // calculate "Snap to Grid" offset snapDeltaX = snapDeltaY = 0; if (diagramPresenter.SnapToGrid && !selectedShapeAtCursorInfo.IsEmpty) { FindNearestSnapPoint(diagramPresenter, selectedShapeAtCursorInfo.Shape, distanceX, distanceY, out snapDeltaX, out snapDeltaY); distanceX += snapDeltaX; distanceY += snapDeltaY; } // Reset all shapes to start values ResetPreviewShapes(diagramPresenter); // Move (preview copies of) the selected shapes Rectangle shapeBounds = Rectangle.Empty; foreach (Shape originalShape in diagramPresenter.SelectedShapes) { // Get preview of the shape to move... Shape previewShape = FindPreviewOfShape(originalShape); // ...and move the preview shape to the new position previewShape.MoveTo(originalShape.X + distanceX, originalShape.Y + distanceY); } }
// Select shapes inside the selection frame private bool PerformFrameSelection(IDiagramPresenter diagramPresenter, MouseState mouseState) { bool multiSelect = mouseState.IsKeyPressed(KeysDg.Control) || mouseState.IsKeyPressed(KeysDg.Shift); diagramPresenter.SelectShapes(frameRect, multiSelect); return true; }
public override void Invalidate(IDiagramPresenter diagramPresenter) { if (diagramPresenter == null) throw new ArgumentNullException("diagramPresenter"); switch (CurrentAction) { case Action.None: case Action.Select: if (!selectedShapeAtCursorInfo.IsEmpty) { selectedShapeAtCursorInfo.Shape.Invalidate(); diagramPresenter.InvalidateGrips(selectedShapeAtCursorInfo.Shape, ControlPointCapabilities.All); } break; case Action.SelectWithFrame: diagramPresenter.DisplayService.Invalidate(frameRect); break; case Action.MoveHandle: case Action.MoveShape: if (Previews.Count > 0) { InvalidateShapes(diagramPresenter, Previews.Values, false); if (diagramPresenter.SnapToGrid) { Shape previewAtCursor = FindPreviewOfShape(selectedShapeAtCursorInfo.Shape); diagramPresenter.InvalidateSnapIndicators(previewAtCursor); } if (CurrentAction == Action.MoveHandle && selectedShapeAtCursorInfo.IsCursorAtGluePoint) InvalidateConnectionTargets(diagramPresenter, CurrentMouseState.X, CurrentMouseState.Y); } break; case Action.ConnectShapes: if (currentConnectionLine != null) currentConnectionLine.Invalidate(); break; default: throw new NShapeUnsupportedValueException(typeof (MenuItemDef), CurrentAction); } }
public IEnumerable<Shape> FindShapesSortedByZOrder(IDiagramPresenter diagramPresenter, int x, int y, ControlPointCapabilities pointCapabilities, int distance) { return FindVisibleShapes(diagramPresenter, x, y, pointCapabilities, distance).OrderByDescending(s => s.ZOrder); }
private bool IsMoveHandleFeasible(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo) { if (shapeAtCursorInfo.IsEmpty) return false; // Collides with the resize modifiers //if (mouseState.IsKeyPressed(KeysDg.Shift)) return false; if (shapeAtCursorInfo.Shape.HasControlPointCapability(shapeAtCursorInfo.ControlPointId, ControlPointCapabilities.Glue)) { if (!diagramPresenter.Project.SecurityManager.IsGranted(Permission.Connect, diagramPresenter.SelectedShapes)) return false; } else { if (!diagramPresenter.Project.SecurityManager.IsGranted(Permission.Layout, diagramPresenter.SelectedShapes)) return false; } if ( !shapeAtCursorInfo.Shape.HasControlPointCapability(shapeAtCursorInfo.ControlPointId, ControlPointCapabilities.Resize | ControlPointCapabilities.Glue /*| ControlPointCapabilities.Movable*/)) return false; if (diagramPresenter.SelectedShapes.Count > 1) { // GluePoints may only be moved alone if (shapeAtCursorInfo.Shape.HasControlPointCapability(shapeAtCursorInfo.ControlPointId, ControlPointCapabilities.Glue)) return false; // Check if all shapes that are going to be resizes are of the same type Shape lastShape = null; foreach (Shape shape in diagramPresenter.SelectedShapes) { if (lastShape != null && lastShape.Type != shape.Type) return false; lastShape = shape; } } return true; }
private bool IsConnectFromShapeFeasible(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo) { if (shapeAtCursorInfo.IsEmpty || mouseState.IsEmpty) return false; if (!diagramPresenter.Project.SecurityManager.IsGranted(Permission.Connect, shapeAtCursorInfo.Shape)) return false; if (shapeAtCursorInfo.Shape is FilterSetupShapeBase) { FilterSetupShapeBase filterShape = shapeAtCursorInfo.Shape as FilterSetupShapeBase; // only check OUTPUT count; we want to enforce the 'drag from OUTPUT, to INPUT' paradigm if (filterShape.OutputCount > 0) return true; } return false; }
public override void EnterDisplay(IDiagramPresenter diagramPresenter) { // Nothing to do }
public override void Invalidate(IDiagramPresenter diagramPresenter) { // Nothing to do }
/// <summary> /// Creates a new instance of Dataweb.NShape.WinFormsUI.InPlaceTextBox. /// </summary> public InPlaceTextBox(IDiagramPresenter owner, ICaptionedShape shape, int captionIndex, string currentText) : this(owner, shape, captionIndex, currentText, null) { }
public override IEnumerable <MenuItemDef> GetMenuItemDefs(IDiagramPresenter diagramPresenter) { // Nothing to do yield break; }
protected override void StartToolAction(IDiagramPresenter diagramPresenter, int action, MouseState mouseState, bool wantAutoScroll) { base.StartToolAction(diagramPresenter, action, mouseState, wantAutoScroll); // Empty selection frame frameRect.Location = mouseState.Position; frameRect.Size = Size.Empty; }
private bool PrepareConnection(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo, Action action) { // if we're not dealing with filter shapes... well, what the f**k?! get out of here! FilterSetupShapeBase shape = shapeAtCursorInfo.Shape as FilterSetupShapeBase; if (shape == null) throw new Exception("Can't connect a shape that isn't a FilterSetup shape!"); if (shape.OutputCount <= 0) return false; // get the starting control point for the line; ie. the first unused output for the shape, or the selected control point (if the mouse is over an output) ControlPointId connectionPoint = ControlPointId.None; if (shapeAtCursorInfo.IsCursorAtConnectionPoint && shape.GetTypeForControlPoint(shapeAtCursorInfo.ControlPointId) == FilterSetupShapeBase.FilterShapeControlPointType.Output) { connectionPoint = shapeAtCursorInfo.ControlPointId; } else { // try and find the first unconnected output if the mouse isn't over a specific control point for (int i = 0; i < shape.OutputCount; i++) { ControlPointId currentPoint = shape.GetControlPointIdForOutput(i); if (shape.GetConnectionInfos(currentPoint, null).Count() == 0) { connectionPoint = currentPoint; break; } } // if we couldn't find an unconnected point, just default to the first if (connectionPoint == ControlPointId.None) { connectionPoint = shape.GetControlPointIdForOutput(0); } } DataFlowConnectionLine line = (DataFlowConnectionLine) diagramPresenter.Project.ShapeTypes["DataFlowConnectionLine"].CreateInstance(); diagramPresenter.InsertShape(line); diagramPresenter.Diagram.Shapes.SetZOrder(line, 100); line.SecurityDomainName = ConfigFiltersAndPatching.SECURITY_DOMAIN_MOVABLE_SHAPE_WITH_CONNECTIONS; line.EndCapStyle = diagramPresenter.Project.Design.CapStyles.ClosedArrow; line.SourceDataFlowComponentReference = new DataFlowComponentReference(shape.DataFlowComponent, shape.GetOutputNumberForControlPoint( connectionPoint)); line.DestinationDataComponent = null; line.Connect(ControlPointId.FirstVertex, shape, connectionPoint); line.Disconnect(ControlPointId.LastVertex); line.MoveControlPointTo(ControlPointId.LastVertex, mouseState.X, mouseState.Y, ResizeModifiers.None); currentConnectionLine = line; StartToolAction(diagramPresenter, (int) action, ActionStartMouseState, true); return true; }
private bool ProcessMouseDown(IDiagramPresenter diagramPresenter, MouseState mouseState) { // Check if the selected shape at cursor is still valid if (!selectedShapeAtCursorInfo.IsEmpty && (!diagramPresenter.SelectedShapes.Contains(selectedShapeAtCursorInfo.Shape) || selectedShapeAtCursorInfo.Shape.HitTest(mouseState.X, mouseState.Y, ControlPointCapabilities.All, diagramPresenter.ZoomedGripSize) == ControlPointId.None)) { selectedShapeAtCursorInfo.Clear(); } // If no action is pending, try to start a new one... if (CurrentAction == Action.None) { // Get suitable action (depending on the currently selected shape under the mouse cursor) Action newAction = DetermineMouseDownAction(diagramPresenter, mouseState); if (newAction != Action.None) { StartToolAction(diagramPresenter, (int) newAction, mouseState, false); Invalidate(ActionDiagramPresenter); } } return false; }
private bool FinishConnection(IDiagramPresenter diagramPresenter) { bool result = false; if (currentConnectionLine.DestinationDataComponent != null && currentConnectionLine.SourceDataFlowComponentReference != null) { // check to see if what we're connecting it to is already connected to something (else): if so, remove that line. // (we don't need to remove the dataflow component as source; since a component can only have a single source, it // will be updated/overwritten by the 'SetComponentSource' below.) FilterSetupShapeBase otherShape = currentConnectionLine.GetConnectionInfo(ControlPointId.LastVertex, null).OtherShape as FilterSetupShapeBase; ControlPointId pointId = currentConnectionLine.GetConnectionInfo(ControlPointId.LastVertex, null).OtherPointId; if (otherShape != null) { foreach (ShapeConnectionInfo ci in otherShape.GetConnectionInfos(pointId, null)) { if (ci.OtherShape == currentConnectionLine) continue; diagramPresenter.DeleteShape(ci.OtherShape, false); } } currentConnectionLine.SecurityDomainName = ConfigFiltersAndPatching.SECURITY_DOMAIN_FIXED_SHAPE_NO_CONNECTIONS_DELETABLE; VixenSystem.DataFlow.SetComponentSource(currentConnectionLine.DestinationDataComponent, currentConnectionLine.SourceDataFlowComponentReference); OnDataFlowModificationMade(); result = true; } else { currentConnectionLine.Disconnect(ControlPointId.FirstVertex); currentConnectionLine.Disconnect(ControlPointId.LastVertex); diagramPresenter.DeleteShape(currentConnectionLine, false); } return result; }
private bool ProcessMouseMove(IDiagramPresenter diagramPresenter, MouseState mouseState) { bool result = true; if (!selectedShapeAtCursorInfo.IsEmpty && !diagramPresenter.SelectedShapes.Contains(selectedShapeAtCursorInfo.Shape)) selectedShapeAtCursorInfo.Clear(); switch (CurrentAction) { case Action.None: result = false; SetSelectedShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, diagramPresenter.ZoomedGripSize, ControlPointCapabilities.All); Invalidate(diagramPresenter); break; case Action.Select: ShapeAtCursorInfo shapeAtActionStartInfo = FindShapeAtCursor(ActionDiagramPresenter, ActionStartMouseState.X, ActionStartMouseState.Y, ControlPointCapabilities.Connect, 3, false); Action newAction = DetermineMouseMoveAction(ActionDiagramPresenter, mouseState, shapeAtActionStartInfo); // If the action has changed, prepare and start the new action if (newAction != CurrentAction) { switch (newAction) { // Select --> SelectWithFrame case Action.SelectWithFrame: StartToolAction(diagramPresenter, (int) newAction, ActionStartMouseState, true); PrepareSelectionFrame(ActionDiagramPresenter, ActionStartMouseState); break; // Select --> (Select shape and) move shape case Action.MoveShape: case Action.MoveHandle: if (selectedShapeAtCursorInfo.IsEmpty) { // Select shape at cursor before start dragging it PerformSelection(ActionDiagramPresenter, ActionStartMouseState, shapeAtActionStartInfo); SetSelectedShapeAtCursor(diagramPresenter, ActionStartMouseState.X, ActionStartMouseState.Y, 0, ControlPointCapabilities.None); } // Init moving shape CreatePreviewShapes(ActionDiagramPresenter); StartToolAction(diagramPresenter, (int) newAction, ActionStartMouseState, true); PrepareMoveShapePreview(ActionDiagramPresenter, ActionStartMouseState); break; case Action.ConnectShapes: bool connectionStarted = PrepareConnection(diagramPresenter, mouseState, shapeAtActionStartInfo, newAction); if (connectionStarted) StartToolAction(diagramPresenter, (int) newAction, ActionStartMouseState, true); break; case Action.None: case Action.Select: throw new Exception("Unhandled state change in MouseMove"); default: throw new Exception(string.Format("Unexpected {0} value: {1}", CurrentAction.GetType().Name, CurrentAction)); } } Invalidate(ActionDiagramPresenter); break; case Action.SelectWithFrame: PrepareSelectionFrame(ActionDiagramPresenter, mouseState); break; case Action.MoveHandle: PrepareMoveHandlePreview(ActionDiagramPresenter, mouseState); break; case Action.MoveShape: PrepareMoveShapePreview(diagramPresenter, mouseState); break; case Action.ConnectShapes: FilterSetupShapeBase filterShape = null; foreach ( var shape in FindShapesSortedByZOrder(ActionDiagramPresenter, mouseState.X, mouseState.Y, ControlPointCapabilities.None, 5)) { filterShape = shape as FilterSetupShapeBase; if (filterShape != null) break; } UpdateConnection(mouseState, filterShape); break; default: throw new NShapeUnsupportedValueException(typeof (Action), CurrentAction); } int cursorId = DetermineCursor(diagramPresenter, mouseState); if (CurrentAction == Action.None) diagramPresenter.SetCursor(cursorId); else ActionDiagramPresenter.SetCursor(cursorId); return result; }
// Apply the move action private bool PerformMoveShape(IDiagramPresenter diagramPresenter) { bool result = false; if (selectedShapeAtCursorInfo.IsEmpty) { // This should never happen... Debug.Assert(!selectedShapeAtCursorInfo.IsEmpty); } if (ActionStartMouseState.Position != CurrentMouseState.Position) { // calculate the movement int distanceX = CurrentMouseState.X - ActionStartMouseState.X; int distanceY = CurrentMouseState.Y - ActionStartMouseState.Y; //snapDeltaX = snapDeltaY = 0; //if (diagramPresenter.SnapToGrid) // FindNearestSnapPoint(diagramPresenter, SelectedShapeAtCursorInfo.Shape, distanceX, distanceY, out snapDeltaX, out snapDeltaY, ControlPointCapabilities.All); ICommand cmd = new MoveShapeByCommand(diagramPresenter.SelectedShapes, distanceX + snapDeltaX, distanceY + snapDeltaY); diagramPresenter.Project.ExecuteCommand(cmd); snapDeltaX = snapDeltaY = 0; snapPtId = ControlPointId.None; result = true; } return result; }
private bool ProcessMouseUp(IDiagramPresenter diagramPresenter, MouseState mouseState) { bool result = false; if (!selectedShapeAtCursorInfo.IsEmpty && !diagramPresenter.SelectedShapes.Contains(selectedShapeAtCursorInfo.Shape)) selectedShapeAtCursorInfo.Clear(); switch (CurrentAction) { case Action.None: // do nothing break; case Action.Select: // Perform selection, but only if it was with the left mouse button. If it was right mouse, ignore it. (Select is only // initiated on right mouse earlier (in ProcessMouseDown) to allow it to 'refine' into other drag actions. If it's // still a select by MouseUp, then we can ignore it.) if (!mouseState.IsButtonDown(MouseButtonsDg.Right)) { ShapeAtCursorInfo shapeAtCursorInfo = FindShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, ControlPointCapabilities.None, 0, false); result = PerformSelection(ActionDiagramPresenter, mouseState, shapeAtCursorInfo); SetSelectedShapeAtCursor(ActionDiagramPresenter, mouseState.X, mouseState.Y, ActionDiagramPresenter.ZoomedGripSize, ControlPointCapabilities.All); } EndToolAction(); break; case Action.SelectWithFrame: // select all selectedShapes within the frame result = PerformFrameSelection(ActionDiagramPresenter, mouseState); while (IsToolActionPending) EndToolAction(); break; case Action.MoveHandle: result = PerformMoveHandle(ActionDiagramPresenter); while (IsToolActionPending) EndToolAction(); break; case Action.MoveShape: result = PerformMoveShape(ActionDiagramPresenter); while (IsToolActionPending) EndToolAction(); break; case Action.ConnectShapes: result = FinishConnection(ActionDiagramPresenter); while (IsToolActionPending) EndToolAction(); break; default: throw new NShapeUnsupportedValueException(CurrentAction); } SetSelectedShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, diagramPresenter.ZoomedGripSize, ControlPointCapabilities.All); diagramPresenter.SetCursor(DetermineCursor(diagramPresenter, mouseState)); OnToolExecuted(ExecutedEventArgs); return result; }
// apply the resize action private bool PerformMoveHandle(IDiagramPresenter diagramPresenter) { bool result = false; Invalidate(diagramPresenter); int distanceX = CurrentMouseState.X - ActionStartMouseState.X; int distanceY = CurrentMouseState.Y - ActionStartMouseState.Y; // if the moved ControlPoint is a single GluePoint, snap to ConnectionPoints bool isGluePoint = false; if (diagramPresenter.SelectedShapes.Count == 1) isGluePoint = selectedShapeAtCursorInfo.Shape.HasControlPointCapability(selectedShapeAtCursorInfo.ControlPointId, ControlPointCapabilities.Glue); // Snap to Grid or ControlPoint bool calcSnapDistance = true; ShapeAtCursorInfo targetShapeInfo = ShapeAtCursorInfo.Empty; if (isGluePoint) { Point currentPtPos = selectedShapeAtCursorInfo.Shape.GetControlPointPosition(selectedShapeAtCursorInfo.ControlPointId); Point newPtPos = Point.Empty; newPtPos.Offset(currentPtPos.X + distanceX, currentPtPos.Y + distanceY); targetShapeInfo = FindConnectionTarget(ActionDiagramPresenter, selectedShapeAtCursorInfo.Shape, selectedShapeAtCursorInfo.ControlPointId, newPtPos, true, true); if (!targetShapeInfo.IsEmpty) { // If there is a target shape to connect to, get the position of the target connection point // and move the gluepoint exactly to this position calcSnapDistance = false; if (targetShapeInfo.ControlPointId != ControlPointId.Reference) { Point pt = targetShapeInfo.Shape.GetControlPointPosition(targetShapeInfo.ControlPointId); distanceX = pt.X - currentPtPos.X; distanceY = pt.Y - currentPtPos.Y; } else { // If the target point is the reference point, use the previously calculated snap distance // ToDo: We need a solution for calculating the nearest point on the target shape's outline distanceX += snapDeltaX; distanceY += snapDeltaY; } } } if (calcSnapDistance) { FindNearestSnapPoint(diagramPresenter, selectedShapeAtCursorInfo.Shape, selectedShapeAtCursorInfo.ControlPointId, distanceX, distanceY, out snapDeltaX, out snapDeltaY); distanceX += snapDeltaX; distanceY += snapDeltaY; } ResizeModifiers resizeModifier = GetResizeModifier(CurrentMouseState); if (isGluePoint) { ICommand cmd = new MoveGluePointCommand(selectedShapeAtCursorInfo.Shape, selectedShapeAtCursorInfo.ControlPointId, targetShapeInfo.Shape, targetShapeInfo.ControlPointId, distanceX, distanceY, resizeModifier); diagramPresenter.Project.ExecuteCommand(cmd); } else { ICommand cmd = new MoveControlPointCommand(ActionDiagramPresenter.SelectedShapes, selectedShapeAtCursorInfo.ControlPointId, distanceX, distanceY, resizeModifier); diagramPresenter.Project.ExecuteCommand(cmd); } snapDeltaX = snapDeltaY = 0; snapPtId = ControlPointId.None; result = true; return result; }
/// <summary> /// Decide which tool action is suitable for the current mouse state. /// </summary> private Action DetermineMouseDownAction(IDiagramPresenter diagramPresenter, MouseState mouseState) { if (mouseState.IsButtonDown(MouseButtonsDg.Left) || mouseState.IsButtonDown(MouseButtonsDg.Right)) { // if left or right buttons are down, start a 'select' action. This will refine to an // appropriate drag action later on (when mouse moving) based on the mouse button, otherwise // it will (de)select the shape on mouseup return Action.Select; } // Ignore other pressed mouse buttons return CurrentAction; }
public override IEnumerable<MenuItemDef> GetMenuItemDefs(IDiagramPresenter diagramPresenter) { // Nothing to do yield break; }
/// <summary> /// Decide which tool action is suitable for the current mouse state. /// </summary> private Action DetermineMouseMoveAction(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo) { switch (CurrentAction) { case Action.None: case Action.MoveHandle: case Action.MoveShape: case Action.SelectWithFrame: case Action.ConnectShapes: // Do not change the current action return CurrentAction; case Action.Select: if (mouseState.IsButtonDown(MouseButtonsDg.Left)) { // if we're doing something with the left mouse button, it will be a 'drag' style action if (!IsDragActionFeasible(mouseState)) { return CurrentAction; } // Check if cursor is over a control point and moving grips is feasible if (selectedShapeAtCursorInfo.IsCursorAtGrip) { if (IsMoveHandleFeasible(diagramPresenter, mouseState, selectedShapeAtCursorInfo)) return Action.MoveHandle; else return Action.SelectWithFrame; } else { // If there is no shape under the cursor, start a SelectWithFrame action, // otherwise start a MoveShape action bool canMove = false; if (!selectedShapeAtCursorInfo.IsEmpty) { // If there are selected shapes, check these shapes... canMove = IsMoveShapeFeasible(diagramPresenter, mouseState, selectedShapeAtCursorInfo); } else { // ... otherwise check the shape under the cursor as it will be selected // before starting a move action canMove = IsMoveShapeFeasible(diagramPresenter, mouseState, shapeAtCursorInfo); } return canMove ? Action.MoveShape : Action.SelectWithFrame; } } else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) { if (IsConnectFromShapeFeasible(diagramPresenter, mouseState, shapeAtCursorInfo)) { return Action.ConnectShapes; } } return CurrentAction; default: throw new NShapeUnsupportedValueException(CurrentAction); } }
public override void LeaveDisplay(IDiagramPresenter diagramPresenter) { // Nothing to do }
/// <override></override> public override bool ProcessKeyEvent(IDiagramPresenter diagramPresenter, KeyEventArgsDg e) { // nothing to do return(false); }
private void Construct(IDiagramPresenter owner, ICaptionedShape shape, int captionIndex, string currentText, string newText) { if (owner == null) throw new ArgumentNullException("owner"); if (shape == null) throw new ArgumentNullException("shape"); if (captionIndex < 0 || captionIndex >= shape.CaptionCount) throw new ArgumentOutOfRangeException("captionIndex"); // Set control styles SetStyle(ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); UpdateStyles(); // Set general properties this.BackColor = Color.Transparent; // Does not matter - see CreateParams() this.AutoScrollOffset = Point.Empty; this.ScrollBars = RichTextBoxScrollBars.None; this.BorderStyle = BorderStyle.None; // Set caption / style specific properties this.owner = owner; this.shape = shape; this.captionIndex = captionIndex; // Set Styles here because the ParagraphStyle is needed for resizing characterStyle = shape.GetCaptionCharacterStyle(captionIndex); paragraphStyle = shape.GetCaptionParagraphStyle(captionIndex); // set base' members SuspendLayout(); try { this.WordWrap = paragraphStyle.WordWrap; this.Font = ToolCache.GetFont(characterStyle); this.ZoomFactor = owner.ZoomLevel / 100f; // Get line height Size textSize = TextRenderer.MeasureText(((IDisplayService)owner).InfoGraphics, "Iq", Font); owner.DiagramToControl(textSize, out textSize); lineHeight = textSize.Height; DoUpdateBounds(); SelectAll(); SelectionAlignment = ConvertToHorizontalAlignment(paragraphStyle.Alignment); DeselectAll(); } finally { ResumeLayout(); } }
// Calculate new selection frame private void PrepareSelectionFrame(IDiagramPresenter diagramPresenter, MouseState mouseState) { Invalidate(ActionDiagramPresenter); frameRect.X = Math.Min(ActionStartMouseState.X, mouseState.X); frameRect.Y = Math.Min(ActionStartMouseState.Y, mouseState.Y); frameRect.Width = Math.Max(ActionStartMouseState.X, mouseState.X) - frameRect.X; frameRect.Height = Math.Max(ActionStartMouseState.Y, mouseState.Y) - frameRect.Y; Invalidate(ActionDiagramPresenter); }
// (Un)Select shape unter the mouse pointer private bool PerformSelection(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo) { bool result = false; bool multiSelect = mouseState.IsKeyPressed(KeysDg.Control) || mouseState.IsKeyPressed(KeysDg.Shift); // When selecting shapes conteolpoints should be ignored as the user does not see them // until a shape is selected const ControlPointCapabilities capabilities = ControlPointCapabilities.None; const int range = 0; // Determine the shape that has to be selected: Shape shapeToSelect = null; if (!selectedShapeAtCursorInfo.IsEmpty) { // When in multiSelection mode, unselect the selected shape under the cursor if (multiSelect) shapeToSelect = selectedShapeAtCursorInfo.Shape; else { // First, check if the selected shape under the cursor has children that can be selected shapeToSelect = selectedShapeAtCursorInfo.Shape.Children.FindShape(mouseState.X, mouseState.Y, capabilities, range, null); // Second, check if the selected shape under the cursor has siblings that can be selected if (shapeToSelect == null && selectedShapeAtCursorInfo.Shape.Parent != null) { shapeToSelect = selectedShapeAtCursorInfo.Shape.Parent.Children.FindShape(mouseState.X, mouseState.Y, capabilities, range, selectedShapeAtCursorInfo.Shape); // Discard found shape if it is the selected shape at cursor if (shapeToSelect == selectedShapeAtCursorInfo.Shape) shapeToSelect = null; if (shapeToSelect == null) { foreach ( Shape shape in selectedShapeAtCursorInfo.Shape.Parent.Children.FindShapes(mouseState.X, mouseState.Y, capabilities, range)) { if (shape == selectedShapeAtCursorInfo.Shape) continue; // Ignore layer visibility for child shapes shapeToSelect = shape; break; } } } } } // If there was a shape to select related to the selected shape under the cursor // (a child or a sibling of the selected shape or a shape below it), // try to select the first non-selected shape under the cursor if (shapeToSelect == null && shapeAtCursorInfo.Shape != null && shapeAtCursorInfo.Shape.ContainsPoint(mouseState.X, mouseState.Y)) shapeToSelect = shapeAtCursorInfo.Shape; // If a new shape to select was found, perform selection if (shapeToSelect != null) { // (check if multiselection mode is enabled (Shift + Click or Ctrl + Click)) if (multiSelect) { // if multiSelect is enabled, add/remove to/from selected selectedShapes... if (diagramPresenter.SelectedShapes.Contains(shapeToSelect)) { // if object is selected -> remove from selection diagramPresenter.UnselectShape(shapeToSelect); RemovePreviewOf(shapeToSelect); result = true; } else { // If object is not selected -> add to selection diagramPresenter.SelectShape(shapeToSelect, true); result = true; } } else { // ... otherwise deselect all selectedShapes but the clicked object ClearPreviews(); // check if the clicked shape is a child of an already selected shape Shape childShape = null; if (diagramPresenter.SelectedShapes.Count == 1 && diagramPresenter.SelectedShapes.TopMost.Children != null && diagramPresenter.SelectedShapes.TopMost.Children.Count > 0) { childShape = diagramPresenter.SelectedShapes.TopMost.Children.FindShape(mouseState.X, mouseState.Y, ControlPointCapabilities.None, 0, null); } diagramPresenter.SelectShape(childShape ?? shapeToSelect, false); result = true; } // validate if the desired shape or its parent was selected if (shapeToSelect.Parent != null) { if (!diagramPresenter.SelectedShapes.Contains(shapeToSelect)) if (diagramPresenter.SelectedShapes.Contains(shapeToSelect.Parent)) shapeToSelect = shapeToSelect.Parent; } } else if (selectedShapeAtCursorInfo.IsEmpty) { // if there was no other shape to select and none of the selected shapes is under the cursor, // clear selection if (!multiSelect) { if (diagramPresenter.SelectedShapes.Count > 0) { diagramPresenter.UnselectAll(); ClearPreviews(); result = true; } } } return result; }
/// <summary> /// Creates a new instance of Dataweb.NShape.WinFormsUI.InPlaceTextBox. /// </summary> public InPlaceTextBox(IDiagramPresenter owner, ICaptionedShape shape, int captionIndex, string currentText) : this(owner, shape, captionIndex, currentText, null) { }