Salome HOME
when adjusting a shapefile, modify it's name with a suffix _adj or _split
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportSinusXDlg.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ImportSinusXDlg.h"
20 #include <QVBoxLayout>
21 #include <QPushButton>
22 #include <QLabel>
23 #include <HYDROData_SinusX.h>
24 #include <assert.h>
25 #include <QHeaderView>
26 #include <QSizePolicy>
27
28 HYDROGUI_ImportSinusXDlg::HYDROGUI_ImportSinusXDlg( QWidget* theParent, const QStringList& theNames,
29   const std::vector<int>& theTypes )
30   : QDialog( theParent )
31 {
32   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
33   aMainLayout->setMargin(5);
34   aMainLayout->setSpacing(5);
35   this->resize(600, 500);
36
37   QLabel* gLabel = new QLabel();
38   gLabel->setText(tr("ENTITIES_TO_IMPORT"));
39
40   assert (theNames.size() == theTypes.size());
41   myTable = new QTableWidget(theNames.size(), 5);
42
43   QStringList header;
44   header << tr("NAME") << tr("TYPE") << tr("AS_BATHY") << tr("AS_POLYXY") << tr("AS_PROFILE");
45   myTable->setHorizontalHeaderLabels(header);
46
47   myTable->setShowGrid(true);
48   myTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
49
50   for (int i = 0; i < theNames.size(); i++)
51   {
52     QTableWidgetItem* item_name = new QTableWidgetItem(theNames[i]);
53     item_name->setFlags(item_name->flags() ^ Qt::ItemIsEditable);
54     myTable->setItem(i, 0, item_name);
55
56     QString TypeName;
57     if (theTypes[i] == 1)
58       TypeName = tr("XYZ_CURVE");
59     else if (theTypes[i] == 2)
60       TypeName = tr("XYZ_PROFILE");
61     else if (theTypes[i] == 3)
62       TypeName = tr("ISOCONTOUR");
63     else if (theTypes[i] == 4)
64       TypeName = tr("SCATTER");
65
66     QTableWidgetItem* item_type = new QTableWidgetItem(TypeName);
67     item_type->setFlags(item_type->flags() ^ Qt::ItemIsEditable);
68     myTable->setItem(i, 1, item_type);
69
70     QTableWidgetItem* itemCheckbox1 = new QTableWidgetItem(""); //as bathy
71     itemCheckbox1->setFlags(itemCheckbox1->flags() ^ Qt::ItemIsEditable);
72     itemCheckbox1->setCheckState(Qt::Checked);
73     myTable->setItem(i, 2, itemCheckbox1);
74
75     QTableWidgetItem* itemCheckbox2 = new QTableWidgetItem("");  ; //as polyXY
76     itemCheckbox2->setFlags(itemCheckbox2->flags() ^ Qt::ItemIsEditable);
77     itemCheckbox2->setCheckState(Qt::Checked);
78     myTable->setItem(i, 3, itemCheckbox2);
79
80     QTableWidgetItem* itemCheckbox3 = new QTableWidgetItem("");  ; //as profile
81     itemCheckbox3->setFlags(itemCheckbox3->flags() ^ Qt::ItemIsEditable);
82     itemCheckbox3->setCheckState(Qt::Checked);
83     myTable->setItem(i, 4, itemCheckbox3);
84
85     if (theTypes[i] == 1 || theTypes[i] == 3) ///XYZ curve 
86     {
87       itemCheckbox1->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); //disable bathy
88       itemCheckbox1->setCheckState(Qt::Unchecked);
89     }
90     else if (theTypes[i] == 2)
91     {
92       itemCheckbox1->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); 
93       itemCheckbox2->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); 
94       itemCheckbox1->setCheckState(Qt::Unchecked);
95       itemCheckbox2->setCheckState(Qt::Unchecked);
96     }
97     else if (theTypes[i] == 4)
98     {
99       //as bathy only
100       itemCheckbox2->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); 
101       itemCheckbox3->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); 
102       itemCheckbox2->setCheckState(Qt::Unchecked);
103       itemCheckbox3->setCheckState(Qt::Unchecked);
104     }
105   }
106
107   aMainLayout->addWidget(gLabel);
108   aMainLayout->addWidget(myTable);
109
110   //QPushButton* CheckAllButton = new QPushButton( tr("CHECK_ALL"), this );
111   //QPushButton* UncheckAllButton = new QPushButton( tr("UNCHECK_ALL"), this );
112
113   QPushButton* anOkButton = new QPushButton( tr("OK"), this );
114   anOkButton->setDefault( true ); 
115
116   //aMainLayout->addWidget( CheckAllButton );
117   //aMainLayout->addWidget( UncheckAllButton );
118   aMainLayout->addWidget( anOkButton );
119
120   connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
121   //connect( CheckAllButton, SIGNAL( clicked() ), this, SLOT( onCheckAll() ) );
122   //connect( UncheckAllButton, SIGNAL( clicked() ), this, SLOT( onUncheckAll() ) );
123
124   connect(myTable, SIGNAL(cellChanged(int,int)), this, SLOT(onCheckChecked(int, int)));
125
126   setLayout(aMainLayout);
127 }
128
129 HYDROGUI_ImportSinusXDlg::~HYDROGUI_ImportSinusXDlg()
130 {
131 }
132
133 void HYDROGUI_ImportSinusXDlg::onCheckChecked(int r, int c)
134 {
135   ///if it's "as POLYLINE" column and now it's unchecked => disable "as PROFILE" checkbox
136   if (c == 3 && myTable->item(r, 3)->checkState() == Qt::Unchecked) 
137   {
138     QString text = myTable->item(r, 1)->text();
139     if (text == tr("XYZ_CURVE") || text == tr("ISOCONTOUR"))
140       myTable->item(r, 4)->setCheckState(Qt::Unchecked);
141   }
142 }
143
144 std::vector<HYDROData_SinusX::ImportOptions> HYDROGUI_ImportSinusXDlg::GetImportOptions() const
145 {
146   std::vector<HYDROData_SinusX::ImportOptions> options; 
147   int size = myTable->rowCount();
148   for (int i = 0; i < size; i++)
149   {
150     HYDROData_SinusX::ImportOptions option;
151     if (myTable->item(i, 2)->checkState() == Qt::CheckState::Checked)
152       option.ImportAsBathy = true;
153     if (myTable->item(i, 3)->checkState() == Qt::CheckState::Checked)
154       option.ImportAsPolyXY = true;
155     if (myTable->item(i, 4)->checkState() == Qt::CheckState::Checked)
156       option.ImportAsProfile = true;
157     options.push_back(option);
158   }
159   return options;
160 }
161
162
163
164