FreeCAD

Форк
0
/
FeatureFace.cpp 
99 строк · 4.1 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
# include <BRepBuilderAPI_Copy.hxx>
26
# include <TopoDS.hxx>
27
#endif
28

29
#include "FeatureFace.h"
30
#include "FaceMaker.h"
31

32

33
using namespace Part;
34

35

36
PROPERTY_SOURCE(Part::Face, Part::Feature)
37

38
Face::Face()
39
{
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.
42
    Sources.setSize(0);
43
}
44

45
short Face::mustExecute() const
46
{
47
    if (FaceMakerClass.isTouched())
48
        return 1;
49
    if (Sources.isTouched())
50
        return 1;
51
    return Part::Feature::mustExecute();
52
}
53

54
void Face::setupObject()
55
{
56
    this->FaceMakerClass.setValue("Part::FaceMakerBullseye");
57
    Feature::setupObject();
58
}
59

60
App::DocumentObjectExecReturn *Face::execute()
61
{
62
    std::vector<App::DocumentObject*> links = Sources.getValues();
63
    if (links.empty())
64
        return new App::DocumentObjectExecReturn("No shapes linked");
65

66
    std::unique_ptr<FaceMaker> facemaker = FaceMaker::ConstructFromType(this->FaceMakerClass.getValue());
67

68
    for (std::vector<App::DocumentObject*>::iterator it = links.begin(); it != links.end(); ++it) {
69
        if (!(*it))
70
            return new App::DocumentObjectExecReturn("Linked object is not a Part object (has no Shape).");
71
        TopoDS_Shape shape = Feature::getShape(*it);
72
        if (shape.IsNull())
73
            return new App::DocumentObjectExecReturn("Linked shape object is empty");
74

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);
80
            shape = copy.Shape();
81
            if (shape.IsNull())
82
                return new App::DocumentObjectExecReturn("Linked shape object is empty");
83
        }*/
84

85
        if(links.size() == 1 && shape.ShapeType() == TopAbs_COMPOUND)
86
            facemaker->useCompound(TopoDS::Compound(shape));
87
        else
88
            facemaker->addShape(shape);
89
    }
90

91
    facemaker->Build();
92

93
    TopoDS_Shape aFace = facemaker->Shape();
94
    if (aFace.IsNull())
95
        return new App::DocumentObjectExecReturn("Creating face failed (null shape result)");
96
    this->Shape.setValue(aFace);
97

98
    return App::DocumentObject::StdReturn;
99
}
100

101

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.