Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
cvhanges
Browse files Browse the repository at this point in the history
  • Loading branch information
PilotMatt committed Feb 25, 2024
1 parent b319982 commit 84db29b
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 5 deletions.
101 changes: 96 additions & 5 deletions src/slic3r/Utils/PrintagoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,11 @@ bool PrintagoDirector::ProcessPrintagoCommand(const PrintagoCommand& cmd)
return false;
}

std::string printagoModelUrl = parameters["model"];
std::string printerConfUrl = parameters["printer_conf"];
std::string printConfUrl = parameters["print_conf"];
std::string filamentConfUrl = parameters["filament_conf"];
std::string printagoModelUrl = parameters["model"];
std::string printerConfUrl = parameters["printer_conf"];
std::string printConfUrl = parameters["print_conf"];
std::string filamentConfUrl = parameters["filament_conf"];
std::string overridePrintConfUrl = parameters["print_override_conf"];

wxString printagoId = parameters["printago_job"];
if (!printagoId.empty()) {
Expand Down Expand Up @@ -668,6 +669,10 @@ bool PrintagoDirector::ProcessPrintagoCommand(const PrintagoCommand& cmd)
filamentConfUrl = Http::url_decode(filamentConfUrl);
}

if (!overridePrintConfUrl.empty()) {
overridePrintConfUrl = Http::url_decode(overridePrintConfUrl);
}

PBJob::SetServerState(JobServerState::Download, true);

// Second param is reference and modified inside SavePrintagoFile.
Expand All @@ -693,6 +698,16 @@ bool PrintagoDirector::ProcessPrintagoCommand(const PrintagoCommand& cmd)
PBJob::configFiles["filament"] = localFilamentConf;
PBJob::configFiles["print"] = localPrintConf;

wxFileName localOverridePrintConf;
if (!overridePrintConfUrl.empty()) {
if (!SavePrintagoFile(overridePrintConfUrl, localOverridePrintConf)) {
PostErrorMessage(printerId, wxString::Format("%s:%s", action, PBJob::serverStateStr()), originalCommand,
"override config download failed", true);
return false;
}
PBJob::configFiles["print_override"] = localOverridePrintConf;
}

PBJob::SetServerState(JobServerState::Configure, true);

std::promise<bool> uiLoadFilesPromise;
Expand All @@ -704,6 +719,7 @@ bool PrintagoDirector::ProcessPrintagoCommand(const PrintagoCommand& cmd)

actionDetail = wxString::Format("slice_config: %s", PBJob::localFile.GetFullPath());

OverridePrintSettings();
ImportPrintagoConfigs();
SetPrintagoConfigs();
wxGetApp().plater()->sidebar().on_bed_type_change(PBJob::bed_type);
Expand All @@ -717,7 +733,7 @@ bool PrintagoDirector::ProcessPrintagoCommand(const PrintagoCommand& cmd)
std::vector<std::string> filePathArray;
filePathArray.push_back(PBJob::localFile.GetFullPath().ToStdString());
LoadStrategy strategy = LoadStrategy::LoadModel |
LoadStrategy::Silence; // LoadStrategy::LoadConfig | LoadStrategy::LoadAuxiliary
LoadStrategy::Silence;
wxGetApp().plater()->load_files(filePathArray, strategy, false);
}
wxGetApp().plater()->select_plate(0, true);
Expand Down Expand Up @@ -853,6 +869,81 @@ bool PrintagoDirector::ProcessPrintagoCommand(const PrintagoCommand& cmd)
return true;
}

