Skip to content

Commit dc8b260

Browse files
committed
Add layer time reporting to sendLayerComplete
Extended the sendLayerComplete method to include the time taken to print each layer. Updated the LayerOptimized protobuf message, relevant communication classes, and associated tests to support and verify this new parameter.
1 parent 8bfb59a commit dc8b260

File tree

9 files changed

+21
-9
lines changed

9 files changed

+21
-9
lines changed

Cura.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ message LayerOptimized {
105105
int32 id = 1;
106106
float height = 2; // Z position
107107
float thickness = 3; // height of a single layer
108+
float layer_time = 4; // time to print this layer in seconds
108109

109-
repeated PathSegment path_segment = 4; // layer data
110+
repeated PathSegment path_segment = 5; // layer data
110111
}
111112

112113

include/communication/ArcusCommunication.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ class ArcusCommunication : public Communication
118118
* \param layer_nr The layer that was completed.
119119
* \param z The z-coordinate of the top side of the layer.
120120
* \param thickness The thickness of the layer.
121+
* \param layer_time The time it took to print this layer in seconds.
121122
*/
122-
void sendLayerComplete(const LayerIndex::value_type& layer_nr, const coord_t& z, const coord_t& thickness) override;
123+
void sendLayerComplete(const LayerIndex::value_type& layer_nr, const coord_t& z, const coord_t& thickness, const Duration& layer_time) override;
123124

124125
/*
125126
* \brief Send a line to the front-end to display in layer view.

include/communication/CommandLine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class CommandLine : public Communication
9393
* The command line doesn't do anything with that information so this is
9494
* ignored.
9595
*/
96-
void sendLayerComplete(const LayerIndex::value_type&, const coord_t&, const coord_t&) override;
96+
void sendLayerComplete(const LayerIndex::value_type&, const coord_t&, const coord_t&, const Duration&) override;
9797

9898
/*
9999
* \brief Send a line for display.

include/communication/Communication.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define COMMUNICATION_H
66

77
#include "geometry/Point2LL.h"
8+
#include "settings/types/Duration.h"
89
#include "settings/types/LayerIndex.h"
910
#include "settings/types/Velocity.h"
1011

@@ -61,8 +62,9 @@ class Communication
6162
* \param layer_nr The layer that was completed.
6263
* \param z The z-coordinate of the top side of the layer.
6364
* \param thickness The thickness of the layer.
65+
* \param layer_time The time it took to print this layer in seconds.
6466
*/
65-
virtual void sendLayerComplete(const LayerIndex::value_type& layer_nr, const coord_t& z, const coord_t& thickness) = 0;
67+
virtual void sendLayerComplete(const LayerIndex::value_type& layer_nr, const coord_t& z, const coord_t& thickness, const Duration& layer_time) = 0;
6668

6769
/*
6870
* \brief Send a line to the user to visualise.

src/LayerPlan.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3874,8 +3874,13 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
38743874
scripta::CellVDI{ "extrusion_mm3_per_mm", &GCodePath::getExtrusionMM3perMM });
38753875
} // extruder plans /\ .
38763876

3877-
communication->sendLayerComplete(layer_nr_, z_, layer_thickness_);
3877+
// Calculate layer time before updating total print time
3878+
const Duration time_before = gcode.getSumTotalPrintTimes();
38783879
gcode.updateTotalPrintTime();
3880+
const Duration time_after = gcode.getSumTotalPrintTimes();
3881+
const Duration layer_time = time_after - time_before;
3882+
3883+
communication->sendLayerComplete(layer_nr_, z_, layer_thickness_, layer_time);
38793884
}
38803885

38813886
void LayerPlan::overrideFanSpeeds(double speed)

src/communication/ArcusCommunication.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,12 @@ void ArcusCommunication::sendFinishedSlicing() const
372372
spdlog::debug("Sent slicing finished message.");
373373
}
374374

375-
void ArcusCommunication::sendLayerComplete(const LayerIndex::value_type& layer_nr, const coord_t& z, const coord_t& thickness)
375+
void ArcusCommunication::sendLayerComplete(const LayerIndex::value_type& layer_nr, const coord_t& z, const coord_t& thickness, const Duration& layer_time)
376376
{
377377
std::shared_ptr<proto::LayerOptimized> layer = private_data->getOptimizedLayerById(layer_nr);
378378
layer->set_height(z);
379379
layer->set_thickness(thickness);
380+
layer->set_layer_time(layer_time);
380381
}
381382

382383
void ArcusCommunication::sendLineTo(const PrintFeatureType& type, const Point3LL& to, const coord_t& line_width, const coord_t& line_thickness, const Velocity& velocity)

src/communication/CommandLine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void CommandLine::sendCurrentPosition(const Point3LL&)
5858
void CommandLine::sendFinishedSlicing() const
5959
{
6060
}
61-
void CommandLine::sendLayerComplete(const LayerIndex::value_type&, const coord_t&, const coord_t&)
61+
void CommandLine::sendLayerComplete(const LayerIndex::value_type&, const coord_t&, const coord_t&, const Duration&)
6262
{
6363
}
6464
void CommandLine::sendLineTo(const PrintFeatureType&, const Point3LL&, const coord_t&, const coord_t&, const Velocity&)

tests/arcus/ArcusCommunicationTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,13 @@ TEST_F(ArcusCommunicationTest, SendLayerComplete)
153153
const LayerIndex layer_nr = 10;
154154
constexpr coord_t layer_z = 20;
155155
constexpr coord_t layer_thickness = 30;
156-
ac->sendLayerComplete(layer_nr, layer_z, layer_thickness);
156+
constexpr Duration layer_time = 40.0;
157+
ac->sendLayerComplete(layer_nr, layer_z, layer_thickness, layer_time);
157158
const std::shared_ptr<proto::LayerOptimized> message = ac->private_data->getOptimizedLayerById(layer_nr);
158159
EXPECT_EQ(static_cast<google::protobuf::int32>(layer_nr), message->id()) << "getOptimizedLayerById() must return a layer with the correct ID.";
159160
EXPECT_EQ(static_cast<float>(layer_z), message->height());
160161
EXPECT_EQ(static_cast<float>(layer_thickness), message->thickness());
162+
EXPECT_EQ(static_cast<float>(layer_time), message->layer_time());
161163
}
162164

163165
TEST_F(ArcusCommunicationTest, SendProgress)

tests/arcus/MockCommunication.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MockCommunication : public Communication
2424
MOCK_CONST_METHOD0(hasSlice, bool());
2525
MOCK_CONST_METHOD0(isSequential, bool());
2626
MOCK_CONST_METHOD1(sendProgress, void(double progress));
27-
MOCK_METHOD3(sendLayerComplete, void(const LayerIndex::value_type& layer_nr, const coord_t& z, const coord_t& thickness));
27+
MOCK_METHOD4(sendLayerComplete, void(const LayerIndex::value_type& layer_nr, const coord_t& z, const coord_t& thickness, const Duration& layer_time));
2828
MOCK_METHOD5(sendLineTo, void(const PrintFeatureType& type, const Point3LL& to, const coord_t& line_width, const coord_t& line_thickness, const Velocity& velocity));
2929
MOCK_METHOD1(sendCurrentPosition, void(const Point3LL& position));
3030
MOCK_METHOD1(setExtruderForSend, void(const ExtruderTrain& extruder));

0 commit comments

Comments
 (0)