Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions include/dulcificum/command_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ enum class CommandType
Pause, // Command to allow for user defined pause.
};

#define MB_BEAD_MODE_TAG(TAG_NAME) \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ cppcoreguidelines-macro-usage ⚠️
function-like macro MB_BEAD_MODE_TAG used; consider a constexpr template function

TAG_NAME##_0, \
TAG_NAME##_1

enum class Tag

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ performance-enum-size ⚠️
enum Tag uses a larger base type (int, size: 4 bytes) than necessary for its value set, consider using std::uint8_t (1 byte) as the base type to reduce its size

{
Invalid,
Expand All @@ -41,11 +45,20 @@ enum class Tag
Restart,
Retract,
Roof,
Support,
Sparse,
TravelMove
TravelMove,
MB_BEAD_MODE_TAG(Fill),
MB_BEAD_MODE_TAG(PrimeTower),
MB_BEAD_MODE_TAG(TopSurface),
MB_BEAD_MODE_TAG(Support),
MB_BEAD_MODE_TAG(SupportInterface),
MB_BEAD_MODE_TAG(WallOuter),
MB_BEAD_MODE_TAG(WallInner),
MB_BEAD_MODE_TAG(Skirt)
};

#undef MB_BEAD_MODE_TAG

using ExtruderIndex = size_t;

struct Command
Expand Down
43 changes: 31 additions & 12 deletions include/dulcificum/miracle_jtp/mgjtp_mappings_json_key_to_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,39 @@ NLOHMANN_JSON_SERIALIZE_ENUM(
{ CommandType::WaitForTemperature, "wait_for_temperature" },
{ CommandType::Pause, "pause" } })

#define MB_JTP_TAG(TAG_NAME, TAG_STR) \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ cppcoreguidelines-macro-usage ⚠️
function-like macro MB_JTP_TAG used; consider a constexpr template function

{ Tag::TAG_NAME, #TAG_STR }

#define MB_BEAD_MODE_TAG_DEF(TAG_NAME, TAG_STR) \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ cppcoreguidelines-macro-usage ⚠️
function-like macro MB_BEAD_MODE_TAG_DEF used; consider a constexpr template function

MB_JTP_TAG(TAG_NAME##_0, TAG_STR##_0), \
MB_JTP_TAG(TAG_NAME##_1, TAG_STR##_1)

NLOHMANN_JSON_SERIALIZE_ENUM(
Tag,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ misc-include-cleaner ⚠️
no header providing "dulcificum::botcmd::Tag" is directly included

{ { Tag::Invalid, "Invalid" },
{ Tag::Infill, "Infill" },
{ Tag::Inset, "Inset" },
{ Tag::Purge, "Purge" },
{ Tag::QuickToggle, "Quick Toggle" },
{ Tag::Raft, "Raft" },
{ Tag::Restart, "Restart" },
{ Tag::Retract, "Retract" },
{ Tag::Roof, "Roof" },
{ Tag::Sparse, "Sparse" },
{ Tag::Support, "Support" },
{ Tag::TravelMove, "Travel Move" } })
{
MB_JTP_TAG(Invalid, Invalid),
MB_JTP_TAG(Infill, Infill),
MB_JTP_TAG(Inset, Inset),
MB_JTP_TAG(Purge, Purge),
MB_JTP_TAG(QuickToggle, Quick Toggle),
MB_JTP_TAG(Raft, Raft),
MB_JTP_TAG(Restart, Restart),
MB_JTP_TAG(Retract, Retract),
MB_JTP_TAG(Roof, Roof),
MB_JTP_TAG(Sparse, Sparse),
MB_JTP_TAG(TravelMove, Travel Move),
MB_BEAD_MODE_TAG_DEF(Fill, FILL),
MB_BEAD_MODE_TAG_DEF(PrimeTower, PRIME_TOWER),
MB_BEAD_MODE_TAG_DEF(TopSurface, TOP_SURFACE),
MB_BEAD_MODE_TAG_DEF(Support, SUPPORT),
MB_BEAD_MODE_TAG_DEF(SupportInterface, SUPPORT_INTERFACE),
MB_BEAD_MODE_TAG_DEF(WallOuter, WALL_OUTER),
MB_BEAD_MODE_TAG_DEF(WallInner, WALL_INNER),
MB_BEAD_MODE_TAG_DEF(Skirt, SKIRT)
})

#undef MB_BEAD_MODE_TAG
#undef MB_JTP_TAG

} // namespace botcmd

Expand Down
105 changes: 95 additions & 10 deletions src/gcode/gcode_to_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,56 +270,141 @@ void VisitCommand::to_proto_path(const gcode::ast::G0_G1& command)
{
if (delta_e > 0)
{
// NOTE: A move may only have a single bead mode tag
move->tags.emplace_back(botcmd::Tag::Restart);
state.is_retracted = false;
proto_path.emplace_back(move);
return;
}
else

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ llvm-else-after-return ⚠️
do not use else after return

Suggested change
else

{
// NOTE: A move may only have a single bead mode tag
move->tags.emplace_back(botcmd::Tag::TravelMove);
proto_path.emplace_back(move);
return;
}
Comment on lines 280 to 285

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ llvm-else-after-return ⚠️
do not use else after return

Suggested change
{
// NOTE: A move may only have a single bead mode tag
move->tags.emplace_back(botcmd::Tag::TravelMove);
proto_path.emplace_back(move);
return;
}
// NOTE: A move may only have a single bead mode tag
move->tags.emplace_back(botcmd::Tag::TravelMove);
proto_path.emplace_back(move);
return;

}
else if (delta_e < 0)
{
// NOTE: A move may only have a single bead mode tag
move->tags.emplace_back(botcmd::Tag::Retract);
state.is_retracted = true;
proto_path.emplace_back(move);
return;
}
else if (delta_e == 0)
{
// NOTE: A move may only have a single bead mode tag
move->tags.emplace_back(botcmd::Tag::TravelMove);
proto_path.emplace_back(move);
return;
}
if (state.feature_type == "WALL-OUTER" || state.feature_type == "INNER-OUTER")

// Bead Mode Tags
// NOTE: A move may only have a single bead mode tag

if (state.feature_type == "WALL-OUTER")
{
move->tags.emplace_back(botcmd::Tag::Inset);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::WallOuter_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::WallOuter_1);
}
}
else if (state.feature_type == "WALL-INNER")
{
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::WallInner_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::WallInner_1);
}
}
else if (state.feature_type == "SKIN")
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ bugprone-branch-clone ⚠️
repeated branch body in conditional chain

