1 2 /* 3 A* ------------------------------------------------------------------- 4 B* This file contains source code for the PyMOL computer program 5 C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. 6 D* ------------------------------------------------------------------- 7 E* It is unlawful to modify or remove this copyright notice. 8 F* ------------------------------------------------------------------- 9 G* Please see the accompanying LICENSE file for further information. 10 H* ------------------------------------------------------------------- 11 I* Additional authors of this source file include: 12 -* 13 -* 14 -* 15 Z* ------------------------------------------------------------------- 16 */ 17 #ifndef _H_PyMOLObject 18 #define _H_PyMOLObject 19 20 21 /* literally a 3-D object...also an object object */ 22 23 #include"Base.h" 24 #include"Ray.h" 25 #include"Rep.h" 26 #include"Setting.h" 27 #include"Symmetry.h" 28 #include"PyMOLGlobals.h" 29 #include"View.h" 30 #include"Word.h" 31 #include"vla.h" 32 33 typedef char ObjectNameType[WordLength]; 34 35 enum cObject_t : int { 36 cObjectMolecule = 1, 37 cObjectMap = 2, 38 cObjectMesh = 3, 39 cObjectMeasurement = 4, 40 cObjectCallback = 5, 41 cObjectCGO = 6, 42 cObjectSurface = 7, 43 cObjectGadget = 8, 44 cObjectCalculator = 9, 45 cObjectSlice = 10, 46 cObjectAlignment = 11, 47 cObjectGroup = 12, 48 cObjectVolume = 13, 49 }; 50 51 /* 52 the object base class is in the process of being converted to support 53 states explicitly (an unfortunate early omission), which will allow 54 for simplified implementation of future multi-state objects. 55 */ 56 57 struct CObjectState { 58 PyMOLGlobals *G; 59 std::vector<double> Matrix; 60 std::vector<double> InvMatrix; CObjectStateCObjectState61 CObjectState() : G(nullptr){}; CObjectStateCObjectState62 CObjectState(PyMOLGlobals * G): G(G) {}; 63 }; 64 65 struct CObject { 66 PyMOLGlobals *G = nullptr; 67 cObject_t type; 68 ObjectNameType Name {}; 69 int Color = 0; 70 int visRep = 0; 71 float ExtentMin[3]{}, ExtentMax[3]{}; 72 int ExtentFlag = false, TTTFlag = false; 73 float TTT[16]{}; /* translate, transform, translate matrix (to apply when rendering) */ 74 CSetting *Setting = nullptr; 75 int Enabled = 0; /* read-only... maintained by Scene */ 76 int Context = 0; /* 0 = Camera, 1 = Unit Window, 2 = Scaled Window */ 77 pymol::vla<CViewElem> ViewElem; /* for animating objects via the TTT */ 78 79 /* not pickled */ 80 int grid_slot = 0; 81 CGO *gridSlotSelIndicatorsCGO = nullptr; 82 int Grabbed = 0; 83 84 // methods 85 int getCurrentState() const; 86 CObjectState* getObjectState(int state); getObjectStateCObject87 const CObjectState* getObjectState(int state) const 88 { 89 return const_cast<CObject*>(this)->getObjectState(state); 90 } 91 92 protected: 93 CObject(PyMOLGlobals* G); 94 95 /// @pre `0 <= state && state < getNFrame()` 96 /// @return NULL if state is empty (not active) _getObjectStateCObject97 virtual CObjectState* _getObjectState(int state) { return nullptr; } 98 99 public: 100 virtual ~CObject(); 101 updateCObject102 virtual void update() {} 103 virtual void render(RenderInfo* info); invalidateCObject104 virtual void invalidate(int rep, int level, int state) {} getNFrameCObject105 virtual int getNFrame() const { return 1; } 106 virtual void describeElement(int index, char* buffer) const; getCaptionCObject107 virtual char* getCaption(char* ch, int len) const { return nullptr; }; 108 virtual CSetting **getSettingHandle(int state); cloneCObject109 virtual CObject* clone() const { return nullptr; }; 110 virtual CSymmetry const* getSymmetry(int state = 0) const { return nullptr; } 111 virtual bool setSymmetry(CSymmetry const&, int state = 0) { return false; } 112 }; 113 114 int ObjectCopyHeader(CObject * I, const CObject * src); 115 void ObjectSetName(CObject * I, const char *name); 116 bool ObjectMakeValidName(char *name); 117 void ObjectMakeValidName(PyMOLGlobals * G, char *name, bool quiet = false); 118 void ObjectPurgeSettings(CObject * I); 119 void ObjectUseColor(CObject * I); 120 void ObjectUseColorCGO(CGO *cgo, CObject * I); 121 void ObjectSetRepVisMask(CObject * I, int repmask, int value); 122 void ObjectToggleRepVis(CObject * I, int rep); 123 void ObjectPrepareContext(CObject * I, RenderInfo * info); 124 void ObjectSetTTT(CObject * I, const float *ttt, int state,int store); 125 int ObjectGetTTT(CObject * I, const float **ttt, int state); 126 int ObjectGetTotalMatrix(CObject * I, int state, int history, double *matrix); 127 void ObjectCombineTTT(CObject * I, const float *ttt, int reverse_order, int store); 128 void ObjectTranslateTTT(CObject * T, const float *v,int store); 129 void ObjectSetTTTOrigin(CObject * I, float *origin); 130 void ObjectResetTTT(CObject * I,int store); 131 PyObject *ObjectAsPyList(CObject * I); 132 int ObjectFromPyList(PyMOLGlobals * G, PyObject * list, CObject * I); 133 int ObjectGetCurrentState(CObject * I, int ignore_all_states); 134 void ObjectAdjustStateRebuildRange(CObject * I, int *start, int *stop); 135 int ObjectMotion(CObject * I, int action, int first, 136 int last, float power, float bias, 137 int simple, float linear, int wrap, 138 int hand, int window, int cycles, int state, int quiet); 139 int ObjectGetSpecLevel(CObject * I, int frame); 140 void ObjectMotionTrim(CObject *I, int n_frame); 141 void ObjectDrawViewElem(CObject *I, BlockRect *rect, int frames, CGO *orthoCGO); 142 void ObjectStateInit(PyMOLGlobals * G, CObjectState * I); 143 void ObjectStatePurge(CObjectState * I); 144 int ObjectStateSetMatrix(CObjectState * I, double *matrix); 145 double *ObjectStateGetMatrix(CObjectState * I); 146 double *ObjectStateGetInvMatrix(CObjectState * I); 147 void ObjectStateTransformMatrix(CObjectState * I, double *matrix); 148 void ObjectStateResetMatrix(CObjectState * I); 149 PyObject *ObjectStateAsPyList(CObjectState * I); 150 int ObjectStateFromPyList(PyMOLGlobals * G, PyObject * list, CObjectState * I); 151 int ObjectStatePushAndApplyMatrix(CObjectState * I, RenderInfo * info); 152 void ObjectStatePopMatrix(CObjectState * I, RenderInfo * info); 153 void ObjectStateRightCombineMatrixR44d(CObjectState * I, double *matrix); 154 void ObjectStateLeftCombineMatrixR44d(CObjectState * I, double *matrix); 155 void ObjectStateCombineMatrixTTT(CObjectState * I, float *matrix); 156 int ObjectMotionModify(CObject *I,int action, int index, int count,int target, int freeze, int localize); 157 void ObjectMotionReinterpolate(CObject *I); 158 int ObjectMotionGetLength(CObject *I); 159 160 typedef struct _CObjectUpdateThreadInfo CObjectUpdateThreadInfo; 161 162 #define cObjectTypeAll 0 163 #define cObjectTypeObjects 1 164 #define cObjectTypeSelections 2 165 #define cObjectTypePublic 3 166 #define cObjectTypePublicObjects 4 167 #define cObjectTypePublicSelections 5 168 #define cObjectTypePublicNonGroupObjects 6 169 #define cObjectTypePublicGroupObjects 7 170 #define cObjectTypeNonGroupObjects 8 171 #define cObjectTypeGroupObjects 9 172 /* Note: public objects are ones that do not start with "_" */ 173 174 // object and object-state level setting 175 template <typename V> void SettingSet(int index, V value, CObject * obj, int state=-1) { 176 auto handle = obj->getSettingHandle(state); 177 if (handle) 178 SettingSet(obj->G, handle, index, value); 179 } 180 181 #endif 182