FreeCAD

Форк
0
/
ProjectionAlgos.cpp 
243 строки · 10.0 Кб
1
/***************************************************************************
2
 *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2002     *
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 <sstream>
26

27
#include <BRepLib.hxx>
28
#include <BRepMesh_IncrementalMesh.hxx>
29
#include <HLRAlgo_Projector.hxx>
30
#include <HLRBRep_Algo.hxx>
31
#include <HLRBRep_HLRToShape.hxx>
32
#include <TopExp_Explorer.hxx>
33
#include <TopoDS.hxx>
34
#include <TopoDS_Shape.hxx>
35
#include <gp_Ax2.hxx>
36
#include <gp_Dir.hxx>
37
#include <gp_Pnt.hxx>
38
#endif
39

40
#include <Base/Exception.h>
41

42
#include "DrawingExport.h"
43
#include "ProjectionAlgos.h"
44

45

46
using namespace Drawing;
47
using namespace std;
48

49
//===========================================================================
50
// ProjectionAlgos
51
//===========================================================================
52

53

54
ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape& Input, const Base::Vector3d& Dir)
55
    : Input(Input)
56
    , Direction(Dir)
57
{
58
    execute();
59
}
60

61
ProjectionAlgos::~ProjectionAlgos()
62
{}
63

64
// added by tanderson. aka blobfish.
65
// projection algorithms build a 2d curve(pcurve) but no 3d curve.
66
// this causes problems with meshing algorithms after save and load.
67
static const TopoDS_Shape& build3dCurves(const TopoDS_Shape& shape)
68
{
69
    TopExp_Explorer it;
70
    for (it.Init(shape, TopAbs_EDGE); it.More(); it.Next()) {
71
        BRepLib::BuildCurve3d(TopoDS::Edge(it.Current()));
72
    }
73
    return shape;
74
}
75

76
void ProjectionAlgos::execute(void)
77
{
78
    Handle(HLRBRep_Algo) brep_hlr = new HLRBRep_Algo;
79
    brep_hlr->Add(Input);
80

81
    gp_Ax2 transform(gp_Pnt(0, 0, 0), gp_Dir(Direction.x, Direction.y, Direction.z));
82
    HLRAlgo_Projector projector(transform);
83
    brep_hlr->Projector(projector);
84
    brep_hlr->Update();
85
    brep_hlr->Hide();
86

87
    // extracting the result sets:
88
    HLRBRep_HLRToShape shapes(brep_hlr);
89

90
    V = build3dCurves(shapes.VCompound());          // hard edge visibly
91
    V1 = build3dCurves(shapes.Rg1LineVCompound());  // Smoth edges visibly
92
    VN = build3dCurves(shapes.RgNLineVCompound());  // contour edges visibly
93
    VO = build3dCurves(shapes.OutLineVCompound());  // contours apparents visibly
94
    VI = build3dCurves(shapes.IsoLineVCompound());  // isoparamtriques   visibly
95
    H = build3dCurves(shapes.HCompound());          // hard edge       invisibly
96
    H1 = build3dCurves(shapes.Rg1LineHCompound());  // Smoth edges  invisibly
97
    HN = build3dCurves(shapes.RgNLineHCompound());  // contour edges invisibly
98
    HO = build3dCurves(shapes.OutLineHCompound());  // contours apparents invisibly
99
    HI = build3dCurves(shapes.IsoLineHCompound());  // isoparamtriques   invisibly
100
}
101

102
string ProjectionAlgos::getSVG(ExtractionType type,
103
                               double tolerance,
104
                               XmlAttributes V_style,
105
                               XmlAttributes V0_style,
106
                               XmlAttributes V1_style,
107
                               XmlAttributes H_style,
108
                               XmlAttributes H0_style,
109
                               XmlAttributes H1_style)
110
{
111
    stringstream result;
112
    SVGOutput output;
113

114
    if (!H.IsNull() && (type & WithHidden)) {
115
        H_style.insert({"stroke", "rgb(0, 0, 0)"});
116
        H_style.insert({"stroke-width", "0.15"});
117
        H_style.insert({"stroke-linecap", "butt"});
118
        H_style.insert({"stroke-linejoin", "miter"});
119
        H_style.insert({"stroke-dasharray", "0.2,0.1)"});
120
        H_style.insert({"fill", "none"});
121
        H_style.insert({"transform", "scale(1,-1)"});
122
        BRepMesh_IncrementalMesh(H, tolerance);
123
        result << "<g";
124
        for (const auto& attribute : H_style) {
125
            result << "   " << attribute.first << "=\"" << attribute.second << "\"\n";
126
        }
127
        result << "  >" << endl << output.exportEdges(H) << "</g>" << endl;
128
    }
129
    if (!HO.IsNull() && (type & WithHidden)) {
130
        H0_style.insert({"stroke", "rgb(0, 0, 0)"});
131
        H0_style.insert({"stroke-width", "0.15"});
132
        H0_style.insert({"stroke-linecap", "butt"});
133
        H0_style.insert({"stroke-linejoin", "miter"});
134
        H0_style.insert({"stroke-dasharray", "0.02,0.1)"});
135
        H0_style.insert({"fill", "none"});
136
        H0_style.insert({"transform", "scale(1,-1)"});
137
        BRepMesh_IncrementalMesh(HO, tolerance);
138
        result << "<g";
139
        for (const auto& attribute : H0_style) {
140
            result << "   " << attribute.first << "=\"" << attribute.second << "\"\n";
141
        }
142
        result << "  >" << endl << output.exportEdges(HO) << "</g>" << endl;
143
    }
144
    if (!VO.IsNull()) {
145
        V0_style.insert({"stroke", "rgb(0, 0, 0)"});
146
        V0_style.insert({"stroke-width", "1.0"});
147
        V0_style.insert({"stroke-linecap", "butt"});
148
        V0_style.insert({"stroke-linejoin", "miter"});
149
        V0_style.insert({"fill", "none"});
150
        V0_style.insert({"transform", "scale(1,-1)"});
151
        BRepMesh_IncrementalMesh(VO, tolerance);
152
        result << "<g";
153
        for (const auto& attribute : V0_style) {
154
            result << "   " << attribute.first << "=\"" << attribute.second << "\"\n";
155
        }
156
        result << "  >" << endl << output.exportEdges(VO) << "</g>" << endl;
157
    }
158
    if (!V.IsNull()) {
159
        V_style.insert({"stroke", "rgb(0, 0, 0)"});
160
        V_style.insert({"stroke-width", "1.0"});
161
        V_style.insert({"stroke-linecap", "butt"});
162
        V_style.insert({"stroke-linejoin", "miter"});
163
        V_style.insert({"fill", "none"});
164
        V_style.insert({"transform", "scale(1,-1)"});
165
        BRepMesh_IncrementalMesh(V, tolerance);
166
        result << "<g";
167
        for (const auto& attribute : V_style) {
168
            result << "   " << attribute.first << "=\"" << attribute.second << "\"\n";
169
        }
170
        result << "  >" << endl << output.exportEdges(V) << "</g>" << endl;
171
    }
172
    if (!V1.IsNull() && (type & WithSmooth)) {
173
        V1_style.insert({"stroke", "rgb(0, 0, 0)"});
174
        V1_style.insert({"stroke-width", "1.0"});
175
        V1_style.insert({"stroke-linecap", "butt"});
176
        V1_style.insert({"stroke-linejoin", "miter"});
177
        V1_style.insert({"fill", "none"});
178
        V1_style.insert({"transform", "scale(1,-1)"});
179
        BRepMesh_IncrementalMesh(V1, tolerance);
180
        result << "<g";
181
        for (const auto& attribute : V1_style) {
182
            result << "   " << attribute.first << "=\"" << attribute.second << "\"\n";
183
        }
184
        result << "  >" << endl << output.exportEdges(V1) << "</g>" << endl;
185
    }
186
    if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) {
187
        H1_style.insert({"stroke", "rgb(0, 0, 0)"});
188
        H1_style.insert({"stroke-width", "0.15"});
189
        H1_style.insert({"stroke-linecap", "butt"});
190
        H1_style.insert({"stroke-linejoin", "miter"});
191
        H1_style.insert({"stroke-dasharray", "0.09,0.05)"});
192
        H1_style.insert({"fill", "none"});
193
        H1_style.insert({"transform", "scale(1,-1)"});
194
        BRepMesh_IncrementalMesh(H1, tolerance);
195
        result << "<g";
196
        for (const auto& attribute : H1_style) {
197
            result << "   " << attribute.first << "=\"" << attribute.second << "\"\n";
198
        }
199
        result << "  >" << endl << output.exportEdges(H1) << "</g>" << endl;
200
    }
201
    return result.str();
202
}
203

204
/* dxf output section - Dan Falck 2011/09/25  */
205

