///////////////////////////////////////////////////////////////////////////////
// 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 _IFC_FILE_H
#define _IFC_FILE_H
#include "OdPlatformSettings.h"
#define STL_USING_MAP
#include "OdaSTL.h"
#include "daiStepFile.h"
#include "daiCompressedGUID.h"
#include "IfcCore.h"
#include "IfcModel.h"
#include "IfcEntity.h"
#include "IfcModelContext.h"
#include "IfcUnitConverter.h"
#include "IfcGeomModule.h"
#include "TD_PackPush.h"
class OdIfcHostAppServices;
class OdIfcEntResolver;
class OdIfcDatabaseReactor;
/** \details
A class that implements working with an IFC file header and data sections (header and model),
takes responsibility for the geometry creation and visualization, higher-level features like the access to unit conversions and mapping IfcGuid - OdDAIObjectId.
*/
class IFCCORE_EXPORT OdIfcFile : public OdStepFile
{
public:
//DOM-IGNORE-BEGIN
ODRX_DECLARE_MEMBERS(OdIfcFile);
//DOM-IGNORE-END
/** \details
Creates a new IFC file object with default parameters.
*/
OdIfcFile();
/** \details
Destroys the IFC file object.
*/
~OdIfcFile();
/** \details
Retrieves the application services object that is associated with the IFC file object.
\returns Returns a raw pointer to the OdIfcHostAppServices object associated with the file object.
*/
OdIfcHostAppServices* getAppServices() const;
/** \details
Sets a new application services object with the IFC file object.
\param svcs [in] A raw pointer to the OdIfcHostAppServices object to be assigned with the file.
*/
void setAppServices(OdIfcHostAppServices* svcs);
/** \details
Initializes the IFC file object with a specified schema.
\param schema [in] A schema identifier.
\returns eOk if the file was successfully initialized; otherwise, the method returns an appropriate error code.
\remarks
If the schema parameter equals the kScmUndefined value, the IFC file object will be created without an underlying OdDAI::Model object.
*/
OdResult initialize(IfcSchema schema);
/** \details
Retrieves the IFC model's root entity.
\returns The identifier of the root entity of the model.
\remarks
Each valid IFC file must have exactly one root entity.
*/
OdDAIObjectId getProjectId() const;
/** \details
Returns all found IfcProject instances object identifiers within a model.
\returns An OdArray of identifiers of the root instances of the model.
\remarks
Each valid IFC model must have exactly one root instance.
*/
const OdDAIObjectIds getRootIds() override;
/** \details
Returns all found IfcSpace instances object identifiers within a model.
\returns An OdArray of identifiers of the IfcSpace instances of the model.
\remarks
Collection could be empty.
*/
const OdDAIObjectIds getSpaces();
/** \details
Retrieves entity database id by IFC GUID.
\param ifcGUID [in] An IFC GUID identifier of entity.
\returns An identifier of the entity.
*/
OdDAIObjectId getEntityId(const OdDAI::CompressedGUID&ifcGUID) const;
/** \details
Performs an attempt to find an instance with the specified GlobalId attribute value.
\param guid [in] An guid identifier of an object to find.
\returns An identifier of the entity or the kNullHandle value otherwise.
*/
const OdDAIObjectId getEntityByGUID(const OdAnsiString& guid) const;
/** \details
Retrieves the current model context of the file object.
\returns An instance of the OdIfcModelContext class.
*/
OdIfcModelContext& getContext();
/** \details
Sets a new model context for the IFC file object.
\param context [in] An instance of the OdIfcModelContext class to be set as the model context object.
*/
void setContext(const OdIfcModelContext& context);
/** \details
Sets a new active view for the IFC file's content.
\param pActiveView [in] A raw pointer to the OdGsView object.
*/
void setActiveView(OdGsView *pActiveView);
/** \details
Retrieves the current active view of the IFC file object.
\returns Returns a raw pointer to the OdGsView object that represents the currently active view.
*/
OdGsView *getActiveView() const;
/** \details
Composes geometry of entities in the IFC model using the assigned resolver object.
\returns eOk if geometry of entities was composed successfully; otherwise, the method returns an appropriate error code.
*/
OdResult composeEntities();
/** \details
Composes geometry of entities subset in the IFC model using the assigned resolver object.
\param entitiesToCompose [in] A set of identifiers of SDAI objects, which represent the entities selection.
\returns eOk if geometry of entities was composed successfully; otherwise, the method returns an appropriate error code.
*/
OdResult composeEntitiesbyIds(const OdDAIObjectIds &entitiesToCompose);
/** \details
Unresolve entities in the IFC model.
\returns eOk if the unresolve was successful; otherwise, the method returns an appropriate error code.
*/
OdResult unresolveEntities();
/** \details
Sets geometrical context selection to build a geometrical representation for selected geometrical contexts.
Only selected contexts will be composed and drawn.
\param contexts [in] A set of identifiers of SDAI objects, which represent the context selection.
\returns eOk if the new context selection was successfully set; otherwise, the method returns an appropriate error code.
*/
OdResult setContextSelection(const OdDAIObjectIds &contexts);
/** \details
Determines whether an instance of the IfcGeometricRepresentationContext class is selected to build the geometry.
\param idCtx [in] Object ID of geometric context to test.
\returns true if an IfcGeometricRepresentationContext object is selected; otherwise, the method returns false.
*/
bool getContextSelected(const OdDAIObjectId &idCtx) const;
/** \details
Determines whether an instance of the IfcGeometricRepresentationContext with contextIdentifier provided is selected to build the geometry.
\param contextIdentifier [in] String which contains Context Identifier of geometric context to test.
\returns true if an IfcGeometricRepresentationContext object is selected; otherwise, the method returns false.
*/
bool getContextSelected(const char* contextIdentifier) const;
/** \details
Finds an IfcGeometricRepresentationContext instance with contextIdentifier provided.
\param contextIdentifier [in] String which contains Context Identifier of geometric context to find.
\returns an Object Identifier of the found context instance, if found; otherwise the method returns null OdDAIObjectId.
*/
OdDAIObjectId findRepresentationContext(const char* contextIdentifier) const;
/** \details
Retrieves the current geometrical extents of the model.
\param extents [out] A placeholder for the current geometry extents object to be returned to a calling subroutine.
\returns eOk if the current extents were successfully returned; otherwise, the method returns an appropriate error code.
\remarks
The method returns the model extents only if the model was created by calling the setGeomResource() method.
The method accepts an instance of the OdGeExtents3d class, fills it with the data about the model's extents and
returns it to a calling subroutine.
*/
OdResult getGeomExtents(OdGeExtents3d& extents) const;
/** \details
Retrieves the current model's unit converter.
\returns An instance of the OdIfcUnitConverter class that represents the current model's unit converter.
*/
OdDAI::OdUnitConverterPtr getUnitConverter();
/** \details
Performs an attempt the compose object for an entity instance, if application instance doesn't have associated compound object.
If application instance already has associated compound, it will be returned by this method.
\param id [in] An identifier of an object to compose.
\returns A smart pointer to the attached compound object.
*/
virtual OdDAI::OdCompoundPtr getCompound(const OdDAIObjectId& id) override;
/** \details
Performs an attempt to compose an instance using the specified resolver object.
\param id [in] An identifier of an object to compose.
\returns A smart pointer to the entity with the attached compound object.
*/
OdIfc::OdIfcInstancePtr get(const OdDAIObjectId &id) const;
/** \details
Performs an attempt to compose entities using the specified resolver object.
\param ids [in] An array of identifiers of objects to compose.
\returns eOk if the compose operation was successful; otherwise the method returns an appropriate error code.
*/
OdResult get(const OdDAIObjectIds &ids) const;
//DOM-IGNORE-BEGIN
typedef OdArray > Reactors;
/** \details
Updates state of newly added to the model IfcProduct and allows reactor mechanism send appropiate notifications.
\param pProduct [in] Pointer to the instance that has been appended to the file content.
\returns true if the operation was successful; otherwise the method returns false.
\remarks
It is recommended registered product to be completely created within IFC Model, including geometric representation and other relationships, before registering.
*/
bool registerProduct(OdDAI::ApplicationInstance* pProduct);
/** \details
Updates state of modified IfcProduct with unresolve/resolve attempt and allows reactor mechanism send appropiate notifications.
\param pProduct [in] Pointer to the instance that has been modified (including geometric representation and others).
\returns true if the operation was successful; otherwise the method returns false.
*/
bool updateProduct(OdDAI::ApplicationInstance * pProduct);
/** \details
Function adds reactor instanse to the OdIfcFile.
\param pReactor [in] Pointer to the notification class.
*/
void addReactor(OdIfcDatabaseReactor* pReactor);
/** \details
Performs notifications whenever an OdIfcCompound inner entity has been erased in the current OdIfcFile.
\param pProduct [in] Pointer to the object being erased.
*/
void fireObjectErased(OdIfc::OdIfcCompound* pProduct, bool pErased);
/** \details
Performs notifications whenever an OdIfcCompound inner entity has been appended to an OdIfcFile.
\param pProduct [in] Pointer to the object being appended.
*/
void fireObjectAppended(OdIfc::OdIfcCompound* pProduct);
/** \details
Performs notifications whenever an OdIfcCompound inner entity has been modified in the current OdIfcFile.
\param pProduct [in] Pointer to the object being modified.
*/
void fireObjectModified(OdIfc::OdIfcCompound* pProduct);
/** \details
Sets a new Gs node cache for the drawable.
\param pGsNode [in] A raw pointer to an OdGsCache object.
*/
virtual void setGsNode(OdGsCache* pGsNode)
{
m_gsNode = pGsNode;
};
/** \details
Retrieves the current Gs node object of the entity.
\returns Returns a raw pointer to the OdGsCache object associated with the entity.
*/
virtual OdGsCache* gsNode() const
{
return m_gsNode;
};
/** \details
Sets convertible unit from current class.
\returns eOk if initialization operation was successful; otherwise the method returns an appropriate error code.
*/
OdResult initializeUnitConverter();
/** \details
Retrieves all found IfcPresentationLayerAssignment and its subclasses instances object identifiers within a model.
\returns An OdArray of identifiers of the layers instances of the model.
*/
const OdDAIObjectIds getPresentationLayers();
using OdStepFile::initialize;
/** \details
Removes associated compounds from full shape representation subtree of IfcProduct.
\param product [in] An object identifier of the entity (the STEP ID is stored in the OdDbHandle).
\returns eOk if method executes successfully.
*/
OdResult unresolveProduct(const OdDAIObjectId& product);
protected:
/** \details
Method is called just after file reading has ended, it initializes units converter for loaded model.
\returns eOk if operation successfully done; otherwise, the method returns an appropriate error code.
*/
virtual OdResult onReadFileEnd() override;
/** \details
Checks if schema with identifier provided is supported by OdIfcFile.
\param schemaIdentifier [in] A string that contains the schema identifier.
\returns true if schema is supported by OdIfcFile instance; otherwise returns false.
\remarks Schema identifier may be empty, or must contain IFC letters.
*/
virtual OdResult checkSchema(const OdAnsiString &schemaIdentifier) const override;
private:
virtual const char* defaultRepoName() override;
OdResult setGeomResource();
/** \details
Updates collection of IFC GUID entitiy identifiers.
\returns Returns eOk if the update was successfull; otherwise, the method returns an appropriate error code.
*/
OdResult collectEntityIds() const;
OdGsCache *m_gsNode = nullptr;
OdGsView *m_ActiveView = nullptr;
OdDAIObjectIds m_selContexts;
OdDAI::OdUnitConverterPtr m_pConverter;
OdIfc::OdIfcGeomModulePtr m_pGeom;
OdIfcEntResolver *m_pEntResolver = nullptr;
mutable OdDAIObjectId m_ifcProjectId;
mutable std::map m_ifcEntities;
Reactors m_Reactors;
bool m_bSuppressNotifications = false;
//DOM-IGNORE-END
};
/** \details
A data type that represents a smart pointer to an OdIfcFile object.
*/
typedef OdSmartPtr OdIfcFilePtr;
namespace OdIfc {
class OdIfcCompound;
}
/** \details
An abstract class that provides an interface for the model's entity resolving functionality.
An entity resolver resolves the underlying application instance data into the corresponding compound object (in most cases) that can later be used and vectorized
or into other objects such as points, matrices, vectors, etc.
\sa
IFC Object Model
*/
class IFCCORE_EXPORT OdIfcEntResolver
{
//DOM-IGNORE-BEGIN
protected:
OdIfcFile *m_pFile;
OdArray m_composeTypes;
void assignEntity(OdIfc::OdIfcCompound* compound, OdIfc::OdIfcInstance *inst);
//DOM-IGNORE-END
public:
/** \details
Creates a new entity resolver with default parameters.
*/
OdIfcEntResolver()
: m_pFile(nullptr)
{}
/** \details
Destroys the entity resolver object.
*/
virtual ~OdIfcEntResolver() {};
/** \details
Sets a new model for the entity resolver object.
\param file [in] A raw pointer to the model content object to be set.
*/
void setFile(OdIfcFile *file) { m_pFile = file; };
/** \details
Sets a set of IfcProduct-base entity types for the processing within a resolver. All other
type branches are resolved by default.
\param composeTypes [in] An array of OdIfcEntityType values that contains entity types for the processing.
\remarks
Empty array allows composing of all entities based on the IfcProduct class.
*/
void setComposeTypes(const OdArray &composeTypes) { m_composeTypes = composeTypes; };
/** \details
Resolves the model's entity.
\param inst [in] A raw pointer to the entity instance to be resolved.
\returns true if the entity was successfully resolved; otherwise, the method returns false.
*/
virtual bool resolve(OdIfc::OdIfcInstance* inst) = 0;
};
#include "TD_PackPop.h"
#endif // _IFC_CORE_H