Class DataEntryMouseProc

3DS Max Plug-In SDK

Class DataEntryMouseProc

See Also: Class MouseCallBack, Class ViewExp, Class Object, Class Interface, Class Point3, Class Matrtix3, Class CreateMouseCallBack.

class DataEntryMouseProc : public MouseCallBack

Description:

This class is available in release 3.0 and later only.

This mouse proc allows drawing in multiple viewports, offsetting from the contruction plane, and orthogonal and angle snapping. This allows developers to support orthogonal snapping and angle snapping on creation (as the Bezier line tool does). If the user presses Shift while dragging the mouse, the point is snapped to the nearest quadrant (ortho snapping). If the Alt key is held, the point is snapped using the setting of the angle snap system.

The typical control flow of this class is that the OnPointSelected() method is called every time the user clicks in the viewport, and OnMouseAbort() is called when the user right clicks to finish the curve. RemoveLastPoint() is called when backspace is pressed, and OnMouseMove(Point3& p) is called every time the mouse moves (this lets the developer update the curve continuously).

This class is a sub-class of MouseCallBack, but it can also be used as a CreateMouseCallBack to create curves from the creation panel. To do this you embed a DataEntryMouseProc in a CreateMouseCallBack as show below. Notice the implementation of the virtual member StartNewCreation(). This is a new virtual method on CreateMouseCallBack that tells the system whether the mouse proc is in a state ready to create a new object. This was required, becase the "proc" function now always returns "CREATE_STOP" in order to implement multi-viewport input.

class TopCVCurveCreateMouseProc : public Em3DDataEntryMouseProc {

public:

TopCVCurveCreateMouseProc() :

Em3DDataEntryMouseProc() {}

virtual BOOL OnPointSelected();

virtual void OnMouseMove(Point3& p);

virtual BOOL AllowAnyViewport();

virtual void RemoveLastPoint();

virtual int OnMouseAbort();

virtual BOOL PerformRedraw() { return FALSE; }

void SetObj(EditableCVCurve* o) { mpOb = o; }

virtual BOOL StartNewCreation() { return mMouseClick == 0; }

friend class EditableCVCurve;

private:

EditableCVCurve * mpOb;

};

 

class EditableCVCurveCreateCallBack: public CreateMouseCallBack {

public:

EditableCVCurveCreateCallBack() {}

 

virtual int proc( ViewExp* vpt,int msg, int point, int flags, IPoint2 m, Matrix3& mat );

friend class CVBackspaceUser;

friend class EditableCVCurve;

virtual BOOL StartNewCreation() { return mMouseProc.StartNewCreation(); }

private:

void RemoveLastPoint();

TopCVCurveCreateMouseProc mMouseProc;

};

 

int EditableCVCurveCreateCallBack::proc(ViewExp* vpt,int msg, int point, int flags, IPoint2 m, Matrix3& mat)

{

spTransformMat = &mat;

return mMouseProc.proc(vpt->GetHWnd(), msg, point, flags, m);

}

static EditableCVCurveCreateCallBack nsCreateCB;

 

CreateMouseCallBack* EditableCVCurve::GetCreateMouseCallBack()

{

nsCreateCB.mMouseProc.SetObj(this);

nsCreateCB.mMouseProc.SetParams(hInstance, mpEM, 0);

return(&nsCreateCB);

}

Data Members:

protected:

Object* mpObject;

This a pointer to the object that is using the mouse proc.

int mMouseClick;

The number of clicks (i.e. selected points) the user has entered in creating this object. It is like the "point" parameter to "proc".

Tab<Point3> mPoints;

These are the 3D values of the points the user has selected.

Tab<IPoint2> mClickPoints;

These are the 2D viewport coordinates the user selected.

BOOL mLiftOffCP;

TRUE when in the mode where we lift off the construction plane

Methods:

public:

Prototype:

DataEntryMouseProc(Object* pObj, int cursor, HINSTANCE hInst);

Remarks:

Constructor. The data members are initialized as follows:

mpObject = pObj;

mCursor = cursor;

mInstance = hInst;

mMouseClick = 0;

mDoNotDouble = TRUE;

mLiftOffCP = FALSE;

mPreviousFlags = 0;

Prototype:

DataEntryMouseProc();

Remarks:

Constructor. The data members are initialized as follows:

mpObject = NULL;

mpIp = NULL;

mMouseClick = 0;

mDoNotDouble = TRUE;

mCursor = 0;

mLiftOffCP = FALSE;

mPreviousFlags = 0;

mInstance = 0;

Prototype:

virtual BOOL OnPointSelected();

Remarks:

Implemented by the Plug-In.

