source: golgotha/src/max_plugin/sdk_inc/ref.h @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
  • Property svn:keywords set to Id
File size: 18.8 KB
Line 
1/**********************************************************************
2 *<
3        FILE:  ref.h
4
5        DESCRIPTION:  Defines Animatable, Reference Classes
6
7        CREATED BY: Rolf Berteig & Dan Silva
8
9        HISTORY: created 9 September 1994
10
11 *>     Copyright (c) 1994, All Rights Reserved.
12 **********************************************************************/
13
14#ifndef _REF_H_
15#define _REF_H_
16
17/* This module implements a first run at the concept of references.
18 * Some other stuff is in here to like time and intervals, but
19 * these are implemented only to get the reference classes working.
20 */
21typedef void *ReferenceData;
22typedef unsigned int TargetParam;
23
24typedef unsigned long PartID;
25
26// Bits for PartID
27
28
29// OBJECT STATE: SUB-PARTS
30// These are the 4 sub-channels object in the object state.
31// Dont change these defines 
32// (See CHANNELS.H for define of TOPO_CHANNEL, etc.)
33#define PART_TOPO                       TOPO_CHANNEL   
34#define PART_GEOM                       GEOM_CHANNEL   
35#define PART_TEXMAP                     TEXMAP_CHANNEL
36#define PART_MTL                        MTL_CHANNEL   
37#define PART_SELECT                     SELECT_CHANNEL
38#define PART_SUBSEL_TYPE        SUBSEL_TYPE_CHANNEL
39#define PART_DISPLAY            DISP_ATTRIB_CHANNEL   
40
41// These represent the TM and MTL parts of the object state
42#define PART_TM_CHAN            TM_CHANNEL              // (1<<7)
43#define PART_MTL_CHAN           GLOBMTL_CHANNEL // (1<<8)
44
45#define PART_OBJECT_TYPE        (1<<10)     
46#define PART_TM                         (1<<11)         // node TM
47#define PART_OBJ                        (PART_TOPO|PART_GEOM)
48
49#define PART_ALL                        (ALL_CHANNELS|PART_TM)
50
51// One of these is set as the PartID when notify dependents is
52// called with REFMSG_FLAGDEPENDENTS
53#define PART_PUT_IN_FG                          (1<<0)
54#define PART_SHOW_DEPENDENCIES          (1<<1)
55#define PART_SHOWDEP_ON                         (1<<2)
56
57/* The message passed to notify and evaluate.
58 */
59typedef unsigned int RefMessage;
60
61#define REFMSG_LOOPTEST                                 0x00000010
62#define REFMSG_TARGET_DELETED                   0x00000020
63#define REFMSG_MODAPP_DELETING                  0x00000021
64#define REFMSG_EVAL                                     0x00000030
65#define REFMSG_RESET_ORIGIN                     0x00000040
66#define REFMSG_CHANGE                                   0x00000050
67#define REFMSG_FLAGDEPENDENTS                   0x00000070
68#define REFMSG_TARGET_SELECTIONCHANGE   0x00000080
69#define REFMSG_BEGIN_EDIT                               0x00000090
70#define REFMSG_END_EDIT                                 0x000000A0
71#define REFMSG_DISABLE                                  0x000000B0
72#define REFMSG_ENABLE                                   0x000000C0
73#define REFMSG_TURNON                                   0x000000D0
74#define REFMSG_TURNOFF                                  0x000000E0
75#define REFMSG_LOOKAT_TARGET_DELETED    0x000000F0
76#define REFMSG_INVALIDATE_IF_BG                 0x000000F1
77// turn on and off the a modifier display
78#define REFMSG_MOD_DISPLAY_ON                   0x000000F2
79#define REFMSG_MOD_DISPLAY_OFF                  0x000000F3
80
81// Modifier uses this to tell Modapps to call their Eval() proc:
82#define REFMSG_MOD_EVAL                                 0x000000F4
83
84// Ask if its ok to change topology.  If any dependents have made
85//  topology-dependent mods, they should return REF_FAIL:
86// a return of REF_SUCCEED means that the answer is YES
87// a return of REF_FAIL means that the answer is NO
88#define REFMSG_IS_OK_TO_CHANGE_TOPOLOGY 0x000000F5
89
90
91// This main purpose of these notifications is to cause the tree
92// view to update when one of these events takes place.
93
94// Sent by a node when it has a child linked to it or unlinked from it.
95#define REFMSG_NODE_LINK                                0x000000F6
96
97// Sent by a node when it's name has been changed.
98#define REFMSG_NODE_NAMECHANGE                  0x000000F7
99
100// Sent by a node (or derived object) when the object it references changes.
101#define REFMSG_OBREF_CHANGE                             0x000000F8
102
103// Sent by a derived object when a modifier is a added or deleted.
104#define REFMSG_MODIFIER_ADDED                   0x000000F9
105
106// Sent when an animatable switches controllers for one of it's parameters.
107#define REFMSG_CONTROLREF_CHANGE                0x000000FA
108
109// A parameter block sends the message to it's client when it needs the anim
110// name of the ith parameter.
111// partID is set to a pointer to a GetParamName structure defined in iparamb.h
112#define REFMSG_GET_PARAM_NAME                   0x000000FB
113
114// A parameter block sends this message to it's client when it needs to know
115// the dimension type of the ith parameter.
116// partID is set to a pointer to a GetParamDim structure  defined in iparamb.h
117#define REFMSG_GET_PARAM_DIM                    0x000000FC
118
119// A controller can send this to it's client to get it's param dimension.
120// It should set partID to a ParamDimension **
121#define REFMSG_GET_CONTROL_DIM                  0x000000FD
122
123// This message is sent by a node when it's TM has changed because it was evaluated
124// at a different time. Normally this isn't neccessary - anyone depending on the
125// node's TM would have a validity interval that reflected the validity of the
126// TM. The axis system doesn't store a validity interval (it probably should) so this
127// message is needed for it.
128#define REFMSG_TM_CHANGE                                0x000000FE
129
130// A node sends this message when it's anim range changes.
131#define REFMSG_RANGE_CHANGE                             0x000000FF
132
133// Sent to the tree view when an animatable's line height changes.
134#define REFMSG_LINEHEIGHT_CHANGE                0x00000100
135
136// A controller should send this message to the treeview when it becomes animated.
137// If the user has the animated only filter on then the tree view will display this item.
138#define REFMSG_BECOMING_ANIMATED                0x00000101
139
140// This is intended mainly for the TrackView to tell it to re-generate
141// view below the message sender's level.
142#define REFMSG_SUBANIM_STRUCTURE_CHANGED 0x00000102
143
144// A target has had a ref deleted: Mtl's use this to tell mtlLib, in case
145// the # of node refs has gone to zero.
146#define REFMSG_REF_DELETED                      0x00000103
147
148// A target has had a ref Added: Mtl's use this to tell mtlLib, in case
149// the # of node refs has become non-zero.
150#define REFMSG_REF_ADDED                        0x00000104
151
152// Sent by an object that provides branching in the history to notify that
153// the structure of the branches changed.
154#define REFMSG_BRANCHED_HISTORY_CHANGED 0x00000105
155
156// The selection set sends this notification when it receives a REFMSG_CHANGE
157// from an item in the selection set. The selection set doesn't propogate the
158// REFMSG_CHANGE message.
159#define REFMSG_NODEINSELSET_CHANGED     0x00000106
160
161// Used to test dependencies
162#define REFMSG_TEST_DEPENDENCY  0x00000107
163
164// A Param block sends this to its client to ask if it should display
165// a distinct "Parameters" level in the track view hierarchy.
166// A pointer to a boolan is passed in for PartID: set this to the desired answer.
167// The default is NO -- in this case the message doesn't need
168// to be responded to.
169#define REFMSG_WANT_SHOWPARAMLEVEL      0x00000108
170
171// Theser are sent before and after a paste has been done: Sent as partID is
172// a pointer to a data structure containing three RefTargetHandle's: the ref maker,
173// the old target,  and the new target. The message is sent to the ref maker initially.
174#define REFMSG_BEFORE_PASTE     0x00000109
175#define REFMSG_NOTIFY_PASTE     0x0000010A
176
177// Sent when a UV Generator changes symmetry, so interactive texture display
178// updates.
179#define REFMSG_UV_SYM_CHANGE    0x0000010B
180
181// The first node that gets this message will fill in the
182// TSTR which partID points to with its name and stop the
183// message from propogating.
184#define REFMSG_GET_NODE_NAME                    0x0000010C
185
186// Sent by the selection set whenever it has just deleted nodes
187#define REFMSG_SEL_NODES_DELETED                0x0000010D
188
189// Sent *before* a reference target is pasted. Sent by the target
190// about to be replaced.
191#define REFMSG_PRENOTIFY_PASTE  0x0000010E
192
193// Sent when a shape enters a state where it'll be changing a lot and it
194// would be a good idea for anybody using it for mesh generation to suppress
195// updates.
196#define REFMSG_SHAPE_START_CHANGE       0x0000010F
197
198// Sent to terminate the above state
199#define REFMSG_SHAPE_END_CHANGE         0x00000110
200
201// A texture map has been removed: tells medit to remove
202// it from the viewport if it is active.
203#define REFMSG_TEXMAP_REMOVED   0x00000111
204
205// Sent by an unselected node to see if any selected nodes depend on it.
206// The partID param points to a boolean. If a selected node receives this
207// message it should set the boolean to true and return REF_STOP.
208#define REFMSG_FLAG_NODES_WITH_SEL_DEPENDENTS   0x00000112
209
210// The following are sent by objects which contain shapes when the selection,
211// position, or both change:
212#define REFMSG_CONTAINED_SHAPE_POS_CHANGE 0x00000120
213#define REFMSG_CONTAINED_SHAPE_SEL_CHANGE 0x00000121
214#define REFMSG_CONTAINED_SHAPE_GENERAL_CHANGE 0x00000122
215
216/* Message numbers above this value can be defined for use
217 * by sub-classes, below are reserved.
218 */
219#define REFMSG_USER             0x00010000
220
221
222/* Some return codes for references...
223 * There would probably be a bunch of these.
224 */
225enum RefResult {
226        REF_FAIL,
227        REF_SUCCEED,
228        REF_DONTCARE,
229        REF_STOP,
230        REF_INVALID     
231        };
232
233
234// Use this to disable ref counting on objects.
235#define MakeFakeHandleClass( className, handleClassName )       \
236        class className; typedef className* handleClassName             
237
238MakeFakeHandleClass( ReferenceTarget, RefTargetHandle );
239MakeFakeHandleClass( ReferenceMaker, RefMakerHandle );
240
241// This replaces the .Valid() method of handles.
242
243#define VALID(x) (x)
244
245// If this super class is passed to NotifyDependents() all dependents will be notified
246#define NOTIFY_ALL              0xfffffff0
247
248// For remapping references during a Clone.
249class RemapDir {
250        public:
251                virtual RefTargetHandle FindMapping(RefTargetHandle from)=0;
252                virtual void AddEntry(RefTargetHandle hfrom, RefTargetHandle hto)=0;
253                virtual RefTargetHandle CloneRef(RefTargetHandle oldTarg);
254                virtual void PatchPointer(RefTargetHandle* patchThis, RefTargetHandle oldTarg)=0;
255                virtual void Backpatch()=0;
256                virtual void Clear()=0;
257                virtual void DeleteThis()=0;
258        };
259
260
261/* Reference list link-node
262 */
263class CoreExport RefListItem {
264       
265        public:
266                RefMakerHandle  maker;
267                RefListItem             *next;
268                /* Constructors:
269                 */             
270                RefListItem( RefMakerHandle hmaker, RefListItem *list ) {
271                        next = list;
272                        maker = hmaker;
273                        }
274        };
275
276class CoreExport RefList {
277        public:
278                RefListItem* first;                                                               
279                RefList() { first = NULL;}
280                RefListItem*  FirstItem() { return first; }
281                RefResult DeleteItem(RefMakerHandle hmaker, int eval);
282                RefResult AddItem(RefMakerHandle hmaker );
283                void Cleanup();  // remove null entries
284        };
285
286class DeleteRefRestore;
287class MakeRefRestore;
288class ParamBlock;
289class ISave;
290class ILoad;
291class DependentIterator;
292
293class DependentEnumProc {
294        public:
295                // proc should return 1 when it wants enumeration to halt.
296                virtual int proc(ReferenceMaker *rmaker)=0;
297        };
298
299class SaveEnumProc {
300        public:
301                virtual void proc(ReferenceMaker *rmaker)=0;
302                virtual int terminate(ReferenceMaker *rmaker)=0;
303        };
304
305CoreExport RemapDir& NoRemap();
306
307// Here's a pointer to a RemapDir: you must delete it when done.
308CoreExport RemapDir* NewRemapDir();
309
310/* Everything can be a reference maker. We might want to keep this
311 * class separate from Animatable just for clarity.
312 */
313class  ReferenceMaker : public Animatable {
314        friend class DeleteRefRestore;
315        friend class MakeRefRestore;
316        friend class ReferenceTarget;
317        friend class ParamBlock;
318
319        public:         
320                /* Constructor:
321                 */
322                ReferenceMaker() { ClearAFlag(A_EVALUATING); }
323
324                // This routine is used when cloning reference makers, to delete old
325                // reference and make a new one.
326                CoreExport RefResult ReplaceReference(int which, RefTargetHandle newtarg, BOOL delOld=TRUE);
327               
328                // new format
329                CoreExport RefResult MakeRefByID(Interval refInterval,int which,RefTargetHandle htarget);
330
331                // Deletes all references from this RefMaker.
332                CoreExport RefResult DeleteAllRefsFromMe();
333
334                // Deletes all refs to this RefMaker/RefTarget.
335                // also sends REFMSG_TARGET_DELETED to all dependents.
336                virtual RefResult DeleteAllRefsToMe() { return REF_SUCCEED; }
337
338                // Deletes all references to AND from this guy.
339                CoreExport RefResult DeleteAllRefs();
340
341                // This deletes all reference to and from, sends REFMSG_TARGET_DELETED
342                // messages, handles UNDO, and deletes the object.     
343                CoreExport void DeleteMe();
344
345                // Enumerator to search back in the dependency network.
346                CoreExport virtual      int EnumDependents(DependentEnumProc* dep);
347
348                CoreExport virtual IOResult Save(ISave *isave);
349                CoreExport virtual IOResult Load(ILoad *iload);
350
351                // Access of refs. -- These functions must be implemented
352                // by ALL classes that make refs.
353                CoreExport virtual      int NumRefs();
354                CoreExport virtual RefTargetHandle GetReference(int i);
355                CoreExport virtual void SetReference(int i, RefTargetHandle rtarg);
356
357                // A maker can choose not to let TransferReferences() affect it. Note that plug-ins probably should not use this
358                // it is used by certain system objects that have references.
359                virtual BOOL CanTransferReference(int i) {return TRUE;}
360
361                //-- default Save enumeration.
362                CoreExport virtual void SaveEnum(SaveEnumProc& sep, BOOL isNodeCall=0);
363
364                CoreExport virtual RefResult
365                        NotifyDependents(Interval changeInt, PartID partID,
366                                RefMessage message, SClass_ID sclass=NOTIFY_ALL,
367                                BOOL propagate=TRUE, RefTargetHandle hTarg=NULL );
368
369                // Enumerate auxiliary files (e.g. bitmaps)
370                // The default implementation just calls itself on all references.
371                // Entities which actually need to load aux files must implement this,
372                // possibly calling ReferenceMaker::EnumAuxFiles also to recurse.
373                CoreExport virtual void EnumAuxFiles(NameEnumCallback& nameEnum, DWORD flags);
374
375                CoreExport RefResult DeleteReference( int i);
376                CoreExport int FindRef(RefTargetHandle rtarg);
377
378                // When a reference target's last "real" reference is deleted
379                // the target is deleted. Any leftover "non-real" reference makers
380                // will receive a REFMSG_TARGET_DELETED notification.
381                virtual BOOL IsRealDependency(ReferenceTarget *rtarg) {return TRUE;}
382
383        protected:
384                void BlockEval() { SetAFlag(A_EVALUATING); }
385                void UnblockEval() { ClearAFlag(A_EVALUATING); }               
386                int Evaluating() { return TestAFlag(A_EVALUATING); }           
387               
388                CoreExport RefResult StdNotifyRefChanged(Interval changeInt, RefTargetHandle hTarget,
389                   PartID partID, RefMessage message, BOOL propagate=TRUE);             
390
391        private:
392               
393
394                // StdNotifyRefChanged calls this, which can change the partID to new value
395                // If it doesnt depend on the particular message& partID, it should return
396                // REF_DONTCARE
397            virtual RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget,
398                 PartID& partID,  RefMessage message)=0;               
399       
400        };
401
402
403
404/* Not everything is a reference target...
405 */
406class  ReferenceTarget : public ReferenceMaker {
407        friend class DependentIterator;
408        friend class DeleteRefRestore;
409        friend class MakeRefRestore;
410        //friend class Remap;
411       
412        public:
413                ReferenceTarget() { ClearAFlag(A_LOCK_TARGET); }
414
415                // old format: will go away
416                CoreExport RefResult MakeReference(Interval refInterval,RefMakerHandle hmaker,int whichRef=-1);
417
418                CoreExport RefResult TestForLoop( Interval refInterval, RefMakerHandle hmaker);
419
420            CoreExport BOOL HasDependents();
421            CoreExport BOOL HasRealDependents();  // not counting tree view
422               
423                // Deletes all references to this refTarget.
424                CoreExport RefResult DeleteAllRefsToMe();
425
426                RefList& GetRefList() { return refs; }
427
428                // This function is called when a targets last ref is deleted
429                // Most subclasses will not need to override this. If you don't want to be
430                // deleted when the last ref is deleted, plug in a noop.
431                CoreExport virtual RefResult AutoDelete();
432
433                // This is called after deleting a reference to a ref target,
434                // in the case that the target was not deleted. If target needs
435                // to know, it should override this method.
436                virtual void RefDeleted() {} 
437
438                // This is called after making a reference-- If the
439                // target needs to know it can override it.
440                virtual void RefAdded(RefMakerHandle rm) {} 
441
442                // Transfer all the references from oldTarget to this
443                CoreExport RefResult TransferReferences(RefTargetHandle oldTarget, BOOL delOld=FALSE);
444
445                // Enumerator to search back in the dependency network.
446                CoreExport virtual      int EnumDependents(DependentEnumProc* dep);
447
448                CoreExport virtual RefTargetHandle Clone(RemapDir &remap = NoRemap());
449
450                // Checks if there are no references, and if object is deletable, deletes it.
451                CoreExport RefResult MaybeAutoDelete();
452
453
454                // This sends the REFMSG_FLAGDEPENDENTS message up the pipeline.
455                // There are two reasons to flag dependents:
456                // 1) To put the node in the FG plane. (PART_PUT_IN_FG)
457                // 2) To set the node's mesh color to green to indicate it is a
458                //    dependent. (PART_SHOW_DEPENDENCIES)
459                //    If the PART_SHOWDEP_ON bit is set, the dependency display is
460                //    turned on, otherwise it is turned off.
461                void FlagDependents( TimeValue t, PartID which=PART_PUT_IN_FG )
462                        {
463                        NotifyDependents(
464                                Interval(t,t),
465                                which,
466                                REFMSG_FLAGDEPENDENTS );
467                        }       
468
469                // This method is called to flag dependents into the FG.
470                // (Note that the above method is obsolete)
471                // The default implementation just sends out the notification.
472                // In particular, a slave controller could override this method
473                // and call its masters version of this method.
474                virtual void NotifyForeground(TimeValue t)
475                        {NotifyDependents(Interval(t,t),PART_PUT_IN_FG,REFMSG_FLAGDEPENDENTS);}
476
477                // To see if this reference target depends on something:
478                // first call BeginDependencyTest()
479                // then call NotifyDependents() on the thing with the REFMSG_TEST_DEPENDENCY
480                // if EndDependencyTest() returns TRUE this target is dependent on the thing.
481                void BeginDependencyTest() {ClearAFlag(A_DEPENDENCY_TEST);}
482                BOOL EndDependencyTest() {return TestAFlag(A_DEPENDENCY_TEST);}
483                       
484                // Notify all dependent RefMakers concerened with the message
485                CoreExport virtual RefResult
486                        NotifyDependents(Interval changeInt, PartID partID,
487                                RefMessage message, SClass_ID sclass=NOTIFY_ALL,
488                                BOOL propagate=TRUE, RefTargetHandle hTarg=NULL);
489        private:               
490               
491                // This is the list of active references that refer to us.
492                RefList refs;
493        };
494
495class DependentIterator {
496        ReferenceTarget *rt;
497        RefListItem *next;
498        public:
499        DependentIterator(ReferenceTarget *rtarg) { rt = rtarg; next = rt->refs.first; }
500        CoreExport ReferenceMaker *Next();
501        void Reset() { next = rt->refs.first; }
502        };
503
504class DeletedRestore: public RestoreObj {
505        RefMakerHandle anim, svanim;
506        public:
507                CoreExport DeletedRestore();
508                CoreExport DeletedRestore(RefMakerHandle an);
509                CoreExport ~DeletedRestore();
510                CoreExport void Restore(int isUndo);
511                CoreExport void Redo();
512                CoreExport TSTR Description();
513        };
514
515
516#endif
517
518
Note: See TracBrowser for help on using the repository browser.