]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #709, #710, #711: bugs fixes, synchronization between selection in Polyline...
authormkr <mkr@opencascade.com>
Wed, 18 Nov 2015 14:49:03 +0000 (17:49 +0300)
committermkr <mkr@opencascade.com>
Wed, 18 Nov 2015 14:49:03 +0000 (17:49 +0300)
src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx
src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h
src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx
src/HYDROGUI/HYDROGUI_LandCoverMapOp.h
src/HYDROGUI/HYDROGUI_Shape.cxx
src/HYDROGUI/HYDROGUI_Shape.h

index 565b678f5d72c2b02257116cec95654175639007..c0b687a5358b905d797127c0b831e7349c8216eb 100644 (file)
 #include <HYDROData_Object.h>
 #include <HYDROData_PolylineXY.h>
 
+#include <OCCViewer_ViewManager.h>
+
+#include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <LightApp_DataOwner.h>
+
+#include <SUIT_DataObject.h>
+
 #include <QLineEdit>
 #include <QComboBox>
 #include <QGroupBox>
@@ -82,7 +90,7 @@ HYDROGUI_LandCoverMapDlg::HYDROGUI_LandCoverMapDlg( HYDROGUI_Module* theModule,
 
   // Connect signals and slots
   connect( myObjectNameEdit, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onLandCoverMapChanged() ) );
-  connect( myPolylinesFaces, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onPolylineFaceChanged( const QString& ) ) );
+  connect( myPolylinesFaces, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onPolylineFaceChanged() ) );
 
   updateState( true );
 
@@ -174,10 +182,11 @@ void HYDROGUI_LandCoverMapDlg::onLandCoverMapChanged()
   emit landCoverMapChanged( getObjectName() );
 }
 
-void HYDROGUI_LandCoverMapDlg::onPolylineFaceChanged( const QString& )
+void HYDROGUI_LandCoverMapDlg::onPolylineFaceChanged()
 {
   updateState();
-  // TODO: select chosen polyline/face in the 3D viewer, if it is not selected yet (i.e. object was chosen not in the viewer, but in combo-box)
+
+  emit polylineFaceChanged();
 }
 
 void HYDROGUI_LandCoverMapDlg::updateState( bool theInitialConfigure )
index 101c1f85e5ad8c77128a0b90ce5df3c1fbe940a7..3547feb8da8e3e1fb9baa47452ae57f236d91bb9 100644 (file)
@@ -53,10 +53,11 @@ public:
 
 signals:
   void                     landCoverMapChanged( const QString& theName );
+  void                     polylineFaceChanged();
 
 private slots:
   void                     onLandCoverMapChanged();
-  void                     onPolylineFaceChanged( const QString& );
+  void                     onPolylineFaceChanged();
 
 private:
   void                     updateState( bool theInitialConfigure = false );
index 5db4f16b8af1e875975c2313f9b4d39240d3c2f2..7aa4036b4dcc67688419dc8ac9af76cc61e92f47 100644 (file)
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewPort3d.h>
 
+#include <OCCViewer_ViewManager.h>
+
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
+#include <LightApp_DataOwner.h>
 #include <SUIT_ViewWindow.h>
+#include <SUIT_DataObject.h>
 
 #include <TopoDS.hxx>
 #include <TopoDS_Face.hxx>
@@ -54,7 +58,8 @@
 HYDROGUI_LandCoverMapOp::HYDROGUI_LandCoverMapOp( HYDROGUI_Module* theModule, const int theOperationId )
 : HYDROGUI_Operation( theModule ),
   myOperationId( theOperationId ),
-  myPreviewPrs( 0 )
+  myPreviewPrs( 0 ),
+  myPolylineFacePreviewPrs( 0 )
 {
   switch( myOperationId )
   {
@@ -168,6 +173,8 @@ HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const
   HYDROGUI_LandCoverMapDlg* aPanel = new HYDROGUI_LandCoverMapDlg( module(), getName(), myOperationId );
   connect( aPanel, SIGNAL( landCoverMapChanged( const QString& ) ),
            this, SLOT( onLandCoverMapChanged( const QString& ) ) );
+  connect( aPanel, SIGNAL( polylineFaceChanged() ),
+           this, SLOT( onPolylineFaceChanged() ) );
   return aPanel;
 }
 
@@ -382,6 +389,88 @@ void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName )
   }
 }
 
