1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ImportBCPolygonOp.h"
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_UpdateFlags.h"
24 #include "HYDROGUI_Tool2.h"
25 #include <HYDROData_PolylineXY.h>
27 #include <HYDROData_BCPolygon.h>
28 #include <HYDROGUI_DataObject.h>
30 #include <HYDROGUI_ImportPolylineOp.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_FileDlg.h>
34 #include <LightApp_Application.h>
36 #include <QApplication>
39 #include <SUIT_MessageBox.h>
42 HYDROGUI_ImportBCPolygonOp::HYDROGUI_ImportBCPolygonOp( HYDROGUI_Module* theModule )
43 : HYDROGUI_Operation( theModule )
45 setName( tr( "IMPORT_BC_POLYGON" ) );
48 HYDROGUI_ImportBCPolygonOp::~HYDROGUI_ImportBCPolygonOp()
52 void HYDROGUI_ImportBCPolygonOp::startOperation()
54 HYDROGUI_Operation::startOperation();
56 myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true );
57 myFileDlg->setWindowTitle( getName() );
58 myFileDlg->setFileMode( SUIT_FileDlg::ExistingFiles );
59 myFileDlg->setNameFilter( tr("BC_POLYGON_FILTER") );
61 connect( myFileDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
62 connect( myFileDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
68 bool HYDROGUI_ImportBCPolygonOp::processApply( int& theUpdateFlags, QString& theErrorMsg,
69 QStringList& theBrowseObjectsEntries )
77 QStringList aFileNames = myFileDlg->selectedFiles();
79 QApplication::setOverrideCursor( Qt::WaitCursor );
80 //startDocOperation();
82 NCollection_Sequence<Handle(HYDROData_Entity)> importedEnts =
83 HYDROGUI_ImportPolylineOp::ImportPolyOp(aFileNames, doc(), module(),
84 HYDROData_ShapeFile::ImportShapeType_Polygon);
86 for (int i=1;i<=importedEnts.Size();i++ )
88 Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast(importedEnts(i));
89 if (aPolylineXY.IsNull())
91 TopoDS_Shape aTopSh = HYDROData_BCPolygon::generateTopShape(aPolylineXY);
95 //get boundary type from DBF
96 QStringList aDBFTableList;
97 aPolylineXY->GetDBFInfo(aDBFTableList);
98 QVector<QString> aDBFTable = aDBFTableList.toVector();
99 int nbs = aDBFTable.size();
101 for (int i = 0; i < nbs / 2; i++)
102 if (aDBFTable[i] == "type")
104 aBTypeStr = aDBFTable[nbs / 2 + i];
110 aBTypeVal = aBTypeStr.toInt(&Ok);
114 QString aPolyXYName = aPolylineXY->GetName();
115 Handle(HYDROData_BCPolygon) aBCObj = Handle(HYDROData_BCPolygon)::DownCast( doc()->CreateObject( KIND_BC_POLYGON ) );
116 aBCObj->SetName( "BP_" + aPolyXYName );
117 aBCObj->SetBoundaryType(aBTypeVal);
119 aBCObj->SetFillingColor( aBCObj->DefaultFillingColor() );
120 aBCObj->SetBorderColor( aBCObj->DefaultBorderColor() );
121 aBCObj->SetPolyline( aPolylineXY );
122 aBCObj->Update(aTopSh);
124 module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aBCObj, true );
125 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aBCObj );
126 theBrowseObjectsEntries.append( anEntry );
127 module()->setIsToUpdate( aBCObj );
130 if (!aFileNames.empty())
132 //commitDocOperation();
134 //module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init | UF_OCCViewer );
135 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
140 QApplication::restoreOverrideCursor();