NEW:step mesh add 'Split compound and compsolid'

Optimize getting STEP node names.
Fix load_same_type_files()

GITHUB: #5214
Change-Id: I7d1035c122f21e3b08305509489bce415634ae80
(cherry picked from commit 76a401bfca1897994795cb37ffa9cbcbdaca8b6c)
(cherry picked from commit a0669137ec7e698320d0bc50ee986cb3f0e85164)
This commit is contained in:
Mack
2024-11-28 12:23:59 +08:00
committed by Noisyfox
parent 1e75686221
commit 588f42e2e2
8 changed files with 56 additions and 21 deletions

View File

@@ -416,6 +416,9 @@ void AppConfig::set_defaults()
set("linear_defletion", "0.003");
set("angle_defletion", "0.5");
}
if (get("is_split_compound").empty()) {
set_bool("is_split_compound", false);
}
// Remove legacy window positions/sizes
erase("app", "main_frame_maximized");

View File

@@ -165,16 +165,21 @@ int StepPreProcessor::preNum(const unsigned char byte) {
return num;
}
static void getNamedSolids(const TopLoc_Location& location, const std::string& prefix,
unsigned int& id, const Handle(XCAFDoc_ShapeTool) shapeTool,
const TDF_Label label, std::vector<NamedSolid>& namedSolids) {
static void getNamedSolids(const TopLoc_Location& location,
const std::string& prefix,
unsigned int& id,
const Handle(XCAFDoc_ShapeTool) shapeTool,
const TDF_Label label,
std::vector<NamedSolid>& namedSolids,
bool isSplitCompound = false) {
TDF_Label referredLabel{label};
if (shapeTool->IsReference(label))
shapeTool->GetReferredShape(label, referredLabel);
std::string name;
Handle(TDataStd_Name) shapeName;
if (referredLabel.FindAttribute(TDataStd_Name::GetID(), shapeName))
if (referredLabel.FindAttribute(TDataStd_Name::GetID(), shapeName) ||
label.FindAttribute(TDataStd_Name::GetID(), shapeName))
name = TCollection_AsciiString(shapeName->Get()).ToCString();
if (name == "" || !StepPreProcessor::isUtf8(name))
@@ -185,7 +190,7 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p
TDF_LabelSequence components;
if (shapeTool->GetComponents(referredLabel, components)) {
for (Standard_Integer compIndex = 1; compIndex <= components.Length(); ++compIndex) {
getNamedSolids(localLocation, fullName, id, shapeTool, components.Value(compIndex), namedSolids);
getNamedSolids(localLocation, fullName, id, shapeTool, components.Value(compIndex), namedSolids, isSplitCompound);
}
} else {
TopoDS_Shape shape;
@@ -196,11 +201,19 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p
int i = 0;
switch (shape_type) {
case TopAbs_COMPOUND:
if (!isSplitCompound) {
namedSolids.emplace_back(TopoDS::Compound(transform.Shape()), fullName);
break;
}
case TopAbs_COMPSOLID:
for (explorer.Init(transform.Shape(), TopAbs_SOLID); explorer.More(); explorer.Next()) {
i++;
const TopoDS_Shape& currentShape = explorer.Current();
namedSolids.emplace_back(TopoDS::Solid(currentShape), fullName + "-SOLID-" + std::to_string(i));
if (!isSplitCompound) {
namedSolids.emplace_back(TopoDS::CompSolid(transform.Shape()), fullName);
} else {
for (explorer.Init(transform.Shape(), TopAbs_SOLID); explorer.More(); explorer.Next()) {
i++;
const TopoDS_Shape& currentShape = explorer.Current();
namedSolids.emplace_back(TopoDS::Solid(currentShape), fullName + "-SOLID-" + std::to_string(i));
}
}
break;
case TopAbs_SOLID:
@@ -218,6 +231,7 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p
bool load_step(const char *path, Model *model, bool& is_cancel,
double linear_defletion/*=0.003*/,
double angle_defletion/*= 0.5*/,
bool isSplitCompound,
ImportStepProgressFn stepFn, StepIsUtf8Fn isUtf8Fn, long& mesh_face_num)
{
bool cb_cancel = false;
@@ -266,7 +280,7 @@ bool load_step(const char *path, Model *model, bool& is_cancel,
return false;
}
}
getNamedSolids(TopLoc_Location{}, "", id, shapeTool, topLevelShapes.Value(iLabel), namedSolids);
getNamedSolids(TopLoc_Location{}, "", id, shapeTool, topLevelShapes.Value(iLabel), namedSolids, isSplitCompound);
}
std::vector<stl_file> stl;

View File

@@ -40,6 +40,7 @@ extern bool load_step(const char *path, Model *model,
bool& is_cancel,
double linear_defletion = 0.003,
double angle_defletion = 0.5,
bool isSplitCompound = false,
ImportStepProgressFn proFn = nullptr,
StepIsUtf8Fn isUtf8Fn = nullptr,
long& mesh_face_num = *(new long(-1)));
@@ -62,7 +63,7 @@ public:
bool preprocess(const char* path, std::string &output_path);
static bool isUtf8File(const char* path);
static bool isUtf8(const std::string str);
private:
private:
static bool isGBK(const std::string str);
static int preNum(const unsigned char byte);
//BBS: default is UTF8 for most step file.

View File

@@ -181,9 +181,10 @@ Model Model::read_from_step(const std::string&
LoadStrategy options,
ImportStepProgressFn stepFn,
StepIsUtf8Fn stepIsUtf8Fn,
std::function<int(Slic3r::Step&, double&, double&)> step_mesh_fn,
std::function<int(Slic3r::Step&, double&, double&, bool&)> step_mesh_fn,
double linear_defletion,
double angle_defletion)
double angle_defletion,
bool is_split_compound)
{
Model model;
bool result = false;
@@ -192,12 +193,12 @@ Model Model::read_from_step(const std::string&
Step step_file(input_file);
step_file.load();
if (step_mesh_fn) {
if (step_mesh_fn(step_file, linear_defletion, angle_defletion) == -1) {
if (step_mesh_fn(step_file, linear_defletion, angle_defletion, is_split_compound) == -1) {
Model empty_model;
return empty_model;
}
}
result = load_step(input_file.c_str(), &model, is_cb_cancel, linear_defletion, angle_defletion, stepFn, stepIsUtf8Fn);
result = load_step(input_file.c_str(), &model, is_cb_cancel, linear_defletion, angle_defletion, is_split_compound, stepFn, stepIsUtf8Fn);
if (is_cb_cancel) {
Model empty_model;
return empty_model;

View File

@@ -1535,9 +1535,10 @@ public:
LoadStrategy options,
ImportStepProgressFn stepFn,
StepIsUtf8Fn stepIsUtf8Fn,
std::function<int(Slic3r::Step&, double&, double&)> step_mesh_fn,
std::function<int(Slic3r::Step&, double&, double&, bool&)> step_mesh_fn,
double linear_defletion,
double angle_defletion);
double angle_defletion,
bool is_split_compound);
//BBS: add part plate related logic
// BBS: backup