X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ImportPolylineOp.cxx;h=e7faee118be82bfaa64f382d43cdcefd0092be0a;hb=58bb6b7459bebeeb089c9ed486c4683a8bae7288;hp=1d02a454ce772bb972d0064c67b08a427a622b9d;hpb=761a81cad129b613ef3d132a43ba82a0cb9f5760;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx index 1d02a454..e7faee11 100644 --- a/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportPolylineOp.cxx @@ -1,8 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// Copyright (C) 2014-2015 EDF-R&D // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either @@ -25,12 +21,13 @@ #include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_UpdateFlags.h" -#include "HYDROGUI_Tool.h" +#include "HYDROGUI_Tool2.h" #include #include #include #include #include +#include #include @@ -41,7 +38,7 @@ #include #include #include -#include +#include HYDROGUI_ImportPolylineOp::HYDROGUI_ImportPolylineOp( HYDROGUI_Module* theModule ) @@ -61,7 +58,7 @@ void HYDROGUI_ImportPolylineOp::startOperation() myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true ); myFileDlg->setWindowTitle( getName() ); myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles ); - myFileDlg->setFilter( tr("POLYLINE_FILTER") ); + myFileDlg->setNameFilter( tr("POLYLINE_FILTER") ); connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) ); connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) ); @@ -77,221 +74,67 @@ void HYDROGUI_ImportPolylineOp::onApply() return; } - QString aFileName = myFileDlg->selectedFile(); - if ( aFileName.isEmpty() ) - { - abort(); - return; - } - - QString anExt = aFileName.split('.', QString::SkipEmptyParts).back(); + QStringList aFileNames = myFileDlg->selectedFiles(); + + QApplication::setOverrideCursor( Qt::WaitCursor ); + startDocOperation(); - if (anExt == "shp") + foreach (QString aFileName, aFileNames) { - SHPHandle aHSHP; - aHSHP = SHPOpen( aFileName.toAscii().data(), "rb" ); - Parse(aHSHP); - - QApplication::setOverrideCursor( Qt::WaitCursor ); - - startDocOperation(); + if ( aFileName.isEmpty() ) + continue; - HYDROData_Iterator anIter( doc() ); - int anInd = 0; - QStringList anExistingNames; - std::vector anAllowedIndexes; - for( ; anIter.More(); anIter.Next() ) - anExistingNames.push_back(anIter.Current()->GetName()); + QString anExt = aFileName.split('.', QString::SkipEmptyParts).back(); - QFileInfo aFileInfo(aFileName); - QString aBaseFileName = aFileInfo.baseName(); - - if (aHSHP->nShapeType == 3 || aHSHP->nShapeType == 23) + if (anExt == "shp") { - anInd = 0; - for (;anAllowedIndexes.size() < mySHPObjects.size();) + HYDROData_ShapeFile anImporter; + NCollection_Sequence theEntities; + int aShapeTypeOfFile = -1; + int aStat = anImporter.ImportPolylines(doc(), aFileName, theEntities, aShapeTypeOfFile ); + if (aStat == 1) + UpdateView(theEntities); + else if (aStat == 2) { - if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd))) - { - anAllowedIndexes.push_back(anInd); - anInd++; - } - else - anInd++; + UpdateView(theEntities); + SUIT_MessageBox::information(module()->getApp()->desktop(), + tr( "IMPORT_POLYLINE" ), "Contour of the polygon(s) have been imported as polyline(s)"); } - - for (size_t i = 0; i < mySHPObjects.size(); i++ ) + else { - ProcessSHPPolyXY(mySHPObjects[i], aBaseFileName, anAllowedIndexes[i]); + QString aMess = "Cannot import content of this file as polyline;\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 " + anImporter.GetShapeTypeName(aShapeTypeOfFile); + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_POLYLINE" ), aMess); } } - else if (aHSHP->nShapeType == 13) - { - anInd = 0; - for (;anAllowedIndexes.size() < mySHPObjects.size();) - { - if (!anExistingNames.contains(aBaseFileName + "_PolyXY_" + QString::number(anInd)) && - !anExistingNames.contains(aBaseFileName + "_Poly3D_" + QString::number(anInd)) && - !anExistingNames.contains(aBaseFileName + "_Bath_" + QString::number(anInd))) - { - anAllowedIndexes.push_back(anInd); - anInd++; - } - else - anInd++; - } - for (size_t i = 0; i < mySHPObjects.size(); i++ ) - ProcessSHPPoly3D(mySHPObjects[i], aBaseFileName, anAllowedIndexes[i]); - } + } + if (!aFileNames.empty()) + { commitDocOperation(); commit(); - - for (size_t i = 0; i < mySHPObjects.size(); i++ ) - free (mySHPObjects[i]); - - mySHPObjects.clear(); - SHPClose(aHSHP); + module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init | UF_OCCViewer ); } - module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init ); + else + abort(); QApplication::restoreOverrideCursor(); } -void HYDROGUI_ImportPolylineOp::ProcessSHPPolyXY(SHPObject* anObj, QString theFileName, int theInd) +void HYDROGUI_ImportPolylineOp::UpdateView( NCollection_Sequence& anEntities) { - //if (anObj->nSHPType != SHPT_ARC && anObj->nSHPType != SHPT_ARCM) - // return false; - Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) ); - - int nParts = anObj->nParts; - for ( int i = 0 ; i < nParts ; i++ ) - { - int StartIndex = anObj->panPartStart[i]; - int EndIndex; - if (i != nParts - 1) - EndIndex = anObj->panPartStart[i + 1]; - else - EndIndex = anObj->nVertices; - - bool IsClosed = false; - HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE; - if (anObj->padfX[StartIndex] == anObj->padfX[EndIndex - 1] && - anObj->padfY[StartIndex] == anObj->padfY[EndIndex - 1] ) - { - IsClosed = true; - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, true); - } - else - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, false); - - if (IsClosed) - EndIndex--; - for ( int k = StartIndex; k < EndIndex ; k++ ) - { - HYDROData_PolylineXY::Point aSectPoint; - aSectPoint.SetX( anObj->padfX[k] ); - aSectPoint.SetY( anObj->padfY[k] ); - aPolylineXY->AddPoint( i, aSectPoint ); - } - - } - - aPolylineXY->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() ); - aPolylineXY->SetName( theFileName + "_PolyXY_" + QString::number(theInd) ); - - aPolylineXY->Update(); - size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); if ( anActiveViewId == 0 ) anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() ); - - module()->setObjectVisible( anActiveViewId, aPolylineXY, true ); - - module()->setIsToUpdate( aPolylineXY ); -} - -void HYDROGUI_ImportPolylineOp::ProcessSHPPoly3D(SHPObject* anObj, QString theFileName, int theInd) -{ - Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) ); - - Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( doc()->CreateObject( KIND_POLYLINE ) ); - Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( doc()->CreateObject( KIND_BATHYMETRY ) ); - HYDROData_Bathymetry::AltitudePoints aAPoints; - - int nParts = anObj->nParts; - for ( int i = 0 ; i < nParts ; i++ ) + for (int i = 1; i <= anEntities.Size() ; i++) { - //bool aSectClosure = true; - int StartIndex = anObj->panPartStart[i]; - int EndIndex; - if (i != nParts - 1) - EndIndex = anObj->panPartStart[i + 1]; - else - EndIndex = anObj->nVertices; - - bool IsClosed = false; - HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE; - if (anObj->padfX[StartIndex] == anObj->padfX[EndIndex - 1] && - anObj->padfY[StartIndex] == anObj->padfY[EndIndex - 1] && - anObj->padfZ[StartIndex] == anObj->padfZ[EndIndex - 1]) - { - IsClosed = true; - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, true ); - } - else - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, false ); - - if (IsClosed) - EndIndex--; - for ( int k = StartIndex ; k < EndIndex ; k++ ) - { - HYDROData_PolylineXY::Point aSectPoint; - aSectPoint.SetX( anObj->padfX[k] ); - aSectPoint.SetY( anObj->padfY[k] ); - aPolylineXY->AddPoint( i, aSectPoint ); - aAPoints.Append(gp_XYZ (anObj->padfX[k], anObj->padfY[k], anObj->padfZ[k])); - } + anEntities(i)->Update(); + module()->setObjectVisible( anActiveViewId, anEntities(i), true ); + module()->setIsToUpdate( anEntities(i) ); } - - - QString aBathName = theFileName + "_bath_" + QString::number(theInd); - QString aPolyXYName = theFileName + "_polyXY_" + QString::number(theInd); - QString aPoly3DName = theFileName + "_poly3D_" + QString::number(theInd); - - aPolylineXY->SetName( aPolyXYName ); - aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor()); - aPolylineXY->Update(); - - aBath->SetAltitudePoints(aAPoints); - aBath->SetName( aBathName ); - - aPolylineObj->SetPolylineXY (aPolylineXY, false); - aPolylineObj->SetAltitudeObject(aBath); - - aPolylineObj->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() ); - aPolylineObj->SetName( aPoly3DName ); - - aPolylineObj->Update(); - - size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() ); - if ( anActiveViewId == 0 ) - anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() ); - - module()->setObjectVisible( anActiveViewId, aPolylineXY, true ); - module()->setObjectVisible( anActiveViewId, aPolylineObj, true ); - - module()->setIsToUpdate( aPolylineObj ); } - -void HYDROGUI_ImportPolylineOp::Parse(SHPHandle theHandle) -{ - int aShapeType; - mySHPObjects.clear(); - SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL ); - if (aShapeType == 3 || aShapeType == 13 || aShapeType == 23) - { - for (int i = 0; i < theHandle->nRecords; i++) - mySHPObjects.push_back(SHPReadObject(theHandle, i)); - } -} \ No newline at end of file