X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ImportLandCoverMapOp.cxx;h=deba3d6c38232dba9b102e18ce3f624ece2b3890;hb=05d82ada59110252be57aaa774095a18ebdca455;hp=3e77bd374e1adc2b21688298ea200698fa9efa6f;hpb=1e2e53d3b9cf6c62ed41e72a0685f7fbb115906c;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx index 3e77bd37..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 @@ -113,106 +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() ); - //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); - } + 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 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) - { - 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 = 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); + 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 @@ -266,7 +262,7 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, if ( !aPanel->getFileName().isEmpty() ) 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; @@ -310,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(); } } @@ -330,13 +336,17 @@ void HYDROGUI_ImportLandCoverMapOp::onViewerSelectionChanged() 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() ) { @@ -346,7 +356,9 @@ void HYDROGUI_ImportLandCoverMapOp::onViewerSelectionChanged() if ( isSelected ) aSelectedNames << aName; } + aPanel->setViewerState(false); aPanel->setSelectedPolygonNames( aSelectedNames ); + aPanel->setViewerState(true); } } @@ -396,7 +408,7 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex ) //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 ) { @@ -430,7 +442,7 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex ) aSTColors.prepend(QColor(Qt::gray)); QVector aCurCBIndices(aSetOfAttrValuesList.size()); - if (DefStricklerTableObj->GetAttrName() == aPanel->getSelectedFieldName()) + if (DefStricklerTableObj->GetAttrName().trimmed() == aPanel->getSelectedFieldName().trimmed()) for (int i = 0; i < aSetOfAttrValuesList.size(); i++) { QString aST = DefStricklerTableObj->GetType(aSetOfAttrValuesList[i]); @@ -450,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;