From: isn Date: Mon, 29 Jun 2015 09:37:10 +0000 (+0300) Subject: Import/Export // API revision. p4 X-Git-Tag: v1.4.2~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=110bfa3fd77aaf18efd70651c134ba419006c15d;p=modules%2Fhydro.git Import/Export // API revision. p4 --- diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index c65c2c2b..fa4fe090 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -261,7 +261,7 @@ void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandl return; } -void HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType) +bool HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType) { int aShapeType; mySHPObjects.clear(); @@ -272,7 +272,10 @@ void HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType) { for (int i = 0; i < theHandle->nRecords; i++) mySHPObjects.push_back(SHPReadObject(theHandle, i)); + return true; } + else + return false; } void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F) @@ -328,7 +331,8 @@ bool HYDROData_ShapeFile::ImportLandCovers(const QString theFileName, QStringLis { Free(); myHSHP = SHPOpen( theFileName.toAscii().data(), "rb" ); - Parse(myHSHP, HYDROData_ShapeFile::ShapeType_Polygon); + if (!Parse(myHSHP, HYDROData_ShapeFile::ShapeType_Polygon)) + return false; for (size_t i = 0; i < mySHPObjects.size(); i++) thePolygonsList.append("polygon_" + QString::number(i + 1)); @@ -493,7 +497,8 @@ bool HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument QFileInfo aFileInfo(theFileName); QString aBaseFileName = aFileInfo.baseName(); - Parse(aHSHP, HYDROData_ShapeFile::ShapeType_Polyline); + if (!Parse(aHSHP, HYDROData_ShapeFile::ShapeType_Polyline)) + return false; bool aStat = false; if (aHSHP->nShapeType == 3 || aHSHP->nShapeType == 23) { diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index c0c823c2..30b1167a 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -64,7 +64,7 @@ public: int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly ); int WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC ); //Import - void Parse(SHPHandle theHandle, ShapeType theType); + bool Parse(SHPHandle theHandle, ShapeType theType); //Import Landcover void ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F); HYDRODATA_EXPORT bool ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces); diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverOp.cxx index d492a668..ef7756b1 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverOp.cxx @@ -215,67 +215,69 @@ void HYDROGUI_ImportLandCoverOp::onFileSelected() TopTools_SequenceOfShape aFaces; HYDROData_ShapeFile anImporter; - if (!anImporter.ImportLandCovers(aFileName, aPolygonsList, aFaces)) + if (anImporter.ImportLandCovers(aFileName, aPolygonsList, aFaces)) { - SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), "Cannot import land cover;\nThe shape type is not polygon" ); - abort(); - } + aPanel->setPolygonNames(aPolygonsList); - aPanel->setPolygonNames(aPolygonsList); - - 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; + Handle(AIS_InteractiveContext) aCtx = NULL; - 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 ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) + if ( aViewManager ) { - aCtx = aViewer->getAISContext(); - connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) ); + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) + { + aCtx = aViewer->getAISContext(); + connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) ); + } } - } - - - QApplication::restoreOverrideCursor(); - - Handle(HYDROData_LandCover) aLC = Handle(HYDROData_LandCover)::DownCast( doc()->CreateObject( KIND_LAND_COVER ) ); - for ( int i = 1; i <= aFaces.Length(); i++ ) - { - TopoDS_Face aFace = TopoDS::Face(aFaces.Value( i )); - aLC->setShape( aFace ); - - if ( aViewManager && !aCtx.IsNull() ) + Handle(HYDROData_LandCover) aLC = Handle(HYDROData_LandCover)::DownCast( doc()->CreateObject( KIND_LAND_COVER ) ); + for ( int i = 1; i <= aFaces.Length(); i++ ) { - HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); + TopoDS_Face aFace = TopoDS::Face(aFaces.Value( i )); + + aLC->setShape( aFace ); + + if ( aViewManager && !aCtx.IsNull() ) + { + HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); + + aShape->setFillingColor( HYDROData_LandCover::DefaultFillingColor(), false, false ); + aShape->setBorderColor( HYDROData_LandCover::DefaultBorderColor(), false, false ); + if( !aFace.IsNull() ) + aShape->setShape( aLC->GetShape() ); + myPolygonName2PrsShape.insert( "polygon_" + QString::number(i), aShape); + } + } + aLC->Remove(); - aShape->setFillingColor( HYDROData_LandCover::DefaultFillingColor(), false, false ); - aShape->setBorderColor( HYDROData_LandCover::DefaultBorderColor(), false, false ); - if( !aFace.IsNull() ) - aShape->setShape( aLC->GetShape() ); - myPolygonName2PrsShape.insert( "polygon_" + QString::number(i), aShape); + if ( !aCtx.IsNull() ) + { + UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD ); + aCtx->UpdateCurrentViewer(); } + + QApplication::restoreOverrideCursor(); + commitDocOperation(); } - aLC->Remove(); - - if ( !aCtx.IsNull() ) { - UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD ); - aCtx->UpdateCurrentViewer(); + else + { + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), "Cannot import land cover;\nThe shape type is not polygon" ); + + QApplication::restoreOverrideCursor(); + abort(); } - - commitDocOperation(); - anImporter.Free(); }