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

◆ WriteEntity()

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