App/FeatureChamfer.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2010 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_MakeChamfer.hxx>
00027 # include <TopExp.hxx>
00028 # include <TopExp_Explorer.hxx>
00029 # include <TopoDS.hxx>
00030 # include <TopoDS_Edge.hxx>
00031 # include <TopTools_ListOfShape.hxx>
00032 # include <TopTools_IndexedMapOfShape.hxx>
00033 # include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
00034 #endif
00035 
00036 
00037 #include "FeatureChamfer.h"
00038 
00039 
00040 using namespace Part;
00041 
00042 
00043 PROPERTY_SOURCE(Part::Chamfer, Part::Feature)
00044 
00045 Chamfer::Chamfer()
00046 {
00047     ADD_PROPERTY(Base,(0));
00048     ADD_PROPERTY(Edges,(0,0,0));
00049     Edges.setSize(0);
00050 }
00051 
00052 short Chamfer::mustExecute() const
00053 {
00054     if (Base.isTouched() || Edges.isTouched())
00055         return 1;
00056     return 0;
00057 }
00058 
00059 App::DocumentObjectExecReturn *Chamfer::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 
00068     try {
00069         BRepFilletAPI_MakeChamfer mkChamfer(base->Shape.getValue());
00070         TopTools_IndexedMapOfShape mapOfEdges;
00071         TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace;
00072         TopExp::MapShapesAndAncestors(base->Shape.getValue(), TopAbs_EDGE, TopAbs_FACE, mapEdgeFace);
00073         TopExp::MapShapes(base->Shape.getValue(), TopAbs_EDGE, mapOfEdges);
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(mapOfEdges.FindKey(id));
00081             const TopoDS_Face& face = TopoDS::Face(mapEdgeFace.FindFromKey(edge).First());
00082             mkChamfer.Add(radius1, radius2, edge, face);
00083         }
00084 
00085         TopoDS_Shape shape = mkChamfer.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 }
00096 

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