From 6d6c4ec18ead5730c1d14090e33dc9667c5a5841 Mon Sep 17 00:00:00 2001 From: rkv Date: Thu, 31 Oct 2013 14:12:56 +0000 Subject: [PATCH] HYDROGUI_Zone class is introduced. --- src/HYDROGUI/CMakeLists.txt | 2 + src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 24 ++- src/HYDROGUI/HYDROGUI_CalculationDlg.h | 21 ++- src/HYDROGUI/HYDROGUI_CalculationOp.cxx | 1 + src/HYDROGUI/HYDROGUI_DataModel.cxx | 14 +- src/HYDROGUI/HYDROGUI_DataObject.cxx | 56 ------- src/HYDROGUI/HYDROGUI_DataObject.h | 9 +- src/HYDROGUI/HYDROGUI_Zone.cxx | 185 +++++++++++++++++++++++ src/HYDROGUI/HYDROGUI_Zone.h | 74 +++++++++ 9 files changed, 311 insertions(+), 75 deletions(-) create mode 100644 src/HYDROGUI/HYDROGUI_Zone.cxx create mode 100644 src/HYDROGUI/HYDROGUI_Zone.h diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index c88b7ba1..32e007dd 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -50,6 +50,7 @@ set(PROJECT_HEADERS HYDROGUI_UpdateImageOp.h HYDROGUI_VisualStateOp.h HYDROGUI_Wizard.h + HYDROGUI_Zone.h ) QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -101,6 +102,7 @@ set(PROJECT_SOURCES HYDROGUI_UpdateImageOp.cxx HYDROGUI_VisualStateOp.cxx HYDROGUI_Wizard.cxx + HYDROGUI_Zone.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 9d5265ac..f254ad44 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -32,11 +32,12 @@ #include #include -#include +#include #include #include +#include #include #include #include @@ -167,19 +168,36 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { aLayout->addWidget( myBrowser, 0, 0, 1, 2 ); - QLabel* aBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame ); + myBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame ); myBathymetryChoice = new QComboBox( aFrame ); myBathymetryChoice->addItem( tr( "ZMIN" ) ); myBathymetryChoice->addItem( tr( "ZMAX" ) ); - aLayout->addWidget( aBatimetryLabel, 1, 0 ); + myBathymetryChoice->setVisible( false ); + myBatimetryLabel->setVisible( false ); + + aLayout->addWidget( myBatimetryLabel, 1, 0 ); aLayout->addWidget( myBathymetryChoice, 1, 1 ); aPage->setLayout( aLayout ); + connect( myBrowser, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); + return aPage; } +void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject ) +{ + bool doShow = false; + HYDROGUI_DataObject* anObject = dynamic_cast( theObject ); + if ( anObject ) + { + doShow = anObject->isMergingNeed(); + } + myBathymetryChoice->setVisible( doShow ); + myBatimetryLabel->setVisible( doShow ); +} + void HYDROGUI_CalculationDlg::setObjectName( const QString& theName ) { myObjectName->setText( theName ); diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index fa48b369..7ddb5391 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -31,9 +31,11 @@ class QGroupBox; class QLineEdit; class QListWidget; class QComboBox; +class QLabel; class QStringList; class HYDROGUI_DataBrowser; class HYDROGUI_NameValidator; +class SUIT_DataObject; class HYDROGUI_CalculationDlg : public HYDROGUI_Wizard { @@ -55,13 +57,17 @@ public: QStringList getSelectedGeomObjects() const; public slots: - void onEmptyName(); - void onAlreadyExists( QString theName ); + void onEmptyName(); + void onAlreadyExists( QString theName ); + /** + * Process items selection: hide/show bathymetry merge type selector. + */ + void onSelected( SUIT_DataObject* theObject ); signals: - void addObjects(); - void removeObjects(); - void splitZones(); + void addObjects(); + void removeObjects(); + void splitZones(); private: @@ -74,9 +80,10 @@ private: QListWidget* myGeomObjects; - HYDROGUI_DataBrowser* myBrowser; + HYDROGUI_DataBrowser* myBrowser; Handle(HYDROData_CalculationCase) myEditedObject; - QComboBox* myBathymetryChoice; + QComboBox* myBathymetryChoice; + QLabel* myBatimetryLabel; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index f36ac726..ea4f7125 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -149,6 +149,7 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) ); connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) ); connect( aPanel, SIGNAL( splitZones() ), SLOT( onSplitZones() ) ); + connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); return aPanel; } diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index a1be099c..6ea2d54a 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -25,6 +25,7 @@ #include "HYDROGUI_DataObject.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" +#include "HYDROGUI_Zone.h" #include #include @@ -527,8 +528,17 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* const QString& theParentEntry, const bool theIsBuildTree ) { - HYDROGUI_DataObject* aResObj = - new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry ); + HYDROGUI_DataObject* aResObj; + Handle(HYDROData_Zone) aRegionZone = + Handle(HYDROData_Zone)::DownCast( theModelObject ); + if( !aRegionZone.IsNull() ) + { + aResObj = new HYDROGUI_Zone( theParent, aRegionZone, theParentEntry ); + } + else + { + aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry ); + } if ( theIsBuildTree ) { diff --git a/src/HYDROGUI/HYDROGUI_DataObject.cxx b/src/HYDROGUI/HYDROGUI_DataObject.cxx index 7b594a28..b54120e1 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.cxx +++ b/src/HYDROGUI/HYDROGUI_DataObject.cxx @@ -23,12 +23,7 @@ #include "HYDROGUI_DataObject.h" #include -#include -#include -#include - #include - #include HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent, @@ -75,57 +70,6 @@ QFont HYDROGUI_DataObject::font( const int theId ) const return aFont; } -QString HYDROGUI_DataObject::text( const int theColumnId ) const -{ - QString aRes; - if( !myData.IsNull() ) - { - if ( theColumnId == RefObjectId || theColumnId == BathymetryId ) - { - Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( myData ); - if ( !aZone.IsNull() ) - { - 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() ) - { - switch ( theColumnId ) - { - case RefObjectId: - // Get Ref.Object name - aRes += aRefGeomObj->GetName() + ", "; - break; - case BathymetryId: - // Get bathymetry name - aRes += aRefGeomObj->GetBathymetry()->GetName() + ", "; - } - } - } - } - if ( aRes.length() > 1 ) - { - aRes.remove( aRes.length() - 2, 2 ); - } - } - else - { - aRes = LightApp_DataObject::text( theColumnId ); - } - } - return aRes; -} - -QColor HYDROGUI_DataObject::color( const ColorRole theColorRole, const int theColumnId ) const -{ - //TODO: Implement red color for bathymetry conflicts in case creation dialog - return LightApp_DataObject::color( theColorRole, theColumnId ); -} - - QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject, const bool theWithPrefix ) { diff --git a/src/HYDROGUI/HYDROGUI_DataObject.h b/src/HYDROGUI/HYDROGUI_DataObject.h index 6ea1038d..80451830 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.h +++ b/src/HYDROGUI/HYDROGUI_DataObject.h @@ -102,14 +102,9 @@ public: const bool theWithPrefix = true ); /** - * Returns the text for the specified column. + * Returns true if it is a zone which needs merge of bathymetries. */ - virtual QString text( const int = NameId ) const; - - /** - * Returns the color for the specified column. - */ - virtual QColor color( const ColorRole, const int = NameId ) const; + virtual bool isMergingNeed() const { return false; } protected: Handle(HYDROData_Entity) myData; ///< object from data model diff --git a/src/HYDROGUI/HYDROGUI_Zone.cxx b/src/HYDROGUI/HYDROGUI_Zone.cxx new file mode 100644 index 00000000..8b6ecfb8 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Zone.cxx @@ -0,0 +1,185 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_Zone.h" + +#include +#include +#include + +#include + +HYDROGUI_Zone::HYDROGUI_Zone( SUIT_DataObject* theParent, + Handle(HYDROData_Zone) theData, + const QString& theParentEntry ) +: HYDROGUI_DataObject( theParent, theData, theParentEntry ), CAM_DataObject( theParent ) +{ +} + +QString HYDROGUI_Zone::text( const int theColumnId ) const +{ + QString aRes; + if( !modelObject().IsNull() ) + { + switch ( theColumnId ) + { + case RefObjectId: + // Get Ref.Object name + aRes = getRefObjectNames(); + break; + case BathymetryId: + // Get bathymetry name + aRes = getBathimetryName(); + break; + default: + aRes = LightApp_DataObject::text( theColumnId ); + } + } + return aRes; +} + +QString HYDROGUI_Zone::getRefObjectNames() const +{ + QString aRes; + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); + if ( !aZone.IsNull() ) + { + 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 Ref.Object name + aRes += aRefGeomObj->GetName() + ", "; + } + } + } + if ( aRes.length() > 1 ) + { + aRes.remove( aRes.length() - 2, 2 ); + } + return aRes; +} + +QString HYDROGUI_Zone::getBathimetryName() const +{ + QString aRes; + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); + if ( !aZone.IsNull() ) + { + HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects(); + if ( aZone->IsMergingNeed() || aSeq.Length() == 1 ) + { + // 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 += aBathymetry->GetName() + ", "; + } + } + } + if ( aRes.length() > 1 ) + { + aRes.remove( aRes.length() - 2, 2 ); + } + } + else + { + switch( aZone->GetMergeType() ) + { + case HYDROData_Zone::Merge_ZMIN: // The minimum values + aRes = QObject::tr( "MERGE_ZMIN" ); + break; + case HYDROData_Zone::Merge_ZMAX: // The maximum values + aRes = QObject::tr( "MERGE_ZMAX" ); + break; + case HYDROData_Zone::Merge_Object: // Only one bathymetry will be taken into account + { + Handle(HYDROData_Bathymetry) aBathymetry = aZone->GetMergeBathymetry(); + if ( !aBathymetry.IsNull() ) + { + aRes = aBathymetry->GetName(); + } + break; + } + default: + aRes = QObject::tr( "MERGE_UNKNOWN" ); + } + } + } + return aRes; +} + +bool HYDROGUI_Zone::isMergingNeed() const +{ + bool aRes = false; + if( !modelObject().IsNull() ) + { + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); + if ( !aZone.IsNull() ) + { + aRes = aZone->IsMergingNeed(); + } + } + return aRes; +} + +QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId ) const +{ + // Implement red color for bathymetry conflicts in case creation dialog + QColor aRes; + if( isMergingNeed() ) + { + switch( theColorRole ) + { + case Text: // editor foreground (text) color + case Foreground: // foreground (text) color + aRes = Qt::red; + break; + case HighlightedText: // highlighted foreground (text) color + aRes = Qt::black; + break; + case Base: // editor background color + case Background: // background color + case Highlight: // highlight background color + default: + aRes = Qt::red; + } + } + else + { + aRes = LightApp_DataObject::color( theColorRole, theColumnId ); + } + return aRes; +} diff --git a/src/HYDROGUI/HYDROGUI_Zone.h b/src/HYDROGUI/HYDROGUI_Zone.h new file mode 100644 index 00000000..1ecc1545 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_Zone.h @@ -0,0 +1,74 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_ZONE_H +#define HYDROGUI_ZONE_H + +#include "HYDROGUI_DataObject.h" + +#include + +#include +#include + +/** + * \class HYDROGUI_Zone + * \brief Browser item presenting a zone, used for object browser tree creation. + * + * This is an Object Browser item that contains reference to a zone data structure + * element inside. + */ +class HYDROGUI_Zone : public HYDROGUI_DataObject +{ +public: + /** + * Constructor. + * \param theParent parent data object + * \param theData reference to the corresponding object from data structure + * \param theParentEntry entry of the parent data object (for reference objects) + */ + HYDROGUI_Zone( SUIT_DataObject* theParent, + Handle(HYDROData_Zone) theData, + const QString& theParentEntry ); + + /** + * Returns the text for the specified column. + */ + QString text( const int = NameId ) const override; + + /** + * Returns the color for the specified column. + */ + 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; + + QStringList getBathymetries() const; + +private: + QString getRefObjectNames() const; + QString getBathimetryName() const; +}; +#endif -- 2.39.2