DATAKIT SDK  V2026.4
testlib3dxmlwrite.cpp File Reference

Functions

DtkErrorStatus _3dxmlWriteSample (const Dtk_string &inResultDirectory)
 Entry point: creates a cube and cylinder mesh then writes them into a sample.3dxml file. More...
 
Dtk_ErrorStatus WriteEntity (const Dtk_MeshPtr &inCubeMesh, const Dtk_MeshPtr &inCylinderMesh)
 Builds the 3DXML product hierarchy with 3 child nodes ( node, cylinder mesh, cube mesh). Demonstrates addInstance3D / addReference3D / addReferenceRep usage. More...
 

Function Documentation

◆ _3dxmlWriteSample()

DtkErrorStatus _3dxmlWriteSample ( const Dtk_string &  inResultDirectory)

Entry point: creates a cube and cylinder mesh then writes them into a sample.3dxml file.

232 {
233  Dtk_MeshPtr CubeMesh;
234  Dtk_MeshPtr CylinderMesh;
235  Dtk_string outputFileName, outputDirectory;
236 
237  std::cout << std::endl << "----------------------------------------------" << std::endl;
238  std::cout << "3dxml Write start" << std::endl;
239 
240  //Choosing output directory and file name
241  outputDirectory = inResultDirectory + L"CatiaV6/";
242  outputDirectory.FixPathSeparator();
243  outputDirectory.mkdir();
244  outputFileName = outputDirectory + L"sample.3dxml";
245 
246  //Creating sample cube meshes
247  CubeMesh = sampleWriter::CreateMeshCube();
248 
249  //Applying render infos (texture + lightmap) to the cube mesh
251 
252  //Creating sample cylinder meshes
253  CylinderMesh = sampleWriter::CreateMeshCylinder( 30 );
254 
255  //Creating hierarchy
256 
257  //Root
258  // |
259  // | __Node(Node_1)
260  // | |
261  // | |
262  // | CylinderMesh(Node_2)
263  // |
264  // | __CubeWireMesh(Node_3)
265  // |
266  // |
267  // | __CylinderMesh(Node_4)
268 
269  _3dxmlw::WriteOptions Options;//no option for the moment
270  Dtk_string inLogFile;//no config for the moment
271 
272  DtkErrorStatus errorStatus = _3dxmlw::InitWrite( outputFileName, inLogFile, Options );
273 
274  if( errorStatus == dtkNoError )
275  {
276  WriteEntity( CubeMesh, CylinderMesh );
277  }
278  else
279  std::cout << "error : " << dtkTypeError( errorStatus ).c_str() << std::endl;
280 
282 
283  if( errorStatus == dtkNoError )
284  std::cout << "=> " << outputFileName.c_str() << std::endl << "3dxml Write end" << std::endl;
285 
286  return errorStatus;
287 }

◆ WriteEntity()

Dtk_ErrorStatus WriteEntity ( const Dtk_MeshPtr &  inCubeMesh,
const Dtk_MeshPtr &  inCylinderMesh 
)

Builds the 3DXML product hierarchy with 3 child nodes ( node, cylinder mesh, cube mesh). Demonstrates addInstance3D / addReference3D / addReferenceRep usage.

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::WriteParameters inParameters2;
108 
109  _3dxmlw::addInstance3D( ChildId_1, ChildId_2, transfo2, Instance_Name_2, metadata_3, inParameters2 ); // 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:688
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:162
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)
Builds the 3DXML product hierarchy with 3 child nodes ( node, cylinder mesh, cube mesh)....
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:71
_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:29
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
sampleWriter::CreateCubeRenderInfos
Dtk_RenderInfosPtr CreateCubeRenderInfos()
Creates a Dtk_RenderInfos object with ambient, diffuse, and specular lighting and a texture for use o...
Definition: testcreatemesh.cpp:501
_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:338
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:60
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:151
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:8
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 .