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