Salome HOME
best warning on qlineedit for double value
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index 2d0822288fab465a5824c36e6d2831bb01d14832..414094665dfa83211ef346660e9f0ade9cc6a113 100644 (file)
 //Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
 #define WITHGENERICOBJ
 
+// Below macro, when uncommented, switches on simplified (more performant) algorithm
+// of auto-color picking up
+#define SIMPLE_AUTOCOLOR
+
 //namespace{
   // Declarations
   //=============================================================
     if ( isDAT )
     {
       format = "DAT";
-      notSupportedElemTypes.push_back( SMESH::Entity_Quad_Quadrangle );
-      notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Quadrangle );
-      notSupportedElemTypes.push_back( SMESH::Entity_Polygon );
-      notSupportedElemTypes.push_back( SMESH::Entity_Quad_Polygon );
-      notSupportedElemTypes.push_back( SMESH::Entity_Tetra );
-      notSupportedElemTypes.push_back( SMESH::Entity_Quad_Tetra );
-      notSupportedElemTypes.push_back( SMESH::Entity_Pyramid );
-      notSupportedElemTypes.push_back( SMESH::Entity_Quad_Pyramid );
-      notSupportedElemTypes.push_back( SMESH::Entity_Quad_Hexa );
-      notSupportedElemTypes.push_back( SMESH::Entity_TriQuad_Hexa );
-      notSupportedElemTypes.push_back( SMESH::Entity_Penta );
-      notSupportedElemTypes.push_back( SMESH::Entity_Quad_Penta );
-      notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
-      notSupportedElemTypes.push_back( SMESH::Entity_Polyhedra );
       notSupportedElemTypes.push_back( SMESH::Entity_0D );
       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
     }
     {
       format = "CGNS";
       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
+      notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Triangle );
     }
     else if ( isSAUV )
     {
       format = "SAUV";
       notSupportedElemTypes.push_back( SMESH::Entity_Ball );
+      notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Triangle );
       notSupportedElemTypes.push_back( SMESH::Entity_BiQuad_Quadrangle );
       notSupportedElemTypes.push_back( SMESH::Entity_TriQuad_Hexa );
       notSupportedElemTypes.push_back( SMESH::Entity_Hexagonal_Prism );
     if ( !presentNotSupported.empty() )
     {
       QString typeNames;
-      const char* typeMsg[SMESH::Entity_Last] = { "SMESH_NODES",
-        "SMESH_ELEMS0D","SMESH_EDGES","SMESH_QUADRATIC_EDGES","SMESH_TRIANGLES",
-        "SMESH_QUADRATIC_TRIANGLES","SMESH_QUADRANGLES","SMESH_QUADRATIC_QUADRANGLES",
-        "SMESH_BIQUADRATIC_QUADRANGLES","SMESH_POLYGONS","SMESH_QUADRATIC_POLYGONS",
+      const char* typeMsg[SMESH::Entity_Last] = {
+        "SMESH_NODES", "SMESH_ELEMS0D","SMESH_EDGES","SMESH_QUADRATIC_EDGES",
+        "SMESH_TRIANGLES", "SMESH_QUADRATIC_TRIANGLES", "SMESH_BIQUADRATIC_TRIANGLES",
+        "SMESH_QUADRANGLES","SMESH_QUADRATIC_QUADRANGLES", "SMESH_BIQUADRATIC_QUADRANGLES",
+        "SMESH_POLYGONS","SMESH_QUADRATIC_POLYGONS",
         "SMESH_TETRAHEDRA","SMESH_QUADRATIC_TETRAHEDRONS","SMESH_PYRAMIDS",
         "SMESH_QUADRATIC_PYRAMIDS","SMESH_HEXAHEDRA","SMESH_QUADRATIC_HEXAHEDRONS",
         "SMESH_TRIQUADRATIC_HEXAHEDRONS","SMESH_PENTAHEDRA","SMESH_QUADRATIC_PENTAHEDRONS",
     if ( resMgr )
       toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
     bool toOverwrite = true;
+    bool toFindOutDim = true;
 
     QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
     QString anInitialPath = "";
                                             anInitialPath + QString("/") + aMeshName,
                                             aFilter, aTitle, false);
     }
-    // else if ( isGMF )// Export to GMF
-    // {
-      // SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
-      //   ( SMESHGUI::desktop(), false, QObject::tr("SMESH_REQUIRED_GROUPS"), true, true );
-      // QStringList filters;
-      // filters << QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)"
-      //         << QObject::tr( "GMF_BINARY_FILES_FILTER" )  + " (*.meshb)";
-      // fd->setWindowTitle( aTitle );
-      // fd->setNameFilters( filters );
-
-      // if ( !aMeshOrGroup->_is_equivalent( aMesh ))
-      //   toCreateGroups = false;
-      // else
-      //   toCreateGroups = ( aMesh->NbGroups() > 0 );
-
-      // fd->SetChecked( true );
-      // if ( !anInitialPath.isEmpty() )
-      //   fd->setDirectory( anInitialPath );
-      // fd->selectFile(aMeshName);
-
-      // if ( fd->exec() )
-      //   aFilename = fd->selectedFile();
-      // toCreateGroups = fd->IsChecked();
-
-      // delete fd;
-    // }
     else if ( isCGNS )// Export to CGNS
     {
       SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
         if (it.value() == SMESH::MED_V2_2)
           aDefaultFilter = it.key();
       }
+      QStringList checkBoxes;
+      checkBoxes << QObject::tr("SMESH_AUTO_GROUPS") << QObject::tr("SMESH_AUTO_DIM");
 
-      SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
-        ( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS"), true, true );
+      SalomeApp_CheckFileDlg* fd =
+        new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true );
       fd->setWindowTitle( aTitle );
       fd->setNameFilters( filters );
       fd->selectNameFilter(aDefaultFilter);
-      fd->SetChecked(toCreateGroups);
+      fd->SetChecked(0,toCreateGroups);
+      fd->SetChecked(1,toFindOutDim);
       if ( !anInitialPath.isEmpty() )
         fd->setDirectory( anInitialPath );
       fd->selectFile(aMeshName);
           }
         }
       }
