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
/////////////////////////////////////////////////////////////////////////////// 
// 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 __ODGSMODELIMPL_H__
#define __ODGSMODELIMPL_H__
 
#define OD_MATERIAL_CACHE_SUPPORTED
class OdGsNode;
class OdGsViewImpl;
 
#include "TD_PackPush.h"
 
#include "OdList.h"
#include "UInt8Array.h"
#include "UInt32Array.h"
#include "DbStubPtrArray.h"
#include "StaticRxObject.h"
#include "OdVector.h"
 
#include "Gi/GiDrawable.h"
#include "Gi/GiCommonDraw.h"
#include "Gi/GiPathNode.h"
 
#include "Gs/GsExport.h"
#include "Gs/GsModel.h"
#include "Gs/GsViewProps.h"
#include "Gs/GsExtAccum.h"
#include "Gs/GsMaterialCache.h"
#include "Gs/GsVisualStyleProperties.h"
#include "Gs/GsViewLocalId.h"
#include "Gs/GsHighlightData.h"
 
#define CACHE_STATISTICS
 
class OdGsLayerNode;
class OdGsBaseVectorizeDevice;
class OdGsBaseVectorizer;
class OdGsBaseModule;
 
class OdGsBaseModelImpl;
class OdGsEntityNode;
class OdGsContainerNode;
 
enum ENodeType
{
  kBlockNode,
  kContainerNode,
  kLayerNode,
  kEntityNode,
  kMaterialNode,
  kLastNodeType //number of types enumerated above
};
 
/** \details
    GsBaseModel reactor.
 
    Library: TD_Gs
    <group OdGs_Classes> 
*/
class OdGsBaseModelReactor : public OdGsModelReactor
{
  public:
    virtual bool onHighlight(OdGsModel *pModel, const OdGiPathNode& path, bool bDoIt, const OdGsView* pView) { return true; }
 
    virtual bool onInvalidate(OdGsModel *pModel, OdGsModel::InvalidationHint hint) { return true; }
    virtual bool onInvalidate(OdGsModel *pModel, OdGsView* pView) { return true; }
 
    enum ModelProperty
    {
      kModelTransform = 0,
      kModelRenderType,
      kModelAdditionMode,
      kModelBackground,
      kModelVisualStyle,
      kModelSectioning,
 
      kNumModelProps
    };
    virtual bool onPropertyModified(OdGsModel *pModel, ModelProperty nProp) { return true; }
};
 
/** \details
    This class is the base class for custom GsBaseModel objects which coordinate custom caching support 
    for Teigha vectorization applications.
 
    \remarks
    Clients should derive their custom model classes from this class.
 
    Library: TD_Gs
    <group OdGs_Classes> 
*/
class GS_TOOLKIT_EXPORT OdGsBaseModel : public OdGsModel
{
protected:
  OdGiOpenDrawableFn      m_openDrawableFn;
  OdGsNode* m_aNodes[kLastNodeType];
 
  friend class OdGsNode;
  friend class OdGsViewImpl;
  friend class OdGsBaseVectorizer;
  friend class OdGsBaseVectorizeDevice;
 
  /** \details
    Adds the specified Node object to this BaseModel object.
    \param pNode [in]  Pointer to the Node to be added.  
  */
  void addNode(OdGsNode* pNode);
 
public:
  virtual void invalidateEntRect(OdGiDrawable* pDrawable, OdGiDrawable* pParent, bool bForceIfNoExtents = false);
  virtual void invalidateEntRect(OdGsEntityNode* pNode, OdGsContainerNode* pParent, bool bForceIfNoExtents);
 
#if defined(CACHE_STATISTICS)
  unsigned m_nMfCached;
  unsigned m_nMfReused;
#endif//CACHE_STATISTICS
protected:
  bool m_bCheckFaded;
public:
  bool checkFaded() const { return m_bCheckFaded; }
  void setCheckFaded(bool bOn) { m_bCheckFaded = bOn; }
#ifdef ODA_DIAGNOSTICS
  OdRefCounter m_nNodes; //number of OdGsNodes allocated within the model (not necessary in 
                //m_pNodes list _directly_, can be owned by insert/block nodes).
#endif
 
  typedef std::pair<OdGsViewImpl*, OdUInt32> ViewRef;
  OdArray<ViewRef, OdMemoryAllocator<ViewRef> > m_views;
  typedef std::pair<const OdGsBaseModule*, OdUInt32> ModuleRef;
  OdArray<ModuleRef, OdMemoryAllocator<ModuleRef> > m_modules;
  const ViewPropsArray& getViewProps() const { return m_viewProps; }
  OdGsViewImpl *refView() const;
  OdGsBaseVectorizeDevice *refDevice() const;
  OdUInt32 refModulesCount() const { return m_modules.size(); }
#ifdef ODGS_LOCAL_IDS
  virtual void attachLocalViewportId(OdGsViewImpl* pView, OdGsViewImpl* pFrom = NULL);
  virtual OdUInt32 getLocalViewportId(OdGsViewImpl* pView);
  virtual OdUInt32 getMaxLocalViewportId() const;
#endif
 
