DATAKIT API  V2025.1
IFC Write Sample
//start_of_mainifcwrite
//This sample show you how to write some ifc objects with several parameters and mesh geometry.
{
//Create a new set of parameters for the ifc element to be written
//Set parameters value according to your needs (OPTIONAL)
Dtk_RGB myColor = Dtk_RGB( 150, 40, 20 ); //Brick color
inParameters.SetColor( myColor );
//Initialize the current object with those parameters
Dtk_ErrorStatus errorStatus = Ifcw::InitObject( inParameters );
if( errorStatus != dtkNoError )
{
cout << "Can't write object " << errorStatus << endl;
}
Dtk_EntityPtr entityShape;
if( inMesh ) // Create ifc object tessallated geometry (mesh)
{
Dtk_pnt wallFirstPoint = Dtk_pnt( 40, 40, 0 );
Dtk_pnt wallSecondPoint = Dtk_pnt( 140, 45, 80 );
Dtk_MeshPtr mesh = sampleWriter::CreateMeshCuboid( wallFirstPoint, wallSecondPoint );
entityShape = Dtk_EntityPtr::DtkDynamicCast( mesh );
}
else // Create ifc object exact geometry (brep); available in IFC4
{
entityShape = Dtk_EntityPtr::DtkDynamicCast( body );
}
// And write the ifc object with previous parameters and geometry
Ifcw::WriteEntity( entityShape );
// Close the current object
return dtkNoError;
}
{
//Create a new set of parameters for the ifc element to be written
inParameters.SetName( L"wallClassified" );
//Create an IfcClassification to represent the classification you're using (e.g. : UniFormat, OmniClass, SfB...)
//Create the reference in this classification you want to assign to the ifc entity to be written
Ifcw::classification::IfcClassification classification = Ifcw::classification::IfcClassification( "ASTM", "E1557", "UniFormat II" );
Ifcw::classification::IfcClassificationReference ref = Ifcw::classification::IfcClassificationReference( "https://www.wbdg.org/FFC/VA/VACOST/triservicemoduniformat.pdf", "B201001", "EXTERIOR CLOSURE", classification );
inParameters.SetClassificationReference( ref );
//Initialize the current object with those parameters
Dtk_ErrorStatus errorStatus = Ifcw::InitObject( inParameters );
if( errorStatus != dtkNoError )
{
cout << "Can't write object : " << errorStatus << endl;;
}
// Create ifc object geometry (mesh)
Dtk_pnt wallFirstPoint = Dtk_pnt( 140, -250, 0 );
Dtk_pnt wallSecondPoint = Dtk_pnt( 145, -70, 60 );
Dtk_MeshPtr mesh = sampleWriter::CreateMeshCuboid( wallFirstPoint, wallSecondPoint );
//Write the geometry of our object. Multiple meshes are possible
//Write the current object and close it
return dtkNoError;
}
{
//Create a new set of parameters for the ifc entity to be written
Ifcw::IfcType myColumnType = Ifcw::IfcType();
Dtk_transfo transformationMatrix;
Dtk_string name = "Column";
//Set type parameters according to your needs
myColumnType.SetName( name );
myColumnType.SetPredefinedType( "COLUMN" );
myColumnType.SetID( 1 );
//Set properties shared by all futur occurences of the type
Dtk_MetaDataPtr myMetadatum1 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, "radius", "2.5", "DOUBLE" );
Dtk_MetaDataPtr myMetadatum2 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, "Manufacturer", "Datakit", "STRING" );
myColumnType.AddProperty( myMetadatum1 );
myColumnType.AddProperty( myMetadatum2, "Identity Data" );
// Create ifc type geometry (mesh)
myColumnType.AddShape( Dtk_EntityPtr::DtkDynamicCast( mesh ) );
//Write the type we have set
Dtk_ErrorStatus errorStatus = Ifcw::WriteType( myColumnType );
if( errorStatus != dtkNoError )
{
cout << "Can't write type : " << errorStatus << endl;;
}
//Now we create colmun occurences of the type we just created. They will share its geometry
for( int i = 0; i < columnNumber; i++ )
{
Dtk_string nameInst = name;
nameInst.add_int( i + 1 );
transformationMatrix.addTranslate( Dtk_dir( -30, -30, 0 ) );
Ifcw::IfcElement inInstanceParameters = Ifcw::IfcElement();
inInstanceParameters.SetName( nameInst );
inInstanceParameters.SetBuildingElementType( Ifcw::IfcColumn );
inInstanceParameters.SetLevel( L"Ground floor" );
inInstanceParameters.SetTypeID( 1 );
inInstanceParameters.SetInstanceTrf( transformationMatrix );
Ifcw::InitObject( inInstanceParameters );
}
return dtkNoError;
}
{
//Create a new set of parameters for the ifc entity to be written
//Set parameters value according to your needs (OPTIONAL)
inParameters.SetName( L"myWall" );
inParameters.SetLevel( L"Ground floor" );
inParameters.SetGUID( L"00024NEV9DMsnaPcrdUcjs" );
Dtk_RGB myColor = Dtk_RGB( 135, 60, 20 ); //Another brick color
inParameters.SetColor( myColor );
//For custom ifc properties, create desired Dtk_MetaDataPtr (OPTIONAL)
Dtk_MetaDataPtr myMetadatum1 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, "customLength", "2.5", "DOUBLE" );
Dtk_MetaDataPtr myMetadatum2 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, "Manufacturer", "Datakit", "STRING" );
//You can assign a category to Dtk_MetaDataPtr, to create Ifc property sets with different name (OPTIONAL)
myMetadatum2->SetCategory( "Identity Data" );
//you can either add single metadatum...
inParameters.AddProperty( myMetadatum1 );
inParameters.AddProperty( myMetadatum2 );
//...or work with a table
//Dtk_tab<Dtk_MetaDataPtr> inMetadata = Dtk_tab<Dtk_MetaDataPtr>();
//inMetadata.push_back( myMetadatum1 );
//inMetadata.push_back( myMetadatum2 );
//inParameters->SetPropertySet( inMetadata );
//Initialize the current object with those parameters
Dtk_ErrorStatus errorStatus = Ifcw::InitObject( inParameters );
if( errorStatus != dtkNoError )
{
cout << "Can't write object : " << errorStatus << endl;;
}
// Create ifc object geometry ((here there are several meshes))mesh)
Dtk_pnt wallFirstPoint = Dtk_pnt( 140, 45, 0 );
Dtk_pnt wallSecondPoint = Dtk_pnt( 145, -40, 80 );
Dtk_MeshPtr mesh = sampleWriter::CreateMeshCuboid( wallFirstPoint, wallSecondPoint );
// Now we write the geometry of our object. Multiple meshes are possible
mesh->Transform( Dtk_transfo( Dtk_dir( 1, 0, 0 ), Dtk_dir( 0, 1, 0 ), Dtk_dir( 0, 0, 1 ), Dtk_pnt( 0, 87, 0 ) ) );
//Write the current object and close it
return dtkNoError;
}
int IfcWriteSample( const Dtk_string &inResultDirectory )
{
Dtk_string outputDirectory, outputFileName;
cout << endl << "----------------------------------------------" << endl;
cout << "Ifc Write start" << endl;
// Choosing output directory and file name
outputDirectory = inResultDirectory + L"dtk/Ifc/";
outputDirectory.FixPathSeparator();
outputDirectory.mkdir();
//The ProjectInformation class enables you to set global information while initializing the writer module
//This information is optionnali
myInfo.projectAuthor = "my name";
myInfo.buildingName = "sample building";
myInfo.siteLatitude = 45.7;
myInfo.siteLongitude = 4.8;
myInfo.siteElevation = 173000;
// First we initialize writing with name of files, log file and the configuration we want to use
Ifcw::WriteOptions myOptions;
myOptions.versionIndicator = 1; //IFC4
myOptions.buildingTypeRecognition = 0; //Forces building type recognition. If set to true, all IfcElement without a building element type set will be analyzed (looking through their metadata etc.. to see if we can deduce their building type
outputFileName = outputDirectory + L"sample.ifc";
Dtk_ErrorStatus st = Ifcw::InitWrite( outputFileName, Dtk_string( outputDirectory + L"testifcw.log" ), myOptions, &myInfo );
if( st != dtkNoError )
{
cout << "error : " << dtkTypeError( st ).c_str() << endl;
return st;
}
//Write an ifc object/entity
cout << "=> " << outputFileName.c_str() << endl << "Ifc Write end" << endl;
return 0;
}
//end_of_mainifcwrite
Ifcw::IfcType::SetPredefinedType
void SetPredefinedType(const Dtk_string &inType)
Setter for IfcType predefined type.
Ifcw::IfcElement::SetBuildingElementType
void SetBuildingElementType(const Dtk_string &inType)
Setter for IfcElement building element type.
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
ProcessBasicWall
Dtk_ErrorStatus ProcessBasicWall(Dtk_bool inMesh)
Definition: testlibifcwrite.cpp:22
Ifcw::ProjectInformation::buildingName
Dtk_string buildingName
Definition: IFCWriter.h:63
Ifcw::WriteEntity
Dtk_ErrorStatus WriteEntity(const Dtk_EntityPtr &inEntity, const Dtk_transfo &inMat=Dtk_transfo())
Write the entity provided in parameter. The entity corresponds to current object geometry (e....
Ifcw::IfcType::SetBuildingElementType
void SetBuildingElementType(const Dtk_string &inType)
Setter for IfcType building element type.
Ifcw::IfcType
A IfcType is used to define the common properties of a certain type or style of an entity that may be...
Definition: IFCWriter.h:274
Ifcw::IfcElement::SetGUID
void SetGUID(const Dtk_string &inGUID)
Setter for IfcElement GUID.
Ifcw::ProjectInformation::siteElevation
Dtk_Double64 siteElevation
Definition: IFCWriter.h:69
Ifcw::InitWrite
DtkErrorStatus InitWrite(const Dtk_string &inOutputFile, const Dtk_string &inLogFile, const WriteOptions &inOptions, ProjectInformation *inProjectInfo=nullptr)
Initialize the Ifc Writer and the IFC version you want to write.
Ifcw::IfcElement::SetColor
void SetColor(const Dtk_RGB &inColor)
Setter for IfcElement color.
Ifcw::WriteOptions::versionIndicator
int versionIndicator
Int representing IFC version to use : 0 ( default ) = IFC2x3; 1 = IFC4.
Definition: IFCWriter.h:35
Ifcw::WriteOptions::buildingTypeRecognition
Dtk_bool buildingTypeRecognition
DTK_TRUE : enable building type recognition (deduces if an element is an IFCWALL, IFCWINDOW....
Definition: IFCWriter.h:37
Ifcw::IfcElement
This class provides several parameters for the next ifc entity to be written, as its custom property ...
Definition: IFCWriter.h:356
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
Ifcw::ProjectInformation::projectAuthor
Dtk_string projectAuthor
Definition: IFCWriter.h:64
Ifcw::IfcElement::SetLevel
void SetLevel(const Dtk_string &inLevel)
Setter for IfcElement level.
IfcWriteSample
int IfcWriteSample(const Dtk_string &inResultDirectory)
Definition: testlibifcwrite.cpp:196
Dtk_bool
char Dtk_bool
Definition: define.h:725
Ifcw::EndObject
DtkErrorStatus EndObject()
Ends the current object.
Dtk_string::add_int
void add_int(const int integer, int force_unsigned_int=0)
concat an int to the Dtk_string (convert the int to Dtk_string)
Ifcw::IfcType::AddShape
void AddShape(Dtk_EntityPtr inShape)
Adds an entity to IfcType shape representation (geometry)
Ifcw::IfcElement::SetTypeID
void SetTypeID(const Dtk_ID &inID)
Setter for IfcElement IfcType ID.
ProcessMultiMeshWall
Dtk_ErrorStatus ProcessMultiMeshWall()
Definition: testlibifcwrite.cpp:145
Ifcw::ProjectInformation::siteLatitude
Dtk_Double64 siteLatitude
Definition: IFCWriter.h:67
Dtk_MetaData::TypeProperty
@ TypeProperty
Definition: dtk_metadata.hpp:28
Ifcw::WriteOptions
This class provides several options to tune the IFC Writer. It must be provided to Ifcw::InitWrite me...
Definition: IFCWriter.h:18
Dtk_SmartPtr< Dtk_Entity >::DtkDynamicCast
static Dtk_SmartPtr< Dtk_Entity > DtkDynamicCast(const Dtk_SmartPtr< T2 > &p)
Definition: util_ptr_dtk.hpp:101
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Ifcw::IfcElement::SetClassificationReference
void SetClassificationReference(classification::IfcClassificationReference inClassificationRef)
Setter for IfcElement classification reference.
ProcessPrototypedColumns
Dtk_ErrorStatus ProcessPrototypedColumns(int columnNumber)
Definition: testlibifcwrite.cpp:94
Ifcw::EndWrite
DtkErrorStatus EndWrite()
Creation of the output file and free the Ifc Writer
Ifcw::InitObject
DtkErrorStatus InitObject(const IfcElement &inParameters)
Initialize an ifcobject with various information.
Dtk_SmartPtr< Dtk_Entity >
Ifcw::IfcType::SetID
void SetID(const Dtk_ID &inID)
Setter for IfcType ID.
Ifcw::ProjectInformation::siteLongitude
Dtk_Double64 siteLongitude
Definition: IFCWriter.h:68
dtkTypeError
Dtk_string dtkTypeError(Dtk_Int32 errNumero)
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
Ifcw::WriteType
Dtk_ErrorStatus WriteType(const IfcType &inType)
Write the type provided in parameter. The type can exists by itself without having entities related t...
sampleWriter::CreateMeshCylinder
Dtk_MeshPtr CreateMeshCylinder(int nbpoints)
Mesh Cylinder sample.
Definition: testcreatemesh.cpp:337
Ifcw::IfcType::AddProperty
void AddProperty(Dtk_MetaDataPtr inProperty, const Dtk_string &inSetName="")
Adds a property to IfcType current property set.
Dtk_string::mkdir
int mkdir() const
File Utility : Create a Directory.
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:22
Dtk_string::FixPathSeparator
void FixPathSeparator()
File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed ...
dtkErrorInvalidComponent
@ dtkErrorInvalidComponent
Definition: error_dtk.hpp:47
Ifcw::classification::IfcClassificationReference
This class represent a classification reference to be used for an ifc object, e.g....
Definition: IFCWriter.h:198
Dtk_transfo::addTranslate
void addTranslate(const Dtk_dir &V)
Translate the Dtk_transfo.
sampleWriter::CreateCube
Dtk_BodyPtr CreateCube()
Definition: testcreatecube.cpp:1249
Ifcw::ProjectInformation
This struct enables the user to define global properties regarding the project, construction site and...
Definition: IFCWriter.h:58
Ifcw::IfcColumn
@ IfcColumn
Definition: IFCWriter.h:250
Ifcw::IfcWall
@ IfcWall
Definition: IFCWriter.h:264
sampleWriter::CreateMeshCuboid
Dtk_MeshPtr CreateMeshCuboid(const Dtk_pnt &inFirstPoint, const Dtk_pnt &inSecondPoint)
Definition: testcreatemesh.cpp:458
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:140
Ifcw::IfcElement::SetInstanceTrf
void SetInstanceTrf(const Dtk_transfo &inTrf)
Setter for IfcElement instance transformation matrice.
Ifcw::IfcElement::AddProperty
void AddProperty(Dtk_MetaDataPtr inProperty, const Dtk_string &inSetName="")
Adds a property to IfcElement current property set.
Ifcw::classification::IfcClassification
A class that represents a classification system, like UniFormat, Omniclass, SfB...
Definition: IFCWriter.h:128
Ifcw::IfcElement::SetName
void SetName(const Dtk_string &inName)
Setter for IfcElement name.
Dtk_RGB
Definition: dtk_rgb.hpp:7
Ifcw::IfcType::SetName
void SetName(const Dtk_string &inName)
Setter for IfcType name.
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15
ProcessWallClassification
Dtk_ErrorStatus ProcessWallClassification()
Definition: testlibifcwrite.cpp:61
Dtk_MetaData::CreateMetaData
static Dtk_MetaDataPtr CreateMetaData(const MetaDataTypeEnum &inEnumType, Dtk_string inTitle, Dtk_string inValue, Dtk_string inValueType=Dtk_string(L"STRING"))
Create a Dtk_MetaDataPtr .