DATAKIT API  V2025.1
WriteComponent.hpp File Reference

Go to the source code of this file.

Functions

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

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 }

◆ WriteInstance()

Dtk_ErrorStatus WriteInstance ( Dtk_ComponentPtr  inComponent,
const Dtk_transfo inMatrix 
)
15 {
16 
17  //Instance represent a prototype with a matrix placement
18  Dtk_string ComponentName;
19  ComponentName = inComponent->Name();//Component name
20  Dtk_ComponentPtr prototype = inComponent->GetChild(0);
21  Dtk_transfo matrix = inComponent->TransformationMatrix();
22  Dtk_ID pdfInstID = 0;
23  Dtk_ID childID = inComponent->GetChild(0)->GetID();
24 
25  if (IsPdfDumpActivated())
26  {
27  pdfInstID = PdfInitInstance(inComponent);
28  }
29 
30 
31  //Dtk_transfo newMatrix = inMatrix * matrix;
32 
33  //you have to write matrix and instance the prototype
34  WriteComponent(prototype, Dtk_transfo());
35 
36 
37 
38  if (IsPdfDumpActivated())
39  {
40  PdfEndInstance(pdfInstID, childID);
41  }
42 
43  if (ComponentProcessed.find(childID) < 0)
44  {
45  ComponentProcessed.push_back(childID);
46  }
47 
48  return dtkNoError;
49 }

◆ WritePrototype()

void WritePrototype ( Dtk_ComponentPtr  inComponent,
const Dtk_transfo inMatrix 
)
15 {
16  Dtk_Size_t i;
17  Dtk_ID ComponentID = inComponent->GetID();
18  Dtk_Int32 ComponentIndex;
19  ComponentIndex = ComponentProcessed.find(ComponentID);
20 
21  if (ComponentIndex == -1)
22  {
23  Dtk_NodePtr RootNode;
24  Dtk_API *inAPI = Dtk_API::GetAPI();
25 
26  //it can also contain some instances
27  Dtk_Size_t NumChildren = inComponent->GetNumChildren();
28  for (i = 0; i < NumChildren; i++)
29  {
30  Dtk_ComponentPtr child = inComponent->GetChild(i);
31  WriteComponent(child, inMatrix);
32  }
33 
34  //Get the Construction tree for this prototype
35  Dtk_ErrorStatus err;
36  if (inComponent->ComponentAvailability() == Dtk_Component::ComponentMissing)
38  else
39  err = inAPI->ReadComponent(inComponent, RootNode);
40 
41  //a RootNode= NULL with err == dtkNoError means that component is empty
42  if (err == dtkNoError && RootNode.IsNotNULL())
43  {
44  // Set matrix to apply to all node if you flat assemblies
45  CurrentMatrix = inMatrix;
46 
47  //Go Through the Root Node and children
48  WriteNode(RootNode);
49 
50  if (IsXmlDumpActivated())
51  {
52  XmlWriteGlobalDataSet(inComponent->GetGlobalDataSet());
53 
54  Dtk_Size_t NumMetaData;
55  NumMetaData = inComponent->GetNumMetaData();
56  if (NumMetaData)
57  {
58  for (i = 0; i < NumMetaData; i++)
59  {
60  XmlWriteMetaData( inComponent->GetMetaData(i));
61  }
62  }
63  }
64  }
65 
66  if (IsPdfDumpActivated())
67  {
68  PdfWriteMetaData(inComponent);
69  }
70 
71  //We close the opened Component and free his construction tree
72  err = inAPI->EndComponent(inComponent);
73 
74  }
75  else
76  {
77  //Get the prototype you ever write
78  //The Component has a unique ID given by GetID to help to map it with your Write ID
79  if (IsPdfDumpActivated())
80  {
81  PdfInstanceExistingPrototype(ComponentIndex);
82  }
83 
84  }
85 }
Dtk_ID
uint32_t Dtk_ID
Definition: define.h:689
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
Dtk_Info::GetBlankedStatus
int GetBlankedStatus() const
Retrieves the entity Blanked Status.
Dtk_Component::CatalogComponentType
@ CatalogComponentType
Definition: dtk_maindoc.hpp:579
dtkErrorFileNotExist
@ dtkErrorFileNotExist
Definition: error_dtk.hpp:95
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
XmlWriteMetaData
void XmlWriteMetaData(const Dtk_MetaDataPtr &inMetaData)
Definition: XmlWrite.cpp:130
XmlEndComponent
void XmlEndComponent()
Definition: XmlWrite.cpp:57
PdfWriteMetaData
void PdfWriteMetaData(Dtk_ComponentPtr inComponent)
Definition: PdfWrite.cpp:117
XmlWriteGlobalDataSet
void XmlWriteGlobalDataSet(const Dtk_GlobalDataSetPtr &inSelectionSet)
Definition: XmlWrite.cpp:124
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
PdfEndInstance
void PdfEndInstance(Dtk_ID pdfInstID, Dtk_ID childID)
Definition: PdfWrite.cpp:108
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_API::EndComponent
Dtk_ErrorStatus EndComponent(Dtk_ComponentPtr &inComponent)
EndComponent.
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_API::GetAPI
static Dtk_API * GetAPI()
Get DATAKIT API.
PdfInstanceExistingPrototype
void PdfInstanceExistingPrototype(Dtk_ID ComponentIndex)
Definition: PdfWrite.cpp:138
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
ComponentProcessed
Dtk_tab< Dtk_ID > ComponentProcessed
Definition: WritePrototype.cpp:12
WriteInstance
Dtk_ErrorStatus WriteInstance(Dtk_ComponentPtr inComponent, const Dtk_transfo &inMatrix)
Definition: WriteInstance.cpp:14
CurrentMatrix
Dtk_transfo CurrentMatrix
Definition: WritePrototype.cpp:11
Dtk_SmartPtr< Dtk_Info >
PdfInitInstance
Dtk_ID PdfInitInstance(Dtk_ComponentPtr inComponent)
Definition: PdfWrite.cpp:90
Dtk_Component::PrototypeComponentType
@ PrototypeComponentType
Definition: dtk_maindoc.hpp:578
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
Dtk_Component::ComponentMissing
@ ComponentMissing
Definition: dtk_maindoc.hpp:567
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:140
Dtk_API::ReadComponent
Dtk_ErrorStatus ReadComponent(const Dtk_ComponentPtr &inComponent, Dtk_NodePtr &outRootNode)
Read Component from Assembly Tree (Call EndComponent to free data allocated)
WriteNode
Dtk_ErrorStatus WriteNode(Dtk_NodePtr inNode)
Definition: WriteNode.cpp:16
Dtk_RGB
Definition: dtk_rgb.hpp:7
ComponentProcessed
Dtk_tab< Dtk_ID > ComponentProcessed
Definition: WritePrototype.cpp:12
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:26
dtkErrorNullPointer
@ dtkErrorNullPointer
Definition: error_dtk.hpp:23
Dtk_API
Definition: dtk_api.hpp:75
PdfEndComponent
void PdfEndComponent()
Definition: PdfWrite.cpp:151
PdfInitComponent
Dtk_ID PdfInitComponent(Dtk_ComponentPtr inComponent)
Definition: PdfWrite.cpp:143