CFx SDK Documentation  2020SP3
TxDefs.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 _TXDEFS_H_
25 #define _TXDEFS_H_
26 
27 
28 #include "RxDictionary.h"
29 #include "OdStreamBuf.h"
30 #include "DynamicLinker.h"
31 
32 
33 #include "OdPlatformSettings.h"
34 #include "StringArray.h"
35 #include "RxVariantValue.h"
36 #include "Ed/EdCommandContext.h"
37 #include "Ed/EdCommandStack.h"
38 #include "Ed/EdFunctionIO.h"
39 #include "Path.h"
40 #include "OdCharMapper.h"
41 
42 
43 #define TXAPP_FULLNAME "Host Application"
44 #define TXHOST_CURR_CMDCTX "TXHOST_CURR_CMDCTX"
45 #define TXHOST_SETTINGS_NAME "TxHostStorage"
46 
47 
48 namespace Oda { // shortened Teigha identifiers
49 
50  typedef OdUInt8 UI8;
51  typedef OdUInt16 UI16;
52  typedef OdUInt32 UI32;
53  typedef OdInt32 I32;
54  typedef OdUInt64 UI64;
55  typedef OdInt64 I64;
56 
57  typedef OdError EXCEP;
58  typedef const EXCEP& EXCEPREF;
59 
60  typedef OdAnsiString ASTR;
61  typedef const ASTR& ASTRREF;
62  typedef OdString WSTR;
63  typedef const WSTR& WSTRREF;
64  typedef const char* ACSZ;
65  typedef const OdChar* WCSZ;
66 
67  typedef OdRxObject RXOBJ;
71 
72 
73  typedef OD::Path PATH;
74  typedef const PATH& PATHREF;
75 
76 
81 
82  typedef OdRxVariant RXVAR;
86 
87 
90  typedef OdEdCommand CMD;
92  typedef OdEdUserIO USERIO;
93 
94 
95  class HRXDIC : public RXDICPTR {
96  protected:
97  inline void validate();
98  public:
99  HRXDIC();
100  HRXDIC(const RXOBJ* dictionary);
101  HRXDIC& operator=(const RXOBJ* dictionary);
102 
103  static HRXDIC create();
104  static HRXDIC arbDataOpen(CMDCTX* cmdctx, WSTRREF name, bool bCreateIfNotFound = false);
105  HRXDIC step(WSTRREF name, bool bCreateIfNotFound = false);
106  HRXDIC walk(const PATH& path, bool bCreateIfNotFound = false);
108  HRXDIC walkCr(const PATH& path);
110  RXPTR putAt(WSTRREF name, RXOBJ* obj);
111  RXPTR getAt(UI32 indx);
112  RXPTR putAt(UI32 indx, RXOBJ* obj);
114  RXPTR putAt(WSTRREF name, RXOBJ* obj, UI32& indx);
115  RXPTR remove(WSTRREF alias);
116  };
117 
118 
119  enum {
120  kCmdGlobal = OdEdCommandStack::kGlobal, // Search global (untranslated) names.
121  kCmdLocal = OdEdCommandStack::kLocal, // Search local (translated) names.
122  kCmdSpecGroup = OdEdCommandStack::kSpecifedGroup, // Search in specified group only.
123  kCmdThrowUnknown = OdEdCommandStack::kThrowUnknown // Do not fire unknownCommand() event.
124  };
125 
126  class HRXCMD {
127  OdEdCommandPtr fn;
128  public:
130  void execute(CMDCTX* ctx);
131  RXPTR callFn(CMDCTX* ctx);
132  RXPTR callFn(CMDCTX* ctx, RXOBJ* param);
133  bool isNull() const { return fn.isNull(); }
134  };
135 
136 
137  inline HRXCMD::HRXCMD(WSTRREF func, int lookup, WSTRREF group) {
138  fn = odedRegCmds()->lookupCmd(func, lookup, group);
139  if(fn.isNull() && GETBIT(lookup, kCmdThrowUnknown))
140  throw OdError("unknown function " + group + "." + func);
141  }
142 
143  inline void HRXCMD::execute(CMDCTX* ctx) { odedRegCmds()->executeCommand(fn, ctx); }
144 
145  inline RXPTR HRXCMD::callFn(CMDCTX* ctx) {
146  fn->execute(ctx);
147  OdEdFunctionIO* fnio = ctx->funcIO();
148  RXPTR res = fnio->result();
149  fnio->setResult(0);
150  return res;
151  }
152 
153  inline RXPTR HRXCMD::callFn(CMDCTX* ctx, RXOBJ* param) {
154  OdEdFunctionIO* fnio = ctx->funcIO();
155  fnio->setParam(param);
156  fn->execute(ctx);
157  RXPTR res = fnio->result();
158  fnio->setParam(0);
159  fnio->setResult(0);
160  return res;
161  }
162 
163 
164 
165  inline RXPTR arbVarSafe(OdEdCommandContext* ctx, const WSTR& varName) {
166  OdRxObjectPtr res = ctx->arbitraryData( varName );
167  if(res.isNull())
168  throw OdError(OdString().format(L"Context variable \"%ls\" was not found", varName.c_str()));
169  return res;
170  }
171 
172 
173 
174 
175  inline void HRXDIC::validate() { if(isNull()) throw EXCEP(eNullObjectPointer); }
176 
177  inline HRXDIC::HRXDIC() { }
178  inline HRXDIC::HRXDIC(const RXOBJ* dictionary) : RXDICPTR(dictionary) { }
179  inline HRXDIC& HRXDIC::operator=(const RXOBJ* dictionary) {
180  assign(dictionary); return *this;
181  }
182 
184  return (RXDIC*)RXDIC::createObject().get();
185  }
186 
187  inline HRXDIC HRXDIC::arbDataOpen(CMDCTX* cmdctx, WSTRREF name, bool bCreateIfNotFound) { // open or create if not found
188  RXDICPTR dic = cmdctx->arbitraryData(name);
189  if(dic.isNull()) {
190  dic = RXDIC::createObject();
191  cmdctx->setArbitraryData(name, dic);
192  }
193  return HRXDIC(dic);
194  }
195  inline HRXDIC HRXDIC::step(WSTRREF name, bool bCreateIfNotFound) {
196  validate();
197  HRXDIC nextdic = getAt(name).get();
198  if(nextdic.isNull() && bCreateIfNotFound) {
199  nextdic = RXDIC::createObject();
200  putAt(name, nextdic);
201  }
202  return nextdic;
203  }
204  inline HRXDIC HRXDIC::walk(const PATH& path, bool bCreateIfNotFound) {
205  validate();
206  HRXDIC nextdic = get();
207  for(OdUInt32 i=0; nextdic.get() && i<path.size(); ++i)
208  nextdic = nextdic.step(WSTR(path[i]), bCreateIfNotFound);
209  return nextdic;
210  }
211  inline HRXDIC HRXDIC::stepCr(WSTRREF name) { return step(name, true); }
212 
213  inline HRXDIC HRXDIC::walkCr(const PATH& path) { return walk(path, true); }
214 
215  inline RXPTR HRXDIC::getAt(WSTRREF name) { validate(); return get()->getAt(name); }
216 
217  inline RXPTR HRXDIC::putAt(WSTRREF name, RXOBJ* obj) { validate(); return get()->putAt(name, obj); }
218 
219  inline RXPTR HRXDIC::remove(WSTRREF name) { validate(); return get()->remove(name); }
220 
221  inline RXPTR HRXDIC::getAt(UI32 indx) { validate(); return get()->getAt(indx); }
222 
223  inline RXPTR HRXDIC::putAt(UI32 indx, RXOBJ* obj) { validate(); return get()->putAt(indx, obj); }
224 
225  inline UI32 HRXDIC::index(WSTRREF name) { validate(); return get()->idAt(name); }
226 
227  inline RXPTR HRXDIC::putAt(WSTRREF name, RXOBJ* obj, UI32& indx) { validate(); return get()->putAt(name, obj, &indx); }
228 
229 
231  OdRxObjectPtr db = ctx->baseDatabase();
232  if (db.isNull())
233  throw OdError(eNoDatabase);
234 
235  OdString dbName = db->isA()->name();
236  if (dbName == "OdDbDatabase") {
237  return "DwgCtx";
238  }
239  else if (dbName == "OdDgDatabase") {
240  return "DgnCtx";
241  }
242  //else if (dbName == "OdDwfDatabase"){
243  // return "OdDwfDatabase";
244  //}
245  //else if (dbName == "OdPrcFile") { // *AutoUpdateReactor commands not implemented
246  // return "PrcCtx";
247  //}
248  //else if (dbName == "OdBmDatabase") // DNA: AutoUpdateReactor will not work with BIM because OdBmDatabaseReactor has no goodby() callback method
249  // return "BimCtx";
250  return OdString();
251  }
252 
253 
254  inline OdString ctxByFileExtension(const OdString& sExt) {
255  if (sExt.iCompare(L"dwg") == 0 ||
256  sExt.iCompare(L"dxf") == 0 ||
257  sExt.iCompare(L"dxb") == 0 ||
258  sExt.iCompare(L"dws") == 0 ||
259  sExt.iCompare(L"tvc") == 0 ||
260  sExt.iCompare(L"tig") == 0 ||
261  sExt.iCompare(L"dwt") == 0) {
262  return OdString("DwgCtx");
263  }
264  HRXDIC txVars = HRXDIC(::odrxSysRegistry()).walkCr("FileFormats");
265  OdRxObjectPtr var = txVars.getAt(sExt);
266  if (var.isNull())
267  throw OdError(eUnknownFileType);
268 
269  OdString sFmtBrdgAppName = HRXVAR(var)->getString();
270  ::odrxDynamicLinker()->loadApp(sFmtBrdgAppName, false);
271  return sFmtBrdgAppName;
272  }
273 
274 
275  inline OdString toUtf16(const char* pAnsi) {
276  OdAnsiString asCmd(pAnsi);
277  OdCharArray buf;
278  OdCharMapper::utf8ToUnicode(asCmd.c_str(), asCmd.getLength(), buf);
279  OdString sRes = OdString(buf.getPtr(), buf.size() - 1);
280  // possible TODO substitutions for & ...
281  return sRes;
282  }
283 
284  inline OdAnsiString toUtf8(const OdString& sUnicode) {
285  OdAnsiCharArray dstBuf;
286  int lenStr = sUnicode.getLength();
287  dstBuf.reserve(lenStr * 4 + 1);
288  OdCharMapper::unicodeToUtf8(sUnicode.c_str(), lenStr, dstBuf);
289  OdAnsiString asRes = (const char*) dstBuf.asArrayPtr();
290  // possible TODO substitutions for & ...
291  return asRes;
292  }
293 
294 } //namespace Oda
295 
296 
297 
298 #endif //#ifndef _TXDEFS_H_
GETBIT
#define GETBIT(flags, bit)
Definition: OdaDefs.h:498
OdSmartPtr< OdRxDictionary >::assign
void assign(const OdRxDictionary *pObject)
Definition: SmartPtr.h:80
Oda::HRXDIC::walk
HRXDIC walk(const PATH &path, bool bCreateIfNotFound=false)
Definition: TxDefs.h:204
OdEdCommandStack::kGlobal
@ kGlobal
Definition: EdCommandStack.h:395
Oda::I32
OdInt32 I32
Definition: TxDefs.h:53
Oda::HRXDIC::walkCr
HRXDIC walkCr(const PATH &path)
Definition: TxDefs.h:213
Oda::I64
OdInt64 I64
Definition: TxDefs.h:55
OdString
Definition: OdString.h:95
Oda::HRXCMD::HRXCMD
HRXCMD(WSTRREF func, int lookup=kCmdGlobal|kCmdLocal|kCmdThrowUnknown, WSTRREF group=WSTR::kEmpty)
Definition: TxDefs.h:137
OdRxVariant
Definition: RxVariantValue.h:44
Oda::toUtf16
OdString toUtf16(const char *pAnsi)
Definition: TxDefs.h:275
OdRxObjectPtr
Definition: RxObject.h:345
OdCharMapper::unicodeToUtf8
static void unicodeToUtf8(const OdChar *srcBuf, int srcSize, OdAnsiCharArray &dstBuf)
Oda::WCSZ
const OdChar * WCSZ
Definition: TxDefs.h:65
EdCommandStack.h
OdUInt8
unsigned char OdUInt8
Definition: OdPlatformSettings.h:759
Oda::HRXDIC::HRXDIC
HRXDIC()
Definition: TxDefs.h:177
odrxDynamicLinker
FIRSTDLL_EXPORT OdRxDynamicLinker * odrxDynamicLinker()
Oda::HRXDIC::stepCr
HRXDIC stepCr(WSTRREF name)
Definition: TxDefs.h:211
Oda::HRXDIC::create
static HRXDIC create()
Definition: TxDefs.h:183
name
GLuint const GLchar * name
Definition: gles2_ext.h:265
OdEdCommandStack::kSpecifedGroup
@ kSpecifedGroup
Definition: EdCommandStack.h:397
OdEdCommandContext::baseDatabase
virtual OdRxObject * baseDatabase()=0
OdInt64
Definition: Int64.h:43
Oda::HRXCMD::execute
void execute(CMDCTX *ctx)
Definition: TxDefs.h:143
Oda::STRMBF
OdStreamBuf STRMBF
Definition: TxDefs.h:69
Oda::CMDCTXPTR
OdEdCommandContextPtr CMDCTXPTR
Definition: TxDefs.h:89
OdEdUserIO
Definition: EdUserIO.h:346
StringArray.h
OdCharMapper.h
Path.h
OdRxObject
Definition: RxObject.h:564
Oda::ASTRREF
const ASTR & ASTRREF
Definition: TxDefs.h:61
Oda
Definition: TxDefs.h:48
Oda::CMD
OdEdCommand CMD
Definition: TxDefs.h:90
Oda::RXOBJ
OdRxObject RXOBJ
Definition: TxDefs.h:67
Oda::HRXCMD
Definition: TxDefs.h:126
Oda::arbVarSafe
RXPTR arbVarSafe(OdEdCommandContext *ctx, const WSTR &varName)
Definition: TxDefs.h:165
OdRxDictionary::putAt
virtual OdRxObjectPtr putAt(const OdString &key, OdRxObject *pObject, OdUInt32 *pRetId=0)=0
OdArray< OdRxObjectPtr >
OdEdFunctionIO
Definition: EdFunctionIO.h:37
OdRxObjectPtr::get
OdRxObject * get()
Definition: RxObject.h:503
Oda::RXPTRARR
OdRxObjectPtrArray RXPTRARR
Definition: TxDefs.h:85
Oda::HRXDIC::operator=
HRXDIC & operator=(const RXOBJ *dictionary)
Definition: TxDefs.h:179
OdUInt16
unsigned short OdUInt16
Definition: OdPlatformSettings.h:760
Oda::kCmdGlobal
@ kCmdGlobal
Definition: TxDefs.h:120
OdUInt32
unsigned int OdUInt32
Definition: OdPlatformSettings.h:783
OdEdCommand
Definition: EdCommandStack.h:75
Oda::getDbCtxName
OdString getDbCtxName(OdEdCommandContext *ctx)
Definition: TxDefs.h:230
odrxSysRegistry
FIRSTDLL_EXPORT OdRxDictionary * odrxSysRegistry()
OdRxDictionary::idAt
virtual OdUInt32 idAt(const OdString &key) const =0
OdArray::getPtr
const T * getPtr() const
Definition: OdArray.h:1102
OdEdCommand::execute
virtual void execute(OdEdCommandContext *pCommandContext)=0
OdRxObject::isA
virtual OdRxClass * isA() const
OdStreamBuf.h
OdEdFunctionIO::setParam
virtual void setParam(OdRxObject *pParamObj)=0
OdArray::asArrayPtr
const T * asArrayPtr() const
Definition: OdArray.h:1094
OdRxDictionary::getAt
virtual OdRxObjectPtr getAt(const OdString &key) const =0
Oda::RXPTR
OdRxObjectPtr RXPTR
Definition: TxDefs.h:68
Oda::ASTR
OdAnsiString ASTR
Definition: TxDefs.h:60
OdBaseObjectPtr::isNull
bool isNull() const
Definition: BaseObjectPtr.h:70
OdString
OdString OdString
Definition: OdString.h:1224
Oda::PATHREF
const PATH & PATHREF
Definition: TxDefs.h:74
OdSmartPtr< OdStreamBuf >
Oda::STRMBFPTR
OdStreamBufPtr STRMBFPTR
Definition: TxDefs.h:70
OdInt32
int OdInt32
Definition: OdPlatformSettings.h:782
Oda::WSTRREF
const WSTR & WSTRREF
Definition: TxDefs.h:63
OdEdCommandContext
Definition: EdCommandContext.h:42
Oda::kCmdLocal
@ kCmdLocal
Definition: TxDefs.h:121
Oda::kCmdThrowUnknown
@ kCmdThrowUnknown
Definition: TxDefs.h:123
Oda::HRXDIC::arbDataOpen
static HRXDIC arbDataOpen(CMDCTX *cmdctx, WSTRREF name, bool bCreateIfNotFound=false)
Definition: TxDefs.h:187
func
GLenum func
Definition: gles2_ext.h:262
Oda::RXDICITER
OdRxDictionaryIterator RXDICITER
Definition: TxDefs.h:79
Oda::HRXDIC::remove
RXPTR remove(WSTRREF alias)
Definition: TxDefs.h:219
OdArray::size
size_type size() const
Definition: OdArray.h:893
Oda::ACSZ
const char * ACSZ
Definition: TxDefs.h:64
OdEdFunctionIO::result
virtual OdRxObjectPtr result()=0
OdSmartPtr::get
const T * get() const
Definition: SmartPtr.h:326
OD::Path
Definition: OdPathUtil.h:36
OdChar
wchar_t OdChar
Definition: OdPlatformSettings.h:745
Oda::EXCEP
OdError EXCEP
Definition: TxDefs.h:57
OdRxClass::name
virtual const OdString name() const =0
DynamicLinker.h
OdPlatformSettings.h
OdEdCommandStack::kLocal
@ kLocal
Definition: EdCommandStack.h:396
OdEdCommandContext::arbitraryData
virtual OdRxObjectPtr arbitraryData(const OdString &szPathName) const =0
Oda::EXCEPREF
const EXCEP & EXCEPREF
Definition: TxDefs.h:58
OdCharMapper::utf8ToUnicode
static void utf8ToUnicode(const char *srcBuf, int srcSize, OdCharArray &dstBuf)
OdRxDictionary
Definition: RxDictionary.h:114
Oda::UI16
OdUInt16 UI16
Definition: TxDefs.h:51
Oda::toUtf8
OdAnsiString toUtf8(const OdString &sUnicode)
Definition: TxDefs.h:284
OdRxDynamicLinker::loadApp
virtual OdRxModulePtr loadApp(const OdString &applicationName, bool silent=true)=0
Oda::PATH
OD::Path PATH
Definition: TxDefs.h:73
OdEdCommandContext::setArbitraryData
virtual void setArbitraryData(const OdString &szPathName, OdRxObject *pDataObj)=0
Oda::HRXVAR
OdRxVariantValue HRXVAR
Definition: TxDefs.h:84
OdRxVariantValue
Definition: RxVariantValue.h:53
Oda::HRXDIC
Definition: TxDefs.h:95
Oda::HRXDIC::validate
void validate()
Definition: TxDefs.h:175
Oda::CMDPTR
OdEdCommandPtr CMDPTR
Definition: TxDefs.h:91
OdEdCommandStack::kThrowUnknown
@ kThrowUnknown
Definition: EdCommandStack.h:399
OdEdCommandContext::funcIO
virtual OdEdFunctionIO * funcIO()=0
OdArray::reserve
void reserve(size_type reserveLength)
Definition: OdArray.h:920
Oda::CMDCTX
OdEdCommandContext CMDCTX
Definition: TxDefs.h:88
Oda::kCmdSpecGroup
@ kCmdSpecGroup
Definition: TxDefs.h:122
OdStreamBuf
Definition: OdStreamBuf.h:67
RxVariantValue.h
OdRxDictionaryIterator
Definition: RxDictionary.h:61
OdError
Definition: OdError.h:43
Oda::HRXDIC::index
UI32 index(WSTRREF name)
Definition: TxDefs.h:225
Oda::RXDICPTR
OdRxDictionaryPtr RXDICPTR
Definition: TxDefs.h:78
Oda::HRXDIC::putAt
RXPTR putAt(WSTRREF name, RXOBJ *obj)
Definition: TxDefs.h:217
OdString::iCompare
int iCompare(const OdChar *otherString) const
Definition: OdString.h:394
Oda::WSTR
OdString WSTR
Definition: TxDefs.h:62
format
GLint GLint GLint GLsizei GLsizei GLenum format
Definition: gles2_ext.h:111
Oda::RXDIC
OdRxDictionary RXDIC
Definition: TxDefs.h:77
Oda::RXVAR
OdRxVariant RXVAR
Definition: TxDefs.h:82
Oda::USERIO
OdEdUserIO USERIO
Definition: TxDefs.h:92
OdString::kEmpty
FIRSTDLL_EXPORT_STATIC static const OdString kEmpty
Definition: OdString.h:98
Oda::UI32
OdUInt32 UI32
Definition: TxDefs.h:52
OdEdFunctionIO::setResult
virtual void setResult(OdRxObject *pResultObj)=0
Oda::ctxByFileExtension
OdString ctxByFileExtension(const OdString &sExt)
Definition: TxDefs.h:254
odedRegCmds
FIRSTDLL_EXPORT OdEdCommandStackPtr odedRegCmds()
Oda::RXVARPTR
OdRxVariantPtr RXVARPTR
Definition: TxDefs.h:83
OdString::c_str
const OdChar * c_str() const
Definition: OdString.h:200
Oda::RXDICITERPTR
OdRxDictionaryIteratorPtr RXDICITERPTR
Definition: TxDefs.h:80
RxDictionary.h
Oda::HRXDIC::getAt
RXPTR getAt(WSTRREF name)
Definition: TxDefs.h:215
Oda::UI64
OdUInt64 UI64
Definition: TxDefs.h:54
Oda::HRXCMD::callFn
RXPTR callFn(CMDCTX *ctx)
Definition: TxDefs.h:145
EdFunctionIO.h
EdCommandContext.h
OdRxDictionary::remove
virtual OdRxObjectPtr remove(const OdString &key)=0
Oda::HRXDIC::step
HRXDIC step(WSTRREF name, bool bCreateIfNotFound=false)
Definition: TxDefs.h:195
OdString::getLength
int getLength() const
Definition: OdString.h:130
Oda::HRXCMD::isNull
bool isNull() const
Definition: TxDefs.h:133
OdUInt64
Definition: Int64.h:137
Oda::UI8
OdUInt8 UI8
Definition: TxDefs.h:50