Salome HOME
updated copyright message
[modules/gui.git] / src / OCCViewer / OCCViewer_ClippingDlg.cxx
index ec75a10529ccbf4c4e93c1cfaddddf4078b41f33..de2c0916a1809204346b2ba689d100914789162b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include "OCCViewer_ClipPlaneInteractor.h"
 
 #include <V3d_View.hxx>
-#include <Visual3d_View.hxx>
 #include <Geom_Plane.hxx>
 #include <Prs3d_Presentation.hxx>
+#include <Prs3d_PlaneAspect.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_InteractiveContext.hxx>
+#include <Prs3d_Drawer.hxx>
 #include <IntAna_IntConicQuad.hxx>
 #include <gp_Lin.hxx>
 #include <gp_Pln.hxx>
@@ -92,7 +93,13 @@ void getMinMaxFromContext( Handle(AIS_InteractiveContext) ic,
       if ( !aPrs->IsEmpty() && !aPrs->IsInfinite() ) {
         isFound = true;
         double xmin, ymin, zmin, xmax, ymax, zmax;
-        aPrs->MinMaxValues( xmin, ymin, zmin, xmax, ymax, zmax );
+       Bnd_Box aBox = aPrs->MinMaxValues();
+       xmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
+       ymin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
+       zmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
+       xmax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().X();
+       ymax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().Y();
+       zmax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().Z();
         aXMin = qMin( aXMin, xmin );  aXMax = qMax( aXMax, xmax );
         aYMin = qMin( aYMin, ymin );  aYMax = qMax( aYMax, ymax );
         aZMin = qMin( aZMin, zmin );  aZMax = qMax( aZMax, zmax );
@@ -507,7 +514,7 @@ OCCViewer_ClippingDlg::OCCViewer_ClippingDlg(OCCViewer_ViewWindow* parent , OCCV
   QFont fnt = SpinSliderDistance->font(); fnt.setBold( true ); SpinSliderDistance->setFont( fnt );
   GroupParametersLayout->addWidget( SpinSliderDistance, 1, 1 );
 
-  QString aUnitRot = "\xB0";
+  QString aUnitRot = QString(QChar(0xB0));
 
   TextLabelRotation1 = new QLabel( tr("ROTATION_AROUND_X_Y2Z"), GroupParameters );
   TextLabelRotation1->setObjectName( "TextLabelRotation1" );
@@ -552,15 +559,15 @@ OCCViewer_ClippingDlg::OCCViewer_ClippingDlg(OCCViewer_ViewWindow* parent , OCCV
   buttonOk = new QPushButton( GroupButtons );
   buttonOk->setObjectName( "buttonOk" );
   buttonOk->setText( tr( "BUT_APPLY_AND_CLOSE"  ) );
-  buttonOk->setAutoDefault( TRUE );
-  buttonOk->setDefault( TRUE );
+  buttonOk->setAutoDefault( true );
+  buttonOk->setDefault( true );
   GroupButtonsLayout->addWidget( buttonOk );
 
   buttonApply = new QPushButton( GroupButtons );
   buttonApply->setObjectName( "buttonApply" );
   buttonApply->setText( tr( "BUT_APPLY"  ) );
-  buttonApply->setAutoDefault( TRUE );
-  buttonApply->setDefault( TRUE );
+  buttonApply->setAutoDefault( true );
+  buttonApply->setDefault( true );
   GroupButtonsLayout->addWidget( buttonApply );
 
   GroupButtonsLayout->addStretch();
@@ -568,11 +575,11 @@ OCCViewer_ClippingDlg::OCCViewer_ClippingDlg(OCCViewer_ViewWindow* parent , OCCV
   buttonClose = new QPushButton( GroupButtons );
   buttonClose->setObjectName( "buttonClose" );
   buttonClose->setText( tr( "BUT_CLOSE"  ) );
-  buttonClose->setAutoDefault( TRUE );
+  buttonClose->setAutoDefault( true );
   GroupButtonsLayout->addWidget( buttonClose );
 
   QPushButton* buttonHelp = new QPushButton( tr( "HELP" ), GroupButtons );
-  buttonHelp->setAutoDefault( TRUE );
+  buttonHelp->setAutoDefault( true );
   GroupButtonsLayout->addWidget( buttonHelp );
 
   /***************************************************************/
@@ -629,8 +636,10 @@ OCCViewer_ClippingDlg::OCCViewer_ClippingDlg(OCCViewer_ViewWindow* parent , OCCV
 
   OCCViewer_ViewManager* aViewMgr = (OCCViewer_ViewManager*) myModel->getViewManager();
   myInteractor = new OCCViewer_ClipPlaneInteractor( aViewMgr, this );
-  connect( myInteractor, SIGNAL( planeClicked( const Handle_AIS_Plane& ) ), SLOT( onPlaneClicked( const Handle_AIS_Plane& ) ) );
-  connect( myInteractor, SIGNAL( planeDragged( const Handle_AIS_Plane& ) ), SLOT( onPlaneDragged( const Handle_AIS_Plane& ) ) );
+  connect( myInteractor, SIGNAL( planeClicked( const Handle_AIS_Plane& ) ),
+          SLOT( onPlaneClicked( const Handle_AIS_Plane& ) ) );
+  connect( myInteractor, SIGNAL( planeDragged( const Handle_AIS_Plane& ) ),
+          SLOT( onPlaneDragged( const Handle_AIS_Plane& ) ) );
 
   myLocalPlanes = myModel->getClipPlanes();
   synchronize();
@@ -732,6 +741,7 @@ void OCCViewer_ClippingDlg::setPlaneParam( OCCViewer_ClipPlane& thePlane )
       thePlane.AbsoluteOrientation.Dx = SpinBox_Dx->value();
       thePlane.AbsoluteOrientation.Dy = SpinBox_Dy->value();
       thePlane.AbsoluteOrientation.Dz = SpinBox_Dz->value();
+      thePlane.AbsoluteOrientation.IsInvert = false;
     }
     else
     {
@@ -781,7 +791,7 @@ void OCCViewer_ClippingDlg::setPlaneParam( OCCViewer_ClipPlane& thePlane )
 void OCCViewer_ClippingDlg::synchronize()
 {
   ComboBoxPlanes->clear();
-  int aNbPlanesAbsolute = myLocalPlanes.size();
+  int aNbPlanesAbsolute = (int)myLocalPlanes.size();
 
   QString aName;
   for(int i = 1; i<=aNbPlanesAbsolute; i++ ) {
@@ -845,7 +855,9 @@ void OCCViewer_ClippingDlg::displayPreview()
       clipPlaneParams(aClipPlane, ic, aSize, aBasePnt, aNormal, myModel->trihedronSize());
       myPreviewPlane = new AIS_Plane( new Geom_Plane( aBasePnt, aNormal ), aBasePnt );
       myPreviewPlane->SetTypeOfSensitivity( Select3D_TOS_INTERIOR );
-      myPreviewPlane->SetSize( aSize, aSize );
+      Handle(Prs3d_PlaneAspect) aPlaneAspect = new Prs3d_PlaneAspect();
+      aPlaneAspect->SetPlaneLength( aSize, aSize );
+      myPreviewPlane->Attributes()->SetPlaneAspect( aPlaneAspect );
       ic->SetWidth( myPreviewPlane, 10, false );
       ic->SetMaterial( myPreviewPlane, Graphic3d_NOM_PLASTIC, false );
       ic->SetTransparency( myPreviewPlane, 0.5, false );
@@ -893,7 +905,7 @@ void OCCViewer_ClippingDlg::updatePreview() {
     gp_Pnt aBasePnt;
     gp_Dir aNormal;
     clipPlaneParams(aClipPlane, ic, aSize, aBasePnt, aNormal, myModel->trihedronSize());
-    if(myPreviewPlaneVector.size() < clipPlanesCount()) {
+    if((int)myPreviewPlaneVector.size() < clipPlanesCount()) { //TODO: mismatch signed/unsigned
       myPreviewPlaneVector.resize(clipPlanesCount());
     }
     myPreviewPlane = myPreviewPlaneVector[aCurPlaneIndex];
@@ -901,7 +913,9 @@ void OCCViewer_ClippingDlg::updatePreview() {
       //Plane was not created
       myPreviewPlane = new AIS_Plane( new Geom_Plane( aBasePnt, aNormal ), aBasePnt );
       myPreviewPlane->SetTypeOfSensitivity( Select3D_TOS_INTERIOR );
-      myPreviewPlane->SetSize( aSize, aSize );
+      Handle(Prs3d_PlaneAspect) aPlaneAspect = new Prs3d_PlaneAspect();
+      aPlaneAspect->SetPlaneLength( aSize, aSize );
+      myPreviewPlane->Attributes()->SetPlaneAspect( aPlaneAspect );
       ic->Display( myPreviewPlane, 1, 0, false );
       ic->SetWidth( myPreviewPlane, 10, false );
       ic->SetMaterial( myPreviewPlane, Graphic3d_NOM_PLASTIC, false );
@@ -916,7 +930,7 @@ void OCCViewer_ClippingDlg::updatePreview() {
     ic->SetColor( myPreviewPlane, Quantity_Color( 255. / 255., 70. / 255., 0. / 255., Quantity_TOC_RGB ), false );
     ic->Update( myPreviewPlane, Standard_False );
   } else {
-    if(myPreviewPlaneVector.size() > aCurPlaneIndex ) {
+    if((int)myPreviewPlaneVector.size() > aCurPlaneIndex ) {
       myPreviewPlane = myPreviewPlaneVector[aCurPlaneIndex];
       if(ic->IsDisplayed(myPreviewPlane)) {
        ic->Erase( myPreviewPlane, false );
@@ -925,7 +939,7 @@ void OCCViewer_ClippingDlg::updatePreview() {
       myPreviewPlaneVector[aCurPlaneIndex].Nullify();
     }
   }
-  for(int i = 0; i < myPreviewPlaneVector.size(); i++) {
+  for(int i = 0; i < (int)myPreviewPlaneVector.size(); i++) {//TODO: mismatch signed/unsigned
     if( i == aCurPlaneIndex ) continue;
     if(!myPreviewPlaneVector[i].IsNull())
       ic->SetColor( myPreviewPlaneVector[i], Quantity_Color( 85 / 255., 85 / 255., 255 / 255., Quantity_TOC_RGB ), false );
@@ -955,7 +969,7 @@ void OCCViewer_ClippingDlg::erasePreview()
 
   Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
 
-  for ( int i=0; i < myPreviewPlaneVector.size(); i++ ) {
+  for ( int i=0; i < (int)myPreviewPlaneVector.size(); i++ ) {//TODO: mismatch signed/unsigned
   Handle(AIS_Plane) myPreviewPlane = myPreviewPlaneVector[i];
     if ( !myPreviewPlane.IsNull() && ic->IsDisplayed( myPreviewPlane ) ) {
       ic->Erase( myPreviewPlane, false );
@@ -1085,7 +1099,7 @@ void OCCViewer_ClippingDlg::ClickOnDelete()
 
   Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
 
-  if(aPlaneIndex+1 <= myPreviewPlaneVector.size()) {
+  if(aPlaneIndex+1 <= (int)myPreviewPlaneVector.size()) {
     Handle(AIS_Plane) myPreviewPlane = myPreviewPlaneVector[aPlaneIndex];
     if ( !myPreviewPlane.IsNull() && ic->IsDisplayed( myPreviewPlane ) ) {
       ic->Erase( myPreviewPlane, false );
@@ -1155,7 +1169,7 @@ void OCCViewer_ClippingDlg::ClickOnHelp()
 {
   SUIT_Application* app = SUIT_Session::session()->activeApplication();
   if ( app )
-    app->onHelpContextModule( "GUI", "occ_3d_viewer_page.html", "clipping_planes" );
+    app->onHelpContextModule( "GUI", "occ_3d_viewer.html", "clipping-planes" );
 }
 
 /*!
@@ -1213,7 +1227,7 @@ void OCCViewer_ClippingDlg::onSelectPlane ( int theIndex )
     return;
   }
 
-  OCCViewer_ClipPlane& aClipPlane = getClipPlane( theIndex );
+  //OCCViewer_ClipPlane& aClipPlane = getClipPlane( theIndex ); // unused
 
   myIsSelectPlane = true;
   updateControls();
@@ -1249,6 +1263,7 @@ void OCCViewer_ClippingDlg::onReset()
   SpinBox_Z->setValue(0);
   myBusy = false;
 
+  SetCurrentPlaneParam();
   updateClipping();
 }
 
@@ -1299,47 +1314,50 @@ void OCCViewer_ClippingDlg::onOrientationAbsoluteChanged( int mode )
   SpinBox_Dy->setEnabled( isUserMode );
   SpinBox_Dz->setEnabled( isUserMode );
 
-  if ( !isUserMode ) {
-
-    double aDx = 0, aDy = 0, aDz = 0;
+  int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
+  OCCViewer_ClipPlane& aPlane = getClipPlane( aCurPlaneIndex );
+  double aDx = 0, aDy = 0, aDz = 0;
 
-    if ( mode == 1 )
-    {
-      aDz = 1;
-      TextLabelZ->setEnabled( true );
-      SpinBox_Z->setEnabled( true );
-      SpinBox_Z->setFocus();
-    }
-    else if ( mode == 2 )
-    {
-      aDx = 1;
-      TextLabelX->setEnabled( true );
-      SpinBox_X->setEnabled( true );
-      SpinBox_X->setFocus();
-    }
-    else if ( mode == 3 )
-    {
-      aDy = 1;
-      TextLabelY->setEnabled( true );
-      SpinBox_Y->setEnabled( true );
-      SpinBox_Y->setFocus();
-    }
-    
-    int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
-    OCCViewer_ClipPlane& aPlane = getClipPlane( aCurPlaneIndex );
-    if ( aPlane.AbsoluteOrientation.IsInvert == true )
-    {
-      aDx = -aDx;
-      aDy = -aDy;
-      aDz = -aDz;
-    }
+  if ( mode == 0 )
+  {
+    aDx = aPlane.AbsoluteOrientation.Dx;
+    aDy = aPlane.AbsoluteOrientation.Dy;
+    aDz = aPlane.AbsoluteOrientation.Dz;
+  }
+  else if ( mode == 1 )
+  {
+    aDz = 1;
+    TextLabelZ->setEnabled( true );
+    SpinBox_Z->setEnabled( true );
+    SpinBox_Z->setFocus();
+  }
+  else if ( mode == 2 )
+  {
+    aDx = 1;
+    TextLabelX->setEnabled( true );
+    SpinBox_X->setEnabled( true );
+    SpinBox_X->setFocus();
+  }
+  else if ( mode == 3 )
+  {
+    aDy = 1;
+    TextLabelY->setEnabled( true );
+    SpinBox_Y->setEnabled( true );
+    SpinBox_Y->setFocus();
+  }
     
-    myBusy = true;
-    SpinBox_Dx->setValue( aDx );
-    SpinBox_Dy->setValue( aDy );
-    SpinBox_Dz->setValue( aDz );
-    myBusy = false;
+  if ( aPlane.AbsoluteOrientation.IsInvert == true )
+  {
+    aDx = -aDx;
+    aDy = -aDy;
+    aDz = -aDz;
   }
+    
+  myBusy = true;
+  SpinBox_Dx->setValue( aDx );
+  SpinBox_Dy->setValue( aDy );
+  SpinBox_Dz->setValue( aDz );
+  myBusy = false;
 
   if ( !myIsUpdatingControls )
   {
@@ -1423,9 +1441,9 @@ void OCCViewer_ClippingDlg::onApply()
 /*!
   SLOT: Called when clip plane is clicked in viewer.
 */
-void OCCViewer_ClippingDlg::onPlaneClicked( const Handle(AIS_Plane)& thePlane )
+void OCCViewer_ClippingDlg::onPlaneClicked( const Handle_AIS_Plane& thePlane )
 {
-  for ( int aPlaneIt = 0; aPlaneIt < myPreviewPlaneVector.size(); aPlaneIt++ )
+  for ( int aPlaneIt = 0; aPlaneIt < (int)myPreviewPlaneVector.size(); aPlaneIt++ )
   {
     Handle(AIS_Plane)& aPlane = myPreviewPlaneVector.at( aPlaneIt );
     if ( aPlane != thePlane )
@@ -1442,9 +1460,9 @@ void OCCViewer_ClippingDlg::onPlaneClicked( const Handle(AIS_Plane)& thePlane )
 /*!
   SLOT: Called when clip plane is changed by dragging in viewer.
 */
-void OCCViewer_ClippingDlg::onPlaneDragged( const Handle(AIS_Plane)& thePlane )
+void OCCViewer_ClippingDlg::onPlaneDragged( const Handle_AIS_Plane& thePlane )
 {
-  for ( int aPlaneIt = 0; aPlaneIt < myPreviewPlaneVector.size(); aPlaneIt++ )
+  for ( int aPlaneIt = 0; aPlaneIt < (int)myPreviewPlaneVector.size(); aPlaneIt++ )
   {
     Handle(AIS_Plane)& aPlane = myPreviewPlaneVector.at( aPlaneIt );
     if ( aPlane != thePlane )
@@ -1466,9 +1484,10 @@ void OCCViewer_ClippingDlg::onPlaneDragged( const Handle(AIS_Plane)& thePlane )
     {
       if ( aClipPlane.OrientationType == OCCViewer_ClipPlane::AbsoluteCustom )
       {
-        aClipPlane.AbsoluteOrientation.Dx = aPlaneN.X();
-        aClipPlane.AbsoluteOrientation.Dy = aPlaneN.Y();
-        aClipPlane.AbsoluteOrientation.Dz = aPlaneN.Z();
+        int anInvertCoeff = aClipPlane.AbsoluteOrientation.IsInvert ? 1 : -1;
+        aClipPlane.AbsoluteOrientation.Dx = anInvertCoeff * aPlaneN.X();
+        aClipPlane.AbsoluteOrientation.Dy = anInvertCoeff * aPlaneN.Y();
+        aClipPlane.AbsoluteOrientation.Dz = anInvertCoeff * aPlaneN.Z();
       }
     }
     else