0027349: XtControl_Reader is not thread-safe
[occt.git] / src / XSControl / XSControl_TransferReader.hxx
CommitLineData
42cf5bc1 1// Created on: 1995-12-05
2// Created by: Christian CAILLET
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
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.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _XSControl_TransferReader_HeaderFile
18#define _XSControl_TransferReader_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_Type.hxx>
22
23#include <TCollection_AsciiString.hxx>
24#include <TColStd_DataMapOfIntegerTransient.hxx>
25#include <TopTools_HSequenceOfShape.hxx>
26#include <MMgt_TShared.hxx>
42cf5bc1 27#include <TColStd_HSequenceOfTransient.hxx>
28#include <Interface_CheckStatus.hxx>
29class XSControl_Controller;
30class Interface_InterfaceModel;
31class Interface_HGraph;
32class Dico_DictionaryOfTransient;
33class Transfer_ActorOfTransientProcess;
34class Transfer_TransientProcess;
35class Standard_Transient;
36class Transfer_ResultFromModel;
37class TopoDS_Shape;
38class Interface_CheckIterator;
39class Interface_Graph;
40
41
42class XSControl_TransferReader;
43DEFINE_STANDARD_HANDLE(XSControl_TransferReader, MMgt_TShared)
44
45//! A TransferReader performs, manages, handles results of,
46//! transfers done when reading a file (i.e. from entities of an
47//! InterfaceModel, to objects for Imagine)
48//!
49//! Running is organised around basic tools : TransientProcess and
50//! its Actor, results are Binders and CheckIterators. It implies
51//! control by a Controller (which prepares the Actor as required)
52//!
53//! Getting results can be done directly on TransientProcess, but
54//! these are immediate "last produced" results. Each transfer of
55//! an entity gives a final result, but also possible intermediate
56//! data, and checks, which can be attached to sub-entities.
57//!
58//! Hence, final results (which intermediates and checks) are
59//! recorded as ResultFromModel and can be queried individually.
60//!
61//! Some more direct access are given for results which are
62//! Transient or Shapes
63class XSControl_TransferReader : public MMgt_TShared
64{
7f56eba8 65 public:
42cf5bc1 66
42cf5bc1 67 //! Creates a TransferReader, empty
7f56eba8 68 XSControl_TransferReader()
69 {}
42cf5bc1 70
71 //! Sets a Controller. It is required to generate the Actor.
72 //! Elsewhere, the Actor must be provided directly
7f56eba8 73 Standard_EXPORT void SetController (const Handle(XSControl_Controller)& theControl);
42cf5bc1 74
75 //! Sets the Actor directly : this value will be used if the
76 //! Controller is not set
7f56eba8 77 void SetActor (const Handle(Transfer_ActorOfTransientProcess)& theActor)
78 { myActor = theActor; }
42cf5bc1 79
80 //! Returns the Actor, determined by the Controller, or if this
81 //! one is unknown, directly set.
82 //! Once it has been defined, it can then be edited.
83 Standard_EXPORT Handle(Transfer_ActorOfTransientProcess) Actor();
84
85 //! Sets an InterfaceModel. This causes former results, computed
86 //! from another one, to be lost (see also Clear)
7f56eba8 87 Standard_EXPORT void SetModel (const Handle(Interface_InterfaceModel)& theModel);
42cf5bc1 88
89 //! Sets a Graph and its InterfaceModel (calls SetModel)
7f56eba8 90 Standard_EXPORT void SetGraph (const Handle(Interface_HGraph)& theGraph);
42cf5bc1 91
92 //! Returns the currently set InterfaceModel
7f56eba8 93 const Handle(Interface_InterfaceModel) & Model() const
94 { return myModel; }
42cf5bc1 95
96 //! Sets a Context : according to receiving appli, to be
97 //! interpreted by the Actor
7f56eba8 98 Standard_EXPORT void SetContext (const Standard_CString theName, const Handle(Standard_Transient)& theCtx);
42cf5bc1 99
100 //! Returns the Context attached to a name, if set and if it is
101 //! Kind of the type, else a Null Handle
102 //! Returns True if OK, False if no Context
7f56eba8 103 Standard_EXPORT Standard_Boolean GetContext (const Standard_CString theName, const Handle(Standard_Type)& theType, Handle(Standard_Transient)& theCtx) const;
42cf5bc1 104
105 //! Returns (modifiable) the whole definition of Context
106 //! Rather for internal use (ex.: preparing and setting in once)
7f56eba8 107 Handle(Dico_DictionaryOfTransient)& Context()
108 { return myContext; }
42cf5bc1 109
110 //! Sets a new value for (loaded) file name
7f56eba8 111 void SetFileName (const Standard_CString theName)
112 { myFileName = theName; }
113
42cf5bc1 114 //! Returns actual value of file name
7f56eba8 115 Standard_CString FileName() const
116 { return myFileName.ToCString(); }
42cf5bc1 117
118 //! Clears data, according mode :
119 //! -1 all
120 //! 0 nothing done
121 //! +1 final results
122 //! +2 working data (model, context, transfer process)
7f56eba8 123 Standard_EXPORT void Clear (const Standard_Integer theMode);
42cf5bc1 124
125 //! Returns the currently used TransientProcess
126 //! It is computed from the model by TransferReadRoots, or by
127 //! BeginTransferRead
7f56eba8 128 const Handle(Transfer_TransientProcess) & TransientProcess () const
129 { return myTP; }
42cf5bc1 130
131 //! Forces the TransientProcess
132 //! Remark : it also changes the Model and the Actor, from those
133 //! recorded in the new TransientProcess
7f56eba8 134 void SetTransientProcess (const Handle(Transfer_TransientProcess)& theTP)
135 { myTP = theTP; }
42cf5bc1 136
137 //! Records a final result of transferring an entity
138 //! This result is recorded as a ResultFromModel, taken from
139 //! the TransientProcess
140 //! Returns True if a result is available, False else
7f56eba8 141 Standard_EXPORT Standard_Boolean RecordResult (const Handle(Standard_Transient)& theEnt);
42cf5bc1 142
143 //! Returns True if a final result is recorded for an entity
144 //! Remark that it can bring no effective result if transfer has
145 //! completely failed (FinalResult brings only fail messages ...)
7f56eba8 146 Standard_EXPORT Standard_Boolean IsRecorded (const Handle(Standard_Transient)& theEnt) const;
42cf5bc1 147
148 //! Returns True if a final result is recorded AND BRINGS AN
149 //! EFFECTIVE RESULT (else, it brings only fail messages)
7f56eba8 150 Standard_EXPORT Standard_Boolean HasResult (const Handle(Standard_Transient)& theEnt) const;
42cf5bc1 151
152 //! Returns the list of entities to which a final result is
153 //! attached (i.e. processed by RecordResult)
154 Standard_EXPORT Handle(TColStd_HSequenceOfTransient) RecordedList() const;
155
156 //! Note that an entity has been required for transfer but no
157 //! result at all is available (typically : case not implemented)
158 //! It is not an error, but it gives a specific status : Skipped
159 //! Returns True if done, False if <ent> is not in starting model
7f56eba8 160 Standard_EXPORT Standard_Boolean Skip (const Handle(Standard_Transient)& theEnt);
42cf5bc1 161
162 //! Returns True if an entity is noted as skipped
7f56eba8 163 Standard_EXPORT Standard_Boolean IsSkipped (const Handle(Standard_Transient)& theEnt) const;
42cf5bc1 164
165 //! Returns True if an entity has been asked for transfert, hence
166 //! it is marked, as : Recorded (a computation has ran, with or
167 //! without an effective result), or Skipped (case ignored)
7f56eba8 168 Standard_EXPORT Standard_Boolean IsMarked (const Handle(Standard_Transient)& theEnt) const;
42cf5bc1 169
170 //! Returns the final result recorded for an entity, as such
7f56eba8 171 Standard_EXPORT Handle(Transfer_ResultFromModel) FinalResult (const Handle(Standard_Transient)& theEnt) const;
42cf5bc1 172
173 //! Returns the label attached to an entity recorded for final,
174 //! or an empty string if not recorded
7f56eba8 175 Standard_EXPORT Standard_CString FinalEntityLabel (const Handle(Standard_Transient)& theEnt) const;
42cf5bc1 176
177 //! Returns the number attached to the entity recorded for final,
178 //! or zero if not recorded (looks in the ResultFromModel)
7f56eba8 179 Standard_EXPORT Standard_Integer FinalEntityNumber (const Handle(Standard_Transient)& theEnt) const;
42cf5bc1 180
181 //! Returns the final result recorded for a NUMBER of entity
182 //! (internal use). Null if out of range
7f56eba8 183 Standard_EXPORT Handle(Transfer_ResultFromModel) ResultFromNumber (const Standard_Integer theNum) const;
42cf5bc1 184
185 //! Returns the resulting object as a Transient
186 //! Null Handle if no result or result not transient
7f56eba8 187 Standard_EXPORT Handle(Standard_Transient) TransientResult (const Handle(Standard_Transient)& theEnt) const;
42cf5bc1 188
189 //! Returns the resulting object as a Shape
190 //! Null Shape if no result or result not a shape
7f56eba8 191 Standard_EXPORT TopoDS_Shape ShapeResult (const Handle(Standard_Transient)& theEnt) const;
42cf5bc1 192
193 //! Clears recorded result for an entity, according mode
194 //! <mode> = -1 : true, complete, clearing (erasing result)
195 //! <mode> >= 0 : simple "stripping", see ResultFromModel,
196 //! in particular, 0 for simple internal strip,
197 //! 10 for all but final result,
198 //! 11 for all : just label, status and filename are kept
199 //! Returns True when done, False if nothing was to clear
7f56eba8 200 Standard_EXPORT Standard_Boolean ClearResult (const Handle(Standard_Transient)& theEnt, const Standard_Integer theMode);
42cf5bc1 201
202 //! Returns an entity from which a given result was produced.
203 //! If <mode> = 0 (D), searches in last root transfers
204 //! If <mode> = 1, searches in last (root & sub) transfers
205 //! If <mode> = 2, searches in root recorded results
206 //! If <mode> = 3, searches in all (root & sub) recordeds
207 //! <res> can be, either a transient object (result itself) or
208 //! a binder. For a binder of shape, calls EntityFromShapeResult
209 //! Returns a Null Handle if <res> not recorded
7f56eba8 210 Standard_EXPORT Handle(Standard_Transient) EntityFromResult (const Handle(Standard_Transient)& theRes, const Standard_Integer theMode = 0) const;
42cf5bc1 211
212 //! Returns an entity from which a given shape result was produced
213 //! Returns a Null Handle if <res> not recorded or not a Shape
7f56eba8 214 Standard_EXPORT Handle(Standard_Transient) EntityFromShapeResult (const TopoDS_Shape& theRes, const Standard_Integer theMode = 0) const;
42cf5bc1 215
216 //! Returns the list of entities from which some shapes were
217 //! produced : it corresponds to a loop on EntityFromShapeResult,
218 //! but is optimised
7f56eba8 219 Standard_EXPORT Handle(TColStd_HSequenceOfTransient) EntitiesFromShapeList (const Handle(TopTools_HSequenceOfShape)& theRes, const Standard_Integer theMode = 0) const;
42cf5bc1 220
221 //! Returns the CheckList resulting from transferring <ent>, i.e.
222 //! stored in its recorded form ResultFromModel
223 //! (empty if transfer successful or not recorded ...)
224 //!
225 //! If <ent> is the Model, returns the complete cumulated
226 //! check-list, <level> is ignored
227 //!
228 //! If <ent> is an entity of the Model, <level> applies as follows
229 //! <level> : -1 for <ent> only, LAST transfer (TransientProcess)
230 //! <level> : 0 for <ent> only (D)
231 //! 1 for <ent> and its immediate subtransfers, if any
232 //! 2 for <ent> and subtransferts at all levels
7f56eba8 233 Standard_EXPORT Interface_CheckIterator CheckList (const Handle(Standard_Transient)& theEnt, const Standard_Integer theLevel = 0) const;
42cf5bc1 234
235 //! Returns True if an entity (with a final result) has checks :
236 //! - failsonly = False : any kind of check message
237 //! - failsonly = True : fails only
238 //! Returns False if <ent> is not recorded
7f56eba8 239 Standard_EXPORT Standard_Boolean HasChecks (const Handle(Standard_Transient)& theEnt, const Standard_Boolean FailsOnly) const;
42cf5bc1 240
241 //! Returns the list of starting entities to which a given check
242 //! status is attached, IN FINAL RESULTS
243 //! <ent> can be an entity, or the model to query all entities
244 //! Below, "entities" are, either <ent> plus its sub-transferred,
245 //! or all the entities of the model
246 //!
247 //! <check> = -2 , all entities whatever the check (see result)
248 //! <check> = -1 , entities with no fail (warning allowed)
249 //! <check> = 0 , entities with no check at all
250 //! <check> = 1 , entities with warning but no fail
251 //! <check> = 2 , entities with fail
252 //! <result> : if True, only entities with an attached result
253 //! Remark : result True and check=0 will give an empty list
7f56eba8 254 Standard_EXPORT Handle(TColStd_HSequenceOfTransient) CheckedList (const Handle(Standard_Transient)& theEnt, const Interface_CheckStatus WithCheck = Interface_CheckAny, const Standard_Boolean theResult = Standard_True) const;
42cf5bc1 255
256 //! Defines a new TransferProcess for reading transfer
257 //! Returns True if done, False if data are not properly defined
258 //! (the Model, the Actor for Read)
259 Standard_EXPORT Standard_Boolean BeginTransfer();
260
261 //! Tells if an entity is recognized as a valid candidate for
262 //! Transfer. Calls method Recognize from the Actor (if known)
7f56eba8 263 Standard_EXPORT Standard_Boolean Recognize (const Handle(Standard_Transient)& theEnt);
42cf5bc1 264
265 //! Commands the transfer on reading for an entity to data for
266 //! Imagine, using the selected Actor for Read
267 //! Returns count of transferred entities, ok or with fails (0/1)
268 //! If <rec> is True (D), the result is recorded by RecordResult
7f56eba8 269 Standard_EXPORT Standard_Integer TransferOne (const Handle(Standard_Transient)& theEnt, const Standard_Boolean theRec = Standard_True);
42cf5bc1 270
271 //! Commands the transfer on reading for a list of entities to
272 //! data for Imagine, using the selected Actor for Read
273 //! Returns count of transferred entities, ok or with fails (0/1)
274 //! If <rec> is True (D), the results are recorded by RecordResult
7f56eba8 275 Standard_EXPORT Standard_Integer TransferList (const Handle(TColStd_HSequenceOfTransient)& theList, const Standard_Boolean theRec = Standard_True);
42cf5bc1 276
277 //! Transfers the content of the current Interface Model to
278 //! data handled by Imagine, starting from its Roots (determined
279 //! by the Graph <G>), using the selected Actor for Read
280 //! Returns the count of performed root transfers (i.e. 0 if none)
281 //! or -1 if no actor is defined
7f56eba8 282 Standard_EXPORT Standard_Integer TransferRoots (const Interface_Graph &theGraph);
42cf5bc1 283
284 //! Clears the results attached to an entity
285 //! if <ents> equates the starting model, clears all results
7f56eba8 286 Standard_EXPORT void TransferClear (const Handle(Standard_Transient)& theEnt, const Standard_Integer theLevel = 0);
42cf5bc1 287
288 //! Prints statistics on current Trace File, according <what> and
289 //! <mode>. See PrintStatsProcess for details
7f56eba8 290 Standard_EXPORT void PrintStats (const Standard_Integer theWhat, const Standard_Integer theMode = 0) const;
42cf5bc1 291
292 //! Returns the CheckList resulting from last TransferRead
293 //! i.e. from TransientProcess itself, recorded from last Clear
294 Standard_EXPORT Interface_CheckIterator LastCheckList() const;
295
296 //! Returns the list of entities recorded as lastly transferred
297 //! i.e. from TransientProcess itself, recorded from last Clear
298 //! If <roots> is True , considers only roots of transfer
299 //! If <roots> is False, considers all entities bound with result
7f56eba8 300 Standard_EXPORT Handle(TColStd_HSequenceOfTransient) LastTransferList (const Standard_Boolean theRoots) const;
42cf5bc1 301
302 //! Returns a list of result Shapes
303 //! If <rec> is True , sees RecordedList
304 //! If <rec> is False, sees LastTransferList (last ROOT transfers)
305 //! For each one, if it is a Shape, it is cumulated to the list
306 //! If no Shape is found, returns an empty Sequence
7f56eba8 307 Standard_EXPORT const Handle(TopTools_HSequenceOfShape) & ShapeResultList (const Standard_Boolean theRec);
42cf5bc1 308
309 //! This routines prints statistics about a TransientProcess
310 //! It can be called, by a TransferReader, or isolately
311 //! Prints are done on the default trace file
312 //! <what> defines what kind of statistics are to be printed :
313 //! 0 : basic figures
314 //! 1 : root results
315 //! 2 : all recorded (roots, intermediate, checked entities)
316 //! 3 : abnormal records
317 //! 4 : check messages (warnings and fails)
318 //! 5 : fail messages
319 //!
320 //! <mode> is used according <what> :
321 //! <what> = 0 : <mode> is ignored
322 //! <what> = 1,2,3 : <mode> as follows :
323 //! 0 (D) : just lists numbers of concerned entities in the model
324 //! 1 : for each entity, gives number,label, type and result
325 //! type and/or status (fail/warning...)
326 //! 2 : for each entity, gives maximal information (i.e. checks)
327 //! 3 : counts per type of starting entity (class type)
328 //! 4 : counts per result type and/or status
329 //! 5 : counts per couple (starting type / result type/status)
330 //! 6 : idem plus gives for each item, the list of numbers of
331 //! entities in the starting model
332 //!
333 //! <what> = 4,5 : modes relays on an enum PrintCount :
334 //! 0 (D) : ItemsByEntity (sequential list by entity)
335 //! 1 : CountByItem
336 //! 2 : ShortByItem (count + 5 first numbers)
337 //! 3 : ListByItem (count + entity numbers)
338 //! 4 : EntitiesByItem (count + entity numbers and labels)
7f56eba8 339 Standard_EXPORT static void PrintStatsProcess (const Handle(Transfer_TransientProcess)& theTP, const Standard_Integer theWhat, const Standard_Integer theMode = 0);
42cf5bc1 340
341 //! Works as PrintStatsProcess, but displays data only on the
342 //! entities which are in <list> (filter)
7f56eba8 343 Standard_EXPORT static void PrintStatsOnList (const Handle(Transfer_TransientProcess)& theTP, const Handle(TColStd_HSequenceOfTransient)& theList, const Standard_Integer theWhat, const Standard_Integer theMode = 0);
42cf5bc1 344
92efcf78 345 DEFINE_STANDARD_RTTIEXT(XSControl_TransferReader,MMgt_TShared)
42cf5bc1 346
7f56eba8 347 private:
42cf5bc1 348
7f56eba8 349 Handle(XSControl_Controller) myController;
350 TCollection_AsciiString myFileName;
351 Handle(Interface_InterfaceModel) myModel;
352 Handle(Interface_HGraph) myGraph;
353 Handle(Dico_DictionaryOfTransient) myContext;
354 Handle(Transfer_ActorOfTransientProcess) myActor;
355 Handle(Transfer_TransientProcess) myTP;
356 TColStd_DataMapOfIntegerTransient myResults;
357 Handle(TopTools_HSequenceOfShape) myShapeResult;
42cf5bc1 358};
359
42cf5bc1 360#endif // _XSControl_TransferReader_HeaderFile