Skip to content

Commit 95da348

Browse files
committed
- Enhanced TUIKIT with new features including tab orientation for TUITabWidget and read-only modes for various input widgets.
- Improved event handling and UI responsiveness. - Add OpenFoam TUI example.
1 parent a79b638 commit 95da348

21 files changed

Lines changed: 838 additions & 87 deletions

CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.15)
22
project(TUIFramework VERSION 0.2 LANGUAGES CXX)
33

4-
set(CMAKE_CXX_STANDARD 17)
4+
set(CMAKE_CXX_STANDARD 20) # 17 is also fine, but 20 is more modern
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_CXX_EXTENSIONS OFF)
77

@@ -134,6 +134,11 @@ set(EXAMPLE_2_SOURCES
134134
examples/example_2.cpp
135135
)
136136

137+
set(OPENFOAM_TUI_SOURCES
138+
examples/openfoam_tui/openfoam_tui.cpp
139+
examples/openfoam_tui/OpenFoamParameters.cpp
140+
)
141+
137142
set(FTXUI_TEST_SOURCES
138143
examples/ftxui_test.cpp
139144
)
@@ -164,6 +169,14 @@ target_link_libraries(example_1 PRIVATE tuikit)
164169
add_executable(example_2 ${EXAMPLE_2_SOURCES})
165170
target_link_libraries(example_2 PRIVATE tuikit)
166171

172+
# =============================================================================
173+
# OPENFOAM TUI EXECUTABLE
174+
# =============================================================================
175+
176+
add_executable(openfoam_tui ${OPENFOAM_TUI_SOURCES})
177+
target_link_libraries(openfoam_tui PRIVATE tuikit)
178+
179+
167180

168181

169182
# =============================================================================

examples/example_1.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,21 @@ int main() {
5959
input_label->setText("Input: " + new_text);
6060
});
6161

62+
// auto read_only_text_field = textfield("This is read-only");
63+
// read_only_text_field->setReadOnly(true);
64+
65+
auto text_area_widget = textarea("Enter multiline text here", "", 2);
66+
// auto read_only_text_area = textarea("This is a read-only textarea");
67+
// read_only_text_area->setReadOnly(true);
68+
6269
auto button_widget = button("Show Input");
6370
button_widget->setIcon(ICON::Rocket);
6471
connect(button_widget, &slots, &AppSlots::handleButtonClick);
6572

6673
input_button_layout->addWidget(text_field_widget);
74+
// input_button_layout->addWidget(read_only_text_field);
75+
input_button_layout->addWidget(text_area_widget);
76+
// input_button_layout->addWidget(read_only_text_area);
6777
input_button_layout->addWidget(button_widget);
6878

