#include "HYDROGUI_DataModel.h"
#include "HYDROGUI_Module.h"
#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_UpdateFlags.h"
#include <HYDROData_Obstacle.h>
#include <HYDROData_Iterator.h>
// 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 );
// 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;
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() ) {
// 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 );
// Set operation status
anIsOk = true;
- theUpdateFlags = UF_Model;
+ theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
}
}
}
#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 );
}
// 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"
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();
anObstacleNameLayout->addWidget( anObstacleNameLabel );
anObstacleNameLayout->addWidget( myObstacleName );
- myObstacleNameGroup->hide(); //TODO to be enabled?
-
// Mode selector (create/edit)
myModeGroup = new QGroupBox( tr( "MODE" ), this );
myObstacles->clear();
myObstacles->addItems( theObstacles );
- UpdateControls();
+ updateControls();
}
void HYDROGUI_ObstacleDlg::onModeActivated( int theMode )
{
- UpdateControls();
+ updateControls();
+ updateObjectName();
}
QString HYDROGUI_ObstacleDlg::getObstacleName() const
if ( !aFileName.isEmpty() ) {
myFileName->setText( aFileName );
-
- QFileInfo aFileInfo( aFileName );
- QString aName = HYDROGUI_Tool::GenerateObjectName( module(), aFileInfo.baseName() );
- myObstacleName->setText( aName );
+ updateObjectName();
}
- UpdateControls();
+ updateControls();
}
}
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
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;
QComboBox* myObstacles;
bool myFileSelectionEnabled;
+ QString myDefaultName;
};
#endif
#include "HYDROGUI_ImportGeomObjectOp.h"
#include "HYDROGUI_ImportObstacleFromFileOp.h"
#include "HYDROGUI_ExportCalculationOp.h"
+#include "HYDROGUI_SetColorOp.h"
#include "HYDROData_Document.h"
#include "HYDROData_Obstacle.h"
createAction( DeleteId, "DELETE", "", Qt::Key_Delete );
+ createAction( SetColorId, "COLOR" );
+
createAction( ShowId, "SHOW" );
createAction( ShowOnlyId, "SHOW_ONLY" );
createAction( ShowAllId, "SHOW_ALL" );
case DeleteId:
anOp = new HYDROGUI_DeleteOp( aModule );
break;
+ case SetColorId:
+ anOp = new HYDROGUI_SetColorOp( aModule );
+ break;
case ShowId:
case ShowOnlyId:
case ShowAllId:
// Start import GEOM object operation
myGeomObjectsToImport = theEntryList;
- startOperation ( ImportCreatedPrimitiveId );
+ startOperation( ImportCreatedPrimitiveId );
myGeomObjectsToImport.clear();
}
ShowAllId,
HideId,
HideAllId,
+
+ SetColorId
};
#endif
}
// Get selection
- HYDROGUI_DataModel* aModel = theModule->getDataModel();
-
SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
SUIT_DataOwnerPtrList anOwners;
aSelectionMgr->selected( anOwners );
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,
* \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.