CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
EditorImpl.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
25
26
27#ifndef _ODEDITORIMPL_H_INCLUDED_
28#define _ODEDITORIMPL_H_INCLUDED_
29
30#include "TD_PackPush.h"
31
32#include "Editor.h"
33#include "DbIdMapping.h"
34
40//FELIX_CHANGE_BEGIN
41
42#ifdef XENON
43TOOLKIT_EXPORT void fxReportReactorExceptionImpl( unsigned iReactorIdx, OdRxObject* pReactor, const char * szMethod, const OdError& err);
44#define FX_SAFE_CALL_REACTOR_EVENT_IMPL(reactor, method, params, index) \
45try { \
46 reactor->method params; \
47} catch (const OdError& err ) { \
48 fxReportReactorExceptionImpl( index, reactor, #method, err ); \
49}
50#else
51#define FX_SAFE_CALL_REACTOR_EVENT_IMPL(reactor, method, params, index) { reactor->method params; }
52#endif
53
54#include"FxDbCoreExtension.h" //FELIX_CHANGE
55
56#ifdef XENON
57#define FX_BEGIN_MAIN_THREAD()
58#define FX_END_MAIN_THREAD()
59#else
60#define FX_BEGIN_MAIN_THREAD() \
61 CFxDbCoreExtension::StaticExecuteInMainThread( [&]() {
62#define FX_END_MAIN_THREAD() \
63 } );
64#endif
65
67{
68 OdArray< OdRxEventReactor* > apRawReactors;
69 apRawReactors.reserve( apReactors.size() );
70 for ( auto& pReactor : apReactors )
71 apRawReactors.append( pReactor.get() );
72 return apRawReactors;
73}
74
75inline bool fxIsValidReactor( OdRxEventReactor* pRawReactor, const OdArray< OdRxEventReactorPtr >& apReactors, unsigned iHeuristicIndex )
76{
77 if ( !pRawReactor )
78 return false;
79
80 if ( iHeuristicIndex < apReactors.length() && apReactors[ iHeuristicIndex ].get() == pRawReactor )
81 return true;
82
83 return apReactors.end() != std::find_if( apReactors.begin(),
84 apReactors.end(),
85 [ pRawReactor ]( const OdRxEventReactorPtr& pReactor )
86 {
87 return pReactor.get() == pRawReactor;
88 } );
89}
90
91#define RXEVENT_FIRE(method, inparams, params) \
92inline void fire_##method inparams \
93{ \
94 FX_BEGIN_MAIN_THREAD(); \
95 TD_AUTOLOCK( m_mutex ); \
96 ++m_EventCounter; \
97 try \
98 { \
99 const auto reactors = fxCopyRawReactorPointers( m_reactors ); \
100 for (unsigned i = 0; i < reactors.size(); ++i) \
101 { \
102 if ( fxIsValidReactor( reactors[i], m_reactors, i ) )\
103 FX_SAFE_CALL_REACTOR_EVENT_IMPL( reactors[i], method, params, i ) \
104 } \
105 } \
106 catch( ... ) \
107 { \
108 --m_EventCounter; \
109 throw; \
110 } \
111 if (!(--m_EventCounter))\
112 while( m_reactors.remove(OdRxEventReactorPtr()) );\
113 FX_END_MAIN_THREAD(); \
114}
115
116#define EDEVENT_FIRE(method, inparams, params) \
117inline void fire_##method inparams \
118{ \
119 FX_BEGIN_MAIN_THREAD(); \
120 TD_AUTOLOCK( m_mutex ); \
121 ++m_EventCounter; \
122 try \
123 { \
124 const auto reactors = fxCopyRawReactorPointers( m_reactors ); \
125 for (unsigned i = 0; i < reactors.size(); ++i) \
126 { \
127 if ( fxIsValidReactor( reactors[i], m_reactors, i ) )\
128 {\
129 OdEditorReactorPtr edReactor = OdEditorReactor::cast(reactors[i]); \
130 if (edReactor.get()) edReactor->method params; \
131 }\
132 } \
133 } \
134 catch( ... ) \
135 { \
136 --m_EventCounter; \
137 throw; \
138 } \
139 if (!(--m_EventCounter))\
140 while( m_reactors.remove(OdRxEventReactorPtr()) );\
141 FX_END_MAIN_THREAD(); \
142}
143
144#define DCEVENT_FIRE(method, inparams, params, IdMappingToDatabase) \
145inline void fire_##method inparams \
146{ \
147 FX_BEGIN_MAIN_THREAD(); \
148 TD_AUTOLOCK( m_mutex ); \
149 try \
150 { \
151 const auto reactors = fxCopyRawReactorPointers( m_reactors ); \
152 for (unsigned i = 0; i < reactors.size(); ++i) \
153 { \
154 if ( fxIsValidReactor( reactors[i], m_reactors, i ) )\
155 reactors[i]->method params; \
156 } \
157 } \
158 catch( ... ) \
159 { \
160 --m_EventCounter; \
161 throw; \
162 } \
163 if (!(--m_EventCounter))\
164 while( m_reactors.remove(OdRxEventReactorPtr()) );\
165 FX_END_MAIN_THREAD(); \
166}
167
168#define RXEVENT_FIRE_ABORT(method, inparams, params, abortmethod, abortparams) \
169inline void fire_##method inparams \
170{ \
171 FX_BEGIN_MAIN_THREAD(); \
172 TD_AUTOLOCK( m_mutex ); \
173 const auto reactors = fxCopyRawReactorPointers( m_reactors ); \
174 OdArray<OdRxEventReactorPtr> firedReactors(reactors.length()); \
175 for (unsigned i = 0; i < reactors.size(); ++i) \
176 { \
177 if ( fxIsValidReactor( reactors[i], m_reactors, i ) ) \
178 { \
179 try \
180 { \
181 firedReactors.append(reactors[i]); \
182 reactors[i]->method params; \
183 } \
184 catch(...) \
185 { \
186 for (unsigned j = 0; j < firedReactors.size(); ++j) \
187 { \
188 if (m_reactors.contains(firedReactors[j])) \
189 firedReactors[j]->abortmethod abortparams; \
190 } \
191 throw; \
192 } \
193 } \
194 } \
195 FX_END_MAIN_THREAD(); \
196}
197
198#define EDEVENT_FIRE_ABORT(method, inparams, params, abortmethod, abortparams) \
199inline void fire_##method inparams \
200{ \
201 FX_BEGIN_MAIN_THREAD(); \
202 TD_AUTOLOCK( m_mutex ); \
203 const auto reactors = fxCopyRawReactorPointers( m_reactors ); \
204 OdArray<OdEditorReactorPtr> firedReactors(reactors.length()); \
205 for (unsigned i = 0; i < reactors.size(); ++i) \
206 { \
207 if ( fxIsValidReactor( reactors[i], m_reactors, i ) ) \
208 { \
209 try \
210 { \
211 OdEditorReactorPtr pReactor = OdEditorReactor::cast(reactors[i]); \
212 if (pReactor.get()) \
213 { \
214 firedReactors.append(pReactor); \
215 pReactor->method params; \
216 } \
217 } \
218 catch(...) \
219 { \
220 for (unsigned j = 0; j < firedReactors.size(); ++j) \
221 { \
222 if (m_reactors.contains(firedReactors[j])) \
223 firedReactors[j]->abortmethod abortparams; \
224 } \
225 throw; \
226 } \
227 } \
228 } \
229 FX_END_MAIN_THREAD(); \
230}
231
232//FELIX_CHANGE_END
233
240{
241//FELIX_CHANGE_BEGIN
242protected:
244public:
247public:
248 OdRxEventImpl() : m_EventCounter(0) {}
249//FELIX_CHANGE_END
251
254
255 // notifiers
256 RXEVENT_FIRE(dwgFileOpened, (OdDbDatabase* db, const OdString& filename),(db, filename))
257 RXEVENT_FIRE(initialDwgFileOpenComplete, (OdDbDatabase* db), (db))
258 RXEVENT_FIRE(databaseConstructed, (OdDbDatabase* db), (db))
259 RXEVENT_FIRE(databaseToBeDestroyed, (OdDbDatabase* db), (db))
260 RXEVENT_FIRE_ABORT(beginSave, (OdDbDatabase* db, const OdString& pIntendedName), (db, pIntendedName), abortSave, (db))
261 RXEVENT_FIRE(saveComplete, (OdDbDatabase* db, const OdString& pActualName), (db, pActualName))
262 RXEVENT_FIRE(abortSave, (OdDbDatabase* db), (db))
263 // DXF In/Out Events.
264 RXEVENT_FIRE_ABORT(beginDxfIn, (OdDbDatabase* db), (db), abortDxfIn, (db))
265 RXEVENT_FIRE(abortDxfIn, (OdDbDatabase* db), (db))
266 RXEVENT_FIRE(dxfInComplete, (OdDbDatabase* db), (db))
267 //
268 RXEVENT_FIRE_ABORT(beginDxfOut, (OdDbDatabase* db), (db), abortDxfOut, (db))
269 RXEVENT_FIRE(abortDxfOut, (OdDbDatabase* db), (db))
270 RXEVENT_FIRE(dxfOutComplete, (OdDbDatabase* db), (db))
271 // Insert Events.
272 RXEVENT_FIRE_ABORT(beginInsert, (OdDbDatabase* pTo, const OdString& pBlockName, OdDbDatabase* pFrom), (pTo, pBlockName, pFrom), abortInsert, (pTo))
273 RXEVENT_FIRE_ABORT(beginInsert, (OdDbDatabase* pTo, const OdGeMatrix3d& xform, OdDbDatabase* pFrom), (pTo, xform, pFrom), abortInsert, (pTo))
274 RXEVENT_FIRE_ABORT(otherInsert, (OdDbDatabase* pTo, OdDbIdMapping& idMap, OdDbDatabase* pFrom), (pTo, idMap, pFrom), abortInsert, (pTo))
275 RXEVENT_FIRE(abortInsert, (OdDbDatabase* pTo), (pTo))
276 RXEVENT_FIRE(endInsert, (OdDbDatabase* pTo), (pTo))
277
278 // Wblock Events.
279 RXEVENT_FIRE(wblockNotice, (OdDbDatabase* pDb), (pDb))
280 RXEVENT_FIRE_ABORT(beginWblock, (OdDbDatabase* pTo, OdDbDatabase* pFrom, const OdGePoint3d& insertionPoint), (pTo, pFrom, insertionPoint), abortWblock, (pTo))
281 RXEVENT_FIRE_ABORT(beginWblock, (OdDbDatabase* pTo, OdDbDatabase* pFrom, OdDbObjectId blockId), (pTo, pFrom, blockId), abortWblock, (pTo))
282 RXEVENT_FIRE_ABORT(beginWblock, (OdDbDatabase* pTo, OdDbDatabase* pFrom), (pTo, pFrom), abortWblock, (pTo))
283 RXEVENT_FIRE_ABORT(otherWblock, (OdDbDatabase* pTo, OdDbIdMapping& m, OdDbDatabase* pFrom), (pTo, m, pFrom), abortWblock, (pTo))
284 RXEVENT_FIRE(abortWblock, (OdDbDatabase* pTo), (pTo))
285 RXEVENT_FIRE(endWblock, (OdDbDatabase* pTo), (pTo))
286 RXEVENT_FIRE(beginWblockObjects, (OdDbDatabase* pDb, OdDbIdMapping& m), (pDb, m))
287
288 // Deep Clone Events.
289 DCEVENT_FIRE(beginDeepClone, (OdDbDatabase* pTo, OdDbIdMapping& m), (pTo, m), &m)
290 RXEVENT_FIRE_ABORT(beginDeepCloneXlation, (OdDbIdMapping& m), (m), abortDeepClone, (m))
291 DCEVENT_FIRE(abortDeepClone, (OdDbIdMapping& m), (m), 0)
292 DCEVENT_FIRE(endDeepClone, (OdDbIdMapping& m), (m), 0)
293
294 // Partial Open Events.
295 RXEVENT_FIRE(partialOpenNotice, (OdDbDatabase* pDb), (pDb))
296
297 RXEVENT_FIRE_ABORT(xrefSubCommandStart, (OdDbDatabase* pHostDb, OdXrefSubCommand subCmd, const OdDbObjectIdArray& btrIds, const OdStringArray& btrNames, const OdStringArray& paths, bool& vetoOp),
298 (pHostDb, subCmd, btrIds, btrNames, paths, vetoOp), xrefSubCommandAborted, (pHostDb, subCmd, btrIds, btrNames, paths))
299
300 RXEVENT_FIRE_ABORT(xrefSubCommandEnd, (OdDbDatabase* pHostDb, OdXrefSubCommand subCmd, const OdDbObjectIdArray& btrIds, const OdStringArray& btrNames, const OdStringArray& paths),
301 (pHostDb, subCmd, btrIds, btrNames, paths), xrefSubCommandAborted, (pHostDb, subCmd, btrIds, btrNames, paths))
302
303 RXEVENT_FIRE_ABORT(xrefSubCommandAborted, (OdDbDatabase* pHostDb, OdXrefSubCommand subCmd, const OdDbObjectIdArray& btrIds, const OdStringArray& btrNames, const OdStringArray& paths),
304 (pHostDb, subCmd, btrIds, btrNames, paths), xrefSubCommandAborted, (pHostDb, subCmd, btrIds, btrNames, paths))
305 //
306 // OdEditorReactor events.
307 //
308 // file events
309 EDEVENT_FIRE(beginDwgOpen, (const OdString& filename), (filename))
310 EDEVENT_FIRE(endDwgOpen, (const OdString& filename), (filename))
311 EDEVENT_FIRE(beginClose, (OdDbDatabase* pDb), (pDb))
312
313 // xref events
314 EDEVENT_FIRE_ABORT(beginAttach, (OdDbDatabase* pToDb, const OdString& filename, OdDbDatabase* pFromDb), (pToDb, filename, pFromDb), abortAttach, (pToDb))
315 EDEVENT_FIRE_ABORT(otherAttach, (OdDbDatabase* pToDb, OdDbDatabase* pFromDb), (pToDb, pFromDb), abortAttach, (pToDb))
316 EDEVENT_FIRE(abortAttach, (OdDbDatabase* pFromDb), (pFromDb))
317 EDEVENT_FIRE(endAttach, (OdDbDatabase* pToDb), (pToDb))
318 EDEVENT_FIRE(redirected, (OdDbObjectId newId, OdDbObjectId oldId), (newId, oldId))
319 EDEVENT_FIRE(comandeered, (OdDbDatabase* pToDb, OdDbObjectId id, OdDbDatabase* pFromDb), (pToDb, id, pFromDb))
320 EDEVENT_FIRE_ABORT(beginRestore, (OdDbDatabase* pToDb, const OdString& filename, OdDbDatabase* pFromDb), (pToDb, filename, pFromDb), abortRestore, (pToDb))
321 EDEVENT_FIRE(abortRestore, (OdDbDatabase* pToDb), (pToDb))
322 EDEVENT_FIRE(endRestore, (OdDbDatabase* pToDb), (pToDb))
323
324 // xref subcommand events
325 EDEVENT_FIRE_ABORT(xrefSubCommandStart, (OdDbDatabase* pHostDb, OdXrefSubCommand subCmd, const OdDbObjectIdArray& btrIds, const OdStringArray& btrNames, const OdStringArray& paths),
326 (pHostDb, subCmd, btrIds, btrNames, paths), xrefSubCommandAborted, (pHostDb, subCmd, btrIds, btrNames, paths))
327 EDEVENT_FIRE(xrefSubcommandBindItem, (int activity, OdDbObjectId blockId), (activity, blockId))
328 EDEVENT_FIRE(xrefSubcommandAttachItem, (int activity, const OdString& xrefPath), (activity, xrefPath))
329 EDEVENT_FIRE(xrefSubcommandOverlayItem, (int activity, const OdString& xrefPath), (activity, xrefPath))
330 EDEVENT_FIRE(xrefSubcommandDetachItem, (int activity, OdDbObjectId blockId), (activity, blockId))
331 EDEVENT_FIRE(xrefSubcommandPathItem, (int activity, OdDbObjectId blockId, const OdString& newPath), (activity, blockId, newPath))
332 EDEVENT_FIRE(xrefSubcommandReloadItem, (int activity, OdDbObjectId blockId), (activity, blockId))
333 EDEVENT_FIRE(xrefSubcommandUnloadItem, (int activity, OdDbObjectId blockId), (activity, blockId))
334
335 // command undo events
336 EDEVENT_FIRE(undoSubcommandAuto, (int activity, bool state), (activity, state))
337 EDEVENT_FIRE(undoSubcommandControl,(int activity, int option), (activity, option))
338 EDEVENT_FIRE(undoSubcommandBegin, (int activity), (activity))
339 EDEVENT_FIRE(undoSubcommandEnd, (int activity), (activity))
340 EDEVENT_FIRE(undoSubcommandMark, (int activity), (activity))
341 EDEVENT_FIRE(undoSubcommandBack, (int activity), (activity))
342 EDEVENT_FIRE(undoSubcommandNumber, (int activity, int num), (activity, num))
343
344 // pickfirst selection event
345 EDEVENT_FIRE(pickfirstModified, (), ())
346
347 // layout event
348 EDEVENT_FIRE(layoutSwitched, (const OdString& newLayoutName), (newLayoutName))
349
350 // window events
351 EDEVENT_FIRE(docFrameMovedOrResized, (OdHWnd hwndDocFrame, bool moved), (hwndDocFrame, moved))
352 EDEVENT_FIRE(mainFrameMovedOrResized, (OdHWnd hwndMainFrame, bool moved), (hwndMainFrame, moved))
353
354 // mouse events
355 EDEVENT_FIRE(beginDoubleClick, (const OdGePoint3d& clickPoint), (clickPoint))
356 EDEVENT_FIRE(beginRightClick, (const OdGePoint3d& clickPoint), (clickPoint))
357
358 // toolbar events
359 EDEVENT_FIRE(toolbarBitmapSizeWillChange, (bool largeBitmaps), (largeBitmaps))
360 EDEVENT_FIRE(toolbarBitmapSizeChanged, (bool largeBitmaps), (largeBitmaps))
361
362 // partial open events
363 EDEVENT_FIRE(objectsLazyLoaded, (const OdDbObjectIdArray& objectIds), (objectIds))
364
365 // quit events
366 EDEVENT_FIRE_ABORT(beginQuit, (), (), quitAborted, ())
367 EDEVENT_FIRE(quitAborted, (), ())
368 EDEVENT_FIRE(quitWillStart, (), ())
369
370 // modeless operation events
371 EDEVENT_FIRE(modelessOperationWillStart, (const OdString& contextString), (contextString))
372 EDEVENT_FIRE(modelessOperationEnded, (const OdString& contextString), (contextString))
373
374 // SysVar events
375 EDEVENT_FIRE( sysVarChanged, (OdDbDatabase* pDb, const OdString& varName),(pDb, varName))
376 EDEVENT_FIRE( sysVarWillChange, (OdDbDatabase* pDb, const OdString& varName), (pDb, varName))
377};
378
380
386{
387public:
390};
391
393
394#include "TD_PackPop.h"
395
396#endif // _ODEDITORIMPL_H_INCLUDED_
397
#define TOOLKIT_EXPORT
Definition: DbExport.h:40
OdSmartPtr< OdEditorImpl > OdEditorImplPtr
Definition: EditorImpl.h:392
#define RXEVENT_FIRE(method, inparams, params)
Definition: EditorImpl.h:91
#define RXEVENT_FIRE_ABORT(method, inparams, params, abortmethod, abortparams)
Definition: EditorImpl.h:168
bool fxIsValidReactor(OdRxEventReactor *pRawReactor, const OdArray< OdRxEventReactorPtr > &apReactors, unsigned iHeuristicIndex)
Definition: EditorImpl.h:75
#define DCEVENT_FIRE(method, inparams, params, IdMappingToDatabase)
Definition: EditorImpl.h:144
#define EDEVENT_FIRE_ABORT(method, inparams, params, abortmethod, abortparams)
Definition: EditorImpl.h:198
#define EDEVENT_FIRE(method, inparams, params)
Definition: EditorImpl.h:116
OdArray< OdRxEventReactor * > fxCopyRawReactorPointers(OdArray< OdRxEventReactorPtr > &apReactors)
Definition: EditorImpl.h:66
int OdRefCounter
Definition: OdMutex.h:487
ptrdiff_t OdHWnd
OdXrefSubCommand
Definition: RxEvent.h:46
iterator end()
Definition: OdArray.h:1041
size_type length() const
Definition: OdArray.h:1537
size_type size() const
Definition: OdArray.h:1247
iterator begin()
Definition: OdArray.h:1017
void reserve(size_type reserveLength)
Definition: OdArray.h:1281
size_type append(const T &value)
Definition: OdArray.h:1725
ODRX_DECLARE_MEMBERS(OdEditorImpl)
OdArray< OdRxEventReactorPtr > m_reactors
Definition: EditorImpl.h:245
void addReactor(OdRxEventReactor *pReactor)
RXEVENT_FIRE(dwgFileOpened,(OdDbDatabase *db, const OdString &filename),(db, filename)) RXEVENT_FIRE(initialDwgFileOpenComplete
ODRX_DECLARE_MEMBERS(OdRxEventImpl)
OdRefCounter m_EventCounter
Definition: EditorImpl.h:243
OdMutex m_mutex
Definition: EditorImpl.h:246
void removeReactor(OdRxEventReactor *pReactor)