Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-25 09:20:21

0001 // Created by: Christian CAILLET <cky@phobox>
0002 // Copyright (c) 1992-1999 Matra Datavision
0003 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _Interface_InterfaceModel_HeaderFile
0017 #define _Interface_InterfaceModel_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <Standard_Type.hxx>
0021 
0022 #include <Standard_Transient.hxx>
0023 #include <NCollection_IndexedMap.hxx>
0024 #include <Standard_Integer.hxx>
0025 #include <NCollection_DataMap.hxx>
0026 #include <Interface_DataState.hxx>
0027 #include <TCollection_HAsciiString.hxx>
0028 #include <NCollection_Sequence.hxx>
0029 #include <NCollection_HSequence.hxx>
0030 class Interface_Check;
0031 class TCollection_HAsciiString;
0032 class Interface_GTool;
0033 class Interface_Protocol;
0034 class Interface_ReportEntity;
0035 class Interface_CheckIterator;
0036 class Interface_GeneralLib;
0037 class Interface_EntityIterator;
0038 
0039 //! Defines an (Indexed) Set of data corresponding to a complete
0040 //! Transfer by a File Interface, i.e. File Header and Transient
0041 //! Entities (Objects) contained in a File. Contained Entities are
0042 //! identified in the Model by unique and consecutive Numbers.
0043 //!
0044 //! In addition, a Model can attach to each entity, a specific
0045 //! Label according to the norm (e.g. Name for VDA, #ident for
0046 //! Step ...), intended to be output on a string or a stream
0047 //! (remark : labels are not obliged to be unique)
0048 //!
0049 //! InterfaceModel itself is not Transient, it is intended to
0050 //! work on a set of Transient Data. The services offered are
0051 //! basic Listing and Identification operations on Transient
0052 //! Entities, storage of Error Reports, Copying.
0053 //!
0054 //! Moreovere, it is possible to define and use templates. These
0055 //! are empty Models, from which copies can be obtained in order
0056 //! to be filled with effective data. This allows to record
0057 //! standard definitions for headers, avoiding to recreate them
0058 //! for each sendings, and assuring customisation of produced
0059 //! files for a given site.
0060 //! A template is attached to a name. It is possible to define a
0061 //! template from another one (get it, edit it then record it
0062 //! under another name).
0063 //!
0064 //! See also Graph, ShareTool, CheckTool for more
0065 class Interface_InterfaceModel : public Standard_Transient
0066 {
0067 
0068 public:
0069   //! Clears the list of entities (service WhenDelete)
0070   Standard_EXPORT void Destroy();
0071 
0072   ~Interface_InterfaceModel() override { Destroy(); }
0073 
0074   //! Sets a Protocol for this Model
0075   //! It is also set by a call to AddWithRefs with Protocol
0076   //! It is used for : DumpHeader (as required), ClearEntities ...
0077   Standard_EXPORT void SetProtocol(const occ::handle<Interface_Protocol>& proto);
0078 
0079   //! Returns the Protocol which has been set by SetProtocol, or
0080   //! AddWithRefs with Protocol
0081   Standard_EXPORT virtual occ::handle<Interface_Protocol> Protocol() const;
0082 
0083   //! Sets a GTool for this model, which already defines a Protocol
0084   Standard_EXPORT void SetGTool(const occ::handle<Interface_GTool>& gtool);
0085 
0086   //! Returns the GTool, set by SetProtocol or by SetGTool
0087   Standard_EXPORT occ::handle<Interface_GTool> GTool() const;
0088 
0089   //! Returns the Dispatch Status, either for get or set
0090   //! A Model which is produced from Dispatch may share entities
0091   //! with the original (according to the Protocol), hence these
0092   //! non-copied entities should not be deleted
0093   Standard_EXPORT bool& DispatchStatus();
0094 
0095   //! Erases contained data; used when a Model is copied to others :
0096   //! the new copied ones begin from clear
0097   //! Clear calls specific method ClearHeader (see below)
0098   Standard_EXPORT virtual void Clear();
0099 
0100   //! Clears the entities; uses the general service WhenDelete, in
0101   //! addition to the standard Memory Manager; can be redefined
0102   Standard_EXPORT virtual void ClearEntities();
0103 
0104   //! Erases information about labels, if any : specific to each
0105   //! norm
0106   Standard_EXPORT virtual void ClearLabels() = 0;
0107 
0108   //! Clears Model's header : specific to each norm
0109   Standard_EXPORT virtual void ClearHeader() = 0;
0110 
0111   //! Returns count of contained Entities
0112   Standard_EXPORT int NbEntities() const;
0113 
0114   //! Returns True if a Model contains an Entity (for a ReportEntity,
0115   //! looks for the ReportEntity itself AND its Concerned Entity)
0116   Standard_EXPORT bool Contains(const occ::handle<Standard_Transient>& anentity) const;
0117 
0118   //! Returns the Number of an Entity in the Model if it contains it.
0119   //! Else returns 0. For a ReportEntity, looks at Concerned Entity.
0120   //! Returns the Directory entry Number of an Entity in
0121   //! the Model if it contains it. Else returns 0.
0122   //! For a ReportEntity, looks at Concerned Entity.
0123   Standard_EXPORT int Number(const occ::handle<Standard_Transient>& anentity) const;
0124 
0125   //! Returns an Entity identified by its number in the Model
0126   //! Each sub-class of InterfaceModel can define its own method
0127   //! Entity to return its specific class of Entity (e.g. for VDA,
0128   //! VDAModel returns a VDAEntity), working by calling Value
0129   //! Remark : For a Reported Entity, (Erroneous, Corrected, Unknown), this
0130   //! method returns this Reported Entity.
0131   //! See ReportEntity for other questions.
0132   Standard_EXPORT const occ::handle<Standard_Transient>& Value(const int num) const;
0133 
0134   //! Returns the count of DISTINCT types under which an entity may
0135   //! be processed. Defined by the Protocol, which gives default as
0136   //! 1 (dynamic Type).
0137   Standard_EXPORT int NbTypes(const occ::handle<Standard_Transient>& ent) const;
0138 
0139   //! Returns a type, given its rank : defined by the Protocol
0140   //! (by default, the first one)
0141   Standard_EXPORT occ::handle<Standard_Type> Type(const occ::handle<Standard_Transient>& ent,
0142                                                   const int num = 1) const;
0143 
0144   //! Returns the type name of an entity, from the list of types
0145   //! (one or more ...)
0146   //! <complete> True (D) gives the complete type, else packages are
0147   //! removed
0148   //! WARNING : buffered, to be immediately copied or printed
0149   Standard_EXPORT const char* TypeName(const occ::handle<Standard_Transient>& ent,
0150                                        const bool complete = true) const;
0151 
0152   //! From a CDL Type Name, returns the Class part (package dropped)
0153   //! WARNING : buffered, to be immediately copied or printed
0154   Standard_EXPORT static const char* ClassName(const char* const typnam);
0155 
0156   //! Returns the State of an entity, given its number
0157   Standard_EXPORT Interface_DataState EntityState(const int num) const;
0158 
0159   //! Returns True if <num> identifies a ReportEntity in the Model
0160   //! Hence, ReportEntity can be called.
0161   //!
0162   //! By default, queries main report, if <semantic> is True, it
0163   //! queries report for semantic check
0164   //!
0165   //! Remember that a Report Entity can be defined for an Unknown
0166   //! Entity, or a Corrected or Erroneous (at read time) Entity.
0167   //! The ReportEntity is defined before call to method AddEntity.
0168   Standard_EXPORT bool IsReportEntity(const int num, const bool semantic = false) const;
0169 
0170   //! Returns a ReportEntity identified by its number in the Model,
0171   //! or a Null Handle If <num> does not identify a ReportEntity.
0172   //!
0173   //! By default, queries main report, if <semantic> is True, it
0174   //! queries report for semantic check
0175   Standard_EXPORT occ::handle<Interface_ReportEntity> ReportEntity(
0176     const int  num,
0177     const bool semantic = false) const;
0178 
0179   //! Returns True if <num> identifies an Error Entity : in this
0180   //! case, a ReportEntity brings Fail Messages and possibly an
0181   //! "undefined" Content, see IsRedefinedEntity
0182   Standard_EXPORT bool IsErrorEntity(const int num) const;
0183 
0184   //! Returns True if <num> identifies an Entity which content is
0185   //! redefined through a ReportEntity (i.e. with literal data only)
0186   //! This happens when an entity is syntactically erroneous in the
0187   //! way that its basic content remains empty.
0188   //! For more details (such as content itself), see ReportEntity
0189   Standard_EXPORT bool IsRedefinedContent(const int num) const;
0190 
0191   //! Removes the ReportEntity attached to Entity <num>. Returns
0192   //! True if done, False if no ReportEntity was attached to <num>.
0193   //! Warning : the caller must assume that this clearing is meaningful
0194   Standard_EXPORT bool ClearReportEntity(const int num);
0195 
0196   //! Sets or Replaces a ReportEntity for the Entity <num>. Returns
0197   //! True if Report is replaced, False if it has been replaced
0198   //! Warning : the caller must assume that this setting is meaningful
0199   Standard_EXPORT bool SetReportEntity(const int                                  num,
0200                                        const occ::handle<Interface_ReportEntity>& rep);
0201 
0202   //! Adds a ReportEntity as such. Returns False if the concerned
0203   //! entity is not recorded in the Model
0204   //! Else, adds it into, either the main report list or the
0205   //! list for semantic checks, then returns True
0206   Standard_EXPORT bool AddReportEntity(const occ::handle<Interface_ReportEntity>& rep,
0207                                        const bool                                 semantic = false);
0208 
0209   //! Returns True if <num> identifies an Unknown Entity : in this
0210   //! case, a ReportEntity with no Check Messages designates it.
0211   Standard_EXPORT bool IsUnknownEntity(const int num) const;
0212 
0213   //! Fills the list of semantic checks.
0214   //! This list is computed (by CheckTool). Hence, it can be stored
0215   //! in the model for later queries
0216   //! <clear> True (D) : new list replaces
0217   //! <clear> False    : new list is cumulated
0218   Standard_EXPORT void FillSemanticChecks(const Interface_CheckIterator& checks,
0219                                           const bool                     clear = true);
0220 
0221   //! Returns True if semantic checks have been filled
0222   Standard_EXPORT bool HasSemanticChecks() const;
0223 
0224   //! Returns the check attached to an entity, designated by its
0225   //! Number. 0 for global check
0226   //! <semantic> True  : recorded semantic check
0227   //! <semantic> False : recorded syntactic check (see ReportEntity)
0228   //! If no check is recorded for <num>, returns an empty Check
0229   Standard_EXPORT const occ::handle<Interface_Check>& Check(const int  num,
0230                                                             const bool syntactic) const;
0231 
0232   //! Does a reservation for the List of Entities (for optimized
0233   //! storage management). If it is not called, storage management
0234   //! can be less efficient. <nbent> is the expected count of
0235   //! Entities to store
0236   Standard_EXPORT virtual void Reservate(const int nbent);
0237 
0238   //! Internal method for adding an Entity. Used by file reading
0239   //! (defined by each Interface) and Transfer tools. It adds the
0240   //! entity required to be added, not its refs : see AddWithRefs.
0241   //! If <anentity> is a ReportEntity, it is added to the list of
0242   //! Reports, its Concerned Entity (Erroneous or Corrected, else
0243   //! Unknown) is added to the list of Entities.
0244   //! That is, the ReportEntity must be created before Adding
0245   Standard_EXPORT virtual void AddEntity(const occ::handle<Standard_Transient>& anentity);
0246 
0247   //! Adds to the Model, an Entity with all its References, as they
0248   //! are defined by General Services FillShared and ListImplied.
0249   //! Process is recursive (any sub-levels) if <level> = 0 (Default)
0250   //! Else, adds sub-entities until the required sub-level.
0251   //! Especially, if <level> = 1, adds immediate subs and that's all
0252   //!
0253   //! If <listall> is False (Default), an entity (<anentity> itself
0254   //! or one of its subs at any level) which is already recorded in
0255   //! the Model is not analysed, only the newly added ones are.
0256   //! If <listall> is True, all items are analysed (this allows to
0257   //! ensure the consistency of an adding made by steps)
0258   Standard_EXPORT void AddWithRefs(const occ::handle<Standard_Transient>& anent,
0259                                    const occ::handle<Interface_Protocol>& proto,
0260                                    const int                              level   = 0,
0261                                    const bool                             listall = false);
0262 
0263   //! Same as above, but works with the Protocol of the Model
0264   Standard_EXPORT void AddWithRefs(const occ::handle<Standard_Transient>& anent,
0265                                    const int                              level   = 0,
0266                                    const bool                             listall = false);
0267 
0268   //! Same as above, but works with an already created GeneralLib
0269   Standard_EXPORT void AddWithRefs(const occ::handle<Standard_Transient>& anent,
0270                                    const Interface_GeneralLib&            lib,
0271                                    const int                              level   = 0,
0272                                    const bool                             listall = false);
0273 
0274   //! Replace Entity with Number=nument on other entity - "anent"
0275   Standard_EXPORT void ReplaceEntity(const int                              nument,
0276                                      const occ::handle<Standard_Transient>& anent);
0277 
0278   //! Reverses the Numbers of the Entities, between <after> and the
0279   //! total count of Entities. Thus, the entities :
0280   //! 1,2 ... after, after+1 ... nb-1, nb  become numbered as :
0281   //! 1,2 ... after, nb, nb-1 ... after+1
0282   //! By default (after = 0) the whole list of Entities is reversed
0283   Standard_EXPORT void ReverseOrders(const int after = 0);
0284 
0285   //! Changes the Numbers of some Entities : <oldnum> is moved to
0286   //! <newnum>, same for <count> entities. Thus :
0287   //! 1,2 ... newnum-1 newnum ... oldnum .. oldnum+count oldnum+count+1 .. gives
0288   //! 1,2 ... newnum-1 oldnum .. oldnum+count newnum ... oldnum+count+1
0289   //! (can be seen as a circular permutation)
0290   Standard_EXPORT void ChangeOrder(const int oldnum, const int newnum, const int count = 1);
0291 
0292   //! Gets contents from an EntityIterator, prepared by a
0293   //! Transfer tool (e.g TransferCopy). Starts from clear
0294   Standard_EXPORT void GetFromTransfer(const Interface_EntityIterator& aniter);
0295 
0296   //! Gets header (data specific of a defined Interface) from
0297   //! another InterfaceModel; called from TransferCopy
0298   Standard_EXPORT virtual void GetFromAnother(
0299     const occ::handle<Interface_InterfaceModel>& other) = 0;
0300 
0301   //! Returns a New Empty Model, same type as <me> (whatever its
0302   //! Type); called to Copy parts a Model into other ones, then
0303   //! followed by a call to GetFromAnother (Header) then filling
0304   //! with specified Entities, themselves copied
0305   Standard_EXPORT virtual occ::handle<Interface_InterfaceModel> NewEmptyModel() const = 0;
0306 
0307   //! Records a category number for an entity number
0308   //! Returns True when done, False if <num> is out of range
0309   Standard_EXPORT bool SetCategoryNumber(const int num, const int val);
0310 
0311   //! Returns the recorded category number for a given entity number
0312   //! 0 if none was defined for this entity
0313   Standard_EXPORT int CategoryNumber(const int num) const;
0314 
0315   //! Allows an EntityIterator to get a list of Entities
0316   Standard_EXPORT void FillIterator(Interface_EntityIterator& iter) const;
0317 
0318   //! Returns the list of all Entities, as an Iterator on Entities
0319   //! (the Entities themselves, not the Reports)
0320   Standard_EXPORT Interface_EntityIterator Entities() const;
0321 
0322   //! Returns the list of all ReportEntities, i.e. data about
0323   //! Entities read with Error or Warning information
0324   //! (each item has to be casted to Report Entity then it can be
0325   //! queried for Concerned Entity, Content, Check ...)
0326   //! By default, returns the main reports, is <semantic> is True it
0327   //! returns the list for semantic checks
0328   Standard_EXPORT Interface_EntityIterator Reports(const bool semantic = false) const;
0329 
0330   //! Returns the list of ReportEntities which redefine data
0331   //! (generally, if concerned entity is "Error", a literal content
0332   //! is added to it : this is a "redefined entity"
0333   Standard_EXPORT Interface_EntityIterator Redefineds() const;
0334 
0335   //! Returns the GlobalCheck, which memorizes messages global to
0336   //! the file (not specific to an Entity), especially Header
0337   Standard_EXPORT const occ::handle<Interface_Check>& GlobalCheck(
0338     const bool syntactic = true) const;
0339 
0340   //! Allows to modify GlobalCheck, after getting then completing it
0341   //! Remark : it is SYNTACTIC check. Semantics, see FillChecks
0342   Standard_EXPORT void SetGlobalCheck(const occ::handle<Interface_Check>& ach);
0343 
0344   //! Minimum Semantic Global Check on data in model (header)
0345   //! Can only check basic Data. See also GlobalCheck from Protocol
0346   //! for a check which takes the Graph into account
0347   //! Default does nothing, can be redefined
0348   Standard_EXPORT virtual void VerifyCheck(occ::handle<Interface_Check>& ach) const;
0349 
0350   //! Dumps Header in a short, easy to read, form, onto a Stream
0351   //! <level> allows to print more or less parts of the header,
0352   //! if necessary. 0 for basic print
0353   Standard_EXPORT virtual void DumpHeader(Standard_OStream& S, const int level = 0) const = 0;
0354 
0355   //! Prints identification of a given entity in <me>, in order to
0356   //! be printed in a list or phrase
0357   //! <mode> < 0 : prints only its number
0358   //! <mode> = 1 : just calls PrintLabel
0359   //! <mode> = 0 (D) : prints its number plus '/' plus PrintLabel
0360   //! If <ent> == <me>, simply prints "Global"
0361   //! If <ent> is unknown, prints "??/its type"
0362   Standard_EXPORT void Print(const occ::handle<Standard_Transient>& ent,
0363                              Standard_OStream&                      s,
0364                              const int                              mode = 0) const;
0365 
0366   //! Prints label specific to each norm, for a given entity.
0367   //! Must only print label itself, in order to be included in a
0368   //! phrase. Can call the result of StringLabel, but not obliged.
0369   Standard_EXPORT virtual void PrintLabel(const occ::handle<Standard_Transient>& ent,
0370                                           Standard_OStream&                      S) const = 0;
0371 
0372   //! Prints label specific to each norm in log format, for
0373   //! a given entity.
0374   //! By default, just calls PrintLabel, can be redefined
0375   Standard_EXPORT virtual void PrintToLog(const occ::handle<Standard_Transient>& ent,
0376                                           Standard_OStream&                      S) const;
0377 
0378   //! Returns a string with the label attached to a given entity.
0379   //! Warning : While this string may be edited on the spot, if it is a read
0380   //! field, the returned value must be copied before.
0381   Standard_EXPORT virtual occ::handle<TCollection_HAsciiString> StringLabel(
0382     const occ::handle<Standard_Transient>& ent) const = 0;
0383 
0384   //! Searches a label which matches with one entity.
0385   //! Begins from <lastnum>+1 (default:1) and scans the entities
0386   //! until <NbEntities>. For the first which matches <label>,
0387   //! this method returns its Number. Returns 0 if nothing found
0388   //! Can be called recursively (labels are not specified as unique)
0389   //! <exact> : if True (default), exact match is required
0390   //! else, checks the END of entity label
0391   //!
0392   //! This method is virtual, hence it can be redefined for a more
0393   //! efficient search (if exact is true).
0394   Standard_EXPORT virtual int NextNumberForLabel(const char* const label,
0395                                                  const int         lastnum = 0,
0396                                                  const bool        exact   = true) const;
0397 
0398   //! Returns true if a template is attached to a given name
0399   Standard_EXPORT static bool HasTemplate(const char* const name);
0400 
0401   //! Returns the template model attached to a name, or a Null Handle
0402   Standard_EXPORT static occ::handle<Interface_InterfaceModel> Template(const char* const name);
0403 
0404   //! Records a new template model with a name. If the name was
0405   //! already recorded, the corresponding template is replaced by
0406   //! the new one. Then, WARNING : test HasTemplate to avoid
0407   //! surprises
0408   Standard_EXPORT static bool SetTemplate(const char* const                            name,
0409                                           const occ::handle<Interface_InterfaceModel>& model);
0410 
0411   //! Returns the complete list of names attached to template models
0412   Standard_EXPORT static occ::handle<NCollection_HSequence<occ::handle<TCollection_HAsciiString>>>
0413     ListTemplates();
0414 
0415   DEFINE_STANDARD_RTTIEXT(Interface_InterfaceModel, Standard_Transient)
0416 
0417 protected:
0418   //! Defines empty InterfaceModel, ready to be filled
0419   Standard_EXPORT Interface_InterfaceModel();
0420 
0421 private:
0422   NCollection_IndexedMap<occ::handle<Standard_Transient>>   theentities;
0423   NCollection_DataMap<int, occ::handle<Standard_Transient>> thereports;
0424   NCollection_DataMap<int, occ::handle<Standard_Transient>> therepch;
0425   occ::handle<Interface_Check>                              thecheckstx;
0426   occ::handle<Interface_Check>                              thechecksem;
0427   bool                                                      haschecksem;
0428   bool                                                      isdispatch;
0429   occ::handle<TCollection_HAsciiString>                     thecategory;
0430   occ::handle<Interface_GTool>                              thegtool;
0431 };
0432 
0433 #endif // _Interface_InterfaceModel_HeaderFile