a2dRestrictionEngine Class Reference

Restriction engine for editing restrictions like snapping. More...

#include <restrict.h>

Inheritance diagram for a2dRestrictionEngine:

Inheritance graph
[legend]
Collaboration diagram for a2dRestrictionEngine:

Collaboration graph
[legend]

List of all members.

Public Types

enum  a2dSnapToWhat {
  snapToNone = 0x00000000, snapToObjectPosX = 0x00000001, snapToObjectPosY = 0x00000002, snapToObjectPos = snapToObjectPosX|snapToObjectPosY,
  snapToStart = 0x00000100, snapToEnd = 0x00000200, snapToPins = 0x00000400, snapToPinsUnconnected = 0x00000800,
  snapToObjectIntersection = 0x00001000, snapToObjectVertexes = 0x00002000, snapToObjectSegmentsMiddle = 0x00004000, snapToObjectSegments = 0x00008000,
  snapToGridPosX = 0x00010000, snapToGridPosY = 0x00020000, snapToGridPos = snapToGridPosX|snapToGridPosY, snapToPointPosX = 0x00040000,
  snapToPointPosY = 0x00080000, snapToPointPosXorY = 0x00100000, snapToPointPosXorYForce = 0x00200000, snapToPointPos = snapToPointPosX|snapToPointPosY,
  snapToPointAngleMod = 0x00400000, snapToPointAngleRational = 0x00800000, snapToPointAngle = snapToPointAngleMod|snapToPointAngleRational, snapToBoundingBox = 0x01000000,
  snapToObjectSnapVPath = 0x02000000, snapToAll = 0xFFFFFFFF
}

Public Member Functions

 a2dRestrictionEngine ()
 Constructor.
 ~a2dRestrictionEngine ()
 Destructor.
void SetSnapGrid (const a2dDoMu &x, const a2dDoMu &y)
 Set snapping grid (only position).
const a2dDoMuGetSnapGridX () const
 Get horizontal center snapping distance (zero if disabled).
const a2dDoMuGetSnapGridY () const
 Get vertical center snapping distance (zero if disabled).
void SetSnapOrigin (const a2dDoMu &x, const a2dDoMu &y)
 Set snapping origin (position grid offest/shift).
void SetSnapOriginX (const a2dDoMu &x)
void SetSnapOriginY (const a2dDoMu &y)
const a2dDoMuGetSnapOriginX () const
 Get snapping origin X (position grid offset/shift).
const a2dDoMuGetSnapOriginY () const
 Get snapping origin Y (position grid offset/shift).
void SetRotationAngle (double a)
 Set rotation angle raster.
double GetRotationAngle () const
 Get rotation angle raster.
int GetSnapThresHold () const
 used to snap vertexes to a pin or point like snapping features in objects.
void SetSnapThresHold (int thresHold)
 used to snap vertexes to a pin or point like snapping features in objects.
double GetSnapThresHoldWorld () const
 used to snap vertexes to a pin or point, for snapping features in objects.
void SetSnap (bool snap)
 enable all snapping features or not
bool GetSnap () const
 enable all snapping features or not
void SetSnapOnlyVisibleObjects (bool snapOnlyVisbleObjects)
 enable all snapping features for object only for visible object.
bool GetSnapOnlyVisibleObjects () const
 all snapping features for object only for visible object?
void SetRotationRational (wxUint32 nomMask, wxUint32 denMask)
 Set rotation rational raster nominator/denominator mask.
void SetSnapSourceFeatures (wxUint32 snapSourceFeatures)
void SetSnapSourceFeature (a2dSnapToWhat snapSourceFeature, bool value=true)
wxUint32 GetSnapSourceFeatures () const
void SetSnapToFeatures (wxUint32 snapToFeatures)
void SetSnapToFeature (a2dSnapToWhat snapToFeature, bool value=true)
bool GetSnapToFeature (a2dSnapToWhat snapToFeature) const
wxUint32 GetSnapToFeatures () const
virtual bool RestrictCanvasObjectAtVertexes (a2dCanvasObject *object, a2dPoint2D &point, double &dx, double &dy, wxUint32 sourceRequired=snapToAll, bool ignoreEngine=false)
 return the clossest vertex which can be snapped if any.
virtual bool RestrictVertexes (a2dVertexArray *segments, a2dPoint2D &point, double &dx, double &dy, wxUint32 sourceRequired=snapToAll, bool ignoreEngine=false)
 return the clossest vertex which can be snapped if any.
