Salome HOME
Issue #143 Focus on "selector" widget allows to select another feature to apply the...
[modules/shaper.git] / src / PartSet / PartSet_OperationFeatureEdit.cpp
index 32f0a86e2f2de97dd6fc01cbb00c7a1e8ee3657d..2036d55760d69e3bf540dd47eef848aafea8f1a8 100644 (file)
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetEditor.h>
 #include <ModuleBase_ViewerPrs.h>
-#include <ModuleBase_Tools.h>
 
 #include <ModelAPI_Events.h>
 
 #include <SketchPlugin_Feature.h>
 #include <GeomDataAPI_Point2D.h>
+
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
-
 #include <ModelAPI_Events.h>
 
 #include <Events_Loop.h>
 using namespace std;
 
 PartSet_OperationFeatureEdit::PartSet_OperationFeatureEdit(const QString& theId,
-                                                 QObject* theParent,
-                                              FeaturePtr theFeature)
-: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false)
+                                                           QObject* theParent,
+                                                           FeaturePtr theFeature)
+    : PartSet_OperationFeatureBase(theId, theParent, theFeature),
+      myIsBlockedSelection(false)
 {
 }
 
@@ -49,57 +49,45 @@ PartSet_OperationFeatureEdit::~PartSet_OperationFeatureEdit()
 {
 }
 
-bool PartSet_OperationFeatureEdit::isGranted(ModuleBase_IOperation* theOperation) const
-{
-  return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
-}
-
-std::list<int> PartSet_OperationFeatureEdit::getSelectionModes(ObjectPtr theFeature) const
-{
-  return PartSet_OperationSketchBase::getSelectionModes(theFeature);
-}
-
 void PartSet_OperationFeatureEdit::initFeature(FeaturePtr theFeature)
 {
   setEditingFeature(theFeature);
 }
 
-
-FeaturePtr PartSet_OperationFeatureEdit::sketch() const
-{
-  return mySketch;
-}
-
 void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                             const std::list<ModuleBase_ViewerPrs>& theSelected,
-                                             const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+                                                const std::list<ModuleBase_ViewerPrs>& theSelected,
+                                                const std::list<ModuleBase_ViewerPrs>& theHighlighted)
 {
+  if(myActiveWidget && myActiveWidget->isViewerSelector()) {
+    // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
+    PartSet_OperationFeatureBase::mousePressed(theEvent, theView, theSelected, theHighlighted);
+    return;
+  }
   ObjectPtr aObject;
   if (!theHighlighted.empty())
     aObject = theHighlighted.front().object();
-  if (!aObject && !theSelected.empty()) // changed for a constrain
+  if (!aObject && !theSelected.empty())  // changed for a constrain
     aObject = theSelected.front().object();
 
-  FeaturePtr aFeature = ModuleBase_Tools::feature(aObject);
+  FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
   if (!aFeature || aFeature != feature()) {
     if (commit()) {
       emit featureConstructed(feature(), FM_Deactivation);
 
       bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
-      if(aHasShift && !theHighlighted.empty()) {
+      if (aHasShift && !theHighlighted.empty()) {
         QList<ObjectPtr> aSelected;
         std::list<ModuleBase_ViewerPrs>::const_iterator aIt;
         for (aIt = theSelected.cbegin(); aIt != theSelected.cend(); ++aIt)
           aSelected.append((*aIt).object());
         /*for (aIt = theHighlighted.cbegin(); aIt != theHighlighted.cend(); ++aIt) {
-          if (!aSelected.contains((*aIt).object()))
-            aSelected.append((*aIt).object());
-        }*/
+         if (!aSelected.contains((*aIt).object()))
+         aSelected.append((*aIt).object());
+         }*/
         //aSelected.push_back(feature());
         //aSelected.push_back(theHighlighted.front().object());
         emit setSelection(aSelected);
-      }
-      else if (aFeature) {
+      } else if (aFeature) {
         restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
       }
     }
@@ -108,7 +96,7 @@ void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3
 
 void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
 {
-  if (!(theEvent->buttons() &  Qt::LeftButton))
+  if (!(theEvent->buttons() & Qt::LeftButton))
     return;
 
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
@@ -124,8 +112,8 @@ void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_
     double aDeltaX = aX - aCurX;
     double aDeltaY = anY - aCurY;
 
-    boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
-                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
+    boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
+        SketchPlugin_Feature>(feature());
     aSketchFeature->move(aDeltaX, aDeltaY);
     static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
     ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent);
@@ -135,25 +123,34 @@ void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_
   myCurPoint.setPoint(aPoint);
 }
 
-void PartSet_OperationFeatureEdit::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                              const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
-                                              const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
+void PartSet_OperationFeatureEdit::mouseReleased(
+    QMouseEvent* theEvent, Handle(V3d_View) theView,
+    const std::list<ModuleBase_ViewerPrs>& theSelected,
+    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
 {
-  blockSelection(false);
+  if(myActiveWidget && myActiveWidget->isViewerSelector()) {
+    // Almost do nothing, all stuff in on PartSet_OperationFeatureBase::mouseReleased
+    PartSet_OperationFeatureBase::mouseReleased(theEvent, theView, theSelected, theHighlighted);
+  } else {
+    blockSelection(false);
+  }
 }
 
-void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                                    const std::list<ModuleBase_ViewerPrs>& theSelected,
-                                                    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
+void PartSet_OperationFeatureEdit::mouseDoubleClick(
+    QMouseEvent* theEvent, Handle_V3d_View theView,
+    const std::list<ModuleBase_ViewerPrs>& theSelected,
+    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
 {
   // TODO the functionality is important only for constraint feature. Should be moved in another place
   if (!theSelected.empty()) {
     ModuleBase_ViewerPrs aFeaturePrs = theSelected.front();
     if (!aFeaturePrs.owner().IsNull()) {
-      Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aFeaturePrs.owner());
+      Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(
+          aFeaturePrs.owner());
       if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
         bool isValid;
-        double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(), isValid);
+        double aValue = PartSet_Tools::featureValue(feature(), SketchPlugin_Constraint::VALUE(),
+                                                    isValid);
         if (isValid) {
           ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE());
           flushUpdated();
@@ -163,15 +160,6 @@ void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handl
   }
 }
 
-
-void PartSet_OperationFeatureEdit::keyReleased(const int theKey)
-{
-  if (theKey == Qt::Key_Return) {
-    commit();
-  } else 
-    PartSet_OperationSketchBase::keyReleased(theKey);
-}
-
 void PartSet_OperationFeatureEdit::startOperation()
 {
   PartSet_OperationSketchBase::startOperation();
@@ -199,8 +187,7 @@ void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isR
   if (isBlocked) {
     emit setSelection(QList<ObjectPtr>());
     emit stopSelection(aFeatureList, true);
-  }
-  else {
+  } else {
     emit stopSelection(aFeatureList, false);
     if (isRestoreSelection)
       emit setSelection(aFeatureList);