ITxnManager.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 #include "ElementAgenda.h"
10 #include <stack>
11 
13 
14 //=======================================================================================
19 //=======================================================================================
21 {
26 };
27 
28 //=======================================================================================
32 // @bsiclass Bentley Systems
33 //=======================================================================================
34 struct TxnPos {Int32 m_pos;};
35 
36 struct TxnFilter;
37 
38 /*=================================================================================**/
130 //=======================================================================================
133 // @bsiclass Bentley Systems
134 //=======================================================================================
136 {
143  virtual void _OnElementChanged (MSElementDescrCP newDscr, MSElementDescrCP oldDscr, ChangeTrackInfoCP info, bool* cantBeUndoneFlag) {}
149  virtual void _OnXAttributeChanged (XAttributeHandleCR attr, ChangeTrackInfoCP info, bool* cantBeUndoneFlag) {}
156  virtual void _OnElementUndoRedo (MSElementDescrCP afterUndoRedo, MSElementDescrCP beforeUndoRedo, ChangeTrackAction originalChange, bool isUndo, ChangeTrackSource, ChangeTrackInfoCP info) {}
162  virtual void _OnXAttributeUndoRedo (XAttributeHandleCR xattr, ChangeTrackAction originalChange, bool isUndo, ChangeTrackSource, ChangeTrackInfoCP info) {}
165  virtual void _OnUndoRedoFinished (bool isUndo) {}
167  virtual void _OnTxnValidate () {}
169  virtual void _OnTxnClose () {}
171  virtual void _OnTxnBoundary () {}
179  virtual void _OnModelChange (DgnModelP model, ModelInfoCP modelInfo, bool isPreChange, ChangeTrackInfoCR info, bool* cantBeUndoneFlag) {}
186  virtual void _OnModelUndoRedo (DgnModelP model, ModelInfoCP modelInfo, bool reverseSettingsChanges, bool isUndo, bool isPreChange, ChangeTrackSource, ChangeTrackInfoCR) {}
187 
189  virtual void _OnUndoInvalidated() {}
190 };
191 
192 /*=================================================================================**/
197  {
198  protected:
199  enum Flags {FLAG_AllOff=0, FLAG_CallAsynchs=1, FLAG_SaveInUndo=2, FLAG_OverrideIdCheck=4};
201  void SetFlag (Flags f, bool b) {if (b) m_flags = (Flags)(m_flags|f); else m_flags = (Flags)(m_flags &~f);}
202  public:
204  TxnElementWriteOptions() : m_flags ((Flags)(FLAG_CallAsynchs|FLAG_SaveInUndo)) {}
206  void SetCallAsynchs (bool b) {SetFlag (FLAG_CallAsynchs, b);}
208  bool GetCallAsynchs () const {return (m_flags&FLAG_CallAsynchs) != 0;}
210  void SetSaveInUndo (bool b) {SetFlag (FLAG_SaveInUndo, b);}
212  bool GetSaveInUndo () const {return (m_flags&FLAG_SaveInUndo) != 0;}
213 
214  };
215 
216 
217 /*=================================================================================**/
222 {
225 
228 };
229 
230 
231 /*=================================================================================**/
236 {
237 protected:
238  bool m_dummy;
239 
240 public:
241  TxnXAttributeWriteOptions() : m_dummy(false) {}
242 };
243 
244 /*=================================================================================**/
249 {
251 };
252 
253 //=======================================================================================
258 // @remark Required library : DgnPlatform<ApiNumber>.lib i.e. DgnPlatform5.lib
259 // @bsiclass Bentley Systems
260 //=======================================================================================
262 {
263 struct ICustomEntry;
264 typedef RefCountedPtr<ICustomEntry> (*DeserializeCustomItemFunc) (byte const* data, size_t numBytes);
265 
266 private:
267  virtual void MakeClassAbstract() = 0;
268 public:
269 public:
270 
272 
273 DGNPLATFORM_EXPORT StatusInt AddXAttribute (ElementRefP elRef, XAttributeHandlerId handlerId, UInt32 xAttrId, void const* xAttrData, UInt32 length, UInt32* outXAttrId=NULL, TxnXAttributeAddOptions const& opts = TxnXAttributeAddOptions());
286 
293 
303 DGNPLATFORM_EXPORT StatusInt ModifyXAttributeData (XAttributeHandleCR xAttr, void const* data, UInt32 start, UInt32 length, TxnXAttributeWriteOptions const& opts = TxnXAttributeWriteOptions());
304 
312 DGNPLATFORM_EXPORT StatusInt ReplaceXAttributeData (XAttributeHandleCR xAttr, void const* data, UInt32 newSize = 0, TxnXAttributeWriteOptions const& opts = TxnXAttributeWriteOptions());
314 
316 
317 
323 
335 
343 
345 
346 
360 DGNPLATFORM_EXPORT DgnModelP CreateNewModel (DgnModelStatus* error, DgnFileR file, WCharCP name, DgnModelType type, bool is3D, DgnModelCP seedModel=NULL, ModelId modelId = INVALID_MODELID);
361 
372 DGNPLATFORM_EXPORT DgnModelP CreateNewModel (DgnModelStatus* error, DgnFileR file, ModelInfoCR modelInfo, ModelId modelId = INVALID_MODELID);
373 
381 DGNPLATFORM_EXPORT StatusInt DeleteModel (DgnModelR dgnModel);
382 
390 // DgnModel::SetModelInfo(). SetModelInfo will then call Txn::SaveModelProperties if the properties have changed. Note that you must eventually call
393 DGNPLATFORM_EXPORT StatusInt SaveModelProperties (DgnModelR model, bool bSaveSettings = false, bool forceSave = false);
394 
396 
398 
399 
400 #if defined (OLD_WAY)
401 struct ICustomEntry : IRefCounted
409 {
410 private:
411  virtual void _OnReverse () {}
412  virtual void _OnReinstate () {}
413  virtual void _OnCancel () {}
414  virtual void _Dump () {}
415 public:
417  DGNPLATFORM_EXPORT void OnReverse ();
419  DGNPLATFORM_EXPORT void OnReinstate ();
421  DGNPLATFORM_EXPORT void OnCancel ();
423  DGNPLATFORM_EXPORT void Dump ();
424 };
425 
428 DGNPLATFORM_EXPORT void SaveCustomEntryInUndo (ICustomEntry& entry);
429 #else
430 
439 {
441 virtual void _OnReverse () {}
443 virtual void _OnReinstate () {}
445 virtual void _OnCancel () {}
447 virtual void _Dump () {}
448 };
449 
455 DGNPLATFORM_EXPORT void SaveCustomEntryInUndo (byte const* data, size_t numBytes, DeserializeCustomItemFunc func);
456 #endif
457 
458 
460 
461 };
462 
463 //=======================================================================================
466 // @remark Required library : DgnPlatform<ApiNumber>.lib i.e. DgnPlatform5.lib
467 // @bsiclass Bentley Systems
468 //=======================================================================================
470 {
471 private:
472  virtual void MakeClassAbstract() = 0;
473 public:
474 public:
475 
478 
479 
481 
482 
486 DGNPLATFORM_EXPORT void ValidateCurrentTxn ();
487 
496 DGNPLATFORM_EXPORT void CloseCurrentTxn (bool doValidate);
497 
507 DGNPLATFORM_EXPORT void UpdateDisplay (bool andDraw=true);
508 
510 DGNPLATFORM_EXPORT static ITxn& GetCurrentTxn();
511 
514 DGNPLATFORM_EXPORT ITxn& SetCurrentTxn (ITxn& newTxn);
516 
523 DGNPLATFORM_EXPORT StatusInt FindElement (DgnModelP model, ElementId eid, TxnPos start, TxnPos end, ChangeTrackAction action);
524 
526 
527 
530 DGNPLATFORM_EXPORT void AddTxnMonitor (TxnMonitor& monitor);
531 
534 DGNPLATFORM_EXPORT void DropTxnMonitor (TxnMonitor& monitor);
535 
537 
539 
540 
544 DGNPLATFORM_EXPORT bool IsActive ();
545 
549 DGNPLATFORM_EXPORT void Activate ();
550 
555 DGNPLATFORM_EXPORT void Deactivate ();
557 
559 
560 
568 DGNPLATFORM_EXPORT void StartTxnGroup (bool startNewTxn);
569 
571 DGNPLATFORM_EXPORT void EndTxnGroup ();
572 
574 DGNPLATFORM_EXPORT size_t GetTxnGroupCount ();
575 
577 DGNPLATFORM_EXPORT TxnPos GetCurrGroupStartPos();
579 
581 
582 
585 DGNPLATFORM_EXPORT bool HasEntries ();
586 
589 DGNPLATFORM_EXPORT bool RedoIsPossible ();
590 
600 DGNPLATFORM_EXPORT void ReverseTxns (int numActions, bool warnIfNotActiveModel);
601 
604 DGNPLATFORM_EXPORT void ReverseSingleTxn (bool callRestartFunc=true);
605 
607 DGNPLATFORM_EXPORT void ReverseToMark ();
608 
611 DGNPLATFORM_EXPORT void ReverseAll (bool prompt);
612 
617 DGNPLATFORM_EXPORT StatusInt ReverseToPos (TxnPos pos);
618 
622 DGNPLATFORM_EXPORT TxnPos GetCurrTxnPos ();
623 
629 DGNPLATFORM_EXPORT StatusInt CancelToPos (TxnPos pos, bool callRestartFunc=true);
630 
635 DGNPLATFORM_EXPORT void ClearReversedTxns ();
636 
640 DGNPLATFORM_EXPORT StatusInt ReinstateTxn ();
641 
643 DGNPLATFORM_EXPORT bool IsUndoInProgress ();
644 
646 
647 };
648 
A "handle" that can be used to access a single XAttribute of a persistent element.
Definition: XAttributeIter.h:74
This interface provides a transaction mechanism for handling changes to persistent elements and model...
Definition: ITxnManager.h:469
TxnXAttributeWriteOptions()
Definition: ITxnManager.h:241
Int32 m_pos
Definition: ITxnManager.h:34
#define END_BENTLEY_DGNPLATFORM_NAMESPACE
Definition: DgnPlatformBaseType.r.h:69
virtual void _OnUndoRedoFinished(bool isUndo)
Undo or redo is finished.
Definition: ITxnManager.h:165
Interface to be implemented to monitor changes to elements.
Definition: ITxnManager.h:135
struct DgnPlatform::ChangeTrackInfo const & ChangeTrackInfoCR
Definition: DgnPlatform.h:176
Options that apply when adding element changes using the current transaction.
Definition: ITxnManager.h:221
The interface to write changes in the context of a transaction to elements, XAttributes, and models.
Definition: ITxnManager.h:261
void SetCallAsynchs(bool b)
Set the option to call asynchs. Defaults to true.
Definition: ITxnManager.h:206
virtual void _OnXAttributeUndoRedo(XAttributeHandleCR xattr, ChangeTrackAction originalChange, bool isUndo, ChangeTrackSource, ChangeTrackInfoCP info)
An XAttribute change was undone or redone.
Definition: ITxnManager.h:162
virtual void _OnCancel()
Called when the transaction is cancelled after being undone. Releases the pointer to the custom entry...
Definition: ITxnManager.h:445
virtual void _OnReinstate()
Called when the transaction is redone.
Definition: ITxnManager.h:443
TxnXAttributeAddOptions()
Definition: ITxnManager.h:250
struct DgnPlatform::XAttributeHandle const & XAttributeHandleCR
Definition: DgnPlatform.h:489
virtual void _OnElementUndoRedo(MSElementDescrCP afterUndoRedo, MSElementDescrCP beforeUndoRedo, ChangeTrackAction originalChange, bool isUndo, ChangeTrackSource, ChangeTrackInfoCP info)
An element change was undone or redone.
Definition: ITxnManager.h:156
iterator end()
Definition: stdcxx/bstdmap.h:186
ChangeTrackAction
ChangeTrackAction's are the type of direct changes that happen to DGN elements.
Definition: DgnPlatform.h:705
Int32 processNumber
process active at time of entry
Definition: ITxnManager.h:23
struct DgnPlatform::ChangeTrackInfo const * ChangeTrackInfoCP
Definition: DgnPlatform.h:176
A writeable "handle" to an MSElement.
Definition: ElementHandle.h:470
bool m_dummy
Definition: ITxnManager.h:238
TxnElementWriteOptions()
The default write options.
Definition: ITxnManager.h:204
bool GetCallAsynchs() const
Get the option to call asynchs.
Definition: ITxnManager.h:208
#define DGNPLATFORM_EXPORT
Definition: DgnPlatform/ExportMacros.h:58
A DgnFile is an in-memory representation of a physical file, regardless of its format.
Definition: DgnFile.h:308
wchar_t const * WCharCP
Definition: Bentley.h:224
int16_t Int16
Definition: Bentley.r.h:117
This structure is passed to TxnMonitor functions as they are called during direct changes to the DGN ...
Definition: ITxnManager.h:20
uint32_t UInt32
Definition: Bentley.r.h:128
#define NULL
Definition: Bentley.h:157
A two-part ID used by XAttribute Handlers.
Definition: DgnCore.h:74
Options that apply when changing, dropping, or deleting elements using the current transaction...
Definition: ITxnManager.h:196
virtual void _OnElementChanged(MSElementDescrCP newDscr, MSElementDescrCP oldDscr, ChangeTrackInfoCP info, bool *cantBeUndoneFlag)
The specified element was changed.
Definition: ITxnManager.h:143
struct DgnPlatform::MSElementDescr const * MSElementDescrCP
Definition: DgnPlatform.h:390
Int32 idNumber
id for grouping undos
Definition: ITxnManager.h:25
The current "transaction position." This structure reflects a point in time for the element changes j...
Definition: ITxnManager.h:34
Options that apply when adding XAttributes using the current transaction.
Definition: ITxnManager.h:248
virtual void _Dump()
For debugging purposes. Should write to stdout.
Definition: ITxnManager.h:447
A DgnModel represents a DgnModel in memory.
Definition: DgnModel.h:236
DgnModelType
Identifies the type or purpose of a model.
Definition: DgnPlatform.r.h:367
int32_t Int32
Definition: Bentley.r.h:119
virtual void _OnXAttributeChanged(XAttributeHandleCR attr, ChangeTrackInfoCP info, bool *cantBeUndoneFlag)
The specified XAttribute was changed.
Definition: ITxnManager.h:149
TxnElementAddOptions(TxnElementWriteOptions const &r)
Define Add options equal to the specified write options.
Definition: ITxnManager.h:227
IManager * GetManager()
Return a pointer to the one and only relationship manager.
A shared pointer template for reference-counted objects.
Definition: RefCounted.h:119
virtual void _OnTxnValidate()
The current transaction is about to be closed.
Definition: ITxnManager.h:167
virtual void _OnUndoInvalidated()
The undo buffer has become invalidated and reset during an undo operation. This is a rare but drastic...
Definition: ITxnManager.h:189
void SetFlag(Flags f, bool b)
Definition: ITxnManager.h:201
Interface for a custom entry to be stored in the undo buffer.
Definition: ITxnManager.h:438
Base class to make a class non-copyable.
Definition: NonCopyableClass.h:23
DgnModelStatus
Errors generated by accessing or attempting to modify a DgnModel.
Definition: DgnPlatformErrors.r.h:146
Interface that provides direct and efficient access to element data.
Definition: ElementRefBase.h:120
struct DgnPlatform::DgnModel const * DgnModelCP
Definition: DgnPlatform.h:220
unsigned char byte
Definition: Bentley.r.h:144
Int32 ModelId
Definition: DgnPlatformBaseType.r.h:84
virtual void _OnModelUndoRedo(DgnModelP model, ModelInfoCP modelInfo, bool reverseSettingsChanges, bool isUndo, bool isPreChange, ChangeTrackSource, ChangeTrackInfoCR)
A model change is being undone or redone.
Definition: ITxnManager.h:186
#define INVALID_MODELID
Definition: DgnPlatform.h:640
Flags
Definition: ITxnManager.h:199
Flags m_flags
Definition: ITxnManager.h:200
#define BEGIN_BENTLEY_DGNPLATFORM_NAMESPACE
Definition: DgnPlatformBaseType.r.h:68
int StatusInt
Definition: Bentley.h:222
UInt64 ElementId
Definition: DgnPlatformBaseType.r.h:83
Options that apply when changing or deleting XAttributes using the current transaction.
Definition: ITxnManager.h:235
virtual void _OnReverse()
Called when the transaction is undone.
Definition: ITxnManager.h:441
ChangeTrackSource
Identifies the transaction manager or the design history manager as the source of the version restore...
Definition: DgnPlatform.h:730
struct DgnPlatform::ModelInfo const * ModelInfoCP
Definition: DgnPlatform.h:400
TxnElementAddOptions()
The default add options.
Definition: ITxnManager.h:224
Interface to be adopted by a class the implements the reference-counting pattern. ...
Definition: RefCounted.h:34
virtual void _OnTxnBoundary()
The current transaction is closed – called after the display is updated.
Definition: ITxnManager.h:171
virtual void _OnTxnClose()
The current transaction is closed – called before the display is updated.
Definition: ITxnManager.h:169
struct DgnPlatform::ModelInfo const & ModelInfoCR
Definition: DgnPlatform.h:400
bool GetSaveInUndo() const
Get the option to save in undo.
Definition: ITxnManager.h:212
void SetSaveInUndo(bool b)
Set the option to save in undo. Defaults to true.
Definition: ITxnManager.h:210
Int16 funcname
Number of RTYPE_CMDNAME resource.
Definition: ITxnManager.h:24
virtual void _OnModelChange(DgnModelP model, ModelInfoCP modelInfo, bool isPreChange, ChangeTrackInfoCR info, bool *cantBeUndoneFlag)
The specified model has been changed.
Definition: ITxnManager.h:179
ChangeTrackAction action
type of action
Definition: ITxnManager.h:22

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.