fixed edge display for volume cells
[engrid-github.git] / src / libengrid / multisolidasciistlreader.cpp
blobd79e18c97d14a4ee2f858dc129fc428b29e760eb
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 "multisolidasciistlreader.h"
23 #include "stlreader.h"
24 #include "guimainwindow.h"
26 #include <QFileInfo>
27 #include <QInputDialog>
28 #include <QFile>
29 #include <QTextStream>
32 MultiSolidAsciiStlReader::MultiSolidAsciiStlReader()
34 setFormat("STL files(*.stl *.STL)");
37 void MultiSolidAsciiStlReader::operate()
39 QFileInfo file_info(GuiMainWindow::pointer()->getFilename());
40 readInputFileName(file_info.completeBaseName() + ".stl");
41 if (isValid()) {
42 double tol = QInputDialog::getText(NULL, "enter STL tolerance", "tolerance", QLineEdit::Normal, "1e-10").toDouble();
43 QList<QString> buffer;
44 QList<QString> bc_name;
46 QFile file(getFileName());
47 if (!file.open(QFile::ReadOnly)) {
48 EG_ERR_RETURN("unable to open file");
50 QTextStream f(&file);
51 QString buf = "";
52 QString name = "unknown";
53 while (!f.atEnd()) {
54 QString line = f.readLine();
55 buf += line + "\n"; // endline??
56 if (line.left(8) == "endsolid") {
57 buffer.append(buf);
58 buf = "";
59 bc_name.append(name);
60 } else if (line.left(5) == "solid") {
61 name = line.right(line.size() - 6);
65 bool first = true;
66 int last_bc = 1;
67 foreach (QString buf, buffer) {
68 QString file_name = getFileName() + ".tmp";
70 QFile file(file_name);
71 if (!file.open(QFile::WriteOnly)) {
72 EG_ERR_RETURN("unable to open file\"" + file_name + "\" for writing");
74 QTextStream f(&file);
75 f << buf << endl;
77 StlReader stl;
78 stl.setTolerance(tol);
79 stl.setFileName(file_name);
80 EG_VTKSP(vtkUnstructuredGrid, grid);
81 stl.setGrid(grid);
82 stl.setMaximalCleaningIterations(3);
83 stl();
85 // @todo set boundary names
86 EG_VTKDCC(vtkIntArray, bc, grid, "cell_code");
87 for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) {
88 bc->SetValue(id_cell, last_bc);
90 ++last_bc;
92 if (first) {
93 first = false;
94 makeCopy(grid, m_Grid);
95 } else {
96 MeshPartition part1(m_Grid, true);
97 MeshPartition part2(grid, true);
98 part1.addPartition(part2);
102 last_bc = 1;
103 GuiMainWindow::pointer()->resetXmlDoc();
104 GuiMainWindow::pointer()->clearBCs();
105 foreach (QString name, bc_name) {
106 GuiMainWindow::pointer()->addBC(last_bc, BoundaryCondition(name, "patch"));
107 ++last_bc;