Salome HOME
#1042 Sometimes when setting distance constraints, the input field is not displayed...
authornds <nds@opencascade.com>
Thu, 10 Dec 2015 06:41:12 +0000 (09:41 +0300)
committernds <nds@opencascade.com>
Thu, 10 Dec 2015 06:41:40 +0000 (09:41 +0300)
src/ModuleBase/ModuleBase_DoubleSpinBox.cpp
src/ModuleBase/ModuleBase_DoubleSpinBox.h
src/ModuleBase/ModuleBase_IViewer.h
src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/ModuleBase/ModuleBase_WidgetEditor.h
src/PartSet/PartSet_Module.cpp
src/SketchPlugin/SketchPlugin_Feature.h
src/XGUI/XGUI_ViewerProxy.cpp
src/XGUI/XGUI_ViewerProxy.h

index 06c1afcd6a045dfd40970fc7fe35cfc11cf2ff64..0f5ebcfc174799a944039109b358b12adfebc4db 100644 (file)
@@ -201,7 +201,7 @@ QString ModuleBase_DoubleSpinBox::removeTrailingZeroes(const QString& src) const
   return res;
 }
 
-void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent)
+void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEventtheEvent)
 {
   bool isEmitKeyRelease = false;
   switch (theEvent->key()) {
@@ -220,7 +220,27 @@ void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent)
   QDoubleSpinBox::keyPressEvent(theEvent);
 
   if (isEmitKeyRelease)
-    emit keyReleased(theEvent);
+    emit enterPressed();
+}
+
+void ModuleBase_DoubleSpinBox::keyReleaseEvent(QKeyEvent* theEvent)
+{
+  switch (theEvent->key()) {
+    case Qt::Key_Enter:
+    case Qt::Key_Return: {
+      // the enter has already been processed when key is pressed,
+      // key release should not be processed in operation manager
+      if (myIsEmitKeyPressEvent) {
+        theEvent->accept();
+        emit enterReleased();
+        return;
+      }
+    }
+    break;
+    default:
+      break;
+  }
+  QDoubleSpinBox::keyReleaseEvent(theEvent);
 }
 
 /*!
index ef22f8ad12bdfffb66dffd176af8d722e429deca..d0b20e6ac785cb062d7664b417c86ce53be67595 100644 (file)
@@ -63,7 +63,8 @@ Q_OBJECT
 signals:
   /// The signal about key release on the control, that corresponds to the attribute
   /// \param theEvent key release event
-  void keyReleased(QKeyEvent* theEvent);
+  void enterPressed();
+  void enterReleased();
 
  protected slots:
    /// Called on text changed
@@ -74,6 +75,9 @@ signals:
  protected:
    /// Removes extra trailing zero symbols
   QString removeTrailingZeroes(const QString&) const;
+  /// Called on key press event
+  virtual void keyReleaseEvent(QKeyEvent* theEvent);
+
   /// Called on key press event
   virtual void keyPressEvent(QKeyEvent* theEvent);
 
index 3c8f67653432a316a5c6534eb9243f81039c6713..4dce665cee53dc8572cd005d66a81fbd8b3ec3fe 100644 (file)
@@ -36,6 +36,8 @@ Q_OBJECT
   //! Returns Vsd_View object from currently active view window
   virtual Handle(V3d_View) activeView() const = 0;
 
+  virtual QWidget* activeViewPort() const = 0;
+
   //! Enable or disable selection in the viewer
   //! \param isEnabled is enable or disable flag
   virtual void enableSelection(bool isEnabled) = 0;
index 6ef0847abd9c093426fb7d12bebb5a00ce01640e..aa4cd79b70bdaa0d9af645402e6779dd43788e61 100644 (file)
@@ -36,7 +36,8 @@ ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
                                                  const Config_WidgetAPI* theData,
                                                  const std::string& theParentId)
 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId),
-  myIsKeyReleasedEmitted(false)
+  //myIsEnterPressedEmitted(false),
+  myXPosition(-1), myYPosition(-1)
 {
 }
 
@@ -52,9 +53,9 @@ void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
 
   ModuleBase_ParamSpinBox* anEditor = new ModuleBase_ParamSpinBox(&aDlg);
   anEditor->enableKeyPressEvent(true);
-  if (!myIsEditing) {
-    connect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SLOT(onKeyReleased(QKeyEvent*)));
-  }
+  //if (!myIsEditing) {
+  //  connect(anEditor, SIGNAL(enterPressed()), this, SLOT(onEnterPressed()));
+  //}
 
   anEditor->setMinimum(0);
   anEditor->setMaximum(DBL_MAX);
@@ -67,14 +68,18 @@ void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
 
   ModuleBase_Tools::setFocus(anEditor, "ModuleBase_WidgetEditor::editedValue");
   anEditor->selectAll();
-  QObject::connect(anEditor, SIGNAL(editingFinished()), &aDlg, SLOT(accept()));
+  QObject::connect(anEditor, SIGNAL(enterReleased()), &aDlg, SLOT(accept()));
+
+  QPoint aPoint = QCursor::pos();
+  if (myXPosition >= 0 && myYPosition >= 0)
+    aPoint = QPoint(myXPosition, myYPosition);
 
-  aDlg.move(QCursor::pos());
+  aDlg.move(aPoint);
   aDlg.exec();
 
-  if (!myIsEditing) {
-    disconnect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SLOT(onKeyReleased(QKeyEvent*)));
-  }
+  //if (!myIsEditing) {
+  //  disconnect(anEditor, SIGNAL(keyReleased(QKeyEvent*)), this, SLOT(onEnterPressed()));
+  //}
 
   outText = anEditor->text();
   bool isDouble;
@@ -87,25 +92,19 @@ void ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText)
 
 bool ModuleBase_WidgetEditor::focusTo()
 {
-  // nds: it seems, that the timer is not necessary anymore
-
-  // We can not launch here modal process for value editing because 
-  // it can be called on other focusOutWidget event and will block it
-  //QTimer::singleShot(1, this, SLOT(showPopupEditor()));
-
   showPopupEditor();
-
   return true;
 }
 
-void ModuleBase_WidgetEditor::showPopupEditor()
+void ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals)
 {
-  myIsKeyReleasedEmitted = false;
+  //myIsEnterPressedEmitted = false;
 
   // we need to emit the focus in event manually in order to save the widget as an active
   // in the property panel before the mouse leave event happens in the viewer. The module
   // ask an active widget and change the feature visualization if the widget is not the current one.
-  emit focusInWidget(this);
+  if (theSendSignals)
+    emit focusInWidget(this);
 
   // nds: it seems, that the envents processing is not necessary anymore
   // White while all events will be processed
@@ -121,16 +120,27 @@ void ModuleBase_WidgetEditor::showPopupEditor()
   } else {
     ModuleBase_Tools::setSpinText(mySpinBox, aText);
   }
-  emit valuesChanged();
-  // the focus leaves the control automatically by the Enter/Esc event
-  // it is processed in operation manager
-  //emit focusOutWidget(this);
-
-  if (myIsKeyReleasedEmitted)
-    emit enterClicked();
+  if (theSendSignals) {
+    emit valuesChanged();
+    // the focus leaves the control automatically by the Enter/Esc event
+    // it is processed in operation manager
+    //emit focusOutWidget(this);
+
+    //if (myIsEnterPressedEmitted)
+    if (!myIsEditing)
+      emit enterClicked();
+  }
+  else
+    storeValue();
 }
 
-void ModuleBase_WidgetEditor::onKeyReleased(QKeyEvent* theEvent)
+/*void ModuleBase_WidgetEditor::onEnterPressed()
+{
+  myIsEnterPressedEmitted = true;
+}*/
+
+void ModuleBase_WidgetEditor::setCursorPosition(const int theX, const int theY)
 {
-  myIsKeyReleasedEmitted = true;
+  myXPosition = theX;
+  myYPosition = theY;
 }
