DATAKIT API  V2025.3
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 
)
10 {
11  Dtk_Size_t i;
12 
13  //Datakit component are given in MM, if original model had other unit you can get it with GetConceptionUnitScale()
14  // UnitFactor = 25.4 for inch
15  double UnitFactor;
16  Dtk_ErrorStatus err;
17  err = inComponent->GetConceptionUnitScale(UnitFactor);
18 
19  //GetName
20  Dtk_string ComponentName = inComponent->Name();
21 
22  //GetAttributes
23  Dtk_InfoPtr attributes = inComponent->GetInfos();
24  if (attributes.IsNotNULL())
25  {
26  int CompoActivationStatus, CompoBlankedStatus;
27  Dtk_RGB CompoColor;
28  CompoActivationStatus = attributes->GetActivationFlag(); // if CompoActivationStatus == 0 Component and his children aren't visible
29  CompoBlankedStatus = attributes->GetBlankedStatus(); // if CompoBlankedStatus == 1 Component and his children aren't visible
30  CompoColor = attributes->GetColor(); // if CompoBlankedStatus == 1 Component and his children are using this color
31  }
32 
33  //You can GetPreview if you want to handle it
34  Dtk_PreviewPtr TmpPreview = inComponent->GetPreview();
35  if (TmpPreview.IsNotNULL())
36  {
37  Dtk_Int32 size = TmpPreview->GetStreamSize();
38  char *jpgimage = TmpPreview->GetStream();
39  Dtk_string Preview_name = "ComponentPreview.jpg";
40  FILE *jpg = Preview_name.OpenFile("wb");
41  if (jpg)
42  {
43  fwrite(jpgimage, sizeof(char), size, jpg);
44  fclose(jpg);
45  }
46  }
47 
48  if (IsXmlDumpActivated())
49  {
50  XmlInitComponent(inComponent);
51  }
52 
53  //You have 4 types for Component
54  Dtk_Component::ComponentTypeEnum type = inComponent->ComponentType();
55  switch (type)
56  {
57  //Instance represent a prototype with a matrix placement
59  {
60  WriteInstance(inComponent);
61  break;
62  }
63  //Prototype (you have to check if you ever read and write it to don't waste time)
64  //you can use the method inComponent->GetID() to get Unique ID for Component
66  {
67  WritePrototype(inComponent, inMatrix);
68  break;
69  }
70  //Catalog Component represent a choice of several possible configuration
71  //(like scene in catiav5, workspace in catiav4, configuration in solidworks)
72  //Default is the first child
74  {
75  Dtk_string name = inComponent->Name();//Component name
76 
77  Dtk_Size_t numComp = inComponent->GetNumChildren();
78  if (numComp > 0)
79  {
80  if (IsXmlDumpActivated())
81  {
82  for (i = 0; i < numComp; i++)
83  {
84  Dtk_ComponentPtr child = inComponent->GetChild(i);
85  XmlInitComponent(child);
87  }
88  }
89  Dtk_Int32 defaultindex = inComponent->GetDefaultChildInCatalog(); //Get Default child
90  Dtk_tab<Dtk_Int32> activatedindex = inComponent->GetActivatedChildrenInCatalog(); //Activated components in Catalog
91  Dtk_Size_t numactivatedchildren = activatedindex.size();
92  if (numactivatedchildren > 0)
93  {
94  for (i = 0; i < numactivatedchildren; i++)
95  {
96  Dtk_ComponentPtr activatedchild = inComponent->GetChild(activatedindex[i]);
97  WriteComponent(activatedchild, inMatrix);
98  }
99  }
100  else
101  {
102  Dtk_ComponentPtr defaultchild = inComponent->GetChild(defaultindex);
103  WriteComponent(defaultchild, inMatrix);
104  }
105  }
106  //if you don't want to use default or activated component you have to scan all children and choose the one you want to convert (see their name)
107  break;
108  }
109  //Component containing only children
111  {
112  Dtk_string name;
113  Dtk_Size_t NumChildren;
114 
115  name = inComponent->Name();//Component name
116 
117  NumChildren = inComponent->GetNumChildren();
118  for (i = 0; i < NumChildren; i++)
119  {
120  Dtk_ComponentPtr child = inComponent->GetChild(i);
121  WriteComponent(child, inMatrix);
122  }
123  break;
124 
125  }
126  }
127  if (IsXmlDumpActivated())
128  {
129  XmlEndComponent();
130  }
131  return dtkNoError;
132 }
Dtk_Info::GetBlankedStatus
int GetBlankedStatus() const
Retrieves the entity Blanked Status.
Dtk_Component::CatalogComponentType
@ CatalogComponentType
Definition: dtk_maindoc.hpp:579
WriteComponent
Dtk_ErrorStatus WriteComponent(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
Definition: WriteComponent.cpp:9
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:58
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:712
Dtk_Info::GetColor
Dtk_RGB GetColor() const
Retrieves the entity color as Dtk_RGBA values.
Dtk_Info::GetActivationFlag
int GetActivationFlag() const
Dtk_string::OpenFile
FILE * OpenFile(const Dtk_string &inRights) const
File Utility : Open a file with the given rights.
WritePrototype
void WritePrototype(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
Definition: WritePrototype.cpp:14
Dtk_Component::VirtualComponentType
@ VirtualComponentType
Definition: dtk_maindoc.hpp:580
Dtk_Component::InstanceComponentType
@ InstanceComponentType
Definition: dtk_maindoc.hpp:577
WriteInstance
Dtk_ErrorStatus WriteInstance(Dtk_ComponentPtr inComponent)
Definition: WriteInstance.cpp:14
Dtk_Int32
int32_t Dtk_Int32
Definition: define.h:687
Dtk_Component::ComponentTypeEnum
ComponentTypeEnum
Definition: dtk_maindoc.hpp:576
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Dtk_SmartPtr< Dtk_Info >
Dtk_tab< Dtk_Int32 >
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:504
Dtk_Component::PrototypeComponentType
@ PrototypeComponentType
Definition: dtk_maindoc.hpp:578
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:144
Dtk_RGB
Definition: dtk_rgb.hpp:7