App/FeatureRevolution.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <gp_Ax1.hxx>
00027 #endif
00028
00029
00030 #include "FeatureRevolution.h"
00031
00032
00033 using namespace Part;
00034
00035 App::PropertyFloatConstraint::Constraints Revolution::angleRangeU = {-360.0f,360.0f,1.0f};
00036
00037 PROPERTY_SOURCE(Part::Revolution, Part::Feature)
00038
00039 Revolution::Revolution()
00040 {
00041 ADD_PROPERTY(Source,(0));
00042 ADD_PROPERTY(Base,(Base::Vector3f(0.0f,0.0f,0.0f)));
00043 ADD_PROPERTY(Axis,(Base::Vector3f(0.0f,0.0f,1.0f)));
00044 ADD_PROPERTY(Angle,(360.0f));
00045 Angle.setConstraints(&angleRangeU);
00046 }
00047
00048 short Revolution::mustExecute() const
00049 {
00050 if (Base.isTouched() ||
00051 Axis.isTouched() ||
00052 Source.isTouched())
00053 return 1;
00054 return 0;
00055 }
00056
00057 App::DocumentObjectExecReturn *Revolution::execute(void)
00058 {
00059 App::DocumentObject* link = Source.getValue();
00060 if (!link)
00061 return new App::DocumentObjectExecReturn("No object linked");
00062 if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
00063 return new App::DocumentObjectExecReturn("Linked object is not a Part object");
00064 Part::Feature *base = static_cast<Part::Feature*>(Source.getValue());
00065
00066 Base::Vector3f b = Base.getValue();
00067 Base::Vector3f v = Axis.getValue();
00068 gp_Pnt pnt(b.x,b.y,b.z);
00069 gp_Dir dir(v.x,v.y,v.z);
00070
00071 try {
00072
00073 TopoDS_Shape revolve = base->Shape.getShape().revolve(gp_Ax1(pnt, dir),
00074 Angle.getValue()/180.0f*Standard_PI);
00075 if (revolve.IsNull())
00076 return new App::DocumentObjectExecReturn("Resulting shape is null");
00077 this->Shape.setValue(revolve);
00078 return App::DocumentObject::StdReturn;
00079 }
00080 catch (Standard_Failure) {
00081 Handle_Standard_Failure e = Standard_Failure::Caught();
00082 return new App::DocumentObjectExecReturn(e->GetMessageString());
00083 }
00084 }