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
/////////////////////////////////////////////////////////////////////////////// 
// 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 DBSYMUTL_DEFINED
#define DBSYMUTL_DEFINED
 
#include "TD_PackPush.h"
 
#include "OdString.h"
#include "DbObjectId.h"
#include "DbSymbolTable.h"
#include "DbSymbolTableRecord.h"
#include "DbTextStyleTableRecord.h"
#include "DbDictionary.h"
#include "DbDatabase.h"
 
// Predefined names
#define AC_STRING(name, val) \
extern TOOLKIT_EXPORT_GLOBAL const OdConstString name;
#include "StdStrings.h"
#undef AC_STRING
 
/** \details
 
    <group TD_Namespaces>
*/
namespace OdDbSymUtil
{
  // --- DbSymbolUtilities Services  ---
 
  TOOLKIT_EXPORT OdResult repairPreExtendedSymbolName(
    OdString& newName,
    const OdString& oldName,
    const OdDbDatabase* pDb,
    bool allowVerticalBar = false,
    const OdChar symSubst = L'_',
    bool insertPrefix = true);
 
  /** \details
    If the symbol name was repaired, then newName is a repaired symbol name. 
    newName is empty if oldName did not need any repairing.
    allowVerticalBar is a boolean to indicate if vertical bars are allowed in the symbol name 
    
    \returns
    eInvalidInput      if the specified name is empty
    eOk                in else case 
  */
  TOOLKIT_EXPORT OdResult repairSymbolName(
    OdString& newName,
    const OdString& oldName,
    const OdDbDatabase* pDb,
    bool allowVerticalBar = false,
    const OdChar symSubst = L'_',
    bool insertPrefix = true);
  
  TOOLKIT_EXPORT OdResult validatePreExtendedSymbolName(
    const OdString& name,
    const OdDbDatabase* pDb,
    bool allowVerticalBar = false);
 
  /** \details
    This method validates name according to the rules for extended (AutoCAD 2000 and later) symbol names.
    allowVerticalBar is a boolean to indicate if vertical bars are allowed in the symbol name 
    
    \returns
    eOk            Symbol name is valid 
    eInvalidInput  Symbol name contains invalid characters 
  */
  TOOLKIT_EXPORT OdResult validateSymbolName(
    const OdString& name,
    const OdDbDatabase* pDb,
    bool allowVerticalBar = false);
 
  TOOLKIT_EXPORT bool getMaxSymbolNameLength(
    OdUInt32& maxLength,
    OdUInt32& maxSize,
    bool isNewName,
    bool compatibilityMode); // true for extended names
 
  inline OdString getSymbolName(const OdDbObjectId& objId)
  {
    OdDbSymbolTableRecordPtr pRec
      = OdDbSymbolTableRecord::cast(objId.openObject(OdDb::kForRead, true).get());
    if (!pRec.isNull())
    {
      return pRec->getName();
    }
    return OdString::kEmpty;
  }
 
  #define DBSYMUTL_MAKE_GETSYMBOLID_FUNC(T_TABLE) \
  inline OdDbObjectId \
  get ## T_TABLE ## Id(const OdString& name, const OdDbDatabase *pDb) \
  { \
    OdDbSymbolTablePtr pTable = pDb->get ## T_TABLE ## TableId().safeOpenObject(); \
    ODA_ASSERT(!pTable->isOdDbObjectIdsInFlux()); \
    return pTable->getAt(name); \
  }
  DBSYMUTL_MAKE_GETSYMBOLID_FUNC(Viewport)
  DBSYMUTL_MAKE_GETSYMBOLID_FUNC(Block)
  DBSYMUTL_MAKE_GETSYMBOLID_FUNC(DimStyle)
  DBSYMUTL_MAKE_GETSYMBOLID_FUNC(Layer)
  DBSYMUTL_MAKE_GETSYMBOLID_FUNC(Linetype)
  DBSYMUTL_MAKE_GETSYMBOLID_FUNC(RegApp)
  //DBSYMUTL_MAKE_GETSYMBOLID_FUNC(TextStyle)
 
