FreeCAD

Форк
0
/
FeatureChamfer.cpp 
94 строки · 4.3 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2010 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_MakeChamfer.hxx>
26
# include <Precision.hxx>
27
# include <TopExp.hxx>
28
# include <TopoDS.hxx>
29
# include <TopoDS_Edge.hxx>
30
# include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
31
# include <TopTools_IndexedMapOfShape.hxx>
32
#endif
33

34
#include "FeatureChamfer.h"
35
#include "TopoShapeOpCode.h"
36

37

38
using namespace Part;
39

40
PROPERTY_SOURCE(Part::Chamfer, Part::FilletBase)
41

42
Chamfer::Chamfer() = default;
43

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

50
    try {
51
        TopoShape baseTopoShape = Feature::getTopoShape(link);
52
        auto baseShape = Feature::getShape(link);
53
        BRepFilletAPI_MakeChamfer mkChamfer(baseShape);
54
        TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace;
55
        TopExp::MapShapesAndAncestors(baseShape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace);
56
        TopTools_IndexedMapOfShape mapOfEdges;
57
        TopExp::MapShapes(baseShape, TopAbs_EDGE, mapOfEdges);
58

59
        const auto &vals = EdgeLinks.getSubValues();
60
        const auto &subs = EdgeLinks.getShadowSubs();
61
        if(subs.size()!=(size_t)Edges.getSize())
62
            return new App::DocumentObjectExecReturn("Edge link size mismatch");
63
        size_t i=0;
64
        for(const auto &info : Edges.getValues()) {
65
            auto &sub = subs[i];
66
            auto &ref = sub.newName.size()?sub.newName:vals[i];
67
            ++i;
68
            // Toponaming project March 2024:  Replaced this code because it wouldn't work:
69
//            TopoDS_Shape edge;
70
//            try {
71
//                edge = baseTopoShape.getSubShape(ref.c_str());
72
//            }catch(...){}
73
            auto id = Data::MappedName(ref.c_str()).toIndexedName().getIndex();
74
            const TopoDS_Edge& edge = TopoDS::Edge(mapOfEdges.FindKey(id));
75
            if(edge.IsNull())
76
                return new App::DocumentObjectExecReturn("Invalid edge link");
77
            double radius1 = info.radius1;
78
            double radius2 = info.radius2;
79
            const TopoDS_Face& face = TopoDS::Face(mapEdgeFace.FindFromKey(edge).First());
80
            mkChamfer.Add(radius1, radius2, TopoDS::Edge(edge), face);
81
        }
82

83
        TopoDS_Shape shape = mkChamfer.Shape();
84
        if (shape.IsNull())
85
            return new App::DocumentObjectExecReturn("Resulting shape is null");
86

87
        TopoShape res(0);
88
        this->Shape.setValue(res.makeElementShape(mkChamfer,baseTopoShape,Part::OpCodes::Chamfer));
89
        return Part::Feature::execute();
90
    }
91
    catch (Standard_Failure& e) {
92
        return new App::DocumentObjectExecReturn(e.GetMessageString());
93
    }
94
}
95

96

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

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

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

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