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

◆ WriteEntity()

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