DATAKIT SDK  V2026.2
WritePrototype.cpp File Reference

Functions

void WritePrototype (Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
 

Variables

Dtk_transfo CurrentMatrix = Dtk_transfo()
 
Dtk_tab< Dtk_IDProcessedComponents
 

Function Documentation

◆ WritePrototype()

void WritePrototype ( Dtk_ComponentPtr  inComponent,
const Dtk_transfo inMatrix 
)
20 {
21  // Get the component ID.
22  Dtk_ID componentID = inComponent->GetID();
23 
24  // Check if the component has already been processed.
25  // Only process the prototype if it hasn't been processed yet.
26  Dtk_Int32 componentIndex = ProcessedComponents.find(componentID);
27  if (componentIndex == -1)
28  {
29  Dtk_NodePtr rootNode;
30 
31  // Get the Datakit API instance.
32  Dtk_API *myAPI = Dtk_API::GetAPI();
33 
34  // Recursively process all child components (instances, sub-assemblies, etc.).
35  Dtk_Size_t numChildComponents = inComponent->GetNumChildren();
36  for ( Dtk_Size_t i = 0; i < numChildComponents; i++)
37  {
38  // Get current child component.
39  Dtk_ComponentPtr childComponent = inComponent->GetChild(i);
40 
41  // Recursively write the child component with the current transformation matrix.
42  WriteComponent(childComponent, inMatrix);
43  }
44 
45  // Read the construction tree for this prototype.
46  Dtk_ErrorStatus errorStatus;
47  if( inComponent->ComponentAvailability() == Dtk_Component::ComponentMissing )
48  {
49  errorStatus = dtkErrorFileNotExist;
50  }
51  else
52  {
53  errorStatus = myAPI->ReadComponent( inComponent, rootNode );
54  }
55 
56  // If the construction tree is valid, process it.
57  // A rootNode == NULL with err == dtkNoError means the component is empty.
58  if (errorStatus == dtkNoError && rootNode.IsNotNULL())
59  {
60  // Set the current matrix for flattening assemblies.
61  CurrentMatrix = inMatrix;
62 
63  // Recursively process the root node and its children.
64  WriteNode(rootNode);
65 
66  // Write global data set and metadata to XML if XML export is enabled.
67  if (IsXmlDumpActivated())
68  {
69  XmlWriteGlobalDataSet(inComponent->GetGlobalDataSet());
70 
71  Dtk_Size_t numMetaData = inComponent->GetNumMetaData();
72  if (numMetaData)
73  {
74  for ( Dtk_Size_t i = 0; i < numMetaData; i++)
75  {
76  XmlWriteMetaData(inComponent->GetMetaData(i));
77  }
78  }
79  }
80  }
81 
82  // Write metadata to PDF if PDF export is enabled.
83  if (IsPdfDumpActivated())
84  {
85  PdfWriteMetaData(inComponent);
86  }
87 
88  // Finalize and free resources for the component.
89  errorStatus = myAPI->EndComponent(inComponent);
90  }
91  else
92  {
93  // If the prototype has already been processed, handle the PDF instance case.
94  // Use the unique ID returned by GetID() to map the component to your write ID.
95  if (IsPdfDumpActivated())
96  {
97  PdfInstanceExistingPrototype(componentIndex);
98  }
99  }
100 }

Variable Documentation

◆ CurrentMatrix

Dtk_transfo CurrentMatrix = Dtk_transfo()

◆ ProcessedComponents

Dtk_tab<Dtk_ID> ProcessedComponents
ProcessedComponents
Dtk_tab< Dtk_ID > ProcessedComponents
Definition: WritePrototype.cpp:16
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:681
dtkErrorFileNotExist
@ dtkErrorFileNotExist
Definition: error_dtk.hpp:101
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
XmlWriteMetaData
void XmlWriteMetaData(const Dtk_MetaDataPtr &inMetaData)
Definition: XmlWrite.cpp:130
PdfWriteMetaData
void PdfWriteMetaData(Dtk_ComponentPtr inComponent)
Definition: PdfWrite.cpp:120
XmlWriteGlobalDataSet
void XmlWriteGlobalDataSet(const Dtk_GlobalDataSetPtr &inSelectionSet)
Definition: XmlWrite.cpp:124
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:704
Dtk_API::EndComponent
Dtk_ErrorStatus EndComponent(Dtk_ComponentPtr &inComponent)
EndComponent.
WriteComponent
Dtk_ErrorStatus WriteComponent(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix=Dtk_transfo())
Definition: WriteComponent.cpp:12
Dtk_API::GetAPI
static Dtk_API * GetAPI()
Get DATAKIT API.
PdfInstanceExistingPrototype
void PdfInstanceExistingPrototype(Dtk_ID ComponentIndex)
Definition: PdfWrite.cpp:141
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:679
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
CurrentMatrix
Dtk_transfo CurrentMatrix
Definition: WritePrototype.cpp:13
Dtk_SmartPtr< Dtk_Node >
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
Dtk_Component::ComponentMissing
@ ComponentMissing
Definition: dtk_maindoc.hpp:559
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:149
Dtk_API::ReadComponent
Dtk_ErrorStatus ReadComponent(const Dtk_ComponentPtr &inComponent, Dtk_NodePtr &outRootNode)
Read Component from Assembly Tree (Call EndComponent to free data allocated)
WriteNode
Dtk_ErrorStatus WriteNode(Dtk_NodePtr inNode)
Definition: WriteNode.cpp:16
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:29
Dtk_API
Definition: dtk_api.hpp:75