virtual bool RestrictVertexes (a2dVertexList *lsegments, a2dPoint2D &point, double &dx, double &dy, wxUint32 sourceRequired=snapToAll, bool ignoreEngine=false)
 return the clossest vertex which can be snapped if any.
virtual bool RestrictPoint (double &x, double &y, wxUint32 sourceRequired=snapToAll, bool ignoreEngine=false)
 Restrict a single point of a line or polyline.
virtual bool RestrictLine (a2dLine &line, wxUint32 sourceRequired=snapToAll, bool ignoreEngine=false)
 Restrict a single line.
virtual bool RestrictAngle (double *ang, wxUint32 sourceRequired=snapToAll, bool ignoreEngine=false)
 Restrict angle.
void SetRestrictPoint (double xSnap, double ySnap)
 sets the point for snapping to
const a2dPoint2DGetRestrictPoint () const
 to ask engine for the restrict point
a2dPoint2D GetPointToSnap () const
 to ask engine for the point that needs to be snapped to a a2dCanvasObject
void SetPointSnapResult (const a2dPoint2D &p)
 set the point that was snapped to a a2dCanvasObject vertex
bool SetPointSnapResultIfCloser (const a2dPoint2D &p)
 set the point that was snapped to a a2dCanvasObject vertex
a2dLineGetLineToSnap ()
 to ask engine for the line that needs to be snapped to a a2dCanvasObject
void SetParentSnapObjects (a2dCanvasObject *obj)
 parent object of objects that need to be snapped to
a2dCanvasObjectGetParentSnapObjects () const
 return pointer of the current parent object
void SetShiftKeyDown (bool shiftDown)
 some snapping may depend on shift key being down
bool GetShiftKeyDown () const
 some snapping may depend on shift key being down
void SetAltKeyDown (bool altDown)
 some snapping may depend on alt key being down
bool GetAltKeyDown () const
 some snapping may depend on alt key being down
void OnActivate (a2dViewEvent &viewevent)
 react on activation of a view, to set snap margin

Static Public Attributes

static a2dPropertyIdUint32PROPID_SnapSourceFeaturesMem
static a2dPropertyIdUint32PROPID_SnapSourceFeatures
static a2dPropertyIdUint32PROPID_SnapToFeatures
static a2dPropertyIdDoublePROPID_RotationAngle
static a2dPropertyIdUint32PROPID_RotationRationalNom
static a2dPropertyIdUint32PROPID_RotationRationalDen
static a2dPropertyIdInt32PROPID_SnapThresHold
static a2dPropertyIdPoint2DPROPID_PointToSnap
static a2dPropertyIdPoint2DPROPID_PointToRestrictTo
static a2dPropertyIdBoolPROPID_SnapOnlyVisbleObjects
static a2dPropertyIdBoolPROPID_Snap
static a2dPropertyIdBoolPROPID_SnapGetSet
static a2dPropertyIdBoolPROPID_AltDown
static a2dPropertyIdBoolPROPID_ShiftDown

Protected Member Functions

void SetInternal ()
double AngleRestrict (double angle)
 Restrict an angle.
void AngleRestrictVectorRot (double *vecx, double *vecy)
 Restrict the angle of a vector, keeping the vectors length.
void AngleRestrictVectorSkew (double *vecx, double *vecy, double otherx, double othery)
 Restrict the angle of a vector, keeping the vectors projection on the orthogonal of another vector.
double RationalRestrict (double angle)
 Rational restrict an angle.
void RationalRestrictVector (double *vecx, double *vecy)
 Rational restrict the angle of a vector.

Protected Attributes

wxUint32 m_snapSourceFeatures
 set to the a2dSnapToWhat features enabled by the engine for the source object
wxUint32 m_snapToFeatures
 set to the a2dSnapToWhat target features enabled by the engine and/or snap source object
a2dDoMu m_snapDistX
 horizontal position snapping grid distance
a2dDoMu m_snapDistY
 vertical position snapping grid distance
a2dDoMu m_originX
 horizontal grid snapping origin vs. coordinate origin
a2dDoMu m_originY
 vertical grid snapping origins vs. coordinate origin
double m_rotationAngle
 angle snapping angle in degrees
wxUint32 m_rotationRationalNom
 bit map of possible nominators (bit1->0.. bit32->31) for rational angle snapping
wxUint32 m_rotationRationalDen
 bit map of possible denominators (bit1->0.. bit32->31) for rational angle snapping
double * m_angleList
 sorted list of allowed rational angles
int m_nAngleList
 number of allowed rational angles