void PrintagoDirector::OverridePrintSettings()
{
auto fullOptionsList = Preset::print_options();
std::vector<std::string> noOverrideKeys = PBJob::PrintSettingsNotToOverride();
std::vector<std::string> layerHeightKeys = {"layer_height", "initial_layer_height", "independent_support_layer_height"};

std::vector<std::string> optionsToUse;
std::copy_if(fullOptionsList.begin(), fullOptionsList.end(), std::back_inserter(optionsToUse),
[&noOverrideKeys](const std::string& option) {
return std::find(noOverrideKeys.begin(), noOverrideKeys.end(), option) == noOverrideKeys.end();
});

wxFileName printSettingsPath = PBJob::configFiles["print"].GetFullPath();
wxFileName overrideSettingsPath = PBJob::configFiles["print_override"].GetFullPath();
wxFileName printerSettingsPath = PBJob::configFiles["printer"].GetFullPath();

// Load JSON data from files
std::ifstream printSettingsFile(printSettingsPath.GetFullPath());
json printSettings;
printSettingsFile >> printSettings;
printSettingsFile.close();

std::ifstream printerSettingsFile(printerSettingsPath.GetFullPath());
json printerSettings;
printerSettingsFile >> printerSettings;
printerSettingsFile.close();

auto min_layer_height = printerSettings["min_layer_height"].get<double>();
auto max_layer_height = printerSettings["max_layer_height"].get<double>();
auto nozzle_diameter = printerSettings["nozzle_diameter"].get<double>();

if (max_layer_height == 0.0) {
max_layer_height = nozzle_diameter * 0.75;
}

std::ifstream overrideSettingsFile(overrideSettingsPath.GetFullPath());
json overrideSettings;
overrideSettingsFile >> overrideSettings;

// Iterate over the override settings
for (auto& el : overrideSettings.items()) {
std::string key = el.key();
if (std::find(optionsToUse.begin(), optionsToUse.end(), key) != optionsToUse.end()) {
if (printSettings.find(key) != printSettings.end()) {
// Check if the key is one of the layer height keys
if (std::find(layerHeightKeys.begin(), layerHeightKeys.end(), key) != layerHeightKeys.end()) {
// Convert the override value to double (assuming all layer heights are double)
double overrideValue = overrideSettings[key].get<double>();

// Clamp the override value to be within the min and max layer height
if (overrideValue < min_layer_height) {
overrideValue = min_layer_height;
} else if (overrideValue > max_layer_height) {
overrideValue = max_layer_height;
}

// Set the clamped value
printSettings[key] = overrideValue;
} else {
// For keys not related to layer height, simply override the value
printSettings[key] = overrideSettings[key];
}
}
}
}

wxFileName newPrintSettingsPath(printSettingsPath);
newPrintSettingsPath.SetName(printSettingsPath.GetName() + "_" + PBJob::jobId.Right(6));
std::ofstream outFile(newPrintSettingsPath.GetFullPath());
outFile << printSettings.dump();
outFile.close();

PBJob::configFiles["print"] = newPrintSettingsPath;
}

//needs UI thread.
void PrintagoDirector::ImportPrintagoConfigs()
{
Expand Down
70 changes: 70 additions & 0 deletions src/slic3r/Utils/PrintagoServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class PrintagoDirector
std::string GetConfigNameFromJsonFile(const wxString& FilePath);
json GetConfigByName(wxString configType, wxString configName);
json GetCompatPrinterConfigNames(std::string printer_type);
void OverridePrintSettings();
void ImportPrintagoConfigs();
void SetPrintagoConfigs();

Expand Down Expand Up @@ -321,6 +322,75 @@ class PBJob
static bool CanProcessJob() { return m_can_process_job; }
static bool BlockJobProcessing() { return SetCanProcessJob(false); }
static bool UnblockJobProcessing() { return SetCanProcessJob(true); }
static std::vector<std::string> PrintSettingsNotToOverride() { return dont_override_these_print_settings; }
private:
static std::vector<std::string> dont_override_these_print_settings{
"max_volumetric_extrusion_rate_slope",
"max_volumetric_extrusion_rate_slope_segment_length",
"inner_wall_speed",
"outer_wall_speed",
"sparse_infill_speed",
"internal_solid_infill_speed",
"top_surface_speed",
"support_speed",
"support_interface_speed",
"bridge_speed",
"internal_bridge_speed",
"gap_infill_speed",
"travel_speed",
"travel_speed_z",
"initial_layer_speed",
"outer_wall_acceleration",
"initial_layer_acceleration",
"top_surface_acceleration",
"default_acceleration",
"wall_filament",
"sparse_infill_filament",
"solid_infill_filament",
"support_filament",
"support_interface_filament",
"infill_wall_overlap",
"bridge_flow",
"internal_bridge_flow",
"elefant_foot_compensation",
"elefant_foot_compensation_layers",
"xy_contour_compensation",
"xy_hole_compensation",
"compatible_printers",
"compatible_printers_condition",
"inherits",
"enable_overhang_speed",
"slowdown_for_curled_perimeters",
"overhang_1_4_speed",
"overhang_2_4_speed",
"overhang_3_4_speed",
"overhang_4_4_speed",
"initial_layer_infill_speed",
"small_perimeter_speed",
"travel_acceleration",
"inner_wall_acceleration",
"default_jerk",
"outer_wall_jerk",
"inner_wall_jerk",
"infill_jerk",
"top_surface_jerk",
"initial_layer_jerk",
"travel_jerk",
"top_solid_infill_flow_ratio",
"bottom_solid_infill_flow_ratio",
"print_flow_ratio",
"role_based_wipe_speed",
"wipe_speed",
"accel_to_decel_enable",
"accel_to_decel_factor",
"bridge_acceleration",
"sparse_infill_acceleration",
"internal_solid_infill_acceleration",
"initial_layer_travel_speed",
"slow_down_layers",
"notes",
"wiping_volumes_extruders",
};
};

} // namespace Slic3r
Expand Down

0 comments on commit 84db29b

Please sign in to comment.