/*************************************************************************** * Copyright (c) 2010 Juergen Riegel * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ # include # include # include # include # include # include # include #endif #include #include "FeatureChamfer.h" using namespace PartDesign; PROPERTY_SOURCE(PartDesign::Chamfer, PartDesign::DressUp) const App::PropertyFloatConstraint::Constraints floatSize = {0.0f,FLT_MAX,0.1f}; Chamfer::Chamfer() { ADD_PROPERTY(Size,(1.0f)); Size.setConstraints(&floatSize); } short Chamfer::mustExecute() const { if (Placement.isTouched() || Size.isTouched()) return 1; return DressUp::mustExecute(); } App::DocumentObjectExecReturn *Chamfer::execute(void) { App::DocumentObject* link = Base.getValue(); if (!link) return new App::DocumentObjectExecReturn("No object linked"); if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) return new App::DocumentObjectExecReturn("Linked object is not a Part object"); Part::Feature *base = static_cast(Base.getValue()); const Part::TopoShape& TopShape = base->Shape.getShape(); if (TopShape._Shape.IsNull()) return new App::DocumentObjectExecReturn("Cannot chamfer invalid shape"); const std::vector& SubVals = Base.getSubValuesStartsWith("Edge"); if (SubVals.size() == 0) return new App::DocumentObjectExecReturn("No edges specified"); float size = Size.getValue(); this->positionByBase(); // create an untransformed copy of the base shape Part::TopoShape baseShape(TopShape); baseShape.setTransform(Base::Matrix4D()); try { BRepFilletAPI_MakeChamfer mkChamfer(baseShape._Shape); TopTools_IndexedMapOfShape mapOfEdges; TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace; TopExp::MapShapesAndAncestors(baseShape._Shape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace); TopExp::MapShapes(baseShape._Shape, TopAbs_EDGE, mapOfEdges); for (std::vector::const_iterator it=SubVals.begin(); it != SubVals.end(); ++it) { TopoDS_Edge edge = TopoDS::Edge(baseShape.getSubShape(it->c_str())); const TopoDS_Face& face = TopoDS::Face(mapEdgeFace.FindFromKey(edge).First()); mkChamfer.Add(size, edge, face); } mkChamfer.Build(); if (!mkChamfer.IsDone()) return new App::DocumentObjectExecReturn("Failed to create chamfer"); TopoDS_Shape shape = mkChamfer.Shape(); if (shape.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is null"); this->Shape.setValue(shape); return App::DocumentObject::StdReturn; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); return new App::DocumentObjectExecReturn(e->GetMessageString()); } }