DATAKIT API  V2025.1
testlibparasolidwrite.cpp File Reference

Functions

int ParasolidWriteSample (const Dtk_string &inResultDirectory)
 

Function Documentation

◆ ParasolidWriteSample()

int ParasolidWriteSample ( const Dtk_string inResultDirectory)
17 {
18  cout << endl << "----------------------------------------------" << endl;
19  cout << "Parasolid Write start" << endl;
20  // Choosing output directory and file name
21  Dtk_string outputDirectory = inResultDirectory + L"dtk/Parasolid/";
22  outputDirectory.FixPathSeparator();
23  outputDirectory.mkdir();
24  Dtk_string outputFileName0 = outputDirectory + L"sample_listofbody.x_t";
25 
26  // We construct 3 parts
30 
31  // We add the 3 parts in an array
32  Dtk_tab<Dtk_BodyPtr> arrayOfParts;
33  arrayOfParts.push_back( body1 );
34  arrayOfParts.push_back( body2 );
35  arrayOfParts.push_back( body3 );
36 
37  // First we initialize writing with name of files and protection function if needed (3rd parameter)
38  Dtk_bool muteMode = DTK_TRUE; // no log write
39  DtkErrorStatus status = psw_InitFile( outputFileName0, muteMode );
40 
41  if( status != dtkNoError )
42  {
43  cout << "error : " << dtkTypeError( status ).c_str() << endl;
44  return status;
45  }
46 
47 
48  // Then we write the 3 parts constructed
49  Dtk_Size_t i, l = arrayOfParts.size();
50  Dtk_tab<Dtk_ID> returnID;
51  for( i = 0; i < l; ++i )
52  status = psw_WriteBody( arrayOfParts[ i ], returnID );
53 
54  // And free memory allocated for writing
55  status = psw_EndFile( returnID );
56 
57 
58  if( status != dtkNoError )
59  {
60  cout << "error : " << dtkTypeError( status ).c_str() << endl;
61  }
62  else
63  cout << "=> " << outputFileName0.c_str() << endl;
64 
65 
66  // then we write the same 3 part as an assembly that use these parts 2 times
67  Dtk_string outputFileName1 = outputDirectory + L"sample_assemblyofbody.x_t";
68  status = psw_InitFile( outputFileName1, muteMode );
69 
70  // first we register all part ID
71  Dtk_tab<Dtk_ID> partID (l, 1);
72  for( i = 0; i < l; ++i )
73  {
74  returnID.clear();
75  status = psw_WriteBody( arrayOfParts[ i ], returnID );
76  if( returnID.size() > 1 )
77  { // if more than one parasolid body created we decide to create a subassembly
78  Dtk_ID outIdass;
79  status = psw_CreateEmptyAssembly( outIdass );
80  Dtk_transfoPtr MatrixIdentity = Dtk_transfo::create();
81  for( Dtk_Size_t j = 0; j < returnID.size(); j++ )
82  {
83  Dtk_ID outIdInst;
84  status = psw_CreateInstance( outIdass, returnID[ j ], MatrixIdentity, outIdInst );
85  }
86 
87  partID[ i ] = outIdass;
88  status = psw_LinkAttribut( outIdass );
89  }
90  else
91  partID[ i ] = returnID[ 0 ];
92 
93  Dtk_string partName = L"DtkPart";
94  partName.add_int((int)i);
96  info->SetName( partName );
97  info->SetId ( Dtk_Int32 (i + 1) );
98 
99  status = psw_CreateAttribut( partID[ i ], info );
100  }
101 
102  // we create an assembly
103  Dtk_ID assemblyID;
104  status = psw_CreateEmptyAssembly( assemblyID );
105 
106  Dtk_string assName = L"DtkAssembly";
107  Dtk_InfoPtr info = Dtk_Info::create();
108  info->SetName( assName );
109  info->SetId( 5 );
110 
111  status = psw_CreateAttribut( assemblyID, info );
112 
113  // we create each instance of the parts
114  for( i = 0; i < l; ++i )
115  {
117  Matrix1->setOrigin( Dtk_pnt( 100.0, 0.0, 0.0 ) );
118  Dtk_ID outIdInst;
119  status = psw_CreateInstance( assemblyID, partID[ i ], Matrix1, outIdInst );
120 
121  Dtk_string instName = L"DtkInstance";
122  instName.add_int( ( int )i );
123  info->SetName( instName );
124  info->SetId( Dtk_Int32( 10 + i) );
125  status = psw_CreateAttribut( outIdInst, info );
126 
127 
129  Matrix2->setOrigin( Dtk_pnt( 100.0, 100.0, 100.0 ) );
130  status = psw_CreateInstance( assemblyID, partID[ i ], Matrix2, outIdInst );
131 
132  Dtk_string instName2 = L"DtkInstance";
133  instName2.add_int( ( int )(i + l));
134  info->SetName( instName2 );
135  info->SetId( Dtk_Int32( 10 + i + l ) );
136  status = psw_CreateAttribut( outIdInst, info );
137  }
138 
139  status = psw_LinkAttribut( assemblyID );
140 
141  returnID.clear();
142  // And free memory allocated for writing
143  status = psw_EndFile( returnID );
144 
145  if( status != dtkNoError )
146  {
147  cout << "error : " << dtkTypeError( status ).c_str() << endl;
148  }
149  else
150  cout << "=> " << outputFileName1.c_str() << endl;
151 
152  cout << "Parasolid Write end" << endl;
153 
154  return 0;
155 }
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
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_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 ...
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
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()