Salome HOME
updating or adding when merging in the main trunk with the version in the
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index ab3327064d318d14e1801deaeca9863efefef90c..861630a2f8fda788e09a873c65392516f573b41f 100644 (file)
@@ -130,6 +130,7 @@ using namespace std;
 #include "VTKViewer_ViewFrame.h"
 #include <vtkLegendBoxActor.h>
 #include <vtkFeatureEdges.h>
+#include <vtkDoubleArray.h>
 
 
 // Open CASCADE Includes
@@ -216,7 +217,7 @@ SMESHGUI* SMESHGUI::GetOrCreateSMESHGUI( QAD_Desktop* desktop )
     Engines::Component_var comp = desktop->getEngine("FactoryServer", "SMESH");
     smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
     
-    Engines::Component_var comp1 = desktop->getEngine("FactoryServer", "Geometry");    
+    Engines::Component_var comp1 = desktop->getEngine("FactoryServer", "GEOM");    
     smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
       
     /* GetCurrentStudy */
@@ -400,6 +401,7 @@ void SMESHGUI::activeStudyChanged( QAD_Desktop* parent )
 bool SMESHGUI::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
 {
   /* Here the position is on the bottom right corner - 10 */
+       aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
   QAD_Desktop* PP = QAD_Application::getDesktop() ;
   x = abs ( PP->x() + PP->size().width()  - aDlg->size().width()  - 10 ) ;
   y = abs ( PP->y() + PP->size().height() - aDlg->size().height() - 10 ) ;
@@ -846,6 +848,8 @@ void SMESHGUI::CreateAlgorithm( QString TypeAlgo, QString NameAlgo )
       Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
     else if ( TypeAlgo.compare("Hexa_3D") == 0 )
       Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
+    else if ( TypeAlgo.compare("NETGEN_3D") == 0 )
+      Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
     
     if ( !Hyp->_is_nil() ) {
       SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms( Hyp );
@@ -928,7 +932,7 @@ void SMESHGUI::CreateMaxElementVolume( QString TypeHypothesis, QString NameHypot
  *
  */
 //=============================================================================
-void SMESHGUI::CreateNbSegments( QString TypeHypothesis, QString NameHypothesis, double nbSegments )
+void SMESHGUI::CreateNbSegments( QString TypeHypothesis, QString NameHypothesis, int nbSegments )
 {
   QApplication::setOverrideCursor( Qt::waitCursor );
   try {
@@ -1316,8 +1320,10 @@ void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
   case 0 : {
     QApplication::setOverrideCursor( Qt::waitCursor );
     if (ac->getDisplayMode()==2) {
+      bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
       vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
       meshMapper->SetInput(ac->DataSource);
+      meshMapper->SetScalarVisibility(isColored); //SAL3899
     }
     ac->setDisplayMode(0);
     ac->GetProperty()->SetRepresentationToWireframe();
@@ -1328,8 +1334,10 @@ void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
   case 1 : {
     QApplication::setOverrideCursor( Qt::waitCursor );
     if (ac->getDisplayMode()==2) {
+      bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
       vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
       meshMapper->SetInput(ac->DataSource);
+      meshMapper->SetScalarVisibility(isColored); //SAL3899
     }
     ac->setDisplayMode(1);
     ac->GetProperty()->SetRepresentationToSurface();
@@ -1342,13 +1350,14 @@ void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
     //    ChangeRepresentation(ac, 1);
     QApplication::setOverrideCursor( Qt::waitCursor );
     ac->setDisplayMode(2);
+    bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
     vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
-    meshMapper->SetInput(ac->DataSource);
     vtkShrinkFilter *shrink = vtkShrinkFilter::New();
-    shrink->SetInput(meshMapper->GetInput());
+    shrink->SetInput(ac->DataSource);
     shrink->SetShrinkFactor(ac->GetShrinkFactor());
     
     meshMapper->SetInput( shrink->GetOutput() );
+    meshMapper->SetScalarVisibility(isColored); //SAL3899
     ac->SetMapper( meshMapper );
     QApplication::restoreOverrideCursor();
     //    }
@@ -1361,13 +1370,29 @@ void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
       float backfacecolor[3];
       float nodecolor[3];
       ac->GetColor(color[0],color[1],color[2]);
-      QColor c(color[0]*255,color[1]*255,color[2]*255);
+//       QColor c(color[0]*255,color[1]*255,color[2]*255);
+      int c0 = int(color[0]*255);
+      int c1 = int(color[1]*255);
+      int c2 = int(color[2]*255);
+      QColor c( c0, c1, c2 );
       ac->GetEdgeColor(edgecolor[0],edgecolor[1],edgecolor[2]);
-      QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
+//       QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
+      c0 = int(edgecolor[0]*255);
+      c1 = int(edgecolor[1]*255);
+      c2 = int(edgecolor[2]*255);
+      QColor e( c0, c1, c2 );
       ac->GetBackfaceProperty()->GetColor(backfacecolor);
-      QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
+//       QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
+      c0 = int(backfacecolor[0]*255);
+      c1 = int(backfacecolor[1]*255);
+      c2 = int(backfacecolor[2]*255);
+      QColor b( c0, c1, c2 );
       ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2] ) ;
-      QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
+//       QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
+      c0 = int(nodecolor[0]*255);
+      c1 = int(nodecolor[1]*255);
+      c2 = int(nodecolor[2]*255);
+      QColor n( c0, c1, c2 ) ;
 
       int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
       if ( Edgewidth == 0 )
@@ -1418,6 +1443,7 @@ void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
        ac->SetNodeSize(aDlg->GetIntValue(2)) ;
        
        if (ac->getDisplayMode()==2) {
+         bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
          vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
          meshMapper->SetInput(ac->DataSource);
          vtkShrinkFilter *shrink = vtkShrinkFilter::New();
@@ -1425,6 +1451,7 @@ void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
          shrink->SetShrinkFactor(ac->GetShrinkFactor());
          
          meshMapper->SetInput( shrink->GetOutput() );
+         meshMapper->SetScalarVisibility(isColored); //SAL3899
          ac->SetMapper( meshMapper );
        }
       }
@@ -2283,7 +2310,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID,       QAD_Desktop* parent)
              double beforeMaxVolume = MEV->GetMaxElementVolume() ;
              double MaxVolume = smeshGUI->Parameter( res, 
                                                      beforeMaxVolume,
-                                                     tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"), 
+                                                     tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"), 
                                                      tr("SMESH_VALUE"), 
                                                      1.0E-5, 1E6, 6 ) ;
              if ( res && MaxVolume != beforeMaxVolume ) {
@@ -2487,7 +2514,12 @@ bool SMESHGUI::OnGUIEvent(int theCommandID,      QAD_Desktop* parent)
       }
     case 5020: 
       {
-       smeshGUI->CreateAlgorithm("Hexa_3D","Hexaedral (i,j,k)");       
+       smeshGUI->CreateAlgorithm("Hexa_3D","Hexahedron (i,j,k)");      
+       break;
+      }
+    case 5021: 
+      {
+       smeshGUI->CreateAlgorithm("NETGEN_3D","Tetrahedron (Netgen)");  
        break;
       }
 
@@ -2823,7 +2855,7 @@ void SMESHGUI::Import_Mesh(QAD_Desktop* parent, int theCommandID)
 //    Mesh_Reader* myReader = SMESHDriver::GetMeshReader(myExtension, myClass);
     
     int myMeshId = (smeshGUI->myDocument)->NewMesh();
-    Handle(SMDS_Mesh) myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
+    SMDS_Mesh* myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
 
     myReader->SetFile(string(filename.latin1()));
     myReader->SetMesh(myMesh);
@@ -2940,7 +2972,7 @@ void SMESHGUI::Import_Document(QAD_Desktop* parent, int theCommandID)
     QApplication::setOverrideCursor( Qt::waitCursor );
     string myClass = string("SMESHDS_Document");
 //    Document_Reader* myReader = SMESHDriver::GetDocumentReader(myExtension, myClass);
-    Handle(SMESHDS_Document) newDocument = new SMESHDS_Document(1);
+       SMESHDS_Document* newDocument = new SMESHDS_Document(1);
 
     myReader->SetFile(string(filename.latin1()));
     myReader->SetDocument(smeshGUI->myDocument);
@@ -4535,9 +4567,7 @@ void SMESHGUI::Control(int theCommandID)
   QApplication::setOverrideCursor( Qt::waitCursor );
   DisplayScalarBar( false );
 
-// mpv porting vtk 4.2.2
-//  vtkScalars *scalars = vtkScalars::New();
-  vtkIntArray *scalars = vtkIntArray::New();
+  vtkDoubleArray *scalars = vtkDoubleArray::New();
   scalars->SetNumberOfComponents(1);
 
   vtkDataSetMapper* meshMapper = 0;
@@ -4553,140 +4583,60 @@ void SMESHGUI::Control(int theCommandID)
     return;
   }
 
-  bool ValidateScalars = false;
-  if ( result ) {
+  vtkDataSet* aDataSet = MeshActor->DataSource;
+  typedef double (*TScalarFun)(vtkCell* theCell);
+  TScalarFun aScalarFun;
+  if(result){
     QString type;
-    switch (theCommandID)
-      {
-      case 6001: //Length Edges
-       {
-         type = tr( "SMESH_CONTROL_LENGTH_EDGES");
-         meshMapper = (vtkDataSetMapper*)MeshActor->EdgeDevice->GetMapper();
-         vtkUnstructuredGrid* grid = (vtkUnstructuredGrid*)meshMapper->GetInput();
-         MESSAGE ( " init minimum length " << grid->GetNumberOfCells() )
-         for (int i=0; i<grid->GetNumberOfCells(); i++ ) {
-           vtkCell* cell = grid->GetCell(i);
-           float len = SMESHGUI_ComputeScalarValue::LengthEdges(cell);
-           if (len == 0) continue;
-           else {
-             ValidateScalars = true;
-// mpv porting vtk 4.2.2
-//           scalars->InsertScalar(i,len);
-             scalars->InsertTuple1(i,len);
-           }
-         }
-         if (ValidateScalars && (MeshActor->getDisplayMode()!=0))
-           ChangeRepresentation( MeshActor, 1 );// limitation; in Wireframe, colored edges are not visible
-         break;
-       }
-      case 6011: // Area Elements
-       {
-         type = tr( "SMESH_CONTROL_AREA_ELEMENTS");
-         for (int i=0; i< MeshActor->GetMapper()->GetInput()->GetNumberOfCells(); i++ ) {
-           vtkCell* cell = MeshActor->GetMapper()->GetInput()->GetCell(i);
-           float area = SMESHGUI_ComputeScalarValue::AreaElements(cell);
-           if (area == 0) continue;
-           else {
-             ValidateScalars = true;
-// mpv porting vtk 4.2.2
-//           scalars->InsertScalar(i,area);
-             scalars->InsertTuple1(i,area);
-           }
-         }
-         if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
-           ChangeRepresentation( MeshActor, 1 );
-         break;
-       }
-      case 6012: // Taper
-       {
-         type = tr( "SMESH_CONTROL_TAPER_ELEMENTS");
-         for (int i=0; i< MeshActor->DataSource->GetNumberOfCells(); i++ ) {
-           vtkCell* cell = MeshActor->DataSource->GetCell(i);
-           float taper = SMESHGUI_ComputeScalarValue::Taper(cell);
-           if (taper == 0) continue;
-           else {
-             ValidateScalars = true;
-// mpv porting vtk 4.2.2
-//           scalars->InsertScalar(i,taper);
-             scalars->InsertTuple1(i,taper);
-           }
-         }
-         break;
-       }
-      case 6013: // Aspect ratio
-       {
-         type = tr( "SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
-         for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
-           vtkCell* cell = MeshActor->DataSource->GetCell(i);
-           float aspect = SMESHGUI_ComputeScalarValue::AspectRatio(cell);
-           if (aspect == 0) continue;
-           else {
-             ValidateScalars = true;
-// mpv porting vtk 4.2.2
-//           scalars->InsertScalar(i,aspect);
-             scalars->InsertTuple1(i,aspect);
-           }
-         }
-         if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
-           ChangeRepresentation( MeshActor, 1 );
-         break;
-       }
-      case 6014: // Minimum angle
-       {
-         type = tr( "SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
-         for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
-           vtkCell* cell = MeshActor->DataSource->GetCell(i);
-           float angle = SMESHGUI_ComputeScalarValue::MinimumAngle(cell);
-           if (angle == 0) continue;
-           else {
-             ValidateScalars = true;
-// mpv porting vtk 4.2.2
-//           scalars->InsertScalar(i,angle);
-             scalars->InsertTuple1(i,angle);
-           }
-         }
-         if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
-           ChangeRepresentation( MeshActor, 1 );
-         break;
-       }
-      case 6015: // Warp
-       {
-         type = tr( "SMESH_CONTROL_WARP_ELEMENTS");
-         for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
-           vtkCell* cell = MeshActor->DataSource->GetCell(i);
-           float Warp = SMESHGUI_ComputeScalarValue::Warp(cell);
-           if (Warp == 0) continue;
-           else {
-             ValidateScalars = true;
-// mpv porting vtk 4.2.2
-//           scalars->InsertScalar(i,Warp);
-             scalars->InsertTuple1(i,Warp);
-           }
-         }
-         break;
-       }
-      case 6016: // Skew
-       {
-         type = tr( "SMESH_CONTROL_SKEW_ELEMENTS");
-         for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
-           vtkCell* cell = MeshActor->DataSource->GetCell(i);
-           float angle = SMESHGUI_ComputeScalarValue::Skew(cell);
-           if (angle == 0) continue;
-           else {
-             ValidateScalars = true;
-// mpv porting vtk 4.2.2
-//           scalars->InsertScalar(i,angle);
-             scalars->InsertTuple1(i,angle);
-           }
-         }
-         break;
-       }
-      }
-
-    if ( !ValidateScalars ) {
-      QApplication::restoreOverrideCursor();
-      return;
+    switch (theCommandID){
+    case 6001: {
+      type = tr( "SMESH_CONTROL_LENGTH_EDGES");
+      aDataSet = MeshActor->EdgeDevice->GetMapper()->GetInput();
+      aScalarFun = &(SMESHGUI_ComputeScalarValue::LengthEdges);
+      MESSAGE ( " init minimum length " << aDataSet->GetNumberOfCells() );
+      if(MeshActor->getDisplayMode() != 0)
+       ChangeRepresentation( MeshActor, 1);// limitation; in Wireframe, colored edges are not visible
+      break;
+    } 
+    case 6011: {
+      type = tr( "SMESH_CONTROL_AREA_ELEMENTS");
+      aScalarFun = &(SMESHGUI_ComputeScalarValue::AreaElements);
+      if(MeshActor->getDisplayMode() != 1)
+       ChangeRepresentation( MeshActor, 1 );
+      break;
+    }
+    case 6012: {
+      type = tr( "SMESH_CONTROL_TAPER_ELEMENTS");
+      aScalarFun = &(SMESHGUI_ComputeScalarValue::Taper);
+      break;
+    }
+    case 6013: {
+      type = tr( "SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
+      aScalarFun = &(SMESHGUI_ComputeScalarValue::AspectRatio);
+      if(MeshActor->getDisplayMode() != 1)
+       ChangeRepresentation( MeshActor, 1 );
+      break;
     }
+    case 6014: {
+      type = tr( "SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
+      aScalarFun = &(SMESHGUI_ComputeScalarValue::MinimumAngle);
+      if(MeshActor->getDisplayMode() != 1)
+       ChangeRepresentation( MeshActor, 1 );
+      break;
+    }
+    case 6015: {
+      type = tr( "SMESH_CONTROL_WARP_ELEMENTS");
+      aScalarFun = &(SMESHGUI_ComputeScalarValue::Warp);
+      break;
+    }
+    case 6016: {
+      type = tr( "SMESH_CONTROL_SKEW_ELEMENTS");
+      aScalarFun = &(SMESHGUI_ComputeScalarValue::Skew);
+      break;
+    }}
+
+    for(int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++)
+      scalars->InsertTuple1(i,aScalarFun(aDataSet->GetCell(i)));
 
     float range[2];
     scalars->GetRange(range);
@@ -4699,7 +4649,7 @@ void SMESHGUI::Control(int theCommandID)
 
     if (!meshMapper) meshMapper = (vtkDataSetMapper*) (MeshActor->getMapper());
     meshMapper->SetScalarModeToUseCellData();
-    meshMapper->GetInput()->GetCellData()->SetScalars(scalars);
+    MeshActor->DataSource->GetCellData()->SetScalars(scalars);
     meshMapper->SetScalarRange( range );
     meshMapper->ScalarVisibilityOn();
 
@@ -5307,7 +5257,8 @@ void SMESHGUI::DisplaySimulationNode( SMESH::SMESH_Mesh_ptr aMesh, float x, floa
     QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
     QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
     if ( !nodecolor.isValid() )
-      nodecolor = QColor(0.,1.,0.);
+//       nodecolor = QColor(0.,1.,0.);
+      nodecolor = QColor(0,1,0);
 
     node->GetProperty()->SetColor( float(nodecolor.red())/255.,
                                   float(nodecolor.green())/255.,