DATAKIT SDK  V2026.1
testlibifcwrite.cpp File Reference

Functions

int IfcWriteSample (const Dtk_string &inResultDirectory)
 
Dtk_ErrorStatus ProcessBasicWall (Dtk_bool inMesh)
 
Dtk_ErrorStatus ProcessMultiMeshWall ()
 
Dtk_ErrorStatus ProcessPrototypedColumns (int columnNumber)
 
Dtk_ErrorStatus ProcessWallClassification ()
 

Function Documentation

◆ IfcWriteSample()

int IfcWriteSample ( const Dtk_string inResultDirectory)
193 {
194  Dtk_string outputDirectory, outputFileName;
195  cout << endl << "----------------------------------------------" << endl;
196  cout << "Ifc Write start" << endl;
197 
198  // Choosing output directory and file name
199  outputDirectory = inResultDirectory + L"Ifc/";
200  outputDirectory.FixPathSeparator();
201  outputDirectory.mkdir();
202 
203  //The ProjectInformation class enables you to set global information while initializing the writer module
204  //This information is optionnali
206  myInfo.projectAuthor = L"my name";
207  myInfo.buildingName = L"sample building";
208  myInfo.siteLatitude = 45.7;
209  myInfo.siteLongitude = 4.8;
210  myInfo.siteElevation = 173000;
211 
212  // First we initialize writing with name of files, log file and the configuration we want to use
213  Ifcw::WriteOptions myOptions;
214  myOptions.versionIndicator = 0; //IFC4
215  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
216  outputFileName = outputDirectory + L"sample.ifc";
217  Dtk_ErrorStatus st = Ifcw::InitWrite( outputFileName, Dtk_string( outputDirectory + L"testifcw.log" ), myOptions, &myInfo );
218 
219  if( st != dtkNoError )
220  {
221  cout << "error : " << dtkTypeError( st ).c_str() << endl;
222  return st;
223  }
224 
225  //Write an ifc object/entity
226  ProcessBasicWall( myOptions.versionIndicator != 1 );
230 
231  Ifcw::EndWrite();
232 
233  cout << "=> " << outputFileName.c_str() << endl << "Ifc Write end" << endl;
234 
235  return 0;
236 }

◆ ProcessBasicWall()

Dtk_ErrorStatus ProcessBasicWall ( Dtk_bool  inMesh)
19 {
20  //Create a new set of parameters for the ifc element to be written
21  Ifcw::IfcElement inParameters = Ifcw::IfcElement();
22 
23  //Set parameters value according to your needs (OPTIONAL)
24  Dtk_RGB myColor = Dtk_RGB( 150, 40, 20 ); //Brick color
25  inParameters.SetColor( myColor );
26 
27  //Initialize the current object with those parameters
28  Dtk_ErrorStatus errorStatus = Ifcw::InitObject( inParameters );
29 
30  if( errorStatus != dtkNoError )
31  {
32  cout << "Can't write object " << errorStatus << endl;
34  }
35 
36  Dtk_EntityPtr entityShape;
37  if( inMesh ) // Create ifc object tessallated geometry (mesh)
38  {
39  Dtk_pnt wallFirstPoint = Dtk_pnt( 40, 40, 0 );
40  Dtk_pnt wallSecondPoint = Dtk_pnt( 140, 45, 80 );
41  Dtk_MeshPtr mesh = sampleWriter::CreateMeshCuboid( wallFirstPoint, wallSecondPoint );
42  entityShape = Dtk_EntityPtr::DtkDynamicCast( mesh );
43  }
44  else // Create ifc object exact geometry (brep); available in IFC4
45  {
47  entityShape = Dtk_EntityPtr::DtkDynamicCast( body );
48  }
49  // And write the ifc object with previous parameters and geometry
50  Ifcw::WriteEntity( entityShape );
51 
52  // Close the current object
54  return dtkNoError;
55 }

◆ ProcessMultiMeshWall()

