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
00186 class SoPath : public SoBase {
00187
00188 public:
00189
00193 SoPath();
00194
00198 SoPath(int approxLength);
00199
00203 SoPath(SoNode *node);
00204
00209 void setHead(SoNode *node);
00210
00215 void append(int childIndex);
00216
00222 void append(SoNode *childNode);
00223
00228 void append(const SoPath *fromPath);
00229
00234 void push(int childIndex);
00235
00240 void pop();
00241
00245 SoNode* getHead() const { return (SoNode*)(nodes.get(0)); }
00246
00250 SoNode* getTail() const;
00251
00258 SoNode* getNode(int i) const;
00259
00266 SoNode* getNode(const SoType type, int &i) const;
00267
00268
00275 SoNode* getNodeFromTail(int i) const;
00276
00281 int getIndex(int i) const;
00282
00287 int getInstanceIndex(int i) const;
00288
00295 int getIndexFromTail(int i) const;
00296
00304 int getInstanceIndexFromTail(int i) const;
00305
00310 int getLength() const;
00311
00317 void truncate(int start);
00318
00322 SbBool containsNode(const SoNode *node) const;
00323
00328 SbBool containsNode(const SoType type) const;
00329
00334 SbBool containsPath(const SoPath *path) const;
00335
00341 int findFork(const SoPath *path) const;
00342
00350 SoPath *copy(int startFromNodeIndex = 0, int numNodes = 0) const;
00351
00355 friend int operator ==(const SoPath &p1, const SoPath &p2);
00356
00360 friend std::ostream& operator << (std::ostream& os, const SoPath& path);
00361
00365 virtual SoType getTypeId() const;
00366
00370 static SoType getClassTypeId();
00371
00380 static SoPath *getByName(const SbName &name);
00389 static int getByName(const SbName &name, SoPathList &list);
00390
00391
00392 private:
00393
00394 static void initClass();
00395 static void exitClass();
00396
00398 SbEventHandler<SoPath*> m_onPathChange;
00399
00403 friend bool operator <(const SoPath &p1, const SoPath &p2);
00404
00405
00406
00407 void insertIndex(SoNode *parent, int newIndex);
00408
00409
00410
00411 void removeIndex(SoNode *parent, int oldIndex);
00412
00413
00414
00415 void replaceIndex(SoNode *parent, int index, SoNode *newChild);
00416
00417
00418 virtual void write(SoWriteAction *writeAction) const;
00419
00420
00421
00422
00423 SbBool isRelevantNotification(SoNotList *list) const;
00424
00425 void setNumPublic(int num);
00426
00427
00428
00429 void append(SoNode *node, int index);
00430
00431
00432
00433 void appendMI(SoNode *node, int index, int instanceIndex);
00434
00435
00436 SoPath *copy_(int startFromNodeIndex = 0, int numNodes = 0, bool createTempPath = false) const;
00437
00438
00439 inline const size_t& getHash() const
00440 {
00441 if ( m_pathHash != static_cast< size_t >(-1) )
00442 return m_pathHash;
00443 return computeHash();
00444 }
00445
00446
00447 void truncate(int start, SbBool doNotify);
00448
00449
00450
00451 SoNode* u_getHead() const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[0]); }
00452 SoNode* u_getTail() const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[getLength() - 1]); }
00453 SoNode* u_getNode(int i) const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[i]); }
00454 SoNode* u_getNodeFromTail(int i) const { return (SoNode*)(const_cast<SoNodeList*>(&nodes)->getArray()[getLength() - 1 - i]); }
00455 int u_getIndex(int i) const { return (int)indices[i].index; }
00456 int u_getIndexFromTail(int i) const { return (int)indices[getLength() - 1 - i].index; }
00457 int u_getInstanceIndex(int i) const { return (int)indices[i].instanceIndex; }
00458
00459
00460
00465 void setHeadMI(SoNode *node, int instanceIndex);
00466
00472 void appendMI(int childIndex, int instanceIndex);
00473
00480 void appendMI(SoNode *childNode, int instanceIndex);
00481
00486 void pushMI(int childIndex, int instanceIndex);
00487
00488 bool isForwardTraversing() const;
00489
00490 private:
00491
00492 void auditPath(SbBool flag) { doAuditors = flag; }
00493
00494
00495 virtual SbBool readInstance(SoInput *in, unsigned short flags);
00496
00497 virtual ~SoPath();
00498
00499 private:
00500 const size_t& computeHash() const;
00501
00502 SoNodeList nodes;
00503 std::vector<inventor::NodeIndex> indices;
00504 mutable int numPublic;
00505 mutable int minNumPublic;
00506 SbBool doAuditors;
00507 static SoType classTypeId;
00508
00509
00510 int getFullLength() const
00511 { return nodes.getLength(); }
00512
00513
00514 static void* createInstance(SoType* dynamicType = NULL);
00515
00516
00517 mutable size_t m_pathHash;
00518
00519 friend class SoFullPath;
00520 friend class SoTempPath;
00521 friend class SoAction;
00522 friend class SoPathNoRef;
00523 friend class SoTraversalPassImpl;
00524
00525 };
00526
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00539
00602 class SoFullPath : public SoPath {
00603
00604 public:
00605
00606
00607
00609 void pop()
00610 { truncate(getFullLength() - 1); }
00611
00613 SoNode *getTail() const
00614 { return (nodes[getFullLength() - 1]); }
00615
00617 SoNode *getNodeFromTail(int i) const
00618 { return (nodes[getFullLength() - 1 - i]); }
00619
00621 int getIndexFromTail(int i) const
00622 {
00623 return indices[getFullLength() - 1 - i].index;
00624 }
00625
00627 int getInstanceIndexFromTail(int i) const
00628 {
00629 return indices[getFullLength() - 1 - i].instanceIndex;
00630 }
00631
00633 int getLength() const
00634 { return getFullLength(); }
00635
00636 private:
00637 SoFullPath(int approxLength) : SoPath(approxLength) {}
00638 virtual ~SoFullPath();
00639
00640 friend class SoTempPath;
00641 };
00642
00643 #ifndef HIDDEN_FROM_DOC
00644
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00657
00658
00659 class SoLightPath {
00660
00661 private:
00662
00663
00664 SoLightPath(int approxLength=0);
00665
00666
00667
00668
00669 void setHead(SoNode *node);
00670
00671
00672 void append(int childIndex)
00673 { indices.push_back(inventor::NodeIndex(childIndex, inventor::NodeIndex::NODE));}
00674
00675
00676 void appendMI(int childIndex, int instanceIndex)
00677 { indices.push_back(inventor::NodeIndex(childIndex, instanceIndex)); }
00678
00679
00680
00681
00682 void push(int childIndex) { append(childIndex); }
00683 void pushMI(int childIndex, int instanceIndex) { appendMI(childIndex, instanceIndex); }
00684 void push() { append(-1);}
00685 void pop() { truncate(getFullLength() - 1); }
00686
00687 void setTail(int childIndex)
00688 {
00689 setTail(childIndex, inventor::NodeIndex::NODE);
00690 }
00691
00692 void setTail(int childIndex, int instanceIndex)
00693 {
00694 setTail(inventor::NodeIndex(childIndex, instanceIndex));
00695 }
00696
00697 void setTail(const inventor::NodeIndex& index)
00698 {
00699 size_t tailPos = (size_t)(getFullLength()-1);
00700 if ( tailPos >= indices.size() )
00701 indices.resize(tailPos+1);
00702 indices[tailPos] = index;
00703 }
00704
00705 SoNode * getTail(){
00706 return getNode(getFullLength()-1);
00707 }
00708
00709
00710 SoNode * getHead() const { return headNode; }
00711
00712
00713 SoNode * getNode(int i) const;
00714
00715
00716
00717 int getIndex(int i) const
00718 {
00719 return indices[i].index;
00720 }
00721
00722
00723 int getInstanceIndex(int i) const
00724 { return indices[i].instanceIndex; }
00725
00726
00727
00728
00729 int getFullLength() const {return (int) indices.size();}
00730
00731
00732 void truncate(int start)
00733 {
00734 indices.resize(start > 0 ? start : 0);
00735 }
00736
00737
00738
00739
00740 void makeTempPath(SoTempPath *) const;
00741
00742 private:
00743
00744 ~SoLightPath();
00745 SoNode * headNode;
00746 mutable std::vector<inventor::NodeIndex> indices;
00747
00748
00749 friend class SoAction;
00750 };
00751
00752 #endif // HIDDEN_FROM_DOC
00753
00757 std::ostream& operator << (std::ostream& os, const SoPath& path);
00758
00759 #endif
00760
00761