FreeCAD

Форк
0
/
FeaturePartCommon.cpp 
122 строки · 4.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2007 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 <BRepAlgoAPI_Common.hxx>
26
# include <BRepCheck_Analyzer.hxx>
27
# include <Standard_Failure.hxx>
28
# include <TopExp.hxx>
29
# include <TopoDS_Iterator.hxx>
30
# include <TopTools_IndexedMapOfShape.hxx>
31
#endif
32

33
#include <App/Application.h>
34
#include <Base/Parameter.h>
35

36
#include "FeaturePartCommon.h"
37
#include "TopoShapeOpCode.h"
38
#include "modelRefine.h"
39

40

41
using namespace Part;
42

43
PROPERTY_SOURCE(Part::Common, Part::Boolean)
44

45

46
Common::Common() = default;
47

48
const char *Common::opCode() const
49
{
50
    return Part::OpCodes::Common;
51
}
52

53
BRepAlgoAPI_BooleanOperation* Common::makeOperation(const TopoDS_Shape& base, const TopoDS_Shape& tool) const
54
{
55
    // Let's call algorithm computing a section operation:
56
    return new BRepAlgoAPI_Common(base, tool);
57
}
58

59
// ----------------------------------------------------
60

61
PROPERTY_SOURCE(Part::MultiCommon, Part::Feature)
62

63

64
MultiCommon::MultiCommon()
65
{
66
    ADD_PROPERTY(Shapes,(nullptr));
67
    Shapes.setSize(0);
68
    ADD_PROPERTY_TYPE(History,(ShapeHistory()), "Boolean", (App::PropertyType)
69
        (App::Prop_Output|App::Prop_Transient|App::Prop_Hidden), "Shape history");
70
    History.setSize(0);
71

72
    ADD_PROPERTY_TYPE(Refine,(0),"Boolean",(App::PropertyType)(App::Prop_None),"Refine shape (clean up redundant edges) after this boolean operation");
73

74
    //init Refine property
75
    Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
76
        .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part/Boolean");
77
    this->Refine.setValue(hGrp->GetBool("RefineModel", false));
78
}
79

80
short MultiCommon::mustExecute() const
81
{
82
    if (Shapes.isTouched())
83
        return 1;
84
    return 0;
85
}
86

87
App::DocumentObjectExecReturn *MultiCommon::execute()
88
{
89
    std::vector<TopoShape> shapes;
90
    for (auto obj : Shapes.getValues()) {
91
        TopoShape sh = Feature::getTopoShape(obj);
92
        if (sh.isNull()) {
93
            return new App::DocumentObjectExecReturn("Input shape is null");
94
        }
95
        shapes.push_back(sh);
96
    }
97

98
    TopoShape res {0};
99
    res.makeElementBoolean(Part::OpCodes::Common, shapes);
100
    if (res.isNull()) {
101
        throw Base::RuntimeError("Resulting shape is null");
102
    }
103

104
    Base::Reference<ParameterGrp> hGrp = App::GetApplication()
105
                                             .GetUserParameter()
106
                                             .GetGroup("BaseApp")
107
                                             ->GetGroup("Preferences")
108
                                             ->GetGroup("Mod/Part/Boolean");
109
    if (hGrp->GetBool("CheckModel", false)) {
110
        BRepCheck_Analyzer aChecker(res.getShape());
111
        if (!aChecker.IsValid()) {
112
            return new App::DocumentObjectExecReturn("Resulting shape is invalid");
113
        }
114
    }
115

116
    if (this->Refine.getValue()) {
117
        res = res.makeElementRefine();
118
    }
119
    this->Shape.setValue(res);
120

121
    return Part::Feature::execute();
122
}
123

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

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

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

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