DATAKIT API  V2025.1
3DXML Write Sample
#ifdef WIN32
#include <windows.h>
#endif
//DATAKIT headers needed
#include "datakit.h"
using namespace std;
//start_of_main3dxmlmeshwrite
Dtk_ErrorStatus WriteEntity( const Dtk_MeshPtr & inCubeMesh, const Dtk_MeshPtr & inCylinderMesh )
{
Dtk_ID inComponentId = 1;
//CREATE ROOT
Dtk_ID RootParentId = 1;//RootParentId: The root id must be equal to 1
//ROOT REFERENCE3D
Dtk_string RootNodeName = L"Root";
//metadata:
//V_description == Description in catiav5 software
//V_version == Revision in catiav5 software
//V_Name == Definition in catiav5 software
_3dxmlw::addReference3D( RootNodeName, RootParentId, metadata );
//END ROOT REFERENCE3D
//END CREATE ROOT
//IT CAN ALSO CONTAIN SOME INSTANCES
//SAMPLE CREATE 3 CHILDRENS
//FIRST CHILD
Dtk_ID ChildId_1 = 2;//ChilId_1 = put your component id
//FIRST CHILD INSTANCE
Dtk_transfo transfo1;
Dtk_string Instance_Name_1 = L"Node_1";//Instance_Name put your instance node name
inParameters.SetBlankedStatus( 0 );
inParameters.SetColor( Dtk_RGB( 0, 0, 255 ) );
transfo1.setXdir( Dtk_dir( 1.0, 0.0, 0.0 ) );
transfo1.setYdir( Dtk_dir( 0.0, 1.0, 0.0 ) );
transfo1.setZdir( Dtk_dir( 0.0, 0.0, 1.0 ) );
transfo1.setOrigin( Dtk_pnt( 0.0, 0.0, 0.0 ) );
//metadata:
//V_description == Description in catiav5 software; only V_description for instance
Dtk_MetaDataPtr metadata_1;
metadata_1 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"V_description", L"description" );
_3dxmlw::addInstance3D( RootParentId, ChildId_1, transfo1, Instance_Name_1, metadata_1, inParameters ); // add a new instance3D linked father reference3D to child reference3D
//END FIRST CHILD INSTANCE
//CREATE FIRST CHILD PROTOTYPE
if( !_3dxmlw::isAlreadyAddComponent( ChildId_1 ) ) // don't create a component already viewed. Is instantiate by an instance
{
//FIRST CHILD REFERENCE3D
Dtk_string NodeName = L"Node";
// We've got all possible meshs for this component, create a unique 3DRep for theses meshs
if( tmpMeshs.size() > 0 )
{
_3dxmlw::addReferenceRep( tmpMeshs, NodeName, ChildId_1 );
}
//metadata:
//V_description == Description in catiav5 software
//V_version == Revision in catiav5 software
//V_Name == Definition in catiav5 software
Dtk_MetaDataPtr tmpMetadata = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"V_description", L"description" );
Dtk_MetaDataPtr tmpMetadata1 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"V_version", L"revision" );
Dtk_MetaDataPtr tmpMetadata2 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"V_Name", L"definition" );
metadata_2.push_back( tmpMetadata );
metadata_2.push_back( tmpMetadata1 );
metadata_2.push_back( tmpMetadata2 );
_3dxmlw::addReference3D( NodeName, ChildId_1, metadata_2 );
//END CHILD REFERENCE3D
}
//END FIRST CHILD PROTOTYPE
//END CREATE FIRST CHILD PROTOTYPE
//SUB CHILD 1
Dtk_ID ChildId_2 = 3;//ChilId_2 = put your component id
//CHILD 2 INSTANCE
Dtk_transfo transfo2;
Dtk_string Instance_Name_2 = L"Node_2";//Instance_Name put your instance node name
transfo2.setXdir( Dtk_dir( 1.0, 0.0, 0.0 ) );
transfo2.setYdir( Dtk_dir( 0.0, 1.0, 0.0 ) );
transfo2.setZdir( Dtk_dir( 0.0, 0.0, 1.0 ) );
transfo2.setOrigin( Dtk_pnt( 0.0, 0.0, 200.0 ) );
//metadata:
//V_description == Description in catiav5 software; only V_description for instance
Dtk_MetaDataPtr metadata_3;
_3dxmlw::addInstance3D( ChildId_1, ChildId_2, transfo2, Instance_Name_2, metadata_3 ); // add a new instance3D linked father reference3D to child reference3D
//END CHILD 2 INSTANCE
//CREATE CHILD 2 PROTOTYPE
if( !_3dxmlw::isAlreadyAddComponent( ChildId_2 ) ) // don't create a component already viewed. Is instantiate by an instance
{
//CHILD 2 REFERENCE3D
Dtk_string NodeName = L"CylinderMesh";
tmpMeshs_2.push_back( inCylinderMesh );
// We've got all possible meshs for this component, create a unique 3DRep for theses meshs
if( tmpMeshs_2.size() > 0 )
{
_3dxmlw::addReferenceRep( tmpMeshs_2, NodeName, ChildId_2 );
}
//metadata:
//V_description == Description in catiav5 software
//V_version == Revision in catiav5 software
//V_Name == Definition in catiav5 software
_3dxmlw::addReference3D( NodeName, ChildId_2, metadata_4 );
//END CHILD 2 REFERENCE3D
}
//END CREATE CHILD 2 PROTOTYPE
//END SUB CHILD 1
//SECOND CHILD
Dtk_ID ChildId_3 = 4;//ChilId_3 = put your component id
//CHILD 3 INSTANCE
Dtk_transfo transfo3;
Dtk_string Instance_Name_3 = L"Node_3";//Instance_Name put your instance node name
transfo3.setXdir( Dtk_dir( 1.0, 0.0, 0.0 ) );
transfo3.setYdir( Dtk_dir( 0.0, 1.0, 0.0 ) );
transfo3.setZdir( Dtk_dir( 0.0, 0.0, 1.0 ) );
transfo3.setOrigin( Dtk_pnt( 0.0, 200.0, 0.0 ) );
//metadata:
//V_description == Description in catiav5 software; only V_description for instance
Dtk_MetaDataPtr metadata_5;
_3dxmlw::addInstance3D( RootParentId, ChildId_3, transfo3, Instance_Name_3, metadata_5 ); // add a new instance3D linked father reference3D to child reference3D
//END CHILD 3 INSTANCE
//CREATE SECOND CHILD PROTOTYPE
if( !_3dxmlw::isAlreadyAddComponent( ChildId_3 ) ) // don't create a component already viewed. Is instantiate by an instance
{
//CHILD 3 REFERENCE3D
Dtk_string NodeName = L"CubeWireMesh";
tmpMeshs_3.push_back( inCubeMesh );
// We've got all possible meshs for this component, create a unique 3DRep for theses meshs
if( tmpMeshs_3.size() > 0 )
{
_3dxmlw::addReferenceRep( tmpMeshs_3, NodeName, ChildId_3 );
}
//metadata:
//V_description == Description in catiav5 software
//V_version == Revision in catiav5 software
//V_Name == Definition in catiav5 software
_3dxmlw::addReference3D( NodeName, ChildId_3, metadata_6 );
//END CHILD 3 REFERENCE3D
}
//END CREATE SECOND CHILD PROTOTYPE
//END SECOND CHILD
//THIRD CHILD
Dtk_ID ChildId_4 = 3;//ChilId_4 = put your component id; ChildId_4 = 3 is the same with ChildId_2
//CHILD 4 INSTANCE
Dtk_transfo transfo4;
Dtk_string Instance_Name_4 = L"Node_4";//Instance_Name put your instance node name
transfo4.setXdir( Dtk_dir( 1.0, 0.0, 0.0 ) );
transfo4.setYdir( Dtk_dir( 0.0, 1.0, 0.0 ) );
transfo4.setZdir( Dtk_dir( 0.0, 0.0, 1.0 ) );
transfo4.setOrigin( Dtk_pnt( -200, 200, 0.0 ) );
//metadata:
//V_description == Description in catiav5 software; only V_description for instance
Dtk_MetaDataPtr metadata_7;
_3dxmlw::addInstance3D( RootParentId, ChildId_4, transfo4, Instance_Name_4, metadata_7 ); // add a new instance3D linked father reference3D to child reference3D
//END CHILD 4 INSTANCE
//CREATE THIRD CHILD PROTOTYPE
if( !_3dxmlw::isAlreadyAddComponent( ChildId_4 ) ) // don't create a component already viewed. Is instantiate by an instance
{
//CHILD 4 REFERENCE3D
Dtk_string NodeName = L"Mesh";
// We've got all possible meshs for this component, create a unique 3DRep for theses meshs
if( tmpMeshs_4.size() > 0 )
{
_3dxmlw::addReferenceRep( tmpMeshs_4, NodeName, ChildId_4 );
}
//metadata:
//V_description == Description in catiav5 software
//V_version == Revision in catiav5 software
//V_Name == Definition in catiav5 software
_3dxmlw::addReference3D( NodeName, ChildId_4, metadata_8 );
//END CHILD 4 REFERENCE3D
}
//END CREATE THIRD CHILD PROTOTYPE
//END THIRD CHILD
return dtkNoError;
}
int
_3dxmlWriteSample( const Dtk_string &inResultDirectory )
{
Dtk_MeshPtr CubeMesh;
Dtk_MeshPtr CylinderMesh;
Dtk_string outputFileName, outputDirectory;
cout << endl << "----------------------------------------------" << endl;
cout << "3dxml Write start" << endl;
// Choosing output directory and file name
outputDirectory = inResultDirectory + L"dtk/CatiaV6/";
outputDirectory.FixPathSeparator();
outputDirectory.mkdir();
outputFileName = outputDirectory + L"sample.3dxml";
// Cube Sample
// Cylinder Sample
CylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
// CREATING HIERARCHY
// Root
// |
// | __Node(Node_1)
// | |
// | |
// | CylinderMesh(Node_2)
// |
// | __CubeWireMesh(Node_3)
// |
// |
// | __CylinderMesh(Node_4)
_3dxmlw::WriteOptions Options;//no option for the moment
Dtk_string inLogFile;//no config for the moment
DtkErrorStatus errorSt = _3dxmlw::InitWrite( outputFileName, inLogFile, Options );
if( errorSt == dtkNoError )
{
WriteEntity( CubeMesh, CylinderMesh );
}
else
cout << "error : " << dtkTypeError( errorSt ).c_str() << endl;
if( errorSt == dtkNoError )
cout << "=> " << outputFileName.c_str() << endl << "3dxml Write end" << endl;
return errorSt;
}
//end_of_main3dxmlmeshwrite
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:689
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
3dxmlw.hpp
sampleWriter::CreateMeshCube
Dtk_MeshPtr CreateMeshCube()
Mesh Cube sample.
Definition: testcreatemesh.cpp:207
Dtk_transfo::setOrigin
void setOrigin(const Dtk_pnt &O)
Set a new O center point.
Dtk_transfo::setZdir
void setZdir(const Dtk_dir &Z)
Set a new Z vector.
_3dxmlw::WriteOptions
This class provides several options to tune 3dxml Writer. It must be provided to _3dxmlw::InitWrite m...
Definition: 3dxmlw.hpp:89
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
_3dxmlw::addInstance3D
void addInstance3D(Dtk_ID parentId, Dtk_ID ref3dId, const Dtk_transfo &matrix, const Dtk_string &objectName, Dtk_MetaDataPtr &inMetadata, const WriteParameters &inParameters=WriteParameters())
Create Instance3D node.
_3dxmlw::addReference3D
void addReference3D(const Dtk_string &inName, Dtk_ID inComponentId, Dtk_tab< Dtk_MetaDataPtr > &inMetadata)
Create Reference3D node.
Dtk_transfo::setXdir
void setXdir(const Dtk_dir &X)
Set a new X vector.
WriteEntity
Dtk_ErrorStatus WriteEntity(const Dtk_MeshPtr &inCubeMesh, const Dtk_MeshPtr &inCylinderMesh)
Definition: testlib3dxmlwrite.cpp:16
_3dxmlw::EndWrite
DtkErrorStatus EndWrite()
Creation of the output file and free the 3dxmlw Writer
_3dxmlw::WriteParameters::SetColor
void SetColor(const Dtk_RGB &inColor)
Sets the color for the written instance node.
Definition: 3dxmlw.hpp:45
_3dxmlw::WriteParameters
This class provides several parameters to tunes 3dxml Writter. It must be provided to addInstance3D m...
Definition: 3dxmlw.hpp:15
Dtk_MetaData::TypeProperty
@ TypeProperty
Definition: dtk_metadata.hpp:28
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
_3dxmlw::isAlreadyAddComponent
Dtk_bool isAlreadyAddComponent(Dtk_ID inCurrentChildId)
Don't create a component already viewed. Is instantiate by an instance.
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
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:337
Dtk_transfo::setYdir
void setYdir(const Dtk_dir &Y)
Set a new Y vector.
Dtk_string::mkdir
int mkdir() const
File Utility : Create a Directory.
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:22
_3dxmlw::WriteParameters::SetBlankedStatus
void SetBlankedStatus(const Dtk_Int32 inBlanked)
Sets the blanked status for the written instance node.
Definition: 3dxmlw.hpp:34
Dtk_string::FixPathSeparator
void FixPathSeparator()
File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed ...
datakit.h
testcreatemesh.hpp
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:85
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:502
_3dxmlw::InitWrite
DtkErrorStatus InitWrite(const Dtk_string &inOutputFile, const Dtk_string &inLogFile, WriteOptions &inOptions)
Initialize the 3dxmlw Writer
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:140
Dtk_tab::push_back
void push_back(const T &x)
Inserts an element at the end of the array.
Definition: util_stl_dtk.hpp:415
_3dxmlw::addReferenceRep
void addReferenceRep(const Dtk_tab< Dtk_MeshPtr > &inMesh, const Dtk_string &inName, Dtk_Size_t inComponentId)
Create ReferenceRep node.
Dtk_RGB
Definition: dtk_rgb.hpp:7
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15
_3dxmlWriteSample
int _3dxmlWriteSample(const Dtk_string &inResultDirectory)
Definition: testlib3dxmlwrite.cpp:230
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 .