Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pgraph/workingNodePath.cxx

Go to the documentation of this file.
00001 // Filename: workingNodePath.cxx
00002 // Created by:  drose (16Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "workingNodePath.h"
00020 
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //     Function: WorkingNodePath::is_valid
00024 //       Access: Public
00025 //  Description: Returns true if the WorkingNodePath object appears to
00026 //               be a valid NodePath reference, false otherwise.
00027 ////////////////////////////////////////////////////////////////////
00028 bool WorkingNodePath::
00029 is_valid() const {
00030   if (_node == (PandaNode *)NULL) {
00031     return false;
00032   }
00033   if (_next == (WorkingNodePath *)NULL) {
00034     return (_start != (NodePathComponent *)NULL);
00035   }
00036 
00037   return _next->is_valid();
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: WorkingNodePath::get_num_nodes
00042 //       Access: Public
00043 //  Description: Returns the number of nodes in the path from the root
00044 //               to the current node.
00045 //
00046 //               Since a WorkingNodePath always consists of, at
00047 //               minimum, a nonempty parent NodePath and one child
00048 //               node, this method will always return at least 2.
00049 ////////////////////////////////////////////////////////////////////
00050 int WorkingNodePath::
00051 get_num_nodes() const {
00052   if (_next == (WorkingNodePath *)NULL) {
00053     return _start->get_length();
00054   }
00055 
00056   return _next->get_num_nodes() + 1;
00057 }
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //     Function: WorkingNodePath::get_node
00061 //       Access: Public
00062 //  Description: Returns the nth node of the path, where 0 is the
00063 //               referenced (bottom) node and get_num_nodes() - 1 is
00064 //               the top node.  This requires iterating through the
00065 //               path.
00066 ////////////////////////////////////////////////////////////////////
00067 PandaNode *WorkingNodePath::
00068 get_node(int index) const {
00069   nassertr(index >= 0, NULL);
00070   if (index == 0) {
00071     return _node;
00072   }
00073 
00074   if (_next == (WorkingNodePath *)NULL) {
00075     return get_node_path().get_node(index - 1);
00076   }
00077 
00078   return _next->get_node(index - 1);
00079 }
00080 
00081 ////////////////////////////////////////////////////////////////////
00082 //     Function: WorkingNodePath::output
00083 //       Access: Public
00084 //  Description: 
00085 ////////////////////////////////////////////////////////////////////
00086 void WorkingNodePath::
00087 output(ostream &out) const {
00088   // Cheesy and slow, but when you're outputting the thing, presumably
00089   // you're not in a hurry.
00090   get_node_path().output(out);
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: WorkingNodePath::r_get_node_path
00095 //       Access: Private
00096 //  Description: The private, recursive implementation of
00097 //               get_node_path(), this returns the NodePathComponent
00098 //               representing the NodePath.
00099 ////////////////////////////////////////////////////////////////////
00100 PT(NodePathComponent) WorkingNodePath::
00101 r_get_node_path() const {
00102   if (_next == (WorkingNodePath *)NULL) {
00103     nassertr(_start != (NodePathComponent *)NULL, NULL);
00104     return _start;
00105   }
00106 
00107   nassertr(_start == (NodePathComponent *)NULL, NULL);
00108   nassertr(_node != (PandaNode *)NULL, NULL);
00109 
00110   PT(NodePathComponent) comp = _next->r_get_node_path();
00111   nassertr(comp != (NodePathComponent *)NULL, NULL);
00112 
00113   PT(NodePathComponent) result = PandaNode::get_component(comp, _node);
00114   nassertr(result != (NodePathComponent *)NULL, NULL);
00115   return result;
00116 }

Generated on Fri May 2 00:42:33 2003 for Panda by doxygen1.3