From 9a1e4f21efdff0f230fcb77bb618a2329a62075f Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 13 May 2014 16:27:26 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Create constraint on selected point. Search features contained this point and create constraints with them. --- src/PartSet/PartSet_OperationSketchLine.cpp | 67 ++++++++++++++++++++- src/PartSet/PartSet_OperationSketchLine.h | 11 ++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 9235348a7..6baec986b 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -7,10 +7,13 @@ #include #include +#include + #include #include #include #include +#include #include @@ -53,7 +56,13 @@ bool PartSet_OperationSketchLine::isGranted() const std::list PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr theFeature) const { - return std::list(); + std::list aModes; + if (theFeature != feature()) + { + aModes.push_back(TopAbs_VERTEX); + aModes.push_back(TopAbs_EDGE); + } + return aModes; } void PartSet_OperationSketchLine::init(boost::shared_ptr theFeature) @@ -84,6 +93,8 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 if (!aVertex.IsNull()) { aPoint = BRep_Tool::Pnt(aVertex); PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY); + + setConstraints(aX, anY); } } else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected @@ -197,7 +208,7 @@ boost::shared_ptr PartSet_OperationSketchLine::createFeature() (aData->attribute(LINE_ATTR_START)); aPoint->setValue(myInitPoint->x(), myInitPoint->y()); - //createConstraint(myInitPoint, aPoint); + createConstraint(myInitPoint, aPoint); } emit featureConstructed(aNewFeature, FM_Activation); @@ -224,6 +235,37 @@ void PartSet_OperationSketchLine::createConstraint(boost::shared_ptrexecute(); } +void PartSet_OperationSketchLine::setConstraints(double theX, double theY) +{ + std::string aPointArg; + switch (myPointSelectionMode) + { + case SM_FirstPoint: + aPointArg = LINE_ATTR_START; + break; + case SM_SecondPoint: + aPointArg = LINE_ATTR_END; + break; + } + + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast + (aData->attribute(aPointArg)); + aData = mySketch->data(); + boost::shared_ptr aRefList = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_FEATURES)); + + std::list > aFeatures = aRefList->list(); + std::list >::const_iterator anIt = aFeatures.begin(), + aLast = aFeatures.end(); + for (; anIt != aLast; anIt++) { + boost::shared_ptr aFeature = *anIt; + boost::shared_ptr aFPoint = findLinePoint(aFeature, theX, theY); + if (aFPoint) + createConstraint(aFPoint, aPoint); + } +} + void PartSet_OperationSketchLine::getLinePoint(boost::shared_ptr theFeature, const std::string& theAttribute, double& theX, double& theY) @@ -237,6 +279,27 @@ void PartSet_OperationSketchLine::getLinePoint(boost::shared_ptry(); } +boost::shared_ptr PartSet_OperationSketchLine::findLinePoint( + boost::shared_ptr theFeature, + double theX, double theY) +{ + boost::shared_ptr aPoint2D; + if (!theFeature) + return aPoint2D; + boost::shared_ptr aData = theFeature->data(); + + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) + aPoint2D = aPoint; + else { + aPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) + aPoint2D = aPoint; + } + return aPoint2D; +} + void PartSet_OperationSketchLine::setLinePoint(double theX, double theY, const std::string& theAttribute) { diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index d92224aaa..c06462d7a 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -88,6 +88,10 @@ protected: void createConstraint(boost::shared_ptr thePoint1, boost::shared_ptr thePoint2); + /// Creates constrains of the current + /// \param theX the horizontal coordnate of the point + /// \param theY the vertical coordnate of the point + void setConstraints(double theX, double theY); protected: /// \brief Get the line point 2d coordinates. /// \param theFeature the line feature @@ -96,6 +100,13 @@ protected: /// \param theY the vertical coordinate void getLinePoint(boost::shared_ptr theFeature, const std::string& theAttribute, double& theX, double& theY); + /// Find a point in the line with given coordinates + /// \param theFeature the line feature + /// \param theX the horizontal point coordinate + /// \param theY the vertical point coordinate + boost::shared_ptr findLinePoint(boost::shared_ptr theFeature, + double theX, double theY); + /// \brief Save the point to the line. /// \param theX the horizontal coordinate /// \param theY the vertical coordinate -- 2.39.2