ViewProviderTrajectory.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include <Inventor/SoDB.h>
00028 # include <Inventor/SoInput.h>
00029 # include <Inventor/SbVec3f.h>
00030 # include <Inventor/nodes/SoSeparator.h>
00031 # include <Inventor/nodes/SoTransform.h>
00032 # include <Inventor/nodes/SoSphere.h>
00033 # include <Inventor/nodes/SoRotation.h>
00034 # include <Inventor/actions/SoSearchAction.h>
00035 # include <Inventor/draggers/SoJackDragger.h>
00036 # include <Inventor/VRMLnodes/SoVRMLTransform.h>
00037 # include <Inventor/nodes/SoBaseColor.h>
00038 # include <Inventor/nodes/SoCoordinate3.h>
00039 # include <Inventor/nodes/SoDrawStyle.h>
00040 # include <Inventor/nodes/SoFaceSet.h>
00041 # include <Inventor/nodes/SoLineSet.h>
00042 # include <Inventor/nodes/SoMarkerSet.h>
00043 # include <Inventor/nodes/SoShapeHints.h>
00044 # include <QFile>
00045 #endif
00046
00047 #include "ViewProviderTrajectory.h"
00048
00049 #include <Mod/Robot/App/TrajectoryObject.h>
00050 #include <Mod/Robot/App/Trajectory.h>
00051 #include <App/Document.h>
00052 #include <Base/FileInfo.h>
00053 #include <Base/Stream.h>
00054 #include <Base/Console.h>
00055 #include <sstream>
00056 using namespace Gui;
00057 using namespace RobotGui;
00058 using namespace Robot;
00059
00060 PROPERTY_SOURCE(RobotGui::ViewProviderTrajectory, Gui::ViewProviderGeometryObject)
00061
00062 ViewProviderTrajectory::ViewProviderTrajectory()
00063 {
00064
00065 pcTrajectoryRoot = new Gui::SoFCSelection();
00066 pcTrajectoryRoot->highlightMode = Gui::SoFCSelection::OFF;
00067 pcTrajectoryRoot->selectionMode = Gui::SoFCSelection::SEL_OFF;
00068
00069 pcTrajectoryRoot->ref();
00070
00071 pcCoords = new SoCoordinate3();
00072 pcCoords->ref();
00073 pcDrawStyle = new SoDrawStyle();
00074 pcDrawStyle->ref();
00075 pcDrawStyle->style = SoDrawStyle::LINES;
00076 pcDrawStyle->lineWidth = 2;
00077
00078 pcLines = new SoLineSet;
00079 pcLines->ref();
00080
00081
00082 }
00083
00084 ViewProviderTrajectory::~ViewProviderTrajectory()
00085 {
00086 pcTrajectoryRoot->unref();
00087 pcCoords->unref();
00088 pcDrawStyle->unref();
00089 pcLines->unref();
00090
00091 }
00092
00093 void ViewProviderTrajectory::attach(App::DocumentObject *pcObj)
00094 {
00095 ViewProviderDocumentObject::attach(pcObj);
00096
00097
00098 SoSeparator* linesep = new SoSeparator;
00099 SoBaseColor * basecol = new SoBaseColor;
00100 basecol->rgb.setValue( 1.0f, 0.5f, 0.0f );
00101 linesep->addChild(basecol);
00102 linesep->addChild(pcCoords);
00103 linesep->addChild(pcLines);
00104
00105
00106 SoBaseColor * markcol = new SoBaseColor;
00107 markcol->rgb.setValue( 1.0f, 1.0f, 0.0f );
00108 SoMarkerSet* marker = new SoMarkerSet;
00109 marker->markerIndex=SoMarkerSet::CROSS_5_5;
00110 linesep->addChild(markcol);
00111 linesep->addChild(marker);
00112
00113 pcTrajectoryRoot->addChild(linesep);
00114
00115 addDisplayMaskMode(pcTrajectoryRoot, "Waypoints");
00116 pcTrajectoryRoot->objectName = pcObj->getNameInDocument();
00117 pcTrajectoryRoot->documentName = pcObj->getDocument()->getName();
00118 pcTrajectoryRoot->subElementName = "Main";
00119
00120 }
00121
00122 void ViewProviderTrajectory::setDisplayMode(const char* ModeName)
00123 {
00124 if ( strcmp("Waypoints",ModeName)==0 )
00125 setDisplayMaskMode("Waypoints");
00126 ViewProviderGeometryObject::setDisplayMode( ModeName );
00127 }
00128
00129 std::vector<std::string> ViewProviderTrajectory::getDisplayModes(void) const
00130 {
00131 std::vector<std::string> StrList;
00132 StrList.push_back("Waypoints");
00133 return StrList;
00134 }
00135
00136 void ViewProviderTrajectory::updateData(const App::Property* prop)
00137 {
00138 Robot::TrajectoryObject* pcTracObj = static_cast<Robot::TrajectoryObject*>(pcObject);
00139 if (prop == &pcTracObj->Trajectory) {
00140 const Trajectory &trak = pcTracObj->Trajectory.getValue();
00141
00142 pcCoords->point.deleteValues(0);
00143 pcCoords->point.setNum(trak.getSize());
00144
00145 for(unsigned int i=0;i<trak.getSize();++i){
00146 Base::Vector3d pos = trak.getWaypoint(i).EndPos.getPosition();
00147 pcCoords->point.set1Value(i,pos.x,pos.y,pos.z);
00148
00149 }
00150 pcLines->numVertices.set1Value(0, trak.getSize());
00151 }else if (prop == &pcTracObj->Base) {
00152 Base::Placement loc = *(&pcTracObj->Base.getValue());
00153 }
00154
00155 }
00156