The PartSet presentation's functionality should be partially moved to SketchPlugin and a custom widget creation.
1. distanceToPoint method is moved to the sketch plugin feature.
return SM_FirstPoint;
}
-double PartSet_ConstraintDistancePrs::distanceToPoint(FeaturePtr theFeature,
- double theX, double theY)
-{
- return 0;
-}
-
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_ConstraintDistancePrs::findPoint(FeaturePtr theFeature,
double theX, double theY)
{
/// \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
- virtual 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
return SM_FirstPoint;
}
-double PartSet_ConstraintLengthPrs::distanceToPoint(FeaturePtr theFeature,
- double theX, double theY)
-{
- return 0;
-}
-
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_ConstraintLengthPrs::findPoint(FeaturePtr theFeature,
double theX, double theY)
{
/// \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
- virtual 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
return SM_FirstPoint;
}
-double PartSet_ConstraintRadiusPrs::distanceToPoint(FeaturePtr theFeature,
- double theX, double theY)
-{
- return 0;
-}
-
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_ConstraintRadiusPrs::findPoint(FeaturePtr theFeature,
double theX, double theY)
{
/// \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
- virtual 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
return aMode;
}
-double PartSet_FeatureArcPrs::distanceToPoint(FeaturePtr theFeature,
- double theX, double theY)
-{
- double aDelta = 0;
- if (!theFeature || theFeature->getKind() != getKind())
- return aDelta;
- boost::shared_ptr<GeomAPI_Pnt2d> aPoint2d(new GeomAPI_Pnt2d(theX, theY));
-
-
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
- aDelta = aPoint1->pnt()->distance(aPoint2d);
-
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
- aDelta = qMin(aDelta, aPoint2->pnt()->distance(aPoint2d));
-
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
- aDelta = qMin(aDelta, aPoint3->pnt()->distance(aPoint2d));
-
- return aDelta;
-}
-
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureArcPrs::findPoint(FeaturePtr theFeature,
double theX, double theY)
{
static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, 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
- virtual 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
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)
{
/// \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
- virtual 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
}
}
-double PartSet_FeatureLinePrs::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> 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));
-
- GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y());
- boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
-
- if (false/*projection*/) { // TODO: if it has not been necessary, remove this block
- boost::shared_ptr<GeomAPI_Pnt2d> aResult = aLin2d.project(aPoint);
- aDelta = aResult->distance(aPoint);
- }
- else { // distance
- aDelta = aLin2d.distance(aPoint);
- }
-
- return aDelta;
-}
-
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLinePrs::findPoint(FeaturePtr theFeature,
double theX, double theY)
{
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
- virtual 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
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)
{
/// \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
- virtual 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
/// \return next attribute selection mode
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const = 0;
- /// 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
- virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY) = 0;
-
/// Find a point in the line with given coordinates
/// \param theFeature the line feature
/// \param theX the horizontal point coordinate
aPrs = *anIt;
if (!aPrs.feature())
continue;
- double aDelta = distanceToPoint(aPrs.feature(), aX, anY);
+ boost::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(aPrs.feature());
+ if (!aSketchFeature)
+ continue;
+ double aDelta = aSketchFeature->distanceToPoint(
+ boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
if (aMinDelta < 0 || aMinDelta > aDelta) {
aMinDelta = aDelta;
aDeltaFeature = aPrs.feature();
return aDeltaFeature;
}
-double PartSet_Tools::distanceToPoint(FeaturePtr theFeature,
- double theX, double theY)
-{
- boost::shared_ptr<PartSet_FeaturePrs> aFeaturePrs = PartSet_Tools::createFeaturePrs(
- theFeature->getKind(), FeaturePtr(), theFeature);
- double aDelta = 0;
- if (aFeaturePrs)
- aDelta = aFeaturePrs->distanceToPoint(theFeature, theX, theY);
-
- return aDelta;
-}
-
boost::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
{
return ModelAPI_PluginManager::get()->rootDocument();
/// \param theKind a feature kind
/// \return the boolean value
static bool isConstraintFeature(const std::string& theKind);
-
-private:
- /// 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);
};
#endif
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <GeomAPI_Pnt2d.h>
+
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
aPoint3->setValue(aPoint3->x() + theDeltaX, aPoint3->y() + theDeltaY);
}
+
+double SketchPlugin_Arc::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ double aDelta = 0;
+ boost::shared_ptr<ModelAPI_Data> aData = data();
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+ aDelta = aPoint1->pnt()->distance(thePoint);
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+ double aDistance = aPoint2->pnt()->distance(thePoint);
+ if (aDelta < aDistance)
+ aDelta = aDistance;
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
+ aDistance = aPoint3->pnt()->distance(thePoint);
+ if (aDelta < aDistance)
+ aDelta = aDistance;
+
+ return aDelta;
+}
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+ /// Return the distance between the feature and the point
+ /// \param thePoint the point
+ virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
/// Use plugin manager for features creation
SketchPlugin_Arc();
};
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <GeomAPI_Pnt2d.h>
+
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
}
+
+double SketchPlugin_Circle::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+
+ return aPoint->pnt()->distance(thePoint);
+}
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+ /// Return the distance between the feature and the point
+ /// \param thePoint the point
+ virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
/// Use plugin manager for features creation
SketchPlugin_Circle();
};
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
+ /// Return the distance between the feature and the point
+ /// \param thePoint the point
+ virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) { return 0; };
+
protected:
/// \brief Use plugin manager for features creation
SketchPlugin_Constraint() {}
#include <GeomAPI_Shape.h>
class SketchPlugin_Sketch;
+class GeomAPI_Pnt2d;
/**\class SketchPlugin_Feature
* \ingroup DataModel
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) = 0;
+ /// Return the distance between the feature and the point
+ /// \param thePoint the point
+ virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
+
protected:
/// Set the shape to the internal preview field
/// \param theShape a preview shape
#include "SketchPlugin_Line.h"
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pnt2d.h>
+
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomDataAPI_Point2D.h>
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY);
}
+
+double SketchPlugin_Line::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ double aDelta = 0;
+
+ boost::shared_ptr<ModelAPI_Data> aData = 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));
+
+ GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y());
+
+ if (false/*projection*/) { // TODO: if it has not been necessary, remove this block
+ boost::shared_ptr<GeomAPI_Pnt2d> aResult = aLin2d.project(thePoint);
+ aDelta = aResult->distance(thePoint);
+ }
+ else { // distance
+ aDelta = aLin2d.distance(thePoint);
+ }
+
+ return aDelta;
+}
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+ /// Return the distance between the feature and the point
+ /// \param thePoint the point
+ virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
/// Use plugin manager for features creation
SketchPlugin_Line();
};
#include "SketchPlugin_Point.h"
#include "SketchPlugin_Sketch.h"
+
#include <ModelAPI_Data.h>
+
+#include <GeomAPI_Pnt2d.h>
+
#include <GeomDataAPI_Point2D.h>
#include <GeomAlgoAPI_PointBuilder.h>
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
}
+
+double SketchPlugin_Point::distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
+
+ return aPoint->pnt()->distance(thePoint);
+}
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+ /// Return the distance between the feature and the point
+ /// \param thePoint the point
+ virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
/// Use plugin manager for features creation
SketchPlugin_Point();
};
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
+ /// Return the distance between the feature and the point
+ /// \param thePoint the point
+ virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) { return 0; };
+
/// Converts a 2D sketch space point into point in 3D space
SKETCHPLUGIN_EXPORT boost::shared_ptr<GeomAPI_Pnt> to3D(
const double theX, const double theY);