DATAKIT SDK  V2026.4
testlibifcwrite.cpp File Reference

Functions

DtkErrorStatus IfcWriteSample (const Dtk_string &inResultDirectory)
 Entry point: orchestrates all IFC sample functions and writes the results into a sample.ifc file. More...
 
Dtk_ErrorStatus ProcessBasicWall (Dtk_bool inMesh)
 
Dtk_ErrorStatus ProcessMultiMeshWall ()
 Writes a wall element composed of multiple mesh pieces with custom properties and a GUID. More...
 
Dtk_ErrorStatus ProcessPrototypedColumns (int inColumnCount)
 Writes a set of column elements sharing the same prototyped geometry (IfcElementType), demonstrating instance reuse. More...
 
Dtk_ErrorStatus ProcessWallClassification ()
 Writes a wall element with a UniFormat classification reference attached to it. More...
 

Function Documentation

◆ IfcWriteSample()

DtkErrorStatus IfcWriteSample ( const Dtk_string &  inResultDirectory)

Entry point: orchestrates all IFC sample functions and writes the results into a sample.ifc file.

202 {
203  Dtk_string outputDirectory, outputFileName;
204  std::cout << std::endl << "----------------------------------------------" << std::endl;
205  std::cout << "Ifc Write start" << std::endl;
206 
207  // Choosing output directory and file name
208  outputDirectory = inResultDirectory + L"Ifc/";
209  outputDirectory.FixPathSeparator();
210  outputDirectory.mkdir();
211 
212  //The ProjectInformation class enables you to set global information while initializing the writer module
213  //This information is optionnali
215  myInfo.projectAuthor = L"my name";
216  myInfo.buildingName = L"sample building";
217  myInfo.siteLatitude = 45.7;
218  myInfo.siteLongitude = 4.8;
219  myInfo.siteElevation = 173000;
220 
221  // First we initialize writing with name of files, log file and the configuration we want to use
222  Ifcw::WriteOptions myOptions;
223  myOptions.versionIndicator = 0; //IFC2x3 version will be used to write the file. Set to 1 for IFC4.
224  outputFileName = outputDirectory + L"sample.ifc";
225  Dtk_ErrorStatus errorStatus = Ifcw::InitWrite( outputFileName, Dtk_string( outputDirectory + L"testifcw.log" ), myOptions, &myInfo );
226 
227  if( errorStatus != dtkNoError )
228  {
229  std::cout << "error : " << dtkTypeError( errorStatus ).c_str() << std::endl;
230  return errorStatus;
231  }
232 
233  //Write an ifc object/entity
234  ProcessBasicWall( myOptions.versionIndicator != 1 );
238 
239  Ifcw::EndWrite();
240 
241  std::cout << "=> " << outputFileName.c_str() << std::endl << "Ifc Write end" << std::endl;
242 
243  return dtkNoError;
244 }

◆ ProcessBasicWall()

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

◆ ProcessMultiMeshWall()

Dtk_ErrorStatus ProcessMultiMeshWall ( )

Writes a wall element composed of multiple mesh pieces with custom properties and a GUID.

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

◆ ProcessPrototypedColumns()

Dtk_ErrorStatus ProcessPrototypedColumns ( int  inColumnCount)

Writes a set of column elements sharing the same prototyped geometry (IfcElementType), demonstrating instance reuse.

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

◆ ProcessWallClassification()

Dtk_ErrorStatus ProcessWallClassification ( )

Writes a wall element with a UniFormat classification reference attached to it.