int m_snapThresHold
 threshold in pixels towards the snapping point.
a2dPoint2D m_pointToSnap
 set to point that is currently being snapped.
a2dPoint2D m_snappedPoint
 set to point that is snapped to m_pointToSnap
a2dPoint2D m_pointToRestrictTo
a2dLine m_lineToSnap
bool m_snapOnlyVisbleObjects
 if true snapping modes for object is only on visible object.
bool m_snap
 if true snapping modes are enabled, else non.
bool m_altDown
 snapping modifier when alt key is pressed
bool m_shiftDown
 snapping modifier when shift key is pressed
a2dCanvasObjectm_parentObject
 parent canvas object in a2dCanvasDocument on which snapping needs to be done.
a2dCanvasDocumentm_doc
 units of measurement taken from here, unless NULL
a2dCanvasViewm_view
 units of view taken from here, unless NULL
double m_docSnapDistX
double m_docSnapDistY
double m_docOriginX
double m_docOriginY

Friends

a2dSnapToWhat operator| (a2dSnapToWhat a, a2dSnapToWhat b)


Detailed Description

Restriction engine for editing restrictions like snapping.

The restriction engine is used by editing tools to restrict/snap editing of points, handles, pins, segments to the same things in other objects or to a grid on the whole drawing area. We call the object which need to be snapped the source, while the object to which we want to snap the targets. When the source is a single vertex, the is no extra feature to be set. But if the source is a a2dCanvasObject, one can specify which features in it can be snapped. For the targets, there or many more options, set by a2dSnapToWhat flags in m_snapToFeatures.

With rational snapping is meant snapping to angles whose tangent is a rational number with a small integer nominatior and denominator. The max nominator/denominator is the snapping parameter. For slanting angles, the absolute slanting angle (that is angle to the coordinate axis) is used, not the slanting angle relative to the rotated coordinate system. With rational snapping, you can solve many problems of slant and angle snapping, where you want to snap also to the horizontal and vertical grid. If we snap to angles with a small rational tan, the resulting points will also snap to a small fraction of the horiontal or vertical grid.

Each of these snapping modes may be enabled separately.

An example menu handler to enable/disable snapping:

    void MyDrawFrm::OnDrawRasterSnap(wxCommandEvent &event)
    {
        if( event.IsChecked() )
        {
            a2dRestrictionEngine
                *restrict=new a2dRestrictionEngine();
            restrict->SetSnapGrid(20,20);
            restrict->SetRotationAngle(15);
            restrict->SetSnapToFeatures( snapToGridPos | 
                   snapToObjectPos | snapToPinsUnconnected  |
                   snapToObjectVertexes | snapToPointAngleMod );

            a2dCanvasGlobals->SetRestrictionEngine(restrict);
        }
        else
        {
            a2dCanvasGlobals->SetRestrictionEngine(0);
        }
    }

Definition at line 76 of file restrict.h.


Member Enumeration Documentation

Flags for defining to what should be snapped to. To the drawing/snapping grid, and inside other a2dCanvasObject's

Enumerator:
snapToNone  no snap to modes specified
snapToObjectPosX  perform x position snapping
snapToObjectPosY  perform y position snapping
snapToStart  snap start point of line
snapToEnd  snap end point of line
snapToPins  snap to pins in other objects
snapToPinsUnconnected  snap to pins in other objects when not connected
snapToObjectIntersection  snap to intersections in other objects
snapToObjectVertexes  snap to other objects its vertexes, which are decided in a2dCanvasObject::RestrictToObject()
snapToObjectSegmentsMiddle  snap segments middle of other objects in a2dCanvasObject::RestrictToObject()
snapToObjectSegments  snap segments of other objects in a2dCanvasObject::RestrictToObject()
snapToGridPosX  perform x grid snapping
snapToGridPosY  perform y grid snapping
snapToPointPosX  perform x position snapping to a specific point
snapToPointPosY  perform y position snapping to a specific point
snapToPointPosXorY  perform snapping to X or Y of a specific point
snapToPointPosXorYForce  perform alligning to X or Y of a specific point
snapToPointAngleMod  perform angle snapping to multiples of m_rotationAngle to a specific point
snapToPointAngleRational  perform rational angle snapping to a specific point
snapToBoundingBox  perform snapping to boundingbox of objects
snapToObjectSnapVPath  perform snapping to snapping vector path returned by a2dCanvasObject::GetSnapVpath()

Definition at line 89 of file restrict.h.


Member Function Documentation

double a2dRestrictionEngine::GetSnapThresHoldWorld (  )  const

