compiles on openSUSE 15.4 part 2
[engrid-github.git] / src / libengrid / deletepickedpoint.cpp
blobc6780fb1b0cf30c2b4aed3d842b1a979226e4175
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "deletepickedpoint.h"
24 #include <QObject>
25 #include <QVector>
27 #include "guimainwindow.h"
29 DeletePickedPoint::DeletePickedPoint() : RemovePoints()
31 EG_TYPENAME;
32 //Activate undo/redo
33 setQuickSave(true);
36 void DeletePickedPoint::operate()
38 vtkIdType id_node = GuiMainWindow::pointer()->getPickedPoint();
39 cout << "You picked " << id_node << endl;
40 if( id_node<0 || GuiMainWindow::pointer()->getPickedObject()!=1 ) {
41 QApplication::restoreOverrideCursor();
42 EG_ERR_RETURN("Error: No node picked.");
45 char type;
46 QVector <vtkIdType> PSP;
48 //IMPORTANT: to make sure only unselected nodes become fixed (redundant with previous line, but more readable)
49 this->m_BoundaryCodes = GuiMainWindow::pointer()->getAllBoundaryCodes();
50 qWarning()<<"m_BoundaryCodes="<<m_BoundaryCodes;
52 updateNodeInfo();
54 QMessageBox msgBox;
55 msgBox.setText("Delete point?");
56 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
57 switch (msgBox.exec()) {
58 case QMessageBox::Yes:
59 cout<<"yes was clicked"<<endl;
60 DeletePoint(id_node);
61 break;
62 case QMessageBox::No:
63 cout<<"no was clicked"<<endl;
64 cout<<"=== Topological neighbours ==="<<endl;
65 PSP = getPotentialSnapPoints(id_node);
66 cout<<"id_node="<<id_node<<" PSP="<<PSP<<endl;
68 cout<<"=== NODE TYPE ==="<<endl;
69 type = getNodeType(id_node);
70 cout<<"id_node="<<id_node<<" is of type="<<(int)type<<"="<<VertexType2Str(type)<<endl;
72 break;
73 default:
74 // should never be reached
75 break;
80 bool DeletePickedPoint::DeletePoint(vtkIdType id_node)
82 EG_BUG;
85 int N1 = m_Grid->GetNumberOfPoints();
87 QVector<vtkIdType> selected_cells;
88 getSurfaceCells(m_BoundaryCodes, selected_cells, m_Grid);
89 QVector<vtkIdType> selected_nodes;
90 getNodesFromCells(selected_cells, selected_nodes, m_Grid);
92 setAllSurfaceCells();
93 l2l_t n2n = getPartN2N();
94 g2l_t _nodes = getPartLocalNodes();
95 l2g_t nodes = getPartNodes();
97 updateNodeInfo();
99 EG_VTKDCN(vtkCharArray, node_type, m_Grid, "node_type" );
100 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code" );
101 EG_VTKDCN(vtkDoubleArray, characteristic_length_desired, m_Grid, "node_meshdensity_desired" );
103 // global values
104 QVector <vtkIdType> all_deadcells;
105 QVector <vtkIdType> all_mutatedcells;
106 int num_newpoints = 0;
107 int num_newcells = 0;
109 QVector <bool> marked_nodes(nodes.size(), false);
111 QVector <vtkIdType> deadnode_vector;
112 QVector <vtkIdType> snappoint_vector;
114 if (node_type->GetValue(id_node) != EG_FIXED_VERTEX) {
115 // local values
116 QVector <vtkIdType> dead_cells;
117 QVector <vtkIdType> mutated_cells;
118 int l_num_newpoints = 0;
119 int l_num_newcells = 0;
121 setDebugLevel(11);
122 vtkIdType snap_point = findSnapPoint(id_node, dead_cells, mutated_cells, l_num_newpoints, l_num_newcells, marked_nodes);
123 qDebug()<<"snap_point="<<snap_point;
124 setDebugLevel(0);
126 if(snap_point >= 0) {
127 // add deadnode/snappoint pair
128 deadnode_vector.push_back(id_node);
129 snappoint_vector.push_back(snap_point);
130 // update global values
131 num_newpoints += l_num_newpoints;
132 num_newcells += l_num_newcells;
133 all_deadcells += dead_cells;
134 all_mutatedcells += mutated_cells;
135 // mark neighbour nodes
136 // foreach(int i_node_neighbour, n2n[_nodes[id_node]]) {
137 // marked_nodes[nodes[i_node_neighbour]] = true;
138 // }
142 //delete
143 if(num_newpoints != -deadnode_vector.size()) EG_BUG;
144 if(num_newcells != -all_deadcells.size()) EG_BUG;
145 deleteSetOfPoints(deadnode_vector, snappoint_vector, all_deadcells, all_mutatedcells);
147 int N2 = m_Grid->GetNumberOfPoints();
148 m_NumRemoved = N1 - N2;
150 createIndices(m_Grid);
152 return( m_NumRemoved == 1 );
154 return false;