64 {
65  //Create a new set of parameters for the ifc element to be written
66  Ifcw::IfcElement inParameters = Ifcw::IfcElement();
67  inParameters.SetName( L"wallClassified" );
69  //Create an IfcClassification to represent the classification you're using (e.g. : UniFormat, OmniClass, SfB...)
70  //Create the reference in this classification you want to assign to the ifc entity to be written
71  Ifcw::classification::IfcClassification classification = Ifcw::classification::IfcClassification( "ASTM", "E1557", "UniFormat II" );
72  Ifcw::classification::IfcClassificationReference ref = Ifcw::classification::IfcClassificationReference( "https://www.wbdg.org/FFC/VA/VACOST/triservicemoduniformat.pdf", "B201001", "EXTERIOR CLOSURE", std::move( classification ) );
73  inParameters.SetClassificationReference( std::move( ref ) );
74 
75  //Initialize the current object with those parameters
76  Dtk_ErrorStatus errorStatus = Ifcw::InitObject( inParameters );
77  if( errorStatus != dtkNoError )
78  {
79  std::cout << "Can't write object : " << errorStatus << std::endl;;
81  }
82 
83  // Create ifc object geometry (mesh)
84  Dtk_pnt wallFirstPoint = Dtk_pnt( 140, -250, 0 );
85  Dtk_pnt wallSecondPoint = Dtk_pnt( 145, -70, 60 );
86  Dtk_MeshPtr mesh = sampleWriter::CreateMeshCuboid( wallFirstPoint, wallSecondPoint );
87 
88  //Write the geometry of our object. Multiple meshes are possible
90 
91  //Write the current object and close it
93  return dtkNoError;
94 }
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
ProcessBasicWall
Dtk_ErrorStatus ProcessBasicWall(Dtk_bool inMesh)
Definition: testlibifcwrite.cpp:23
Ifcw::IfcElement::SetGUID
void SetGUID(Dtk_string inGUID)
Setter for IfcElement GUID.
Ifcw::ProjectInformation::buildingName
Dtk_string buildingName
Definition: IFCWriter.h:70
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::IfcElement::AddProperty
void AddProperty(Dtk_MetaDataPtr inProperty, Dtk_string inSetName="")
Adds a property to IfcElement current property set.
Ifcw::ProjectInformation::siteElevation
Dtk_Double64 siteElevation
Definition: IFCWriter.h:76
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
Definition: IFCWriter.h:38
Ifcw::IfcElement
This class provides several parameters for the next ifc entity to be written, as its custom property ...
Definition: IFCWriter.h:456
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:71
Ifcw::IfcElement::SetSubtype
void SetSubtype(Dtk_string inType)
Setter for IfcElement subtype.
Ifcw::typing::predefined::IfcWall
@ IfcWall
Definition: IFCWriter.h:121
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::IfcElementType
A IfcElementType is used to define the common properties of a certain type or style of an entity that...
Definition: IFCWriter.h:297
Ifcw::IfcElement::SetTypeID
void SetTypeID(const Dtk_ID &inID)
Setter for IfcElement IfcElementType ID.
ProcessMultiMeshWall
Dtk_ErrorStatus ProcessMultiMeshWall()
Writes a wall element composed of multiple mesh pieces with custom properties and a GUID.
Definition: testlibifcwrite.cpp:149
Ifcw::ProjectInformation::siteLatitude
Dtk_Double64 siteLatitude
Definition: IFCWriter.h:74
Dtk_MetaData::TypeProperty
@ TypeProperty
Definition: dtk_metadata.hpp:29
Ifcw::WriteOptions
This class provides several options to tune the IFC Writer. It must be provided to Ifcw::InitWrite me...
Definition: IFCWriter.h:29
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.
Ifcw::EndWrite
DtkErrorStatus EndWrite()
Creation of the output file and free the Ifc Writer
Dtk_SmartPtr< Dtk_Entity >
Ifcw::ProjectInformation::siteLongitude
Dtk_Double64 siteLongitude
Definition: IFCWriter.h:75
dtkTypeError
Dtk_string dtkTypeError(Dtk_Int32 errNumero)
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
sampleWriter::CreateMeshCylinder
Dtk_MeshPtr CreateMeshCylinder(int nbpoints)
Mesh Cylinder sample.
Definition: testcreatemesh.cpp:338
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::typing::predefined::IfcColumn
@ IfcColumn
Definition: IFCWriter.h:106
Ifcw::classification::IfcClassificationReference
This class represent a classification reference to be used for an ifc object, e.g....
Definition: IFCWriter.h:249
ProcessPrototypedColumns
Dtk_ErrorStatus ProcessPrototypedColumns(int inColumnCount)
Writes a set of column elements sharing the same prototyped geometry (IfcElementType),...
Definition: testlibifcwrite.cpp:97
Dtk_transfo::addTranslate
void addTranslate(const Dtk_dir &V)
Translate the Dtk_transfo.
sampleWriter::CreateCube
Dtk_BodyPtr CreateCube()
Creates a 100x100x100 mm closed BRep cube body. Builds the full BRep hierarchy (Vertex,...
Definition: testcreatecube.cpp:1325
Ifcw::ProjectInformation
This struct enables the user to define global properties regarding the project, construction site and...
Definition: IFCWriter.h:65
sampleWriter::CreateMeshCuboid
Dtk_MeshPtr CreateMeshCuboid(const Dtk_pnt &inFirstPoint, const Dtk_pnt &inSecondPoint)
Creates an axis-aligned cuboid mesh from two opposite corner points.
Definition: testcreatemesh.cpp:460
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:151
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:191
Dtk_RGB
Definition: dtk_rgb.hpp:8
Ifcw::WriteType
Dtk_ErrorStatus WriteType(const IfcElementType &inType)
Write the type provided in parameter. The type can exists by itself without having entities related t...
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:14
ProcessWallClassification
Dtk_ErrorStatus ProcessWallClassification()
Writes a wall element with a UniFormat classification reference attached to it.
Definition: testlibifcwrite.cpp:63
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 .