zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2016, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2002-2016 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
#ifndef DBLAYERSTATEMANAGER_H
#define DBLAYERSTATEMANAGER_H
 
#include "TD_PackPush.h"
#include "StringArray.h"
 
/** \details
  This class implements an interface for manipulating LayerStates in multiple OdDbDatabase instances.
  
  Library: TD_Db
  <group OdDb_Classes> 
*/
class TOOLKIT_EXPORT OdDbLayerState
{
public:
  enum Mask
  {
    kDefMask          = (long)0xFFFFFFFF,
    kNone             = 0x0000,
    kOn               = 0x0001,
    kFrozen           = 0x0002,
    kLocked           = 0x0004,
    kPlot             = 0x0008,
    kNewViewport      = 0x0010,
    kColor            = 0x0020,
    kLineType         = 0x0040,
    kLineWeight       = 0x0080,
    kPlotStyle        = 0x0100,
    kCurrentViewport  = 0x0200,
    kTransparency     = 0x0400,
 
    kAll              = kOn | kFrozen | kLocked | kPlot | kNewViewport |
                        kColor | kLineType | kLineWeight | kPlotStyle |
                        kCurrentViewport | kTransparency,
 
    kHidden           = 0x8000        
  };
  
  enum
  {
    kUndefDoNothing     = 0x00,
    kUndefTurnOff       = 0x01,
    kUndefFreeze        = 0x02,
    kRestoreAsOverrides = 0x04
  };
 
  /** \details
    Returns the Object ID of the LayerStates dictionary for the specified database.
    \param pDb [in]  Pointer to the database.
    \param createIfNotFound [in]  Controls the creation of the dictionary if it does not exist.
  */
  static OdDbObjectId dictionaryId(OdDbDatabase *pDb, bool createIfNotFound = false);
  
  /** \details
    Returns true if and only if the specified database
    has a LayerState with the specified name.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
  */
  static bool has(OdDbDatabase *pDb, const OdString &layerStateName);
  
  /** \details
    Saves the current LayerState of the specified database.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
    \param layerStateMask [in]  LayerState mask.
    \param viewportId [in]  Viewport whose LayerState is to be saved.
    
    \remarks
    layerStateMask determines which layer attributes are to be stored in the LayerState.  
    layerStateMask must be a combination of one or more of the following:
    
    <table>
    Name                   Value        
    kNone                  0x0000       
    kOn                    0x0001       
    kFrozen                0x0002       
    kLocked                0x0004       
    kPlot                  0x0008       
    kNewViewport           0x0010       
    kColor                 0x0020       
    kLineType              0x0040       
    kLineWeight            0x0080       
    kPlotStyle             0x0100        
    kCurrentViewport       0x0200     
    kTransparency          0x0400
    kAll                   kOn | kFrozen | kLocked | kPlot | kNewViewport |
                           kColor | kLineType | kLineWeight | kPlotStyle |
                           kCurrentViewport | kTransparency       
    kHidden                0x8000        
    </table>
    
  */
  static void save(OdDbDatabase *pDb, const OdString &layerStateName, int layerStateMask, const OdDbObjectId &viewportId = OdDbObjectId::kNull);
 
