DATAKIT SDK  V2026.1
testlibparasolidwrite.cpp File Reference

Functions

int ParasolidWriteSample (const Dtk_string &inResultDirectory)
 

Function Documentation

◆ ParasolidWriteSample()

int ParasolidWriteSample ( const Dtk_string inResultDirectory)
13 {
14  cout << endl << "----------------------------------------------" << endl;
15  cout << "Parasolid Write start" << endl;
16  // Choosing output directory and file name
17  Dtk_string outputDirectory = inResultDirectory + L"Parasolid/";
18  outputDirectory.FixPathSeparator();
19  outputDirectory.mkdir();
20  Dtk_string outputFileName0 = outputDirectory + L"sample_listofbody.x_t";
21 
22  // We construct 3 parts
26 
27  // We add the 3 parts in an array
28  Dtk_tab<Dtk_BodyPtr> arrayOfParts;
29  arrayOfParts.push_back( body1 );
30  arrayOfParts.push_back( body2 );
31  arrayOfParts.push_back( body3 );
32 
33  // First we initialize writing with name of files and protection function if needed (3rd parameter)
34  Dtk_bool muteMode = DTK_TRUE; // no log write
35  DtkErrorStatus status = psw_InitFile( outputFileName0, muteMode );
36 
37  if( status != dtkNoError )
38  {
39  cout << "error : " << dtkTypeError( status ).c_str() << endl;
40  return status;
41  }
42 
43 
44  // Then we write the 3 parts constructed
45  Dtk_Size_t i, l = arrayOfParts.size();
46  Dtk_tab<Dtk_ID> returnID;
47  for( i = 0; i < l; ++i )
48  status = psw_WriteBody( arrayOfParts[ i ], returnID );
49 
50  // And free memory allocated for writing
51  status = psw_EndFile( returnID );
52 
53 
54  if( status != dtkNoError )
55  {
56  cout << "error : " << dtkTypeError( status ).c_str() << endl;
57  }
58  else
59  cout << "=> " << outputFileName0.c_str() << endl;
60 
61 
62  // then we write the same 3 part as an assembly that use these parts 2 times
63  Dtk_string outputFileName1 = outputDirectory + L"sample_assemblyofbody.x_t";
64  status = psw_InitFile( outputFileName1, muteMode );
65 
66  // first we register all part ID
67  Dtk_tab<Dtk_ID> partID (l, 1);
68  for( i = 0; i < l; ++i )
69  {
70  returnID.clear();
71  status = psw_WriteBody( arrayOfParts[ i ], returnID );
72  if( returnID.size() > 1 )
73  { // if more than one parasolid body created we decide to create a subassembly
74  Dtk_ID outIdass;
75  status = psw_CreateEmptyAssembly( outIdass );
76  Dtk_transfoPtr MatrixIdentity = Dtk_transfo::create();
77  for( Dtk_Size_t j = 0; j < returnID.size(); j++ )
78  {
79  Dtk_ID outIdInst;
80  status = psw_CreateInstance( outIdass, returnID[ j ], MatrixIdentity, outIdInst );
81  }
82 
83  partID[ i ] = outIdass;
84  status = psw_LinkAttribut( outIdass );
85  }
86  else
87  partID[ i ] = returnID[ 0 ];
88 
89  Dtk_string partName = L"DtkPart";
90  partName.add_int((int)i);
92  info->SetName( partName );
93  info->SetId ( Dtk_Int32 (i + 1) );
94  Dtk_Val MyVal = Dtk_Val("MyValue");
95  info->AddCustomerDefinedAttribute("MyAttribute", MyVal);
96 
97  status = psw_CreateAttribut( partID[ i ], info );
98  }
99 
100  // we create an assembly
101  Dtk_ID assemblyID;
102  status = psw_CreateEmptyAssembly( assemblyID );
103 
104  Dtk_string assName = L"DtkAssembly";
105  Dtk_InfoPtr info = Dtk_Info::create();
106  info->SetName( assName );
107  info->SetId( 5 );
108 
109  status = psw_CreateAttribut( assemblyID, info );
110 
111  // we create each instance of the parts
112  for( i = 0; i < l; ++i )
113  {
115  Matrix1->setOrigin( Dtk_pnt( 100.0, 0.0, 0.0 ) );
116  Dtk_ID outIdInst;
117  status = psw_CreateInstance( assemblyID, partID[ i ], Matrix1, outIdInst );
118 
119  Dtk_string instName = L"DtkInstance";
120  instName.add_int( ( int )i );
121  info->SetName( instName );
122  info->SetId( Dtk_Int32( 10 + i) );
123  status = psw_CreateAttribut( outIdInst, info );
124 
125 
127  Matrix2->setOrigin( Dtk_pnt( 100.0, 100.0, 100.0 ) );
128  status = psw_CreateInstance( assemblyID, partID[ i ], Matrix2, outIdInst );
129 
130  Dtk_string instName2 = L"DtkInstance";
131  instName2.add_int( ( int )(i + l));
132  info->SetName( instName2 );
133  info->SetId( Dtk_Int32( 10 + i + l ) );
134  status = psw_CreateAttribut( outIdInst, info );
135  }
136 
137  status = psw_LinkAttribut( assemblyID );
138 
139  returnID.clear();
140  // And free memory allocated for writing
141  status = psw_EndFile( returnID );
142 
143  if( status != dtkNoError )
144  {
145  cout << "error : " << dtkTypeError( status ).c_str() << endl;
146  }
147  else
148  cout << "=> " << outputFileName1.c_str() << endl;
149 
150  cout << "Parasolid Write end" << endl;
151 
152  return 0;
153 }
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:692
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_Info::AddCustomerDefinedAttribute
Dtk_ErrorStatus AddCustomerDefinedAttribute(Dtk_string name, Dtk_Val val)
Dtk_transfo::create
static Dtk_SmartPtr< Dtk_transfo > create()
DTK_TRUE
#define DTK_TRUE
Definition: define.h:730
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:715
Dtk_bool
char Dtk_bool
Definition: define.h:728
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)
Dtk_Val
Definition: dtk_val.hpp:67
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:690
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:20
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 ...
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:84
sampleWriter::CreateCube
Dtk_BodyPtr CreateCube()
Definition: testcreatecube.cpp:1316
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:503
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:1357
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
psw_LinkAttribut
DtkErrorStatus psw_LinkAttribut(Dtk_ID inIdAss)
link all attributes attached to an assembly
Dtk_tab::clear
void clear(int no_delete=0)
Resets the Dtk_tab content.
Definition: util_stl_dtk.hpp:352
Dtk_Info::create
static Dtk_SmartPtr< Dtk_Info > create()
Calls default constructor to allocate a new object.
sampleWriter::CreateOpenShell
Dtk_BodyPtr CreateOpenShell()
Definition: testcreatecube.cpp:1343