  /** \details
    For internal needs. Do not use!
  */
  bool invalidVp(unsigned int viewportId) const
  {
    if(m_viewProps.size()>viewportId)
      return m_viewProps[viewportId].isInvalid();
    return true;
  }
 
  OdGsBaseModelImpl* impl() { return m_impl; }
  void invalidateRegenDrawBlocks(OdGsViewImpl& view, const OdDbStub* layoutId);
  void invalidateSectionableBlocks();
 
  struct SectioningSettings
  {
    bool             m_bEnabled;
    bool             m_bTopSet;
    bool             m_bBottomSet;
    bool             m_bVisualStyle;
    OdGePoint3dArray m_points;
    OdGeVector3d     m_upVector;
    double           m_dTop;
    double           m_dBottom;
    OdDbStub        *m_visualStyle;
    SectioningSettings()
      : m_bEnabled(false), m_bTopSet(false), m_bBottomSet(false), m_bVisualStyle(false)
      , m_dTop(0.0), m_dBottom(0.0), m_visualStyle(NULL) { }
    bool isEnabled() const { return m_bEnabled && !m_points.isEmpty(); }
  };
 
protected:
  void addViewRef(OdGsViewImpl* pView);
  void removeViewRef(OdGsViewImpl* pView);
 
  /** \details
    For internal needs. Do not use!
  */
  void setInvalidVp(unsigned int viewportId, bool val)
  {
    if(m_viewProps.size()>viewportId)
      m_viewProps[viewportId].setInvalid(val);
  }
  virtual void clearChangedLayersList();
 
protected:
 
  OdArray<ViewProps>           m_viewProps;
  OdUInt32                     m_nLayers;
  OdGsLayerNode*               m_pFirstChangedLayer;
 
  OdGsView::RenderMode         m_renderModeOverride;
  OdGeMatrix3d                 m_xForm;
  AdditionMode                 m_additionMode;
  OdDbStub*                    m_modelBackground;
  OdGsVisualStylePropertiesPtr m_modelVisualStyle;
 
  RenderType                   m_renderType;
  // Reserved pointer for internal use (binary incompatible changes), do not delete.
  OdRxObjectPtr                m_pGsReserved;
 
  // Material cache support
  OdGsMaterialCachePtr         m_pMaterialCache;
 
  OdGsBaseModelImpl*           m_impl;
 
  SectioningSettings           m_sectioning;
 
#ifdef ODGS_LOCAL_IDS
  OdGsBaseModelLocalIdsPtr     m_pViewIds;
#endif
 
  OdVector<OdGsModelReactor*, OdMemoryAllocator<OdGsModelReactor*> > m_modelReactors;
  OdVector<OdGsBaseModelReactor*, OdMemoryAllocator<OdGsBaseModelReactor*> > m_baseModelReactors;
 
protected:
 
  OdGsBaseModel();
  ~OdGsBaseModel();
 
public:
  /** \details
    Returns the OdGsNode object associated with the specified Drawable.
    
    \param pDrawable [in]  Pointer to the Drawable object.
    \remarks
    If no Node object is associated with the Drawable object, one is created.
  */
  virtual OdGsNode* gsNode(OdGiDrawable* pDrawable);
 
  /** \details
    Removes the associations between the specified Node object and this BaseModel object.
    \param pNode [in]  Pointer to the Node object. 
  */
  virtual void detach(OdGsNode* pNode);
 
  /** \details
    Removes all Node objects from this BaseModel object.
  */
  virtual void detachAll();
 
  void detachAllFromDb(const OdDbBaseDatabase* pDb);
 
  /** \details
    Opens the specified object.
    \param objectID [in]  Object ID of the Drawable object to be opened.
    
    \remarks
    Returns a SmartPointer to the opened object.
  */
  OdGiDrawablePtr open(OdDbStub* objectId);
 
  void setOpenDrawableFn(OdGiOpenDrawableFn openDrawableFn);
  OdGiOpenDrawableFn openDrawableFn() const;
 
  void onAdded(OdGiDrawable* pAdded, OdGiDrawable* pParent);
  void onAdded(OdGiDrawable* pAdded, OdDbStub* parentID);
  virtual void onAddedImpl(OdGiDrawable* pAdded, OdGiDrawable* pParent);
  
  void onModified(OdGiDrawable* pModified, OdGiDrawable* pParent);
  void onModified(OdGiDrawable* pModified, OdDbStub* parentID);
  virtual void onModifiedImpl(OdGiDrawable* pModified, OdGiDrawable* pParent);
  
  void onErased(OdGiDrawable* pErased, OdGiDrawable* pParent);
  void onErased(OdGiDrawable* pErased, OdDbStub* parentID);
  virtual void onErasedImpl(OdGiDrawable* pErased, OdGiDrawable* pParent);
 
  void invalidate(InvalidationHint hint);
  void invalidate(OdGsView* pView);
  /** \param view [in]  BaseVectorizeView object for which data are to be invalidated.
    \param mask [in]  Mask.
  */
  void invalidate(OdGsViewImpl& view, OdUInt32 mask);
 
