Skip to content

Commit

Permalink
Add translation functionality to pyDulcificum
Browse files Browse the repository at this point in the history
Build pyDulcificum target

Usage:
```bash
cd build/<Debug/Release>
source generate/conanrun.sh
cd pyDulcificum
python
```

Then in the Python interpreter you can do:

```python
import pyDulcificum as du
gcode = du.read_file("<path_to_gcode_file>.gcode")  # this will simply return the file content as a string
miracle_jtp = du.gcode_2_miracle_jtp(gcode)  # Translate the gcode to a jsontoolpath as string
du.write_file("<path_to_jsontoolpath_file>.jsontoolpath", jsontoolpath)
```

Contributes to CURA-10561
  • Loading branch information
jellespijker committed Oct 26, 2023
1 parent e1f75c4 commit 2dc556a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion include/dulcificum.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@
#define DULCIFICUM_VERSION "0.1.0"
#endif

// TODO: this will be the main API
#include <dulcificum/gcode/gcode_to_command.h>
#include <dulcificum/gcode/parse.h>
#include <dulcificum/miracle_jtp/mgjtp_command_to_json.h>

namespace dulcificum
{

[[nodiscard]] std::string GCode2Miracle_JTP(const std::string& content)
{
auto gcode_ast = dulcificum::gcode::parse(content);
auto command_list = dulcificum::gcode::toCommand(gcode_ast);
auto json_commands = nlohmann::json::array();
for (const auto& command : command_list)
{
json_commands.emplace_back(dulcificum::miracle_jtp::toJson(*command));
}
return json_commands.dump();
}


} // namespace dulcificum

#endif // DULCIFICUM_INCLUDE_DULCIFICUM_H

0 comments on commit 2dc556a

Please sign in to comment.