NDEVR
API Documentation
IOFactory.h
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/Scene.h>
38#include <NDEVR/File.h>
39#include <NDEVR/FileFormat.h>
40namespace NDEVR
41{
42 class Model;
43 class Log;
44 class SpatialObject;
46 class FactoryFeatures;
73
96
196
229
248 {
249 public:
250 friend class ModelFactory;
251
256 IOFactory(const StringView& factory_name);
257
262 const String& name() const { return m_factory_name; }
263
267 virtual ~IOFactory();
268
275 bool writeScenesToFile(const File& file, const Buffer<Scene>& scene);
276
284
290
296 virtual void getSupportedFormats(Buffer<FileFormat>& formats, bool is_read) = 0;
297
303 virtual void getSupportedFormats(Buffer<FileFormat>& formats, const File& file);
304
311 virtual void getSupportedFormats(Buffer<FileFormat>& formats, DesignObjectLookup* lookup, const Buffer<UUID>& models);
312
319 virtual void getSupportedFormatsForExtension(Buffer<FileFormat>& formats, bool is_read, const StringView& extension);
320
327 virtual void getSupportedFormatsByModelType(Buffer<FileFormat>& formats, bool is_read, const StringView& model_type);
328
336 virtual Buffer<UUID> filterModelsToExport(Buffer<UUID> models_to_check, const DesignObjectLookup* lookup, const FileFormat& export_format) const;
337
343 virtual bool isFactoryEnabled(bool is_read) const;
344
350 virtual bool canRead(const File& file);
351
358 virtual bool determineExtension(const File& file, String& extension);
359
365 virtual bool canWrite(const File& file);
366
371 virtual bool isAutoEnabled() const;
372
378 virtual String getIcon(const File& file);
379
385 virtual bool canRead(const FactoryParameters& file);
386
392 virtual bool canWrite(const FactoryParameters& file);
393
399 virtual bool canRead(const FileFormat& file);
400
406 virtual bool canWrite(const FileFormat& file);
407
414
421
428
435 virtual bool updateFromFile(const FactoryParameters& file, const FactoryOptions& old_options);
436
443 virtual FactoryFeatures factoryFeatures(const FactoryParameters& file, bool is_import) const = 0;
444
450
456
464 void throwIfNotEnabled(bool is_read);
465
472 static void EnableFactory(IOFactory* factory, const StringView& read_password, const StringView& write_password);
473
480 static void EnableFactory(const StringView& factory, const StringView& read_password, const StringView& write_password);
481
488 static void EnableExtension(const StringView& extension, const StringView& read_password, const StringView& write_password);
489 private:
495 virtual bool readFile(FactoryParameters& file) = 0;
496
502 virtual bool writeFile(FactoryParameters& file) = 0;
503 private:
504 String m_factory_name;
505 };
506}
Provides cross-platform DLL export/import macros for the IOFactory module.
#define NDEVR_FACTORY_API
GCC/Clang symbol visibility — marks symbols as visible in the shared library.
Definition DLLInfo.h:92
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Used with InfoPipe to signal that the process can be cancelled.
A core class where all Design Objects including models, materials, and geometries are stored.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Allows IOFactories to report what features they support to make the import/export dialogs easier to s...
User-defined options that define preferences for importing and exporting using IOFactory objects.
Data that describes a particular file format and how to use the format with the program.
Definition FileFormat.h:45
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
virtual void getSupportedFormats(Buffer< FileFormat > &formats, const File &file)
Populates the given buffer with formats supported for the specified file.
virtual void getSupportedFormats(Buffer< FileFormat > &formats, bool is_read)=0
Populates the given buffer with supported file formats for reading or writing.
void throwIfNotEnabled(bool is_read)
Throws an exception if the factory is not enabled for the given operation direction.
virtual void getSupportedFormatsForExtension(Buffer< FileFormat > &formats, bool is_read, const StringView &extension)
Populates the given buffer with formats matching a specific file extension.
virtual FactoryOptions defaultWriteOptions(const FactoryParameters &file) const
Returns the default write options for the given factory parameters.
virtual bool isAutoEnabled() const
Checks whether this factory is automatically enabled without requiring a password.
Buffer< Scene > readScenesFromFile(const File &file)
Reads scenes from a file and returns them as a buffer of Scene objects.
virtual void getSupportedFormats(Buffer< FileFormat > &formats, DesignObjectLookup *lookup, const Buffer< UUID > &models)
Populates the given buffer with formats supported for writing the specified models.
virtual bool canRead(const File &file)
Checks whether this factory can read the given file.
virtual bool updateFromFile(const FactoryParameters &file, const FactoryOptions &old_options)
Updates the factory parameters from a file, comparing against old options.
static void EnableExtension(const StringView &extension, const StringView &read_password, const StringView &write_password)
Enables a specific file extension with the given read and write passwords.
bool writeScenesToFile(const File &file, const Buffer< Scene > &scene)
Writes a buffer of scenes to a file.
IOFactory(const StringView &factory_name)
Constructs an IOFactory with the given factory name.
virtual bool canWrite(const File &file)
Checks whether this factory can write the given file.
virtual String getIcon(const File &file)
Returns the icon name associated with the given file type.
virtual bool readFile(FactoryParameters &file)=0
Reads data from a file into the design object hierarchy.
virtual ~IOFactory()
Virtual destructor.
virtual void getSupportedFormatsByModelType(Buffer< FileFormat > &formats, bool is_read, const StringView &model_type)
Populates the given buffer with formats matching a specific model type.
static void EnableFactory(const StringView &factory, const StringView &read_password, const StringView &write_password)
Enables a factory by name with the given read and write passwords.
void getSupportedFormats(Buffer< FileFormat > &formats)
Populates the given buffer with all supported file formats (both read and write).
virtual bool determineExtension(const File &file, String &extension)
Attempts to determine the file extension for the given file.
const String & name() const
Returns the name of this factory.
Definition IOFactory.h:262
virtual Buffer< UUID > filterModelsToExport(Buffer< UUID > models_to_check, const DesignObjectLookup *lookup, const FileFormat &export_format) const
Filters a list of model UUIDs to only those that can be exported in the given format.
Buffer< UUID > readFileWithDefaultSettings(const File &file, DesignObjectLookup *lookup)
Reads a file using default settings and returns the UUIDs of the created models.
virtual bool writeFile(FactoryParameters &file)=0
Writes data from the design object hierarchy to a file.
virtual bool canWrite(const FileFormat &file)
Checks whether this factory can write the given file format.
virtual bool isFactoryEnabled(bool is_read) const
Checks whether this factory is enabled for reading or writing.
static void EnableFactory(IOFactory *factory, const StringView &read_password, const StringView &write_password)
Registers an IOFactory instance with the system, enabling it for read and/or write.
virtual bool canRead(const FactoryParameters &file)
Checks whether this factory can read using the given FactoryParameters.
virtual bool canWrite(const FactoryParameters &file)
Checks whether this factory can write using the given FactoryParameters.
String factoryWriteAppFeature() const
Returns the application feature string required for write operations.
virtual FactoryFeatures factoryFeatures(const FactoryParameters &file, bool is_import) const =0
Returns the features and configurable options for this factory given the parameters.
String factoryReadAppFeature() const
Returns the application feature string required for read operations.
virtual FactoryOptions defaultReadOptions(const FactoryParameters &file) const
Returns the default read options for the given factory parameters.
virtual bool canRead(const FileFormat &file)
Checks whether this factory can read the given file format.
A light-weight base class for Log that allows processes to update, without the need for additional in...
Serves as the primary program interface for processes to report issues and allows any number of LogSt...
Definition Log.h:50
A core class that represents a node on model hierarchy.
Definition Model.h:292
Used with InfoPipe to signal that the system will be using progress.
Base interface for services that extend or modify software behavior through modules.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Manages temporary file paths during an IOFactory write operation, ensuring safe writes by writing to ...
Definition IOFactory.h:207
TemporaryIOFileLocker(FactoryParameters &params)
Constructs the locker, replacing file paths in params with temporary paths.
Buffer< std::pair< File, File > > writeToActual()
Moves all temporary files to their actual (final) destinations.
FactoryParameters & m_params
Reference to the FactoryParameters being managed.
Definition IOFactory.h:227
Dictionary< String, FileRequest > m_original_requests
The original file requests before temporary path substitution.
Definition IOFactory.h:226
~TemporaryIOFileLocker()
Destructor.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
A container of input information that is to be filled with output information by an IOFactory.
Definition IOFactory.h:105
const FileFormat & format(const StringView &name="default") const
The format to read/write.
Buffer< FileFactoryWarning > warnings
Any warnings to show to the user after the operation.
Definition IOFactory.h:186
FactoryOptions options
All read/write options including special parameters.
Definition IOFactory.h:185
CancelInfo cancel
Provides cancellation support for the operation.
Definition IOFactory.h:194
void setInfoPipe(InfoPipe *pipe)
Sets the info pipe for streaming log messages or cancelling the operation.
Buffer< UUID > cameras
UUIDs of cameras created or targeted by the operation.
Definition IOFactory.h:189
FactoryParameters & operator=(const FactoryParameters &params)
Copy assignment operator.
bool shouldWriteModel(const Model &model) const
Checks whether a given model is in the list of models to be written.
ProgressInfo progress
Tracks progress of the read/write operation.
Definition IOFactory.h:191
Buffer< DynamicPointer< FindFileFunction > > missing_files
Files that could not be found and require user input.
Definition IOFactory.h:187
void addWarning(const FileFactoryWarning &warning)
Adds a warning that will be shown to the user when the IOFactory operation is completed.
FactoryParameters(const FactoryParameters &params)
Copy constructor.
Buffer< UUID > models
UUIDs of models created or targeted by the operation.
Definition IOFactory.h:188
TranslatedString custom_message
An optional custom message to display during the operation.
Definition IOFactory.h:192
FactoryParameters(const FileRequest &request, const StringView &name="default")
Constructs FactoryParameters from a FileRequest and optional name.
void addMissingFile(const DynamicPointer< FindFileFunction > &file)
Registers a missing file that the user needs to locate before the operation can complete.
String custom_message_icon
An optional icon name for the custom message.
Definition IOFactory.h:193
Dictionary< String, FileRequest > requests
Maps name keys to FileRequest objects for multi-file formats.
Definition IOFactory.h:184
const File & file(const StringView &name="default") const
The address for reading/writing.
FileFormat & format(const StringView &name="default")
The format to read/write.
std::function< bool(UUID library_id, Model &model)> assign_to_library
Callback to assign a model to a specific library by UUID.
Definition IOFactory.h:183
FactoryParameters(const File &file, const FileFormat &format, const StringView &name="default")
Constructs FactoryParameters from a file, format, and optional name.
DesignObjectLookup * lookup
The design object lookup used to resolve models and objects.
Definition IOFactory.h:190
Allows the software to display a warning to the end user about a problem encountered during an IOFact...
Definition IOFactory.h:53
FileFactoryWarning(const TranslatedString &title, const TranslatedString &message)
Constructs a warning with a title and descriptive message.
FileFactoryWarning(const TranslatedString &title, const File &file, uint04 line_number=Constant< uint04 >::Invalid)
Constructs a warning referencing a specific file and optional line number.
TranslatedString message
The descriptive message body of the warning.
Definition IOFactory.h:71
TranslatedString title
The title or heading of the warning.
Definition IOFactory.h:70
A FileRequest bundles format data as well as a particular file.
Definition FileFormat.h:101
TranslatedString message
The descriptive message explaining which file is needed.
Definition IOFactory.h:91
File default_file
The default file path suggestion for the user.
Definition IOFactory.h:92
TranslatedString title
The title shown to the user when requesting the file.
Definition IOFactory.h:90
Buffer< FileFormat > formats
The acceptable file formats for the missing file.
Definition IOFactory.h:93
FindFileFunction(const TranslatedString &title, const TranslatedString &message, const std::function< void(const File &f)> &file)
Constructs a FindFileFunction with a title, message, and callback for when the file is found.
std::function< void(const File &f)> callback
The callback invoked when the user provides the file.
Definition IOFactory.h:94