  /** \details
    Returns the view properties that have changed for the specified Viewport
    
    \param viewportId [in]  Viewport ID. 
  */
  OdUInt32 viewChanges(OdUInt32 viewportId) const;
  /** \details
    Returns the size of the ViewProperties array for this BaseModel object.
  */
  OdUInt32 numViewProps() const;
  
  /** \details
    Returns a reference to the the ViewProp structure for the specified Viewport.
    
    \param viewportId [in]  Viewport ID. 
  */
  const ViewProps& viewProps(OdUInt32 viewportId) const;
  
  /** \details
    Updates the ViewProps structure for the specified Viewport.
    \param viewport [in]  Viewport.
  */
  virtual void updateViewProps(const OdGsViewImpl& viewport);
 
  virtual bool isViewPropsValid(OdUInt32 viewportId) const;
 
  virtual OdGsLayerNode* gsLayerNode(OdDbStub* layerId, const OdGsBaseVectorizer* pView);
 
  virtual void propagateLayerChanges(OdGsBaseVectorizeDevice& device);
 
  void setTransform(const OdGeMatrix3d& xForm);
 
  OdGeMatrix3d transform() const;
 
  OdGsView::RenderMode renderModeOverride() const;
 
  void setRenderModeOverride(OdGsView::RenderMode mode = OdGsView::kNone);
 
  void highlight(const OdGiPathNode& path, bool bDoIt = true, const OdGsView* pView = NULL);
  virtual void highlightImpl(const OdGiPathNode& path, bool bDoIt = true, const OdGsView* pView = NULL);
 
  // Material cache support
  OdGsMaterialCache* materialCache() { return m_pMaterialCache.get(); }
 
  void setAdditionMode(AdditionMode mode);
  AdditionMode additionMode() const;
 
  void setRenderType(RenderType renderType);
  RenderType renderType() const;
 
  void setBackground(OdDbStub *backgroundId);
  OdDbStub *background() const;
 
  void setVisualStyle(OdDbStub *visualStyleId);
  OdDbStub *visualStyle() const;
  void setVisualStyle(const OdGiVisualStyle &visualStyle);
  bool visualStyle(OdGiVisualStyle &visualStyle) const;
 
  virtual bool makeStock(OdDbStub* layoutId);
  virtual void releaseStock(OdDbStub* layoutId);
 
  bool hasChangedLayers() const { return m_pFirstChangedLayer != NULL; }
 
  void addModelReactor(OdGsModelReactor *pReactor);
  void removeModelReactor(OdGsModelReactor *pReactor);
 
  void setEnableSectioning(bool bEnable);
  bool isSectioningEnabled() const;
  bool setSectioning(const OdGePoint3dArray &points, const OdGeVector3d &upVector);
  bool setSectioning(const OdGePoint3dArray &points, const OdGeVector3d &upVector,
                     double dTop, double dBottom);
  void setSectioningVisualStyle(OdDbStub *visualStyleId);
  const SectioningSettings &getSectioning() const { return m_sectioning; }
 
  virtual bool saveModelState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer = NULL) const;
  virtual bool loadModelState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer = NULL);
  virtual bool saveClientModelState(OdGsFiler *pFiler) const;
  virtual bool loadClientModelState(OdGsFiler *pFiler);
  bool postprocessModelLoading(OdGsFiler *pFiler);
protected:
  void onModifiedNode(OdGsNode* pCache, OdGiDrawable* pDrawable, OdGiDrawable* pParent);
  void onModifiedDrawable(OdGiDrawable* pDrawable, OdGiDrawable* pParent);
  void onPropertyModifiedImpl(OdGsBaseModelReactor::ModelProperty nProp, bool &bReturnValue);
  virtual bool onPropertyModified(OdGsBaseModelReactor::ModelProperty nProp);
};
 
inline OdGsView::RenderMode OdGsBaseModel::renderModeOverride() const
{
  return m_renderModeOverride;
}
 
inline OdGiDrawablePtr OdGsBaseModel::open(OdDbStub* objectId) 
{
  if(m_openDrawableFn)
    return m_openDrawableFn(objectId);
  //ODA_ASSERT_ONCE(objectId==0);
  return OdGiDrawablePtr();
}
 
inline OdUInt32 OdGsBaseModel::numViewProps() const
{
  return m_viewProps.size();
}
 
inline const ViewProps& OdGsBaseModel::viewProps(OdUInt32 viewportId) const
{
  ODA_ASSERT(m_viewProps.size() > viewportId);
  return m_viewProps[viewportId];
}
 
inline OdUInt32 OdGsBaseModel::viewChanges(OdUInt32 viewportId) const
{
  return viewProps(viewportId).m_nViewChanges;
}
 
inline OdGsViewImpl *OdGsBaseModel::refView() const
{
  if (m_views.empty())
    return NULL;
  return m_views.first().first;
}
 
inline OdGsModel::AdditionMode OdGsBaseModel::additionMode() const
{
  return m_additionMode;
}
 
inline OdGsModel::RenderType OdGsBaseModel::renderType() const
{
  return m_renderType;
}
 
#include "TD_PackPop.h"
 
#endif // __ODGSMODELIMPL_H__