SET(PROJECT_HEADERS
GeomAPI.h
+ GeomAPI_Circ2d.h
GeomAPI_Interface.h
GeomAPI_XY.h
GeomAPI_XYZ.h
)
SET(PROJECT_SOURCES
+ GeomAPI_Circ2d.cpp
GeomAPI_Interface.cpp
GeomAPI_XY.cpp
GeomAPI_XYZ.cpp
--- /dev/null
+// File: GeomAPI_Circ2d.cpp
+// Created: 29 May 2014
+// Author: Artem ZHIDKOV
+
+#include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Pnt2d.h>
+
+#include <gp_Dir2d.hxx>
+#include <gp_Circ2d.hxx>
+#include <gp_Pnt2d.hxx>
+#include <gp_Ax2d.hxx>
+#include <Geom2d_Circle.hxx>
+#include <Geom2dAPI_ProjectPointOnCurve.hxx>
+#include <Precision.hxx>
+
+#include <IntAna2d_AnaIntersection.hxx>
+
+#define MY_CIRC2D static_cast<gp_Circ2d*>(myImpl)
+
+static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
+ const double thePointX, const double thePointY)
+{
+ gp_Pnt2d aCenter(theCenterX, theCenterY);
+ gp_Pnt2d aPoint(thePointX, thePointY);
+
+ double aRadius = aCenter.Distance(aPoint);
+
+ if (aCenter.IsEqual(aPoint, Precision::Confusion()))
+ return NULL;
+
+ gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY);
+ return new gp_Circ2d(gp_Ax2d(aCenter, aDir), aRadius);
+}
+
+
+GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+ const boost::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint)
+ : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(),
+ theCirclePoint->x(), theCirclePoint->y()))
+{}
+
+const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
+{
+ boost::shared_ptr<GeomAPI_Pnt2d> aResult;
+ if (!MY_CIRC2D)
+ return aResult;
+
+ Handle(Geom2d_Circle) aCircle = new Geom2d_Circle(MY_CIRC2D->Axis(), MY_CIRC2D->Radius());//(aCirc);
+
+ const gp_Pnt2d& aPoint = thePoint->impl<gp_Pnt2d>();
+
+ Geom2dAPI_ProjectPointOnCurve aProj(aPoint, aCircle);
+ Standard_Integer aNbPoint = aProj.NbPoints();
+ double aX, anY;
+ if (aNbPoint > 0) {
+ double aMinDistance = 0, aDistance;
+ for (Standard_Integer j = 1; j <= aNbPoint; j++) {
+ gp_Pnt2d aNewPoint = aProj.Point(j);
+ aDistance = aNewPoint.Distance(aPoint);
+ if (!aMinDistance || aDistance < aMinDistance) {
+ aX = aNewPoint.X();
+ anY = aNewPoint.Y();
+ aMinDistance = aDistance;
+ aResult = boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY));
+ }
+ }
+ }
+ return aResult;
+}
+
--- /dev/null
+// File: GeomAPI_Circ2d.h
+// Created: 29 May 2014
+// Author: Artem ZHIDKOV
+
+#ifndef GeomAPI_Circ2d_HeaderFile
+#define GeomAPI_Circ2d_HeaderFile
+
+#include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
+
+class GeomAPI_Pnt2d;
+
+/**\class GeomAPI_Circ2d
+ * \ingroup DataModel
+ * \brief Line in 2D
+ */
+
+class GEOMAPI_EXPORT GeomAPI_Circ2d: public GeomAPI_Interface
+{
+public:
+ /// Creation of circle defined by center point and circle radius
+ GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+ const boost::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint);
+
+ /// Project point on line
+ const boost::shared_ptr<GeomAPI_Pnt2d> project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
+};
+
+#endif
+
double aRadius = theCenter->distance(theStartPoint);
gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius);
- BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle);
+ const gp_Pnt& aStart = theStartPoint->impl<gp_Pnt>();
+ const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
+
+ BRepBuilderAPI_MakeEdge anEdgeBuilder;
+ if (aStart.IsEqual(anEnd, Precision::Confusion()) ||
+ gp_Pnt(0, 0, 0).IsEqual(anEnd, Precision::Confusion()))
+ anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle);
+ else
+ anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
+
boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
TopoDS_Edge anEdge = anEdgeBuilder.Edge();
aRes->setImpl(new TopoDS_Shape(anEdge));
#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;
}
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::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)
{
#include "PartSet_FeaturePrs.h"
#include "PartSet_Constants.h"
+#include <gp_Pnt.hxx>
+
class GeomDataAPI_Point2D;
+class Handle_V3d_View;
/*!
\class PartSet_FeatureArcPrs
/// \return next attribute selection mode
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+ void projectPointOnArc(gp_Pnt& thePoint, Handle_V3d_View theView,
+ 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
case SM_FirstPoint:
case SM_SecondPoint:
case SM_ThirdPoint: {
+ if (feature()->getKind() == SKETCH_ARC_KIND) {
+ PartSet_FeatureArcPrs* anArcPrs = dynamic_cast<PartSet_FeatureArcPrs*>(myFeaturePrs);
+ if (anArcPrs) {
+ anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
+ }
+ }
PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
flushUpdated();
setPointSelectionMode(aMode);
double aX, anY;
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+ if (myPointSelectionMode == SM_ThirdPoint) {
+ if (feature()->getKind() == SKETCH_ARC_KIND) {
+ PartSet_FeatureArcPrs* anArcPrs = dynamic_cast<PartSet_FeatureArcPrs*>(myFeaturePrs);
+ if (anArcPrs) {
+ anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
+ }
+ }
+ }
myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
flushUpdated();