DATAKIT API  V2025.2
WriteDocument.cpp File Reference

Functions

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

Variables

Dtk_string inputFileName
 

Function Documentation

◆ WriteComponent()

Dtk_ErrorStatus WriteComponent ( Dtk_ComponentPtr  inComponent,
const Dtk_transfo inMatrix = Dtk_transfo() 
)
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 to use
90  Dtk_ComponentPtr defaultchoice = inComponent->GetChild(defaultindex);
91  if (defaultchoice.IsNotNULL())
92  {
93  WriteComponent(defaultchoice, inMatrix);
94  }
95  }
96  //if you don't want to use default you have to scan all children and choose the one you want to convert (see their name)
97  break;
98  }
99  //Component containing only children
101  {
102  Dtk_string name;
103  Dtk_Size_t NumChildren;
104 
105  name = inComponent->Name();//Component name
106 
107  NumChildren = inComponent->GetNumChildren();
108  for (i = 0; i < NumChildren; i++)
109  {
110  Dtk_ComponentPtr child = inComponent->GetChild(i);
111  WriteComponent(child, inMatrix);
112  }
113  break;
114 
115  }
116  }
117  if (IsXmlDumpActivated())
118  {
119  XmlEndComponent();
120  }
121  return dtkNoError;
122 }

◆ WriteDocument()

Dtk_ErrorStatus WriteDocument ( Dtk_MainDocPtr  inDocument)
13 {
14  //First we get the root component in the document
15  Dtk_ComponentPtr RootComponent = inDocument->RootComponent();
16  //if no Error we write the Component
17  if (RootComponent.IsNotNULL())
18  {
19  if (IsPdfDumpActivated())
20  {
21  PdfInitComponent(RootComponent);
22  }
23 
24  //Go Through the Root Component and children
25  WriteComponent(RootComponent);
26 
27  if (IsPdfDumpActivated())
28  {
30  }
31  return dtkNoError;
32  }
33 
34  return dtkErrorNullPointer;
35 }

Variable Documentation

◆ inputFileName

Dtk_string inputFileName
extern
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
WriteComponent
Dtk_ErrorStatus WriteComponent(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix=Dtk_transfo())
Definition: WriteComponent.cpp:9
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_Component::PrototypeComponentType
@ PrototypeComponentType
Definition: dtk_maindoc.hpp:578
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:140
Dtk_RGB
Definition: dtk_rgb.hpp:7
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:26
dtkErrorNullPointer
@ dtkErrorNullPointer
Definition: error_dtk.hpp:23
PdfEndComponent
void PdfEndComponent()
Definition: PdfWrite.cpp:151
PdfInitComponent
Dtk_ID PdfInitComponent(Dtk_ComponentPtr inComponent)
Definition: PdfWrite.cpp:143