~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Drawing/App/ProjectionAlgos.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2010-01-11 08:48:33 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100111084833-4g9vgdqbkw8u34zb
Tags: 0.9.2646.5-1
* New upstream version (closes: #561696).
* Added swig to Build-Depends (closes: #563523, #563772).
* Removed python-opencv from Build-Depends and Recommends (closes: #560768).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
24
#include "PreCompiled.h"
 
25
 
 
26
#ifndef _PreComp_
 
27
# include <sstream>
 
28
#endif
 
29
 
 
30
 
 
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>
 
38
#include <gp_Ax2.hxx>
 
39
#include <gp_Pnt.hxx>
 
40
#include <gp_Dir.hxx>
 
41
#include <Poly_Polygon3D.hxx>
 
42
#include <Poly_Triangulation.hxx>
 
43
#include <Poly_PolygonOnTriangulation.hxx>
 
44
#include <TopoDS.hxx>
 
45
#include <TopoDS_Face.hxx>
 
46
#include <TopoDS_Edge.hxx>
 
47
#include <TopoDS_Vertex.hxx>
 
48
#include <TopExp.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>
 
56
 
 
57
 
 
58
#include <Base/Exception.h>
 
59
#include <Base/FileInfo.h>
 
60
#include <Mod/Part/App/PartFeature.h>
 
61
 
 
62
#include "ProjectionAlgos.h"
 
63
 
 
64
using namespace Drawing;
 
65
using namespace std;
 
66
 
 
67
 
 
68
//===========================================================================
 
69
// FeatureView
 
70
//===========================================================================
 
71
 
 
72
 
 
73
 
 
74
ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape &Input,const Base::Vector3f &Dir) 
 
75
:Input(Input), Direction(Dir)
 
76
{
 
77
        execute();
 
78
}
 
79
 
 
80
ProjectionAlgos::~ProjectionAlgos()
 
81
{
 
82
}
 
83
 
 
84
void ProjectionAlgos::execute(void)
 
85
{
 
86
 
 
87
    Handle( HLRBRep_Algo ) brep_hlr = new HLRBRep_Algo;
 
88
    brep_hlr->Add( Input );
 
89
 
 
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 );
 
93
    brep_hlr->Update();
 
94
    brep_hlr->Hide();
 
95
 
 
96
    // extracting the result sets:
 
97
    HLRBRep_HLRToShape shapes( brep_hlr );
 
98
 
 
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
 
109
 
 
110
}
 
111
 
 
112
std::string  ProjectionAlgos::getSVG(SvgExtractionType type)
 
113
{
 
114
        std::stringstream result;
 
115
 
 
116
 
 
117
        if(!H.IsNull() && type==WithHidden){
 
118
                        BRepMesh::Mesh(H,0.1);
 
119
                        result  << "<g" 
 
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
 
127
                                        << "  >" << endl
 
128
                                        << Edges2SVG(H)
 
129
                                        << "</g>" << endl;
 
130
        }
 
131
        if(!V1.IsNull()){
 
132
                        BRepMesh::Mesh(V1,0.1);
 
133
                        result  << "<g" 
 
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
 
140
                                        << "  >" << endl
 
141
                                        << Edges2SVG(V1)
 
142
                                        << "</g>" << endl;
 
143
        }
 
144
        if(!V.IsNull()){
 
145
                        BRepMesh::Mesh(V,0.1);
 
146
                        result  << "<g" 
 
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
 
153
                                        << "  >" << endl
 
154
                                        << Edges2SVG(V)
 
155
                                        << "</g>" << endl;
 
156
        }
 
157
        return result.str();
 
158
}
 
159
 
 
160
std::string ProjectionAlgos::Edges2SVG(const TopoDS_Shape &Input)
 
161
{
 
162
        std::stringstream result;
 
163
 
 
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();
 
171
         char c = 'M';
 
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()<< " " ; 
 
175
            c = 'L';
 
176
        }
 
177
        result << "\" />" << endl;
 
178
      }
 
179
    }
 
180
        return result.str();
 
181
}
 
182
 
 
183