used to snap vertexes to a pin or point, for snapping features in objects.

Calculated from m_snapThresHold, taking into account the active a2dCanvasView.

Definition at line 84 of file restrict.cpp.

void a2dRestrictionEngine::SetRotationRational ( wxUint32  nomMask,
wxUint32  denMask 
) [inline]

Set rotation rational raster nominator/denominator mask.

nomMask bitX / denMask bit Y present an angle in radians to which can be snapped. e.g. if bit 2 is set in nomMask, and bit 6 is set in denMask, we will have 1/5 snap to 2*PI/5

Parameters:
nomMask each bit set here presents a number (bit1 number 0 until bit32 number 31)
denMask each bit set here presents a number (bit1 number 0 until bit32 number 31)

Definition at line 194 of file restrict.h.

void a2dRestrictionEngine::SetSnapSourceFeatures ( wxUint32  snapSourceFeatures  )  [inline]

set what snapping features or enabled for the source to snap to. see a2dSnapToWhat for snapping features.

Definition at line 199 of file restrict.h.

wxUint32 a2dRestrictionEngine::GetSnapSourceFeatures (  )  const [inline]

set what snapping features or enabled for the source to snap to. see a2dSnapToWhat for snapping features.

Definition at line 209 of file restrict.h.

void a2dRestrictionEngine::SetSnapToFeatures ( wxUint32  snapToFeatures  )  [inline]

set what snapping features or enabled for the target to snap to. see a2dSnapToWhat for snapping features.

Definition at line 213 of file restrict.h.

wxUint32 a2dRestrictionEngine::GetSnapToFeatures (  )  const [inline]

set what snapping features or enabled for the target to snap to. see a2dSnapToWhat for snapping features.

Definition at line 228 of file restrict.h.

bool a2dRestrictionEngine::RestrictCanvasObjectAtVertexes ( a2dCanvasObject object,
a2dPoint2D point,
double &  dx,
double &  dy,
wxUint32  sourceRequired = snapToAll,
bool  ignoreEngine = false 
) [virtual]

return the clossest vertex which can be snapped if any.

The source a2dCanvasObject is asked for its snapping features/vertexes via a2dCanvasObject::GetSnapVpath(), but only those ementioned in m_snapSourceFeatures. All the features returned will be tried to snap to neighbouring canvas objects, and eventually the grid. e.g. It calls for each vertex in the snapping path the function RestrictPoint(), and the clossest snapped point will be snapped to.

Parameters:
object object to be snapped to other snapping targets
point if a point to snap is found, it is stored here.
dx x distance from the returned point to the snapping point.
dy y distance from the returned point to the snapping point.
sourceRequired what the caller wants the snapping points in the object to restrict to. ( is ANDed with m_snapToFeatures )
ignoreEngine set to ignore engine its own snap modes.

Definition at line 693 of file restrict.cpp.

bool a2dRestrictionEngine::RestrictVertexes ( a2dVertexArray segments,
a2dPoint2D point,
double &  dx,
double &  dy,
wxUint32  sourceRequired = snapToAll,
bool  ignoreEngine = false 
) [virtual]

return the clossest vertex which can be snapped if any.

Parameters:
segments segments to be snapped to other snapping targets
point if a point to snap is found, it is stored here.
dx x distance from the returned point to the snapping point.
dy y distance from the returned point to the snapping point.
sourceRequired what the caller wants the snapping points to restrict to. ( is ANDed with m_snapToFeatures )
ignoreEngine set to ignore engine its own snap modes.

Definition at line 755 of file restrict.cpp.

bool a2dRestrictionEngine::RestrictVertexes ( a2dVertexList lsegments,
a2dPoint2D point,
double &  dx,
double &  dy,
wxUint32  sourceRequired = snapToAll,
bool  ignoreEngine = false 
) [virtual]

return the clossest vertex which can be snapped if any.

Parameters:
lsegments segments to be snapped to other snapping targets
point if a point to snap is found, it is stored here.
dx x distance from the returned point to the snapping point.
dy y distance from the returned point to the snapping point.
sourceRequired what the caller wants the snapping points to restrict to. ( is ANDed with m_snapToFeatures )
ignoreEngine set to ignore engine its own snap modes.

Definition at line 782 of file restrict.cpp.

bool a2dRestrictionEngine::RestrictPoint ( double &  x,
double &  y,
wxUint32  sourceRequired = snapToAll,
bool  ignoreEngine = false 
) [virtual]

Restrict a single point of a line or polyline.

