CFx SDK Documentation  2022 SP0
GsBlockNode.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef __OD_GS_BLOCK_NODE__
25 #define __OD_GS_BLOCK_NODE__
26 
27 #include "TD_PackPush.h"
28 
29 #include "GsBlockReferenceNode.h"
30 #include "Ge/GeScale3d.h"
32 #include "Gi/GiAnnoScaleSet.h"
33 #define STL_USING_SET
34 #define STL_USING_MAP
35 #include "OdaSTL.h"
36 #include "ThreadsCounter.h"
37 
38 class OdGsSharedRefDefinition;
39 class OdGsReferenceImpl;
40 
47 {
48 public:
49  OdGsBlockRefNodeDescMem(const OdDbStub* layoutBlockId, const OdGiSubEntityTraitsData& tr,
50  const OdGeScale3d& scale, bool bUsePlotStyles):
51  m_layoutBlockId(layoutBlockId),
52  m_layerId(tr.layer())
53  , m_lineTypeId(tr.lineType())
54  , m_cmColor(tr.trueColor().color())
55  , m_lineWeight(tr.lineWeight())
56  , m_lineTypeScale(tr.lineTypeScale())
57  , m_plotStyleNameType(bUsePlotStyles ? tr.plotStyleNameType() : OdDb::kPlotStyleNameIsDictDefault)
58  , m_plotStyleNameId(bUsePlotStyles ? tr.plotStyleNameId() : NULL)
59  , m_materialId(tr.material()), m_cmTransparency(tr.transparency().serializeOut())
60  , m_scale(scale)
61  {
62  }
64  {
65  ::memcpy(this, &c, sizeof(OdGsBlockRefNodeDescMem));
66  }
67  OdGsBlockRefNodeDescMem(){ ::memset(this, 0, sizeof(OdGsBlockRefNodeDescMem)); }
68 
69 protected:
70  bool lessOrEqual(const OdGsBlockRefNodeDescMem& v, bool& bEqual) const;
71 
72 public:
73  const OdDbStub* m_layoutBlockId;
74  OdDbStub* m_layerId;
75  OdDbStub* m_lineTypeId;
79 
81  OdDbStub* m_plotStyleNameId;
82 
83  OdDbStub* m_materialId;
85 
87 };
88 
95 {
96 public:
97  OdGsBlockRefNodeDesc(const OdDbStub* layoutBlockId, const OdGiSubEntityTraitsData& tr,
98  const OdGeScale3d& scale, bool bUsePlotStyles, const OdGiAnnoScaleSet& annoScales):
99  OdGsBlockRefNodeDescMem(layoutBlockId, tr, scale, bUsePlotStyles), m_annoScales(annoScales)
100  {
101  }
102  OdGsBlockRefNodeDesc(const OdGsBlockRefNodeDesc& c): OdGsBlockRefNodeDescMem(c), m_annoScales(c.m_annoScales)
103  {
104  }
106 
107  bool operator < (const OdGsBlockRefNodeDesc& v) const
108  {
109  bool bEqual = false;
110  if(lessOrEqual(v, bEqual) && !bEqual)
111  return true;
112  return bEqual ? m_annoScales < v.m_annoScales : false;
113  }
114 public:
116 };
117 
124 {
125 protected:
126  enum
127  {
128  kUnloaded = OdGsNode::kLastFlag << 1,
129  kLastFlag = kUnloaded
130  };
131 public:
132  enum
133  {
134  kInvalidateRefExtentsMask = (kVpLastPropBit << 1)
135  //NS: use this mask in invalidate() to invalidate extents of corresponding
136  //references when block is modified
137  };
138 
140 
141  OdGsBlockNode(OdGsBaseModel* pModel, const OdGiDrawable* pUnderlyingDrawable,
142  bool bSetGsNode): OdGsNode(pModel, pUnderlyingDrawable), m_bModelTfDependent(0)
143  {
144  if(bSetGsNode)
145  setToDrawable(pUnderlyingDrawable);
146  }
148  {
149  if (isUnloaded())
150  {
151  // this block-node corresponds to block in xreffed db;
152  // here db can be unloaded, so prevent access to the associated block table record.
153  SETBIT(m_flags, kSyncDrawable, false);
154  }
155  clearInserts();
156  }
157 
158  void setUnloaded(bool isUnloaded);
159  bool isUnloaded() const;
160  void setModelTfDependent(bool bOn);
161  bool isModelTfDependent() const;
162 
163  virtual ENodeType nodeType() const { return kBlockNode; }
164 
166 
168  {
169  if(odThreadsCounter())
170  {
171  TD_AUTOLOCK_P(m_insertsMt.get());
172  m_inserts.insert(pEntity);
173  }
174  else
175  {
176  m_inserts.insert(pEntity);
177  }
178  }
179 
181  {
182  TD_AUTOLOCK_P_DEF(m_insertsMt);
183  m_inserts.erase(pEntity);
184  if(!isUnloaded() || !m_inserts.empty())
185  return;
186  // this block-node corresponds to block in xreffed db;
187  // here db can be unloaded, so prevent access to the associated block table record.
188  SETBIT(m_flags, kSyncDrawable, false);
189  baseModel()->detach(this);
190  }
191 
197  void update(OdGsUpdateContext&, OdGsContainerNode*, OdSiSpatialIndex*)
198  {
199  ODA_ASSERT(false);
200  }
201 
206  void display(OdGsDisplayContext&)
207  {
208  ODA_ASSERT(false);
209  }
210 
219  bool extents(OdGeExtents3d&) const
220  {
221  ODA_ASSERT(false);
222  return false;
223  }
224 
232  virtual void propagateLayerChanges(OdGsViewImpl& /*view*/);
233 
234  void destroy();
235 
237  {
238  m_sharedImp.destroy();
239  }
240 
241  OdGsSharedRefDefinition* createDef(const OdGsBlockRefNodeDesc& d);
242  OdGsSharedRefDefinition* findCreateDef(const OdGsBlockRefNodeDesc& d)
243  {
244  if(odThreadsCounter())
245  {
246  TD_AUTOLOCK_P(m_sharedMt.get());
247  OdGsSharedRefDefinition* pRes = m_sharedImp.findAt(d);
248  return pRes ? pRes : createDef(d);
249  }
250  OdGsSharedRefDefinition* pRes = m_sharedImp.findAt(d);
251  return pRes ? pRes : createDef(d);
252  }
253 
254  void invalidateSharedSubents(OdUInt32 vpID, OdUInt32 nViewChanges);
255 
256  void invalidateSharedRegenDraw(OdUInt32 vpID, const OdDbStub* layoutId);
258  void invalidateSharedAwareFlags(OdGsViewImpl* pView, OdUInt32 nViewChanges, const OdDbStub* layoutId);
259 
260  void removeDef(OdGsSharedRefDefinition* pDef)
261  {
262  if(odThreadsCounter())
263  {
264  TD_AUTOLOCK_P(m_sharedMt.get());
265  m_sharedImp.removeDef(pDef);
266  }
267  else
268  {
269  m_sharedImp.removeDef(pDef);
270  }
271  }
272  bool findDef(OdGsSharedRefDefinition* pDef, OdGsBlockRefNodeDesc& d)
273  {
274  if(odThreadsCounter())
275  {
276  TD_AUTOLOCK_P(m_sharedMt.get());
277  return m_sharedImp.findDef(pDef, d);
278  }
279  return m_sharedImp.findDef(pDef, d);
280  }
281 
282  bool saveNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer = NULL) const;
283  bool loadNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer = NULL);
285 
286 protected:
287  void clearInserts();
288 
289 protected:
291  {
292  public:
293  ~ImpMap() { clear(); }
294  void clear();
295  void destroy();
296  OdGsSharedRefDefinition* findAt(const OdGsBlockRefNodeDesc& d)
297  {
298  _map::iterator it = m_map.find(d);
299  return (it == m_map.end() ? NULL : it->second);
300  }
301  OdGsSharedRefDefinition* insertAt(const OdGsBlockRefNodeDesc& d,
302  OdGsReferenceImpl* pImp);
304  void invalidateSubents(OdUInt32 vpID, OdUInt32 nViewChanges);
305  void invalidateRegenDraw(OdUInt32 vpID, const OdDbStub* layoutId);
306  void removeDef(OdGsSharedRefDefinition* pDef);
307  bool findDef(OdGsSharedRefDefinition* pDef, OdGsBlockRefNodeDesc& d);
309 #ifndef ODGS_LOCAL_IDS
310  void invalidateAwareFlags(OdGsViewImpl* pView, OdUInt32 nViewChanges, const OdDbStub* layoutId);
311 #else
312  void invalidateAwareFlags(OdGsViewImpl* pView, OdUInt32 nViewChanges, const OdDbStub* layoutId, OdGsBaseModel* pModel);
313 #endif
315 
316  public:
317  typedef std::map<OdGsBlockRefNodeDesc, OdGsSharedRefDefinition*,
318  std::less<OdGsBlockRefNodeDesc> > _map;
320  };
321 
322 protected:
323  typedef std::set<OdGsBlockReferenceNode*> Inserts;
324  typedef Inserts::iterator InsertIterator;
329  volatile int m_bModelTfDependent;
330 };
331 
332 inline void OdGsBlockNode::setUnloaded(bool isUnloaded)
333 {
335 }
336 
337 inline bool OdGsBlockNode::isUnloaded() const
338 {
339  return GETBIT(m_flags, kUnloaded);
340 }
341 
343 {
344  if(isModelTfDependent() == bOn)
345  return;
346 #ifndef TD_SINGLE_THREAD
347  OdInterlockedExchangeAdd(&m_bModelTfDependent, bOn ? 1 : -1);
348 #else
349  m_bModelTfDependent = bOn;
350 #endif
351  if(bOn)
352  {
353  //don't keep content of m_sharedImp anymore. These definitions remain
354  //on inserts, if any, and will be released in the course of their update()
355  if(odThreadsCounter())
356  {
358  m_sharedImp.clear();
359  }
360  else
361  {
362  m_sharedImp.clear();
363  }
364  }
365 }
366 
368 {
369  //atomic function is required, called in MT mode (update)
370 #ifndef TD_SINGLE_THREAD
371  return OdInterlockedExchangeAdd(&const_cast<OdGsBlockNode*>(this)->m_bModelTfDependent, 0) != 0;
372 #else
373  return m_bModelTfDependent;
374 #endif
375 }
376 
377 #include "TD_PackPop.h"
378 
379 #endif // __OD_GS_BLOCK_NODE__
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
scale
Definition: DimVarDefs.h:1684
ENodeType
Definition: GsBaseModel.h:65
@ kBlockNode
Definition: GsBaseModel.h:69
#define GS_TOOLKIT_EXPORT
Definition: GsExport.h:37
#define NULL
Definition: GsProperties.h:177
bool isModelTfDependent(OdUInt32 flags)
@ kVpLastPropBit
unsigned int OdUInt32
bool operator<(const OdString &s1, const OdString &s2)
Definition: OdString.h:1284
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:497
#define GETBIT(flags, bit)
Definition: OdaDefs.h:498
FIRSTDLL_EXPORT ThreadsCounter & odThreadsCounter()
#define TD_AUTOLOCK_P_DEF(Mutex)
#define TD_AUTOLOCK_P(Mutex)
bool layersChanged(OdGsViewImpl &view, OdGsBaseModel *pModel)
void removeDef(OdGsSharedRefDefinition *pDef)
void invalidateRegenDraw(OdUInt32 vpID, const OdDbStub *layoutId)
void propagateLayerChangesStock()
OdGsSharedRefDefinition * insertAt(const OdGsBlockRefNodeDesc &d, OdGsReferenceImpl *pImp)
bool findDef(OdGsSharedRefDefinition *pDef, OdGsBlockRefNodeDesc &d)
void invalidateAwareFlags(OdGsViewImpl *pView, OdUInt32 nViewChanges, const OdDbStub *layoutId)
std::map< OdGsBlockRefNodeDesc, OdGsSharedRefDefinition *, std::less< OdGsBlockRefNodeDesc > > _map
Definition: GsBlockNode.h:318
OdGsSharedRefDefinition * findAt(const OdGsBlockRefNodeDesc &d)
Definition: GsBlockNode.h:296
void invalidateSubents(OdUInt32 vpID, OdUInt32 nViewChanges)
Inserts::iterator InsertIterator
Definition: GsBlockNode.h:324
bool extents(OdGeExtents3d &) const
Definition: GsBlockNode.h:219
virtual void propagateLayerChanges(OdGsViewImpl &)
ODRX_DECLARE_MEMBERS(OdGsBlockNode)
void update(OdGsUpdateContext &, OdGsContainerNode *, OdSiSpatialIndex *)
Definition: GsBlockNode.h:197
bool findDef(OdGsSharedRefDefinition *pDef, OdGsBlockRefNodeDesc &d)
Definition: GsBlockNode.h:272
bool saveNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer=NULL) const
void removeDef(OdGsSharedRefDefinition *pDef)
Definition: GsBlockNode.h:260
void clearInserts()
void invalidateSharedAwareFlags(OdGsViewImpl *pView, OdUInt32 nViewChanges, const OdDbStub *layoutId)
void invalidateSharedRegenDraw(OdUInt32 vpID, const OdDbStub *layoutId)
Inserts m_inserts
Definition: GsBlockNode.h:325
void setModelTfDependent(bool bOn)
Definition: GsBlockNode.h:342
bool isUnloaded() const
Definition: GsBlockNode.h:337
void invalidate(OdGsContainerNode *pParent, OdGsViewImpl *view, OdUInt32 mask)
OdMutexPtr m_insertsMt
Definition: GsBlockNode.h:328
std::set< OdGsBlockReferenceNode * > Inserts
Definition: GsBlockNode.h:323
OdMutexPtr m_sharedMt
Definition: GsBlockNode.h:327
OdGsBlockNode(OdGsBaseModel *pModel, const OdGiDrawable *pUnderlyingDrawable, bool bSetGsNode)
Definition: GsBlockNode.h:141
void invalidateSharedSectionable()
void display(OdGsDisplayContext &)
Definition: GsBlockNode.h:206
void invalidateShared()
Definition: GsBlockNode.h:236
bool loadNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer=NULL)
void release(OdGsBlockReferenceNode *pEntity)
Definition: GsBlockNode.h:180
volatile int m_bModelTfDependent
Definition: GsBlockNode.h:329
OdGsSharedRefDefinition * findCreateDef(const OdGsBlockRefNodeDesc &d)
Definition: GsBlockNode.h:242
void setUnloaded(bool isUnloaded)
Definition: GsBlockNode.h:332
void addRef(OdGsBlockReferenceNode *pEntity)
Definition: GsBlockNode.h:167
ImpMap m_sharedImp
Definition: GsBlockNode.h:326
virtual ENodeType nodeType() const
Definition: GsBlockNode.h:163
void invalidateSharedSubents(OdUInt32 vpID, OdUInt32 nViewChanges)
OdGsSharedRefDefinition * createDef(const OdGsBlockRefNodeDesc &d)
bool isModelTfDependent() const
Definition: GsBlockNode.h:367
bool postprocessNodeLoading(OdGsFiler *pFiler)
OdGsBlockRefNodeDesc(const OdGsBlockRefNodeDesc &c)
Definition: GsBlockNode.h:102
OdGiAnnoScaleSet m_annoScales
Definition: GsBlockNode.h:115
OdGsBlockRefNodeDesc(const OdDbStub *layoutBlockId, const OdGiSubEntityTraitsData &tr, const OdGeScale3d &scale, bool bUsePlotStyles, const OdGiAnnoScaleSet &annoScales)
Definition: GsBlockNode.h:97
OdGsBlockRefNodeDescMem(const OdGsBlockRefNodeDescMem &c)
Definition: GsBlockNode.h:63
bool lessOrEqual(const OdGsBlockRefNodeDescMem &v, bool &bEqual) const
OdGsBlockRefNodeDescMem(const OdDbStub *layoutBlockId, const OdGiSubEntityTraitsData &tr, const OdGeScale3d &scale, bool bUsePlotStyles)
Definition: GsBlockNode.h:49
OdDb::LineWeight m_lineWeight
Definition: GsBlockNode.h:77
OdDbStub * m_plotStyleNameId
Definition: GsBlockNode.h:81
const OdDbStub * m_layoutBlockId
Definition: GsBlockNode.h:73
OdDb::PlotStyleNameType m_plotStyleNameType
Definition: GsBlockNode.h:80
OdUInt32 m_flags
Definition: GsNode.h:87
@ kLastFlag
Definition: GsNode.h:84
OdMutex * get()
GLenum GLint GLuint mask
Definition: gles2_ext.h:262
const GLfloat * v
Definition: gles2_ext.h:315
PlotStyleNameType
Definition: OdaDefs.h:413
@ kPlotStyleNameIsDictDefault
Definition: OdaDefs.h:416
LineWeight
Definition: OdaDefs.h:382