00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef _SO_PATH_
00053 #define _SO_PATH_
00054
00055 #include <Inventor/misc/SoBase.h>
00056 #include <Inventor/nodes/SoNode.h>
00057 #include <Inventor/SoLists.h>
00058 #include <Inventor/lists/NodeIndex.h>
00059 #include <Inventor/STL/iostream>
00060 #include <Inventor/SbEventHandler.h>
00061
00062 class SoTempPath;
00063
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00079
00080 class SoPathList;
00081 class SoWriteAction;
00082
00187 class SoPath : public SoBase {
00188
00189 public:
00190
00194 SoPath();
00195
00199 SoPath(int approxLength);
00200
00204 SoPath(SoNode *node);
00205
00210 void setHead(SoNode *node);
00211
00216 void append(int childIndex);
00217
00223 void append(SoNode *childNode);
00224
00229 void append(const SoPath *fromPath);
00230
00235 void push(int childIndex);
00236
00241 void pop();
00242
00246 SoNode* getHead() const { return (SoNode*)(nodes.get(0)); }
00247
00251 SoNode* getTail() const;
00252
00259 SoNode* getNode(int i) const;
00260
00267 SoNode* getNode(const SoType type, int &i) const;
00268
00269
00276 SoNode* getNodeFromTail(int i) const;
00277
00282 int getIndex(int i) const;
00283
00288 int getInstanceIndex(int i) const;
00289
00296 int getIndexFromTail(int i) const;
00297
00305 int getInstanceIndexFromTail(int i) const;
00306
00311 int getLength() const;
00312
00318 void truncate(int start);
00319
00323 SbBool containsNode(const SoNode *node) const;
00324
00329 SbBool containsNode(const SoType type) const;
00330
00335 SbBool containsPath(const SoPath *path) const;
00336
00342 int findFork(const SoPath *path) const;
00343
00351 SoPath *copy(int startFromNodeIndex = 0, int numNodes = 0) const;
00352
00356 friend int operator ==(const SoPath &p1, const SoPath &p2);
00357
00361 friend std::ostream& operator << (std::ostream& os, const SoPath& path);
00362
00366 virtual SoType getTypeId() const;
00367
00371 static SoType getClassTypeId();
00372
00381 static SoPath *getByName(const SbName &name);
00390 static int getByName(const SbName &name, SoPathList &list);
00391
00392
00393 private:
00394
00395 static void initClass();
00396 static void exitClass();
00397
00399 SbEventHandler<SoPath*> m_onPathChange;
00400
00404 friend bool operator <(const SoPath &p1, const SoPath &p2);
00405
00406
00407
00408 void insertIndex(SoNode *parent, int newIndex);
00409
00410
00411
00412 void removeIndex(SoNode *parent, int oldIndex);
00413
00414
00415
00416 void replaceIndex(SoNode *parent, int index, SoNode *newChild);
00417
00418
00419 virtual void write(SoWriteAction *writeAction) const;
00420
00421
00422
00423
00424 SbBool isRelevantNotification(SoNotList *list) const;
00425
00426 void setNumPublic(int num);
00427
00428
00429
00430 void append(SoNode *node, int index);
00431
00432
00433
00434 void appendMI(SoNode *node, int index, int instanceIndex);
00435
00436
00437 SoPath *copy_(int startFromNodeIndex = 0, int numNodes = 0, bool createTempPath = false) const;
00438
00439
00440 inline const size_t& getHash() const
00441 {
00442 if ( m_pathHash != static_cast< size_t >(-1) )
00443 return m_pathHash;
00444 return computeHash();
00445 }
00446
00447
00448 void truncate(int start, SbBool doNotify);
00449
00450
00451
00452 SoNode* u_getHead() const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[0]); }
00453 SoNode* u_getTail() const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[getLength() - 1]); }
00454 SoNode* u_getNode(int i) const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[i]); }
00455 SoNode* u_getNodeFromTail(int i) const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[getLength() - 1 - i]); }
00456 int u_getIndex(int i) const { return (int)indices[i].index; }
00457 int u_getIndexFromTail(int i) const { return (int)indices[getLength() - 1 - i].index; }
00458 int u_getInstanceIndex(int i) const { return (int)indices[i].instanceIndex; }
00459
00460
00461
00466 void setHeadMI(SoNode *node, int instanceIndex);
00467
00473 void appendMI(int childIndex, int instanceIndex);
00474
00481 void appendMI(SoNode *childNode, int instanceIndex);
00482
00487 void pushMI(int childIndex, int instanceIndex);
00488
00489 bool isForwardTraversing() const;
00490
00491 private:
00492
00493 void auditPath(SbBool flag) { doAuditors = flag; }
00494
00495
00496 virtual SbBool readInstance(SoInput *in, unsigned short flags);
00497
00498 virtual ~SoPath();
00499
00500 private:
00501 const size_t& computeHash() const;
00502
00503 SoNodeList nodes;
00504 std::vector<inventor::NodeIndex> indices;
00505 mutable int numPublic;
00506 mutable int minNumPublic;
00507 SbBool doAuditors;
00508 static SoType classTypeId;
00509
00510
00511 int getFullLength() const
00512 { return nodes.getLength(); }
00513
00514
00515 static void* createInstance(SoType* dynamicType = NULL);
00516
00517
00518 mutable size_t m_pathHash;
00519
00520 friend class SoFullPath;
00521 friend class SoTempPath;
00522 friend class SoAction;
00523 friend class SoPathNoRef;
00524 friend class SoTraversalPassImpl;
00525
00526 };
00527
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00540
00604 class SoFullPath : public SoPath {
00605
00606 public:
00607
00608
00609
00611 void pop()
00612 { truncate(getFullLength() - 1); }
00613
00615 SoNode *getTail() const
00616 { return (nodes[getFullLength() - 1]); }
00617
00619 SoNode *getNodeFromTail(int i) const
00620 { return (nodes[getFullLength() - 1 - i]); }
00621
00623 int getIndexFromTail(int i) const
00624 {
00625 return indices[getFullLength() - 1 - i].index;
00626 }
00627
00629 int getInstanceIndexFromTail(int i) const
00630 {
00631 return indices[getFullLength() - 1 - i].instanceIndex;
00632 }
00633
00635 int getLength() const
00636 { return getFullLength(); }
00637
00638 private:
00639 SoFullPath(int approxLength) : SoPath(approxLength) {}
00640 virtual ~SoFullPath();
00641
00642 friend class SoTempPath;
00643 };
00644
00645 #ifndef HIDDEN_FROM_DOC
00646
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00659
00660
00661 class SoLightPath {
00662
00663 private:
00664
00665
00666 SoLightPath(int approxLength=0);
00667
00668 SoLightPath(const SoLightPath& other);
00669
00670
00671
00672 void setHead(SoNode *node);
00673
00674
00675 void append(int childIndex)
00676 { indices.push_back(inventor::NodeIndex(childIndex, inventor::NodeIndex::NODE));}
00677
00678
00679 void appendMI(int childIndex, int instanceIndex)
00680 { indices.push_back(inventor::NodeIndex(childIndex, instanceIndex)); }
00681
00682
00683
00684
00685 void push(int childIndex) { append(childIndex); }
00686 void pushMI(int childIndex, int instanceIndex) { appendMI(childIndex, instanceIndex); }
00687 void push() { append(-1);}
00688 void pop() { truncate(getFullLength() - 1); }
00689
00690 void setTail(int childIndex)
00691 {
00692 setTail(childIndex, inventor::NodeIndex::NODE);
00693 }
00694
00695 void setTail(int childIndex, int instanceIndex)
00696 {
00697 setTail(inventor::NodeIndex(childIndex, instanceIndex));
00698 }
00699
00700 void setTail(const inventor::NodeIndex& index)
00701 {
00702 size_t tailPos = (size_t)(getFullLength()-1);
00703 if ( tailPos >= indices.size() )
00704 indices.resize(tailPos+1);
00705 indices[tailPos] = index;
00706 }
00707
00708 SoNode * getTail(){
00709 return getNode(getFullLength()-1);
00710 }
00711
00712
00713 SoNode * getHead() const { return headNode; }
00714
00715
00716 SoNode * getNode(int i) const;
00717
00718
00719
00720 int getIndex(int i) const
00721 {
00722 return indices[i].index;
00723 }
00724
00725
00726 int getInstanceIndex(int i) const
00727 { return indices[i].instanceIndex; }
00728
00729
00730
00731
00732 int getFullLength() const {return (int) indices.size();}
00733
00734
00735 void truncate(int start)
00736 {
00737 indices.resize(start > 0 ? start : 0);
00738 }
00739
00740
00741
00742
00743 void makeTempPath(SoTempPath *) const;
00744
00745 SoLightPath& operator=(const SoLightPath& other);
00746
00747 private:
00748
00749 ~SoLightPath();
00750 SoNode * headNode;
00751 mutable std::vector<inventor::NodeIndex> indices;
00752
00753
00754 friend class SoAction;
00755 };
00756
00757 #endif // HIDDEN_FROM_DOC
00758
00762 std::ostream& operator << (std::ostream& os, const SoPath& path);
00763
00764 #endif
00765
00766