mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-08 00:01:09 +00:00
* Stop Leaking json Through Headers and Drop Includes Kept Only for the Name AppConfig.hpp, DeviceManager.hpp and UserManager.hpp carried a global "using namespace nlohmann;", json_diff.hpp a global "using json = nlohmann::json;" and PrinterFileSystem.h a global "using nlohmann::json;". Every file that included one of them, directly or not, could write a bare json, and 63 did without declaring it. The last two also made the include checker treat json_diff.hpp and PrinterFileSystem.h as the headers that provide json, so they were included from files that use nothing else from them: 57 of the 59 includers of json_diff.hpp never name json_diff. The five statements are removed. Headers that use the type now spell nlohmann::json, source files declare their own "using json = nlohmann::json;", and the includes that only supplied the name are dropped or replaced by <nlohmann/json.hpp>. Eight files reached json_diff.hpp only through an include that is now gone and with it lost that header's "using namespace std;". The std names they used unqualified are qualified. * Declare json in OrcaSlicer.cpp on Every Platform OrcaSlicer.cpp had its "using namespace nlohmann;" and the json include inside the Linux-only include block, so on Windows and macOS it took json from AppConfig.hpp's global directive, which is gone. The include and a "using json = nlohmann::json;" now sit outside the block.
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
#include <nlohmann/json.hpp>
|
|
#include <string>
|
|
#include "DevLamp.h"
|
|
|
|
// TODO: remove this include
|
|
#include "slic3r/GUI/DeviceManager.hpp"
|
|
|
|
using namespace nlohmann;
|
|
|
|
namespace Slic3r
|
|
{
|
|
|
|
|
|
static std::string _light_effect_str(DevLamp::LIGHT_EFFECT effect)
|
|
{
|
|
switch (effect)
|
|
{
|
|
case Slic3r::DevLamp::LIGHT_EFFECT_ON:
|
|
return "on";
|
|
case Slic3r::DevLamp::LIGHT_EFFECT_OFF:
|
|
return "off";
|
|
case Slic3r::DevLamp::LIGHT_EFFECT_FLASHING:
|
|
return "flashing";
|
|
default:
|
|
return "unknown";
|
|
}
|
|
return "unknown";
|
|
}
|
|
|
|
void DevLamp::CtrlSetChamberLight(LIGHT_EFFECT effect)
|
|
{
|
|
// copied from others, TODO CHECK
|
|
command_set_chamber_light(effect);
|
|
command_set_chamber_light2(effect);
|
|
}
|
|
|
|
int DevLamp::command_set_chamber_light(LIGHT_EFFECT effect, int on_time, int off_time, int loops, int interval)
|
|
{
|
|
json j;
|
|
j["system"]["command"] = "ledctrl";
|
|
j["system"]["led_node"] = "chamber_light";
|
|
j["system"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
|
|
j["system"]["led_mode"] = _light_effect_str(effect);
|
|
j["system"]["led_on_time"] = on_time;
|
|
j["system"]["led_off_time"] = off_time;
|
|
j["system"]["loop_times"] = loops;
|
|
j["system"]["interval_time"] = interval;
|
|
return m_owner->publish_json(j);
|
|
}
|
|
|
|
int DevLamp::command_set_chamber_light2(LIGHT_EFFECT effect, int on_time, int off_time, int loops, int interval)
|
|
{
|
|
json j;
|
|
j["system"]["command"] = "ledctrl";
|
|
j["system"]["led_node"] = "chamber_light2";
|
|
j["system"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
|
|
j["system"]["led_mode"] = _light_effect_str(effect);
|
|
j["system"]["led_on_time"] = on_time;
|
|
j["system"]["led_off_time"] = off_time;
|
|
j["system"]["loop_times"] = loops;
|
|
j["system"]["interval_time"] = interval;
|
|
return m_owner->publish_json(j);
|
|
}
|
|
|
|
} |