]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Implement panel for obstacles creation/modification.
authormzn <mzn@opencascade.com>
Wed, 20 Nov 2013 07:38:55 +0000 (07:38 +0000)
committermzn <mzn@opencascade.com>
Wed, 20 Nov 2013 07:38:55 +0000 (07:38 +0000)
src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx
src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.cxx
src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.h
src/HYDROGUI/HYDROGUI_ObstacleDlg.cxx
src/HYDROGUI/HYDROGUI_ObstacleDlg.h
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/HYDROGUI_Tool.cxx
src/HYDROGUI/HYDROGUI_Tool.h

index fd32dfad5d30c928c5489c4c7321448d8e2163ab..6f771664c77dc88de9c4851591cf51cc62c274ba 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>
 #include <HYDROData_Iterator.h>
@@ -74,6 +75,17 @@ void HYDROGUI_ImportGeomObjectOp::startOperation()
       // Reset the panel state
       aPanel->reset();
 
+      // Set default name
+      SalomeApp_Study* aStudy = 
+        dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
+      if ( aStudy ) {
+        QString anEntry = myGeomObjects.first();
+        _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID( qPrintable(anEntry) ) );
+        if ( aSObject ) {
+          aPanel->setDefaultName( QString::fromStdString(aSObject->GetName()) );
+        }
+      }
+
       // Pass the existing obstacle names to the panel
       QStringList anObstacles = 
         HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_OBSTACLE );
@@ -113,14 +125,29 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags,
   // Get panel
   HYDROGUI_ObstacleDlg* aPanel = ::qobject_cast<HYDROGUI_ObstacleDlg*>( inputPanel() );
   if ( aPanel ) {
+    // Check obstacle name
+    anObstacleName = aPanel->getObstacleName().simplified();
+    if ( anObstacleName.isEmpty() ) {
+      theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
+      return false;
+    }
+
+    // Get obstacle to edit
     QString anEditedName = aPanel->getEditedObstacleName().simplified();
 
     if ( !anEditedName.isEmpty() ) {
       anObstacleToEdit = Handle(HYDROData_Obstacle)::DownCast(
         HYDROGUI_Tool::FindObjectByName( module(), anEditedName, KIND_OBSTACLE ) );
     }
+  }
 
-    anObstacleName = anEditedName; //TODO: aPanel->getObstacleName();
+  if( anObstacleToEdit.IsNull() || anObstacleToEdit->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;
@@ -133,7 +160,6 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags,
       TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( aSObject->GetIOR().c_str() );
       if ( !aShape.IsNull() ) {
         // Create/edit an obstacle object
-        // TODO refactoring: get rid of obstacle from TopoDS_Shape creation code copy/paste
         Handle(HYDROData_Obstacle) anObstacle; 
 
         if ( anObstacleToEdit.IsNull() ) {
@@ -146,7 +172,8 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags,
         // Set name
         if ( anObstacleName.isEmpty() ) {
           QString aName = QString::fromStdString( aSObject->GetName() );
-          anObstacleName = HYDROGUI_Tool::GenerateObjectName( module(), aName );
+          anObstacleName = HYDROGUI_Tool::GenerateObjectName( 
+            module(), aName, QStringList(), true );
         }
         if ( anObstacle->GetName() != anObstacleName ) {
           anObstacle->SetName( anObstacleName );
@@ -157,7 +184,7 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags,
 
         // Set operation status
         anIsOk = true;
-        theUpdateFlags = UF_Model;
+        theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
       }
     }
   }
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 );
     }
index 05b217fdefb8677ffd3d54f7fd9b814a412dc59f..e264729300fe8044288b9db828f4bfef0d5fedab 100644 (file)
@@ -20,8 +20,8 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef HYDROGUI_IMPORTOBSTACLEFROMFILE_H
-#define HYDROGUI_IMPORTOBSTACLEFROMFILE_H
+#ifndef HYDROGUI_IMPORTOBSTACLEFROMFILEOP_H
+#define HYDROGUI_IMPORTOBSTACLEFROMFILEOP_H
 
 #include "HYDROGUI_Operation.h"
 
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
index af303096de6684925b8985217aa26137895fed91..60d2acbb139e49405f0dfa76de6611de38119e3c 100644 (file)
@@ -50,13 +50,17 @@ public:
 
   QString                    getFileName() const;
 
