Salome HOME
Porting to VTK 6.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ClippingDlg.cxx
index ac190be77b4c17d6a890f56631cf20e4e67b2fd2..4d636f5316dc1cac5d306a96b91078f72f86ab08 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  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
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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.
+// 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.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 // SMESH SMESHGUI : GUI for SMESH component
@@ -105,6 +105,7 @@ void SMESH::OrientedPlane::ShallowCopy(SMESH::OrientedPlane* theOrientedPlane)
   myPlaneSource->SetOrigin(theOrientedPlane->myPlaneSource->GetOrigin());
   myPlaneSource->SetPoint1(theOrientedPlane->myPlaneSource->GetPoint1());
   myPlaneSource->SetPoint2(theOrientedPlane->myPlaneSource->GetPoint2());
+  myPlaneSource->Update();
 }
 
 SMESH::OrientedPlane::OrientedPlane(SVTK_ViewWindow* theViewWindow):
@@ -113,7 +114,7 @@ SMESH::OrientedPlane::OrientedPlane(SVTK_ViewWindow* theViewWindow):
   myDistance(0.5)
 {
   Init();
-  myViewWindow->AddActor(myActor);
+  myViewWindow->AddActor(myActor, false, false); // don't adjust actors
 }
 
 SMESH::OrientedPlane::OrientedPlane():
@@ -132,7 +133,7 @@ void SMESH::OrientedPlane::Init()
 
   // Create and display actor
   myMapper = vtkDataSetMapper::New();
-  myMapper->SetInput(myPlaneSource->GetOutput());
+  myMapper->SetInputConnection(myPlaneSource->GetOutputPort());
 
   myActor = SALOME_Actor::New();
   myActor->VisibilityOff();
@@ -140,7 +141,7 @@ void SMESH::OrientedPlane::Init()
   myActor->SetInfinitive(true);
   myActor->SetMapper(myMapper);
 
-  vtkFloatingPointType anRGB[3];
+  double anRGB[3];
   vtkProperty* aProp = vtkProperty::New();
   SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
   aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
@@ -194,7 +195,8 @@ private:
 struct TSetVisibility {
   TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){}
   void operator()(SMESH::TPlaneData& thePlaneData){
-    thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible);
+    bool anIsEmpty = thePlaneData.ActorList.empty();
+    thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty);
   }
   int myIsVisible;
 };
@@ -207,7 +209,7 @@ SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList
                                                       SVTK_ViewWindow*           theViewWindow,
                                                       SMESH::Orientation         theOrientation,
                                                       double                     theDistance,
-                                                      const vtkFloatingPointType theAngle[2])
+                                                      const double theAngle[2])
 {
   SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(theViewWindow);
 
@@ -217,13 +219,13 @@ SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList
   aPlane->SetOrientation(theOrientation);
   aPlane->SetDistance(theDistance);
 
-  vtkFloatingPointType aNormal[3];
-  vtkFloatingPointType aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
+  double aNormal[3];
+  double aDir[2][3] = {{0, 0, 0}, {0, 0, 0}};
   {
     static double aCoeff = vtkMath::Pi()/180.0;
 
-    vtkFloatingPointType anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
-    vtkFloatingPointType aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
+    double anU[2] = {cos(aCoeff * theAngle[0]), cos(aCoeff * theAngle[1])};
+    double aV[2] = {sqrt(1.0 - anU[0]*anU[0]), sqrt(1.0 - anU[1]*anU[1])};
     aV[0] = theAngle[0] > 0? aV[0]: -aV[0];
     aV[1] = theAngle[1] > 0? aV[1]: -aV[1];
 
@@ -259,51 +261,62 @@ SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList
     vtkMath::Cross(aNormal,aDir[1],aDir[0]);
   }
 
-  vtkFloatingPointType aBounds[6];
-  vtkFloatingPointType anOrigin[3];
-  bool anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
-                                                       aNormal,
-                                                       theDistance,
-                                                       aBounds,
-                                                       anOrigin );
+  double aBounds[6];
+  double anOrigin[3];
+
+  bool anIsOk = false;
+  if( theActorList.empty() ) {
+    // to support planes with empty actor list we should create
+    // a nullified plane that will be initialized later 
+    anOrigin[0] = anOrigin[1] = anOrigin[2] = 0;
+    aBounds[0] = aBounds[2] = aBounds[4] = 0;
+    aBounds[1] = aBounds[3] = aBounds[5] = 0;
+    anIsOk = true;
+  }
+  else
+    anIsOk = SMESH::ComputeClippingPlaneParameters( theActorList,
+                                                    aNormal,
+                                                    theDistance,
+                                                    aBounds,
+                                                    anOrigin );
   if( !anIsOk )
     return NULL;
 
   aPlane->SetNormal( aNormal );
   aPlane->SetOrigin( anOrigin );
 
-  vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
+  double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
                                    ( aBounds[2] + aBounds[3] ) / 2.,
                                    ( aBounds[4] + aBounds[5] ) / 2. };
 
