/*************************************************************************** * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ # include # include # include # include # include #endif #include #include #include #include #include #include //#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ProjectionAlgos.h" #include "DrawingExport.h" using namespace Drawing; using namespace std; //=========================================================================== // ProjectionAlgos //=========================================================================== ProjectionAlgos::ProjectionAlgos(const TopoDS_Shape &Input, const Base::Vector3f &Dir) : Input(Input), Direction(Dir) { execute(); } ProjectionAlgos::~ProjectionAlgos() { } TopoDS_Shape ProjectionAlgos::invertY(const TopoDS_Shape& shape) { // make sure to have the y coordinates inverted gp_Trsf mat; Bnd_Box bounds; BRepBndLib::Add(shape, bounds); bounds.SetGap(0.0); Standard_Real xMin, yMin, zMin, xMax, yMax, zMax; bounds.Get(xMin, yMin, zMin, xMax, yMax, zMax); mat.SetMirror(gp_Ax2(gp_Pnt((xMin+xMax)/2,(yMin+yMax)/2,(zMin+zMax)/2), gp_Dir(0,1,0))); BRepBuilderAPI_Transform mkTrf(shape, mat); return mkTrf.Shape(); } void ProjectionAlgos::execute(void) { Handle( HLRBRep_Algo ) brep_hlr = new HLRBRep_Algo; brep_hlr->Add(Input); try { #if defined(__GNUC__) && defined (FC_OS_LINUX) Base::SignalException se; #endif gp_Ax2 transform(gp_Pnt(0,0,0),gp_Dir(Direction.x,Direction.y,Direction.z)); HLRAlgo_Projector projector( transform ); brep_hlr->Projector(projector); brep_hlr->Update(); brep_hlr->Hide(); } catch (...) { Standard_Failure::Raise("Fatal error occurred while projecting shape"); } // extracting the result sets: HLRBRep_HLRToShape shapes( brep_hlr ); V = shapes.VCompound ();// hard edge visibly V1 = shapes.Rg1LineVCompound();// Smoth edges visibly VN = shapes.RgNLineVCompound();// contour edges visibly VO = shapes.OutLineVCompound();// contours apparents visibly VI = shapes.IsoLineVCompound();// isoparamtriques visibly H = shapes.HCompound ();// hard edge invisibly H1 = shapes.Rg1LineHCompound();// Smoth edges invisibly HN = shapes.RgNLineHCompound();// contour edges invisibly HO = shapes.OutLineHCompound();// contours apparents invisibly HI = shapes.IsoLineHCompound();// isoparamtriques invisibly } std::string ProjectionAlgos::getSVG(ExtractionType type, float scale, float tolerance) { std::stringstream result; SVGOutput output; float hfactor = 0.5f; // hidden line size factor, was 0.15f / 0.35f; if (!H.IsNull() && (type & WithHidden)) { float width = hfactor * scale; BRepMesh::Mesh(H,tolerance); result << "" << endl << output.exportEdges(H) << "" << endl; } if (!HO.IsNull() && (type & WithHidden)) { float width = hfactor * scale; BRepMesh::Mesh(HO,tolerance); result << "" << endl << output.exportEdges(HO) << "" << endl; } if (!VO.IsNull()) { float width = scale; BRepMesh::Mesh(VO,tolerance); result << "" << endl << output.exportEdges(VO) << "" << endl; } if (!V.IsNull()) { float width = scale; BRepMesh::Mesh(V,tolerance); result << "" << endl << output.exportEdges(V) << "" << endl; } if (!V1.IsNull() && (type & WithSmooth)) { float width = scale; BRepMesh::Mesh(V1,tolerance); result << "" << endl << output.exportEdges(V1) << "" << endl; } if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) { float width = hfactor * scale; BRepMesh::Mesh(H1,tolerance); result << "" << endl << output.exportEdges(H1) << "" << endl; } /*result << "0" << endl << "SECTION" << endl << "2" << endl << "ENTITIES" << endl;*/ return result.str(); } /* dxf output section - Dan Falck 2011/09/25 */ std::string ProjectionAlgos::getDXF(ExtractionType type, float scale, float tolerance) { std::stringstream result; DXFOutput output; result << "0" << endl << "SECTION" << endl << "2" << endl << "ENTITIES" << endl; if (!H.IsNull() && (type & WithHidden)) { //float width = 0.15f/scale; BRepMesh::Mesh(H,tolerance); result //<< "" << endl*/ << output.exportEdges(H); //<< "" << endl; } if (!HO.IsNull() && (type & WithHidden)) { //float width = 0.15f/scale; BRepMesh::Mesh(HO,tolerance); result //<< "" << endl*/ << output.exportEdges(HO); //<< "" << endl; } if (!VO.IsNull()) { //float width = 0.35f/scale; BRepMesh::Mesh(VO,tolerance); result //<< "" << endl*/ << output.exportEdges(VO); //<< "" << endl; } if (!V.IsNull()) { //float width = 0.35f/scale; BRepMesh::Mesh(V,tolerance); result //<< "" << endl*/ << output.exportEdges(V); //<< "" << endl; } if (!V1.IsNull() && (type & WithSmooth)) { //float width = 0.35f/scale; BRepMesh::Mesh(V1,tolerance); result //<< "" << endl*/ << output.exportEdges(V1); //<< "" << endl; } if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) { //float width = 0.15f/scale; BRepMesh::Mesh(H1,tolerance); result //<< "" << endl*/ << output.exportEdges(H1); //<< "" << endl; } result << 0 << endl << "ENDSEC" << endl << 0 << endl << "EOF"; return result.str(); }