Salome HOME
Improvement:
authorenk <enk@opencascade.com>
Fri, 23 Mar 2007 11:31:50 +0000 (11:31 +0000)
committerenk <enk@opencascade.com>
Fri, 23 Mar 2007 11:31:50 +0000 (11:31 +0000)
Adding support of export to STL format (ASCII and Binary modes)

resources/SMESH_en.xml
resources/SMESH_fr.xml
src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESH_msg_en.po

index 7d314c75df252290c08ab99d2a2e2f41b0fc227b..6702d3e213e59e0f8008ae3cb298a8f408ff32f0 100644 (file)
@@ -24,6 +24,7 @@
         <popup-item item-id="121" pos-id="" label-id="DAT File" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
         <popup-item item-id="122" pos-id="" label-id="MED File" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
         <popup-item item-id="123" pos-id="" label-id="UNV File" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
+        <popup-item item-id="140" pos-id="" label-id="STL File" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
       </submenu>
       <endsubmenu />
       <separator pos-id="10"/>
    <separator pos-id=""/>
    <popup-item item-id="122" pos-id="" label-id="Export to MED" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>   
    <popup-item item-id="123" pos-id="" label-id="Export to UNV" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>   
+   <popup-item item-id="140" pos-id="" label-id="Export to STL" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>   
 </popupmenu>
 
 <popupmenu label-id="Popup for ObjectBrowser" context-id="" parent-id="ObjectBrowser" object-id="SubMesh">
index d5dbf4640e29e36ab9d46671692c1328788c2991..e25d5ef35edcba377db720bbc3a7853d7842b02d 100644 (file)
@@ -24,6 +24,7 @@
         <popup-item item-id="121" pos-id="" label-id="DAT File" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
         <popup-item item-id="122" pos-id="" label-id="MED File" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
         <popup-item item-id="123" pos-id="" label-id="UNV File" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
+        <popup-item item-id="140" pos-id="" label-id="STL File" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
       </submenu>
       <endsubmenu />
       <separator pos-id="10"/>
index 9427c8d61c5667dcc0755b9be798a046447fe5b9..d56b7424a46e19454bd2d236ec9a4ff46623419b 100644 (file)
@@ -260,6 +260,7 @@ using namespace std;
       if ( !aMesh->_is_nil() ) {
        QString aFilter, aTitle = QObject::tr("Export mesh");
        QMap<QString, SMESH::MED_VERSION> aFilterMap;
+       QMap<QString, int> aFilterMapSTL;
        switch ( theCommandID ) {
        case 125:
        case 122:
@@ -299,6 +300,36 @@ using namespace std;
             aFilter = QObject::tr("IDEAS files (*.unv)");
           }
          break;
+       case 140:
+       case 141:
+          {
+           // export STL
+           /*
+             there must be check on others mesh elements not equal triangles
+           */
+           if (aMesh->NbTriangles() < 1) {
+              int aRet = SUIT_MessageBox::warn1
+                (SMESHGUI::desktop(),
+                 QObject::tr("SMESH_WRN_WARNING"),
+                 QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()),
+                 QObject::tr("SMESH_BUT_OK"));
+             return;
+            }
+           if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
+              int aRet = SUIT_MessageBox::warn2
+                (SMESHGUI::desktop(),
+                 QObject::tr("SMESH_WRN_WARNING"),
+                 QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()),
+                 QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
+                 0, 1, 0);
+              if (aRet)
+                return;
+            }
+
+            aFilterMapSTL.insert( QObject::tr("STL ASCII  (*.stl)"), 1 ); // 1 - ASCII mode
+            aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode
+          }
+         break;
        default:
          return;
        }
@@ -306,13 +337,35 @@ using namespace std;
        QString aFilename;
        SMESH::MED_VERSION aFormat;
        // Init the parameter with the default value
+       bool aIsASCII_STL = true;
        bool toCreateGroups = false;
        SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
        if ( resMgr )
          toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
 
-       if ( theCommandID != 122 && theCommandID != 125 )
+       if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141)
+
          aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), "", aFilter, aTitle, false);
