mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 07:34:03 -06:00
NEW:Add progress bar for large file loading (3mf,stl,step)
Change-Id: Ic54ca21e8193b15bbda08c22ea2fc4c93b440741
This commit is contained in:
parent
c6fc915164
commit
9c55893954
12 changed files with 130 additions and 38 deletions
|
@ -45,6 +45,8 @@ typedef Eigen::Matrix<int, 3, 1, Eigen::DontAlign> stl_triangle_vertex_indices
|
|||
static_assert(sizeof(stl_vertex) == 12, "size of stl_vertex incorrect");
|
||||
static_assert(sizeof(stl_normal) == 12, "size of stl_normal incorrect");
|
||||
|
||||
typedef std::function<void(int current, int total, bool& cancel)> ImportstlProgressFn;
|
||||
|
||||
typedef enum {
|
||||
eNormal, // normal face
|
||||
eSmallOverhang, // small overhang
|
||||
|
@ -244,7 +246,7 @@ struct indexed_triangle_set
|
|||
}
|
||||
};
|
||||
|
||||
extern bool stl_open(stl_file *stl, const char *file);
|
||||
extern bool stl_open(stl_file *stl, const char *file, ImportstlProgressFn stlFn = nullptr);
|
||||
extern void stl_stats_out(stl_file *stl, FILE *file, char *input_file);
|
||||
extern bool stl_print_neighbors(stl_file *stl, char *file);
|
||||
extern bool stl_write_ascii(stl_file *stl, const char *file, const char *label);
|
||||
|
@ -398,7 +400,7 @@ extern void stl_calculate_volume(stl_file *stl);
|
|||
extern void stl_repair(stl_file *stl, bool fixall_flag, bool exact_flag, bool tolerance_flag, float tolerance, bool increment_flag, float increment, bool nearby_flag, int iterations, bool remove_unconnected_flag, bool fill_holes_flag, bool normal_directions_flag, bool normal_values_flag, bool reverse_all_flag, bool verbose_flag);
|
||||
|
||||
extern void stl_allocate(stl_file *stl);
|
||||
extern void stl_read(stl_file *stl, int first_facet, bool first);
|
||||
extern void stl_read(stl_file *stl, int first_facet, bool first, ImportstlProgressFn stlFn = nullptr);
|
||||
extern void stl_facet_stats(stl_file *stl, stl_facet facet, bool &first);
|
||||
extern void stl_reallocate(stl_file *stl);
|
||||
extern void stl_add_facet(stl_file *stl, const stl_facet *new_facet);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <boost/predef/other/endian.h>
|
||||
|
||||
#include "stl.h"
|
||||
#include "libslic3r/Format/STL.hpp"
|
||||
|
||||
#include "libslic3r/LocalesUtils.hpp"
|
||||
|
||||
|
@ -42,6 +43,8 @@
|
|||
extern void stl_internal_reverse_quads(char *buf, size_t cnt);
|
||||
#endif /* BOOST_ENDIAN_BIG_BYTE */
|
||||
|
||||
const int LOAD_STL_UNIT_NUM = 5;
|
||||
|
||||
static FILE* stl_open_count_facets(stl_file *stl, const char *file)
|
||||
{
|
||||
// Open the file in binary mode first.
|
||||
|
@ -145,7 +148,7 @@ static FILE* stl_open_count_facets(stl_file *stl, const char *file)
|
|||
/* Reads the contents of the file pointed to by fp into the stl structure,
|
||||
starting at facet first_facet. The second argument says if it's our first
|
||||
time running this for the stl and therefore we should reset our max and min stats. */
|
||||
static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first)
|
||||
static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first, ImportstlProgressFn stlFn)
|
||||
{
|
||||
if (stl->stats.type == binary)
|
||||
fseek(fp, HEADER_SIZE, SEEK_SET);
|
||||
|
@ -153,7 +156,19 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first)
|
|||
rewind(fp);
|
||||
|
||||
char normal_buf[3][32];
|
||||
for (uint32_t i = first_facet; i < stl->stats.number_of_facets; ++ i) {
|
||||
|
||||
uint32_t facets_num = stl->stats.number_of_facets;
|
||||
uint32_t unit = facets_num / LOAD_STL_UNIT_NUM + 1;
|
||||
for (uint32_t i = first_facet; i < facets_num; ++ i) {
|
||||
if ((i % unit) == 0) {
|
||||
bool cb_cancel = false;
|
||||
if (stlFn) {
|
||||
stlFn(i, facets_num, cb_cancel);
|
||||
if (cb_cancel)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
stl_facet facet;
|
||||
|
||||
if (stl->stats.type == binary) {
|
||||
|
@ -232,7 +247,7 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool stl_open(stl_file *stl, const char *file)
|
||||
bool stl_open(stl_file *stl, const char *file, ImportstlProgressFn stlFn)
|
||||
{
|
||||
Slic3r::CNumericLocalesSetter locales_setter;
|
||||
stl->clear();
|
||||
|
@ -240,7 +255,7 @@ bool stl_open(stl_file *stl, const char *file)
|
|||
if (fp == nullptr)
|
||||
return false;
|
||||
stl_allocate(stl);
|
||||
bool result = stl_read(stl, fp, 0, true);
|
||||
bool result = stl_read(stl, fp, 0, true, stlFn);
|
||||
fclose(fp);
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue