M/c++_api/inc/DM/IO/IExport.hpp
1 #pragma once
2 
3 #include "DM/config.hpp"
4 #include "DM/AutoLink.hpp" //enable autolink
5 
6 #include "DM/IControlObject.hpp"
7 #include "DM/IFilter.hpp"
8 #include "DM/IAddInfoLayout.hpp"
9 #include "DM/IBox.hpp"
10 
11 #include "DM/IO/IFileHeader.hpp"
12 #include "DM/IO/DataFormat.hpp"
13 
14 #include "DM/Log.hpp"
15 #include "DM/IO/DataFormat.hpp"
16 
17 //stl
18 #include <memory>
19 
20 #include <float.h>
21 
22 DM_NAMESPACE_BEGIN
23 
24 class DM_API IDatamanager;
25 
26 enum struct ExportError
27 {
28  noDataToWrite = -7, ///< no data to write
29  exportStreamNotAccessible, ///< export stream is not accessible
30  writingHeaderFailure, ///< error while writing the header
31  writingDataFailure, ///< error while writing data
32  exportStreamClosed, ///< export stream already closed
33  exportLimitReaced, ///< export limit is reached
34  interrupted, ///< export was interrupted
35  successful = 1 ///< no error occurred
36 };
37 
38 DM_API const char* toString(ExportError error); ///< get a textual description of an export error (this function is not thread safe)
39 
40 /// behaviour in case two consecutive lines have the same winput code (and structure line number)
42 {
43  insertSeparatorCode = 0, ///< correct solution based on winput specification (but doesn't work in gve)
44  insertMassPoint, ///< work-a-round for gve by duplicating the line start point as mass point
45  throwExpection ///< throw excpetion
46 };
47 
48 
49 /// \brief base class for exporting original geometry data file
50 class DM_API IExport : public ObjectBase
51 {
52 public:
53  /// \brief creates new export object
54  /**
55  interface for exporting geometry objects for different file formats. if not specified the function estimates the file format
56  based on the file extension.
57  \param[in] file filename
58  \param[in] format defines file format or use null for auto detection based on file extension
59  \param[in] filter filter for subselecting/transforming objects during export
60  \param[in] control control object for retrieving export progress information
61  \param[in] collectHdrContents flag for explicitly collecting header information while exporting
62  \param[in] invalidHeight height value that defines an invalid height (ie. no data value)
63  */
64  static IExport* New( const char *file, DM::DataFormat format = DM::DataFormat::null,
65  const FilterHandle filter = FilterHandle(),
67  bool collectHdrContents = false, double invalidHeight = DBL_MAX );
68 
69  /// The export object holds a handle to the manager object, securing its life time
70  static IExport* NewODM( Handle< IDatamanager > manager, bool preserveFileLayerInfo, const FilterHandle filter = FilterHandle(),
71  ControlObjectHandle control = ControlObjectHandle(), bool collectHdrContents = false,
72  unsigned maxBulkPoints = 1000, bool cloneAddInfos = true);
73  static IExport* NewODM( std::shared_ptr< IDatamanager > manager, bool preserveFileLayerInfo, const FilterHandle filter = FilterHandle(),
74  ControlObjectHandle control = ControlObjectHandle(), bool collectHdrContents = false,
75  unsigned maxBulkPoints = 1000, bool cloneAddInfos = true);
76  /// The export only stores a reference to the manager. hence it's the programmers responsiblity to secure its life time
77  static IExport* NewODM( IDatamanager &manager, bool preserveFileLayerInfo, const FilterHandle filter = FilterHandle(),
78  ControlObjectHandle control = ControlObjectHandle(), bool collectHdrContents = false,
79  unsigned maxBulkPoints = 1000, bool cloneAddInfos = true);
80 
81  /// Create an full waveform export
82  static IExport* NewFWF( const char *filename, unsigned versionMajor = 1, unsigned versionMinor = 0, bool binary = false,
84  bool collectHdrContents = false, bool append = false, int decimals = 3, int coordFieldWidth = 12,
85  bool echoWidthIsSigmaOfFit = true);
86 
87  /// Create an full waveform export
88  static IExport* NewSDW( const char *filename, unsigned versionMajor = 1, unsigned versionMinor = 0,
90  double invalidHeight = DBL_MAX );
91 
92  /// Create a winput export
93  static IExport* NewWinput( const char *filename, bool binary, DM::ColumnSemantic structIdAddInfoCol = DM::ColumnSemantic::null,
94  ExportWinputSeparator separator = ExportWinputSeparator::insertSeparatorCode,
96  bool collectHdrContents = false, bool append = false );
97 
98 
99 protected:
100  virtual ~IExport() {}
101 
102 public:
103  virtual void setControlObject(ControlObjectHandle control) = 0;
104  virtual ControlObjectHandle getControlObject() const = 0;
105 
106  //get the file header object
107  virtual FileHeaderHandle getHeader() const = 0;
108 
109  virtual void setFilter( FilterHandle filter ) = 0;
110  virtual FilterHandle getFilter() const = 0;
111 
112  // Export objects may benefit from knowing the data extents beforehand,
113  // e.g. NG_ExportLAS will better estimate coordinate reduction and scaling to internal representation
114  // This info cannot be passed in the base Ctor, as headers are allocated in the Ctor's of descendant export classes only if needed.
115  virtual void setBoundingBox( BoxHandle box ) = 0;
116 
117 
118  /// Retuns the filename
119  virtual const char* getFilename() const = 0;
120 
121  /// Retuns the file format
122  virtual DataFormat getFileFormat() const = 0;
123 
124  /// Set logging call back function
125  virtual void logTo( LogFn logFn ) = 0;
126 
127  /// write next object to the export object
128  virtual ExportError writeNext(const GeometryHandle &obj) = 0;
129 
130  /// close open file(s)
131  virtual void close() = 0;
132 
133  /// remove files
134  virtual bool removeFile() = 0;
135 
136  /// set coordinate reference system using a wkt string
137  virtual void setCRS(const char *crs) = 0;
138 };
139 
141 
142 DM_NAMESPACE_END
@ writingDataFailure
error while writing data
ExportWinputSeparator
behaviour in case two consecutive lines have the same winput code (and structure line number)
Definition: M/c++_api/inc/DM/IO/IExport.hpp:41
ExportError
Definition: M/c++_api/inc/DM/IO/IExport.hpp:26
@ noDataToWrite
no data to write
ColumnSemantic
Pre-defined attributes (attributes with semantic)
Definition: ColumnTypes.hpp:38
@ null
undefined semantic
@ throwExpection
throw excpetion
@ insertMassPoint
work-a-round for gve by duplicating the line start point as mass point
DataFormat
list of known data formats
Definition: DataFormat.hpp:9
@ insertSeparatorCode
correct solution based on winput specification (but doesn't work in gve)
base class for exporting original geometry data file
Definition: M/c++_api/inc/DM/IO/IExport.hpp:50
Interface to an Datamanager (ODM) object.
Definition: IDatamanager.hpp:57
@ box
box type (3D)
@ exportStreamClosed
export stream already closed
@ exportStreamNotAccessible
export stream is not accessible
Definition: M/c++_api/inc/DM/ObjectBase.hpp:8
@ writingHeaderFailure
error while writing the header
@ interrupted
export was interrupted
@ exportLimitReaced
export limit is reached
@ successful
no error occurred