Salome HOME
0021197: EDF 1772 SMESH: Automatic meshing hypothesis
authoreap <eap@opencascade.com>
Fri, 11 Mar 2011 13:16:16 +0000 (13:16 +0000)
committereap <eap@opencascade.com>
Fri, 11 Mar 2011 13:16:16 +0000 (13:16 +0000)
return names of HypoSets sorted with dimension and [custom] appended

-  QStringList GetHypothesesSets();
+  QStringList GetHypothesesSets( int maxDim );

src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx
src/SMESHGUI/SMESHGUI_HypothesesUtils.h

index 005e6a87345a0d37feecec9494ea05e8a84baaca..3eb8a4b6ec468cdfbf0c90e81dc7b7d18a63abe2 100644 (file)
@@ -50,6 +50,7 @@
 
 // Qt includes
 #include <QMap>
 
 // Qt includes
 #include <QMap>
+#include <QDir>
 //#include <QList>
 
 // Other includes
 //#include <QList>
 
 // Other includes
@@ -126,6 +127,40 @@ namespace SMESH
     }
   }
 
     }
   }
 
+  //================================================================================
+  /*!
+   * \brief Prepends dimension and appends '[custom]' to the name of hypothesis set
+   */
+  //================================================================================
+
+  static QString mangledHypoSetName(HypothesesSet* hypSet)
+  {
+    QString name = hypSet->name();
+
+    // prepend 'xD: '
+    int dim = hypSet->maxDim();
+    if ( dim > -1 )
+      name = QString("%1D: %2").arg(dim).arg(name);
+
+    // custom
+    if ( hypSet->getIsCustom() )
+      name = QString("%1 [custom]").arg(name);
+
+    return name;
+  }
+
+  //================================================================================
+  /*!
+   * \brief Removes dimension and '[custom]' from the name of hypothesis set
+   */
+  //================================================================================
+
+  static QString demangledHypoSetName(QString name)
+  {
+    name.remove(QRegExp("[0-3]D: "));
+    name.remove(" [custom]");
+    return name;
+  }
 
   void InitAvailableHypotheses()
   {
 
   void InitAvailableHypotheses()
   {
@@ -148,9 +183,9 @@ namespace SMESH
                                   QObject::tr("MESHERS_FILE_NO_VARIABLE"));
         return;
       }
                                   QObject::tr("MESHERS_FILE_NO_VARIABLE"));
         return;
       }
-
-      // loop on files in HypsXml
-      QString aNoAccessFiles;
+      // get full names of xml files from HypsXmlList
+      QStringList xmlFiles;
+      xmlFiles.append( QDir::home().filePath("CustomMeshers.xml")); // may be inexistent
       for (int i = 0; i < HypsXmlList.count(); i++) {
         QString HypsXml = HypsXmlList[ i ];
 
       for (int i = 0; i < HypsXmlList.count(); i++) {
         QString HypsXml = HypsXmlList[ i ];
 
@@ -158,9 +193,18 @@ namespace SMESH
         QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
         if ( xmlFile.isEmpty() ) // try PLUGIN resources
           xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
         QString xmlFile = resMgr->path("resources", "SMESH", HypsXml + ".xml");
         if ( xmlFile.isEmpty() ) // try PLUGIN resources
           xmlFile = resMgr->path("resources", HypsXml, HypsXml + ".xml");
-        
+        if ( !xmlFile.isEmpty() )
+          xmlFiles.append( xmlFile );
+      }
+
+      // loop on xmlFiles
+      QString aNoAccessFiles;
+      for (int i = 0; i < xmlFiles.count(); i++)
+      {
+        QString xmlFile = xmlFiles[ i ];
         QFile file (xmlFile);
         QFile file (xmlFile);
-        if (file.exists() && file.open(QIODevice::ReadOnly)) {
+        if (file.exists() && file.open(QIODevice::ReadOnly))
+        {
           file.close();
 
           SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
           file.close();
 
           SMESHGUI_XmlHandler* aXmlHandler = new SMESHGUI_XmlHandler();
@@ -178,7 +222,9 @@ namespace SMESH
             QList<HypothesesSet*>::iterator it, pos = myListOfHypothesesSets.begin();
             for ( it = aXmlHandler->myListOfHypothesesSets.begin(); 
                   it != aXmlHandler->myListOfHypothesesSets.end();
             QList<HypothesesSet*>::iterator it, pos = myListOfHypothesesSets.begin();
             for ( it = aXmlHandler->myListOfHypothesesSets.begin(); 
                   it != aXmlHandler->myListOfHypothesesSets.end();
-                  ++it ) {
+                  ++it )
+            {
+              (*it)->setIsCustom( i == 0 );
               myListOfHypothesesSets.insert( pos, *it );
             }
           }
               myListOfHypothesesSets.insert( pos, *it );
             }
           }
@@ -187,15 +233,15 @@ namespace SMESH
                                       QObject::tr("INF_PARSE_ERROR"),
                                       QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
           }
                                       QObject::tr("INF_PARSE_ERROR"),
                                       QObject::tr(aXmlHandler->errorProtocol().toLatin1().data()));
           }
