DATAKIT SDK  V2026.4
Full samples source code
// -------------------------------------------------------------------------
// Datakit PLMXMLWriter samples
// this file allow to write several PLMXML files
// see main function for each case, on the end of this file
// -------------------------------------------------------------------------
#include "testwriters.h"
#include "datakit.h" // DATAKIT header needed
#include "jw/jtw.h" // JtWrite header, for parts
#include "plmxmlw/plmxmlw.hpp" // PlmXml header needed
#include "tess/tess.h" // tessellation header needed for example from 2.
#include "SampleWriter/testcreatecube.hpp" // common datakit bodies creation
//start_of_plmxmlwsample
template <typename T>
inline void Shift(T& inoutMesh, double inShiftAmount)
{
Dtk_transfo translation;
translation.addTranslate(Dtk_dir(inShiftAmount, 0, 0));
inoutMesh->Transform(translation);
}
Dtk_ErrorStatus CreateJtFileForPLMXML(const Dtk_string& inOutputFileName, const Dtk_BodyPtr& inBody)
{
Dtk_ErrorStatus errorStatus;
Dtk_Jtw_Interface jtWriter(inOutputFileName,errorStatus);
CHECK_OK(errorStatus);
CHECK_OK(jtWriter.AddBody(inBody));
return dtkNoError;
}
{
// create JT leaves
Dtk_string outputDirectory = inResultDirectory + L"Plmxml/";
outputDirectory.FixPathSeparator();
outputDirectory.mkdir();
Dtk_string axlename = outputDirectory + L"axle.jt";
Dtk_string wheelname = outputDirectory + L"wheel.jt";
Dtk_string plmxmlfile = outputDirectory + L"sample1.plmxml";
CHECK_OK(CreateJtFileForPLMXML(axlename, axle));
CHECK_OK(CreateJtFileForPLMXML(wheelname, wheel));
// prepare datas for PLMXML
Dtk_Int64 id_of_wheel = 1;
Dtk_Int64 id_of_axles = 2;
Dtk_dir X(1, 0, 0);
Dtk_dir Y(0, 1, 0);
Dtk_dir Z(0, 0, 1);
// create PLMXML
Dtk_ErrorStatus errorStatus;
Dtk_Plmxmlw_Interface P(plmxmlfile, errorStatus, 0.001); // scale millimeters to meters
CHECK_OK(errorStatus);
CHECK_OK(P.OpenInstance("RootNode")); // Rootnode creation
CHECK_OK(P.OpenInstance("Axles", id_of_axles)); // open Axles, give an ID for future reinstance, placement by default : identity matrix
CHECK_OK(P.OpenInstance("Axle")); // open
CHECK_OK(P.SetExternFic(axlename));
CHECK_OK(P.CloseLastInstance()); // close Axle
CHECK_OK(P.OpenInstance("Wheels")); // open
CHECK_OK(P.OpenInstance("Wheel", id_of_wheel, Dtk_transfo(X, Y, Z, Dtk_pnt(0, 0, 5)))); // open instance
CHECK_OK(P.SetExternFic(wheelname));
CHECK_OK(P.CloseLastInstance()); // close Wheel
CHECK_OK(P.OpenInstance("Wheel2", id_of_wheel, Dtk_transfo(X, -Y, -Z, Dtk_pnt()), meta1)); // open reinstance
CHECK_OK(P.CloseLastInstance()); // reinstancied : must close Wheel immediatly.
CHECK_OK(P.CloseLastInstance()); // close Wheels
CHECK_OK(P.CloseLastInstance()); // close Axles
CHECK_OK(P.OpenInstance("Axles2", id_of_axles, Dtk_transfo(X, Y, Z, Dtk_pnt(10, 0, 0)),meta2)); // reinstance whole subassembly with matrix
CHECK_OK(P.CloseLastInstance()); // reinstancied : must close Wheel immediatly.
CHECK_OK(P.CloseLastInstance()); // close RootNode
std::cout << "=> " << plmxmlfile.c_str() << std::endl;
return dtkNoError;// Automatic Finish while P released
}
//end_of_plmxmlwsample
// -------------------------------- main -------------------------------------------------
//start_of_plmxmlwmain
DtkErrorStatus PlmxmlWriteSample(const Dtk_string& inResultDirectory)
{
std::cout << std::endl << "----------------------------------------------" << std::endl;
std::cout << "Plmxml Write start" << std::endl;
tess_InitTesselation("./", 0.005); // For JT : Init Tessellation : working directory and default tolerance (needed for writing bodies)
tess_ComputeBoundariesFromMesh(0); // Disable wire creation on mesh during Brep tessellation.
DtkErrorStatus errorStatus = PlmxmlwritesampleJT(inResultDirectory);
tess_EndTesselation(); // End of tessellation
std::cout << "Plmxml Write end" << std::endl;
return errorStatus;
}
//end_of_plmxmlwmain
plmxmlw.hpp
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
PlmxmlWriteSample
DtkErrorStatus PlmxmlWriteSample(const Dtk_string &inResultDirectory)
Definition: testlibplmxmlwrite.cpp:100
Dtk_Plmxmlw_Interface
Definition: plmxmlw.hpp:12
jtw.h
sampleWriter::CreateCyl
Dtk_BodyPtr CreateCyl(double radius, double height)
Creates a BRep cylinder body with the given radius and height using analytical cylindrical and planar...
Definition: testcreatecube.cpp:1770
tess_InitTesselation
int tess_InitTesselation(Dtk_string inWorkingDirectory, double inTolerance)
Init the tesselation library.
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Shift
void Shift(T &inoutMesh, double inShiftAmount)
Definition: testlibplmxmlwrite.cpp:20
tess_ComputeBoundariesFromMesh
void tess_ComputeBoundariesFromMesh(int value)
Set boundaries computation from mesh option. Default value is enabled (1). See tess_getBoundariesFrom...
CreateJtFileForPLMXML
Dtk_ErrorStatus CreateJtFileForPLMXML(const Dtk_string &inOutputFileName, const Dtk_BodyPtr &inBody)
Definition: testlibplmxmlwrite.cpp:27
PlmxmlwritesampleJT
Dtk_ErrorStatus PlmxmlwritesampleJT(const Dtk_string &inResultDirectory)
Definition: testlibplmxmlwrite.cpp:36
Dtk_Int64
int64_t Dtk_Int64
Definition: define.h:691
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
CHECK_OK
#define CHECK_OK(X)
Definition: testwriters.h:8
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
Dtk_MetaData::TypeParameter
@ TypeParameter
Definition: dtk_metadata.hpp:33
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
tess.h
Dtk_string::mkdir
int mkdir() const
File Utility : Create a Directory.
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:20
Dtk_string::FixPathSeparator
void FixPathSeparator()
File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed ...
datakit.h
testcreatecube.hpp
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:84
Dtk_transfo::addTranslate
void addTranslate(const Dtk_dir &V)
Translate the Dtk_transfo.
tess_EndTesselation
void tess_EndTesselation()
Free the data used by tesselation library.
dtkNoError
@ dtkNoError
Definition: error_dtk.hpp:151
Dtk_tab::push_back
void push_back(const T &x)
Inserts an element at the end of the array.
Definition: util_stl_dtk.hpp:416
Dtk_Jtw_Interface
This is Jt Interface class used to write Jt files.
Definition: jtw.h:21
testwriters.h
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:14
Dtk_MetaData::CreateMetaData
static Dtk_MetaDataPtr CreateMetaData(const MetaDataTypeEnum &inEnumType, Dtk_string inTitle, Dtk_string inValue, Dtk_string inValueType=Dtk_string(L"STRING"))
Create a Dtk_MetaDataPtr .