Files
OrcaSlicer/src/slic3r/GUI/DeviceCore/DevChamber.cpp
T
HanifKoh 73d32d4791 Stop Leaking json Through Headers and Drop Includes Kept Only for the Name (#16221)
* 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.
2026-10-07 14:22:16 +08:00

53 lines
1.8 KiB
C++

#include "DevChamber.h"
#include "DevConfig.h"
#include "DevUtil.h"
#include <nlohmann/json.hpp>
#include "slic3r/GUI/DeviceManager.hpp"
using json = nlohmann::json;
namespace Slic3r {
bool DevChamber::HasChamber() const { return m_owner->GetConfig()->HasChamber(); }
bool DevChamber::SupportChamberTempDisplay() const { return m_owner->GetConfig()->SupportChamberTempDisplay();}
bool DevChamber::SupportChamberEdit() const { return m_owner->GetConfig()->SupportChamberEdit(); }
int DevChamber::GetChamberTempEditMin() const { return m_owner->GetConfig()->GetChamberTempEditMin(); }
int DevChamber::GetChamberTempEditMax() const { return m_owner->GetConfig()->GetChamberTempEditMax(); }
int DevChamber::GetChamberTempSwitchHeat() const { return m_owner->GetConfig()->GetChamberTempSwitchHeat(); }
void DevChamber::ParseChamber(const json &print_json)
{
ParseChamberV1_0(print_json);
ParseChamberV2_0(print_json);
}
void DevChamber::ParseChamberV1_0(const json &print_json)
{
DevJsonValParser::ParseVal(print_json, "chamber_temper", m_temp);
DevJsonValParser::ParseVal(print_json, "ctt", m_temp_target);
}
void DevChamber::ParseChamberV2_0(const json &print_json)
{
if (print_json.contains("device")) {
const json &device_jj = print_json["device"];
if (device_jj.contains("ctc")) {
const json &ctc = device_jj["ctc"];
int state = DevUtil::get_flag_bits(ctc["state"].get<int>(), 0, 4);
if (ctc.contains("info")) {
const json &info = ctc["info"];
m_temp = DevUtil::get_flag_bits(info["temp"].get<int>(), 0, 16);
m_temp_target = DevUtil::get_flag_bits(info["temp"].get<int>(), 16, 16);
}
}
}
}
} // namespace Slic3r