Salome HOME
Architecture changes
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.cpp
index ff37f046271aef492cc0f8be9901ee4c67390c9a..eddf4b07eb0afb9e2f5d3048ec5bdc18b566b272 100755 (executable)
@@ -11,6 +11,7 @@
 #include "PartSet_WidgetPoint2dDistance.h"
 #include "PartSet_Tools.h"
 #include "PartSet_WidgetSketchLabel.h"
+#include "PartSet_WidgetEditor.h"
 
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Displayer.h>
 
 #include <QMouseEvent>
 #include <QApplication>
+#include <QCursor>
 
 //#define DEBUG_DO_NOT_BY_ENTER
 
+//#define DEBUG_CURSOR
+
 /// Returns list of unique objects by sum of objects from List1 and List2
 /*QList<ModuleBase_ViewerPrs> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
                                        const QList<ModuleBase_ViewerPrs>& theList2)
@@ -196,11 +200,19 @@ void PartSet_SketcherMgr::onEnterViewPort()
   return;
   #endif
 
+  if (canChangeCursor(getCurrentOperation())) {
+    QCursor* aCurrentCursor = QApplication::overrideCursor();
+    if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
+      QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
+#ifdef DEBUG_CURSOR
+      qDebug("onEnterViewPort() : Qt::CrossCursor");
+#endif
+    }
+  }
+
   if (!isNestedCreateOperation(getCurrentOperation()))
     return;
 
-  QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
-
   operationMgr()->onValidateOperation();
 
   // we need change displayed state of the current operation feature
@@ -231,11 +243,16 @@ void PartSet_SketcherMgr::onLeaveViewPort()
   return;
   #endif
 
+  if (canChangeCursor(getCurrentOperation())) {
+    QApplication::restoreOverrideCursor();
+#ifdef DEBUG_CURSOR
+    qDebug("onLeaveViewPort() : None");
+#endif
+  }
+
   if (!isNestedCreateOperation(getCurrentOperation()))
     return;
 
-  QApplication::restoreOverrideCursor();
-
   // the method should be performed if the popup menu is called,
   // the reset of the current widget should not happen
   if (myIsPopupMenuActive)
@@ -253,7 +270,6 @@ void PartSet_SketcherMgr::onLeaveViewPort()
   ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
   if (anActiveWidget)
     anActiveWidget->reset();
-  aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
 
   // hides the presentation of the current operation feature
   // the feature is to be erased here, but it is correct to call canDisplayObject because
@@ -264,11 +280,15 @@ void PartSet_SketcherMgr::onLeaveViewPort()
     FeaturePtr aFeature = aFOperation->feature();
     visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
   }
+  // we should update viewer after the presentation are hidden in the viewer
+  // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
+  aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
 }
 
 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
 {
-  if (isNestedCreateOperation(getCurrentOperation()))
+  if (!isNestedEditOperation(getCurrentOperation()) ||
+      myModule->sketchReentranceMgr()->isInternalEditActive())
     return;
   // it is necessary to save current selection in order to restore it after the values are modifed
   storeSelection();
@@ -281,7 +301,8 @@ void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
 
 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
 {
-  if (isNestedCreateOperation(getCurrentOperation()))
+  if (!isNestedEditOperation(getCurrentOperation()) ||
+      myModule->sketchReentranceMgr()->isInternalEditActive())
     return;
   // it is necessary to restore current selection in order to restore it after the values are modified
   restoreSelection();
@@ -299,14 +320,14 @@ void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
 
 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
+    return;
+
   get2dPoint(theWnd, theEvent, myClickedPoint);
 
   if (!(theEvent->buttons() & Qt::LeftButton))
     return;
 
-  if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
-    return;
-
   // Clear dragging mode
   myIsDragging = false;
 
@@ -579,7 +600,9 @@ void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMo
       // Find corresponded widget to activate value editing
       foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
         if (aWgt->attributeID() == "ConstraintValue") {
-          aWgt->focusTo();
+          PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
+          if (anEditor)
+            anEditor->showPopupEditor();
           return;
         }
       }
@@ -675,7 +698,7 @@ bool PartSet_SketcherMgr::sketchSolverError()
   return anError;
 }
 
-QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI)
+QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
 {
   QString anError = "";
   if (!theFeature.get() || !theFeature->data()->isValid())
@@ -686,34 +709,16 @@ QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature, const
     AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
     anError = aAttributeString->value().c_str();
   }
-  else {
-    ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
-    if (isCheckGUI && anActiveWidget) {
-      ModuleBase_ModelWidget::ValueState aState = anActiveWidget->getValueState();
-      if (aState != ModuleBase_ModelWidget::Stored) {
-        AttributePtr anAttr = anActiveWidget->feature()->attribute(anActiveWidget->attributeID());
-        if (anAttr.get()) {
-          QString anAttributeName = anAttr->id().c_str();
-          switch (aState) {
-            case ModuleBase_ModelWidget::ModifiedInPP:
-              anError = "Attribute \"" + anAttributeName +
-                        "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
-              break;
-            case ModuleBase_ModelWidget::ModifiedInViewer:
-              anError = "Attribute \"" + anAttributeName +
-                        "\" is locked by modification value in the viewer.";
-              break;
-            case ModuleBase_ModelWidget::Reset:
-              anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
-              break;
-          }
-        }
-      }
-    }
-  }
   return anError;
 }
 
+void PartSet_SketcherMgr::clearClickedFlags()
+{
+  return;
+  myClickedPoint.clear();
+  myCurrentPoint.clear();
+}
+
 const QStringList& PartSet_SketcherMgr::sketchOperationIdList()
 {
   static QStringList aIds;
@@ -780,6 +785,13 @@ bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOpera
   return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
 }
 
+bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation)
+{
+  ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+                                                               (theOperation);
+  return aFOperation && aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
+}
+
 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
 {
   return (theId == SketchPlugin_Line::ID()) ||
@@ -810,6 +822,7 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
   // Display all sketcher sub-Objects
   myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
+  aConnector->workshop()->displayer()->activateTrihedron(true);
 
   // Hide sketcher result
   std::list<ResultPtr> aResults = myCurrentSketch->results();
@@ -912,20 +925,32 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
   }
   // restore the module selection modes, which were changed on startSketch
   aConnector->activateModuleSelectionModes();
+  aConnector->workshop()->displayer()->activateTrihedron(false);
 }
 
 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
 {
-  if (isNestedCreateOperation(theOperation) && myIsMouseOverWindow)
-    QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
+  if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
+    QCursor* aCurrentCursor = QApplication::overrideCursor();
+    if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
+      QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
+#ifdef DEBUG_CURSOR
+      qDebug("startNestedSketch() : Qt::CrossCursor");
+#endif
+    }
+  }
 }
 
-void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
+void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
 {
   myIsMouseOverViewProcessed = true;
   operationMgr()->onValidateOperation();
-  if (isNestedCreateOperation(theOp))
+  if (canChangeCursor(theOperation)) {
     QApplication::restoreOverrideCursor();
+#ifdef DEBUG_CURSOR
+    qDebug("stopNestedSketch() : None");
+#endif
+  }
 }
 
 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
@@ -1057,6 +1082,12 @@ bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
   return aCanDisplay;
 }
 
+bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
+{
+  return isNestedCreateOperation(theOperation) ||
+         myModule->sketchReentranceMgr()->isInternalEditActive();
+}
+
 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
 {
   bool isFoundObject = false;
@@ -1357,3 +1388,4 @@ XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
 
   return aWorkshop->operationMgr();
 }
+