From: vsv Date: Tue, 28 Oct 2014 16:29:09 +0000 (+0300) Subject: Provide preselection X-Git-Tag: V_0.5~66^2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a226d633772b2f4c5e327b7451147912e4f84efb;p=modules%2Fshaper.git Provide preselection --- diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 773c84b5a..df2502fbb 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -34,9 +34,7 @@ void ModuleBase_IModule::launchOperation(const QString& theCmdId) ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString()); ModuleBase_ISelection* aSelection = myWorkshop->selection(); // Initialise operation with preliminary selection - QList aSelected = aSelection->getSelected(); - QList aHighlighted = aSelection->getHighlighted(); - anOperation->initSelection(aSelected, aHighlighted); + anOperation->initSelection(aSelection); sendOperation(anOperation); } diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.h b/src/ModuleBase/ModuleBase_IPropertyPanel.h index b43a3d42c..7f8d9d32d 100644 --- a/src/ModuleBase/ModuleBase_IPropertyPanel.h +++ b/src/ModuleBase/ModuleBase_IPropertyPanel.h @@ -24,6 +24,9 @@ public: /// Returns currently active widget virtual ModuleBase_ModelWidget* activeWidget() const = 0; + /// Returns all property panel's widget created by WidgetFactory + virtual const QList& modelWidgets() const = 0; + signals: /// The signal about key release on the control, that corresponds to the attribute /// \param theEvent key release event diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index d6d3c416b..12e9aef22 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -56,6 +56,10 @@ Q_OBJECT //! Returns data object by AIS virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0; + //! Select features clearing previous selection. + //! If the list is empty then selection will be cleared + virtual void setSelected(const QList& theFeatures) = 0; + signals: void selectionChanged(); diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 763efbd16..b4c4c01d1 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -12,6 +12,7 @@ #include "ModuleBase_WidgetValueFeature.h" #include "ModuleBase_ViewerPrs.h" #include "ModuleBase_IPropertyPanel.h" +#include "ModuleBase_ISelection.h" #include #include @@ -232,33 +233,58 @@ void ModuleBase_Operation::setRunning(bool theState) } } -void ModuleBase_Operation::activateByPreselection() +bool ModuleBase_Operation::activateByPreselection() { if (!myPropertyPanel) - return; - ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); - if ((myPreSelection.size() > 0) && aActiveWgt) { - const ModuleBase_ViewerPrs& aPrs = myPreSelection.first(); + return false; + if (myPreSelection.empty()) + return false; + const QList& aWidgets = myPropertyPanel->modelWidgets(); + if (aWidgets.empty()) + return false; + + ModuleBase_ModelWidget* aWgt; + ModuleBase_ViewerPrs aPrs; + QList::const_iterator aWIt; + QList::const_iterator aPIt; + for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin(); + (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd()); + ++aWIt, ++aPIt) { + aWgt = (*aWIt); + aPrs = (*aPIt); ModuleBase_WidgetValueFeature aValue; aValue.setObject(aPrs.object()); - if (aActiveWgt->setValue(&aValue)) { - myPreSelection.removeOne(aPrs); - myPropertyPanel->activateNextWidget(); - } - // If preselection is enough to make a valid feature - apply it immediately + if (!aWgt->setValue(&aValue)) + break; } + if (canBeCommitted()) { + // if all widgets are filled with selection + commit(); + return true; + } + + //ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + //if ((myPreSelection.size() > 0) && aActiveWgt) { + // const ModuleBase_ViewerPrs& aPrs = myPreSelection.first(); + // ModuleBase_WidgetValueFeature aValue; + // aValue.setObject(aPrs.object()); + // if (aActiveWgt->setValue(&aValue)) { + // myPreSelection.removeOne(aPrs); + // myPropertyPanel->activateNextWidget(); + // } + // // If preselection is enough to make a valid feature - apply it immediately + //} + return false; } -void ModuleBase_Operation::initSelection( - const QList& theSelected, - const QList& /*theHighlighted*/) +void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection) { - myPreSelection = theSelected; + myPreSelection = theSelection->getSelected(); } void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget) { - activateByPreselection(); + //activateByPreselection(); //if (theWidget && myPropertyPanel) { // myPropertyPanel->activateNextWidget(); //// //emit activateNextWidget(myActiveWidget); diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 0d1ea591e..9608ecd9f 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -22,6 +22,7 @@ class ModuleBase_ModelWidget; class ModuleBase_OperationDescription; class ModuleBase_IPropertyPanel; +class ModuleBase_ISelection; class QKeyEvent; @@ -117,13 +118,15 @@ Q_OBJECT /// Initialisation of operation with preliminary selection /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations - virtual void initSelection(const QList& theSelected, - const QList& theHighlighted); + virtual void initSelection(ModuleBase_ISelection* theSelection); virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp); ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; } + /// Activates widgets by preselection if it is accepted + virtual bool activateByPreselection(); + signals: void started(); /// the operation is started void aborted(); /// the operation is aborted @@ -205,9 +208,6 @@ signals: /// Returns pointer to the root document. boost::shared_ptr document() const; - /// Activates widgets by preselection if it is accepted - virtual void activateByPreselection(); - /// Set value to the active widget /// \param theFeature the feature /// \param theX the horizontal coordinate diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index d3058ab2b..8f0252c8b 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -310,9 +310,7 @@ void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject } ModuleBase_ISelection* aSelection = workshop()->selection(); // Initialise operation with preliminary selection - QList aSelected = aSelection->getSelected(); - QList aHighlighted = aSelection->getHighlighted(); - aSketchOp->initSelection(aSelected, aHighlighted); + aSketchOp->initSelection(aSelection); } //else if (aFeature) { //anOperation->setFeature(aFeature); ////Deactivate result of current feature in order to avoid its selection diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index bc73304dd..f84466fe2 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -86,6 +86,7 @@ void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, ModuleBas FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); if (!aFeature || aFeature != feature() || (aSelected.size() > 1)) { if (commit()) { + theViewer->enableSelection(true); emit featureConstructed(feature(), FM_Deactivation); // If we have selection and prehilighting with shift pressed @@ -111,7 +112,7 @@ void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, ModuleBas } //} } - } + } } void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer) @@ -121,8 +122,7 @@ void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, ModuleBase_ Handle(V3d_View) aView = theViewer->activeView(); gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); - if (theViewer->isSelectionEnabled()) - theViewer->enableSelection(false); + theViewer->enableSelection(false); //blockSelection(true); if (myCurPoint.myIsInitialized) { @@ -153,6 +153,7 @@ void PartSet_OperationFeatureEdit::mouseReleased( QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection) { + theViewer->enableSelection(true); ModuleBase_ModelWidget* aActiveWgt = 0; if (myPropertyPanel) aActiveWgt = myPropertyPanel->activeWidget(); @@ -162,8 +163,6 @@ void PartSet_OperationFeatureEdit::mouseReleased( }// else { //blockSelection(false); //} - if (!theViewer->isSelectionEnabled()) - theViewer->enableSelection(true); } void PartSet_OperationFeatureEdit::mouseDoubleClick( diff --git a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp index 0e37baa77..4b10858a0 100644 --- a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp +++ b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -57,9 +58,7 @@ bool isContains(const QList& theSelected, const ModuleBase } -void PartSet_OperationFeatureEditMulti::initSelection( - const QList& theSelected, - const QList& theHighlighted) +void PartSet_OperationFeatureEditMulti::initSelection(ModuleBase_ISelection* theSelection) { //if (!theHighlighted.empty()) { // // if there is highlighted object, we check whether it is in the list of selected objects @@ -77,9 +76,10 @@ void PartSet_OperationFeatureEditMulti::initSelection( // else // myFeatures = theSelected; //} else - myFeatures = theSelected; + myFeatures = theSelection->getSelected(); + QList aHighlighted = theSelection->getHighlighted(); // add highlighted elements if they are not selected - foreach (ModuleBase_ViewerPrs aPrs, theHighlighted) { + foreach (ModuleBase_ViewerPrs aPrs, aHighlighted) { if (!isContains(myFeatures, aPrs)) myFeatures.append(aPrs); } @@ -98,21 +98,21 @@ CompositeFeaturePtr PartSet_OperationFeatureEditMulti::sketch() const return mySketch; } -void PartSet_OperationFeatureEditMulti::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection) -{ -} +//void PartSet_OperationFeatureEditMulti::mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection) +//{ +//} void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer) { if (!(theEvent->buttons() & Qt::LeftButton)) return; - Handle(V3d_View) aView = theViewer->activeView(); - gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); - if (theViewer->isSelectionEnabled()) theViewer->enableSelection(false); + Handle(V3d_View) aView = theViewer->activeView(); + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView); + //blockSelection(true); if (myCurPoint.myIsInitialized) { double aCurX, aCurY; @@ -149,6 +149,7 @@ void PartSet_OperationFeatureEditMulti::mouseReleased( QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection) { + theViewer->enableSelection(true); if (commit()) { foreach (ModuleBase_ViewerPrs aPrs, myFeatures) { ObjectPtr aFeature = aPrs.object(); @@ -157,8 +158,6 @@ void PartSet_OperationFeatureEditMulti::mouseReleased( } } } - if (!theViewer->isSelectionEnabled()) - theViewer->enableSelection(true); } void PartSet_OperationFeatureEditMulti::startOperation() diff --git a/src/PartSet/PartSet_OperationFeatureEditMulti.h b/src/PartSet/PartSet_OperationFeatureEditMulti.h index e0fe5da1c..77a9dbb54 100644 --- a/src/PartSet/PartSet_OperationFeatureEditMulti.h +++ b/src/PartSet/PartSet_OperationFeatureEditMulti.h @@ -76,8 +76,7 @@ Q_OBJECT /// Initialisation of operation with preliminary selection /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations - virtual void initSelection(const QList& theSelected, - const QList& theHighlighted); + virtual void initSelection(ModuleBase_ISelection* theSelection); /// Returns the operation sketch feature /// \returns the sketch instance @@ -88,7 +87,7 @@ Q_OBJECT /// \param theView a viewer to have the viewer the eye position /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations - virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection); + //virtual void mousePressed(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection); /// Gives the current mouse point in the viewer /// \param theEvent the mouse event diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 7bfddff30..804086bbe 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -76,7 +76,6 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, ModuleBase_IVi std::string anOperationType = (aSelected.size() > 1) ? PartSet_OperationFeatureEditMulti::Type() : PartSet_OperationFeatureEdit::Type(); - //theViewer->enableSelection(false); restartOperation(anOperationType, aFeature); } } //else diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 3ca38de90..1f7550403 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -96,26 +96,3 @@ void PartSet_OperationSketchBase::restartOperation(const std::string& theType, O } - -void PartSet_OperationSketchBase::activateByPreselection() -{ - if (!myPropertyPanel) - return; - ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); - if ((myPreSelection.size() > 0) && aActiveWgt) { - const ModuleBase_ViewerPrs& aPrs = myPreSelection.first(); - ModuleBase_WidgetValueFeature aValue; - aValue.setObject(aPrs.object()); - if (aActiveWgt->setValue(&aValue)) { - myPreSelection.removeOne(aPrs); - if(isValid()) { - //myActiveWidget = NULL; - commit(); - } else { - myPropertyPanel->activateNextWidget(); - //emit activateNextWidget(myActiveWidget); - } - } - // If preselection is enough to make a valid feature - apply it immediately - } -} diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 5de7b7330..ef3991a9a 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -143,9 +143,6 @@ signals: /// \param theFlushMessage the flag whether the create message should be flushed /// \returns the created feature virtual FeaturePtr createFeature(const bool theFlushMessage = true); - - /// Activates widgets by preselection if it is accepted - virtual void activateByPreselection(); }; #endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index dfbb75db5..0bdf7633e 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -232,11 +232,8 @@ void XGUI_Displayer::setSelected(const QList& theResults, const bool aContext->ClearSelected(); foreach(ObjectPtr aResult, theResults) { - if (myResult2AISObjectMap.find(aResult) == myResult2AISObjectMap.end()) - continue; - - AISObjectPtr anObj = myResult2AISObjectMap[aResult]; - if (anObj) { + if (isVisible(aResult)) { + AISObjectPtr anObj = myResult2AISObjectMap[aResult]; Handle(AIS_InteractiveObject) anAIS = anObj->impl(); if (!anAIS.IsNull()) aContext->SetSelected(anAIS, false); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 5bb4445fe..6a3c81a9f 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -88,4 +88,10 @@ ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) { XGUI_Displayer* aDisp = myWorkshop->displayer(); return aDisp->getObject(theAIS); +} + +void XGUI_ModuleConnector::setSelected(const QList& theFeatures) +{ + XGUI_Displayer* aDisp = myWorkshop->displayer(); + aDisp->setSelected(theFeatures); } \ No newline at end of file diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h index f6d071f2a..8a869f1d0 100644 --- a/src/XGUI/XGUI_ModuleConnector.h +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -50,6 +50,10 @@ Q_OBJECT //! Returns data object by AIS virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const; + //! Select features clearing previous selection. + //! If the list is empty then selection will be cleared + virtual void setSelected(const QList& theFeatures); + XGUI_Workshop* workshop() const { return myWorkshop; } private: diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index ebd529d11..04c4d1ed3 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -28,11 +28,14 @@ Q_OBJECT /// Returns main widget of the property panel, which children will be created /// by WidgetFactory using the XML definition QWidget* contentWidget(); + /// Brings back all widget created by widget factory for signal/slot /// connections and further processing void setModelWidgets(const QList& theWidgets); + /// Returns all property panel's widget created by WidgetFactory - const QList& modelWidgets() const; + virtual const QList& modelWidgets() const; + /// Removes all widgets in the widget area of the property panel void cleanContent(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 6fd3bd0f3..b9c0de9a1 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -513,10 +513,7 @@ void XGUI_Workshop::onOperationStarted() ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget()); QList aWidgets = aFactory.getModelWidgets(); - QList::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end(); - ModuleBase_ModelWidget* aWidget; - for (; anIt != aLast; anIt++) { - aWidget = *anIt; + foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { aWidget->setFeature(aOperation->feature()); aWidget->enableFocusProcessing(); QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged())); @@ -528,7 +525,8 @@ void XGUI_Workshop::onOperationStarted() aOperation->setPropertyPanel(myPropertyPanel); myPropertyPanel->setModelWidgets(aWidgets); - myPropertyPanel->activateNextWidget(NULL); + if (!aOperation->activateByPreselection()) + myPropertyPanel->activateNextWidget(NULL); // Widget activation (from the previous method) may commit the current operation // if pre-selection is enougth for it. So we shouldn't update prop panel's title if(myOperationMgr->isCurrentOperation(aOperation)) {