Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/database/include/Inventor/SoPath.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 
00038 /*
00039  * Copyright (C) 1990,91   Silicon Graphics, Inc.
00040  *
00041  _______________________________________________________________________
00042  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00043  |
00044  |   $Revision: 1.2 $
00045  |
00046  |   Description:
00047  |      This file contains the definition of the SoPath and SoFullPath
00048  |      classes, and the related class SoLightPath
00049  |
00050  |   Author(s)          : Paul S. Strauss, Nick Thompson, Alan Norton
00051  |
00052  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00053  _______________________________________________________________________
00054  */
00055 
00056 #ifndef  _SO_PATH_
00057 #define  _SO_PATH_
00058 
00059 #include <Inventor/system/SbSystem.h>
00060 #include <Inventor/misc/SoBase.h>
00061 #include <Inventor/nodes/SoNode.h>
00062 #include <Inventor/SoLists.h>
00063 
00064 
00065 class SoPathList;
00066 class SoWriteAction;
00067 class SoTempPath;
00068 
00071 
00107 
00108 
00109 class INVENTOR_API SoPath : public SoBase {
00110 
00111   public:
00112 
00114     SoPath();
00115 
00117     SoPath(int approxLength);
00118 
00120     SoPath(SoNode *node);
00121 
00125     void                setHead(SoNode *node);
00126 
00129     void                append(int childIndex);
00130 
00135     void                append(SoNode *childNode);
00136 
00139     void                append(const SoPath *fromPath);
00140 
00143     void                push(int childIndex) { append(childIndex); }
00146     void                pop()                { truncate(getFullLength() - 1); }
00147 
00149     SoNode *            getHead() const { return nodes[0]; }
00151     SoNode *            getTail() const { return (nodes[getLength() - 1]); }
00152 
00155     SoNode *            getNode(int i) const    { return (nodes[i]); }
00156 
00159     SoNode *            getNodeFromTail(int i) const
00160         { return (nodes[getLength() - 1 - i]); }
00161 
00164     int                 getIndex(int i) const   { return (indices[i]); }
00165 
00169     int                 getIndexFromTail(int i) const
00170         { return (indices[getLength() - 1 - i]); }
00171 
00173     int                 getLength() const;
00174 
00179     void                truncate(int start);
00180 
00182     SbBool              containsNode(const SoNode *node) const;
00183 
00186     SbBool              containsPath(const SoPath *path) const;
00187 
00191     int                 findFork(const SoPath *path) const;
00192 
00197     SoPath *            copy(int startFromNodeIndex = 0,
00198                              int numNodes = 0) const;
00199 
00201     friend INVENTOR_API int             operator ==(const SoPath &p1, const SoPath &p2);
00202 
00204     virtual SoType      getTypeId() const;
00205 
00207     static SoType       getClassTypeId()        { return classTypeId; }
00208 
00210     static SoPath *     getByName(const SbName &name);
00222     static int          getByName(const SbName &name, SoPathList &list);
00223 
00224   SoINTERNAL public:
00226     static void         initClass();
00227 
00230     void                insertIndex(SoNode *parent, int newIndex);
00231 
00234     void                removeIndex(SoNode *parent, int oldIndex);
00235 
00238     void                replaceIndex(SoNode *parent, int index,
00239                                      SoNode *newChild);
00240 
00242     virtual void        write(SoWriteAction *writeAction) const;
00243 
00247     SbBool              isRelevantNotification(SoNotList *list) const;
00248 
00249   protected:
00251     void                auditPath(SbBool flag)  { doAuditors = flag; }
00252 
00253     ~SoPath();
00254 
00255   private:
00256     SoNodeList          nodes;          
00257     SbIntList           indices;        
00258     int                 numPublic;      
00259     int                 minNumPublic;   
00260     SbBool              doAuditors;     
00261     static SoType       classTypeId;    
00262 
00264     int                 getFullLength() const   { return nodes.getLength(); }
00265 
00268     void                append(SoNode *node, int index);
00269 
00271     static void *       createInstance();
00272 
00274     virtual SbBool      readInstance(SoInput *in, unsigned short flags);
00275 
00277     void                truncate(int start, SbBool doNotify);
00278 
00279 friend class SoFullPath;
00280 friend class SoTempPath;
00281 friend class SoAction;
00282 };
00283 
00296 
00297 SoEXTENDER class INVENTOR_API SoFullPath : public SoPath {
00298 
00299   public:
00303 
00306     void                pop()           { truncate(getFullLength() - 1); }
00307 
00309     SoNode *            getTail() const
00310         { return (nodes[getFullLength() - 1]); }
00311 
00313     SoNode *            getNodeFromTail(int i) const
00314         { return (nodes[getFullLength() - 1 - i]); }
00315 
00319     int                 getIndexFromTail(int i) const
00320         { return (indices[getFullLength() - 1 - i]); }
00321 
00323     int                 getLength() const       { return getFullLength(); }
00324 
00325   private:
00326     SoFullPath(int approxLength) : SoPath(approxLength) {}
00327     virtual ~SoFullPath();
00328 
00329 friend class SoTempPath;
00330 };
00331 
00332 
00333 
00346 
00347 
00348 class INVENTOR_API SoLightPath  {
00349 
00350   SoINTERNAL public:
00351 
00353     SoLightPath(int approxLength);
00354  
00355 
00358     void                setHead(SoNode *node);
00359 
00361     void                append(int childIndex) 
00362         { indices.append(childIndex);}
00363 
00364 
00367     void                push(int childIndex)    { append(childIndex); }
00368     void                push()                  { append(-1);}
00369     void                pop()           { truncate(getFullLength() - 1); }
00370     void                setTail(int childIndex) 
00371                 { indices.set(getFullLength()-1,(void *)(size_t)childIndex);}
00372     SoNode *            getTail()
00373                 { return getNode(getFullLength()-1);}
00374 
00376     SoNode *            getHead() const { return headNode; }
00377 
00379     SoNode *            getNode(int i) const;   
00380 
00383     int                 getFullLength() const {return indices.getLength();}
00384 
00386     void                truncate(int start) { indices.truncate(start);}
00387 
00388     
00391     void                makeTempPath(SoTempPath *tmpPath) const;
00392 
00393   private:
00394 
00395     ~SoLightPath();
00396     SoNode *            headNode;       
00397     SbIntList           indices;        
00398 
00399 
00400   friend class SoAction;
00401 };
00402 
00403 
00404 
00405 #endif /* _SO_PATH_ */