FIX: cancel loading .step without warning

Change-Id: I5274b744c223fbd92dbca669f3d57c01b5558f88
This commit is contained in:
tao.jin 2023-02-16 11:49:55 +08:00 committed by Lane.Wei
parent 1d92895456
commit f5e8d70989
3 changed files with 14 additions and 4 deletions

View File

@ -210,14 +210,16 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p
} }
} }
bool load_step(const char *path, Model *model, ImportStepProgressFn stepFn, StepIsUtf8Fn isUtf8Fn) bool load_step(const char *path, Model *model, bool& is_cancel, ImportStepProgressFn stepFn, StepIsUtf8Fn isUtf8Fn)
{ {
bool cb_cancel = false; bool cb_cancel = false;
if (stepFn) { if (stepFn) {
stepFn(LOAD_STEP_STAGE_READ_FILE, 0, 1, cb_cancel); stepFn(LOAD_STEP_STAGE_READ_FILE, 0, 1, cb_cancel);
if (cb_cancel) is_cancel = cb_cancel;
if (cb_cancel) {
return false; return false;
} }
}
if (!StepPreProcessor::isUtf8File(path) && isUtf8Fn) if (!StepPreProcessor::isUtf8File(path) && isUtf8Fn)
isUtf8Fn(false); isUtf8Fn(false);
@ -248,6 +250,7 @@ bool load_step(const char *path, Model *model, ImportStepProgressFn stepFn, Step
if (stepFn) { if (stepFn) {
if ((iLabel % stage_unit2) == 0) { if ((iLabel % stage_unit2) == 0) {
stepFn(LOAD_STEP_STAGE_GET_SOLID, iLabel, topShapeLength, cb_cancel); stepFn(LOAD_STEP_STAGE_GET_SOLID, iLabel, topShapeLength, cb_cancel);
is_cancel = cb_cancel;
} }
if (cb_cancel) { if (cb_cancel) {
shapeTool.reset(nullptr); shapeTool.reset(nullptr);
@ -345,6 +348,7 @@ bool load_step(const char *path, Model *model, ImportStepProgressFn stepFn, Step
if (stepFn) { if (stepFn) {
if ((i % stage_unit3) == 0) { if ((i % stage_unit3) == 0) {
stepFn(LOAD_STEP_STAGE_GET_MESH, i, stl.size(), cb_cancel); stepFn(LOAD_STEP_STAGE_GET_MESH, i, stl.size(), cb_cancel);
is_cancel = cb_cancel;
} }
if (cb_cancel) { if (cb_cancel) {
model->delete_object(new_object); model->delete_object(new_object);

View File

@ -17,7 +17,7 @@ typedef std::function<void(int load_stage, int current, int total, bool& cancel)
typedef std::function<void(bool isUtf8)> StepIsUtf8Fn; typedef std::function<void(bool isUtf8)> StepIsUtf8Fn;
//BBS: Load an step file into a provided model. //BBS: Load an step file into a provided model.
extern bool load_step(const char *path, Model *model, ImportStepProgressFn proFn = nullptr, StepIsUtf8Fn isUtf8Fn = nullptr); extern bool load_step(const char *path, Model *model, bool& is_cancel, ImportStepProgressFn proFn = nullptr, StepIsUtf8Fn isUtf8Fn = nullptr);
//BBS: Used to detect what kind of encoded type is used in name field of step //BBS: Used to detect what kind of encoded type is used in name field of step
// If is encoded in UTF8, the file don't need to be handled, then return the original path directly. // If is encoded in UTF8, the file don't need to be handled, then return the original path directly.

View File

@ -165,10 +165,11 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c
file_version = &temp_version; file_version = &temp_version;
bool result = false; bool result = false;
bool is_cb_cancel = false;
std::string message; std::string message;
if (boost::algorithm::iends_with(input_file, ".stp") || if (boost::algorithm::iends_with(input_file, ".stp") ||
boost::algorithm::iends_with(input_file, ".step")) boost::algorithm::iends_with(input_file, ".step"))
result = load_step(input_file.c_str(), &model, stepFn, stepIsUtf8Fn); result = load_step(input_file.c_str(), &model, is_cb_cancel, stepFn, stepIsUtf8Fn);
else if (boost::algorithm::iends_with(input_file, ".stl")) else if (boost::algorithm::iends_with(input_file, ".stl"))
result = load_stl(input_file.c_str(), &model, nullptr, stlFn); result = load_stl(input_file.c_str(), &model, nullptr, stlFn);
else if (boost::algorithm::iends_with(input_file, ".obj")) else if (boost::algorithm::iends_with(input_file, ".obj"))
@ -189,6 +190,11 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c
else else
throw Slic3r::RuntimeError("Unknown file format. Input file must have .stl, .obj, .amf(.xml) extension."); throw Slic3r::RuntimeError("Unknown file format. Input file must have .stl, .obj, .amf(.xml) extension.");
if (is_cb_cancel) {
Model empty_model;
return empty_model;
}
if (!result) { if (!result) {
if (message.empty()) if (message.empty())
throw Slic3r::RuntimeError("Loading of a model file failed."); throw Slic3r::RuntimeError("Loading of a model file failed.");