206
string ProjectionAlgos::getDXF(ExtractionType type, double /*scale*/, double tolerance)
207
{
208
    stringstream result;
209
    DXFOutput output;
210

211
    if (!H.IsNull() && (type & WithHidden)) {
212
        // float width = 0.15f/scale;
213
        BRepMesh_IncrementalMesh(H, tolerance);
214
        result << output.exportEdges(H);
215
    }
216
    if (!HO.IsNull() && (type & WithHidden)) {
217
        // float width = 0.15f/scale;
218
        BRepMesh_IncrementalMesh(HO, tolerance);
219
        result << output.exportEdges(HO);
220
    }
221
    if (!VO.IsNull()) {
222
        // float width = 0.35f/scale;
223
        BRepMesh_IncrementalMesh(VO, tolerance);
224
        result << output.exportEdges(VO);
225
    }
226
    if (!V.IsNull()) {
227
        // float width = 0.35f/scale;
228
        BRepMesh_IncrementalMesh(V, tolerance);
229
        result << output.exportEdges(V);
230
    }
231
    if (!V1.IsNull() && (type & WithSmooth)) {
232
        // float width = 0.35f/scale;
233
        BRepMesh_IncrementalMesh(V1, tolerance);
234
        result << output.exportEdges(V1);
235
    }
236
    if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) {
237
        // float width = 0.15f/scale;
238
        BRepMesh_IncrementalMesh(H1, tolerance);
239
        result << output.exportEdges(H1);
240
    }
241

242
    return result.str();
243
}
244

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

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

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

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