mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-04 06:11:02 +00:00
* Ignore Clipper, libpng, mcut and Boost.Polygon Internals in clang-tidy Each only works through a wrapper or umbrella header: libslic3r/clipper.hpp or clipper_z.hpp configure Clipper before including it, png.h pulls in libpng's config headers, and Boost.Polygon's headers only compile through polygon.hpp or voronoi.hpp. * Ignore minilzo's Config Headers in clang-tidy lzoconf.h and lzodefs.h are internal to minilzo.h, which is what the code includes. * Add Missing Includes Across the Remaining Sources and Tests Covers src/slic3r/Utils, src/slic3r/plugin, src/slic3r/Config, src/libvgcode, src/dev-utils, src/OrcaSlicer.cpp and tests/, the directories left after src/slic3r/GUI and src/libslic3r. Generated with clang-tidy misc-include-cleaner. libvgcode's own headers are included by relative path as in the rest of that library, and Catch2 and pybind11 with angle brackets as elsewhere in the repo. * Make the GUI and Test Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Headers that only compile on one platform, or that nothing built includes, are left alone. * Keep Windows and nanosvg Setup Ahead of the Added Includes OrcaSlicer.cpp and several tests set _WIN32_WINNT, WIN32_LEAN_AND_MEAN or NOMINMAX before including Windows.h, and the profile validator defines NANOSVG_IMPLEMENTATION before any libslic3r header. The added includes had landed above those blocks, which broke the Windows build. * Add the GUI Includes the First Pass Missed Covers headers that only became editable once they compiled on their own, and wx symbols whose suggested header changed as the clang-tidy ignore list grew after the src/slic3r/GUI pass. * Keep the Added Test Includes Below the NOMINMAX Guard test_marchingsquares.cpp and test_texture_displacement.cpp had includes inside #ifndef NOMINMAX, which the tests inherit as defined on Windows from libslic3r, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory, as in #16068.
136 lines
6.5 KiB
C++
136 lines
6.5 KiB
C++
#ifndef SLIC3R_TEST_HELPERS_HPP
|
|
#define SLIC3R_TEST_HELPERS_HPP
|
|
|
|
#include "libslic3r/Config.hpp"
|
|
#include "libslic3r/Geometry.hpp"
|
|
#include "libslic3r/Model.hpp"
|
|
#include "libslic3r/Point.hpp"
|
|
#include "libslic3r/Print.hpp"
|
|
#include "libslic3r/TriangleMesh.hpp"
|
|
|
|
#include "libslic3r/libslic3r.h"
|
|
#include <cstddef>
|
|
#include "libslic3r/PrintConfig.hpp"
|
|
#include <initializer_list>
|
|
#include <set>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace Slic3r { namespace Test {
|
|
|
|
constexpr double MM_PER_MIN = 60.0;
|
|
|
|
// True when `a` and `b` are within EPSILON.
|
|
template <typename T>
|
|
bool _equiv(const T& a, const T& b) { return std::abs(a - b) < EPSILON; }
|
|
|
|
// True when `a` and `b` are within `epsilon`.
|
|
template <typename T>
|
|
bool _equiv(const T& a, const T& b, double epsilon) { return abs(a - b) < epsilon; }
|
|
|
|
// Named reusable test meshes, resolved by mesh().
|
|
enum class TestMesh {
|
|
A,
|
|
L,
|
|
V,
|
|
_40x10,
|
|
sphere_50mm,
|
|
bridge,
|
|
bridge_with_hole,
|
|
cube_with_concave_hole,
|
|
cube_with_hole,
|
|
gt2_teeth,
|
|
ipadstand,
|
|
overhang,
|
|
pyramid,
|
|
sloping_hole,
|
|
slopy_cube,
|
|
small_dorito,
|
|
step,
|
|
two_hollow_squares
|
|
};
|
|
|
|
// Hash for TestMesh (std::hash lacks scoped-enum support before C++17).
|
|
struct TestMeshHash {
|
|
std::size_t operator()(TestMesh tm) const {
|
|
return static_cast<std::size_t>(tm);
|
|
}
|
|
};
|
|
|
|
// TestMesh value to name mapping.
|
|
extern const std::unordered_map<TestMesh, const char*, TestMeshHash> mesh_names;
|
|
|
|
// Geometry for the named test fixture `m`, optionally translated and scaled.
|
|
TriangleMesh mesh(TestMesh m);
|
|
TriangleMesh mesh(TestMesh m, Vec3d translate, Vec3d scale = Vec3d(1.0, 1.0, 1.0));
|
|
TriangleMesh mesh(TestMesh m, Vec3d translate, double scale = 1.0);
|
|
|
|
// An equal-sided cube, `size` mm on each edge.
|
|
inline TriangleMesh cube(double size) { return make_cube(size, size, size); }
|
|
|
|
// A Model holding one object built from `mesh`.
|
|
Slic3r::Model model(const std::string& model_name, TriangleMesh&& _mesh);
|
|
|
|
// Single-nozzle, `filaments`-filament config from defaults; `extra` is applied last.
|
|
DynamicPrintConfig multifilament_config(unsigned int filaments,
|
|
std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> extra = {});
|
|
|
|
// Apply `meshes` and config to `print`/`model`, each object with `instances` copies; optional per-object overrides,
|
|
// auto-arranged unless `arrange` is false.
|
|
void init_print(std::vector<TriangleMesh> &&meshes, Slic3r::Print &print, Slic3r::Model &model, const DynamicPrintConfig &config_in,
|
|
const std::vector<std::vector<Slic3r::ConfigBase::SetDeserializeItem>> *per_object_overrides = nullptr, bool arrange = true,
|
|
size_t instances = 1);
|
|
void init_print(std::initializer_list<TestMesh> meshes, Slic3r::Print &print, Slic3r::Model &model, const Slic3r::DynamicPrintConfig &config_in = Slic3r::DynamicPrintConfig::full_print_config());
|
|
void init_print(std::initializer_list<TriangleMesh> meshes, Slic3r::Print &print, Slic3r::Model &model, const Slic3r::DynamicPrintConfig &config_in = Slic3r::DynamicPrintConfig::full_print_config());
|
|
void init_print(std::initializer_list<TestMesh> meshes, Slic3r::Print &print, Slic3r::Model &model, std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> config_items);
|
|
void init_print(std::initializer_list<TriangleMesh> meshes, Slic3r::Print &print, Slic3r::Model &model, std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> config_items);
|
|
|
|
// init_print followed by process(), leaving a sliced `print` to inspect.
|
|
void init_and_process_print(std::initializer_list<TestMesh> meshes, Slic3r::Print &print, const DynamicPrintConfig& config);
|
|
void init_and_process_print(std::initializer_list<TriangleMesh> meshes, Slic3r::Print &print, const DynamicPrintConfig& config);
|
|
void init_and_process_print(std::initializer_list<TestMesh> meshes, Slic3r::Print &print, std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> config_items);
|
|
void init_and_process_print(std::initializer_list<TriangleMesh> meshes, Slic3r::Print &print, std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> config_items);
|
|
|
|
// Process `print` and return its exported G-code.
|
|
std::string gcode(Print& print);
|
|
|
|
// Build, slice, and return the G-code for `meshes` under the given config.
|
|
std::string slice(std::initializer_list<TestMesh> meshes, const DynamicPrintConfig &config);
|
|
std::string slice(std::initializer_list<TriangleMesh> meshes, const DynamicPrintConfig &config);
|
|
std::string slice(std::initializer_list<TestMesh> meshes, std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> config_items);
|
|
std::string slice(std::initializer_list<TriangleMesh> meshes, std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> config_items);
|
|
|
|
// Slice `meshes`, applying per_object_overrides[i] to object i first (empty entry = none).
|
|
std::string slice_with_object_overrides(std::initializer_list<TriangleMesh> meshes, const DynamicPrintConfig &config,
|
|
const std::vector<std::vector<Slic3r::ConfigBase::SetDeserializeItem>> &per_object_overrides);
|
|
|
|
// Slice two auto-arranged 20mm cubes (the arranger positions them).
|
|
std::string slice_two_cubes_arranged(std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> config_items);
|
|
|
|
// Place two 20mm cubes `gap` mm apart edge-to-edge, not auto-arranged (the caller controls spacing).
|
|
void place_two_cubes_apart(double gap, std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> config_items,
|
|
Slic3r::Print &print, Slic3r::Model &model);
|
|
// Slice two 20mm cubes `gap` mm apart (not auto-arranged) and return the G-code.
|
|
std::string slice_two_cubes_apart(double gap, std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> config_items);
|
|
|
|
// Place two instances of one 20mm cube `gap` mm apart edge-to-edge.
|
|
void place_two_cube_instances_apart(double gap, std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> config_items,
|
|
Slic3r::Print &print, Slic3r::Model &model);
|
|
|
|
// Distinct layer Z heights carrying an extrusion of the given `role` (e.g. "skirt").
|
|
std::set<double> layers_with_role(const std::string &gcode, const std::string &role);
|
|
|
|
// Highest Z reached by any move in the G-code.
|
|
double max_z(const std::string &gcode);
|
|
|
|
// Count of contiguous extrusion blocks of `role` (each uninterrupted run counts once).
|
|
int role_passes(const std::string &gcode, const std::string &role);
|
|
|
|
// The `roles` in the order their extrusion blocks first appear, consecutive repeats collapsed.
|
|
std::vector<std::string> role_sequence(const std::string &gcode, const std::vector<std::string> &roles);
|
|
|
|
} } // namespace Slic3r::Test
|
|
|
|
#endif // SLIC3R_TEST_HELPERS_HPP
|