Files
OrcaSlicer/src/slic3r/GUI/DeviceCore/DevExtensionTool.h
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

68 lines
1.4 KiB
C++

#pragma once
#include <memory>
#include <optional>
#include "libslic3r/CommonDefs.hpp"
#include <nlohmann/json.hpp>
#include <wx/string.h>
#include "DevDefs.h"
namespace Slic3r
{
//Previous definitions
class MachineObject;
// some extension tools for toolheads
class DevExtensionTool
{
friend class DevExtensionToolParser;
public:
static std::shared_ptr<DevExtensionTool> Create(MachineObject* obj) { return std::shared_ptr<DevExtensionTool>(new DevExtensionTool(obj)); }
public:
// tool type
bool IsToolTypeFanF000() const { return m_tool_type == TOOL_TYPE_FAN_F000; }
// mount state
bool IsMounted() const { return m_mount_3dp == MOUNT_MOUNTED; }
protected:
DevExtensionTool(MachineObject* obj);
private:
[[maybe_unused]] MachineObject* m_owner = nullptr;
enum MountState
{
MOUNT_NOT_MOUNTED = 0,
MOUNT_MOUNTED = 1,
MOUNT_NO_MODULE = 2,
MOUNT_NO_CABLE = 3
} m_mount_3dp;
enum CalibState
{
CALIB_NONE = 0,
CALIB_FIRST = 1,
CALIB_MOUNT = 2
} m_calib;
enum ToolType
{
TOOL_TYPE_EMPTY = 0,
TOOL_TYPE_CUT_CP00 = 1,
TOOL_TYPE_LASER_LB00 = 2,
TOOL_TYPE_FAN_F000 = 3,
} m_tool_type;
};
class DevExtensionToolParser
{
public:
static void ParseV2_0(const nlohmann::json& extension_tool_json, std::weak_ptr<DevExtensionTool> extension_tool);
};
};