Dtk_ErrorStatus ProcessMultiMeshWall ( )
142 {
143  //Create a new set of parameters for the ifc entity to be written
144  Ifcw::IfcElement inParameters = Ifcw::IfcElement();
145  //Set parameters value according to your needs (OPTIONAL)
146  inParameters.SetName( L"myWall" );
147  inParameters.SetBuildingElementType( Ifcw::IfcWall );
148  inParameters.SetLevel( L"Ground floor" );
149  inParameters.SetGUID( L"00024NEV9DMsnaPcrdUcjs" );
150  Dtk_RGB myColor = Dtk_RGB( 135, 60, 20 ); //Another brick color
151  inParameters.SetColor( myColor );
152 
153  //For custom ifc properties, create desired Dtk_MetaDataPtr (OPTIONAL)
154  Dtk_MetaDataPtr myMetadatum1 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"customLength", L"2.5", L"DOUBLE" );
155  Dtk_MetaDataPtr myMetadatum2 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"Manufacturer", L"Datakit", L"STRING" );
156  //You can assign a category to Dtk_MetaDataPtr, to create Ifc property sets with different name (OPTIONAL)
157  myMetadatum2->SetCategory( "Identity Data" );
158 
159  //you can either add single metadatum...
160  inParameters.AddProperty( myMetadatum1 );
161  inParameters.AddProperty( myMetadatum2 );
162 
163  //...or work with a table
164  //Dtk_tab<Dtk_MetaDataPtr> inMetadata = Dtk_tab<Dtk_MetaDataPtr>();
165  //inMetadata.push_back( myMetadatum1 );
166  //inMetadata.push_back( myMetadatum2 );
167  //inParameters->SetPropertySet( inMetadata );
168 
169  //Initialize the current object with those parameters
170  Dtk_ErrorStatus errorStatus = Ifcw::InitObject( std::move( inParameters ) );
171  if( errorStatus != dtkNoError )
172  {
173  cout << "Can't write object : " << errorStatus << endl;;
175  }
176 
177  // Create ifc object geometry ((here there are several meshes))mesh)
178  Dtk_pnt wallFirstPoint = Dtk_pnt( 140, 45, 0 );
179  Dtk_pnt wallSecondPoint = Dtk_pnt( 145, -40, 80 );
180  Dtk_MeshPtr mesh = sampleWriter::CreateMeshCuboid( wallFirstPoint, wallSecondPoint );
181 
182  // Now we write the geometry of our object. Multiple meshes are possible
184  mesh->Transform( Dtk_transfo( Dtk_dir( 1, 0, 0 ), Dtk_dir( 0, 1, 0 ), Dtk_dir( 0, 0, 1 ), Dtk_pnt( 0, 87, 0 ) ) );
186 
187  //Write the current object and close it
188  Ifcw::EndObject();
189  return dtkNoError;
190 }

◆ ProcessPrototypedColumns()

Dtk_ErrorStatus ProcessPrototypedColumns ( int  columnNumber)
91 {
92  //Create a new set of parameters for the ifc entity to be written
93  Ifcw::IfcType myColumnType = Ifcw::IfcType();
94  Dtk_transfo transformationMatrix;
95  Dtk_string name = "Column";
96 
97  //Set type parameters according to your needs
98  myColumnType.SetName( std::move( name ) );
100  myColumnType.SetPredefinedType( L"COLUMN" );
101  myColumnType.SetID( 1 );
102 
103  //Set properties shared by all futur occurences of the type
104  Dtk_MetaDataPtr myMetadatum1 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"radius", L"2.5", L"DOUBLE" );
105  Dtk_MetaDataPtr myMetadatum2 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"Manufacturer", L"Datakit", L"STRING" );
106  myColumnType.AddProperty( myMetadatum1 );
107  myColumnType.AddProperty( myMetadatum2, L"Identity Data" );
108 
109  // Create ifc type geometry (mesh)
111  myColumnType.AddShape( Dtk_EntityPtr::DtkDynamicCast( mesh ) );
112  //Write the type we have set
113  Dtk_ErrorStatus errorStatus = Ifcw::WriteType( myColumnType );
114  if( errorStatus != dtkNoError )
115  {
116  cout << "Can't write type : " << errorStatus << endl;;
118  }
119 
120  //Now we create colmun occurences of the type we just created. They will share its geometry
121  for( int i = 0; i < columnNumber; i++ )
122  {
123  Dtk_string nameInst = name;
124  nameInst.add_int( i + 1 );
125  transformationMatrix.addTranslate( Dtk_dir( -30, -30, 0 ) );
126 
127  Ifcw::IfcElement inInstanceParameters = Ifcw::IfcElement();
128  inInstanceParameters.SetName( std::move( nameInst ) );
129  inInstanceParameters.SetBuildingElementType( Ifcw::IfcColumn );
130  inInstanceParameters.SetLevel( L"Ground floor" );
131  inInstanceParameters.SetTypeID( 1 );
132  inInstanceParameters.SetInstanceTrf( transformationMatrix );
133 
134  Ifcw::InitObject( inInstanceParameters );
135  Ifcw::EndObject();
136  }
137 
138  return dtkNoError;
139 }

◆ ProcessWallClassification()

