Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:22:32

0001 // Created on: 1992-02-03
0002 // Created by: Christian CAILLET
0003 // Copyright (c) 1992-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 _Transfer_ProcessForTransient_HeaderFile
0018 #define _Transfer_ProcessForTransient_HeaderFile
0019 
0020 #include <Standard_Integer.hxx>
0021 #include <NCollection_IndexedMap.hxx>
0022 #include <NCollection_IndexedDataMap.hxx>
0023 #include <Transfer_Binder.hxx>
0024 #include <Message_ProgressRange.hxx>
0025 
0026 class Message_Messenger;
0027 class Transfer_Binder;
0028 class Transfer_ActorOfProcessForTransient;
0029 class Interface_InterfaceError;
0030 class Transfer_TransferFailure;
0031 class Transfer_IteratorOfProcessForTransient;
0032 class Message_Msg;
0033 class Interface_Check;
0034 class Interface_CheckIterator;
0035 
0036 //! Manages Transfer of Transient Objects. Produces also
0037 //! ActorOfTransientProcess       (deferred class),
0038 //! IteratorOfTransientProcess    (for Results),
0039 //! TransferMapOfTransientProcess (internally used)
0040 //! Normally uses as TransientProcess, which adds some specifics
0041 
0042 class Transfer_ProcessForTransient : public Standard_Transient
0043 {
0044 
0045 public:
0046   //! Sets TransferProcess at initial state. Gives an Initial size
0047   //! (indicative) for the Map when known (default is 10000).
0048   //! Sets default trace file as a printer and default trace level
0049   //! (see Message_TraceFile).
0050   Standard_EXPORT Transfer_ProcessForTransient(const int nb = 10000);
0051 
0052   //! Sets TransferProcess at initial state. Gives an Initial size
0053   //! (indicative) for the Map when known (default is 10000).
0054   //! Sets a specified printer.
0055   Standard_EXPORT Transfer_ProcessForTransient(const occ::handle<Message_Messenger>& printer,
0056                                                const int                             nb = 10000);
0057 
0058   //! Resets a TransferProcess as ready for a completely new work.
0059   //! Clears general data (roots) and the Map
0060   Standard_EXPORT void Clear();
0061 
0062   //! Rebuilds the Map and the roots to really remove Unbound items
0063   //! Because Unbind keeps the entity in place, even if not bound
0064   //! Hence, working by checking new items is meaningless if a
0065   //! formerly unbound item is rebound
0066   Standard_EXPORT void Clean();
0067 
0068   //! Resizes the Map as required (if a new reliable value has been
0069   //! determined). Acts only if <nb> is greater than actual NbMapped
0070   Standard_EXPORT void Resize(const int nb);
0071 
0072   //! Defines an Actor, which is used for automatic Transfer
0073   //! If already defined, the new Actor is cumulated
0074   //! (see SetNext from Actor)
0075   Standard_EXPORT void SetActor(const occ::handle<Transfer_ActorOfProcessForTransient>& actor);
0076 
0077   //! Returns the defined Actor. Returns a Null Handle if
0078   //! not set.
0079   Standard_EXPORT occ::handle<Transfer_ActorOfProcessForTransient> Actor() const;
0080 
0081   //! Returns the Binder which is linked with a starting Object
0082   //! It can either bring a Result (Transfer done) or none (for a
0083   //! pre-binding).
0084   //! If no Binder is linked with <start>, returns a Null Handle
0085   //! Considers a category number, by default 0
0086   Standard_EXPORT occ::handle<Transfer_Binder> Find(
0087     const occ::handle<Standard_Transient>& start) const;
0088 
0089   //! Returns True if a Result (whatever its form) is Bound with
0090   //! a starting Object. I.e., if a Binder with a Result set,
0091   //! is linked with it
0092   //! Considers a category number, by default 0
0093   Standard_EXPORT bool IsBound(const occ::handle<Standard_Transient>& start) const;
0094 
0095   //! Returns True if the result of the transfer of an object is
0096   //! already used in other ones. If it is, Rebind cannot change it.
0097   //! Considers a category number, by default 0
0098   Standard_EXPORT bool IsAlreadyUsed(const occ::handle<Standard_Transient>& start) const;
0099 
0100   //! Creates a Link a starting Object with a Binder. This Binder
0101   //! can either bring a Result (effective Binding) or none (it can
0102   //! be set later : pre-binding).
0103   //! Considers a category number, by default 0
0104   Standard_EXPORT void Bind(const occ::handle<Standard_Transient>& start,
0105                             const occ::handle<Transfer_Binder>&    binder);
0106 
0107   //! Changes the Binder linked with a starting Object for its
0108   //! unitary transfer. This it can be useful when the exact form
0109   //! of the result is known once the transfer is widely engaged.
0110   //! This can be done only on first transfer.
0111   //! Considers a category number, by default 0
0112   Standard_EXPORT void Rebind(const occ::handle<Standard_Transient>& start,
0113                               const occ::handle<Transfer_Binder>&    binder);
0114 
0115   //! Removes the Binder linked with a starting object
0116   //! If this Binder brings a non-empty Check, it is replaced by
0117   //! a VoidBinder. Also removes from the list of Roots as required.
0118   //! Returns True if done, False if <start> was not bound
0119   //! Considers a category number, by default 0
0120   Standard_EXPORT bool Unbind(const occ::handle<Standard_Transient>& start);
0121 
0122   //! Returns a Binder for a starting entity, as follows :
0123   //! Tries to Find the already bound one
0124   //! If none found, creates a VoidBinder and Binds it
0125   Standard_EXPORT occ::handle<Transfer_Binder> FindElseBind(
0126     const occ::handle<Standard_Transient>& start);
0127 
0128   //! Sets Messenger used for outputting messages.
0129   Standard_EXPORT void SetMessenger(const occ::handle<Message_Messenger>& messenger);
0130 
0131   //! Returns Messenger used for outputting messages.
0132   //! The returned object is guaranteed to be non-null;
0133   //! default is Message::Messenger().
0134   Standard_EXPORT occ::handle<Message_Messenger> Messenger() const;
0135 
0136   //! Sets trace level used for outputting messages:
0137   //! <trace> = 0 : no trace at all
0138   //! <trace> = 1 : handled exceptions and calls to AddError
0139   //! <trace> = 2 : also calls to AddWarning
0140   //! <trace> = 3 : also traces new Roots
0141   //! (uses method ErrorTrace).
0142   //! Default is 1 : Errors traced
0143   Standard_EXPORT void SetTraceLevel(const int tracelev);
0144 
0145   //! Returns trace level used for outputting messages.
0146   Standard_EXPORT int TraceLevel() const;
0147 
0148   //! New name for AddFail (Msg)
0149   Standard_EXPORT void SendFail(const occ::handle<Standard_Transient>& start,
0150                                 const Message_Msg&                     amsg);
0151 
0152   //! New name for AddWarning (Msg)
0153   Standard_EXPORT void SendWarning(const occ::handle<Standard_Transient>& start,
0154                                    const Message_Msg&                     amsg);
0155 
0156   //! Adds an information message
0157   //! Trace is filled if trace level is at least 3
0158   Standard_EXPORT void SendMsg(const occ::handle<Standard_Transient>& start,
0159                                const Message_Msg&                     amsg);
0160 
0161   //! Adds an Error message to a starting entity (to the check of
0162   //! its Binder of category 0, as a Fail)
0163   Standard_EXPORT void AddFail(const occ::handle<Standard_Transient>& start,
0164                                const char* const                      mess,
0165                                const char* const                      orig = "");
0166 
0167   //! (other name of AddFail, maintained for compatibility)
0168   Standard_EXPORT void AddError(const occ::handle<Standard_Transient>& start,
0169                                 const char* const                      mess,
0170                                 const char* const                      orig = "");
0171 
0172   //! Adds an Error Message to a starting entity from the definition
0173   //! of a Msg (Original+Value)
0174   Standard_EXPORT void AddFail(const occ::handle<Standard_Transient>& start,
0175                                const Message_Msg&                     amsg);
0176 
0177   //! Adds a Warning message to a starting entity (to the check of
0178   //! its Binder of category 0)
0179   Standard_EXPORT void AddWarning(const occ::handle<Standard_Transient>& start,
0180                                   const char* const                      mess,
0181                                   const char* const                      orig = "");
0182 
0183   //! Adds a Warning Message to a starting entity from the definition
0184   //! of a Msg (Original+Value)
0185   Standard_EXPORT void AddWarning(const occ::handle<Standard_Transient>& start,
0186                                   const Message_Msg&                     amsg);
0187 
0188   Standard_EXPORT void Mend(const occ::handle<Standard_Transient>& start,
0189                             const char* const                      pref = "");
0190 
0191   //! Returns the Check attached to a starting entity. If <start>
0192   //! is unknown, returns an empty Check
0193   //! Adds a case name to a starting entity
0194   //! Adds a case value to a starting entity
0195   //! Returns the complete case list for an entity. Null Handle if empty
0196   //! In the list of mapped items (between 1 and NbMapped),
0197   //! searches for the first item which follows <num0>(not included)
0198   //! and which has an attribute named <name>
0199   //! Attributes are brought by Binders
0200   //! Hence, allows such an iteration
0201   //!
0202   //! for (num = TP->NextItemWithAttribute(name,0);
0203   //! num > 0;
0204   //! num = TP->NextItemWithAttribute(name,num) {
0205   //! .. process mapped item <num>
0206   //! }
0207   //! Returns the type of an Attribute attached to binders
0208   //! If this name gives no Attribute, returns ParamVoid
0209   //! If this name gives several different types, returns ParamMisc
0210   //! Else, returns the effective type (ParamInteger, ParamReal,
0211   //! ParamIdent, or ParamText)
0212   //! Returns the list of recorded Attribute Names, as a Dictionary
0213   //! of Integer : each value gives the count of items which bring
0214   //! this attribute name
0215   //! By default, considers all the attribute names
0216   //! If <rootname> is given, considers only the attribute names
0217   //! which begin by <rootname>
0218   Standard_EXPORT occ::handle<Interface_Check> Check(
0219     const occ::handle<Standard_Transient>& start) const;
0220 
0221   //! Binds a starting object with a Transient Result.
0222   //! Uses a SimpleBinderOfTransient to work. If there is already
0223   //! one but with no Result set, sets its Result.
0224   //! Considers a category number, by default 0
0225   Standard_EXPORT void BindTransient(const occ::handle<Standard_Transient>& start,
0226                                      const occ::handle<Standard_Transient>& res);
0227 
0228   //! Returns the Result of the Transfer of an object <start> as a
0229   //! Transient Result.
0230   //! Returns a Null Handle if there is no Transient Result
0231   //! Considers a category number, by default 0
0232   //! Warning : Supposes that Binding is done with a SimpleBinderOfTransient
0233   Standard_EXPORT const occ::handle<Standard_Transient>& FindTransient(
0234     const occ::handle<Standard_Transient>& start) const;
0235 
0236   //! Prepares an object <start> to be bound with several results.
0237   //! If no Binder is yet attached to <obj>, a MultipleBinder
0238   //! is created, empty. If a Binder is already set, it must
0239   //! accept Multiple Binding.
0240   //! Considers a category number, by default 0
0241   Standard_EXPORT void BindMultiple(const occ::handle<Standard_Transient>& start);
0242 
0243   //! Adds an item to a list of results bound to a starting object.
0244   //! Considers a category number, by default 0, for all results
0245   Standard_EXPORT void AddMultiple(const occ::handle<Standard_Transient>& start,
0246                                    const occ::handle<Standard_Transient>& res);
0247 
0248   //! Searches for a transient result attached to a starting object,
0249   //! according to its type, by criterium IsKind(atype)
0250   //!
0251   //! In case of multiple result, explores the list and gives in
0252   //! <val> the first transient result IsKind(atype)
0253   //! Returns True and fills <val> if found
0254   //! Else, returns False (<val> is not touched, not even nullified)
0255   //!
0256   //! This syntactic form avoids to do DownCast : if a result is
0257   //! found with the good type, it is loaded in <val> and can be
0258   //! immediately used, well initialised
0259   Standard_EXPORT bool FindTypedTransient(const occ::handle<Standard_Transient>& start,
0260                                           const occ::handle<Standard_Type>&      atype,
0261                                           occ::handle<Standard_Transient>&       val) const;
0262 
0263   //! Searches for a transient result recorded in a Binder, whatever
0264   //! this Binder is recorded or not in <me>
0265   //!
0266   //! This is strictly equivalent to the class method GetTypedResult
0267   //! from class SimpleBinderOfTransient, but is just lighter to call
0268   //!
0269   //! Apart from this, works as FindTypedTransient
0270   Standard_EXPORT bool GetTypedTransient(const occ::handle<Transfer_Binder>& binder,
0271                                          const occ::handle<Standard_Type>&   atype,
0272                                          occ::handle<Standard_Transient>&    val) const;
0273 
0274   //! Returns the maximum possible value for Map Index
0275   //! (no result can be bound with a value greater than it)
0276   Standard_EXPORT int NbMapped() const;
0277 
0278   //! Returns the Starting Object bound to an Index,
0279   Standard_EXPORT const occ::handle<Standard_Transient>& Mapped(const int num) const;
0280 
0281   //! Returns the Index value bound to a Starting Object, 0 if none
0282   Standard_EXPORT int MapIndex(const occ::handle<Standard_Transient>& start) const;
0283 
0284   //! Returns the Binder bound to an Index
0285   //! Considers a category number, by default 0
0286   Standard_EXPORT occ::handle<Transfer_Binder> MapItem(const int num) const;
0287 
0288   //! Declares <obj> (and its Result) as Root. This status will be
0289   //! later exploited by RootResult, see below (Result can be
0290   //! produced at any time)
0291   Standard_EXPORT void SetRoot(const occ::handle<Standard_Transient>& start);
0292 
0293   //! Enable (if <stat> True) or Disables (if <stat> False) Root
0294   //! Management. If it is set, Transfers are considered as stacked
0295   //! (a first Transfer commands other Transfers, and so on) and
0296   //! the Transfers commanded by an external caller are "Root".
0297   //! Remark : SetRoot can be called whatever this status, on every
0298   //! object.
0299   //! Default is set to True.
0300   Standard_EXPORT void SetRootManagement(const bool stat);
0301 
0302   //! Returns the count of recorded Roots
0303   Standard_EXPORT int NbRoots() const;
0304 
0305   //! Returns a Root Entity given its number in the list (1-NbRoots)
0306   Standard_EXPORT const occ::handle<Standard_Transient>& Root(const int num) const;
0307 
0308   //! Returns the Binder bound with a Root Entity given its number
0309   //! Considers a category number, by default 0
0310   Standard_EXPORT occ::handle<Transfer_Binder> RootItem(const int num) const;
0311 
0312   //! Returns the index in the list of roots for a starting item,
0313   //! or 0 if it is not recorded as a root
0314   Standard_EXPORT int RootIndex(const occ::handle<Standard_Transient>& start) const;
0315 
0316   //! Returns Nesting Level of Transfers (managed by methods
0317   //! TranscriptWith & Co). Starts to zero. If no automatic Transfer
0318   //! is used, it remains to zero. Zero means Root Level.
0319   Standard_EXPORT int NestingLevel() const;
0320 
0321   //! Resets Nesting Level of Transfers to Zero (Root Level),
0322   //! whatever its current value.
0323   Standard_EXPORT void ResetNestingLevel();
0324 
0325   //! Tells if <start> has been recognized as good candidate for
0326   //! Transfer. i.e. queries the Actor and its Nexts
0327   Standard_EXPORT bool Recognize(const occ::handle<Standard_Transient>& start) const;
0328 
0329   //! Performs the Transfer of a Starting Object, by calling
0330   //! the method TransferProduct (see below).
0331   //! Mapping and Roots are managed : nothing is done if a Result is
0332   //! already Bound, an exception is raised in case of error.
0333   Standard_EXPORT occ::handle<Transfer_Binder> Transferring(
0334     const occ::handle<Standard_Transient>& start,
0335     const Message_ProgressRange&           theProgress = Message_ProgressRange());
0336 
0337   //! Same as Transferring but does not return the Binder.
0338   //! Simply returns True in case of success (for user call)
0339   Standard_EXPORT bool Transfer(const occ::handle<Standard_Transient>& start,
0340                                 const Message_ProgressRange& theProgress = Message_ProgressRange());
0341 
0342   //! Allows controls if exceptions will be handled
0343   //! Transfer Operations
0344   //! <err> False : they are not handled with try {} catch {}
0345   //! <err> True  : they are
0346   //! Default is False: no handling performed
0347   Standard_EXPORT void SetErrorHandle(const bool err);
0348 
0349   //! Returns error handling flag
0350   Standard_EXPORT bool ErrorHandle() const;
0351 
0352   //! Method called when trace is asked
0353   //! Calls PrintTrace to display information relevant for starting
0354   //! objects (which can be redefined)
0355   //! <level> is Nesting Level of Transfer (0 = root)
0356   //! <mode> controls the way the trace is done :
0357   //! 0 neutral, 1 for Error, 2 for Warning message, 3 for new Root
0358   Standard_EXPORT void StartTrace(const occ::handle<Transfer_Binder>&    binder,
0359                                   const occ::handle<Standard_Transient>& start,
0360                                   const int                              level,
0361                                   const int                              mode) const;
0362 
0363   //! Prints a short information on a starting object. By default
0364   //! prints its Dynamic Type. Can be redefined
0365   Standard_EXPORT virtual void PrintTrace(const occ::handle<Standard_Transient>& start,
0366                                           Standard_OStream&                      S) const;
0367 
0368   //! Returns True if we are surely in a DeadLoop. Evaluation is not
0369   //! exact, it is a "majorant" which must be computed fast.
0370   //! This "majorant" is : <alevel> greater than NbMapped.
0371   Standard_EXPORT bool IsLooping(const int alevel) const;
0372 
0373   //! Returns, as an iterator, the log of root transfer, i.e. the
0374   //! created objects and Binders bound to starting roots
0375   //! If withstart is given True, Starting Objects are also returned
0376   Standard_EXPORT Transfer_IteratorOfProcessForTransient
0377     RootResult(const bool withstart = false) const;
0378 
0379   //! Returns, as an Iterator, the entire log of transfer (list of
0380   //! created objects and Binders which can bring errors)
0381   //! If withstart is given True, Starting Objects are also returned
0382   Standard_EXPORT Transfer_IteratorOfProcessForTransient
0383     CompleteResult(const bool withstart = false) const;
0384 
0385   //! Returns Binders which are neither "Done" nor "Initial",
0386   //! that is Error,Loop or Run (abnormal states at end of Transfer)
0387   //! Starting Objects are given in correspondence in the iterator
0388   Standard_EXPORT Transfer_IteratorOfProcessForTransient AbnormalResult() const;
0389 
0390   //! Returns a CheckList as a list of Check : each one is for a
0391   //! starting entity which have either check (warning or fail)
0392   //! messages are attached, or are in abnormal state : that case
0393   //! gives a specific message
0394   //! If <erronly> is True, checks with Warnings only are ignored
0395   Standard_EXPORT Interface_CheckIterator CheckList(const bool erronly) const;
0396 
0397   //! Returns, as an Iterator, the log of transfer for one object
0398   //! <level> = 0 : this object only
0399   //! and if <start> is a scope owner (else, <level> is ignored) :
0400   //! <level> = 1 : object plus its immediate scoped ones
0401   //! <level> = 2 : object plus all its scoped ones
0402   Standard_EXPORT Transfer_IteratorOfProcessForTransient
0403     ResultOne(const occ::handle<Standard_Transient>& start,
0404               const int                              level,
0405               const bool                             withstart = false) const;
0406 
0407   //! Returns a CheckList for one starting object
0408   //! <level> interpreted as by ResultOne
0409   //! If <erronly> is True, checks with Warnings only are ignored
0410   Standard_EXPORT Interface_CheckIterator CheckListOne(const occ::handle<Standard_Transient>& start,
0411                                                        const int                              level,
0412                                                        const bool erronly) const;
0413 
0414   //! Returns True if no check message is attached to a starting
0415   //! object. <level> interpreted as by ResultOne
0416   //! If <erronly> is True, checks with Warnings only are ignored
0417   Standard_EXPORT bool IsCheckListEmpty(const occ::handle<Standard_Transient>& start,
0418                                         const int                              level,
0419                                         const bool                             erronly) const;
0420 
0421   //! Removes Results attached to (== Unbinds) a given object and,
0422   //! according <level> :
0423   //! <level> = 0 : only it
0424   //! <level> = 1 : it plus its immediately owned sub-results(scope)
0425   //! <level> = 2 : it plus all its owned sub-results(scope)
0426   Standard_EXPORT void RemoveResult(const occ::handle<Standard_Transient>& start,
0427                                     const int                              level,
0428                                     const bool                             compute = true);
0429 
0430   //! Computes a number to be associated to a starting object in
0431   //! a check or a check-list
0432   //! By default, returns 0; can be redefined
0433   Standard_EXPORT virtual int CheckNum(const occ::handle<Standard_Transient>& start) const;
0434 
0435   DEFINE_STANDARD_RTTI_INLINE(Transfer_ProcessForTransient, Standard_Transient)
0436 
0437 private:
0438   //! Same as Find but stores the last access to the map, for a
0439   //! faster access on next calls (as Bind does too)
0440   //! Considers a category number, by default 0
0441   //! C++ : return const &
0442   Standard_EXPORT occ::handle<Transfer_Binder> FindAndMask(
0443     const occ::handle<Standard_Transient>& start);
0444 
0445   //! Internal action of Transfer, called by Transferring, with or
0446   //! without ErrorHandle. It invokes the Actor to work (set by
0447   //! SetActor), and tries its Nexts if no result is produced,
0448   //! until a Non Null Binder is produced.
0449   //! But keep in mind that a Null Binder can always be returned
0450   //! if a Starting Entity has not been recognized at all.
0451   Standard_EXPORT occ::handle<Transfer_Binder> TransferProduct(
0452     const occ::handle<Standard_Transient>& start,
0453     const Message_ProgressRange&           theProgress = Message_ProgressRange());
0454 
0455   bool                                             theerrh;
0456   int                                              thetrace;
0457   occ::handle<Message_Messenger>                   themessenger;
0458   int                                              thelevel;
0459   int                                              therootl;
0460   bool                                             therootm;
0461   NCollection_IndexedMap<int>                      theroots;
0462   occ::handle<Standard_Transient>                  thelastobj;
0463   occ::handle<Transfer_Binder>                     thelastbnd;
0464   int                                              theindex;
0465   occ::handle<Transfer_ActorOfProcessForTransient> theactor;
0466   NCollection_IndexedDataMap<occ::handle<Standard_Transient>, occ::handle<Transfer_Binder>> themap;
0467 };
0468 
0469 #endif // _Transfer_ProcessForTransient_HeaderFile