X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_OperationEditLine.cpp;h=f0049b007d46a956a908173655af8fda6266e2f6;hb=1d7a043abfadf964bf38802e8adb5a4773fec900;hp=72020fb9ac11a479596aa97f8a33e97127f988db;hpb=eba34f3947483cd9a7a8f441af334fba01f36425;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp index 72020fb9a..f0049b007 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -3,21 +3,25 @@ // Author: Natalia ERMOLAEVA #include +#include + +#include #include #include -#include -#include #include #include -#include #include +#include + #ifdef _DEBUG #include #endif +#include + using namespace std; PartSet_OperationEditLine::PartSet_OperationEditLine(const QString& theId, @@ -39,8 +43,8 @@ bool PartSet_OperationEditLine::isGranted() const std::list PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr theFeature) const { std::list aModes; - //if (theFeature != feature()) - // aModes.push_back(TopAbs_VERTEX); + aModes.push_back(TopAbs_VERTEX); + aModes.push_back(TopAbs_EDGE); return aModes; } @@ -49,158 +53,89 @@ void PartSet_OperationEditLine::init(boost::shared_ptr theFeat setFeature(theFeature); } -void PartSet_OperationEditLine::mouseReleased(const gp_Pnt& thePoint) +void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView) { - /*switch (myPointSelectionMode) - { - case SM_FirstPoint: { - setLinePoint(thePoint, LINE_ATTR_START); - myPointSelectionMode = SM_SecondPoint; - } - break; - case SM_SecondPoint: { - setLinePoint(thePoint, LINE_ATTR_END); - myPointSelectionMode = SM_None; - } - break; - case SM_None: { - - } - break; - default: - break; - } -*/ + if (!(theEvent->buttons() & Qt::LeftButton)) + return; + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); + myCurPoint.setPoint(aPoint); } -void PartSet_OperationEditLine::mouseMoved(const gp_Pnt& thePoint) +void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected) { -/* 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); - } - break; - default: - break; - } -*/ -} + if (!(theEvent->buttons() & Qt::LeftButton)) + return; + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); -void PartSet_OperationEditLine::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; - } - break; - default: - break; + if (myCurPoint.myIsInitialized) { + double aCurX, aCurY; + PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY); + + double aX, anY; + PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY); + + double aDeltaX = aX - aCurX; + double aDeltaY = anY - aCurY; + + moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START); + moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END); + + /*std::list::const_iterator anIt = theSelected.begin(), aLast = theSelected.end(); + for (; anIt != aLast; anIt++) { + boost::shared_ptr aFeature = (*anIt).feature(); + if (!aFeature) + continue; + moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START); + moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END); + }*/ } - */ + myCurPoint.setPoint(aPoint); } -void PartSet_OperationEditLine::setSelected(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape) +void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected) { - if (theFeature == feature()) + boost::shared_ptr aFeature; + if (!theSelected.empty()) + aFeature = theSelected.front().feature(); + + if (aFeature == feature()) return; - + commit(); - - if (theFeature) - emit launchOperation("EditLine", theFeature); + if (aFeature) + emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); } void PartSet_OperationEditLine::startOperation() { - //PartSet_OperationSketchBase::startOperation(); - //myPointSelectionMode = SM_FirstPoint; + // do nothing in order to do not create a new feature + emit selectionEnabled(false); + myCurPoint.clear(); } void PartSet_OperationEditLine::stopOperation() { - PartSet_OperationSketchBase::stopOperation(); - //myPointSelectionMode = SM_None; + emit selectionEnabled(true); } boost::shared_ptr PartSet_OperationEditLine::createFeature() { + // do nothing in order to do not create a new feature return boost::shared_ptr(); } -void PartSet_OperationEditLine::setLinePoint(const gp_Pnt& thePoint, +void PartSet_OperationEditLine::moveLinePoint(boost::shared_ptr theFeature, + double theDeltaX, double theDeltaY, const std::string& theAttribute) { - boost::shared_ptr aData = feature()->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); -} - -void PartSet_OperationEditLine::setLinePoint(boost::shared_ptr theSourceFeature, - const std::string& theSourceAttribute, - const std::string& theAttribute) -{ - boost::shared_ptr aData = theSourceFeature->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); -} - -void PartSet_OperationEditLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY) -{ - if (!mySketch) + if (!theFeature) 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)); + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - 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(); + aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY); }