From 8b96b3bed4a6e6cc026dd36e39c5bbeb0a2ee61e Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 18 Jun 2014 15:07:57 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc 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 | 4 ++-- src/GeomAPI/GeomAPI_Lin2d.h | 2 +- src/PartSet/PartSet_EditLine.cpp | 17 ++++++++++++++++- src/PartSet/PartSet_EditLine.h | 14 +++++++++++--- src/PartSet/PartSet_FeatureLengthPrs.cpp | 2 +- .../PartSet_OperationCreateConstraint.cpp | 11 +++++++---- src/PartSet/PartSet_OperationCreateConstraint.h | 2 ++ src/XGUI/XGUI_Displayer.cpp | 5 ++--- 8 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/GeomAPI/GeomAPI_Lin2d.cpp b/src/GeomAPI/GeomAPI_Lin2d.cpp index 1299c7503..5267000f3 100644 --- a/src/GeomAPI/GeomAPI_Lin2d.cpp +++ b/src/GeomAPI/GeomAPI_Lin2d.cpp @@ -60,11 +60,11 @@ const boost::shared_ptr GeomAPI_Lin2d::project(const boost::share return boost::shared_ptr(new GeomAPI_Pnt2d(aResult.X(), aResult.Y())); } -double GeomAPI_Lin2d::crossed(const boost::shared_ptr& thePoint) const +bool GeomAPI_Lin2d::isRight(const boost::shared_ptr& thePoint) const { const gp_XY& aDir = MY_LIN2D->Direction().XY(); const gp_XY& aLoc = MY_LIN2D->Location().XY(); const gp_XY& aPnt = thePoint->impl().XY(); - return aDir.Crossed(aPnt - aLoc); + return aDir.Crossed(aPnt - aLoc) > 0; } diff --git a/src/GeomAPI/GeomAPI_Lin2d.h b/src/GeomAPI/GeomAPI_Lin2d.h index 2344648ea..71136e035 100644 --- a/src/GeomAPI/GeomAPI_Lin2d.h +++ b/src/GeomAPI/GeomAPI_Lin2d.h @@ -32,7 +32,7 @@ public: /// Project point on line const boost::shared_ptr project(const boost::shared_ptr& 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& thePoint) const; + bool isRight(const boost::shared_ptr& thePoint) const; }; #endif diff --git a/src/PartSet/PartSet_EditLine.cpp b/src/PartSet/PartSet_EditLine.cpp index 4d8e7e9d8..a8bccebaf 100644 --- a/src/PartSet/PartSet_EditLine.cpp +++ b/src/PartSet/PartSet_EditLine.cpp @@ -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()); } diff --git a/src/PartSet/PartSet_EditLine.h b/src/PartSet/PartSet_EditLine.h index 1a7b5badd..f389a45f9 100644 --- a/src/PartSet/PartSet_EditLine.h +++ b/src/PartSet/PartSet_EditLine.h @@ -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(); diff --git a/src/PartSet/PartSet_FeatureLengthPrs.cpp b/src/PartSet/PartSet_FeatureLengthPrs.cpp index c8390f991..24c798fb6 100644 --- a/src/PartSet/PartSet_FeatureLengthPrs.cpp +++ b/src/PartSet/PartSet_FeatureLengthPrs.cpp @@ -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 = diff --git a/src/PartSet/PartSet_OperationCreateConstraint.cpp b/src/PartSet/PartSet_OperationCreateConstraint.cpp index 9801884c6..ec9ae0662 100644 --- a/src/PartSet/PartSet_OperationCreateConstraint.cpp +++ b/src/PartSet/PartSet_OperationCreateConstraint.cpp @@ -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) diff --git a/src/PartSet/PartSet_OperationCreateConstraint.h b/src/PartSet/PartSet_OperationCreateConstraint.h index 90a916267..311dbe5dd 100644 --- a/src/PartSet/PartSet_OperationCreateConstraint.h +++ b/src/PartSet/PartSet_OperationCreateConstraint.h @@ -12,6 +12,7 @@ #include +class PartSet_EditLine; class PartSet_FeaturePrs; class GeomDataAPI_Point2D; class QMouseEvent; @@ -129,6 +130,7 @@ private: boost::shared_ptr myFeaturePrs; ///< the feature presentation FeaturePtr myInitFeature; ///< the initial feature PartSet_SelectionMode myPointSelectionMode; ///< point selection mode + PartSet_EditLine* myEditor; ///< the constraint value editor }; #endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index ae0ff21bb..c4d8b001e 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -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); } -- 2.39.2