FeatureExtrusion.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 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 
00029 #include "FeatureExtrusion.h"
00030 
00031 
00032 using namespace Part;
00033 
00034 
00035 PROPERTY_SOURCE(Part::Extrusion, Part::Feature)
00036 
00037 Extrusion::Extrusion()
00038 {
00039     ADD_PROPERTY(Base,(0));
00040     ADD_PROPERTY(Dir,(Base::Vector3f(0.0f,0.0f,1.0f)));
00041 }
00042 
00043 short Extrusion::mustExecute() const
00044 {
00045     if (Base.isTouched() ||
00046         Dir.isTouched() )
00047         return 1;
00048     return 0;
00049 }
00050 
00051 App::DocumentObjectExecReturn *Extrusion::execute(void)
00052 {
00053     App::DocumentObject* link = Base.getValue();
00054     if (!link)
00055         return new App::DocumentObjectExecReturn("No object linked");
00056     if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
00057         return new App::DocumentObjectExecReturn("Linked object is not a Part object");
00058     Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
00059 
00060     Base::Vector3f v = Dir.getValue();
00061     gp_Vec vec(v.x,v.y,v.z);
00062 
00063     try {
00064         // Now, let's get the TopoDS_Shape
00065         TopoDS_Shape swept = base->Shape.getShape().makePrism(vec);
00066         if (swept.IsNull())
00067             return new App::DocumentObjectExecReturn("Resulting shape is null");
00068         this->Shape.setValue(swept);
00069         return App::DocumentObject::StdReturn;
00070     }
00071     catch (Standard_Failure) {
00072         Handle_Standard_Failure e = Standard_Failure::Caught();
00073         return new App::DocumentObjectExecReturn(e->GetMessageString());
00074     }
00075 }

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