Edit Mesh Selection Example

The sample code below is from \MAXSDK\SAMPLES\MODIFIERS\EDITMESH.H. It shows how the extrude command mode of the Edit Mesh modifier uses the SelectionProcessor class to handle selection yet performs its own work after the selection process has been handled. The extrude command mode allows the user to select items with the mouse using all the standard logic such as box selection, and using the Ctrl and Alt keys. If the user drags the mouse however, the extrude operation is performed. By using the selection processor all the logic for selection is handled automatically.

A command mode has a method MouseProc() that returns an instance of MouseCallBack to handle the user / mouse interaction. In the extrude command mode's implementation of MouseProc() it returns an instance of a selection processor (which is derived from MouseCallBack). The constructor for the selection processor takes a pointer to another MouseCallBack. This is the extrude mouse callback. When the command mode is processing mouse input, the selection processor mouse callback is called first. It processes all the logic for the selection. If the user drags the mouse however the selection processor calls the extrude mouse callback to handle the extrude operation. Below are the class definitions showing how this is set up.

The mouse callback below implements the user / mouse interaction for the extrude operation.

class ExtrudeMouseProc : publicMouseCallBack
{
   private:
      MoveTransformer moveTrans;
     EditMeshMod *em;
     IObjParam *ip;
     IPoint2 om;
   public:
     //constructor
     ExtrudeMouseProc(EditMeshMod* mod, IObjParam *i)
       : moveTrans(i)
         {em=mod;ip=i;}
 
     int proc(HWND hwnd, int msg, int point, int flags, IPoint2 m );
};

The code below defines a class derived from GenModSelectionProcessor. The constructor passes on the mouse procedure for the extrusion interaction to the base class GenModSelectionProcessor. This allows the selection processor to call the extrusion mouse procedure.

class ExtrudeSelectionProcessor : public  GenModSelectionProcessor
{
   protected:
     HCURSOR GetTransformCursor();
   public:
     ExtrudeSelectionProcessor(ExtrudeMouseProc *mc, Modifier *m, IObjParam *i)
       : GenModSelectionProcessor(mc,m,i) {}
};

The command mode declares an instance of the selection processor and extrude mouse procedure. The extrude mouse procedure is passed into the selection processor.

class ExtrudeCMode : public CommandMode
{
   private:
      ChangeFGObject fgProc;
     ExtrudeSelectionProcessor mouseProc;
     ExtrudeMouseProc eproc;
     EditMeshMod* em;
   public:
     //Constructor
     ExtrudeCMode(EditMeshMod* mod, IObjParam *i)
       : fgProc(mod), mouseProc(&eproc,mod,i), eproc(mod,i)
         {em=mod;}
 
     int Class() { return MODIFY_COMMAND; }
     int ID()   { return CID_EXTRUDE; }
 
     MouseCallBack *MouseProc(int *numPoints)
       { *numPoints=2; return &mouseProc; }
      ChangeForegroundCallback *ChangeFGProc()
       { return &fgProc; }
     BOOL ChangeFG( CommandMode *oldMode )
       { return oldMode->ChangeFGProc() != &fgProc; }
 
     void EnterMode();
     void ExitMode();
};

See the source code in EDITMOPS.CPP for the full implementation of the methods of these classes.