X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROCurveCreator%2FCurveCreator_Widget.cxx;h=f59fb1e8139aea601e7984590e3bbf1772024cc4;hb=cab84b2968166d7b7b8673765307403b1f571a5b;hp=ac5b638f90122df6179ca83dbe1f12179527b56d;hpb=254aba54a085eac64aa4ec13f1d46beac722a252;p=modules%2Fhydro.git diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index ac5b638f..f59fb1e8 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -52,6 +52,8 @@ #include #include #include +#include +#include #include #include @@ -75,7 +77,8 @@ const int SCENE_PIXEL_TOLERANCE = 10; CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, CurveCreator_ICurve *theCurve, Qt::WindowFlags fl) -: QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0), myDragStarted( false ), +: QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0), + myDragStarted( false ), myDragInteractionStyle( SUIT_ViewModel::STANDARD ), myOCCViewer( 0 ) { myNewSectionEditor = new CurveCreator_NewSectionDlg( this ); @@ -234,9 +237,6 @@ void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer ) myOCCViewer = theViewer; if ( myOCCViewer ) { - //OCCViewer_ViewWindow* aWnd = dynamic_cast(myOCCViewer->getViewManager()->getActiveView()); - //if ( aWnd ) - // aWnd->installEventFilter( this ); OCCViewer_ViewManager* aViewManager = dynamic_cast ( myOCCViewer->getViewManager() ); connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), @@ -256,27 +256,6 @@ OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer() return myOCCViewer; } -/*! - \brief Customize event handling - \param watched event receiver object - \param e event - \return \c true if the event processing should be stopped -*/ -/*bool CurveCreator_Widget::eventFilter( QObject* theWatched, QEvent* theEvent ) -{ - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( !aViewer ) - return; - Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext(); - bool isLocalContext = aContext->HasOpenedContext(); - if ( !isLocalContext ) - return QWidget::eventFilter( theWatched, theEvent ); - - bool isProcessed = true; - - return isProcessed; -}*/ - //======================================================================= // function: getUniqSectionName // purpose: return unique section name @@ -918,8 +897,11 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven if ( getActionMode() != ModificationMode ) return; - if ( myDragStarted ) + if ( myDragStarted ) { + if ( myDragged ) // if the drag of some points has happened, restore the drag selection + setSelectedPonts( 0, myDragPoints ); setDragStarted( false ); + } else // check whether the segment is clicked an a new point should be added to the segment insertPointToSelectedSegment( theEvent->pos().x(), theEvent->pos().y() ); @@ -1015,15 +997,15 @@ void CurveCreator_Widget::removePoint() { int aSectionId = 0; QList aPoints; - qSort( aPoints ); getSelectedPonts( aSectionId, aPoints ); - if ( aPoints.size() == 0 ) return; QList aSelPoints; startCurveModification( aSelPoints, false ); + // the points should be removed in a decreased order + qSort( aPoints ); for( int i = aPoints.size()-1; i >= 0; i-- ){ int aPntIndx = aPoints[i]; myCurve->removePoint( aSectionId, aPntIndx ); @@ -1119,6 +1101,7 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition, aChangedPos[1] = aChangedPos[1] - anYDelta; myCurve->setPoint( aSectionId, aPointId, aChangedPos ); } + myDragged = true; finishCurveModification( myDragPoints ); } @@ -1256,15 +1239,24 @@ void CurveCreator_Widget::addLocalPointToTable( const double theX, const double */ void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint ) { - if ( !theState ) { - myDragStarted = false; - myDragPoints.clear(); - } - else { + OCCViewer_Viewer* aViewer = getOCCViewer(); + if ( theState ) { getSelectedPonts( 0, myDragPoints ); myDragStarted = myDragPoints.size(); myDragStartPosition = thePoint; + if ( aViewer && myDragStarted ) { + // change a viewer interaction style in order to avoid a select rectangle build + myDragInteractionStyle = aViewer->interactionStyle(); + aViewer->setInteractionStyle(SUIT_ViewModel::KEY_FREE); + } + } + else { + if ( aViewer && myDragStarted ) + aViewer->setInteractionStyle( myDragInteractionStyle ); + myDragStarted = false; + myDragPoints.clear(); } + myDragged = false; } void CurveCreator_Widget::getSelectedPonts( int theSectionId, QList& thePoints ) @@ -1317,6 +1309,7 @@ void CurveCreator_Widget::setSelectedPonts( const int theSectionId, const QList< aListToSelect.Append( anAIS ); } + ic->ClearSelected( Standard_False ); aViewer->setObjectsSelected( aListToSelect ); updateLocalPointView(); } @@ -1374,6 +1367,11 @@ int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, floa return aPntIndex; } +void CurveCreator_Widget::findSections( int thePointId, QList& theSections ) +{ + +} + /** * Checks whether the point belongs to the OCC object * \param theObject a line or shape with a bspline inside @@ -1395,16 +1393,27 @@ bool CurveCreator_Widget::pointOnObject( Handle(AIS_InteractiveObject) theObject return isFound; gp_Pnt aPoint; + Standard_Real aParameter; gp_Pnt aPnt1, aPnt2; Handle(AIS_Line) aLine = Handle(AIS_Line)::DownCast( theObject ); if ( !aLine.IsNull() ) { const Handle(Geom_Line) aGLine = aLine->Line(); - Handle(Geom_Point) aPStart; - Handle(Geom_Point) aPEnd; - aLine->Points( aPStart, aPEnd ); - aPnt1 = aPStart->Pnt(); - aPnt2 = aPEnd->Pnt(); - isFound = hasProjectPointOnCurve( theX, theY, aGLine, aPoint ); + isFound = hasProjectPointOnCurve( theX, theY, aGLine, aParameter ); + if ( isFound ) { + aPoint = aGLine->Value( aParameter ); + + Handle(Geom_Point) aPStart; + Handle(Geom_Point) aPEnd; + aLine->Points( aPStart, aPEnd ); + aPnt1 = aPStart->Pnt(); + aPnt2 = aPEnd->Pnt(); + + // in case of Geom line a projection is performed to the infinite line, + // so it is necessary to bound it by the line size + Bnd_Box aLineBox; + aLineBox.Set( aPnt1, gp_Vec( aPnt1, aPnt2 ) ); + isFound = !aLineBox.IsOut( aPoint ); + } } else { Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast( theObject ); @@ -1418,9 +1427,21 @@ bool CurveCreator_Widget::pointOnObject( Handle(AIS_InteractiveObject) theObject if ( !anEdge.IsNull() ) { Standard_Real aFirst, aLast; Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aFirst, aLast ); - aCurve->D0(aFirst,aPnt1); - aCurve->D0(aLast,aPnt2); - isFound = hasProjectPointOnCurve( theX, theY, aCurve, aPoint ); + + if ( aCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) ) { + Handle(Geom_BSplineCurve) aBSplineCurve = Handle(Geom_BSplineCurve)::DownCast( aCurve ); + if ( !aBSplineCurve.IsNull() ) { + isFound = hasProjectPointOnCurve( theX, theY, aCurve, aParameter ); + if ( isFound ) { + aPoint = aBSplineCurve->Value( aParameter ); + Standard_Integer anI1, anI2; + aBSplineCurve->LocateU( aParameter, LOCAL_SELECTION_TOLERANCE, anI1, anI2 ); + + aPnt1 = aBSplineCurve->Value( aBSplineCurve->Knot( anI1 ) ); + aPnt2 = aBSplineCurve->Value( aBSplineCurve->Knot( anI2 ) ); + } + } + } } } } @@ -1444,7 +1465,7 @@ bool CurveCreator_Widget::pointOnObject( Handle(AIS_InteractiveObject) theObject */ bool CurveCreator_Widget::hasProjectPointOnCurve( const int theX, const int theY, const Handle(Geom_Curve)& theCurve, - gp_Pnt& theOutPoint ) + Standard_Real& theParameter ) { bool isFound = false; OCCViewer_Viewer* aViewer = getOCCViewer(); @@ -1460,7 +1481,8 @@ bool CurveCreator_Widget::hasProjectPointOnCurve( const int theX, const int theY Standard_Integer aNbPoint = aProj.NbPoints(); if (aNbPoint > 0) { for (Standard_Integer j = 1; j <= aNbPoint && !isFound; j++) { - gp_Pnt aNewPoint = aProj.Point(j); + gp_Pnt aNewPoint = aProj.Point( j ); + theParameter = aProj.Parameter( j ); int aX, anY; CurveCreator_Utils::ConvertPointToClick( aNewPoint, aView, aX, anY ); @@ -1468,9 +1490,6 @@ bool CurveCreator_Widget::hasProjectPointOnCurve( const int theX, const int theY int aXDelta = abs( aX - theX ); int anYDelta = abs( anY - theY ); isFound = aXDelta < SCENE_PIXEL_TOLERANCE && anYDelta < SCENE_PIXEL_TOLERANCE; - if ( isFound ) { - theOutPoint = aNewPoint; - } } } return isFound;