+  QString                    getDefaultName();
+  void                       setDefaultName( const QString& theName );
+
 protected slots:
   void                       onModeActivated( int );
   void                       onObstacleSelectionChanged();
   void                       onBrowse();
 
 private:
-  void                       UpdateControls();
+  void                       updateControls();
+  void                       updateObjectName();
 
 private:
   QLineEdit*                 myFileName;
@@ -71,6 +75,7 @@ private:
   QComboBox*                 myObstacles;
 
   bool                       myFileSelectionEnabled;
+  QString                    myDefaultName;
 };
 
 #endif
index 0378857cad988d630d31302ab8ca41267e7eeaeb..d32802e9d418aed99851cd5e8f623b17f3cab2f1 100644 (file)
@@ -44,6 +44,7 @@
 #include "HYDROGUI_ImportGeomObjectOp.h"
 #include "HYDROGUI_ImportObstacleFromFileOp.h"
 #include "HYDROGUI_ExportCalculationOp.h"
+#include "HYDROGUI_SetColorOp.h"
 
 #include "HYDROData_Document.h"
 #include "HYDROData_Obstacle.h"
@@ -128,6 +129,8 @@ void HYDROGUI_Module::createActions()
 
   createAction( DeleteId, "DELETE", "", Qt::Key_Delete );
 
+  createAction( SetColorId, "COLOR" );
+
   createAction( ShowId, "SHOW" );
   createAction( ShowOnlyId, "SHOW_ONLY" );
   createAction( ShowAllId, "SHOW_ALL" );
@@ -351,6 +354,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
   case DeleteId:
     anOp = new HYDROGUI_DeleteOp( aModule );
     break;
+  case SetColorId:
+    anOp = new HYDROGUI_SetColorOp( aModule );
+    break;
   case ShowId:
   case ShowOnlyId:
   case ShowAllId:
@@ -392,7 +398,7 @@ void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName,
   
   // Start import GEOM object operation
   myGeomObjectsToImport = theEntryList;
-  startOperation ( ImportCreatedPrimitiveId );
+  startOperation( ImportCreatedPrimitiveId );
   myGeomObjectsToImport.clear();
 }
 
index cdfe34d34eec820436e363606bc5d491d99a35b5..c27188a18aea85c3b1820cdb7947e570c2c83682 100644 (file)
@@ -78,6 +78,8 @@ enum OperationId
   ShowAllId,
   HideId,
   HideAllId,
+
+  SetColorId
 };
 
 #endif
index 19d4e9c93b53c47aa71d1d76f5b54ae486fc1902..5e026dd4b61866821e7c5633b616bdf4789092c4 100644 (file)
@@ -356,8 +356,6 @@ QStringList HYDROGUI_Tool::GetSelectedGeomObjects( HYDROGUI_Module* theModule )
   }
 
   // Get selection
-  HYDROGUI_DataModel* aModel = theModule->getDataModel();
-
   SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
   SUIT_DataOwnerPtrList anOwners;
   aSelectionMgr->selected( anOwners );
@@ -404,10 +402,11 @@ HYDROData_SequenceOfObjects HYDROGUI_Tool::FindObjectsByNames( HYDROGUI_Module*
 
 QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module*   theModule,
                                            const QString&     thePrefix,
-                                           const QStringList& theUsedNames )
+                                           const QStringList& theUsedNames,
+                                           const bool         theIsTryToUsePurePrefix)
 {
   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
-  return HYDROData_Tool::GenerateObjectName( aDocument, thePrefix, theUsedNames );
+  return HYDROData_Tool::GenerateObjectName( aDocument, thePrefix, theUsedNames, theIsTryToUsePurePrefix );
 }
 
 size_t HYDROGUI_Tool::GetActiveViewId( HYDROGUI_Module* theModule,
index 5b5908657847dc7dfd2dc109afc665d87140564d..7a77b3af51efe00c0ca0c58a53ade409b7e6b32b 100644 (file)
@@ -196,11 +196,13 @@ public:
    * \param theModule module
    * \param thePrefix name prefix
    * \param theUsedNames list of already used names
+   * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
    * \return generated name
    */
   static QString                  GenerateObjectName( HYDROGUI_Module*   theModule,
                                                       const QString&     thePrefix,
-                                                      const QStringList& theUsedNames = QStringList() );
+                                                      const QStringList& theUsedNames = QStringList(),
+                                                      const bool         theIsTryToUsePurePrefix = false );
 
   /**
    * \brief Get id of the active view.