  inline OdDbObjectId getTextStyleId(const OdString& name, const OdDbDatabase *pDb)
  {
    OdDbSymbolTablePtr pTable = pDb->getTextStyleTableId().safeOpenObject();
    ODA_ASSERT(!pTable->isOdDbObjectIdsInFlux());
    OdDbTextStyleTableRecordPtr pRec = pTable->getAt(name, OdDb::kForRead);
 
    if (pRec.get())
      if (!pRec->isShapeFile())
        return pRec->objectId();
    return OdDbObjectId::kNull;
  }
 
  DBSYMUTL_MAKE_GETSYMBOLID_FUNC(UCS)
  DBSYMUTL_MAKE_GETSYMBOLID_FUNC(View)
  #undef DBSYMUTL_MAKE_GETSYMBOLID_FUNC
 
  inline OdDbObjectId getPlotstyleId(const OdString& name, const OdDbDatabase *pDb)
  {
    OdDbDictionaryPtr pDic = pDb->getPlotStyleNameDictionaryId(false).openObject();
    if (!pDic.isNull())
    {
      ODA_ASSERT(!pDic->isOdDbObjectIdsInFlux());
      return pDic->getAt(name);
    }
    return OdDbObjectId::kNull;
  }
 
  inline OdDbObjectId getMLStyleId(const OdString& name, const OdDbDatabase *pDb)
  {
    OdDbDictionaryPtr pDic = pDb->getMLStyleDictionaryId(false).openObject();
    if (!pDic.isNull())
    {
      ODA_ASSERT(!pDic->isOdDbObjectIdsInFlux());
      return pDic->getAt(name);
    }
    return OdDbObjectId::kNull;
  }
 
  inline OdDbObjectId getTableStyleId(const OdString& name, const OdDbDatabase *pDb)
  {
    OdDbDictionaryPtr pDic = pDb->getTableStyleDictionaryId(false).openObject();
    if (!pDic.isNull())
    {
      ODA_ASSERT(!pDic->isOdDbObjectIdsInFlux());
      return pDic->getAt(name);
    }
    return OdDbObjectId::kNull;
  }
 
  inline OdDbObjectId getMLeaderStyleId(const OdString& name, const OdDbDatabase *pDb)
  {
    OdDbDictionaryPtr pDic = pDb->getMLeaderStyleDictionaryId(false).openObject();
    if (!pDic.isNull())
    {
      ODA_ASSERT(!pDic->isOdDbObjectIdsInFlux());
      return pDic->getAt(name);
    }
    return OdDbObjectId::kNull;
  }
 
  inline OdDbObjectId getVisualStyleId(const OdString& name, const OdDbDatabase *pDb)
  {
    OdDbDictionaryPtr pDic = pDb->getVisualStyleDictionaryId(false).openObject();
    if (!pDic.isNull())
    {
      ODA_ASSERT(!pDic->isOdDbObjectIdsInFlux());
      return pDic->getAt(name);
    }
    return OdDbObjectId::kNull;
  }
 
  inline const OdString& linetypeByLayerName()
  { return  byLayerNameStr; }
 
  inline bool isLinetypeByLayerName(const OdString& name)
  { return !odStrICmp(name, linetypeByLayerName()); }
 
  inline const OdString& linetypeByBlockName()
  { return  byBlockNameStr; }
 
  inline bool isLinetypeByBlockName(const OdString& name)
  { return !odStrICmp(name, linetypeByBlockName()); }
 
  inline const OdString& linetypeContinuousName()
  { return  linetypeContinuousNameStr; }
 
  inline bool isLinetypeContinuousName(const OdString& name)
  { return !odStrICmp(name, linetypeContinuousName()); }
 
  inline const OdString& layerZeroName()
  { return  layerZeroNameStr; }
 
