CFx SDK Documentation  2022 SP0
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_
FIRSTDLL_EXPORT OdRxDynamicLinker * odrxDynamicLinker()
FIRSTDLL_EXPORT OdEdCommandStackPtr odedRegCmds()
unsigned int OdUInt32
unsigned short OdUInt16
int OdInt32
unsigned char OdUInt8
wchar_t OdChar
OdString OdString
Definition: OdString.h:1224
#define GETBIT(flags, bit)
Definition: OdaDefs.h:498
FIRSTDLL_EXPORT OdRxDictionary * odrxSysRegistry()
size_type size() const
Definition: OdArray.h:893
const T * getPtr() const
Definition: OdArray.h:1102
void reserve(size_type reserveLength)
Definition: OdArray.h:920
const T * asArrayPtr() const
Definition: OdArray.h:1094
bool isNull() const
Definition: BaseObjectPtr.h:70
static void unicodeToUtf8(const OdChar *srcBuf, int srcSize, OdAnsiCharArray &dstBuf)
static void utf8ToUnicode(const char *srcBuf, int srcSize, OdCharArray &dstBuf)
virtual OdRxObject * baseDatabase()=0
virtual OdRxObjectPtr arbitraryData(const OdString &szPathName) const =0
virtual void setArbitraryData(const OdString &szPathName, OdRxObject *pDataObj)=0
virtual OdEdFunctionIO * funcIO()=0
virtual void execute(OdEdCommandContext *pCommandContext)=0
virtual OdRxObjectPtr result()=0
virtual void setParam(OdRxObject *pParamObj)=0
virtual void setResult(OdRxObject *pResultObj)=0
Definition: Int64.h:43
virtual const OdString name() const =0
virtual OdUInt32 idAt(const OdString &key) const =0
virtual OdRxObjectPtr getAt(const OdString &key) const =0
virtual OdRxObjectPtr remove(const OdString &key)=0
virtual OdRxObjectPtr putAt(const OdString &key, OdRxObject *pObject, OdUInt32 *pRetId=0)=0
virtual OdRxModulePtr loadApp(const OdString &applicationName, bool silent=true)=0
virtual OdRxClass * isA() const
OdRxObject * get()
Definition: RxObject.h:503
void assign(const OdRxDictionary *pObject)
Definition: SmartPtr.h:80
const T * get() const
Definition: SmartPtr.h:326
const OdChar * c_str() const
Definition: OdString.h:200
int iCompare(const OdChar *otherString) const
Definition: OdString.h:394
FIRSTDLL_EXPORT_STATIC static const OdString kEmpty
Definition: OdString.h:98
int getLength() const
Definition: OdString.h:130
RXPTR callFn(CMDCTX *ctx)
Definition: TxDefs.h:145
HRXCMD(WSTRREF func, int lookup=kCmdGlobal|kCmdLocal|kCmdThrowUnknown, WSTRREF group=WSTR::kEmpty)
Definition: TxDefs.h:137
bool isNull() const
Definition: TxDefs.h:133
void execute(CMDCTX *ctx)
Definition: TxDefs.h:143
void validate()
Definition: TxDefs.h:175
RXPTR getAt(WSTRREF name)
Definition: TxDefs.h:215
UI32 index(WSTRREF name)
Definition: TxDefs.h:225
HRXDIC stepCr(WSTRREF name)
Definition: TxDefs.h:211
HRXDIC walk(const PATH &path, bool bCreateIfNotFound=false)
Definition: TxDefs.h:204
RXPTR putAt(WSTRREF name, RXOBJ *obj)
Definition: TxDefs.h:217
HRXDIC step(WSTRREF name, bool bCreateIfNotFound=false)
Definition: TxDefs.h:195
static HRXDIC create()
Definition: TxDefs.h:183
HRXDIC & operator=(const RXOBJ *dictionary)
Definition: TxDefs.h:179
RXPTR remove(WSTRREF alias)
Definition: TxDefs.h:219
HRXDIC walkCr(const PATH &path)
Definition: TxDefs.h:213
static HRXDIC arbDataOpen(CMDCTX *cmdctx, WSTRREF name, bool bCreateIfNotFound=false)
Definition: TxDefs.h:187
GLenum func
Definition: gles2_ext.h:262
GLuint const GLchar * name
Definition: gles2_ext.h:265
GLint GLint GLint GLsizei GLsizei GLenum format
Definition: gles2_ext.h:111
Definition: TxDefs.h:48
OdUInt8 UI8
Definition: TxDefs.h:50
OdEdCommand CMD
Definition: TxDefs.h:90
OdString ctxByFileExtension(const OdString &sExt)
Definition: TxDefs.h:254
OdUInt64 UI64
Definition: TxDefs.h:54
OdInt32 I32
Definition: TxDefs.h:53
OdRxDictionaryIteratorPtr RXDICITERPTR
Definition: TxDefs.h:80
OdRxVariantPtr RXVARPTR
Definition: TxDefs.h:83
@ kCmdGlobal
Definition: TxDefs.h:120
@ kCmdSpecGroup
Definition: TxDefs.h:122
@ kCmdThrowUnknown
Definition: TxDefs.h:123
@ kCmdLocal
Definition: TxDefs.h:121
OdError EXCEP
Definition: TxDefs.h:57
OdEdCommandPtr CMDPTR
Definition: TxDefs.h:91
const WSTR & WSTRREF
Definition: TxDefs.h:63
OdRxVariantValue HRXVAR
Definition: TxDefs.h:84
const ASTR & ASTRREF
Definition: TxDefs.h:61
const char * ACSZ
Definition: TxDefs.h:64
RXPTR arbVarSafe(OdEdCommandContext *ctx, const WSTR &varName)
Definition: TxDefs.h:165
OdString getDbCtxName(OdEdCommandContext *ctx)
Definition: TxDefs.h:230
OdAnsiString ASTR
Definition: TxDefs.h:60
OdRxDictionaryPtr RXDICPTR
Definition: TxDefs.h:78
const PATH & PATHREF
Definition: TxDefs.h:74
OdRxDictionaryIterator RXDICITER
Definition: TxDefs.h:79
OD::Path PATH
Definition: TxDefs.h:73
OdAnsiString toUtf8(const OdString &sUnicode)
Definition: TxDefs.h:284
OdEdUserIO USERIO
Definition: TxDefs.h:92
OdUInt16 UI16
Definition: TxDefs.h:51
OdEdCommandContext CMDCTX
Definition: TxDefs.h:88
OdRxVariant RXVAR
Definition: TxDefs.h:82
OdRxDictionary RXDIC
Definition: TxDefs.h:77
OdEdCommandContextPtr CMDCTXPTR
Definition: TxDefs.h:89
const OdChar * WCSZ
Definition: TxDefs.h:65
const EXCEP & EXCEPREF
Definition: TxDefs.h:58
OdRxObjectPtrArray RXPTRARR
Definition: TxDefs.h:85
OdRxObjectPtr RXPTR
Definition: TxDefs.h:68
OdRxObject RXOBJ
Definition: TxDefs.h:67
OdString WSTR
Definition: TxDefs.h:62
OdStreamBuf STRMBF
Definition: TxDefs.h:69
OdString toUtf16(const char *pAnsi)
Definition: TxDefs.h:275
OdUInt32 UI32
Definition: TxDefs.h:52
OdInt64 I64
Definition: TxDefs.h:55
OdStreamBufPtr STRMBFPTR
Definition: TxDefs.h:70