This method is called every time the user clicks in the viewport to enter data. This is the method in NURBS curves, for example, that adds a new CV or point to the curve. The method can query the mMouseClick member to see which point this is in the sequence (like the "point" parameter to traditional MouseCallback classes), and the 3D value of the point can be determined from mPoints[mMouseClick]. The data member mPoints contains all the 3D points selected, and mClickPoints is a table of the 2d points where the user clicked in the viewport.

Return Value:

The return value is used to determine whether the creation should continue or not. If it returns TRUE, more points are selected. If it returns FALSE, then the creation is done. In the case of NURBS, this is used to implement the feature that asks users if they want to close a curve when they click on the same point where they started the curve. If the answer is yes, this method returns FALSE, otherwise it always return TRUE.

Default Implementation:

{return TRUE; }

Prototype:

virtual void OnMouseMove(Point3& p);

Remarks:

Implemented by the Plug-In.

This method is called on every mouse move event.

Parameters:

Point3& p

The current point in world space of the mouse position.

Default Implementation:

{}

Prototype:

virtual BOOL AllowAnyViewport();

Remarks:

Implemented by the Plug-In.

This method tells the system when to allow drawing in mutiple viewports.

Return Value:

TRUE to allow drawing between viewports; FALSE to not allow drawing between viewports.

Default Implementation:

{ return TRUE; }

Prototype:

virtual void RemoveLastPoint();

Remarks:

Implemented by the Plug-In.

This method is called when the backspace key is pressed. Typically this deletes the last point entered by the user so they may correct its entry.

Default Implementation:

{}

Prototype:

virtual int OnMouseAbort();

Remarks:

Implemented by the Plug-In.

This method is called when the creation is finished.

Return Value:

Return one of the following value to indicate the state of the creation process:

CREATE_CONTINUE

The creation process should continue.

CREATE_STOP

The creation process has terminated normally.

CREATE_ABORT

The creation process has been aborted. The system will delete the created object and node.

Default Implementation:

{ return CREATE_ABORT; }

Prototype:

virtual BOOL PerformRedraw();

Remarks:

Implemented by the Plug-In.

This method indicates whether the mouse proc should perform redraws. When used in a CreateMouseCallBack, this should return FALSE.

Return Value:

TRUE to have the mouse proc perform redraws; otherwise FALSE.

Default Implementation:

{ return TRUE; }

Prototype:

virtual void SetUseConstructionLine(BOOL useLine) = 0;

Remarks:

Implemented by the Plug-In.

This method is called to tell the object to draw offset lines. This is called passing TRUE when the system enters the mode where points are lifted off the construction plane. It is telling the object that it needs to draw a line between the points supplied by SetConstructionLine(int i, Point3 p). It is called passing FALSE when the offset procedure is complete.

To see an example of how this is used, create a NURBS Point curve, and press the Control key while laying down a point. It enters a mode that lets you lift the point off the construction plane, and draws a red dotted line back to the CP to give some visual feedback.

Parameters:

BOOL useLine

TRUE if the mode is beginning; FALSE if it is ending.

Prototype:

virtual void SetConstructionLine(int i, Point3 p) = 0;

Remarks:

These methods need to be implemented to get the offset line drawn

This method is called with i==0 for the start point and with i==1 for the end point.

Parameters:

int i

The point index: 0 for the start or 1 for the end.

Point3 p

The point to draw to or from.

Prototype:

int proc(HWND hwnd, int msg, int point, int flags, IPoint2 m);

Remarks:

Implemented by the System.

This is the method where the developer defines the user / mouse interaction that takes place.

Parameters:

HWND hwnd

The window handle of the window the user clicked in. This is one of the viewports.

int msg

This message describes the type of event that occurred. See List of Mouse Callback Messages.

int point

The point number. This is 0 for the first click, 1 for the second, etc.

int flags

These flags describe the state of the mouse buttons. See List of Mouse Callback Flags.

IPoint2 m

The 2D screen point that the user clicked on.

Return Value:

CREATE_STOP is returned.

Note: Notice the implementation of the virtual member StartNewCreation(). This is a virtual method on CreateMouseCallBack that tells the system whether the mouse proc is in a state ready to creat a new object. This was required, becase this method now always returns CREATE_STOP in order to implement the multi-viewport input

Prototype:

void ClearCreationParams();

Remarks:

Implemented by the System.

This method clears the creation parameters. The data members are reset as follows:

mMouseClick = 0;

mPoints.SetCount(0);

mClickPoints.SetCount(0);

mLiftOffCP = FALSE;

mPreviousFlags = 0;

Prototype:

void SetParams(HINSTANCE hInst, Object* pObj, int cursor);

Remarks:

Implemented by the System.

This method sets the parameters as follows:

mpObject = pObj;

mCursor = cursor;

mInstance = hInst;