fixed edge display for volume cells
[engrid-github.git] / src / libengrid / guimergevolumes.cpp
blob81fb9484100cea50459b1a101090f5282befea8a
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 "guimergevolumes.h"
22 #include "guimainwindow.h"
24 GuiMergeVolumes::GuiMergeVolumes()
28 void GuiMergeVolumes::before()
30 populateVolumes(m_Ui.listWidgetVC1);
31 populateVolumes(m_Ui.listWidgetVC2);
34 void GuiMergeVolumes::operate()
36 QString vol_name1 = getSelectedVolume(m_Ui.listWidgetVC1);
37 QString vol_name2 = getSelectedVolume(m_Ui.listWidgetVC2);
38 VolumeDefinition V1 = GuiMainWindow::pointer()->getVol(vol_name1);
39 VolumeDefinition V2 = GuiMainWindow::pointer()->getVol(vol_name2);
40 QSet<int> all_bcs = GuiMainWindow::pointer()->getAllBoundaryCodes();
42 // identify boundary patches to be deleted
43 QSet<int> del_bcs;
44 foreach (int bc, all_bcs) {
45 int sign1 = V1.getSign(bc);
46 int sign2 = V2.getSign(bc);
47 if (sign1 != 0 && sign2 != 0) {
48 if (sign1*sign2 > 0) {
49 EG_ERR_RETURN("volume definition not consistent (A<</>>B)");
51 del_bcs.insert(bc);
55 // count cells of new mesh
56 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
57 int num_new_cells = 0;
58 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
59 if (isVolume(id_cell, m_Grid)) {
60 ++num_new_cells;
61 } else {
62 if (!del_bcs.contains(cell_code->GetValue(id_cell))) {
63 ++num_new_cells;
68 // copy nodes and cells
69 EG_VTKSP(vtkUnstructuredGrid, new_grid);
70 allocateGrid(new_grid, num_new_cells, m_Grid->GetNumberOfPoints());
71 vtkIdType id_new_node = 0;
72 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
73 vec3_t x;
74 m_Grid->GetPoint(id_node, x.data());
75 new_grid->GetPoints()->SetPoint(id_new_node, x.data());
76 copyNodeData(m_Grid, id_node, new_grid, id_new_node);
77 ++id_new_node;
79 vtkIdType id_new_cell;
80 EG_VTKDCC(vtkIntArray, new_cell_code, new_grid, "cell_code");
81 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
82 bool insert_cell = true;
83 if (isSurface(id_cell, m_Grid)) {
84 if (del_bcs.contains(cell_code->GetValue(id_cell))) {
85 insert_cell = false;
88 if (insert_cell) {
89 id_new_cell = copyCell(m_Grid, id_cell, new_grid);
90 copyCellData(m_Grid, id_cell, new_grid, id_new_cell);
91 if (isVolume(id_new_cell, new_grid)) {
92 new_cell_code->SetValue(id_new_cell, V1.getVC());
97 // update volume definitions
98 QList<VolumeDefinition> old_vols = GuiMainWindow::pointer()->getAllVols();
99 QList<VolumeDefinition> new_vols;
100 foreach (VolumeDefinition V, old_vols) {
101 if (V.getName() != vol_name1 && V.getName() != vol_name2) {
102 new_vols.append(V);
105 VolumeDefinition V(m_Ui.lineEditNewVol->text(), V1.getVC());
106 foreach (int bc, all_bcs) {
107 if (!del_bcs.contains(bc)) {
108 if (V1.getSign(bc) != 0) {
109 V.addBC(bc, V1.getSign(bc));
110 } else if (V2.getSign(bc) != 0) {
111 V.addBC(bc, V2.getSign(bc));
112 } else {
113 V.addBC(bc, 0);
117 new_vols.append(V);
118 GuiMainWindow::pointer()->setAllVols(new_vols);
119 makeCopy(new_grid, m_Grid);
120 GuiMainWindow::pointer()->updateBoundaryCodes(false);