Class Action
- Namespace
- CADability.Actions
- Assembly
- CADability.dll
Base class for all "Actions". An Action is an object, that receives various MouseInput events once it has been "Set" by a call to SetAction(Action). After performing the required tasks, the Action is removed from the ActionStack and the previous active action is resumed. The action on the bottom of the action stack is the SelectObjectsAction. Use the ConstructAction for typical drawing purposes, because it provides a convenient set of methods. If an action object is set by a call to SetAction(Action) the following sequence of calls to the new and the old action is executed:
- new action: OnSetAction() (as a reaction to SetAction(Action))
- old action: OnInactivate(Action, bool) (may call RemoveActiveAction() if desired)
- new action: OnActivate(Action, bool) (from now on the new action may receive mouse events).
- After the new action calls RemoveThisAction() or someone calls RemoveActiveAction() the new action will receive OnInactivate(Action, bool).
- The old action (if still on the stack) will receive a call to OnActivate(Action, bool) and finally
- the new action will receive a call to OnRemoveAction() as a last call.
public abstract class Action : ICommandHandler
- Inheritance
-
Action
- Implements
- Derived
- Inherited Members
Constructors
Action()
Creates a new Action and sets some default.
protected Action()
Fields
IgnoreForSnap
a list of objects that are not considered when snapping is resolved. Usually the object currently under construction (if any) is in this list.
protected GeoObjectList IgnoreForSnap
Field Value
MenuId
Contains the menu id of the command that invoked this action. used in OnUpdateCommand(string, CommandState).
protected string MenuId
Field Value
OnlyThisModel
If OnlyThisModel is not null, only those mouseevents are forwarded which come from a view that presents this model.
protected Model OnlyThisModel
Field Value
OnlyThisView
If OnlyThisView is not null, only those mouseevents are forwarded which come from this view.
protected IView OnlyThisView
Field Value
UseFilter
Use the active filter objects of the project for adjusting the mouse position (snap etc.)
public bool UseFilter
Field Value
ViewType
If ViewType is not null, only those mouseevents are forwarded which come from a view of that type.
protected Type ViewType
Field Value
Properties
ActiveDrawingPlane
Returns the active drawing plane, that is the drawing plane of the active view.
public Plane ActiveDrawingPlane { get; }
Property Value
AutoCursor
true: this class takes responsibility for setting the cursor, false: the derived class manages the cursor.
public bool AutoCursor { get; set; }
Property Value
ChangeTabInControlCenter
true: this class may change the selection in the control center false: this class may not change the selection in the control center
public bool ChangeTabInControlCenter { get; set; }
Property Value
CurrentMousePosition
Returns the current mouse position.
public Point CurrentMousePosition { get; }
Property Value
CurrentMouseView
The view from which the last OnMouseMove/Up/Down was evoked
protected IView CurrentMouseView { get; set; }
Property Value
FeedBack
Provides access to the "feedback" object, which is used to define visual feedback of the action. When objects in a model are modified, you will immediately see the feedback (if this model is visible in a ModelView). But sometimes you need more feedback, like arrows or imtermediate objects that change while the mousinput (or controlcenter input or some other conditions) change. Add those objects to the feedback and they will be displayed immediately.
public ActionFeedBack FeedBack { get; }
Property Value
Frame
Returns the frame (IFrame) of the context of this action. The frame also gives access to the project.
public IFrame Frame { get; }
Property Value
IsActive
Checks, whether this action is the currently active action
protected bool IsActive { get; }
Property Value
PreviousAction
The action below this one on the action stack, i.e. the action that was active before this one was set and becomes active again when this one is removed. Null if there is none or this action is not on the stack.
public Action PreviousAction { get; }
Property Value
WorksOnLayoutView
Determins, wether this action can work on a LayoutView. Default implementation returns false. Override, if your Action can work on a LayoutView.
public virtual bool WorksOnLayoutView { get; }
Property Value
Methods
AutoRepeat()
Defines, whether this Action should be repeated after it was removed. The default implementation returns false, override it if you want a different behaviour.
public virtual bool AutoRepeat()
Returns
- bool
true to repeat, false otherwise
AutoRepeated()
Called before OnSetAction() is called, if the action is created by the "autorepeat" machanism.
public virtual void AutoRepeated()
CurveHitTest(ICurve, Point)
Detects whether a given curve (ICurve) is touched by the cursor position given in mousePoint in respect to the active view. The setting "Select.Pick" gives the maximum pixel distance for the test.
public bool CurveHitTest(ICurve curve, Point mousePoint)
Parameters
Returns
- bool
true if the mouse position is close to the curve
GetID()
Must be implemented by derived class. Returns an identification string. All CADability actions return the unique strings like "Draw.Line.TwoPoints" or "Zoom"
public abstract string GetID()
Returns
- string
the identification of the action
GetObjectsUnderCursor(Point)
Returns a list of IGeoObjects that are close to the mouse point with respect to the current view.
public GeoObjectList GetObjectsUnderCursor(Point mousePoint)
Parameters
mousePointPointthe mouse position to test
Returns
- GeoObjectList
list of touched IGeoObjects
OnActivate(Action, bool)
The action has been activated. From now on it will receive calls of the mouse event methods like OnMouseMove(MouseEventArgs, IView).
public virtual void OnActivate(Action OldActiveAction, bool SettingAction)
Parameters
OldActiveActionActionthe action that was active
SettingActionbooltrue: if the action has bee set, false: if the action is resumed
OnCommand(string)
Override if you want to process menu commands with your action. Default implementation always returns false.
public virtual bool OnCommand(string MenuId)
Parameters
MenuIdstringthe menu id to process
Returns
- bool
true if processed, false if not
OnDelete()
This method will be called when the user presses the delete key. The default implementation does nothing.
public virtual bool OnDelete()
Returns
OnDelete(object)
This method will be called when the user presses the delete key. The default implementation does nothing.
public virtual bool OnDelete(object sender)
Parameters
senderobject
Returns
OnDisplayChanged(DisplayChangeArg)
Zooming or scrolling changed the visible aspect of the current view.
public virtual void OnDisplayChanged(DisplayChangeArg d)
Parameters
dDisplayChangeArgthe reason for the call
OnEnter()
This method will be called when the user presses the enter key. The default implementation does nothing.
public virtual bool OnEnter()
Returns
OnEnter(object)
This method will be called when the user presses the enter key. The default implementation does nothing.
public virtual bool OnEnter(object sender)
Parameters
senderobject
Returns
OnEscape()
This method will be called when the user presses the escape key. The default implementation does nothing.
public virtual bool OnEscape()
Returns
OnEscape(object)
This method will be called when the user presses the escape key. The default implementation does nothing.
public virtual bool OnEscape(object sender)
Parameters
senderobject
Returns
OnInactivate(Action, bool)
The action has been inactivated. No more calls to the mouse events will appear.
public virtual void OnInactivate(Action NewActiveAction, bool RemovingAction)
Parameters
NewActiveActionActionthe action that will become active
RemovingActionbooltrue: if called because the action is removed, false: if called when a new action is set on top of this action
OnMouseDown(MouseEventArgs, IView)
Override this method to react on the MouseDown event.
public virtual void OnMouseDown(MouseEventArgs e, IView vw)
Parameters
eMouseEventArgsMouseEventArgs of the call
vwIViewthe IView which contains the mouse
OnMouseEnter(EventArgs, IView)
Override this method to react on the MouseEnter event.
public virtual void OnMouseEnter(EventArgs e, IView vw)
Parameters
OnMouseHover(EventArgs, IView)
Override this method to react on the MouseHover event.
public virtual void OnMouseHover(EventArgs e, IView vw)
Parameters
OnMouseLeave(EventArgs, IView)
Override this method to react on the MouseLeave event.
public virtual void OnMouseLeave(EventArgs e, IView vw)
Parameters
OnMouseMove(MouseEventArgs, IView)
Override this method to react on the MouseMove event.
public virtual void OnMouseMove(MouseEventArgs e, IView vw)
Parameters
eMouseEventArgsMouseEventArgs of the call
vwIViewthe IView which contains the mouse
OnMouseUp(MouseEventArgs, IView)
Override this method to react on the MouseUp event.
public virtual void OnMouseUp(MouseEventArgs e, IView vw)
Parameters
eMouseEventArgsMouseEventArgs of the call
vwIViewthe IView which contains the mouse
OnMouseWheel(MouseEventArgs, IView)
Override this method to react on the MouseWheel event.
public virtual void OnMouseWheel(MouseEventArgs e, IView vw)
Parameters
eMouseEventArgsMouseEventArgs of the call
vwIViewthe IView which contains the mouse
OnRemoveAction()
Last event that is called when the action is removed from the action stack.
public virtual void OnRemoveAction()
OnSelected(MenuWithHandler, bool)
Override if your action needs to handle menu selection changes (very rare)
public virtual void OnSelected(MenuWithHandler selectedMenuItem, bool selected)
Parameters
selectedMenuItemMenuWithHandlerthe menu item that was selected or deselected
selectedbooltrue, if selected, false if deselected
OnSetAction()
First event that is called when the action is set via SetAction(Action)
public virtual void OnSetAction()
OnTab(object)
This method will be called when the user presses the tab key. The default implementation does nothing.
public virtual bool OnTab(object sender)
Parameters
senderobject
Returns
OnUpdateCommand(string, CommandState)
Override if you also override OnCommand(string) to manipulate the appearance of the corresponding menu item or the state of the toolbar button. The default implementation checks whether the MenuId from the parameter corresponds to the menuId member variable and checks the item if appropriate
public virtual bool OnUpdateCommand(string MenuId, CommandState CommandState)
Parameters
MenuIdstringmenu id the command state is queried for
CommandStateCommandStatethe command state to manipulate
Returns
OnViewsChanged()
Will be called if new views (LayoutView or ModelView) are created or removed from the project. Default implementation does nothing.
public virtual void OnViewsChanged()
RemoveThisAction()
Removes this action from the action stack if this action is on top of the action stack
public void RemoveThisAction()
SetCursor(DidSnapModes, IView)
Sets the cursor int hte provided view according to the provided snap mode. The cursors may be redefined by calling SetCursor(DidSnapModes, string)
protected void SetCursor(SnapPointFinder.DidSnapModes DidSnap, IView vw)
Parameters
DidSnapSnapPointFinder.DidSnapModesvwIView
SetCursor(DidSnapModes, string)
Sets the cursor name for different snap situation. The CursorTable contains the resources of the named cursors.
public void SetCursor(SnapPointFinder.DidSnapModes DidSnap, string CursorName)
Parameters
DidSnapSnapPointFinder.DidSnapModesthe snap situation
CursorNamestringthe name of the cursor
SnapPoint(MouseEventArgs, GeoPoint, IView, out DidSnapModes)
Returns a snap point according to the current snap settings in the given IView with respect to a basepoint. Sets the cursor if AutoCursor is true.
public GeoPoint SnapPoint(MouseEventArgs e, GeoPoint BasePoint, IView vw, out SnapPointFinder.DidSnapModes DidSnap)
Parameters
eMouseEventArgspoint in the view
BasePointGeoPointthe base point
vwIViewthe view
DidSnapSnapPointFinder.DidSnapModeskind of snap operation that was used
Returns
- GeoPoint
the best snapping point found
SnapPoint(MouseEventArgs, IView, out DidSnapModes)
Returns a snap point according to the current snap settings in the given IView. Sets the cursor if AutoCursor is true.
public GeoPoint SnapPoint(MouseEventArgs e, IView vw, out SnapPointFinder.DidSnapModes DidSnap)
Parameters
eMouseEventArgspoint in the view
vwIViewthe view
DidSnapSnapPointFinder.DidSnapModeskind of snap operation that was used
Returns
- GeoPoint
the best snapping point found
WorldDirection(Angle)
Returns a 3D vector in the world coordinate system corresponding to the given angle in the active drawing plane.
public GeoVector WorldDirection(Angle a)
Parameters
aAngleAngle of the requested direction
Returns
- GeoVector
Direction vector of the angle a
WorldLength(double)
Coverts the given length in pixel (screen) coordinates to w length in the model coordinate system of the active view
public double WorldLength(double ViewLength)
Parameters
ViewLengthdouble
Returns
WorldPoint(GeoPoint2D)
Returns a 3D point in the world coordinate system corresponding to the given 2D point in the active drawing plane.
public GeoPoint WorldPoint(GeoPoint2D p)
Parameters
pGeoPoint2D2D point in the drawing plane
Returns
- GeoPoint
3D point in the world coordinate system
WorldPoint(MouseEventArgs, IView)
Returns a GeoPoint in the model coordinate system that corresponds to the MouseEventArgs point. No snapping is performed. The drawing plane of the projection is used
public GeoPoint WorldPoint(MouseEventArgs e, IView vw)
Parameters
eMouseEventArgsa MouseEventArgs object, that contains the window coordinate
vwIViewthe IView of the MouseEventArgs
Returns
- GeoPoint
the model coordinate
WorldPoint(Point)
Returns a GeoPoint in the model coordinate system that corresponds to the Client point. No snapping is performed. The drawing plane of the projection is used
public GeoPoint WorldPoint(Point p)
Parameters
pPointPoint in the client coordinate system of the active view
Returns
- GeoPoint
the model coordinate