index 8f494b366decf324104319c0fbc82f85658b219c..063dd2b2b33d56ddf980e940fadcb8662f0ecb55 100644 (file)
@@ -43,11 +43,15 @@ Q_OBJECT
   /// \return the state whether the widget can accept the focus
   virtual bool focusTo();
 
-   /// Shous popup window under cursor for data editing
-   void showPopupEditor();
+  /// Shous popup window under cursor for data editing
+  /// \param theSendSignals a flag whether the signals should be sent or the value
+  /// is to be applyed directly
+  void showPopupEditor(const bool theSendSignals = true);
 
-protected slots:
-  void onKeyReleased(QKeyEvent* theEvent);
+  void setCursorPosition(const int theX, const int theY);
+
+//protected slots:
+  //void onEnterPressed();
 
 private:
    void editedValue(double& outValue, QString& outText);
@@ -59,7 +63,9 @@ private:
    ///< the kinds of possible features
    QStringList myFeatureKinds;  
 
-   bool myIsKeyReleasedEmitted;
+   //bool myIsEnterPressedEmitted;
+
+   int myXPosition, myYPosition;
 };
 
 #endif
index 1f0598bb4a50a5d0f101c174f1ebb67509e874a0..68d855a482e3be39151f115695395d68b4b13817 100755 (executable)
@@ -473,6 +473,7 @@ void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* the
   anOpMgr->onKeyReleased(theEvent);
 }
 