  /** \details
    Restores the specified LayerState of the specified database.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
    \param layerStateMask [in]  LayerState mask.
    \param viewportId [in]  Viewport whose LayerState is to be saved.
    \param undefAction [in]  Action for undefined layers.
    
    \remarks
    undefAction specified the action for layers not defined in the LayerState.
    undefAction must be one of the following:
    
    <table>
    Name               Value  
    kUndefDoNothing    0      
    kUndefTurnOff      1        
    kUndefFreeze       2
    </table>
    
    layerStateMask determines which layer attributes are to be restored from the LayerState.  
    layerStateMask must be a combination of one or more of the following:
    
    <table>
    Name                   Value        
    kDefMask               0xFFFFFFFF   
    kNone                  0x0000       
    kOn                    0x0001       
    kFrozen                0x0002       
    kLocked                0x0004       
    kPlot                  0x0008       
    kNewViewport           0x0010       
    kColor                 0x0020       
    kLineType              0x0040       
    kLineWeight            0x0080       
    kPlotStyle             0x0100        
    kCurrentViewport       0x0200        
    kTransparency          0x0400
    kAll                   kOn | kFrozen | kLocked | kPlot | kNewViewport |
                           kColor | kLineType | kLineWeight | kPlotStyle |
                           kCurrentViewport | kTransparency       
    kHidden                0x8000        
    </table>
    
  */
  static void restore(OdDbDatabase *pDb, const OdString &layerStateName,
    int flags = kUndefDoNothing, const int layerStateMask = kDefMask, const OdDbObjectId& viewportId = OdDbObjectId::kNull);
  /** \details
    Sets the LayerState mask for the specified LayerState in the specified database.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
    \param layerStateMask [in]  LayerState mask.
    
    \remarks
    layerStateMask determines which layer attributes are to be restored from the LayerState.  
    layerStateMask must be a combination of one or more of the following:
    
    <table>
    Name                   Value        
    kNone                  0x0000       
    kOn                    0x0001       
    kFrozen                0x0002       
    kLocked                0x0004       
    kPlot                  0x0008       
    kNewViewport           0x0010       
    kColor                 0x0020       
    kLineType              0x0040       
    kLineWeight            0x0080       
    kPlotStyle             0x0100        
    kCurrentViewport       0x0200        
    kTransparency          0x0400
    kAll                   kOn | kFrozen | kLocked | kPlot | kNewViewport |
                           kColor | kLineType | kLineWeight | kPlotStyle |
                           kCurrentViewport | kTransparency       
    kHidden                0x8000        
    </table>
    
  */
  static void setMask(OdDbDatabase *pDb, const OdString &layerStateName, int layerStateMask);
  
  /** \details
    Returns the LayerState mask for the specified LayerState in the specified database.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
    
    \remarks
    The layer state mask determines which layer attributes are to be restored from the LayerState.  
 
    mask() returns a combination of one or more of the following:
    
    <table>
    Name                   Value        
    kNone                  0x0000       
    kOn                    0x0001       
    kFrozen                0x0002       
    kLocked                0x0004       
    kPlot                  0x0008       
    kNewViewport           0x0010       
    kColor                 0x0020       
    kLineType              0x0040       
    kLineWeight            0x0080       
    kPlotStyle             0x0100        
    kCurrentViewport       0x0200        
    kTransparency          0x0400
    kAll                   kOn | kFrozen | kLocked | kPlot | kNewViewport |
                           kColor | kLineType | kLineWeight | kPlotStyle |
                           kCurrentViewport | kTransparency       
    kHidden                0x8000        
    </table>
    
  */
  static int  mask(OdDbDatabase *pDb, const OdString &layerStateName);
 
  /** \details
    Removes the specified LayerState from the specified database.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
  */
  static void remove(OdDbDatabase *pDb, const OdString &layerStateName);
 
  /** \details
    Renames the specified LayerState in the specified database.
 
    \param pDb [in]  Pointer to the database.
    \param oldName [in]  Old name.
    \param newName [in]  New name.
  */
  static void rename(OdDbDatabase *pDb, const OdString &oldName, const OdString &newName);
 
  enum ImportResult
  {
    kImported,
    kAlreadyExists
  };
 
  /** \details
    Imports the LayerState from the specified file to the specified database.
 
    \param pDb [in]  Pointer to the database.
    \param pStreamBuf [in]  Pointer to the StreamBuf object from which the data are to be read.    
    \param pName [out]  Optional pointer to the string where imported layer state name will be stored.
 
    Returns one of the following:
 
    <table>
    Name               Value  
    kImported          0      
    kAlreadyExists     1        
    </table>
  */
  static ImportResult importData(OdDbDatabase *pDb, OdStreamBuf* pStreamBuf, OdString* pName = 0);
 
