From: adv Date: Fri, 15 Nov 2013 08:40:01 +0000 (+0000) Subject: Modified mode for the polyline. It is possible to change the polyline points. X-Git-Tag: BR_hydro_v_0_3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4e7f0692821fc25214c394b5df638bba2e672d22;p=modules%2Fhydro.git Modified mode for the polyline. It is possible to change the polyline points. ToDo: - double editor for point coordinate - restore selection after the value applying - IT IS DONE - local selection only for section objects - viewer comes to the widget constructor --- diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index 5aea5035..fe6d6b88 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -43,8 +43,7 @@ #include #include #include -#include -//#include +#include #include #include @@ -925,34 +924,38 @@ void CurveCreator_Widget::onPointDrag( SUIT_ViewWindow* theViewWindow, QMouseEve void CurveCreator_Widget::onLocalPointChanged( int theRow, int theColumn ) { - setLocalPointContext( false ); - QList aSelSections = mySectionView->getSelectedSections(); + if ( aSelSections.size() < 0 ) + return; + + int aSection = aSelSections[0]; + + QList aSelPoints; + getSelectedPonts( aSection, aSelPoints ); + setLocalPointContext( false ); int aPntIndex = -1; int aCurrSect=-1; std::deque aChangedPos; float aPrevX, aPrevY, aX, anY; - for( int i = 0 ; i < aSelSections.size() ; i++ ){ - aCurrSect = aSelSections[i]; + //for( int i = 0 ; i < aSelSections.size() ; i++ ){ + aCurrSect = aSection;//aSelSections[i]; aPrevX = myLocalPointView->item( theRow, 1 )->data( Qt::UserRole ).toDouble(); aPrevY = myLocalPointView->item( theRow, 2 )->data( Qt::UserRole ).toDouble(); aPntIndex = findLocalPointIndex( aCurrSect, aPrevX, aPrevY ); - if ( aPntIndex < 0 ) - continue; - - aX = myLocalPointView->item( theRow, 1 )->text().toDouble(); - anY = myLocalPointView->item( theRow, 2 )->text().toDouble(); - aChangedPos.clear(); - aChangedPos.push_back( aX ); - aChangedPos.push_back( anY ); - myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos ); - } - updateLocalPointView(); - + if ( aPntIndex >= 0 ) { + aX = myLocalPointView->item( theRow, 1 )->text().toDouble(); + anY = myLocalPointView->item( theRow, 2 )->text().toDouble(); + aChangedPos.clear(); + aChangedPos.push_back( aX ); + aChangedPos.push_back( anY ); + myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos ); + } + //} setLocalPointContext( true ); + setSelectedPonts( aSection, aSelPoints ); } int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, float theY ) @@ -1076,7 +1079,9 @@ void CurveCreator_Widget::addLocalPointToTable( const double theX, const double QTableWidgetItem* anItem; myLocalPointView->setRowCount( aRowId+1 ); - myLocalPointView->setItem( aRowId, 0, new QTableWidgetItem( QString::number( aRowId + 1 ) ) ); + anItem = new QTableWidgetItem( QString::number( aRowId + 1 ) ); + anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled ); + myLocalPointView->setItem( aRowId, 0, anItem ); anItem = new QTableWidgetItem( QString::number( theX ) ); anItem->setData( Qt::UserRole, theX ); @@ -1085,4 +1090,56 @@ void CurveCreator_Widget::addLocalPointToTable( const double theX, const double anItem = new QTableWidgetItem( QString::number( theY ) ); anItem->setData( Qt::UserRole, theY ); myLocalPointView->setItem( aRowId, 2, anItem ); -} \ No newline at end of file +} + +void CurveCreator_Widget::getSelectedPonts( int theSectionId, QList& thePoints ) +{ + float aPrevX, aPrevY; + int aPntIndex; + for ( int i = 0, aNb = myLocalPointView->rowCount(); i < aNb; i++ ) { + aPrevX = myLocalPointView->item( i, 1 )->data( Qt::UserRole ).toDouble(); + aPrevY = myLocalPointView->item( i, 2 )->data( Qt::UserRole ).toDouble(); + + aPntIndex = findLocalPointIndex( theSectionId, aPrevX, aPrevY ); + if ( aPntIndex >= 0 ) + thePoints.append( aPntIndex ); + } +} + +void CurveCreator_Widget::setSelectedPonts( const int theSectionId, const QList& thePoints ) +{ + OCCViewer_Viewer* anOCCViewer = getOCCViewer(); + if ( !anOCCViewer ) + return; + + AIS_ListOfInteractive aListToSelect; + + Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext(); + if ( !ic->HasOpenedContext() ) + return; + + AIS_ListOfInteractive aDisplayedList; + ic->DisplayedObjects( aDisplayedList ); + for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() ) + { + Handle(AIS_InteractiveObject) anAIS = it.Value(); + if ( anAIS.IsNull() ) + continue; + Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast( anAIS ); + if ( aPoint.IsNull() ) + continue; + + TopoDS_Vertex aVertex = TopoDS::Vertex( aPoint->Vertex() ); + + if ( aVertex.IsNull() ) + continue; + + gp_Pnt aPnt = BRep_Tool::Pnt( aVertex ); + int aPointIndex = findLocalPointIndex( theSectionId, aPnt.X(), aPnt.Y() ); + if ( thePoints.contains( aPointIndex ) ) + aListToSelect.Append( anAIS ); + } + + anOCCViewer->setObjectsSelected( aListToSelect ); + updateLocalPointView(); +} diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.h b/src/HYDROCurveCreator/CurveCreator_Widget.h index 82e5b732..22d57e91 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.h +++ b/src/HYDROCurveCreator/CurveCreator_Widget.h @@ -122,6 +122,9 @@ private: void setLocalPointContext( const bool theOpen ); void addLocalPointToTable( const double theX, const double theY ); + void getSelectedPonts( const int theSectionId, QList& thePoints ); + void setSelectedPonts( const int theSectionId, const QList& thePoints ); + private: QMap myActionMap; CurveCreator_ICurve* myCurve;