API Documentation
Loading...
Searching...
No Matches
IOFactory.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: IOFactory
28File: IOFactory
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/SoftwareService.h>
35#include <NDEVR/FactoryOptions.h>
36#include <NDEVR/Model.h>
37#include <NDEVR/File.h>
38#include <NDEVR/FileFormat.h>
39namespace NDEVR
40{
41 class Model;
42 class Log;
43 class SpatialObject;
44 class DesignObjectLookup;
45 class FactoryFeatures;
46 /**--------------------------------------------------------------------------------------------------
47 \brief Allows the software to display a warning to the end user about a problem encountered during
48 an IOFactory read/write operation.
49 **/
57 /**--------------------------------------------------------------------------------------------------
58 \brief A container of input information that is to be filled with output information by an IOFactory
59 **/
61 {
62 FactoryParameters(const File& file, const FileFormat& format, const String& name = "default");
63 FactoryParameters(const FileRequest& request, const String& name = "default");
64
65 /**--------------------------------------------------------------------------------------------------
66 \brief The format to read/write. If factory supports more than one format (eg: .obj and .mtl),
67 the name parameter can specify which part to lookup.
68 **/
69 const FileFormat& format(const String& name = "default") const;
70
71 /**--------------------------------------------------------------------------------------------------
72 \brief The format to read/write. If factory supports more than one format (eg: .obj and .mtl),
73 the name parameter can specify which part to lookup.
74 **/
75 FileFormat& format(const String& name = "default");
76 /**--------------------------------------------------------------------------------------------------
77 \brief The address for reading/writing. If factory supports more than one file (eg: .obj and .mtl),
78 the name parameter can specify which part to lookup.
79 **/
80 const File& file(const String& name = "default") const;
81
82 /**--------------------------------------------------------------------------------------------------
83 \brief Checks to see if a given model is on the list
84 **/
85 bool shouldWriteModel(const Model& model) const;
86
87 /**--------------------------------------------------------------------------------------------------
88 \brief Adds a warning that will be shown to the user when the IOFactory operation is completed
89 **/
90 void addWarning(const FileFactoryWarning& warning);
91 public:
93 FactoryOptions options;//All read/write options including special parameters
94 Buffer<FileFactoryWarning> warnings;//Any warnings to show to the user
97 DesignObjectLookup* lookup = nullptr;
98 ProgressInfo* log = nullptr;
99 };
100
101 /**--------------------------------------------------------------------------------------------------
102 \brief A service that provides Import/Export functionality for a model heirarchy. These can be
103 registered with a EnableFactory to allow the user to export/import to certain file formats.
104 In order to provide support for new file formats, classes should overrdide this class and then add
105 themselves using EnableFactory.
106
107 For write operations we will first send which data structures the user wishes to export, if it is
108 possible for a certain implementation to write those data structures, it will then be asked to
109 provide available write formats. If the user chooses the provided format FactoryFeatures will
110 be requested to see what options to show the user. The factory can then write this data.
111
112 For read operations we will first ask which extensions are supported. If the user chooses a file with
113 the supported extension, FactoryFeatures will be requested to see what options to show the user.
114 The factory can then read this data.
115 **/
117 {
118 public:
119 friend class ModelFactory;
120 IOFactory(const String& factory_name);
121 const String& name() const { return m_factory_name; }
122 virtual ~IOFactory();
123 bool writeScenesToFile(const File& file, const Buffer<Scene>& scene);
126 virtual void getSupportedFormats(Buffer<FileFormat>& formats, bool is_read) = 0;
127 virtual void getSupportedFormats(Buffer<FileFormat>& formats, const File& file);
128 virtual void getSupportedFormats(Buffer<FileFormat>& formats, DesignObjectLookup* lookup, const Buffer<UUID>& models);
129 virtual void getSupportedFormatsForExtension(Buffer<FileFormat>& formats, bool is_read, const String& extension);
130 virtual void getSupportedFormatsByModelType(Buffer<FileFormat>& formats, bool is_read, const String& model_type);
131 virtual Buffer<UUID> filterModelsToExport(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, const FileFormat& export_format) const;
132 virtual bool isFactoryEnabled(bool is_read) const;
133 virtual bool canRead(const File& file);
134 virtual bool determineExtension(const File& file, String& extension);
135 virtual bool canWrite(const File& file);
136 virtual bool isAutoEnabled() const;
137 virtual String getIcon(const File& file);
138 virtual bool canRead(const FactoryParameters& file);
139 virtual bool canWrite(const FactoryParameters& file);
140 virtual bool canRead(const FileFormat& file);
141 virtual bool canWrite(const FileFormat& file);
145 virtual bool updateFromFile(const FactoryParameters& file, const FactoryOptions& old_options);
146 virtual FactoryFeatures factoryFeatures(const FactoryParameters& file, bool is_import) const = 0;
149 //If isAutoEnabled returns false and the system does not detect a valid password for the operation, an exception will be thrown.
150 void throwIfNotEnabled(bool is_read);
151 //Functions should call this in order to add a factory to the system
152 static void EnableFactory(IOFactory* factory, const String& read_password, const String& write_password);
153 static void EnableFactory(const String& factory, const String& read_password, const String& write_password);
154 static void EnableExtension(const String& extension, const String& read_password, const String& write_password);
155 private:
156 virtual bool readFile(FactoryParameters& file) = 0;
157 virtual bool writeFile(FactoryParameters& file) = 0;
158 private:
159 String m_factory_name;
160 };
161}
#define NDEVR_FACTORY_API
Definition DLLInfo.h:57
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A core class where all Design Objects including models, materials, and geometries are stored....
Definition DesignObjectLookup.h:65
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Allows IOFactories to report what features they support to make the import/export dialogs easier to s...
Definition FactoryFeatures.h:44
User-defined options that define preferences for importing and exporting using IOFactory objects.
Definition FactoryOptions.h:49
Data that describes a particular file format and how to use the format with the program....
Definition FileFormat.h:43
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
A service that provides Import/Export functionality for a model heirarchy. These can be registered wi...
Definition IOFactory.h:117
String factoryReadAppFeature() const
static void EnableFactory(IOFactory *factory, const String &read_password, const String &write_password)
virtual String getIcon(const File &file)
virtual bool canWrite(const File &file)
String factoryWriteAppFeature() const
virtual bool canWrite(const FactoryParameters &file)
virtual FactoryFeatures factoryFeatures(const FactoryParameters &file, bool is_import) const =0
virtual ~IOFactory()
virtual bool canWrite(const FileFormat &file)
virtual bool determineExtension(const File &file, String &extension)
virtual FactoryOptions defaultReadOptions(const FactoryParameters &file) const
virtual void getSupportedFormatsForExtension(Buffer< FileFormat > &formats, bool is_read, const String &extension)
void throwIfNotEnabled(bool is_read)
virtual bool canRead(const File &file)
static void EnableFactory(const String &factory, const String &read_password, const String &write_password)
virtual FactoryOptions defaultWriteOptions(const FactoryParameters &file) const
virtual void getSupportedFormats(Buffer< FileFormat > &formats, DesignObjectLookup *lookup, const Buffer< UUID > &models)
virtual bool isAutoEnabled() const
virtual void getSupportedFormatsByModelType(Buffer< FileFormat > &formats, bool is_read, const String &model_type)
Buffer< Scene > readScenesFromFile(const File &file)
virtual bool canRead(const FileFormat &file)
const String & name() const
Definition IOFactory.h:121
bool writeScenesToFile(const File &file, const Buffer< Scene > &scene)
virtual bool updateFromFile(const FactoryParameters &file, const FactoryOptions &old_options)
virtual void getSupportedFormats(Buffer< FileFormat > &formats, bool is_read)=0
virtual bool canRead(const FactoryParameters &file)
void getSupportedFormats(Buffer< FileFormat > &formats)
bool readFileWithDefaultSettings(const File &file, DesignObjectLookup *lookup)
virtual bool isFactoryEnabled(bool is_read) const
static void EnableExtension(const String &extension, const String &read_password, const String &write_password)
virtual void getSupportedFormats(Buffer< FileFormat > &formats, const File &file)
virtual Buffer< UUID > filterModelsToExport(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, const FileFormat &export_format) const
IOFactory(const String &factory_name)
The core logic for importing and exporting files from the model heirarchy. Stores a series of IOFacto...
Definition ModelFactory.h:45
A core class that represents a node on model heirarchy. This node may contain a Geometry or one or mo...
Definition Model.h:58
A light-weight base class for Log that allows processes to update, without the need for additional in...
Definition ProgressInfo.hpp:48
Software Services provide an interface for adding to or changing the software behavior via functional...
Definition SoftwareService.h:9
The core String class for the NDEVR API.
Definition String.h:69
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
A container of input information that is to be filled with output information by an IOFactory.
Definition IOFactory.h:61
Buffer< UUID > models
Definition IOFactory.h:95
const File & file(const String &name="default") const
The address for reading/writing. If factory supports more than one file (eg: .obj and ....
bool shouldWriteModel(const Model &model) const
Checks to see if a given model is on the list.
FactoryParameters(const FileRequest &request, const String &name="default")
const FileFormat & format(const String &name="default") const
The format to read/write. If factory supports more than one format (eg: .obj and ....
void addWarning(const FileFactoryWarning &warning)
Adds a warning that will be shown to the user when the IOFactory operation is completed.
FactoryParameters(const File &file, const FileFormat &format, const String &name="default")
FileFormat & format(const String &name="default")
The format to read/write. If factory supports more than one format (eg: .obj and ....
FactoryOptions options
Definition IOFactory.h:93
Dictionary< String, FileRequest > requests
Definition IOFactory.h:92
Buffer< FileFactoryWarning > warnings
Definition IOFactory.h:94
Buffer< UUID > cameras
Definition IOFactory.h:96
Allows the software to display a warning to the end user about a problem encountered during an IOFact...
Definition IOFactory.h:51
TranslatedString message
Definition IOFactory.h:55
FileFactoryWarning(const TranslatedString &title, const TranslatedString &message)
FileFactoryWarning(const TranslatedString &title, const File &file, uint04 line_number=Constant< uint04 >::Invalid)
TranslatedString title
Definition IOFactory.h:54
A FileRequest bundles format data as well as a particular file.
Definition FileFormat.h:75