DATAKIT SDK  V2026.3
WriteDocument.cpp File Reference

Functions

Dtk_ErrorStatus WriteComponent (Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix=Dtk_transfo())
 
Dtk_ErrorStatus WriteDocument (Dtk_MainDocPtr inDocument)
 

Function Documentation

◆ WriteComponent()

Dtk_ErrorStatus WriteComponent ( Dtk_ComponentPtr  inComponent,
const Dtk_transfo inMatrix = Dtk_transfo() 
)
13 {
14  // Get the unit scale (e.g., 25.4 for inch) for the component.
15  double unitFactor;
16  inComponent->GetConceptionUnitScale(unitFactor);
17 
18  // Get the component name.
19  Dtk_string componentName = inComponent->Name();
20 
21  // Get component attributes (activation, blanked status, color).
22  Dtk_InfoPtr componentAttributes = inComponent->GetInfos();
23  if (componentAttributes.IsNotNULL())
24  {
25  // Get activation flag (1 if activated, 0 otherwise).
26  int activationStatus = 1;
27  activationStatus = componentAttributes->GetActivationFlag();
28 
29  // Get blanked status (0: visible, 1: invisible, 2: construction geometry).
30  int blankedStatus = 0;
31  blankedStatus = componentAttributes->GetBlankedStatus();
32 
33  // Get color (RGB values).
34  Dtk_RGB color = componentAttributes->GetColor();
35  }
36 
37  // Get and write preview image if available.
38  Dtk_PreviewPtr preview = inComponent->GetPreview();
39  Dtk_string previewName = componentName + L"_";
40  previewName.add_int( inComponent->GetID() );
41  if( preview.IsNotNULL() )
42  {
43  WritePreview( preview, previewName );
44  }
45 
46 
47  if (IsXmlDumpActivated())
48  {
49  // initialize XML output for the component if XML export is enabled.
50  XmlInitComponent(inComponent);
51  }
52 
53  // Process the component based on its type.
54  Dtk_Component::ComponentTypeEnum type = inComponent->ComponentType();
55  switch (type)
56  {
57  // Instance: represents a prototype with a matrix placement.
59  {
60  // Write the component instance
61  WriteInstance(inComponent);
62  break;
63  }
64  // Prototype: check if already processed to avoid redundant work.
65  // Use inComponent->GetID() to obtain its unique ID.
67  {
68  // Write the prototype component with the given transformation matrix.
69  WritePrototype(inComponent, inMatrix);
70  break;
71  }
72  // Catalog: represents multiple possible configurations (scene, workspace, etc.).
74  {
75  // Get number of children and recursively write each child component.
76  Dtk_Size_t numChildren = inComponent->GetNumChildren();
77  if (numChildren > 0)
78  {
79  // Get default component index in the catalog
80  Dtk_Int32 defaultComponentIndex = inComponent->GetDefaultChildInCatalog();
81 
82  // Get activated component indices in the catalog
83  Dtk_tab<Dtk_Int32> activatedComponentIndices = inComponent->GetActivatedChildrenInCatalog();
84 
85  // Get number of activated components in the catalog
86  Dtk_Size_t numActivatedComponents = activatedComponentIndices.size();
87 
88  if (IsXmlDumpActivated())
89  {
90  // Write all non-activated and non-default children as XML dump entries (to provide a complete component tree)
91  for (Dtk_Size_t i = 0; i < numChildren; i++)
92  {
93  // Skip activated components
94  if( activatedComponentIndices.find( ( Dtk_Int32 )i ) >= 0 )
95  {
96  continue;
97  }
98 
99  // Skip default component
100  if( defaultComponentIndex == ( Dtk_Int32 )i )
101  {
102  continue;
103  }
104 
105  // Write XML entry for non-activated and non-default child component
106  Dtk_ComponentPtr childComponent = inComponent->GetChild(i);
107  XmlInitComponent(childComponent);
108  XmlEndComponent();
109  }
110  }
111 
112  // Write activated components or default component
113  if (numActivatedComponents > 0)
114  {
115  // Write all activated components
116  for ( Dtk_Size_t i = 0; i < numActivatedComponents; i++)
117  {
118  // Write the activated component
119  Dtk_ComponentPtr activatedComponent = inComponent->GetChild(activatedComponentIndices[i]);
120  WriteComponent(activatedComponent, inMatrix);
121  }
122  }
123  else
124  {
125  // Write the default component
126  Dtk_ComponentPtr defaultChildComponent = inComponent->GetChild(defaultComponentIndex);
127  WriteComponent(defaultChildComponent, inMatrix);
128  }
129  }
130 
131  // If necessary, iterate over all children and select the desired one(s) to process based on their name.
132  break;
133  }
134  // Virtual: component containing only children.
136  {
137  // Get number of child components and recursively write each child component.
138  Dtk_Size_t numChildComponents = inComponent->GetNumChildren();
139  for (Dtk_Size_t i = 0; i < numChildComponents; i++)
140  {
141  Dtk_ComponentPtr childComponent = inComponent->GetChild(i);
142  WriteComponent(childComponent, inMatrix);
143  }
144  break;
145  }
146  }
147 
148  if (IsXmlDumpActivated())
149  {
150  // Finalize XML output for the component if XML export is enabled.
151  XmlEndComponent();
152  }
153 
154  return dtkNoError;
155 }

