WIP Extending the expressivity of ExtrusionRole
Separated ExtrusionRole / GCodeExtrusionRole into ExtrusionRole.cpp,hpp
This commit is contained in:
Vojtech Bubnik 2023-01-16 10:47:27 +01:00
parent d58cb1b5ba
commit e50e96bb26
9 changed files with 243 additions and 219 deletions

View File

@ -56,6 +56,8 @@ set(SLIC3R_SOURCES
ExtrusionEntity.hpp
ExtrusionEntityCollection.cpp
ExtrusionEntityCollection.hpp
ExtrusionRole.cpp
ExtrusionRole.hpp
ExtrusionSimulator.cpp
ExtrusionSimulator.hpp
FileParserError.hpp

View File

@ -8,8 +8,6 @@
#include <limits>
#include <sstream>
#define L(s) (s)
namespace Slic3r {
void ExtrusionPath::intersect_expolygons(const ExPolygons &collection, ExtrusionEntityCollection* retval) const
@ -322,83 +320,4 @@ double ExtrusionLoop::min_mm3_per_mm() const
return min_mm3_per_mm;
}
// Convert a rich bitmask based ExtrusionRole to a less expressive ordinal GCodeExtrusionRole.
// GCodeExtrusionRole is to be serialized into G-code and deserialized by G-code viewer,
GCodeExtrusionRole extrusion_role_to_gcode_extrusion_role(ExtrusionRole role)
{
if (role == ExtrusionRole::None) return erNone;
if (role == ExtrusionRole::Perimeter) return erPerimeter;
if (role == ExtrusionRole::ExternalPerimeter) return erExternalPerimeter;
if (role == ExtrusionRole::OverhangPerimeter) return erOverhangPerimeter;
if (role == ExtrusionRole::InternalInfill) return erInternalInfill;
if (role == ExtrusionRole::SolidInfill) return erSolidInfill;
if (role == ExtrusionRole::TopSolidInfill) return erTopSolidInfill;
if (role == ExtrusionRole::Ironing) return erIroning;
if (role == ExtrusionRole::BridgeInfill) return erBridgeInfill;
if (role == ExtrusionRole::GapFill) return erGapFill;
if (role == ExtrusionRole::Skirt) return erSkirt;
if (role == ExtrusionRole::SupportMaterial) return erSupportMaterial;
if (role == ExtrusionRole::SupportMaterialInterface) return erSupportMaterialInterface;
if (role == ExtrusionRole::WipeTower) return erWipeTower;
assert(false);
return erNone;
}
std::string gcode_extrusion_role_to_string(GCodeExtrusionRole role)
{
switch (role) {
case erNone : return L("Unknown");
case erPerimeter : return L("Perimeter");
case erExternalPerimeter : return L("External perimeter");
case erOverhangPerimeter : return L("Overhang perimeter");
case erInternalInfill : return L("Internal infill");
case erSolidInfill : return L("Solid infill");
case erTopSolidInfill : return L("Top solid infill");
case erIroning : return L("Ironing");
case erBridgeInfill : return L("Bridge infill");
case erGapFill : return L("Gap fill");
case erSkirt : return L("Skirt/Brim");
case erSupportMaterial : return L("Support material");
case erSupportMaterialInterface : return L("Support material interface");
case erWipeTower : return L("Wipe tower");
case erCustom : return L("Custom");
default : assert(false);
}
return {};
}
GCodeExtrusionRole string_to_gcode_extrusion_role(const std::string_view role)
{
if (role == L("Perimeter"))
return erPerimeter;
else if (role == L("External perimeter"))
return erExternalPerimeter;
else if (role == L("Overhang perimeter"))
return erOverhangPerimeter;
else if (role == L("Internal infill"))
return erInternalInfill;
else if (role == L("Solid infill"))
return erSolidInfill;
else if (role == L("Top solid infill"))
return erTopSolidInfill;
else if (role == L("Ironing"))
return erIroning;
else if (role == L("Bridge infill"))
return erBridgeInfill;
else if (role == L("Gap fill"))
return erGapFill;
else if (role == L("Skirt") || role == L("Skirt/Brim")) // "Skirt" is for backward compatibility with 2.3.1 and earlier
return erSkirt;
else if (role == L("Support material"))
return erSupportMaterial;
else if (role == L("Support material interface"))
return erSupportMaterialInterface;
else if (role == L("Wipe tower"))
return erWipeTower;
else if (role == L("Custom"))
return erCustom;
else
return erNone;
}
}

