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 (const Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO, const Handle(XCAFDoc_ShapeTool)& STool, const STEPConstruct_Tool& Tool, const STEPCAFControl_DataMapOfPDExternFile& PDRFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap);
125 //! Set ColorMode for indicate read Colors or not.
126 Standard_EXPORT void SetColorMode (const Standard_Boolean colormode);
128 Standard_EXPORT Standard_Boolean GetColorMode() const;
130 //! Set NameMode for indicate read Name or not.
131 Standard_EXPORT void SetNameMode (const Standard_Boolean namemode);
133 Standard_EXPORT Standard_Boolean GetNameMode() const;
135 //! Set LayerMode for indicate read Layers or not.
136 Standard_EXPORT void SetLayerMode (const Standard_Boolean layermode);
138 Standard_EXPORT Standard_Boolean GetLayerMode() const;
140 //! PropsMode for indicate read Validation properties or not.
141 Standard_EXPORT void SetPropsMode (const Standard_Boolean propsmode);
143 Standard_EXPORT Standard_Boolean GetPropsMode() const;
145 //! Set SHUO mode for indicate write SHUO or not.
146 Standard_EXPORT void SetSHUOMode (const Standard_Boolean shuomode);
148 Standard_EXPORT Standard_Boolean GetSHUOMode() const;
150 //! Set GDT mode for indicate write GDT or not.
151 Standard_EXPORT void SetGDTMode (const Standard_Boolean gdtmode);
153 Standard_EXPORT Standard_Boolean GetGDTMode() const;
155 //! Set Material mode
156 Standard_EXPORT void SetMatMode (const Standard_Boolean matmode);
158 Standard_EXPORT Standard_Boolean GetMatMode() const;
161 Standard_EXPORT void SetViewMode(const Standard_Boolean viewmode);
164 Standard_EXPORT Standard_Boolean GetViewMode() const;
172 //! Translates STEP file already loaded into the reader
173 //! into the document
174 //! If num==0, translates all roots, else only root number num
175 //! Returns True if succeeded, and False in case of fail
176 //! If asOne is True, in case of multiple results composes
177 //! them into assembly. Fills sequence of produced labels
178 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);
180 //! Add a shape to a document
181 //! Depending on a case, this shape can be added as one, or
182 //! as assembly, or (in case if it is associated with external
183 //! reference) taken as that referred shape
184 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;
186 //! Reads (or if returns already read) extern file with
188 Standard_EXPORT Handle(STEPCAFControl_ExternFile) ReadExternFile (const Standard_CString file, const Standard_CString fullpath, Handle(TDocStd_Document)& doc);
190 //! Reads style assignments from STEP model and sets
191 //! corresponding color assignments in the DECAF document
192 Standard_EXPORT Standard_Boolean ReadColors (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
194 //! Reads names of parts defined in the STEP model and
195 //! assigns them to corresponding labels in the DECAF document
196 Standard_EXPORT Standard_Boolean ReadNames (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
198 //! Reads validation properties assigned to shapes in the STEP
199 //! model and assigns them to corresponding labels in the DECAF
201 Standard_EXPORT Standard_Boolean ReadValProps (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
203 //! Reads layers of parts defined in the STEP model and
204 //! set reference between shape and layers in the DECAF document
205 Standard_EXPORT Standard_Boolean ReadLayers (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc) const;
207 //! Reads SHUO for instances defined in the STEP model and
208 //! set reference between shape instances from different assemblyes
209 Standard_EXPORT Standard_Boolean ReadSHUOs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
211 //! Reads D> for instances defined in the STEP model and
212 //! set reference between shape instances from different assemblyes
213 Standard_EXPORT Standard_Boolean ReadGDTs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc);
215 //! Reads materials for instances defined in the STEP model and
216 //! set reference between shape instances from different assemblyes
217 Standard_EXPORT Standard_Boolean ReadMaterials (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const Handle(TColStd_HSequenceOfTransient)& SeqPDS) const;
219 //! Reads Views for instances defined in the STEP model
220 Standard_EXPORT Standard_Boolean ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const;
222 //! Populates the sub-Label of the passed TDF Label with shape
223 //! data associated with the given STEP Representation Item,
224 //! including naming and topological information.
225 Standard_EXPORT TDF_Label SettleShapeData (const Handle(StepRepr_RepresentationItem)& theItem, TDF_Label& theLab, const Handle(XCAFDoc_ShapeTool)& theShapeTool, const Handle(Transfer_TransientProcess)& theTP) const;
227 //! Given the maps of already translated shapes, this method
228 //! expands their correspondent Labels in XDE Document so that
229 //! to have a dedicated sub-Label for each sub-shape coming
230 //! with associated name in its STEP Representation Item.
231 Standard_EXPORT void ExpandSubShapes (const Handle(XCAFDoc_ShapeTool)& theShapeTool, const XCAFDoc_DataMapOfShapeLabel& theShapeLabelMap, const STEPCAFControl_DataMapOfShapePD& theShapePDMap) const;
233 //! Expands the topological structure of Manifold Solid BRep
234 //! STEP entity to OCAF sub-tree. Entities having no names
235 //! associated via their Representation Items are skipped.
236 Standard_EXPORT void ExpandManifoldSolidBrep (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
238 //! Expands the topological structure of Shell-Based Surface
239 //! Model STEP entity to OCAF sub-tree. Entities having no names
240 //! associated via their Representation Items are skipped.
241 Standard_EXPORT void ExpandSBSM (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
243 //! Expands STEP Shell structure to OCAF sub-tree. Entities
244 //! having no names associated via their Representation Items
246 Standard_EXPORT void ExpandShell (const Handle(StepShape_ConnectedFaceSet)& theShell, TDF_Label& theLab, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
253 //! Internal method. Import all Datum attributes and set them to XCAF object. Set connection of Datum to GeomTolerance (theGDTL).
254 Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
255 const TDF_Label theGDTL,
256 const Standard_Integer thePositionCounter,
257 const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
258 const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
259 const Standard_Real theModifValue,
260 const Handle(TDocStd_Document)& theDoc,
261 const Handle(XSControl_WorkSession)& theWS);
263 //! Internal method. Read Datums, connected to GeomTolerance theGDTL.
264 Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt,
265 const TDF_Label theGDTL,
266 const Handle(TDocStd_Document)& theDoc,
267 const Handle(XSControl_WorkSession)& theWS);
269 //! Internal method. Read Dimension or GeomTolerance.
270 TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
271 const Handle(TDocStd_Document)& theDoc,
272 const Handle(XSControl_WorkSession)& theWS);
275 STEPControl_Reader myReader;
276 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles;
277 Standard_Boolean myColorMode;
278 Standard_Boolean myNameMode;
279 Standard_Boolean myLayerMode;
280 Standard_Boolean myPropsMode;
281 Standard_Boolean mySHUOMode;
282 Standard_Boolean myGDTMode;
283 Standard_Boolean myMatMode;
284 Standard_Boolean myViewMode;
285 NCollection_DataMap<Handle(Standard_Transient), TDF_Label> myGDTMap;
295 #endif // _STEPCAFControl_Reader_HeaderFile