00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include <sstream>
00028 # include <BRepAdaptor_Curve.hxx>
00029 # include <Geom_Circle.hxx>
00030 # include <gp_Circ.hxx>
00031 # include <gp_Elips.hxx>
00032 #endif
00033
00034 #include <Bnd_Box.hxx>
00035 #include <BRepBndLib.hxx>
00036 #include <BRepBuilderAPI_Transform.hxx>
00037 #include <HLRBRep_Algo.hxx>
00038 #include <TopoDS_Shape.hxx>
00039 #include <HLRTopoBRep_OutLiner.hxx>
00040
00041 #include <HLRAlgo_Projector.hxx>
00042 #include <HLRBRep_ShapeBounds.hxx>
00043 #include <HLRBRep_HLRToShape.hxx>
00044 #include <gp_Ax2.hxx>
00045 #include <gp_Pnt.hxx>
00046 #include <gp_Dir.hxx>
00047 #include <gp_Vec.hxx>
00048 #include <Poly_Polygon3D.hxx>
00049 #include <Poly_Triangulation.hxx>
00050 #include <Poly_PolygonOnTriangulation.hxx>
00051 #include <TopoDS.hxx>
00052 #include <TopoDS_Face.hxx>
00053 #include <TopoDS_Edge.hxx>
00054 #include <TopoDS_Vertex.hxx>
00055 #include <TopExp.hxx>
00056 #include <TopExp_Explorer.hxx>
00057 #include <TopTools_IndexedMapOfShape.hxx>
00058 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
00059 #include <TopTools_ListOfShape.hxx>
00060 #include <TColgp_Array1OfPnt2d.hxx>
00061 #include <BRep_Tool.hxx>
00062 #include <BRepMesh.hxx>
00063
00064 #include <BRepAdaptor_CompCurve.hxx>
00065 #include <Handle_BRepAdaptor_HCompCurve.hxx>
00066 #include <Approx_Curve3d.hxx>
00067 #include <BRepAdaptor_HCurve.hxx>
00068 #include <Handle_BRepAdaptor_HCurve.hxx>
00069 #include <Geom_BSplineCurve.hxx>
00070 #include <Handle_Geom_BSplineCurve.hxx>
00071 #include <Geom_BezierCurve.hxx>
00072 #include <GeomConvert_BSplineCurveToBezierCurve.hxx>
00073 #include <GeomConvert_BSplineCurveKnotSplitting.hxx>
00074 #include <Geom2d_BSplineCurve.hxx>
00075
00076 #include <Base/Exception.h>
00077 #include <Base/FileInfo.h>
00078 #include <Base/Tools.h>
00079 #include <Mod/Part/App/PartFeature.h>
00080
00081 #include "ProjectionAlgos.h"
00082 #include "DrawingExport.h"
00083
00084 using namespace Drawing;
00085 using namespace std;
00086
00087
00088
00089
00090
00091
00092
00093 ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape &Input, const Base::Vector3f &Dir)
00094 : Input(Input), Direction(Dir)
00095 {
00096 execute();
00097 }
00098
00099 ProjectionAlgos::~ProjectionAlgos()
00100 {
00101 }
00102
00103 TopoDS_Shape ProjectionAlgos::invertY(const TopoDS_Shape& shape)
00104 {
00105
00106 gp_Trsf mat;
00107 Bnd_Box bounds;
00108 BRepBndLib::Add(shape, bounds);
00109 bounds.SetGap(0.0);
00110 Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
00111 bounds.Get(xMin, yMin, zMin, xMax, yMax, zMax);
00112 mat.SetMirror(gp_Ax2(gp_Pnt((xMin+xMax)/2,(yMin+yMax)/2,(zMin+zMax)/2), gp_Dir(0,1,0)));
00113 BRepBuilderAPI_Transform mkTrf(shape, mat);
00114 return mkTrf.Shape();
00115 }
00116
00117 void ProjectionAlgos::execute(void)
00118 {
00119 Handle( HLRBRep_Algo ) brep_hlr = new HLRBRep_Algo;
00120 brep_hlr->Add(Input);
00121
00122 try {
00123 #if defined(__GNUC__) && defined (FC_OS_LINUX)
00124 Base::SignalException se;
00125 #endif
00126 gp_Ax2 transform(gp_Pnt(0,0,0),gp_Dir(Direction.x,Direction.y,Direction.z));
00127 HLRAlgo_Projector projector( transform );
00128 brep_hlr->Projector(projector);
00129 brep_hlr->Update();
00130 brep_hlr->Hide();
00131 }
00132 catch (...) {
00133 Standard_Failure::Raise("Fatal error occurred while projecting shape");
00134 }
00135
00136
00137 HLRBRep_HLRToShape shapes( brep_hlr );
00138
00139 V = shapes.VCompound ();
00140 V1 = shapes.Rg1LineVCompound();
00141 VN = shapes.RgNLineVCompound();
00142 VO = shapes.OutLineVCompound();
00143 VI = shapes.IsoLineVCompound();
00144 H = shapes.HCompound ();
00145 H1 = shapes.Rg1LineHCompound();
00146 HN = shapes.RgNLineHCompound();
00147 HO = shapes.OutLineHCompound();
00148 HI = shapes.IsoLineHCompound();
00149
00150 }
00151
00152 std::string ProjectionAlgos::getSVG(SvgExtractionType type, float scale)
00153 {
00154 std::stringstream result;
00155 SVGOutput output;
00156 if (!H.IsNull() && (type & WithHidden)) {
00157 float width = 0.15f/scale;
00158 BRepMesh::Mesh(H,0.1);
00159 result << "<g"
00160
00161 << " stroke=\"rgb(0, 0, 0)\"" << endl
00162 << " stroke-width=\"" << width << "\"" << endl
00163 << " stroke-linecap=\"butt\"" << endl
00164 << " stroke-linejoin=\"miter\"" << endl
00165 << " stroke-dasharray=\"5 3\"" << endl
00166 << " fill=\"none\"" << endl
00167 << " >" << endl
00168 << output.exportEdges(H)
00169 << "</g>" << endl;
00170 }
00171 if (!HO.IsNull() && (type & WithHidden)) {
00172 float width = 0.15f/scale;
00173 BRepMesh::Mesh(HO,0.1);
00174 result << "<g"
00175
00176 << " stroke=\"rgb(0, 0, 0)\"" << endl
00177 << " stroke-width=\"" << width << "\"" << endl
00178 << " stroke-linecap=\"butt\"" << endl
00179 << " stroke-linejoin=\"miter\"" << endl
00180 << " stroke-dasharray=\"5 3\"" << endl
00181 << " fill=\"none\"" << endl
00182 << " >" << endl
00183 << output.exportEdges(HO)
00184 << "</g>" << endl;
00185 }
00186 if (!VO.IsNull()) {
00187 float width = 0.35f/scale;
00188 BRepMesh::Mesh(VO,0.1);
00189 result << "<g"
00190
00191 << " stroke=\"rgb(0, 0, 0)\"" << endl
00192 << " stroke-width=\"" << width << "\"" << endl
00193 << " stroke-linecap=\"butt\"" << endl
00194 << " stroke-linejoin=\"miter\"" << endl
00195 << " fill=\"none\"" << endl
00196 << " >" << endl
00197 << output.exportEdges(VO)
00198 << "</g>" << endl;
00199 }
00200 if (!V.IsNull()) {
00201 float width = 0.35f/scale;
00202 BRepMesh::Mesh(V,0.1);
00203 result << "<g"
00204
00205 << " stroke=\"rgb(0, 0, 0)\"" << endl
00206 << " stroke-width=\"" << width << "\"" << endl
00207 << " stroke-linecap=\"butt\"" << endl
00208 << " stroke-linejoin=\"miter\"" << endl
00209 << " fill=\"none\"" << endl
00210 << " >" << endl
00211 << output.exportEdges(V)
00212 << "</g>" << endl;
00213 }
00214 if (!V1.IsNull() && (type & WithSmooth)) {
00215 float width = 0.35f/scale;
00216 BRepMesh::Mesh(V1,0.1);
00217 result << "<g"
00218
00219 << " stroke=\"rgb(0, 0, 0)\"" << endl
00220 << " stroke-width=\"" << width << "\"" << endl
00221 << " stroke-linecap=\"butt\"" << endl
00222 << " stroke-linejoin=\"miter\"" << endl
00223 << " fill=\"none\"" << endl
00224 << " >" << endl
00225 << output.exportEdges(V1)
00226 << "</g>" << endl;
00227 }
00228 if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) {
00229 float width = 0.15f/scale;
00230 BRepMesh::Mesh(H1,0.1);
00231 result << "<g"
00232
00233 << " stroke=\"rgb(0, 0, 0)\"" << endl
00234 << " stroke-width=\"" << width << "\"" << endl
00235 << " stroke-linecap=\"butt\"" << endl
00236 << " stroke-linejoin=\"miter\"" << endl
00237 << " stroke-dasharray=\"5 3\"" << endl
00238 << " fill=\"none\"" << endl
00239 << " >" << endl
00240 << output.exportEdges(H1)
00241 << "</g>" << endl;
00242 }
00243
00244
00245
00246
00247 return result.str();
00248 }
00249
00250
00251
00252 std::string ProjectionAlgos::getDXF(SvgExtractionType type, float scale)
00253 {
00254 std::stringstream result;
00255 DXFOutput output;
00256
00257 result << "0" << endl
00258 << "SECTION" << endl
00259
00260 << "2" << endl
00261 << "ENTITIES" << endl;
00262
00263 if (!H.IsNull() && (type & WithHidden)) {
00264 float width = 0.15f/scale;
00265 BRepMesh::Mesh(H,0.1);
00266 result
00267
00268
00269
00270
00271
00272
00273
00274
00275 << output.exportEdges(H);
00276
00277 }
00278 if (!HO.IsNull() && (type & WithHidden)) {
00279 float width = 0.15f/scale;
00280 BRepMesh::Mesh(HO,0.1);
00281 result
00282
00283
00284
00285
00286
00287
00288
00289
00290 << output.exportEdges(HO);
00291
00292 }
00293 if (!VO.IsNull()) {
00294 float width = 0.35f/scale;
00295 BRepMesh::Mesh(VO,0.1);
00296 result
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 << output.exportEdges(VO);
00307
00308 }
00309 if (!V.IsNull()) {
00310 float width = 0.35f/scale;
00311
00312 BRepMesh::Mesh(V,0.1);
00313 result
00314
00315
00316
00317
00318
00319
00320
00321
00322 << output.exportEdges(V);
00323
00324
00325 }
00326 if (!V1.IsNull() && (type & WithSmooth)) {
00327 float width = 0.35f/scale;
00328 BRepMesh::Mesh(V1,0.1);
00329 result
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 << output.exportEdges(V1);
00340
00341 }
00342 if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) {
00343
00344 float width = 0.15f/scale;
00345 BRepMesh::Mesh(H1,0.1);
00346 result
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 << output.exportEdges(H1);
00358
00359 }
00360
00361
00362 result << 0 << endl
00363 << "ENDSEC" << endl
00364 << 0 << endl
00365 << "EOF";
00366
00367 return result.str();
00368 }