FeatureMeshSolid.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2006 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 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 #endif
00027 
00028 #include <Base/Console.h>
00029 #include <Base/Exception.h>
00030 #include <Base/Interpreter.h>
00031 #include <App/Document.h>
00032 
00033 #include "FeatureMeshSolid.h"
00034 #include "Mesh.h"
00035 
00036 
00037 namespace Mesh {
00038     const App::PropertyIntegerConstraint::Constraints intSampling = {0,1000,1};
00039     const App::PropertyFloatConstraint::Constraints floatRange = {0.0,1000.0,1.0};
00040 }
00041 
00042 using namespace Mesh;
00043 using namespace MeshCore;
00044 
00045 PROPERTY_SOURCE(Mesh::Sphere, Mesh::Feature)
00046 
00047 Sphere::Sphere(void)
00048 {
00049     ADD_PROPERTY(Radius  ,(5.0));
00050     ADD_PROPERTY(Sampling  ,(50));
00051     Radius.setConstraints(&floatRange);
00052     Sampling.setConstraints(&intSampling);
00053 }
00054 
00055 short Sphere::mustExecute() const
00056 {
00057     if (Radius.isTouched() || Sampling.isTouched())
00058         return 1;
00059     return Feature::mustExecute();
00060 }
00061 
00062 App::DocumentObjectExecReturn *Sphere::execute(void)
00063 {
00064     std::auto_ptr<MeshObject> mesh(MeshObject::createSphere(Radius.getValue(),Sampling.getValue()));
00065     if (mesh.get()) {
00066         mesh->setPlacement(this->Placement.getValue());
00067         Mesh.setValue(mesh->getKernel());
00068         return App::DocumentObject::StdReturn;
00069     }
00070     else {
00071         return new App::DocumentObjectExecReturn("Cannot create sphere", this);
00072     }
00073 }
00074 
00075 // -------------------------------------------------------------
00076 
00077 PROPERTY_SOURCE(Mesh::Ellipsoid, Mesh::Feature)
00078 
00079 Ellipsoid::Ellipsoid(void)
00080 {
00081     ADD_PROPERTY(Radius1  ,(2.0));
00082     ADD_PROPERTY(Radius2  ,(4.0));
00083     ADD_PROPERTY(Sampling  ,(50));
00084     Radius1.setConstraints(&floatRange);
00085     Radius2.setConstraints(&floatRange);
00086     Sampling.setConstraints(&intSampling);
00087 }
00088 
00089 short Ellipsoid::mustExecute() const
00090 {
00091     if (Radius1.isTouched() || 
00092         Radius2.isTouched() || 
00093         Sampling.isTouched())
00094         return 1;
00095     return Feature::mustExecute();
00096 }
00097 
00098 App::DocumentObjectExecReturn *Ellipsoid::execute(void)
00099 {
00100     std::auto_ptr<MeshObject> mesh(MeshObject::createEllipsoid(Radius1.getValue(),Radius2.getValue(),Sampling.getValue()));
00101     if (mesh.get()) {
00102         mesh->setPlacement(this->Placement.getValue());
00103         Mesh.setValue(mesh->getKernel());
00104         return App::DocumentObject::StdReturn;
00105     }
00106     else {
00107         return new App::DocumentObjectExecReturn("Cannot create ellipsoid", this);
00108     }
00109 }
00110 
00111 // -------------------------------------------------------------
00112 
00113 PROPERTY_SOURCE(Mesh::Cylinder, Mesh::Feature)
00114 
00115 Cylinder::Cylinder(void)
00116 {
00117     ADD_PROPERTY(Radius  ,(2.0));
00118     ADD_PROPERTY(Length  ,(10.0));
00119     ADD_PROPERTY(EdgeLength,(1.0));
00120     ADD_PROPERTY(Closed  ,(true));
00121     ADD_PROPERTY(Sampling  ,(50));
00122     Radius.setConstraints(&floatRange);
00123     Length.setConstraints(&floatRange);
00124     EdgeLength.setConstraints(&floatRange);
00125     Sampling.setConstraints(&intSampling);
00126 }
00127 
00128 short Cylinder::mustExecute() const
00129 {
00130     if (Radius.isTouched() || 
00131         Length.isTouched() ||
00132         EdgeLength.isTouched() ||
00133         Closed.isTouched() ||
00134         Sampling.isTouched())
00135         return 1;
00136     return Feature::mustExecute();
00137 }
00138 
00139 App::DocumentObjectExecReturn *Cylinder::execute(void)
00140 {
00141     std::auto_ptr<MeshObject> mesh(MeshObject::createCylinder(Radius.getValue(),Length.getValue(),
00142                                    Closed.getValue(),EdgeLength.getValue(),Sampling.getValue()));
00143     if (mesh.get()) {
00144         mesh->setPlacement(this->Placement.getValue());
00145         Mesh.setValue(mesh->getKernel());
00146         return App::DocumentObject::StdReturn;
00147     }
00148     else {
00149         return new App::DocumentObjectExecReturn("Cannot create cylinder", this);
00150     }
00151 }
00152 
00153 // -------------------------------------------------------------
00154 
00155 PROPERTY_SOURCE(Mesh::Cone, Mesh::Feature)
00156 
00157 Cone::Cone(void)
00158 {
00159     ADD_PROPERTY(Radius1  ,(2.0));
00160     ADD_PROPERTY(Radius2  ,(4.0));
00161     ADD_PROPERTY(Length  ,(10.0));
00162     ADD_PROPERTY(EdgeLength,(1.0));
00163     ADD_PROPERTY(Closed  ,(true));
00164     ADD_PROPERTY(Sampling  ,(50));
00165     Radius1.setConstraints(&floatRange);
00166     Radius2.setConstraints(&floatRange);
00167     Length.setConstraints(&floatRange);
00168     EdgeLength.setConstraints(&floatRange);
00169     Sampling.setConstraints(&intSampling);
00170 }
00171 
00172 short Cone::mustExecute() const
00173 {
00174     if (Radius1.isTouched() || 
00175         Radius2.isTouched() || 
00176         Length.isTouched()  ||
00177         EdgeLength.isTouched() ||
00178         Closed.isTouched()  ||
00179         Sampling.isTouched())
00180         return 1;
00181     return Feature::mustExecute();
00182 }
00183 
00184 App::DocumentObjectExecReturn *Cone::execute(void)
00185 {
00186     std::auto_ptr<MeshObject> mesh(MeshObject::createCone(Radius1.getValue(),Radius2.getValue(),Length.getValue(),
00187                                    Closed.getValue(),EdgeLength.getValue(),Sampling.getValue()));
00188     if (mesh.get()) {
00189         mesh->setPlacement(this->Placement.getValue());
00190         Mesh.setValue(mesh->getKernel());
00191         return App::DocumentObject::StdReturn;
00192     }
00193     else {
00194         return new App::DocumentObjectExecReturn("Cannot create cone", this);
00195     }
00196 }
00197 
00198 // -------------------------------------------------------------
00199 
00200 PROPERTY_SOURCE(Mesh::Torus, Mesh::Feature)
00201 
00202 Torus::Torus(void)
00203 {
00204     ADD_PROPERTY(Radius1  ,(10.0));
00205     ADD_PROPERTY(Radius2  ,(2.0));
00206     ADD_PROPERTY(Sampling  ,(50));
00207     Radius1.setConstraints(&floatRange);
00208     Radius2.setConstraints(&floatRange);
00209     Sampling.setConstraints(&intSampling);
00210 }
00211 
00212 short Torus::mustExecute() const
00213 {
00214     if (Radius1.isTouched() || 
00215         Radius2.isTouched() || 
00216         Sampling.isTouched())
00217         return 1;
00218     return Feature::mustExecute();
00219 }
00220 
00221 App::DocumentObjectExecReturn *Torus::execute(void)
00222 {
00223     std::auto_ptr<MeshObject> mesh(MeshObject::createTorus(Radius1.getValue(),Radius2.getValue(),Sampling.getValue()));
00224     if (mesh.get()) {
00225         mesh->setPlacement(this->Placement.getValue());
00226         Mesh.setValue(mesh->getKernel());
00227         return App::DocumentObject::StdReturn;
00228     }
00229     else {
00230         return new App::DocumentObjectExecReturn("Cannot create torus", this);
00231     }
00232 }
00233 
00234 // -------------------------------------------------------------
00235 
00236 PROPERTY_SOURCE(Mesh::Cube, Mesh::Feature)
00237 
00238 Cube::Cube(void)
00239 {
00240     ADD_PROPERTY_TYPE(Length,(10.0f),"Cube",App::Prop_None,"The length of the cube");
00241     ADD_PROPERTY_TYPE(Width ,(10.0f),"Cube",App::Prop_None,"The width of the cube");
00242     ADD_PROPERTY_TYPE(Height,(10.0f),"Cube",App::Prop_None,"The height of the cube");
00243     Length.setConstraints(&floatRange);
00244     Width.setConstraints(&floatRange);
00245     Height.setConstraints(&floatRange);
00246 }
00247 
00248 short Cube::mustExecute() const
00249 {
00250     if (Length.isTouched() || 
00251         Width.isTouched() || 
00252         Height.isTouched())
00253         return 1;
00254     return Feature::mustExecute();
00255 }
00256 
00257 App::DocumentObjectExecReturn *Cube::execute(void)
00258 {
00259     std::auto_ptr<MeshObject> mesh(MeshObject::createCube(Length.getValue(),Width.getValue(),Height.getValue()));
00260     if (mesh.get()) {
00261         mesh->setPlacement(this->Placement.getValue());
00262         Mesh.setValue(mesh->getKernel());
00263         return App::DocumentObject::StdReturn;
00264     }
00265     else {
00266         return new App::DocumentObjectExecReturn("Cannot create cube", this);
00267     }
00268 }

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