1 // Created on: 1997-05-14
2 // Created by: Christian CAILLET
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _XSControl_Reader_HeaderFile
18 #define _XSControl_Reader_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <TColStd_SequenceOfTransient.hxx>
26 #include <TopTools_SequenceOfShape.hxx>
27 #include <Standard_CString.hxx>
28 #include <IFSelect_ReturnStatus.hxx>
29 #include <TColStd_HSequenceOfTransient.hxx>
30 #include <Standard_Integer.hxx>
31 #include <IFSelect_PrintCount.hxx>
32 #include <Message_ProgressRange.hxx>
34 class XSControl_WorkSession;
35 class Interface_InterfaceModel;
36 class Standard_Transient;
40 //! A groundwork to convert a shape to data which complies
41 //! with a particular norm. This data can be that of a whole
42 //! model or that of a specific list of entities in the model.
43 //! You specify the list using a single selection or a
44 //! combination of selections. A selection is an operator which
45 //! computes a list of entities from a list given in input. To
46 //! specify the input, you can use:
47 //! - A predefined selection such as "xst-transferrable-roots"
48 //! - A filter based on a signature.
49 //! A signature is an operator which returns a string from an
50 //! entity according to its type.
52 //! - "xst-type" (CDL)
55 //! A filter can be based on a signature by giving a value to
56 //! be matched by the string returned. For example,
57 //! "xst-type(Curve)".
58 //! If no list is specified, the selection computes its list of
59 //! entities from the whole model. To use this class, you have to
60 //! initialize the transfer norm first, as shown in the example below.
62 //! Control_Reader reader;
63 //! IFSelect_ReturnStatus status = reader.ReadFile (filename.);
64 //! When using IGESControl_Reader or STEPControl_Reader - as the
65 //! above example shows - the reader initializes the norm directly.
66 //! Note that loading the file only stores the data. It does
67 //! not translate this data. Shapes are accumulated by
68 //! successive transfers. The last shape is cleared by:
69 //! - ClearShapes which allows you to handle a new batch
70 //! - TransferRoots which restarts the list of shapes from scratch.
71 class XSControl_Reader
78 //! Creates a Reader from scratch (creates an empty WorkSession)
79 //! A WorkSession or a Controller must be provided before running
80 Standard_EXPORT XSControl_Reader();
82 //! Creates a Reader from scratch, with a norm name which
83 //! identifies a Controller
84 Standard_EXPORT XSControl_Reader(const Standard_CString norm);
86 //! Creates a Reader from an already existing Session, with a
87 //! Controller already set
88 //! Virtual destructor
89 Standard_EXPORT XSControl_Reader(const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
91 //! Empty virtual destructor
92 virtual ~XSControl_Reader() {}
94 //! Sets a specific norm to <me>
95 //! Returns True if done, False if <norm> is not available
96 Standard_EXPORT Standard_Boolean SetNorm (const Standard_CString norm);
98 //! Sets a specific session to <me>
99 Standard_EXPORT void SetWS (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
101 //! Returns the session used in <me>
102 Standard_EXPORT Handle(XSControl_WorkSession) WS() const;
104 //! Loads a file and returns the read status
105 //! Zero for a Model which compies with the Controller
106 Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename);
108 //! Loads a file from stream and returns the read status
109 Standard_EXPORT IFSelect_ReturnStatus ReadStream(const Standard_CString theName, std::istream& theIStream);
111 //! Returns the model. It can then be consulted (header, product)
112 Standard_EXPORT Handle(Interface_InterfaceModel) Model() const;
114 //! Returns a list of entities from the IGES or STEP file
115 //! according to the following rules:
116 //! - if first and second are empty strings, the whole file is selected.
117 //! - if first is an entity number or label, the entity referred to is selected.
118 //! - if first is a list of entity numbers/labels separated by commas, the entities referred to are selected,
119 //! - if first is the name of a selection in the worksession and second is not defined,
120 //! the list contains the standard output for that selection.
121 //! - if first is the name of a selection and second is defined, the criterion defined
122 //! by second is applied to the result of the first selection.
123 //! A selection is an operator which computes a list of entities from a list given in
124 //! input according to its type. If no list is specified, the selection computes its
125 //! list of entities from the whole model.
126 //! A selection can be:
127 //! - A predefined selection (xst-transferrable-mode)
128 //! - A filter based on a signature
129 //! A Signature is an operator which returns a string from an entity according to its type. For example:
130 //! - "xst-type" (CDL)
133 //! For example, if you wanted to select only the advanced_faces in a STEP file you
134 //! would use the following code:
136 //! Reader.GiveList("xst-transferrable-roots","step-type(ADVANCED_FACE)");
138 //! If the value given to second is incorrect, it will simply be ignored.
139 Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GiveList (const Standard_CString first = "", const Standard_CString second = "");
141 //! Computes a List of entities from the model as follows
142 //! <first> being a Selection, <ent> being an entity or a list
143 //! of entities (as a HSequenceOfTransient) :
144 //! the standard result of this selection applied to this list
145 //! if <first> is erroneous, a null handle is returned
146 Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GiveList (const Standard_CString first, const Handle(Standard_Transient)& ent);
148 //! Determines the list of root entities which are candidate for
149 //! a transfer to a Shape, and returns the number
150 //! of entities in the list
151 Standard_EXPORT virtual Standard_Integer NbRootsForTransfer();
153 //! Returns an IGES or STEP root
154 //! entity for translation. The entity is identified by its
156 Standard_EXPORT Handle(Standard_Transient) RootForTransfer (const Standard_Integer num = 1);
158 //! Translates a root identified by the rank num in the model.
159 //! false is returned if no shape is produced.
160 Standard_EXPORT Standard_Boolean TransferOneRoot (const Standard_Integer num = 1,
161 const Message_ProgressRange& theProgress = Message_ProgressRange());
163 //! Translates an IGES or STEP
164 //! entity identified by the rank num in the model.
165 //! false is returned if no shape is produced.
166 Standard_EXPORT Standard_Boolean TransferOne (const Standard_Integer num,
167 const Message_ProgressRange& theProgress = Message_ProgressRange());
169 //! Translates an IGES or STEP
170 //! entity in the model. true is returned if a shape is
171 //! produced; otherwise, false is returned.
172 Standard_EXPORT Standard_Boolean TransferEntity (const Handle(Standard_Transient)& start,
173 const Message_ProgressRange& theProgress = Message_ProgressRange());
175 //! Translates a list of entities.
176 //! Returns the number of IGES or STEP entities that were
177 //! successfully translated. The list can be produced with GiveList.
178 //! Warning - This function does not clear the existing output shapes.
179 Standard_EXPORT Standard_Integer TransferList (const Handle(TColStd_HSequenceOfTransient)& list,
180 const Message_ProgressRange& theProgress = Message_ProgressRange());
182 //! Translates all translatable
183 //! roots and returns the number of successful translations.
184 //! Warning - This function clears existing output shapes first.
185 Standard_EXPORT Standard_Integer TransferRoots(const Message_ProgressRange& theProgress = Message_ProgressRange());
187 //! Clears the list of shapes that
188 //! may have accumulated in calls to TransferOne or TransferRoot.C
189 Standard_EXPORT void ClearShapes();
191 //! Returns the number of shapes produced by translation.
192 Standard_EXPORT Standard_Integer NbShapes() const;
194 //! Returns the shape resulting
195 //! from a translation and identified by the rank num.
196 //! num equals 1 by default. In other words, the first shape
197 //! resulting from the translation is returned.
198 Standard_EXPORT TopoDS_Shape Shape (const Standard_Integer num = 1) const;
200 //! Returns all of the results in
201 //! a single shape which is:
202 //! - a null shape if there are no results,
203 //! - a shape if there is one result,
204 //! - a compound containing the resulting shapes if there are more than one.
205 Standard_EXPORT TopoDS_Shape OneShape() const;
207 //! Prints the check list attached to loaded data, on the Standard
208 //! Trace File (starts at std::cout)
209 //! All messages or fails only, according to <failsonly>
210 //! mode = 0 : per entity, prints messages
211 //! mode = 1 : per message, just gives count of entities per check
212 //! mode = 2 : also gives entity numbers
213 Standard_EXPORT void PrintCheckLoad (const Standard_Boolean failsonly, const IFSelect_PrintCount mode) const;
215 //! Prints the check list attached to loaded data.
216 Standard_EXPORT void PrintCheckLoad (Standard_OStream& theStream, const Standard_Boolean failsonly, const IFSelect_PrintCount mode) const;
218 //! Displays check results for the
219 //! last translation of IGES or STEP entities to Open CASCADE
220 //! entities. Only fail messages are displayed if failsonly is
221 //! true. All messages are displayed if failsonly is
222 //! false. mode determines the contents and the order of the
223 //! messages according to the terms of the IFSelect_PrintCount enumeration.
224 Standard_EXPORT void PrintCheckTransfer (const Standard_Boolean failsonly, const IFSelect_PrintCount mode) const;
226 //! Displays check results for the last translation of IGES or STEP entities to Open CASCADE entities.
227 Standard_EXPORT void PrintCheckTransfer (Standard_OStream& theStream, const Standard_Boolean failsonly, const IFSelect_PrintCount mode) const;
229 //! Displays the statistics for
230 //! the last translation. what defines the kind of
231 //! statistics that are displayed as follows:
232 //! - 0 gives general statistics (number of translated roots,
233 //! number of warnings, number of fail messages),
234 //! - 1 gives root results,
235 //! - 2 gives statistics for all checked entities,
236 //! - 3 gives the list of translated entities,
237 //! - 4 gives warning and fail messages,
238 //! - 5 gives fail messages only.
239 //! The use of mode depends on the value of what. If what is 0,
240 //! mode is ignored. If what is 1, 2 or 3, mode defines the following:
241 //! - 0 lists the numbers of IGES or STEP entities in the respective model
242 //! - 1 gives the number, identifier, type and result
243 //! type for each IGES or STEP entity and/or its status
244 //! (fail, warning, etc.)
245 //! - 2 gives maximum information for each IGES or STEP entity (i.e. checks)
246 //! - 3 gives the number of entities per type of IGES or STEP entity
247 //! - 4 gives the number of IGES or STEP entities per result type and/or status
248 //! - 5 gives the number of pairs (IGES or STEP or result type and status)
249 //! - 6 gives the number of pairs (IGES or STEP or result type
250 //! and status) AND the list of entity numbers in the IGES or STEP model.
251 //! If what is 4 or 5, mode defines the warning and fail
252 //! messages as follows:
253 //! - if mode is 0 all warnings and checks per entity are returned
254 //! - if mode is 2 the list of entities per warning is returned.
255 //! If mode is not set, only the list of all entities per warning is given.
256 Standard_EXPORT void PrintStatsTransfer (const Standard_Integer what, const Standard_Integer mode = 0) const;
258 //! Displays the statistics for the last translation.
259 Standard_EXPORT void PrintStatsTransfer (Standard_OStream& theStream, const Standard_Integer what, const Standard_Integer mode = 0) const;
261 //! Gives statistics about Transfer
262 Standard_EXPORT void GetStatsTransfer (const Handle(TColStd_HSequenceOfTransient)& list, Standard_Integer& nbMapped, Standard_Integer& nbWithResult, Standard_Integer& nbWithFail) const;
270 //! Returns a sequence of produced shapes
271 Standard_EXPORT TopTools_SequenceOfShape& Shapes();
274 Standard_Boolean therootsta;
275 TColStd_SequenceOfTransient theroots;
282 Handle(XSControl_WorkSession) thesession;
283 TopTools_SequenceOfShape theshapes;
294 #endif // _XSControl_Reader_HeaderFile