-  vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
+  double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
                                    pow( aBounds[3] - aBounds[2], 2 ) +
                                    pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
 
-  vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
+  double aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
                                        {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
-  vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
+  double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
 
-  vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
+  double aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
                                     aPnt[1] - aDelta[0][1] - aDelta[1][1],
                                     aPnt[2] - aDelta[0][2] - aDelta[1][2]};
-  vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
+  double aPnt02[3] = {aPnt01[0] + aNormal[0],
                                     aPnt01[1] + aNormal[1],
                                     aPnt01[2] + aNormal[2]};
   vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
 
-  vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
+  double aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
                                     aPnt[1] - aDelta[0][1] + aDelta[1][1],
                                     aPnt[2] - aDelta[0][2] + aDelta[1][2]};
-  vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
+  double aPnt12[3] = {aPnt11[0] + aNormal[0],
                                     aPnt11[1] + aNormal[1],
                                     aPnt11[2] + aNormal[2]};
   vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
 
-  vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
+  double aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
                                     aPnt[1] + aDelta[0][1] - aDelta[1][1],
                                     aPnt[2] + aDelta[0][2] - aDelta[1][2]};
-  vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
+  double aPnt22[3] = {aPnt21[0] + aNormal[0],
                                     aPnt21[1] + aNormal[1],
                                     aPnt21[2] + aNormal[2]};
   vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
@@ -313,6 +326,7 @@ SMESH::OrientedPlane* SMESHGUI_ClippingDlg::AddPlane (SMESH::TActorList
   aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
   aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
   aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
+  aPlaneSource->Update();
 
   SMESH::TActorList::iterator anIter = theActorList.begin();
   for ( ; anIter != theActorList.end(); anIter++ )
@@ -358,7 +372,7 @@ SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow
 
   ActorList = new QListWidget(GroupPlanes);
   ActorList->setSelectionMode(QAbstractItemView::SingleSelection);
-
+  
   SelectAllCheckBox = new QCheckBox(tr("SELECT_ALL"), GroupPlanes);
 
   GroupPlanesLayout->addWidget(ComboBoxPlanes,    0, 0);
@@ -465,7 +479,7 @@ SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow
   connect(SpinBoxRot1, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
   connect(SpinBoxRot2, SIGNAL(valueChanged(double)), this, SLOT(SetCurrentPlaneParam()));
   connect(PreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(OnPreviewToggle(bool)));
-  connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(ClickOnApply()));
+  connect(AutoApplyCheckBox, SIGNAL(toggled(bool)), this, SLOT(onAutoApply(bool)));
   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
@@ -545,8 +559,10 @@ void SMESHGUI_ClippingDlg::ClickOnApply()
       SMESH::TPlaneData aPlaneData = *anIter2;
       SMESH::TPlane aPlane = aPlaneData.Plane;
       SMESH::TActorList anActorList = aPlaneData.ActorList;
-      if( anActorList.empty() )
-        continue;
+
+      // the check is disabled to support planes with empty actor list
+      //if( anActorList.empty() )
+      //  continue;
 
       SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
       anOrientedPlane->ShallowCopy(aPlane.GetPointer());
@@ -728,14 +744,8 @@ void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
         if( anItem->checkState() == Qt::Checked )
           aNbChecked++;
 
-    Qt::CheckState aCheckState = Qt::Unchecked;
-    if( aNbChecked == aNbItems )
-      aCheckState = Qt::Checked;
-    else if( aNbChecked > 0 )
-      aCheckState = Qt::PartiallyChecked;
-
     bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
-    SelectAllCheckBox->setCheckState( aCheckState );
+    SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
     SelectAllCheckBox->blockSignals( anIsBlocked );
   }
 
@@ -889,18 +899,18 @@ void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
   SMESH::TPlaneData aPlaneData = myPlanes[aCurPlaneIndex];
   SMESH::OrientedPlane* aPlane = aPlaneData.Plane.GetPointer();
 
-  vtkFloatingPointType aNormal[3];
+  double aNormal[3];
   SMESH::Orientation anOrientation;
