]> 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 11:07:57 +0000 (15:07 +0400)
committernds <natalia.donis@opencascade.com>
Wed, 18 Jun 2014 11:07:57 +0000 (15:07 +0400)
1. ToolTip style for a constraint editor, close the control by the Esc button, erase constraint if the operation is aborted.

src/GeomAPI/GeomAPI_Lin2d.cpp
src/GeomAPI/GeomAPI_Lin2d.h
src/PartSet/PartSet_EditLine.cpp
src/PartSet/PartSet_EditLine.h
src/PartSet/PartSet_FeatureLengthPrs.cpp
src/PartSet/PartSet_OperationCreateConstraint.cpp
src/PartSet/PartSet_OperationCreateConstraint.h
src/XGUI/XGUI_Displayer.cpp

index 1299c75032db1b12fb1a4062f2090f49412ca737..5267000f3be66ce32a4042b8148834d4b46780cd 100644 (file)
@@ -60,11 +60,11 @@ const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Lin2d::project(const boost::share
   return boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aResult.X(), aResult.Y()));
 }
 
-double GeomAPI_Lin2d::crossed(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
+bool GeomAPI_Lin2d::isRight(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
 {
   const gp_XY& aDir = MY_LIN2D->Direction().XY();
   const gp_XY& aLoc = MY_LIN2D->Location().XY();
   const gp_XY& aPnt = thePoint->impl<gp_Pnt2d>().XY();
 
-  return aDir.Crossed(aPnt - aLoc);
+  return aDir.Crossed(aPnt - aLoc) > 0;
 }
index 2344648ea230aeb51b2471e89522e75494b007df..71136e035e255329808fe568ccad425f5f05e795 100644 (file)
@@ -32,7 +32,7 @@ public:
   /// Project point on line
   const boost::shared_ptr<GeomAPI_Pnt2d> project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
   /// Computes the cross product of the line direction and a vector from the line start point to the point
-  double crossed(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
+  bool isRight(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
 };
 
 #endif
index 4d8e7e9d8a6c15e753f78451e37fa86875da15ed..a8bccebafe4bd6e280e558c17c86dd37f9030ff2 100644 (file)
@@ -10,6 +10,8 @@ PartSet_EditLine::PartSet_EditLine(QWidget* theParent)
 : QObject(theParent)
 {
   myEditor = new QLineEdit(theParent);
+  myEditor->setWindowFlags(Qt::ToolTip);
+  myEditor->setFocusPolicy(Qt::StrongFocus);
 
   connect(myEditor, SIGNAL(returnPressed()), this, SLOT(onStopEditing()));
 }
@@ -19,6 +21,19 @@ void PartSet_EditLine::start(const QPoint& thePoint, double theValue)
   myEditor->move(thePoint);
   myEditor->setText(QString::number(theValue));
   myEditor->show();
+
+  myEditor->selectAll();
+  myEditor->setFocus();
+}
+
+bool PartSet_EditLine::isStarted() const
+{
+  return myEditor->isVisible();
+}
+
+void PartSet_EditLine::stop()
+{
+  myEditor->hide();
 }
 
 double PartSet_EditLine::getValue() const
@@ -28,6 +43,6 @@ double PartSet_EditLine::getValue() const
 
 void PartSet_EditLine::onStopEditing()
 {
-  myEditor->hide();
+  stop();
   emit stopped(getValue());
 }
index 1a7b5badd2baf1991032f54ee699bd44027f609d..f389a45f9ec5509aa1ea0b4cf3886f74d1313143 100644 (file)
@@ -31,15 +31,23 @@ public:
   /// \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;
+  /// Checks whether the editor is started
+  /// \returns true if the editor is activated
+  bool isStarted() const;
+
+  /// Stop the editor, in other words hide it
+  void stop();
 
 signals:
   /// Signals about the editing stop
   /// \param theValue the editor value
   void stopped(double theValue);
 
+protected:
+  /// Returns the editor value
+  /// \return the real value
+  double getValue() const;
+
 protected slots:
   /// Slot to check the editing stop
   void onStopEditing();
index c8390f99114ce525027f64fd77fe7cbef09306e2..24c798fb693407974901da8bca772cbaa46039be 100644 (file)
@@ -67,7 +67,7 @@ PartSet_SelectionMode PartSet_FeatureLengthPrs::setPoint(double theX, double the
       double aStartX, aStartY;
       PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY);
 
-      if (aFeatureLin->crossed(aPoint) < 0)
+      if (!aFeatureLin->isRight(aPoint))
         aDistance = -aDistance;
 
       AttributeDoublePtr aFlyoutAttr = 
index 9801884c6792c1993a23753d21b60707a2fa60cd..ec9ae0662b6c755481ea3e7d2e49857ca0abe7a3 100644 (file)
@@ -46,6 +46,10 @@ PartSet_OperationCreateConstraint::PartSet_OperationCreateConstraint(const QStri
 {
   std::string aKind = theId.toStdString();
   myFeaturePrs = PartSet_Tools::createFeaturePrs(aKind, theFeature);
+
+  // changed
+  myEditor = new PartSet_EditLine(0);
+  connect(myEditor, SIGNAL(stopped(double)), this, SLOT(onEditStopped(double)));
 }
 
 PartSet_OperationCreateConstraint::~PartSet_OperationCreateConstraint()
@@ -191,6 +195,8 @@ void PartSet_OperationCreateConstraint::keyReleased(const int theKey)
     }
     break;
     case Qt::Key_Escape: {
+      if (myEditor->isStarted())
+        myEditor->stop();
       if (myPointSelectionMode == SM_DonePoint)
       {
         commit();
@@ -265,10 +271,7 @@ void PartSet_OperationCreateConstraint::showEditor(QMouseEvent* theEvent, double
 {
   // 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);
+  myEditor->start(aPos, theValue);
 }
 
 void PartSet_OperationCreateConstraint::onEditStopped(double theValue)
index 90a9162678b8fa1fc814cfa0ee71a6e8f07534f9..311dbe5ddc8cd3dda1a4b51ff041b82a0c1260cf 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <QObject>
 
+class PartSet_EditLine;
 class PartSet_FeaturePrs;
 class GeomDataAPI_Point2D;
 class QMouseEvent;
@@ -129,6 +130,7 @@ private:
   boost::shared_ptr<PartSet_FeaturePrs> myFeaturePrs; ///< the feature presentation
   FeaturePtr myInitFeature; ///< the initial feature
   PartSet_SelectionMode myPointSelectionMode; ///< point selection mode
+  PartSet_EditLine* myEditor; ///< the constraint value editor
 };
 
 #endif
index ae0ff21bb633159bbadc1fe14a79cc026fefa068..c4d8b001e2977d07018b69b746304f71941da008 100644 (file)
@@ -134,10 +134,9 @@ void XGUI_Displayer::erase(FeaturePtr theFeature,
 
   Handle(AIS_InteractiveContext) aContext = AISContext();
   Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[aFeature];
-  Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
-  if (!anAISShape.IsNull())
+  if (!anAIS.IsNull())
   {
-    aContext->Erase(anAISShape, isUpdateViewer);
+    aContext->Erase(anAIS, isUpdateViewer);
   }
   myFeature2AISObjectMap.erase(aFeature);
 }