DgnFile.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 
10 #include "DgnModel.h"
11 #include "DgnDocumentManager.h"
12 #include <Bentley/bvector.h>
13 #include <Bentley/bset.h>
14 #include <Bentley/bmap.h>
15 #include <Bentley/WString.h>
17 #include "DgnFileIO/DgnItemIndex.h"
18 
19 #define SUMMARY_STREAM 0 // The Summary Information Property Set
20 #define DOCSUMMARY_STREAM 1 // The DocumentSummaryInformation Property Set
21 #define USERDEFINED_STREAM 2 // The UserDefined Property Set
22 #define MEDIASUMMARY_STREAM 3 // The MediaFileSummaryInformation Property Set
23 
24 #define WORKSETPROPERTYID_WORKSETGUID L"WorkSetGUID"
25 #define WORKSETPROPERTYID_WORKSETNAME L"WorkSetName"
26 #define WORKSETPROPERTYID_WORKSETDESCRIPTION L"WorkSetDescription"
27 
28 
30 
33 {
39  DGNFILE_RIGHT_Unlimited = 0xffffffff,
40 };
41 
48 enum class ProcessChangesWhen
50 {
51  BeforeProcessing = 0,
52  AfterProcessing = 1
53 };
54 
56 enum class DgnFileChanges
57 {
58  Abandon = 0, // abandon any changes
59  Save = 1, // default, save any changes
60  FullSave = 2 // perform a full save in the case of a new file or new format
61 };
62 
64 enum class DgnSaveReason
65 {
66  UserInitiated = 1,
67  ApplInitiated = 2,
68  ReferenceFileSave = 3,
69  FileClose = 4,
70  FileCompress = 5,
71  FileSaveAs = 6,
72  AutoTime = 7,
73  PreCommit = 8,
74  SaveSettings = 9,
75  Backup = 10,
76  Encrypt = 11,
77  PreCompress = 12,
78 };
79 
81 enum class SeedCopyFlags
82 {
83  None = 0,
84  TCBData = (1 << 1),
85  DefaultViews = (1 << 2),
86  AllViewGroups = (1 << 3),
87  LevelTable = (1 << 4),
88  ColorTable = (1 << 5),
89  FontTable = (1 << 6),
90  TextStyleTable = (1 << 7),
91  DimStyleTable = (1 << 8),
92  MlineStyleTable = (1 << 9),
93  LineStyleTable = (1 << 10),
94  FilterTable = (1 << 11),
95  DictionaryTable = (1 << 12),
96  ReferenceAttach = (1 << 13),
97  RasterRefs = (1 << 14),
98  AllNamedViews = (1 << 15),
99  NamedViewsOfSeed = (1 << 16),
100  ApplicationInfo = (1 << 17),
101  AuxCoordSystem = (1 << 18),
102  AllLevelTables = (1 << 19), // not included in SeedCopyFlags::AllData. Copies level tables of all references as well as the level table for the file itself.
103  CreateDefaultModel = (1 << 20),
104  MaterialPalette = (1 << 21),
105  GeoCoordinateSystem = (1 << 22),
106  LevelNameDictionary = (1 << 23),
107  NoViewGroups = (1 << 24),
108  DisplayStyles = (1 << 25),
110  AllData = ((0x7fffffff) & ~(AllLevelTables | CreateDefaultModel)),
111 };
112 
114 
115 struct SeedData
117 {
123 
129 SeedData (DgnFileP seedFile, ModelId seedModel, SeedCopyFlags flags, bool headerXAttributes) { m_seedFile = seedFile, m_seedModel = seedModel, m_flags = flags, m_headerXAttributes = headerXAttributes; m_seedHighestId = 0; }
130 };
131 
133 typedef bvector<DgnModelP> T_DgnModelVector;
135 
136 class ZipInput;
137 class ZipOutput;
138 struct DgnModelFillContext;
139 struct ModelIndexItem;
140 struct ModelIndex;
141 
142 
144 enum class DgnFileOpenMode
145  {
146  ReadOnly = 1,
147  ReadWrite = 2,
148  PreferablyReadWrite = 3,
150  };
151 
153 enum class DgnFilePurpose
154  {
155  Unknown = 0,
156  MasterFile = 1,
157  DgnAttachment = 2,
158  DgnLib = 3,
159  ActivatedAttachment = 4,
160  CellLibrary = 5,
161  WorkDgn = 6,
162  Clipboard = 7,
163  Temporary = 8,
164  Icons = 9,
165  LevelLibrary = 10,
166  Overlay = 11,
167  };
168 
169 //=======================================================================================
172 //=======================================================================================
174 {
175  struct Key : AppDataKey {};
176 
177  virtual ~DgnFileAppData () {}
178 
183  virtual void _OnCleanup (DgnFileR host) = 0;
184 
191  virtual void _OnSave (DgnFileR host, ProcessChangesWhen when, DgnFileChanges changesFlag, DgnSaveReason reason, double timestamp) {}
192 
197  virtual void _OnModelDelete (DgnFileR host, ProcessChangesWhen when, ModelId modelID) {}
198 
202  virtual void _OnModelUnDeleted (DgnFileR host, ModelId modelID) {}
203 
209  virtual bool _OnModelsReloaded (DgnFileR host) { return false; }
210 
212  virtual bool _Dummy5(void*) {return false;}
213  virtual bool _Dummy4(void*) {return false;}
214  virtual bool _Dummy3(void*) {return false;}
215  virtual bool _Dummy2(void*) {return false;}
216  virtual bool _Dummy1(void*) {return false;}
218 };
219 
220 
221 //=======================================================================================
307 //=======================================================================================
309 {
310 private:
311  virtual void MakeClassAbstract() = 0;
312 public:
313  //=======================================================================================
318  //=======================================================================================
320  {
321  typedef T_DgnModelVector::const_iterator const_iterator;
323 
324  private:
325  T_DgnModelVector m_models;
326 
327  LoadedModelsCollection (T_DgnModelVector const&);
328  friend struct DgnFile;
329 
330  public:
331  // Returns an iterator to the first element in the collection.
333 
334  // Returns an iterator that points to the end of the collection.
336  };
337 
338 
339 public:
340 
342 
343 
357  DGNPLATFORM_EXPORT DgnFileStatus LoadDgnFile (StatusInt* openForWriteStatus);
358 
361  DGNPLATFORM_EXPORT StatusInt FillDictionaryModel ();
362 
369  DGNPLATFORM_EXPORT StatusInt FillSectionsInModel (DgnModelP model, DgnModelSections sectionsToFill=DgnModelSections::Model, DgnModelFillContext* unused=NULL);
371 
373 
374 
377  DGNPLATFORM_EXPORT int AddRef ();
378 
382  DGNPLATFORM_EXPORT int Release ();
384 
386 
387 
402  DGNPLATFORM_EXPORT LoadedModelsCollection GetLoadedModelsCollection () const;
403 
404  DGNPLATFORM_EXPORT ModelIndex const& GetModelIndex () const;
405 
408  DGNPLATFORM_EXPORT DgnModelR GetDictionaryModel ();
409 
412  DGNPLATFORM_EXPORT ModelId FindModelIdByName (WCharCP name) const;
413 
415  DGNPLATFORM_EXPORT ModelId GetDefaultModelId () const;
416 
420  DGNPLATFORM_EXPORT DgnModelP FindLoadedModelById (ModelId);
421 
430  DGNPLATFORM_EXPORT DgnModelPtr LoadModelById (ModelId modelID);
431 
433 
435 
436 
439  DGNPLATFORM_EXPORT bool HasPendingChanges ();
440 
444  DGNPLATFORM_EXPORT void SetFullSaveFlag ();
445 
449  DGNPLATFORM_EXPORT void SetAbandonChangesFlag ();
450 
454  DGNPLATFORM_EXPORT void ClearAbandonChangesFlag ();
455 
463  DGNPLATFORM_EXPORT StatusInt ProcessChanges (DgnSaveReason reason, double timestamp=0);
464 
472  DGNPLATFORM_EXPORT StatusInt DoSaveAs (DgnDocumentR newDoc, DgnFileFormatType format=DgnFileFormatType::V8, bool saveChanges=false, bool doPreSaveAsHooks=true);
473 
478  DGNPLATFORM_EXPORT StatusInt DoSaveTo (WCharCP newFileName, DgnFileFormatType format=DgnFileFormatType::V8);
479 
481  DGNPLATFORM_EXPORT void SetTransactable (bool yesNo);
483 
488  DGNPLATFORM_EXPORT void GetUniqueModelName (WStringR uniqueModelName, WCharCP baseName, bool forCopy = false);
489 
490 
492 
493 
496  DGNPLATFORM_EXPORT double GetLastSaveTime ();
497 
501  DGNPLATFORM_EXPORT DgnDocumentPtr GetDocumentPtr () const;
502 
506  DGNPLATFORM_EXPORT DgnDocumentCR GetDocument () const;
507 
510  DGNPLATFORM_EXPORT WString GetFileName () const;
511 
514  WString GetPackagedName () {return GetFileName();}
515 
518  DGNPLATFORM_EXPORT WString GetPackageName();
519 
523  DGNPLATFORM_EXPORT WString GetEmbeddedName() const;
524 
526  DGNPLATFORM_EXPORT UInt32 GetEmbeddedFileId () const;
527 
528  // test whether this is an embedded file.
529  bool IsEmbeddedFile() const {return GetEmbeddedFileId() > 0;}
530 
535  DGNPLATFORM_EXPORT StatusInt GetVersion (DgnFileFormatType* format, int* majorVersion, int* minorVersion);
536 
538  DGNPLATFORM_EXPORT bool IsTransactable () const;
539 
542  DGNPLATFORM_EXPORT bool IsLoaded () const;
543 
547  DGNPLATFORM_EXPORT bool IsOpen () const;
548 
550  DGNPLATFORM_EXPORT bool IsReadOnly () const;
551 
553  DGNPLATFORM_EXPORT bool IsIModel () const;
554 
585  DGNPLATFORM_EXPORT StatusInt GetDocumentProperty (int* propIDP, WCharCP nameP, int* propType, int streamToUse, void* value);
586 
601  DGNPLATFORM_EXPORT StatusInt SaveDocumentProperty (int* propIDP, WCharCP nameP, int propType, int streamToUse, const void *value);
602 
604  DGNPLATFORM_EXPORT FileLevelCacheR GetLevelCacheR ();
605 
607  enum SignatureCountType {SIGNATURE_COUNT_File=0, SIGNATURE_COUNT_Model=1, SIGNATURE_COUNT_All=-1};
608 
610  DGNPLATFORM_EXPORT size_t GetSignatureCount (SignatureCountType ct = SIGNATURE_COUNT_All) const;
611 
612 
614 
616 
621  DGNPLATFORM_EXPORT static DgnFilePtr Create (DgnDocumentR document, DgnFileOpenMode openMode);
622 
634  DGNPLATFORM_EXPORT static DgnFilePtr CreateNew (DgnFileStatus& status, DgnDocumentR document, DgnFileOpenMode openMode, SeedDataCR seedData, DgnFileFormatType format, bool threeD);
635 
637 
639 
640  DGNPLATFORM_EXPORT DgnModelP CreateNewModel (DgnModelStatus*, WCharCP, DgnModelType, bool, DgnModelCP seedModel=NULL, ModelId modelId = INVALID_MODELID);
642 
644  DGNPLATFORM_EXPORT DgnModelP CreateNewModel (DgnModelStatus* error, DgnFileR file, ModelInfoCR modelInfo, ModelId modelId = INVALID_MODELID);
645 
647  DGNPLATFORM_EXPORT StatusInt DeleteModel (DgnModelR);
648 
662  DGNPLATFORM_EXPORT DgnModelP LoadRootModelById (StatusInt* errorDetails, ModelId modelID, bool fillCache=false, bool andRefs=false, bool processAffected=false);
663 
670  DGNPLATFORM_EXPORT static BentleyStatus CopyModelContents (DgnModelR destModel, DgnModelCR sourceModel, T_StdElementRefVector* dictionaryElements);
672 
674 
675 
687  DGNPLATFORM_EXPORT StatusInt AddAppData (DgnFileAppData::Key const& key, DgnFileAppData* appData);
688 
694  DGNPLATFORM_EXPORT StatusInt DropAppData (DgnFileAppData::Key const& key);
695 
699  DGNPLATFORM_EXPORT DgnFileAppData* FindAppData (DgnFileAppData::Key const& key);
701 
703  DGNPLATFORM_EXPORT DgnColorMapP GetColorMapP();
704 
706  DGNPLATFORM_EXPORT DgnFontNumMapP GetDgnFontMapP();
707 
709  DGNPLATFORM_EXPORT LsDgnFileMapP GetLineStyleMapP ();
710 
724  DGNPLATFORM_EXPORT static bool IsSameFile (WCharCP fileName1, WCharCP fileName2, FileCompareMask compareMask);
725 
728 
731 
735  DGNPLATFORM_EXPORT BentleyStatus SetModelBackgroundColor (RgbColorDef const& color, DgnModelType type);
736 
739  DGNPLATFORM_EXPORT BentleyStatus GetModelBackgroundColor (RgbColorDef& color, DgnModelType type);
740 
743  DGNPLATFORM_EXPORT ModelId GetLastActiveModelId ();
744 };
745 
746 /*=================================================================================**/
750 
751 struct FilesToEmbedList : bvector <struct FileToEmbedEntry*>
752 {
754 DGNPLATFORM_EXPORT ~FilesToEmbedList();
755 
759 DGNPLATFORM_EXPORT StatusInt AddFile (DgnDocumentR fileToEmbed, WCharCP embedName);
760 
765 DGNPLATFORM_EXPORT StatusInt AddFile (DgnDocumentR fileToEmbed, WCharCP embedName, WString* alias);
766 
771 DGNPLATFORM_EXPORT StatusInt AddFile (DgnDocumentR fileToEmbed, WCharCP embedName, bvector<WString>* aliases);
772 
775 DGNPLATFORM_EXPORT StatusInt AddList (FilesToEmbedList& filesListToAdd);
776 
779 DGNPLATFORM_EXPORT StatusInt EmbedAll (DgnFileP dgnFile);
780 
782 DGNPLATFORM_EXPORT void ShowAll ();
783 
786 DGNPLATFORM_EXPORT WString GetFilePath (size_t index);
787 
791 DGNPLATFORM_EXPORT DgnDocumentPtr GetFileToEmbed (size_t index);
792 
797 DGNPLATFORM_EXPORT void SetFileToEmbed (DgnDocumentR fileToEmbed, size_t index);
798 
802 DGNPLATFORM_EXPORT WCharCP GetEmbedName (size_t index);
803 
807 DGNPLATFORM_EXPORT void SetEmbedName (WCharCP fileName, size_t index);
808 
812 DGNPLATFORM_EXPORT void AddAlias (WCharCP alias, size_t index);
813 
814 
818 DGNPLATFORM_EXPORT StatusInt FindEntryIndex (size_t& index, WCharCP embedName);
819 
820 
824 DGNPLATFORM_EXPORT StatusInt FindEntryIndexByFilePath (size_t& index, WCharCP filePath);
825 
826 };
829 
DgnFileStatus
Definition: DgnPlatformErrors.r.h:66
A DgnFontNumMap is a per-DgnFile object that maps "FontID" (int) values to Font objects. FontNumMaps are loaded from the FontTable element stored in the dictionary model of a DgnFile.
Definition: DgnFontManager.h:364
struct DgnPlatform::ViewGroupCollection const & ViewGroupCollectionCR
Definition: DgnPlatform.h:474
#define ENUM_IS_FLAGS(ENUMTYPE)
Definition: Bentley.r.h:164
T_DgnModelVector::const_iterator const_iterator
Definition: DgnFile.h:321
DgnFilePurpose
File purpose mode.
Definition: DgnFile.h:153
try read-write, if that doesn't work, try read-only
Seed data.
Definition: DgnFile.h:116
#define END_BENTLEY_DGNPLATFORM_NAMESPACE
Definition: DgnPlatformBaseType.r.h:69
save changes before a backup command.
struct DgnPlatform::DgnModel const & DgnModelCR
Definition: DgnPlatform.h:220
SeedCopyFlags m_flags
Seed model.
Definition: DgnFile.h:120
Used to access the line styles known to a given DgnFile.
Definition: DgnPlatform/LineStyle.h:341
Provides Bentley specific set implementation (Bentley/bset.h).
bool m_headerXAttributes
flags
Definition: DgnFile.h:121
struct DgnPlatform::DgnDocument const & DgnDocumentCR
Definition: DgnPlatform.h:195
A DgnDocument represents a file.
Definition: DgnDocumentManager.h:385
All rights, present and future.
Definition: DgnFile.h:38
ModelIndex - Provides access to basic information about all the models in a DgnFile.
Definition: dgnitemindex.h:60
File will be the "master file".
Applications subclass from this class to store their DgnFile specific data on a DgnFile via DgnFile::...
Definition: DgnFile.h:173
iterator begin()
Definition: stdcxx/bstdmap.h:178
save in preparation for design history commit
save was intiated by file compress
SaveAs, Export, Copy to clipboard.
Definition: DgnFile.h:36
SeedData(DgnFileP seedFile, ModelId seedModel, SeedCopyFlags flags, bool headerXAttributes)
Seed Highest Id (0).
Definition: DgnFile.h:129
File used as manually attached level library.
iterator end()
Definition: stdcxx/bstdmap.h:186
SignatureCountType
Identifies which digital signatures should be counted by GetSignatureCount.
Definition: DgnFile.h:607
DgnFileOpenMode
File open mode.
Definition: DgnFile.h:144
#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
No rights checking.
Definition: DgnFile.h:34
File opened through the "workDgn" interface.
Currently used by cell libraries when making change to remote file.
bool IsEmbeddedFile() const
Definition: DgnFile.h:529
DgnFileFormatType
Known file formats supported by DgnPlatform.
Definition: DgnPlatform.r.h:1043
uint32_t UInt32
Definition: Bentley.r.h:128
#define NULL
Definition: Bentley.h:157
ElementId m_seedHighestId
header xAttributes.
Definition: DgnFile.h:122
virtual void _OnModelUnDeleted(DgnFileR host, ModelId modelID)
This method is called after a model has been undeleted from the DgnFile on which this DgnFileAppData ...
Definition: DgnFile.h:202
const_iterator iterator
only const iteration is possible
Definition: DgnFile.h:322
virtual void _OnSave(DgnFileR host, ProcessChangesWhen when, DgnFileChanges changesFlag, DgnSaveReason reason, double timestamp)
This method is called before and after a "Save" operation is performed on the DgnFile on which this D...
Definition: DgnFile.h:191
DgnFileChanges
Possible values for DgnFileChanges.
Definition: DgnFile.h:56
! List of files to embed within an I-Model package.
Definition: DgnFile.h:751
Collection of all models that are currently loaded in a DgnFile.
Definition: DgnFile.h:319
A DgnModel represents a DgnModel in memory.
Definition: DgnModel.h:236
struct DgnPlatform::SeedData const & SeedDataCR
Definition: DgnPlatform.h:445
encrypting/decrypting the file
FileCompareMask
File Compare Masks - Used to control degree of comparison in function mdlFile_isSameFile.
Definition: DgnPlatform.h:1602
DgnModelType
Identifies the type or purpose of a model.
Definition: DgnPlatform.r.h:367
#define CLRPUBLIC
Definition: DgnPlatform/ExportMacros.h:12
virtual void _OnModelDelete(DgnFileR host, ProcessChangesWhen when, ModelId modelID)
This method is called before and after a model is deleted from the DgnFile on which this DgnFileAppDa...
Definition: DgnFile.h:197
BentleyStatus
Definition: Bentley.h:208
Open for both read and write.
save was initiated explicitly by user
DgnModelSections
The element sections within a DgnModel.
Definition: BentleyDgn.h:16
save was initiated by an application
A shared pointer template for reference-counted objects.
Definition: RefCounted.h:119
user selected a "save as" to new file
Plot, print preview.
Definition: DgnFile.h:35
Reference counted class for storing information about a MicroStation color table. ...
Definition: DgnColorMap.h:22
virtual ~DgnFileAppData()
Definition: DgnFile.h:177
File used as manually attached level library.
DgnModelStatus
Errors generated by accessing or attempting to modify a DgnModel.
Definition: DgnPlatformErrors.r.h:146
save was intiated by file close
A unique (for this session) key to identify this AppData type.
Definition: DgnAppData.h:21
struct DgnPlatform::DgnModel const * DgnModelCP
Definition: DgnPlatform.h:220
Int32 ModelId
Definition: DgnPlatformBaseType.r.h:84
#define INVALID_MODELID
Definition: DgnPlatform.h:640
#define BEGIN_BENTLEY_DGNPLATFORM_NAMESPACE
Definition: DgnPlatformBaseType.r.h:68
A FileLevelCache contains the level definitions for a file.
Definition: LevelCache.h:850
A DgnAttachment represents a reference from one model to another, with transforming, clipping, and filtering applied.
Definition: DgnAttachment.h:192
int StatusInt
Definition: Bentley.h:222
UInt64 ElementId
Definition: DgnPlatformBaseType.r.h:83
struct DgnPlatform::NamedViewCollection const & NamedViewCollectionCR
Definition: DgnPlatform.h:413
bvector< ElementRefP > T_StdElementRefVector
Definition: ElementRefBase.h:102
WString GetPackagedName()
Get the PackagedFileName of this DgnFile.
Definition: DgnFile.h:514
virtual bool _OnModelsReloaded(DgnFileR host)
This method is called when the DgnModels in memory are going to be reloaded.
Definition: DgnFile.h:209
DgnFileP m_seedFile
Definition: DgnFile.h:118
May modify file contents (implies not read-only)
Definition: DgnFile.h:37
All rights, present and future.
Definition: DgnFile.h:39
ModelId m_seedModel
Seed file.
Definition: DgnFile.h:119
struct DgnPlatform::ModelInfo const & ModelInfoCR
Definition: DgnPlatform.h:400
Definition: DgnPlatform.r.h:339
DgnSaveReason
Save reasons set to FileSave callback.
Definition: DgnFile.h:64
SeedCopyFlags
Seed copy flags for new DgnFile creation.
Definition: DgnFile.h:81
File created for temporary use (such as Save As).
ProcessChangesWhen
File-Save hooks get called before and after processing changes.
Definition: DgnFile.h:49
A string class that has many of the same capabilities as std::string, plus additional functions such ...
Definition: WString.h:51
unknown status (newly added to system)
DgnFileRights
Builtin access rights for protected files.
Definition: DgnFile.h:32

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