+
+       else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
+         QStringList filters;
+          QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
+          for ( ; it != aFilterMapSTL.end(); ++it )
+            filters.push_back( it.key() );
+
+          SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
+          fd->setCaption( aTitle );
+          fd->setFilters( filters );
+          fd->setSelectedFilter( QObject::tr("STL ASCII  (*.stl)") );
+          bool is_ok = false;
+          while (!is_ok) {
+            fd->exec();
+            aFilename = fd->selectedFile();
+            aIsASCII_STL = (aFilterMapSTL[fd->selectedFilter()]) == 1 ? true: false;
+            is_ok = true;
+         }
+          delete fd;
+       }
        else {
           QStringList filters;
           QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
@@ -381,6 +434,10 @@ using namespace std;
            case 123:
              aMesh->ExportUNV( aFilename.latin1() );
              break;
+           case 140:
+           case 141:
+             aMesh->ExportSTL( aFilename.latin1(), aIsASCII_STL );
+             break;
            default:
              break;
            }
@@ -1150,6 +1207,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case 124:
   case 125:
   case 126:
+  case 140:
+  case 141:
     {
       ::ExportMeshToFile(theCommandID);
       break;
@@ -2347,9 +2406,11 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction(  121, "DAT" );
   createSMESHAction(  122, "MED" );
   createSMESHAction(  123, "UNV" );
+  createSMESHAction(  140, "STL" );
   createSMESHAction(  124, "EXPORT_DAT" );
   createSMESHAction(  125, "EXPORT_MED" );
   createSMESHAction(  126, "EXPORT_UNV" );
+  createSMESHAction(  141, "EXPORT_STL" );
   createSMESHAction(   33, "DELETE",          "ICON_DELETE" );
   createSMESHAction( 5105, "SEL_FILTER_LIB" );
   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
@@ -2472,6 +2533,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( 121, exportId, -1 );
   createMenu( 122, exportId, -1 );
   createMenu( 123, exportId, -1 );
+  createMenu( 140, exportId, -1 ); // export to stl STL
 
   createMenu( separator(), fileId, 10 );
 
@@ -2693,6 +2755,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
   createPopupItem( 125, OB, mesh, only_one_non_empty );    // EXPORT_MED
   createPopupItem( 126, OB, mesh, only_one_non_empty );    // EXPORT_UNV
+  createPopupItem( 141, OB, mesh, only_one_non_empty );    // EXPORT_STL
   createPopupItem( 33, OB, subMesh + " " + group );        // DELETE
   popupMgr()->insert( separator(), -1, 0 );
 
index a3320a865c214b8b83fe15a61d2c19a09c1bcc31..41cf35f580ef776f61b117e37b76c430c80b0c22 100644 (file)
@@ -1349,6 +1349,13 @@ msgid "SMESH_EXPORT_UNV"
 msgstr "During export mesh with name - \"%1\" to UNV\n"
        "       pyramid's elements will be missed"
 
+msgid "SMESH_EXPORT_STL1"
+msgstr "Mesh  - \"%1\" does not contain triangles"
+
+msgid "SMESH_EXPORT_STL2"
+msgstr "Mesh  - \"%1\" contains another than triangles elements,"
+       "     they are ignored during writing to STL"
+
 msgid "SMESH_EXPORT_MED_DUPLICATED_GRP"
 msgstr "There are duplicated group names in mesh \"%1\".\n"
        "You can cancel exporting and rename them,\n"
@@ -2109,6 +2116,9 @@ msgstr "UNV file"
 msgid "MEN_MED"
 msgstr "MED file"
 
+msgid "MEN_STL"
+msgstr "STL file"
+
 msgid "MEN_EXPORT_DAT"
 msgstr "Export to DAT file"
 
@@ -2118,6 +2128,9 @@ msgstr "Export to UNV file"
 msgid "MEN_EXPORT_MED"
 msgstr "Export to MED file"
 
+msgid "MEN_EXPORT_STL"
+msgstr "Export to STL file"
+
 msgid "MEN_DELETE"
 msgstr "Delete"
 
@@ -2480,6 +2493,9 @@ msgstr "Export to UNV file"
 msgid "TOP_EXPORT_MED"
 msgstr "Export to MED file"
 
+msgid "TOP_EXPORT_STL"
+msgstr "Export to STL file"
+
 msgid "TOP_DELETE"
 msgstr "Delete"
 
@@ -2790,6 +2806,9 @@ msgstr "Export to UNV file"
 msgid "STB_EXPORT_MED"
 msgstr "Export to MED file"
 
+msgid "STB_EXPORT_STL"
+msgstr "Export to STL file"
+
 msgid "STB_DELETE"
 msgstr "Delete"