+#include <XGUI_SalomeConnector.h>
 void PartSet_Module::onOperationActivatedByPreselection()
 {
   if (!mySketchReentrantMgr->canBeCommittedByPreselection())
@@ -483,6 +484,64 @@ void PartSet_Module::onOperationActivatedByPreselection()
     // Set final definitions if they are necessary
     //propertyPanelDefined(aOperation);
     /// Commit sketcher operations automatically
+    ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+                                                                            (anOperation);
+    if (aFOperation) {
+      if (PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
+        // Activate dimension value editing on double click
+        ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
+        QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
+        // Find corresponded widget to activate value editing
+        foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
+          if (aWgt->attributeID() == "ConstraintValue") {
+            FeaturePtr aFeature = aFOperation->feature();
+            // the featue should be displayed in order to find the AIS text position,
+            // the place where the editor will be shown
+            aFeature->setDisplayed(true);
+            /// the execute is necessary to perform in the feature compute for flyout position
+            aFeature->execute();
+
+            Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+            Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+
+            PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
+            if (anEditor) {
+              int aX = 0, anY = 0;
+              XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+              XGUI_Workshop* aWorkshop = aConnector->workshop();
+              XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+              AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
+              Handle(AIS_InteractiveObject) anAISIO;
+              if (anAIS.get() != NULL) {
+                anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
+              }
+              if (anAIS.get() != NULL) {
+                Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
+
+                if (!anAISIO.IsNull()) {
+                  Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
+                  if (!aDim.IsNull()) {
+                    gp_Pnt aPosition = aDim->GetTextPosition();
+
+                    ModuleBase_IViewer* aViewer = myWorkshop->viewer();
+                    Handle(V3d_View) aView = aViewer->activeView();
+                    int aCX, aCY;
+                    aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
+
+                    QWidget* aViewPort = aViewer->activeViewPort();
+                    QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
+                    aX = aGlPoint.x();
+                    anY = aGlPoint.y();
+                  }
+                }
+                anEditor->setCursorPosition(aX, anY);
+                anEditor->showPopupEditor(false);
+              }
+            }
+          }
+        }
+      }
+    }
     anOperation->commit();
   }
 }
index 2f386d18d4e63e8275bd0f32c7a897f3987b21b8..de39f17b8c7dc41c096918d610500afa6e705225 100644 (file)
@@ -10,7 +10,6 @@
 #include "SketchPlugin.h"
 #include <ModelAPI_CompositeFeature.h>
 #include <GeomAPI_Shape.h>
-#include <GeomAPI_AISObject.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeBoolean.h>
index 053a87abe71513c1335cfbbcef4ca9de7ea1284f..54dc14670143a4886ebefd7afde87cdae7ed223c 100644 (file)
@@ -52,6 +52,17 @@ Handle(V3d_View) XGUI_ViewerProxy::activeView() const
 #endif
 }
 
+QWidget* XGUI_ViewerProxy::activeViewPort() const
+{
+#ifdef HAVE_SALOME
+  return myWorkshop->salomeConnector()->viewer()->activeView();
+#else
+  AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+  return (aViewer->activeViewWindow()) ? 
+         aViewer->activeViewWindow()->viewPortApp(): 0;
+#endif
+}
+
 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist)
 {
   Handle(V3d_View) aView3d = activeView();
index 8763be818e45d363214ec7e474ea42b72fc73b93..bce1db650127e232a9a7c1a272add53edfbcbc76 100644 (file)
@@ -35,6 +35,8 @@ Q_OBJECT
   //! Returns Vsd_View object from currently active view window
   virtual Handle(V3d_View) activeView() const;
 
+  virtual QWidget* activeViewPort() const;
+
   //! Enable or disable selection in the viewer
   virtual void enableSelection(bool isEnabled);