Salome HOME
Fix for the bug #42: point C is not activated, but point C is shown in preview in...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
index 4c2a2cc5e2202f8120d62a027cc4b18585a1c240..b36585e22f5de3e928030780271e0b060830d6c4 100644 (file)
@@ -29,6 +29,7 @@
 #include "HYDROGUI_InputPanel.h"
 #include "HYDROGUI_ObjSelector.h"
 #include "HYDROGUI_OCCDisplayer.h"
+#include "HYDROGUI_OCCSelector.h"
 #include "HYDROGUI_Operations.h"
 #include "HYDROGUI_PrsImage.h"
 #include "HYDROGUI_Tool.h"
@@ -36,8 +37,9 @@
 #include "HYDROGUI_Shape.h"
 
 #include <HYDROData_Image.h>
+#include <HYDROData_Lambert93.h>
 
-#include <HYDROOperations_Factory.h>
+#include <HYDROData_OperationsFactory.h>
 
 #include <GraphicsView_ViewFrame.h>
 #include <GraphicsView_ViewManager.h>
@@ -197,21 +199,21 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
   bool anIsImage = false;
   bool anIsImportedImage = false;
-  bool anIsCompositeImage = false;
+  bool anIsImageHasRefs = false;
   bool anIsFusedImage = false;
   bool anIsCutImage = false;
   bool anIsSplittedImage = false;
   bool anIsMustBeUpdatedImage = false;
   bool anIsPolyline = false;
   bool anIsCalculation = false;
-  bool anIsZone = false;
+  bool anIsImmersibleZone = false;
   bool anIsVisualState = false;
 
   // check the selected data model objects
   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
   for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
   {
-    Handle(HYDROData_Object) anObject = aSeq.Value( anIndex );
+    Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
     if( !anObject.IsNull() )
     {
       anIsSelectedDataObjects = true;
@@ -226,9 +228,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
         if( !anImage.IsNull() )
         {
-          anIsImportedImage = anImage->HasTrsfPoints() && !anImage->IsSelfSplitted();
-          anIsCompositeImage = anImage->NbReferences() > 0;
-          if( HYDROOperations_Factory* aFactory = HYDROOperations_Factory::Factory() )
+          anIsImportedImage = anImage->HasLocalPoints() && !anImage->IsSelfSplitted();
+          anIsImageHasRefs = anImage->HasReferences();
+          if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
           {
             if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
             {
@@ -241,15 +243,15 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
                 anIsSplittedImage = true;
             }
           }
-          anIsMustBeUpdatedImage = anImage->MustBeUpdated();
+          anIsMustBeUpdatedImage = anImage->IsMustBeUpdated();
         }
       }
       else if( anObject->GetKind() == KIND_POLYLINE )
         anIsPolyline = true;
       else if( anObject->GetKind() == KIND_CALCULATION )
         anIsCalculation = true;
-      else if( anObject->GetKind() == KIND_ZONE )
-        anIsZone = true;
+      else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
+        anIsImmersibleZone = true;
       else if( anObject->GetKind() == KIND_VISUAL_STATE )
         anIsVisualState = true;
     }
@@ -278,8 +280,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         case KIND_CALCULATION:
           theMenu->addAction( action( CreateCalculationId ) );
           break;
-        case KIND_ZONE:
-          theMenu->addAction( action( CreateZoneId ) );
+        case KIND_IMMERSIBLE_ZONE:
+          theMenu->addAction( action( CreateImmersibleZoneId ) );
           break;
       }
       theMenu->addSeparator();
@@ -298,7 +300,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     {
       if( anIsImportedImage )
         theMenu->addAction( action( EditImportedImageId ) );
-      else if( anIsCompositeImage )
+      else if( anIsImageHasRefs )
       {
         if( anIsFusedImage )
           theMenu->addAction( action( EditFusedImageId ) );
@@ -312,6 +314,12 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       theMenu->addAction( action( ExportImageId ) );
       theMenu->addSeparator();
 
+      if( anIsImageHasRefs )
+      {
+        theMenu->addAction( action( RemoveImageRefsId ) );
+        theMenu->addSeparator();
+      }
+
       theMenu->addAction( action( FuseImagesId ) );
       theMenu->addAction( action( CutImagesId ) );
       theMenu->addAction( action( SplitImageId ) );
@@ -327,9 +335,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
       theMenu->addAction( action( EditCalculationId ) );
       theMenu->addSeparator();
     }
-    else if( anIsZone )
+    else if( anIsImmersibleZone )
     {
-      theMenu->addAction( action( EditZoneId ) );
+      theMenu->addAction( action( EditImmersibleZoneId ) );
       theMenu->addSeparator();
     }
     else if( anIsVisualState && anIsObjectBrowser )
@@ -346,7 +354,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addSeparator();
   }
 
-  if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline || anIsZone ) )
+  if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline || anIsImmersibleZone ) )
   {
     if( anIsHiddenInSelection )
       theMenu->addAction( action( ShowId ) );
@@ -394,7 +402,7 @@ void HYDROGUI_Module::update( const int flags )
     // the selection in the object browser.
     // Note: processEvents() should be called after updateGV(),
     // otherwise the application crashes from time to time.
-    qApp->processEvents(); 
+    //RKV: qApp->processEvents(); 
     getApp()->updateObjectBrowser( true );
   }
 
@@ -506,7 +514,7 @@ void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
 }
 
 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
