App/FeatureChamfer.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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