DATAKIT SDK  V2026.4
LoadBodiesIntoSession.hpp File Reference

Go to the source code of this file.

Functions

void ActivatePsMemory (bool inActivate)
 
void ActivatePsSession (bool inActivate)
 
void ActivatePsTraverse (bool inActivate)
 
void EnumerateBodiesInSession ()
 
bool IsPsMemoryActivated ()
 
bool IsPsSessionActivated ()
 
bool IsPsTraverseActivated ()
 
void LoadAssemblyIntoPsSession (const Dtk_string &inInputFile)
 
void LoadBodiesIntoPsSession (const Dtk_string &inXtFile)
 
void LoadBodiesIntoPsSessionFromStream (const Dtk_tab< char > &inStream)
 
void ReceiveBodiesIntoCurrentPsSession (const Dtk_string &inXtFile)
 
void ReceiveBodiesIntoCurrentPsSessionFromStream (const Dtk_tab< char > &inStream)
 
void StartSharedPsSession ()
 
void StopSharedPsSession ()
 

Function Documentation

◆ ActivatePsMemory()

void ActivatePsMemory ( bool  inActivate)
44 { s_psMemoryActivated = inActivate; }

◆ ActivatePsSession()

void ActivatePsSession ( bool  inActivate)
43 { s_psSessionActivated = inActivate; }

◆ ActivatePsTraverse()

void ActivatePsTraverse ( bool  inActivate)
45 { s_psTraverseActivated = inActivate; }

◆ EnumerateBodiesInSession()

void EnumerateBodiesInSession ( )
148 {
149  PK_PARTITION_t partition = 0;
150  PK_SESSION_ask_curr_partition( &partition );
151 
152  int nBodies = 0;
153  PK_BODY_t* bodies = nullptr;
154  PK_PARTITION_ask_bodies( partition, &nBodies, &bodies );
155  cout << "Bodies in active partition: " << nBodies << endl;
156 
157  for( int i = 0; i < nBodies; ++i )
158  {
159  PK_BODY_t body = bodies[ i ];
160 
161  PK_BODY_type_t bodyType = 0;
162  PK_BODY_ask_type( body, &bodyType );
163 
164  int nFaces = 0;
165  PK_FACE_t* faces = nullptr;
166  PK_ERROR_code_t fErr = PK_BODY_ask_faces( body, &nFaces, &faces );
167 
168  const char* typeName = "unknown";
169  if ( bodyType == PK_BODY_type_solid_c ) typeName = "solid";
170  else if( bodyType == PK_BODY_type_sheet_c ) typeName = "sheet";
171  else if( bodyType == PK_BODY_type_wire_c ) typeName = "wire";
172  else if( bodyType == PK_BODY_type_acorn_c ) typeName = "acorn";
173  else if( bodyType == PK_BODY_type_general_c ) typeName = "general";
174 
175  if( fErr == PK_ERROR_none )
176  {
177  cout << " Body[" << i << "] tag=" << body
178  << " type=" << typeName
179  << " faces=" << nFaces << endl;
180  if( faces ) PK_MEMORY_free( faces );
181  }
182  else
183  {
184  cout << " Body[" << i << "] tag=" << body
185  << " type=" << typeName
186  << " PK_BODY_ask_faces error=" << fErr << endl;
187  }
188  }
189 
190  if( bodies ) PK_MEMORY_free( bodies );
191 }

◆ IsPsMemoryActivated()

bool IsPsMemoryActivated ( )
48 { return s_psMemoryActivated; }

◆ IsPsSessionActivated()

bool IsPsSessionActivated ( )
47 { return s_psSessionActivated; }

◆ IsPsTraverseActivated()

bool IsPsTraverseActivated ( )
49 { return s_psTraverseActivated; }

◆ LoadAssemblyIntoPsSession()

void LoadAssemblyIntoPsSession ( const Dtk_string &  inInputFile)

◆ LoadBodiesIntoPsSession()

void LoadBodiesIntoPsSession ( const Dtk_string &  inXtFile)
199 {
200  cout << "\n--- Parasolid session: loading \""
201  << inXtFile.c_str() << "\" from disk ---" << endl;
202 
203  SetPSchema();
204  StartPsSession();
205 
206  PK_PART_receive_o_t recvOpts;
207  PK_PART_receive_o_m( recvOpts );
208 
209  int nParts = 0;
210  PK_PART_t* parts = nullptr;
211  PK_ERROR_code_t pkErr = PK_PART_receive(
212  inXtFile.c_str(), &recvOpts, &nParts, &parts );
213 
214  if( pkErr != PK_ERROR_none )
215  {
216  cout << "PK_PART_receive failed, error code: " << pkErr << endl;
217  StopPsSession();
218  return;
219  }
220  cout << "PK_PART_receive: " << nParts << " part(s) received." << endl;
221 
223 
224  if( parts ) PK_MEMORY_free( parts );
225 
226  StopPsSession();
227  cout << "--- Parasolid session closed ---" << endl;
228 }

