DATAKIT SDK  V2026.1
testlib3dxmlwrite.cpp File Reference

Functions

int _3dxmlWriteSample (const Dtk_string &inResultDirectory)
 
Dtk_ErrorStatus WriteEntity (const Dtk_MeshPtr &inCubeMesh, const Dtk_MeshPtr &inCylinderMesh)
 

Function Documentation

◆ _3dxmlWriteSample()

int _3dxmlWriteSample ( const Dtk_string inResultDirectory)
225 {
226  Dtk_MeshPtr CubeMesh;
227  Dtk_MeshPtr CylinderMesh;
228  Dtk_string outputFileName, outputDirectory;
229 
230  cout << endl << "----------------------------------------------" << endl;
231  cout << "3dxml Write start" << endl;
232 
233  // Choosing output directory and file name
234  outputDirectory = inResultDirectory + L"CatiaV6/";
235  outputDirectory.FixPathSeparator();
236  outputDirectory.mkdir();
237  outputFileName = outputDirectory + L"sample.3dxml";
238 
239  // Cube Sample
240  CubeMesh = sampleWriter::CreateMeshCube();
241 
242  // Cylinder Sample
243  CylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
244 
245  // CREATING HIERARCHY
246 
247  // Root
248  // |
249  // | __Node(Node_1)
250  // | |
251  // | |
252  // | CylinderMesh(Node_2)
253  // |
254  // | __CubeWireMesh(Node_3)
255  // |
256  // |
257  // | __CylinderMesh(Node_4)
258 
259  _3dxmlw::WriteOptions Options;//no option for the moment
260  Dtk_string inLogFile;//no config for the moment
261  DtkErrorStatus errorSt = _3dxmlw::InitWrite( outputFileName, inLogFile, Options );
262 
263  if( errorSt == dtkNoError )
264  {
265  WriteEntity( CubeMesh, CylinderMesh );
266  }
267  else
268  cout << "error : " << dtkTypeError( errorSt ).c_str() << endl;
269 
271 
272  if( errorSt == dtkNoError )
273  cout << "=> " << outputFileName.c_str() << endl << "3dxml Write end" << endl;
274 
275  return errorSt;
276 }

◆ WriteEntity()

