-// 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
#include "HYDROGUI_DataModel.h"
#include "HYDROGUI_Module.h"
#include "HYDROGUI_UpdateFlags.h"
-#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_Tool2.h"
#include <HYDROData_PolylineXY.h>
#include <HYDROData_Polyline3D.h>
#include <HYDROGUI_DataObject.h>
#include <HYDROData_Bathymetry.h>
+#include <HYDROData_Iterator.h>
+#include <HYDROData_ShapeFile.h>
#include <HYDROData_Profile.h>
#include <QApplication>
#include <QFile>
+#include <QFileInfo>
+#include <SUIT_MessageBox.h>
+
HYDROGUI_ImportPolylineOp::HYDROGUI_ImportPolylineOp( HYDROGUI_Module* theModule )
: HYDROGUI_Operation( theModule )
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() ) );
return;
}
- QString aFileName = myFileDlg->selectedFile();
- if ( aFileName.isEmpty() )
- {
- abort();
- return;
- }
-
- QFile aFile (aFileName);
- aFile.open(QIODevice::ReadOnly);
-
- Parse(aFile);
-
- QApplication::setOverrideCursor( Qt::WaitCursor );
-
+ QStringList aFileNames = myFileDlg->selectedFiles();
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
startDocOperation();
- Process();
-
- commitDocOperation();
- commit();
-
- module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
-
- aFile.close();
-
- QApplication::restoreOverrideCursor();
-}
-
-void HYDROGUI_ImportPolylineOp::Process()
-{
-
- 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 aNSect = myCurveBlocks.size();
- for ( int i = 0 ; i < aNSect ; i++ )
+ foreach (QString aFileName, aFileNames)
{
- bool aSectClosure = true;
- HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
- aPolylineXY->AddSection( TCollection_AsciiString(myCurveBlocks[i].myName.toStdString().c_str()), aSectType, myCurveBlocks[i].myIsClosed );
+ if ( aFileName.isEmpty() )
+ continue;
- for ( int k = 0 ; k < myCurveBlocks[i].myXYZPoints.size() ; k+=3 )
- {
- HYDROData_PolylineXY::Point aSectPoint;
- aSectPoint.SetX( myCurveBlocks[i].myXYZPoints[k].X() );
- aSectPoint.SetY( myCurveBlocks[i].myXYZPoints[k].Y() );
- aPolylineXY->AddPoint( i, aSectPoint );
+ QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
- aAPoints.Append(myCurveBlocks[i].myXYZPoints[k]);
+ if (anExt == "shp")
+ {
+ HYDROData_ShapeFile anImporter;
+ NCollection_Sequence<Handle(HYDROData_Entity)> theEntities;
+ int aShapeTypeOfFile = -1;
+ int aStat = anImporter.ImportPolylines(doc(), aFileName, theEntities, aShapeTypeOfFile );
+ if (aStat == 1)
+ UpdateView(theEntities);
+ else
+ {
+ 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);
+ }
}
}
- aPolylineXY->SetName("P_XY");
- aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor());
- aPolylineXY->Update();
-
- aBath->SetAltitudePoints(aAPoints);
- aBath->SetName("P_B");
-
- aPolylineObj->SetPolylineXY (aPolylineXY, false);
- aPolylineObj->SetAltitudeObject(aBath);
-
- aPolylineObj->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() );
- aPolylineObj->SetName("P_3D");
+ if (!aFileNames.empty())
+ {
+ commitDocOperation();
+ commit();
+ module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
+ }
+ else
+ abort();
- aPolylineObj->Update();
-
+ QApplication::restoreOverrideCursor();
+}
+void HYDROGUI_ImportPolylineOp::UpdateView( NCollection_Sequence<Handle(HYDROData_Entity)>& anEntities)
+{
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 );
-}
-
-bool HYDROGUI_ImportPolylineOp::Parse( QFile& theFile)
-{
- if ( !theFile.isOpen() )
- return false;
-
- QString aLine;
- QString aBLine;
- QStringList aList;
- QStringList aBList;
- myCurveBlocks.clear();
- bool aTotStat = true;
-
- aLine = theFile.readLine().simplified();
- aList = aLine.split( ' ', QString::SkipEmptyParts );
-
- for (;!theFile.atEnd();)
+ for (int i = 1; i <= anEntities.Size() ; i++)
{
- if (aList[0] == "B" && (aList[1] == "C" || aList[1] == "P" || aList[1] == "N"))
- {
- HYDROGUI_CurveBlock aCurveBlockInfo;
- if (aList[1] == "C")
- aCurveBlockInfo.myType = 1;
- else if (aList[1] == "P")
- aCurveBlockInfo.myType = 2;
- else if (aList[1] == "N")
- aCurveBlockInfo.myType = 2;
-
- QString Name;
- do
- {
- aBLine = theFile.readLine().simplified();
- aBList = aBLine.split( ' ', QString::SkipEmptyParts );
-
- if (aBList[0] == "CP")
- {
- if (aBList.size() == 2 && (aBList[1] == "0" || aBList[1] == "1" || aBList[1] == "2"))
- aCurveBlockInfo.myCurvePlane = aBList[1].toInt();
- if (aBList.size() == 3 && (aBList[1] == "0" || aBList[1] == "1") && (aBList[2] == "0" || aBList[2] == "1"))
- {
- aCurveBlockInfo.myIsClosed = aBList[1].toInt();
- aCurveBlockInfo.myIsClosed = aBList[2].toInt();
- }
- }
- if (aBList[0] == "CN")
- {
- for (int i = 1; i < aBList.size(); i++)
- Name += aBList[i] + "_";
- Name.remove(Name.size() - 1, 1);
- aCurveBlockInfo.myName = Name;
- }
- } while (!theFile.atEnd() && aBLine[0] == 'C' );
-
- bool aStat;
- aTotStat = true;
- do
- {
- if (aBList.size() >= 3 && aBLine[0] != 'B' && aBLine[0] != 'C') {
- gp_XYZ anXYZ;
- anXYZ.SetX (aBList[0].toDouble(&aStat));
- aTotStat = aTotStat && aStat;
- anXYZ.SetY (aBList[1].toDouble(&aStat));
- aTotStat = aTotStat && aStat;
- anXYZ.SetZ (aBList[2].toDouble(&aStat));
- aTotStat = aTotStat && aStat;
-
- aCurveBlockInfo.myXYZPoints.push_back(anXYZ);
-
- aBLine = theFile.readLine().simplified();
- aBList = aBLine.split( ' ', QString::SkipEmptyParts );
- }
- else
- break;
-
- } while (!theFile.atEnd()/* && aBLine[0] == 'B'*/ );
- if (aTotStat)
- myCurveBlocks.push_back(aCurveBlockInfo);
-
- }
- else
- {
- aLine = theFile.readLine().simplified();
- aList = aLine.split( ' ', QString::SkipEmptyParts );
- }
-
+ anEntities(i)->Update();
+ module()->setObjectVisible( anActiveViewId, anEntities(i), true );
+ module()->setIsToUpdate( anEntities(i) );
}
-
- return true;
-
-}
\ No newline at end of file
+}