23
#include "PreCompiled.h"
25
#include <App/Document.h>
27
#include "FeatureMeshSolid.h"
32
const App::PropertyIntegerConstraint::Constraints intSampling = {0, INT_MAX, 1};
33
const App::PropertyLength::Constraints floatRange = {0.0, FLT_MAX, 1.0};
37
using namespace MeshCore;
39
PROPERTY_SOURCE(Mesh::Sphere, Mesh::Feature)
43
ADD_PROPERTY(Radius, (5.0));
44
ADD_PROPERTY(Sampling, (50));
45
Radius.setConstraints(&floatRange);
46
Sampling.setConstraints(&intSampling);
49
short Sphere::mustExecute() const
51
if (Radius.isTouched() || Sampling.isTouched()) {
54
return Feature::mustExecute();
57
App::DocumentObjectExecReturn* Sphere::execute()
59
std::unique_ptr<MeshObject> mesh(
60
MeshObject::createSphere((float)Radius.getValue(), Sampling.getValue()));
62
mesh->setPlacement(this->Placement.getValue());
63
Mesh.setValue(mesh->getKernel());
64
return App::DocumentObject::StdReturn;
67
return new App::DocumentObjectExecReturn("Cannot create sphere", this);
71
void Sphere::handleChangedPropertyType(Base::XMLReader& reader,
75
if (prop == &Radius && strcmp(TypeName, "App::PropertyFloatConstraint") == 0) {
76
App::PropertyFloatConstraint r;
78
Radius.setValue(r.getValue());
81
Mesh::Feature::handleChangedPropertyType(reader, TypeName, prop);
87
PROPERTY_SOURCE(Mesh::Ellipsoid, Mesh::Feature)
91
ADD_PROPERTY(Radius1, (2.0));
92
ADD_PROPERTY(Radius2, (4.0));
93
ADD_PROPERTY(Sampling, (50));
94
Radius1.setConstraints(&floatRange);
95
Radius2.setConstraints(&floatRange);
96
Sampling.setConstraints(&intSampling);
99
short Ellipsoid::mustExecute() const
101
if (Radius1.isTouched() || Radius2.isTouched() || Sampling.isTouched()) {
104
return Feature::mustExecute();
107
App::DocumentObjectExecReturn* Ellipsoid::execute()
109
std::unique_ptr<MeshObject> mesh(MeshObject::createEllipsoid((float)Radius1.getValue(),
110
(float)Radius2.getValue(),
111
Sampling.getValue()));
113
mesh->setPlacement(this->Placement.getValue());
114
Mesh.setValue(mesh->getKernel());
115
return App::DocumentObject::StdReturn;
118
return new App::DocumentObjectExecReturn("Cannot create ellipsoid", this);
122
void Ellipsoid::handleChangedPropertyType(Base::XMLReader& reader,
123
const char* TypeName,
126
if ((prop == &Radius1 || prop == &Radius2)
127
&& strcmp(TypeName, "App::PropertyFloatConstraint") == 0) {
128
App::PropertyFloatConstraint r;
130
static_cast<App::PropertyLength*>(prop)->setValue(r.getValue());
133
Mesh::Feature::handleChangedPropertyType(reader, TypeName, prop);
139
PROPERTY_SOURCE(Mesh::Cylinder, Mesh::Feature)
143
ADD_PROPERTY(Radius, (2.0));
144
ADD_PROPERTY(Length, (10.0));
145
ADD_PROPERTY(EdgeLength, (1.0));
146
ADD_PROPERTY(Closed, (true));
147
ADD_PROPERTY(Sampling, (50));
148
Radius.setConstraints(&floatRange);
149
Length.setConstraints(&floatRange);
150
EdgeLength.setConstraints(&floatRange);
151
Sampling.setConstraints(&intSampling);
154
short Cylinder::mustExecute() const
156
if (Radius.isTouched() || Length.isTouched() || EdgeLength.isTouched() || Closed.isTouched()
157
|| Sampling.isTouched()) {
160
return Feature::mustExecute();
163
App::DocumentObjectExecReturn* Cylinder::execute()
165
std::unique_ptr<MeshObject> mesh(MeshObject::createCylinder((float)Radius.getValue(),
166
(float)Length.getValue(),
168
(float)EdgeLength.getValue(),
169
Sampling.getValue()));
171
mesh->setPlacement(this->Placement.getValue());
172
Mesh.setValue(mesh->getKernel());
173
return App::DocumentObject::StdReturn;
176
return new App::DocumentObjectExecReturn("Cannot create cylinder", this);
180
void Cylinder::handleChangedPropertyType(Base::XMLReader& reader,
181
const char* TypeName,
184
if ((prop == &Radius || prop == &Length || prop == &EdgeLength)
185
&& strcmp(TypeName, "App::PropertyFloatConstraint") == 0) {
186
App::PropertyFloatConstraint r;
188
static_cast<App::PropertyLength*>(prop)->setValue(r.getValue());
191
Mesh::Feature::handleChangedPropertyType(reader, TypeName, prop);
197
PROPERTY_SOURCE(Mesh::Cone, Mesh::Feature)
201
ADD_PROPERTY(Radius1, (2.0));
202
ADD_PROPERTY(Radius2, (4.0));
203
ADD_PROPERTY(Length, (10.0));
204
ADD_PROPERTY(EdgeLength, (1.0));
205
ADD_PROPERTY(Closed, (true));
206
ADD_PROPERTY(Sampling, (50));
207
Radius1.setConstraints(&floatRange);
208
Radius2.setConstraints(&floatRange);
209
Length.setConstraints(&floatRange);
210
EdgeLength.setConstraints(&floatRange);
211
Sampling.setConstraints(&intSampling);
214
short Cone::mustExecute() const
216
if (Radius1.isTouched() || Radius2.isTouched() || Length.isTouched() || EdgeLength.isTouched()
217
|| Closed.isTouched() || Sampling.isTouched()) {
220
return Feature::mustExecute();
223
App::DocumentObjectExecReturn* Cone::execute()
225
std::unique_ptr<MeshObject> mesh(MeshObject::createCone((float)Radius1.getValue(),
226
(float)Radius2.getValue(),
227
(float)Length.getValue(),
229
(float)EdgeLength.getValue(),
230
Sampling.getValue()));
232
mesh->setPlacement(this->Placement.getValue());
233
Mesh.setValue(mesh->getKernel());
234
return App::DocumentObject::StdReturn;
237
return new App::DocumentObjectExecReturn("Cannot create cone", this);
241
void Cone::handleChangedPropertyType(Base::XMLReader& reader,
242
const char* TypeName,
245
if ((prop == &Radius1 || prop == &Radius2 || prop == &Length || prop == &EdgeLength)
246
&& strcmp(TypeName, "App::PropertyFloatConstraint") == 0) {
247
App::PropertyFloatConstraint r;
249
static_cast<App::PropertyLength*>(prop)->setValue(r.getValue());
252
Mesh::Feature::handleChangedPropertyType(reader, TypeName, prop);
258
PROPERTY_SOURCE(Mesh::Torus, Mesh::Feature)
262
ADD_PROPERTY(Radius1, (10.0));
263
ADD_PROPERTY(Radius2, (2.0));
264
ADD_PROPERTY(Sampling, (50));
265
Radius1.setConstraints(&floatRange);
266
Radius2.setConstraints(&floatRange);
267
Sampling.setConstraints(&intSampling);
270
short Torus::mustExecute() const
272
if (Radius1.isTouched() || Radius2.isTouched() || Sampling.isTouched()) {
275
return Feature::mustExecute();
278
App::DocumentObjectExecReturn* Torus::execute()
280
std::unique_ptr<MeshObject> mesh(MeshObject::createTorus((float)Radius1.getValue(),
281
(float)Radius2.getValue(),
282
Sampling.getValue()));
284
mesh->setPlacement(this->Placement.getValue());
285
Mesh.setValue(mesh->getKernel());
286
return App::DocumentObject::StdReturn;
289
return new App::DocumentObjectExecReturn("Cannot create torus", this);
293
void Torus::handleChangedPropertyType(Base::XMLReader& reader,
294
const char* TypeName,
297
if ((prop == &Radius1 || prop == &Radius2)
298
&& strcmp(TypeName, "App::PropertyFloatConstraint") == 0) {
299
App::PropertyFloatConstraint r;
301
static_cast<App::PropertyLength*>(prop)->setValue(r.getValue());
304
Mesh::Feature::handleChangedPropertyType(reader, TypeName, prop);
310
PROPERTY_SOURCE(Mesh::Cube, Mesh::Feature)
314
ADD_PROPERTY_TYPE(Length, (10.0f), "Cube", App::Prop_None, "The length of the cube");
315
ADD_PROPERTY_TYPE(Width, (10.0f), "Cube", App::Prop_None, "The width of the cube");
316
ADD_PROPERTY_TYPE(Height, (10.0f), "Cube", App::Prop_None, "The height of the cube");
317
Length.setConstraints(&floatRange);
318
Width.setConstraints(&floatRange);
319
Height.setConstraints(&floatRange);
322
short Cube::mustExecute() const
324
if (Length.isTouched() || Width.isTouched() || Height.isTouched()) {
327
return Feature::mustExecute();
330
App::DocumentObjectExecReturn* Cube::execute()
332
std::unique_ptr<MeshObject> mesh(MeshObject::createCube((float)Length.getValue(),
333
(float)Width.getValue(),
334
(float)Height.getValue()));
336
mesh->setPlacement(this->Placement.getValue());
337
Mesh.setValue(mesh->getKernel());
338
return App::DocumentObject::StdReturn;
341
return new App::DocumentObjectExecReturn("Cannot create cube", this);
345
void Cube::handleChangedPropertyType(Base::XMLReader& reader,
346
const char* TypeName,
349
if ((prop == &Length || prop == &Width || prop == &Height)
350
&& strcmp(TypeName, "App::PropertyFloatConstraint") == 0) {
351
App::PropertyFloatConstraint r;
353
static_cast<App::PropertyLength*>(prop)->setValue(r.getValue());
356
Mesh::Feature::handleChangedPropertyType(reader, TypeName, prop);