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