Salome HOME
[bos #32517][EDF] Dynamic log messages switched on and off by SALOME_VERBOSE environm...
[modules/geom.git] / src / EntityGUI / EntityGUI.cxx
index 8962ed0d6d2f95c362b60c661892ce2c92ae0fbf..b47285b72a5f96d04fdc9ec6322fed5ae79cbe88 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "GeometryGUI.h"
 #include "GeometryGUI_Operations.h"
+#include "GEOMUtils.hxx"
 
 #include <LightApp_SelectionMgr.h>
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
 #include <OCCViewer_ViewPort3d.h>
 #include <OCCViewer_ViewWindow.h>
-#include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOME_ListIO.hxx>
 #include <SUIT_Desktop.h>
 #include <SUIT_MessageBox.h>
 #include <SUIT_Session.h>
 #include <SUIT_ViewWindow.h>
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
+#include "utilities.h"
 
 #include <TopoDS_Shape.hxx>
 #include <TopoDS.hxx>
 
 #include "EntityGUI_SketcherDlg.h"        // Sketcher
 #include "EntityGUI_3DSketcherDlg.h"      // Sketcher
+#include "EntityGUI_IsolineDlg.h"         // Isoline
+#include "EntityGUI_SurfFromFaceDlg.h"    // Surface From Face
 #include "EntityGUI_SubShapeDlg.h"        // Method SUBSHAPE
 #include "EntityGUI_FeatureDetectorDlg.h" // Feature Detection
 #include "EntityGUI_PictureImportDlg.h"   // Import Picture in viewer
 #include "EntityGUI_FieldDlg.h"           // Create/Edit Field
+#include "EntityGUI_PolylineDlg.h"        // Create/Edit 2d polyline
 
 #include "GEOMImpl_Types.hxx"
 
@@ -100,6 +105,12 @@ bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
   case GEOMOp::Op3dSketcher: // 3D SKETCHER
     aDlg = new EntityGUI_3DSketcherDlg( getGeometryGUI(), parent );
     break;
+  case GEOMOp::OpIsoline:    // ISOLINE
+    aDlg = new EntityGUI_IsolineDlg( getGeometryGUI(), parent );
+    break;
+  case GEOMOp::OpSurfaceFromFace:    // SURFACE FROM FACE
+    aDlg = new EntityGUI_SurfFromFaceDlg( getGeometryGUI(), parent );
+    break;
   case GEOMOp::OpExplode:    // EXPLODE
     aDlg = new EntityGUI_SubShapeDlg( getGeometryGUI(), parent );
     break;
@@ -130,14 +141,16 @@ bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
     GEOM::GEOM_FieldStep_var step;
 
     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
-    if ( aList.Extent() > 0 && study ) {
+    if ( study )
       for ( ; anIter.More(); anIter.Next() )
       {
         Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
         if ( !anIObj.IsNull() && anIObj->hasEntry() )
-          if ( _PTR(SObject) obj = study->studyDS()->FindObjectID( anIObj->getEntry() ))
+        {
+          _PTR(SObject) obj = study->studyDS()->FindObjectID( anIObj->getEntry() );
+          if ( GeometryGUI::IsInGeomComponent( obj ))
           {
-            CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( obj );
+            CORBA::Object_var   corbaObj = GeometryGUI::ClientSObjectToObject( obj );
             GEOM::GEOM_BaseObject_var bo = GEOM::GEOM_BaseObject::_narrow( corbaObj );
             GEOM::GEOM_Field_var     f;
             GEOM::GEOM_FieldStep_var s;
@@ -162,9 +175,8 @@ bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
               field = f;
             }
           }
+        }
       }
-    }
-
     if ( !field->_is_nil()) {
       int stepID;
       if ( !step->_is_nil() ) {
@@ -183,6 +195,10 @@ bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
     SUIT_MessageBox::warning(parent, tr("WRN_WARNING"), tr("NO_FIELD"));
     break;
   }
+  case GEOMOp::Op2dPolylineEditor: // POLYLINE EDITOR
+    getGeometryGUI()->ActiveWorkingPlane();
+    aDlg = new EntityGUI_PolylineDlg( getGeometryGUI(), parent );
+    break;
   default:
     app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
     break;
@@ -197,7 +213,7 @@ bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
 // function : 0nMousePress()
 // purpose  : [static] manage mouse events
 //=================================================================================
-bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
+bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* /*parent*/, SUIT_ViewWindow* theViewWindow )
 {
   QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
 
@@ -219,9 +235,9 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi
     
         ic->InitSelected();
         if ( pe->modifiers() == Qt::ShiftModifier )
-          ic->ShiftSelect();  // Append selection
+          ic->ShiftSelect( Standard_True );  // Append selection
         else
-          ic->Select();       // New selection
+          ic->Select( Standard_True );       // New selection
 
         ic->InitSelected();
         if ( ic->MoreSelected() ) {
@@ -231,7 +247,7 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi
         }
         else {
           OCCViewer_ViewPort3d* vp =  ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
-          aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
+          aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
         }
         
         Qt::KeyboardModifiers modifiers = pe->modifiers();
@@ -248,7 +264,7 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi
         Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();   
 
         ic->InitSelected();
-        ic->Select();       // New selection
+        ic->Select( Standard_True );       // New selection
 
         ic->InitSelected();
         TopoDS_Shape aShape;
@@ -259,7 +275,7 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi
         else 
         {
           OCCViewer_ViewPort3d* vp =  ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
-          aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
+          aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
         }
         
 //         aCornerDlg->OnPointSelected( aPnt );  // "feed" the point to corner detection dialog
@@ -279,11 +295,11 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi
 // function : 0nMouseRelease()
 // purpose  : [static] manage mouse events
 //=================================================================================
-bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
+bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* /*parent*/, SUIT_ViewWindow* theViewWindow )
 {
   ((OCCViewer_ViewWindow*)theViewWindow)->setSketcherStyle(false);
-  QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
 #ifdef WITH_OPENCV
+  QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
   if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) &&
        theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
        pe->modifiers() != Qt::ControlModifier ) 
