1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
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. +
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. +
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/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "multisolidasciistlreader.h"
23 #include "stlreader.h"
24 #include "guimainwindow.h"
27 #include <QInputDialog>
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");
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");
52 QString name
= "unknown";
54 QString line
= f
.readLine();
55 buf
+= line
+ "\n"; // endline??
56 if (line
.left(8) == "endsolid") {
60 } else if (line
.left(5) == "solid") {
61 name
= line
.right(line
.size() - 6);
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");
78 stl
.setTolerance(tol
);
79 stl
.setFileName(file_name
);
80 EG_VTKSP(vtkUnstructuredGrid
, grid
);
82 stl
.setMaximalCleaningIterations(3);
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
);
94 makeCopy(grid
, m_Grid
);
96 MeshPartition
part1(m_Grid
, true);
97 MeshPartition
part2(grid
, true);
98 part1
.addPartition(part2
);
103 GuiMainWindow::pointer()->resetXmlDoc();
104 GuiMainWindow::pointer()->clearBCs();
105 foreach (QString name
, bc_name
) {
106 GuiMainWindow::pointer()->addBC(last_bc
, BoundaryCondition(name
, "patch"));