DATAKIT SDK  V2026.2
LibReadersSample/main.cpp File Reference

Functions

int LaunchAPISample (int argc, char **argv)
 
int main (int argc, char **argv)
 
void printError (char *executableName)
 

Function Documentation

◆ LaunchAPISample()

int LaunchAPISample ( int  argc,
char **  argv 
)
29 {
30  ////////// Project Options //////////
31 
32  // Activate/Deactivate 3D PDF file creation (geometry, PMI, assembly, materials, etc.)
33  // This option requires Datakit tessellation.
35 
36  // Activate/Deactivate dumping of DTK classes to XML file.
38 
39  // Activate/Deactivate dumping of features (only for CatiaV5, Proe, UG NX).
41 
42  ////////// End Project Options //////
43 
44  // Enable the readers you want to use.
45  EnableReaders();
46 
47  // Set working directory for Dtk_API.
48 #ifndef Linux
49  wchar_t temporaryWorkingDirectory[1024];
50  wchar_t *retwc;
51  retwc = _wgetcwd(temporaryWorkingDirectory, 1024);
52 #else
53  char temporaryWorkingDirectory[1024];
54  getcwd(temporaryWorkingDirectory, 1024);
55 #endif
56 
57  std::cout << "Starting DATAKIT API..." << std::endl;
58 
59  // Start DATAKIT API with the working directory.
60  Dtk_ErrorStatus errorStatus = dtkNoError;
61  Dtk_API *myApi = Dtk_API::StartAPI(temporaryWorkingDirectory, errorStatus);
62  if (myApi == NULL)
63  {
64  // Report error if API fails to start.
65  std::cout << "Can't start DATAKIT API (error code: " << errorStatus << ")" << std::endl;
66  return dtkErrorAPINotStarted;
67  }
68  else
69  {
70  // Report successful API start.
71  std::cout << "DATAKIT API started successfully." << std::endl << std::endl;
72  }
73 
74  // Activate additional API options.
75  ActivateApiOptions(myApi);
76 
77  // Initialize tessellation library if PDF export is enabled.
79  {
81  }
82 
83  // Set Schema directory (required for some readers).
84  SetSchemaDirectory(myApi);
85 
86  // Supported extensions: sat, prt, asm, igs, iges, jt, vda, CATDrawing, CATPart, CATProduct,
87  // cgr, model, x_t, x_b, xmt, par, sldprt, step, stp, ipt, iam, dwg, and more.
88  // Integration is identical for all supported file types.
89 
90  // Process each input file.
91  for (int i = 1; i < argc; i++)
92  {
93  Dtk_string inputFile = argv[i];
94 
95  // Start measuring processing time.
96  time_t startTime;
97  time(&startTime);
98 
99  // Process the current file.
100  Dtk_ErrorStatus curError = ProcessCADFile(inputFile, "");
101 
102  // Stop measuring processing time.
103  time_t stopTime;
104  time(&stopTime);
105 
106  if (curError)
107  {
108  // Report any errors encountered during processing.
109  std::cout << "Error processing file: " << inputFile.c_str()
110  << " (" << dtkTypeError(curError).c_str() << ")" << std::endl;
111  }
112  else
113  {
114  // Report successful processing time.
115  double elapsedTime = difftime(stopTime, startTime);
116  std::cout << "File: " << inputFile.c_str()
117  << " successfully processed in " << elapsedTime << " s" << std::endl << std::endl;
118  }
119  }
120 
121  // Close tessellation kernel if PDF export is enabled.
122  if (IsPdfDumpActivated() == DTK_TRUE)
123  {
124  EndTesselation();
125  }
126 
127  // Stop DATAKIT API at the end.
128  Dtk_API::StopAPI(myApi);
129 
130  std::cout << "Stopping DATAKIT API" << std::endl;
131 
132  return 0;
133 }

◆ main()

int main ( int  argc,
char **  argv 
)
40 {
41 #ifndef Linux
42  // Change the working directory to "../../bin" on non-Linux systems.
43  // This ensures that required binaries and resources are found.
44  _wchdir(L"../../bin");
45 #endif
46 
47  // If no input files are provided, display usage instructions and exit.
48  if (argc == 1)
49  {
50  printError(argv[0]);
51  return 1;
52  }
53 
54  // Process the input files using the Datakit API.
55  return LaunchAPISample(argc, argv);
56 }

◆ printError()

void printError ( char *  executableName)
18 {
19  std::cout << "Usage:\n";
20  std::cout << " " << executableName << " <InputFile1> <InputFile2>\n";
21  std::cout << "\n";
22  std::cout << "Arguments:\n";
23  std::cout << " <InputFile> Mandatory parameter: Path to one or more input files\n";
24  std::cout << "\n";
25  std::cout << "Example:\n";
26  std::cout << " " << executableName << " \"../SampleFiles/Piston.CATPart\"\n";
27 }
SetSchemaDirectory
Dtk_ErrorStatus SetSchemaDirectory(Dtk_API *inoutMyApi)
Definition: EnableReaders.cpp:82
printError
void printError(char *executableName)
Definition: LibReadersSample/main.cpp:17
ActivateApiOptions
void ActivateApiOptions(Dtk_API *inoutMyApi)
Definition: ActivateApiOptions.cpp:3
ActivatePdfDump
void ActivatePdfDump(Dtk_bool inDumpPDF)
Definition: PdfWrite.cpp:24
DTK_TRUE
#define DTK_TRUE
Definition: define.h:719
Dtk_API::StartAPI
static Dtk_API * StartAPI(const Dtk_string &inTemporyDirectory, Dtk_ErrorStatus &outErrorCode, const Dtk_string &inCustomerID=Dtk_string())
Start DATAKIT API.
InitTesselation
DtkErrorStatus InitTesselation()
Definition: TesselationEngine.cpp:18
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
ActivateFeatureDump
void ActivateFeatureDump(Dtk_bool inDumpFeature)
Definition: WriteFeature.cpp:7
DTK_FALSE
#define DTK_FALSE
Definition: define.h:720
dtkErrorAPINotStarted
@ dtkErrorAPINotStarted
Definition: error_dtk.hpp:107
ActivateXmlDump
void ActivateXmlDump(Dtk_bool inDumpXml)
Definition: XmlWrite.cpp:12
EndTesselation
void EndTesselation()
Definition: TesselationEngine.cpp:47
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
dtkTypeError
Dtk_string dtkTypeError(Dtk_Int32 errNumero)
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
EnableReaders
void EnableReaders()
Definition: EnableReaders.cpp:12
LaunchAPISample
int LaunchAPISample(int argc, char **argv)
Definition: StartAPI.cpp:28
Dtk_API::StopAPI
static void StopAPI(Dtk_API *&inAPI, Dtk_bool inWriteTimeInLog=1)
Stop DATAKIT API.
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:149
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:29
Dtk_API
Definition: dtk_api.hpp:75
ProcessCADFile
Dtk_ErrorStatus ProcessCADFile(const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
Definition: OpenDocument.cpp:18