Salome HOME
Restore old planes selection definition
[modules/shaper.git] / src / PartSet / PartSet_OperationFeatureEdit.cpp
index d87a1b5b58b313ac9e3fbf647e7e93fd80ee803d..7975baa652d223a39a1765023498965bc8b29277 100644 (file)
 
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetEditor.h>
-#include <Model_Events.h>
+#include <ModuleBase_ViewerPrs.h>
 
-#include <XGUI_ViewerPrs.h>
+#include <ModelAPI_Events.h>
 
 #include <SketchPlugin_Feature.h>
 #include <GeomDataAPI_Point2D.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 
-#include <Model_Events.h>
+#include <ModelAPI_Events.h>
 
 #include <Events_Loop.h>
 
 #include <SketchPlugin_Line.h>
 
 #include <V3d_View.hxx>
+#include <AIS_DimensionOwner.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -51,43 +53,40 @@ bool PartSet_OperationFeatureEdit::isGranted(ModuleBase_IOperation* theOperation
   return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
 }
 
-std::list<int> PartSet_OperationFeatureEdit::getSelectionModes(FeaturePtr theFeature) const
+std::list<int> PartSet_OperationFeatureEdit::getSelectionModes(ObjectPtr theFeature) const
 {
   return PartSet_OperationSketchBase::getSelectionModes(theFeature);
 }
 
-void PartSet_OperationFeatureEdit::init(FeaturePtr theFeature,
-                                     const std::list<XGUI_ViewerPrs>& theSelected,
-                                     const std::list<XGUI_ViewerPrs>& theHighlighted)
+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<XGUI_ViewerPrs>& theSelected,
-                                             const std::list<XGUI_ViewerPrs>& theHighlighted)
+                                             const std::list<ModuleBase_ViewerPrs>& theSelected,
+                                             const std::list<ModuleBase_ViewerPrs>& theHighlighted)
 {
-  FeaturePtr aFeature;
+  ObjectPtr aFeature;
   if (!theHighlighted.empty())
-    aFeature = theHighlighted.front().feature();
+    aFeature = theHighlighted.front().object();
   if (!aFeature && !theSelected.empty()) // changed for a constrain
-    aFeature = theSelected.front().feature();
-
-  if (!aFeature || aFeature != feature())
-  {
+    aFeature = theSelected.front().object();
+  if (!aFeature || aFeature != feature()) {
     commit();
     emit featureConstructed(feature(), FM_Deactivation);
 
     bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
     if(aHasShift && !theHighlighted.empty()) {
-      QFeatureList aSelected;
+      QList<ObjectPtr> aSelected;
       aSelected.push_back(feature());
-      aSelected.push_back(theHighlighted.front().feature());
+      aSelected.push_back(theHighlighted.front().object());
       emit setSelection(aSelected);
     }
     else if (aFeature) {
@@ -124,25 +123,29 @@ void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_
 }
 
 void PartSet_OperationFeatureEdit::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                              const std::list<XGUI_ViewerPrs>& /*theSelected*/,
-                                              const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
+                                              const std::list<ModuleBase_ViewerPrs>& /*theSelected*/,
+                                              const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
 {
   blockSelection(false);
 }
 
 void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                                    const std::list<XGUI_ViewerPrs>& theSelected,
-                                                    const std::list<XGUI_ViewerPrs>& theHighlighted)
+                                                    const std::list<ModuleBase_ViewerPrs>& theSelected,
+                                                    const std::list<ModuleBase_ViewerPrs>& theHighlighted)
 {
-  // changed
+  // TODO the functionality is important only for constraint feature. Should be moved in another place
   if (!theSelected.empty()) {
-    bool isValid;
-    double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid);
-    if (isValid) {
-      ModuleBase_WidgetEditor::editFeatureValue(feature(), CONSTRAINT_ATTR_VALUE);
-
-      //QPoint aPos = theEvent->globalPos();
-      //myEditor->start(aPos, aValue);
+    ModuleBase_ViewerPrs aFeaturePrs = theSelected.front();
+    if (!aFeaturePrs.owner().IsNull()) {
+      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);
+        if (isValid) {
+          ModuleBase_WidgetEditor::editFeatureValue(feature(), SketchPlugin_Constraint::VALUE());
+          flushUpdated();
+        }
+      }
     }
   }
 }
@@ -168,11 +171,11 @@ void PartSet_OperationFeatureEdit::blockSelection(bool isBlocked, const bool isR
     return;
 
   myIsBlockedSelection = isBlocked;
-  QFeatureList aFeatureList;
+  QList<ObjectPtr> aFeatureList;
   aFeatureList.append(feature());
 
   if (isBlocked) {
-    emit setSelection(QFeatureList());
+    emit setSelection(QList<ObjectPtr>());
     emit stopSelection(aFeatureList, true);
   }
   else {
@@ -190,12 +193,10 @@ FeaturePtr PartSet_OperationFeatureEdit::createFeature(const bool /*theFlushMess
 
 void PartSet_OperationFeatureEdit::sendFeatures()
 {
-  static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
+  static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
 
   FeaturePtr aFeature = feature();
-
-  Model_FeatureUpdatedMessage aMessage(aFeature, anEvent);
-  Events_Loop::loop()->send(aMessage);
+  ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
 
   Events_Loop::loop()->flush(anEvent);
   flushUpdated();