Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

robot/ToolDescription.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2003 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: ToolDescription.cpp 1039 2004-02-11 20:50:52Z jungd $
00019   $Revision: 1.2 $
00020   $Date: 2004-02-11 15:50:52 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #include <robot/ToolDescription>
00026 
00027 #include <base/Externalizer>
00028 #include <base/externalization_error>
00029 #include <base/Application>
00030 #include <base/VFile>
00031 
00032 using robot::ToolDescription;
00033 
00034 using base::Externalizer;
00035 using base::externalization_error;
00036 using base::Application;
00037 using base::VFile;
00038 using base::PathName;
00039 using base::dom::DOMNode;
00040 using base::dom::DOMElement;
00041 
00042 
00043 void ToolDescription::externalize(base::Externalizer& e, String format, Real version)
00044 {
00045   if (format == "") format = "xml";
00046 
00047   if (!formatSupported(format,version,e.ioType()))
00048     throw std::invalid_argument(Exception(String("format ")+format+" v"+base::realToString(version)+" unsupported"));
00049 
00050   if (e.isOutput()) {
00051 
00052     DOMElement*  toolElem = e.createElement("tool");
00053     e.setElementAttribute(toolElem,"name", getName());
00054 
00055     e.pushContext(toolElem);
00056     kinematicChain.externalize(e, format, version);
00057     e.popContext();
00058       
00059     e.appendElement(toolElem);
00060 
00061   } else { // input
00062       
00063     DOMNode* context = e.context();
00064     
00065     DOMElement* toolElem = e.getFirstElement(context, "tool");
00066 
00067     // handle link
00068     String link = e.getElementAttribute(toolElem,"link",false);
00069     if (link != "") {
00070 
00071       ref<VFile> linkFile = Application::getInstance()->universe()->cache()->findFile(link,e.getArchivePath());
00072       load(linkFile,format,version);
00073     }
00074     else {
00075       setName( e.getDefaultedElementAttribute(toolElem, "name", "tool") );
00076 
00077       e.pushContext(toolElem);
00078       kinematicChain.externalize(e, format, version);
00079       e.popContext();
00080       
00081       // the first link of a tool is always considered inactive/static (i.e. it's mount point
00082       //  on an existing manipulator is not a joint)
00083       kinematicChain.activateLink(0,false);
00084     }
00085 
00086     e.removeElement(toolElem);
00087     
00088   }
00089 }

Generated on Thu Jul 29 15:56:44 2004 for OpenSim by doxygen 1.3.6