DATAKIT SDK  V2026.4
WriteComponent.cpp File Reference

Functions

Dtk_ErrorStatus WriteComponent (Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
 

Function Documentation

◆ WriteComponent()

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