6979
auto input_button_group = vbox();
@@ -281,6 +291,16 @@ int main() {
281291
advanced_widgets_content->addWidget(left_advanced_group);
282292
advanced_widgets_content->addWidget(right_advanced_group);
283293

294+
// --- Vertical Tab Widget Example ---
295+
auto vertical_tab_content_1 = vbox();
296+
vertical_tab_content_1->addWidget(label("Content for Vertical Tab 1"));
297+
auto vertical_tab_content_2 = vbox();
298+
vertical_tab_content_2->addWidget(label("Content for Vertical Tab 2"));
299+
300+
auto vertical_tab_widget = tabwidget(TabOrientation::Vertical);
301+
vertical_tab_widget->addTab("Vert Tab 1", vertical_tab_content_1);
302+
vertical_tab_widget->addTab("Vert Tab 2", vertical_tab_content_2);
303+
284304
// --- Tab Widget ---
285305
auto tab_widget = tabwidget();
286306
tab_widget->addTab("Main Widgets", main_widgets_content, ICON::Home);
@@ -289,6 +309,7 @@ int main() {
289309
tab_widget->addTab("Form & Status", form_status_tab_content, ICON::Tasks);
290310
tab_widget->addTab("Toolbar", toolbar_tab_content, ICON::NewFile);
291311
tab_widget->addTab("Advanced Widgets", advanced_widgets_content, ICON::Tasks);
312+
tab_widget->addTab("Vertical Tabs", vertical_tab_widget, ICON::Tasks);
292313

293314
// --- Main Layout ---
294315
auto main_layout = vbox();
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
#include "OpenFoamParameters.h"
2+
#include <iostream>
3+
#include <fstream>
4+
#include <filesystem>
5+
6+
namespace OpenFoamTUI
7+
{
8+
9+
namespace fs = std::filesystem;
10+
11+
void OpenFoamParameters::writeOpenFoamFiles(const std::string &output_dir) const
12+
{
13+
std::cout << "Writing OpenFoam files to: " << output_dir << std::endl;
14+
15+
fs::path case_path = output_dir;
16+
fs::create_directories(case_path);
17+
fs::create_directories(case_path / "0");
18+
fs::create_directories(case_path / "constant");
19+
fs::create_directories(case_path / "system");
20+
21+
// Write controlDict
22+
std::ofstream controlDictFile(case_path / "system" / "controlDict");
23+
controlDictFile <<
24+
R"(/*--------------------------------*- C++ -*----------------------------------*\
25+
| ========= | |
26+
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
27+
| \\ / O peration | Version: v2312 |
28+
| \\ / A nd | Website: www.OpenFOAM.com |
29+
| \\/ M anipulation | |
30+
*-------------------------------------------------------------------------------*/
31+
FoamFile
32+
{
33+
format ascii;
34+
class dictionary;
35+
location "system";
36+
object controlDict;
37+
}
38+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39+
40+
application )" << solverType
41+
<< R"(;
42+
43+
startFrom startTime;
44+
45+
startTime )" << startTime
46+
<< R"(;
47+
48+
stopAt endTime;
49+
50+
endTime )" << endTime
51+
<< R"(;
52+
53+
deltaT )" << deltaT
54+
<< R"(;
55+
56+
writeControl timeStep;
57+
58+
writeInterval )" << writeInterval
59+
<< R"(;
60+
61+
purgeWrite 0;
62+
63+
writeFormat ascii;
64+
65+
writePrecision 6;
66+
67+
writeCompression off;
68+
69+
runTimeModifiable true;
70+
71+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72+
)";
73+
controlDictFile.close();
74+
75+
// Write transportProperties
76+
std::ofstream transportPropertiesFile(case_path / "constant" / "transportProperties");
77+
transportPropertiesFile <<
78+
R"(/*--------------------------------*- C++ -*----------------------------------*\
79+
| ========= | |
80+
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
81+
| \\ / O peration | Version: v2312 |
82+
| \\ / A nd | Website: www.OpenFOAM.com |
83+
| \\/ M anipulation | |
84+
*-------------------------------------------------------------------------------*\
85+
FoamFile
86+
{
87+
format ascii;
88+
class dictionary;
89+
location "constant";
90+
object transportProperties;
91+
}
92+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93+
94+
)" << (flowType == "Incompressible" ? "nu nu [0 2 -1 0 0 0 0] " + std::to_string(nu_value) + ";" : "")
95+
<< "\n";
96+
transportPropertiesFile.close();
97+
98+
// Write 0/U
99+
std::ofstream UFile(case_path / "0" / "U");
100+
UFile << R"(FoamFile
101+
{
102+
format ascii;
103+
class volVectorField;
104+
object U;
105+
}
106+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107+
108+
dimensions [0 1 -1 0 0 0 0];
109+
110+
internalField uniform ()"
111+
<< U_x << " " << U_y << " " << U_z << R"();
112+
113+
boundaryField
114+
{
115+
// Placeholder for boundary conditions
116+
defaultFaces
117+
{
118+
type empty;
119+
}
120+
}
121+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122+
)";
123+
UFile.close();
124+
125+
// Write 0/p
126+
std::ofstream pFile(case_path / "0" / "p");
127+
pFile << R"(FoamFile
128+
{
129+
format ascii;
130+
class volScalarField;
131+
object p;
132+
}
133+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134+
135+
dimensions [0 2 -2 0 0 0 0];
136+
137+
internalField uniform )"
138+
<< p_init << R"(;
139+
140+
boundaryField
141+
{
142+
// Placeholder for boundary conditions
143+
defaultFaces
144+
{
145+
type empty;
146+
}
147+
}
148+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149+
)";
150+
pFile.close();
151+
152+
// Write 0/T (if compressible)
153+
if (flowType == "Compressible")
154+
{
155+
std::ofstream TFile(case_path / "0" / "T");
156+
TFile << R"(FoamFile
157+
{
158+
format ascii;
159+
class volScalarField;
160+
object T;
161+
}
162+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163+
164+
dimensions [0 0 0 1 0 0 0];
165+
166+
internalField uniform )"
167+
<< T_init << R"(;
168+
169+
boundaryField
170+
{
171+
// Placeholder for boundary conditions
172+
defaultFaces
173+
{
174+
type empty;
175+
}
176+
}
177+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178+
)";
179+
TFile.close();
180+
}
181+
182+
} // namespace OpenFoamTUI
183+
184+
} // namespace OpenFoamTUI
185+
186+
// Move the definition of readOpenFoamFiles outside of writeOpenFoamFiles
187+
namespace OpenFoamTUI
188+
{
189+
bool OpenFoamParameters::readOpenFoamFiles(const std::string &case_dir)
190+
{
191+
std::cout << "Reading OpenFoam files from: " << case_dir << std::endl;
192+
193+
fs::path case_path = case_dir;
194+
if (!fs::exists(case_path) || !fs::is_directory(case_path))
195+
{
196+
std::cerr << "Error: Case directory not found: " << case_dir << std::endl;
197+
return false;
198+
}
199+
200+
caseName = case_path.filename().string();
201+
202+
// Read controlDict
203+
fs::path controlDictPath = case_path / "system" / "controlDict";
204+
if (fs::exists(controlDictPath))
205+
{
206+
std::ifstream controlDictFile(controlDictPath);
207+
std::string line;
208+
while (std::getline(controlDictFile, line))
209+
{
210+
if (line.find("application") != std::string::npos)
211+
{
212+
size_t start = line.find("application") + std::string("application").length();
213+
size_t end = line.find(";", start);
214+
solverType = line.substr(start, end - start);
215+
solverType.erase(0, solverType.find_first_not_of(" \t")); // Trim leading whitespace
216+
solverType.erase(solverType.find_last_not_of(" \t") + 1); // Trim trailing whitespace
217+
}
218+
else if (line.find("startTime") != std::string::npos && line.find("startFrom") == std::string::npos)
219+
{
220+
size_t start = line.find("startTime") + std::string("startTime").length();
221+
size_t end = line.find(";", start);
222+
startTime = std::stod(line.substr(start, end - start));
223+
}
224+
else if (line.find("endTime") != std::string::npos)
225+
{
226+
size_t start = line.find("endTime") + std::string("endTime").length();
227+
size_t end = line.find(";", start);
228+
endTime = std::stod(line.substr(start, end - start));
229+
}
230+
else if (line.find("deltaT") != std::string::npos)
231+
{
232+
size_t start = line.find("deltaT") + std::string("deltaT").length();
233+
size_t end = line.find(";", start);
234+
deltaT = std::stod(line.substr(start, end - start));
235+
}
236+
else if (line.find("writeInterval") != std::string::npos)
237+
{
238+
size_t start = line.find("writeInterval") + std::string("writeInterval").length();
239+
size_t end = line.find(";", start);
240+
writeInterval = std::stod(line.substr(start, end - start));
241+
}
242+
}
243+
}
244+
245+
// Read transportProperties
246+
fs::path transportPropertiesPath = case_path / "constant" / "transportProperties";
247+
if (fs::exists(transportPropertiesPath))
248+
{
249+
std::ifstream transportPropertiesFile(transportPropertiesPath);
250+
std::string line;
251+
while (std::getline(transportPropertiesFile, line))
252+
{
253+
if (line.find("nu") != std::string::npos)
254+
{
255+
size_t start = line.find("nu") + std::string("nu").length();
256+
size_t end = line.find(";", start);
257+
nu_value = std::stod(line.substr(start, end - start));
258+
flowType = "Incompressible"; // Assume incompressible if nu is found
259+
}
260+
}
261+
}
262+
263+
std::cout << "Case parameters read: " << caseName << std::endl;
264+
return true;
265+
}
266+
} // namespace OpenFoamTUI

0 commit comments

Comments
 (0)