DATAKIT API  V2025.1
StartAPI.cpp File Reference

Functions

void ActivateApiOptions (Dtk_API *inoutMyApi)
 
void ActivateFeatureDump (Dtk_bool inDumpFeature)
 
void EnableReaders ()
 
int LaunchAPISample (int argc, char **argv)
 
Dtk_ErrorStatus ProcessCADFile (const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
 
Dtk_ErrorStatus SetSchemaDirectory (Dtk_API *inoutMyApi)
 

Function Documentation

◆ ActivateApiOptions()

void ActivateApiOptions ( Dtk_API inoutMyApi)
9 {
10 
11 }

◆ ActivateFeatureDump()

void ActivateFeatureDump ( Dtk_bool  inDumpFeature)
8 {
9  toDumpFeatures = inDumpFeature;
10 }

◆ EnableReaders()

void EnableReaders ( )
13 {
14 // Supported Format : extensions
15 //Acis : sat
16 //Catiav4 : model (both 2d and 3d) session, dlv
17 //Catiav5 : CATDrawing,CATPart,CATProduct
18 //Cgr : cgr
19 //Dwg : dwg
20 //Iges : igs,iges
21 //Inventor : ipt,iam
22 //Jt : jt
23 //Parasolid : x_t,x_b,xmt
24 //Proe : prt,asm
25 //Solidedge : par,asm
26 //Solidworks : sldprt,sldasm
27 //Step : step,stp
28 //Unigraphics: prt (both 2d and 3d)
29 //Vda : vda
30  //First You have to Enable the readers you want to use
33 #ifndef Linux
35 #endif
45 #ifndef CENTOS
47 #endif
61 #ifdef USE_PSKERNEL
63 #else
65 #endif
75 }

◆ LaunchAPISample()

int LaunchAPISample ( int  argc,
char **  argv 
)
41 {
42 
44  // Activates / deactivates 3D PDF file creation with geometrical, PMI, assembly, materials datas...
45  // This option requires Datakit tessellation
47 
48  // Activates / deactivates dumping of DTK classes to XML file
50 
51  // Activates / deactivates dumping of features (only implemented for CatiaV5, Proe, UG)
54 
55  //First You have to Enable the readers you want to use
56  EnableReaders();
57 
58  //Dtk_API need a working directory where it can write
59 #ifndef Linux
60  wchar_t TemporaryWorkingDirectory[1024];
61  wchar_t *retwc;
62  retwc = _wgetcwd(TemporaryWorkingDirectory, 1024);
63 #else
64  char TemporaryWorkingDirectory[1024];
65  getcwd(TemporaryWorkingDirectory, 1024);
66 #endif
67 
68  //Then You have to Start DATAKIT API with a temporary directory
69  Dtk_ErrorStatus errorStatus = dtkNoError;
70  cout << "Starting DATAKIT API " << endl;
71  Dtk_API * MyAPI = Dtk_API::StartAPI(TemporaryWorkingDirectory, errorStatus);
72  if (MyAPI == NULL)
73  {
74  cout << "Can't Start DATAKIT API : " << errorStatus << endl;
75  return dtkErrorAPINotStarted;
76  }
77 
78  ActivateApiOptions(MyAPI);
79 
80  //Initialization of tessellation library (used for PDF )
82  {
84  }
85 
86  //
87  Dtk_ErrorStatus SchemaStatus;
88  SchemaStatus = SetSchemaDirectory(MyAPI);
89 
90 
91 //Here are sample files coming from several CAD software or neutral format
92 //Integration is the same for all type of file
93 // Supported Extensions : sat,prt,asm,igs,iges,jt,vda,CATDrawing,CATPart,CATProduct,cgr,model,x_t,x_b,xmt,par,sldprt,step,stp,ipt,iam, dwg and more
94 
95  for (int i = 1; i < argc; i++)
96  {
97  Dtk_string InputFile = argv[i];
98  time_t StartTime;
99  time(&(StartTime));
100  Dtk_ErrorStatus curError = ProcessCADFile(InputFile, "");
101 
102  time_t StopTime;
103  time(&(StopTime));
104 
105  if (curError)
106  {
107  cout << "error processing file " << InputFile.c_str() << " (" << dtkTypeError(curError).c_str() << " s)" << endl;
108  }
109  else
110  {
111  double elaps_time = difftime(StopTime, StartTime);
112  cout << "file " << InputFile.c_str() << "processed during (" << elaps_time << " s)" << endl;
113  }
114  }
115 
116  if (IsPdfDumpActivated() == DTK_TRUE)
117  {//Close tessellation kernel
118  EndTesselation();
119  }
120 
121  //At the end you stop DATAKIT API
122  Dtk_API::StopAPI(MyAPI);
123  cout << "Stopping DATAKIT API " << endl;
124 
125  return 0;
126 }

◆ ProcessCADFile()

Dtk_ErrorStatus ProcessCADFile ( const Dtk_string inInputFile,
const Dtk_string inOutputFolder 
)
19 {
20  DtkErrorStatus stError = dtkNoError;
21  Dtk_ErrorStatus stErrorPdf = dtkNoError;
22  Dtk_ErrorStatus stErrorXml = dtkNoError;
23 
24  Dtk_MainDocPtr TmpDoc;
25  ComponentProcessed.clear();
26 
27  // You Get the current API
28  Dtk_API * MyAPI = Dtk_API::GetAPI();
29 
30  cout << "Processing file " << inInputFile.c_str() << endl;
31 
32  Dtk_string FileVersion;
33  stError = MyAPI->GetFileVersion(inInputFile, FileVersion);
34 
35  if( FileVersion.is_not_NULL() )
36  cout <<"File version = " << FileVersion.c_str() << endl;
37  if (stError != dtkNoError)
38  {
39  cout << "Error with file version: " << dtkTypeError( stError ).c_str() << endl;
40  return stError;
41  }
42 
43  //If you want to get a log file for reader (inventory, missing files in assembly...) you have to set it
44  MyAPI->SetLogFile( "DtkLogFile.txt" );
45 
46  //Following Project Options
47  // To Write an Xml file
48  if(IsXmlDumpActivated())
49  {
50  stErrorXml = XmlWriteInit( inInputFile, inOutputFolder );
51  }
52  // To Write an PDF file
53  if(IsPdfDumpActivated())
54  {
55  stErrorPdf = PdfInitWrite( inInputFile, inOutputFolder );
56  }
57 
58 
59 
60  //You Open the file you want to read and get corresponding Document
61  Dtk_ErrorStatus err = MyAPI->OpenDocument( inInputFile, TmpDoc );
62 
63  //If no Error we write the Document
64  if( err == dtkNoError && TmpDoc.IsNotNULL() )
65  {
66  WriteDocument( TmpDoc ); //see WriteDocument.cpp
67  }
68  else
69  {
70  cout << "Error OpenDocument: " << err << dtkTypeError( err ).c_str() << endl;
71  }
72 
73  //We close the opened document
74  err = MyAPI->EndDocument( TmpDoc );
75 
76  if(IsXmlDumpActivated())
77  {
78  XmlWriteEnd();
79  }
80  if(IsPdfDumpActivated())
81  {
82  PdfEndWrite( inInputFile );
83  }
84 
85  return err;
86 }

◆ SetSchemaDirectory()

Dtk_ErrorStatus SetSchemaDirectory ( Dtk_API inoutMyApi)
79 {
80  Dtk_ErrorStatus SchemaStatus;
81  Dtk_string SchemaDirectory = "./Schema";
82 
83  //Set the Schema directory needed for readers based on Pskernel (UG, Solidworks, Solidedge), or CADDS
84 #ifndef Linux
85  char TmpFullPathSchemaDir[_MAX_PATH];
86  if (_fullpath(TmpFullPathSchemaDir, SchemaDirectory.c_str(), _MAX_PATH) != NULL)
87  SchemaStatus = inoutMyApi->SetSchemaDir(TmpFullPathSchemaDir);
88  else
89  SchemaStatus = inoutMyApi->SetSchemaDir(SchemaDirectory);
90 #else
91  SchemaStatus = inoutMyApi->SetSchemaDir(SchemaDirectory);
92 #endif
93 
94 #ifdef USE_PSKERNEL
95  if (SchemaStatus != dtkNoError)
96  {
97  cout <<"Schema Directory error -needed for readers based on Pskernel (UG, Solidworks, Solidedge), or CADDS- : " << dtkTypeError(SchemaStatus).c_str() << endl;
98  }
99 #endif
100  return SchemaStatus;
101 }
ObjReader::Enable
static Dtk_bool Enable()
Dtk_API::EndDocument
Dtk_ErrorStatus EndDocument(Dtk_MainDocPtr &inoutDocument)
Close a Document.
CgrReader::Enable
static Dtk_bool Enable()
SmgReader::Enable
static Dtk_bool Enable()
SetSchemaDirectory
Dtk_ErrorStatus SetSchemaDirectory(Dtk_API *inoutMyApi)
Definition: EnableReaders.cpp:78
NavisReader::Enable
static Dtk_bool Enable()
LavaReader::Enable
static Dtk_bool Enable()
JtReader::Enable
static Dtk_bool Enable()
CgmReader::Enable
static Dtk_bool Enable()
GltfReader::Enable
static Dtk_bool Enable()
StlReader::Enable
static Dtk_bool Enable()
Dtk_SmartPtr::IsNotNULL
Dtk_bool IsNotNULL() const
Definition: util_ptr_dtk.hpp:119
SwReader::Enable
static Dtk_bool Enable()
toDumpFeatures
Dtk_bool toDumpFeatures
Definition: WriteFeature.cpp:5
_3dmReader::Enable
static Dtk_bool Enable()
ActivateApiOptions
void ActivateApiOptions(Dtk_API *inoutMyApi)
Definition: ActivateApiOptions.cpp:8
ActivatePdfDump
void ActivatePdfDump(Dtk_bool inDumpPDF)
Definition: PdfWrite.cpp:21
CerconReader::Enable
static Dtk_bool Enable()
DTK_TRUE
#define DTK_TRUE
Definition: define.h:727
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:13
F3dReader::Enable
static Dtk_bool Enable()
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
WriteDocument
Dtk_ErrorStatus WriteDocument(Dtk_MainDocPtr inDocument)
Definition: WriteDocument.cpp:12
PlmXmlReader::Enable
static Dtk_bool Enable()
XmlWriteInit
Dtk_ErrorStatus XmlWriteInit(Dtk_string inInputFile, const Dtk_string &inOutputFolder)
Definition: XmlWrite.cpp:22
ActivateFeatureDump
void ActivateFeatureDump(Dtk_bool inDumpFeature)
Definition: WriteFeature.cpp:7
CatiaV4Reader::Enable
static Dtk_bool Enable()
StepReader::Enable
static Dtk_bool Enable()
Dtk_API::OpenDocument
Dtk_ErrorStatus OpenDocument(const Dtk_string &inInputFile, Dtk_MainDocPtr &outDocument)
Open a Document (call EndDocument to close it)
DTK_FALSE
#define DTK_FALSE
Definition: define.h:728
RevitReader::Enable
static Dtk_bool Enable()
dtkErrorAPINotStarted
@ dtkErrorAPINotStarted
Definition: error_dtk.hpp:101
Dtk_API::SetSchemaDir
Dtk_ErrorStatus SetSchemaDir(const Dtk_string &inSchemaDir)
Set Schema Directory needed for Unigraphics, Parasolid, Solidedge, Solidworks and Jt readers.
ProeReader::Enable
static Dtk_bool Enable()
CaddsReader::Enable
static Dtk_bool Enable()
DwgReader::Enable
static Dtk_bool Enable()
InvReader::Enable
static Dtk_bool Enable()
ProCeraReader::Enable
static Dtk_bool Enable()
ActivateXmlDump
void ActivateXmlDump(Dtk_bool inDumpXml)
Definition: XmlWrite.cpp:12
Dtk_string::is_not_NULL
Dtk_bool is_not_NULL() const
UgReader::Enable
static Dtk_bool Enable()
Dtk_API::GetAPI
static Dtk_API * GetAPI()
Get DATAKIT API.
CatiaV5Reader::Enable
static Dtk_bool Enable()
PdfEndWrite
void PdfEndWrite(const Dtk_string &inInputFile)
Definition: PdfWrite.cpp:80
IgesReader::Enable
static Dtk_bool Enable()
EndTesselation
void EndTesselation()
Definition: TesselationEngine.cpp:40
CatiaV6Reader::Enable
static Dtk_bool Enable()
XmlWriteEnd
Dtk_ErrorStatus XmlWriteEnd()
Definition: XmlWrite.cpp:39
IfcReader::Enable
static Dtk_bool Enable()
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
DcmReader::Enable
static Dtk_bool Enable()
PsReader::Enable
static Dtk_bool Enable()
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.
EnableReaders
void EnableReaders()
Definition: EnableReaders.cpp:12
CerecReader::Enable
static Dtk_bool Enable()
ComponentProcessed
Dtk_tab< Dtk_ID > ComponentProcessed
Definition: WritePrototype.cpp:12
CreoviewReader::Enable
static Dtk_bool Enable()
XmtReader::Enable
static Dtk_bool Enable()
FbxReader::Enable
static Dtk_bool Enable()
Dtk_API::StopAPI
static void StopAPI(Dtk_API *&inAPI, Dtk_bool inWriteTimeInLog=1)
Stop DATAKIT API.
IsXmlDumpActivated
Dtk_bool IsXmlDumpActivated()
Definition: XmlWrite.cpp:17
PdfInitWrite
Dtk_ErrorStatus PdfInitWrite(const Dtk_string &inInputFileName, const Dtk_string &inOutputFolder)
Definition: PdfWrite.cpp:31
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:140
VdaReader::Enable
static Dtk_bool Enable()
SolidEdgeReader::Enable
static Dtk_bool Enable()
QifReader::Enable
static Dtk_bool Enable()
Dtk_API::SetLogFile
Dtk_ErrorStatus SetLogFile(const Dtk_string &inLogFile)
Set Log File.
IsPdfDumpActivated
Dtk_bool IsPdfDumpActivated()
Definition: PdfWrite.cpp:26
Dtk_API
Definition: dtk_api.hpp:75
ProcessCADFile
Dtk_ErrorStatus ProcessCADFile(const Dtk_string &inInputFile, const Dtk_string &inOutputFolder)
Definition: OpenDocument.cpp:18
AcisReader::Enable
static Dtk_bool Enable()