From: Markus R. <rol...@us...> - 2006-01-22 12:17:45
|
Update of /cvsroot/simspark/simspark/contrib/rsgedit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5597 Added Files: property.h property.cpp Log Message: - added class Property that generates a list of name/value pairs to describe a zeitgeist class instance --- NEW FILE: property.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: property.cpp,v 1.1 2006/01/22 12:17:33 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "property.h" #include "main.h" //! wxWidgets and zeitgeist both use a 'DECLARE_CLASS' macro #undef DECLARE_CLASS #include "simspark.h" #include <salt/vector.h> #include <salt/bounds.h> #include <salt/matrix.h> #include <zeitgeist/logserver/logserver.h> #include <zeitgeist/class.h> #include <zeitgeist/core.h> #include <oxygen/sceneserver/basenode.h> #include <oxygen/sceneserver/transform.h> using namespace std; using namespace boost; using namespace salt; using namespace zeitgeist; using namespace oxygen; inline wxString FormatVector3(const Vector3f& vec) { return wxString::Format(_T("(%.2f, %.2f, %.2f)"),vec[0],vec[1],vec[2]); } inline wxString FormatAABB3(const AABB3& bound) { return FormatVector3(bound.minVec) + _T(" ") + FormatVector3(bound.maxVec); } inline wxString FormatMatrix(const Matrix& m) { wxString str = wxString::Format(_T("(%.2f"),m.m[0]); for (int i=1;i<16;++i) { str += wxString::Format(_T(", %.2f"),m.m[i]); } str += _T(")"); return str; } Property::Property() { Init(); } void Property::Init() { mClassMap.clear(); mClassMap["/classes/zeitgeist/Leaf"] = CL_LEAF; mClassMap["ClassClass"] = CL_CLASS; mClassMap["/classes/oxygen/BaseNode"] = CL_BASENODE; mClassMap["/classes/oxygen/Transform"] = CL_TRANSFORM; } void Property::GenLeafEntries(shared_ptr<Leaf> leaf, TEntryList& entries) const { entries.push_back(Entry(_T("GetFullPath"), leaf->GetFullPath())); } void Property::GenBaseNodeEntries(shared_ptr<Leaf> leaf, TEntryList& entries) const { shared_ptr<BaseNode> baseNode = shared_static_cast<BaseNode>(leaf); entries.push_back(Entry(_T("GetWorldBoundingBox"), FormatAABB3(baseNode->GetWorldBoundingBox()))); } void Property::GenClassEntries(shared_ptr<Leaf> leaf, TEntryList& entries) const { shared_ptr<Class> cl = shared_static_cast<Class>(leaf); // originating bundle shared_ptr<salt::SharedLibrary> bundle = cl->GetBundle(); entries.push_back( Entry( _T("GetBundle"), (bundle.get() != 0) ? bundle->GetName() : _T("<None>") ) ); // base classes const Class::TStringList& baseCl = cl->GetBaseClasses(); for ( Class::TStringList::const_iterator iter = baseCl.begin(); iter != baseCl.end(); ++iter ) { entries.push_back(Entry(_T("GetBaseClasses"), _T((*iter).c_str()))); } // supported functions const Class::TCommandMap& cmds = cl->GetCommandMap(); for ( Class::TCommandMap::const_iterator iter = cmds.begin(); iter != cmds.end(); ++iter ) { entries.push_back(Entry(_T("GetCommandMap"), _T((*iter).first.c_str()))); } } void Property::GenTransformEntries(shared_ptr<Leaf> leaf, TEntryList& entries) const { shared_ptr<Transform> trans = shared_static_cast<Transform>(leaf); entries.push_back(Entry(_T("GetChangedMark"), wxString::Format("%d",trans->GetChangedMark()))); entries.push_back(Entry(_T("GetLocalTransform"), FormatMatrix(trans->GetLocalTransform()))); entries.push_back(Entry(_T("GetWorldTransform"), FormatMatrix(trans->GetWorldTransform()))); } void Property::GetClassList(boost::shared_ptr<Class> cl, TClassList& clList) const { if (cl.get() == 0) { return; } shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); if (spark.get() == 0) { return; } TClassMap::const_iterator iter = mClassMap.find(cl->GetFullPath()); if (iter != mClassMap.end()) { clList.push_back((*iter).second); } const Class::TStringList& baseClasses = cl->GetBaseClasses(); for ( Class::TStringList::const_iterator iter = baseClasses.begin(); iter != baseClasses.end(); ++iter ) { string basePath = "/classes/"+(*iter); shared_ptr<Class> base = shared_dynamic_cast<Class> (spark->GetCore()->Get(basePath)); if (base.get() == 0) { cl->GetLog()->Error() << "(Property) invalid base class " << basePath << " defined for " << cl->GetFullPath() << std::endl; continue; } GetClassList(base, clList); } } void Property::GetClassList(boost::shared_ptr<Leaf> leaf, TClassList& clList) const { clList.clear(); if (leaf.get() == 0) { return; } shared_ptr<Class> cl = leaf->GetClass(); GetClassList(cl, clList); } void Property::GenEntries(shared_ptr<zeitgeist::Leaf> leaf, const TClassList& clList, TEntryList& entries) const { entries.clear(); if (leaf.get() == 0) { return; } for ( TClassList::const_reverse_iterator iter = clList.rbegin(); iter != clList.rend(); ++iter ) { switch (*iter) { default: break; case CL_LEAF: GenLeafEntries(leaf, entries); break; case CL_BASENODE: GenBaseNodeEntries(leaf, entries); break; case CL_CLASS: GenClassEntries(leaf, entries); break; case CL_TRANSFORM: GenTransformEntries(leaf, entries); break; } } } --- NEW FILE: property.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2003 Koblenz University $Id: property.h,v 1.1 2006/01/22 12:17:33 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <list> #include <map> #include <boost/weak_ptr.hpp> #include <wx/string.h> namespace zeitgeist { class Class; class Leaf; } class Property { public: enum EClass { CL_LEAF, CL_CLASS, CL_BASENODE, CL_TRANSFORM }; //! mapping from path of zeitgeist class to EClass value typedef std::map<wxString, EClass> TClassMap; //! list of base class types typedef std::list<EClass> TClassList; struct Entry { public: wxString name; wxString value; public: Entry(const wxString& n, const wxString& v) : name(n), value(v) {} }; typedef std::list<Entry> TEntryList; public: Property(); void GetClassList(boost::shared_ptr<zeitgeist::Leaf> leaf, TClassList& clList) const; void GenEntries(boost::shared_ptr<zeitgeist::Leaf> leaf, const TClassList& clList, TEntryList& entries) const; protected: void GenLeafEntries(boost::shared_ptr<zeitgeist::Leaf> leaf, TEntryList& entries) const; void GenClassEntries(boost::shared_ptr<zeitgeist::Leaf> leaf, TEntryList& entries) const; void GenBaseNodeEntries(boost::shared_ptr<zeitgeist::Leaf> leaf, TEntryList& entries) const; void GenTransformEntries(boost::shared_ptr<zeitgeist::Leaf> leaf, TEntryList& entries) const; void GetClassList(boost::shared_ptr<zeitgeist::Class> cl, TClassList& clList) const; void Init(); protected: TClassMap mClassMap; }; |