+void HYDROGUI_LandCoverMapOp::onPolylineFaceChanged()
+{
+  HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
+  if ( !aPanel )
+    return;
+
+  LightApp_DataOwner* aPolylineFaceDataOwner = NULL;
+  Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace();
+  if ( !aPolylineFace.IsNull() )
+  {
+    // Select chosen polyline/face in the Object Browser, if it is not selected yet
+    // (i.e. object was chosen not in the Object Browser or 3d Viewer, but in combo-box)
+    aPolylineFaceDataOwner = new LightApp_DataOwner( HYDROGUI_DataObject::dataObjectEntry( aPolylineFace ) );  
+    LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
+    if ( aSelectionMgr )
+    {
+      bool bIsAlreadySelected = false;
+      SUIT_DataOwnerPtrList aSelectedOwners;
+      aSelectionMgr->selected( aSelectedOwners );
+      foreach( SUIT_DataOwner* aSUITOwner, aSelectedOwners )
+      {
+        if ( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
+        {
+          if ( anOwner->entry() == aPolylineFaceDataOwner->entry() )
+          {
+            bIsAlreadySelected = true;
+            break;
+          }
+        }
+      }
+      if ( !bIsAlreadySelected )
+      {
+        SUIT_DataOwnerPtrList aList( true );
+        aList.append( SUIT_DataOwnerPtr( aPolylineFaceDataOwner ) );
+        aSelectionMgr->setSelected( aList );
+      }
+    }
+
+    // Show Preview of selected polyline/face
+    Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aPolylineFace );
+    Handle(HYDROData_Object) aFace = Handle(HYDROData_Object)::DownCast( aPolylineFace );
+    if ( !aPolyline.IsNull() || !aFace.IsNull() )
+    {
+      TopoDS_Shape aTopoDSShape;
+      if ( !aPolyline.IsNull() )
+        aTopoDSShape = aPolyline->GetShape();
+      else
+        aTopoDSShape = aFace->GetTopShape();
+
+      OCCViewer_ViewManager* aViewManager = ::qobject_cast<OCCViewer_ViewManager*>( 
+        module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) );
+      if ( aViewManager )
+      {
+        if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
+        {
+          if ( myPolylineFacePreviewPrs )
+          {
+            delete myPolylineFacePreviewPrs;
+            myPolylineFacePreviewPrs = 0;
+          }
+
+          int aViewerId = (size_t)aViewer;
+          if ( !module()->isObjectVisible( aViewerId, aPolylineFace ) )
+          {
+            Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+            if ( !aCtx.IsNull() )
+            {
+              myPolylineFacePreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
+              aCtx->ClearSelected();
+
+              myPolylineFacePreviewPrs->setBorderColor( Qt::white, false, false );
+              myPolylineFacePreviewPrs->setShape( aTopoDSShape, true, true, !aPolyline.IsNull() ? AIS_WireFrame : AIS_Shaded );
+
+              module()->update( UF_OCCViewer | UF_FitAll );
+            }       
+          }
+        }
+      }
+    }
+  }
+}
+
 void HYDROGUI_LandCoverMapOp::onCreatePreview()
 {
   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
@@ -402,34 +491,41 @@ void HYDROGUI_LandCoverMapOp::onCreatePreview()
       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
       if ( !aCtx.IsNull() )
       {
-        disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
-          aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
-        disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
-          aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));        
-
-        connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
-            this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
-        connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
-          this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
-
-        LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
-        if( aSelectionMgr )
+        if ( myOperationId == RemoveLandCoverId || 
+             myOperationId == MergeLandCoverId ||
+             myOperationId == ChangeLandCoverTypeId )
         {
-          QList<SUIT_Selector*> aSelectorList;
-          aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
-          QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
-          for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
+          disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+            aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+          disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
+            aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));        
+
+          connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+              this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+          connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
+            this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
+
+          LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
+          if ( aSelectionMgr )
           {
-            HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
-            if ( aHydroSelector )
+            QList<SUIT_Selector*> aSelectorList;
+            aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
+            QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
+            for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
             {
-              disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
-              connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+              HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
+              if ( aHydroSelector )
+              {
+                disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+                connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+              }
             }
           }