  /** \details
    Exports the LayerState from the specified database to the specified file.
 
    \param pDb [in]  Pointer to the database.
    \param pStreamBuf [in]  Pointer to the StreamBuf object to which the data are to be written.
    \param layerStateName [in]  LayerState name.
  */
  static void exportData(OdDbDatabase *pDb, const OdString &layerStateName, OdStreamBuf* pStreamBuf);
  
  /** \details
    Sets the description of the specified LayerState in the specified database.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
    \param description [in]  Description.
  */
      static void setDescription(OdDbDatabase *pDb, const OdString &layerStateName, const OdString &description);
  /** \details
    Returns the description of the specified LayerState in the specified database.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
  */
      static OdString description(OdDbDatabase *pDb, const OdString &layerStateName);
 
  /** \details
    Returns true if and only if there is viewport data associated with specified LayerState in the specified database.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
  */
      static bool hasViewportData(OdDbDatabase *pDb, const OdString &layerStateName);
 
  /** \details
    Adds more layers to a layer state.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
    \param layerIds [in]  Array of object Ids of layers to be added to the layer state 
  */
      static OdResult addLayerStateLayers(const OdString &sName, OdDbObjectIdArray layerIds);
 
  /** \details
    Removes layers from a layer state.
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
    \param layerNames [in]  Array of names of layers to be removed from the layer state.
  */
      static OdResult removeLayerStateLayers(OdDbDatabase* pDb, const OdString sName, const OdStringArray& layerNames);
 
  /** \details
    Creates a layer state where specified layers are assigned one state (e.g. ON), 
    and all the others are assigned other state (e.g. OFF).
 
    \param pDb [in]  Pointer to the database.
    \param layerStateName [in]  LayerState name.
    \param layerIds [in]  Array of object Ids of layers to be added to the layer state 
    \param mask [in]  created 
  */
  static OdResult saveGroup(OdDbDatabase *pDb, const OdString &sName,
    const OdDbObjectIdArray& pLayers, int mask = kOn,
    int includedLayersState = kOn, int otherLayersState = kNone);
};
 
class OdDbLayerStateManagerReactor;
class OdDbLayerStateManagerImpl;
 
/** \details
  Library: TD_Db
  <group OdDb_Classes> 
*/
class TOOLKIT_EXPORT OdDbLayerStateManager: public OdRxObject
{
protected:
  OdDbLayerStateManager(OdDbLayerStateManagerImpl*);
public:
  ODRX_DECLARE_MEMBERS(OdDbLayerStateManager);
  OdDbLayerStateManager();
  ~OdDbLayerStateManager();
 
  enum LayerStateMask {
    kNone           = 0x0000,
    kOn             = 0x0001,
    kFrozen         = 0x0002,
    kLocked         = 0x0004,
    kPlot           = 0x0008,
    kNewViewport    = 0x0010,
    kColor          = 0x0020,
    kLineType       = 0x0040,
    kLineWeight     = 0x0080,
    kPlotStyle      = 0x0100,
    kCurrentViewport = 0x0200,
    kTransparency   = 0x0400,
    kAll            = kOn | kFrozen | kLocked | kPlot | kNewViewport |
    kColor | kLineType | kLineWeight | kPlotStyle |
    kCurrentViewport | kTransparency,
    kStateIsHidden  = 0x8000,        
    kLastRestored   = 0x10000,        
    kDecomposition  = kAll | 0x20000
  };
 
  enum {
    kUndefDoNothing = 0,
    kUndefTurnOff = 1,
    kUndefFreeze = 2,
    kRestoreAsOverrides = 4
  };
 
  bool                addReactor(OdDbLayerStateManagerReactor * pReactor);
  bool                removeReactor(OdDbLayerStateManagerReactor * pReactor);
 
