DATAKIT API  V2025.1
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& mesh, double sh)
{
t.addTranslate(Dtk_dir(sh, 0, 0));
mesh->Transform(t);
}
{
Dtk_Jtw_Interface J(ficname,err);
CHECK_OK(err);
CHECK_OK(J.AddBody(body));
return dtkNoError;
}
{
// create JT leaves
Dtk_string outputDirectory = inResultDirectory + L"dtk/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_Plmxmlw_Interface P(plmxmlfile, err, 0.001); // scale millimeters to meters
CHECK_OK(err);
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() << endl;
return dtkNoError;// Automatic Finish while P released
}
//end_of_plmxmlwsample
// -------------------------------- main -------------------------------------------------
//start_of_plmxmlwmain
int PlmxmlWriteSample(const Dtk_string& inResultDirectory)
{
std::cout << endl << "----------------------------------------------" << endl;
std::cout << "Plmxml Write start" << 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.
int err = PlmxmlwritesampleJT(inResultDirectory);
tess_EndTesselation(); // End of tessellation
std::cout << "Plmxml Write end" << endl;
return err;
}
//end_of_plmxmlwmain
plmxmlw.hpp
Dtk_transfo
This is the Transformation dedicated class.
Definition: dtk_transfo.hpp:19
Dtk_Plmxmlw_Interface
Definition: plmxmlw.hpp:12
jtw.h
sampleWriter::CreateCyl
Dtk_BodyPtr CreateCyl(double radius, double height)
Definition: testcreatecube.cpp:1791
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
tess_InitTesselation
int tess_InitTesselation(Dtk_string inWorkingDirectory, double inTolerance)
Init the tesselation library.
PlmxmlwritesampleJT
Dtk_ErrorStatus PlmxmlwritesampleJT(const Dtk_string &inResultDirectory)
Definition: testlibplmxmlwrite.cpp:36
Dtk_Int64
int64_t Dtk_Int64
Definition: define.h:692
CreateJtFileForPLMXML
Dtk_ErrorStatus CreateJtFileForPLMXML(const Dtk_string &ficname, const Dtk_BodyPtr &body)
Definition: testlibplmxmlwrite.cpp:27
Dtk_ErrorStatus
Dtk_ErrorStatus
Definition: error_dtk.hpp:6
CHECK_OK
#define CHECK_OK(X)
Definition: testwriters.h:9
Dtk_SmartPtr
Definition: util_ptr_dtk.hpp:37
Dtk_MetaData::TypeParameter
@ TypeParameter
Definition: dtk_metadata.hpp:32
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:22
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
tess_ComputeBoundariesFromMesh
int tess_ComputeBoundariesFromMesh()
: Check value of option memorize noundaries of mesh
Dtk_tab
This is a high level array class.
Definition: util_stl_dtk.hpp:85
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:140
Dtk_tab::push_back
void push_back(const T &x)
Inserts an element at the end of the array.
Definition: util_stl_dtk.hpp:415
Dtk_Jtw_Interface
This is Jt Interface class used to write Jt files.
Definition: jtw.h:8
testwriters.h
Shift
void Shift(T &mesh, double sh)
Definition: testlibplmxmlwrite.cpp:20
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:15
Dtk_Jtw_Interface::AddBody
Dtk_ErrorStatus AddBody(const Dtk_BodyPtr &inToWrite, const Dtk_tab< Dtk_Float32 > &makelods=Dtk_tab< Dtk_Float32 >(), Dtk_Float32 inLossytol=0)
Add a body into the current node.
PlmxmlWriteSample
int PlmxmlWriteSample(const Dtk_string &inResultDirectory)
Definition: testlibplmxmlwrite.cpp:100
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 .