DATAKIT API  V2025.1
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 = inComponent->GetConceptionUnitScale(UnitFactor);
17 
18  //GetName
19  Dtk_string ComponentName = inComponent->Name();
20 
21  //GetAttributes
22  Dtk_InfoPtr attributes = inComponent->GetInfos();
23  if (attributes.IsNotNULL())
24  {
25  int CompoActivationStatus = attributes->GetActivationFlag(); // if CompoActivationStatus == 0 Component and his children aren't visible
26  int CompoBlankedStatus = attributes->GetBlankedStatus(); // if CompoBlankedStatus == 1 Component and his children aren't visible
27  Dtk_RGB CompoColor = attributes->GetColor(); // if CompoBlankedStatus == 1 Component and his children are using this color
28  }
29 
30  //You can GetPreview if you want to handle it
31  Dtk_PreviewPtr TmpPreview = inComponent->GetPreview();
32  if (TmpPreview.IsNotNULL())
33  {
34  Dtk_Int32 size = TmpPreview->GetStreamSize();
35  char *jpgimage = TmpPreview->GetStream();
36  Dtk_string Preview_name = "ComponentPreview.jpg";
37  FILE *jpg = Preview_name.OpenFile("wb");
38  if (jpg)
39  {
40  fwrite(jpgimage, sizeof(char), size, jpg);
41  fclose(jpg);
42  }
43  }
44 
45  if (IsXmlDumpActivated())
46  {
47  XmlInitComponent(inComponent);
48  }
49 
50  //You have 4 types for Component
51  Dtk_Component::ComponentTypeEnum type = inComponent->ComponentType();
52  switch (type)
53  {
54  //Instance represent a prototype with a matrix placement
56  {
57  WriteInstance(inComponent, inMatrix);
58  break;
59  }
60  //Prototype (you have to check if you ever read and write it to don't waste time)
61  //you can use the method inComponent->GetID() to get Unique ID for Component
63  {
64  WritePrototype(inComponent, inMatrix);
65  break;
66  }
67  //Catalog Component represent a choice of several possible configuration
68  //(like scene in catiav5, workspace in catiav4, configuration in solidworks)
69  //Default is the first child
71  {
72  Dtk_string name = inComponent->Name();//Component name
73 
74  Dtk_Size_t numComp = inComponent->GetNumChildren();
75  if (numComp > 0)
76  {
77  if (IsXmlDumpActivated())
78  {
79  for (i = 0; i < numComp; i++)
80  {
81  Dtk_ComponentPtr child = inComponent->GetChild(i);
82  XmlInitComponent(child);
84  }
85  }
86  Dtk_Int32 defaultindex = inComponent->GetDefaultChildInCatalog(); //Get Default child to use
87  Dtk_ComponentPtr defaultchoice = inComponent->GetChild(defaultindex);
88  if (defaultchoice.IsNotNULL())
89  {
90  WriteComponent(defaultchoice, inMatrix);
91  }
92  }
93  //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)
94  break;
95  }
96  //Component containing only children
98  {
99  Dtk_string name;
100  Dtk_Size_t NumChildren;
101 
102  name = inComponent->Name();//Component name
103 
104  NumChildren = inComponent->GetNumChildren();
105  for (i = 0; i < NumChildren; i++)
106  {
107  Dtk_ComponentPtr child = inComponent->GetChild(i);
108  WriteComponent(child, inMatrix);
109  }
110  break;
111 
112  }
113  }
114  if (IsXmlDumpActivated())
115  {
116  XmlEndComponent();
117  }
118  return dtkNoError;
119 }

◆ 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
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
WriteInstance
Dtk_ErrorStatus WriteInstance(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
Definition: WriteInstance.cpp:14
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