View File

@ -2,9 +2,9 @@
#define slic3r_ExtrusionEntity_hpp_
#include "libslic3r.h"
#include "ExtrusionRole.hpp"
#include "Polygon.hpp"
#include "Polyline.hpp"
#include "enum_bitmask.hpp"
#include <assert.h>
#include <string_view>
@ -17,133 +17,6 @@ using ExPolygons = std::vector<ExPolygon>;
class ExtrusionEntityCollection;
class Extruder;
enum class ExtrusionRoleModifier : uint16_t {
// 1) Extrusion types
// Perimeter (external, inner, ...)
Perimeter,
// Infill (top / bottom / solid inner / sparse inner / bridging inner ...)
Infill,
// Variable width extrusion
Thin,
// Support material extrusion
Support,
Skirt,
Wipe,
// 2) Extrusion modifiers
External,
Solid,
Ironing,
Bridge,
// 3) Special types
// Indicator that the extrusion role was mixed from multiple differing extrusion roles,
// for example from Support and SupportInterface.
Mixed,
// Stopper, there should be maximum 16 modifiers defined for uint16_t bit mask.
Count
};
// There should be maximum 16 modifiers defined for uint16_t bit mask.
static_assert(int(ExtrusionRoleModifier::Count) <= 16, "ExtrusionRoleModifier: there must be maximum 16 modifiers defined to fit a 16 bit bitmask");
using ExtrusionRoleModifiers = enum_bitmask<ExtrusionRoleModifier>;
ENABLE_ENUM_BITMASK_OPERATORS(ExtrusionRoleModifier);
struct ExtrusionRole : public ExtrusionRoleModifiers
{
constexpr ExtrusionRole(const ExtrusionRoleModifier bit) : ExtrusionRoleModifiers(bit) {}
constexpr ExtrusionRole(const ExtrusionRoleModifiers bits) : ExtrusionRoleModifiers(bits) {}
static constexpr const ExtrusionRoleModifiers None{};
// Internal perimeter, not bridging.
static constexpr const ExtrusionRoleModifiers Perimeter{ ExtrusionRoleModifier::Perimeter };
// External perimeter, not bridging.
static constexpr const ExtrusionRoleModifiers ExternalPerimeter{ ExtrusionRoleModifier::Perimeter | ExtrusionRoleModifier::External };
// Perimeter, bridging. To be or'ed with ExtrusionRoleModifier::External for external bridging perimeter.
static constexpr const ExtrusionRoleModifiers OverhangPerimeter{ ExtrusionRoleModifier::Perimeter | ExtrusionRoleModifier::Bridge };
// Sparse internal infill.
static constexpr const ExtrusionRoleModifiers InternalInfill{ ExtrusionRoleModifier::Infill };
// Solid internal infill.
static constexpr const ExtrusionRoleModifiers SolidInfill{ ExtrusionRoleModifier::Infill | ExtrusionRoleModifier::Solid };
// Top solid infill (visible).
//FIXME why there is no bottom solid infill type?
static constexpr const ExtrusionRoleModifiers TopSolidInfill{ ExtrusionRoleModifier::Infill | ExtrusionRoleModifier::Solid | ExtrusionRoleModifier::External };
// Ironing infill at the top surfaces.
static constexpr const ExtrusionRoleModifiers Ironing{ ExtrusionRoleModifier::Infill | ExtrusionRoleModifier::Ironing | ExtrusionRoleModifier::External };
// Visible bridging infill at the bottom of an object.
static constexpr const ExtrusionRoleModifiers BridgeInfill{ ExtrusionRoleModifier::Infill | ExtrusionRoleModifier::Solid | ExtrusionRoleModifier::Bridge | ExtrusionRoleModifier::External };
// static constexpr const ExtrusionRoleModifiers InternalBridgeInfill{ ExtrusionRoleModifier::Infill | ExtrusionRoleModifier::Solid | ExtrusionRoleModifier::Bridge };
// Gap fill extrusion, currently used for any variable width extrusion: Thin walls outside of the outer extrusion,
// gap fill in between perimeters, gap fill between the inner perimeter and infill.
//FIXME revise GapFill and ThinWall types, split Gap Fill to Gap Fill and ThinWall.
static constexpr const ExtrusionRoleModifiers GapFill{ ExtrusionRoleModifier::Thin }; // | ExtrusionRoleModifier::External };
// static constexpr const ExtrusionRoleModifiers ThinWall{ ExtrusionRoleModifier::Thin };
static constexpr const ExtrusionRoleModifiers Skirt{ ExtrusionRoleModifier::Skirt };
// Support base material, printed with non-soluble plastic.
static constexpr const ExtrusionRoleModifiers SupportMaterial{ ExtrusionRoleModifier::Support };
// Support interface material, printed with soluble plastic.
static constexpr const ExtrusionRoleModifiers SupportMaterialInterface{ ExtrusionRoleModifier::Support | ExtrusionRoleModifier::External };
// Wipe tower material.
static constexpr const ExtrusionRoleModifiers WipeTower{ ExtrusionRoleModifier::Wipe };
// Extrusion role for a collection with multiple extrusion roles.
static constexpr const ExtrusionRoleModifiers Mixed{ ExtrusionRoleModifier::Mixed };
};
// Special flags describing loop
enum ExtrusionLoopRole {
elrDefault,
elrContourInternalPerimeter,
elrSkirt,
};
inline bool is_perimeter(ExtrusionRole role)
{
return role == ExtrusionRole::Perimeter
|| role == ExtrusionRole::ExternalPerimeter
|| role == ExtrusionRole::OverhangPerimeter;
}
inline bool is_infill(ExtrusionRole role)
{
return role == ExtrusionRole::BridgeInfill
|| role == ExtrusionRole::InternalInfill
|| role == ExtrusionRole::SolidInfill
|| role == ExtrusionRole::TopSolidInfill
|| role == ExtrusionRole::Ironing;
}
inline bool is_solid_infill(ExtrusionRole role)
{
return role == ExtrusionRole::BridgeInfill
|| role == ExtrusionRole::SolidInfill
|| role == ExtrusionRole::TopSolidInfill
|| role == ExtrusionRole::Ironing;
}
inline bool is_bridge(ExtrusionRole role) {
return role == ExtrusionRole::BridgeInfill
|| role == ExtrusionRole::OverhangPerimeter;
}
enum GCodeExtrusionRole : uint8_t {
erNone,
erPerimeter,
erExternalPerimeter,
erOverhangPerimeter,
erInternalInfill,
erSolidInfill,
erTopSolidInfill,
erIroning,
erBridgeInfill,
erGapFill,
erSkirt,
erSupportMaterial,
erSupportMaterialInterface,
erWipeTower,
// Custom (user defined) G-code block, for example start / end G-code.
erCustom,
// Stopper to count number of enums.
erCount
};
class ExtrusionEntity
{
public:
@ -179,13 +52,6 @@ public:
virtual double total_volume() const = 0;
};
// Convert a rich bitmask based ExtrusionRole to a less expressive ordinal GCodeExtrusionRole.
// GCodeExtrusionRole is to be serialized into G-code and deserialized by G-code viewer,
GCodeExtrusionRole extrusion_role_to_gcode_extrusion_role(ExtrusionRole role);
std::string gcode_extrusion_role_to_string(GCodeExtrusionRole role);
GCodeExtrusionRole string_to_gcode_extrusion_role(const std::string_view role);
typedef std::vector<ExtrusionEntity*> ExtrusionEntitiesPtr;
class ExtrusionPath : public ExtrusionEntity

