From b3eb2ec99597987ae45f7b0f8edafb03a6cae129 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 18 Jun 2014 14:03:18 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc 1. The lenght constraint --- src/PartSet/CMakeLists.txt | 2 + src/PartSet/PartSet_EditLine.cpp | 33 ++++++++++++ src/PartSet/PartSet_EditLine.h | 51 +++++++++++++++++++ .../PartSet_OperationCreateConstraint.cpp | 31 +++++++++-- .../PartSet_OperationCreateConstraint.h | 10 ++++ src/PartSet/PartSet_Tools.cpp | 16 ++++++ src/PartSet/PartSet_Tools.h | 8 +++ 7 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 src/PartSet/PartSet_EditLine.cpp create mode 100644 src/PartSet/PartSet_EditLine.h diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 7c38f2fa0..524327e82 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -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 index 000000000..4d8e7e9d8 --- /dev/null +++ b/src/PartSet/PartSet_EditLine.cpp @@ -0,0 +1,33 @@ +// File: PartSet_EditLine.h +// Created: 02 June 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include + +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 index 000000000..1a7b5badd --- /dev/null +++ b/src/PartSet/PartSet_EditLine.h @@ -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 +#include + +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 diff --git a/src/PartSet/PartSet_OperationCreateConstraint.cpp b/src/PartSet/PartSet_OperationCreateConstraint.cpp index 78d0fe251..9801884c6 100644 --- a/src/PartSet/PartSet_OperationCreateConstraint.cpp +++ b/src/PartSet/PartSet_OperationCreateConstraint.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -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()); +} diff --git a/src/PartSet/PartSet_OperationCreateConstraint.h b/src/PartSet/PartSet_OperationCreateConstraint.h index 9e09ad7df..90a916267 100644 --- a/src/PartSet/PartSet_OperationCreateConstraint.h +++ b/src/PartSet/PartSet_OperationCreateConstraint.h @@ -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 myFeaturePrs; ///< the feature presentation FeaturePtr myInitFeature; ///< the initial feature diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 451971a16..02f216cfc 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -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 aData = theFeature->data(); + AttributeDoublePtr anAttribute = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + if (anAttribute) { + theValue = anAttribute->value(); + aResult = true; + } + return aResult; +} + void PartSet_Tools::createConstraint(FeaturePtr theSketch, boost::shared_ptr thePoint1, boost::shared_ptr thePoint2) diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index a3de5e0f2..0ddb45e7f 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -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 -- 2.39.2