DATAKIT SDK  V2026.4
WriteBodyForParasolid.cpp File Reference

Functions

void WriteBodyForParasolid (Dtk_BodyPtr inBody, Dtk_tab< Dtk_ID > &outIds)
 

Function Documentation

◆ WriteBodyForParasolid()

void WriteBodyForParasolid ( Dtk_BodyPtr  inBody,
Dtk_tab< Dtk_ID > &  outIds 
)
13 {
14 
15  Dtk_tab<Dtk_ID> bodyIds;
16 
17  DtkErrorStatus errf, err;
18 
19  Dtk_InfoPtr infBody = inBody->info();
20  if( infBody.IsNULL() )
21  {
22  infBody = Dtk_Info::Create();
23  }
24  // Add custom attributes to the body and its faces, edges, and vertices
25  // Custom attributes are stored in the Parasolid file and can be retrieved later
26  // For example, you can use the following code to retrieve the custom attributes from a Parasolid file:
27  infBody->AddCustomerDefinedAttribute( L"my_body_id", inBody->get_info()->GetId() );
28  // You can also add custom attributes as string
29  infBody->AddCustomerDefinedAttribute( L"my_feature", Dtk_string( L"created_from_feature" ) );
30 
31  for( size_t i = 0; i < inBody->GetNumTopologicalEntities( DTK_TYPE_UNKNOWN ); i++ )
32  {
33  Dtk_FacePtr face = Dtk_FacePtr::DtkDynamicCast( inBody->GetPtr( i ) );
34  if( face.IsNotNULL() && face->get_info().IsNotNULL() )
35  {
36  face->get_info()->AddCustomerDefinedAttribute( L"my_face_id", face->get_info()->GetId() );
37  }
38  Dtk_EdgePtr edge = Dtk_EdgePtr::DtkDynamicCast( inBody->GetPtr( i ) );
39  if( edge.IsNotNULL() && edge->get_info().IsNotNULL() )
40  {
41  edge->get_info()->AddCustomerDefinedAttribute( L"my_edge_id", edge->get_info()->GetId() );
42  }
43  Dtk_VertexPtr vertex = Dtk_VertexPtr::DtkDynamicCast( inBody->GetPtr( i ) );
44  if( vertex.IsNotNULL() && vertex->get_info().IsNotNULL() )
45  {
46  vertex->get_info()->AddCustomerDefinedAttribute( L"my_vertex_id", vertex->get_info()->GetId() );
47  }
48  }
49 
50 
51 
52  // Initialize the Parasolid file in memory
53  Dtk_tab<char> outParasolidStream;
54  errf = psw_InitFile( outParasolidStream, 0 );
55 
56  // Initialize the Parasolid file on disk (uncomment the following lines to write to disk)
57  // The filename is constructed using the body name and ID to ensure uniqueness
58  //Dtk_string myFilename = infBody->GetName() +"_";
59  //myFilename.add_int( infBody->GetId() );
60  //myFilename += "_myxbfile.x_b";
61  //errf = psw_InitFile( myFilename ,1,270);
62 
63  // Write the body to the Parasolid file or memory stream
64  err = psw_WriteBody( inBody, bodyIds );
65 
66  // End the Parasolid file and write the body IDs to the output file or memory stream
67  errf = psw_EndFile( bodyIds );
68 
69  // The following code is commented out because it requires the Parasolid kernel headers and libraries to be linked
70  // It allows to read the Parasolid file from memory and transmit it to an existing Parasolid session
71 
72  //// #include "Include_pskernel\parasolid_kernel.h"
73  //// PK_PART_receive_o_t recvOpts;
74  //// PK_PART_receive_o_m( recvOpts );
75  //// int nParts = 0;
76  //// PK_PART_t* parts = nullptr;
77 
78  //// PK_MEMORY_block_t block;
79  //// block.next = nullptr;
80  //// block.n_bytes = static_cast< size_t >( outParasolidStream.size() );
81  //// block.bytes = &outParasolidStream.GetArray()[ 0 ];
82 
83  ////// Load stream into Parasolid memory and receive the parts (bodies) from it
84  //// PK_ERROR_code_t pkErr = PK_PART_receive_b( block, &recvOpts, &nParts, &parts);
85 
86  ////// Control by dumping a file
87  ////PK_PART_transmit_o_t transmit_option;
88  ////PK_PART_transmit_o_m( transmit_option );
89  ////pkErr = PK_PART_transmit( nParts, parts, "xmtControlFile", &transmit_option );
90 
91 
92  if( err == dtkNoError )
93  {
94  for( Dtk_Size_t i = 0; i < bodyIds.size(); ++i )
95  outIds.push_back( bodyIds[ i ] );
96  }
97  else
98  {
99  cout << "Warning: psw_WriteBody failed: " << dtkTypeError( err ).c_str() << endl;
100  }
101 }
Dtk_Info::Create
static Dtk_SmartPtr< Dtk_Info > Create()
Calls default constructor to allocate a new object.
Dtk_Entity::get_info
Dtk_InfoPtr get_info() const
DTK_TYPE_UNKNOWN
@ DTK_TYPE_UNKNOWN
Definition: define.h:26
psw_InitFile
DtkErrorStatus psw_InitFile(const Dtk_string &inFileOut, Dtk_bool muteMode, Dtk_Int32 inVersion=180)
Initialise a file to be written.
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
Dtk_Info::AddCustomerDefinedAttribute
Dtk_ErrorStatus AddCustomerDefinedAttribute(Dtk_string name, Dtk_Val val)
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:711
Dtk_SmartPtr< Dtk_Face >::DtkDynamicCast
static Dtk_SmartPtr< Dtk_Face > DtkDynamicCast(const Dtk_SmartPtr< T2 > &p)
Definition: util_ptr_dtk.hpp:101
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Dtk_SmartPtr::IsNULL
Dtk_bool IsNULL() const
Definition: util_ptr_dtk.hpp:118
Dtk_SmartPtr< Dtk_Info >
dtkTypeError
Dtk_string dtkTypeError(Dtk_Int32 errNumero)
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
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_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
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.
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
Dtk_Info::GetId
int GetId() const