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.hxx> 00028 # include <TopExp_Explorer.hxx> 00029 # include <TopoDS.hxx> 00030 # include <TopoDS_Edge.hxx> 00031 # include <TopTools_IndexedMapOfShape.hxx> 00032 #endif 00033 00034 00035 #include "FeatureFillet.h" 00036 #include <Base/Exception.h> 00037 00038 00039 using namespace Part; 00040 00041 00042 PROPERTY_SOURCE(Part::Fillet, Part::Feature) 00043 00044 Fillet::Fillet() 00045 { 00046 ADD_PROPERTY(Base,(0)); 00047 ADD_PROPERTY(Edges,(0,0,0)); 00048 Edges.setSize(0); 00049 } 00050 00051 short Fillet::mustExecute() const 00052 { 00053 if (Base.isTouched() || Edges.isTouched()) 00054 return 1; 00055 return 0; 00056 } 00057 00058 App::DocumentObjectExecReturn *Fillet::execute(void) 00059 { 00060 App::DocumentObject* link = Base.getValue(); 00061 if (!link) 00062 return new App::DocumentObjectExecReturn("No object linked"); 00063 if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) 00064 return new App::DocumentObjectExecReturn("Linked object is not a Part object"); 00065 Part::Feature *base = static_cast<Part::Feature*>(Base.getValue()); 00066 00067 try { 00068 #if defined(__GNUC__) && defined (FC_OS_LINUX) 00069 Base::SignalException se; 00070 #endif 00071 BRepFilletAPI_MakeFillet mkFillet(base->Shape.getValue()); 00072 TopTools_IndexedMapOfShape mapOfShape; 00073 TopExp::MapShapes(base->Shape.getValue(), TopAbs_EDGE, mapOfShape); 00074 00075 std::vector<FilletElement> values = Edges.getValues(); 00076 for (std::vector<FilletElement>::iterator it = values.begin(); it != values.end(); ++it) { 00077 int id = it->edgeid; 00078 double radius1 = it->radius1; 00079 double radius2 = it->radius2; 00080 const TopoDS_Edge& edge = TopoDS::Edge(mapOfShape.FindKey(id)); 00081 mkFillet.Add(radius1, radius2, edge); 00082 } 00083 00084 TopoDS_Shape shape = mkFillet.Shape(); 00085 if (shape.IsNull()) 00086 return new App::DocumentObjectExecReturn("Resulting shape is null"); 00087 this->Shape.setValue(shape); 00088 return App::DocumentObject::StdReturn; 00089 } 00090 catch (Standard_Failure) { 00091 Handle_Standard_Failure e = Standard_Failure::Caught(); 00092 return new App::DocumentObjectExecReturn(e->GetMessageString()); 00093 } 00094 catch (...) { 00095 return new App::DocumentObjectExecReturn("A fatal error occurred when making fillets"); 00096 } 00097 }