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-2020 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 00230 class SoDataSensor : public SoDelayQueueSensor { 00231 00232 public: 00234 enum ChangeType { 00236 UNSPECIFIED, 00238 GROUP_ADD_CHILD, 00240 GROUP_INSERT_CHILD, 00242 GROUP_REPLACE_CHILD, 00244 GROUP_REMOVE_CHILD, 00246 GROUP_REMOVE_ALL_CHILDREN, 00248 FIELD_MULTIVALUE 00249 }; 00250 00254 SoDataSensor(); 00259 SoDataSensor(SoSensorCB *func, void *data); 00260 00261 // Destructor 00262 #ifndef HIDDEN_FROM_DOC 00263 virtual ~SoDataSensor(); 00264 #endif // HIDDEN_FROM_DOC 00265 00270 void setDeleteCallback(SoSensorCB *f, void *data = NULL) 00271 { deleteFunc = f; deleteData = data; } 00272 00282 SoNode * getTriggerNode() const; 00283 00293 SoField * getTriggerField() const; 00294 00303 SoPath * getTriggerPath() const; 00304 00311 void setTriggerPathFlag(SbBool flag) 00312 { doTrigPath = flag; } 00313 00321 void setTriggerFastEditInfoFlag(SbBool flag) 00322 { doTrigFastEditInfo = flag; } 00323 00328 SbBool getTriggerPathFlag() const 00329 { return doTrigPath; } 00330 00336 SbBool getTriggerFastEditInfoFlag() const 00337 { return doTrigFastEditInfo; } 00338 00347 ChangeType getTriggerType() const; 00348 00356 SoNode* getTriggerChild() const; 00357 00365 int getTriggerChildIndex() const; 00366 00373 int getTriggerMFieldStartIndex() const; 00374 00381 int getTriggerMFieldNumValues() const; 00382 00388 int getTriggerFastEditInfo() const; 00389 00390 // Override unschedule() to reset trigNode and trigPath. 00391 virtual void unschedule(); 00392 00393 private: 00394 // Override trigger to reset trigNode and trigPath, if 00395 // necessary. 00396 virtual void trigger(); 00397 00398 // Propagates modification notification through an instance. By 00399 // default, this schedules the sensor to be triggered and saves 00400 // some information from the notification list for use by the 00401 // callback function. Called by SoBase. 00402 virtual void notify(SoNotList *list); 00403 00404 // This is called when the base (path, field, node, whatever) is 00405 // deleted. All subclasses must implement this to do the right 00406 // thing. 00407 virtual void dyingReference() = 0; 00408 00409 // delete the list of dataSensor in the pending list 00410 static void clearPendingDeleteList(); 00411 00412 // add an SoDataSensor to the pending delete list 00413 static void addToPendingDeleteList(SoDataSensor* dataSensor); 00414 00415 private: 00416 // Invokes the delete callback 00417 void invokeDeleteCallback(); 00418 00419 private: 00420 SoSensorCB* deleteFunc; // CB and data for when attached SoBase 00421 void* deleteData; // is about to be deleted 00422 00423 class SoDataSensorData 00424 { 00425 public: 00426 SoDataSensorData() 00427 { 00428 reset(); 00429 } 00430 void reset() 00431 { 00432 trigNode = NULL; 00433 trigField = NULL; 00434 trigPath = NULL; 00435 00436 trigChildIndex = -1; 00437 trigChild = NULL; 00438 trigMFieldStartIndex = -1; 00439 trigMFieldNumValues = -1; 00440 m_flag.trigChangeType = UNSPECIFIED; 00441 m_flag.trigFromFastEdit = 0; 00442 } 00443 // usefull for debug 00444 bool isEmpty() const 00445 { 00446 return (trigNode==NULL) && (trigField==NULL) && (trigPath==NULL) && (m_flag.trigChangeType==UNSPECIFIED); 00447 } 00448 00449 void setTriggerType(ChangeType changeType) 00450 { 00451 //assert(changeType< (1<<31)); 00452 m_flag.trigChangeType = changeType; 00453 } 00454 00455 ChangeType getTriggerType() const 00456 { return (ChangeType)(m_flag.trigChangeType); } 00457 00458 void setTriggerFromFastEdit(bool flag) 00459 { m_flag.trigFromFastEdit = flag; } 00460 00461 bool isTriggerFromFastEdit() const 00462 { return m_flag.trigFromFastEdit; } 00463 00464 public: 00465 // members 00466 SoNode* trigNode; // Node that triggered sensor 00467 SoField* trigField; // Field that triggered sensor 00468 SoPath* trigPath; // Path to trigNode 00469 SoNode* trigChild; // changed child (if parent is SoGroup) 00470 int trigChildIndex; // index of changed child in group (if parent is SoGroup) 00471 int trigMFieldStartIndex; // index of the first value which change in the MField 00472 int trigMFieldNumValues; // num of values which change in the MField 00473 private: 00474 struct { 00476 unsigned int trigChangeType : 31; 00478 unsigned int trigFromFastEdit : 1; 00479 } m_flag; 00480 }; 00481 00482 // Store the current notification info (common to all threads) 00483 // Doing multiple notification before trigger is managed will result in only the last 00484 // notification to be triggered 00485 // any access read/write to this member should be lock/unlock protected. 00486 // as we cannot lock/unlock the trigger() method which use this member in readMode, 00487 // we copy m_notifyData in m_triggerNotifyData (with a specific lock) in order to keep 00488 // trigger call safe. 00489 SoDataSensorData m_notifyData; 00490 00491 SoDataSensorData m_triggerNotifyData; 00492 SbThreadSpinlock m_triggerNotifyDataMutex; 00493 00494 bool doTrigPath; // Whether to compute trigger path 00495 bool doTrigFastEditInfo; // Whether to compute fastEditInfo 00496 00497 // manage pending delete list 00498 static SbThreadSpinlock s_pendingDeleteListMutex; 00499 static std::list<SoDataSensor*> s_pendingDeleteList; 00500 00501 }; 00502 00503 #ifdef _WIN32 00504 #pragma warning(pop) 00505 #endif 00506 00507 #endif /* _SO_DATA_SENSOR_ */ 00508 00509