1 #ifndef slic3r_CustomGCode_hpp_
2 #define slic3r_CustomGCode_hpp_
3 
4 #include <string>
5 #include <vector>
6 
7 namespace Slic3r {
8 
9 class DynamicPrintConfig;
10 
11 namespace CustomGCode {
12 
13 enum Type
14 {
15     ColorChange,
16     PausePrint,
17     ToolChange,
18     Template,
19     Custom
20 };
21 
22 struct Item
23 {
operator <Slic3r::CustomGCode::Item24     bool operator<(const Item& rhs) const { return this->print_z < rhs.print_z; }
operator ==Slic3r::CustomGCode::Item25     bool operator==(const Item& rhs) const
26     {
27         return (rhs.print_z   == this->print_z    ) &&
28                (rhs.type      == this->type       ) &&
29                (rhs.extruder  == this->extruder   ) &&
30                (rhs.color     == this->color      ) &&
31                (rhs.extra     == this->extra      );
32     }
operator !=Slic3r::CustomGCode::Item33     bool operator!=(const Item& rhs) const { return ! (*this == rhs); }
34 
35     double      print_z;
36     Type        type;
37     int         extruder;   // Informative value for ColorChangeCode and ToolChangeCode
38                             // "gcode" == ColorChangeCode   => M600 will be applied for "extruder" extruder
39                             // "gcode" == ToolChangeCode    => for whole print tool will be switched to "extruder" extruder
40     std::string color;      // if gcode is equal to PausePrintCode,
41                             // this field is used for save a short message shown on Printer display
42     std::string extra;      // this field is used for the extra data like :
43                             // - G-code text for the Type::Custom
44                             // - message text for the Type::PausePrint
45 };
46 
47 enum Mode
48 {
49     Undef,
50     SingleExtruder,   // Single extruder printer preset is selected
51     MultiAsSingle,    // Multiple extruder printer preset is selected, but
52                       // this mode works just for Single extruder print
53                       // (The same extruder is assigned to all ModelObjects and ModelVolumes).
54     MultiExtruder     // Multiple extruder printer preset is selected
55 };
56 
57 // string anlogue of custom_code_per_height mode
58 static constexpr char SingleExtruderMode[] = "SingleExtruder";
59 static constexpr char MultiAsSingleMode [] = "MultiAsSingle";
60 static constexpr char MultiExtruderMode [] = "MultiExtruder";
61 
62 struct Info
63 {
64     Mode mode = Undef;
65     std::vector<Item> gcodes;
66 
operator ==Slic3r::CustomGCode::Info67     bool operator==(const Info& rhs) const
68     {
69         return  (rhs.mode   == this->mode   ) &&
70                 (rhs.gcodes == this->gcodes );
71     }
operator !=Slic3r::CustomGCode::Info72     bool operator!=(const Info& rhs) const { return !(*this == rhs); }
73 };
74 
75 // If loaded configuration has a "colorprint_heights" option (if it was imported from older Slicer),
76 // and if CustomGCode::Info.gcodes is empty (there is no color print data available in a new format
77 // then CustomGCode::Info.gcodes should be updated considering this option.
78 extern void update_custom_gcode_per_print_z_from_config(Info& info, DynamicPrintConfig* config);
79 
80 // If information for custom Gcode per print Z was imported from older Slicer, mode will be undefined.
81 // So, we should set CustomGCode::Info.mode should be updated considering code values from items.
82 extern void check_mode_for_custom_gcode_per_print_z(Info& info);
83 
84 // Return pairs of <print_z, 1-based extruder ID> sorted by increasing print_z from custom_gcode_per_print_z.
85 // print_z corresponds to the first layer printed with the new extruder.
86 std::vector<std::pair<double, unsigned int>> custom_tool_changes(const Info& custom_gcode_per_print_z, size_t num_extruders);
87 
88 } // namespace CustomGCode
89 
90 } // namespace Slic3r
91 
92 
93 
94 #endif /* slic3r_CustomGCode_hpp_ */
95