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