]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
publish imported fields to study
authorfps <fps@opencascade.com>
Thu, 14 Nov 2013 16:58:32 +0000 (16:58 +0000)
committerfps <fps@opencascade.com>
Thu, 14 Nov 2013 16:58:32 +0000 (16:58 +0000)
src/ImportExportGUI/CMakeLists.txt
src/ImportExportGUI/ImportExportGUI_ImportXAODlg.cxx
src/ImportExportGUI/ImportExportGUI_ImportXAODlg.h

index 2ffcf72f02705ddd44535d1ae8cd3a1b8941a3c3..fd1451b78624bc38b27547987880eeea34293349 100644 (file)
@@ -38,6 +38,7 @@ INCLUDE_DIRECTORIES(
   ${PROJECT_SOURCE_DIR}/src/GEOMImpl
   ${PROJECT_SOURCE_DIR}/src/GEOMGUI
   ${PROJECT_SOURCE_DIR}/src/GEOMBase
+  ${PROJECT_SOURCE_DIR}/src/GEOM
   ${PROJECT_SOURCE_DIR}/src/DlgRef
   ${PROJECT_BINARY_DIR}/src/DlgRef
   )
index e3b17f678a67aad876a17e1a46b02321d471465a..186f4f357e613f02403c06911c0085cfa4b6f138 100644 (file)
 #include <DlgRef.h>
 #include <GeometryGUI.h>
 #include <GEOMBase.h>
+#include <GEOM_Field.hxx>
 
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
+#include <SUIT_OverrideCursor.h>
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
 #include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Tools.h>
 
 #include <QLabel>
 #include <QLineEdit>
@@ -43,6 +46,8 @@
 #include <GEOMImpl_Types.hxx>
 #include "ImportExportGUI_ImportXAODlg.h"
 
+#include <SALOMEDS_wrap.hxx>
+
 //=================================================================================
 // Constructor
 //=================================================================================
@@ -139,7 +144,7 @@ void ImportExportGUI_ImportXAODlg::ClickOnOk()
 // function : ClickOnApply()
 // purpose  :
 //=================================================================================
-bool ImportExportGUI_ImportXAODlg::ClickOnApply()
+/*bool ImportExportGUI_ImportXAODlg::ClickOnApply()
 {
     if (!onAccept())
         return false;
@@ -147,6 +152,45 @@ bool ImportExportGUI_ImportXAODlg::ClickOnApply()
     initName();
 
     return true;
+}*/
+
+bool ImportExportGUI_ImportXAODlg::ClickOnApply()
+{
+  if(!isApplyAndClose()) {
+    setIsDisableBrowsing( true );
+    setIsDisplayResult( false );
+  }
+
+  QString msg;
+  if ( !isValid( msg ) ) {
+    showError( msg );
+    return false;
+  }
+  SUIT_OverrideCursor wc;
+  SUIT_Session::session()->activeApplication()->putInfo( "" );
+
+  try {
+    if ( openCommand() )
+      if (!execute (/*isApplyAndClose()*/))
+      {
+        abortCommand();
+        showError();
+        return false;
+      }
+  }
+  catch( const SALOME::SALOME_Exception& e ) {
+    SalomeApp_Tools::QtCatchCorbaException( e );
+    abortCommand();
+    return false;
+  }
+  commitCommand();
+
+  if(!isApplyAndClose()) {
+    setIsDisableBrowsing( false );
+    setIsDisplayResult( true );
+  }
+
+  return true;
 }
 
 //=================================================================================
@@ -208,7 +252,7 @@ bool ImportExportGUI_ImportXAODlg::isValid(QString& msg)
 // function : execute
 // purpose  :
 //=================================================================================
-bool ImportExportGUI_ImportXAODlg::execute(ObjectList& objects)
+bool ImportExportGUI_ImportXAODlg::execute()
 {
     bool res = false;
 
@@ -223,29 +267,70 @@ bool ImportExportGUI_ImportXAODlg::execute(ObjectList& objects)
     if (!shape->_is_nil())
     {
         m_mainShape = shape;
-        objects.push_back(shape._retn());
     }
     else
     {
         m_mainShape = NULL;
     }
 
-    for (int i = 0; i < subShapes->length(); i++)
-    {
-        objects.push_back(GEOM::GEOM_Object::_duplicate(subShapes[i]));
-    }
-    for (int i = 0; i < groups->length(); i++)
-    {
-        objects.push_back(GEOM::GEOM_Object::_duplicate(groups[i]));
-    }
-    for (int i = 0; i < fields->length(); i++)
+    if (m_mainShape != NULL)
     {
-        //objects.push_back(GEOM::GEOM_Field::_duplicate(fields[i]));
+        addInStudy(m_mainShape, m_mainShape->GetName());
+
+        for (int i = 0; i < subShapes->length(); i++)
+        {
+            addInStudy(subShapes[i].in(), subShapes[i]->GetName());
+        }
+        for (int i = 0; i < groups->length(); i++)
+        {
+            addInStudy(groups[i].in(), groups[i]->GetName());
+        }
+        for (int i = 0; i < fields->length(); i++)
+        {
+            addFieldInStudy(fields[i].in(), m_mainShape);
+        }
+
+        updateObjBrowser();
     }
 
     return res;
 }
 
+QString ImportExportGUI_ImportXAODlg::addFieldInStudy( GEOM::GEOM_Field_ptr theField, GEOM::GEOM_Object_ptr theFather)
+{
+  if ( !hasCommand() )
+    return QString();
+
+  _PTR(Study) aStudy = getStudy()->studyDS();
+  if ( !aStudy || theField->_is_nil() )
+    return QString();
+
+  SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
+
+  SALOMEDS::SObject_var aSO =
+    getGeomEngine()->AddInStudy(aStudyDS, theField, theField->GetName(), theFather);
+
+  QString anEntry;
+  if ( !aSO->_is_nil() ) {
+    CORBA::String_var entry = aSO->GetID();
+    anEntry = entry.in();
+  }
+
+  // add steps
+  GEOM::ListOfLong_var steps = theField->GetSteps();
+  for (int i = 0; i < steps->length(); ++i)
+  {
+    GEOM::GEOM_FieldStep_ptr step = theField->GetStep(steps[i]);
+    QString stepName = (tr("STEP") + " %1 %2").arg( step->GetID() ).arg( step->GetStamp() );
+    SALOMEDS::SObject_wrap aSOField =
+      getGeomEngine()->AddInStudy( aStudyDS, step, stepName.toLatin1().constData(), theField );
+  }
+
+  aSO->UnRegister();
+
+  return anEntry;
+}
+
 GEOM::GEOM_Object_ptr ImportExportGUI_ImportXAODlg::getFather(GEOM::GEOM_Object_ptr object)
 {
     GEOM::GEOM_Object_var fatherObj;
index baacc3311f000e37807f291f2f889f57c14e5481..15ec77b01ed2bced66a86583e719980bbf57327b 100644 (file)
@@ -42,9 +42,10 @@ protected:
     // redefined from GEOMBase_Helper
     virtual GEOM::GEOM_IOperations_ptr createOperation();
     virtual bool isValid(QString&);
-    virtual bool execute(ObjectList&);
+    virtual bool execute();
     virtual GEOM::GEOM_Object_ptr getFather(GEOM::GEOM_Object_ptr object);
     virtual QString getObjectName(GEOM::GEOM_Object_ptr object) const;
+    virtual QString addFieldInStudy( GEOM::GEOM_Field_ptr theField, GEOM::GEOM_Object_ptr theFather );
 
 private:
     void Init();