PartDesign: Highlight profile for profile based features

This adds highlight for sketches etc that are used to create certain
featuires.
This commit is contained in:
Kacper Donat
2025-08-30 01:05:10 +02:00
committed by Chris Hennes
parent 23691409e0
commit 767c3f1f67
5 changed files with 120 additions and 4 deletions

View File

@@ -67,6 +67,7 @@ void DlgSettingsGeneral::saveSettings()
ui->comboDefaultProfileTypeForHole->onSave();
ui->checkShowFinalPreview->onSave();
ui->checkShowTransparentPreview->onSave();
ui->checkShowProfilePreview->onSave();
ui->checkSwitchToTask->onSave();
}
@@ -82,6 +83,7 @@ void DlgSettingsGeneral::loadSettings()
ui->comboDefaultProfileTypeForHole->onRestore();
ui->checkShowFinalPreview->onRestore();
ui->checkShowTransparentPreview->onRestore();
ui->checkShowProfilePreview->onRestore();
ui->checkSwitchToTask->onRestore();
}

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>550</width>
<height>513</height>
<height>552</height>
</rect>
</property>
<property name="windowTitle">
@@ -203,7 +203,7 @@
<item>
<widget class="Gui::PrefCheckBox" name="checkShowFinalPreview">
<property name="text">
<string>Show final result by default when editing feature</string>
<string>Show final result by default when editing features</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ShowFinal</cstring>
@@ -216,7 +216,7 @@
<item>
<widget class="Gui::PrefCheckBox" name="checkShowTransparentPreview">
<property name="text">
<string>Show transparent preview overlay by default when editing feature</string>
<string>Show transparent preview overlay by default when editing features</string>
</property>
<property name="checked">
<bool>true</bool>
@@ -229,6 +229,22 @@
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkShowProfilePreview">
<property name="text">
<string>Highlight the profile used to create features</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ShowProfilePreview</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/PartDesign/Preview</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@@ -32,6 +32,9 @@ namespace PartDesignGui::StyleParameters {
DEFINE_STYLE_PARAMETER(PreviewCommonColor, Base::Color(1.0F, 1.0F, 0.0F));
DEFINE_STYLE_PARAMETER(PreviewDressUpColor, Base::Color(1.0F, 0.0F, 1.0F));
DEFINE_STYLE_PARAMETER(PreviewProfileLineWidth, Gui::StyleParameters::Numeric(4));
DEFINE_STYLE_PARAMETER(PreviewProfileOpacity, Gui::StyleParameters::Numeric(0.0));
DEFINE_STYLE_PARAMETER(PreviewErrorColor, Base::Color(1.0F, 0.0F, 0.0F));
DEFINE_STYLE_PARAMETER(PreviewErrorOpacity, Gui::StyleParameters::Numeric(0.05));

View File

@@ -23,11 +23,21 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Inventor/nodes/SoAnnotation.h>
#endif
#include <App/Document.h>
#include <Base/ServiceProvider.h>
#include <Gui/Application.h>
#include <Gui/Utilities.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/PartDesign/App/FeatureSketchBased.h>
#include "ViewProviderSketchBased.h"
#include "StyleParameters.h"
#include <Gui/Inventor/So3DAnnotation.h>
using namespace PartDesignGui;
@@ -35,7 +45,32 @@ using namespace PartDesignGui;
PROPERTY_SOURCE(PartDesignGui::ViewProviderSketchBased, PartDesignGui::ViewProvider)
ViewProviderSketchBased::ViewProviderSketchBased() = default;
ViewProviderSketchBased::ViewProviderSketchBased() :
pcProfileToggle(new SoToggleSwitch),
pcProfileShape(new PartGui::SoPreviewShape)
{
auto annotation = new Gui::So3DAnnotation;
annotation->addChild(pcProfileShape);
pcProfileToggle->addChild(annotation);
const auto updateProfileVisibility = [this]() {
pcProfileToggle->on = hGrp->GetBool("ShowProfilePreview", true);
};
handlers.addHandler(hGrp, "ShowProfilePreview", [updateProfileVisibility](const Gui::ParamKey*) {
updateProfileVisibility();
});
updateProfileVisibility();
auto* styleParametersManager = Base::provideService<Gui::StyleParameters::ParameterManager>();
pcProfileShape->transparency = 1.0F - static_cast<float>(
styleParametersManager->resolve(StyleParameters::PreviewProfileOpacity).value);
pcProfileShape->lineWidth = static_cast<float>(
styleParametersManager->resolve(StyleParameters::PreviewProfileLineWidth).value);
}
ViewProviderSketchBased::~ViewProviderSketchBased() = default;
@@ -47,3 +82,45 @@ std::vector<App::DocumentObject*> ViewProviderSketchBased::claimChildren() const
return temp;
}
void ViewProviderSketchBased::attach(App::DocumentObject* pcObject)
{
ViewProvider::attach(pcObject);
pcPreviewRoot->addChild(pcProfileToggle);
// we want the profile to be the same color as the preview
pcProfileShape->color.connectFrom(&pcPreviewShape->color);
}
void ViewProviderSketchBased::updateProfileShape()
{
auto document = pcObject->getDocument();
if (document->testStatus(App::Document::Restoring)) {
return;
}
auto profileBased = getObject<PartDesign::ProfileBased>();
updatePreviewShape(profileBased->getTopoShapeVerifiedFace(true), pcProfileShape);
}
void ViewProviderSketchBased::updateData(const App::Property* prop)
{
ViewProvider::updateData(prop);
auto profileBased = getObject<PartDesign::ProfileBased>();
if (!profileBased) {
return;
}
if (prop == &profileBased->Profile) {
updateProfileShape();
}
}
void ViewProviderSketchBased::updatePreview()
{
ViewProvider::updatePreview();
updateProfileShape();
}

View File

@@ -25,6 +25,9 @@
#include "ViewProvider.h"
#include <Gui/ParamHandler.h>
#include <Gui/Inventor/SoToggleSwitch.h>
namespace PartDesignGui {
/**
@@ -43,6 +46,21 @@ public:
/// grouping handling
std::vector<App::DocumentObject*> claimChildren() const override;
void attach(App::DocumentObject* pcObject) override;
protected:
void updateData(const App::Property* prop) override;
void updatePreview() override;
private:
void updateProfileShape();
Gui::CoinPtr<SoToggleSwitch> pcProfileToggle;
Gui::CoinPtr<PartGui::SoPreviewShape> pcProfileShape;
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/PartDesign/Preview");
Gui::ParamHandlers handlers;
};
} /* PartDesignGui */