00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Nick Thompson (MMM yyyy) 00025 ** Modified by : Gavin Bell (MMM yyyy) 00026 ** Modified by : Paul Strauss (MMM yyyy) 00027 **=======================================================================*/ 00028 /*======================================================================= 00029 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00030 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00031 *** *** 00032 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00033 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00034 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00035 *** *** 00036 *** RESTRICTED RIGHTS LEGEND *** 00037 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00038 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00039 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00040 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00041 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00042 *** *** 00043 *** COPYRIGHT (C) 1996-2019 BY FEI S.A.S, *** 00044 *** BORDEAUX, FRANCE *** 00045 *** ALL RIGHTS RESERVED *** 00046 **=======================================================================*/ 00047 /*======================================================================= 00048 ** Modified by : VSG (MMM YYYY) 00049 **=======================================================================*/ 00050 00051 00052 #ifndef _SO_DATA_SENSOR_ 00053 #define _SO_DATA_SENSOR_ 00054 00055 class SoBase; 00056 class SoNode; 00057 class SoPath; 00058 class SoNotList; 00059 00060 #include <Inventor/sensors/SoDelayQueueSensor.h> 00061 #include <Inventor/threads/SbThreadStorage.h> 00062 #include <Inventor/threads/SbThreadSpinlock.h> 00063 #include <Inventor/STL/list> 00064 00065 #ifdef _WIN32 00066 #pragma warning(push) 00067 #pragma warning(disable:4251) 00068 #endif 00069 00228 class SoDataSensor : public SoDelayQueueSensor { 00229 00230 public: 00232 enum ChangeType { 00234 UNSPECIFIED, 00236 GROUP_ADD_CHILD, 00238 GROUP_INSERT_CHILD, 00240 GROUP_REPLACE_CHILD, 00242 GROUP_REMOVE_CHILD, 00244 GROUP_REMOVE_ALL_CHILDREN, 00246 FIELD_MULTIVALUE 00247 }; 00248 00252 SoDataSensor(); 00257 SoDataSensor(SoSensorCB *func, void *data); 00258 00259 // Destructor 00260 #ifndef HIDDEN_FROM_DOC 00261 virtual ~SoDataSensor(); 00262 #endif // HIDDEN_FROM_DOC 00263 00268 void setDeleteCallback(SoSensorCB *f, void *data = NULL) 00269 { deleteFunc = f; deleteData = data; } 00270 00280 SoNode * getTriggerNode() const; 00281 00291 SoField * getTriggerField() const; 00292 00301 SoPath * getTriggerPath() const; 00302 00309 void setTriggerPathFlag(SbBool flag) 00310 { doTrigPath = flag; } 00311 00319 void setTriggerFastEditInfoFlag(SbBool flag) 00320 { doTrigFastEditInfo = flag; } 00321 00326 SbBool getTriggerPathFlag() const 00327 { return doTrigPath; } 00328 00334 SbBool getTriggerFastEditInfoFlag() const 00335 { return doTrigFastEditInfo; } 00336 00345 ChangeType getTriggerType() const; 00346 00354 SoNode* getTriggerChild() const; 00355 00363 int getTriggerChildIndex() const; 00364 00371 int getTriggerMFieldStartIndex() const; 00372 00379 int getTriggerMFieldNumValues() const; 00380 00386 int getTriggerFastEditInfo() const; 00387 00388 // Override unschedule() to reset trigNode and trigPath. 00389 virtual void unschedule(); 00390 00391 private: 00392 // Override trigger to reset trigNode and trigPath, if 00393 // necessary. 00394 virtual void trigger(); 00395 00396 // Propagates modification notification through an instance. By 00397 // default, this schedules the sensor to be triggered and saves 00398 // some information from the notification list for use by the 00399 // callback function. Called by SoBase. 00400 virtual void notify(SoNotList *list); 00401 00402 // This is called when the base (path, field, node, whatever) is 00403 // deleted. All subclasses must implement this to do the right 00404 // thing. 00405 virtual void dyingReference() = 0; 00406 00407 // delete the list of dataSensor in the pending list 00408 static void clearPendingDeleteList(); 00409 00410 // add an SoDataSensor to the pending delete list 00411 static void addToPendingDeleteList(SoDataSensor* dataSensor); 00412 00413 private: 00414 // Invokes the delete callback 00415 void invokeDeleteCallback(); 00416 00417 private: 00418 SoSensorCB* deleteFunc; // CB and data for when attached SoBase 00419 void* deleteData; // is about to be deleted 00420 00421 class SoDataSensorData 00422 { 00423 public: 00424 SoDataSensorData() 00425 { 00426 reset(); 00427 } 00428 void reset() 00429 { 00430 trigNode = NULL; 00431 trigField = NULL; 00432 trigPath = NULL; 00433 00434 trigChildIndex = -1; 00435 trigChild = NULL; 00436 trigMFieldStartIndex = -1; 00437 trigMFieldNumValues = -1; 00438 m_flag.trigChangeType = UNSPECIFIED; 00439 m_flag.trigFromFastEdit = 0; 00440 } 00441 // usefull for debug 00442 bool isEmpty() const 00443 { 00444 return (trigNode==NULL) && (trigField==NULL) && (trigPath==NULL) && (m_flag.trigChangeType==UNSPECIFIED); 00445 } 00446 00447 void setTriggerType(ChangeType changeType) 00448 { 00449 //assert(changeType< (1<<31)); 00450 m_flag.trigChangeType = changeType; 00451 } 00452 00453 ChangeType getTriggerType() const 00454 { return (ChangeType)(m_flag.trigChangeType); } 00455 00456 void setTriggerFromFastEdit(bool flag) 00457 { m_flag.trigFromFastEdit = flag; } 00458 00459 bool isTriggerFromFastEdit() const 00460 { return m_flag.trigFromFastEdit; } 00461 00462 public: 00463 // members 00464 SoNode* trigNode; // Node that triggered sensor 00465 SoField* trigField; // Field that triggered sensor 00466 SoPath* trigPath; // Path to trigNode 00467 SoNode* trigChild; // changed child (if parent is SoGroup) 00468 int trigChildIndex; // index of changed child in group (if parent is SoGroup) 00469 int trigMFieldStartIndex; // index of the first value which change in the MField 00470 int trigMFieldNumValues; // num of values which change in the MField 00471 private: 00472 struct { 00474 unsigned int trigChangeType : 31; 00476 unsigned int trigFromFastEdit : 1; 00477 } m_flag; 00478 }; 00479 00480 // Store the current notification info (common to all threads) 00481 // Doing multiple notification before trigger is managed will result in only the last 00482 // notification to be triggered 00483 // any access read/write to this member should be lock/unlock protected. 00484 // as we cannot lock/unlock the trigger() method which use this member in readMode, 00485 // we copy m_notifyData in m_triggerNotifyData (with a specific lock) in order to keep 00486 // trigger call safe. 00487 SoDataSensorData m_notifyData; 00488 00489 SoDataSensorData m_triggerNotifyData; 00490 SbThreadSpinlock m_triggerNotifyDataMutex; 00491 00492 bool doTrigPath; // Whether to compute trigger path 00493 bool doTrigFastEditInfo; // Whether to compute fastEditInfo 00494 00495 // manage pending delete list 00496 static SbThreadSpinlock s_pendingDeleteListMutex; 00497 static std::list<SoDataSensor*> s_pendingDeleteList; 00498 00499 }; 00500 00501 #ifdef _WIN32 00502 #pragma warning(pop) 00503 #endif 00504 00505 #endif /* _SO_DATA_SENSOR_ */ 00506 00507