1. ToolTip style for a constraint editor, close the control by the Esc button, erase constraint if the operation is aborted.
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;
}
/// 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
: QObject(theParent)
{
myEditor = new QLineEdit(theParent);
+ myEditor->setWindowFlags(Qt::ToolTip);
+ myEditor->setFocusPolicy(Qt::StrongFocus);
connect(myEditor, SIGNAL(returnPressed()), this, SLOT(onStopEditing()));
}
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
void PartSet_EditLine::onStopEditing()
{
- myEditor->hide();
+ stop();
emit stopped(getValue());
}
/// \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();
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 =
{
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()
}
break;
case Qt::Key_Escape: {
+ if (myEditor->isStarted())
+ myEditor->stop();
if (myPointSelectionMode == SM_DonePoint)
{
commit();
{
// 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)
#include <QObject>
+class PartSet_EditLine;
class PartSet_FeaturePrs;
class GeomDataAPI_Point2D;
class QMouseEvent;
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
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);
}