]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Wed, 18 Jun 2014 10:03:18 +0000 (14:03 +0400)
committernds <natalia.donis@opencascade.com>
Wed, 18 Jun 2014 10:03:18 +0000 (14:03 +0400)
1. The lenght constraint

src/PartSet/CMakeLists.txt
src/PartSet/PartSet_EditLine.cpp [new file with mode: 0644]
src/PartSet/PartSet_EditLine.h [new file with mode: 0644]
src/PartSet/PartSet_OperationCreateConstraint.cpp
src/PartSet/PartSet_OperationCreateConstraint.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h

index 7c38f2fa093662a36a0c612f1bc67e7340cd1892..524327e825f4b254b4ae96962f856884dd6901f8 100644 (file)
@@ -5,6 +5,7 @@ SET(CMAKE_AUTOMOC ON)
 SET(PROJECT_HEADERS
        PartSet.h
        PartSet_Constants.h
+       PartSet_EditLine.h
        PartSet_FeatureArcPrs.h
        PartSet_FeatureCirclePrs.h
        PartSet_FeaturePrs.h
@@ -25,6 +26,7 @@ SET(PROJECT_HEADERS
 )
 
 SET(PROJECT_SOURCES
+       PartSet_EditLine.cpp
        PartSet_FeaturePrs.cpp
        PartSet_FeatureArcPrs.cpp
        PartSet_FeatureCirclePrs.cpp
diff --git a/src/PartSet/PartSet_EditLine.cpp b/src/PartSet/PartSet_EditLine.cpp
new file mode 100644 (file)
index 0000000..4d8e7e9
--- /dev/null
@@ -0,0 +1,33 @@
+// File:        PartSet_EditLine.h
+// Created:     02 June 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <PartSet_EditLine.h>
+
+#include <QLineEdit>
+
+PartSet_EditLine::PartSet_EditLine(QWidget* theParent)
+: QObject(theParent)
+{
+  myEditor = new QLineEdit(theParent);
+
+  connect(myEditor, SIGNAL(returnPressed()), this, SLOT(onStopEditing()));
+}
+
+void PartSet_EditLine::start(const QPoint& thePoint, double theValue)
+{
+  myEditor->move(thePoint);
+  myEditor->setText(QString::number(theValue));
+  myEditor->show();
+}
+
+double PartSet_EditLine::getValue() const
+{
+  return myEditor->text().toDouble();
+}
+
+void PartSet_EditLine::onStopEditing()
+{
+  myEditor->hide();
+  emit stopped(getValue());
+}
diff --git a/src/PartSet/PartSet_EditLine.h b/src/PartSet/PartSet_EditLine.h
new file mode 100644 (file)
index 0000000..1a7b5ba
--- /dev/null
@@ -0,0 +1,51 @@
+// File:        PartSet_EditLine.h
+// Created:     02 Jun 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef PartSet_EditLine_H
+#define PartSet_EditLine_H
+
+#include "PartSet.h"
+
+#include <QObject>
+#include <QPoint>
+
+class QLineEdit;
+class QWidget;
+
+/*!
+ \class PartSet_EditLine
+ * \brief The class to give an editor to modify a real value
+*/
+class PARTSET_EXPORT PartSet_EditLine : public QObject
+{
+  Q_OBJECT
+public:
+  /// Constructor
+  PartSet_EditLine(QWidget* theParent);
+  /// Destructor
+  virtual ~PartSet_EditLine() {};
+
+  /// Show the editor in the given global position
+  /// \param thePoint a position
+  /// \param theValue a value for the editor
+  void start(const QPoint& thePoint, double theValue);
+
+  /// Returns the editor value
+  /// \return the real value
+  double getValue() const;
+
+signals:
+  /// Signals about the editing stop
+  /// \param theValue the editor value
+  void stopped(double theValue);
+
+protected slots:
+  /// Slot to check the editing stop
+  void onStopEditing();
+
+protected:
+  QLineEdit* myEditor; /// the value editor
+};
+
+#endif
index 78d0fe251cfc3b065f670937342f15024d11e65d..9801884c6792c1993a23753d21b60707a2fa60cd 100644 (file)
@@ -10,6 +10,7 @@
 #include <PartSet_FeatureLinePrs.h>
 #include <PartSet_FeatureCirclePrs.h>
 #include <PartSet_FeatureArcPrs.h>
+#include <PartSet_EditLine.h>
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Point.h>
@@ -113,11 +114,12 @@ void PartSet_OperationCreateConstraint::mouseReleased(QMouseEvent* theEvent, Han
       PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
 
       PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
-      flushUpdated();
       // show value edit dialog
-      //setPointSelectionMode(aMode);
-      commit();
-      restartOperation(feature()->getKind(), FeaturePtr());
+      double aValue;
+      if (PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, aValue)) {
+        showEditor(theEvent, aValue);
+        setPointSelectionMode(SM_ThirdPoint/*aMode*/);
+      }
     }
     break;
     default:
@@ -247,7 +249,7 @@ FeaturePtr PartSet_OperationCreateConstraint::createFeature(const bool theFlushM
 }
 
 void PartSet_OperationCreateConstraint::setPointSelectionMode(const PartSet_SelectionMode& theMode,
-                                                           const bool isToEmitSignal)
+                                                              const bool isToEmitSignal)
 {
   myPointSelectionMode = theMode;
   if (isToEmitSignal) {
@@ -258,3 +260,22 @@ void PartSet_OperationCreateConstraint::setPointSelectionMode(const PartSet_Sele
     emit focusActivated(aName);
   }
 }
+
+void PartSet_OperationCreateConstraint::showEditor(QMouseEvent* theEvent, double theValue)
+{
+  // changed
+  QPoint aPos = theEvent->globalPos();
+
+  PartSet_EditLine* anEditor = new PartSet_EditLine(0);
+  connect(anEditor, SIGNAL(stopped(double)), this, SLOT(onEditStopped(double)));
+  anEditor->start(aPos, theValue);
+}
+
+void PartSet_OperationCreateConstraint::onEditStopped(double theValue)
+{
+  PartSet_Tools::setFeatureValue(feature(), theValue, CONSTRAINT_ATTR_VALUE);
+
+  flushUpdated();
+  commit();
+  restartOperation(feature()->getKind(), FeaturePtr());
+}
index 9e09ad7df2992b914a855ea8d6dcb272659c5b09..90a9162678b8fa1fc814cfa0ee71a6e8f07534f9 100644 (file)
@@ -115,6 +115,16 @@ protected:
   void setPointSelectionMode(const PartSet_SelectionMode& theMode,
                              const bool isToEmitSignal = true);
 
+  /// Show the value editor
+  /// \param theEvent to get the mouse cursor position
+  /// \param theValue an editor value
+  void showEditor(QMouseEvent* theEvent, double theValue);
+
+protected slots:
+  /// SLOT, that listens the value edited signal and set the new value to the feature
+  /// \param theValue the editor value
+  void onEditStopped(double theValue);
+
 private:
   boost::shared_ptr<PartSet_FeaturePrs> myFeaturePrs; ///< the feature presentation
   FeaturePtr myInitFeature; ///< the initial feature
index 451971a16c145ef5e60f0f699aba57552b804388..02f216cfcb7deb9520354995fb1e000df8e0952f 100644 (file)
@@ -243,6 +243,22 @@ void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue,
     anAttribute->setValue(theValue);
 }
 
+bool PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& theAttribute,
+                                 double& theValue)
+{
+  bool aResult = false;
+  if (!theFeature)
+    return aResult;
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  AttributeDoublePtr anAttribute =
+        boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(theAttribute));
+  if (anAttribute) {
+    theValue = anAttribute->value();
+    aResult = true;
+  }
+  return aResult;
+}
+
 void PartSet_Tools::createConstraint(FeaturePtr theSketch,
                                      boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
                                      boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
index a3de5e0f259d3ae76304d538877ad4dc5893776e..0ddb45e7f7e339d4a917c3da406d193b82eef5c6 100644 (file)
@@ -89,6 +89,14 @@ public:
   /// \param theAttribute the feature attribute
   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
 
+  /// \brief Returns the feature double value if it is.
+  /// \param theFeature the feature
+  /// \param theAttribute the feature attribute
+  /// \param theValue the horizontal coordinate
+  /// \returns the state whether the value is correct
+  static bool featureValue(FeaturePtr theFeature, const std::string& theAttribute,
+                           double& theValue);
+
   /// Creates a constraint on two points
   /// \param thePoint1 the first point
   /// \param thePoint1 the second point