From 9fa90624eab8ca53b895fd42c1894bdb0302ff7c Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 20 May 2014 10:33:31 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Set end point to the start point in created line at the beginning. --- src/PartSet/PartSet_OperationSketchLine.cpp | 17 +++++++++++------ src/PartSet/PartSet_OperationSketchLine.h | 4 +++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index c5ac31a6f..e1c31afd1 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -140,12 +140,13 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 switch (myPointSelectionMode) { case SM_FirstPoint: { - setLinePoint(aX, anY, LINE_ATTR_START); + setLinePoint(feature(), aX, anY, LINE_ATTR_START); + setLinePoint(feature(), aX, anY, LINE_ATTR_END); myPointSelectionMode = SM_SecondPoint; } break; case SM_SecondPoint: { - setLinePoint(aX, anY, LINE_ATTR_END); + setLinePoint(feature(), aX, anY, LINE_ATTR_END); commit(); emit featureConstructed(feature(), FM_Deactivation); emit launchOperation(PartSet_OperationSketchLine::Type(), feature()); @@ -217,11 +218,12 @@ boost::shared_ptr PartSet_OperationSketchLine::createFeature() aFeature->addSub(aNewFeature); } if (myInitPoint) { + setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START); + setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END); + boost::shared_ptr aData = aNewFeature->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast (aData->attribute(LINE_ATTR_START)); - aPoint->setValue(myInitPoint->x(), myInitPoint->y()); - createConstraint(myInitPoint, aPoint); } @@ -320,10 +322,13 @@ boost::shared_ptr PartSet_OperationSketchLine::findLinePoin return aPoint2D; } -void PartSet_OperationSketchLine::setLinePoint(double theX, double theY, +void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr theFeature, + double theX, double theY, const std::string& theAttribute) { - boost::shared_ptr aData = feature()->data(); + if (!theFeature) + return; + boost::shared_ptr aData = theFeature->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(theAttribute)); aPoint->setValue(theX, theY); diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index fa5f12938..e6cabaa88 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -115,10 +115,12 @@ protected: double theX, double theY); /// \brief Save the point to the line. + /// \param theFeature the line feature /// \param theX the horizontal coordinate /// \param theY the vertical coordinate /// \param theAttribute the start or end attribute of the line - void setLinePoint(double theX, double theY, const std::string& theAttribute); + void setLinePoint(boost::shared_ptr, double theX, double theY, + const std::string& theAttribute); /// \brief Save the point to the line. /// \param thePoint the 3D point in the viewer /// \param theAttribute the start or end attribute of the line -- 2.39.2