FreeCAD

Форк
0
/
FeatureFillet.cpp 
101 строка · 4.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2008 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 <BRepFilletAPI_MakeFillet.hxx>
26
# include <Precision.hxx>
27
# include <TopExp.hxx>
28
# include <TopExp_Explorer.hxx>
29
# include <TopoDS.hxx>
30
# include <TopoDS_Edge.hxx>
31
# include <TopTools_IndexedMapOfShape.hxx>
32
#endif
33

34
#include <Base/Exception.h>
35

36
#include "FeatureFillet.h"
37
#include "TopoShapeOpCode.h"
38

39

40
using namespace Part;
41

42
PROPERTY_SOURCE(Part::Fillet, Part::FilletBase)
43

44
Fillet::Fillet() = default;
45

46
App::DocumentObjectExecReturn *Fillet::execute()
47
{
48
    App::DocumentObject* link = Base.getValue();
49
    if (!link)
50
        return new App::DocumentObjectExecReturn("No object linked");
51

52

53
    try {
54
#if defined(__GNUC__) && defined (FC_OS_LINUX)
55
        Base::SignalException se;
56
#endif
57
        auto baseShape = Feature::getShape(link);
58
        TopoShape baseTopoShape = Feature::getTopoShape(link);
59
        BRepFilletAPI_MakeFillet mkFillet(baseShape);
60
        TopTools_IndexedMapOfShape mapOfShape;
61
        TopExp::MapShapes(baseShape, TopAbs_EDGE, mapOfShape);
62
        TopTools_IndexedMapOfShape mapOfEdges;
63
        TopExp::MapShapes(baseShape, TopAbs_EDGE, mapOfEdges);
64
        const auto &vals = EdgeLinks.getSubValues();
65
        const auto &subs = EdgeLinks.getShadowSubs();
66
        if(subs.size()!=(size_t)Edges.getSize())
67
            return new App::DocumentObjectExecReturn("Edge link size mismatch");
68
        size_t i=0;
69
        for(const auto &info : Edges.getValues()) {
70
            auto &sub = subs[i];
71
            auto &ref = sub.newName.size()?sub.newName:vals[i];
72
            ++i;
73
            // Toponaming project March 2024:  Replaced this code because it wouldn't work:
74
//            TopoDS_Shape edge;
75
//            try {
76
//                edge = baseTopoShape.getSubShape(ref.c_str());
77
//            }catch(...){}
78
            auto id = Data::MappedName(ref.c_str()).toIndexedName().getIndex();
79
            const TopoDS_Edge& edge = TopoDS::Edge(mapOfEdges.FindKey(id));
80
            if(edge.IsNull())
81
                return new App::DocumentObjectExecReturn("Invalid edge link");
82
            double radius1 = info.radius1;
83
            double radius2 = info.radius2;
84
            mkFillet.Add(radius1, radius2, TopoDS::Edge(edge));
85
        }
86

87
        TopoDS_Shape shape = mkFillet.Shape();
88
        if (shape.IsNull())
89
            return new App::DocumentObjectExecReturn("Resulting shape is null");
90

91
        TopoShape res(0);
92
        this->Shape.setValue(res.makeElementShape(mkFillet,baseTopoShape,Part::OpCodes::Fillet));
93
        return Part::Feature::execute();
94
    }
95
    catch (Standard_Failure& e) {
96
        return new App::DocumentObjectExecReturn(e.GetMessageString());
97
    }
98
    catch (...) {
99
        return new App::DocumentObjectExecReturn("A fatal error occurred when making fillets");
100
    }
101
}
102

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

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

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

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