///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
// All rights reserved.
//
// This software and its documentation and related materials are owned by
// the Alliance. The software may only be incorporated into application
// programs owned by members of the Alliance, subject to a signed
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable
// trade secrets of the Alliance and its suppliers. The software is also
// protected by copyright law and international treaty provisions. Application
// programs incorporating this software must include the following statement
// with their copyright notices:
//
// This application incorporates Open Design Alliance software pursuant to a license
// agreement with Open Design Alliance.
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
// All rights reserved.
//
// By use of this software, its documentation or related materials, you
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
#ifndef _DAI_REPOSITORY_H
#define _DAI_REPOSITORY_H
#include "daiDictionaryInstance.h"
#include "daiSessionInstance.h"
#include "daiAnchor.h"
#include "daiReference.h"
#include "daiSignature.h"
#include "sdai.h"
#include "OdStreamBuf.h"
#include "OdArray.h"
#include "SmartPtr.h"
#include "TD_PackPush.h"
#define REPOSITORY_DEFAULT_MODEL_NAME "default"
class OdDAIHostAppServicesBase;
/** \details
Implements the Data Access Interface (DAI) that provides functionality for manipulating data that is defined within the EXPRESS SCHEMA format.
*/
namespace OdDAI {
class Session;
class OdHeaderSection;
/** \details
A data type that represents a smart pointer to a object.
*/
typedef OdSmartPtr OdHeaderSectionPtr;
class Model;
/** \details
A data type that represents a smart pointer to a object.
*/
typedef OdSmartPtr ModelPtr;
class Schema;
/** \details
A data type that represents a smart pointer to a object.
*/
typedef OdSmartPtr SchemaPtr;
class SchemaInstance;
/** \details
A data type that represents a smart pointer to a object.
*/
typedef OdSmartPtr SchemaInstancePtr;
/** \details
A class that provides functionality for working with archive folder.
*/
class DiskFolder;
/** \details
A data type that represents a smart pointer to an object.
*/
typedef OdSmartPtr DiskFolderPtr;
/** \details
A class that implements functionality for working with a repository within the Data Access Interface.
A repository is a collection of models, which represents the physical organization of a database.
*/
class DAI_EXPORT Repository : public SessionInstance
{
/** \details
Creates a new repository within a specified session.
\param session [in] A raw pointer to a object.
\returns A smart pointer to the created repository object.
*/
static OdSmartPtr createObject(Session *session);
public:
//DOM-IGNORE-BEGIN
ODRX_DECLARE_MEMBERS(Repository);
//DOM-IGNORE-END
/** \details
Creates a new repository object with default parameters.
*/
Repository();
/**
Retrieves the current name of repository.
\returns
A string that contains the name.
*/
const OdString& name() const
{
return m_name;
}
/** \details
Assigns a name to the repository.
\param name [in] A string that contains the name.
*/
void name(const OdString &name);
/** \details
Retrieves the array of the repository consists of.
\returns An array of pointer to the repository consists of.
*/
const OdArray& models() const { return m_models; };
/** \details
Creates a new with specified name and schema in the repository.
\param name [in] An ANSI string that contains the name of the to be created.
\param schemaName [in] An ANSI string that contains the schema name for the to be created.
\returns A smart pointer to the created .
*/
ModelPtr createModel(const OdAnsiString &name, const OdAnsiString &schemaName);
/** \details
Creates a new with specified name and schema in the repository.
\param name [in] An ANSI string that contains the name of the to be created.
\param schema [in] A smart pointer to the object for the to be created.
\returns A smart pointer to the created .
*/
ModelPtr createModel(const OdAnsiString &name, const SchemaPtr schema);
/** \details
Opens a specified in the read-only mode.
\param modelPtr [in] A smart pointer to the to open.
\returns A smart pointer to the object that represents the opened model data.
*/
const ModelPtr getModel(ModelPtr& modelPtr) const;
/** \details
Opens a specified in the read-write mode.
\param modelPtr [in] A smart pointer to the to open.
\returns A smart pointer to the object that represents the opened model data.
*/
ModelPtr getModelRW(ModelPtr& modelPtr);
/** \details
Opens a specified in the read-only mode.
\param modelName [in] An ANSI string that contains the name of the to open.
\returns A smart pointer to the object that represents the opened model data.
*/
const ModelPtr getModel(const OdAnsiString &modelName = REPOSITORY_DEFAULT_MODEL_NAME) const;
/** \details
Opens a specified in the read-write mode.
\param modelName [in] An ANSI string that contains the name of the to open.
\returns ModelPtr in read/write mode
*/
ModelPtr getModelRW(const OdAnsiString &modelName = REPOSITORY_DEFAULT_MODEL_NAME);
/* \details
Removes a from the repository.
\param model [in] A smart pointer to the to remove from the repository.
*/
void deleteModel(ModelPtr& model);
/** \details
Retrieves the of a specified .
\param modelName [in] An ANSI string that contains the name
\returns A value of the data type that represents the access mode.
*/
SdaiAccessMode getModelAccessMode(const OdAnsiString &modelName = REPOSITORY_DEFAULT_MODEL_NAME) const;
/** \details
Creates a new with specified name and schema in the repository.
\param name [in] An ANSI string that contains the name of the to be created.
\param schemaName [in] An ANSI string that contains the schema name for the to be created.
\returns A smart pointer to the created .
*/
SchemaInstancePtr createSchemaInstance(const OdAnsiString& name, const OdAnsiString& schemaName);
/** \details
Creates a new with specified name and schema in the repository.
\param name [in] An ANSI string that contains the name of the to be created.
\param schema [in] A smart pointer to the object for the to be created.
\returns A smart pointer to the created .
*/
SchemaInstancePtr createSchemaInstance(const OdAnsiString& name, const SchemaPtr schema);
/* \details
Removes a from the repository.
\param schemaInstance [in] A smart pointer to the to remove from the repository.
*/
void deleteSchemaInstance(SchemaInstancePtr& schemaInstance);
/* \details
Initializes the repository.
\returns eOk if the repository has been initialized successfully; otherwise, the method returns an appropriate error code.
*/
OdResult initialize();
/** \details
Retrieves associated with the repository.
\returns An array of smart pointers to objects associated with the repository object.
*/
OdArray schemas() { return m_schemas; };
/** \details
Retrieves associated with the repository.
\returns An array of smart pointers to objects associated with the repository object.
*/
const OdArray& schemaInstances() const { return m_schemaInstances; };
/** \details
Retrieves the file object's .
\returns A smart pointer to the object that represents the file object's header section.
*/
OdHeaderSectionPtr getHeaderSection();
/** \details
Retrieves the anchor section from the repository object.
\returns A reference to the AnchorSection object.
*/
AnchorSection& getAnchorSection();
/** \details
Retrieves the from the repository object.
\returns A reference to the object.
*/
ReferenceSection& getReferenceSection();
/** \details
Retrieves read from file associated with the repository.
\returns An array of objects read from file.
*/
OdArray& getReadSignatureSection() { return m_readSignatureSection; };
/** \details
Retrieves read from file associated with the repository.
\returns A const array of objects read from file.
*/
const OdArray& getReadSignatureSection() const { return m_readSignatureSection; };
/** \details
Retrieves to be written to file associated with the repository.
\returns An array of objects to be written to file.
*/
OdArray& getWriteSignatureSection() { return m_writeSignatureSection; };
/** \details
Retrieves to be written to file associated with the repository.
\returns A const array of objects to be written to file.
*/
const OdArray& getWriteSignatureSection() const { return m_writeSignatureSection; };
/** \details
Sets to be written to file for the repository.
\param signatureSection [in] An array of objects to be written to file.
*/
void setWriteSignatureSection(const OdArray& signatureSection) { m_writeSignatureSection = signatureSection; };
/** \details
Creates the repository from a specified STEP Physical File (*.spf).
\param fileName [in] A string that contains the file name.
\returns eOk if the data content is successfully read; otherwise, the method returns an appropriate error code.
*/
OdResult readFile(const OdString& fileName);
/** \details
Creates the repository from a STEP Physical File (*.spf) with specified schema.
\param fileName [in] A string that contains the file name.
\param schemaName [in] valid schema name
\returns eOk if the data content is successfully read; otherwise, the method returns an appropriate error code.
\remarks
The successful result of force reading with not native schema for a file isn't guaranteed as different schemas may be not compatible with each other.
*/
OdResult readFile(const OdString& fileName, const OdAnsiString& schemaName);
/** \details
Creates the repository from a STEP Physical File (*.spf) with specified schema.
\param fileName [in] A string that contains the file name.
\param schema [in] valid smart pointer to schema definition
\returns eOk if the data content is successfully read; otherwise, the method returns an appropriate error code.
\remarks
The successful result of force reading with not native schema for a file isn't guaranteed as different schemas may be not compatible with each other.
*/
OdResult readFile(const OdString& fileName, const SchemaPtr schema);
/** \details
Creates the repository from a memory buffer that contains STEP Physical File (*.spf) data.
\param spfBuf [in] A char array that contains buffered data of the model in the STEP Physical File representation.
\returns eOk if the data is successfully read; otherwise, the method returns an appropriate error.
*/
OdResult readBuffer(const char* spfBuf);
/** \details
Reads data from a specified stream buffer.
\param pStream [in] A smart pointer to the stream buffer object to read data from.
\returns eOk if the data is successfully read; otherwise, the method returns an appropriate error.
*/
OdResult readStream(OdStreamBufPtr pStream);
/** \details
Reads data from a specified stream buffer.
\param pStream [in] A smart pointer to the stream buffer object to read data from.
\param schemaName [in] Schema name.
\returns eOk if the data is successfully read; otherwise, the method returns an appropriate error.
*/
OdResult readStream(OdStreamBufPtr pStream, const OdAnsiString& schemaName);
/** \details
Reads data from a specified stream buffer.
\param pStream [in] A smart pointer to the stream buffer object to read data from.
\param schema [in] Smart pointer to a schema.
\returns eOk if the data is successfully read; otherwise, the method returns an appropriate error.
*/
OdResult readStream(OdStreamBufPtr pStream, const SchemaPtr schema);
/** \details
Reads the data of a specified IFC file.
\param fileName [in] A string that contains the IFC file name.
\returns A smart pointer to an instance of the class that contains read data.
\remarks
This method is used to extract information about the IFC file without reading all of its content.
*/
static OdHeaderSectionPtr readHeaderSection(const OdString& fileName);
/** \details
Reads the < data from a specified stream buffer associated with a STEP Physical File (*.spf).
\param pStream [in] A raw pointer to a file stream buffer to read data from.
\returns A smart pointer to an instance of the class that contains read data.
\remarks
This method is used to extract information about the STEP Physical File (*.spf) without reading all of its content.
*/
static OdHeaderSectionPtr readHeaderSection(OdStreamBufPtr pStream);
/** \details
Writes data from the repository object to a physical file.
\param filename [in] A string that contains the full path to the output file to write data.
\param saveLogFile [in] A flag that determines whether the log file should also be written (if equal to true) or not (if equal to false).
\returns eOk if the data is successfully written; otherwise, the method returns an appropriate error.
*/
virtual OdResult writeFile(const OdString& filename, bool saveLogFile = false);
/** \details
Writes data from the specified stream buffer to a physical file.
\param pStream [in] A smart pointer to the output stream buffer object to wtite data.
\param saveLogFile [in] A flag that determines whether the log file should also be written (if equal to true) or not (if equal to false).
\returns eOk if the data is successfully written; otherwise, the method returns an appropriate error code.
\remarks
This method does not support writing to Zip format.
*/
virtual OdResult writeStream(OdStreamBufPtr pStream, bool saveLogFile = false);
/** \details
Retrieves the the repository is created within.
\returns A raw pointer to the object the repository is created within.
*/
OdDAI::Session* session() const { return m_session; };
/** \details
Checks whether a with a specified name exists in the repository.
\param modelName [in] An ANSI string that contains the name.
\returns true if the exists in repository, otherwise returns false.
*/
bool hasModel(const OdAnsiString &modelName);
//DOM-IGNORE-BEGIN
/** \details
Sets a new application services object.
\param svcs [in] A raw pointer to the object to be assigned with the repository.
*/
void attachTo(OdDAIHostAppServicesBase* svcs, OdRxObject *owner)
{
m_svcs = svcs;
m_owner = owner;
}
void detach()
{
// TODO: Clean resolved model?
m_svcs = nullptr;
m_owner = nullptr;
}
OdRxObjectPtr attachedTo()
{
return m_owner;
}
OdDAIHostAppServicesBase* appServices()
{
return m_svcs;
}
/** \details
Sets a new disk folder object.
\param pDiskFolder [in] A raw pointer to the object to be assigned with the repository.
*/
void attachDiskFolder(DiskFolderPtr& pDiskFolder);
/** \details
Retrieves the of the repository.
\returns A smart pointer to the object of the repository.
*/
const DiskFolderPtr diskFolder() const;
//DOM-IGNORE-END
protected:
class InternalUtils;
bool setModelAccessMode(ModelPtr& modelToSet, SdaiAccessMode accessMode) const;
void synchronizeSchemas();
OdResult writeStreamBase(OdStreamBufPtr pStream, bool saveLogFile = false);
void onClose();
protected:
OdString m_name;
OdHeaderSectionPtr m_pHeaderSection;
AnchorSection m_anchorSection;
ReferenceSection m_referenceSection;
OdArray m_readSignatureSection;
OdArray m_writeSignatureSection;
OdArray m_models;
OdArray m_schemas;
OdArray m_schemaInstances;
OdDAIHostAppServicesBase *m_svcs;
OdRxObject *m_owner;
DiskFolderPtr m_pDiskFolder;
Session *m_session;
friend class Session;
private:
class ModelModeRestorer;
};
/** \details
A data type that represents a smart pointer to a object.
*/
typedef OdSmartPtr RepositoryPtr;
}
#include "TD_PackPop.h"
#endif // _DAI_REPOSITORY_H