-                                       const Handle(HYDROData_Object)& theObject ) const
+                                       const Handle(HYDROData_Entity)& theObject ) const
 {
   if( theObject.IsNull() )
     return false;
@@ -526,7 +534,7 @@ bool HYDROGUI_Module::isObjectVisible( const int theViewId,
 }
 
 void HYDROGUI_Module::setObjectVisible( const int theViewId,
-                                        const Handle(HYDROData_Object)& theObject,
+                                        const Handle(HYDROData_Entity)& theObject,
                                         const bool theState )
 {
   if( !theObject.IsNull() )
@@ -538,7 +546,7 @@ void HYDROGUI_Module::setObjectVisible( const int theViewId,
 }
 
 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int                       theViewId,
-                                                 const Handle(HYDROData_Object)& theObject ) const
+                                                 const Handle(HYDROData_Entity)& theObject ) const
 {
   HYDROGUI_Shape* aResShape = NULL;
   if( theObject.IsNull() )
@@ -561,7 +569,7 @@ HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int
 }
 
 void HYDROGUI_Module::setObjectShape( const int                       theViewId,
-                                      const Handle(HYDROData_Object)& theObject,
+                                      const Handle(HYDROData_Entity)& theObject,
                                       HYDROGUI_Shape*                 theShape )
 {
   if( theObject.IsNull() )
@@ -572,16 +580,18 @@ void HYDROGUI_Module::setObjectShape( const int                       theViewId,
 }
 
 void HYDROGUI_Module::removeObjectShape( const int                       theViewId,
-                                         const Handle(HYDROData_Object)& theObject )
+                                         const Handle(HYDROData_Entity)& theObject )
 {
   if ( !myShapesMap.contains( theViewId ) )
     return;
 
   ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
+  Handle(HYDROData_Entity) anObject;
   for ( int i = 0; i < aViewShapes.length(); )
   {
     HYDROGUI_Shape* aShape = aViewShapes.at( i );
-    if ( aShape && IsEqual( aShape->getObject(), theObject ) )
+    anObject = aShape->getObject();
+    if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
     {
       delete aShape;
       aViewShapes.removeAt( i );
@@ -623,8 +633,14 @@ void HYDROGUI_Module::customEvent( QEvent* e )
     {
       if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
       {
+        SUIT_ViewManager* aViewManager = aViewer->getViewManager();
+        ViewManagerRole aRole = getViewManagerRole( aViewManager );
+
         if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
         {
+          if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
+            aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
+
           aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
           aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
@@ -633,9 +649,7 @@ void HYDROGUI_Module::customEvent( QEvent* e )
           //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
         }
 
-        SUIT_ViewManager* aViewManager = aViewer->getViewManager();
-        ViewManagerRole aRole = getViewManagerRole( aViewManager );
-        if( aRole != VMR_TransformImage )
+        if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
           update( UF_Viewer );
 
         aViewer->activateTransform( GraphicsView_Viewer::FitAll );
@@ -666,8 +680,6 @@ void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
 
   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
   { 
-    createSelector( theViewManager ); // replace the default selector
-
     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
   }
@@ -677,6 +689,8 @@ void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
   }
 
+  createSelector( theViewManager ); // replace the default selector
+
   ViewManagerInfo anInfo( theViewManager, VMR_General );
   myViewManagerMap.insert( ViewManagerId++, anInfo );
 }
@@ -728,6 +742,7 @@ void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
 
 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
 {
+  /* ouv: currently unused
   if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
   {
     SUIT_ViewManager* aViewManager = 0;
@@ -757,8 +772,8 @@ void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
       int aXDeg = 0, aYDeg = 0;
       int aXMin = 0, aYMin = 0;
       double aXSec = 0, aYSec = 0;
-      HYDROGUI_Tool::DoubleToLambert( aMouseX, aXDeg, aXMin, aXSec );
-      HYDROGUI_Tool::DoubleToLambert( aMouseY, aYDeg, aYMin, aYSec );
+      HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
+      HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
 
       QString aDegSymbol( QChar( 0x00B0 ) );
       QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
@@ -769,6 +784,7 @@ void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
     else if( aRole == VMR_TransformImage )
       aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
   }
+  */
 }
 
 void HYDROGUI_Module::updateGV( const bool theIsInit,
@@ -834,12 +850,8 @@ void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
     return;
 
   QString aViewType = theViewManager->getType();
-  if( aViewType != GraphicsView_Viewer::Type() )
-    return;
-
-  GraphicsView_ViewManager* aViewManager =
-    dynamic_cast<GraphicsView_ViewManager*>( theViewManager );
-  if( !aViewManager )
+  if( aViewType != GraphicsView_Viewer::Type() &&
+      aViewType != OCCViewer_Viewer::Type())
     return;
 
   QList<SUIT_Selector*> aSelectorList;
@@ -850,11 +862,25 @@ void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
   for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
   {
     SUIT_Selector* aSelector = *anIter;
-    if( aSelector && !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) )
+    if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
+                       !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
       aSelector->setEnabled( false );
   }
 
-  new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
+  if ( aViewType == GraphicsView_Viewer::Type() )
+  {
+    GraphicsView_ViewManager* aViewManager =
+      ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
+    if( aViewManager )
+      new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
+  }
+  else if ( aViewType == OCCViewer_Viewer::Type() )
+  {
+    OCCViewer_ViewManager* aViewManager =
+      ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
+    if( aViewManager )
+      new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
+  }
 }
 
 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )