From 0c76593b1d11353467fe978da4ad99549c59899e Mon Sep 17 00:00:00 2001 From: rkv Date: Fri, 1 Nov 2013 06:30:21 +0000 Subject: [PATCH] - Merge type combo box in Calculation case dialog is filled and connected to get/set merge type and merge bathymetry of a selected zone. - Calculation case dialog labels are updated. --- src/HYDROData/HYDROData_Zone.cxx | 11 +++- src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 75 ++++++++++++++++------- src/HYDROGUI/HYDROGUI_CalculationDlg.h | 8 +++ src/HYDROGUI/HYDROGUI_CalculationOp.cxx | 16 +++++ src/HYDROGUI/HYDROGUI_CalculationOp.h | 4 ++ src/HYDROGUI/HYDROGUI_DataObject.h | 5 -- src/HYDROGUI/HYDROGUI_Zone.cxx | 71 +++++++++++++++++++++ src/HYDROGUI/HYDROGUI_Zone.h | 20 +++++- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 12 ++++ 9 files changed, 190 insertions(+), 32 deletions(-) diff --git a/src/HYDROData/HYDROData_Zone.cxx b/src/HYDROData/HYDROData_Zone.cxx index 29fd5bbe..5d6b4b65 100644 --- a/src/HYDROData/HYDROData_Zone.cxx +++ b/src/HYDROData/HYDROData_Zone.cxx @@ -110,9 +110,14 @@ bool HYDROData_Zone::IsMergingNeed() const void HYDROData_Zone::SetMergeType( const MergeBathymetriesType& theType ) { Handle(TDataStd_Integer) anInt; - if ( !myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) ) - anInt = TDataStd_Integer::Set( myLab, 0 ); - anInt->Set( (int)theType ); + if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) ) + { + anInt->Set( (int)theType ); + } + else + { + anInt = TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType ); + } } HYDROData_Zone::MergeBathymetriesType HYDROData_Zone::GetMergeType() const diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index f254ad44..4cf7eb37 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include @@ -81,10 +81,8 @@ void HYDROGUI_CalculationDlg::reset() QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { QWizardPage* aPage = new QWizardPage( wizard() ); QFrame* aFrame = new QFrame( aPage ); - // Calculation name -// myObjectNameGroup = new QGroupBox( tr( "CALCULATION_NAME" ), aFrame ); -// myObjectName = new QLineEdit( myObjectNameGroup ); + // Calculation name myObjectName = new QLineEdit( aPage ); myValidator = new HYDROGUI_NameValidator(module(), myObjectName); myObjectName->setValidator( myValidator ); @@ -92,16 +90,6 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { connect( myValidator, SIGNAL( emptyName() ), this, SLOT( onEmptyName() ) ); connect( myValidator, SIGNAL( alreadyExists( QString ) ), this, SLOT( onAlreadyExists( QString ) ) ); - //QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup ); - //aNameLayout->setMargin( 5 ); - //aNameLayout->setSpacing( 5 ); - //aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) ); - //aNameLayout->addWidget( myObjectName ); - - // Calculation zones - //QFrame* anObjectsFrame = new QFrame( aFrame ); - - //myGeomObjects = new QListWidget( anObjectsFrame ); myGeomObjects = new QListWidget( aPage ); myGeomObjects->setSelectionMode( QListWidget::SingleSelection ); myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers ); @@ -159,9 +147,8 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { QFrame* aFrame = new QFrame( aPage ); QGridLayout* aLayout = new QGridLayout( aPage ); - //Handle(HYDROData_Entity) anEntity = module()->getDataModel()->getDocument()->CreateObject( KIND_CALCULATION ); - myBrowser = new HYDROGUI_DataBrowser( module(), 0/*module()->application()->activeStudy()->root()*/, aPage ); + myBrowser = new HYDROGUI_DataBrowser( module(), 0, aPage ); myBrowser->setAutoOpenLevel( 3 ); aLayout->setMargin( 5 ); aLayout->setSpacing( 5 ); @@ -170,8 +157,6 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { myBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame ); myBathymetryChoice = new QComboBox( aFrame ); - myBathymetryChoice->addItem( tr( "ZMIN" ) ); - myBathymetryChoice->addItem( tr( "ZMAX" ) ); myBathymetryChoice->setVisible( false ); myBatimetryLabel->setVisible( false ); @@ -182,18 +167,61 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { aPage->setLayout( aLayout ); connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); + connect( myBathymetryChoice, SIGNAL( activated( int ) ), SLOT( onMergeTypeSelected( int ) ) ); return aPage; } +void HYDROGUI_CalculationDlg::onMergeTypeSelected( int theIndex ) +{ + int aType = myBathymetryChoice->itemData( theIndex ).toInt(); + QString aText = myBathymetryChoice->itemText( theIndex ); + emit setMergeType( aType, aText ); +} + void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject ) { bool doShow = false; - HYDROGUI_DataObject* anObject = dynamic_cast( theObject ); - if ( anObject ) + HYDROGUI_Zone* aZone = dynamic_cast( theObject ); + if ( aZone ) { - doShow = anObject->isMergingNeed(); + doShow = aZone->isMergingNeed(); } + + if ( doShow ) + { + // Fill the merge type combo box + bool prevBlock = myBathymetryChoice->blockSignals( true ); + myCurrentZone = aZone; + myBathymetryChoice->clear(); + myBathymetryChoice->addItem( QObject::tr("MERGE_UNKNOWN"), HYDROData_Zone::Merge_UNKNOWN ); + myBathymetryChoice->addItem( QObject::tr("MERGE_ZMIN"), HYDROData_Zone::Merge_ZMIN ); + myBathymetryChoice->addItem( QObject::tr("MERGE_ZMAX"), HYDROData_Zone::Merge_ZMAX ); + QStringList aList = aZone->getBathymetries(); + for ( int i = 0; i < aList.length(); i++ ) + { + myBathymetryChoice->addItem( aList.at( i ), HYDROData_Zone::Merge_Object ); + } + // Select the current choice if any + int aCurIndex = 0; + switch ( aZone->getMergeType() ) + { + case HYDROData_Zone::Merge_ZMIN: + aCurIndex = 1; + break; + case HYDROData_Zone::Merge_ZMAX: + aCurIndex = 2; + break; + case HYDROData_Zone::Merge_Object: + aCurIndex = aList.indexOf( aZone->text( HYDROGUI_DataObject::BathymetryId ) ); + break; + default: + aCurIndex = 0; // Select unknown by default + } + myBathymetryChoice->setCurrentIndex( aCurIndex ); + myBathymetryChoice->blockSignals( prevBlock ); + } + myBathymetryChoice->setVisible( doShow ); myBatimetryLabel->setVisible( doShow ); } @@ -249,3 +277,8 @@ void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_Calculatio myBrowser->updateTree(); myBrowser->openLevels(); } + +HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const +{ + return myCurrentZone; +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index 7ddb5391..3e137479 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -36,6 +36,7 @@ class QStringList; class HYDROGUI_DataBrowser; class HYDROGUI_NameValidator; class SUIT_DataObject; +class HYDROGUI_Zone; class HYDROGUI_CalculationDlg : public HYDROGUI_Wizard { @@ -55,6 +56,7 @@ public: void setGeomObjects( const QStringList& theObjects ); void setSelectedGeomObjects( const QStringList& theObjects ); QStringList getSelectedGeomObjects() const; + HYDROGUI_Zone* getCurrentZone() const; public slots: void onEmptyName(); @@ -63,11 +65,16 @@ public slots: * Process items selection: hide/show bathymetry merge type selector. */ void onSelected( SUIT_DataObject* theObject ); + /** + * Process merge type selection: set the selected bathymetry merge type for the currently selected zone. + */ + void onMergeTypeSelected( int theIndex ); signals: void addObjects(); void removeObjects(); void splitZones(); + void setMergeType( int theMergeType, QString theBathymetryName ); private: @@ -84,6 +91,7 @@ private: Handle(HYDROData_CalculationCase) myEditedObject; QComboBox* myBathymetryChoice; QLabel* myBatimetryLabel; + HYDROGUI_Zone* myCurrentZone; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index ea4f7125..30b2c638 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -27,6 +27,7 @@ #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" #include "HYDROGUI_UpdateFlags.h" +#include "HYDROGUI_Zone.h" #include #include @@ -150,10 +151,25 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) ); connect( aPanel, SIGNAL( splitZones() ), SLOT( onSplitZones() ) ); connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); + connect( aPanel, SIGNAL( setMergeType( int, QString ) ), SLOT( onSetMergeType( int, QString ) ) ); return aPanel; } +void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString theBathymetryName ) +{ + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( aPanel ) + { + HYDROGUI_Zone* aZone = aPanel->getCurrentZone(); + if ( aZone ) + { + aZone->setMergeType( theMergeType, theBathymetryName ); + } + } +} + void HYDROGUI_CalculationOp::onAddObjects() { // Add geometry objects selected in the module browser to the calculation case diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index 9735e436..729db62e 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -89,6 +89,10 @@ protected slots: * Remove selected objects from the calculation case. */ void onRemoveObjects(); + /** + * Set the given bathymetry merge type to the current zone. + */ + void onSetMergeType( int theMergeType, QString theBathymetryName ); void onSplitZones(); void onLastViewClosed( SUIT_ViewManager* ); diff --git a/src/HYDROGUI/HYDROGUI_DataObject.h b/src/HYDROGUI/HYDROGUI_DataObject.h index 80451830..c48daaa0 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.h +++ b/src/HYDROGUI/HYDROGUI_DataObject.h @@ -101,11 +101,6 @@ public: static QString dataObjectEntry( const Handle(HYDROData_Entity)& theObject, const bool theWithPrefix = true ); - /** - * Returns true if it is a zone which needs merge of bathymetries. - */ - virtual bool isMergingNeed() const { return false; } - protected: Handle(HYDROData_Entity) myData; ///< object from data model QString myParentEntry; diff --git a/src/HYDROGUI/HYDROGUI_Zone.cxx b/src/HYDROGUI/HYDROGUI_Zone.cxx index 8b6ecfb8..195afa15 100644 --- a/src/HYDROGUI/HYDROGUI_Zone.cxx +++ b/src/HYDROGUI/HYDROGUI_Zone.cxx @@ -183,3 +183,74 @@ QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId } return aRes; } + +QStringList HYDROGUI_Zone::getBathymetries() const +{ + QStringList aRes; + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); + if ( !aZone.IsNull() ) + { + HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects(); + // Collect all used bathymetries names when merging is necessary + // or just get the name of bathymetry of a single geometry object + HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Object) aRefGeomObj = + Handle(HYDROData_Object)::DownCast( anIter.Value() ); + if ( !aRefGeomObj.IsNull() ) + { + // Get bathymetry name + Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry(); + if ( !aBathymetry.IsNull() && !aRes.contains( aBathymetry->GetName() )) + { + aRes.append( aBathymetry->GetName() ); + } + } + } + } + return aRes; +} + +HYDROData_Zone::MergeBathymetriesType HYDROGUI_Zone::getMergeType() const +{ + HYDROData_Zone::MergeBathymetriesType aRes = HYDROData_Zone::Merge_UNKNOWN; + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); + if ( !aZone.IsNull() ) + { + aRes = aZone->GetMergeType(); + } + return aRes; +} + +void HYDROGUI_Zone::setMergeType( int theMergeType, QString theBathymetryName ) +{ + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); + if ( !aZone.IsNull() ) + { + HYDROData_Zone::MergeBathymetriesType aMergeType = + ( HYDROData_Zone::MergeBathymetriesType )theMergeType; + aZone->SetMergeType( aMergeType ); + if ( aMergeType == HYDROData_Zone::Merge_Object ) + { + // Find a bathymetry by the given name and set it as the zone's merge bathymetry + HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects(); + HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Object) aRefGeomObj = + Handle(HYDROData_Object)::DownCast( anIter.Value() ); + if ( !aRefGeomObj.IsNull() ) + { + // Get bathymetry name + Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry(); + if ( !aBathymetry.IsNull() && theBathymetryName == aBathymetry->GetName() ) + { + aZone->SetMergeBathymetry( aBathymetry ); + break; + } + } + } + } + } +} diff --git a/src/HYDROGUI/HYDROGUI_Zone.h b/src/HYDROGUI/HYDROGUI_Zone.h index 1ecc1545..2b1f08fd 100644 --- a/src/HYDROGUI/HYDROGUI_Zone.h +++ b/src/HYDROGUI/HYDROGUI_Zone.h @@ -53,20 +53,34 @@ public: /** * Returns the text for the specified column. */ - QString text( const int = NameId ) const override; + QString text( const int = NameId ) const override; /** * Returns the color for the specified column. */ - QColor color( const ColorRole, const int = NameId ) const override; + QColor color( const ColorRole, const int = NameId ) const override; /** * Returns true if it is a zone which needs merge of bathymetries. */ - bool isMergingNeed() const override; + bool isMergingNeed() const; + /** + * Returns the list of bathymetries names. + */ QStringList getBathymetries() const; + /** + * Returns the merging type for conflict bathymetries. + */ + HYDROData_Zone::MergeBathymetriesType getMergeType() const; + + /** + * Set the merging type for conflict bathymetries. + * If the type is Merge_Object then use the second parameter to set the merge bathymetry. + */ + void setMergeType( int theMergeType, QString theBathymetryName = QString() ); + private: QString getRefObjectNames() const; QString getBathimetryName() const; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index c7c7a8b2..c99e1aa0 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -88,6 +88,18 @@ does not exist or you have not enough permissions to open it. REMOVE Remove + + MERGE_UNKNOWN + Unresolved Conflict + + + MERGE_ZMIN + ZMIN + + + MERGE_ZMAX + ZMAX + -- 2.39.2