/////////////////////////////////////////////////////////////////////////////// // 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 _FILLER_EXTENDER_H #define _FILLER_EXTENDER_H #include "ExPrintConsole.h" #include "IfcCore.h" #include "IfcEntityTypes.h" #include "IfcEntity.h" #include "Ifc2x3/Ifc2x3Entities.h" #include "Ifc2x3/Ifc2x3SelectTypes.h" #include "Ifc2x3/Ifc2x3Enum.h" #include "daiConsts.h" #include "daiSettings.h" #include "daiUtils/daiTextEncodeDecode.h" #include "daiUtils/daiEmbededTypeUtils.h" #include "daiObjectId.h" #define STL_USING_VECTOR #include "OdaSTL.h" namespace OdIfc { namespace Utils { /*template inline OdSmartPtr CreateEntity(OdIfcModelPtr model) { OdSmartPtr entity = model->createEntityInstance(entityType); if (entity.isNull()) { throw OdError(eNullEntityPointer); } OdDAIObjectId oid = model->appendEntityInstance(entity); if (oid.isNull()) { throw OdError(eBrokenHandle); } if (entity->isKindOf(kIfcRoot)) assignGlobalId(entity); return entity; }*/ template inline OdSmartPtr CreateEntity(OdIfcModel *model) { OdSmartPtr inst = EntityType::createObject(model); if (inst.isNull()) { throw OdError(eNullEntityPointer); } if (inst->isKindOf(kIfcRoot)) assignGlobalId(inst); return inst; } inline OdDAIObjectId createOwnerHistory(OdIfcModel *model) { // Use static method createObject from entity instance classes OdIfc2x3::IfcPersonPtr personData = CreateEntity(model); OdIfc2x3::IfcOrganizationPtr organizationData = CreateEntity(model); const char applicationName[] = "ODA ExIfcModelFiller"; organizationData->setName(applicationName); OdIfc2x3::IfcPersonAndOrganizationPtr personAndOrganizationData = CreateEntity(model); personAndOrganizationData->setTheOrganization(organizationData->id()); personAndOrganizationData->setThePerson(personData->id()); OdIfc2x3::IfcApplicationPtr applicationData = CreateEntity(model); applicationData->setApplicationDeveloper(organizationData->id()); const char applicationVersion[] = TD_SHORT_STRING_VER_S; applicationData->setVersion(applicationVersion); // provide version current SDK applicationData->setApplicationFullName(applicationName); applicationData->setApplicationIdentifier(applicationName); OdIfc2x3::IfcOwnerHistoryPtr ownerHistoryData = CreateEntity(model); ownerHistoryData->setOwningUser(personAndOrganizationData->id()); ownerHistoryData->setOwningApplication(applicationData->id()); ownerHistoryData->setChangeAction(OdIfc2x3::kIfcChangeActionEnum_ADDED); ownerHistoryData->setLastModifyingUser(personAndOrganizationData->id()); ownerHistoryData->setLastModifyingApplication(applicationData->id()); ownerHistoryData->setCreationDate(0); return ownerHistoryData->id(); } inline OdDAIObjectId createDirection(OdIfcModel *model, double x, double y, double z = OdDAI::Consts::OdNan) { OdIfc2x3::IfcDirectionPtr direction = CreateEntity(model); OdArray arrRatios; arrRatios.reserve(OdDAI::Utils::isUnset(z) ? 2 : 3); arrRatios.append(x); arrRatios.append(y); if (!OdDAI::Utils::isUnset(z)) arrRatios.append(z); direction->directionRatios().setArray(arrRatios); return direction->id(); } inline OdDAIObjectId createCartesianPoint(OdIfcModelPtr model, double x, double y, double z = OdDAI::Consts::OdNan) { OdIfc2x3::IfcCartesianPointPtr cartesianPoint = CreateEntity(model); OdArray arrCoords; arrCoords.reserve(OdDAI::Utils::isUnset(z) ? 2 : 3); arrCoords.append(x); arrCoords.append(y); if (!OdDAI::Utils::isUnset(z)) arrCoords.append(z); cartesianPoint->coordinates().setArray(arrCoords); return cartesianPoint->id(); } inline OdDAIObjectId createAxis2Placement3D(OdIfcModelPtr model, const OdDAIObjectId& location, const OdDAIObjectId& axis, const OdDAIObjectId& direction) { OdIfc2x3::IfcAxis2Placement3DPtr entityData = CreateEntity(model); entityData->setAxis(axis); entityData->setRefDirection(direction); entityData->setLocation(location); return entityData->id(); } inline OdDAIObjectId createGeometricRepresentationContext(OdIfcModelPtr model, const char *contextIdentifier, const char *contextType, OdInt16 dimensionsCount, double precision, const OdDAIObjectId& coordinateSystem, const OdDAIObjectId& trueNorth) { OdIfc2x3::IfcGeometricRepresentationContextPtr repContextData = CreateEntity(model); OdIfc2x3::IfcAxis2Placement axis2Placement = repContextData->worldCoordinateSystem(); axis2Placement.select().setHandle(coordinateSystem); repContextData->setContextIdentifier(contextIdentifier); repContextData->setContextType(contextType); repContextData->setTrueNorth(trueNorth); repContextData->setPrecision(precision); repContextData->setCoordinateSpaceDimension(dimensionsCount); return repContextData->id(); } inline OdDAIObjectId createDimensionalExponents(OdIfcModelPtr model, OdInt32 lengthExponent, OdInt32 massExponent, OdInt32 timeExponent, OdInt32 electricCurrentExponent, OdInt32 thermodynamicTemperatureExponent, OdInt32 amountOfSubstanceExponent, OdInt32 luminousIntensityExponent) { OdIfc2x3::IfcDimensionalExponentsPtr entityData = CreateEntity(model); entityData->setLengthExponent(lengthExponent); entityData->setMassExponent(massExponent); entityData->setTimeExponent(timeExponent); entityData->setElectricCurrentExponent(electricCurrentExponent); entityData->setThermodynamicTemperatureExponent(thermodynamicTemperatureExponent); entityData->setAmountOfSubstanceExponent(amountOfSubstanceExponent); entityData->setLuminousIntensityExponent(luminousIntensityExponent); return entityData->id(); } inline OdDAIObjectId createSIUnit(OdIfcModelPtr model, OdIfc2x3::IfcUnitEnum unitType, OdIfc2x3::IfcSIPrefix prefix, OdIfc2x3::IfcSIUnitName name, const OdDAIObjectId &dimensions) { OdIfc2x3::IfcSIUnitPtr entityData = CreateEntity(model); entityData->setUnitType(unitType); entityData->setPrefix(prefix); entityData->setName(name); if (dimensions) { entityData->setDimensions(dimensions); } return entityData->id(); } inline OdDAIObjectId createMeasureWithUnit(OdIfcModelPtr model, double angleMeasure, const OdDAIObjectId& unit) { OdIfc2x3::IfcMeasureWithUnitPtr entityData = CreateEntity(model); OdIfc2x3::IfcUnit unitWrapper = entityData->unitComponent(); unitWrapper.select().setHandle(unit); OdIfc2x3::IfcValue valueComponent = entityData->valueComponent(); valueComponent.setIfcPlaneAngleMeasure(angleMeasure); return entityData->id(); } inline OdDAIObjectId createConversionBasedUnit(OdIfcModelPtr model, const OdString& name, const OdDAIObjectId& conversionFactor, const OdDAIObjectId& dimensions, const OdIfc2x3::IfcUnitEnum& unitType) { OdIfc2x3::IfcConversionBasedUnitPtr entityData = CreateEntity(model); OdAnsiString encodedName; if (!OdDAI::Utils::encodeText(name, encodedName, OdDAI::Utils::CodecType::utf8)) { throw OdError(eSyntaxError); } entityData->setName(encodedName); entityData->setConversionFactor(conversionFactor); entityData->setDimensions(dimensions); entityData->setUnitType(unitType); return entityData->id(); } inline OdDAIObjectId createUnitAssignment(OdIfcModelPtr model, const OdArray& unitsCollection) { OdIfc2x3::IfcUnitAssignmentPtr entityData = CreateEntity(model); OdDAIObjectIds::const_iterator nextUnitHandle = unitsCollection.begin(); OdDAI::Set& unitsWrapperCollection = entityData->units(); if (unitsWrapperCollection.empty()) { unitsWrapperCollection.createEmpty(); } auto schema = model->underlyingSchema(); OdDAI::NamedTypePtr simpleValue = schema->types()->getAt("ifcunit"); auto selectTypeToInit = OdDAI::Utils::extractEmbeddedType(simpleValue); for (; nextUnitHandle != unitsCollection.end(); ++nextUnitHandle) { OdDAI::Select unitWrapper(selectTypeToInit); if (unitWrapper.setHandle(*nextUnitHandle)) unitsWrapperCollection.Add(unitWrapper); } return entityData->id(); } inline OdDAIObjectId createProject(OdIfcModelPtr model, const OdString& longName, const OdDAIObjectIds& representationContexts, const OdDAIObjectId& unitsInContext, const OdDAIObjectId& ownerHistory) { OdIfc2x3::IfcProjectPtr entityData = CreateEntity(model); OdAnsiString encodedLongName; if (!OdDAI::Utils::encodeText(longName, encodedLongName, OdDAI::Utils::CodecType::utf8)) { throw OdError(eSyntaxError); } entityData->setLongName(encodedLongName); entityData->setUnitsInContext(unitsInContext); entityData->representationContexts().setArray(representationContexts); entityData->setOwnerHistory(ownerHistory); return entityData->id(); } inline OdDAIObjectId createLocalPlacement(OdIfcModelPtr model, const OdDAIObjectId& axis2PlacementRelative, const OdDAIObjectId* pPlacementRelatesTo = NULL) { OdIfc2x3::IfcLocalPlacementPtr entityData = CreateEntity(model); OdIfc2x3::IfcAxis2Placement axisPlacement = entityData->relativePlacement(); axisPlacement.select().setHandle(axis2PlacementRelative); if (pPlacementRelatesTo) { entityData->setPlacementRelTo(*pPlacementRelatesTo); } return entityData->id(); } inline OdDAIObjectId createSite(OdIfcModelPtr model, const OdDAIObjectId& objectPlacement, const OdDAIObjectId& ownerHistory, OdIfc2x3::IfcElementCompositionEnum compositionType) { OdIfc2x3::IfcSitePtr entityData = CreateEntity(model); entityData->setObjectPlacement(objectPlacement); entityData->setCompositionType(compositionType); entityData->setOwnerHistory(ownerHistory); entityData->setName("Site"); return entityData->id(); } inline OdDAIObjectId createRelAggregates(OdIfcModelPtr model, const OdDAIObjectId& ownerHistory, const OdDAIObjectId& relatingObject, const OdDAIObjectIds& relatedObjectCollection) { OdIfc2x3::IfcRelAggregatesPtr entityData = CreateEntity(model); entityData->setRelatingObject(relatingObject); entityData->relatedObjects().setArray(relatedObjectCollection); entityData->setOwnerHistory(ownerHistory); return entityData->id(); } inline OdDAIObjectId createBuilding(OdIfcModelPtr model, const OdDAIObjectId& ownerHistory, const OdDAIObjectId& objectPlacement, OdIfc2x3::IfcElementCompositionEnum compositionType) { OdIfc2x3::IfcBuildingPtr entityData = CreateEntity(model); entityData->setObjectPlacement(objectPlacement); entityData->setCompositionType(compositionType); entityData->setOwnerHistory(ownerHistory); return entityData->id(); } inline OdDAIObjectId createBuildingStorey(OdIfcModelPtr model, const OdDAIObjectId& ownerHistory, const OdDAIObjectId& objectPlacement, OdIfc2x3::IfcElementCompositionEnum compositionType) { OdIfc2x3::IfcBuildingStoreyPtr entityData = CreateEntity(model); entityData->setObjectPlacement(objectPlacement); entityData->setCompositionType(compositionType); entityData->setOwnerHistory(ownerHistory); return entityData->id(); } inline OdDAIObjectId createBuildingElementProxy(OdIfcModelPtr model, const OdDAIObjectId& ownerHistory, const OdDAIObjectId* pLocalPlacement = NULL, const OdDAIObjectId* pProductDefinitionShape = NULL) { OdIfc2x3::IfcBuildingElementProxyPtr entityData = CreateEntity(model); entityData->setOwnerHistory(ownerHistory); if (pLocalPlacement) { entityData->setObjectPlacement(*pLocalPlacement); } if (pProductDefinitionShape) { entityData->setRepresentation(*pProductDefinitionShape); } return entityData->id(); } inline OdDAIObjectId createRelContainedInspatialStructure(OdIfcModelPtr model, const OdDAIObjectId& ownerHistory, const OdDAIObjectIds& relatedElements, const OdDAIObjectId& relatingStructure) { OdIfc2x3::IfcRelContainedInSpatialStructurePtr entityData = CreateEntity(model); entityData->setOwnerHistory(ownerHistory); entityData->relatedElements().setArray(relatedElements); entityData->setRelatingStructure(relatingStructure); return entityData->id(); } inline OdDAIObjectId createAxis2Placement2D(OdIfcModelPtr model, const OdDAIObjectId& location, const OdDAIObjectId& direction) { OdIfc2x3::IfcAxis2Placement2DPtr entityData = CreateEntity(model); entityData->setRefDirection(direction); entityData->setLocation(location); return entityData->id(); } inline OdDAIObjectId createZShapeProfileDef(OdIfcModelPtr model, OdIfc2x3::IfcProfileTypeEnum profileType, const OdDAIObjectId& positionPlacement, double depth, double flangeWidth, double webThickness, double flangeThickness, const double* filletRadius = NULL, const double* edgeRadius = NULL) { OdIfc2x3::IfcZShapeProfileDefPtr entityData = CreateEntity(model); entityData->setPosition(positionPlacement); entityData->setProfileType(profileType); entityData->setDepth(depth); entityData->setFlangeWidth(flangeWidth); entityData->setWebThickness(webThickness); entityData->setFlangeThickness(flangeThickness); if (filletRadius) { entityData->setFilletRadius(*filletRadius); } if (edgeRadius) { entityData->setEdgeRadius(*edgeRadius); } return entityData->id(); } inline OdDAIObjectId createIShapeProfileDef(OdIfcModelPtr model, OdIfc2x3::IfcProfileTypeEnum profileType, const OdDAIObjectId& positionPlacement, double depth, double flangeWidth, double webThickness, double flangeThickness, const double* filletRadius = NULL) { OdIfc2x3::IfcIShapeProfileDefPtr entityData = CreateEntity(model); entityData->setPosition(positionPlacement); entityData->setProfileType(profileType); entityData->setOverallDepth(depth); entityData->setOverallWidth(flangeWidth); entityData->setWebThickness(webThickness); entityData->setFlangeThickness(flangeThickness); if (filletRadius) { entityData->setFilletRadius(*filletRadius); } return entityData->id(); } inline OdDAIObjectId createExtrudedAreaSolid(OdIfcModelPtr model, const OdDAIObjectId& shape, const OdDAIObjectId& placementPoint, const OdDAIObjectId& direction, double depth) { OdIfc2x3::IfcExtrudedAreaSolidPtr entityData = CreateEntity(model); entityData->setDepth(depth); entityData->setExtrudedDirection(direction); entityData->setSweptArea(shape); entityData->setPosition(placementPoint); return entityData->id(); } inline OdDAIObjectId createShapeRepresentation(OdIfcModelPtr model, const OdDAIObjectId& context, const char *representationIdentifier, const char *representationType, const OdArray& representationItemsCollection) { OdIfc2x3::IfcShapeRepresentationPtr entityData = CreateEntity(model); entityData->setContextOfItems(context); entityData->setRepresentationIdentifier(representationIdentifier); entityData->setRepresentationType(representationType); entityData->items().setArray(representationItemsCollection); return entityData->id(); } inline OdDAIObjectId createProductDefinitionShape(OdIfcModelPtr model, const OdArray& represntationCollection) { OdIfc2x3::IfcProductDefinitionShapePtr entityData = CreateEntity(model); entityData->representations().setArray(represntationCollection); return entityData->id(); } } namespace Utils { template class ParamPostSetter { public: ParamPostSetter(OdIfcModelPtr model, const OdDAIObjectId& targetHandle) : m_targetHandle(targetHandle) , m_wasSettled(false) , m_model(model) { } virtual ~ParamPostSetter() { ODA_ASSERT(m_wasSettled); } void Set(const TParam& paramToSet) { OdSmartPtr entity = m_targetHandle.openObject(); ODA_ASSERT(!entity.isNull()); if (!entity.isNull()) { SetParam(*entity, paramToSet); m_wasSettled = true; } } private: virtual void SetParam(TTarget& target, const TParam& paramToSet) = 0; private: OdIfcModelPtr m_model; OdDAIObjectId m_targetHandle; bool m_wasSettled; }; template class LocalPlacementPostSetter : public ParamPostSetter { public: LocalPlacementPostSetter(OdIfcModelPtr model, const OdDAIObjectId& targetHandle) : ParamPostSetter(model, targetHandle) {} private: virtual void SetParam(TTarget& target, const OdDAIObjectId& paramToSet) { target.setObjectPlacement(paramToSet); } }; template class ProductDefinitionShapeSetter : public ParamPostSetter { public: ProductDefinitionShapeSetter(OdIfcModelPtr model, const OdDAIObjectId& targetHandle) : ParamPostSetter(model, targetHandle) {} private: virtual void SetParam(TTarget& target, const OdDAIObjectId& paramToSet) { target.setRepresentation(paramToSet); } }; } } #endif