View File

@ -0,0 +1,89 @@
#include "ExtrusionRole.hpp"
#include <string>
#include <string_view>
#define L(s) (s)
namespace Slic3r {
// Convert a rich bitmask based ExtrusionRole to a less expressive ordinal GCodeExtrusionRole.
// GCodeExtrusionRole is to be serialized into G-code and deserialized by G-code viewer,
GCodeExtrusionRole extrusion_role_to_gcode_extrusion_role(ExtrusionRole role)
{
if (role == ExtrusionRole::None) return erNone;
if (role == ExtrusionRole::Perimeter) return erPerimeter;
if (role == ExtrusionRole::ExternalPerimeter) return erExternalPerimeter;
if (role == ExtrusionRole::OverhangPerimeter) return erOverhangPerimeter;
if (role == ExtrusionRole::InternalInfill) return erInternalInfill;
if (role == ExtrusionRole::SolidInfill) return erSolidInfill;
if (role == ExtrusionRole::TopSolidInfill) return erTopSolidInfill;
if (role == ExtrusionRole::Ironing) return erIroning;
if (role == ExtrusionRole::BridgeInfill) return erBridgeInfill;
if (role == ExtrusionRole::GapFill) return erGapFill;
if (role == ExtrusionRole::Skirt) return erSkirt;
if (role == ExtrusionRole::SupportMaterial) return erSupportMaterial;
if (role == ExtrusionRole::SupportMaterialInterface) return erSupportMaterialInterface;
if (role == ExtrusionRole::WipeTower) return erWipeTower;
assert(false);
return erNone;
}
std::string gcode_extrusion_role_to_string(GCodeExtrusionRole role)
{
switch (role) {
case erNone : return L("Unknown");
case erPerimeter : return L("Perimeter");
case erExternalPerimeter : return L("External perimeter");
case erOverhangPerimeter : return L("Overhang perimeter");
case erInternalInfill : return L("Internal infill");
case erSolidInfill : return L("Solid infill");
case erTopSolidInfill : return L("Top solid infill");
case erIroning : return L("Ironing");
case erBridgeInfill : return L("Bridge infill");
case erGapFill : return L("Gap fill");
case erSkirt : return L("Skirt/Brim");
case erSupportMaterial : return L("Support material");
case erSupportMaterialInterface : return L("Support material interface");
case erWipeTower : return L("Wipe tower");
case erCustom : return L("Custom");
default : assert(false);
}
return {};
}
GCodeExtrusionRole string_to_gcode_extrusion_role(const std::string_view role)
{
if (role == L("Perimeter"))
return erPerimeter;
else if (role == L("External perimeter"))
return erExternalPerimeter;
else if (role == L("Overhang perimeter"))
return erOverhangPerimeter;
else if (role == L("Internal infill"))
return erInternalInfill;
else if (role == L("Solid infill"))
return erSolidInfill;
else if (role == L("Top solid infill"))
return erTopSolidInfill;
else if (role == L("Ironing"))
return erIroning;
else if (role == L("Bridge infill"))
return erBridgeInfill;
else if (role == L("Gap fill"))
return erGapFill;
else if (role == L("Skirt") || role == L("Skirt/Brim")) // "Skirt" is for backward compatibility with 2.3.1 and earlier
return erSkirt;
else if (role == L("Support material"))
return erSupportMaterial;
else if (role == L("Support material interface"))
return erSupportMaterialInterface;
else if (role == L("Wipe tower"))
return erWipeTower;
else if (role == L("Custom"))
return erCustom;
else
return erNone;
}
}

