Salome HOME
Provide preselection
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 28 Oct 2014 16:29:09 +0000 (19:29 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 28 Oct 2014 16:29:09 +0000 (19:29 +0300)
17 files changed:
src/ModuleBase/ModuleBase_IModule.cpp
src/ModuleBase/ModuleBase_IPropertyPanel.h
src/ModuleBase/ModuleBase_IWorkshop.h
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationFeatureEdit.cpp
src/PartSet/PartSet_OperationFeatureEditMulti.cpp
src/PartSet/PartSet_OperationFeatureEditMulti.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketchBase.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ModuleConnector.h
src/XGUI/XGUI_PropertyPanel.h
src/XGUI/XGUI_Workshop.cpp

index 773c84b5a32542459a3078a08108c60aa94a4c37..df2502fbbb4af73292b0b998b5d25cd7f405544a 100644 (file)
@@ -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<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-  QList<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
-  anOperation->initSelection(aSelected, aHighlighted);
+  anOperation->initSelection(aSelection);
   sendOperation(anOperation);
 }
 
index b43a3d42c1ec92ff548cf6b883220a8282ca4728..7f8d9d32d3c06e0a915adce51a348ed52db54e42 100644 (file)
@@ -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<ModuleBase_ModelWidget*>& modelWidgets() const = 0;
+
 signals:
   /// The signal about key release on the control, that corresponds to the attribute
   /// \param theEvent key release event
index d6d3c416b33aa6bce54ee4d12f0a456cb1e9a27b..12e9aef22040c91a4a762d8028dcb794291c48b7 100644 (file)
@@ -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<ObjectPtr>& theFeatures) = 0;
+
 signals:
   void selectionChanged();
 
index 763efbd161d369e79caa86a0615b41344f960db7..b4c4c01d131bffa5cb51716a8d03e5cc06c2631d 100644 (file)
@@ -12,6 +12,7 @@
 #include "ModuleBase_WidgetValueFeature.h"
 #include "ModuleBase_ViewerPrs.h"
 #include "ModuleBase_IPropertyPanel.h"
+#include "ModuleBase_ISelection.h"
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Document.h>
@@ -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<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
+  if (aWidgets.empty())
+    return false;
+  
+  ModuleBase_ModelWidget* aWgt;
+  ModuleBase_ViewerPrs aPrs;
+  QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+  QList<ModuleBase_ViewerPrs>::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<ModuleBase_ViewerPrs>& theSelected,
-    const QList<ModuleBase_ViewerPrs>& /*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);
index 0d1ea591e818e0a1e2358418457ef944582b7c4f..9608ecd9f2e165abe2995e28f215071fb2f592e2 100644 (file)
@@ -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<ModuleBase_ViewerPrs>& theSelected,
-                             const QList<ModuleBase_ViewerPrs>& 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<ModelAPI_Document> 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
index d3058ab2bf63bd86a83ad8898517260b10365a00..8f0252c8b50e9946416b66a7d149e2a7fd97ec1a 100644 (file)
@@ -310,9 +310,7 @@ void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject
     }
     ModuleBase_ISelection* aSelection = workshop()->selection();
     // Initialise operation with preliminary selection
-    QList<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
-    QList<ModuleBase_ViewerPrs> 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
index bc73304dd1c8b7f52307a63cc6f69e4884ee770d..f84466fe2e4261ff5f6613e2ac569d574659d31e 100644 (file)
@@ -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(
index 0e37baa770fb33885c1986c6fb803bb46f19dc0e..4b10858a0bc40ff31371022d816479a616c610e3 100644 (file)
@@ -9,6 +9,7 @@
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_ViewerPrs.h>
 #include <ModuleBase_IViewer.h>
+#include <ModuleBase_ISelection.h>
 
 #include <ModelAPI_Events.h>
 
@@ -57,9 +58,7 @@ bool isContains(const QList<ModuleBase_ViewerPrs>& theSelected, const ModuleBase
 }
 
 
-void PartSet_OperationFeatureEditMulti::initSelection(
-    const QList<ModuleBase_ViewerPrs>& theSelected,
-    const QList<ModuleBase_ViewerPrs>& 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<ModuleBase_ViewerPrs> 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()
index e0fe5da1cb80c6a519c1b645ba976fbbb116cfe5..77a9dbb5408916e6bc38c7300a677213d99f7801 100644 (file)
@@ -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<ModuleBase_ViewerPrs>& theSelected,
-                             const QList<ModuleBase_ViewerPrs>& 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
index 7bfddff3066104fa436db128714d63338039b724..804086bbebf98de4a1020c86233783a39bb8aad9 100644 (file)
@@ -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
index 3ca38de905f599dea7ca664c9dbbe945887cef1f..1f7550403123cabec03ac0a7ad79dacf3d6a482b 100644 (file)
@@ -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
-  }
-}
index 5de7b7330c594baff0265d480475b31dd8820583..ef3991a9a1710c0557e48c23b3f22d77d44c7830 100644 (file)
@@ -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
index dfbb75db58bb234acee173434b96204b9ab2ce9e..0bdf7633e70b7beec87742510e57237057f02272 100644 (file)
@@ -232,11 +232,8 @@ void XGUI_Displayer::setSelected(const QList<ObjectPtr>& 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<Handle(AIS_InteractiveObject)>();
       if (!anAIS.IsNull())
         aContext->SetSelected(anAIS, false);
index 5bb4445fe695490c00a5d2208e28fd17533224e6..6a3c81a9f35b5ccda61750026914f4970ff75231 100644 (file)
@@ -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<ObjectPtr>& theFeatures)
+{
+  XGUI_Displayer* aDisp = myWorkshop->displayer();
+  aDisp->setSelected(theFeatures);
 }
\ No newline at end of file
index f6d071f2ac375615cbca24a72b832d1d8e632a18..8a869f1d0db026bc03fafe78162c78df67dad92e 100644 (file)
@@ -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<ObjectPtr>& theFeatures);
+
   XGUI_Workshop* workshop() const { return myWorkshop; }
 
 private:
index ebd529d11056c439f61df3f0353d807501862ea7..04c4d1ed3c5521bfe40ab28368bc5de21968f906 100644 (file)
@@ -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<ModuleBase_ModelWidget*>& theWidgets);
+
   /// Returns all property panel's widget created by WidgetFactory
-  const QList<ModuleBase_ModelWidget*>& modelWidgets() const;
+  virtual const QList<ModuleBase_ModelWidget*>& modelWidgets() const;
+
   /// Removes all widgets in the widget area of the property panel
   void cleanContent();
 
index 6fd3bd0f3b02ab2d7175a6451fb563be63a8c845..b9c0de9a1f3150856087cf3491eecbfba16d6ca6 100644 (file)
@@ -513,10 +513,7 @@ void XGUI_Workshop::onOperationStarted()
     ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
 
     QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
-    QList<ModuleBase_ModelWidget*>::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)) {