TrajectoryDressUpObject.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2010 Jürgen Riegel (juergen.riegel@web.de)              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #ifndef _PreComp_
00027 #endif
00028 
00029 #include "TrajectoryDressUpObject.h"
00030 //#include <App/DocumentObjectPy.h>
00031 //#include <Base/Placement.h>
00032 #include <Mod/Part/App/edgecluster.h>
00033 #include <Mod/Part/App/PartFeature.h>
00034 #include <TopoDS.hxx>
00035 #include <TopoDS_Edge.hxx>
00036 #include <TopoDS_Vertex.hxx>
00037 #include <BRep_Tool.hxx>
00038 #include <BRepAdaptor_Curve.hxx>
00039 #include <CPnts_AbscissaPoint.hxx>
00040 #include <TopExp.hxx>
00041 #include "Waypoint.h"
00042 #include "Trajectory.h"
00043 
00044 using namespace Robot;
00045 using namespace App;
00046 
00047 PROPERTY_SOURCE(Robot::TrajectoryDressUpObject, Robot::TrajectoryObject)
00048 
00049 const char* TrajectoryDressUpObject::ContTypeEnums[]= {"DontChange","Continues","Discontinues",NULL};
00050 const char* TrajectoryDressUpObject::AddTypeEnums[] = {"DontChange","UseOrientation","AddPosition","AddOrintation","AddPositionAndOrientation",NULL};
00051 
00052 TrajectoryDressUpObject::TrajectoryDressUpObject()
00053 {
00054 
00055     ADD_PROPERTY_TYPE( Source,          (0)                 , "TrajectoryDressUp",Prop_None,"Trajectory to dress up");
00056     ADD_PROPERTY_TYPE( Speed,           (1000)              , "TrajectoryDressUp",Prop_None,"Speed to use");
00057     ADD_PROPERTY_TYPE( UseSpeed    ,    (0)                 , "TrajectoryDressUp",Prop_None,"Switch the speed usage on");
00058     ADD_PROPERTY_TYPE( Acceleration,    (1000)              , "TrajectoryDressUp",Prop_None,"Acceleration to use");
00059     ADD_PROPERTY_TYPE( UseAcceleration, (0)                 , "TrajectoryDressUp",Prop_None,"Switch the acceleration usage on");
00060     ADD_PROPERTY_TYPE( ContType,        ((long)0)           , "TrajectoryDressUp",Prop_None,"Define the dress up of continuity");
00061     ContType.setEnums(ContTypeEnums);
00062     ADD_PROPERTY_TYPE( PosAdd,          (Base::Placement()) , "TrajectoryDressUp",Prop_None,"Position & Orientation to use");
00063     ADD_PROPERTY_TYPE( AddType,         ((long)0)           , "TrajectoryDressUp",Prop_None,"How to change the Position & Orientation");
00064     AddType.setEnums(AddTypeEnums);
00065 
00066 }
00067 
00068 TrajectoryDressUpObject::~TrajectoryDressUpObject()
00069 {
00070 }
00071 
00072 App::DocumentObjectExecReturn *TrajectoryDressUpObject::execute(void)
00073 {
00074     Robot::Trajectory result;
00075 
00076     App::DocumentObject* link = Source.getValue();
00077     if (!link)
00078         return new App::DocumentObjectExecReturn("No object linked");
00079     if (!link->getTypeId().isDerivedFrom(Robot::TrajectoryObject::getClassTypeId()))
00080         return new App::DocumentObjectExecReturn("Linked object is not a Trajectory object");
00081 
00082     const std::vector<Waypoint*> &wps = static_cast<Robot::TrajectoryObject*>(link)->Trajectory.getValue().getWaypoints();
00083     for (std::vector<Waypoint*>::const_iterator it= wps.begin();it!=wps.end();++it) {
00084         Waypoint wpt = **it;
00085         if(UseSpeed.getValue())
00086             wpt.Velocity = Speed.getValue();
00087         if(UseAcceleration.getValue())
00088             wpt.Accelaration = Acceleration.getValue();
00089         switch(ContType.getValue()){
00090             case 0: break;
00091             case 1: wpt.Cont = true;break;
00092             case 2: wpt.Cont = false;break;
00093             default: assert(0); // must not happen!
00094         }
00095         switch(AddType.getValue()){
00096             // do nothing 
00097             case 0: break;
00098             // use orientation  
00099             case 1:
00100                 wpt.EndPos.setRotation(PosAdd.getValue().getRotation());
00101                 break;
00102             // add position 
00103             case 2:
00104                 wpt.EndPos.setPosition(wpt.EndPos.getPosition() + PosAdd.getValue().getPosition());
00105                 break;
00106             // add orientation 
00107             case 3:
00108                 wpt.EndPos.setRotation(wpt.EndPos.getRotation() * PosAdd.getValue().getRotation());
00109                 break;
00110             // add orientation & position 
00111             case 4:
00112                 wpt.EndPos= wpt.EndPos * PosAdd.getValue();
00113                 break;
00114             default: assert(0); // must not happen!
00115         }
00116 
00117         result.addWaypoint(wpt);
00118     }
00119 
00120     // set the resulting Trajectory to the object
00121     Trajectory.setValue(result);
00122     
00123     return App::DocumentObject::StdReturn;
00124 }
00125 
00126 void TrajectoryDressUpObject::onChanged(const Property* prop)
00127 {
00128  
00129     App::GeoFeature::onChanged(prop);
00130 }

Generated on Wed Nov 23 19:00:49 2011 for FreeCAD by  doxygen 1.6.1