NEW:Add progress bar for large file loading (3mf,stl,step)

Change-Id: Ic54ca21e8193b15bbda08c22ea2fc4c93b440741
This commit is contained in:
tao.jin 2022-08-12 16:57:33 +08:00 committed by Lane.Wei
parent c6fc915164
commit 9c55893954
12 changed files with 130 additions and 38 deletions

View file

@ -31,9 +31,6 @@
const double STEP_TRANS_CHORD_ERROR = 0.005;
const double STEP_TRANS_ANGLE_RES = 1;
const int LOAD_STEP_STAGE_READ_FILE = 0;
const int LOAD_STEP_STAGE_GET_SOLID = 1;
const int LOAD_STEP_STAGE_GET_MESH = 2;
namespace Slic3r {
@ -213,11 +210,11 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p
}
}
bool load_step(const char *path, Model *model, ImportStepProgressFn proFn, StepIsUtf8Fn isUtf8Fn)
bool load_step(const char *path, Model *model, ImportStepProgressFn stepFn, StepIsUtf8Fn isUtf8Fn)
{
bool cb_cancel = false;
if (proFn) {
proFn(LOAD_STEP_STAGE_READ_FILE, 0, 1, cb_cancel);
if (stepFn) {
stepFn(LOAD_STEP_STAGE_READ_FILE, 0, 1, cb_cancel);
if (cb_cancel)
return false;
}
@ -245,9 +242,13 @@ bool load_step(const char *path, Model *model, ImportStepProgressFn proFn, StepI
unsigned int id{1};
Standard_Integer topShapeLength = topLevelShapes.Length() + 1;
auto stage_unit2 = topShapeLength / LOAD_STEP_STAGE_UNIT_NUM + 1;
for (Standard_Integer iLabel = 1; iLabel < topShapeLength; ++iLabel) {
if (proFn) {
proFn(LOAD_STEP_STAGE_GET_SOLID, iLabel, topShapeLength, cb_cancel);
if (stepFn) {
if ((iLabel % stage_unit2) == 0) {
stepFn(LOAD_STEP_STAGE_GET_SOLID, iLabel, topShapeLength, cb_cancel);
}
if (cb_cancel) {
shapeTool.reset(nullptr);
application->Close(document);
@ -338,9 +339,13 @@ bool load_step(const char *path, Model *model, ImportStepProgressFn proFn, StepI
const char * last_slash = strrchr(path, DIR_SEPARATOR);
new_object->name.assign((last_slash == nullptr) ? path : last_slash + 1);
new_object->input_file = path;
auto stage_unit3 = stl.size() / LOAD_STEP_STAGE_UNIT_NUM + 1;
for (size_t i = 0; i < stl.size(); i++) {
if (proFn) {
proFn(LOAD_STEP_STAGE_GET_MESH, i, namedSolids.size(), cb_cancel);
if (stepFn) {
if ((i % stage_unit3) == 0) {
stepFn(LOAD_STEP_STAGE_GET_MESH, i, stl.size(), cb_cancel);
}
if (cb_cancel) {
model->delete_object(new_object);
shapeTool.reset(nullptr);

View file

@ -6,6 +6,13 @@ namespace Slic3r {
class TriangleMesh;
class ModelObject;
// load step stage
const int LOAD_STEP_STAGE_READ_FILE = 0;
const int LOAD_STEP_STAGE_GET_SOLID = 1;
const int LOAD_STEP_STAGE_GET_MESH = 2;
const int LOAD_STEP_STAGE_NUM = 3;
const int LOAD_STEP_STAGE_UNIT_NUM = 5;
typedef std::function<void(int load_stage, int current, int total, bool& cancel)> ImportStepProgressFn;
typedef std::function<void(bool isUtf8)> StepIsUtf8Fn;

View file

@ -14,10 +14,10 @@
namespace Slic3r {
bool load_stl(const char *path, Model *model, const char *object_name_in)
bool load_stl(const char *path, Model *model, const char *object_name_in, ImportstlProgressFn stlFn)
{
TriangleMesh mesh;
if (! mesh.ReadSTLFile(path)) {
if (! mesh.ReadSTLFile(path, true, stlFn)) {
// die "Failed to open $file\n" if !-e $path;
return false;
}

View file

@ -1,13 +1,16 @@
#ifndef slic3r_Format_STL_hpp_
#define slic3r_Format_STL_hpp_
#include <admesh/stl.h>
namespace Slic3r {
class Model;
class TriangleMesh;
class ModelObject;
// Load an STL file into a provided model.
extern bool load_stl(const char *path, Model *model, const char *object_name = nullptr);
extern bool load_stl(const char *path, Model *model, const char *object_name = nullptr, ImportstlProgressFn stlFn = nullptr);
extern bool store_stl(const char *path, TriangleMesh *mesh, bool binary);
extern bool store_stl(const char *path, ModelObject *model_object, bool binary);

View file

@ -166,6 +166,7 @@ const int IMPORT_STAGE_CHECK_MODE_GCODE = 9;
const int UPDATE_GCODE_RESULT = 10;
const int IMPORT_LOAD_CONFIG = 11;
const int IMPORT_LOAD_MODEL_OBJECTS = 12;
const int IMPORT_STAGE_MAX = 13;
//BBS export 3mf progress
typedef std::function<void(int export_stage, int current, int total, bool& cancel)> Export3mfProgressFn;