]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Modified mode for the polyline. It is possible to change the polyline points. BR_hydro_v_0_3
authoradv <adv@opencascade.com>
Fri, 15 Nov 2013 08:40:01 +0000 (08:40 +0000)
committeradv <adv@opencascade.com>
Fri, 15 Nov 2013 08:40:01 +0000 (08:40 +0000)
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

src/HYDROCurveCreator/CurveCreator_Widget.cxx
src/HYDROCurveCreator/CurveCreator_Widget.h

index 5aea503571e5054bbcef4836ba7e09f518eae8d1..fe6d6b8848cf55a46adf683ab10d816ef845d594 100644 (file)
@@ -43,8 +43,7 @@
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <AIS_Shape.hxx>
 #include <AIS_Point.hxx>
-#include <SelectMgr_EntityOwner.hxx>
-//#include <StdSelect_BRepOwner.hxx>
+#include <StdSelect_BRepOwner.hxx>
 
 #include <QHBoxLayout>
 #include <QVBoxLayout>
@@ -925,34 +924,38 @@ void CurveCreator_Widget::onPointDrag( SUIT_ViewWindow* theViewWindow, QMouseEve
 
 void CurveCreator_Widget::onLocalPointChanged( int theRow, int theColumn )
 {
-  setLocalPointContext( false );
-
   QList<int> aSelSections = mySectionView->getSelectedSections();
+  if ( aSelSections.size() < 0 )
+    return;
+
+  int aSection = aSelSections[0];
+
+  QList<int> aSelPoints;
+  getSelectedPonts( aSection, aSelPoints );
+  setLocalPointContext( false );
 
   int aPntIndex = -1;
   int aCurrSect=-1;
   std::deque<float> 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<int>& 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<int>& 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();
+}
index 82e5b732c2d3b0b828a998589cf28d1993d7e843..22d57e91198dcec4fb0fa43612fc274ee09fd1ba 100644 (file)
@@ -122,6 +122,9 @@ private:
     void     setLocalPointContext( const bool theOpen );
     void     addLocalPointToTable( const double theX, const double theY );
 
+    void getSelectedPonts( const int theSectionId, QList<int>& thePoints );
+    void setSelectedPonts( const int theSectionId, const QList<int>& thePoints );
+
 private:
     QMap<ActionId, QAction*>    myActionMap;
     CurveCreator_ICurve*         myCurve;