Salome HOME
Rewrite local function ModifySurface of BlockFix_SphereSpaceModifier
[modules/geom.git] / src / MeasureGUI / MeasureGUI_ManageDimensionsDlg.cxx
index 9433464b1604e878c7c4785a720d34caf649f569..0843b57f5436d81444b69cdeaef192c66df0eb44 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  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
@@ -29,6 +29,7 @@
 #include "MeasureGUI_DimensionFilter.h"
 
 #include <GEOMGUI_DimensionProperty.h>
+#include <GEOMGUI_TextTreeWdg.h>
 #include <GEOMUtils.hxx>
 #include <GEOMGUI_OCCSelector.h>
 #include <GEOM_AISDimension.hxx>
@@ -60,6 +61,8 @@
 #include <QHBoxLayout>
 #include <QPixmap>
 
+#include <Basics_OCCTVersion.hxx>
+
 //=================================================================================
 // function : Constructor
 // purpose  :
@@ -67,7 +70,8 @@
 MeasureGUI_ManageDimensionsDlg::MeasureGUI_ManageDimensionsDlg( GeometryGUI* theGUI, QWidget* theParent )
 : GEOMBase_Skeleton( theGUI, theParent ),
   myOperatedViewer( NULL ),
-  myCurrentSelection( Selection_None )
+  myCurrentSelection( Selection_None ),
+  myCreateDialog(0)
 {
   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
 
@@ -125,7 +129,7 @@ MeasureGUI_ManageDimensionsDlg::MeasureGUI_ManageDimensionsDlg( GeometryGUI* the
   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
 
-  myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, theParent ),
+  myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, this ),
 
   SelectionIntoArgument( Selection_Object );
 
@@ -133,7 +137,7 @@ MeasureGUI_ManageDimensionsDlg::MeasureGUI_ManageDimensionsDlg( GeometryGUI* the
   {
     myObjectSelector->PushButton1->click();
   }
-
+  myIsNeedRedisplay = false;
   setHelpFileName("managing_dimensions_page.html");
 }
 
