Salome HOME
Feature #86: The hierarchy in the Object Browser (T 19).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ObstacleDlg.cxx
index beb9f0d1e02efa39a90db3d3c38778fe41e84515..2697c8d365efd66d162f945341674aae3a7a1252 100644 (file)
@@ -42,7 +42,8 @@ static QString lastUsedFilter;
 HYDROGUI_ObstacleDlg::HYDROGUI_ObstacleDlg( HYDROGUI_Module* theModule, const QString& theTitle,
                                             const bool theIsToEnableFileSelection )
 : HYDROGUI_InputPanel( theModule, theTitle ),
-  myFileSelectionEnabled ( theIsToEnableFileSelection )
+  myFileSelectionEnabled ( theIsToEnableFileSelection ),
+  myDefaultName( tr("DEFAULT_OBSTACLE_NAME") )
 {
   // Get resource manager
   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
@@ -83,8 +84,6 @@ HYDROGUI_ObstacleDlg::HYDROGUI_ObstacleDlg( HYDROGUI_Module* theModule, const QS
   anObstacleNameLayout->addWidget( anObstacleNameLabel );
   anObstacleNameLayout->addWidget( myObstacleName );
 
-  myObstacleNameGroup->hide(); //TODO to be enabled?
-
   // Mode selector (create/edit)
   myModeGroup = new QGroupBox( tr( "MODE" ), this );
 
@@ -138,12 +137,13 @@ void HYDROGUI_ObstacleDlg::setObstacleNames( const QStringList& theObstacles )
   myObstacles->clear();
   myObstacles->addItems( theObstacles );
 
-  UpdateControls();
+  updateControls();
 }
 
 void HYDROGUI_ObstacleDlg::onModeActivated( int theMode )
 {
-  UpdateControls();
+  updateControls();
+  updateObjectName();
 }
 
 QString HYDROGUI_ObstacleDlg::getObstacleName() const
@@ -191,13 +191,10 @@ void HYDROGUI_ObstacleDlg::onBrowse()
 
     if ( !aFileName.isEmpty() ) {
       myFileName->setText( aFileName );
-
-      QFileInfo aFileInfo( aFileName );
-      QString aName = HYDROGUI_Tool::GenerateObjectName( module(), aFileInfo.baseName() );
-      myObstacleName->setText( aName );
+      updateObjectName();
     }
 
-    UpdateControls();
+    updateControls();
   }
 }
 
@@ -212,21 +209,56 @@ void HYDROGUI_ObstacleDlg::reset()
   myModeButtons->button( CreateNewId )->setChecked( true );
   onModeActivated( CreateNewId );
 
-  UpdateControls();
+  updateControls();
 }
 
 void HYDROGUI_ObstacleDlg::onObstacleSelectionChanged()
 {
-  if ( myObstacleName->text().isEmpty() ) {
-    myObstacleName->setText( myObstacles->currentText() );
-  }
+  updateObjectName();
 }
 
-void HYDROGUI_ObstacleDlg::UpdateControls()
+void HYDROGUI_ObstacleDlg::updateControls()
 {
   myObstacleNameGroup->setEnabled( !myFileSelectionEnabled || 
                                    !myFileName->text().isEmpty() );
   myModeGroup->setEnabled( myObstacleNameGroup->isEnabled() && 
                            myObstacles->count() > 0 );
   myObstaclesGroup->setEnabled( myModeButtons->checkedId() == ModifyExistentId );
+}
+
+void HYDROGUI_ObstacleDlg::updateObjectName()
+{
+  QString aName;
+
+  // Creation mode
+  int aMode = myModeButtons->checkedId();
+  if ( aMode == CreateNewId ) {
+    if ( myFileSelectionEnabled ) {
+      QString aFileName = myFileName->text();
+      if ( !aFileName.isEmpty() ) {
+        QFileInfo aFileInfo( aFileName );
+        aName = HYDROGUI_Tool::GenerateObjectName( 
+          module(), aFileInfo.baseName(), QStringList(), true );
+      }
+    } else {
+      aName = HYDROGUI_Tool::GenerateObjectName( 
+        module(), getDefaultName(), QStringList(), true );
+    }
+  } else if ( aMode == ModifyExistentId ) {
+      aName = getEditedObstacleName();
+  }
+
+  myObstacleName->setText( aName );
+}
+
+void HYDROGUI_ObstacleDlg::setDefaultName( const QString& theName )
+{
+  myDefaultName = theName;
+
+  updateObjectName();
+}
+
+QString HYDROGUI_ObstacleDlg::getDefaultName()
+{
+  return myDefaultName;
 }
\ No newline at end of file