diff --git a/src/Mod/Part/Gui/SectionCutting.cpp b/src/Mod/Part/Gui/SectionCutting.cpp index 121f08f294..b0400e3928 100644 --- a/src/Mod/Part/Gui/SectionCutting.cpp +++ b/src/Mod/Part/Gui/SectionCutting.cpp @@ -29,6 +29,7 @@ # include # include # include +# include #endif #include @@ -40,8 +41,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -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::Application::Instance->getViewProvider(pcBox)); + if (vpBox) { + cutColor = vpBox->ShapeColor.getValue(); + cutTransparency = vpBox->Transparency.getValue(); + ui->CutColor->setColor(cutColor.asValue()); + 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(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(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(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(CutCompound); + // store color and transparency of first object + App::Color cutColor; + int cutTransparency; + bool autoColor = true; + bool autoTransparency = true; + auto vpFirstObject = dynamic_cast( + 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::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()); + 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(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::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::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::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() { diff --git a/src/Mod/Part/Gui/SectionCutting.h b/src/Mod/Part/Gui/SectionCutting.h index 60247508b7..e121a818ea 100644 --- a/src/Mod/Part/Gui/SectionCutting.h +++ b/src/Mod/Part/Gui/SectionCutting.h @@ -56,6 +56,9 @@ protected Q_SLOTS: void onFlipYclicked(); void onFlipZclicked(); void onRefreshCutPBclicked(); + void onCutColorclicked(); + void onTransparencySliderMoved(int); + void onTransparencyChanged(int); public: void reject(); diff --git a/src/Mod/Part/Gui/SectionCutting.ui b/src/Mod/Part/Gui/SectionCutting.ui index 01dc1ca877..45996a05ed 100644 --- a/src/Mod/Part/Gui/SectionCutting.ui +++ b/src/Mod/Part/Gui/SectionCutting.ui @@ -6,8 +6,8 @@ 0 0 - 233 - 340 + 230 + 427 @@ -20,7 +20,7 @@ Permanent Section Cutting - + @@ -94,33 +94,7 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - true - - - Refreshes the list of visible objects - - - Refresh view - - - - + @@ -188,41 +162,7 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::Close - - - - - - - When the dialog is closed, -only created cuts will be visible - - - Keep only cuts visible when closing - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - + @@ -296,8 +236,201 @@ only created cuts will be visible + + + + Cut face + + + + + + + 0 + 0 + + + + Color of cut face + + + Color + + + + + + + false + + + + 50 + 20 + + + + + 16777215 + 16777215 + + + + + 204 + 204 + 204 + + + + DefaultShapeColor + + + View + + + + + + + + 0 + 0 + + + + If checked, the color and transpareny +will be taken from the cut objects. +Works only if all objects have the same values. + + + Auto + + + true + + + TwoSideRendering + + + Mod/Part + + + + + + + + 0 + 0 + + + + Transparency of cut face + + + Transparency + + + + + + + false + + + 0 % + + + 100 + + + Qt::Horizontal + + + + + + + + + + true + + + Refreshes the list of visible objects + + + Refresh view + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + When the dialog is closed, +only created cuts will be visible + + + Keep only cuts visible when closing + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + Gui::ColorButton + QPushButton +
Gui/Widgets.h
+
+ + Gui::PrefColorButton + Gui::ColorButton +
Gui/PrefWidgets.h
+
+ + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+
groupBoxX cutX @@ -327,5 +460,37 @@ only created cuts will be visible + + AutoCutfaceColor + toggled(bool) + CutTransparency + setDisabled(bool) + + + 182 + 311 + + + 150 + 338 + + + + + AutoCutfaceColor + toggled(bool) + CutColor + setDisabled(bool) + + + 182 + 311 + + + 119 + 311 + + +