[Part] Section cut: add missing color handling for the cut faces

- the color was not handled at all and thus was often criticized
This commit is contained in:
Uwe
2022-03-18 06:01:14 +01:00
parent 94c32d9a46
commit 66a5cd1a49
3 changed files with 345 additions and 65 deletions

View File

@@ -29,6 +29,7 @@
# include <QDockWidget>
# include <QDoubleSpinBox>
# include <QSlider>
# include <QToolTip>
#endif
#include <App/Document.h>
@@ -40,8 +41,10 @@
#include <Gui/DockWindowManager.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/PrefWidgets.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#include <Gui/ViewProviderGeometryObject.h>
#include <Mod/Part/App/FeatureCompound.h>
#include <Mod/Part/App/FeaturePartBox.h>
#include <Mod/Part/App/FeaturePartCommon.h>
@@ -104,11 +107,28 @@ SectionCut::SectionCut(QWidget* parent)
ObjectsListVisible.push_back(*it);
}
// lambda function to set color and transpareny
auto setColorTransparency = [&](Part::Box* pcBox) {
App::Color cutColor;
long cutTransparency;
auto vpBox = dynamic_cast<Gui::ViewProviderGeometryObject*>(
Gui::Application::Instance->getViewProvider(pcBox));
if (vpBox) {
cutColor = vpBox->ShapeColor.getValue();
cutTransparency = vpBox->Transparency.getValue();
ui->CutColor->setColor(cutColor.asValue<QColor>());
ui->CutTransparency->setValue(cutTransparency);
ui->CutTransparency->setToolTip(QString::number(cutTransparency) + QString::fromLatin1(" %"));
}
};
// if we can have existing cut boxes, take their values
// to access the flip state we must compare the bounding boxes of the cutbox and the compound
Base::BoundBox3d BoundCompound;
Base::BoundBox3d BoundCutBox;
if (doc->getObject(BoxXName) || doc->getObject(BoxYName) || doc->getObject(BoxZName)) {
// automatic coloring must be disabled
ui->AutoCutfaceColor->setChecked(false);
if (doc->getObject(CompoundName)) {
auto compoundObject = doc->getObject(CompoundName);
Part::Compound* pcCompound = dynamic_cast<Part::Compound*>(compoundObject);
@@ -138,6 +158,8 @@ SectionCut::SectionCut(QWidget* parent)
ui->cutZ->setValue(pcBox->Height.getValue() + pcBox->Placement.getValue().getPosition().z);
ui->flipZ->setChecked(false);
}
// set color and transparency
setColorTransparency(pcBox);
}
if (doc->getObject(BoxYName)) {
Part::Box* pcBox = dynamic_cast<Part::Box*>(doc->getObject(BoxYName));
@@ -156,6 +178,7 @@ SectionCut::SectionCut(QWidget* parent)
ui->cutY->setValue(pcBox->Width.getValue() + pcBox->Placement.getValue().getPosition().y);
ui->flipY->setChecked(false);
}
setColorTransparency(pcBox);
}
if (doc->getObject(BoxXName)) {
Part::Box* pcBox = dynamic_cast<Part::Box*>(doc->getObject(BoxXName));
@@ -174,6 +197,7 @@ SectionCut::SectionCut(QWidget* parent)
ui->cutX->setValue(pcBox->Length.getValue() + pcBox->Placement.getValue().getPosition().x);
ui->flipX->setChecked(false);
}
setColorTransparency(pcBox);
}
// hide existing cuts to check if there are objects to be cut visible
@@ -214,6 +238,9 @@ SectionCut::SectionCut(QWidget* parent)
connect(ui->flipY, &QPushButton::clicked, this, &SectionCut::onFlipYclicked);
connect(ui->flipZ, &QPushButton::clicked, this, &SectionCut::onFlipZclicked);
connect(ui->RefreshCutPB, &QPushButton::clicked, this, &SectionCut::onRefreshCutPBclicked);
connect(ui->CutColor, &QPushButton::clicked, this, &SectionCut::onCutColorclicked);
connect(ui->CutTransparency, &QSlider::sliderMoved, this, &SectionCut::onTransparencySliderMoved);
connect(ui->CutTransparency, &QSlider::valueChanged, this, &SectionCut::onTransparencyChanged);
// if there is a cut, perform it
if (hasBoxX || hasBoxY || hasBoxZ) {
@@ -450,6 +477,17 @@ void SectionCut::startCutting(bool isInitial)
return;
}
Part::Compound* pcCompound = static_cast<Part::Compound*>(CutCompound);
// store color and transparency of first object
App::Color cutColor;
int cutTransparency;
bool autoColor = true;
bool autoTransparency = true;
auto vpFirstObject = dynamic_cast<Gui::ViewProviderGeometryObject*>(
Gui::Application::Instance->getViewProvider(*ObjectsListCut.begin()));
if (vpFirstObject) {
cutColor = vpFirstObject->ShapeColor.getValue();
cutTransparency = vpFirstObject->Transparency.getValue();
}
// fill it with all found elements with the copies of the elements
int count = 0;
for (auto itCuts = ObjectsListCut.begin(); itCuts != ObjectsListCut.end(); ++itCuts, count++) {
@@ -492,6 +530,18 @@ void SectionCut::startCutting(bool isInitial)
// hide the objects since only the cut should later be visible
(*itCuts)->Visibility.setValue(false);
// check if all objects have same color and transparency
if (ui->AutoCutfaceColor->isChecked()) {
auto vpObject = dynamic_cast<Gui::ViewProviderGeometryObject*>(
Gui::Application::Instance->getViewProvider(*itCuts));
if (vpObject) {
if (cutColor != vpObject->ShapeColor.getValue())
autoColor = false;
if (cutTransparency != vpObject->Transparency.getValue())
autoTransparency = false;
}
}
}
// compute the filled compound
@@ -534,6 +584,26 @@ void SectionCut::startCutting(bool isInitial)
hasBoxZ = false;
hasBoxCustom = false;
// if automatic, we take this color for the cut
if (ui->AutoCutfaceColor->isChecked()) {
if (autoColor) {
ui->CutColor->blockSignals(true);
ui->CutColor->setColor(cutColor.asValue<QColor>());
ui->CutColor->blockSignals(false);
}
if (autoTransparency) {
ui->CutTransparency->blockSignals(true);
ui->CutTransparency->setValue(cutTransparency);
ui->CutTransparency->setToolTip(QString::number(cutTransparency) + QString::fromLatin1(" %"));
ui->CutTransparency->blockSignals(false);
}
}
// read cutface color for the cut box
App::Color boxColor;
boxColor.setValue<QColor>(ui->CutColor->color());
int boxTransparency = ui->CutTransparency->value();
if (ui->groupBoxX->isChecked()) {
// create a box
auto CutBox = doc->addObject("Part::Box", BoxXName);
@@ -568,7 +638,14 @@ void SectionCut::startCutting(bool isInitial)
BoxOriginSet.y = BoundingBoxOrigin[1] - 0.5;
BoxOriginSet.z = BoundingBoxOrigin[2] - 0.5;
placement.setPosition(BoxOriginSet);
// set box color
pcBox->Placement.setValue(placement);
auto vpBox = dynamic_cast<Gui::ViewProviderGeometryObject*>(
Gui::Application::Instance->getViewProvider(pcBox));
if (vpBox) {
vpBox->ShapeColor.setValue(boxColor);
vpBox->Transparency.setValue(boxTransparency);
}
// create a cut feature
auto CutFeature = doc->addObject("Part::Cut", CutXName);
@@ -627,6 +704,12 @@ void SectionCut::startCutting(bool isInitial)
BoxOriginSet.z = BoundingBoxOrigin[2] - 0.5;
placement.setPosition(BoxOriginSet);
pcBox->Placement.setValue(placement);
auto vpBox = dynamic_cast<Gui::ViewProviderGeometryObject*>(
Gui::Application::Instance->getViewProvider(pcBox));
if (vpBox) {
vpBox->ShapeColor.setValue(boxColor);
vpBox->Transparency.setValue(boxTransparency);
}
auto CutFeature = doc->addObject("Part::Cut", CutYName);
if (!CutFeature) {
@@ -682,6 +765,12 @@ void SectionCut::startCutting(bool isInitial)
BoxOriginSet.z = CutPosZ;
placement.setPosition(BoxOriginSet);
pcBox->Placement.setValue(placement);
auto vpBox = dynamic_cast<Gui::ViewProviderGeometryObject*>(
Gui::Application::Instance->getViewProvider(pcBox));
if (vpBox) {
vpBox->ShapeColor.setValue(boxColor);
vpBox->Transparency.setValue(boxTransparency);
}
auto CutFeature = doc->addObject("Part::Cut", CutZName);
if (!CutFeature) {
@@ -1391,6 +1480,29 @@ void SectionCut::onFlipZclicked()
pcCut->recomputeFeature(true);
}
// changes the cutface color
void SectionCut::onCutColorclicked()
{
// re-cut to change the color of all cut boxes
if (ui->groupBoxX->isChecked() || ui->groupBoxY->isChecked() || ui->groupBoxZ->isChecked())
startCutting();
}
void SectionCut::onTransparencySliderMoved(int val)
{
ui->CutTransparency->setToolTip(QString::number(val) + QString::fromLatin1(" %"));
// highlight the tooltip
QToolTip::showText(QCursor::pos(), QString::number(val) + QString::fromLatin1(" %"), nullptr);
// re-cut to change the color of all cut boxes
if (ui->groupBoxX->isChecked() || ui->groupBoxY->isChecked() || ui->groupBoxZ->isChecked())
startCutting();
}
void SectionCut::onTransparencyChanged(int val)
{
onTransparencySliderMoved(val);
}
// refreshes the list of document objects and the visible objects
void SectionCut::onRefreshCutPBclicked()
{

View File

@@ -56,6 +56,9 @@ protected Q_SLOTS:
void onFlipYclicked();
void onFlipZclicked();
void onRefreshCutPBclicked();
void onCutColorclicked();
void onTransparencySliderMoved(int);
void onTransparencyChanged(int);
public:
void reject();

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>233</width>
<height>340</height>
<width>230</width>
<height>427</height>
</rect>
</property>
<property name="maximumSize">
@@ -20,7 +20,7 @@
<string>Permanent Section Cutting</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0" colspan="4">
<item row="0" column="0" colspan="3">
<widget class="QGroupBox" name="groupBoxX">
<property name="maximumSize">
<size>
@@ -94,33 +94,7 @@
</layout>
</widget>
</item>
<item row="5" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="RefreshCutPB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Refreshes the list of visible objects</string>
</property>
<property name="text">
<string>Refresh view</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<item row="1" column="0" colspan="3">
<widget class="QGroupBox" name="groupBoxY">
<property name="maximumSize">
<size>
@@ -188,41 +162,7 @@
</layout>
</widget>
</item>
<item row="3" column="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
<item row="4" column="0" colspan="4">
<widget class="QCheckBox" name="keepOnlyCutCB">
<property name="toolTip">
<string>When the dialog is closed,
only created cuts will be visible</string>
</property>
<property name="text">
<string>Keep only cuts visible when closing</string>
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="4">
<item row="2" column="0" colspan="3">
<widget class="QGroupBox" name="groupBoxZ">
<property name="maximumSize">
<size>
@@ -296,8 +236,201 @@ only created cuts will be visible</string>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QGroupBox" name="CutfaceGB">
<property name="title">
<string>Cut face</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Color of cut face</string>
</property>
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::PrefColorButton" name="CutColor">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="color" stdset="0">
<color>
<red>204</red>
<green>204</green>
<blue>204</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultShapeColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="Gui::PrefCheckBox" name="AutoCutfaceColor">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>If checked, the color and transpareny
will be taken from the cut objects.
Works only if all objects have the same values.</string>
</property>
<property name="text">
<string>Auto</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>TwoSideRendering</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Part</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Transparency of cut face</string>
</property>
<property name="text">
<string>Transparency</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QSlider" name="CutTransparency">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>0 %</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="RefreshCutPB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Refreshes the list of visible objects</string>
</property>
<property name="text">
<string>Refresh view</string>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="keepOnlyCutCB">
<property name="toolTip">
<string>When the dialog is closed,
only created cuts will be visible</string>
</property>
<property name="text">
<string>Keep only cuts visible when closing</string>
</property>
</widget>
</item>
<item row="6" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::ColorButton</class>
<extends>QPushButton</extends>
<header>Gui/Widgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefColorButton</class>
<extends>Gui::ColorButton</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>groupBoxX</tabstop>
<tabstop>cutX</tabstop>
@@ -327,5 +460,37 @@ only created cuts will be visible</string>
</hint>
</hints>
</connection>
<connection>
<sender>AutoCutfaceColor</sender>
<signal>toggled(bool)</signal>
<receiver>CutTransparency</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>182</x>
<y>311</y>
</hint>
<hint type="destinationlabel">
<x>150</x>
<y>338</y>
</hint>
</hints>
</connection>
<connection>
<sender>AutoCutfaceColor</sender>
<signal>toggled(bool)</signal>
<receiver>CutColor</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>182</x>
<y>311</y>
</hint>
<hint type="destinationlabel">
<x>119</x>
<y>311</y>
</hint>
</hints>
</connection>
</connections>
</ui>