X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_LandCoverOp.cxx;h=9cf2567e4ea5aa58380c420f8a81de0adfd1106b;hb=298c1759f9b1d4a7dc316742b7a13008eb4234e1;hp=75c4ce082a4225d2a7a445ddfc46c11c401244b1;hpb=0053e6ddd7cd8e0462b53851fa921cd4e17d42d1;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverOp.cxx index 75c4ce08..9cf2567e 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 ) @@ -84,7 +87,7 @@ void HYDROGUI_LandCoverOp::startOperation() 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( aPolyline->GetName() ); + aSelectedPolylines.append( HYDROGUI_ListModel::Object2Visible( aPolyline, true ) ); } } } @@ -93,7 +96,6 @@ void HYDROGUI_LandCoverOp::startOperation() } 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 ); @@ -118,7 +120,7 @@ void HYDROGUI_LandCoverOp::startOperation() aPanel->blockSignals( false ); - aPanel->setSelectedPolylineNames( aSelectedPolylines ); + aPanel->includePolylines( aSelectedPolylines ); aPanel->setSelectedAdditionalParamName( aSelectedStricklerType ); } @@ -141,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; } @@ -173,7 +177,7 @@ bool HYDROGUI_LandCoverOp::processApply( int& theUpdateFlags, 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++ ) { @@ -185,17 +189,25 @@ bool HYDROGUI_LandCoverOp::processApply( int& theUpdateFlags, } } + if ( aZonePolylines.IsEmpty() ) + { + theErrorMsg = tr( "POLYLINES_NOT_DEFINED" ); + return false; + } + QString aSelectedStricklerType = aPanel->getSelectedAdditionalParamName(); - // TODO: Generate TopoDS_Shape based on the set of polylines, implement generateTopShape data model method - /* - if ( HYDROData_LandCover::generateTopShape( aZonePolylines ).IsNull() ) + TCollection_AsciiString anError; + if ( HYDROData_LandCover::buildShape( aZonePolylines, anError ).IsNull() ) { - theErrorMsg = tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ); + if ( !anError.IsEmpty() ) { + theErrorMsg = HYDROGUI_Tool::ToQString( anError ); + } else { + theErrorMsg = tr( "LAND_COVER_OBJECT_CANNOT_BE_CREATED" ); + } return false; } - */ - + Handle(HYDROData_LandCover) aZoneObj = myIsEdit ? myEditedObject : Handle(HYDROData_LandCover)::DownCast( doc()->CreateObject( KIND_LAND_COVER ) ); @@ -235,7 +247,7 @@ void HYDROGUI_LandCoverOp::onCreatePreview( const QStringList& thePolylineNames QApplication::setOverrideCursor( Qt::WaitCursor ); - QList aZonePolylines; + HYDROData_SequenceOfObjects aZonePolylines; QStringList::const_iterator anIt = thePolylineNames.begin(), aLast = thePolylineNames.end(); for( ; anIt!=aLast; anIt++ ) { @@ -243,14 +255,11 @@ void HYDROGUI_LandCoverOp::onCreatePreview( const QStringList& thePolylineNames Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) ); if ( !aPolyline.IsNull() ) - aZonePolylines.append( aPolyline ); + aZonePolylines.Append( aPolyline ); } - - // TODO: Generate TopoDS_Shape based on the set of polylines, implement generateTopShape data model method - TopoDS_Shape aZoneShape;/* = HYDROData_LandCover::generateTopShape( aZonePolylines ); - if( aZoneShape.IsNull() ) - printErrorMessage( tr( "ZONE_OBJECT_CANNOT_BE_CREATED" ) ); - */ + + TCollection_AsciiString anError; + TopoDS_Shape aZoneShape = HYDROData_LandCover::buildShape( aZonePolylines, anError ); LightApp_Application* anApp = module()->getApp(); if ( !getPreviewManager() ) @@ -279,15 +288,72 @@ void HYDROGUI_LandCoverOp::onCreatePreview( const QStringList& thePolylineNames myPreviewPrs->setFillingColor( aFillingColor, false, false ); myPreviewPrs->setBorderColor( aBorderColor, false, false ); - TopoDS_Face aFace; if( !aZoneShape.IsNull() ) - aFace = TopoDS::Face( aZoneShape ); - myPreviewPrs->setFace( aFace, true, true, "" ); + myPreviewPrs->setShape( aZoneShape ); } 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 ) ); + } + + if ( aPanel->includePolylines( aSelectedPolylines ) ) + { + closePreview(); + onCreatePreview( aPanel->getPolylineNames() ); + } +} + +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 ); + + if ( aPanel->excludePolylines( aSelectedPolylines ) ) + { + closePreview(); + onCreatePreview( aPanel->getPolylineNames() ); + } +} + void HYDROGUI_LandCoverOp::closePreview() { if( myPreviewPrs ) @@ -296,3 +362,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; +}