00001 // Filename: physicalNode.cxx 00002 // Created by: charles (01Aug00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "physicalNode.h" 00016 00017 // static stuff. 00018 TypeHandle PhysicalNode::_type_handle; 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function : PhysicalNode 00022 // Access : public 00023 // Description : default constructor 00024 //////////////////////////////////////////////////////////////////// 00025 PhysicalNode:: 00026 PhysicalNode(const string &name) : 00027 PandaNode(name) 00028 { 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function : PhysicalNode 00033 // Access : protected 00034 // Description : copy constructor 00035 //////////////////////////////////////////////////////////////////// 00036 PhysicalNode:: 00037 PhysicalNode(const PhysicalNode ©) : 00038 PandaNode(copy), _physicals(copy._physicals) { 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function : ~PhysicalNode 00043 // Access : protected, virtual 00044 // Description : destructor 00045 //////////////////////////////////////////////////////////////////// 00046 PhysicalNode:: 00047 ~PhysicalNode() { 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function : make_copy 00052 // Access : public, virtual 00053 // Description : dynamic child copy 00054 //////////////////////////////////////////////////////////////////// 00055 PandaNode *PhysicalNode:: 00056 make_copy() const { 00057 return new PhysicalNode(*this); 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function : add_physicals_from 00062 // Access : public 00063 // Description : append operation 00064 //////////////////////////////////////////////////////////////////// 00065 void PhysicalNode:: 00066 add_physicals_from(const PhysicalNode &other) { 00067 pvector< PT(Physical) >::iterator last = _physicals.end() - 1; 00068 00069 _physicals.insert(_physicals.end(), 00070 other._physicals.begin(), other._physicals.end()); 00071 00072 for (; last != _physicals.end(); last++) { 00073 (*last)->_physical_node = this; 00074 } 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function : remove_physical 00079 // Access : public 00080 // Description : remove operation 00081 //////////////////////////////////////////////////////////////////// 00082 void PhysicalNode:: 00083 remove_physical(Physical *physical) { 00084 pvector< PT(Physical) >::iterator found; 00085 PT(Physical) ptp = physical; 00086 found = find(_physicals.begin(), _physicals.end(), ptp); 00087 if (found == _physicals.end()) 00088 return; 00089 _physicals.erase(found); 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function : remove_physical 00094 // Access : public 00095 // Description : remove operation 00096 //////////////////////////////////////////////////////////////////// 00097 void PhysicalNode:: 00098 remove_physical(int index) { 00099 nassertv(index >= 0 && index <= (int)_physicals.size()); 00100 00101 pvector< PT(Physical) >::iterator remove; 00102 remove = _physicals.begin() + index; 00103 (*remove)->_physical_node = (PhysicalNode *) NULL; 00104 00105 _physicals.erase(remove); 00106 } 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function : write 00110 // Access : Public 00111 // Description : Write a string representation of this instance to 00112 // <out>. 00113 //////////////////////////////////////////////////////////////////// 00114 void PhysicalNode:: 00115 write(ostream &out, unsigned int indent) const { 00116 #ifndef NDEBUG //[ 00117 out.width(indent); out<<""; out<<"PhysicalNode:\n"; 00118 //PandaNode::write(out, indent+2); 00119 #endif //] NDEBUG 00120 }