1 //Copyright (c) 2018 Ultimaker B.V.
2 //CuraEngine is released under the terms of the AGPLv3 or higher.
3 
4 #ifndef WIREFRAME2GCODE_H
5 #define WIREFRAME2GCODE_H
6 
7 #include <functional> // passing function pointer or lambda as argument to a function
8 
9 #include "RetractionConfig.h"
10 #include "settings/types/AngleRadians.h" //For the nozzle expansion angle setting.
11 #include "utils/NoCopy.h"
12 
13 namespace cura
14 {
15 
16 class Weaver;
17 
18 /*!
19  * Export class for exporting wireframe print gcode / weaver gcode / wireprint gcode.
20  */
21 class Wireframe2gcode : public NoCopy
22 {
23 private:
24     static const int STRATEGY_COMPENSATE = 0;
25     static const int STRATEGY_KNOT = 1;
26     static const int STRATEGY_RETRACT = 2;
27 
28     coord_t initial_layer_thickness;
29     coord_t filament_diameter;
30     coord_t line_width;
31     Ratio flowConnection;
32     Ratio flowFlat;
33     double extrusion_mm3_per_mm_connection;
34     double extrusion_mm3_per_mm_flat;
35     bool update_extrusion_offset;
36     coord_t nozzle_outer_diameter;
37     AngleRadians nozzle_expansion_angle;
38     coord_t nozzle_clearance;
39     coord_t nozzle_top_diameter;
40     Velocity moveSpeed;
41     Velocity speedBottom;
42     Velocity speedUp;
43     Velocity speedDown;
44     Velocity speedFlat;
45     coord_t connectionHeight;
46     coord_t roof_inset;
47     Duration flat_delay;
48     Duration bottom_delay;
49     Duration top_delay;
50     coord_t up_dist_half_speed;
51     coord_t top_jump_dist;
52     coord_t fall_down;
53     coord_t drag_along;
54     int strategy;
55     bool go_back_to_last_top;
56     Ratio straight_first_when_going_down;
57     coord_t roof_fall_down;
58     coord_t roof_drag_along;
59     Duration roof_outer_delay;
60     RetractionConfig standard_retraction_config; //!< The standard retraction settings used for moves between parts etc.
61 
62 public:
63     GCodeExport& gcode; //!< Where the result is 'stored'
64 
65     Wireframe2gcode(Weaver& weaver, GCodeExport& gcode);
66 
67     void writeGCode();
68 
69 
70 private:
71     WireFrame& wireFrame;
72 
73     /*!
74      * Startup gcode: nozzle temp up, retraction settings, bed temp
75      */
76     void processStartingCode();
77 
78     /*!
79      * Lay down a skirt
80      */
81     void processSkirt();
82 
83     /*!
84      * End gcode: nozzle temp down
85      */
86     void finalize();
87 
88     void writeFill(std::vector<WeaveRoofPart>& infill_insets, Polygons& outlines
89         , std::function<void (Wireframe2gcode&, WeaveConnectionPart& part, unsigned int segment_idx)> connectionHandler
90         , std::function<void (Wireframe2gcode&, WeaveConnectionSegment& p)> flatHandler);
91 
92     /*!
93      * Function for writing the gcode for a diagonally down movement of a connection.
94      *
95      * \param part The part in which the segment is
96      * \param segment_idx The index of the segment in the \p part
97      */
98     void go_down(WeaveConnectionPart& part, unsigned int segment_idx);
99 
100     /*!
101      * Function for writing the gcode of an upward move of a connection, which does a couple of small moves at the top.
102      *
103      * \param part The part in which the segment is
104      * \param segment_idx The index of the segment in the \p part
105      */
106     void strategy_knot(WeaveConnectionPart& part, unsigned int segment_idx);
107 
108     /*!
109      * Function for writing the gcode of an upward move of a connection, which does a retract at the top.
110      *
111      * \param part The part in which the segment is
112      * \param segment_idx The index of the segment in the \p part
113      */
114     void strategy_retract(WeaveConnectionPart& part, unsigned int segment_idx);
115 
116     /*!
117      * Function for writing the gcode of an upward move of a connection, which goes Wireframe2gcode::fall_down further up
118      * and Wireframe2gcode::drag_along back from the direction it will go to next.
119      *
120      * \param part The part in which the segment is
121      * \param segment_idx The index of the segment in the \p part
122      */
123     void strategy_compensate(WeaveConnectionPart& part, unsigned int segment_idx);
124 
125     /*!
126      * Function writing the gcode of a segment in the connection between two layers.
127      *
128      * \param part The part in which the segment is
129      * \param segment_idx The index of the segment in the \p part
130      */
131     void handle_segment(WeaveConnectionPart& part, unsigned int segment_idx);
132 
133     /*!
134      * Function for writing the gcode of a segment in the connection between two roof insets / floor outsets.
135      *
136      * \param part the part in which the segment is
137      * \param segment_idx The index of the segment in the \p part
138      */
139     void handle_roof_segment(WeaveConnectionPart& part, unsigned int segment_idx);
140 
141     /*!
142      * Write a move action to gcode, inserting a retraction if neccesary.
143      *
144      * \param to The 3D destination of the move
145      */
146     void writeMoveWithRetract(Point3 to);
147 
148     /*!
149      * Write a move action to gcode, inserting a retraction if neccesary.
150      *
151      * \param to The 2D destination of the move
152      */
153     void writeMoveWithRetract(Point to);
154 
155 };
156 
157 }//namespace cura
158 
159 #endif//WIREFRAME2GCODE_H
160