fixed edge display for volume cells
[engrid-github.git] / src / libengrid / guisetboundarycode.cpp
blob6ed740925bf8baee33e3cff21eae00744e6fb540
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
11 // + +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
16 // + +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "guisetboundarycode.h"
22 #include "setboundarycode.h"
23 #include "guimainwindow.h"
25 ///\todo Add automatic BC generation using feature edges
26 void GuiSetBoundaryCode::before()
28 //prepare radiobuttons
29 m_ButtonGroup = new QButtonGroup(this);
30 m_RadioButtonProcessOnlyVisible = new QRadioButton("Process only visible cells",this);
31 m_RadioButtonProcessAll = new QRadioButton("Process all cells (even invisible ones)",this);
32 m_RadioButtonSelectAllVisible = new QRadioButton("Select all visible cells",this);
33 m_RadioButtonOnlyPickedCell = new QRadioButton("Only picked cell",this);
34 m_RadioButtonOnlyPickedCellAndNeighbours = new QRadioButton("Only picked cell and neighbours",this);
35 m_RadioButtonAuto = new QRadioButton("automatic",this);
36 m_ButtonGroup->addButton(m_RadioButtonProcessOnlyVisible,0);
37 m_ButtonGroup->addButton(m_RadioButtonProcessAll,1);
38 m_ButtonGroup->addButton(m_RadioButtonSelectAllVisible,2);
39 m_ButtonGroup->addButton(m_RadioButtonOnlyPickedCell,3);
40 m_ButtonGroup->addButton(m_RadioButtonOnlyPickedCellAndNeighbours,4);
41 m_ButtonGroup->addButton(m_RadioButtonAuto,5);
42 m_Ui.verticalLayout_PickMethod->addWidget(m_RadioButtonProcessOnlyVisible);
43 m_Ui.verticalLayout_PickMethod->addWidget(m_RadioButtonProcessAll);
44 m_Ui.verticalLayout_PickMethod->addWidget(m_RadioButtonSelectAllVisible);
45 m_Ui.verticalLayout_PickMethod->addWidget(m_RadioButtonOnlyPickedCell);
46 m_Ui.verticalLayout_PickMethod->addWidget(m_RadioButtonOnlyPickedCellAndNeighbours);
47 m_Ui.verticalLayout_PickMethod->addWidget(m_RadioButtonAuto);
49 //read settings
50 QSettings local_qset("enGits","enGrid_GuisetBoundaryCode");
51 m_Ui.doubleSpinBoxFeatureAngle->setValue(local_qset.value("FeatureAngle", 45).toDouble());
52 m_Ui.spinBoxBoundaryCode->setValue(local_qset.value("BoundaryCode", 1).toInt());
53 m_ButtonGroup->button(local_qset.value("PickMethod",0).toInt())->setChecked(true);
56 void GuiSetBoundaryCode::operate()
58 m_ButtonGroup->checkedId();
59 cout<<"buttongroup->checkedId()="<<m_ButtonGroup->checkedId()<<endl;
61 //save settings
62 QSettings local_qset("enGits","enGrid_GuisetBoundaryCode");
63 local_qset.setValue("FeatureAngle", m_Ui.doubleSpinBoxFeatureAngle->value());
64 local_qset.setValue("BoundaryCode", m_Ui.spinBoxBoundaryCode->value());
65 local_qset.setValue("PickMethod", m_ButtonGroup->checkedId());
67 SetBoundaryCode set_bc;
68 set_bc.setGrid(m_Grid);
69 set_bc.setAllSurfaceCells();
70 if (m_RadioButtonAuto->isChecked()) {
71 QSet <int> display_bcs;
72 GuiMainWindow::pointer()->getDisplayBoundaryCodes(display_bcs);
73 int bc = m_Ui.spinBoxBoundaryCode->value();
74 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
75 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
76 bc = max(bc, cell_code->GetValue(id_cell));
77 if (display_bcs.contains(cell_code->GetValue(id_cell))) {
78 cell_code->SetValue(id_cell, 9999);
81 bool done = false;
82 do {
83 vtkIdType id_start = -1;
84 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
85 if (cell_code->GetValue(id_cell) == 9999) {
86 id_start = id_cell;
87 break;
90 if (id_start == -1) {
91 done = true;
92 } else {
93 set_bc.setFeatureAngle(m_Ui.doubleSpinBoxFeatureAngle->value());
94 set_bc.setBC(bc);
95 set_bc.setProcessAll(false);
96 set_bc.setSelectAllVisible(false);
97 set_bc.setOnlyPickedCell(false);
98 set_bc.setOnlyPickedCellAndNeighbours(false);
99 set_bc.setStart(id_start);
100 QString bc_name = GuiMainWindow::pointer()->getBC(bc).getName();
101 if (bc_name == "unknown") {
102 bc_name.setNum(bc);
103 bc_name = "wall_" + bc_name.rightJustified(3, '0');
104 BoundaryCondition sym_bc(bc_name, "wall");
105 GuiMainWindow::pointer()->addBC(bc, sym_bc);
107 set_bc();
108 ++bc;
110 } while (!done);
111 } else {
112 if (0 <= mainWindow()->getPickedCell() && mainWindow()->getPickedCell() < GuiMainWindow::pointer()->getGrid()->GetNumberOfCells() ) {
113 set_bc.setFeatureAngle(m_Ui.doubleSpinBoxFeatureAngle->value());
114 set_bc.setBC(m_Ui.spinBoxBoundaryCode->value());
116 set_bc.setProcessAll(m_ButtonGroup->button(1)->isChecked());
117 set_bc.setSelectAllVisible(m_ButtonGroup->button(2)->isChecked());
118 set_bc.setOnlyPickedCell(m_ButtonGroup->button(3)->isChecked());
119 set_bc.setOnlyPickedCellAndNeighbours(m_ButtonGroup->button(4)->isChecked());
121 cout << "GuiMainWindow::getPickedCell()=" << mainWindow()->getPickedCell() << endl;
122 set_bc.setStart(mainWindow()->getPickedCell());
123 set_bc();
124 } else {
125 EG_ERR_RETURN("Please select a cell first.");