FemMeshProperty.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 <sstream>
00028 #endif
00029 
00030 
00031 #include <strstream>
00032 #include <Base/Console.h>
00033 #include <Base/Writer.h>
00034 #include <Base/Reader.h>
00035 #include <Base/Exception.h>
00036 #include <Base/FileInfo.h>
00037 #include <Base/Stream.h>
00038 
00039 #include "FemMeshProperty.h"
00040 #include "FemMeshPy.h"
00041 
00042 using namespace Fem;
00043 
00044 TYPESYSTEM_SOURCE(Fem::PropertyFemMesh , App::PropertyComplexGeoData);
00045 
00046 PropertyFemMesh::PropertyFemMesh() : _FemMesh(new FemMesh)
00047 {
00048 }
00049 
00050 PropertyFemMesh::~PropertyFemMesh()
00051 {
00052 }
00053 
00054 void PropertyFemMesh::setValuePtr(FemMesh* mesh)
00055 {
00056     // use the tmp. object to guarantee that the referenced mesh is not destroyed
00057     // before calling hasSetValue()
00058     Base::Reference<FemMesh> tmp(_FemMesh);
00059     aboutToSetValue();
00060     _FemMesh = mesh;
00061     hasSetValue();
00062 }
00063 
00064 void PropertyFemMesh::setValue(const FemMesh& sh)
00065 {
00066     aboutToSetValue();
00067     *_FemMesh = sh;
00068     hasSetValue();
00069 }
00070 
00071 const FemMesh &PropertyFemMesh::getValue(void)const 
00072 {
00073     return *_FemMesh;
00074 }
00075 
00076 const Data::ComplexGeoData* PropertyFemMesh::getComplexData() const
00077 {
00078     return (FemMesh*)_FemMesh;
00079 }
00080 
00081 Base::BoundBox3d PropertyFemMesh::getBoundingBox() const
00082 {
00083     return _FemMesh->getBoundBox();
00084 }
00085 
00086 void PropertyFemMesh::transformGeometry(const Base::Matrix4D &rclMat)
00087 {
00088     aboutToSetValue();
00089     _FemMesh->transformGeometry(rclMat);
00090     hasSetValue();
00091 }
00092 
00093 void PropertyFemMesh::getFaces(std::vector<Base::Vector3d> &aPoints,
00094                                std::vector<Data::ComplexGeoData::Facet> &aTopo,
00095                                float accuracy, uint16_t flags) const
00096 {
00097     _FemMesh->getFaces(aPoints, aTopo, accuracy, flags);
00098 }
00099 
00100 PyObject *PropertyFemMesh::getPyObject(void)
00101 {
00102     FemMeshPy* mesh = new FemMeshPy(&*_FemMesh);
00103     mesh->setConst();
00104     return mesh;
00105 }
00106 
00107 void PropertyFemMesh::setPyObject(PyObject *value)
00108 {
00109     if (PyObject_TypeCheck(value, &(FemMeshPy::Type))) {
00110         FemMeshPy *pcObject = static_cast<FemMeshPy*>(value);
00111         setValue(*pcObject->getFemMeshPtr());
00112     }
00113     else {
00114         std::string error = std::string("type must be 'FemMesh', not ");
00115         error += value->ob_type->tp_name;
00116         throw Py::TypeError(error);
00117     }
00118 }
00119 
00120 App::Property *PropertyFemMesh::Copy(void) const
00121 {
00122     PropertyFemMesh *prop = new PropertyFemMesh();
00123     prop->_FemMesh = this->_FemMesh;
00124     return prop;
00125 }
00126 
00127 void PropertyFemMesh::Paste(const App::Property &from)
00128 {
00129     aboutToSetValue();
00130     _FemMesh = dynamic_cast<const PropertyFemMesh&>(from)._FemMesh;
00131     hasSetValue();
00132 }
00133 
00134 unsigned int PropertyFemMesh::getMemSize (void) const
00135 {
00136     return _FemMesh->getMemSize();
00137 }
00138 
00139 void PropertyFemMesh::Save (Base::Writer &writer) const
00140 {
00141     if (!writer.isForceXML()) {
00142         //See SaveDocFile(), RestoreDocFile()
00143         writer.Stream() << writer.ind() << "<FemMesh file=\"" 
00144                         << writer.addFile("FemMesh.unv", this)
00145                         << "\"/>" << std::endl;
00146     }
00147 }
00148 
00149 void PropertyFemMesh::Restore(Base::XMLReader &reader)
00150 {
00151     reader.readElement("FemMesh");
00152     std::string file (reader.getAttribute("file") );
00153 
00154     if (!file.empty()) {
00155         // initate a file read
00156         reader.addFile(file.c_str(),this);
00157     }
00158 }
00159 
00160 void PropertyFemMesh::SaveDocFile (Base::Writer &writer) const
00161 {
00162     _FemMesh->SaveDocFile(writer);
00163 }
00164 
00165 void PropertyFemMesh::RestoreDocFile(Base::Reader &reader)
00166 {
00167     aboutToSetValue();
00168     _FemMesh->RestoreDocFile(reader);
00169     hasSetValue();
00170 }

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