PartDesign: Add transparent previews

This commit is contained in:
Kacper Donat
2024-10-13 13:33:18 +02:00
parent 2b5a95f3d0
commit c4b741f488
58 changed files with 1438 additions and 1021 deletions

View File

@@ -28,10 +28,13 @@
#include <App/FeaturePythonPyImp.h>
#include <Mod/Part/App/modelRefine.h>
#include <Mod/Part/App/TopoShapeOpCode.h>
#include "FeatureAddSub.h"
#include "FeaturePy.h"
#include <Mod/Part/App/Tools.h>
using namespace PartDesign;
@@ -43,7 +46,12 @@ PROPERTY_SOURCE(PartDesign::FeatureAddSub, PartDesign::FeatureRefine)
FeatureAddSub::FeatureAddSub()
{
ADD_PROPERTY(AddSubShape,(TopoDS_Shape()));
ADD_PROPERTY(AddSubShape, (TopoDS_Shape()));
}
void FeatureAddSub::onChanged(const App::Property* property)
{
Feature::onChanged(property);
}
FeatureAddSub::Type FeatureAddSub::getAddSubType()
@@ -58,16 +66,53 @@ short FeatureAddSub::mustExecute() const
return PartDesign::Feature::mustExecute();
}
void FeatureAddSub::getAddSubShape(Part::TopoShape &addShape, Part::TopoShape &subShape)
void FeatureAddSub::getAddSubShape(Part::TopoShape& addShape, Part::TopoShape& subShape)
{
if (addSubType == Additive)
if (addSubType == Additive) {
addShape = AddSubShape.getShape();
else if (addSubType == Subtractive)
}
else if (addSubType == Subtractive) {
subShape = AddSubShape.getShape();
}
}
void FeatureAddSub::updatePreviewShape()
{
const auto notifyWarning = [](const QString& message) {
Base::Console().translatedUserWarning(
"Preview",
tr("Failure while computing removed volume preview: %1")
.arg(message)
.toUtf8());
};
// for subtractive shapes we want to also showcase removed volume, not only the tool
if (addSubType == Subtractive) {
TopoShape base = getBaseTopoShape(true).moved(getLocation().Inverted());
if (const TopoShape& addSubShape = AddSubShape.getShape(); !addSubShape.isEmpty()) {
try {
base.makeElementBoolean(Part::OpCodes::Common, { base, addSubShape });
} catch (Standard_Failure& e) {
notifyWarning(QString::fromUtf8(e.GetMessageString()));
} catch (Base::Exception& e) {
notifyWarning(QString::fromStdString(e.getMessage()));
}
if (base.isEmpty()) {
notifyWarning(tr("Resulting shape is empty. That may indicate that no material will be removed or a problem with the model."));
}
PreviewShape.setValue(base);
return;
}
}
PreviewShape.setValue(AddSubShape.getShape());
}
} // namespace PartDesign
namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(PartDesign::FeatureAddSubPython, PartDesign::FeatureAddSub)