◆ LoadBodiesIntoPsSessionFromStream()

void LoadBodiesIntoPsSessionFromStream ( const Dtk_tab< char > &  inStream)
237 {
238  if( inStream.size() == 0 )
239  {
240  cout << "Warning: in-memory stream is empty, nothing to load." << endl;
241  return;
242  }
243 
244  cout << "\n--- Parasolid session: loading "
245  << inStream.size() << " bytes from in-memory stream ---" << endl;
246 
247  SetPSchema();
248  StartPsSession();
249 
250  // Map the Dtk_tab<char> buffer to a single PK_MEMORY_block_t.
251  PK_MEMORY_block_t block;
252  block.next = nullptr;
253  block.n_bytes = static_cast<size_t>( inStream.size() );
254  block.bytes = &inStream[ 0 ];
255 
256  PK_PART_receive_o_t recvOpts;
257  PK_PART_receive_o_m( recvOpts );
258 
259  int nParts = 0;
260  PK_PART_t* parts = nullptr;
261  PK_ERROR_code_t pkErr = PK_PART_receive_b( block, &recvOpts, &nParts, &parts );
262 
263  if( pkErr != PK_ERROR_none )
264  {
265  cout << "PK_PART_receive_b failed, error code: " << pkErr << endl;
266  StopPsSession();
267  return;
268  }
269  cout << "PK_PART_receive_b: " << nParts << " part(s) received." << endl;
270 
272 
273  if( parts ) PK_MEMORY_free( parts );
274 
275  StopPsSession();
276  cout << "--- Parasolid session closed ---" << endl;
277 }

◆ ReceiveBodiesIntoCurrentPsSession()

void ReceiveBodiesIntoCurrentPsSession ( const Dtk_string &  inXtFile)
291 {
292  cout << "\n--- Receiving \""
293  << inXtFile.c_str()
294  << "\" into existing Parasolid session ---" << endl;
295 
296  PK_PART_receive_o_t recvOpts;
297  PK_PART_receive_o_m( recvOpts );
298 
299  int nParts = 0;
300  PK_PART_t* parts = nullptr;
301  PK_ERROR_code_t pkErr = PK_PART_receive(
302  inXtFile.c_str(), &recvOpts, &nParts, &parts );
303 
304  if( pkErr != PK_ERROR_none )
305  {
306  cout << "PK_PART_receive failed, error code: " << pkErr << endl;
307  return;
308  }
309  cout << "PK_PART_receive: " << nParts << " part(s) received." << endl;
310 
311  if( parts ) PK_MEMORY_free( parts );
312 }

◆ ReceiveBodiesIntoCurrentPsSessionFromStream()

void ReceiveBodiesIntoCurrentPsSessionFromStream ( const Dtk_tab< char > &  inStream)
320 {
321  if( inStream.size() == 0 )
322  {
323  cout << "Warning: in-memory stream is empty, nothing to receive." << endl;
324  return;
325  }
326 
327  cout << "\n--- Receiving "
328  << inStream.size()
329  << " bytes from in-memory stream into existing Parasolid session ---" << endl;
330 
331  PK_MEMORY_block_t block;
332  block.next = nullptr;
333  block.n_bytes = static_cast<size_t>( inStream.size() );
334  block.bytes = &inStream[ 0 ];
335 
336  PK_PART_receive_o_t recvOpts;
337  PK_PART_receive_o_m( recvOpts );
338 
339  int nParts = 0;
340  PK_PART_t* parts = nullptr;
341  PK_ERROR_code_t pkErr = PK_PART_receive_b( block, &recvOpts, &nParts, &parts );
342 
343  if( pkErr != PK_ERROR_none )
344  {
345  cout << "PK_PART_receive_b failed, error code: " << pkErr << endl;
346  return;
347  }
348  cout << "PK_PART_receive_b: " << nParts << " part(s) received." << endl;
349 
350  if( parts ) PK_MEMORY_free( parts );
351 }

◆ StartSharedPsSession()

void StartSharedPsSession ( )
140 { SetPSchema(); StartPsSession(); }

◆ StopSharedPsSession()

void StopSharedPsSession ( )
141 { StopPsSession(); }
EnumerateBodiesInSession
void EnumerateBodiesInSession()
Definition: LoadBodiesIntoSession.cpp:147
s_psMemoryActivated
static bool s_psMemoryActivated
Definition: LoadBodiesIntoSession.cpp:40
StopPsSession
static void StopPsSession()
Definition: LoadBodiesIntoSession.cpp:130
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
SetPSchema
static void SetPSchema()
Definition: LoadBodiesIntoSession.cpp:64
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:503
s_psTraverseActivated
static bool s_psTraverseActivated
Definition: LoadBodiesIntoSession.cpp:41
StartPsSession
static void StartPsSession()
Definition: LoadBodiesIntoSession.cpp:87
s_psSessionActivated
static bool s_psSessionActivated
Definition: LoadBodiesIntoSession.cpp:39