From 840655e90a46754f2dd37aac6b888ec32eec69d3 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 3 Jul 2015 18:21:49 +0300 Subject: [PATCH] Shape plane filter should process shapes of objects selected in object browser. Provides the vidget validated by IWorkshop to use the filters of AIS context The goal is to ask context filters by preselection an in onSelectionChanged for presentations from OB only. --- src/ModuleBase/ModuleBase_ModelWidget.h | 5 +- src/ModuleBase/ModuleBase_Operation.cpp | 2 +- .../ModuleBase_WidgetMultiSelector.cpp | 11 ++-- .../ModuleBase_WidgetMultiSelector.h | 3 +- src/ModuleBase/ModuleBase_WidgetSelector.cpp | 36 ++----------- src/ModuleBase/ModuleBase_WidgetSelector.h | 3 -- src/ModuleBase/ModuleBase_WidgetValidated.cpp | 52 ++++++++++++++++--- src/ModuleBase/ModuleBase_WidgetValidated.h | 16 ++++-- src/PartSet/PartSet_Module.cpp | 3 +- src/PartSet/PartSet_WidgetMultiSelector.cpp | 5 +- src/PartSet/PartSet_WidgetMultiSelector.h | 3 +- src/PartSet/PartSet_WidgetPoint2d.cpp | 3 +- src/PartSet/PartSet_WidgetPoint2d.h | 3 +- src/PartSet/PartSet_WidgetSketchLabel.cpp | 47 ++++++++++------- src/PartSet/PartSet_WidgetSketchLabel.h | 18 +++---- 15 files changed, 119 insertions(+), 91 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index a237e6e29..4926a1e81 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -17,6 +17,7 @@ #include class Config_WidgetAPI; +class ModuleBase_IWorkshop; class QKeyEvent; /**\class ModuleBase_ModelWidget @@ -82,7 +83,9 @@ Q_OBJECT /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValues the wrapped selection values - virtual bool setSelection(QList& theValues) + /// \param toValidate the boolean value whether the value should be checked by filters + virtual bool setSelection(QList& theValues, + const bool theToValidate) { return false; } diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 58891e564..0cfb98630 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -288,7 +288,7 @@ void ModuleBase_Operation::activateByPreselection() if (!aWgt->canSetValue()) continue; - if (!aWgt->setSelection(myPreSelection)) { + if (!aWgt->setSelection(myPreSelection, true)) { isSet = false; break; } else { diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 946bfa116..9b0222ca5 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -201,7 +201,8 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) } //******************************************************************** -bool ModuleBase_WidgetMultiSelector::setSelection(QList& theValues) +bool ModuleBase_WidgetMultiSelector::setSelection(QList& theValues, + const bool theToValidate) { QList aSkippedValues; @@ -210,7 +211,7 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList& t for (; anIt != aLast; anIt++) { ModuleBase_ViewerPrs aValue = *anIt; bool aProcessed = false; - if (isValidSelection(aValue)) { + if (!theToValidate || isValidInFilters(aValue)) { aProcessed = setSelectionCustom(aValue); } else @@ -272,7 +273,7 @@ QList ModuleBase_WidgetMultiSelector::getControls() const void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() { activateSelection(true); - activateFilters(myWorkshop, true); + activateFilters(true); QList anEmptyList; // This method will call Selection changed event which will call onSelectionChanged // To clear mySelection, myListControl and storeValue() @@ -319,13 +320,13 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName); if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) { activateSelection(false); - activateFilters(myWorkshop, false); + activateFilters(false); bool isBlocked = myTypeCombo->blockSignals(true); myTypeCombo->setCurrentIndex(idx); myTypeCombo->blockSignals(isBlocked); activateSelection(true); - activateFilters(myWorkshop, true); + activateFilters(true); break; } } diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 921140887..2fed320e4 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -72,7 +72,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValues the wrapped selection values - virtual bool setSelection(QList& theValues); + virtual bool setSelection(QList& theValues, + const bool theToValidate); /// Checks the widget validity. By default, it returns true. /// \param theValue a selected presentation in the view diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index dcfb86bec..1b9df3d57 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -15,8 +15,7 @@ ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId) - : ModuleBase_WidgetValidated(theParent, theData, theParentId), - myWorkshop(theWorkshop) + : ModuleBase_WidgetValidated(theParent, theWorkshop, theData, theParentId) { } @@ -48,7 +47,7 @@ void ModuleBase_WidgetSelector::onSelectionChanged() QList aSelected = myWorkshop->selection()->getSelected( ModuleBase_ISelection::AllControls); - bool isDone = setSelection(aSelected); + bool isDone = setSelection(aSelected, true); emit valuesChanged(); // the updateObject method should be called to flush the updated sigal. The workshop listens it, @@ -138,13 +137,10 @@ void ModuleBase_WidgetSelector::activateCustom() // Restore selection in the viewer by the attribute selection list myWorkshop->setSelected(getAttributeSelection()); - activateFilters(myWorkshop, true); + activateFilters(true); } //******************************************************************** -#include -#include -#include bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs); @@ -157,30 +153,6 @@ bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPr FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult); aValid = aSelectedFeature != myFeature; } - - // selection happens in the Object browser. - // it creates a selection owner and check whether the viewer filters process it - if (thePrs.owner().IsNull() && thePrs.object().get()) { - ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); - if (aResult.get()) - aShape = aResult->shape(); - - const TopoDS_Shape aTDShape = aShape->impl(); - - Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs); - Handle(StdSelect_BRepOwner) aShapeOwner = new StdSelect_BRepOwner(aTDShape, anIO); - - const SelectMgr_ListOfFilter& aFilters = myWorkshop->viewer()->AISContext()->Filters(); - SelectMgr_ListIteratorOfListOfFilter anIt(aFilters); - for (; anIt.More() && aValid; anIt.Next()) { - Handle(SelectMgr_Filter) aFilter = anIt.Value(); - if (aFilter == myWorkshop->validatorFilter()) - continue; - - aValid = aFilter->IsOk(aShapeOwner); - } - aShapeOwner.Nullify(); - } return aValid; } @@ -200,5 +172,5 @@ void ModuleBase_WidgetSelector::deactivate() { disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); activateSelection(false); - activateFilters(myWorkshop, false); + activateFilters(false); } diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index dd853530e..2d3796f67 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -111,9 +111,6 @@ protected: GeomShapePtr& theShape); //----------- Class members ------------- -protected: - /// Reference to workshop - ModuleBase_IWorkshop* myWorkshop; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 889817706..94f837e92 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -12,6 +12,7 @@ #include #include +#include #include @@ -20,9 +21,11 @@ //#define DEBUG_VALID_STATE ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId) - : ModuleBase_ModelWidget(theParent, theData, theParentId), isValidateBlocked(false) +: ModuleBase_ModelWidget(theParent, theData, theParentId), isValidateBlocked(false), + myWorkshop(theWorkshop) { } @@ -31,7 +34,8 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated() } //******************************************************************** -bool ModuleBase_WidgetValidated::setSelection(QList& theValues) +bool ModuleBase_WidgetValidated::setSelection(QList& theValues, + const bool theToValidate) { if (theValues.empty()) return false; @@ -39,7 +43,7 @@ bool ModuleBase_WidgetValidated::setSelection(QList& theVa ModuleBase_ViewerPrs aValue = theValues.takeFirst(); bool isDone = false; - if (isValidSelection(aValue)) { + if (!theToValidate || isValidInFilters(aValue)) { isDone = setSelectionCustom(aValue); // updateObject - to update/redisplay feature // it is commented in order to perfom it outside the method @@ -50,6 +54,41 @@ bool ModuleBase_WidgetValidated::setSelection(QList& theVa return isDone; } +//******************************************************************** +bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrs& thePrs) +{ + bool aValid = true; + Handle(SelectMgr_EntityOwner) anOwner = thePrs.owner(); + + // if an owern is null, the selection happens in the Object browser. + // creates a selection owner on the base of object shape and the object AIS object + if (anOwner.IsNull() && thePrs.owner().IsNull() && thePrs.object().get()) { + ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); + if (aResult.get()) { + GeomShapePtr aShape = aResult->shape(); + + const TopoDS_Shape aTDShape = aShape->impl(); + Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs); + anOwner = new StdSelect_BRepOwner(aTDShape, anIO); + } + } + // finds + if (!anOwner.IsNull()) { + const SelectMgr_ListOfFilter& aFilters = myWorkshop->viewer()->AISContext()->Filters(); + SelectMgr_ListIteratorOfListOfFilter anIt(aFilters); + for (; anIt.More() && aValid; anIt.Next()) { + Handle(SelectMgr_Filter) aFilter = anIt.Value(); + //if (aFilter == myWorkshop->validatorFilter()) + // continue; + aValid = aFilter->IsOk(anOwner); + } + } + // removes created owner + if (!anOwner.IsNull() && anOwner != thePrs.owner()) + anOwner.Nullify(); + return aValid; +} + //******************************************************************** bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& theValue) { @@ -139,12 +178,11 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const return aValid; } -void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop, - const bool toActivate) +void ModuleBase_WidgetValidated::activateFilters(const bool toActivate) { - ModuleBase_IViewer* aViewer = theWorkshop->viewer(); + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); - Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter(); + Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter(); if (toActivate) aViewer->addSelectionFilter(aSelFilter); else { diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index f1caa0905..9861d4248 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -38,10 +38,17 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg /// \param theData the widget configuation. The attribute of the model widget is obtained from /// \param theParentId is Id of a parent of the current attribute ModuleBase_WidgetValidated(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId); virtual ~ModuleBase_WidgetValidated(); + /// Checks whether all active viewer filters validate the presentation + /// \param theWorkshop an active workshop + /// \param theValue a selected presentation in the view + /// \return a boolean value + bool isValidInFilters(const ModuleBase_ViewerPrs& thePrs); + /// Checks all widget validator if the owner is valid /// \param theValue a selected presentation in the view /// \return a boolean value @@ -52,8 +59,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg /// The method is called by the current operation to process the operation preselection. /// It is redefined to check the value validity and if it is, fill the attribute with by value /// \param theValues the wrapped selection values - virtual bool setSelection(QList& theValues); - + virtual bool setSelection(QList& theValues, + const bool theToValidate); protected: /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different @@ -82,7 +89,7 @@ protected: /// It obtains selection filters from the workshop and activates them in the active viewer /// \param theWorkshop an active workshop /// \param toActivate a flag about activation or deactivation the filters - virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate); + virtual void activateFilters(const bool toActivate); /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored /// \param theValue a viewer presentation @@ -97,6 +104,9 @@ protected: // Removes all presentations from internal maps. void clearValidState(); +protected: + ModuleBase_IWorkshop* myWorkshop; /// Reference to workshop + private: QList myValidPrs; QList myInvalidPrs; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e997f05cf..8ad7937e4 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -503,9 +503,8 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th XGUI_Workshop* aXUIWorkshop = aConnector->workshop(); ModuleBase_ModelWidget* aWgt = NULL; if (theType == "sketch-start-label") { - PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, + PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop, theWidgetApi, theParentId, mySketchMgr->isConstraintsShown()); - aLabelWgt->setWorkshop(aXUIWorkshop); connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr&)), mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr&))); connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)), diff --git a/src/PartSet/PartSet_WidgetMultiSelector.cpp b/src/PartSet/PartSet_WidgetMultiSelector.cpp index fbce745f6..00b126e9c 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.cpp +++ b/src/PartSet/PartSet_WidgetMultiSelector.cpp @@ -41,9 +41,10 @@ PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector() delete myExternalObjectMgr; } -bool PartSet_WidgetMultiSelector::setSelection(QList& theValues) +bool PartSet_WidgetMultiSelector::setSelection(QList& theValues, + const bool theToValidate) { - bool aSucceed = ModuleBase_WidgetMultiSelector::setSelection(theValues); + bool aSucceed = ModuleBase_WidgetMultiSelector::setSelection(theValues, theToValidate); if (aSucceed) { // TODO(nds): unite with externalObject(), remove parameters //myFeature->execute(); diff --git a/src/PartSet/PartSet_WidgetMultiSelector.h b/src/PartSet/PartSet_WidgetMultiSelector.h index 20fead7d5..e0479547e 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.h +++ b/src/PartSet/PartSet_WidgetMultiSelector.h @@ -49,7 +49,8 @@ Q_OBJECT /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValues the wrapped selection values - virtual bool setSelection(QList& theValues); + virtual bool setSelection(QList& theValues, + const bool theToValidate); protected: /// Checks the widget validity. By default, it returns true. diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index ab596837d..e48dc8b0e 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -122,7 +122,8 @@ PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D() { } -bool PartSet_WidgetPoint2D::setSelection(QList& theValues) +bool PartSet_WidgetPoint2D::setSelection(QList& theValues, + const bool theToValidate) { if (theValues.empty()) return false; diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 6e9ba6003..d42bd44fb 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -56,7 +56,8 @@ Q_OBJECT /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValues the wrapped widget values - virtual bool setSelection(QList& theValues); + virtual bool setSelection(QList& theValues, + const bool theToValidate); virtual bool restoreValue(); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index d0de6fb94..e9e43ba5a 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -52,12 +52,12 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId, bool toShowConstraints) - : ModuleBase_WidgetValidated(theParent, theData, theParentId), - myPreviewDisplayed(false), - myWorkshop(NULL) +: ModuleBase_WidgetValidated(theParent, theWorkshop, theData, theParentId), + myPreviewDisplayed(false) { myText = QString::fromStdString(theData->getProperty("title")); myLabel = new QLabel("", theParent); @@ -83,7 +83,8 @@ PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel() erasePreviewPlanes(); } -bool PartSet_WidgetSketchLabel::setSelection(QList& theValues) +bool PartSet_WidgetSketchLabel::setSelection(QList& theValues, + const bool theToValidate) { // do not use the given selection if the plane of the sketch has been already set. // If this check is absent, a selected plane in the viewer can be set in the sketch @@ -91,7 +92,7 @@ bool PartSet_WidgetSketchLabel::setSelection(QList& theVal if (plane().get()) return true; - return ModuleBase_WidgetValidated::setSelection(theValues); + return ModuleBase_WidgetValidated::setSelection(theValues, theToValidate); } QList PartSet_WidgetSketchLabel::getControls() const @@ -103,13 +104,13 @@ QList PartSet_WidgetSketchLabel::getControls() const void PartSet_WidgetSketchLabel::onSelectionChanged() { - QList aSelected = myWorkshop->selector()->selection()->getSelected( + QList aSelected = myWorkshop->selection()->getSelected( ModuleBase_ISelection::AllControls); if (aSelected.empty()) return; ModuleBase_ViewerPrs aPrs = aSelected.first(); - bool isDone = ModuleBase_WidgetValidated::setSelection(aSelected); + bool isDone = ModuleBase_WidgetValidated::setSelection(aSelected, true); if (!isDone) return; @@ -164,13 +165,13 @@ void PartSet_WidgetSketchLabel::onSelectionChanged() // 5. Clear text in the label myLabel->setText(""); myLabel->setToolTip(""); - disconnect(myWorkshop->selector(), SIGNAL(selectionChanged()), + disconnect(workshop()->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); // 6. deactivate face selection filter - activateFilters(myWorkshop->module()->workshop(), false); + activateFilters(false); // 7. Clear selection mode and define sketching mode - //XGUI_Displayer* aDisp = myWorkshop->displayer(); + //XGUI_Displayer* aDisp = workshop()->displayer(); //aDisp->closeLocalContexts(); emit planeSelected(plane()); // after the plane is selected in the sketch, the sketch selection should be activated @@ -179,7 +180,7 @@ void PartSet_WidgetSketchLabel::onSelectionChanged() activateSelection(true); // 8. Update sketcher actions - XGUI_ActionsMgr* anActMgr = myWorkshop->actionsMgr(); + XGUI_ActionsMgr* anActMgr = workshop()->actionsMgr(); anActMgr->update(); myWorkshop->viewer()->update(); } @@ -264,7 +265,7 @@ void PartSet_WidgetSketchLabel::activateCustom() } bool aBodyIsVisualized = false; - XGUI_Displayer* aDisp = myWorkshop->displayer(); + XGUI_Displayer* aDisp = workshop()->displayer(); QObjectPtrList aDisplayed = aDisp->displayedObjects(); foreach (ObjectPtr anObj, aDisplayed) { ResultPtr aResult = std::dynamic_pointer_cast(anObj); @@ -284,8 +285,8 @@ void PartSet_WidgetSketchLabel::activateCustom() myLabel->setText(myText); myLabel->setToolTip(myTooltip); - connect(myWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - activateFilters(myWorkshop->module()->workshop(), true); + connect(workshop()->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + activateFilters(true); aDisp->updateViewer(); } @@ -295,7 +296,7 @@ void PartSet_WidgetSketchLabel::deactivate() erasePreviewPlanes(); activateSelection(false); - activateFilters(myWorkshop->module()->workshop(), false); + activateFilters(false); } void PartSet_WidgetSketchLabel::activateSelection(bool toActivate) @@ -304,21 +305,21 @@ void PartSet_WidgetSketchLabel::activateSelection(bool toActivate) QIntList aModes; std::shared_ptr aPlane = plane(); if (aPlane.get()) { - myWorkshop->moduleConnector()->module()->activeSelectionModes(aModes); + myWorkshop->module()->activeSelectionModes(aModes); } else { aModes << TopAbs_FACE; } - myWorkshop->moduleConnector()->activateSubShapesSelection(aModes); + myWorkshop->activateSubShapesSelection(aModes); } else { - myWorkshop->moduleConnector()->deactivateSubShapesSelection(); + myWorkshop->deactivateSubShapesSelection(); } } void PartSet_WidgetSketchLabel::erasePreviewPlanes() { if (myPreviewDisplayed) { - XGUI_Displayer* aDisp = myWorkshop->displayer(); + XGUI_Displayer* aDisp = workshop()->displayer(); aDisp->eraseAIS(myYZPlane, false); aDisp->eraseAIS(myXZPlane, false); aDisp->eraseAIS(myXYPlane, false); @@ -353,7 +354,7 @@ void PartSet_WidgetSketchLabel::showPreviewPlanes() myXZPlane = createPreviewPlane(anOrigin, aXZDir, aG); myXYPlane = createPreviewPlane(anOrigin, aXYDir, aB); } - XGUI_Displayer* aDisp = myWorkshop->displayer(); + XGUI_Displayer* aDisp = workshop()->displayer(); aDisp->displayAIS(myYZPlane, false); aDisp->displayAIS(myXZPlane, false); aDisp->displayAIS(myXYPlane, false); @@ -426,3 +427,9 @@ void PartSet_WidgetSketchLabel::showConstraints(bool theOn) myShowConstraints->setChecked(theOn); emit showConstraintToggled(theOn); } + +XGUI_Workshop* PartSet_WidgetSketchLabel::workshop() const +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + return aConnector->workshop(); +} diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 4074ad53d..3eddeb2d2 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -42,7 +42,8 @@ Q_OBJECT /// \param theParent the parent object /// \param theData the widget configuation. The attribute of the model widget is obtained from /// \param theParentId is Id of a parent of the current attribute - PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData, + PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, const std::string& theParentId, bool toShowConstraints); virtual ~PartSet_WidgetSketchLabel(); @@ -52,7 +53,8 @@ Q_OBJECT /// The method is called by the current operation to process the operation preselection. /// It is redefined to do nothing if the plane of the sketch has been already set. /// \param theValues the wrapped selection values - virtual bool setSelection(QList& theValues); + virtual bool setSelection(QList& theValues, + const bool theToValidate); virtual bool restoreValue() { @@ -66,13 +68,6 @@ Q_OBJECT /// The methiod called when widget is deactivated virtual void deactivate(); - /// Returns pointer to workshop - XGUI_Workshop* workshop() const { return myWorkshop; } - - /// Set pointer to workshop - /// \param theWork a pointer to workshop - void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; } - /// Returns sketcher plane std::shared_ptr plane() const; @@ -132,6 +127,9 @@ protected: std::shared_ptr theNorm, const int theRGB[3]); + //! Returns workshop + XGUI_Workshop* workshop() const; + /// Set sketch plane by shape /// \param theShape a planar face std::shared_ptr setSketchPlane(const TopoDS_Shape& theShape); @@ -147,8 +145,6 @@ protected: QString myText; QString myTooltip; - XGUI_Workshop* myWorkshop; - AISObjectPtr myYZPlane; AISObjectPtr myXZPlane; AISObjectPtr myXYPlane; -- 2.30.2