From: mkr Date: Thu, 11 Jun 2015 14:56:06 +0000 (+0300) Subject: refs #573, #574: implementation of ordered list widget and a table to define prioriti... X-Git-Tag: v1.4.1~6^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=21eebcb554d7cf6c6ee051aca4f01d84750abce3;p=modules%2Fhydro.git refs #573, #574: implementation of ordered list widget and a table to define priorities for land covers. --- diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 8ef1bd1b..bfed4f10 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -348,7 +348,7 @@ void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Docume QMap aRegionsMap; //object name to region QMap aRegionNameToObjNameMap; QString aZonesPref = CALCULATION_ZONES_PREF; - HYDROData_PriorityQueue aPr( this ); + HYDROData_PriorityQueue aPr( this, DataTag_CustomRules ); // 1. First we create a default region for each object included into the calculation case HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects(); @@ -371,7 +371,8 @@ void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Docume { const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next(); HYDROData_Zone::MergeAltitudesType aMergeType; - Handle(HYDROData_Object) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType ); + Handle(HYDROData_Object) aRegObj = + Handle(HYDROData_Object)::DownCast( aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType ) ); if( aRegObj.IsNull() ) continue; Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()]; @@ -1237,9 +1238,10 @@ GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM( return aGeomObj._retn(); } -void HYDROData_CalculationCase::ClearRules( const bool theIsSetToUpdate ) +void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag, + const bool theIsSetToUpdate ) { - TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules ); + TDF_Label aRulesLab = myLab.FindChild( theDataTag ); HYDROData_PriorityQueue::ClearRules( aRulesLab ); // Indicate model of the need to update splitting @@ -1248,12 +1250,13 @@ void HYDROData_CalculationCase::ClearRules( const bool theIsSetToUpdate ) } } -void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Object)& theObject1, +void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1, HYDROData_PriorityType thePriority, - const Handle(HYDROData_Object)& theObject2, - HYDROData_Zone::MergeAltitudesType theMergeType ) + const Handle(HYDROData_Entity)& theObject2, + HYDROData_Zone::MergeAltitudesType theMergeType, + HYDROData_CalculationCase::DataTag theDataTag ) { - TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules ); + TDF_Label aRulesLab = myLab.FindChild( theDataTag ); HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType ); // Indicate model of the need to update splitting @@ -1304,12 +1307,13 @@ void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const } bool HYDROData_CalculationCase::GetRule( int theIndex, - Handle(HYDROData_Object)& theObject1, + Handle(HYDROData_Entity)& theObject1, HYDROData_PriorityType& thePriority, - Handle(HYDROData_Object)& theObject2, - HYDROData_Zone::MergeAltitudesType& theMergeType ) const + Handle(HYDROData_Entity)& theObject2, + HYDROData_Zone::MergeAltitudesType& theMergeType, + HYDROData_CalculationCase::DataTag& theDataTag) const { - TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules ); + TDF_Label aRulesLab = myLab.FindChild( theDataTag ); return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex, theObject1, thePriority, theObject2, theMergeType ); } @@ -1332,41 +1336,3 @@ HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignme else return MANUAL; } - -void HYDROData_CalculationCase::ClearLandCoverRules( const bool theIsSetToUpdate ) -{ - TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules ); - // TODO: adapt HYDROData_PriorityQueue to use with land covers - //HYDROData_PriorityQueue::ClearRules( aRulesLab ); - - // Indicate model of the need to update land covers partition - if ( theIsSetToUpdate ) { - SetToUpdate( true ); - } -} - -void HYDROData_CalculationCase::AddLandCoverRule( const Handle(HYDROData_LandCover)& theLandCover1, - HYDROData_PriorityType thePriority, - const Handle(HYDROData_LandCover)& theLandCover2/*, - HYDROData_LandCover::MergeStricklerCoefficientType theMergeType*/ ) -{ - TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules ); - // TODO: adapt HYDROData_PriorityQueue to use with land covers - //HYDROData_PriorityQueue::AddRule( aRulesLab, theLandCover1, thePriority, theLandCover2, theMergeType ); - - // Indicate model of the need to update splitting - SetToUpdate( true ); -} - -bool HYDROData_CalculationCase::GetLandCoverRule( int theIndex, - Handle(HYDROData_LandCover)& theLandCover1, - HYDROData_PriorityType& thePriority, - Handle(HYDROData_LandCover)& theLandCover2/*, - HYDROData_LandCover::MergeStricklerCoefficientType& theMergeType*/ ) const -{ - TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules ); - // TODO: adapt HYDROData_PriorityQueue to use with land covers - //return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex, - // theLandCover1, thePriority, theLandCover2, theMergeType ); - return true; -} diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index d1a24b4d..b40503ba 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -358,31 +358,23 @@ public: HYDRODATA_EXPORT void SetAssignmentMode( AssignmentMode theMode ); HYDRODATA_EXPORT AssignmentMode GetAssignmentMode() const; - HYDRODATA_EXPORT void ClearRules( const bool theIsSetToUpdate = true ); - HYDRODATA_EXPORT void AddRule( const Handle(HYDROData_Object)& theObject1, - HYDROData_PriorityType thePriority, - const Handle(HYDROData_Object)& theObject2, - HYDROData_Zone::MergeAltitudesType theMergeType ); + HYDRODATA_EXPORT void ClearRules( HYDROData_CalculationCase::DataTag theDataTag, + const bool theIsSetToUpdate = true ); + HYDRODATA_EXPORT void AddRule( const Handle(HYDROData_Entity)& theObject1, + HYDROData_PriorityType thePriority, + const Handle(HYDROData_Entity)& theObject2, + HYDROData_Zone::MergeAltitudesType theMergeType, + HYDROData_CalculationCase::DataTag theDataTag ); HYDRODATA_EXPORT bool GetRule( int theIndex, - Handle(HYDROData_Object)& theObject1, + Handle(HYDROData_Entity)& theObject1, HYDROData_PriorityType& thePriority, - Handle(HYDROData_Object)& theObject2, - HYDROData_Zone::MergeAltitudesType& theMergeType ) const; + Handle(HYDROData_Entity)& theObject2, + HYDROData_Zone::MergeAltitudesType& theMergeType, + HYDROData_CalculationCase::DataTag& theDataTag ) const; HYDRODATA_EXPORT void SetAssignmentLandCoverMode( AssignmentMode theMode ); HYDRODATA_EXPORT AssignmentMode GetAssignmentLandCoverMode() const; - HYDRODATA_EXPORT void ClearLandCoverRules( const bool theIsSetToUpdate = true ); - HYDRODATA_EXPORT void AddLandCoverRule( const Handle(HYDROData_LandCover)& theLandCover1, - HYDROData_PriorityType thePriority, - const Handle(HYDROData_LandCover)& theLandCover2/*, - HYDROData_LandCover::MergeStricklerCoefficientType theMergeType*/ ); - HYDRODATA_EXPORT bool GetLandCoverRule( int theIndex, - Handle(HYDROData_LandCover)& theLandCover1, - HYDROData_PriorityType& thePriority, - Handle(HYDROData_LandCover)& theLandCover2/*, - HYDROData_LandCover::MergeStricklerCoefficientType& theMergeType*/ ) const; - HYDRODATA_EXPORT QString DumpRules() const; HYDRODATA_EXPORT HYDROData_Warning GetLastWarning() const; diff --git a/src/HYDROData/HYDROData_PriorityQueue.cxx b/src/HYDROData/HYDROData_PriorityQueue.cxx index 3e85dfd2..6dbb5dae 100644 --- a/src/HYDROData/HYDROData_PriorityQueue.cxx +++ b/src/HYDROData/HYDROData_PriorityQueue.cxx @@ -19,16 +19,18 @@ #include #include #include +#include #include #include #include -HYDROData_PriorityQueue::HYDROData_PriorityQueue( HYDROData_CalculationCase* theCalcCase ) +HYDROData_PriorityQueue::HYDROData_PriorityQueue( HYDROData_CalculationCase* theCalcCase, + Standard_Integer aTag ) { myGeomObjects = theCalcCase->GetGeometryObjects(); for( int i=myGeomObjects.Lower(), n=myGeomObjects.Upper(); i<=n; i++ ) { - Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( myGeomObjects.Value( i ) ); + Handle(HYDROData_Entity) anObj = myGeomObjects.Value( i ); if( !anObj.IsNull() ) { QString anObjName = anObj->GetName(); @@ -36,14 +38,14 @@ HYDROData_PriorityQueue::HYDROData_PriorityQueue( HYDROData_CalculationCase* the } } - myRules = GetRules( theCalcCase->Label().FindChild( HYDROData_CalculationCase::DataTag_CustomRules ) ); + myRules = GetRules( theCalcCase->Label().FindChild( aTag ) ); } HYDROData_PriorityQueue::~HYDROData_PriorityQueue() { } -Handle(HYDROData_Object) HYDROData_PriorityQueue::GetMostPriorityObject( const QStringList& theZoneObjects, +Handle(HYDROData_Entity) HYDROData_PriorityQueue::GetMostPriorityObject( const QStringList& theZoneObjects, HYDROData_Zone::MergeAltitudesType& theMergeType ) const { QStringList aSortedZoneObjects; @@ -54,13 +56,13 @@ Handle(HYDROData_Object) HYDROData_PriorityQueue::GetMostPriorityObject( const Q aSortedZoneObjects.append( aName ); } - Handle(HYDROData_Object) aMostPriorityObj; + Handle(HYDROData_Entity) aMostPriorityObj; theMergeType = HYDROData_Zone::Merge_UNKNOWN; QStringList::const_iterator anIt = aSortedZoneObjects.begin(), aLast = aSortedZoneObjects.end(); for( ; anIt!=aLast; anIt++ ) { HYDROData_Zone::MergeAltitudesType aLocalMerge = HYDROData_Zone::Merge_UNKNOWN; - Handle(HYDROData_Object) anObj = myNames[*anIt]; + Handle(HYDROData_Entity) anObj = myNames[*anIt]; if( !anObj.IsNull() ) { if( aMostPriorityObj.IsNull() ) @@ -82,8 +84,8 @@ Handle(HYDROData_Object) HYDROData_PriorityQueue::GetMostPriorityObject( const Q return aMostPriorityObj; } -bool HYDROData_PriorityQueue::IsMorePriority( const Handle(HYDROData_Object)& theObj1, - const Handle(HYDROData_Object)& theObj2, +bool HYDROData_PriorityQueue::IsMorePriority( const Handle(HYDROData_Entity)& theObj1, + const Handle(HYDROData_Entity)& theObj2, HYDROData_Zone::MergeAltitudesType& theMergeType ) const { // 1. First we check custom rules @@ -133,9 +135,9 @@ enum HYDROData_PriorityQueueTag }; void HYDROData_PriorityQueue::AddRule( TDF_Label& theRulesLabel, - const Handle(HYDROData_Object)& theObject1, + const Handle(HYDROData_Entity)& theObject1, HYDROData_PriorityType thePriority, - const Handle(HYDROData_Object)& theObject2, + const Handle(HYDROData_Entity)& theObject2, HYDROData_Zone::MergeAltitudesType theMergeType ) { // Get the last rule index @@ -185,9 +187,9 @@ HYDROData_ListOfRules HYDROData_PriorityQueue::GetRules( const TDF_Label& theRul if( isObj1OK && isPriorityOK && isObj2OK && isMergeOK ) { HYDROData_CustomRule aRule; - aRule.Object1 = Handle_HYDROData_Object::DownCast( HYDROData_Iterator::Object( aRefs1->First() ) ); + aRule.Object1 = HYDROData_Iterator::Object( aRefs1->First() ); aRule.Priority = ( HYDROData_PriorityType ) aPriorityAttr->Get(); - aRule.Object2 = Handle_HYDROData_Object::DownCast( HYDROData_Iterator::Object( aRefs2->First() ) ); + aRule.Object2 = HYDROData_Iterator::Object( aRefs2->First() ); aRule.MergeType = ( HYDROData_Zone::MergeAltitudesType ) aMergeAttr->Get(); aRules.append( aRule ); } @@ -240,6 +242,12 @@ void HYDROData_PriorityQueue::DumpRulesToPython( const TDF_Label& theRulesLab, QString aPriority = anIt->Priority == LESS ? "LESS" : "GREATER"; QString aMergeType; + HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules; + Handle(HYDROData_LandCover) aLandCover1 = Handle(HYDROData_LandCover)::DownCast( anIt->Object1 ); + Handle(HYDROData_LandCover) aLandCover2 = Handle(HYDROData_LandCover)::DownCast( anIt->Object2 ); + if ( !aLandCover1.IsNull() && !aLandCover2.IsNull() ) + aDataTag = HYDROData_CalculationCase::DataTag_CustomLandCoverRules; + switch( anIt->MergeType ) { case HYDROData_Zone::Merge_UNKNOWN: @@ -256,8 +264,8 @@ void HYDROData_PriorityQueue::DumpRulesToPython( const TDF_Label& theRulesLab, break; } - QString aRule = QString( "%0.AddRule( %1, %2, %3, %4 )" ). - arg( theCalcCaseName ).arg( anObj1 ).arg( aPriority ).arg( anObj2 ).arg( aMergeType ); + QString aRule = QString( "%0.AddRule( %1, %2, %3, %4, %5 )" ). + arg( theCalcCaseName ).arg( anObj1 ).arg( aPriority ).arg( anObj2 ).arg( aMergeType ).arg( aDataTag ); theScript << aRule; } @@ -265,9 +273,9 @@ void HYDROData_PriorityQueue::DumpRulesToPython( const TDF_Label& theRulesLab, bool HYDROData_PriorityQueue::GetRule( const TDF_Label& theRulesLab, int theIndex, - Handle(HYDROData_Object)& theObject1, + Handle(HYDROData_Entity)& theObject1, HYDROData_PriorityType& thePriority, - Handle(HYDROData_Object)& theObject2, + Handle(HYDROData_Entity)& theObject2, HYDROData_Zone::MergeAltitudesType& theMergeType ) { TDF_Label aRuleLabel = theRulesLab.FindChild( theIndex ); @@ -283,9 +291,9 @@ bool HYDROData_PriorityQueue::GetRule( const TDF_Label& theRulesLab, bool isOK = isObj1OK && isPriorityOK && isObj2OK && isMergeOK; if( isOK ) { - theObject1 = Handle_HYDROData_Object::DownCast( HYDROData_Iterator::Object( aRefs1->First() ) ); + theObject1 = HYDROData_Iterator::Object( aRefs1->First() ); thePriority = ( HYDROData_PriorityType ) aPriorityAttr->Get(); - theObject2 = Handle_HYDROData_Object::DownCast( HYDROData_Iterator::Object( aRefs2->First() ) ); + theObject2 = HYDROData_Iterator::Object( aRefs2->First() ); theMergeType = ( HYDROData_Zone::MergeAltitudesType ) aMergeAttr->Get(); } return isOK; diff --git a/src/HYDROData/HYDROData_PriorityQueue.h b/src/HYDROData/HYDROData_PriorityQueue.h index 87ae4d60..80d1b652 100644 --- a/src/HYDROData/HYDROData_PriorityQueue.h +++ b/src/HYDROData/HYDROData_PriorityQueue.h @@ -20,7 +20,7 @@ #define HYDROData_PriorityQueue_HeaderFile #include -#include +#include #include class HYDROData_CalculationCase; @@ -33,9 +33,9 @@ enum HYDROData_PriorityType struct HYDROData_CustomRule { - Handle(HYDROData_Object) Object1; + Handle(HYDROData_Entity) Object1; HYDROData_PriorityType Priority; - Handle(HYDROData_Object) Object2; + Handle(HYDROData_Entity) Object2; HYDROData_Zone::MergeAltitudesType MergeType; }; @@ -44,21 +44,22 @@ typedef QList HYDROData_ListOfRules; class HYDROData_PriorityQueue { public: - HYDROData_PriorityQueue( HYDROData_CalculationCase* ); + HYDROData_PriorityQueue( HYDROData_CalculationCase* theCalcCase, + Standard_Integer aTag ); ~HYDROData_PriorityQueue(); - Handle_HYDROData_Object GetMostPriorityObject( const QStringList& theZoneObjects, + Handle_HYDROData_Entity GetMostPriorityObject( const QStringList& theZoneObjects, HYDROData_Zone::MergeAltitudesType& theMergeType ) const; - bool IsMorePriority( const Handle(HYDROData_Object)& theObj1, - const Handle(HYDROData_Object)& theObj2, + bool IsMorePriority( const Handle(HYDROData_Entity)& theObj1, + const Handle(HYDROData_Entity)& theObj2, HYDROData_Zone::MergeAltitudesType& theMergeType ) const; static void ClearRules( TDF_Label& theRulesLabel ); static void AddRule( TDF_Label& theRulesLabel, - const Handle(HYDROData_Object)& theObject1, + const Handle(HYDROData_Entity)& theObject1, HYDROData_PriorityType thePriority, - const Handle(HYDROData_Object)& theObject2, + const Handle(HYDROData_Entity)& theObject2, HYDROData_Zone::MergeAltitudesType theMergeType ); static HYDROData_ListOfRules GetRules( const TDF_Label& theRulesLabel ); static QString DumpRules( const TDF_Label& theRulesLab ); @@ -67,12 +68,12 @@ public: QStringList& theScript ); static bool GetRule( const TDF_Label& theRulesLab, int theIndex, - Handle(HYDROData_Object)& theObject1, + Handle(HYDROData_Entity)& theObject1, HYDROData_PriorityType& thePriority, - Handle(HYDROData_Object)& theObject2, + Handle(HYDROData_Entity)& theObject2, HYDROData_Zone::MergeAltitudesType& theMergeType ); private: - typedef QMap MapNameToObject; + typedef QMap MapNameToObject; HYDROData_SequenceOfObjects myGeomObjects; ///< the ordered list of objects (default priority) MapNameToObject myNames; ///< the map of name to object diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 889e8114..9e97678e 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -30,6 +30,7 @@ #include "HYDROGUI_Zone.h" #include "HYDROGUI_OrderedListWidget.h" #include "HYDROGUI_PriorityWidget.h" +#include "HYDROGUI_PriorityTableModel.h" #include #include @@ -95,8 +96,9 @@ void HYDROGUI_CalculationDlg::reset() setLandCoverMode( HYDROData_CalculationCase::AUTOMATIC ); // Reset the priority widget state - QList anObjects; + QList anObjects; myPriorityWidget->setObjects( anObjects ); + myLandCoverPriorityWidget->setObjects( anObjects ); } QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { @@ -405,6 +407,10 @@ QWizardPage* HYDROGUI_CalculationDlg::createLandCoversPage() { // Bottom of the page myLandCoverPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() ); + HYDROGUI_PriorityTableModel* aModel = + dynamic_cast( myLandCoverPriorityWidget->getTable()->model() ); + if ( aModel ) + aModel->setColumnCount( 3 ); QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) ); QBoxLayout* aPriorityLayout = new QHBoxLayout; @@ -935,10 +941,10 @@ void HYDROGUI_CalculationDlg::setEditLandCoversEnabled( const bool theIsEnabled Get included geometry objects. @return the list of geometry objects */ -QList HYDROGUI_CalculationDlg::getGeometryObjects() +QList HYDROGUI_CalculationDlg::getGeometryObjects() { QList anEntities = myGeomObjects->getObjects(); - QList anObjects; + QList anObjects; foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) { Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity ); @@ -956,10 +962,10 @@ QList HYDROGUI_CalculationDlg::getGeometryObjects() Get included land covers. @return the list of land covers */ -QList HYDROGUI_CalculationDlg::getLandCovers() +QList HYDROGUI_CalculationDlg::getLandCovers() { QList anEntities = myLandCovers->getObjects(); - QList aLandCovers; + QList aLandCovers; foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) { Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity ); @@ -991,6 +997,24 @@ void HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) myPriorityWidget->setRules( theRules ); } +/** + Get rules defined for land covers. + @return the list of rules + */ +HYDROData_ListOfRules HYDROGUI_CalculationDlg::getLandCoverRules() const +{ + return myLandCoverPriorityWidget->getRules(); +} + +/** + Set rules for land covers. + @param theRules the list of rules + */ +void HYDROGUI_CalculationDlg::setLandCoverRules( const HYDROData_ListOfRules& theRules ) const +{ + myLandCoverPriorityWidget->setRules( theRules ); +} + /** Slot called when objects order is changed. */ @@ -1004,15 +1028,28 @@ void HYDROGUI_CalculationDlg::onOrderChanged() myGeomObjects->undoLastMove(); } -void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName ) +void HYDROGUI_CalculationDlg::setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals ) { - bool isBlocked = myStricklerTableName->blockSignals( true ); + bool isBlocked; + if ( theBlockSignals ) + isBlocked = myStricklerTableName->blockSignals( true ); + myStricklerTableName->setCurrentIndex( myStricklerTableName->findText( theStricklerTableName ) ); - myStricklerTableName->blockSignals( isBlocked ); + + if ( theBlockSignals ) + myStricklerTableName->blockSignals( isBlocked ); + else + emit StricklerTableSelected( theStricklerTableName ); } -void HYDROGUI_CalculationDlg::includeLandCovers( const QStringList& theLandCovers ) +void HYDROGUI_CalculationDlg::includeLandCovers( const QStringList& theLandCovers, bool theReset ) { + if ( theReset ) + { + HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList; + myLandCovers->setObjects(anObject2VisibleList); + } + HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude; QList aFoundItems; foreach ( const QString& anObjName, theLandCovers ) { @@ -1028,8 +1065,7 @@ void HYDROGUI_CalculationDlg::includeLandCovers( const QStringList& theLandCover myLandCovers->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) ); } - // TODO: adapt HYDROGUI_PriorityWidget to process land covers - //myLandCoverPriorityWidget->setObjects( getLandCovers() ); + myLandCoverPriorityWidget->setObjects( getLandCovers() ); } void HYDROGUI_CalculationDlg::excludeLandCovers( const QStringList& theLandCovers ) @@ -1046,8 +1082,7 @@ void HYDROGUI_CalculationDlg::excludeLandCovers( const QStringList& theLandCover myLandCovers->removeObjectByName( anObjName ); } - // TODO: adapt HYDROGUI_PriorityWidget to process land covers - //myLandCoverPriorityWidget->setObjects( getLandCovers() ); + myLandCoverPriorityWidget->setObjects( getLandCovers() ); } /** @@ -1057,9 +1092,8 @@ void HYDROGUI_CalculationDlg::onOrderLandCoverChanged() { bool isConfirmed = true; emit orderLandCoverChanged( isConfirmed ); - // TODO: adapt HYDROGUI_PriorityWidget to process land covers - /*if( isConfirmed ) + if( isConfirmed ) myLandCoverPriorityWidget->setObjects( getLandCovers() ); - else*/ + else myLandCovers->undoLastMove(); } diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index 9bcdfd8a..f4ee385f 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -83,6 +83,9 @@ public: HYDROData_ListOfRules getRules() const; void setRules( const HYDROData_ListOfRules& theRules ) const; + HYDROData_ListOfRules getLandCoverRules() const; + void setLandCoverRules( const HYDROData_ListOfRules& theRules ) const; + public slots: void setMode( int theMode ); void setBoundary( const QString& theObjName ); @@ -97,8 +100,8 @@ public slots: void onOrderChanged(); void setLandCoverMode( int theMode ); - void setStricklerTable( const QString& theStricklerTableName ); - void includeLandCovers( const QStringList& theLandCovers ); + void setStricklerTable( const QString& theStricklerTableName, bool theBlockSignals = true ); + void includeLandCovers( const QStringList& theLandCovers, bool theReset ); void excludeLandCovers( const QStringList& theLandCovers ); void onOrderLandCoverChanged(); @@ -151,8 +154,8 @@ protected slots: void OnNewRegion(); private: - QList getGeometryObjects(); - QList getLandCovers(); + QList getGeometryObjects(); + QList getLandCovers(); QWizardPage* createObjectsPage(); QWizardPage* createGroupsPage(); diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 8ace99e3..f8311d5a 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -149,25 +149,7 @@ void HYDROGUI_CalculationOp::startOperation() aPanel->includeGeomObjects( aList ); // set rules - HYDROData_ListOfRules aRules; - Handle(HYDROData_Object) anObject1, anObject2; - HYDROData_PriorityType aPriority; - HYDROData_Zone::MergeAltitudesType aMergeType; - for ( int anIndex = 0; ; anIndex++ ) - { - if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType ) ) { - HYDROData_CustomRule aRule; - aRule.Object1 = anObject1; - aRule.Object2 = anObject2; - aRule.Priority = aPriority; - aRule.MergeType = aMergeType; - - aRules << aRule; - } - else - break; - } - aPanel->setRules( aRules ); + setRules( HYDROData_CalculationCase::DataTag_CustomRules ); } } else @@ -783,10 +765,10 @@ bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags, // For manual mode priority rules are redundant if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) { - myEditedObject->ClearRules( false ); + myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false ); } if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) { - myEditedObject->ClearLandCoverRules( false ); + myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false ); } theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init; @@ -869,13 +851,15 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) QStringList aList; QStringList anEntryList; + HYDROData_SequenceOfObjects aSeq; + + Handle(HYDROData_StricklerTable) aStricklerTableObj; + QString aStricklerTableName; // Get all Strickler table objects to fill in combo-box aList.clear(); anEntryList.clear(); - HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE ); - Handle(HYDROData_StricklerTable) aStricklerTableObj; - QString aStricklerTableName; + HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE ); for ( ; anIter.More(); anIter.Next() ) { aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() ); @@ -891,11 +875,18 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) } } aPanel->setStricklerTableNames( aList, anEntryList ); + if ( !aList.isEmpty() ) + aPanel->setStricklerTable( aList.at( 0 ), false ); // Fill in list widget with all available land covers - HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetLandCovers( module() ); + aSeq = HYDROGUI_Tool::GetLandCovers( module() ); getNamesAndEntries( aSeq, aList, anEntryList ); aPanel->setAllLandCovers( aList, anEntryList ); + + // Set list of included land covers + aSeq = myEditedObject->GetLandCovers(); + getNamesAndEntries( aSeq, aList, anEntryList ); + aPanel->includeLandCovers( aList, true ); if ( !myEditedObject.IsNull() ) { @@ -915,6 +906,9 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) // Set mode (Auto or Manual) to defined priority of land covers aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() ); + + // Set rules defined on land covers + setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules ); } else { @@ -962,12 +956,13 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) // Clear priority rules //@ASL if ( myEditedObject->GetRulesCount() > 0 ) { - myEditedObject->ClearRules( true ); + myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true ); //@ASL } // Set priority rules foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) { myEditedObject->AddRule( aRule.Object1, aRule.Priority, - aRule.Object2, aRule.MergeType ); + aRule.Object2, aRule.MergeType, + HYDROData_CalculationCase::DataTag_CustomRules ); } } } @@ -987,6 +982,8 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) createPreview(); anIsToUpdateOb = true; + + myEditedObject->SetToUpdate( true ); } else { @@ -997,6 +994,7 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) } } + // Move this code to processing od the last panel (see below) if ( anIsToUpdateOb ) { SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser(); if ( anObjBrowser ) { @@ -1016,8 +1014,6 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) QApplication::setOverrideCursor( Qt::WaitCursor ); - //... - // Set parameters for automatic mode int aMode = aPanel->getLandCoverMode(); if ( aMode == HYDROData_CalculationCase::AUTOMATIC ) @@ -1038,11 +1034,13 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) } // Clear priority rules - myEditedObject->ClearLandCoverRules( true ); - // TODO: Set priority rules - //foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) { - // myEditedObject->AddLandCoverRule( aRule.Object1, aRule.Priority, - // aRule.Object2, aRule.MergeType ); + myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true ); + // Set priority rules + foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) { + myEditedObject->AddRule( aRule.Object1, aRule.Priority, + aRule.Object2, HYDROData_Zone::Merge_Object, + HYDROData_CalculationCase::DataTag_CustomLandCoverRules ); + } } } aPanel->setEditLandCoversEnabled( aMode == HYDROData_CalculationCase::MANUAL ); @@ -1161,6 +1159,39 @@ QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex, return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() ); } +void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag ) +{ + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + HYDROData_ListOfRules aRules; + Handle(HYDROData_Entity) anObject1, anObject2; + HYDROData_PriorityType aPriority; + HYDROData_Zone::MergeAltitudesType aMergeType; + HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules; + for ( int anIndex = 0; ; anIndex++ ) + { + if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) { + HYDROData_CustomRule aRule; + aRule.Object1 = anObject1; + aRule.Object2 = anObject2; + aRule.Priority = aPriority; + aRule.MergeType = aMergeType; + + aRules << aRule; + } + else + break; + } + + if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules ) + aPanel->setRules( aRules ); + else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules ) + aPanel->setLandCoverRules( aRules ); +} + void HYDROGUI_CalculationOp::createPreview() { LightApp_Application* anApp = module()->getApp(); @@ -1437,7 +1468,7 @@ void HYDROGUI_CalculationOp::onAddLandCovers() if ( !anAddedList.isEmpty() ) { - aPanel->includeLandCovers( anAddedList ); + aPanel->includeLandCovers( anAddedList, false ); // TODO: create preview of included land covers //createPreview(); } diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index cf6a52a0..4966ee3c 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -169,6 +169,8 @@ private: float theSaturation = 0.5, float theValue = 0.95 ) const; + void setRules( HYDROData_CalculationCase::DataTag theDataTag ); + bool confirmRegionsChange() const; bool confirmModeChange() const; bool confirmOrderChange() const; diff --git a/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx index fe83e5d5..6e2e46cd 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx +++ b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx @@ -18,13 +18,15 @@ #include "HYDROGUI_PriorityTableModel.h" +#include /** Constructor. @param theParent the parent object */ HYDROGUI_PriorityTableModel::HYDROGUI_PriorityTableModel( QObject* theParent ) - : QAbstractTableModel( theParent ) + : QAbstractTableModel( theParent ), + myColumnCount( 4 ) { } @@ -83,7 +85,7 @@ QVariant HYDROGUI_PriorityTableModel::data( const QModelIndex &theIndex, int the if ( aColumn == 0 || aColumn == 2 ) { QStringList aNames; HYDROData_CustomRule aRule = myRules.at( aRow ); - Handle(HYDROData_Object) aUsedObject = aColumn == 0 ? aRule.Object2 : aRule.Object1; + Handle(HYDROData_Entity) aUsedObject = aColumn == 0 ? aRule.Object2 : aRule.Object1; if ( !aUsedObject.IsNull() ) { aNames = getAvailablePairs( aUsedObject ); } @@ -122,9 +124,9 @@ bool HYDROGUI_PriorityTableModel::setData( const QModelIndex & theIndex, const Q int aColumn = theIndex.column(); if ( aColumn == 0 || aColumn == 2 ) { - Handle(HYDROData_Object) anObject; + Handle(HYDROData_Entity) anObject; QString anObjName = theValue.toString(); - foreach ( const Handle(HYDROData_Object) anObj, myObjects ) { + foreach ( const Handle(HYDROData_Entity) anObj, myObjects ) { if ( anObj->GetName() == anObjName ) { anObject = anObj; break; @@ -167,7 +169,7 @@ int HYDROGUI_PriorityTableModel::rowCount( const QModelIndex &theParent ) const */ int HYDROGUI_PriorityTableModel::columnCount( const QModelIndex &theParent ) const { - return 4; + return myColumnCount; } /** @@ -215,7 +217,10 @@ QVariant HYDROGUI_PriorityTableModel::headerData( int theSection, aData = tr( "OBJECT2" ); break; case 3: - aData = tr( "BATHYMETRY" ); + { + if ( getObjectsKind() != KIND_LAND_COVER ) + aData = tr( "BATHYMETRY" ); + } break; }; } else if ( theOrientation == Qt::Vertical ) { @@ -229,7 +234,7 @@ QVariant HYDROGUI_PriorityTableModel::headerData( int theSection, Set objects which could be used for rules definition. @param theObjects the ordered list of objects */ -void HYDROGUI_PriorityTableModel::setObjects( const QList& theObjects ) +void HYDROGUI_PriorityTableModel::setObjects( const QList& theObjects ) { myObjects = theObjects; @@ -274,7 +279,7 @@ bool HYDROGUI_PriorityTableModel::createNewRule() // Try to find: // 1. the new pair of objects // 2. the priority type corresponding to the objects order - Handle(HYDROData_Object) anObject1, anObject2; + Handle(HYDROData_Entity) anObject1, anObject2; HYDROData_PriorityType aPriorityType = GREATER; int aNbObjects = myObjects.count(); @@ -372,7 +377,7 @@ bool HYDROGUI_PriorityTableModel::removeAll() @param theObject the object @return the list of object names */ -QStringList HYDROGUI_PriorityTableModel::getAvailablePairs( const Handle(HYDROData_Object)& theObject ) const +QStringList HYDROGUI_PriorityTableModel::getAvailablePairs( const Handle(HYDROData_Entity)& theObject ) const { QStringList aNames; @@ -446,8 +451,8 @@ QString HYDROGUI_PriorityTableModel::mergeTypeToString( const int theMergeType ) Check if the given pair of objects is already used. @return true if the pair is used */ -bool HYDROGUI_PriorityTableModel::isUsed( const Handle(HYDROData_Object)& theObj1, - const Handle(HYDROData_Object)& theObj2 ) const +bool HYDROGUI_PriorityTableModel::isUsed( const Handle(HYDROData_Entity)& theObj1, + const Handle(HYDROData_Entity)& theObj2 ) const { bool isUsed = false; @@ -472,11 +477,33 @@ QStringList HYDROGUI_PriorityTableModel::getAvailableObjectNames() const { QStringList aNames; - foreach ( const Handle(HYDROData_Object) anObj, myObjects ) { + foreach ( const Handle(HYDROData_Entity) anObj, myObjects ) { if ( !anObj.IsNull() ) { aNames << anObj->GetName(); } } return aNames; -} \ No newline at end of file +} + +/** + Set number of columns in the table. + @param theColumnCount the number of columns + */ +void HYDROGUI_PriorityTableModel::setColumnCount( int theColumnCount ) +{ + myColumnCount = theColumnCount; +} + +/** + Get type of objects for which rules are defined assuming, + that all objects in the list have the same type. + @return the type of objects + */ +const ObjectKind HYDROGUI_PriorityTableModel::getObjectsKind() const +{ + if ( myObjects.isEmpty() ) + return KIND_UNKNOWN; + + return myObjects.at( 0 )->GetKind(); +} diff --git a/src/HYDROGUI/HYDROGUI_PriorityTableModel.h b/src/HYDROGUI/HYDROGUI_PriorityTableModel.h index 28b058db..91338437 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityTableModel.h +++ b/src/HYDROGUI/HYDROGUI_PriorityTableModel.h @@ -58,19 +58,21 @@ public: bool removeRows( const QList theRows ); bool removeAll(); - void setObjects( const QList& theObjects ); + void setObjects( const QList& theObjects ); void setRules( const HYDROData_ListOfRules& theObjects ); HYDROData_ListOfRules getRules() const; bool createNewRule(); bool canCreateNewRule() const; + + void setColumnCount( int theColumnCount ); protected: - bool isUsed( const Handle(HYDROData_Object)& theObj1, - const Handle(HYDROData_Object)& theObj2 ) const; + bool isUsed( const Handle(HYDROData_Entity)& theObj1, + const Handle(HYDROData_Entity)& theObj2 ) const; - QStringList getAvailablePairs( const Handle(HYDROData_Object)& theObject ) const; + QStringList getAvailablePairs( const Handle(HYDROData_Entity)& theObject ) const; QStringList getAvailableObjectNames() const; QString priorityToString( const int thePriority ) const; @@ -80,12 +82,16 @@ signals: void showError( const QString& theMsg ); private: + const ObjectKind getObjectsKind() const; + friend class test_HYDROGUI_PriorityTableModel; HYDROGUI_Module* myModule; HYDROData_ListOfRules myRules; - QList myObjects; + QList myObjects; + + int myColumnCount; }; #endif \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx index f4c9fb7e..7175941c 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx @@ -246,7 +246,7 @@ void HYDROGUI_PriorityWidget::onClearRules() Set objects which could be used for rules definition. @param theObjects the ordered list of objects */ -void HYDROGUI_PriorityWidget::setObjects( const QList& theObjects ) +void HYDROGUI_PriorityWidget::setObjects( const QList& theObjects ) { HYDROGUI_PriorityTableModel* aModel = dynamic_cast( myTable->model() ); @@ -287,6 +287,15 @@ void HYDROGUI_PriorityWidget::setRules( const HYDROData_ListOfRules& theRules ) } } +/** + Get table view. + @return the table view + */ +QTableView* HYDROGUI_PriorityWidget::getTable() const +{ + return myTable; +} + /** Slot called on table selection change. */ diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.h b/src/HYDROGUI/HYDROGUI_PriorityWidget.h index 7d5828f7..bbc6c9ed 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityWidget.h +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.h @@ -21,7 +21,7 @@ #include -#include +#include #include #include @@ -47,11 +47,13 @@ public: HYDROGUI_PriorityWidget( QWidget* theParent ); virtual ~HYDROGUI_PriorityWidget(); - void setObjects( const QList& theObjects ); + void setObjects( const QList& theObjects ); HYDROData_ListOfRules getRules() const; void setRules( const HYDROData_ListOfRules& theRules ); + QTableView* getTable() const; + protected: void updateControls(); diff --git a/src/HYDROPy/HYDROData_CalculationCase.sip b/src/HYDROPy/HYDROData_CalculationCase.sip index 1e9ae573..7a2eeeaf 100644 --- a/src/HYDROPy/HYDROData_CalculationCase.sip +++ b/src/HYDROPy/HYDROData_CalculationCase.sip @@ -62,6 +62,25 @@ public: AUTOMATIC, }; +public: + + enum DataTag + { + DataTag_First = 100, ///< first tag, to reserve + DataTag_GeometryObject, ///< reference geometry objects + DataTag_ChildRegion, ///< child regions + DataTag_Region, ///< reference regions + DataTag_Polyline, ///< reference boundary polyline + DataTag_GeometryGroup, ///< reference geometry groups + DataTag_SplittedGroups, ///< reference splitted groups + DataTag_CustomRules, ///< custom rules + DataTag_AssignmentMode, ///< assignment mode + DataTag_StricklerTable, ///< reference Strickler table + DataTag_LandCover, ///< reference land covers + DataTag_CustomLandCoverRules, ///< custom rules for land covers priority + DataTag_AssignmentLandCoverMode ///< assignment mode of land covers priority + }; + public: /** * Add new one reference geometry object for calculation case. @@ -484,22 +503,23 @@ public: %End - void ClearRules(); + void ClearRules( HYDROData_CalculationCase::DataTag theDataTag ); - void AddRule( HYDROData_Object theObject1, + void AddRule( HYDROData_Entity theObject1, HYDROData_PriorityType thePriority, - HYDROData_Object theObject2, - HYDROData_Zone::MergeAltitudesType theMergeType ) - [void ( const Handle_HYDROData_Object&, HYDROData_PriorityType, const Handle_HYDROData_Object&, HYDROData_Zone::MergeAltitudesType )]; + HYDROData_Entity theObject2, + HYDROData_Zone::MergeAltitudesType theMergeType, + HYDROData_CalculationCase::DataTag theDataTag ) + [void ( const Handle_HYDROData_Entity&, HYDROData_PriorityType, const Handle_HYDROData_Entity&, HYDROData_Zone::MergeAltitudesType, HYDROData_CalculationCase::DataTag )]; %MethodCode - Handle(HYDROData_Object) anObject1 = - Handle(HYDROData_Object)::DownCast( createHandle( a0 ) ); - Handle(HYDROData_Object) anObject2 = - Handle(HYDROData_Object)::DownCast( createHandle( a2 ) ); + Handle(HYDROData_Entity) anObject1 = + Handle(HYDROData_Entity)::DownCast( createHandle( a0 ) ); + Handle(HYDROData_Entity) anObject2 = + Handle(HYDROData_Entity)::DownCast( createHandle( a2 ) ); Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_CalculationCase::AddRule( anObject1, a1, anObject2, a3 ) : - sipCpp->AddRule( anObject1, a1, anObject2, a3 ); + sipSelfWasArg ? sipCpp->HYDROData_CalculationCase::AddRule( anObject1, a1, anObject2, a3, a4 ) : + sipCpp->AddRule( anObject1, a1, anObject2, a3, a4 ); Py_END_ALLOW_THREADS %End