Salome HOME
Process property panel values change. This modification should be corrected: keyRelea...
[modules/shaper.git] / src / PartSet / PartSet_OperationSketchLine.cpp
index 36c969305b60f69ecbb67385904e4b44cd379514..ddd9bd7281857bdf1ab1d34ac2ebc7adb9e60068 100644 (file)
@@ -25,6 +25,7 @@
 #include <gp_Lin.hxx>
 
 #include <XGUI_ViewerPrs.h>
+#include <XGUI_Constants.h>
 
 #include <SketchPlugin_Line.h>
 
@@ -67,7 +68,8 @@ std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<
 }
 
 void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                       const std::list<XGUI_ViewerPrs>& /*thePresentations*/)
+                                       const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+                                       const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
 {
   if (!theFeature || theFeature->getKind() != "SketchLine")
     return;
@@ -82,7 +84,8 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::sketch() const
 }
 
 void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                                const std::list<XGUI_ViewerPrs>& theSelected)
+                                                const std::list<XGUI_ViewerPrs>& theSelected,
+                                                const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
 {
   double aX, anY;
 
@@ -142,13 +145,17 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3
     case SM_FirstPoint: {
       setLinePoint(feature(), aX, anY, LINE_ATTR_START);
       setLinePoint(feature(), aX, anY, LINE_ATTR_END);
-      myPointSelectionMode = SM_SecondPoint;
+      flushUpdated();
+
+      setPointSelectionMode(SM_SecondPoint);
     }
     break;
     case SM_SecondPoint: {
       setLinePoint(feature(), aX, anY, LINE_ATTR_END);
-      myPointSelectionMode = SM_DonePoint;
-    }
+      flushUpdated();
+
+      setPointSelectionMode(SM_DonePoint);
+   }
     break;
     default:
       break;
@@ -165,12 +172,16 @@ void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_V
       PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
       setLinePoint(feature(), aX, anY, LINE_ATTR_START);
       setLinePoint(feature(), aX, anY, LINE_ATTR_END);
+      flushUpdated();
+      emit focusActivated(LINE_ATTR_START);
     }
     break;
     case SM_SecondPoint:
     {
       gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
       setLinePoint(aPoint, theView, LINE_ATTR_END);
+      flushUpdated();
+      emit focusActivated(LINE_ATTR_END);
     }
     break;
     case SM_DonePoint:
@@ -184,10 +195,36 @@ void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_V
   }
 }
 
+void PartSet_OperationSketchLine::keyReleased(std::string theName, QKeyEvent* theEvent)
+{
+  int aKeyType = theEvent->key();
+  if (!theName.empty() && aKeyType == Qt::Key_Return) {
+    if (theName == LINE_ATTR_START) {
+      setPointSelectionMode(SM_SecondPoint, false);
+    }
+    else if (theName == LINE_ATTR_END) {
+      setPointSelectionMode(SM_DonePoint, false);
+    }
+  }
+  keyReleased(theEvent->key());
+}
+
 void PartSet_OperationSketchLine::keyReleased(const int theKey)
 {
   switch (theKey) {
     case Qt::Key_Return: {
+      if (myPointSelectionMode == SM_DonePoint)
+      {
+        commit();
+        emit featureConstructed(feature(), FM_Deactivation);
+        emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr<ModelAPI_Feature>());
+      }
+      //else
+      //  abort();
+      //emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr<ModelAPI_Feature>());
+    }
+    break;
+    case Qt::Key_Escape: {
       if (myPointSelectionMode == SM_DonePoint)
       {
         commit();
@@ -195,11 +232,8 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey)
       }
       else
         abort();
-      emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr<ModelAPI_Feature>());
     }
-    break;
     default:
-      PartSet_OperationSketchBase::keyReleased(theKey); 
     break;
   }
 }
@@ -207,13 +241,14 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey)
 void PartSet_OperationSketchLine::startOperation()
 {
   PartSet_OperationSketchBase::startOperation();
-  myPointSelectionMode = !myInitPoint ? SM_FirstPoint : SM_SecondPoint;
+  setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint);
+
   emit multiSelectionEnabled(false);
 }
 
 void PartSet_OperationSketchLine::abortOperation()
 {
-  emit featureConstructed(feature(), FM_Abort);
+  emit featureConstructed(feature(), FM_Hide);
   PartSet_OperationSketchBase::abortOperation();
 }
 
@@ -223,9 +258,9 @@ void PartSet_OperationSketchLine::stopOperation()
   emit multiSelectionEnabled(true);
 }
 
-boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature(const bool theFlushMessage)
 {
-  boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature();
+  boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature(false);
   if (sketch()) {
     boost::shared_ptr<SketchPlugin_Feature> aFeature = 
                            boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
@@ -243,6 +278,8 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
   }
 
   emit featureConstructed(aNewFeature, FM_Activation);
+  if (theFlushMessage)
+    flushCreated();
   return aNewFeature;
 }
 
@@ -360,3 +397,26 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint,
         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
   aPoint->setValue(aX, anY);
 }
+
+void PartSet_OperationSketchLine::setPointSelectionMode(const PointSelectionMode& theMode,
+                                                        const bool isToEmitSignal)
+{
+  myPointSelectionMode = theMode;
+  if (isToEmitSignal) {
+    std::string aName;
+    switch (theMode) {
+      case SM_FirstPoint:
+        aName = LINE_ATTR_START;
+        break;
+      case SM_SecondPoint:
+        aName = LINE_ATTR_END;
+        break;
+      case SM_DonePoint:
+        aName = XGUI::PROP_PANEL_OK;
+        break;
+      default:
+        break;
+    }
+    emit focusActivated(aName);
+  }
+}