Salome HOME
Feature #86: The hierarchy in the Object Browser (T 19).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportObstacleFromFileOp.cxx
index 85320817fb01f4db895905c97e60d42ee37730a1..0fc2e3e58fd7a0720cd868538cea38ee472a1b71 100644 (file)
@@ -27,6 +27,7 @@
 #include "HYDROGUI_DataModel.h"
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Tool.h"
+#include "HYDROGUI_UpdateFlags.h"
 
 #include <HYDROData_Obstacle.h>
 
@@ -72,7 +73,7 @@ void HYDROGUI_ImportObstacleFromFileOp::startOperation()
 
     aPanel->setObstacleNames( anObstacles );
   } else {
-    myFileDlg = new SUIT_FileDlg( module()->application()->desktop(), true );
+    myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
     myFileDlg->setWindowTitle( getName() );
     myFileDlg->setFilter( tr("OBSTACLE_FILTER") );
     if ( !lastUsedFilter.isEmpty() ) {
@@ -116,8 +117,6 @@ bool HYDROGUI_ImportObstacleFromFileOp::processApply( int& theUpdateFlags,
       anObstacle = Handle(HYDROData_Obstacle)::DownCast(
         HYDROGUI_Tool::FindObjectByName( module(), anEditedName, KIND_OBSTACLE ) );
     }
-
-    anObstacleName = anEditedName; //TODO: aPanel->getObstacleName();
   } else if ( myFileDlg ) {
     // Get file name and file filter defined by the user
     aFileName = myFileDlg->selectedFile();
@@ -125,12 +124,31 @@ bool HYDROGUI_ImportObstacleFromFileOp::processApply( int& theUpdateFlags,
   }
 
   // Check the file name
+  if ( aFileName.isEmpty() ) {
+    return false;
+  }
   QFileInfo aFileInfo( aFileName );
   if ( !aFileInfo.exists() || !aFileInfo.isReadable() ) {
     theErrorMsg = tr( "FILE_NOT_EXISTS_OR_CANT_BE_READ" ).arg( aFileName );
     return false;
   }
 
+  // Check obstacle name
+  anObstacleName = aPanel->getObstacleName().simplified();
+  if ( anObstacleName.isEmpty() ) {
+    theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
+    return false;
+  }
+
+  if( anObstacle.IsNull() || anObstacle->GetName() != anObstacleName ) {
+    // check that there are no other objects with the same name in the document
+    Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObstacleName );
+    if( !anObject.IsNull() ) {
+      theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObstacleName );
+      return false;
+    }
+  }
+
   bool anIsOk = false;
  
   // If the obstacle for edit is null - create new obstacle object
@@ -142,7 +160,8 @@ bool HYDROGUI_ImportObstacleFromFileOp::processApply( int& theUpdateFlags,
     if ( anObstacle->ImportFromFile( aFileName ) ) {
       // Set name
       if ( anObstacleName.isEmpty() ) {
-        anObstacleName = HYDROGUI_Tool::GenerateObjectName( module(), aFileInfo.baseName() );
+        anObstacleName = HYDROGUI_Tool::GenerateObjectName( 
+          module(), aFileInfo.baseName(), QStringList(), true );
       }
       if ( anObstacle->GetName() != anObstacleName ) {
         anObstacle->SetName( anObstacleName );
@@ -150,7 +169,7 @@ bool HYDROGUI_ImportObstacleFromFileOp::processApply( int& theUpdateFlags,
 
       // Set operation status
       anIsOk = true;
-      theUpdateFlags = UF_Model;
+      theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;;
     } else {
       theErrorMsg = tr( "BAD_IMPORTED_OBSTACLE_FILE" ).arg( aFileName );
     }