Parameters:
x input x and output x after restriction
y input y and output y after restriction
sourceRequired what the caller wants the (x,y) to restrict to. ( is ANDed with m_snapToFeatures )
ignoreEngine set to ignore engine its own snap modes.
Returns:
true if the point was restricted

Definition at line 250 of file restrict.cpp.

bool a2dRestrictionEngine::RestrictLine ( a2dLine line,
wxUint32  sourceRequired = snapToAll,
bool  ignoreEngine = false 
) [virtual]

Restrict a single line.

Parameters:
line the line to restrict
sourceRequired what the caller wants the (x,y) to restrict to. ( is ANDed with m_snapToFeatures )
ignoreEngine set to ignore engine its own snap modes.
Returns:
true if the point was restricted

Definition at line 488 of file restrict.cpp.

bool a2dRestrictionEngine::RestrictAngle ( double *  ang,
wxUint32  sourceRequired = snapToAll,
bool  ignoreEngine = false 
) [virtual]

Restrict angle.

Parameters:
ang input angle and output angle after restriction
sourceRequired what the caller wants the (x,y) to restrict to. ( is ANDed with m_snapToFeatures )
ignoreEngine set to ignore engine its own snap modes.
Returns:
true if the point was restricted

Definition at line 493 of file restrict.cpp.

void a2dRestrictionEngine::SetRestrictPoint ( double  xSnap,
double  ySnap 
) [inline]

sets the point for snapping to

In modes:

  • a2dSnapToWhat::snapToPointPos
  • a2dSnapToWhat::snapToPointPosX
  • a2dSnapToWhat::snapToPointPosY
  • a2dSnapToWhat::snapToPointPos
  • a2dSnapToWhat::snapToPointPosXorY

Definition at line 308 of file restrict.h.

const a2dPoint2D& a2dRestrictionEngine::GetRestrictPoint (  )  const [inline]

to ask engine for the restrict point

For snapping modes that restrict to X,Y of the restrict Point.

Definition at line 314 of file restrict.h.

a2dPoint2D a2dRestrictionEngine::GetPointToSnap (  )  const [inline]

to ask engine for the point that needs to be snapped to a a2dCanvasObject

When engine is asked to snap a vertex/point, the result point to snap is set. This can be used by e.g. a2dCanvasObject::RestrictToObject() to snap to pins etc.

Definition at line 321 of file restrict.h.

void a2dRestrictionEngine::SetPointSnapResult ( const a2dPoint2D p  ) 

set the point that was snapped to a a2dCanvasObject vertex

When engine is asked to snap a vertex/point, the result point is set here. This is used e.g. a2dCanvasObject::RestrictToObject() to snap to pins etc.

Definition at line 227 of file restrict.cpp.

bool a2dRestrictionEngine::SetPointSnapResultIfCloser ( const a2dPoint2D p  ) 

set the point that was snapped to a a2dCanvasObject vertex

When engine is asked to snap a vertex/point, the result point is set here. But only of the new point is closer than the old one. This is used e.g. a2dCanvasObject::RestrictToObject() to snap to pins etc.

Definition at line 232 of file restrict.cpp.

a2dLine& a2dRestrictionEngine::GetLineToSnap (  )  [inline]

to ask engine for the line that needs to be snapped to a a2dCanvasObject

When engine is asked to snape a line, the line to snap is set. This can be used by e.g. a2dCanvasObject::RestrictToObject() to snap to othere lines, pins etc.

Definition at line 343 of file restrict.h.

void a2dRestrictionEngine::SetParentSnapObjects ( a2dCanvasObject obj  )  [inline]

parent object of objects that need to be snapped to

For snapping features where canvas objects are involved, this needs to be set to the parent object of the objects which can be snaped or can be snapped to. For example when needing to snap a vertex/point to the objects in a a2dcanvasView, set this parent object to the a2dcanvasView::GetShowObject().

Remarks:
when using the restriction engine, you much make sure this is set right each time.
Parameters:
obj,: pointer to object to set as parent

Definition at line 356 of file restrict.h.

a2dCanvasObject* a2dRestrictionEngine::GetParentSnapObjects (  )  const [inline]

return pointer of the current parent object

Returns:
: pointer to the current parent object.

Definition at line 362 of file restrict.h.


The documentation for this class was generated from the following files:
a2dRestrictionEngine Class Reference -- Tue Aug 31 18:33:27 2010 -- 31 Aug 2010 -- 1.5.5 -- wxArt2D -- . -- Main Page Reference Documentation