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 XCAFDoc_ColorTool; 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 {} 66 67 /** 68 * Add one shape to the internal list, may be called several times with 69 * different shapes. 70 */ 71 Standard_EXPORT void AddShape (const TopoDS_Shape& theShape, 72 const char * theName = 0L); 73 74 /** 75 * Convert all accumulated shapes and store them in myScene. 76 * The internal data structures are cleared in the end of convertion. 77 * @param theExtractFaces 78 * If True, converter extracst faces from the shapes. 79 * @param theExtractEdges 80 * If True, converter extracts edges from the shapes. 81 * @param theDeflection 82 * Deflection for tessellation of geometrical lines/surfaces. Existing mesh 83 * is used if its deflection is smaller than the one given by this 84 * parameter. 85 * @param theDeflAngle 86 * Angular deflection for tessellation of geometrical lines. 87 */ 88 Standard_EXPORT void Convert (const Standard_Boolean theExtractFaces, 89 const Standard_Boolean theExtractEdges, 90 const Standard_Real theDeflection = 0.01, 91 const Standard_Real theDeflAngle = 20.*M_PI/180.); 92 //this value of theDeflAngle is used by default 93 //for tesselation while shading (Drawer->HLRAngle()) 94 95 /** 96 * Add all shapes start from given document with colors and names to the internal structure 97 */ 98 Standard_EXPORT void ConvertDocument(const Handle(TDocStd_Document)& theDoc); 99 100 protected: 101 // ---------- PROTECTED METHODS ---------- 102 103 Handle(VrmlData_Geometry) triToIndexedFaceSet 104 (const Handle(Poly_Triangulation)&, 105 const TopoDS_Face&, 106 const Handle(VrmlData_Coordinate)&); 107 108 Handle(VrmlData_Geometry) polToIndexedLineSet 109 (const Handle(Poly_Polygon3D)&); 110 111 Handle(VrmlData_Appearance) defaultMaterialFace () const; 112 113 Handle(VrmlData_Appearance) defaultMaterialEdge () const; 114 115 Handle(VrmlData_Geometry) makeTShapeNode(const TopoDS_Shape& theShape, 116 const TopAbs_ShapeEnum theShapeType, 117 TopLoc_Location& theLoc); 118 119 void addAssembly (const Handle(VrmlData_Group)& theParent, 120 const TDF_Label& theLabel, 121 const Handle(TDocStd_Document)& theDoc, 122 const Standard_Boolean theNeedCreateGroup); 123 124 void addInstance (const Handle(VrmlData_Group)& theParent, 125 const TDF_Label& theLabel, 126 const Handle(TDocStd_Document)& theDoc); 127 128 void addShape (const Handle(VrmlData_Group)& theParent, 129 const TDF_Label& theLabel, 130 const Handle(TDocStd_Document)& theDoc); 131 132 Handle(VrmlData_Appearance) makeMaterialFromColor(const TDF_Label& theColorL, 133 const Handle(XCAFDoc_ColorTool)& theColorTool) const; 134 135 136 private: 137 // ---------- PRIVATE FIELDS ---------- 138 139 VrmlData_Scene& myScene; 140 Standard_Real myScale; 141 NCollection_List <ShapeData> myShapes; 142 143 Standard_Real myDeflection; 144 Standard_Real myDeflAngle; 145 NCollection_DataMap <TopoDS_Shape, Handle(VrmlData_Geometry)> myRelMap; 146 147 // ---------- PRIVATE METHODS ---------- 148 void operator= (const VrmlData_ShapeConvert&); 149 }; 150 151 #endif 152