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

◆ ProcessBasicWall()

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

◆ ProcessMultiMeshWall()

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

◆ ProcessPrototypedColumns()

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

◆ ProcessWallClassification()

Dtk_ErrorStatus ProcessWallClassification ( )
62 {
63  //Create a new set of parameters for the ifc element to be written
64  Ifcw::IfcElement inParameters = Ifcw::IfcElement();
65  inParameters.SetName( L"wallClassified" );
66  inParameters.SetBuildingElementType( Ifcw::IfcWall );
67  //Create an IfcClassification to represent the classification you're using (e.g. : UniFormat, OmniClass, SfB...)
68  //Create the reference in this classification you want to assign to the ifc entity to be written
69  Ifcw::classification::IfcClassification classification = Ifcw::classification::IfcClassification( "ASTM", "E1557", "UniFormat II" );
70  Ifcw::classification::IfcClassificationReference ref = Ifcw::classification::IfcClassificationReference( "https://www.wbdg.org/FFC/VA/VACOST/triservicemoduniformat.pdf", "B201001", "EXTERIOR CLOSURE", classification );
71  inParameters.SetClassificationReference( ref );
72 
73  //Initialize the current object with those parameters
74  Dtk_ErrorStatus errorStatus = Ifcw::InitObject( inParameters );
75  if( errorStatus != dtkNoError )
76  {
77  cout << "Can't write object : " << errorStatus << endl;;
79  }
80 
81  // Create ifc object geometry (mesh)
82  Dtk_pnt wallFirstPoint = Dtk_pnt( 140, -250, 0 );
83  Dtk_pnt wallSecondPoint = Dtk_pnt( 145, -70, 60 );
84  Dtk_MeshPtr mesh = sampleWriter::CreateMeshCuboid( wallFirstPoint, wallSecondPoint );
85 
86  //Write the geometry of our object. Multiple meshes are possible
88 
89  //Write the current object and close it
91  return dtkNoError;
92 }
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.
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 .