DATAKIT SDK  V2026.3
OpenDocument.cpp File Reference

Functions

Dtk_ErrorStatus ProcessCADFile (const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
 

Variables

Dtk_tab< Dtk_IDProcessedComponents
 

Function Documentation

◆ ProcessCADFile()

Dtk_ErrorStatus ProcessCADFile ( const Dtk_string inInputFile,
const Dtk_string inOutputFolder 
)
19 {
20  // Clear the list of processed components before starting.
21  ProcessedComponents.clear();
22 
23  // Get the current Datakit API instance.
24  Dtk_API* myApi = Dtk_API::GetAPI();
25 
26  std::cout << "Processing file: " << inInputFile.c_str() << std::endl;
27 
28  // Retrieve and display the file version.
29  Dtk_string fileVersion;
30  Dtk_ErrorStatus stError = myApi->GetFileVersion(inInputFile, fileVersion);
31 
32  if( fileVersion.is_not_NULL() )
33  {
34  // Display the file version.
35  std::cout << "File version: " << fileVersion.c_str() << std::endl;
36  }
37 
38  if (stError != dtkNoError)
39  {
40  // Report error if unable to get file version.
41  std::cout << "Unable to get file version (error code: " << dtkTypeError(stError).c_str() << ")" << std::endl;
42  return stError;
43  }
44 
45  // Retrieve and write the file-level preview image.
46  Dtk_PreviewPtr FilePreview;
47  stError = myApi->GetFilePreview( inInputFile, FilePreview );
48  // If the preview was successfully retrieved, write it alongside the input file.
49  if( stError == dtkNoError )
50  WritePreview( FilePreview, inInputFile );
51 
52 
53  // Set log file for the reader (inventory, missing files in assembly, etc.).
54  Dtk_string logFilePath = inInputFile.filename() + Dtk_string("-dtk.log");
55  myApi->SetLogFile( logFilePath );
56 
57  // Initialize XML writing if XML export is enabled.
58  Dtk_ErrorStatus stErrorXml = dtkNoError;
59  if (IsXmlDumpActivated())
60  {
61  stErrorXml = XmlWriteInit(inInputFile, inOutputFolder);
62  }
63 
64  // Initialize PDF writing if PDF export is enabled.
65  Dtk_ErrorStatus stErrorPdf = dtkNoError;
66  if (IsPdfDumpActivated())
67  {
68  stErrorPdf = PdfInitWrite(inInputFile, inOutputFolder);
69  }
70 
71  // Open the input file and obtain the corresponding document.
72  Dtk_MainDocPtr tmpDoc;
73  Dtk_ErrorStatus err = myApi->OpenDocument(inInputFile, tmpDoc);
74 
75  // If successful, write the document (see WriteDocument.cpp)
76  if (err == dtkNoError && tmpDoc.IsNotNULL())
77  {
78  WriteDocument(tmpDoc);
79  }
80  else
81  {
82  // Report error if unable to open the document.
83  std::cout << "Error with OpenDocument (error code: " << err << " " << dtkTypeError(err).c_str() << ")" << std::endl;
84  }
85 
86  // Close the opened document.
87  err = myApi->EndDocument(tmpDoc);
88 
89  // Finalize XML writing if XML export is enabled.
90  if (IsXmlDumpActivated())
91  {
92  XmlWriteEnd();
93  }
94 
95  // Finalize PDF writing if PDF export is enabled.
96  if (IsPdfDumpActivated())
97  {
98  PdfEndWrite(inInputFile);
99  }
100 
101  return err;
102 }

Variable Documentation

◆ ProcessedComponents

Dtk_tab<Dtk_ID> ProcessedComponents
extern
Dtk_API::EndDocument
Dtk_ErrorStatus EndDocument(Dtk_MainDocPtr &inoutDocument)
Close a Document.
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
WriteDocument
Dtk_ErrorStatus WriteDocument(Dtk_MainDocPtr inDocument)
Definition: WriteDocument.cpp:14
XmlWriteInit
Dtk_ErrorStatus XmlWriteInit(Dtk_string inInputFile, const Dtk_string &inOutputFolder)
Definition: XmlWrite.cpp:22
Dtk_API::OpenDocument
Dtk_ErrorStatus OpenDocument(const Dtk_string &inInputFile, Dtk_MainDocPtr &outDocument)
Open a Document (call EndDocument to close it)
Dtk_string::is_not_NULL
Dtk_bool is_not_NULL() const
Dtk_API::GetAPI
static Dtk_API * GetAPI()
Get DATAKIT API.
Dtk_string::filename
Dtk_string filename() const
File Utility : Retrieves the filename in Dtk_string form.
PdfEndWrite
void PdfEndWrite(const Dtk_string &inInputFile)
Definition: PdfWrite.cpp:83
XmlWriteEnd
Dtk_ErrorStatus XmlWriteEnd()
Definition: XmlWrite.cpp:39
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
dtkTypeError
Dtk_string dtkTypeError(Dtk_Int32 errNumero)
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
WritePreview
void WritePreview(const Dtk_PreviewPtr &inPreview, const Dtk_string &inName)
Definition: WritePreview.cpp:4
ProcessedComponents
Dtk_tab< Dtk_ID > ProcessedComponents
Definition: WritePrototype.cpp:16
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
PdfInitWrite
Dtk_ErrorStatus PdfInitWrite(const Dtk_string &inInputFileName, const Dtk_string &inOutputFolder)
Definition: PdfWrite.cpp:34
Dtk_API::GetFilePreview
Dtk_ErrorStatus GetFilePreview(const Dtk_string &inInputFile, Dtk_PreviewPtr &outPreview)
Independant method to get preview of inInputFile.
Dtk_API::GetFileVersion
Dtk_ErrorStatus GetFileVersion(const Dtk_string &inInputFile, Dtk_string &outVersion)
Independant method to get version of inInputFile.
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:151
Dtk_API::SetLogFile
Dtk_ErrorStatus SetLogFile(const Dtk_string &inLogFile)
Set Log File.
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:29
Dtk_API
Definition: dtk_api.hpp:75