@@ -296,7 +312,7 @@ bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_View
     {
 //       QPoint end = QPoint(pe->x(),pe->y());
       OCCViewer_ViewPort3d* vp =  ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
-      aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
+      aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
       aCornerDlg->setEndPnt( aPnt );
     }    
   }
@@ -308,7 +324,7 @@ bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_View
 // function : 0nMouseMove()
 // purpose  : [static] manage mouse events
 //=================================================================================
-bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
+bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* /*parent*/, SUIT_ViewWindow* theViewWindow )
 {
   QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
   
@@ -319,7 +335,7 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin
     if ( aSketcherDlg->acceptMouseEvent() ) 
     {    
       OCCViewer_ViewPort3d* vp =  ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
-      gp_Pnt aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
+      gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
   
       Qt::KeyboardModifiers modifiers = pe->modifiers();
       if (QApplication::mouseButtons() == Qt::LeftButton )
@@ -330,39 +346,13 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin
   return false;
 }
 
-//=======================================================================
-// function : ConvertClickToPoint()
-// purpose  : Returns the point clicked in 3D view
-//=======================================================================
-gp_Pnt EntityGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
-{
-  V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
-  aView->Eye( XEye, YEye, ZEye );
-
-  aView->At( XAt, YAt, ZAt );
-  gp_Pnt EyePoint( XEye, YEye, ZEye );
-  gp_Pnt AtPoint( XAt, YAt, ZAt );
-
-  gp_Vec EyeVector( EyePoint, AtPoint );
-  gp_Dir EyeDir( EyeVector );
-
-  gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
-  Standard_Real X, Y, Z;
-  aView->Convert( x, y, X, Y, Z );
-  gp_Pnt ConvertedPoint( X, Y, Z );
-
-  gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
-  gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
-  return ResultPoint;
-}
-
 //=====================================================================================
 // function : DisplaySimulationShape() 
 // purpose  : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
 //=====================================================================================
 void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Shape& S2 ) 
 {
-  MESSAGE("EntityGUI::DisplaySimulationShape")
+  MESSAGE("EntityGUI::DisplaySimulationShape");
   SalomeApp_Application* app = getGeometryGUI()->getApp();
   if ( !app ) return;
 
@@ -375,12 +365,8 @@ void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Sha
   try {
     if ( !S1.IsNull() ) {
       /* erase any previous */
-#if OCC_VERSION_LARGE <= 0x06060000
-      ic->Erase( mySimulationShape1, Standard_True, Standard_False );
-#else
       ic->Erase( mySimulationShape1, Standard_True );
-#endif
-      ic->ClearPrs( mySimulationShape1 );
+      ic->ClearPrs( mySimulationShape1, 0, Standard_True );
 
       mySimulationShape1 = new AIS_Shape( TopoDS_Shape() );
       mySimulationShape1->Set( S1 );
@@ -391,12 +377,8 @@ void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Sha
       mySimulationShape1->UnsetColor();
     }
     if ( !S2.IsNull() ) {
-#if OCC_VERSION_LARGE <= 0x06060000
-      ic->Erase( mySimulationShape2, Standard_True, Standard_False );
-#else
       ic->Erase( mySimulationShape2, Standard_True );
-#endif
-      ic->ClearPrs( mySimulationShape2 );
+      ic->ClearPrs( mySimulationShape2, 0, Standard_True );
 
       mySimulationShape2 = new AIS_Shape( TopoDS_Shape() );
       mySimulationShape2->Set( S2 );
@@ -408,8 +390,8 @@ void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Sha
     }
     ic->UpdateCurrentViewer();
   }
-  catch( Standard_Failure ) {
-    MESSAGE( "Exception catched in EntityGUI::DisplaySimulationShape" );
+  catch( Standard_Failure& ) {
+    MESSAGE( "Exception caught in EntityGUI::DisplaySimulationShape" );
   } 
 }
 
@@ -419,7 +401,7 @@ void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Sha
 //==================================================================================
 void EntityGUI::EraseSimulationShape()
 {
-  MESSAGE("EntityGUI::EraseSimulationShape")
+  MESSAGE("EntityGUI::EraseSimulationShape");
   SalomeApp_Application* app = getGeometryGUI()->getApp();
   if ( !app ) return;
 
@@ -439,15 +421,10 @@ void EntityGUI::EraseSimulationShape()
     if ( vw->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
       OCCViewer_Viewer* v3d = ( (OCCViewer_ViewManager*)( vw->getViewManager() ) )->getOCCViewer();
       Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
-#if OCC_VERSION_LARGE <= 0x06060000
-      ic->Erase( mySimulationShape1, Standard_True, Standard_False );
-      ic->Erase( mySimulationShape2, Standard_True, Standard_False );
-#else 
       ic->Erase( mySimulationShape1, Standard_True );
       ic->Erase( mySimulationShape2, Standard_True );
-#endif
-      ic->ClearPrs( mySimulationShape1 );
-      ic->ClearPrs( mySimulationShape2 );
+      ic->ClearPrs( mySimulationShape1, 0, Standard_True );
+      ic->ClearPrs( mySimulationShape2, 0, Standard_True );
       ic->UpdateCurrentViewer();
     } 
   }