@@ -192,10 +196,8 @@ void MeasureGUI_ManageDimensionsDlg::StartSelection( const Selection theSelectio
 
     Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
 
-    anAISContext->ClearCurrents( Standard_False );
+    anAISContext->ClearCurrents( Standard_False );  // todo: deprecated OCCT API
     anAISContext->ClearSelected( Standard_False );
-    anAISContext->OpenLocalContext( Standard_True, Standard_False );
-
     Handle(MeasureGUI_DimensionFilter) aFilter = new MeasureGUI_DimensionFilter( myEditObject->GetStudyEntry() );
 
     anAISContext->AddFilter( aFilter );
@@ -240,6 +242,9 @@ void MeasureGUI_ManageDimensionsDlg::StartSelection( const Selection theSelectio
 //=================================================================================
 void MeasureGUI_ManageDimensionsDlg::StopSelection()
 {
+  if( !myGeomGUI || !myGeomGUI->getApp() || !myGeomGUI->getApp()->selectionMgr() )
+    return;
+
   if ( myCurrentSelection == Selection_Object )
   {
     /* -----------------------------------------------  *
@@ -259,8 +264,8 @@ void MeasureGUI_ManageDimensionsDlg::StopSelection()
      * ------------------------------------------------ */
 
     Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
-
-    anAISContext->CloseLocalContext();
+    anAISContext->Deactivate();
+    anAISContext->Activate(0);
 
     LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
 
@@ -353,16 +358,7 @@ void MeasureGUI_ManageDimensionsDlg::SelectionIntoArgument( const Selection theS
     anAISContext->InitSelected();
 
     Handle(AIS_InteractiveObject) anAIS;
-
-    if ( anAISContext->HasOpenedContext() )
-    {
-      Handle(SelectMgr_EntityOwner) anAISOwner = anAISContext->SelectedOwner();
-      anAIS = Handle(AIS_InteractiveObject)::DownCast( anAISOwner->Selectable() );
-    }
-    else
-    {
-      anAIS = anAISContext->Current();
-    }
+    anAIS = anAISContext->Current(); // todo: deprecated OCCT API
 
     int aDimensionId = IdFromPrs( anAIS );
 
@@ -381,20 +377,22 @@ void MeasureGUI_ManageDimensionsDlg::SelectionIntoArgument( const Selection theS
 //=================================================================================
 void MeasureGUI_ManageDimensionsDlg::OnAdd()
 {
-  QWidget* aParent = qobject_cast<QWidget*>( this->parent() );
-
-  this->Suspend();
-
-  MeasureGUI_CreateDimensionDlg* aCreateDlg = new MeasureGUI_CreateDimensionDlg( myEditObject, myGeomGUI, aParent );
-
-  connect( aCreateDlg, SIGNAL( finished( int ) ), this, SLOT( Resume() ) );
-
-  // this is necessary as the GEOMBase_Helper switches selection mode on destruction
-  connect( aCreateDlg, SIGNAL( destroyed( QObject* ) ), this, SLOT( Resume() ) );
-
-  aCreateDlg->updateGeometry();
-  aCreateDlg->resize( aCreateDlg->minimumSizeHint() );
-  aCreateDlg->show();
+  if(!myCreateDialog) {
+    QWidget* aParent = qobject_cast<QWidget*>( this->parent() );
+    this->Suspend();
+    myCreateDialog = new MeasureGUI_CreateDimensionDlg( myEditObject, myGeomGUI, aParent );
+    connect( myCreateDialog, SIGNAL( finished( int ) ), this, SLOT( Resume() ) );
+    // this is necessary as the GEOMBase_Helper switches selection mode on destruction
+    connect( myCreateDialog, SIGNAL( destroyed( QObject* ) ), this, SLOT( Resume() ) );
+    connect( myCreateDialog, SIGNAL( applyClicked() ), this, SLOT( OnDimensionAdded() ) );
+    myCreateDialog->updateGeometry();
+    myCreateDialog->resize( myCreateDialog->minimumSizeHint() );
+    myCreateDialog->show();
+  } else {
+    myCreateDialog->activateWindow();
+  }
+  myObjectSelector->setEnabled(false);
+  myDimensionView->setEnabled(false);
 }
 
 //=================================================================================
@@ -528,7 +526,7 @@ void MeasureGUI_ManageDimensionsDlg::OnSelectItem()
 //=================================================================================
 void MeasureGUI_ManageDimensionsDlg::OnShowAll()
 {
-  // read propety data
+  // read property data
   SalomeApp_Application* anApp = myGeomGUI->getApp();
   if ( !anApp )
   {
@@ -577,7 +575,7 @@ void MeasureGUI_ManageDimensionsDlg::OnShowAll()
 //=================================================================================
 void MeasureGUI_ManageDimensionsDlg::OnHideAll()
 {
-  // read propety data
+  // read property data
   SalomeApp_Application* anApp = myGeomGUI->getApp();
   if ( !anApp )
   {
@@ -624,7 +622,7 @@ void MeasureGUI_ManageDimensionsDlg::OnHideAll()
 // function : OnInteractionFinished
 // purpose  :
 //=================================================================================
-void MeasureGUI_ManageDimensionsDlg::OnInteractionFinished( Handle(AIS_InteractiveObject) theIO )
+void MeasureGUI_ManageDimensionsDlg::OnInteractionFinished( Handle_AIS_InteractiveObject theIO )
 {
   // update property data
   SalomeApp_Application* anApp = myGeomGUI->getApp();
@@ -672,7 +670,6 @@ void MeasureGUI_ManageDimensionsDlg::OnInteractionFinished( Handle(AIS_Interacti
 void MeasureGUI_ManageDimensionsDlg::Suspend()
 {
   StopSelection();
-  hide();
 }
 
 //=================================================================================
@@ -681,7 +678,12 @@ void MeasureGUI_ManageDimensionsDlg::Suspend()
 //=================================================================================
 void MeasureGUI_ManageDimensionsDlg::Resume()
 {
-  this->show();
+  if(myCreateDialog){
+    myCreateDialog = 0;
+    myObjectSelector->setEnabled(true);
+    myDimensionView->setEnabled(true);
+  }
+
   if ( !myEditObject.isNull() )
   {
     PopulateList();
@@ -689,6 +691,17 @@ void MeasureGUI_ManageDimensionsDlg::Resume()
   }
 }
 
+//=================================================================================
+// function : Suspend
+// purpose  :
+//=================================================================================
+void MeasureGUI_ManageDimensionsDlg::OnDimensionAdded() {
+  if ( !myEditObject.isNull() )
+  {
+    PopulateList();
+  }
+}
+
 //=================================================================================
 // function : ClickOnOk
 // purpose  : 
@@ -712,7 +725,12 @@ void MeasureGUI_ManageDimensionsDlg::ClickOnCancel()
   {
     return;
   }
-
+  
+  if( myCreateDialog ) {
+    myCreateDialog->close();
+    myCreateDialog = 0;
+  }
+  
   GEOMBase_Skeleton::ClickOnCancel();
 }
 
@@ -746,7 +764,9 @@ bool MeasureGUI_ManageDimensionsDlg::ClickOnApply()
                                QVariant() )
                                .value<GEOMGUI_DimensionProperty>();
 
-  mySavedPropertyState.SaveToAttribute( aStudy, myEditObject->GetStudyEntry() );
+  mySavedPropertyState.SaveToAttribute( myEditObject->GetStudyEntry() );
+
+  myGeomGUI->emitDimensionsUpdated( QString( myEditObject->GetStudyEntry() ) );
 
   return true;
 }
@@ -783,7 +803,11 @@ void MeasureGUI_ManageDimensionsDlg::OnFinish()
                              GEOM::propertyName( GEOM::Dimensions ),
                              QVariant() );
 
-  redisplay( myEditObject.get() );
+  if ( myIsNeedRedisplay ) {
+    redisplay( myEditObject.get() );
+  }
+  
+  myGeomGUI->emitDimensionsUpdated( QString( myEditObject->GetStudyEntry() ) );
 }
 
 //=================================================================================
@@ -866,8 +890,8 @@ void MeasureGUI_ManageDimensionsDlg::SetEditObject( const GEOM::GeomObjPtr& theO
 
   if ( myEditObject.isNull() )
   {
+    myDimensionView->TreeWidget->clear();
     myDimensionView->setEnabled( false );
-
     return;
   }
 
@@ -889,7 +913,7 @@ void MeasureGUI_ManageDimensionsDlg::SetEditObject( const GEOM::GeomObjPtr& theO
     return;
   }
 
-  mySavedPropertyState.LoadFromAttribute( getStudy(), myEditObject->GetStudyEntry() );
+  mySavedPropertyState.LoadFromAttribute( myEditObject->GetStudyEntry() );
 
   // set property state for preview
   aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
@@ -932,8 +956,6 @@ void MeasureGUI_ManageDimensionsDlg::RestoreState()
                              myEditObject->GetStudyEntry(),
                              GEOM::propertyName( GEOM::Dimensions ),
                              QVariant() );
-
-  RedisplayObject();
 }
 
 //=================================================================================
@@ -1084,8 +1106,8 @@ bool MeasureGUI_ManageDimensionsDlg::AllowedToCancelChanges()
                                             tr( "WRN_MSG_CHANGES_LOST" ),
                                             QMessageBox::Ok,
                                             QMessageBox::Cancel );
-
-  return aResponse == QMessageBox::Ok;
+  myIsNeedRedisplay = ( aResponse == QMessageBox::Ok );
+  return myIsNeedRedisplay;
 }
 
 //=================================================================================
@@ -1211,17 +1233,7 @@ void MeasureGUI_ManageDimensionsDlg::SelectInViewer( SOCC_Viewer* theViewer, con
   {
     return;
   }
-
-  Standard_Boolean isLocal = anAISContext->HasOpenedContext();
-  if ( isLocal )
-  {
-    anAISContext->ClearSelected( Standard_False );
-  }
-  else
-  {
-    anAISContext->ClearCurrents( Standard_False );
-  }
-
+  anAISContext->ClearCurrents( Standard_False ); // todo: deprecated OCCT API
   SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( theViewer->CreatePrs( myEditObject->GetStudyEntry() ) );
 
   AIS_ListOfInteractive aListOfIO;
@@ -1233,25 +1245,26 @@ void MeasureGUI_ManageDimensionsDlg::SelectInViewer( SOCC_Viewer* theViewer, con
     const Handle(AIS_InteractiveObject)& anIO = anIt.Value();
     if ( IdFromPrs( anIO ) != theId )
     {
-      if ( isLocal )
-      {
-        anAISContext->Deactivate( anIO, AIS_DSM_Line );
-        anAISContext->Deactivate( anIO, AIS_DSM_Text );
-      }
+#if OCC_VERSION_LARGE >= 0x070400ff
+      anAISContext->Deactivate( anIO, PrsDim_DimensionSelectionMode_Line );
+      anAISContext->Deactivate( anIO, PrsDim_DimensionSelectionMode_Text );
+#else
+      anAISContext->Deactivate( anIO, AIS_DSM_Line );
+      anAISContext->Deactivate( anIO, AIS_DSM_Text );
+#endif
       continue;
     }
+    anAISContext->AddOrRemoveSelected( anIO, Standard_False );
 
-    if ( isLocal )
-    {
-      anAISContext->AddOrRemoveSelected( anIO, Standard_False );
-      anAISContext->Activate( anIO, AIS_DSM_Line );
-      anAISContext->Activate( anIO, AIS_DSM_Text );
-    }
-    else
-    {
-      anAISContext->AddOrRemoveCurrentObject( anIO, Standard_False );
-    }
+#if OCC_VERSION_LARGE >= 0x070400ff
+    anAISContext->Activate( anIO, PrsDim_DimensionSelectionMode_Line );
+    anAISContext->Activate( anIO, PrsDim_DimensionSelectionMode_Text );
+#else
+    anAISContext->Activate( anIO, AIS_DSM_Line );
+    anAISContext->Activate( anIO, AIS_DSM_Text );
+#endif
 
+    anAISContext->AddOrRemoveCurrentObject( anIO, Standard_False ); // todo: deprecated OCCT API
     anAISContext->UpdateCurrentViewer();
   }
 }