1
/***************************************************************************
2
* Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <BRepBuilderAPI_Copy.hxx>
29
#include "FeatureFace.h"
36
PROPERTY_SOURCE(Part::Face, Part::Feature)
40
ADD_PROPERTY(Sources,(nullptr));
41
ADD_PROPERTY(FaceMakerClass,("Part::FaceMakerCheese"));//default value here is for legacy documents. Default for new objects is set in setupObject.
45
short Face::mustExecute() const
47
if (FaceMakerClass.isTouched())
49
if (Sources.isTouched())
51
return Part::Feature::mustExecute();
54
void Face::setupObject()
56
this->FaceMakerClass.setValue("Part::FaceMakerBullseye");
57
Feature::setupObject();
60
App::DocumentObjectExecReturn *Face::execute()
62
std::vector<App::DocumentObject*> links = Sources.getValues();
64
return new App::DocumentObjectExecReturn("No shapes linked");
66
std::unique_ptr<FaceMaker> facemaker = FaceMaker::ConstructFromType(this->FaceMakerClass.getValue());
68
for (std::vector<App::DocumentObject*>::iterator it = links.begin(); it != links.end(); ++it) {
70
return new App::DocumentObjectExecReturn("Linked object is not a Part object (has no Shape).");
71
TopoDS_Shape shape = Feature::getShape(*it);
73
return new App::DocumentObjectExecReturn("Linked shape object is empty");
75
// this is a workaround for an obscure OCC bug which leads to empty tessellations
76
// for some faces. Making an explicit copy of the linked shape seems to fix it.
77
// The error only happens when re-computing the shape.
78
/*if (!this->Shape.getValue().IsNull()) {
79
BRepBuilderAPI_Copy copy(shape);
82
return new App::DocumentObjectExecReturn("Linked shape object is empty");
85
if(links.size() == 1 && shape.ShapeType() == TopAbs_COMPOUND)
86
facemaker->useCompound(TopoDS::Compound(shape));
88
facemaker->addShape(shape);
93
TopoDS_Shape aFace = facemaker->Shape();
95
return new App::DocumentObjectExecReturn("Creating face failed (null shape result)");
96
this->Shape.setValue(aFace);
98
return App::DocumentObject::StdReturn;