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
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_TransferReader_HeaderFile
18 #define _XSControl_TransferReader_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <TCollection_AsciiString.hxx>
24 #include <TColStd_DataMapOfIntegerTransient.hxx>
25 #include <TopTools_HSequenceOfShape.hxx>
26 #include <Standard_Transient.hxx>
27 #include <TColStd_HSequenceOfTransient.hxx>
28 #include <Interface_CheckStatus.hxx>
29 #include <Message_ProgressRange.hxx>
31 class XSControl_Controller;
32 class Interface_InterfaceModel;
33 class Interface_HGraph;
34 class Transfer_ActorOfTransientProcess;
35 class Transfer_TransientProcess;
36 class Standard_Transient;
37 class Transfer_ResultFromModel;
39 class Interface_CheckIterator;
40 class Interface_Graph;
42 class XSControl_TransferReader;
43 DEFINE_STANDARD_HANDLE(XSControl_TransferReader, Standard_Transient)
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)
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)
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.
58 //! Hence, final results (which intermediates and checks) are
59 //! recorded as ResultFromModel and can be queried individually.
61 //! Some more direct access are given for results which are
62 //! Transient or Shapes
63 class XSControl_TransferReader : public Standard_Transient
67 //! Creates a TransferReader, empty
68 XSControl_TransferReader()
71 //! Sets a Controller. It is required to generate the Actor.
72 //! Elsewhere, the Actor must be provided directly
73 Standard_EXPORT void SetController (const Handle(XSControl_Controller)& theControl);
75 //! Sets the Actor directly : this value will be used if the
76 //! Controller is not set
77 void SetActor (const Handle(Transfer_ActorOfTransientProcess)& theActor)
78 { myActor = theActor; }
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();
85 //! Sets an InterfaceModel. This causes former results, computed
86 //! from another one, to be lost (see also Clear)
87 Standard_EXPORT void SetModel (const Handle(Interface_InterfaceModel)& theModel);
89 //! Sets a Graph and its InterfaceModel (calls SetModel)
90 Standard_EXPORT void SetGraph (const Handle(Interface_HGraph)& theGraph);
92 //! Returns the currently set InterfaceModel
93 const Handle(Interface_InterfaceModel) & Model() const
96 //! Sets a Context : according to receiving appli, to be
97 //! interpreted by the Actor
98 Standard_EXPORT void SetContext (const Standard_CString theName, const Handle(Standard_Transient)& theCtx);
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
103 Standard_EXPORT Standard_Boolean GetContext (const Standard_CString theName, const Handle(Standard_Type)& theType, Handle(Standard_Transient)& theCtx) const;
105 //! Returns (modifiable) the whole definition of Context
106 //! Rather for internal use (ex.: preparing and setting in once)
107 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& Context()
108 { return myContext; }
110 //! Sets a new value for (loaded) file name
111 void SetFileName (const Standard_CString theName)
112 { myFileName = theName; }
114 //! Returns actual value of file name
115 Standard_CString FileName() const
116 { return myFileName.ToCString(); }
118 //! Clears data, according mode :
122 //! +2 working data (model, context, transfer process)
123 Standard_EXPORT void Clear (const Standard_Integer theMode);
125 //! Returns the currently used TransientProcess
126 //! It is computed from the model by TransferReadRoots, or by
127 //! BeginTransferRead
128 const Handle(Transfer_TransientProcess) & TransientProcess () const
131 //! Forces the TransientProcess
132 //! Remark : it also changes the Model and the Actor, from those
133 //! recorded in the new TransientProcess
134 void SetTransientProcess (const Handle(Transfer_TransientProcess)& theTP)
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
141 Standard_EXPORT Standard_Boolean RecordResult (const Handle(Standard_Transient)& theEnt);
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 ...)
146 Standard_EXPORT Standard_Boolean IsRecorded (const Handle(Standard_Transient)& theEnt) const;
148 //! Returns True if a final result is recorded AND BRINGS AN
149 //! EFFECTIVE RESULT (else, it brings only fail messages)
150 Standard_EXPORT Standard_Boolean HasResult (const Handle(Standard_Transient)& theEnt) const;
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;
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
160 Standard_EXPORT Standard_Boolean Skip (const Handle(Standard_Transient)& theEnt);
162 //! Returns True if an entity is noted as skipped
163 Standard_EXPORT Standard_Boolean IsSkipped (const Handle(Standard_Transient)& theEnt) const;
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)
168 Standard_EXPORT Standard_Boolean IsMarked (const Handle(Standard_Transient)& theEnt) const;
170 //! Returns the final result recorded for an entity, as such
171 Standard_EXPORT Handle(Transfer_ResultFromModel) FinalResult (const Handle(Standard_Transient)& theEnt) const;
173 //! Returns the label attached to an entity recorded for final,
174 //! or an empty string if not recorded
175 Standard_EXPORT Standard_CString FinalEntityLabel (const Handle(Standard_Transient)& theEnt) const;
177 //! Returns the number attached to the entity recorded for final,
178 //! or zero if not recorded (looks in the ResultFromModel)
179 Standard_EXPORT Standard_Integer FinalEntityNumber (const Handle(Standard_Transient)& theEnt) const;
181 //! Returns the final result recorded for a NUMBER of entity
182 //! (internal use). Null if out of range
183 Standard_EXPORT Handle(Transfer_ResultFromModel) ResultFromNumber (const Standard_Integer theNum) const;
185 //! Returns the resulting object as a Transient
186 //! Null Handle if no result or result not transient
187 Standard_EXPORT Handle(Standard_Transient) TransientResult (const Handle(Standard_Transient)& theEnt) const;
189 //! Returns the resulting object as a Shape
190 //! Null Shape if no result or result not a shape
191 Standard_EXPORT TopoDS_Shape ShapeResult (const Handle(Standard_Transient)& theEnt) const;
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
200 Standard_EXPORT Standard_Boolean ClearResult (const Handle(Standard_Transient)& theEnt, const Standard_Integer theMode);
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
210 Standard_EXPORT Handle(Standard_Transient) EntityFromResult (const Handle(Standard_Transient)& theRes, const Standard_Integer theMode = 0) const;
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
214 Standard_EXPORT Handle(Standard_Transient) EntityFromShapeResult (const TopoDS_Shape& theRes, const Standard_Integer theMode = 0) const;
216 //! Returns the list of entities from which some shapes were
217 //! produced : it corresponds to a loop on EntityFromShapeResult,
219 Standard_EXPORT Handle(TColStd_HSequenceOfTransient) EntitiesFromShapeList (const Handle(TopTools_HSequenceOfShape)& theRes, const Standard_Integer theMode = 0) const;
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 ...)
225 //! If <ent> is the Model, returns the complete cumulated
226 //! check-list, <level> is ignored
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
233 Standard_EXPORT Interface_CheckIterator CheckList (const Handle(Standard_Transient)& theEnt, const Standard_Integer theLevel = 0) const;
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
239 Standard_EXPORT Standard_Boolean HasChecks (const Handle(Standard_Transient)& theEnt, const Standard_Boolean FailsOnly) const;
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
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
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;
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();
261 //! Tells if an entity is recognized as a valid candidate for
262 //! Transfer. Calls method Recognize from the Actor (if known)
263 Standard_EXPORT Standard_Boolean Recognize (const Handle(Standard_Transient)& theEnt);
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
269 Standard_EXPORT Standard_Integer TransferOne (const Handle(Standard_Transient)& theEnt,
270 const Standard_Boolean theRec = Standard_True,
271 const Message_ProgressRange& theProgress = Message_ProgressRange());
273 //! Commands the transfer on reading for a list of entities to
274 //! data for Imagine, using the selected Actor for Read
275 //! Returns count of transferred entities, ok or with fails (0/1)
276 //! If <rec> is True (D), the results are recorded by RecordResult
277 Standard_EXPORT Standard_Integer TransferList (const Handle(TColStd_HSequenceOfTransient)& theList,
278 const Standard_Boolean theRec = Standard_True,
279 const Message_ProgressRange& theProgress = Message_ProgressRange());
281 //! Transfers the content of the current Interface Model to
282 //! data handled by Imagine, starting from its Roots (determined
283 //! by the Graph <G>), using the selected Actor for Read
284 //! Returns the count of performed root transfers (i.e. 0 if none)
285 //! or -1 if no actor is defined
286 Standard_EXPORT Standard_Integer TransferRoots (const Interface_Graph &theGraph,
287 const Message_ProgressRange& theProgress = Message_ProgressRange());
289 //! Clears the results attached to an entity
290 //! if <ents> equates the starting model, clears all results
291 Standard_EXPORT void TransferClear (const Handle(Standard_Transient)& theEnt, const Standard_Integer theLevel = 0);
293 //! Prints statistics on current Trace File, according <what> and
294 //! <mode>. See PrintStatsProcess for details
295 Standard_EXPORT void PrintStats (Standard_OStream& theStream, const Standard_Integer theWhat, const Standard_Integer theMode = 0) const;
297 //! Returns the CheckList resulting from last TransferRead
298 //! i.e. from TransientProcess itself, recorded from last Clear
299 Standard_EXPORT Interface_CheckIterator LastCheckList() const;
301 //! Returns the list of entities recorded as lastly transferred
302 //! i.e. from TransientProcess itself, recorded from last Clear
303 //! If <roots> is True , considers only roots of transfer
304 //! If <roots> is False, considers all entities bound with result
305 Standard_EXPORT Handle(TColStd_HSequenceOfTransient) LastTransferList (const Standard_Boolean theRoots) const;
307 //! Returns a list of result Shapes
308 //! If <rec> is True , sees RecordedList
309 //! If <rec> is False, sees LastTransferList (last ROOT transfers)
310 //! For each one, if it is a Shape, it is cumulated to the list
311 //! If no Shape is found, returns an empty Sequence
312 Standard_EXPORT const Handle(TopTools_HSequenceOfShape) & ShapeResultList (const Standard_Boolean theRec);
314 //! This routines prints statistics about a TransientProcess
315 //! It can be called, by a TransferReader, or isolately
316 //! Prints are done on the default trace file
317 //! <what> defines what kind of statistics are to be printed :
318 //! 0 : basic figures
320 //! 2 : all recorded (roots, intermediate, checked entities)
321 //! 3 : abnormal records
322 //! 4 : check messages (warnings and fails)
323 //! 5 : fail messages
325 //! <mode> is used according <what> :
326 //! <what> = 0 : <mode> is ignored
327 //! <what> = 1,2,3 : <mode> as follows :
328 //! 0 (D) : just lists numbers of concerned entities in the model
329 //! 1 : for each entity, gives number,label, type and result
330 //! type and/or status (fail/warning...)
331 //! 2 : for each entity, gives maximal information (i.e. checks)
332 //! 3 : counts per type of starting entity (class type)
333 //! 4 : counts per result type and/or status
334 //! 5 : counts per couple (starting type / result type/status)
335 //! 6 : idem plus gives for each item, the list of numbers of
336 //! entities in the starting model
338 //! <what> = 4,5 : modes relays on an enum PrintCount :
339 //! 0 (D) : ItemsByEntity (sequential list by entity)
341 //! 2 : ShortByItem (count + 5 first numbers)
342 //! 3 : ListByItem (count + entity numbers)
343 //! 4 : EntitiesByItem (count + entity numbers and labels)
344 Standard_EXPORT static void PrintStatsProcess (const Handle(Transfer_TransientProcess)& theTP, const Standard_Integer theWhat, const Standard_Integer theMode = 0);
346 //! Works as PrintStatsProcess, but displays data only on the
347 //! entities which are in <list> (filter)
348 Standard_EXPORT static void PrintStatsOnList (const Handle(Transfer_TransientProcess)& theTP, const Handle(TColStd_HSequenceOfTransient)& theList, const Standard_Integer theWhat, const Standard_Integer theMode = 0);
350 DEFINE_STANDARD_RTTIEXT(XSControl_TransferReader,Standard_Transient)
354 Handle(XSControl_Controller) myController;
355 TCollection_AsciiString myFileName;
356 Handle(Interface_InterfaceModel) myModel;
357 Handle(Interface_HGraph) myGraph;
358 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> myContext;
359 Handle(Transfer_ActorOfTransientProcess) myActor;
360 Handle(Transfer_TransientProcess) myTP;
361 TColStd_DataMapOfIntegerTransient myResults;
362 Handle(TopTools_HSequenceOfShape) myShapeResult;
365 #endif // _XSControl_TransferReader_HeaderFile