1
/***************************************************************************
2
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
23
#include "PreCompiled.h"
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>
34
#include <TopoDS_Shape.hxx>
40
#include <Base/Exception.h>
42
#include "DrawingExport.h"
43
#include "ProjectionAlgos.h"
46
using namespace Drawing;
49
//===========================================================================
51
//===========================================================================
54
ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape& Input, const Base::Vector3d& Dir)
61
ProjectionAlgos::~ProjectionAlgos()
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)
70
for (it.Init(shape, TopAbs_EDGE); it.More(); it.Next()) {
71
BRepLib::BuildCurve3d(TopoDS::Edge(it.Current()));
76
void ProjectionAlgos::execute(void)
78
Handle(HLRBRep_Algo) brep_hlr = new HLRBRep_Algo;
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);
87
// extracting the result sets:
88
HLRBRep_HLRToShape shapes(brep_hlr);
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
102
string ProjectionAlgos::getSVG(ExtractionType type,
104
XmlAttributes V_style,
105
XmlAttributes V0_style,
106
XmlAttributes V1_style,
107
XmlAttributes H_style,
108
XmlAttributes H0_style,
109
XmlAttributes H1_style)
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);
124
for (const auto& attribute : H_style) {
125
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
127
result << " >" << endl << output.exportEdges(H) << "</g>" << endl;
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);
139
for (const auto& attribute : H0_style) {
140
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
142
result << " >" << endl << output.exportEdges(HO) << "</g>" << endl;
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);
153
for (const auto& attribute : V0_style) {
154
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
156
result << " >" << endl << output.exportEdges(VO) << "</g>" << endl;
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);
167
for (const auto& attribute : V_style) {
168
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
170
result << " >" << endl << output.exportEdges(V) << "</g>" << endl;
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);
181
for (const auto& attribute : V1_style) {
182
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
184
result << " >" << endl << output.exportEdges(V1) << "</g>" << endl;
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);
196
for (const auto& attribute : H1_style) {
197
result << " " << attribute.first << "=\"" << attribute.second << "\"\n";
199
result << " >" << endl << output.exportEdges(H1) << "</g>" << endl;
204
/* dxf output section - Dan Falck 2011/09/25 */
206
string ProjectionAlgos::getDXF(ExtractionType type, double /*scale*/, double tolerance)
211
if (!H.IsNull() && (type & WithHidden)) {
212
// float width = 0.15f/scale;
213
BRepMesh_IncrementalMesh(H, tolerance);
214
result << output.exportEdges(H);
216
if (!HO.IsNull() && (type & WithHidden)) {
217
// float width = 0.15f/scale;
218
BRepMesh_IncrementalMesh(HO, tolerance);
219
result << output.exportEdges(HO);
222
// float width = 0.35f/scale;
223
BRepMesh_IncrementalMesh(VO, tolerance);
224
result << output.exportEdges(VO);
227
// float width = 0.35f/scale;
228
BRepMesh_IncrementalMesh(V, tolerance);
229
result << output.exportEdges(V);
231
if (!V1.IsNull() && (type & WithSmooth)) {
232
// float width = 0.35f/scale;
233
BRepMesh_IncrementalMesh(V1, tolerance);
234
result << output.exportEdges(V1);
236
if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) {
237
// float width = 0.15f/scale;
238
BRepMesh_IncrementalMesh(H1, tolerance);
239
result << output.exportEdges(H1);