0025748: Parallel version of progress indicator
[occt.git] / src / STEPCAFControl / STEPCAFControl_Reader.hxx
CommitLineData
42cf5bc1 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
e3249d8e 19#include <Resource_FormatType.hxx>
42cf5bc1 20#include <STEPControl_Reader.hxx>
42cf5bc1 21#include <IFSelect_ReturnStatus.hxx>
42cf5bc1 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>
0c63f2f8 28#include <XCAFDimTolObjects_DatumModifiersSequence.hxx>
29#include <XCAFDimTolObjects_DatumModifWithValue.hxx>
e3249d8e 30
42cf5bc1 31class XSControl_WorkSession;
32class TDocStd_Document;
33class TCollection_AsciiString;
34class STEPCAFControl_ExternFile;
35class STEPControl_Reader;
36class TDF_Label;
37class TopoDS_Shape;
38class XCAFDoc_ShapeTool;
39class StepRepr_RepresentationItem;
40class Transfer_TransientProcess;
41class StepShape_ConnectedFaceSet;
42class StepRepr_NextAssemblyUsageOccurrence;
43class STEPConstruct_Tool;
0c63f2f8 44class StepDimTol_Datum;
42cf5bc1 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
58class STEPCAFControl_Reader
59{
60public:
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);
90bc1adb 73
74 //! Destructor.
75 Standard_EXPORT virtual ~STEPCAFControl_Reader();
76
42cf5bc1 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
7e785937 92 Standard_EXPORT Standard_Boolean TransferOneRoot (const Standard_Integer num,
93 Handle(TDocStd_Document)& doc,
94 const Message_ProgressRange& theProgress = Message_ProgressRange());
42cf5bc1 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
7e785937 99 Standard_EXPORT Standard_Boolean Transfer (Handle(TDocStd_Document)& doc,
100 const Message_ProgressRange& theProgress = Message_ProgressRange());
42cf5bc1 101
7e785937 102 Standard_EXPORT Standard_Boolean Perform (const TCollection_AsciiString& filename,
103 Handle(TDocStd_Document)& doc,
104 const Message_ProgressRange& theProgress = Message_ProgressRange());
42cf5bc1 105
106 //! Translate STEP file given by filename into the document
107 //! Return True if succeeded, and False in case of fail
7e785937 108 Standard_EXPORT Standard_Boolean Perform (const Standard_CString filename,
109 Handle(TDocStd_Document)& doc,
110 const Message_ProgressRange& theProgress = Message_ProgressRange());
42cf5bc1 111
112 //! Returns data on external files
113 //! Returns Null handle if no external files are read
997e128f 114 Standard_EXPORT const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> & ExternFiles() const;
42cf5bc1 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
63cdf48e 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);
42cf5bc1 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;
e3249d8e 143
144 //! Return the encoding of STEP file for converting names into UNICODE.
145 //! Initialized from "read.stepcaf.codepage" variable by constructor, which is Resource_UTF8 by default.
146 Resource_FormatType SourceCodePage() const { return mySourceCodePage; }
147
148 //! Return the encoding of STEP file for converting names into UNICODE.
149 void SetSourceCodePage (Resource_FormatType theCode) { mySourceCodePage = theCode; }
150
42cf5bc1 151 //! Set LayerMode for indicate read Layers or not.
152 Standard_EXPORT void SetLayerMode (const Standard_Boolean layermode);
153
154 Standard_EXPORT Standard_Boolean GetLayerMode() const;
155
156 //! PropsMode for indicate read Validation properties or not.
157 Standard_EXPORT void SetPropsMode (const Standard_Boolean propsmode);
158
159 Standard_EXPORT Standard_Boolean GetPropsMode() const;
160
161 //! Set SHUO mode for indicate write SHUO or not.
162 Standard_EXPORT void SetSHUOMode (const Standard_Boolean shuomode);
163
164 Standard_EXPORT Standard_Boolean GetSHUOMode() const;
165
166 //! Set GDT mode for indicate write GDT or not.
167 Standard_EXPORT void SetGDTMode (const Standard_Boolean gdtmode);
168
169 Standard_EXPORT Standard_Boolean GetGDTMode() const;
170
171 //! Set Material mode
172 Standard_EXPORT void SetMatMode (const Standard_Boolean matmode);
173
174 Standard_EXPORT Standard_Boolean GetMatMode() const;
0c63f2f8 175
176 //! Set View mode
177 Standard_EXPORT void SetViewMode(const Standard_Boolean viewmode);
178
179 //! Get View mode
180 Standard_EXPORT Standard_Boolean GetViewMode() const;
42cf5bc1 181
182
183
184
185protected:
186
187
188 //! Translates STEP file already loaded into the reader
189 //! into the document
190 //! If num==0, translates all roots, else only root number num
191 //! Returns True if succeeded, and False in case of fail
192 //! If asOne is True, in case of multiple results composes
193 //! them into assembly. Fills sequence of produced labels
7e785937 194 Standard_EXPORT Standard_Boolean Transfer (STEPControl_Reader& rd,
195 const Standard_Integer num,
196 Handle(TDocStd_Document)& doc,
197 TDF_LabelSequence& Lseq,
198 const Standard_Boolean asOne = Standard_False,
199 const Message_ProgressRange& theProgress = Message_ProgressRange());
42cf5bc1 200
201 //! Add a shape to a document
202 //! Depending on a case, this shape can be added as one, or
203 //! as assembly, or (in case if it is associated with external
204 //! reference) taken as that referred shape
205 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;
206
207 //! Reads (or if returns already read) extern file with
208 //! given name
7e785937 209 Standard_EXPORT Handle(STEPCAFControl_ExternFile) ReadExternFile (const Standard_CString file,
210 const Standard_CString fullpath,
211 Handle(TDocStd_Document)& doc,
212 const Message_ProgressRange& theProgress = Message_ProgressRange());
42cf5bc1 213
214 //! Reads style assignments from STEP model and sets
215 //! corresponding color assignments in the DECAF document
63cdf48e 216 Standard_EXPORT Standard_Boolean ReadColors
217 (const Handle(XSControl_WorkSession)& WS,
218 Handle(TDocStd_Document)& doc,
219 const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
42cf5bc1 220
221 //! Reads names of parts defined in the STEP model and
222 //! assigns them to corresponding labels in the DECAF document
223 Standard_EXPORT Standard_Boolean ReadNames (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
224
225 //! Reads validation properties assigned to shapes in the STEP
226 //! model and assigns them to corresponding labels in the DECAF
227 //! document
228 Standard_EXPORT Standard_Boolean ReadValProps (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
229
230 //! Reads layers of parts defined in the STEP model and
231 //! set reference between shape and layers in the DECAF document
232 Standard_EXPORT Standard_Boolean ReadLayers (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc) const;
233
234 //! Reads SHUO for instances defined in the STEP model and
235 //! set reference between shape instances from different assemblyes
236 Standard_EXPORT Standard_Boolean ReadSHUOs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap, const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap) const;
237
238 //! Reads D&GT for instances defined in the STEP model and
239 //! set reference between shape instances from different assemblyes
0c63f2f8 240 Standard_EXPORT Standard_Boolean ReadGDTs (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc);
42cf5bc1 241
242 //! Reads materials for instances defined in the STEP model and
243 //! set reference between shape instances from different assemblyes
244 Standard_EXPORT Standard_Boolean ReadMaterials (const Handle(XSControl_WorkSession)& WS, Handle(TDocStd_Document)& doc, const Handle(TColStd_HSequenceOfTransient)& SeqPDS) const;
245
0c63f2f8 246 //! Reads Views for instances defined in the STEP model
247 Standard_EXPORT Standard_Boolean ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const;
248
42cf5bc1 249 //! Populates the sub-Label of the passed TDF Label with shape
250 //! data associated with the given STEP Representation Item,
251 //! including naming and topological information.
44f29823 252 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;
42cf5bc1 253
254 //! Given the maps of already translated shapes, this method
255 //! expands their correspondent Labels in XDE Document so that
256 //! to have a dedicated sub-Label for each sub-shape coming
257 //! with associated name in its STEP Representation Item.
258 Standard_EXPORT void ExpandSubShapes (const Handle(XCAFDoc_ShapeTool)& theShapeTool, const XCAFDoc_DataMapOfShapeLabel& theShapeLabelMap, const STEPCAFControl_DataMapOfShapePD& theShapePDMap) const;
259
260 //! Expands the topological structure of Manifold Solid BRep
261 //! STEP entity to OCAF sub-tree. Entities having no names
262 //! associated via their Representation Items are skipped.
263 Standard_EXPORT void ExpandManifoldSolidBrep (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
264
265 //! Expands the topological structure of Shell-Based Surface
266 //! Model STEP entity to OCAF sub-tree. Entities having no names
267 //! associated via their Representation Items are skipped.
268 Standard_EXPORT void ExpandSBSM (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
269
270 //! Expands STEP Shell structure to OCAF sub-tree. Entities
271 //! having no names associated via their Representation Items
272 //! are skipped.
273 Standard_EXPORT void ExpandShell (const Handle(StepShape_ConnectedFaceSet)& theShell, TDF_Label& theLab, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
274
e3249d8e 275 //! Convert name into UNICODE text.
276 Standard_EXPORT virtual TCollection_ExtendedString convertName (const TCollection_AsciiString& theName) const;
42cf5bc1 277
278private:
279
0c63f2f8 280 //! Internal method. Import all Datum attributes and set them to XCAF object. Set connection of Datum to GeomTolerance (theGDTL).
281 Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
282 const TDF_Label theGDTL,
283 const Standard_Integer thePositionCounter,
284 const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
285 const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
286 const Standard_Real theModifValue,
287 const Handle(TDocStd_Document)& theDoc,
288 const Handle(XSControl_WorkSession)& theWS);
289
290 //! Internal method. Read Datums, connected to GeomTolerance theGDTL.
291 Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt,
292 const TDF_Label theGDTL,
293 const Handle(TDocStd_Document)& theDoc,
294 const Handle(XSControl_WorkSession)& theWS);
295
296 //! Internal method. Read Dimension or GeomTolerance.
297 TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
298 const Handle(TDocStd_Document)& theDoc,
299 const Handle(XSControl_WorkSession)& theWS);
42cf5bc1 300
301
302 STEPControl_Reader myReader;
997e128f 303 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles;
e3249d8e 304 Resource_FormatType mySourceCodePage;
42cf5bc1 305 Standard_Boolean myColorMode;
306 Standard_Boolean myNameMode;
307 Standard_Boolean myLayerMode;
308 Standard_Boolean myPropsMode;
309 Standard_Boolean mySHUOMode;
310 Standard_Boolean myGDTMode;
311 Standard_Boolean myMatMode;
0c63f2f8 312 Standard_Boolean myViewMode;
313 NCollection_DataMap<Handle(Standard_Transient), TDF_Label> myGDTMap;
42cf5bc1 314
315};
316
42cf5bc1 317#endif // _STEPCAFControl_Reader_HeaderFile