App/FeatureRevolution.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2009 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 # 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         // Now, let's get the TopoDS_Shape
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 }

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