Circle final creation.
#include <BRep_Tool.hxx>
#include <Geom_Plane.hxx>
+#include <gp_Ax2.hxx>
+#include <gp_Circ.hxx>
+
boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::line(
boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd)
{
aRes->setImpl(new TopoDS_Shape(anEdge));
return aRes;
}
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::lineCircle(
+ boost::shared_ptr<GeomAPI_Pnt> theCenter,
+ boost::shared_ptr<GeomAPI_Dir> theNormal, double theRadius)
+{
+ const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
+ const gp_Dir& aDir = theNormal->impl<gp_Dir>();
+
+ gp_Circ aCircle(gp_Ax2(aCenter, aDir), theRadius);
+
+ BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle);
+ boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+ TopoDS_Edge anEdge = anEdgeBuilder.Edge();
+ aRes->setImpl(new TopoDS_Shape(anEdge));
+ return aRes;
+}
#include <GeomAlgoAPI.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Dir.h>
#include <boost/shared_ptr.hpp>
/**\class GeomAlgoAPI_EdgeBuilder
/// Creates linear edge by two points
static boost::shared_ptr<GeomAPI_Shape> line(
boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd);
+
+ /// Creates linear edge in a form of a circle by a point and a circle radius
+ static boost::shared_ptr<GeomAPI_Shape> lineCircle(
+ boost::shared_ptr<GeomAPI_Pnt> theCenter,
+ boost::shared_ptr<GeomAPI_Dir> theNormal, double theRadius);
};
#endif
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_Line.h>
-#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_Circle.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt2d.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
{
}
-void PartSet_FeatureCirclePrs::initFeature(FeaturePtr theFeature)
-{
- if (feature() && theFeature)
- {
- // use the last point of the previous feature as the first of the new one
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> anInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aData->attribute(LINE_ATTR_END));
- PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START);
- PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END);
-
- aData = feature()->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aData->attribute(LINE_ATTR_START));
- PartSet_Tools::createConstraint(sketch(), anInitPoint, aPoint);
- }
-}
-
PartSet_SelectionMode PartSet_FeatureCirclePrs::setPoint(double theX, double theY,
- const PartSet_SelectionMode& theMode)
+ const PartSet_SelectionMode& theMode)
{
PartSet_SelectionMode aMode = theMode;
switch (theMode)
{
case SM_FirstPoint: {
- PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_START);
- PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END);
+ PartSet_Tools::setFeaturePoint(feature(), theX, theY, CIRCLE_ATTR_CENTER);
aMode = SM_SecondPoint;
}
break;
case SM_SecondPoint: {
- PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END);
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(CIRCLE_ATTR_CENTER));
+ boost::shared_ptr<GeomAPI_Pnt2d> aCoordPoint(new GeomAPI_Pnt2d(theX, theY));
+ double aRadius = aCoordPoint->distance(aPoint->pnt());
+ PartSet_Tools::setFeatureValue(feature(), aRadius, CIRCLE_ATTR_RADIUS);
+
aMode = SM_DonePoint;
}
break;
switch (theMode)
{
case SM_FirstPoint:
- aAttribute = LINE_ATTR_START;
+ aAttribute = CIRCLE_ATTR_CENTER;
break;
case SM_SecondPoint:
- aAttribute = LINE_ATTR_END;
+ aAttribute = CIRCLE_ATTR_RADIUS;
break;
default:
break;
{
PartSet_SelectionMode aMode;
- if (theAttribute == LINE_ATTR_START)
+ if (theAttribute == CIRCLE_ATTR_CENTER)
aMode = SM_SecondPoint;
- else if (theAttribute == LINE_ATTR_END)
+ else if (theAttribute == CIRCLE_ATTR_RADIUS)
aMode = SM_DonePoint;
return aMode;
}
switch (theMode)
{
case SM_FirstPoint:
- aPointArg = LINE_ATTR_START;
- break;
- case SM_SecondPoint:
- aPointArg = LINE_ATTR_END;
+ aPointArg = CIRCLE_ATTR_CENTER;
break;
default:
break;
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
protected:
- /// Initializes current feature by the given
- /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
- virtual void initFeature(FeaturePtr theSourceFeature);
-
/// 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);
{
}
-void PartSet_FeaturePointPrs::initFeature(FeaturePtr theFeature)
-{
-}
-
PartSet_SelectionMode PartSet_FeaturePointPrs::setPoint(double theX, double theY,
const PartSet_SelectionMode& theMode)
{
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
protected:
- /// Initializes current feature by the given
- /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
- virtual void initFeature(FeaturePtr theSourceFeature);
-
/// 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);
/// Initializes current feature by the given
/// \param theSourceFeature the feature, which attributes are used to initialize the current feature
- virtual void initFeature(FeaturePtr theSourceFeature) = 0;
+ virtual void initFeature(FeaturePtr theSourceFeature) {};
/// Returns the feature point in the selection mode position.
/// \param theMode the current operation selection mode. The feature attribute depends on the mode
aPoint->setValue(theX, theY);
}
+void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue,
+ const std::string& theAttribute)
+{
+ if (!theFeature)
+ return;
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeDouble> anAttribute =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(theAttribute));
+ if (anAttribute)
+ anAttribute->setValue(theValue);
+}
+
void PartSet_Tools::createConstraint(FeaturePtr theSketch,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
aPoint2D = aPoint;
}
+
return aPoint2D;
}
/// \param theX the horizontal coordinate
/// \param theY the vertical coordinate
/// \param theAttribute the feature attribute
- static void setFeaturePoint(FeaturePtr, double theX, double theY, const std::string& theAttribute);
+ static void setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
+ const std::string& theAttribute);
- /// Creates a constraint on two points
+ /// \brief Save the double to the feature. If the attribute is double, it is filled.
+ /// \param theFeature the feature
+ /// \param theValue the horizontal coordinate
+ /// \param theAttribute the feature attribute
+ static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
+
+ /// Creates a constraint on two points
/// \param thePoint1 the first point
/// \param thePoint1 the second point
static void createConstraint(FeaturePtr theSketch,
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomDataAPI_Dir.h>
+
#include <ModelAPI_AttributeDouble.h>
SketchPlugin_Circle::SketchPlugin_Circle()
const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Circle::preview()
{
+ SketchPlugin_Sketch* aSketch = sketch();
+ if (aSketch) {
+ // compute a circle point in 3D view
+ boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CIRCLE_ATTR_CENTER));
+ boost::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+
+ // compute the circle radius
+ boost::shared_ptr<ModelAPI_AttributeDouble> aRadiusAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CIRCLE_ATTR_RADIUS));
+ double aRadius = aRadiusAttr->value();
+
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aShapes;
+ // make a visible point
+ boost::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+ aShapes.push_back(aCenterPointShape);
+
+ // make a visible circle
+ boost::shared_ptr<GeomDataAPI_Dir> aNDir =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->data()->attribute(SKETCH_ATTR_NORM));
+ bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
+ if (aHasPlane) {
+ boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
+
+ boost::shared_ptr<GeomAPI_Shape> aCircleShape =
+ GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius);
+ aShapes.push_back(aCircleShape);
+
+ boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+ setPreview(aCompound);
+ }
+ }
/// \todo Implement preview for the circle
return getPreview();
}
const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Point::preview()
{
SketchPlugin_Sketch* aSketch = sketch();
- // compute a point in 3D view
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(POINT_ATTR_COORD));
- boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
- // make a visible point
- boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
- setPreview(aPointShape);
-
+ if (aSketch) {
+ // compute a point in 3D view
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(POINT_ATTR_COORD));
+ boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
+ // make a visible point
+ boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
+ setPreview(aPointShape);
+ }
return getPreview();
}