PartFeature.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2002     *
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 # include <gp_Trsf.hxx>
00028 # include <gp_Ax1.hxx>
00029 #endif
00030 
00031 
00032 #include <strstream>
00033 #include <Base/Console.h>
00034 #include <Base/Writer.h>
00035 #include <Base/Reader.h>
00036 #include <Base/Exception.h>
00037 #include <Base/FileInfo.h>
00038 #include <Base/Stream.h>
00039 #include <Base/Placement.h>
00040 #include <Base/Rotation.h>
00041 
00042 #include "PartFeature.h"
00043 #include "PartFeaturePy.h"
00044 #include "FeaturePythonPy.h"
00045 
00046 using namespace Part;
00047 
00048 
00049 PROPERTY_SOURCE(Part::Feature, App::GeoFeature)
00050 
00051 
00052 Feature::Feature(void) 
00053 {
00054     ADD_PROPERTY(Shape, (TopoDS_Shape()));
00055 }
00056 
00057 Feature::~Feature()
00058 {
00059 }
00060 
00061 short Feature::mustExecute(void) const
00062 {
00063     return GeoFeature::mustExecute();
00064 }
00065 
00066 App::DocumentObjectExecReturn *Feature::execute(void)
00067 {
00068     return App::DocumentObject::StdReturn;
00069 }
00070 
00071 PyObject *Feature::getPyObject(void)
00072 {
00073     if (PythonObject.is(Py::_None())){
00074         // ref counter is set to 1
00075         PythonObject = Py::Object(new PartFeaturePy(this),true);
00076     }
00077     return Py::new_reference_to(PythonObject); 
00078 }
00079 
00080 std::vector<PyObject *> Feature::getPySubObjects(const std::vector<std::string>& NameVec) const
00081 {
00082     std::vector<PyObject *> temp;
00083     for(std::vector<std::string>::const_iterator it=NameVec.begin();it!=NameVec.end();++it){
00084         PyObject *obj = Shape.getShape().getPySubShape((*it).c_str());
00085         if(obj)
00086             temp.push_back(obj);
00087     }
00088     return temp;
00089 }
00090 
00091 void Feature::onChanged(const App::Property* prop)
00092 {
00093     // if the placement has changed apply the change to the point data as well
00094     if (prop == &this->Placement) {
00095         TopoShape& shape = const_cast<TopoShape&>(this->Shape.getShape());
00096         shape.setTransform(this->Placement.getValue().toMatrix());
00097     }
00098     // if the point data has changed check and adjust the transformation as well
00099     else if (prop == &this->Shape) {
00100         if (this->isRecomputing()) {
00101             TopoShape& shape = const_cast<TopoShape&>(this->Shape.getShape());
00102             shape.setTransform(this->Placement.getValue().toMatrix());
00103         }
00104         else {
00105             Base::Placement p;
00106             p.fromMatrix(this->Shape.getShape().getTransform());
00107             if (p != this->Placement.getValue())
00108                 this->Placement.setValue(p);
00109         }
00110     }
00111     
00112     GeoFeature::onChanged(prop);
00113 }
00114 
00115 TopLoc_Location Feature::getLocation() const
00116 {
00117     Base::Placement pl = this->Placement.getValue();
00118     Base::Rotation rot(pl.getRotation());
00119     Base::Vector3d axis;
00120     double angle;
00121     rot.getValue(axis, angle);
00122     gp_Trsf trf;
00123     trf.SetRotation(gp_Ax1(gp_Pnt(), gp_Dir(axis.x, axis.y, axis.z)), angle);
00124     trf.SetTranslationPart(gp_Vec(pl.getPosition().x,pl.getPosition().y,pl.getPosition().z));
00125     return TopLoc_Location(trf);
00126 }
00127 
00129 const char* Feature::getViewProviderName(void) const {
00130     return "PartGui::ViewProviderPart";
00131 }
00132 
00133 // ---------------------------------------------------------
00134 
00135 PROPERTY_SOURCE(Part::FeatureExt, Part::Feature)
00136 
00137 
00138 
00139 namespace App {
00141 PROPERTY_SOURCE_TEMPLATE(Part::FeaturePython, Part::Feature)
00142 template<> const char* Part::FeaturePython::getViewProviderName(void) const {
00143     return "PartGui::ViewProviderPython";
00144 }
00145 
00146 template<> PyObject* Part::FeaturePython::getPyObject(void) {
00147     if (PythonObject.is(Py::_None())){
00148         // ref counter is set to 1
00149         PythonObject = Py::Object(new Part::FeaturePythonPy(this),true);
00150     }
00151     return Py::new_reference_to(PythonObject); 
00152 }
00154 
00155 // explicit template instantiation
00156 template class PartExport FeaturePythonT<Part::Feature>;
00157 }
00158 

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