Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code quality 1 #8617

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OrcaSlicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5770,7 +5770,7 @@ int CLI::run(int argc, char **argv)
gcode_viewer.render_calibration_thumbnail(*calibration_data, cali_thumbnail_width, cali_thumbnail_height,
calibration_params, partplate_list, opengl_mgr);
//generate_calibration_thumbnail(*calibration_data, thumbnail_width, thumbnail_height, calibration_params);
//*plate_bboxes[index] = p->generate_first_layer_bbox();
//plate_bboxes[index] = p->generate_first_layer_bbox();
calibration_thumbnails.push_back(calibration_data);*/

PlateBBoxData* plate_bbox = new PlateBBoxData();
Expand Down
36 changes: 19 additions & 17 deletions src/admesh/stlinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static FILE *stl_open_count_facets(stl_file *stl, const char *file, unsigned int
unsigned char chtest[128];
if (! fread(chtest, sizeof(chtest), 1, fp)) {
BOOST_LOG_TRIVIAL(error) << "stl_open_count_facets: The input is an empty file: " << file;
fclose(fp);
[[maybe_unused]] int ret = fclose(fp);
return nullptr;
}
stl->stats.type = ascii;
Expand All @@ -85,7 +85,7 @@ static FILE *stl_open_count_facets(stl_file *stl, const char *file, unsigned int
// Test if the STL file has the right size.
if (((file_size - header_size) % SIZEOF_STL_FACET != 0) || (file_size < STL_MIN_FILE_SIZE)) {
BOOST_LOG_TRIVIAL(error) << "stl_open_count_facets: The file " << file << " has the wrong size.";
fclose(fp);
[[maybe_unused]] int ret = fclose(fp);
return nullptr;
}
num_facets = (file_size - header_size) / SIZEOF_STL_FACET;
Expand Down Expand Up @@ -115,7 +115,6 @@ static FILE *stl_open_count_facets(stl_file *stl, const char *file, unsigned int
// do another null check to be safe
if (fp == nullptr) {
BOOST_LOG_TRIVIAL(error) << "stl_open_count_facets: Couldn't open " << file << " for reading";
fclose(fp);
return nullptr;
}

Expand Down Expand Up @@ -225,32 +224,35 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first, Impor
stl_internal_reverse_quads((char*)&facet, 48);
#endif /* BOOST_ENDIAN_BIG_BYTE */
} else {
int ret = 0;
char *cret = nullptr;

// Read a single facet from an ASCII .STL file
// skip solid/endsolid
// (in this order, otherwise it won't work when they are paired in the middle of a file)
fscanf(fp, " endsolid%*[^\n]\n");
fscanf(fp, " solid%*[^\n]\n"); // name might contain spaces so %*s doesn't work and it also can be empty (just "solid")
ret = fscanf(fp, " endsolid%*[^\n]\n");
ret = fscanf(fp, " solid%*[^\n]\n"); // name might contain spaces so %*s doesn't work and it also can be empty (just "solid")
// Leading space in the fscanf format skips all leading white spaces including numerous new lines and tabs.
int res_normal = fscanf(fp, " facet normal %31s %31s %31s", normal_buf[0], normal_buf[1], normal_buf[2]);
[[maybe_unused]] int res_normal = fscanf(fp, " facet normal %31s %31s %31s", normal_buf[0], normal_buf[1], normal_buf[2]);
assert(res_normal == 3);
int res_outer_loop = fscanf(fp, " outer loop");
[[maybe_unused]]int res_outer_loop = fscanf(fp, " outer loop");
assert(res_outer_loop == 0);
int res_vertex1 = fscanf(fp, " vertex %f %f %f", &facet.vertex[0](0), &facet.vertex[0](1), &facet.vertex[0](2));
[[maybe_unused]] int res_vertex1 = fscanf(fp, " vertex %f %f %f", &facet.vertex[0](0), &facet.vertex[0](1), &facet.vertex[0](2));
assert(res_vertex1 == 3);
int res_vertex2 = fscanf(fp, " vertex %f %f %f", &facet.vertex[1](0), &facet.vertex[1](1), &facet.vertex[1](2));
[[maybe_unused]] int res_vertex2 = fscanf(fp, " vertex %f %f %f", &facet.vertex[1](0), &facet.vertex[1](1), &facet.vertex[1](2));
assert(res_vertex2 == 3);
// Trailing whitespace is there to eat all whitespaces and empty lines up to the next non-whitespace.
int res_vertex3 = fscanf(fp, " vertex %f %f %f ", &facet.vertex[2](0), &facet.vertex[2](1), &facet.vertex[2](2));
[[maybe_unused]] int res_vertex3 = fscanf(fp, " vertex %f %f %f ", &facet.vertex[2](0), &facet.vertex[2](1), &facet.vertex[2](2));
assert(res_vertex3 == 3);
// Some G-code generators tend to produce text after "endloop" and "endfacet". Just ignore it.
char buf[2048];
fgets(buf, 2047, fp);
bool endloop_ok = strncmp(buf, "endloop", 7) == 0 && (buf[7] == '\r' || buf[7] == '\n' || buf[7] == ' ' || buf[7] == '\t');
cret = fgets(buf, 2047, fp);
[[maybe_unused]] bool endloop_ok = strncmp(buf, "endloop", 7) == 0 && (buf[7] == '\r' || buf[7] == '\n' || buf[7] == ' ' || buf[7] == '\t');
assert(endloop_ok);
// Skip the trailing whitespaces and empty lines.
fscanf(fp, " ");
fgets(buf, 2047, fp);
bool endfacet_ok = strncmp(buf, "endfacet", 8) == 0 && (buf[8] == '\r' || buf[8] == '\n' || buf[8] == ' ' || buf[8] == '\t');
ret = fscanf(fp, " ");
cret = fgets(buf, 2047, fp);
[[maybe_unused]] bool endfacet_ok = strncmp(buf, "endfacet", 8) == 0 && (buf[8] == '\r' || buf[8] == '\n' || buf[8] == ' ' || buf[8] == '\t');
assert(endfacet_ok);
if (res_normal != 3 || res_outer_loop != 0 || res_vertex1 != 3 || res_vertex2 != 3 || res_vertex3 != 3 || ! endloop_ok || ! endfacet_ok) {
BOOST_LOG_TRIVIAL(error) << "Something is syntactically very wrong with this ASCII STL! ";
Expand Down Expand Up @@ -314,8 +316,8 @@ bool stl_open(stl_file *stl, const char *file, ImportstlProgressFn stlFn, int cu
if (fp == nullptr)
return false;
stl_allocate(stl);
bool result = stl_read(stl, fp, 0, true, stlFn, custom_header_length);
fclose(fp);
bool result = stl_read(stl, fp, 0, true, stlFn, custom_header_length);
[[maybe_unused]] int ret = fclose(fp);
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions src/imgui/imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void ImGui::Text(const char* fmt, ...)
void ImGui::TextCentered(const char* text, ...)
{
va_list vaList;
va_start(vaList,&text);
va_start(vaList,text);

float font_size = ImGui::GetFontSize() * strlen(text) / 2;
ImGui::SameLine(ImGui::GetCursorPos().x / 2 - font_size + (font_size / 2));
Expand Down Expand Up @@ -6298,9 +6298,9 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl
RenderFrameBorder(bb.Min, bb.Max, rounding);
else
#ifdef __APPLE__
window->DrawList->AddRect(bb.Min - ImVec2(3, 3), bb.Max + ImVec2(3, 3), GetColorU32(ImGuiCol_FrameBg), rounding * 2,NULL,4.0f);; // Color button are often in need of some sort of border
window->DrawList->AddRect(bb.Min - ImVec2(3, 3), bb.Max + ImVec2(3, 3), GetColorU32(ImGuiCol_FrameBg), rounding * 2,0,4.0f);; // Color button are often in need of some sort of border
#else
window->DrawList->AddRect(bb.Min - ImVec2(2, 2), bb.Max + ImVec2(2, 2), GetColorU32(ImGuiCol_FrameBg), rounding * 2,NULL,3.0f); // Color button are often in need of some sort of border
window->DrawList->AddRect(bb.Min - ImVec2(2, 2), bb.Max + ImVec2(2, 2), GetColorU32(ImGuiCol_FrameBg), rounding * 2,0,3.0f); // Color button are often in need of some sort of border
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/imgui/imstb_truetype.h
Original file line number Diff line number Diff line change
Expand Up @@ -4528,7 +4528,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
float ax = x1-x0, ay = y1-y0;
float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2;
float mx = x0 - sx, my = y0 - sy;
float res[3],px,py,t,it;
float res[3] = {},px,py,t,it;
float a_inv = precompute[i];
if (a_inv == 0.0) { // if a_inv is 0, it's 2nd degree so use quadratic formula
float a = 3*(ax*bx + ay*by);
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Algorithm/LineSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ SplittedLine do_split_line(const ClipperZUtils::ZPath& path, const ExPolygons& c

// Chain segment back to the original path
ClipperZUtils::ZPoint& front = segment.front();
const ClipperZUtils::ZPoint* previous_src_point;
const ClipperZUtils::ZPoint* previous_src_point = nullptr;
if (is_src(front)) {
// The segment starts with a point from src path, which means apart from the last point,
// all other points on this segment should come from the src path or the clip polygon
Expand Down
3 changes: 2 additions & 1 deletion src/libslic3r/Brim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,15 @@ double getadhesionCoeff(const PrintObject* printObject)
for (const ModelVolume* modelVolume : objectVolumes) {
for (auto iter = extrudersFirstLayer.begin(); iter != extrudersFirstLayer.end(); iter++)
if (modelVolume->extruder_id() == *iter) {
if (Model::extruderParamsMap.find(modelVolume->extruder_id()) != Model::extruderParamsMap.end())
if (Model::extruderParamsMap.find(modelVolume->extruder_id()) != Model::extruderParamsMap.end()) {
if (Model::extruderParamsMap.at(modelVolume->extruder_id()).materialName == "PETG" ||
Model::extruderParamsMap.at(modelVolume->extruder_id()).materialName == "PCTG") {
adhesionCoeff = 2;
}
else if (Model::extruderParamsMap.at(modelVolume->extruder_id()).materialName == "TPU") {
adhesionCoeff = 0.5;
}
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/libslic3r/ClipperUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ template<typename PointType> inline void clip_clipper_polygon_with_subject_bbox_
}

// Never produce just a single point output polygon.
if (!out.empty())
if (!out.empty()) {
if(get_entire_polygons){
out=src;
}else{
Expand All @@ -106,6 +106,7 @@ template<typename PointType> inline void clip_clipper_polygon_with_subject_bbox_
(sides_prev & sides_this & sides_next) == 0)
out.emplace_back(src.back());
}
}

}

Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ ColorRGBA complementary(const ColorRGBA& color)

ColorRGB saturate(const ColorRGB& color, float factor)
{
float h, s, v;
float h = 0.0, s = 0.0, v = 0.0;
RGBtoHSV(color.r(), color.g(), color.b(), h, s, v);
s = std::clamp(s * factor, 0.0f, 1.0f);
float r, g, b;
Expand Down
7 changes: 4 additions & 3 deletions src/libslic3r/Fill/FillConcentric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ int stagger_seam_index(int ind, LINE_T line, double shift, bool dir)
if (dir)
ind = (ind + 1) % line.points.size();
else
ind = ind > 0 ? --ind : line.points.size() - 1;
ind = (ind > 0) ? (ind - 1) : (line.points.size() - 1);

Point const &next = line.points[ind];
dist += point->distance_to(next);
point = &next;
Expand Down Expand Up @@ -61,8 +62,8 @@ void FillConcentric::_fill_surface_single(
size_t iPathFirst = polylines_out.size();
Point last_pos(0, 0);

double min_nozzle_diameter;
bool dir;
double min_nozzle_diameter = 0.0;
bool dir = false;
if (this->print_config != nullptr && params.density >= STAGGER_SEAM_THRESHOLD) {
min_nozzle_diameter = *std::min_element(print_config->nozzle_diameter.values.begin(), print_config->nozzle_diameter.values.end());
dir = rand() % 2;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/TriangleMeshSlicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,7 @@ void cut_mesh(const indexed_triangle_set& mesh, float z, indexed_triangle_set* u
// intersect v0-v1 and v2-v0 with cutting plane and make new vertices
auto new_vertex = [upper, lower, &upper_slice_vertices, &lower_slice_vertices](const Vec3f &a, const int ia, const Vec3f &b, const int ib, const Vec3f &c,
const int ic, const Vec3f &new_pt, bool &is_new_vertex) {
int iupper, ilower;
int iupper = 0, ilower = 0;
is_new_vertex = false;
if (is_equal(new_pt, a))
iupper = ilower = ia;
Expand Down
2 changes: 1 addition & 1 deletion src/mcut/source/shewchuk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2770,7 +2770,7 @@ REAL permanent;
REAL cxtaa[8], cxtbb[8], cytaa[8], cytbb[8];
int cxtaalen, cxtbblen, cytaalen, cytbblen;
REAL axtbc[8], aytbc[8], bxtca[8], bytca[8], cxtab[8], cytab[8];
int axtbclen, aytbclen, bxtcalen, bytcalen, cxtablen, cytablen;
int axtbclen = 0, aytbclen = 0, bxtcalen = 0, bytcalen = 0, cxtablen = 0, cytablen = 0;
REAL axtbct[16], aytbct[16], bxtcat[16], bytcat[16], cxtabt[16], cytabt[16];
int axtbctlen, aytbctlen, bxtcatlen, bytcatlen, cxtabtlen, cytabtlen;
REAL axtbctt[8], aytbctt[8], bxtcatt[8];
Expand Down
3 changes: 2 additions & 1 deletion src/slic3r/GUI/ConnectPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ void ConnectPrinterDialog::on_button_confirm(wxCommandEvent &event)
{
wxString code = m_textCtrl_code->GetTextCtrl()->GetValue();
for (char c : code) {
if (!('0' <= c && c <= '9' || 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z')) {
//if (!((('0' <= c) && (c <= '9')) || (('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')))) {
if(isalnum(c) == 0) {
show_error(this, _L("Invalid input."));
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/slic3r/GUI/EditGCodeDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ wxDataViewItem EditGCodeDialog::add_presets_placeholders()
const auto& full_config = wxGetApp().preset_bundle->full_config();
const auto& tab_list = wxGetApp().tabs_list;

Tab* tab_print;
Tab* tab_filament;
Tab* tab_printer;
Tab* tab_print = nullptr;
Tab* tab_filament = nullptr;
Tab* tab_printer = nullptr;
for (const auto tab : tab_list) {
if (tab->m_type == Preset::TYPE_PRINT)
tab_print = tab;
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/Gizmos/GLGizmoBrimEars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ bool GLGizmoBrimEars::unproject_on_mesh2(const Vec2d &mouse_pos, std::pair<Vec3f
double clp_dist = m_c->object_clipper()->get_position();
const ClippingPlane *clp = m_c->object_clipper()->get_clipping_plane();
bool mouse_on_object = false;
Vec3f position_on_model;
Vec3f normal_on_model;
Vec3f position_on_model {};
Vec3f normal_on_model {};
double closest_hit_distance = std::numeric_limits<double>::max();

for (auto item : m_mesh_raycaster_map) {
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ void GLGizmoMeasure::show_selection_ui()
return text;
};

float selection_cap_length;
float selection_cap_length = 0.0;
if (m_measure_mode == EMeasureMode::ONLY_ASSEMBLY) {
if (m_assembly_mode == AssemblyMode::FACE_FACE) {
selection_cap_length = ImGui::CalcTextSize((_u8L("Selection") + " 1" + _u8L(" (Moving)")).c_str()).x * 1.2;
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/ObjColorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ void ObjColorPanel::draw_table()

m_color_cluster_icon_list.clear();
m_extruder_icon_list.clear();
float row_height ;
float row_height = 0.0;
for (size_t ii = 0; ii < row; ii++) {
wxPanel *row_panel = new wxPanel(m_scrolledWindow);
row_panel->SetBackgroundColour(ii % 2 == 0 ? *wxWHITE : wxColour(238, 238, 238));
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/PlateSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ LayerNumberTextInput::LayerNumberTextInput(wxWindow* parent, int layer_number, w
// value should not be less than MIN_LAYER_VALUE, and should not be greater than MAX_LAYER_VALUE
gui_value = std::clamp(gui_value, MIN_LAYER_VALUE, MAX_LAYER_VALUE);

int begin_value;
int end_value;
int begin_value = 0;
int end_value = 0;
LayerNumberTextInput* end_layer_input = nullptr;
if (this->m_type == Type::Begin) {
begin_value = gui_value;
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3639,7 +3639,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
bool dlg_cont = true;
bool is_user_cancel = false;
bool translate_old = false;
int current_width, current_depth, current_height;
int current_width = 0, current_depth = 0, current_height = 0;

if (input_files.empty()) { return std::vector<size_t>(); }

Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/calib_dlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void Temp_Calibration_Dlg::on_start(wxCommandEvent& event) {

void Temp_Calibration_Dlg::on_filament_type_changed(wxCommandEvent& event) {
int selection = event.GetSelection();
unsigned long start,end;
unsigned long start = 0, end = 0;
switch(selection)
{
case tABS_ASA:
Expand Down
Loading