Edit feature: move specific feature functionality to the feature presentation.
{
}
+std::string PartSet_FeatureCirclePrs::getKind()
+{
+ return SKETCH_CIRCLE_KIND;
+}
+
PartSet_SelectionMode PartSet_FeatureCirclePrs::setPoint(double theX, double theY,
const PartSet_SelectionMode& theMode)
{
return aMode;
}
+double PartSet_FeatureCirclePrs::distanceToPoint(FeaturePtr theFeature,
+ double theX, double theY)
+{
+ double aDelta = 0;
+ if (!theFeature || theFeature->getKind() != getKind())
+ return aDelta;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+
+ boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
+ return aPoint->pnt()->distance(aPoint2d);
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::findPoint(FeaturePtr theFeature,
+ double theX, double theY)
+{
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
+ if (!theFeature || theFeature->getKind() != getKind())
+ return aPoint2D;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
+ aPoint2D = aPoint;
+
+ return aPoint2D;
+}
+
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::featurePoint
(const PartSet_SelectionMode& theMode)
{
class PARTSET_EXPORT PartSet_FeatureCirclePrs : public PartSet_FeaturePrs
{
public:
+ /// Returns the feature type processed by this presentation
+ /// \return the feature kind
+ static std::string getKind();
+
/// Constructor
/// \param theSketch the sketch feature
PartSet_FeatureCirclePrs(FeaturePtr theSketch);
/// \return next attribute selection mode
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+ /// Return the distance between the feature and the point
+ /// \param theFeature feature object
+ /// \param theX the horizontal coordinate of the point
+ /// \param theX the vertical coordinate of the point
+ static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
+
+ /// Find a point in the line with given coordinates
+ /// \param theFeature the line feature
+ /// \param theX the horizontal point coordinate
+ /// \param theY the vertical point coordinate
+ static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
+ double theY);
protected:
/// Returns the feature point in the selection mode position.
/// \param theMode the current operation selection mode. The feature attribute depends on the mode
{
}
+std::string PartSet_FeatureLinePrs::getKind()
+{
+ return SKETCH_LINE_KIND;
+}
+
void PartSet_FeatureLinePrs::initFeature(FeaturePtr theFeature)
{
if (feature() && theFeature)
if (theFeature) {
double X0, X1, X2, X3;
double Y0, Y1, Y2, Y3;
- PartSet_Tools::getLinePoint(theFeature, LINE_ATTR_START, X2, Y2);
- PartSet_Tools::getLinePoint(theFeature, LINE_ATTR_END, X3, Y3);
+ getLinePoint(theFeature, LINE_ATTR_START, X2, Y2);
+ getLinePoint(theFeature, LINE_ATTR_END, X3, Y3);
PartSet_Tools::convertTo2D(thePoint, sketch(), theView, X1, Y1);
switch (theMode) {
PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, theX, theY);
break;
case SM_SecondPoint: {
- PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
+ getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, theX, theY);
}
break;
}
}
+double PartSet_FeatureLinePrs::distanceToPoint(FeaturePtr theFeature,
+ double theX, double theY)
+{
+ double aDelta = 0;
+ if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ return aDelta;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+
+ double aX, anY;
+ PartSet_Tools::projectPointOnLine(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y(), theX, theY, aX, anY);
+ aDelta = gp_Pnt(theX, theY, 0).Distance(gp_Pnt(aX, anY, 0));
+
+ return aDelta;
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLinePrs::findPoint(FeaturePtr theFeature,
+ double theX, double theY)
+{
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
+ if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+ return aPoint2D;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ aPoint2D = PartSet_FeatureLinePrs::findPoint(theFeature, theX, theY);
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
+ fabs(aPoint->y() - theY) < Precision::Confusion())
+ aPoint2D = aPoint;
+ else {
+ aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
+ fabs(aPoint->y() - theY) < Precision::Confusion())
+ aPoint2D = aPoint;
+ }
+ return aPoint2D;
+}
+
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLinePrs::featurePoint
(const PartSet_SelectionMode& theMode)
{
(aData->attribute(aPointArg));
return aPoint;
}
+
+void PartSet_FeatureLinePrs::getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
+ double& theX, double& theY)
+{
+ if (!theFeature || theFeature->getKind() != PartSet_FeatureLinePrs::getKind())
+ return;
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
+ theX = aPoint->x();
+ theY = aPoint->y();
+}
class PARTSET_EXPORT PartSet_FeatureLinePrs : public PartSet_FeaturePrs
{
public:
+ /// Returns the feature type processed by this presentation
+ /// \return the feature kind
+ static std::string getKind();
+
/// Constructor
/// \param theSketch the sketch feature
PartSet_FeatureLinePrs(FeaturePtr theSketch);
const gp_Pnt& thePoint, Handle_V3d_View theView,
double& theX, double& theY);
+ /// Return the distance between the feature and the point
+ /// \param theFeature feature object
+ /// \param theX the horizontal coordinate of the point
+ /// \param theX the vertical coordinate of the point
+ static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
+
+ /// Find a point in the line with given coordinates
+ /// \param theFeature the line feature
+ /// \param theX the horizontal point coordinate
+ /// \param theY the vertical point coordinate
+ static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
+ double theY);
+
protected:
/// Initializes current feature by the given
/// \param theSourceFeature the feature, which attributes are used to initialize the current feature
/// Returns the feature point in the selection mode position.
/// \param theMode the current operation selection mode. The feature attribute depends on the mode
virtual boost::shared_ptr<GeomDataAPI_Point2D> featurePoint(const PartSet_SelectionMode& theMode);
+
+ /// \brief Get the line point 2d coordinates.
+ /// \param theFeature the line feature
+ /// \param theAttribute the start or end attribute of the line
+ /// \param theX the horizontal coordinate
+ /// \param theY the vertical coordinate
+ static void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
+ double& theX, double& theY);
};
#endif
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Point.h>
+#include <GeomAPI_Pnt2d.h>
#include <GeomDataAPI_Point2D.h>
#include <ModelAPI_Data.h>
{
}
+std::string PartSet_FeaturePointPrs::getKind()
+{
+ return SKETCH_POINT_KIND;
+}
+
PartSet_SelectionMode PartSet_FeaturePointPrs::setPoint(double theX, double theY,
const PartSet_SelectionMode& theMode)
{
return aMode;
}
+double PartSet_FeaturePointPrs::distanceToPoint(FeaturePtr theFeature,
+ double theX, double theY)
+{
+ double aDelta = 0;
+ if (!theFeature || theFeature->getKind() != getKind())
+ return aDelta;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
+
+ boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
+ return aPoint->pnt()->distance(aPoint2d);
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePointPrs::findPoint(FeaturePtr theFeature,
+ double theX, double theY)
+{
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
+ if (!theFeature || theFeature->getKind() != getKind())
+ return aPoint2D;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
+ aPoint2D = aPoint;
+
+ return aPoint2D;
+}
+
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePointPrs::featurePoint
(const PartSet_SelectionMode& theMode)
{
class PARTSET_EXPORT PartSet_FeaturePointPrs : public PartSet_FeaturePrs
{
public:
+ /// Returns the feature type processed by this presentation
+ /// \return the feature kind
+ static std::string getKind();
+
/// Constructor
/// \param theSketch the sketch feature
PartSet_FeaturePointPrs(FeaturePtr theSketch);
/// \return next attribute selection mode
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+ /// Return the distance between the feature and the point
+ /// \param theFeature feature object
+ /// \param theX the horizontal coordinate of the point
+ /// \param theX the vertical coordinate of the point
+ static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
+
+ /// Find a point in the line with given coordinates
+ /// \param theFeature the line feature
+ /// \param theX the horizontal point coordinate
+ /// \param theY the vertical point coordinate
+ static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
+ double theY);
+
protected:
/// Returns the feature point in the selection mode position.
/// \param theMode the current operation selection mode. The feature attribute depends on the mode
return;
if (myFeatures.size() != 1) {
- FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(),
- theView, feature(), myFeatures);
+ FeaturePtr aFeature = PartSet_Tools::nearestFeature(theEvent->pos(), theView, feature(),
+ myFeatures);
if (aFeature)
restartOperation(PartSet_OperationEditFeature::Type(), aFeature);
}
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
-#include <SketchPlugin_Point.h>
-#include <SketchPlugin_Line.h>
-#include <SketchPlugin_Circle.h>
#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_Constraint.h>
+#include <PartSet_FeatureLinePrs.h>
+#include <PartSet_FeaturePointPrs.h>
+#include <PartSet_FeatureCirclePrs.h>
+
#include <XGUI_ViewerPrs.h>
#include <V3d_View.hxx>
}
}
-FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint,
- Handle_V3d_View theView,
- FeaturePtr theSketch,
- const std::list<XGUI_ViewerPrs>& theFeatures)
+FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
+ FeaturePtr theSketch,
+ const std::list<XGUI_ViewerPrs>& theFeatures)
{
double aX, anY;
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView);
double theX, double theY)
{
double aDelta = 0;
- if (theFeature->getKind() != SKETCH_LINE_KIND)
- return aDelta;
-
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-
- double aX, anY;
- PartSet_Tools::projectPointOnLine(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y(), theX, theY, aX, anY);
-
- aDelta = gp_Pnt(theX, theY, 0).Distance(gp_Pnt(aX, anY, 0));
+ std::string aKind = theFeature->getKind();
+ if (aKind == PartSet_FeatureLinePrs::getKind()) {
+ aDelta = PartSet_FeatureLinePrs::distanceToPoint(theFeature, theX, theY);
+ }
+ else if (aKind == PartSet_FeaturePointPrs::getKind()) {
+ aDelta = PartSet_FeaturePointPrs::distanceToPoint(theFeature, theX, theY);
+ }
+ else if (aKind == PartSet_FeatureCirclePrs::getKind()) {
+ aDelta = PartSet_FeatureCirclePrs::distanceToPoint(theFeature, theX, theY);
+ }
return aDelta;
}
aFeature->execute();
}
-void PartSet_Tools::getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
- double& theX, double& theY)
-{
- if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
- return;
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
- theX = aPoint->x();
- theY = aPoint->y();
-}
-
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findPoint(FeaturePtr theFeature,
double theX, double theY)
{
if (!theFeature)
return aPoint2D;
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- if (theFeature->getKind() == SKETCH_LINE_KIND)
- {
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
- if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
- aPoint2D = aPoint;
- else {
- aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
- if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
- aPoint2D = aPoint;
- }
+ std::string aKind = theFeature->getKind();
+ if (aKind == PartSet_FeatureLinePrs::getKind()) {
+ aPoint2D = PartSet_FeatureLinePrs::findPoint(theFeature, theX, theY);
}
- else if (theFeature->getKind() == SKETCH_POINT_KIND)
- {
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
- if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
- aPoint2D = aPoint;
+ else if (aKind == PartSet_FeaturePointPrs::getKind()) {
+ aPoint2D = PartSet_FeaturePointPrs::findPoint(theFeature, theX, theY);
}
- else if (theFeature->getKind() == SKETCH_CIRCLE_KIND)
- {
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
- if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
- aPoint2D = aPoint;
+ else if (aKind == PartSet_FeatureCirclePrs::getKind()) {
+ aPoint2D = PartSet_FeatureCirclePrs::findPoint(theFeature, theX, theY);
}
return aPoint2D;
boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
- /// \brief Get the line point 2d coordinates.
- /// \param theFeature the line feature
- /// \param theAttribute the start or end attribute of the line
- /// \param theX the horizontal coordinate
- /// \param theY the vertical coordinate
- static void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
- double& theX, double& theY);
/// Find a point in the line with given coordinates
/// \param theFeature the line feature
/// \param theX the horizontal point coordinate