#include <SketchPlugin_Arc.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Circ2d.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
+#include <V3d_View.hxx>
+
#include <Precision.hxx>
using namespace std;
{
}
+std::string PartSet_FeatureArcPrs::getKind()
+{
+ return SKETCH_ARC_KIND;
+}
+
PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY,
const PartSet_SelectionMode& theMode)
{
}
break;
case SM_ThirdPoint: {
- PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_END);
- aMode = SM_DonePoint;
+ PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_END);
+ aMode = SM_DonePoint;
}
break;
default:
return aMode;
}
+void PartSet_FeatureArcPrs::move(double theDeltaX, double theDeltaY)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ if (!aData->isValid())
+ return;
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_CENTER));
+ aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+ aPoint2->setValue(aPoint2->x() + theDeltaX, aPoint2->y() + theDeltaY);
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint3 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
+ aPoint1->setValue(aPoint3->x() + theDeltaX, aPoint3->y() + theDeltaY);
+}
+
+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)
+{
+ 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(ARC_ATTR_CENTER));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
+ fabs(aPoint->y() - theY) < Precision::Confusion()) {
+ aPoint2D = aPoint;
+ }
+ if (!aPoint2D) {
+ aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_START));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
+ fabs(aPoint->y() - theY) < Precision::Confusion())
+ aPoint2D = aPoint;
+ }
+ if (!aPoint2D) {
+ aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(ARC_ATTR_END));
+ if (fabs(aPoint->x() - theX) < Precision::Confusion() &&
+ fabs(aPoint->y() - theY) < Precision::Confusion())
+ aPoint2D = aPoint;
+ }
+ return aPoint2D;
+}
+
+void PartSet_FeatureArcPrs::projectPointOnArc(gp_Pnt& thePoint, Handle(V3d_View) theView,
+ double& theX, double& theY)
+{
+ FeaturePtr aSketch = sketch();
+ if (aSketch) {
+ double aX, anY;
+ PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY);
+
+ // circle origin point and radius
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aCenter = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(ARC_ATTR_CENTER));
+ boost::shared_ptr<GeomDataAPI_Point2D> aStart = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(ARC_ATTR_START));
+
+ boost::shared_ptr<GeomAPI_Circ2d> aCirc(new GeomAPI_Circ2d(aCenter->pnt(), aStart->pnt()));
+ boost::shared_ptr<GeomAPI_Pnt2d> aGeomPoint2d(new GeomAPI_Pnt2d(aX, anY));
+ boost::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aCirc->project(aGeomPoint2d);
+ if (aPnt2d) {
+ theX = aPnt2d->x();
+ theY = aPnt2d->y();
+ }
+ }
+}
+
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureArcPrs::featurePoint
(const PartSet_SelectionMode& theMode)
{