1 // Created by: Christian CAILLET <cky@phobox>
2 // Copyright (c) 1992-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Interface_InterfaceModel_HeaderFile
17 #define _Interface_InterfaceModel_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
22 #include <TColStd_IndexedMapOfTransient.hxx>
23 #include <TColStd_DataMapOfIntegerTransient.hxx>
24 #include <Standard_Transient.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Interface_DataState.hxx>
27 #include <TColStd_HSequenceOfHAsciiString.hxx>
28 class Interface_Check;
29 class TCollection_HAsciiString;
30 class Interface_GTool;
31 class Interface_Protocol;
32 class Interface_ReportEntity;
33 class Interface_CheckIterator;
34 class Interface_GeneralLib;
35 class Interface_EntityIterator;
38 class Interface_InterfaceModel;
39 DEFINE_STANDARD_HANDLE(Interface_InterfaceModel, Standard_Transient)
41 //! Defines an (Indexed) Set of data corresponding to a complete
42 //! Transfer by a File Interface, i.e. File Header and Transient
43 //! Entities (Objects) contained in a File. Contained Entities are
44 //! identified in the Model by unique and consecutive Numbers.
46 //! In addition, a Model can attach to each entity, a specific
47 //! Label according to the norm (e.g. Name for VDA, #ident for
48 //! Step ...), intended to be output on a string or a stream
49 //! (remark : labels are not obliged to be unique)
51 //! InterfaceModel itself is not Transient, it is intended to
52 //! work on a set of Transient Data. The services offered are
53 //! basic Listing and Identification operations on Transient
54 //! Entities, storage of Error Reports, Copying.
56 //! Moreovere, it is possible to define and use templates. These
57 //! are empty Models, from which copies can be obtained in order
58 //! to be filled with effective data. This allows to record
59 //! standard definitions for headers, avoiding to recreate them
60 //! for each sendings, and assuring customisation of produced
61 //! files for a given site.
62 //! A template is attached to a name. It is possible to define a
63 //! template from another one (get it, edit it then record it
64 //! under another name).
66 //! See also Graph, ShareTool, CheckTool for more
67 class Interface_InterfaceModel : public Standard_Transient
73 //! Clears the list of entities (service WhenDelete)
74 Standard_EXPORT void Destroy();
75 ~Interface_InterfaceModel()
80 //! Sets a Protocol for this Model
81 //! It is also set by a call to AddWithRefs with Protocol
82 //! It is used for : DumpHeader (as required), ClearEntities ...
83 Standard_EXPORT void SetProtocol (const Handle(Interface_Protocol)& proto);
85 //! Returns the Protocol which has been set by SetProtocol, or
86 //! AddWithRefs with Protocol
87 Standard_EXPORT virtual Handle(Interface_Protocol) Protocol() const;
89 //! Sets a GTool for this model, which already defines a Protocol
90 Standard_EXPORT void SetGTool (const Handle(Interface_GTool)& gtool);
92 //! Returns the GTool, set by SetProtocol or by SetGTool
93 Standard_EXPORT Handle(Interface_GTool) GTool() const;
95 //! Returns the Dispatch Status, either for get or set
96 //! A Model which is produced from Dispatch may share entities
97 //! with the original (according to the Protocol), hence these
98 //! non-copied entities should not be deleted
99 Standard_EXPORT Standard_Boolean& DispatchStatus();
101 //! Erases contained data; used when a Model is copied to others :
102 //! the new copied ones begin from clear
103 //! Clear calls specific method ClearHeader (see below)
104 Standard_EXPORT virtual void Clear();
106 //! Clears the entities; uses the general service WhenDelete, in
107 //! addition to the standard Memory Manager; can be redefined
108 Standard_EXPORT virtual void ClearEntities();
110 //! Erases information about labels, if any : specific to each
112 Standard_EXPORT virtual void ClearLabels() = 0;
114 //! Clears Model's header : specific to each norm
115 Standard_EXPORT virtual void ClearHeader() = 0;
117 //! Returns count of contained Entities
118 Standard_EXPORT Standard_Integer NbEntities() const;
120 //! Returns True if a Model contains an Entity (for a ReportEntity,
121 //! looks for the ReportEntity itself AND its Concerned Entity)
122 Standard_EXPORT Standard_Boolean Contains (const Handle(Standard_Transient)& anentity) const;
124 //! Returns the Number of an Entity in the Model if it contains it.
125 //! Else returns 0. For a ReportEntity, looks at Concerned Entity.
126 //! Returns the Directory entry Number of an Entity in
127 //! the Model if it contains it. Else returns 0. For a
128 //! ReportEntity, looks at Concerned Entity.
129 Standard_EXPORT Standard_Integer Number (const Handle(Standard_Transient)& anentity) const;
131 //! Returns an Entity identified by its number in the Model
132 //! Each sub-class of InterfaceModel can define its own method
133 //! Entity to return its specific class of Entity (e.g. for VDA,
134 //! VDAModel returns a VDAEntity), working by calling Value
135 //! Remark : For a Reported Entity, (Erroneous, Corrected, Unknown), this
136 //! method returns this Reported Entity.
137 //! See ReportEntity for other questions.
138 Standard_EXPORT const Handle(Standard_Transient)& Value (const Standard_Integer num) const;
140 //! Returns the count of DISTINCT types under which an entity may
141 //! be processed. Defined by the Protocol, which gives default as
142 //! 1 (dynamic Type).
143 Standard_EXPORT Standard_Integer NbTypes (const Handle(Standard_Transient)& ent) const;
145 //! Returns a type, given its rank : defined by the Protocol
146 //! (by default, the first one)
147 Standard_EXPORT Handle(Standard_Type) Type (const Handle(Standard_Transient)& ent, const Standard_Integer num = 1) const;
149 //! Returns the type name of an entity, from the list of types
150 //! (one or more ...)
151 //! <complete> True (D) gives the complete type, else packages are
153 //! WARNING : buffered, to be immediately copied or printed
154 Standard_EXPORT Standard_CString TypeName (const Handle(Standard_Transient)& ent, const Standard_Boolean complete = Standard_True) const;
156 //! From a CDL Type Name, returns the Class part (package dropped)
157 //! WARNING : buffered, to be immediately copied or printed
158 Standard_EXPORT static Standard_CString ClassName (const Standard_CString typnam);
160 //! Returns the State of an entity, given its number
161 Standard_EXPORT Interface_DataState EntityState (const Standard_Integer num) const;
163 //! Returns True if <num> identifies a ReportEntity in the Model
164 //! Hence, ReportEntity can be called.
166 //! By default, queries main report, if <semantic> is True, it
167 //! queries report for semantic check
169 //! Remember that a Report Entity can be defined for an Unknown
170 //! Entity, or a Corrected or Erroneous (at read time) Entity.
171 //! The ReportEntity is defined before call to method AddEntity.
172 Standard_EXPORT Standard_Boolean IsReportEntity (const Standard_Integer num, const Standard_Boolean semantic = Standard_False) const;
174 //! Returns a ReportEntity identified by its number in the Model,
175 //! or a Null Handle If <num> does not identify a ReportEntity.
177 //! By default, queries main report, if <semantic> is True, it
178 //! queries report for semantic check
179 Standard_EXPORT Handle(Interface_ReportEntity) ReportEntity (const Standard_Integer num, const Standard_Boolean semantic = Standard_False) const;
181 //! Returns True if <num> identifies an Error Entity : in this
182 //! case, a ReportEntity brings Fail Messages and possibly an
183 //! "undefined" Content, see IsRedefinedEntity
184 Standard_EXPORT Standard_Boolean IsErrorEntity (const Standard_Integer num) const;
186 //! Returns True if <num> identifies an Entity which content is
187 //! redefined through a ReportEntity (i.e. with literal data only)
188 //! This happens when an entity is syntactically erroneous in the
189 //! way that its basic content remains empty.
190 //! For more details (such as content itself), see ReportEntity
191 Standard_EXPORT Standard_Boolean IsRedefinedContent (const Standard_Integer num) const;
193 //! Removes the ReportEntity attached to Entity <num>. Returns
194 //! True if done, False if no ReportEntity was attached to <num>.
195 //! Warning : the caller must assume that this clearing is meaningful
196 Standard_EXPORT Standard_Boolean ClearReportEntity (const Standard_Integer num);
198 //! Sets or Replaces a ReportEntity for the Entity <num>. Returns
199 //! True if Report is replaced, False if it has been replaced
200 //! Warning : the caller must assume that this setting is meaningful
201 Standard_EXPORT Standard_Boolean SetReportEntity (const Standard_Integer num, const Handle(Interface_ReportEntity)& rep);
203 //! Adds a ReportEntity as such. Returns False if the concerned
204 //! entity is not recorded in the Model
205 //! Else, adds it into, either the main report list or the
206 //! list for semantic checks, then returns True
207 Standard_EXPORT Standard_Boolean AddReportEntity (const Handle(Interface_ReportEntity)& rep, const Standard_Boolean semantic = Standard_False);
209 //! Returns True if <num> identifies an Unknown Entity : in this
210 //! case, a ReportEntity with no Check Messages designates it.
211 Standard_EXPORT Standard_Boolean IsUnknownEntity (const Standard_Integer num) const;
213 //! Fills the list of semantic checks.
214 //! This list is computed (by CheckTool). Hence, it can be stored
215 //! in the model for later queries
216 //! <clear> True (D) : new list replaces
217 //! <clear> False : new list is cumulated
218 Standard_EXPORT void FillSemanticChecks (const Interface_CheckIterator& checks, const Standard_Boolean clear = Standard_True);
220 //! Returns True if semantic checks have been filled
221 Standard_EXPORT Standard_Boolean HasSemanticChecks() const;
223 //! Returns the check attached to an entity, designated by its
224 //! Number. 0 for global check
225 //! <semantic> True : recorded semantic check
226 //! <semantic> False : recorded syntactic check (see ReportEntity)
227 //! If no check is recorded for <num>, returns an empty Check
228 Standard_EXPORT const Handle(Interface_Check)& Check (const Standard_Integer num, const Standard_Boolean syntactic) const;
230 //! Does a reservation for the List of Entities (for optimized
231 //! storage management). If it is not called, storage management
232 //! can be less efficient. <nbent> is the expected count of
233 //! Entities to store
234 Standard_EXPORT virtual void Reservate (const Standard_Integer nbent);
236 //! Internal method for adding an Entity. Used by file reading
237 //! (defined by each Interface) and Transfer tools. It adds the
238 //! entity required to be added, not its refs : see AddWithRefs.
239 //! If <anentity> is a ReportEntity, it is added to the list of
240 //! Reports, its Concerned Entity (Erroneous or Corrected, else
241 //! Unknown) is added to the list of Entities.
242 //! That is, the ReportEntity must be created before Adding
243 Standard_EXPORT virtual void AddEntity (const Handle(Standard_Transient)& anentity);
245 //! Adds to the Model, an Entity with all its References, as they
246 //! are defined by General Services FillShared and ListImplied.
247 //! Process is recursive (any sub-levels) if <level> = 0 (Default)
248 //! Else, adds sub-entities until the required sub-level.
249 //! Especially, if <level> = 1, adds immediate subs and that's all
251 //! If <listall> is False (Default), an entity (<anentity> itself
252 //! or one of its subs at any level) which is already recorded in
253 //! the Model is not analysed, only the newly added ones are.
254 //! If <listall> is True, all items are analysed (this allows to
255 //! ensure the consistency of an adding made by steps)
256 Standard_EXPORT void AddWithRefs (const Handle(Standard_Transient)& anent, const Handle(Interface_Protocol)& proto, const Standard_Integer level = 0, const Standard_Boolean listall = Standard_False);
258 //! Same as above, but works with the Protocol of the Model
259 Standard_EXPORT void AddWithRefs (const Handle(Standard_Transient)& anent, const Standard_Integer level = 0, const Standard_Boolean listall = Standard_False);
261 //! Same as above, but works with an already created GeneralLib
262 Standard_EXPORT void AddWithRefs (const Handle(Standard_Transient)& anent, const Interface_GeneralLib& lib, const Standard_Integer level = 0, const Standard_Boolean listall = Standard_False);
264 //! Replace Entity with Number=nument on other entity - "anent"
265 Standard_EXPORT void ReplaceEntity (const Standard_Integer nument, const Handle(Standard_Transient)& anent);
267 //! Reverses the Numbers of the Entities, between <after> and the
268 //! total count of Entities. Thus, the entities :
269 //! 1,2 ... after, after+1 ... nb-1, nb become numbered as :
270 //! 1,2 ... after, nb, nb-1 ... after+1
271 //! By default (after = 0) the whole list of Entities is reversed
272 Standard_EXPORT void ReverseOrders (const Standard_Integer after = 0);
274 //! Changes the Numbers of some Entities : <oldnum> is moved to
275 //! <newnum>, same for <count> entities. Thus :
276 //! 1,2 ... newnum-1 newnum ... oldnum .. oldnum+count oldnum+count+1 .. gives
277 //! 1,2 ... newnum-1 oldnum .. oldnum+count newnum ... oldnum+count+1
278 //! (can be seen as a circular permutation)
279 Standard_EXPORT void ChangeOrder (const Standard_Integer oldnum, const Standard_Integer newnum, const Standard_Integer count = 1);
281 //! Gets contents from an EntityIterator, prepared by a
282 //! Transfer tool (e.g TransferCopy). Starts from clear
283 Standard_EXPORT void GetFromTransfer (const Interface_EntityIterator& aniter);
285 //! Gets header (data specific of a defined Interface) from
286 //! another InterfaceModel; called from TransferCopy
287 Standard_EXPORT virtual void GetFromAnother (const Handle(Interface_InterfaceModel)& other) = 0;
289 //! Returns a New Empty Model, same type as <me> (whatever its
290 //! Type); called to Copy parts a Model into other ones, then
291 //! followed by a call to GetFromAnother (Header) then filling
292 //! with specified Entities, themselves copied
293 Standard_EXPORT virtual Handle(Interface_InterfaceModel) NewEmptyModel() const = 0;
295 //! Records a category number for an entity number
296 //! Returns True when done, False if <num> is out of range
297 Standard_EXPORT Standard_Boolean SetCategoryNumber (const Standard_Integer num, const Standard_Integer val);
299 //! Returns the recorded category number for a given entity number
300 //! 0 if none was defined for this entity
301 Standard_EXPORT Standard_Integer CategoryNumber (const Standard_Integer num) const;
303 //! Allows an EntityIterator to get a list of Entities
304 Standard_EXPORT void FillIterator (Interface_EntityIterator& iter) const;
306 //! Returns the list of all Entities, as an Iterator on Entities
307 //! (the Entities themselves, not the Reports)
308 Standard_EXPORT Interface_EntityIterator Entities() const;
310 //! Returns the list of all ReportEntities, i.e. data about
311 //! Entities read with Error or Warning information
312 //! (each item has to be casted to Report Entity then it can be
313 //! queried for Concerned Entity, Content, Check ...)
314 //! By default, returns the main reports, is <semantic> is True it
315 //! returns the list for semantic checks
316 Standard_EXPORT Interface_EntityIterator Reports (const Standard_Boolean semantic = Standard_False) const;
318 //! Returns the list of ReportEntities which redefine data
319 //! (generally, if concerned entity is "Error", a literal content
320 //! is added to it : this is a "redefined entity"
321 Standard_EXPORT Interface_EntityIterator Redefineds() const;
323 //! Returns the GlobalCheck, which memorizes messages global to
324 //! the file (not specific to an Entity), especially Header
325 Standard_EXPORT const Handle(Interface_Check)& GlobalCheck (const Standard_Boolean syntactic = Standard_True) const;
327 //! Allows to modify GlobalCheck, after getting then completing it
328 //! Remark : it is SYNTACTIC check. Semantics, see FillChecks
329 Standard_EXPORT void SetGlobalCheck (const Handle(Interface_Check)& ach);
331 //! Minimum Semantic Global Check on data in model (header)
332 //! Can only check basic Data. See also GlobalCheck from Protocol
333 //! for a check which takes the Graph into account
334 //! Default does nothing, can be redefined
335 Standard_EXPORT virtual void VerifyCheck (Handle(Interface_Check)& ach) const;
337 //! Dumps Header in a short, easy to read, form, onto a Stream
338 //! <level> allows to print more or less parts of the header,
339 //! if necessary. 0 for basic print
340 Standard_EXPORT virtual void DumpHeader (Standard_OStream& S, const Standard_Integer level = 0) const = 0;
342 //! Prints identification of a given entity in <me>, in order to
343 //! be printed in a list or phrase
344 //! <mode> < 0 : prints only its number
345 //! <mode> = 1 : just calls PrintLabel
346 //! <mode> = 0 (D) : prints its number plus '/' plus PrintLabel
347 //! If <ent> == <me>, simply prints "Global"
348 //! If <ent> is unknown, prints "??/its type"
349 Standard_EXPORT void Print (const Handle(Standard_Transient)& ent, Standard_OStream& s, const Standard_Integer mode = 0) const;
351 //! Prints label specific to each norm, for a given entity.
352 //! Must only print label itself, in order to be included in a
353 //! phrase. Can call the result of StringLabel, but not obliged.
354 Standard_EXPORT virtual void PrintLabel (const Handle(Standard_Transient)& ent, Standard_OStream& S) const = 0;
356 //! Prints label specific to each norm in log format, for
358 //! By default, just calls PrintLabel, can be redefined
359 Standard_EXPORT virtual void PrintToLog (const Handle(Standard_Transient)& ent, Standard_OStream& S) const;
361 //! Returns a string with the label attached to a given entity.
362 //! Warning : While this string may be edited on the spot, if it is a read
363 //! field, the returned value must be copied before.
364 Standard_EXPORT virtual Handle(TCollection_HAsciiString) StringLabel (const Handle(Standard_Transient)& ent) const = 0;
366 //! Searches a label which matches with one entity.
367 //! Begins from <lastnum>+1 (default:1) and scans the entities
368 //! until <NbEntities>. For the first which matches <label>,
369 //! this method returns its Number. Returns 0 if nothing found
370 //! Can be called recursively (labels are not specified as unique)
371 //! <exact> : if True (default), exact match is required
372 //! else, checks the END of entity label
374 //! This method is virtual, hence it can be redefined for a more
375 //! efficient search (if exact is true).
376 Standard_EXPORT virtual Standard_Integer NextNumberForLabel (const Standard_CString label, const Standard_Integer lastnum = 0, const Standard_Boolean exact = Standard_True) const;
378 //! Returns true if a template is attached to a given name
379 Standard_EXPORT static Standard_Boolean HasTemplate (const Standard_CString name);
381 //! Returns the template model attached to a name, or a Null Handle
382 Standard_EXPORT static Handle(Interface_InterfaceModel) Template (const Standard_CString name);
384 //! Records a new template model with a name. If the name was
385 //! already recorded, the corresponding template is replaced by
386 //! the new one. Then, WARNING : test HasTemplate to avoid
388 Standard_EXPORT static Standard_Boolean SetTemplate (const Standard_CString name, const Handle(Interface_InterfaceModel)& model);
390 //! Returns the complete list of names attached to template models
391 Standard_EXPORT static Handle(TColStd_HSequenceOfHAsciiString) ListTemplates();
395 DEFINE_STANDARD_RTTIEXT(Interface_InterfaceModel,Standard_Transient)
400 //! Defines empty InterfaceModel, ready to be filled
401 Standard_EXPORT Interface_InterfaceModel();
408 TColStd_IndexedMapOfTransient theentities;
409 TColStd_DataMapOfIntegerTransient thereports;
410 TColStd_DataMapOfIntegerTransient therepch;
411 Handle(Interface_Check) thecheckstx;
412 Handle(Interface_Check) thechecksem;
413 Standard_Boolean haschecksem;
414 Standard_Boolean isdispatch;
415 Handle(TCollection_HAsciiString) thecategory;
416 Handle(Interface_GTool) thegtool;
427 #endif // _Interface_InterfaceModel_HeaderFile