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_ImportSinusXOp.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>
33 #include <HYDROData_Iterator.h>
35 #include <HYDROData_Profile.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_FileDlg.h>
39 #include <LightApp_Application.h>
41 #include <QApplication>
44 #include <QMessageBox>
47 HYDROGUI_ImportSinusXOp::HYDROGUI_ImportSinusXOp( HYDROGUI_Module* theModule )
48 : HYDROGUI_Operation( theModule )
50 setName( tr( "IMPORT_SINUSX" ) );
53 HYDROGUI_ImportSinusXOp::~HYDROGUI_ImportSinusXOp()
57 void HYDROGUI_ImportSinusXOp::startOperation()
59 HYDROGUI_Operation::startOperation();
61 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
62 myFileDlg->setWindowTitle( getName() );
63 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
64 myFileDlg->setFilter( tr("SINUSX_FILTER") );
66 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
67 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
72 void HYDROGUI_ImportSinusXOp::onApply()
80 QString aFileName = myFileDlg->selectedFile();
81 if ( aFileName.isEmpty() )
87 QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
91 QFile aFile (aFileName);
92 aFile.open(QIODevice::ReadOnly);
96 QApplication::setOverrideCursor( Qt::WaitCursor );
102 commitDocOperation();
107 module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
109 QApplication::restoreOverrideCursor();
112 void HYDROGUI_ImportSinusXOp::ProcessSX()
114 Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) );
116 Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( doc()->CreateObject( KIND_POLYLINE ) );
118 Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( doc()->CreateObject( KIND_BATHYMETRY ) );
119 HYDROData_Bathymetry::AltitudePoints aAPoints;
121 int aNSect = myCurveBlocks.size();
122 for ( int i = 0 ; i < aNSect ; i++ )
124 bool aSectClosure = true;
125 HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
126 aPolylineXY->AddSection( TCollection_AsciiString(myCurveBlocks[i].myName.toStdString().c_str()), aSectType, myCurveBlocks[i].myIsConnected );
128 for ( int k = 0 ; k < myCurveBlocks[i].myXYZPoints.size() ; k+=3 )
130 HYDROData_PolylineXY::Point aSectPoint;
131 aSectPoint.SetX( myCurveBlocks[i].myXYZPoints[k].X() );
132 aSectPoint.SetY( myCurveBlocks[i].myXYZPoints[k].Y() );
133 aPolylineXY->AddPoint( i, aSectPoint );
135 aAPoints.Append(myCurveBlocks[i].myXYZPoints[k]);
138 QString aFileName = myFileDlg->selectedFile();
139 QFileInfo aFileInfo(aFileName);
140 QString aBaseFileName = aFileInfo.baseName();
141 QString aBathName = aBaseFileName + "_bath_1";
142 QString aPolyXYName = aBaseFileName + "_polyXY_1";
143 QString aPoly3DName = aBaseFileName + "_poly3D_1";
146 for (;HYDROGUI_Tool::FindObjectByName( module(), aBathName, KIND_BATHYMETRY) ||
147 HYDROGUI_Tool::FindObjectByName( module(), aPolyXYName, KIND_POLYLINEXY) ||
148 HYDROGUI_Tool::FindObjectByName( module(), aPoly3DName, KIND_POLYLINE);)
150 aBathName = aBaseFileName + "_bath_" + QString::number(anInd);
151 aPolyXYName = aBaseFileName + "_polyXY_" + QString::number(anInd);
152 aPoly3DName = aBaseFileName + "_poly3D_" + QString::number(anInd);
156 aPolylineXY->SetName( aPolyXYName );
157 aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor());
158 aPolylineXY->Update();
160 aBath->SetAltitudePoints(aAPoints);
161 aBath->SetName( aBathName );
163 aPolylineObj->SetPolylineXY (aPolylineXY, false);
164 aPolylineObj->SetAltitudeObject(aBath);
166 aPolylineObj->SetBorderColor( HYDROData_Polyline3D::DefaultBorderColor() );
167 aPolylineObj->SetName( aPoly3DName );
169 aPolylineObj->Update();
171 size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
172 if ( anActiveViewId == 0 )
173 anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
175 module()->setObjectVisible( anActiveViewId, aPolylineXY, true );
176 module()->setObjectVisible( anActiveViewId, aPolylineObj, true );
178 module()->setIsToUpdate( aPolylineObj );
182 bool HYDROGUI_ImportSinusXOp::Parse( QFile& theFile)
184 if ( !theFile.isOpen() )
191 myCurveBlocks.clear();
192 bool aTotStat = true;
194 aLine = theFile.readLine().simplified();
195 aList = aLine.split( ' ', QString::SkipEmptyParts );
197 for (;!theFile.atEnd();)
199 if (aList[0] == "B" && (aList[1] == "C" || aList[1] == "P" || aList[1] == "N"))
201 HYDROGUI_CurveBlock aCurveBlockInfo;
203 aCurveBlockInfo.myType = 1;
204 else if (aList[1] == "P")
205 aCurveBlockInfo.myType = 2;
206 else if (aList[1] == "N")
207 aCurveBlockInfo.myType = 2;
209 if (aList.size() == 9)
211 for (int j = 2; j < 8; j++)
212 aCurveBlockInfo.myRefCoords.push_back(aList[j].toDouble());
213 aCurveBlockInfo.myRefRatio = aList[8].toDouble();
219 aBLine = theFile.readLine().simplified();
220 aBList = aBLine.split( ' ', QString::SkipEmptyParts );
222 if (aBList[0] == "CP")
224 if (aBList.size() == 2 && (aBList[1] == "0" || aBList[1] == "1" || aBList[1] == "2"))
225 aCurveBlockInfo.myCurvePlane = aBList[1].toInt();
226 else if (aBList.size() == 3 && (aBList[1] == "0" || aBList[1] == "1") && (aBList[2] == "0" || aBList[2] == "1"))
228 aCurveBlockInfo.myIsClosed = aBList[1].toInt();
229 aCurveBlockInfo.myIsClosed = aBList[2].toInt();
233 for (int j = 1; j < aBList.size(); j++)
234 aCurveBlockInfo.myAdditionalCurveInfo.push_back(aBList[j].toDouble());
237 if (aBList[0] == "CN")
239 for (int i = 1; i < aBList.size(); i++)
240 Name += aBList[i] + "_";
241 Name.remove(Name.size() - 1, 1);
242 aCurveBlockInfo.myName = Name;
244 } while (!theFile.atEnd() && aBLine[0] == 'C' );
250 if (aBList.size() >= 3 && aBLine[0] != 'B' && aBLine[0] != 'C') {
252 anXYZ.SetX (aBList[0].toDouble(&aStat));
253 aTotStat = aTotStat && aStat;
254 anXYZ.SetY (aBList[1].toDouble(&aStat));
255 aTotStat = aTotStat && aStat;
256 anXYZ.SetZ (aBList[2].toDouble(&aStat));
257 aTotStat = aTotStat && aStat;
259 aCurveBlockInfo.myXYZPoints.push_back(anXYZ);
261 aBLine = theFile.readLine().simplified();
262 aBList = aBLine.split( ' ', QString::SkipEmptyParts );
267 } while (!theFile.atEnd()/* && aBLine[0] == 'B'*/ );
269 myCurveBlocks.push_back(aCurveBlockInfo);
274 aLine = theFile.readLine().simplified();
275 aList = aLine.split( ' ', QString::SkipEmptyParts );