move->tags.emplace_back(botcmd::Tag::Roof);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::TopSurface_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::TopSurface_1);
}
}
else if (state.feature_type == "TOP-SURFACE")
{
move->tags.emplace_back(botcmd::Tag::Roof);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::TopSurface_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::TopSurface_1);
}
}
else if (state.feature_type == "PRIME-TOWER")
{
move->tags.emplace_back(botcmd::Tag::Purge);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::PrimeTower_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::PrimeTower_1);
}
}
else if (state.feature_type == "FILL")
{
move->tags.emplace_back(botcmd::Tag::Infill);
move->tags.emplace_back(botcmd::Tag::Sparse);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::Fill_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::Fill_1);
}
}
else if (state.feature_type == "Purge")
{
move->tags.emplace_back(botcmd::Tag::Raft);
}
else if (state.feature_type == "SUPPORT")
{
move->tags.emplace_back(botcmd::Tag::Sparse);
move->tags.emplace_back(botcmd::Tag::Support);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::Support_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::Support_1);
}
}
else if (state.feature_type == "SUPPORT-INTERFACE")
{
move->tags.emplace_back(botcmd::Tag::Support);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::SupportInterface_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::SupportInterface_1);
}
}
else if (state.feature_type == "SKIRT")
{
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::Skirt_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::Skirt_1);
}
}
proto_path.emplace_back(move);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/miracle_jsontoolpath_dialect_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ TEST_F(MiracleJTP, fan_duty)
botcmd::FanDuty cmd;
cmd.index = 0;
cmd.duty = 0.12;
cmd.tags = { botcmd::Tag::TopSurface_1};
auto jcmd = miracle_jtp::toJson(cmd);
auto cmd1 = miracle_jtp::toCommand(jcmd);
auto jcmd1 = miracle_jtp::toJson(*cmd1);
EXPECT_EQ(jcmd, jcmd1);

EXPECT_EQ(nlohmann::to_string(jcmd), "{\"command\":{\"function\":\"fan_duty\",\"metadata\":{},\"parameters\":{\"index\":0,\"value\":0.12},\"tags\":[]}}");
EXPECT_EQ(nlohmann::to_string(jcmd), "{\"command\":{\"function\":\"fan_duty\",\"metadata\":{},\"parameters\":{\"index\":0,\"value\":0.12},\"tags\":[\"TOP_SURFACE_1\"]}}");
}

TEST_F(MiracleJTP, rwrw)
Expand Down
Loading