1 // Created on: 2000-08-15
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _STEPCAFControl_Reader_HeaderFile
17 #define _STEPCAFControl_Reader_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
23 #include <STEPControl_Reader.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <IFSelect_ReturnStatus.hxx>
26 #include <Standard_CString.hxx>
27 #include <Standard_Integer.hxx>
28 #include <TDF_LabelSequence.hxx>
29 #include <TopTools_MapOfShape.hxx>
30 #include <STEPCAFControl_DataMapOfShapePD.hxx>
31 #include <STEPCAFControl_DataMapOfPDExternFile.hxx>
32 #include <XCAFDoc_DataMapOfShapeLabel.hxx>
33 #include <TColStd_HSequenceOfTransient.hxx>
34 #include <XCAFDimTolObjects_DatumModifiersSequence.hxx>
35 #include <XCAFDimTolObjects_DatumModifWithValue.hxx>
36 class XSControl_WorkSession;
37 class TDocStd_Document;
38 class TCollection_AsciiString;
39 class STEPCAFControl_ExternFile;
40 class STEPControl_Reader;
43 class XCAFDoc_ShapeTool;
44 class StepRepr_RepresentationItem;
45 class Transfer_TransientProcess;
46 class StepShape_ConnectedFaceSet;
47 class StepRepr_NextAssemblyUsageOccurrence;
48 class STEPConstruct_Tool;
49 class StepDimTol_Datum;
52 //! Provides a tool to read STEP file and put it into
53 //! DECAF document. Besides transfer of shapes (including
54 //! assemblies) provided by STEPControl, supports also
55 //! colors and part names
57 //! This reader supports reading files with external references
58 //! i.e. multifile reading
59 //! It behaves as usual Reader (from STEPControl) for the main
60 //! file (e.g. if it is single file)
61 //! Results of reading other files can be accessed by name of the
62 //! file or by iterating on a readers
63 class STEPCAFControl_Reader
70 //! Creates a reader with an empty
71 //! STEP model and sets ColorMode, LayerMode, NameMode and
72 //! PropsMode to Standard_True.
73 Standard_EXPORT STEPCAFControl_Reader();
75 //! Creates a reader tool and attaches it to an already existing Session
76 //! Clears the session if it was not yet set for STEP
77 Standard_EXPORT STEPCAFControl_Reader(const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
79 //! Clears the internal data structures and attaches to a new session
80 //! Clears the session if it was not yet set for STEP
81 Standard_EXPORT void Init (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
83 //! Loads a file and returns the read status
84 //! Provided for use like single-file reader
85 Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename);
87 //! Returns number of roots recognized for transfer
88 //! Shortcut for Reader().NbRootsForTransfer()
89 Standard_EXPORT Standard_Integer NbRootsForTransfer();
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 TransferOneRoot (const Standard_Integer num, Handle(TDocStd_Document)& doc);
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);
101 Standard_EXPORT Standard_Boolean Perform (const TCollection_AsciiString& filename, Handle(TDocStd_Document)& doc);
103 //! Translate STEP file given by filename into the document
104 //! Return True if succeeded, and False in case of fail
105 Standard_EXPORT Standard_Boolean Perform (const Standard_CString filename, Handle(TDocStd_Document)& doc);
107 //! Returns data on external files
108 //! Returns Null handle if no external files are read
109 Standard_EXPORT const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> & ExternFiles() const;
111 //! Returns data on external file by its name
112 //! Returns False if no external file with given name is read
113 Standard_EXPORT Standard_Boolean ExternFile (const Standard_CString name, Handle(STEPCAFControl_ExternFile)& ef) const;
115 //! Returns basic reader
116 Standard_EXPORT STEPControl_Reader& ChangeReader();
118 //! Returns basic reader as const
119 Standard_EXPORT const STEPControl_Reader& Reader() const;
121 //! Returns label of instance of an assembly component
122 //! corresponding to a given NAUO
123 Standard_EXPORT static TDF_Label FindInstance
124 (const Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO,
125 const Handle(XCAFDoc_ShapeTool)& STool,
126 const STEPConstruct_Tool& Tool,
127 const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap);
129 //! Set ColorMode for indicate read Colors or not.
130 Standard_EXPORT void SetColorMode (const Standard_Boolean colormode);
132 Standard_EXPORT Standard_Boolean GetColorMode() const;
134 //! Set NameMode for indicate read Name or not.
135 Standard_EXPORT void SetNameMode (const Standard_Boolean namemode);
137 Standard_EXPORT Standard_Boolean GetNameMode() const;
139 //! Set LayerMode for indicate read Layers or not.
140 Standard_EXPORT void SetLayerMode (const Standard_Boolean layermode);
142 Standard_EXPORT Standard_Boolean GetLayerMode() const;
144 //! PropsMode for indicate read Validation properties or not.
145 Standard_EXPORT void SetPropsMode (const Standard_Boolean propsmode);
147 Standard_EXPORT Standard_Boolean GetPropsMode() const;
149 //! Set SHUO mode for indicate write SHUO or not.
150 Standard_EXPORT void SetSHUOMode (const Standard_Boolean shuomode);
152 Standard_EXPORT Standard_Boolean GetSHUOMode() const;
154 //! Set GDT mode for indicate write GDT or not.
155 Standard_EXPORT void SetGDTMode (const Standard_Boolean gdtmode);
157 Standard_EXPORT Standard_Boolean GetGDTMode() const;
159 //! Set Material mode
160 Standard_EXPORT void SetMatMode (const Standard_Boolean matmode);
162 Standard_EXPORT Standard_Boolean GetMatMode() const;
165 Standard_EXPORT void SetViewMode(const Standard_Boolean viewmode);
168 Standard_EXPORT Standard_Boolean GetViewMode() const;
176 //! Translates STEP file already loaded into the reader
177 //! into the document
178 //! If num==0, translates all roots, else only root number num
179 //! Returns True if succeeded, and False in case of fail
180 //! If asOne is True, in case of multiple results composes
181 //! them into assembly. Fills sequence of produced labels
182 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);
184 //! Add a shape to a document
185 //! Depending on a case, this shape can be added as one, or
186 //! as assembly, or (in case if it is associated with external
187 //! reference) taken as that referred shape
188 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;
190 //! Reads (or if returns already read) extern file with
192 Standard_EXPORT Handle(STEPCAFControl_ExternFile) ReadExternFile (const Standard_CString file, const Standard_CString fullpath, Handle(TDocStd_Document)& doc);
194 //! Reads style assignments from STEP model and sets
195 //! corresponding color assignments in the DECAF document
196 Standard_EXPORT Standard_Boolean ReadColors
197 (const Handle(XSControl_WorkSession)& WS,
198 Handle(TDocStd_Document)& doc,
199 const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
201 //! Reads names of parts defined in the STEP model and
202 //! assigns them to corresponding labels in the DECAF document
203 Standard_EXPORT Standard_Boolean ReadNames (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
205 //! Reads validation properties assigned to shapes in the STEP
206 //! model and assigns them to corresponding labels in the DECAF
208 Standard_EXPORT Standard_Boolean ReadValProps (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
210 //! Reads layers of parts defined in the STEP model and
211 //! set reference between shape and layers in the DECAF document
212 Standard_EXPORT Standard_Boolean ReadLayers (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc) const;
214 //! Reads SHUO for instances defined in the STEP model and
215 //! set reference between shape instances from different assemblyes
216 Standard_EXPORT Standard_Boolean ReadSHUOs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
218 //! Reads D> for instances defined in the STEP model and
219 //! set reference between shape instances from different assemblyes
220 Standard_EXPORT Standard_Boolean ReadGDTs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc);
222 //! Reads materials for instances defined in the STEP model and
223 //! set reference between shape instances from different assemblyes
224 Standard_EXPORT Standard_Boolean ReadMaterials (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const Handle(TColStd_HSequenceOfTransient)& SeqPDS) const;
226 //! Reads Views for instances defined in the STEP model
227 Standard_EXPORT Standard_Boolean ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const;
229 //! Populates the sub-Label of the passed TDF Label with shape
230 //! data associated with the given STEP Representation Item,
231 //! including naming and topological information.
232 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;
234 //! Given the maps of already translated shapes, this method
235 //! expands their correspondent Labels in XDE Document so that
236 //! to have a dedicated sub-Label for each sub-shape coming
237 //! with associated name in its STEP Representation Item.
238 Standard_EXPORT void ExpandSubShapes (const Handle(XCAFDoc_ShapeTool)& theShapeTool, const XCAFDoc_DataMapOfShapeLabel& theShapeLabelMap, const STEPCAFControl_DataMapOfShapePD& theShapePDMap) const;
240 //! Expands the topological structure of Manifold Solid BRep
241 //! STEP entity to OCAF sub-tree. Entities having no names
242 //! associated via their Representation Items are skipped.
243 Standard_EXPORT void ExpandManifoldSolidBrep (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
245 //! Expands the topological structure of Shell-Based Surface
246 //! Model STEP entity to OCAF sub-tree. Entities having no names
247 //! associated via their Representation Items are skipped.
248 Standard_EXPORT void ExpandSBSM (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
250 //! Expands STEP Shell structure to OCAF sub-tree. Entities
251 //! having no names associated via their Representation Items
253 Standard_EXPORT void ExpandShell (const Handle(StepShape_ConnectedFaceSet)& theShell, TDF_Label& theLab, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
260 //! Internal method. Import all Datum attributes and set them to XCAF object. Set connection of Datum to GeomTolerance (theGDTL).
261 Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
262 const TDF_Label theGDTL,
263 const Standard_Integer thePositionCounter,
264 const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
265 const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
266 const Standard_Real theModifValue,
267 const Handle(TDocStd_Document)& theDoc,
268 const Handle(XSControl_WorkSession)& theWS);
270 //! Internal method. Read Datums, connected to GeomTolerance theGDTL.
271 Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt,
272 const TDF_Label theGDTL,
273 const Handle(TDocStd_Document)& theDoc,
274 const Handle(XSControl_WorkSession)& theWS);
276 //! Internal method. Read Dimension or GeomTolerance.
277 TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
278 const Handle(TDocStd_Document)& theDoc,
279 const Handle(XSControl_WorkSession)& theWS);
282 STEPControl_Reader myReader;
283 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles;
284 Standard_Boolean myColorMode;
285 Standard_Boolean myNameMode;
286 Standard_Boolean myLayerMode;
287 Standard_Boolean myPropsMode;
288 Standard_Boolean mySHUOMode;
289 Standard_Boolean myGDTMode;
290 Standard_Boolean myMatMode;
291 Standard_Boolean myViewMode;
292 NCollection_DataMap<Handle(Standard_Transient), TDF_Label> myGDTMap;
302 #endif // _STEPCAFControl_Reader_HeaderFile