  OdDbObjectId        layerStatesDictionaryId(bool bCreateIfNotPresent=false);
  bool                hasLayerState(const OdString& sName);
  OdResult   saveLayerState(const OdString& sName, LayerStateMask mask);
  OdResult   restoreLayerState(const OdString& sName);
  OdResult   setLayerStateMask(const OdString& sName, LayerStateMask mask);
  OdResult   getLayerStateMask(const OdString& sName, LayerStateMask &returnMask);
  OdResult   deleteLayerState(const OdString& sName);
  OdResult   renameLayerState(const OdString& sName, const OdString& sNewName);
  OdResult   importLayerState(OdStreamBuf* pStreamBuf);
  OdResult   importLayerState(OdStreamBuf* pStreamBuf, OdString& sName);
  OdResult   exportLayerState(const OdString& sNameToExport, OdStreamBuf* pStreamBuf);
  OdResult   saveLayerState(const OdString& sName, LayerStateMask mask, const OdDbObjectId& idVp);
  OdResult   restoreLayerState(const OdString& sName, const OdDbObjectId& idVp, int nRestoreFlags = 0, const LayerStateMask* pClientMask = NULL);
  OdResult   setLayerStateDescription(const OdString& sName, const OdString& sDesc);
  OdResult   getLayerStateDescription(const OdString& sName, OdString& sDesc);
  bool       layerStateHasViewportData(const OdString&  sName);
  OdResult   importLayerStateFromDb(const OdString& pStateName, OdDbDatabase* pDb);
  OdResult   getLayerStateNames(OdStringArray& lsArray, bool bIncludeHidden = true, bool bIncludeXref = true);
  OdResult   getLastRestoredLayerState(OdString& sName, OdDbObjectId &restoredLSId);
  OdResult   getLayerStateLayers(OdStringArray& layerArray, const OdString& sName, bool bInvert = false);
  bool       compareLayerStateToDb(const OdString& sName, const OdDbObjectId& idVp);
  OdResult   addLayerStateLayers(const OdString& sName, const OdDbObjectIdArray& layerIds);
  OdResult   removeLayerStateLayers(const OdString& sName, const OdStringArray& layerNames);
  bool       isDependentLayerState(const OdString& sName);
  OdDbDatabase* getDatabase() const;
protected:
  OdDbLayerStateManagerImpl* m_pImpl;
  friend class OdDbLayerStateManagerImpl;
  friend class OdDbDatabase;
};
 
 
/** \details
  Library: TD_Db
  <group OdDb_Classes> 
*/
class TOOLKIT_EXPORT OdDbLayerStateManagerReactor : public OdRxObject
{
public:
  ODRX_DECLARE_MEMBERS(OdDbLayerStateManagerReactor);
 
  virtual void layerStateCreated(const OdString& layerStateName,
    const OdDbObjectId& layerStateId);
  virtual void layerStateCompareFailed(const OdString& layerStateName,
    const OdDbObjectId& layerStateId);
 
  virtual void layerStateToBeRestored(const OdString& layerStateName,
    const OdDbObjectId& layerStateId);
  virtual void layerStateRestored(const OdString& layerStateName,
    const OdDbObjectId& layerStateId);
  virtual void abortLayerStateRestore(const OdString& layerStateName,
    const OdDbObjectId& layerStateId);
 
 
  virtual void layerStateToBeDeleted(const OdString& layerStateName,
    const OdDbObjectId& layerStateId);
  virtual void layerStateDeleted(const OdString& layerStateName);
  virtual void abortLayerStateDelete(const OdString& layerStateName,
    const OdDbObjectId& layerStateId);
 
  virtual void layerStateToBeRenamed(const OdString& oldLayerStateName,
    const OdString& newLayerStateName);
  virtual void layerStateRenamed(const OdString& oldLayerStateName,
    const OdString& newLayerStateName);
  virtual void abortLayerStateRename(const OdString& oldLayerStateName,
    const OdString& newLayerStateName);
};
 
typedef OdSmartPtr<OdDbLayerStateManagerReactor> OdDbLayerStateManagerReactorPtr;
 
#include "TD_PackPop.h"
 
#endif //#ifndef DBLAYERSTATEMANAGER_H