Dtk_ErrorStatus ProcessWallClassification ( )
58 {
59  //Create a new set of parameters for the ifc element to be written
60  Ifcw::IfcElement inParameters = Ifcw::IfcElement();
61  inParameters.SetName( L"wallClassified" );
62  inParameters.SetBuildingElementType( Ifcw::IfcWall );
63  //Create an IfcClassification to represent the classification you're using (e.g. : UniFormat, OmniClass, SfB...)
64  //Create the reference in this classification you want to assign to the ifc entity to be written
65  Ifcw::classification::IfcClassification classification = Ifcw::classification::IfcClassification( "ASTM", "E1557", "UniFormat II" );
66  Ifcw::classification::IfcClassificationReference ref = Ifcw::classification::IfcClassificationReference( "https://www.wbdg.org/FFC/VA/VACOST/triservicemoduniformat.pdf", "B201001", "EXTERIOR CLOSURE", std::move( classification ) );
67  inParameters.SetClassificationReference( std::move( ref ) );
68 
69  //Initialize the current object with those parameters
70  Dtk_ErrorStatus errorStatus = Ifcw::InitObject( inParameters );
71  if( errorStatus != dtkNoError )
72  {
73  cout << "Can't write object : " << errorStatus << endl;;
75  }
76 
77  // Create ifc object geometry (mesh)
78  Dtk_pnt wallFirstPoint = Dtk_pnt( 140, -250, 0 );
79  Dtk_pnt wallSecondPoint = Dtk_pnt( 145, -70, 60 );
80  Dtk_MeshPtr mesh = sampleWriter::CreateMeshCuboid( wallFirstPoint, wallSecondPoint );
81 
82  //Write the geometry of our object. Multiple meshes are possible
84 
85  //Write the current object and close it
87  return dtkNoError;
88 }
Ifcw::IfcType::SetPredefinedType
void SetPredefinedType(const Dtk_string &inType)
Setter for IfcType predefined type.
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
ProcessBasicWall
Dtk_ErrorStatus ProcessBasicWall(Dtk_bool inMesh)
Definition: testlibifcwrite.cpp:18
Ifcw::IfcElement::SetGUID
void SetGUID(Dtk_string inGUID)
Setter for IfcElement GUID.
Ifcw::ProjectInformation::buildingName
Dtk_string buildingName
Definition: IFCWriter.h:56
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::IfcElement::SetLevel
void SetLevel(Dtk_string inLevel)
Setter for IfcElement level.
Ifcw::IfcType::SetBuildingElementType
void SetBuildingElementType(const Dtk_string &inType)
Setter for IfcType building element type.
Ifcw::IfcElement::AddProperty
void AddProperty(Dtk_MetaDataPtr inProperty, Dtk_string inSetName="")
Adds a property to IfcElement current property set.
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:249
Ifcw::ProjectInformation::siteElevation
Dtk_Double64 siteElevation
Definition: IFCWriter.h:62
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:28
Ifcw::WriteOptions::buildingTypeRecognition
Dtk_bool buildingTypeRecognition
DTK_TRUE : enable building type recognition (deduces if an element is an IFCWALL, IFCWINDOW....
Definition: IFCWriter.h:30
Ifcw::IfcElement
This class provides several parameters for the next ifc entity to be written, as its custom property ...
Definition: IFCWriter.h:331
Ifcw::InitObject
DtkErrorStatus InitObject(IfcElement inParameters)
Initialize an ifcobject with various information.
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Ifcw::ProjectInformation::projectAuthor
Dtk_string projectAuthor
Definition: IFCWriter.h:57
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::SetBuildingElementType
void SetBuildingElementType(Dtk_string inType)
Setter for IfcElement building element type.
Ifcw::IfcElement::SetTypeID
void SetTypeID(const Dtk_ID &inID)
Setter for IfcElement IfcType ID.
ProcessMultiMeshWall
Dtk_ErrorStatus ProcessMultiMeshWall()
Definition: testlibifcwrite.cpp:141
Ifcw::ProjectInformation::siteLatitude
Dtk_Double64 siteLatitude
Definition: IFCWriter.h:60
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:90
Ifcw::EndWrite
DtkErrorStatus EndWrite()
Creation of the output file and free the Ifc Writer
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:61
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:334
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:20
Dtk_string::FixPathSeparator
void FixPathSeparator()
File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed ...
Ifcw::IfcElement::SetName
void SetName(Dtk_string inName)
Setter for IfcElement name.
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:175
Dtk_transfo::addTranslate
void addTranslate(const Dtk_dir &V)
Translate the Dtk_transfo.
sampleWriter::CreateCube
Dtk_BodyPtr CreateCube()
Definition: testcreatecube.cpp:1316
Ifcw::ProjectInformation
This struct enables the user to define global properties regarding the project, construction site and...
Definition: IFCWriter.h:51
Ifcw::IfcColumn
@ IfcColumn
Definition: IFCWriter.h:225
Ifcw::IfcWall
@ IfcWall
Definition: IFCWriter.h:239
sampleWriter::CreateMeshCuboid
Dtk_MeshPtr CreateMeshCuboid(const Dtk_pnt &inFirstPoint, const Dtk_pnt &inSecondPoint)
Definition: testcreatemesh.cpp:455
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:147
Ifcw::IfcElement::SetInstanceTrf
void SetInstanceTrf(const Dtk_transfo &inTrf)
Setter for IfcElement instance transformation matrice.
Ifcw::classification::IfcClassification
A class that represents a classification system, like UniFormat, Omniclass, SfB...
Definition: IFCWriter.h:117
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:14
ProcessWallClassification
Dtk_ErrorStatus ProcessWallClassification()
Definition: testlibifcwrite.cpp:57
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 .