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_ImportLandCoverOp.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_UpdateFlags.h"
28 #include "HYDROGUI_Tool.h"
29 #include "HYDROGUI_ImportLandCoverDlg.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 <SUIT_MessageBox.h>
46 #include <BRep_Builder.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopoDS_Wire.hxx>
50 #include <BRepBuilderAPI_MakeEdge2d.hxx>
51 #include <BRepBuilderAPI_MakeWire.hxx>
52 #include <BRepBuilderAPI_MakeFace.hxx>
53 #include <gp_Pnt2d.hxx>
54 #include <BRepTools.hxx>
58 HYDROGUI_ImportLandCoverOp::HYDROGUI_ImportLandCoverOp( HYDROGUI_Module* theModule )
59 : HYDROGUI_Operation( theModule )
61 setName( tr( "IMPORT_LANDCOVER" ) );
64 HYDROGUI_ImportLandCoverOp::~HYDROGUI_ImportLandCoverOp()
68 void HYDROGUI_ImportLandCoverOp::startOperation()
70 HYDROGUI_Operation::startOperation();
72 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
73 myFileDlg->setWindowTitle( getName() );
74 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
75 myFileDlg->setFilter( tr("LANDCOVER_FILTER") );
77 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
78 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
83 void HYDROGUI_ImportLandCoverOp::onApply()
91 QString aFileName = myFileDlg->selectedFile();
92 if ( aFileName.isEmpty() )
98 QString anExt = aFileName.split('.', QString::SplitBehavior::SkipEmptyParts).back();
103 aHSHP = SHPOpen( aFileName.toAscii().data(), "rb" );
105 std::map<QListWidgetItem*, SHPObject*> aWItemToSObjectMap;
106 HYDROGUI_ImportLandCoverDlg anImportLandCoverDlg( mySHPObjects, aWItemToSObjectMap, module()->getApp()->desktop() );
107 if ( anImportLandCoverDlg.exec() == HYDROGUI_ImportLandCoverDlg::Accepted )
109 QApplication::setOverrideCursor( Qt::WaitCursor );
113 int T = anImportLandCoverDlg.GetSelectedItems().size();
117 BB.MakeCompound(cmp);
119 if (aHSHP->nShapeType == 5)
121 for (int i = 0; i < this->mySHPObjects.size(); i++) {
122 ProcessSHP(mySHPObjects[i], i, F);
125 ///to hydro_landcover
126 // BRepTools::Write(cmp, "d:/h1.brep");
129 SUIT_MessageBox::warning( module()->getApp()->desktop(), "Import Land cover", "Cannot land cover;\nThe shape type is not polygon" );
130 commitDocOperation();
134 for (size_t i = 0; i < mySHPObjects.size(); i++ )
135 free (mySHPObjects[i]);
137 mySHPObjects.clear();
141 module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
143 QApplication::restoreOverrideCursor();
148 void HYDROGUI_ImportLandCoverOp::Parse(SHPHandle theHandle)
151 mySHPObjects.clear();
152 SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL );
155 for (int i = 0; i < theHandle->nRecords; i++)
156 mySHPObjects.push_back(SHPReadObject(theHandle, i));
160 void HYDROGUI_ImportLandCoverOp::ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F)
164 int nParts = anObj->nParts;
165 gp_Pln pln(gp_Pnt(0,0,0), gp_Dir(0,0,1));
166 BRepBuilderAPI_MakeFace aFBuilder(pln);
167 for ( int i = 0 ; i < nParts ; i++ )
169 BRepBuilderAPI_MakeWire aBuilder;
170 int StartIndex = anObj->panPartStart[i];
173 EndIndex = anObj->panPartStart[i + 1];
175 EndIndex = anObj->nVertices;
177 for ( int k = StartIndex; k < EndIndex - 1 ; k++ )
179 gp_Pnt2d P1 (anObj->padfX[k], anObj->padfY[k]);
180 gp_Pnt2d P2 (anObj->padfX[k+1], anObj->padfY[k+1]);
181 BRepBuilderAPI_MakeEdge2d aMakeEdge(P1, P2);
182 aBuilder.Add(TopoDS::Edge(aMakeEdge.Shape()));
185 W = TopoDS::Wire(aBuilder.Shape());
190 F = aFBuilder.Face();
192 //TODO build curve 3d
194 /*aPolylineXY->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
195 aPolylineXY->SetName( theFileName + "_PolyXY_" + QString::number(theInd) );
197 aPolylineXY->Update();
199 size_t anActiveViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( module() );
200 if ( anActiveViewId == 0 )
201 anActiveViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
203 module()->setObjectVisible( anActiveViewId, aPolylineXY, true );
205 module()->setIsToUpdate( aPolylineXY );*/