SET(PROJECT_HEADERS
PartSet.h
PartSet_Constants.h
+ PartSet_EditLine.h
PartSet_FeatureArcPrs.h
PartSet_FeatureCirclePrs.h
PartSet_FeaturePrs.h
)
SET(PROJECT_SOURCES
+ PartSet_EditLine.cpp
PartSet_FeaturePrs.cpp
PartSet_FeatureArcPrs.cpp
PartSet_FeatureCirclePrs.cpp
--- /dev/null
+// 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());
+}
--- /dev/null
+// 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
#include <PartSet_FeatureLinePrs.h>
#include <PartSet_FeatureCirclePrs.h>
#include <PartSet_FeatureArcPrs.h>
+#include <PartSet_EditLine.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Point.h>
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:
}
void PartSet_OperationCreateConstraint::setPointSelectionMode(const PartSet_SelectionMode& theMode,
- const bool isToEmitSignal)
+ const bool isToEmitSignal)
{
myPointSelectionMode = theMode;
if (isToEmitSignal) {
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());
+}
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
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)
/// \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