◆ WriteDocument()

Dtk_ErrorStatus WriteDocument ( Dtk_MainDocPtr  inDocument)
15 {
16  // Retrieve the root component from the document.
17  Dtk_ComponentPtr rootComponent = inDocument->RootComponent();
18 
19  // If the root component is valid, process it and its children.
20  if (rootComponent.IsNotNULL())
21  {
22  // Initialize PDF output for the root component if PDF export is enabled.
23  if (IsPdfDumpActivated())
24  {
25  PdfInitComponent(rootComponent);
26  }
27 
28  // Recursively process the root component and its children.
29  WriteComponent(rootComponent);
30 
31  // Finalize PDF output for the root component if PDF export is enabled.
32  if (IsPdfDumpActivated())
33  {
34  // Finalize PDF output for the root component if PDF export is enabled.
36  }
37  return dtkNoError;
38  }
39 
40  // Return error if the document is invalid.
41  return dtkErrorNullPointer;
42 }
Dtk_Info::GetBlankedStatus
int GetBlankedStatus() const
Retrieves the entity Blanked Status.
Dtk_Component::CatalogComponentType
@ CatalogComponentType
Definition: dtk_maindoc.hpp:576
WriteComponent
Dtk_ErrorStatus WriteComponent(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
Definition: WriteComponent.cpp:12
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
XmlInitComponent
void XmlInitComponent(Dtk_ComponentPtr inComponent)
Definition: XmlWrite.cpp:50
XmlEndComponent
void XmlEndComponent()
Definition: XmlWrite.cpp:57
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_Info::GetColor
Dtk_RGB GetColor() const
Retrieves the entity color as Dtk_RGBA values.
Dtk_Info::GetActivationFlag
int GetActivationFlag() const
WriteComponent
Dtk_ErrorStatus WriteComponent(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix=Dtk_transfo())
Definition: WriteComponent.cpp:12
WritePrototype
void WritePrototype(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
Definition: WritePrototype.cpp:19
Dtk_Component::VirtualComponentType
@ VirtualComponentType
Definition: dtk_maindoc.hpp:577
Dtk_Component::InstanceComponentType
@ InstanceComponentType
Definition: dtk_maindoc.hpp:574
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)
WriteInstance
Dtk_ErrorStatus WriteInstance(Dtk_ComponentPtr inComponent)
Definition: WriteInstance.cpp:16
Dtk_tab::find
int find(const T &e) const
Definition: util_stl_dtk.hpp:746
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:686
Dtk_Component::ComponentTypeEnum
ComponentTypeEnum
Definition: dtk_maindoc.hpp:573
Dtk_SmartPtr< Dtk_Info >
WritePreview
void WritePreview(const Dtk_PreviewPtr &inPreview, const Dtk_string &inName)
Definition: WritePreview.cpp:4
Dtk_tab< Dtk_Int32 >
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:503
Dtk_Component::PrototypeComponentType
@ PrototypeComponentType
Definition: dtk_maindoc.hpp:575
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:151
Dtk_RGB
Definition: dtk_rgb.hpp:7
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:29
dtkErrorNullPointer
@ dtkErrorNullPointer
Definition: error_dtk.hpp:23
PdfEndComponent
void PdfEndComponent()
Definition: PdfWrite.cpp:154
PdfInitComponent
Dtk_ID PdfInitComponent(Dtk_ComponentPtr inComponent)
Definition: PdfWrite.cpp:146