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