Class DragCreatingTool

GoDiagram®
v10.0.12
by Northwoods Software®

The DragCreatingTool lets the user create a new node by dragging in the background to indicate its size and position.

Inheritance
DragCreatingTool
Namespace: Northwoods.Go.Tools.Extensions
Assembly: DragCreatingAvalonia.dll
Syntax
public class DragCreatingTool : Tool
Remarks

The default drag selection box is a magenta rectangle. You can modify the Box to customize its appearance.

This tool will not be able to start running unless you have set the ArchetypeNodeData property to an object that can be copied and added to the diagram's model.

You can use this tool in a modal manner by executing:

diagram.CurrentTool = new DragCreatingTool();

Use this tool in a mode-less manner by executing:

myDiagram.ToolManager.MouseMoveTools.InsertAt(2, new DragCreatingTool());

However when used mode-lessly as a mouse-move tool, in MouseMoveTools, this cannot start running unless there has been a motionless delay after the mouse-down event of at least Delay milliseconds.

This tool does not utilize any Adornments or tool handles, but it does temporarily add the Box Part to the diagram. This tool does conduct a transaction when inserting the new node.

Constructors

DragCreatingTool()

Constructs a DragCreatingTool, sets Box to a magenta rectangle, and sets name of the tool.

Declaration
public DragCreatingTool()

Properties

ArchetypeNodeData

Gets or sets a data object that will be copied and added to the diagram's model each time this tool executes.

Declaration
public object ArchetypeNodeData { get; set; }
Property Value
Type Description
object
Remarks

The default value is null. The value must be non-null for this tool to be able to run. Setting this property does not raise any events.

Box

Gets or sets the Part used as the "rubber-band box" that is stretched to follow the mouse, as feedback for what area will be passed to InsertPart(Rect) upon a mouse-up.

Declaration
public Part Box { get; set; }
Property Value
Type Description
Part
Remarks

Initially this is a Part containing only a simple magenta rectangular Shape. The object to be resized should be named "SHAPE". Setting this property does not raise any events.

Modifying this property while this tool IsActive might have no effect.

Delay

Gets or sets the TimeSpan for which the mouse must be stationary before this tool can be started.

Declaration
public TimeSpan Delay { get; set; }
Property Value
Type Description
TimeSpan
Remarks

The default value is 175 milliseconds. A value of zero will allow this tool to run without any wait after the mouse down. Setting this property does not raise any events.

Methods

CanStart()

This tool can run when there has been a mouse-drag, far enough away not to be a click, and there has been delay of at least Delay milliseconds after the mouse-down before a mouse-move.

Declaration
public override bool CanStart()
Returns
Type Description
bool
Overrides

ComputeBoxBounds()

This just returns a Rect stretching from the mouse-down point to the current mouse point.

Declaration
public Rect ComputeBoxBounds()
Returns
Type Description
Rect

a Rect in document coordinates.

DoActivate()

Capture the mouse and show the Box.

Declaration
public override void DoActivate()
Overrides

DoDeactivate()

Release the mouse and remove any Box.

Declaration
public override void DoDeactivate()
Overrides

DoMouseMove()

Update the Box"s position and size according to the value of ComputeBoxBounds().

Declaration
public override void DoMouseMove()
Overrides

DoMouseUp()

Call InsertPart(Rect) with the value of a call to ComputeBoxBounds().

Declaration
public override void DoMouseUp()
Overrides

InsertPart(Rect)

Create a node by adding a copy of the ArchetypeNodeData object to the diagram's model, assign its Position and DesiredSize according to the given bounds, and select the new part.

Declaration
public virtual Part InsertPart(Rect bounds)
Parameters
Type Name Description
Rect bounds

a Point in document coordinates.

Returns
Type Description
Part

the newly created Part, or null if it failed.

Remarks

The actual part that is added to the diagram may be a Part, a Node, or even a Group, depending on the properties of the ArchetypeNodeData and the type of the template that is copied to create the part.