1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_ImportPolylineOp.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_UpdateFlags.h"
28 #include "HYDROGUI_Tool.h"
29 #include <HYDROData_PolylineXY.h>
30 #include <HYDROData_Polyline3D.h>
31 #include <HYDROGUI_DataObject.h>
32 #include <HYDROData_Bathymetry.h>
34 #include <HYDROData_Profile.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_FileDlg.h>
38 #include <LightApp_Application.h>
40 #include <QApplication>
43 HYDROGUI_ImportPolylineOp::HYDROGUI_ImportPolylineOp( HYDROGUI_Module* theModule )
44 : HYDROGUI_Operation( theModule )
46 setName( tr( "IMPORT_POLYLINE" ) );
49 HYDROGUI_ImportPolylineOp::~HYDROGUI_ImportPolylineOp()
53 void HYDROGUI_ImportPolylineOp::startOperation()
55 HYDROGUI_Operation::startOperation();
57 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
58 myFileDlg->setWindowTitle( getName() );
59 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
60 myFileDlg->setFilter( tr("POLYLINE_FILTER") );
62 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
63 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
68 void HYDROGUI_ImportPolylineOp::onApply()
76 QString aFileName = myFileDlg->selectedFile();
77 if ( aFileName.isEmpty() )
83 QFile aFile (aFileName);
84 aFile.open(QIODevice::ReadOnly);
88 QApplication::setOverrideCursor( Qt::WaitCursor );
97 module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
101 QApplication::restoreOverrideCursor();
104 void HYDROGUI_ImportPolylineOp::Process()
107 Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) );
109 Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( doc()->CreateObject( KIND_POLYLINE ) );
111 Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( doc()->CreateObject( KIND_BATHYMETRY ) );;
112 HYDROData_Bathymetry::AltitudePoints aAPoints;
114 int aNSect = myCurveBlocks.size();
115 for ( int i = 0 ; i < aNSect ; i++ )
117 bool aSectClosure = true;
118 HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
119 aPolylineXY->AddSection( TCollection_AsciiString(myCurveBlocks[i].myName.toStdString().c_str()), aSectType, myCurveBlocks[i].myIsClosed );
121 for ( int k = 0 ; k < myCurveBlocks[i].myXYZPoints.size() ; k+=3 )
123 HYDROData_PolylineXY::Point aSectPoint;
124 aSectPoint.SetX( myCurveBlocks[i].myXYZPoints[k].X() );
125 aSectPoint.SetY( myCurveBlocks[i].myXYZPoints[k].Y() );
126 aPolylineXY->AddPoint( i, aSectPoint );
128 aAPoints.Append(myCurveBlocks[i].myXYZPoints[k]);
131 aPolylineXY->SetName("P_XY");
132 aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor());
133 aPolylineXY->Update();
135 aBath->SetAltitudePoints(aAPoints);
136 aBath->SetName("P_B");
138 aPolylineObj->SetPolylineXY (aPolylineXY, false);
139 aPolylineObj->SetAltitudeObject(aBath);
141 aPolylineObj->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() );
142 aPolylineObj->SetName("P_3D");
144 aPolylineObj->Update();
147 size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
148 if ( anActiveViewId == 0 )
149 anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
151 module()->setObjectVisible( anActiveViewId, aPolylineXY, true );
152 module()->setObjectVisible( anActiveViewId, aPolylineObj, true );
154 module()->setIsToUpdate( aPolylineObj );
157 bool HYDROGUI_ImportPolylineOp::Parse( QFile& theFile)
159 if ( !theFile.isOpen() )
166 myCurveBlocks.clear();
167 bool aTotStat = true;
169 aLine = theFile.readLine().simplified();
170 aList = aLine.split( ' ', QString::SkipEmptyParts );
172 for (;!theFile.atEnd();)
174 if (aList[0] == "B" && (aList[1] == "C" || aList[1] == "P" || aList[1] == "N"))
176 HYDROGUI_CurveBlock aCurveBlockInfo;
178 aCurveBlockInfo.myType = 1;
179 else if (aList[1] == "P")
180 aCurveBlockInfo.myType = 2;
181 else if (aList[1] == "N")
182 aCurveBlockInfo.myType = 2;
187 aBLine = theFile.readLine().simplified();
188 aBList = aBLine.split( ' ', QString::SkipEmptyParts );
190 if (aBList[0] == "CP")
192 if (aBList.size() == 2 && (aBList[1] == "0" || aBList[1] == "1" || aBList[1] == "2"))
193 aCurveBlockInfo.myCurvePlane = aBList[1].toInt();
194 if (aBList.size() == 3 && (aBList[1] == "0" || aBList[1] == "1") && (aBList[2] == "0" || aBList[2] == "1"))
196 aCurveBlockInfo.myIsClosed = aBList[1].toInt();
197 aCurveBlockInfo.myIsClosed = aBList[2].toInt();
200 if (aBList[0] == "CN")
202 for (int i = 1; i < aBList.size(); i++)
203 Name += aBList[i] + "_";
204 Name.remove(Name.size() - 1, 1);
205 aCurveBlockInfo.myName = Name;
207 } while (!theFile.atEnd() && aBLine[0] == 'C' );
213 if (aBList.size() >= 3 && aBLine[0] != 'B' && aBLine[0] != 'C') {
215 anXYZ.SetX (aBList[0].toDouble(&aStat));
216 aTotStat = aTotStat && aStat;
217 anXYZ.SetY (aBList[1].toDouble(&aStat));
218 aTotStat = aTotStat && aStat;
219 anXYZ.SetZ (aBList[2].toDouble(&aStat));
220 aTotStat = aTotStat && aStat;
222 aCurveBlockInfo.myXYZPoints.push_back(anXYZ);
224 aBLine = theFile.readLine().simplified();
225 aBList = aBLine.split( ' ', QString::SkipEmptyParts );
230 } while (!theFile.atEnd()/* && aBLine[0] == 'B'*/ );
232 myCurveBlocks.push_back(aCurveBlockInfo);
237 aLine = theFile.readLine().simplified();
238 aList = aLine.split( ' ', QString::SkipEmptyParts );