X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ImportLandCoverMapOp.cxx;h=deba3d6c38232dba9b102e18ce3f624ece2b3890;hb=05d82ada59110252be57aaa774095a18ebdca455;hp=6274879f8cbb4d2dfb39f67d841399f43633195e;hpb=acd7a6036bedb1360688f10a57f52a3daca3d84c;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx index 6274879f..deba3d6c 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx @@ -25,7 +25,7 @@ #include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_UpdateFlags.h" -#include "HYDROGUI_Tool.h" +#include "HYDROGUI_Tool2.h" #include "HYDROGUI_ImportLandCoverMapDlg.h" #include "HYDROGUI_Shape.h" #include @@ -64,34 +64,29 @@ #define MAX_LCM_NAME_INDEX 1000 -//TODO add definitions into TS file HYDROGUI_ImportLandCoverMapOp::HYDROGUI_ImportLandCoverMapOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) { - setName( tr( "IMPORT_LANDCOVERMAP" ) ); + setName( tr( "IMPORT_LANDCOVER_MAP" ) ); } HYDROGUI_ImportLandCoverMapOp::~HYDROGUI_ImportLandCoverMapOp() { erasePreview(); myImporter.Free(); - myAttrV.clear(); + myAttrValue.clear(); } void HYDROGUI_ImportLandCoverMapOp::startOperation() { HYDROGUI_Operation::startOperation(); - if ( !getPreviewManager() ) { - setPreviewManager( ::qobject_cast( - module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); - } + if ( !getPreviewManager() ) + setPreviewManager( ::qobject_cast( module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); - HYDROGUI_ImportLandCoverMapDlg* aPanel = - ::qobject_cast( inputPanel() ); - if ( !aPanel ) { + HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) return; - } aPanel->reset(); } @@ -118,108 +113,102 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected() return; } - QString anExt = myFileName.split('.', QString::SkipEmptyParts).back(); - - if (anExt == "shp") - { - startDocOperation(); - QApplication::setOverrideCursor(Qt::WaitCursor); - - QStringList aPolygonsList; - myPolygonFaces.Clear(); - myImporter.Free(); + startDocOperation(); + QApplication::setOverrideCursor(Qt::WaitCursor); + + QStringList aPolygonsList; + myPolygonFaces.Clear(); + myImporter.Free(); - SalomeApp_Study* aStudy = dynamic_cast( module()->getApp()->activeStudy() ); - if ( !aStudy ) - return; + SalomeApp_Study* aStudy = dynamic_cast( module()->getApp()->activeStudy() ); + if ( !aStudy ) + return; - erasePreview(); + erasePreview(); - Handle(AIS_InteractiveContext) aCtx = NULL; - int aShapeTypeOfFile = -1; + Handle(AIS_InteractiveContext) aCtx = NULL; + int aShapeTypeOfFile = -1; - //Import polygons from SHP file as faces - //This faces should be added to the new LCM object + //Import polygons from SHP file as faces + //This faces should be added to the new LCM object - int aStat = myImporter.ImportPolygons(myFileName, aPolygonsList, myPolygonFaces, aShapeTypeOfFile); - if (aStat == 1) - { - aPanel->setPolygonNames(aPolygonsList); + int aStat = myImporter.ImportPolygons(doc(), myFileName, aPolygonsList, myPolygonFaces, aShapeTypeOfFile); + if (aStat == 1) + { + aPanel->setPolygonNames(aPolygonsList); - LightApp_Application* anApp = module()->getApp(); - if ( !getPreviewManager() ) - setPreviewManager( ::qobject_cast( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); - OCCViewer_ViewManager* aViewManager = getPreviewManager(); + LightApp_Application* anApp = module()->getApp(); + if ( !getPreviewManager() ) + setPreviewManager( ::qobject_cast( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); + OCCViewer_ViewManager* aViewManager = getPreviewManager(); - if ( aViewManager ) + if ( aViewManager ) + { + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) { - if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) - { - aCtx = aViewer->getAISContext(); - connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) ); - } + aCtx = aViewer->getAISContext(); + connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) ); } + } - for ( int i = 1; i <= myPolygonFaces.Length(); i++ ) + for ( int i = 1; i <= myPolygonFaces.Length(); i++ ) + { + TopoDS_Face aFace = TopoDS::Face(myPolygonFaces.Value( i )); + if ( aViewManager && !aCtx.IsNull() ) { - TopoDS_Face aFace = TopoDS::Face(myPolygonFaces.Value( i )); - if ( aViewManager && !aCtx.IsNull() ) - { - HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); - //Green color for now.. - aShape->setFillingColor(QColor(0,255,0), false, false); - aShape->setBorderColor(QColor(0,255,0), false, false); - if( !aFace.IsNull() ) - aShape->setShape( aFace); - - myPolygonName2PrsShape.insert( "polygon_" + QString::number(i), aShape); - } + HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); + //Preview color is grey + aShape->setFillingColor(QColor(50,50,50), false, false); + aShape->setBorderColor(QColor(50,50,50), false, false); + if( !aFace.IsNull() ) + aShape->setShape( aFace); + + myPolygonName2PrsShape.insert( tr( "DEF_POLYGON_NAME" ) + "_" + QString::number(i), aShape); } + } - if ( !aCtx.IsNull() ) - { - UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD ); - aCtx->UpdateCurrentViewer(); - } - // - QApplication::restoreOverrideCursor(); - aPanel->setFirstPageState(true); - // - //Try to load DBF-database... - QString theDBFFileName; - theDBFFileName = myFileName.simplified().replace( ".shp", ".dbf", Qt::CaseInsensitive); - bool DBF_Stat = myImporter.DBF_OpenDBF(theDBFFileName); - // TODO: - // add MSG BOX if stat is bad - if (DBF_Stat) - { - myFieldList = myImporter.DBF_GetFieldList(); - aPanel->setAttributeNames(myFieldList); - } - aPanel->setDbfState(DBF_Stat); + if ( !aCtx.IsNull() ) + { + UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD ); + aCtx->UpdateCurrentViewer(); } - else + // + QApplication::restoreOverrideCursor(); + aPanel->setFirstPageState(true); + // + //Try to load DBF-database... + QString aDBFFileName; + aDBFFileName = myFileName.simplified().replace( myFileName.simplified().size() - 4, 4, ".dbf"); + bool DBF_Stat = myImporter.DBF_OpenDBF(aDBFFileName); + // TODO: + // add MSG BOX if stat is bad + if (DBF_Stat) { - erasePreview(); - aPanel->setPolygonNames(QStringList()); - aPanel->setObjectName(""); - QApplication::restoreOverrideCursor(); - QString aMess = "Cannot import land cover;\n"; - if (aStat == -1) - aMess += "Cannot open SHP file"; - else if (aStat == -2) - aMess += "Cannot open SHX file"; - else - aMess += "The shape type of file is " + myImporter.GetShapeTypeName(aShapeTypeOfFile); - SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), aMess); - commitDocOperation(); - myImporter.Free(); - //abort(); - aPanel->setFirstPageState(false); + myFieldList = myImporter.DBF_GetFieldList(); + aPanel->setAttributeNames(myFieldList); } - + aPanel->setDbfState(DBF_Stat); } - + else + { + erasePreview(); + aPanel->setPolygonNames(QStringList()); + aPanel->setObjectName(""); + QApplication::restoreOverrideCursor(); + QString aMess = tr( "CANNT_IMPORT_LCM" ) + "\n"; + if (aStat == -1) + aMess += tr( "CANNT_OPEN_SHP" ); + else if (aStat == -2) + aMess += tr( "CANNT_OPEN_SHX" ); + else + aMess += tr ("SHP_TYPEFORMAT_MESS") + myImporter.GetShapeTypeName(aShapeTypeOfFile); + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER_MAP" ), aMess); + commitDocOperation(); + myImporter.Free(); + //abort(); + aPanel->setFirstPageState(false); + } + } HYDROGUI_InputPanel* HYDROGUI_ImportLandCoverMapOp::createInputPanel() const @@ -247,10 +236,10 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, QStringList aAttrV_T; QStringList aSTL; - aPanel->GetAttribute2StricklerCorr(aAttrV_T, aSTL); + aPanel->getValAttr2StricklerTypeCorr(aAttrV_T, aSTL); QVector aSelIndices = aPanel->getSelectedPolygonIndices(); - foreach ( int Ind, aSelIndices ) //check i-base. + foreach ( int Ind, aSelIndices ) { TopoDS_Shape aShape = myPolygonFaces(Ind + 1); if ( aShape.IsNull() ) @@ -258,9 +247,9 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, QString aST = ""; if (aPanel->getAttrCheckBoxState()) { - HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[Ind]; - int StricklerTypesInd = aAttrV_T.indexOf(QString(aV.myStrVal)); - aST = aSTL.at(StricklerTypesInd); + HYDROData_ShapeFile::DBF_AttrValue aDataVal = myAttrValue[Ind]; + int aStricklerTypesInd = aAttrV_T.indexOf(QString(aDataVal.myStrVal)); + aST = aSTL.at(aStricklerTypesInd); } // else => ST is empty aMapFace2ST.Add( TopoDS::Face( aShape ), aST ); @@ -269,28 +258,28 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, // myLCM->StoreLandCovers(aMapFace2ST); - QString ObjName; + QString anObjName; if ( !aPanel->getFileName().isEmpty() ) - ObjName = aPanel->getObjectName(); + anObjName = aPanel->getObjectName(); - Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() ); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() ); //check if name of LCM is already exists QSet aNameList; if (aDoc) { - HYDROData_Iterator It( aDoc, KIND_LAND_COVER_MAP ); - for( ; It.More(); It.Next() ) - aNameList << It.Current()->GetName(); + HYDROData_Iterator anIt( aDoc, KIND_LAND_COVER_MAP ); + for( ; anIt.More(); anIt.Next() ) + aNameList << anIt.Current()->GetName(); } - QString NewName = ObjName; - for ( int i = 1; i < MAX_LCM_NAME_INDEX && aNameList.contains(NewName); i++) - NewName = ObjName + "_" + QString::number(i); + QString aNewName = anObjName; + for ( int i = 1; i < MAX_LCM_NAME_INDEX && aNameList.contains(aNewName); i++) + aNewName = anObjName + "_" + QString::number(i); if( !myLCM.IsNull() ) { - myLCM->SetName( NewName ); + myLCM->SetName( aNewName ); myLCM->SetColor( Qt::gray ); myLCM->Show(); module()->setIsToUpdate( myLCM ); @@ -300,7 +289,7 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, erasePreview(); myImporter.Free(); - myAttrV.clear(); + myAttrValue.clear(); return true; } @@ -317,16 +306,26 @@ void HYDROGUI_ImportLandCoverMapOp::onSelectionChanged( const QStringList& theSe } if ( !aCtx.IsNull() ) { - foreach ( QString aName, myPolygonName2PrsShape.keys() ) { + bool bSelChanged = false; + foreach ( QString aName, myPolygonName2PrsShape.keys() ) + { Handle(AIS_InteractiveObject) anObject = myPolygonName2PrsShape.value(aName)->getAISObject(); bool isSelected = theSelectedNames.contains( aName ); - if ( ( isSelected && !aCtx->IsSelected( anObject) ) || - ( !isSelected && aCtx->IsSelected( anObject) ) ) + if ( ( isSelected && !aCtx->IsSelected( anObject) ) || ( !isSelected && aCtx->IsSelected( anObject) ) ) + { aCtx->AddOrRemoveSelected( anObject, Standard_False ); + bSelChanged = true; + } } - aCtx->UpdateCurrentViewer(); + + HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + if (bSelChanged && aPanel->getViewerState()) + aCtx->UpdateCurrentViewer(); } } @@ -334,17 +333,20 @@ void HYDROGUI_ImportLandCoverMapOp::onSelectionChanged( const QStringList& theSe void HYDROGUI_ImportLandCoverMapOp::onViewerSelectionChanged() { HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel ) { + if ( !aPanel ) + return; + + int aCurIndex = -1; + aCurIndex = aPanel->getCurrentWizardIndex(); + + if (aCurIndex != 0) return; - } OCCViewer_ViewManager* aViewManager = getPreviewManager(); Handle(AIS_InteractiveContext) aCtx = NULL; - if ( aViewManager ) { - if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) { + if ( aViewManager ) + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) aCtx = aViewer->getAISContext(); - } - } if ( !aCtx.IsNull() ) { @@ -354,16 +356,17 @@ void HYDROGUI_ImportLandCoverMapOp::onViewerSelectionChanged() if ( isSelected ) aSelectedNames << aName; } + aPanel->setViewerState(false); aPanel->setSelectedPolygonNames( aSelectedNames ); + aPanel->setViewerState(true); } } void HYDROGUI_ImportLandCoverMapOp::erasePreview() { - foreach ( HYDROGUI_Shape* aShape, myPolygonName2PrsShape ) { + foreach ( HYDROGUI_Shape* aShape, myPolygonName2PrsShape ) delete aShape; - } myPolygonName2PrsShape.clear(); } @@ -388,24 +391,24 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex ) if (theIndex == 2) { - //std::vector myAttrV; - int Ind = myFieldList.indexOf(aPanel->getSelectedFieldName()); - if (Ind == -1) + //std::vector myAttrValue; + int anIndOfSelField = myFieldList.indexOf(aPanel->getSelectedFieldName()); + if (anIndOfSelField == -1) return; //aPanel->setSecondPageState(true); - myAttrV.clear(); - myImporter.DBF_GetAttributeList(Ind, myAttrV ); + myAttrValue.clear(); + myImporter.DBF_GetAttributeList(anIndOfSelField, myAttrValue ); mySetOfAttrValues.clear(); - for (size_t i = 0; i < myAttrV.size(); i++) + for (size_t i = 0; i < myAttrValue.size(); i++) { - HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[i]; - mySetOfAttrValues << QString(aV.myStrVal); //take myStrVal by now.. + HYDROData_ShapeFile::DBF_AttrValue aV = myAttrValue[i]; + mySetOfAttrValues << QString(aV.myStrVal); //take myStrVal for now.. } //Collect all strickler_types QSet aSTSet; - Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() ); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() ); Handle(HYDROData_StricklerTable) DefStricklerTableObj; if ( aDoc ) { @@ -423,38 +426,35 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex ) } } } - QList SetOfAttrValuesList = mySetOfAttrValues.toList(); + + QList aSetOfAttrValuesList = mySetOfAttrValues.toList(); QList aSTSetList = aSTSet.toList(); - QVector STColors; - STColors.reserve(aSTSetList.size()); + QVector aSTColors; + aSTColors.reserve(aSTSetList.size()); foreach (QString str, aSTSetList) { QColor col = aDoc->GetAssociatedColor(str, NULL); - STColors.append (col); + aSTColors.append (col); } //add an empty Strickler type aSTSetList.prepend(""); - STColors.prepend(QColor(Qt::gray)); + aSTColors.prepend(QColor(Qt::gray)); - QVector aCurCBIndices(SetOfAttrValuesList.size()); - if (DefStricklerTableObj->GetAttrName() == aPanel->getSelectedFieldName()) - { - for (int i = 0; i < SetOfAttrValuesList.size(); i++) + QVector aCurCBIndices(aSetOfAttrValuesList.size()); + if (DefStricklerTableObj->GetAttrName().trimmed() == aPanel->getSelectedFieldName().trimmed()) + for (int i = 0; i < aSetOfAttrValuesList.size(); i++) { - QString ST = DefStricklerTableObj->GetType(SetOfAttrValuesList[i]); - int IndofSt = aSTSetList.indexOf(ST); - aCurCBIndices[i] = IndofSt; + QString aST = DefStricklerTableObj->GetType(aSetOfAttrValuesList[i]); + int anIndOfSt = aSTSetList.indexOf(aST); + aCurCBIndices[i] = anIndOfSt; } - } else - { //TODO add warning ??? - for (int i = 0; i < SetOfAttrValuesList.size(); i++) + for (int i = 0; i < aSetOfAttrValuesList.size(); i++) aCurCBIndices[i] = 0; - } - aPanel->FillCorrTable(SetOfAttrValuesList, aSTSetList, aCurCBIndices, STColors); + aPanel->FillCorrespondenceTable(aSetOfAttrValuesList, aSTSetList, aCurCBIndices, aSTColors); } } @@ -462,6 +462,13 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex ) void HYDROGUI_ImportLandCoverMapOp::onApply() { + HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + if (!aPanel->CheckFirstPageFilling()) + return; + QApplication::setOverrideCursor( Qt::WaitCursor ); int anUpdateFlags = 0; QString anErrorMsg; @@ -474,7 +481,7 @@ void HYDROGUI_ImportLandCoverMapOp::onApply() } catch (...) { - SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "LCM_IMPORT_ERROR" ), "Cant import choosed polygons"); + SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "LCM_IMPORT_ERROR" ), tr ("CANNT_IMPORT_POLYGONS_FROM_SHP")); aResult = false; }