MeshFeature.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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 
00025 #include "PreCompiled.h"
00026 
00027 #ifndef _PreComp_
00028 #endif
00029 
00030 #include <Base/Console.h>
00031 #include <Base/Exception.h>
00032 #include <Base/Reader.h>
00033 #include <Base/Writer.h>
00034 
00035 #include "Core/MeshIO.h"
00036 
00037 #include "MeshFeature.h"
00038 #include "MeshFeaturePy.h"
00039 #include "FeaturePythonPy.h"
00040 
00041 using namespace Mesh;
00042 
00043 
00044 //===========================================================================
00045 // Feature
00046 //===========================================================================
00047 
00048 PROPERTY_SOURCE(Mesh::Feature, App::GeoFeature)
00049 
00050 Feature::Feature()
00051 {
00052     ADD_PROPERTY_TYPE(Mesh,(MeshObject()),0,App::Prop_Output,"The mesh kernel");
00053 }
00054 
00055 Feature::~Feature()
00056 {
00057 }
00058 
00059 App::DocumentObjectExecReturn *Feature::execute(void)
00060 {
00061     return App::DocumentObject::StdReturn;
00062 }
00063 
00064 PyObject *Feature::getPyObject(void)
00065 {
00066     if(PythonObject.is(Py::_None())){
00067         // ref counter is set to 1
00068         PythonObject = Py::Object(new MeshFeaturePy(this),true);
00069     }
00070     return Py::new_reference_to(PythonObject); 
00071 }
00072 
00073 void Feature::onChanged(const App::Property* prop)
00074 {
00075     // if the placement has changed apply the change to the mesh data as well
00076     if (prop == &this->Placement) {
00077         MeshObject& mesh = const_cast<MeshObject&>(this->Mesh.getValue());
00078         mesh.setTransform(this->Placement.getValue().toMatrix());
00079     }
00080     // if the mesh data has changed check and adjust the transformation as well
00081     else if (prop == &this->Mesh) {
00082         Base::Placement p;
00083         p.fromMatrix(this->Mesh.getValue().getTransform());
00084         if (p != this->Placement.getValue())
00085             this->Placement.setValue(p);
00086     }
00087 
00088     // Note: If the Mesh property has changed the property and this object are marked as 'touched'
00089     // but no recomputation of this objects needs to be done because the Mesh property is regarded
00090     // as output of a previous recomputation The mustExecute() method returns 0 in that case. 
00091     // However, objects that reference this object the Mesh property can be an input parameter.
00092     // As this object and the property are touched such objects can check this and return a value 1 
00093     // (or -1) in their mustExecute() to be recomputed the next time the document recomputes itself.
00094     DocumentObject::onChanged(prop);
00095 }
00096 
00097 // ---------------------------------------------------------
00098 
00099 namespace App {
00101 PROPERTY_SOURCE_TEMPLATE(Mesh::FeaturePython, Mesh::Feature)
00102 template<> const char* Mesh::FeaturePython::getViewProviderName(void) const {
00103     return "MeshGui::ViewProviderPython";
00104 }
00105 template<> PyObject* Mesh::FeaturePython::getPyObject(void) {
00106     if (PythonObject.is(Py::_None())) {
00107         // ref counter is set to 1
00108         PythonObject = Py::Object(new Mesh::FeaturePythonPy(this),true);
00109     }
00110     return Py::new_reference_to(PythonObject);
00111 }
00113 
00114 // explicit template instantiation
00115 template class MeshExport FeaturePythonT<Mesh::Feature>;
00116 }
00117 

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