| 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 | //! Clears the internal data structures and attaches to a new session |
| 75 | //! Clears the session if it was not yet set for STEP |
| 76 | Standard_EXPORT void Init (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True); |
| 77 | |
| 78 | //! Loads a file and returns the read status |
| 79 | //! Provided for use like single-file reader |
| 80 | Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename); |
| 81 | |
| 82 | //! Returns number of roots recognized for transfer |
| 83 | //! Shortcut for Reader().NbRootsForTransfer() |
| 84 | Standard_EXPORT Standard_Integer NbRootsForTransfer(); |
| 85 | |
| 86 | //! Translates currently loaded STEP file into the document |
| 87 | //! Returns True if succeeded, and False in case of fail |
| 88 | //! Provided for use like single-file reader |
| 89 | Standard_EXPORT Standard_Boolean TransferOneRoot (const Standard_Integer num, Handle(TDocStd_Document)& doc); |
| 90 | |
| 91 | //! Translates currently loaded STEP file into the document |
| 92 | //! Returns True if succeeded, and False in case of fail |
| 93 | //! Provided for use like single-file reader |
| 94 | Standard_EXPORT Standard_Boolean Transfer (Handle(TDocStd_Document)& doc); |
| 95 | |
| 96 | Standard_EXPORT Standard_Boolean Perform (const TCollection_AsciiString& filename, Handle(TDocStd_Document)& doc); |
| 97 | |
| 98 | //! Translate STEP file given by filename into the document |
| 99 | //! Return True if succeeded, and False in case of fail |
| 100 | Standard_EXPORT Standard_Boolean Perform (const Standard_CString filename, Handle(TDocStd_Document)& doc); |
| 101 | |
| 102 | //! Returns data on external files |
| 103 | //! Returns Null handle if no external files are read |
| 104 | Standard_EXPORT const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> & ExternFiles() const; |
| 105 | |
| 106 | //! Returns data on external file by its name |
| 107 | //! Returns False if no external file with given name is read |
| 108 | Standard_EXPORT Standard_Boolean ExternFile (const Standard_CString name, Handle(STEPCAFControl_ExternFile)& ef) const; |
| 109 | |
| 110 | //! Returns basic reader |
| 111 | Standard_EXPORT STEPControl_Reader& ChangeReader(); |
| 112 | |
| 113 | //! Returns basic reader as const |
| 114 | Standard_EXPORT const STEPControl_Reader& Reader() const; |
| 115 | |
| 116 | //! Returns label of instance of an assembly component |
| 117 | //! corresponding to a given NAUO |
| 118 | Standard_EXPORT static TDF_Label FindInstance |
| 119 | (const Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO, |
| 120 | const Handle(XCAFDoc_ShapeTool)& STool, |
| 121 | const STEPConstruct_Tool& Tool, |
| 122 | const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap); |
| 123 | |
| 124 | //! Set ColorMode for indicate read Colors or not. |
| 125 | Standard_EXPORT void SetColorMode (const Standard_Boolean colormode); |
| 126 | |
| 127 | Standard_EXPORT Standard_Boolean GetColorMode() const; |
| 128 | |
| 129 | //! Set NameMode for indicate read Name or not. |
| 130 | Standard_EXPORT void SetNameMode (const Standard_Boolean namemode); |
| 131 | |
| 132 | Standard_EXPORT Standard_Boolean GetNameMode() const; |
| 133 | |
| 134 | //! Return the encoding of STEP file for converting names into UNICODE. |
| 135 | //! Initialized from "read.stepcaf.codepage" variable by constructor, which is Resource_UTF8 by default. |
| 136 | Resource_FormatType SourceCodePage() const { return mySourceCodePage; } |
| 137 | |
| 138 | //! Return the encoding of STEP file for converting names into UNICODE. |
| 139 | void SetSourceCodePage (Resource_FormatType theCode) { mySourceCodePage = theCode; } |
| 140 | |
| 141 | //! Set LayerMode for indicate read Layers or not. |
| 142 | Standard_EXPORT void SetLayerMode (const Standard_Boolean layermode); |
| 143 | |
| 144 | Standard_EXPORT Standard_Boolean GetLayerMode() const; |
| 145 | |
| 146 | //! PropsMode for indicate read Validation properties or not. |
| 147 | Standard_EXPORT void SetPropsMode (const Standard_Boolean propsmode); |
| 148 | |
| 149 | Standard_EXPORT Standard_Boolean GetPropsMode() const; |
| 150 | |
| 151 | //! Set SHUO mode for indicate write SHUO or not. |
| 152 | Standard_EXPORT void SetSHUOMode (const Standard_Boolean shuomode); |
| 153 | |
| 154 | Standard_EXPORT Standard_Boolean GetSHUOMode() const; |
| 155 | |
| 156 | //! Set GDT mode for indicate write GDT or not. |
| 157 | Standard_EXPORT void SetGDTMode (const Standard_Boolean gdtmode); |
| 158 | |
| 159 | Standard_EXPORT Standard_Boolean GetGDTMode() const; |
| 160 | |
| 161 | //! Set Material mode |
| 162 | Standard_EXPORT void SetMatMode (const Standard_Boolean matmode); |
| 163 | |
| 164 | Standard_EXPORT Standard_Boolean GetMatMode() const; |
| 165 | |
| 166 | //! Set View mode |
| 167 | Standard_EXPORT void SetViewMode(const Standard_Boolean viewmode); |
| 168 | |
| 169 | //! Get View mode |
| 170 | Standard_EXPORT Standard_Boolean GetViewMode() const; |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | protected: |
| 176 | |
| 177 | |
| 178 | //! Translates STEP file already loaded into the reader |
| 179 | //! into the document |
| 180 | //! If num==0, translates all roots, else only root number num |
| 181 | //! Returns True if succeeded, and False in case of fail |
| 182 | //! If asOne is True, in case of multiple results composes |
| 183 | //! them into assembly. Fills sequence of produced labels |
| 184 | Standard_EXPORT Standard_Boolean Transfer (STEPControl_Reader& rd, const Standard_Integer num, Handle(TDocStd_Document)& doc, TDF_LabelSequence& Lseq, const Standard_Boolean asOne = Standard_False); |
| 185 | |
| 186 | //! Add a shape to a document |
| 187 | //! Depending on a case, this shape can be added as one, or |
| 188 | //! as assembly, or (in case if it is associated with external |
| 189 | //! reference) taken as that referred shape |
| 190 | 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, XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const; |
| 191 | |
| 192 | //! Reads (or if returns already read) extern file with |
| 193 | //! given name |
| 194 | Standard_EXPORT Handle(STEPCAFControl_ExternFile) ReadExternFile (const Standard_CString file, const Standard_CString fullpath, Handle(TDocStd_Document)& doc); |
| 195 | |
| 196 | //! Reads style assignments from STEP model and sets |
| 197 | //! corresponding color assignments in the DECAF document |
| 198 | Standard_EXPORT Standard_Boolean ReadColors |
| 199 | (const Handle(XSControl_WorkSession)& WS, |
| 200 | Handle(TDocStd_Document)& doc, |
| 201 | const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const; |
| 202 | |
| 203 | //! Reads names of parts defined in the STEP model and |
| 204 | //! assigns them to corresponding labels in the DECAF document |
| 205 | Standard_EXPORT Standard_Boolean ReadNames (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const; |
| 206 | |
| 207 | //! Reads validation properties assigned to shapes in the STEP |
| 208 | //! model and assigns them to corresponding labels in the DECAF |
| 209 | //! document |
| 210 | Standard_EXPORT Standard_Boolean ReadValProps (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const; |
| 211 | |
| 212 | //! Reads layers of parts defined in the STEP model and |
| 213 | //! set reference between shape and layers in the DECAF document |
| 214 | Standard_EXPORT Standard_Boolean ReadLayers (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc) const; |
| 215 | |
| 216 | //! Reads SHUO for instances defined in the STEP model and |
| 217 | //! set reference between shape instances from different assemblyes |
| 218 | Standard_EXPORT Standard_Boolean ReadSHUOs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const; |
| 219 | |
| 220 | //! Reads D> for instances defined in the STEP model and |
| 221 | //! set reference between shape instances from different assemblyes |
| 222 | Standard_EXPORT Standard_Boolean ReadGDTs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc); |
| 223 | |
| 224 | //! Reads materials for instances defined in the STEP model and |
| 225 | //! set reference between shape instances from different assemblyes |
| 226 | Standard_EXPORT Standard_Boolean ReadMaterials (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const Handle(TColStd_HSequenceOfTransient)& SeqPDS) const; |
| 227 | |
| 228 | //! Reads Views for instances defined in the STEP model |
| 229 | Standard_EXPORT Standard_Boolean ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const; |
| 230 | |
| 231 | //! Populates the sub-Label of the passed TDF Label with shape |
| 232 | //! data associated with the given STEP Representation Item, |
| 233 | //! including naming and topological information. |
| 234 | 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; |
| 235 | |
| 236 | //! Given the maps of already translated shapes, this method |
| 237 | //! expands their correspondent Labels in XDE Document so that |
| 238 | //! to have a dedicated sub-Label for each sub-shape coming |
| 239 | //! with associated name in its STEP Representation Item. |
| 240 | Standard_EXPORT void ExpandSubShapes (const Handle(XCAFDoc_ShapeTool)& theShapeTool, const XCAFDoc_DataMapOfShapeLabel& theShapeLabelMap, const STEPCAFControl_DataMapOfShapePD& theShapePDMap) const; |
| 241 | |
| 242 | //! Expands the topological structure of Manifold Solid BRep |
| 243 | //! STEP entity to OCAF sub-tree. Entities having no names |
| 244 | //! associated via their Representation Items are skipped. |
| 245 | Standard_EXPORT void ExpandManifoldSolidBrep (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const; |
| 246 | |
| 247 | //! Expands the topological structure of Shell-Based Surface |
| 248 | //! Model STEP entity to OCAF sub-tree. Entities having no names |
| 249 | //! associated via their Representation Items are skipped. |
| 250 | Standard_EXPORT void ExpandSBSM (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const; |
| 251 | |
| 252 | //! Expands STEP Shell structure to OCAF sub-tree. Entities |
| 253 | //! having no names associated via their Representation Items |
| 254 | //! are skipped. |
| 255 | Standard_EXPORT void ExpandShell (const Handle(StepShape_ConnectedFaceSet)& theShell, TDF_Label& theLab, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const; |
| 256 | |
| 257 | //! Convert name into UNICODE text. |
| 258 | Standard_EXPORT virtual TCollection_ExtendedString convertName (const TCollection_AsciiString& theName) const; |
| 259 | |
| 260 | private: |
| 261 | |
| 262 | //! Internal method. Import all Datum attributes and set them to XCAF object. Set connection of Datum to GeomTolerance (theGDTL). |
| 263 | Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat, |
| 264 | const TDF_Label theGDTL, |
| 265 | const Standard_Integer thePositionCounter, |
| 266 | const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers, |
| 267 | const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal, |
| 268 | const Standard_Real theModifValue, |
| 269 | const Handle(TDocStd_Document)& theDoc, |
| 270 | const Handle(XSControl_WorkSession)& theWS); |
| 271 | |
| 272 | //! Internal method. Read Datums, connected to GeomTolerance theGDTL. |
| 273 | Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt, |
| 274 | const TDF_Label theGDTL, |
| 275 | const Handle(TDocStd_Document)& theDoc, |
| 276 | const Handle(XSControl_WorkSession)& theWS); |
| 277 | |
| 278 | //! Internal method. Read Dimension or GeomTolerance. |
| 279 | TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt, |
| 280 | const Handle(TDocStd_Document)& theDoc, |
| 281 | const Handle(XSControl_WorkSession)& theWS); |
| 282 | |
| 283 | |
| 284 | STEPControl_Reader myReader; |
| 285 | NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles; |
| 286 | Resource_FormatType mySourceCodePage; |
| 287 | Standard_Boolean myColorMode; |
| 288 | Standard_Boolean myNameMode; |
| 289 | Standard_Boolean myLayerMode; |
| 290 | Standard_Boolean myPropsMode; |
| 291 | Standard_Boolean mySHUOMode; |
| 292 | Standard_Boolean myGDTMode; |
| 293 | Standard_Boolean myMatMode; |
| 294 | Standard_Boolean myViewMode; |
| 295 | NCollection_DataMap<Handle(Standard_Transient), TDF_Label> myGDTMap; |
| 296 | |
| 297 | }; |
| 298 | |
| 299 | #endif // _STEPCAFControl_Reader_HeaderFile |