Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:21:04

0001 // Created on: 1992-09-22
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 _Interface_Graph_HeaderFile
0018 #define _Interface_Graph_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <Interface_BitMap.hxx>
0025 #include <Interface_InterfaceModel.hxx>
0026 
0027 #include <TCollection_HAsciiString.hxx>
0028 #include <Standard_Integer.hxx>
0029 #include <NCollection_Array1.hxx>
0030 #include <NCollection_HArray1.hxx>
0031 #include <NCollection_List.hxx>
0032 #include <Standard_Transient.hxx>
0033 #include <NCollection_Sequence.hxx>
0034 #include <NCollection_HSequence.hxx>
0035 
0036 class Interface_GeneralLib;
0037 class Interface_Protocol;
0038 class Interface_GTool;
0039 class Standard_Transient;
0040 class Interface_EntityIterator;
0041 
0042 // resolve name collisions with X11 headers
0043 #ifdef Status
0044   #undef Status
0045 #endif
0046 
0047 //! Gives basic data structure for operating and storing
0048 //! graph results (usage is normally internal)
0049 //! Entities are Mapped according their Number in the Model
0050 //!
0051 //! Each Entity from the Model can be known as "Present" or
0052 //! not; if it is, it is Mapped with a Status : an Integer
0053 //! which can be used according to needs of each algorithm
0054 //! In addition, the Graph brings a BitMap which can be used
0055 //! by any caller
0056 //!
0057 //! Also, it is bound with two lists : a list of Shared
0058 //! Entities (in fact, their Numbers in the Model) which is
0059 //! filled by a ShareTool, and a list of Sharing Entities,
0060 //! computed by deduction from the Shared Lists
0061 //!
0062 //! Moreover, it is possible to redefine the list of Entities
0063 //! Shared by an Entity (instead of standard answer by general
0064 //! service Shareds) : this new list can be empty; it can
0065 //! be changed or reset (i.e. to come back to standard answer)
0066 class Interface_Graph
0067 {
0068 public:
0069   DEFINE_STANDARD_ALLOC
0070 
0071   //! Creates an empty graph, ready to receive Entities from amodel
0072   //! Note that this way of Creation allows <me> to verify that
0073   //! Entities to work with are contained in <amodel>
0074   //! Basic Shared and Sharing lists are obtained from a General
0075   //! Services Library, given directly as an argument
0076   Standard_EXPORT Interface_Graph(const occ::handle<Interface_InterfaceModel>& amodel,
0077                                   const Interface_GeneralLib&                  lib,
0078                                   const bool                                   theModeStats = true);
0079 
0080   //! Same as above, but the Library is defined through a Protocol
0081   Standard_EXPORT Interface_Graph(const occ::handle<Interface_InterfaceModel>& amodel,
0082                                   const occ::handle<Interface_Protocol>&       protocol,
0083                                   const bool                                   theModeStats = true);
0084 
0085   //! Same as above, but the Library is defined through a Protocol
0086   Standard_EXPORT Interface_Graph(const occ::handle<Interface_InterfaceModel>& amodel,
0087                                   const occ::handle<Interface_GTool>&          gtool,
0088                                   const bool                                   theModeStats = true);
0089 
0090   //! Same a above but works with the Protocol recorded in the Model
0091   Standard_EXPORT Interface_Graph(const occ::handle<Interface_InterfaceModel>& amodel,
0092                                   const bool                                   theModeStats = true);
0093 
0094   //! Creates a Graph from another one, getting all its data
0095   //! Remark that status are copied from <agraph>, but the other
0096   //! lists (sharing/shared) are copied only if <copied> = True
0097   Standard_EXPORT Interface_Graph(const Interface_Graph& agraph, const bool copied = false);
0098 
0099   //! Assignment
0100   Standard_EXPORT Interface_Graph& operator=(const Interface_Graph& theOther);
0101 
0102   //! Erases data, making graph ready to rebegin from void
0103   //! (also resets Shared lists redefinitions)
0104   Standard_EXPORT void Reset();
0105 
0106   //! Erases Status (Values and Flags of Presence), making graph
0107   //! ready to rebegin from void. Does not concerns Shared lists
0108   Standard_EXPORT void ResetStatus();
0109 
0110   //! Returns size (max nb of entities, i.e. Model's nb of entities)
0111   Standard_EXPORT int Size() const;
0112 
0113   //! Returns size of array of statuses
0114   Standard_EXPORT int NbStatuses() const;
0115 
0116   //! Returns the Number of the entity in the Map, computed at
0117   //! creation time (Entities loaded from the Model)
0118   //! Returns 0 if <ent> not contained by Model used to create <me>
0119   //! (that is, <ent> is unknown from <me>)
0120   Standard_EXPORT int EntityNumber(const occ::handle<Standard_Transient>& ent) const;
0121 
0122   //! Returns True if an Entity is noted as present in the graph
0123   //! (See methods Get... which determine this status)
0124   //! Returns False if <num> is out of range too
0125   Standard_EXPORT bool IsPresent(const int num) const;
0126 
0127   //! Same as above but directly on an Entity <ent> : if it is not
0128   //! contained in the Model, returns False. Else calls
0129   //! IsPresent(num) with <num> given by EntityNumber
0130   Standard_EXPORT bool IsPresent(const occ::handle<Standard_Transient>& ent) const;
0131 
0132   //! Returns mapped Entity given its no (if it is present)
0133   Standard_EXPORT const occ::handle<Standard_Transient>& Entity(const int num) const;
0134 
0135   //! Returns Status associated to a numero (only to read it)
0136   Standard_EXPORT int Status(const int num) const;
0137 
0138   //! Modifies Status associated to a numero
0139   Standard_EXPORT void SetStatus(const int num, const int stat);
0140 
0141   //! Clears Entity and sets Status to 0, for a numero
0142   Standard_EXPORT void RemoveItem(const int num);
0143 
0144   //! Changes all status which value is oldstat to new value newstat
0145   Standard_EXPORT void ChangeStatus(const int oldstat, const int newstat);
0146 
0147   //! Removes all items of which status has a given value stat
0148   Standard_EXPORT void RemoveStatus(const int stat);
0149 
0150   //! Returns the Bit Map in order to read or edit flag values
0151   Standard_EXPORT const Interface_BitMap& BitMap() const;
0152 
0153   //! Returns the Bit Map in order to edit it (add new flags)
0154   Standard_EXPORT Interface_BitMap& CBitMap();
0155 
0156   //! Returns the Model with which this Graph was created
0157   Standard_EXPORT const occ::handle<Interface_InterfaceModel>& Model() const;
0158 
0159   //! Loads Graph with all Entities contained in the Model
0160   Standard_EXPORT void GetFromModel();
0161 
0162   //! Gets an Entity, plus its shared ones (at every level) if
0163   //! "shared" is True. New items are set to status "newstat"
0164   //! Items already present in graph remain unchanged
0165   //! Of course, redefinitions of Shared lists are taken into
0166   //! account if there are some
0167   Standard_EXPORT void GetFromEntity(const occ::handle<Standard_Transient>& ent,
0168                                      const bool                             shared,
0169                                      const int                              newstat = 0);
0170 
0171   //! Gets an Entity, plus its shared ones (at every level) if
0172   //! "shared" is True. New items are set to status "newstat".
0173   //! Items already present in graph are processed as follows :
0174   //! - if they already have status "newstat", they remain unchanged
0175   //! - if they have another status, this one is modified :
0176   //! if cumul is True,  to former status + overlapstat (cumul)
0177   //! if cumul is False, to overlapstat (enforce)
0178   Standard_EXPORT void GetFromEntity(const occ::handle<Standard_Transient>& ent,
0179                                      const bool                             shared,
0180                                      const int                              newstat,
0181                                      const int                              overlapstat,
0182                                      const bool                             cumul);
0183 
0184   //! Gets Entities given by an EntityIterator. Entities which were
0185   //! not yet present in the graph are mapped with status "newstat"
0186   //! Entities already present remain unchanged
0187   Standard_EXPORT void GetFromIter(const Interface_EntityIterator& iter, const int newstat);
0188 
0189   //! Gets Entities given by an EntityIterator and distinguishes
0190   //! those already present in the Graph :
0191   //! - new entities added to the Graph with status "newstst"
0192   //! - entities already present with status = "newstat" remain
0193   //! unchanged
0194   //! - entities already present with status different form
0195   //! "newstat" have their status modified :
0196   //! if cumul is True,  to former status + overlapstat (cumul)
0197   //! if cumul is False, to overlapstat (enforce)
0198   //! (Note : works as GetEntity, shared = False, for each entity)
0199   Standard_EXPORT void GetFromIter(const Interface_EntityIterator& iter,
0200                                    const int                       newstat,
0201                                    const int                       overlapstat,
0202                                    const bool                      cumul);
0203 
0204   //! Gets all present items from another graph
0205   Standard_EXPORT void GetFromGraph(const Interface_Graph& agraph);
0206 
0207   //! Gets items from another graph which have a specific Status
0208   Standard_EXPORT void GetFromGraph(const Interface_Graph& agraph, const int stat);
0209 
0210   //! Returns True if <ent> or the list of entities shared by <ent>
0211   //! (not redefined) contains items unknown from this Graph
0212   //! Remark : apart from the status HasShareError, these items
0213   //! are ignored
0214   Standard_EXPORT bool HasShareErrors(const occ::handle<Standard_Transient>& ent) const;
0215 
0216   //! Returns the sequence of Entities Shared by an Entity
0217   Standard_EXPORT occ::handle<NCollection_HSequence<occ::handle<Standard_Transient>>> GetShareds(
0218     const occ::handle<Standard_Transient>& ent) const;
0219 
0220   //! Returns the list of Entities Shared by an Entity, as recorded
0221   //! by the Graph. That is, by default Basic Shared List, else it
0222   //! can be redefined by methods SetShare, SetNoShare ... see below
0223   Standard_EXPORT Interface_EntityIterator
0224     Shareds(const occ::handle<Standard_Transient>& ent) const;
0225 
0226   //! Returns the list of Entities which Share an Entity, computed
0227   //! from the Basic or Redefined Shared Lists
0228   Standard_EXPORT Interface_EntityIterator
0229     Sharings(const occ::handle<Standard_Transient>& ent) const;
0230 
0231   //! Returns the sequence of Entities Sharings by an Entity
0232   Standard_EXPORT occ::handle<NCollection_HSequence<occ::handle<Standard_Transient>>> GetSharings(
0233     const occ::handle<Standard_Transient>& ent) const;
0234 
0235   //! Returns the list of sharings entities, AT ANY LEVEL, which are
0236   //! kind of a given type. A sharing entity kind of this type
0237   //! ends the exploration of its branch
0238   Standard_EXPORT Interface_EntityIterator
0239     TypedSharings(const occ::handle<Standard_Transient>& ent,
0240                   const occ::handle<Standard_Type>&      type) const;
0241 
0242   //! Returns the Entities which are not Shared (their Sharing List
0243   //! is empty) in the Model
0244   Standard_EXPORT Interface_EntityIterator RootEntities() const;
0245 
0246   //! Determines the name attached to an entity, by using the
0247   //! general service Name in GeneralModule
0248   //! Returns a null handle if no name could be computed or if
0249   //! the entity is not in the model
0250   Standard_EXPORT occ::handle<TCollection_HAsciiString> Name(
0251     const occ::handle<Standard_Transient>& ent) const;
0252 
0253   //! Returns the Table of Sharing lists. Used to Create
0254   //! another Graph from <me>
0255   Standard_EXPORT const occ::handle<NCollection_HArray1<NCollection_List<int>>>& SharingTable()
0256     const;
0257 
0258   //! Returns mode responsible for computation of statuses;
0259   Standard_EXPORT bool ModeStat() const;
0260 
0261 protected:
0262   //! Initialize statuses and flags
0263   Standard_EXPORT void InitStats();
0264 
0265   occ::handle<Interface_InterfaceModel>                   themodel;
0266   TCollection_AsciiString                                 thepresents;
0267   occ::handle<NCollection_HArray1<int>>                   thestats;
0268   occ::handle<NCollection_HArray1<NCollection_List<int>>> thesharings;
0269 
0270 private:
0271   //! Performs the Evaluation of the Graph, from an initial Library,
0272   //! either defined through a Protocol, or given dierctly
0273   //! Called by the non-empty Constructors
0274   //!
0275   //! Normally, gtool suffices. But if a Graph is created from a
0276   //! GeneralLib directly, it cannot be used
0277   //! If <gtool> is defined, it has priority
0278   Standard_EXPORT void Evaluate();
0279 
0280   Interface_BitMap theflags;
0281 };
0282 
0283 #endif // _Interface_Graph_HeaderFile