X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_LandCoverOp.cxx;h=5240b42d86bdcbdbcd2879078db995073d854b55;hb=d6e19029f8b41f295db878e9aecf451c2edda4af;hp=d8b4fdc36811221377d778809512b54583fd8076;hpb=e0ed73f9fe23d646ae3b99ee4446098f10f3cb55;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx index d8b4fdc3..5240b42d 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx @@ -35,6 +35,9 @@ #include +#include +#include + #include #include #include @@ -69,7 +72,7 @@ void HYDROGUI_LandCoverOp::startOperation() QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_LAND_COVER_NAME" ) ); - QStringList aSelectedPolylines; + HYDROGUI_ListModel::Object2VisibleList aSelectedPolylines; QString aSelectedStricklerType; if ( myIsEdit ) @@ -80,28 +83,19 @@ void HYDROGUI_LandCoverOp::startOperation() { anObjectName = myEditedObject->GetName(); - // TODO: Temporary commented until getPolylinesCount, GetPolyline and GetStricklerType data model methods will be implemented - /* - int nNoPolylines = myEditedObject->getPolylinesCount(); - for (int i=0; iGetPolyline(i); - if ( !aRefPolyline.IsNull() ) - aSelectedPolylines.append( aRefPolyline->GetName() ); + HYDROData_SequenceOfObjects aRefPolylines = myEditedObject->GetPolylines(); + for ( int i = aRefPolylines.Lower(); i <= aRefPolylines.Upper(); i++ ) { + Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) ); + if ( !aPolyline.IsNull() ) { + aSelectedPolylines.append( HYDROGUI_ListModel::Object2Visible( aPolyline, true ) ); + } } - - aSelectedStricklerType = myEditedObject->GetStricklerType(); - */ - - // The code below is a sample of data filling Land cover object - aSelectedPolylines.append( "Lake_1" ); - aSelectedPolylines.append( "Polyline_1" ); - aSelectedStricklerType = "Canaux naturels"; } + + aSelectedStricklerType = myEditedObject->GetStricklerType(); } aPanel->setObjectName( anObjectName ); - aPanel->setPolylineNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) ); // Construct a list of unique names of all Strickler types defined within the data model QStringList aStricklerTypes; HYDROData_Iterator anIterator( doc(), KIND_STRICKLER_TABLE ); @@ -111,17 +105,11 @@ void HYDROGUI_LandCoverOp::startOperation() Handle(HYDROData_StricklerTable)::DownCast( anIterator.Current() ); if ( !aStricklerTableObj.IsNull() ) { - // TODO: implement GetTypes method in data model - //QStringList aTypes = aStricklerTableObj->GetTypes(); - // The code below is a sample of data filling list of Strickler types - QStringList aTypes; - aTypes.append("Zones de champs, prairies, sans cultures"); - aTypes.append("Canaux naturels"); - aTypes.append("Zones à faible urbanization (bourg)"); - QStringList::const_iterator anIt = aTypes.begin(), aLast = aTypes.end(); - for( ; anIt!=aLast; anIt++ ) + // Get Strickler table data from the data model + TColStd_SequenceOfExtendedString aTypes = aStricklerTableObj->GetTypes(); + for ( int i = 1; i <= aTypes.Length(); i++ ) { - QString aType = *anIt; + QString aType = HYDROGUI_Tool::ToQString( aTypes.Value( i ) ); if ( !aType.isEmpty() && !aStricklerTypes.contains( aType )) aStricklerTypes.append( aType ); } @@ -132,7 +120,7 @@ void HYDROGUI_LandCoverOp::startOperation() aPanel->blockSignals( false ); - aPanel->setSelectedPolylineNames( aSelectedPolylines ); + aPanel->includePolylines( aSelectedPolylines ); aPanel->setSelectedAdditionalParamName( aSelectedStricklerType ); } @@ -155,6 +143,8 @@ HYDROGUI_InputPanel* HYDROGUI_LandCoverOp::createInputPanel() const HYDROGUI_LandCoverDlg* aPanel = new HYDROGUI_LandCoverDlg( module(), getName() ); connect( aPanel, SIGNAL( CreatePreview( const QStringList& ) ), this, SLOT( onCreatePreview( const QStringList& ) ) ); + connect( aPanel, SIGNAL( addPolylines() ), SLOT( onAddPolylines() ) ); + connect( aPanel, SIGNAL( removePolylines() ), SLOT( onRemovePolylines() ) ); return aPanel; } @@ -184,17 +174,17 @@ bool HYDROGUI_LandCoverOp::processApply( int& theUpdateFlags, } } - QList aZonePolylines; + HYDROData_SequenceOfObjects aZonePolylines; QString aStricklerType; - QStringList aSelectedPolylineNames = aPanel->getSelectedPolylineNames(); + QStringList aSelectedPolylineNames = aPanel->getPolylineNames(); QStringList::const_iterator anIt = aSelectedPolylineNames.begin(), aLast = aSelectedPolylineNames.end(); for( ; anIt!=aLast; anIt++ ) { QString aPolylineName = *anIt; if ( !aPolylineName.isEmpty() ) { - aZonePolylines.append( Handle(HYDROData_PolylineXY)::DownCast( + aZonePolylines.Append( Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) ) ); } } @@ -215,19 +205,14 @@ bool HYDROGUI_LandCoverOp::processApply( int& theUpdateFlags, aZoneObj->SetName( anObjectName ); - // TODO: Temporary commented until SetFillingColor, DefaultFillingColor, - // SetBorderColor and DefaultBorderColor data model methods will be implemented - /* if ( !myIsEdit ) { aZoneObj->SetFillingColor( HYDROData_LandCover::DefaultFillingColor() ); aZoneObj->SetBorderColor( HYDROData_LandCover::DefaultBorderColor() ); } - */ - // TODO: Temporary commented until SetPolylines and SetStricklerType data model methods will be implemented - //aZoneObj->SetPolylines( aZonePolylines ); - //aZoneObj->SetStricklerType( aSelectedStricklerType ); + aZoneObj->SetPolylines( aZonePolylines ); + aZoneObj->SetStricklerType( aSelectedStricklerType ); aZoneObj->Update(); closePreview(); @@ -288,9 +273,6 @@ void HYDROGUI_LandCoverOp::onCreatePreview( const QStringList& thePolylineNames if ( aViewManager && myPreviewPrs ) { - // TODO: Temporary commented until GetFillingColor, DefaultFillingColor, - // GetBorderColor and DefaultBorderColor data model methods will be implemented - /* QColor aFillingColor = HYDROData_LandCover::DefaultFillingColor(); QColor aBorderColor = HYDROData_LandCover::DefaultBorderColor(); if ( !myEditedObject.IsNull() ) { @@ -300,7 +282,6 @@ void HYDROGUI_LandCoverOp::onCreatePreview( const QStringList& thePolylineNames myPreviewPrs->setFillingColor( aFillingColor, false, false ); myPreviewPrs->setBorderColor( aBorderColor, false, false ); - */ TopoDS_Face aFace; if( !aZoneShape.IsNull() ) @@ -311,6 +292,57 @@ void HYDROGUI_LandCoverOp::onCreatePreview( const QStringList& thePolylineNames QApplication::restoreOverrideCursor(); } +void HYDROGUI_LandCoverOp::onAddPolylines() +{ + HYDROGUI_LandCoverDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + // Add polylines selected in the module browser + Handle(HYDROData_PolylineXY) aPolyXY; + HYDROGUI_ListModel::Object2VisibleList aSelectedPolylines; + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() ); + + if ( aSeq.IsEmpty() || !confirmPolylinesChange() ) + return; + + for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) + { + aPolyXY = Handle(HYDROData_PolylineXY)::DownCast( aSeq.Value( anIndex )); + if (!aPolyXY.IsNull()) + aSelectedPolylines.append( HYDROGUI_ListModel::Object2Visible( aPolyXY, true ) ); + } + + aPanel->includePolylines( aSelectedPolylines ); + // TODO: create preview of included polylines +} + +void HYDROGUI_LandCoverOp::onRemovePolylines() +{ + // Remove selected polylines from the calculation case + HYDROGUI_LandCoverDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + QStringList aSelectedList = aPanel->getSelectedPolylineNames(); + if ( aSelectedList.isEmpty() || !confirmPolylinesChange() ) + return; + + HYDROGUI_ListModel::Object2VisibleList aSelectedPolylines; + for (int i = 0; i < aSelectedList.length(); i++) + { + Handle(HYDROData_PolylineXY) anObject = Handle(HYDROData_PolylineXY)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) ); + if ( anObject.IsNull() ) + continue; + + aSelectedPolylines.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) ); + } + + module()->update( UF_OCCViewer ); + aPanel->excludePolylines( aSelectedPolylines ); +} + void HYDROGUI_LandCoverOp::closePreview() { if( myPreviewPrs ) @@ -319,3 +351,31 @@ void HYDROGUI_LandCoverOp::closePreview() myPreviewPrs = 0; } } + +bool HYDROGUI_LandCoverOp::confirmPolylinesChange() const +{ + if ( myEditedObject.IsNull() ) + return true; + + // Check if the land cover object is already modified or not + bool isConfirmed = myEditedObject->IsMustBeUpdated(); + if ( !isConfirmed ) + { + // If not modified check if the land cover has already defined polylines + HYDROData_SequenceOfObjects aSeq = myEditedObject->GetPolylines(); + if ( aSeq.Length() > 0 ) + { + // If there are already defined polylines then ask a user to confirm land cover recalculation + isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(), + tr( "POLYLINES_CHANGED" ), + tr( "CONFIRM_LAND_COVER_RECALCULATION" ), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No ) == QMessageBox::Yes ); + } + else + { + isConfirmed = true; // No polylines - nothing to recalculate + } + } + return isConfirmed; +}