View File

@ -0,0 +1,147 @@
#ifndef slic3r_ExtrusionRole_hpp_
#define slic3r_ExtrusionRole_hpp_
#include "enum_bitmask.hpp"
#include <string>
#include <string_view>
namespace Slic3r {
enum class ExtrusionRoleModifier : uint16_t {
// 1) Extrusion types
// Perimeter (external, inner, ...)
Perimeter,
// Infill (top / bottom / solid inner / sparse inner / bridging inner ...)
Infill,
// Variable width extrusion
Thin,
// Support material extrusion
Support,
Skirt,
Wipe,
// 2) Extrusion modifiers
External,
Solid,
Ironing,
Bridge,
// 3) Special types
// Indicator that the extrusion role was mixed from multiple differing extrusion roles,
// for example from Support and SupportInterface.
Mixed,
// Stopper, there should be maximum 16 modifiers defined for uint16_t bit mask.
Count
};
// There should be maximum 16 modifiers defined for uint16_t bit mask.
static_assert(int(ExtrusionRoleModifier::Count) <= 16, "ExtrusionRoleModifier: there must be maximum 16 modifiers defined to fit a 16 bit bitmask");
using ExtrusionRoleModifiers = enum_bitmask<ExtrusionRoleModifier>;
ENABLE_ENUM_BITMASK_OPERATORS(ExtrusionRoleModifier);
struct ExtrusionRole : public ExtrusionRoleModifiers
{
constexpr ExtrusionRole(const ExtrusionRoleModifier bit) : ExtrusionRoleModifiers(bit) {}
constexpr ExtrusionRole(const ExtrusionRoleModifiers bits) : ExtrusionRoleModifiers(bits) {}
static constexpr const ExtrusionRoleModifiers None{};
// Internal perimeter, not bridging.
static constexpr const ExtrusionRoleModifiers Perimeter{ ExtrusionRoleModifier::Perimeter };
// External perimeter, not bridging.
static constexpr const ExtrusionRoleModifiers ExternalPerimeter{ ExtrusionRoleModifier::Perimeter | ExtrusionRoleModifier::External };
// Perimeter, bridging. To be or'ed with ExtrusionRoleModifier::External for external bridging perimeter.
static constexpr const ExtrusionRoleModifiers OverhangPerimeter{ ExtrusionRoleModifier::Perimeter | ExtrusionRoleModifier::Bridge };
// Sparse internal infill.
static constexpr const ExtrusionRoleModifiers InternalInfill{ ExtrusionRoleModifier::Infill };
// Solid internal infill.
static constexpr const ExtrusionRoleModifiers SolidInfill{ ExtrusionRoleModifier::Infill | ExtrusionRoleModifier::Solid };
// Top solid infill (visible).
//FIXME why there is no bottom solid infill type?
static constexpr const ExtrusionRoleModifiers TopSolidInfill{ ExtrusionRoleModifier::Infill | ExtrusionRoleModifier::Solid | ExtrusionRoleModifier::External };
// Ironing infill at the top surfaces.
static constexpr const ExtrusionRoleModifiers Ironing{ ExtrusionRoleModifier::Infill | ExtrusionRoleModifier::Ironing | ExtrusionRoleModifier::External };
// Visible bridging infill at the bottom of an object.
static constexpr const ExtrusionRoleModifiers BridgeInfill{ ExtrusionRoleModifier::Infill | ExtrusionRoleModifier::Solid | ExtrusionRoleModifier::Bridge | ExtrusionRoleModifier::External };
// static constexpr const ExtrusionRoleModifiers InternalBridgeInfill{ ExtrusionRoleModifier::Infill | ExtrusionRoleModifier::Solid | ExtrusionRoleModifier::Bridge };
// Gap fill extrusion, currently used for any variable width extrusion: Thin walls outside of the outer extrusion,
// gap fill in between perimeters, gap fill between the inner perimeter and infill.
//FIXME revise GapFill and ThinWall types, split Gap Fill to Gap Fill and ThinWall.
static constexpr const ExtrusionRoleModifiers GapFill{ ExtrusionRoleModifier::Thin }; // | ExtrusionRoleModifier::External };
// static constexpr const ExtrusionRoleModifiers ThinWall{ ExtrusionRoleModifier::Thin };
static constexpr const ExtrusionRoleModifiers Skirt{ ExtrusionRoleModifier::Skirt };
// Support base material, printed with non-soluble plastic.
static constexpr const ExtrusionRoleModifiers SupportMaterial{ ExtrusionRoleModifier::Support };
// Support interface material, printed with soluble plastic.
static constexpr const ExtrusionRoleModifiers SupportMaterialInterface{ ExtrusionRoleModifier::Support | ExtrusionRoleModifier::External };
// Wipe tower material.
static constexpr const ExtrusionRoleModifiers WipeTower{ ExtrusionRoleModifier::Wipe };
// Extrusion role for a collection with multiple extrusion roles.
static constexpr const ExtrusionRoleModifiers Mixed{ ExtrusionRoleModifier::Mixed };
};
// Special flags describing loop
enum ExtrusionLoopRole {
elrDefault,
elrContourInternalPerimeter,
elrSkirt,
};
inline bool is_perimeter(ExtrusionRole role)
{
return role == ExtrusionRole::Perimeter
|| role == ExtrusionRole::ExternalPerimeter
|| role == ExtrusionRole::OverhangPerimeter;
}
inline bool is_infill(ExtrusionRole role)
{
return role == ExtrusionRole::BridgeInfill
|| role == ExtrusionRole::InternalInfill
|| role == ExtrusionRole::SolidInfill
|| role == ExtrusionRole::TopSolidInfill
|| role == ExtrusionRole::Ironing;
}
inline bool is_solid_infill(ExtrusionRole role)
{
return role == ExtrusionRole::BridgeInfill
|| role == ExtrusionRole::SolidInfill
|| role == ExtrusionRole::TopSolidInfill
|| role == ExtrusionRole::Ironing;
}
inline bool is_bridge(ExtrusionRole role) {
return role == ExtrusionRole::BridgeInfill
|| role == ExtrusionRole::OverhangPerimeter;
}
enum GCodeExtrusionRole : uint8_t {
erNone,
erPerimeter,
erExternalPerimeter,
erOverhangPerimeter,
erInternalInfill,
erSolidInfill,
erTopSolidInfill,
erIroning,
erBridgeInfill,
erGapFill,
erSkirt,
erSupportMaterial,
erSupportMaterialInterface,
erWipeTower,
// Custom (user defined) G-code block, for example start / end G-code.
erCustom,
// Stopper to count number of enums.
erCount
};
// Convert a rich bitmask based ExtrusionRole to a less expressive ordinal GCodeExtrusionRole.
// GCodeExtrusionRole is to be serialized into G-code and deserialized by G-code viewer,
GCodeExtrusionRole extrusion_role_to_gcode_extrusion_role(ExtrusionRole role);
std::string gcode_extrusion_role_to_string(GCodeExtrusionRole role);
GCodeExtrusionRole string_to_gcode_extrusion_role(const std::string_view role);
}
#endif // slic3r_ExtrusionRole_hpp_

View File

@ -4,7 +4,7 @@
#include "libslic3r.h"
#include "Config.hpp"
#include "Exception.hpp"
#include "ExtrusionEntity.hpp"
#include "ExtrusionRole.hpp"
namespace Slic3r {

View File

@ -3,7 +3,7 @@
#include "libslic3r/GCodeReader.hpp"
#include "libslic3r/Point.hpp"
#include "libslic3r/ExtrusionEntity.hpp"
#include "libslic3r/ExtrusionRole.hpp"
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/CustomGCode.hpp"

View File

@ -3,7 +3,7 @@
#include "../libslic3r.h"
#include "../PrintConfig.hpp"
#include "../ExtrusionEntity.hpp"
#include "../ExtrusionRole.hpp"
#include <queue>

View File

@ -3,6 +3,7 @@
#include "libslic3r.h"
#include <vector>
#include "ExtrusionEntityCollection.hpp"
#include "Flow.hpp"
#include "Polygon.hpp"
#include "PrintConfig.hpp"