-  vtkFloatingPointType aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
+  double aDir[3][3] = {{0, 0, 0}, {0, 0, 0}};
   {
     static double aCoeff = vtkMath::Pi()/180.0;
 
-    vtkFloatingPointType aRot[2] = {getRotation1(), getRotation2()};
+    double aRot[2] = {getRotation1(), getRotation2()};
     aPlane->myAngle[0] = aRot[0];
     aPlane->myAngle[1] = aRot[1];
 
-    vtkFloatingPointType anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
-    vtkFloatingPointType aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
+    double anU[2] = {cos(aCoeff*aRot[0]), cos(aCoeff*aRot[1])};
+    double aV[2] = {sqrt(1.0-anU[0]*anU[0]), sqrt(1.0-anU[1]*anU[1])};
     aV[0] = aRot[0] > 0? aV[0]: -aV[0];
     aV[1] = aRot[1] > 0? aV[1]: -aV[1];
 
@@ -947,8 +957,8 @@ void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
 
   SMESH::TActorList anActorList = aPlaneData.ActorList;
 
-  vtkFloatingPointType aBounds[6];
-  vtkFloatingPointType anOrigin[3];
+  double aBounds[6];
+  double anOrigin[3];
   bool anIsOk = SMESH::ComputeClippingPlaneParameters( anActorList,
                                                        aNormal,
                                                        getDistance(),
@@ -961,38 +971,38 @@ void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
     aPlane->SetNormal( aNormal );
     aPlane->SetOrigin( anOrigin );
 
-    vtkFloatingPointType aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
+    double aPnt[3] = { ( aBounds[0] + aBounds[1] ) / 2.,
                                      ( aBounds[2] + aBounds[3] ) / 2.,
                                      ( aBounds[4] + aBounds[5] ) / 2. };
 
-    vtkFloatingPointType aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
+    double aDel = pow( pow( aBounds[1] - aBounds[0], 2 ) +
                                      pow( aBounds[3] - aBounds[2], 2 ) +
                                      pow( aBounds[5] - aBounds[4], 2 ), 0.5 );
 
-    vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
+    double aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
                                          {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
-    vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
+    double aParam, aPnt0[3], aPnt1[3], aPnt2[3];
 
-    vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
+    double aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
                                       aPnt[1] - aDelta[0][1] - aDelta[1][1],
                                       aPnt[2] - aDelta[0][2] - aDelta[1][2]};
-    vtkFloatingPointType aPnt02[3] = {aPnt01[0] + aNormal[0],
+    double aPnt02[3] = {aPnt01[0] + aNormal[0],
                                       aPnt01[1] + aNormal[1],
                                       aPnt01[2] + aNormal[2]};
     vtkPlane::IntersectWithLine(aPnt01,aPnt02,aNormal,anOrigin,aParam,aPnt0);
 
-    vtkFloatingPointType aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
+    double aPnt11[3] = {aPnt[0] - aDelta[0][0] + aDelta[1][0],
                                       aPnt[1] - aDelta[0][1] + aDelta[1][1],
                                       aPnt[2] - aDelta[0][2] + aDelta[1][2]};
-    vtkFloatingPointType aPnt12[3] = {aPnt11[0] + aNormal[0],
+    double aPnt12[3] = {aPnt11[0] + aNormal[0],
                                       aPnt11[1] + aNormal[1],
                                       aPnt11[2] + aNormal[2]};
     vtkPlane::IntersectWithLine(aPnt11,aPnt12,aNormal,anOrigin,aParam,aPnt1);
 
-    vtkFloatingPointType aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
+    double aPnt21[3] = {aPnt[0] + aDelta[0][0] - aDelta[1][0],
                                       aPnt[1] + aDelta[0][1] - aDelta[1][1],
                                       aPnt[2] + aDelta[0][2] - aDelta[1][2]};
-    vtkFloatingPointType aPnt22[3] = {aPnt21[0] + aNormal[0],
+    double aPnt22[3] = {aPnt21[0] + aNormal[0],
                                       aPnt21[1] + aNormal[1],
                                       aPnt21[2] + aNormal[2]};
     vtkPlane::IntersectWithLine(aPnt21,aPnt22,aNormal,anOrigin,aParam,aPnt2);
@@ -1002,6 +1012,7 @@ void SMESHGUI_ClippingDlg::SetCurrentPlaneParam()
     aPlaneSource->SetOrigin(aPnt0[0],aPnt0[1],aPnt0[2]);
     aPlaneSource->SetPoint1(aPnt1[0],aPnt1[1],aPnt1[2]);
     aPlaneSource->SetPoint2(aPnt2[0],aPnt2[1],aPnt2[2]);
+    aPlaneSource->Update();
   }
 
   if(AutoApplyCheckBox->isChecked())
@@ -1049,7 +1060,9 @@ void SMESHGUI_ClippingDlg::initializePlaneData()
     SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
     for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
       const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
-      SMESH::TPlane aTPlane( aClippingPlaneInfo.Plane );
+      SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
+      anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
+      SMESH::TPlane aTPlane( anOrientedPlane );
       SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
       myPlanes.push_back( aPlaneData );
     }
@@ -1137,8 +1150,8 @@ void SMESHGUI_ClippingDlg::dumpPlaneData() const
   for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
     SMESH::TPlaneData aPlaneData = *anIter1;
     SMESH::TPlane aPlane = aPlaneData.Plane;
-    vtkFloatingPointType* aNormal = aPlane->GetNormal();
-    vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
+    double* aNormal = aPlane->GetNormal();
+    double* anOrigin = aPlane->GetOrigin();
     printf( "Plane N%d:\n", anId );
     printf( "  Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
     printf( "  Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
@@ -1156,3 +1169,8 @@ void SMESHGUI_ClippingDlg::dumpPlaneData() const
   }
   printf( "----------------------------------\n" );
 }
+
+void SMESHGUI_ClippingDlg::onAutoApply(bool toggled)
+{
+  if ( toggled ) ClickOnApply();
+}