///////////////////////////////////////////////////////////////////////////////
// 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_INSTANCE_H_
#define _IFC_INSTANCE_H_
#include "IfcCommon.h"
#include "IfcBuildOptions.h"
#include "IfcEntityTypes.h"
#include "IfcAttributesEnum.h"
#include "daiApplicationInstance.h"
#include "daiEntity.h"
#include "Ge/GePoint2d.h"
#include "Ge/GePoint3d.h"
#include "Ge/GeVector2d.h"
#include "Ge/GeVector3d.h"
#include "Ge/GeMatrix2d.h"
#include "Ge/GeMatrix3d.h"
#include "CmColorBase.h"
#include "TD_PackPush.h"
/** \details
Contains declarations related to working with IFC files content.
*/
namespace OdIfc {
/** \details
Types of results of IFC file operations.
*/
enum IfcOpResult
{
/**Unresolved operation.*/
kUnresolved = 0,
/**No appropriate compound object exists for the IFC entity instance.*/
kResVisited = 1,
/**The instance is composed as an OdGePoint2d object.*/
kResPoint2d,
/**The instance is composed as an OdGePoint3d object.*/
kResPoint3d,
/**The instance is composed as an OdGeVector2d object.*/
kResVector2d,
/**The instance is composed as an OdGeVector3d object.*/
kResVector3d,
/**The instance is composed as an OdGeMatrix2d object.*/
kResMatrix2d,
/**The instance is composed as an OdGeMatrix3d object.*/
kResMatrix3d,
/**The instance is composed as an RGB color value.*/
kRgbColor,
/**The instance has an attached compound object.*/
kResCompound,
/**An error occurred during the compose operation.*/
kResError
};
class OdIfcCompound;
/** \details
A data type that represents a smart pointer to an OdIfcCompound object.
*/
typedef OdSmartPtr OdIfcCompoundPtr;
/** \details
A class that represents an entity instance of an IFC file and provides IFC-specific functionality.
*/
class IFCCORE_EXPORT OdIfcInstance : public OdDAI::ApplicationInstance
{
public:
//DOM-IGNORE-BEGIN
ODRX_DECLARE_MEMBERS(OdIfcInstance);
//DOM-IGNORE-END
/** \details
Creates a new IFC instance object with default parameters.
*/
OdIfcInstance();
/** \details
Destroys the instance object.
\remarks
All attached compound objects are deleted as well.
*/
~OdIfcInstance();
/** \details
Retrieves whether the instance belongs to a specified entity type.
\param entityType [in] An entity type.
\returns true if the entity belongs to the specified type; otherwise, the method returns false.
*/
virtual bool isKindOf(OdIfcEntityType entityType) const;
/** \details
Retrieves whether the instance is an instance of a specified type.
\param entityType [in] An instance of the OdIfcEntityType enumeration that represents the entity type.
\returns true if the instance is an instance of the specified type; otherwise, the method returns false.
*/
bool isInstanceOf(OdIfcEntityType entityType) const;
/** \details
Retrieves the current type of the instance.
\returns A value of the OdIfcEntityType enumeration that represents the current instance's type.
*/
virtual OdIfcEntityType type() const;
/** \details
Retrieves the current value of an attribute specified by its name.
\param attrName [in] An ANSI string that contains the attribute name.
\returns The current value of the attribute.
\remarks
The method provides late binding access to the attribute value by its name.
Attributes of select and aggregate data types are also supported.
*/
using OdDAI::ApplicationInstance::getAttr;
/** \details
Retrieves the current value of an attribute specified by its definition.
\param attrDef [in] A value of the OdIfcAttribute enumeration that represents the attribute definition.
\returns The current value of the attribute.
\remarks
The method provides late binding access to the attribute value by its name.
Attributes of select and aggregate data types are also supported.
*/
virtual OdRxValue getAttr(const OdIfcAttribute attrDef) const;
/** \details
Retrieves whether the attribute value is set or is unset.
\returns true if the attribute has a value; otherwise, the method returns false (the attribute value is not set).
*/
using OdDAI::ApplicationInstance::testAttr;
/** \details
Retrieves whether the attribute value is set or is unset.
\param explicitAttrName [in] An ANSI string that contains the attribute name.
\returns true if the attribute has a value; otherwise, the method returns false (the attribute value is not set).
*/
bool testAttr(const char * explicitAttrName) const override;
/** \details
Retrieves whether the attribute value is set or is unset.
\param explicitAttrDef [in] An OdIfcAttribute enumeration that represents the attribute definition.
\returns true if the attribute has a value; otherwise, the method returns false (the attribute value is not set).
*/
virtual bool testAttr(const OdIfcAttribute explicitAttrDef) const;
/** \details
Clears the attribute value.
\param explicitAttrName [in] An ANSI string that contains the attribute name.
*/
void unsetAttr(const char * explicitAttrName) override;
/** \details
Clears the attribute value.
\param explicitAttrDef [in] An OdIfcAttribute enumeration that represents the attribute definition.
*/
virtual void unsetAttr(const OdIfcAttribute explicitAttrDef);
using OdDAI::ApplicationInstance::putAttr;
/** \details
Sets a new value of an attribute that is specified by its name.
\param explicitAttrName [in] An ANSI string that contains the attribute name.
\param val [in] A new attribute value to be set.
\returns true if the attribute value was successfully set; otherwise, the method returns false.
*/
bool putAttr(const char * explicitAttrName, const OdRxValue &val) override;
/** \details
Sets a new value of a specified attribute.
\param explicitAttrDef [in] An OdIfcAttribute enumeration that represents the attribute definition.
\param val [in] A new attribute value to be set.
\returns true if the attribute value was successfully set; otherwise, the method returns false.
*/
virtual bool putAttr(const OdIfcAttribute explicitAttrDef, const OdRxValue &val);
/** \details
Retrieves whether the instance is resolved into a compound object, into a Ge compound object, or is unresolved/visited.
\returns A value of the IfcOpResult enumeration that contains the result of the instance resolution.
*/
IfcOpResult resolved() { return m_resolved; };
/** \details
Resolves the instance and returns the result of the instance composition to a calling subroutine.
\param resolved [in] A resolution operation result.
\param resPtr [out] A raw pointer that references the instance composition result value.
*/
void resolve(IfcOpResult resolved, void *resPtr)
{
ODA_ASSERT_ONCE(
((resolved == kUnresolved || resolved == kResVisited) && !resPtr)
|| resPtr);
m_resolved = resolved;
m_resPtr = resPtr;
};
/** \details
Unresolves the instance.
*/
void unresolve();
/** \details
Returns the result of the instance resolution represented as a three-dimensional point.
\param inst [in] A smart pointer to an instance to be resolved.
\returns A raw pointer to an instance of the OdGePoint3d class.
\remarks
The method returns a valid raw pointer to the OdGePoint3d object
if the resolution result is equal to the kResPoint3d
or the kResPoint2d; otherwise, the method returns a NULL pointer.
*/
static const OdGePoint3d* asPoint3d(const OdIfcInstance *inst) {
if (inst->m_resolved == kResPoint3d || inst->m_resolved == kResPoint2d)
return reinterpret_cast(inst->m_resPtr);
ODA_ASSERT(0);
return nullptr;
};
/** \details
Returns the result of the instance resolution represented as a two-dimensional point.
\param inst [in] A smart pointer to an instance to be resolved.
\returns A raw pointer to an instance of the OdGePoint2d class.
\remarks
The method returns a valid raw pointer to the OdGePoint2d object
if the resolution result is equal to kResPoint3d
or kResPoint2d; otherwise, the method returns a NULL pointer.
*/
static const OdGePoint2d* asPoint2d(const OdIfcInstance *inst) {
if (inst->m_resolved == kResPoint2d || inst->m_resolved == kResPoint3d)
return reinterpret_cast(inst->m_resPtr);
ODA_ASSERT(0);
return nullptr;
};
/** \details
Returns the result of the instance resolution represented as a three-dimensional vector.
\param inst [in] A smart pointer to an instance to be resolved.
\returns A raw pointer to an instance of the OdGeVector3d class.
\remarks
The method returns a valid raw pointer to the OdVector3d object
if the resolution result is equal to kResVector3d
or kResVector2d; otherwise, the method returns a NULL pointer.
*/
static const OdGeVector3d* asVector3d(const OdIfcInstance *inst) {
if (inst->m_resolved == kResVector3d || inst->m_resolved == kResVector2d)
return reinterpret_cast(inst->m_resPtr);
ODA_ASSERT(0);
return nullptr;
};
/** \details
Returns the result of the instance resolution represented as a two-dimensional vector.
\param inst [in] A smart pointer to an instance to be resolved.
\returns A raw pointer to an instance of the OdGeVector2d class.
\remarks
The method returns a valid raw pointer to the OdVector2d object
if the resolution result is equal to kResVector3d
or kResVector2d; otherwise, the method returns a NULL pointer.
*/
static const OdGeVector2d* asVector2d(const OdIfcInstance *inst) {
if (inst->m_resolved == kResVector2d || inst->m_resolved == kResVector3d)
return reinterpret_cast(inst->m_resPtr);
ODA_ASSERT(0);
return nullptr;
};
/** \details
Returns the result of the instance resolution represented as a two-dimensional matrix.
\param inst [in] A smart pointer to an instance to be resolved.
\returns A raw pointer to an instance of the OdGeMatrix2d class.
\remarks
The method returns a valid raw pointer to the OdMatrix2d object
if the resolution result is equal to kResMatrix2d; otherwise, the method returns a NULL pointer.
*/
static const OdGeMatrix2d* asMatrix2d(const OdIfcInstance *inst) {
if (inst->m_resolved == kResMatrix2d)
return reinterpret_cast(inst->m_resPtr);
ODA_ASSERT(0);
return nullptr;
};
/** \details
Returns the result of the instance resolution represented as a three-dimensional vector.
\param inst [in] A smart pointer to an instance to be resolved.
\returns A raw pointer to an instance of the OdGeMatrix3d class.
\remarks
The method returns a valid raw pointer to the OdMatrix3d object
if the resolution result is equal to kResMatrix3d; otherwise, the method returns a NULL pointer.
*/
static const OdGeMatrix3d* asMatrix3d(const OdIfcInstance *inst) {
if (inst->m_resolved == kResMatrix3d)
return reinterpret_cast(inst->m_resPtr);
ODA_ASSERT_ONCE(0);
return nullptr;
};
/** \details
Returns the result of the instance resolution represented as a compound object.
\param inst [in] A smart pointer to an instance to get the compound object from.
\returns A smart pointer to a OdIfcCompound object.
\remarks
The method returns a valid smart pointer to the OdIfcCompound object
if the resolution result is equal to kResCompound; otherwise, the method returns a NULL pointer.
*/
static OdIfcCompoundPtr asCompound(OdSmartPtr inst);
/** \details
Returns the result of the instance resolution represented as an RGB color object.
\param inst [in] A pointer to an instance to be resolved.
\returns A raw pointer to an RGB color object.
\remarks
The method returns a valid raw pointer to the RGB color object
if the resolution result is equal to kRgbColor; otherwise, the method returns a NULL pointer.
*/
static const OdCmEntityColor* asRgbColor(const OdIfcInstance *inst) {
if (inst->m_resolved == kRgbColor)
return reinterpret_cast(inst->m_resPtr);
ODA_ASSERT(0);
return nullptr;
}
/** \details
Sets a new Gs node cache for the instance.
\param pGsNode [in] A raw pointer to an OdGsCache object.
*/
void setGsNode(OdGsCache* pGsNode) override;
/** \details
Retrieves the current Gs node object of the instance.
\returns A raw pointer to the OdGsCache object associated with the instance.
*/
OdGsCache* gsNode() const override;
/** \details
Sets the values of the instance's sub-entity traits.
\param traits [out] A raw pointer to the traits to be filled and returned to a calling subroutine.
\returns The result of setting the values.
*/
OdUInt32 subSetAttributes(OdGiDrawableTraits * traits) const override;
/** \details
Draws a graphical instance representation that is independent of any viewport context.
\param wd [in] A raw pointer to the object that encapsulates parameters of viewport-independent vectorization.
\returns true if the drawing was successful; otherwise, the method returns false.
*/
bool subWorldDraw(OdGiWorldDraw * wd) const override;
/** \details
Retrieves the identifier of the instance object's parent item.
\returns A raw pointer to a stub object that provides access to the database.
\remarks
The method returns a NULL pointer if the instance object doesn't have parent item.
*/
virtual OdDbStub* ownerId() const;
using OdDAI::ApplicationInstance::isKindOf;
//DOM-IGNORE-BEGIN
protected:
void *m_resPtr;
IfcOpResult m_resolved;
private:
void* asCustom() const { return m_resPtr; }
friend class OdIfcCompound;
//DOM-IGNORE-END
};
SMARTPTR(OdIfcInstance);
} //namespace OdIfc
#include "TD_PackPop.h"
#endif // _IFC_INSTANCE_H_