cgma
|
00001 00002 #include "CubitCoordinateSystem.hpp" 00003 00004 #include <cassert> 00005 00006 #include "CubitMessage.hpp" 00007 #include "CubitBox.hpp" 00008 #include "CubitObserver.hpp" 00009 #include "CubitString.hpp" 00010 #include "AppUtil.hpp" 00011 #include "CubitCoordEvent.hpp" 00012 00014 CubitCoordinateSystem::CubitCoordinateSystem(int id) 00015 : mType(Rectangular), mMatrix(CubitTransformMatrix()), mReference(0) 00016 { 00017 this->set_id(id); 00018 } 00019 00020 CubitCoordinateSystem::~CubitCoordinateSystem() 00021 { 00022 if(mReference) 00023 mReference->mUses.remove(this); 00024 00025 // if we have uses, make them reference this reference 00026 while(mUses.size()) 00027 { 00028 CubitCoordinateSystem* sys = mUses.get(); 00029 sys->set_transform(sys->mMatrix * this->mMatrix); 00030 sys->mReference = this->mReference; 00031 if(mReference) 00032 mReference->mUses.append(sys); 00033 mUses.remove(); 00034 } 00035 00036 this->remove_from_observers(); 00037 00038 AppUtil::instance()->send_event(CubitCoordEvent(CubitCoordEvent::COORDINATE_SYSTEM_DELETED, this)); 00039 } 00040 00041 CubitBox CubitCoordinateSystem::bounding_box() 00042 { 00043 assert(0); // this function is only here b/c CubitEntity requires it 00044 00045 CubitBox temp; 00046 return temp; 00047 } 00048 00049 const std::type_info& CubitCoordinateSystem::entity_type_info() const 00050 { 00051 return typeid(CubitCoordinateSystem); 00052 } 00053 00054 const char* CubitCoordinateSystem::class_name() const 00055 { 00056 return "Coordinate System"; 00057 } 00058 00059 CubitString CubitCoordinateSystem::entity_name() const 00060 { 00061 CubitString name = class_name(); 00062 name += " "; 00063 name += CubitString::number( this->id() ); 00064 return name; 00065 } 00066 00067 CubitCoordinateSystem::Type CubitCoordinateSystem::get_type() const 00068 { 00069 return mType; 00070 } 00071 00072 void CubitCoordinateSystem::set_type(CubitCoordinateSystem::Type type) 00073 { 00074 mType = type; 00075 AppUtil::instance()->send_event(CubitCoordEvent(CubitCoordEvent::COORDINATE_SYSTEM_MODIFIED, this)); 00076 } 00077 00078 00080 const CubitTransformMatrix& CubitCoordinateSystem::get_transform() const 00081 { 00082 return mMatrix; 00083 } 00084 00085 void CubitCoordinateSystem::set_transform(const CubitTransformMatrix& mat) 00086 { 00087 mMatrix = mat; 00088 AppUtil::instance()->send_event(CubitCoordEvent(CubitCoordEvent::COORDINATE_SYSTEM_MODIFIED, this)); 00089 } 00090 00091 00094 CubitTransformMatrix CubitCoordinateSystem::get_concatenated_transform() const 00095 { 00096 CubitTransformMatrix mat; 00097 mat = mMatrix; 00098 CubitCoordinateSystem* ref; 00099 for(ref = mReference; ref != 0; ref = ref->mReference) 00100 mat = mat * ref->mMatrix; 00101 return mat; 00102 } 00103 00104