#include "HYDROGUI_DataModel.h"
#include "HYDROGUI_Module.h"
#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_UpdateFlags.h"
#include <HYDROData_Obstacle.h>
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() ) {
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();
}
// 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
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 );
// 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 );
}