Dtk_ErrorStatus WriteEntity ( const Dtk_MeshPtr inCubeMesh,
const Dtk_MeshPtr inCylinderMesh 
)
13 {
14  //CREATE ROOT
15  Dtk_ID RootParentId = 1;//RootParentId: The root id must be equal to 1
16  //ROOT REFERENCE3D
17  Dtk_string RootNodeName = L"Root";
18  //metadata:
19  //V_description == Description in catiav5 software
20  //V_version == Revision in catiav5 software
21  //V_Name == Definition in catiav5 software
22  Dtk_tab<Dtk_MetaDataPtr> metadata;
23  _3dxmlw::addReference3D( RootNodeName, RootParentId, metadata );
24  //END ROOT REFERENCE3D
25  //END CREATE ROOT
26 
27  //IT CAN ALSO CONTAIN SOME INSTANCES
28 
29  //SAMPLE CREATE 3 CHILDRENS
30 
31 
32 
33  //FIRST CHILD
34  Dtk_ID ChildId_1 = 2;//ChilId_1 = put your component id
35 
36  //FIRST CHILD INSTANCE
37  Dtk_transfo transfo1;
38  Dtk_string Instance_Name_1 = L"Node_1";//Instance_Name put your instance node name
39  _3dxmlw::WriteParameters inParameters;
40  inParameters.SetBlankedStatus( 0 );
41  inParameters.SetColor( Dtk_RGB( 0, 0, 255 ) );
42 
43  transfo1.setXdir( Dtk_dir( 1.0, 0.0, 0.0 ) );
44  transfo1.setYdir( Dtk_dir( 0.0, 1.0, 0.0 ) );
45  transfo1.setZdir( Dtk_dir( 0.0, 0.0, 1.0 ) );
46  transfo1.setOrigin( Dtk_pnt( 0.0, 0.0, 0.0 ) );
47 
48  //metadata:
49  //V_description == Description in catiav5 software; only V_description for instance
50  Dtk_MetaDataPtr metadata_1;
51  metadata_1 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"V_description", L"description" );
52 
53  _3dxmlw::addInstance3D( RootParentId, ChildId_1, transfo1, Instance_Name_1, metadata_1, inParameters ); // add a new instance3D linked father reference3D to child reference3D
54  //END FIRST CHILD INSTANCE
55 
56  //CREATE FIRST CHILD PROTOTYPE
57  if( !_3dxmlw::isAlreadyAddComponent( ChildId_1 ) ) // don't create a component already viewed. Is instantiate by an instance
58  {
59  //FIRST CHILD REFERENCE3D
60  Dtk_string NodeName = L"Node";
61  Dtk_tab<Dtk_MeshPtr> tmpMeshs;
62  // We've got all possible meshs for this component, create a unique 3DRep for theses meshs
63  if( tmpMeshs.size() > 0 )
64  {
65  _3dxmlw::addReferenceRep( tmpMeshs, NodeName, ChildId_1 );
66  }
67 
68  //metadata:
69  //V_description == Description in catiav5 software
70  //V_version == Revision in catiav5 software
71  //V_Name == Definition in catiav5 software
72  Dtk_tab<Dtk_MetaDataPtr> metadata_2;
73  Dtk_MetaDataPtr tmpMetadata = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"V_description", L"description" );
74  Dtk_MetaDataPtr tmpMetadata1 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"V_version", L"revision" );
75  Dtk_MetaDataPtr tmpMetadata2 = Dtk_MetaData::CreateMetaData( Dtk_MetaData::TypeProperty, L"V_Name", L"definition" );
76 
77  metadata_2.push_back( tmpMetadata );
78  metadata_2.push_back( tmpMetadata1 );
79  metadata_2.push_back( tmpMetadata2 );
80 
81  _3dxmlw::addReference3D( NodeName, ChildId_1, metadata_2 );
82  //END CHILD REFERENCE3D
83  }
84  //END FIRST CHILD PROTOTYPE
85  //END CREATE FIRST CHILD PROTOTYPE
86 
87  //SUB CHILD 1
88  Dtk_ID ChildId_2 = 3;//ChilId_2 = put your component id
89 
90  //CHILD 2 INSTANCE
91  Dtk_transfo transfo2;
92  Dtk_string Instance_Name_2 = L"Node_2";//Instance_Name put your instance node name
93 
94  transfo2.setXdir( Dtk_dir( 1.0, 0.0, 0.0 ) );
95  transfo2.setYdir( Dtk_dir( 0.0, 1.0, 0.0 ) );
96  transfo2.setZdir( Dtk_dir( 0.0, 0.0, 1.0 ) );
97  transfo2.setOrigin( Dtk_pnt( 0.0, 0.0, 200.0 ) );
98 
99 
100  //metadata:
101  //V_description == Description in catiav5 software; only V_description for instance
102  Dtk_MetaDataPtr metadata_3;
103  _3dxmlw::addInstance3D( ChildId_1, ChildId_2, transfo2, Instance_Name_2, metadata_3 ); // add a new instance3D linked father reference3D to child reference3D
104  //END CHILD 2 INSTANCE
105 
106  //CREATE CHILD 2 PROTOTYPE
107  if( !_3dxmlw::isAlreadyAddComponent( ChildId_2 ) ) // don't create a component already viewed. Is instantiate by an instance
108  {
109  //CHILD 2 REFERENCE3D
110  Dtk_string NodeName = L"CylinderMesh";
111  Dtk_tab<Dtk_MeshPtr> tmpMeshs_2;
112  tmpMeshs_2.push_back( inCylinderMesh );
113  // We've got all possible meshs for this component, create a unique 3DRep for theses meshs
114  if( tmpMeshs_2.size() > 0 )
115  {
116  _3dxmlw::addReferenceRep( tmpMeshs_2, NodeName, ChildId_2 );
117  }
118 
119  //metadata:
120  //V_description == Description in catiav5 software
121  //V_version == Revision in catiav5 software
122  //V_Name == Definition in catiav5 software
123  Dtk_tab<Dtk_MetaDataPtr> metadata_4;
124  _3dxmlw::addReference3D( NodeName, ChildId_2, metadata_4 );
125  //END CHILD 2 REFERENCE3D
126  }
127  //END CREATE CHILD 2 PROTOTYPE
128  //END SUB CHILD 1
129 
130 
131 
132  //SECOND CHILD
133  Dtk_ID ChildId_3 = 4;//ChilId_3 = put your component id
134 
135  //CHILD 3 INSTANCE
136  Dtk_transfo transfo3;
137  Dtk_string Instance_Name_3 = L"Node_3";//Instance_Name put your instance node name
138 
139  transfo3.setXdir( Dtk_dir( 1.0, 0.0, 0.0 ) );
140  transfo3.setYdir( Dtk_dir( 0.0, 1.0, 0.0 ) );
141  transfo3.setZdir( Dtk_dir( 0.0, 0.0, 1.0 ) );
142  transfo3.setOrigin( Dtk_pnt( 0.0, 200.0, 0.0 ) );
143 
144 
145  //metadata:
146  //V_description == Description in catiav5 software; only V_description for instance
147  Dtk_MetaDataPtr metadata_5;
148  _3dxmlw::addInstance3D( RootParentId, ChildId_3, transfo3, Instance_Name_3, metadata_5 ); // add a new instance3D linked father reference3D to child reference3D
149  //END CHILD 3 INSTANCE
150 
151  //CREATE SECOND CHILD PROTOTYPE
152  if( !_3dxmlw::isAlreadyAddComponent( ChildId_3 ) ) // don't create a component already viewed. Is instantiate by an instance
153  {
154  //CHILD 3 REFERENCE3D
155  Dtk_string NodeName = L"CubeWireMesh";
156  Dtk_tab<Dtk_MeshPtr> tmpMeshs_3;
157  tmpMeshs_3.push_back( inCubeMesh );
158  // We've got all possible meshs for this component, create a unique 3DRep for theses meshs
159  if( tmpMeshs_3.size() > 0 )
160  {
161  _3dxmlw::addReferenceRep( tmpMeshs_3, NodeName, ChildId_3 );
162  }
163 
164  //metadata:
165  //V_description == Description in catiav5 software
166  //V_version == Revision in catiav5 software
167  //V_Name == Definition in catiav5 software
168  Dtk_tab<Dtk_MetaDataPtr> metadata_6;
169  _3dxmlw::addReference3D( NodeName, ChildId_3, metadata_6 );
170  //END CHILD 3 REFERENCE3D
171  }
172  //END CREATE SECOND CHILD PROTOTYPE
173  //END SECOND CHILD
174 
175 
176 
177  //THIRD CHILD
178  Dtk_ID ChildId_4 = 3;//ChilId_4 = put your component id; ChildId_4 = 3 is the same with ChildId_2
179 
180  //CHILD 4 INSTANCE
181  Dtk_transfo transfo4;
182  Dtk_string Instance_Name_4 = L"Node_4";//Instance_Name put your instance node name
183 
184  transfo4.setXdir( Dtk_dir( 1.0, 0.0, 0.0 ) );
185  transfo4.setYdir( Dtk_dir( 0.0, 1.0, 0.0 ) );
186  transfo4.setZdir( Dtk_dir( 0.0, 0.0, 1.0 ) );
187  transfo4.setOrigin( Dtk_pnt( -200, 200, 0.0 ) );
188 
189  //metadata:
190  //V_description == Description in catiav5 software; only V_description for instance
191  Dtk_MetaDataPtr metadata_7;
192  _3dxmlw::addInstance3D( RootParentId, ChildId_4, transfo4, Instance_Name_4, metadata_7 ); // add a new instance3D linked father reference3D to child reference3D
193  //END CHILD 4 INSTANCE
194 
195  //CREATE THIRD CHILD PROTOTYPE
196  if( !_3dxmlw::isAlreadyAddComponent( ChildId_4 ) ) // don't create a component already viewed. Is instantiate by an instance
197  {
198  //CHILD 4 REFERENCE3D
199  Dtk_string NodeName = L"Mesh";
200  Dtk_tab<Dtk_MeshPtr> tmpMeshs_4;
201  // We've got all possible meshs for this component, create a unique 3DRep for theses meshs
202  if( tmpMeshs_4.size() > 0 )
203  {
204  _3dxmlw::addReferenceRep( tmpMeshs_4, NodeName, ChildId_4 );
205  }
206 
207  //metadata:
208  //V_description == Description in catiav5 software
209  //V_version == Revision in catiav5 software
210  //V_Name == Definition in catiav5 software
211  Dtk_tab<Dtk_MetaDataPtr> metadata_8;
212  _3dxmlw::addReference3D( NodeName, ChildId_4, metadata_8 );
213  //END CHILD 4 REFERENCE3D
214  }
215  //END CREATE THIRD CHILD PROTOTYPE
216  //END THIRD CHILD
217 
218  return dtkNoError;
219 }
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:692
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
sampleWriter::CreateMeshCube
Dtk_MeshPtr CreateMeshCube()
Mesh Cube sample.
Definition: testcreatemesh.cpp:204
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:53
_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:12
_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:334
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:20
_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 ...
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:84
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:503
_3dxmlw::InitWrite
DtkErrorStatus InitWrite(const Dtk_string &inOutputFile, const Dtk_string &inLogFile, WriteOptions &inOptions)
Initialize the 3dxmlw Writer
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:147
Dtk_tab::push_back
void push_back(const T &x)
Inserts an element at the end of the array.
Definition: util_stl_dtk.hpp:416
_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:14
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 .