From 575552af0d56b268d9cdd1ddd423365f99b95d77 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 9 Jun 2014 10:48:14 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc Arc feature inital creation. Preview draft --- src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp | 19 +++++++ src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h | 7 +++ src/PartSet/PartSet_Constants.h | 1 + src/PartSet/PartSet_FeatureArcPrs.cpp | 52 ++++++++----------- src/PartSet/PartSet_FeatureArcPrs.h | 4 -- src/PartSet/PartSet_FeatureLinePrs.cpp | 28 ++++++++++ src/PartSet/PartSet_FeatureLinePrs.h | 15 ++++++ .../PartSet_OperationCreateFeature.cpp | 36 ++++--------- src/SketchPlugin/SketchPlugin_Arc.cpp | 42 ++++++++++++++- src/SketchPlugin/SketchPlugin_Circle.cpp | 23 ++++---- 10 files changed, 153 insertions(+), 74 deletions(-) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp index 57afd7a69..514374749 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp @@ -45,3 +45,22 @@ boost::shared_ptr GeomAlgoAPI_EdgeBuilder::lineCircle( aRes->setImpl(new TopoDS_Shape(anEdge)); return aRes; } + +boost::shared_ptr GeomAlgoAPI_EdgeBuilder::lineCircleArc( + boost::shared_ptr theCenter, + boost::shared_ptr theStartPoint, + boost::shared_ptr theEndPoint, + boost::shared_ptr theNormal) +{ + const gp_Pnt& aCenter = theCenter->impl(); + const gp_Dir& aDir = theNormal->impl(); + + double aRadius = theCenter->distance(theStartPoint); + gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius); + + BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle); + boost::shared_ptr aRes(new GeomAPI_Shape); + TopoDS_Edge anEdge = anEdgeBuilder.Edge(); + aRes->setImpl(new TopoDS_Shape(anEdge)); + return aRes; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h index b7f527230..de532ea56 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h @@ -27,6 +27,13 @@ public: static boost::shared_ptr lineCircle( boost::shared_ptr theCenter, boost::shared_ptr theNormal, double theRadius); + + /// Creates linear edge in a form of a circle arc by a three points + static boost::shared_ptr lineCircleArc( + boost::shared_ptr theCenter, + boost::shared_ptr theStartPoint, + boost::shared_ptr theEndPoint, + boost::shared_ptr theNormal); }; #endif diff --git a/src/PartSet/PartSet_Constants.h b/src/PartSet/PartSet_Constants.h index 95b28bd00..141e25bde 100644 --- a/src/PartSet/PartSet_Constants.h +++ b/src/PartSet/PartSet_Constants.h @@ -14,6 +14,7 @@ enum PartSet_SelectionMode { SM_FirstPoint, SM_SecondPoint, + SM_ThirdPoint, SM_DonePoint }; diff --git a/src/PartSet/PartSet_FeatureArcPrs.cpp b/src/PartSet/PartSet_FeatureArcPrs.cpp index 024d911d2..4cc26f008 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.cpp +++ b/src/PartSet/PartSet_FeatureArcPrs.cpp @@ -7,9 +7,7 @@ #include #include -#include -#include -#include +#include #include @@ -27,24 +25,6 @@ PartSet_FeatureArcPrs::PartSet_FeatureArcPrs(FeaturePtr theSketch) { } -void PartSet_FeatureArcPrs::initFeature(FeaturePtr theFeature) -{ - if (feature() && theFeature) - { - // use the last point of the previous feature as the first of the new one - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr anInitPoint = boost::dynamic_pointer_cast - (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 aPoint = boost::dynamic_pointer_cast - (aData->attribute(LINE_ATTR_START)); - PartSet_Tools::createConstraint(sketch(), anInitPoint, aPoint); - } -} - PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY, const PartSet_SelectionMode& theMode) { @@ -52,13 +32,17 @@ PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY, 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, ARC_ATTR_CENTER); aMode = SM_SecondPoint; } break; case SM_SecondPoint: { - PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END); + PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_START); + aMode = SM_ThirdPoint; + } + break; + case SM_ThirdPoint: { + PartSet_Tools::setFeaturePoint(feature(), theX, theY, ARC_ATTR_END); aMode = SM_DonePoint; } break; @@ -74,10 +58,13 @@ std::string PartSet_FeatureArcPrs::getAttribute(const PartSet_SelectionMode& the switch (theMode) { case SM_FirstPoint: - aAttribute = LINE_ATTR_START; + aAttribute = ARC_ATTR_CENTER; break; case SM_SecondPoint: - aAttribute = LINE_ATTR_END; + aAttribute = ARC_ATTR_START; + break; + case SM_ThirdPoint: + aAttribute = ARC_ATTR_END; break; default: break; @@ -89,9 +76,11 @@ PartSet_SelectionMode PartSet_FeatureArcPrs::getNextMode(const std::string& theA { PartSet_SelectionMode aMode; - if (theAttribute == LINE_ATTR_START) + if (theAttribute == ARC_ATTR_CENTER) aMode = SM_SecondPoint; - else if (theAttribute == LINE_ATTR_END) + else if (theAttribute == ARC_ATTR_START) + aMode = SM_ThirdPoint; + else if (theAttribute == ARC_ATTR_END) aMode = SM_DonePoint; return aMode; } @@ -103,10 +92,13 @@ boost::shared_ptr PartSet_FeatureArcPrs::featurePoint switch (theMode) { case SM_FirstPoint: - aPointArg = LINE_ATTR_START; + aPointArg = ARC_ATTR_CENTER; break; case SM_SecondPoint: - aPointArg = LINE_ATTR_END; + aPointArg = ARC_ATTR_START; + break; + case SM_ThirdPoint: + aPointArg = ARC_ATTR_END; break; default: break; diff --git a/src/PartSet/PartSet_FeatureArcPrs.h b/src/PartSet/PartSet_FeatureArcPrs.h index b0807db84..ea25b971f 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.h +++ b/src/PartSet/PartSet_FeatureArcPrs.h @@ -45,10 +45,6 @@ public: 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 featurePoint(const PartSet_SelectionMode& theMode); diff --git a/src/PartSet/PartSet_FeatureLinePrs.cpp b/src/PartSet/PartSet_FeatureLinePrs.cpp index 5e67aaeee..d6200d576 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.cpp +++ b/src/PartSet/PartSet_FeatureLinePrs.cpp @@ -19,6 +19,7 @@ #include #include +#include using namespace std; @@ -96,6 +97,33 @@ PartSet_SelectionMode PartSet_FeatureLinePrs::getNextMode(const std::string& the return aMode; } +void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature, + const PartSet_SelectionMode& theMode, + const gp_Pnt& thePoint, Handle(V3d_View) theView, + double& theX, double& theY) +{ + 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); + PartSet_Tools::convertTo2D(thePoint, sketch(), theView, X1, Y1); + + switch (theMode) { + case SM_FirstPoint: + PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, theX, theY); + break; + case SM_SecondPoint: { + PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0); + PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, theX, theY); + } + break; + default: + break; + } + } +} + boost::shared_ptr PartSet_FeatureLinePrs::featurePoint (const PartSet_SelectionMode& theMode) { diff --git a/src/PartSet/PartSet_FeatureLinePrs.h b/src/PartSet/PartSet_FeatureLinePrs.h index b94e40265..eefced5e5 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.h +++ b/src/PartSet/PartSet_FeatureLinePrs.h @@ -10,7 +10,10 @@ #include "PartSet_FeaturePrs.h" #include "PartSet_Constants.h" +#include + class GeomDataAPI_Point2D; +class Handle_V3d_View; /*! \class PartSet_FeatureLinePrs @@ -44,6 +47,18 @@ public: /// \return next attribute selection mode virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; + + /// Project the point on a feature + /// \param theFeature the feature to be projected on + /// \param theMode the selection mode + /// \param thePoint the clicked point + /// \param theView the viewer + /// \param theX the output horizontal coordinate + /// \param theY the output vertical coordinate + void projectPointOnLine(FeaturePtr theFeature, const PartSet_SelectionMode& theMode, + const gp_Pnt& thePoint, Handle_V3d_View theView, + double& theX, double& theY); + protected: /// Initializes current feature by the given /// \param theSourceFeature the feature, which attributes are used to initialize the current feature diff --git a/src/PartSet/PartSet_OperationCreateFeature.cpp b/src/PartSet/PartSet_OperationCreateFeature.cpp index 2bfa875d6..4c117b3eb 100644 --- a/src/PartSet/PartSet_OperationCreateFeature.cpp +++ b/src/PartSet/PartSet_OperationCreateFeature.cpp @@ -115,11 +115,9 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle double aX, anY; - bool isFoundPoint = false; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); if (theSelected.empty()) { PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); - isFoundPoint = true; } else { XGUI_ViewerPrs aPrs = theSelected.front(); @@ -131,7 +129,6 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle if (!aVertex.IsNull()) { aPoint = BRep_Tool::Pnt(aVertex); PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); - isFoundPoint = true; myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode); } @@ -139,31 +136,14 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected { PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); - isFoundPoint = true; - /* - FeaturePtr aFeature = aPrs.feature(); - if (aFeature) { - double X0, X1, X2, X3; - double Y0, Y1, Y2, Y3; - PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_START, X2, Y2); - PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_END, X3, Y3); - PartSet_Tools::convertTo2D(aPoint, sketch(), theView, X1, Y1); - - switch (myPointSelectionMode) { - case SM_FirstPoint: - PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY); - break; - case SM_SecondPoint: { - PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0); - PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY); - } - break; - default: - break; + // move to selected line + if (feature()->getKind() == SKETCH_LINE_KIND) { + PartSet_FeatureLinePrs* aLinePrs = dynamic_cast(myFeaturePrs); + if (aLinePrs) { + FeaturePtr aFeature = aPrs.feature(); + aLinePrs->projectPointOnLine(aFeature, myPointSelectionMode, aPoint, theView, aX, anY); } - isFoundPoint = true; } - */ } } } @@ -171,7 +151,8 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle switch (myPointSelectionMode) { case SM_FirstPoint: - case SM_SecondPoint: { + case SM_SecondPoint: + case SM_ThirdPoint: { PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode); flushUpdated(); setPointSelectionMode(aMode); @@ -188,6 +169,7 @@ void PartSet_OperationCreateFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3 { case SM_FirstPoint: case SM_SecondPoint: + case SM_ThirdPoint: { double aX, anY; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index ed5275b00..1830a0058 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -5,7 +5,13 @@ #include "SketchPlugin_Arc.h" #include "SketchPlugin_Sketch.h" #include + #include +#include + +#include +#include +#include SketchPlugin_Arc::SketchPlugin_Arc() : SketchPlugin_Feature() @@ -25,6 +31,40 @@ void SketchPlugin_Arc::execute() const boost::shared_ptr& SketchPlugin_Arc::preview() { - /// \todo Implement preview for arc of circle + SketchPlugin_Sketch* aSketch = sketch(); + if (aSketch) { + std::list > aShapes; + + // compute a circle point in 3D view + boost::shared_ptr aCenterAttr = + boost::dynamic_pointer_cast(data()->attribute(ARC_ATTR_CENTER)); + boost::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); + // make a visible point + boost::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); + aShapes.push_back(aCenterPointShape); + + // make a visible circle + boost::shared_ptr aNDir = + boost::dynamic_pointer_cast(aSketch->data()->attribute(SKETCH_ATTR_NORM)); + bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0); + if (aHasPlane) { + boost::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); + // compute the arc start point + boost::shared_ptr aStartAttr = + boost::dynamic_pointer_cast(data()->attribute(ARC_ATTR_START)); + boost::shared_ptr aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); + + // compute the arc end point + boost::shared_ptr anEndAttr = + boost::dynamic_pointer_cast(data()->attribute(ARC_ATTR_END)); + boost::shared_ptr aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); + + boost::shared_ptr aCircleShape = + GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStartPoint, aEndPoint, aNormal); + aShapes.push_back(aCircleShape); + } + boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); + setPreview(aCompound); + } return getPreview(); } diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index af26e9230..d58a58dd7 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -5,11 +5,13 @@ #include "SketchPlugin_Circle.h" #include "SketchPlugin_Sketch.h" #include + #include +#include + #include #include #include -#include #include @@ -32,17 +34,12 @@ const boost::shared_ptr& SketchPlugin_Circle::preview() { SketchPlugin_Sketch* aSketch = sketch(); if (aSketch) { + std::list > aShapes; + // compute a circle point in 3D view boost::shared_ptr aCenterAttr = boost::dynamic_pointer_cast(data()->attribute(CIRCLE_ATTR_CENTER)); boost::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); - - // compute the circle radius - boost::shared_ptr aRadiusAttr = - boost::dynamic_pointer_cast(data()->attribute(CIRCLE_ATTR_RADIUS)); - double aRadius = aRadiusAttr->value(); - - std::list > aShapes; // make a visible point boost::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); aShapes.push_back(aCenterPointShape); @@ -53,15 +50,17 @@ const boost::shared_ptr& SketchPlugin_Circle::preview() bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0); if (aHasPlane) { boost::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); + // compute the circle radius + boost::shared_ptr aRadiusAttr = + boost::dynamic_pointer_cast(data()->attribute(CIRCLE_ATTR_RADIUS)); + double aRadius = aRadiusAttr->value(); boost::shared_ptr aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius); aShapes.push_back(aCircleShape); - - boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); - setPreview(aCompound); } + boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); + setPreview(aCompound); } - /// \todo Implement preview for the circle return getPreview(); } -- 2.39.2