-        }
         
-        connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
+          connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
+        }
+        else
+          connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) );
         myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ );
       }
     }
@@ -552,12 +648,18 @@ void HYDROGUI_LandCoverMapOp::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseE
 
 void HYDROGUI_LandCoverMapOp::closePreview()
 {
-  if( myPreviewPrs )
+  if ( myPreviewPrs )
   {
     delete myPreviewPrs;
     myPreviewPrs = 0;
   }
 
+  if ( myPolylineFacePreviewPrs )
+  {
+    delete myPolylineFacePreviewPrs;
+    myPolylineFacePreviewPrs = 0;
+  }
+
   HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_LandCoverMapDlg*>( inputPanel() );
   if ( !aPanel )
     return;
@@ -565,33 +667,38 @@ void HYDROGUI_LandCoverMapOp::closePreview()
   if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId )
     aPanel->setApplyEnabled( false );
 
-  OCCViewer_ViewManager* aViewManager = getPreviewManager();
-  if ( aViewManager )
+  if ( myOperationId == RemoveLandCoverId || 
+       myOperationId == MergeLandCoverId ||
+       myOperationId == ChangeLandCoverTypeId )
   {
-    if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
+    OCCViewer_ViewManager* aViewManager = getPreviewManager();
+    if ( aViewManager )
     {
-      disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
-        this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
-      disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
-        this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
-      connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
-        aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
-      connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
-        aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));  
-
-      LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
-      if( aSelectionMgr )
+      if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() )
       {
-        QList<SUIT_Selector*> aSelectorList;
-        aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
-        QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
-        for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
+        disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+          this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+        disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
+          this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
+        connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
+          aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
+        connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
+          aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));  
+
+        LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr();
+        if ( aSelectionMgr )
         {
-          HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
-          if ( aHydroSelector )
+          QList<SUIT_Selector*> aSelectorList;
+          aSelectionMgr->selectors( aViewManager->getType(), aSelectorList );
+          QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
+          for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
           {
-            disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
-            connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );            
+            HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast<HYDROGUI_OCCSelector*>( *anIter );
+            if ( aHydroSelector )
+            {
+              disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );
+              connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) );            
+            }
           }
         }
       }
index d5c7e6405ec246413e07cfda4b5c76f8d68cf135..b34d2f422b1c66e9c68bc7cbc73c27be63d2279f 100644 (file)
@@ -54,6 +54,7 @@ signals:
 
 protected slots:
   void                           onLandCoverMapChanged( const QString& theName );
+  void                           onPolylineFaceChanged();
   void                           onCreatePreview();
   void                           onViewerSelectionChanged();
   void                           onMousePress(SUIT_ViewWindow*, QMouseEvent*);
@@ -72,6 +73,7 @@ private:
   Handle(HYDROData_LandCoverMap)  myEditedObject;
 
   HYDROGUI_Shape*                 myPreviewPrs;
+  HYDROGUI_Shape*                 myPolylineFacePreviewPrs;
 
   QPoint                          myStartPnt, myEndPnt;
 };
index ba8a9d8fb85d1094aedfa3ac9270371762d13660..5b73a7ad9778c00897f7352041966d7b131450b5 100644 (file)
@@ -424,10 +424,11 @@ void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
 
 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
                                const bool          theToDisplay,
-                               const bool          theIsUpdateViewer )
+                               const bool          theIsUpdateViewer,
+                               const int           theDisplayMode )
 {
   myTopoShape = theShape;
-  myDisplayMode = AIS_Shaded;
+  myDisplayMode = theDisplayMode;
 
   buildShape();
   updateShape( theToDisplay, theIsUpdateViewer );
index 695310583709b36f07d5d2df2316e9197e54f0b2..5447abb04b7a98660d1c32d72741b2adce0da109 100644 (file)
@@ -79,7 +79,8 @@ public:
 
   virtual void               setShape( const TopoDS_Shape& theShape,
                                        const bool          theToDisplay = true,
-                                       const bool          theIsUpdateViewer = true );
+                                       const bool          theIsUpdateViewer = true,
+                                       const int           theDisplayMode = AIS_Shaded );
 
   virtual void               setFillingColor( const QColor& theColor,
                                               const bool    theToDisplay = true,