1 // Created on: 1992-09-22
2 // Created by: Christian CAILLET
3 // Copyright (c) 1992-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 _Interface_Graph_HeaderFile
18 #define _Interface_Graph_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Interface_BitMap.hxx>
25 #include <Interface_InterfaceModel.hxx>
27 #include <TCollection_HAsciiString.hxx>
28 #include <TColStd_HArray1OfInteger.hxx>
29 #include <TColStd_HArray1OfListOfInteger.hxx>
30 #include <TColStd_HSequenceOfTransient.hxx>
32 class Standard_DomainError;
33 class Interface_GeneralLib;
34 class Interface_Protocol;
35 class Interface_GTool;
36 class Standard_Transient;
37 class Interface_EntityIterator;
39 // resolve name collisions with X11 headers
44 //! Gives basic data structure for operating and storing
45 //! graph results (usage is normally internal)
46 //! Entities are Mapped according their Number in the Model
48 //! Each Entity from the Model can be known as "Present" or
49 //! not; if it is, it is Mapped with a Status : an Integer
50 //! which can be used according to needs of each algorithm
51 //! In addition, the Graph brings a BitMap which can be used
54 //! Also, it is bound with two lists : a list of Shared
55 //! Entities (in fact, their Numbers in the Model) which is
56 //! filled by a ShareTool, and a list of Sharing Entities,
57 //! computed by deduction from the Shared Lists
59 //! Moreover, it is possible to redefine the list of Entities
60 //! Shared by an Entity (instead of standard answer by general
61 //! service Shareds) : this new list can be empty; it can
62 //! be changed or reset (i.e. to come back to standard answer)
70 //! Creates an empty graph, ready to receive Entities from amodel
71 //! Note that this way of Creation allows <me> to verify that
72 //! Entities to work with are contained in <amodel>
73 //! Basic Shared and Sharing lists are obtained from a General
74 //! Services Library, given directly as an argument
75 Standard_EXPORT Interface_Graph(const Handle(Interface_InterfaceModel)& amodel, const Interface_GeneralLib& lib, const Standard_Boolean theModeStats = Standard_True);
77 //! Same as above, but the Library is defined through a Protocol
78 Standard_EXPORT Interface_Graph(const Handle(Interface_InterfaceModel)& amodel, const Handle(Interface_Protocol)& protocol, const Standard_Boolean theModeStats = Standard_True);
80 //! Same as above, but the Library is defined through a Protocol
81 Standard_EXPORT Interface_Graph(const Handle(Interface_InterfaceModel)& amodel, const Handle(Interface_GTool)& gtool, const Standard_Boolean theModeStats = Standard_True);
83 //! Same a above but works with the Protocol recorded in the Model
84 Standard_EXPORT Interface_Graph(const Handle(Interface_InterfaceModel)& amodel, const Standard_Boolean theModeStats = Standard_True);
86 //! Creates a Graph from another one, getting all its data
87 //! Remark that status are copied from <agraph>, but the other
88 //! lists (sharing/shared) are copied only if <copied> = True
89 Standard_EXPORT Interface_Graph(const Interface_Graph& agraph, const Standard_Boolean copied = Standard_False);
92 Standard_EXPORT Interface_Graph& operator= (const Interface_Graph& theOther);
94 //! Erases data, making graph ready to rebegin from void
95 //! (also resets Shared lists redefinitions)
96 Standard_EXPORT void Reset();
98 //! Erases Status (Values and Flags of Presence), making graph
99 //! ready to rebegin from void. Does not concerns Shared lists
100 Standard_EXPORT void ResetStatus();
102 //! Returns size (max nb of entities, i.e. Model's nb of entities)
103 Standard_EXPORT Standard_Integer Size() const;
105 //! Returns size of array of statuses
106 Standard_EXPORT Standard_Integer NbStatuses() const;
108 //! Returns the Number of the entity in the Map, computed at
109 //! creation time (Entities loaded from the Model)
110 //! Returns 0 if <ent> not contained by Model used to create <me>
111 //! (that is, <ent> is unknown from <me>)
112 Standard_EXPORT Standard_Integer EntityNumber (const Handle(Standard_Transient)& ent) const;
114 //! Returns True if an Entity is noted as present in the graph
115 //! (See methods Get... which determine this status)
116 //! Returns False if <num> is out of range too
117 Standard_EXPORT Standard_Boolean IsPresent (const Standard_Integer num) const;
119 //! Same as above but directly on an Entity <ent> : if it is not
120 //! contained in the Model, returns False. Else calls
121 //! IsPresent(num) with <num> given by EntityNumber
122 Standard_EXPORT Standard_Boolean IsPresent (const Handle(Standard_Transient)& ent) const;
124 //! Returns mapped Entity given its no (if it is present)
125 Standard_EXPORT const Handle(Standard_Transient)& Entity (const Standard_Integer num) const;
127 //! Returns Status associated to a numero (only to read it)
128 Standard_EXPORT Standard_Integer Status (const Standard_Integer num) const;
130 //! Modifies Status associated to a numero
131 Standard_EXPORT void SetStatus (const Standard_Integer num, const Standard_Integer stat);
133 //! Clears Entity and sets Status to 0, for a numero
134 Standard_EXPORT void RemoveItem (const Standard_Integer num);
136 //! Changes all status which value is oldstat to new value newstat
137 Standard_EXPORT void ChangeStatus (const Standard_Integer oldstat, const Standard_Integer newstat);
139 //! Removes all items of which status has a given value stat
140 Standard_EXPORT void RemoveStatus (const Standard_Integer stat);
142 //! Returns the Bit Map in order to read or edit flag values
143 Standard_EXPORT const Interface_BitMap& BitMap() const;
145 //! Returns the Bit Map in order to edit it (add new flags)
146 Standard_EXPORT Interface_BitMap& CBitMap();
148 //! Returns the Model with which this Graph was created
149 Standard_EXPORT const Handle(Interface_InterfaceModel)& Model() const;
151 //! Loads Graph with all Entities contained in the Model
152 Standard_EXPORT void GetFromModel();
154 //! Gets an Entity, plus its shared ones (at every level) if
155 //! "shared" is True. New items are set to status "newstat"
156 //! Items already present in graph remain unchanged
157 //! Of course, redefinitions of Shared lists are taken into
158 //! account if there are some
159 Standard_EXPORT void GetFromEntity (const Handle(Standard_Transient)& ent, const Standard_Boolean shared, const Standard_Integer newstat = 0);
161 //! Gets an Entity, plus its shared ones (at every level) if
162 //! "shared" is True. New items are set to status "newstat".
163 //! Items already present in graph are processed as follows :
164 //! - if they already have status "newstat", they remain unchanged
165 //! - if they have another status, this one is modified :
166 //! if cumul is True, to former status + overlapstat (cumul)
167 //! if cumul is False, to overlapstat (enforce)
168 Standard_EXPORT void GetFromEntity (const Handle(Standard_Transient)& ent, const Standard_Boolean shared, const Standard_Integer newstat, const Standard_Integer overlapstat, const Standard_Boolean cumul);
170 //! Gets Entities given by an EntityIterator. Entities which were
171 //! not yet present in the graph are mapped with status "newstat"
172 //! Entities already present remain unchanged
173 Standard_EXPORT void GetFromIter (const Interface_EntityIterator& iter, const Standard_Integer newstat);
175 //! Gets Entities given by an EntityIterator and distinguishes
176 //! those already present in the Graph :
177 //! - new entities added to the Graph with status "newstst"
178 //! - entities already present with status = "newstat" remain
180 //! - entities already present with status different form
181 //! "newstat" have their status modified :
182 //! if cumul is True, to former status + overlapstat (cumul)
183 //! if cumul is False, to overlapstat (enforce)
184 //! (Note : works as GetEntity, shared = False, for each entity)
185 Standard_EXPORT void GetFromIter (const Interface_EntityIterator& iter, const Standard_Integer newstat, const Standard_Integer overlapstat, const Standard_Boolean cumul);
187 //! Gets all present items from another graph
188 Standard_EXPORT void GetFromGraph (const Interface_Graph& agraph);
190 //! Gets items from another graph which have a specific Status
191 Standard_EXPORT void GetFromGraph (const Interface_Graph& agraph, const Standard_Integer stat);
193 //! Returns True if <ent> or the list of entities shared by <ent>
194 //! (not redefined) contains items unknown from this Graph
195 //! Remark : apart from the status HasShareError, these items
197 Standard_EXPORT Standard_Boolean HasShareErrors (const Handle(Standard_Transient)& ent) const;
199 //! Returns the sequence of Entities Shared by an Entity
200 Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetShareds (const Handle(Standard_Transient)& ent) const;
202 //! Returns the list of Entities Shared by an Entity, as recorded
203 //! by the Graph. That is, by default Basic Shared List, else it
204 //! can be redefined by methods SetShare, SetNoShare ... see below
205 Standard_EXPORT Interface_EntityIterator Shareds (const Handle(Standard_Transient)& ent) const;
207 //! Returns the list of Entities which Share an Entity, computed
208 //! from the Basic or Redefined Shared Lists
209 Standard_EXPORT Interface_EntityIterator Sharings (const Handle(Standard_Transient)& ent) const;
211 //! Returns the sequence of Entities Sharings by an Entity
212 Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetSharings (const Handle(Standard_Transient)& ent) const;
214 //! Returns the list of sharings entities, AT ANY LEVEL, which are
215 //! kind of a given type. A sharing entity kind of this type
216 //! ends the exploration of its branch
217 Standard_EXPORT Interface_EntityIterator TypedSharings (const Handle(Standard_Transient)& ent, const Handle(Standard_Type)& type) const;
219 //! Returns the Entities which are not Shared (their Sharing List
220 //! is empty) in the Model
221 Standard_EXPORT Interface_EntityIterator RootEntities() const;
223 //! Determines the name attached to an entity, by using the
224 //! general service Name in GeneralModule
225 //! Returns a null handle if no name could be computed or if
226 //! the entity is not in the model
227 Standard_EXPORT Handle(TCollection_HAsciiString) Name (const Handle(Standard_Transient)& ent) const;
229 //! Returns the Table of Sharing lists. Used to Create
230 //! another Graph from <me>
231 Standard_EXPORT const Handle(TColStd_HArray1OfListOfInteger)& SharingTable() const;
233 //! Returns mode resposible for computation of statuses;
234 Standard_EXPORT Standard_Boolean ModeStat() const;
242 //! Initialize statuses and flags
243 Standard_EXPORT void InitStats();
246 Handle(Interface_InterfaceModel) themodel;
247 TCollection_AsciiString thepresents;
248 Handle(TColStd_HArray1OfInteger) thestats;
249 Handle(TColStd_HArray1OfListOfInteger) thesharings;
255 //! Performs the Evaluation of the Graph, from an initial Library,
256 //! either defined through a Protocol, or given dierctly
257 //! Called by the non-empty Constructors
259 //! Normally, gtool suffices. But if a Graph is created from a
260 //! GeneralLib directly, it cannot be used
261 //! If <gtool> is defined, it has priority
262 Standard_EXPORT void Evaluate();
265 Interface_BitMap theflags;
276 #endif // _Interface_Graph_HeaderFile