-    delete aXmlHandler;
+          delete aXmlHandler;
         }
         }
-        else {
+        else if ( i > 0 ) { // 1st is ~/CustomMeshers.xml
           if (aNoAccessFiles.isEmpty())
             aNoAccessFiles = xmlFile;
           else
             aNoAccessFiles += ", " + xmlFile;
         }
           if (aNoAccessFiles.isEmpty())
             aNoAccessFiles = xmlFile;
           else
             aNoAccessFiles += ", " + xmlFile;
         }
-      } // end loop
+      } // end loop on xmlFiles
 
 
       if (!aNoAccessFiles.isEmpty()) {
 
 
       if (!aNoAccessFiles.isEmpty()) {
@@ -240,7 +286,7 @@ namespace SMESH
   }
 
 
   }
 
 
-  QStringList GetHypothesesSets()
+  QStringList GetHypothesesSets(int maxDim)
   {
     QStringList aSetNameList;
 
   {
     QStringList aSetNameList;
 
@@ -252,22 +298,32 @@ namespace SMESH
           hypoSet != myListOfHypothesesSets.end();
           ++hypoSet ) {
       HypothesesSet* aSet = *hypoSet;
           hypoSet != myListOfHypothesesSets.end();
           ++hypoSet ) {
       HypothesesSet* aSet = *hypoSet;
-      if ( aSet && aSet->count( true ) ) {
-        aSetNameList.append( aSet->name() );
+      if ( aSet &&
+           ( aSet->count( true ) || aSet->count( false )) &&
+           aSet->maxDim() <= maxDim)
+      {
+        aSetNameList.append( mangledHypoSetName( aSet ));
       }
     }
       }
     }
+    aSetNameList.sort();
+
+    //  reverse order of aSetNameList
+    QStringList reversedNames;
+    for ( int i = 0; i < aSetNameList.count(); ++i )
+      reversedNames.prepend( aSetNameList[i] );
     
     
-    return aSetNameList;
+    return reversedNames;
   }
 
   HypothesesSet* GetHypothesesSet(const QString& theSetName)
   {
   }
 
   HypothesesSet* GetHypothesesSet(const QString& theSetName)
   {
+    QString name = demangledHypoSetName( theSetName );
     QList<HypothesesSet*>::iterator hypoSet;
     for ( hypoSet  = myListOfHypothesesSets.begin(); 
           hypoSet != myListOfHypothesesSets.end();
           ++hypoSet ) {
       HypothesesSet* aSet = *hypoSet;
     QList<HypothesesSet*>::iterator hypoSet;
     for ( hypoSet  = myListOfHypothesesSets.begin(); 
           hypoSet != myListOfHypothesesSets.end();
           ++hypoSet ) {
       HypothesesSet* aSet = *hypoSet;
-      if ( aSet && aSet->name() == theSetName )
+      if ( aSet && aSet->name() == name )
         return aSet;
     }
     return 0;
         return aSet;
     }
     return 0;
index 54e36e04b7d6e5dbb80fe17f9ae4a05fadc16f41..8a0544a33040f4e06f1b6a5a72d66da44790ddbe 100644 (file)
@@ -68,7 +68,7 @@ namespace SMESH
                                       const bool = false,
                                       const bool = true);
   SMESHGUI_EXPORT
                                       const bool = false,
                                       const bool = true);
   SMESHGUI_EXPORT
-  QStringList GetHypothesesSets();
+  QStringList GetHypothesesSets( int maxDim );
 
   SMESHGUI_EXPORT
   HypothesesSet* GetHypothesesSet( const QString& );
 
   SMESHGUI_EXPORT
   HypothesesSet* GetHypothesesSet( const QString& );