osnap.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: osnap.h
00004 
00005     DESCRIPTION:  Classes for Osnaps
00006 
00007     CREATED BY: John Hutchinson
00008 
00009     HISTORY: December 9, 1996
00010  *> Copyright (c) 1994, All Rights Reserved.
00011  **********************************************************************/
00012 
00013 #pragma once
00014 #include "export.h"
00015 #include "maxheap.h"
00016 #include "tab.h"
00017 #include "maxtypes.h"
00018 #include "point2.h"
00019 #include "strclass.h"
00020 
00021 // forward declarations
00022 class Point3;
00023 class Object;
00024 class IPoint2;
00025 class INode;
00026 class ViewExp;
00027 struct SnapInfo;
00028 class GraphicsWindow;
00029 class ObjectState;
00030 
00031 #define RESET 0
00032 #define NEXT 1
00033 #define ICON_WIDTH 32
00034 
00035 #define HILITE_NORMAL   (1<<0)
00036 #define HILITE_BOX      (1<<1)
00037 #define HILITE_NODE     (1<<2)//Not implemented
00038 #define HILITE_CROSSHAIR (1<<3)
00039 
00040 #define OSNAP_STATE _M("ObjectSnapPluginState")
00041 
00042 //Some types
00043 class Candidate: public MaxHeapOperators
00044 {
00045 public:
00046     Candidate(){};
00047     Candidate(Point3* p, int s, int num=0, ...);
00048     void SetMeshPoint(int which, const Point3 p);
00049     ~Candidate();
00050     Point3 *pt;
00051     int type;
00052     int count;
00053     Point3 *meshverts;
00054 };
00055 
00056 typedef Tab<Candidate *> CandidateTab;
00057 typedef void (*SnapCallback) (Object* pobj, IPoint2 *p) ;
00058 
00059 class OsnapMarker; 
00060 class HitMesh;
00061 class IOsnapManager;
00062 class MXS_IOsnap; // LAM: added 2/6/01 for MXS osnap exposure
00063 
00064 //The osnap class
00065 //===========================================================================
00066 
00084 #pragma warning(push)
00085 #pragma warning(disable:4100)
00086 class Osnap: public MaxHeapOperators {
00087     friend class OsnapHit;
00088     friend class MXS_IOsnap; // LAM: added 2/6/01 for MXS osnap exposure
00089     friend class OsnapManager;
00090     friend class OSnapDecorator;
00091 
00092 protected:
00093     BOOL *m_active;
00094     DllExport void _Snap(INode* inode, TimeValue t, ViewExp* vpt, IPoint2* p, SnapInfo* snap);
00095     DllExport Point3 _ReEvaluate(TimeValue t, OsnapHit *hit);
00098     DllExport boolean IsActive();
00101     DllExport void SetActive(int index, boolean state);
00104     DllExport boolean GetActive(int index);
00105 
00106     GraphicsWindow *m_hitgw;
00107 
00108     //Point management.
00109     //Some osnaps may want to maintain a list of potential hit points. 
00110     //Note that the points should be passed in in modeling space
00111     DllExport void AddCandidate(Point3 *pt, int type = -1, int num = 0,...);
00112     DllExport Point3 *GetCandidatePoint(int index);
00113     DllExport void GetCandidateMesh(int index, HitMesh *m);
00114     DllExport int GetCandidateType(int index);
00115     DllExport void ClearCandidates();
00116     DllExport int NumCandidates(){return point_candidates.Count();}
00117     DllExport virtual Point3 ReEvaluate(TimeValue t, OsnapHit *hit, Object* pobj);
00118 
00119     //Note: the following version uses an index into the candidate list
00120     DllExport BOOL CheckPotentialHit(int ptindex, Point2 cursor);
00121     //Note: the following version uses a remote matrix of points
00122     DllExport BOOL CheckPotentialHit(Point3 *p, int ptindex, Point2 cursor);
00123     int m_baseindex;//an index into the tool array
00124 
00125 public:
00126 
00129     DllExport Osnap();
00132     DllExport virtual ~Osnap();
00133     DllExport void Init();
00134 
00138     virtual int numsubs(){return 1;}; //the number of subsnaps this guy has
00144     DllExport virtual MCHAR *Category();//JH 01/04/98 {return NULL;}
00148     virtual Class_ID ClassID() { return Class_ID( 0, 0); }
00156     virtual BOOL UseCallbacks(){return FALSE;}
00160     virtual int NumCallbacks(){return 0;}
00184     DllExport virtual BOOL GetSupportedObject(INode* iNode, TimeValue t, ObjectState* os);
00185 
00191     virtual MSTR *snapname(int index)=0; // the snaps name to be displayed in the UI
00198     virtual MSTR *tooltip(int index){return NULL;} // the snaps name to be displayed in the UI
00216     virtual boolean ValidInput(SClass_ID scid, Class_ID cid)=0;//the objects it supports 
00225     virtual OsnapMarker *GetMarker(int index)=0; // single object might contain subsnaps
00244     virtual WORD HiliteMode(){return HILITE_NORMAL;}
00245     // UI methods
00249     virtual boolean BeginUI(HWND hwnd){return TRUE;}
00253     virtual void EndUI(HWND hwnd){};
00257     virtual HBITMAP getTools()=0;
00260     virtual HBITMAP getMasks()=0;
00274     virtual void Snap(Object* pobj, IPoint2 *p, TimeValue t){};
00293     virtual BOOL HitTest(Object* pobj, IPoint2 *p, TimeValue t){return TRUE;}
00303     virtual SnapCallback GetSnapCallback( int sub){ return NULL;}
00305     virtual WORD AccelKey(int index)=0;
00306 
00307 
00308 protected://data
00309     IOsnapManager *theman;
00310     // Holds the point candidates
00311     CandidateTab point_candidates; 
00312 };
00313 #pragma warning(pop)
00314 
00315 //-----------------------------------------------------------------------------
00316 //  OSnapDecorator
00317 
00324 class OSnapDecorator : public Osnap
00325 {
00326     public:
00327         // Ctor\Dtor
00328         DllExport OSnapDecorator(Osnap* pOsnap);
00329 
00331         DllExport virtual bool IsActive() const;
00333         DllExport virtual bool IsActive(const int nSnapIdx) const;
00335         DllExport virtual void Activate(const int nSnapIdx);
00337         DllExport virtual void Deactivate(const int nSnapIdx);
00338 
00339         // --- From Osnap
00340         DllExport virtual int numsubs(); 
00341         DllExport virtual MCHAR *Category();
00342         DllExport virtual Class_ID ClassID();
00343         DllExport virtual BOOL UseCallbacks();
00344         DllExport virtual int NumCallbacks();
00345         DllExport virtual BOOL GetSupportedObject(
00346             INode *iNode, TimeValue t, ObjectState *os);
00347 
00348         DllExport virtual MSTR *snapname(int index);
00349         DllExport virtual OsnapMarker *GetMarker(int index);
00350         DllExport virtual HBITMAP getTools();
00351         DllExport virtual HBITMAP getMasks();
00352         DllExport virtual WORD AccelKey(int index);
00353         DllExport virtual boolean ValidInput(SClass_ID scid, Class_ID cid);
00354 
00355         DllExport virtual boolean BeginUI(HWND hwnd);
00356         DllExport virtual void EndUI(HWND hwnd);
00357         DllExport virtual void Snap(Object* pobj, IPoint2 *p, TimeValue t);
00358         DllExport virtual BOOL HitTest(Object* pobj, IPoint2 *p, TimeValue t);
00359         DllExport virtual SnapCallback GetSnapCallback( int sub);
00360 
00361     protected:
00362         OSnapDecorator(); // not implemented
00363 
00364     private:
00365         Osnap*  mpOsnapImp;
00366 };
00367 
00368 
00369