esign/App/FeatureFillet.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 # include <BRepFilletAPI_MakeFillet.hxx>
00027 # include <TopExp_Explorer.hxx>
00028 # include <TopoDS.hxx>
00029 # include <TopoDS_Edge.hxx>
00030 #endif
00031 
00032 #include <Mod/Part/App/TopoShape.h>
00033 
00034 #include "FeatureFillet.h"
00035 
00036 
00037 using namespace PartDesign;
00038 
00039 
00040 PROPERTY_SOURCE(PartDesign::Fillet, PartDesign::DressUp)
00041 
00042 const App::PropertyFloatConstraint::Constraints floatRadius = {0.0f,FLT_MAX,0.1f};
00043 
00044 Fillet::Fillet()
00045 {
00046     ADD_PROPERTY(Radius,(1.0f));
00047     Radius.setConstraints(&floatRadius);
00048 }
00049 
00050 short Fillet::mustExecute() const
00051 {
00052     if (Base.isTouched() || Radius.isTouched())
00053         return 1;
00054     if (Base.getValue() && Base.getValue()->isTouched())
00055         return 1;
00056     return 0;
00057 }
00058 
00059 App::DocumentObjectExecReturn *Fillet::execute(void)
00060 {
00061     App::DocumentObject* link = Base.getValue();
00062     if (!link)
00063         return new App::DocumentObjectExecReturn("No object linked");
00064     if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
00065         return new App::DocumentObjectExecReturn("Linked object is not a Part object");
00066     Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
00067     const Part::TopoShape& TopShape = base->Shape.getShape();
00068     if (TopShape._Shape.IsNull())
00069         return new App::DocumentObjectExecReturn("Cannot fillet invalid shape");
00070 
00071     const std::vector<std::string>& SubVals = Base.getSubValuesStartsWith("Edge");
00072     if (SubVals.size() == 0)
00073         return new App::DocumentObjectExecReturn("No edges specified");
00074 
00075     float radius = Radius.getValue();
00076 
00077     try {
00078         BRepFilletAPI_MakeFillet mkFillet(base->Shape.getValue());
00079 
00080         for (std::vector<std::string>::const_iterator it= SubVals.begin();it!=SubVals.end();++it) {
00081             TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(it->c_str()));
00082             mkFillet.Add(radius, radius, edge);
00083         }
00084 
00085         TopoDS_Shape shape = mkFillet.Shape();
00086         if (shape.IsNull())
00087             return new App::DocumentObjectExecReturn("Resulting shape is null");
00088         this->Shape.setValue(shape);
00089         return App::DocumentObject::StdReturn;
00090     }
00091     catch (Standard_Failure) {
00092         Handle_Standard_Failure e = Standard_Failure::Caught();
00093         return new App::DocumentObjectExecReturn(e->GetMessageString());
00094     }
00095 }

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