-      toCreateGroups = fd->IsChecked();
+      toCreateGroups = fd->IsChecked(0);
+      toFindOutDim   = fd->IsChecked(1);
       delete fd;
     }
     else
             SMESH::SMESH_Mesh_var        aMeshItem = aMeshOrGroup->GetMesh();
             if ( aMeshOrGroup->_is_equivalent( aMeshItem ))
               aMeshItem->ExportToMEDX( aFilename.toLatin1().data(), toCreateGroups,
-                                       aFormat, toOverwrite && aMeshIndex == 0 );
+                                       aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim );
             else
               aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toLatin1().data(), toCreateGroups,
-                                          aFormat, toOverwrite && aMeshIndex == 0 );
+                                          aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim );
           }
         }
         else if ( isSAUV )
 
     aMainObject->SetAutoColor( true ); // mesh groups are re-colored here
 
+    QList<SALOMEDS::Color> aReservedColors;
+
     SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
     {
       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
-      SALOMEDS::Color aColor = aGroupObject->GetColor();
+      //SALOMEDS::Color aColor = aGroupObject->GetColor();
+      
+#ifdef SIMPLE_AUTOCOLOR   // simplified algorithm for auto-colors
+      SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
+#else                     // old algorithm  for auto-colors
+      SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
+      aReservedColors.append( aColor );
+#endif                    // SIMPLE_AUTOCOLOR
+
       _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
       if (aGroupSObject) {
         QColor c;
@@ -3057,6 +3039,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case 4035:     // QUADRATIC TRIANGLE
   case 4036:     // QUADRATIC QUADRANGLE
   case 4136:     // BIQUADRATIC QUADRANGLE
+  case 4137:     // BIQUADRATIC TRIANGLE
   case 4037:     // QUADRATIC TETRAHEDRON
   case 4038:     // QUADRATIC PYRAMID
   case 4039:     // QUADRATIC PENTAHEDRON
@@ -3077,6 +3060,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
           type = SMDSEntity_Quad_Quadrangle; break;
         case 4136:
           type = SMDSEntity_BiQuad_Quadrangle; break;
+        case 4137:
+          type = SMDSEntity_BiQuad_Triangle; break;
         case 4037:
           type = SMDSEntity_Quad_Tetra; break;
         case 4038:
@@ -3675,6 +3660,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction( 4035, "QUADRATIC_TRIANGLE",      "ICON_DLG_QUADRATIC_TRIANGLE" );
   createSMESHAction( 4036, "QUADRATIC_QUADRANGLE",    "ICON_DLG_QUADRATIC_QUADRANGLE" );
   createSMESHAction( 4136, "BIQUADRATIC_QUADRANGLE",  "ICON_DLG_BIQUADRATIC_QUADRANGLE" );
+  createSMESHAction( 4137, "BIQUADRATIC_TRIANGLE",    "ICON_DLG_BIQUADRATIC_TRIANGLE" );
   createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON",   "ICON_DLG_QUADRATIC_TETRAHEDRON" );
   createSMESHAction( 4038, "QUADRATIC_PYRAMID",       "ICON_DLG_QUADRATIC_PYRAMID" );
   createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON",   "ICON_DLG_QUADRATIC_PENTAHEDRON" );
@@ -3873,6 +3859,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( separator(), addId, -1 );
   createMenu( 4034, addId, -1 );
   createMenu( 4035, addId, -1 );
+  createMenu( 4137, addId, -1 );
   createMenu( 4036, addId, -1 );
   createMenu( 4136, addId, -1 );
   createMenu( 4037, addId, -1 );
@@ -3999,6 +3986,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createTool( separator(), addRemTb );
   createTool( 4034, addRemTb );
   createTool( 4035, addRemTb );
+  createTool( 4137, addRemTb );
   createTool( 4036, addRemTb );
   createTool( 4136, addRemTb );
   createTool( 4037, addRemTb );
@@ -6544,3 +6532,33 @@ bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
   }
   return false;
 }
+
+
+SALOMEDS::Color SMESHGUI::getPredefinedUniqueColor()
+{
+  static QList<QColor> colors;
+
+  if ( colors.isEmpty() ) {
+
+    for (int s = 0; s < 2 ; s++)
+    {
+      for (int v = 100; v >= 40; v = v - 20)
+      {
+        for (int h = 0; h < 359 ; h = h + 60)
+        {
+          colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
+        }
+      }
+    }
+  }
+  static int currentColor = 0;
+
+  SALOMEDS::Color color;
+  color.R = (double)colors[currentColor].red()   / 255.0;
+  color.G = (double)colors[currentColor].green() / 255.0;
+  color.B = (double)colors[currentColor].blue()  / 255.0;
+
+  currentColor = (currentColor+1) % colors.count();
+
+  return color;
+}