  inline bool isLayerZeroName(const OdString& name)
  { return !odStrICmp(name, layerZeroName()); }
 
  inline const OdString& layerDefpointsName()
  { return  layerDefpointsNameStr; }
 
  inline bool isLayerDefpointsName(const OdString& name)
  { return !odStrICmp(name, layerDefpointsName()); }
 
  inline const OdString& textStyleStandardName()
  { return standardStr; }
 
  inline const OdString& MLineStyleStandardName()
  { return standardStr; }
 
  inline bool isMLineStandardName(const OdString& name)
  { return !odStrICmp(name, MLineStyleStandardName()); }
 
  inline const OdString& dimStyleStandardName(OdDb::MeasurementValue measurement)
  { return measurement == OdDb::kEnglish ? standardStr : metricDimStandardStr; }
 
  inline const OdString& viewportActiveName()
  { return viewportActiveNameStr; }
 
  inline bool isViewportActiveName(const OdString& name)
  { return !odStrICmp(name, viewportActiveName()); }
 
  inline bool isTextStyleStandardName(const OdString& name)
  { return !odStrICmp(name, textStyleStandardName()); }
 
  TOOLKIT_EXPORT const OdDbObjectId& textStyleStandardId(OdDbDatabase* pDb);
    TOOLKIT_EXPORT const OdDbObjectId& dimStyleStandardId(OdDbDatabase* pDb);
  TOOLKIT_EXPORT const OdDbObjectId  MLineStyleStandardId(OdDbDatabase* pDb);
 
  inline const OdString& blockModelSpaceName(OdDb::DwgVersion version = OdDb::kDHL_CURRENT)
  { return version <= OdDb::vAC12 ? modelSpaceStr_R12 : modelSpaceStr; }
 
  inline bool isBlockModelSpaceName(const OdString& pN, OdDb::DwgVersion version = OdDb::kDHL_CURRENT)
  { return odStrICmp(pN, blockModelSpaceName(version)) == 0; }
 
  inline const OdString& blockPaperSpaceName(OdDb::DwgVersion version = OdDb::kDHL_CURRENT)
  { return version <= OdDb::vAC12 ? paperSpaceStr_R12 : paperSpaceStr; }
 
  inline bool isBlockPaperSpaceName(const OdString& pN, OdDb::DwgVersion version = OdDb::kDHL_CURRENT)
  { return odStrICmp(pN, blockPaperSpaceName(version)) == 0; }
 
  inline const OdString& plotStyleNormalName()
  { return plotStyleNormalNameStr;}
 
  inline const OdString& TableStyleStandardName()
  { return standardStr; }
 
  inline bool isTableStandardName(const OdString& name)
  { return !odStrICmp(name, TableStyleStandardName()); }
 
  inline const OdString& MLeaderStyleStandardName()
  { return standardStr; }
 
  inline bool isMLeaderStandardName(const OdString& name)
  { return !odStrICmp(name, MLeaderStyleStandardName()); }
 
  inline const OdString& DetailViewStyleStandardName(OdDbDatabase* pDb)
  {
    ODA_ASSERT_ONCE(pDb);
    return (pDb && pDb->getMEASUREMENT() == OdDb::kMetric) ? standardMetricDictStr : standardImperialDictStr;
  }
 
  inline bool isDetailViewStyleStandardName(OdDbDatabase* pDb, const OdString& name)
  { 
    return !odStrICmp(name, DetailViewStyleStandardName(pDb)); 
  }
 
  inline const OdString& SectionViewStyleStandardName(OdDbDatabase* pDb)
  {
    return DetailViewStyleStandardName(pDb);
  }
 
  inline bool isSectionViewStyleStandardName(OdDbDatabase* pDb, const OdString& name)
  { 
    return !odStrICmp(name, SectionViewStyleStandardName(pDb)); 
  }
}
// namespace OdDbSymUtil
 
#include "TD_PackPop.h"
 
#endif // DBSYMUTL_DEFINED