1 // Created on: 2000-08-15 2 // Created by: Andrey BETENEV 3 // Copyright (c) 2000-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 _STEPCAFControl_Reader_HeaderFile 17 #define _STEPCAFControl_Reader_HeaderFile 18 19 #include <Resource_FormatType.hxx> 20 #include <STEPControl_Reader.hxx> 21 #include <IFSelect_ReturnStatus.hxx> 22 #include <TDF_LabelSequence.hxx> 23 #include <TopTools_MapOfShape.hxx> 24 #include <STEPCAFControl_DataMapOfShapePD.hxx> 25 #include <STEPCAFControl_DataMapOfPDExternFile.hxx> 26 #include <XCAFDoc_DataMapOfShapeLabel.hxx> 27 #include <TColStd_HSequenceOfTransient.hxx> 28 #include <XCAFDimTolObjects_DatumModifiersSequence.hxx> 29 #include <XCAFDimTolObjects_DatumModifWithValue.hxx> 30 31 class XSControl_WorkSession; 32 class TDocStd_Document; 33 class TCollection_AsciiString; 34 class STEPCAFControl_ExternFile; 35 class STEPControl_Reader; 36 class TDF_Label; 37 class TopoDS_Shape; 38 class XCAFDoc_ShapeTool; 39 class StepRepr_RepresentationItem; 40 class Transfer_TransientProcess; 41 class StepShape_ConnectedFaceSet; 42 class StepRepr_NextAssemblyUsageOccurrence; 43 class STEPConstruct_Tool; 44 class StepDimTol_Datum; 45 46 47 //! Provides a tool to read STEP file and put it into 48 //! DECAF document. Besides transfer of shapes (including 49 //! assemblies) provided by STEPControl, supports also 50 //! colors and part names 51 //! 52 //! This reader supports reading files with external references 53 //! i.e. multifile reading 54 //! It behaves as usual Reader (from STEPControl) for the main 55 //! file (e.g. if it is single file) 56 //! Results of reading other files can be accessed by name of the 57 //! file or by iterating on a readers 58 class STEPCAFControl_Reader 59 { 60 public: 61 62 DEFINE_STANDARD_ALLOC 63 64 65 //! Creates a reader with an empty 66 //! STEP model and sets ColorMode, LayerMode, NameMode and 67 //! PropsMode to Standard_True. 68 Standard_EXPORT STEPCAFControl_Reader(); 69 70 //! Creates a reader tool and attaches it to an already existing Session 71 //! Clears the session if it was not yet set for STEP 72 Standard_EXPORT STEPCAFControl_Reader(const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True); 73 74 //! Destructor. 75 Standard_EXPORT virtual ~STEPCAFControl_Reader(); 76 77 //! Clears the internal data structures and attaches to a new session 78 //! Clears the session if it was not yet set for STEP 79 Standard_EXPORT void Init (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True); 80 81 //! Loads a file and returns the read status 82 //! Provided for use like single-file reader 83 Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename); 84 85 //! Returns number of roots recognized for transfer 86 //! Shortcut for Reader().NbRootsForTransfer() 87 Standard_EXPORT Standard_Integer NbRootsForTransfer(); 88 89 //! Translates currently loaded STEP file into the document 90 //! Returns True if succeeded, and False in case of fail 91 //! Provided for use like single-file reader 92 Standard_EXPORT Standard_Boolean TransferOneRoot (const Standard_Integer num, 93 Handle(TDocStd_Document)& doc, 94 const Message_ProgressRange& theProgress = Message_ProgressRange()); 95 96 //! Translates currently loaded STEP file into the document 97 //! Returns True if succeeded, and False in case of fail 98 //! Provided for use like single-file reader 99 Standard_EXPORT Standard_Boolean Transfer (Handle(TDocStd_Document)& doc, 100 const Message_ProgressRange& theProgress = Message_ProgressRange()); 101 102 Standard_EXPORT Standard_Boolean Perform (const TCollection_AsciiString& filename, 103 Handle(TDocStd_Document)& doc, 104 const Message_ProgressRange& theProgress = Message_ProgressRange()); 105 106 //! Translate STEP file given by filename into the document 107 //! Return True if succeeded, and False in case of fail 108 Standard_EXPORT Standard_Boolean Perform (const Standard_CString filename, 109 Handle(TDocStd_Document)& doc, 110 const Message_ProgressRange& theProgress = Message_ProgressRange()); 111 112 //! Returns data on external files 113 //! Returns Null handle if no external files are read 114 Standard_EXPORT const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> & ExternFiles() const; 115 116 //! Returns data on external file by its name 117 //! Returns False if no external file with given name is read 118 Standard_EXPORT Standard_Boolean ExternFile (const Standard_CString name, Handle(STEPCAFControl_ExternFile)& ef) const; 119 120 //! Returns basic reader 121 Standard_EXPORT STEPControl_Reader& ChangeReader(); 122 123 //! Returns basic reader as const 124 Standard_EXPORT const STEPControl_Reader& Reader() const; 125 126 //! Returns label of instance of an assembly component 127 //! corresponding to a given NAUO 128 Standard_EXPORT static TDF_Label FindInstance 129 (const Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO, 130 const Handle(XCAFDoc_ShapeTool)& STool, 131 const STEPConstruct_Tool& Tool, 132 const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap); 133 134 //! Set ColorMode for indicate read Colors or not. 135 Standard_EXPORT void SetColorMode (const Standard_Boolean colormode); 136 137 Standard_EXPORT Standard_Boolean GetColorMode() const; 138 139 //! Set NameMode for indicate read Name or not. 140 Standard_EXPORT void SetNameMode (const Standard_Boolean namemode); 141 142 Standard_EXPORT Standard_Boolean GetNameMode() const; 143 144 //! Set LayerMode for indicate read Layers or not. 145 Standard_EXPORT void SetLayerMode (const Standard_Boolean layermode); 146 147 Standard_EXPORT Standard_Boolean GetLayerMode() const; 148 149 //! PropsMode for indicate read Validation properties or not. 150 Standard_EXPORT void SetPropsMode (const Standard_Boolean propsmode); 151 152 Standard_EXPORT Standard_Boolean GetPropsMode() const; 153 154 //! Set SHUO mode for indicate write SHUO or not. 155 Standard_EXPORT void SetSHUOMode (const Standard_Boolean shuomode); 156 157 Standard_EXPORT Standard_Boolean GetSHUOMode() const; 158 159 //! Set GDT mode for indicate write GDT or not. 160 Standard_EXPORT void SetGDTMode (const Standard_Boolean gdtmode); 161 162 Standard_EXPORT Standard_Boolean GetGDTMode() const; 163 164 //! Set Material mode 165 Standard_EXPORT void SetMatMode (const Standard_Boolean matmode); 166 167 Standard_EXPORT Standard_Boolean GetMatMode() const; 168 169 //! Set View mode 170 Standard_EXPORT void SetViewMode(const Standard_Boolean viewmode); 171 172 //! Get View mode 173 Standard_EXPORT Standard_Boolean GetViewMode() const; 174 GetShapeLabelMap() const175 const XCAFDoc_DataMapOfShapeLabel& GetShapeLabelMap() const { return myMap; } 176 177 protected: 178 179 180 //! Translates STEP file already loaded into the reader 181 //! into the document 182 //! If num==0, translates all roots, else only root number num 183 //! Returns True if succeeded, and False in case of fail 184 //! If asOne is True, in case of multiple results composes 185 //! them into assembly. Fills sequence of produced labels 186 Standard_EXPORT Standard_Boolean Transfer (STEPControl_Reader& rd, 187 const Standard_Integer num, 188 Handle(TDocStd_Document)& doc, 189 TDF_LabelSequence& Lseq, 190 const Standard_Boolean asOne = Standard_False, 191 const Message_ProgressRange& theProgress = Message_ProgressRange()); 192 193 //! Add a shape to a document 194 //! Depending on a case, this shape can be added as one, or 195 //! as assembly, or (in case if it is associated with external 196 //! reference) taken as that referred shape 197 Standard_EXPORT TDF_Label AddShape (const TopoDS_Shape& S, const Handle(XCAFDoc_ShapeTool)& STool, const TopTools_MapOfShape& NewShapesMap, const STEPCAFControl_DataMapOfShapePD& ShapePDMap, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap); 198 199 //! Reads (or if returns already read) extern file with 200 //! given name 201 Standard_EXPORT Handle(STEPCAFControl_ExternFile) ReadExternFile (const Standard_CString file, 202 const Standard_CString fullpath, 203 Handle(TDocStd_Document)& doc, 204 const Message_ProgressRange& theProgress = Message_ProgressRange()); 205 206 //! Reads style assignments from STEP model and sets 207 //! corresponding color assignments in the DECAF document 208 Standard_EXPORT Standard_Boolean ReadColors 209 (const Handle(XSControl_WorkSession)& WS, 210 Handle(TDocStd_Document)& doc) const; 211 212 //! Reads names of parts defined in the STEP model and 213 //! assigns them to corresponding labels in the DECAF document 214 Standard_EXPORT Standard_Boolean ReadNames (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const; 215 216 //! Reads validation properties assigned to shapes in the STEP 217 //! model and assigns them to corresponding labels in the DECAF 218 //! document 219 Standard_EXPORT Standard_Boolean ReadValProps (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const; 220 221 //! Reads layers of parts defined in the STEP model and 222 //! set reference between shape and layers in the DECAF document 223 Standard_EXPORT Standard_Boolean ReadLayers (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc) const; 224 225 //! Reads SHUO for instances defined in the STEP model and 226 //! set reference between shape instances from different assemblyes 227 Standard_EXPORT Standard_Boolean ReadSHUOs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const; 228 229 //! Reads D> for instances defined in the STEP model and 230 //! set reference between shape instances from different assemblyes 231 Standard_EXPORT Standard_Boolean ReadGDTs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc); 232 233 //! Reads materials for instances defined in the STEP model and 234 //! set reference between shape instances from different assemblyes 235 Standard_EXPORT Standard_Boolean ReadMaterials (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const Handle(TColStd_HSequenceOfTransient)& SeqPDS) const; 236 237 //! Reads Views for instances defined in the STEP model 238 Standard_EXPORT Standard_Boolean ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const; 239 240 //! Populates the sub-Label of the passed TDF Label with shape 241 //! data associated with the given STEP Representation Item, 242 //! including naming and topological information. 243 Standard_EXPORT TDF_Label SettleShapeData (const Handle(StepRepr_RepresentationItem)& theItem, const TDF_Label& theLab, const Handle(XCAFDoc_ShapeTool)& theShapeTool, const Handle(Transfer_TransientProcess)& theTP) const; 244 245 //! Given the maps of already translated shapes, this method 246 //! expands their correspondent Labels in XDE Document so that 247 //! to have a dedicated sub-Label for each sub-shape coming 248 //! with associated name in its STEP Representation Item. 249 Standard_EXPORT void ExpandSubShapes (const Handle(XCAFDoc_ShapeTool)& theShapeTool, const STEPCAFControl_DataMapOfShapePD& theShapePDMap) const; 250 251 //! Expands the topological structure of Manifold Solid BRep 252 //! STEP entity to OCAF sub-tree. Entities having no names 253 //! associated via their Representation Items are skipped. 254 Standard_EXPORT void ExpandManifoldSolidBrep (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const; 255 256 //! Expands the topological structure of Shell-Based Surface 257 //! Model STEP entity to OCAF sub-tree. Entities having no names 258 //! associated via their Representation Items are skipped. 259 Standard_EXPORT void ExpandSBSM (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const; 260 261 //! Expands STEP Shell structure to OCAF sub-tree. Entities 262 //! having no names associated via their Representation Items 263 //! are skipped. 264 Standard_EXPORT void ExpandShell (const Handle(StepShape_ConnectedFaceSet)& theShell, TDF_Label& theLab, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const; 265 266 //! Convert name into UNICODE text. 267 Standard_EXPORT virtual TCollection_ExtendedString convertName (const TCollection_AsciiString& theName) const; 268 269 private: 270 271 //! Internal method. Import all Datum attributes and set them to XCAF object. Set connection of Datum to GeomTolerance (theGDTL). 272 Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat, 273 const TDF_Label theGDTL, 274 const Standard_Integer thePositionCounter, 275 const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers, 276 const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal, 277 const Standard_Real theModifValue, 278 const Handle(TDocStd_Document)& theDoc, 279 const Handle(XSControl_WorkSession)& theWS); 280 281 //! Internal method. Read Datums, connected to GeomTolerance theGDTL. 282 Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt, 283 const TDF_Label theGDTL, 284 const Handle(TDocStd_Document)& theDoc, 285 const Handle(XSControl_WorkSession)& theWS); 286 287 //! Internal method. Read Dimension or GeomTolerance. 288 TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt, 289 const Handle(TDocStd_Document)& theDoc, 290 const Handle(XSControl_WorkSession)& theWS); 291 292 //! Prepares units for transfer 293 void prepareUnits(const Handle(StepData_StepModel)& theModel, 294 const Handle(TDocStd_Document)& theDoc) const; 295 296 private: 297 298 STEPControl_Reader myReader; 299 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles; 300 XCAFDoc_DataMapOfShapeLabel myMap; 301 Standard_Boolean myColorMode; 302 Standard_Boolean myNameMode; 303 Standard_Boolean myLayerMode; 304 Standard_Boolean myPropsMode; 305 Standard_Boolean mySHUOMode; 306 Standard_Boolean myGDTMode; 307 Standard_Boolean myMatMode; 308 Standard_Boolean myViewMode; 309 NCollection_DataMap<Handle(Standard_Transient), TDF_Label> myGDTMap; 310 311 }; 312 313 #endif // _STEPCAFControl_Reader_HeaderFile 314