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
***************************************************************************/
24
#include "PreCompiled.h"
31
#include <HLRBRep_Algo.hxx>
32
#include <TopoDS_Shape.hxx>
33
#include <HLRTopoBRep_OutLiner.hxx>
34
//#include <BRepAPI_MakeOutLine.hxx>
35
#include <HLRAlgo_Projector.hxx>
36
#include <HLRBRep_ShapeBounds.hxx>
37
#include <HLRBRep_HLRToShape.hxx>
41
#include <Poly_Polygon3D.hxx>
42
#include <Poly_Triangulation.hxx>
43
#include <Poly_PolygonOnTriangulation.hxx>
45
#include <TopoDS_Face.hxx>
46
#include <TopoDS_Edge.hxx>
47
#include <TopoDS_Vertex.hxx>
49
#include <TopExp_Explorer.hxx>
50
#include <TopTools_IndexedMapOfShape.hxx>
51
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
52
#include <TopTools_ListOfShape.hxx>
53
#include <TColgp_Array1OfPnt2d.hxx>
54
#include <BRep_Tool.hxx>
55
#include <BRepMesh.hxx>
58
#include <Base/Exception.h>
59
#include <Base/FileInfo.h>
60
#include <Mod/Part/App/PartFeature.h>
62
#include "ProjectionAlgos.h"
64
using namespace Drawing;
68
//===========================================================================
70
//===========================================================================
74
ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape &Input,const Base::Vector3f &Dir)
75
:Input(Input), Direction(Dir)
80
ProjectionAlgos::~ProjectionAlgos()
84
void ProjectionAlgos::execute(void)
87
Handle( HLRBRep_Algo ) brep_hlr = new HLRBRep_Algo;
88
brep_hlr->Add( Input );
90
gp_Ax2 transform(gp_Pnt(0,0,0),gp_Dir(Direction.x,Direction.y,Direction.z));
91
HLRAlgo_Projector projector( transform );
92
brep_hlr->Projector( projector );
96
// extracting the result sets:
97
HLRBRep_HLRToShape shapes( brep_hlr );
99
V = shapes.VCompound ();// hard edge visibly
100
V1 = shapes.Rg1LineVCompound();// Smoth edges visibly
101
VN = shapes.RgNLineVCompound();// contour edges visibly
102
VO = shapes.OutLineVCompound();// contours apparents visibly
103
VI = shapes.IsoLineVCompound();// isoparamtriques visibly
104
H = shapes.HCompound ();// hard edge invisibly
105
H1 = shapes.Rg1LineHCompound();// Smoth edges invisibly
106
HN = shapes.RgNLineHCompound();// contour edges invisibly
107
HO = shapes.OutLineHCompound();// contours apparents invisibly
108
HI = shapes.IsoLineHCompound();// isoparamtriques invisibly
112
std::string ProjectionAlgos::getSVG(SvgExtractionType type)
114
std::stringstream result;
117
if(!H.IsNull() && type==WithHidden){
118
BRepMesh::Mesh(H,0.1);
120
//<< " id=\"" << ViewName << "\"" << endl
121
<< " stroke=\"rgb(0, 0, 0)\"" << endl
122
<< " stroke-width=\"0.15\"" << endl
123
<< " stroke-linecap=\"butt\"" << endl
124
<< " stroke-linejoin=\"miter\"" << endl
125
<< " stroke-dasharray=\"5 3\"" << endl
126
<< " fill=\"none\"" << endl
132
BRepMesh::Mesh(V1,0.1);
134
//<< " id=\"" << ViewName << "\"" << endl
135
<< " stroke=\"rgb(0, 0, 0)\"" << endl
136
<< " stroke-width=\"0.15\"" << endl
137
<< " stroke-linecap=\"butt\"" << endl
138
<< " stroke-linejoin=\"miter\"" << endl
139
<< " fill=\"none\"" << endl
145
BRepMesh::Mesh(V,0.1);
147
//<< " id=\"" << ViewName << "\"" << endl
148
<< " stroke=\"rgb(0, 0, 0)\"" << endl
149
<< " stroke-width=\"0.35\"" << endl
150
<< " stroke-linecap=\"butt\"" << endl
151
<< " stroke-linejoin=\"miter\"" << endl
152
<< " fill=\"none\"" << endl
160
std::string ProjectionAlgos::Edges2SVG(const TopoDS_Shape &Input)
162
std::stringstream result;
164
TopExp_Explorer edges( Input, TopAbs_EDGE );
165
for (int i = 1 ; edges.More(); edges.Next(),i++ ) {
166
TopoDS_Edge edge = TopoDS::Edge( edges.Current() );
167
TopLoc_Location location;
168
Handle( Poly_Polygon3D ) polygon = BRep_Tool::Polygon3D( edge, location );
169
if ( !polygon.IsNull() ) {
170
const TColgp_Array1OfPnt& nodes = polygon->Nodes();
172
result << "<path id= \"" /*<< ViewName*/ << i << "\" d=\" ";
173
for ( int i = nodes.Lower(); i<= nodes.Upper(); i++ ){
174
result << c << " " << nodes(i).X() << " " << nodes(i).Y()<< " " ;
177
result << "\" />" << endl;