DATAKIT API  V2025.1
Sample
//start_of_mainxmtwrite_dtk
#ifdef WIN32
#include <windows.h>
#endif
#include "testwriters.h"
//DATAKIT headers needed
#include "datakit.h"
#include "psw/psw.hpp"
int
ParasolidWriteSample( const Dtk_string &inResultDirectory )
{
cout << endl << "----------------------------------------------" << endl;
cout << "Parasolid Write start" << endl;
// Choosing output directory and file name
Dtk_string outputDirectory = inResultDirectory + L"dtk/Parasolid/";
outputDirectory.FixPathSeparator();
outputDirectory.mkdir();
Dtk_string outputFileName0 = outputDirectory + L"sample_listofbody.x_t";
// We construct 3 parts
// We add the 3 parts in an array
Dtk_tab<Dtk_BodyPtr> arrayOfParts;
arrayOfParts.push_back( body1 );
arrayOfParts.push_back( body2 );
arrayOfParts.push_back( body3 );
// First we initialize writing with name of files and protection function if needed (3rd parameter)
Dtk_bool muteMode = DTK_TRUE; // no log write
DtkErrorStatus status = psw_InitFile( outputFileName0, muteMode );
if( status != dtkNoError )
{
cout << "error : " << dtkTypeError( status ).c_str() << endl;
return status;
}
// Then we write the 3 parts constructed
Dtk_Size_t i, l = arrayOfParts.size();
Dtk_tab<Dtk_ID> returnID;
for( i = 0; i < l; ++i )
status = psw_WriteBody( arrayOfParts[ i ], returnID );
// And free memory allocated for writing
status = psw_EndFile( returnID );
if( status != dtkNoError )
{
cout << "error : " << dtkTypeError( status ).c_str() << endl;
}
else
cout << "=> " << outputFileName0.c_str() << endl;
// then we write the same 3 part as an assembly that use these parts 2 times
Dtk_string outputFileName1 = outputDirectory + L"sample_assemblyofbody.x_t";
status = psw_InitFile( outputFileName1, muteMode );
// first we register all part ID
Dtk_tab<Dtk_ID> partID (l, 1);
for( i = 0; i < l; ++i )
{
returnID.clear();
status = psw_WriteBody( arrayOfParts[ i ], returnID );
if( returnID.size() > 1 )
{ // if more than one parasolid body created we decide to create a subassembly
Dtk_ID outIdass;
status = psw_CreateEmptyAssembly( outIdass );
Dtk_transfoPtr MatrixIdentity = Dtk_transfo::create();
for( Dtk_Size_t j = 0; j < returnID.size(); j++ )
{
Dtk_ID outIdInst;
status = psw_CreateInstance( outIdass, returnID[ j ], MatrixIdentity, outIdInst );
}
partID[ i ] = outIdass;
status = psw_LinkAttribut( outIdass );
}
else
partID[ i ] = returnID[ 0 ];
Dtk_string partName = L"DtkPart";
partName.add_int((int)i);
info->SetName( partName );
info->SetId ( Dtk_Int32 (i + 1) );
status = psw_CreateAttribut( partID[ i ], info );
}
// we create an assembly
Dtk_ID assemblyID;
status = psw_CreateEmptyAssembly( assemblyID );
Dtk_string assName = L"DtkAssembly";
info->SetName( assName );
info->SetId( 5 );
status = psw_CreateAttribut( assemblyID, info );
// we create each instance of the parts
for( i = 0; i < l; ++i )
{
Matrix1->setOrigin( Dtk_pnt( 100.0, 0.0, 0.0 ) );
Dtk_ID outIdInst;
status = psw_CreateInstance( assemblyID, partID[ i ], Matrix1, outIdInst );
Dtk_string instName = L"DtkInstance";
instName.add_int( ( int )i );
info->SetName( instName );
info->SetId( Dtk_Int32( 10 + i) );
status = psw_CreateAttribut( outIdInst, info );
Matrix2->setOrigin( Dtk_pnt( 100.0, 100.0, 100.0 ) );
status = psw_CreateInstance( assemblyID, partID[ i ], Matrix2, outIdInst );
Dtk_string instName2 = L"DtkInstance";
instName2.add_int( ( int )(i + l));
info->SetName( instName2 );
info->SetId( Dtk_Int32( 10 + i + l ) );
status = psw_CreateAttribut( outIdInst, info );
}
status = psw_LinkAttribut( assemblyID );
returnID.clear();
// And free memory allocated for writing
status = psw_EndFile( returnID );
if( status != dtkNoError )
{
cout << "error : " << dtkTypeError( status ).c_str() << endl;
}
else
cout << "=> " << outputFileName1.c_str() << endl;
cout << "Parasolid Write end" << endl;
return 0;
}
//end_of_mainxmtwrite_dtk
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:689
psw_CreateInstance
DtkErrorStatus psw_CreateInstance(Dtk_ID inIdAss, Dtk_ID inIdPart, Dtk_transfoPtr &Matrix, Dtk_ID &outIdInst)
Create an Instance item of a part referenced by inIdPart.
Dtk_Info::SetName
Dtk_ErrorStatus SetName(Dtk_string inName)
psw_InitFile
DtkErrorStatus psw_InitFile(const Dtk_string &inFileOut, Dtk_bool muteMode, Dtk_Int32 inVersion=180)
Initialise a file to be written.
Dtk_transfo::create
static Dtk_SmartPtr< Dtk_transfo > create()
DTK_TRUE
#define DTK_TRUE
Definition: define.h:727
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:712
Dtk_bool
char Dtk_bool
Definition: define.h:725
psw.hpp
Dtk_string::add_int
void add_int(const int integer, int force_unsigned_int=0)
concat an int to the Dtk_string (convert the int to Dtk_string)
psw_CreateAttribut
DtkErrorStatus psw_CreateAttribut(Dtk_ID inIdCompo, Dtk_InfoPtr &info)
Create all attribut attached to a component (body, assembly, instance)
ParasolidWriteSample
int ParasolidWriteSample(const Dtk_string &inResultDirectory)
Definition: testlibparasolidwrite.cpp:16
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:687
psw_CreateEmptyAssembly
DtkErrorStatus psw_CreateEmptyAssembly(Dtk_ID &outIdass)
Create the entry item of an assembly.
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Dtk_Info::SetId
Dtk_ErrorStatus SetId(const Dtk_Int32 &inId)
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.
Dtk_string::mkdir
int mkdir() const
File Utility : Create a Directory.
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:22
psw_WriteBody
Dtk_ErrorStatus psw_WriteBody(Dtk_BodyPtr &inBody)
Writes a Body of a 3D part (3D content of a product), of any kind (solid, shell / faces,...
Dtk_string::FixPathSeparator
void FixPathSeparator()
File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed ...
datakit.h
testcreatecube.hpp
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:85
sampleWriter::CreateCube
Dtk_BodyPtr CreateCube()
Definition: testcreatecube.cpp:1249
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:502
psw_EndFile
DtkErrorStatus psw_EndFile(Dtk_tab< Dtk_ID > &inTabIds, Dtk_bool binForceListOfBody=DTK_FALSE)
Ends the writing of the Parasolid (x_t or x_b) file.
sampleWriter::CreateCurves
Dtk_BodyPtr CreateCurves()
Definition: testcreatecube.cpp:1292
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
testwriters.h
psw_LinkAttribut
DtkErrorStatus psw_LinkAttribut(Dtk_ID inIdAss)
link all attribut attached to an assembly
Dtk_tab::clear
void clear(int no_delete=0)
Resets the Dtk_tab content.
Definition: util_stl_dtk.hpp:351
sampleWriter::CreateOpenShell
void CreateOpenShell(std::map< Dtk_ID, Dtk_EntityPtr > &outArrayTopo, const Dtk_BodyPtr &inDtkBody)
Definition: testcreatecube.cpp:1194
Dtk_Info::create
static Dtk_SmartPtr< Dtk_Info > create()