X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OperationSketchLine.cpp;h=03912db526aef928e604e76ae73206545d818dee;hb=4a417f26297d6a29659acaae76676cc633fed169;hp=21f09e9c1f125e3004b8dbb6a4f78e6fde177541;hpb=8de33e2487eed6e3aded5c2b086bd2d8b6e36f55;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 21f09e9c1..03912db52 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -4,20 +4,31 @@ #include +#include + #include #include -#include -#include #include #include -#include +#include +#include + +#include + #include +#include +#include +#include +#include + #ifdef _DEBUG #include #endif +#include + using namespace std; PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId, @@ -39,28 +50,71 @@ bool PartSet_OperationSketchLine::isGranted() const std::list PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr theFeature) const { - std::list aModes; - if (theFeature != feature()) - aModes.push_back(TopAbs_VERTEX); - return aModes; + return std::list(); } -void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint) +void PartSet_OperationSketchLine::init(boost::shared_ptr theFeature) { + if (!theFeature) + return; + // use the last point of the previous feature as the first of the new one + boost::shared_ptr aData = theFeature->data(); + myInitPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); +} + +void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected) +{ + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); + + if (!theSelected.empty()) { + XGUI_ViewerPrs aPrs = theSelected.front(); + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) { + if (aShape.ShapeType() == TopAbs_VERTEX) { + const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); + if (!aVertex.IsNull()) + aPoint = BRep_Tool::Pnt(aVertex); + } + else if (aShape.ShapeType() == TopAbs_EDGE) { + boost::shared_ptr aFeature = aPrs.feature(); + if (!aFeature) + return; + double X0, X1, X2, X3; + double Y0, Y1, Y2, Y3; + getLinePoint(aFeature, LINE_ATTR_START, X2, Y2); + getLinePoint(aFeature, LINE_ATTR_END, X3, Y3); + + if (myPointSelectionMode == SM_SecondPoint) { + getLinePoint(feature(), LINE_ATTR_START, X0, Y0); + PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, X1, Y1); + + double aX, anY; + PartSet_Tools::IntersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY); + + setLinePoint(aX, anY, LINE_ATTR_END); + commit(); + emit featureConstructed(feature(), FM_Deactivation); + emit launchOperation(PartSet_OperationSketchLine::Type(), feature()); + return; + } + + } + } + } + switch (myPointSelectionMode) { case SM_FirstPoint: { - setLinePoint(thePoint, LINE_ATTR_START); + setLinePoint(aPoint, theView, LINE_ATTR_START); myPointSelectionMode = SM_SecondPoint; } break; case SM_SecondPoint: { - setLinePoint(thePoint, LINE_ATTR_END); - myPointSelectionMode = SM_None; - } - break; - case SM_None: { - + setLinePoint(aPoint, theView, LINE_ATTR_END); + commit(); + emit featureConstructed(feature(), FM_Deactivation); + emit launchOperation(PartSet_OperationSketchLine::Type(), feature()); } break; default: @@ -68,27 +122,14 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint) } } -void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint) +void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) { switch (myPointSelectionMode) { case SM_SecondPoint: - setLinePoint(thePoint, LINE_ATTR_END); - break; - case SM_None: { - boost::shared_ptr aPrevFeature = feature(); - // stop the last operation - commitOperation(); - document()->finishOperation(); - //emit changeSelectionMode(aPrevFeature, TopAbs_VERTEX); - // start a new operation - document()->startOperation(); - startOperation(); - // use the last point of the previous feature as the first of the new one - setLinePoint(aPrevFeature, LINE_ATTR_END, LINE_ATTR_START); - myPointSelectionMode = SM_SecondPoint; - - emit featureConstructed(aPrevFeature, FM_Deactivation); + { + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); + setLinePoint(aPoint, theView, LINE_ATTR_END); } break; default: @@ -100,19 +141,12 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey) { switch (theKey) { case Qt::Key_Escape: { - if (myPointSelectionMode != SM_None) - emit featureConstructed(feature(), FM_Abort); abort(); } break; case Qt::Key_Return: { - if (myPointSelectionMode != SM_None) { - emit featureConstructed(feature(), FM_Abort); - myPointSelectionMode = SM_FirstPoint; - document()->abortOperation(); - } - else - myPointSelectionMode = SM_FirstPoint; + abort(); + emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr()); } break; default: @@ -123,73 +157,72 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey) void PartSet_OperationSketchLine::startOperation() { PartSet_OperationSketchBase::startOperation(); - myPointSelectionMode = SM_FirstPoint; + myPointSelectionMode = !myInitPoint ? SM_FirstPoint : SM_SecondPoint; + emit multiSelectionEnabled(false); +} + +void PartSet_OperationSketchLine::abortOperation() +{ + emit featureConstructed(feature(), FM_Abort); + PartSet_OperationSketchBase::abortOperation(); } void PartSet_OperationSketchLine::stopOperation() { PartSet_OperationSketchBase::stopOperation(); - myPointSelectionMode = SM_None; + emit multiSelectionEnabled(true); } boost::shared_ptr PartSet_OperationSketchLine::createFeature() { - boost::shared_ptr aNewFeature = PartSet_OperationSketchBase::createFeature(); + boost::shared_ptr aNewFeature = ModuleBase_Operation::createFeature(); if (mySketch) { boost::shared_ptr aFeature = boost::dynamic_pointer_cast(mySketch); aFeature->addSub(aNewFeature); } - //emit featureConstructed(aNewFeature, FM_Activation); + if (myInitPoint) { + 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()); + } + + emit featureConstructed(aNewFeature, FM_Activation); return aNewFeature; } -void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, - const std::string& theAttribute) +void PartSet_OperationSketchLine::getLinePoint(boost::shared_ptr theFeature, + const std::string& theAttribute, + double& theX, double& theY) { - 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)); - - double aX = 0; - double anY = 0; - convertTo2D(thePoint, aX, anY); - aPoint->setValue(aX, anY); + theX = aPoint->x(); + theY = aPoint->y(); } -void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr theSourceFeature, - const std::string& theSourceAttribute, +void PartSet_OperationSketchLine::setLinePoint(double theX, double theY, const std::string& theAttribute) { - boost::shared_ptr aData = theSourceFeature->data(); + boost::shared_ptr aData = feature()->data(); boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(theSourceAttribute)); - double aX = aPoint->x(); - double anY = aPoint->y(); - - aData = feature()->data(); - aPoint = boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - aPoint->setValue(aX, anY); + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + aPoint->setValue(theX, theY); } -void PartSet_OperationSketchLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY) +void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, + Handle(V3d_View) theView, + const std::string& theAttribute) { - if (!mySketch) - return; - - boost::shared_ptr anAttr; - boost::shared_ptr aData = mySketch->data(); - - boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); - - boost::shared_ptr aX = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); - boost::shared_ptr anY = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); - - gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z()); - theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z(); - theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z(); + double aX, anY; + PartSet_Tools::ConvertTo2D(thePoint, mySketch, theView, aX, anY); + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + aPoint->setValue(aX, anY); }