1 // Created on: 2007-08-04 2 // Created by: Alexander GRIGORIEV 3 // Copyright (c) 2007-2014 OPEN CASCADE SAS 4 // 5 // This file is part of Open CASCADE Technology software library. 6 // 7 // This library is free software; you can redistribute it and/or modify it under 8 // the terms of the GNU Lesser General Public License version 2.1 as published 9 // by the Free Software Foundation, with special exception defined in the file 10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 11 // distribution for complete text of the license and disclaimer of any warranty. 12 // 13 // Alternatively, this file may be used under the terms of Open CASCADE 14 // commercial license or contractual agreement. 15 16 #ifndef VrmlData_ShapeConvert_HeaderFile 17 #define VrmlData_ShapeConvert_HeaderFile 18 19 #include <VrmlData_Geometry.hxx> 20 #include <VrmlData_Appearance.hxx> 21 #include <VrmlData_Group.hxx> 22 #include <NCollection_List.hxx> 23 #include <NCollection_DataMap.hxx> 24 #include <TopoDS_Shape.hxx> 25 26 class VrmlData_Scene; 27 class VrmlData_Coordinate; 28 class TopoDS_Face; 29 class Poly_Polygon3D; 30 class Poly_Triangulation; 31 class XCAFPrs_Style; 32 class TDocStd_Document; 33 class TDF_Label; 34 35 36 /** 37 * Algorithm converting one shape or a set of shapes to VrmlData_Scene. 38 */ 39 40 class VrmlData_ShapeConvert 41 { 42 public: 43 44 typedef struct { 45 TCollection_AsciiString Name; 46 TopoDS_Shape Shape; 47 Handle(VrmlData_Node) Node; 48 } ShapeData; 49 50 // ---------- PUBLIC METHODS ---------- 51 52 53 /** 54 * Constructor. 55 * @param theScene 56 * Scene receiving all Vrml data. 57 * @param theScale 58 * Scale factor, considering that VRML standard specifies coordinates in 59 * meters. So if your data are in mm, you should provide theScale=0.001 60 */ VrmlData_ShapeConvert(VrmlData_Scene & theScene,const Standard_Real theScale=1.)61 inline VrmlData_ShapeConvert (VrmlData_Scene& theScene, 62 const Standard_Real theScale = 1.) 63 : myScene (theScene), 64 myScale (theScale), 65 myDeflection(0.0), 66 myDeflAngle(0.0) 67 {} 68 69 /** 70 * Add one shape to the internal list, may be called several times with 71 * different shapes. 72 */ 73 Standard_EXPORT void AddShape (const TopoDS_Shape& theShape, 74 const char * theName = 0L); 75 76 /** 77 * Convert all accumulated shapes and store them in myScene. 78 * The internal data structures are cleared in the end of conversion. 79 * @param theExtractFaces 80 * If True, converter extracst faces from the shapes. 81 * @param theExtractEdges 82 * If True, converter extracts edges from the shapes. 83 * @param theDeflection 84 * Deflection for tessellation of geometrical lines/surfaces. Existing mesh 85 * is used if its deflection is smaller than the one given by this 86 * parameter. 87 * @param theDeflAngle 88 * Angular deflection for tessellation of geometrical lines. 89 */ 90 Standard_EXPORT void Convert (const Standard_Boolean theExtractFaces, 91 const Standard_Boolean theExtractEdges, 92 const Standard_Real theDeflection = 0.01, 93 const Standard_Real theDeflAngle = 20.*M_PI/180.); 94 //this value of theDeflAngle is used by default 95 //for tesselation while shading (Drawer->HLRAngle()) 96 97 /** 98 * Add all shapes start from given document with colors and names to the internal structure 99 */ 100 Standard_EXPORT void ConvertDocument(const Handle(TDocStd_Document)& theDoc); 101 102 protected: 103 // ---------- PROTECTED METHODS ---------- 104 105 Handle(VrmlData_Geometry) triToIndexedFaceSet 106 (const Handle(Poly_Triangulation)&, 107 const TopoDS_Face&, 108 const Handle(VrmlData_Coordinate)&); 109 110 Handle(VrmlData_Geometry) polToIndexedLineSet 111 (const Handle(Poly_Polygon3D)&); 112 113 Handle(VrmlData_Appearance) defaultMaterialFace () const; 114 115 Handle(VrmlData_Appearance) defaultMaterialEdge () const; 116 117 Handle(VrmlData_Geometry) makeTShapeNode(const TopoDS_Shape& theShape, 118 const TopAbs_ShapeEnum theShapeType, 119 TopLoc_Location& theLoc); 120 121 void addAssembly (const Handle(VrmlData_Group)& theParent, 122 const TDF_Label& theLabel, 123 const Handle(TDocStd_Document)& theDoc, 124 const Standard_Boolean theNeedCreateGroup); 125 126 void addInstance (const Handle(VrmlData_Group)& theParent, 127 const TDF_Label& theLabel, 128 const Handle(TDocStd_Document)& theDoc); 129 130 void addShape (const Handle(VrmlData_Group)& theParent, 131 const TDF_Label& theLabel, 132 const Handle(TDocStd_Document)& theDoc); 133 134 Handle(VrmlData_Appearance) makeMaterialFromStyle (const XCAFPrs_Style& theStyle, 135 const TDF_Label& theAttribLab) const; 136 137 private: 138 // ---------- PRIVATE FIELDS ---------- 139 140 VrmlData_Scene& myScene; 141 Standard_Real myScale; 142 NCollection_List <ShapeData> myShapes; 143 144 Standard_Real myDeflection; 145 Standard_Real myDeflAngle; 146 NCollection_DataMap <TopoDS_Shape, Handle(VrmlData_Geometry)> myRelMap; 147 148 // ---------- PRIVATE METHODS ---------- 149 void operator= (const VrmlData_ShapeConvert&); 150 }; 151 152 #endif 153