Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-01 09:02:53

0001 // Created on: 1995-12-05
0002 // Created by: Christian CAILLET
0003 // Copyright (c) 1995-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _XSControl_TransferReader_HeaderFile
0018 #define _XSControl_TransferReader_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_Type.hxx>
0022 
0023 #include <TCollection_AsciiString.hxx>
0024 #include <Standard_Integer.hxx>
0025 #include <Standard_Transient.hxx>
0026 #include <NCollection_DataMap.hxx>
0027 #include <TopoDS_Shape.hxx>
0028 #include <NCollection_Sequence.hxx>
0029 #include <NCollection_HSequence.hxx>
0030 #include <Interface_CheckStatus.hxx>
0031 #include <Message_ProgressRange.hxx>
0032 
0033 class XSControl_Controller;
0034 class Interface_InterfaceModel;
0035 class Interface_HGraph;
0036 class Transfer_ActorOfTransientProcess;
0037 class Transfer_TransientProcess;
0038 class Transfer_ResultFromModel;
0039 class TopoDS_Shape;
0040 class Interface_CheckIterator;
0041 class Interface_Graph;
0042 
0043 //! A TransferReader performs, manages, handles results of,
0044 //! transfers done when reading a file (i.e. from entities of an
0045 //! InterfaceModel, to objects for Imagine)
0046 //!
0047 //! Running is organised around basic tools : TransientProcess and
0048 //! its Actor, results are Binders and CheckIterators. It implies
0049 //! control by a Controller (which prepares the Actor as required)
0050 //!
0051 //! Getting results can be done directly on TransientProcess, but
0052 //! these are immediate "last produced" results. Each transfer of
0053 //! an entity gives a final result, but also possible intermediate
0054 //! data, and checks, which can be attached to sub-entities.
0055 //!
0056 //! Hence, final results (which intermediates and checks) are
0057 //! recorded as ResultFromModel and can be queried individually.
0058 //!
0059 //! Some more direct access are given for results which are
0060 //! Transient or Shapes
0061 class XSControl_TransferReader : public Standard_Transient
0062 {
0063 public:
0064   //! Creates a TransferReader, empty
0065   XSControl_TransferReader() = default;
0066 
0067   //! Sets a Controller. It is required to generate the Actor.
0068   //! Elsewhere, the Actor must be provided directly
0069   Standard_EXPORT void SetController(const occ::handle<XSControl_Controller>& theControl);
0070 
0071   //! Sets the Actor directly : this value will be used if the
0072   //! Controller is not set
0073   void SetActor(const occ::handle<Transfer_ActorOfTransientProcess>& theActor)
0074   {
0075     myActor = theActor;
0076   }
0077 
0078   //! Returns the Actor, determined by the Controller, or if this
0079   //! one is unknown, directly set.
0080   //! Once it has been defined, it can then be edited.
0081   Standard_EXPORT occ::handle<Transfer_ActorOfTransientProcess> Actor();
0082 
0083   //! Sets an InterfaceModel. This causes former results, computed
0084   //! from another one, to be lost (see also Clear)
0085   Standard_EXPORT void SetModel(const occ::handle<Interface_InterfaceModel>& theModel);
0086 
0087   //! Sets a Graph and its InterfaceModel (calls SetModel)
0088   Standard_EXPORT void SetGraph(const occ::handle<Interface_HGraph>& theGraph);
0089 
0090   //! Returns the currently set InterfaceModel
0091   const occ::handle<Interface_InterfaceModel>& Model() const { return myModel; }
0092 
0093   //! Sets a Context : according to receiving appli, to be
0094   //! interpreted by the Actor
0095   Standard_EXPORT void SetContext(const char* const                      theName,
0096                                   const occ::handle<Standard_Transient>& theCtx);
0097 
0098   //! Returns the Context attached to a name, if set and if it is
0099   //! Kind of the type, else a Null Handle
0100   //! Returns True if OK, False if no Context
0101   Standard_EXPORT bool GetContext(const char* const                 theName,
0102                                   const occ::handle<Standard_Type>& theType,
0103                                   occ::handle<Standard_Transient>&  theCtx) const;
0104 
0105   //! Returns (modifiable) the whole definition of Context
0106   //! Rather for internal use (ex.: preparing and setting in once)
0107   NCollection_DataMap<TCollection_AsciiString, occ::handle<Standard_Transient>>& Context()
0108   {
0109     return myContext;
0110   }
0111 
0112   //! Sets a new value for (loaded) file name
0113   void SetFileName(const char* const theName) { myFileName = theName; }
0114 
0115   //! Returns actual value of file name
0116   const char* FileName() const { return myFileName.ToCString(); }
0117 
0118   //! Clears data, according mode :
0119   //! -1 all
0120   //! 0 nothing done
0121   //! +1 final results
0122   //! +2 working data (model, context, transfer process)
0123   Standard_EXPORT void Clear(const int theMode);
0124 
0125   //! Returns the currently used TransientProcess
0126   //! It is computed from the model by TransferReadRoots, or by
0127   //! BeginTransferRead
0128   const occ::handle<Transfer_TransientProcess>& TransientProcess() const { return myTP; }
0129 
0130   //! Forces the TransientProcess
0131   //! Remark : it also changes the Model and the Actor, from those
0132   //! recorded in the new TransientProcess
0133   void SetTransientProcess(const occ::handle<Transfer_TransientProcess>& theTP) { myTP = theTP; }
0134 
0135   //! Records a final result of transferring an entity
0136   //! This result is recorded as a ResultFromModel, taken from
0137   //! the TransientProcess
0138   //! Returns True if a result is available, False else
0139   Standard_EXPORT bool RecordResult(const occ::handle<Standard_Transient>& theEnt);
0140 
0141   //! Returns True if a final result is recorded for an entity
0142   //! Remark that it can bring no effective result if transfer has
0143   //! completely failed (FinalResult brings only fail messages ...)
0144   Standard_EXPORT bool IsRecorded(const occ::handle<Standard_Transient>& theEnt) const;
0145 
0146   //! Returns True if a final result is recorded AND BRINGS AN
0147   //! EFFECTIVE RESULT (else, it brings only fail messages)
0148   Standard_EXPORT bool HasResult(const occ::handle<Standard_Transient>& theEnt) const;
0149 
0150   //! Returns the list of entities to which a final result is
0151   //! attached (i.e. processed by RecordResult)
0152   Standard_EXPORT occ::handle<NCollection_HSequence<occ::handle<Standard_Transient>>> RecordedList()
0153     const;
0154 
0155   //! Note that an entity has been required for transfer but no
0156   //! result at all is available (typically : case not implemented)
0157   //! It is not an error, but it gives a specific status : Skipped
0158   //! Returns True if done, False if <ent> is not in starting model
0159   Standard_EXPORT bool Skip(const occ::handle<Standard_Transient>& theEnt);
0160 
0161   //! Returns True if an entity is noted as skipped
0162   Standard_EXPORT bool IsSkipped(const occ::handle<Standard_Transient>& theEnt) const;
0163 
0164   //! Returns True if an entity has been asked for transfert, hence
0165   //! it is marked, as : Recorded (a computation has ran, with or
0166   //! without an effective result), or Skipped (case ignored)
0167   Standard_EXPORT bool IsMarked(const occ::handle<Standard_Transient>& theEnt) const;
0168 
0169   //! Returns the final result recorded for an entity, as such
0170   Standard_EXPORT occ::handle<Transfer_ResultFromModel> FinalResult(
0171     const occ::handle<Standard_Transient>& theEnt) const;
0172 
0173   //! Returns the label attached to an entity recorded for final,
0174   //! or an empty string if not recorded
0175   Standard_EXPORT const char* FinalEntityLabel(const occ::handle<Standard_Transient>& theEnt) const;
0176 
0177   //! Returns the number attached to the entity recorded for final,
0178   //! or zero if not recorded (looks in the ResultFromModel)
0179   Standard_EXPORT int FinalEntityNumber(const occ::handle<Standard_Transient>& theEnt) const;
0180 
0181   //! Returns the final result recorded for a NUMBER of entity
0182   //! (internal use). Null if out of range
0183   Standard_EXPORT occ::handle<Transfer_ResultFromModel> ResultFromNumber(const int theNum) const;
0184 
0185   //! Returns the resulting object as a Transient
0186   //! Null Handle if no result or result not transient
0187   Standard_EXPORT occ::handle<Standard_Transient> TransientResult(
0188     const occ::handle<Standard_Transient>& theEnt) const;
0189 
0190   //! Returns the resulting object as a Shape
0191   //! Null Shape if no result or result not a shape
0192   Standard_EXPORT TopoDS_Shape ShapeResult(const occ::handle<Standard_Transient>& theEnt) const;
0193 
0194   //! Clears recorded result for an entity, according mode
0195   //! <mode> = -1 : true, complete, clearing (erasing result)
0196   //! <mode> >= 0 : simple "stripping", see ResultFromModel,
0197   //! in particular, 0 for simple internal strip,
0198   //! 10 for all but final result,
0199   //! 11 for all : just label, status and filename are kept
0200   //! Returns True when done, False if nothing was to clear
0201   Standard_EXPORT bool ClearResult(const occ::handle<Standard_Transient>& theEnt,
0202                                    const int                              theMode);
0203 
0204   //! Returns an entity from which a given result was produced.
0205   //! If <mode> = 0 (D), searches in last root transfers
0206   //! If <mode> = 1,     searches in last (root & sub) transfers
0207   //! If <mode> = 2,     searches in root recorded results
0208   //! If <mode> = 3,     searches in all (root & sub) recordeds
0209   //! <res> can be, either a transient object (result itself) or
0210   //! a binder. For a binder of shape, calls EntityFromShapeResult
0211   //! Returns a Null Handle if <res> not recorded
0212   Standard_EXPORT occ::handle<Standard_Transient> EntityFromResult(
0213     const occ::handle<Standard_Transient>& theRes,
0214     const int                              theMode = 0) const;
0215 
0216   //! Returns an entity from which a given shape result was produced
0217   //! Returns a Null Handle if <res> not recorded or not a Shape
0218   Standard_EXPORT occ::handle<Standard_Transient> EntityFromShapeResult(
0219     const TopoDS_Shape& theRes,
0220     const int           theMode = 0) const;
0221 
0222   //! Returns the list of entities from which some shapes were
0223   //! produced : it corresponds to a loop on EntityFromShapeResult,
0224   //! but is optimised
0225   Standard_EXPORT occ::handle<NCollection_HSequence<occ::handle<Standard_Transient>>>
0226     EntitiesFromShapeList(const occ::handle<NCollection_HSequence<TopoDS_Shape>>& theRes,
0227                           const int theMode = 0) const;
0228 
0229   //! Returns the CheckList resulting from transferring <ent>, i.e.
0230   //! stored in its recorded form ResultFromModel
0231   //! (empty if transfer successful or not recorded ...)
0232   //!
0233   //! If <ent> is the Model, returns the complete cumulated
0234   //! check-list, <level> is ignored
0235   //!
0236   //! If <ent> is an entity of the Model, <level> applies as follows
0237   //! <level> : -1 for <ent> only, LAST transfer (TransientProcess)
0238   //! <level> : 0  for <ent> only (D)
0239   //! 1  for <ent> and its immediate subtransfers, if any
0240   //! 2  for <ent> and subtransferts at all levels
0241   Standard_EXPORT Interface_CheckIterator CheckList(const occ::handle<Standard_Transient>& theEnt,
0242                                                     const int theLevel = 0) const;
0243 
0244   //! Returns True if an entity (with a final result) has checks :
0245   //! - failsonly = False : any kind of check message
0246   //! - failsonly = True  : fails only
0247   //! Returns False if <ent> is not recorded
0248   Standard_EXPORT bool HasChecks(const occ::handle<Standard_Transient>& theEnt,
0249                                  const bool                             FailsOnly) const;
0250 
0251   //! Returns the list of starting entities to which a given check
0252   //! status is attached, IN FINAL RESULTS
0253   //! <ent> can be an entity, or the model to query all entities
0254   //! Below, "entities" are, either <ent> plus its sub-transferred,
0255   //! or all the entities of the model
0256   //!
0257   //! <check> = -2 , all entities whatever the check (see result)
0258   //! <check> = -1 , entities with no fail (warning allowed)
0259   //! <check> =  0 , entities with no check at all
0260   //! <check> =  1 , entities with warning but no fail
0261   //! <check> =  2 , entities with fail
0262   //! <result> : if True, only entities with an attached result
0263   //! Remark : result True and check=0 will give an empty list
0264   Standard_EXPORT occ::handle<NCollection_HSequence<occ::handle<Standard_Transient>>> CheckedList(
0265     const occ::handle<Standard_Transient>& theEnt,
0266     const Interface_CheckStatus            WithCheck = Interface_CheckAny,
0267     const bool                             theResult = true) const;
0268 
0269   //! Defines a new TransferProcess for reading transfer
0270   //! Returns True if done, False if data are not properly defined
0271   //! (the Model, the Actor for Read)
0272   Standard_EXPORT bool BeginTransfer();
0273 
0274   //! Tells if an entity is recognized as a valid candidate for
0275   //! Transfer. Calls method Recognize from the Actor (if known)
0276   Standard_EXPORT bool Recognize(const occ::handle<Standard_Transient>& theEnt);
0277 
0278   //! Commands the transfer on reading for an entity to data for
0279   //! Imagine, using the selected Actor for Read
0280   //! Returns count of transferred entities, ok or with fails (0/1)
0281   //! If <rec> is True (D), the result is recorded by RecordResult
0282   Standard_EXPORT int TransferOne(
0283     const occ::handle<Standard_Transient>& theEnt,
0284     const bool                             theRec      = true,
0285     const Message_ProgressRange&           theProgress = Message_ProgressRange());
0286 
0287   //! Commands the transfer on reading for a list of entities to
0288   //! data for Imagine, using the selected Actor for Read
0289   //! Returns count of transferred entities, ok or with fails (0/1)
0290   //! If <rec> is True (D), the results are recorded by RecordResult
0291   Standard_EXPORT int TransferList(
0292     const occ::handle<NCollection_HSequence<occ::handle<Standard_Transient>>>& theList,
0293     const bool                                                                 theRec = true,
0294     const Message_ProgressRange& theProgress = Message_ProgressRange());
0295 
0296   //! Transfers the content of the current Interface Model to
0297   //! data handled by Imagine, starting from its Roots (determined
0298   //! by the Graph <G>), using the selected Actor for Read
0299   //! Returns the count of performed root transfers (i.e. 0 if none)
0300   //! or -1 if no actor is defined
0301   Standard_EXPORT int TransferRoots(
0302     const Interface_Graph&       theGraph,
0303     const Message_ProgressRange& theProgress = Message_ProgressRange());
0304 
0305   //! Clears the results attached to an entity
0306   //! if <ents> equates the starting model, clears all results
0307   Standard_EXPORT void TransferClear(const occ::handle<Standard_Transient>& theEnt,
0308                                      const int                              theLevel = 0);
0309 
0310   //! Prints statistics on current Trace File, according <what> and
0311   //! <mode>. See PrintStatsProcess for details
0312   Standard_EXPORT void PrintStats(Standard_OStream& theStream,
0313                                   const int         theWhat,
0314                                   const int         theMode = 0) const;
0315 
0316   //! Returns the CheckList resulting from last TransferRead
0317   //! i.e. from TransientProcess itself, recorded from last Clear
0318   Standard_EXPORT Interface_CheckIterator LastCheckList() const;
0319 
0320   //! Returns the list of entities recorded as lastly transferred
0321   //! i.e. from TransientProcess itself, recorded from last Clear
0322   //! If <roots> is True , considers only roots of transfer
0323   //! If <roots> is False, considers all entities bound with result
0324   Standard_EXPORT occ::handle<NCollection_HSequence<occ::handle<Standard_Transient>>>
0325                   LastTransferList(const bool theRoots) const;
0326 
0327   //! Returns a list of result Shapes
0328   //! If <rec> is True , sees RecordedList
0329   //! If <rec> is False, sees LastTransferList (last ROOT transfers)
0330   //! For each one, if it is a Shape, it is cumulated to the list
0331   //! If no Shape is found, returns an empty Sequence
0332   Standard_EXPORT const occ::handle<NCollection_HSequence<TopoDS_Shape>>& ShapeResultList(
0333     const bool theRec);
0334 
0335   //! This routines prints statistics about a TransientProcess
0336   //! It can be called, by a TransferReader, or isolately
0337   //! Prints are done on the default trace file
0338   //! <what> defines what kind of statistics are to be printed :
0339   //! 0 : basic figures
0340   //! 1 : root results
0341   //! 2 : all recorded (roots, intermediate, checked entities)
0342   //! 3 : abnormal records
0343   //! 4 : check messages (warnings and fails)
0344   //! 5 : fail messages
0345   //!
0346   //! <mode> is used according <what> :
0347   //! <what> = 0 : <mode> is ignored
0348   //! <what> = 1,2,3 : <mode> as follows :
0349   //! 0 (D) : just lists numbers of concerned entities in the model
0350   //! 1 : for each entity, gives number,label, type and result
0351   //! type and/or status (fail/warning...)
0352   //! 2 : for each entity, gives maximal information (i.e. checks)
0353   //! 3 : counts per type of starting entity (class type)
0354   //! 4 : counts per result type and/or status
0355   //! 5 : counts per couple (starting type / result type/status)
0356   //! 6 : idem plus gives for each item, the list of numbers of
0357   //! entities in the starting model
0358   //!
0359   //! <what> = 4,5 : modes relays on an enum PrintCount :
0360   //! 0 (D) : ItemsByEntity (sequential list by entity)
0361   //! 1 : CountByItem
0362   //! 2 : ShortByItem       (count + 5 first numbers)
0363   //! 3 : ListByItem        (count + entity numbers)
0364   //! 4 : EntitiesByItem    (count + entity numbers and labels)
0365   Standard_EXPORT static void PrintStatsProcess(const occ::handle<Transfer_TransientProcess>& theTP,
0366                                                 const int theWhat,
0367                                                 const int theMode = 0);
0368 
0369   //! Works as PrintStatsProcess, but displays data only on the
0370   //! entities which are in <list> (filter)
0371   Standard_EXPORT static void PrintStatsOnList(
0372     const occ::handle<Transfer_TransientProcess>&                              theTP,
0373     const occ::handle<NCollection_HSequence<occ::handle<Standard_Transient>>>& theList,
0374     const int                                                                  theWhat,
0375     const int                                                                  theMode = 0);
0376 
0377   DEFINE_STANDARD_RTTIEXT(XSControl_TransferReader, Standard_Transient)
0378 
0379 private:
0380   occ::handle<XSControl_Controller>                                             myController;
0381   TCollection_AsciiString                                                       myFileName;
0382   occ::handle<Interface_InterfaceModel>                                         myModel;
0383   occ::handle<Interface_HGraph>                                                 myGraph;
0384   NCollection_DataMap<TCollection_AsciiString, occ::handle<Standard_Transient>> myContext;
0385   occ::handle<Transfer_ActorOfTransientProcess>                                 myActor;
0386   occ::handle<Transfer_TransientProcess>                                        myTP;
0387   NCollection_DataMap<int, occ::handle<Standard_Transient>>                     myResults;
0388   occ::handle<NCollection_HSequence<TopoDS_Shape>>                              myShapeResult;
0389 };
0390 
0391 #endif // _XSControl_TransferReader_HeaderFile