Skip to content

Commit bffb308

Browse files
committed
fixed file dialog from both inspector and object config menu
1 parent efede3f commit bffb308

File tree

16 files changed

+273
-4
lines changed

16 files changed

+273
-4
lines changed

src/objects/computer_vision/HaarTracking.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ void HaarTracking::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRend
192192

193193
//--------------------------------------------------------------
194194
void HaarTracking::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
195+
loadHaarConfigFlag = false;
195196

196197
// CONFIG GUI inside Menu
197198
if(_nodeCanvas.BeginNodeMenu()){
@@ -260,6 +261,18 @@ void HaarTracking::drawObjectNodeConfig(){
260261
ImGuiEx::ObjectInfo(
261262
"Detects shapes with specific characteristics or structures within images or video frames.",
262263
"https://mosaic.d3cod3.org/reference.php?r=haar-tracking", scaleFactor);
264+
265+
// file dialog
266+
if(ImGuiEx::getFileDialog(fileDialog, loadHaarConfigFlag, "Select haarcascade xml file", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".xml", "", scaleFactor)){
267+
ofFile file (fileDialog.selected_path);
268+
if (file.exists()){
269+
filepath = copyFileToPatchFolder(this->patchFolderPath,file.getAbsolutePath());
270+
haarFinder->setup(filepath);
271+
272+
size_t start = file.getFileName().find_first_of("_");
273+
haarfileName = file.getFileName().substr(start+1,file.getFileName().size()-start-5);
274+
}
275+
}
263276
}
264277

265278
//--------------------------------------------------------------

src/objects/data/DataToFile.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void DataToFile::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRender
113113

114114
//--------------------------------------------------------------
115115
void DataToFile::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
116+
exportFileFlag = false;
116117

117118
// CONFIG GUI inside Menu
118119
if(_nodeCanvas.BeginNodeMenu()){
@@ -211,6 +212,17 @@ void DataToFile::drawObjectNodeConfig(){
211212
ImGuiEx::ObjectInfo(
212213
"Saves the vector data in a .txt file, line by line for each computing frame.",
213214
"https://mosaic.d3cod3.org/reference.php?r=data-to-file", scaleFactor);
215+
216+
// file dialog
217+
if(ImGuiEx::getFileDialog(fileDialog, exportFileFlag, "Export new data file as", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ".txt", "data.txt", scaleFactor)){
218+
ofFile file (fileDialog.selected_path);
219+
if (!file.exists()){
220+
file.create();
221+
}
222+
filepath = checkFileExtension(file.getAbsolutePath(), ofToUpper(file.getExtension()), "TXT");
223+
tmpFileName = file.getFileName();
224+
fileSaved = true;
225+
}
214226
}
215227

216228
//--------------------------------------------------------------

src/objects/data/FileToData.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ void FileToData::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRender
109109

110110
//--------------------------------------------------------------
111111
void FileToData::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
112+
openFileFlag = false;
112113

113114
// CONFIG GUI inside Menu
114115
if(_nodeCanvas.BeginNodeMenu()){
@@ -171,6 +172,15 @@ void FileToData::drawObjectNodeConfig(){
171172
ImGuiEx::ObjectInfo(
172173
"Loads a txt file, previously saved by the 'data to file' object, and return the vector data, line by line, with reading synced by his bang inlet.",
173174
"https://mosaic.d3cod3.org/reference.php?r=file-to-data", scaleFactor);
175+
176+
// file dialog
177+
if(ImGuiEx::getFileDialog(fileDialog, openFileFlag, "Open a previously saved Mosaic data file", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".txt", "", scaleFactor)){
178+
ofLog(OF_LOG_NOTICE,"START IMPORTING DATA");
179+
ofFile file (fileDialog.selected_path);
180+
tmpFileName = file.getFileName();
181+
filepath = file.getAbsolutePath();
182+
loadDataFile(filepath);
183+
}
174184
}
175185

176186
//--------------------------------------------------------------

src/objects/graphics/ImageExporter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void ImageExporter::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRen
117117

118118
//--------------------------------------------------------------
119119
void ImageExporter::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
120+
saveImgFlag = false;
120121

121122
// CONFIG GUI inside Menu
122123
if(_nodeCanvas.BeginNodeMenu()){
@@ -195,6 +196,13 @@ void ImageExporter::drawObjectNodeConfig(){
195196
ImGuiEx::ObjectInfo(
196197
"Export an image or image sequence (using ### for auto-numeration) from every texture cable (blue ones).",
197198
"https://mosaic.d3cod3.org/reference.php?r=image-exporter", scaleFactor);
199+
200+
// file dialog
201+
if(ImGuiEx::getFileDialog(fileDialog, saveImgFlag, "Save image", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ".jpg,.jpeg,.gif,.png,.tif,.tiff", "imageExport.jpg", scaleFactor)){
202+
lastImageFile = fileDialog.selected_path;
203+
filepath = lastImageFile;
204+
isImageSaved= true;
205+
}
198206
}
199207

200208
//--------------------------------------------------------------

src/objects/graphics/ImageLoader.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void ImageLoader::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRende
127127

128128
//--------------------------------------------------------------
129129
void ImageLoader::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
130+
loadImgFlag = false;
130131

131132
// CONFIG GUI inside Menu
132133
if(_nodeCanvas.BeginNodeMenu()){
@@ -192,6 +193,16 @@ void ImageLoader::drawObjectNodeConfig(){
192193
ImGuiEx::ObjectInfo(
193194
"Simple object for loading image files. Compatible formats are jpg, png, gif and tif.",
194195
"https://mosaic.d3cod3.org/reference.php?r=image-loader", scaleFactor);
196+
197+
// file dialog
198+
if(ImGuiEx::getFileDialog(fileDialog, loadImgFlag, "Select image", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".jpg,.jpeg,.gif,.png,.tif,.tiff", "", scaleFactor)){
199+
ofFile file (fileDialog.selected_path);
200+
if (file.exists()){
201+
filepath = copyFileToPatchFolder(this->patchFolderPath,file.getAbsolutePath());
202+
isImageLoaded= true;
203+
isFileLoaded = false;
204+
}
205+
}
195206
}
196207

197208
//--------------------------------------------------------------

src/objects/scripting/BashScript.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ void BashScript::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRender
160160

161161
//--------------------------------------------------------------
162162
void BashScript::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
163+
loadScriptFlag = false;
164+
saveScriptFlag = false;
163165

164166
// CONFIG GUI inside Menu
165167
if(_nodeCanvas.BeginNodeMenu()){
@@ -240,6 +242,24 @@ void BashScript::drawObjectNodeConfig(){
240242
ImGuiEx::ObjectInfo(
241243
"Load and run a bash script files (Bourne-Again SHell). You can type code with the Mosaic code editor, or with the default code editor on your computer.",
242244
"https://mosaic.d3cod3.org/reference.php?r=bash-script", scaleFactor);
245+
246+
// file dialog
247+
string newFileName = "bashScript_"+ofGetTimestampString("%y%m%d")+".sh";
248+
if(ImGuiEx::getFileDialog(fileDialog, saveScriptFlag, "Save new bash script as", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ".sh", newFileName, scaleFactor)){
249+
ofFile fileToRead(ofToDataPath("scripts/empty.sh"));
250+
ofFile newBashFile (fileDialog.selected_path);
251+
ofFile::copyFromTo(fileToRead.getAbsolutePath(),checkFileExtension(newBashFile.getAbsolutePath(), ofToUpper(newBashFile.getExtension()), "SH"),true,true);
252+
filepath = copyFileToPatchFolder(this->patchFolderPath,checkFileExtension(newBashFile.getAbsolutePath(), ofToUpper(newBashFile.getExtension()), "SH"));
253+
threadLoaded = false;
254+
reloadScript();
255+
}
256+
257+
if(ImGuiEx::getFileDialog(fileDialog, loadScriptFlag, "Select a bash script", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".sh", "", scaleFactor)){
258+
ofFile bashFile (fileDialog.selected_path);
259+
filepath = copyFileToPatchFolder(this->patchFolderPath,bashFile.getAbsolutePath());
260+
threadLoaded = false;
261+
reloadScript();
262+
}
243263
}
244264

245265
//--------------------------------------------------------------

src/objects/scripting/LuaScript.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ void LuaScript::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRendere
277277
//--------------------------------------------------------------
278278
void LuaScript::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
279279

280+
loadLuaScriptFlag = false;
281+
saveLuaScriptFlag = false;
282+
280283
// CONFIG GUI inside Menu
281284
if(_nodeCanvas.BeginNodeMenu()){
282285

@@ -371,6 +374,18 @@ void LuaScript::drawObjectNodeConfig(){
371374
ImGuiEx::ObjectInfo(
372375
"This object is a live-coding lua script container, with OF bindings mimicking the OF programming structure. You can type code with the Mosaic code editor, or with the default code editor on your computer",
373376
"https://mosaic.d3cod3.org/reference.php?r=lua-script", scaleFactor);
377+
378+
// file dialog
379+
string newFileName = "luaScript_"+ofGetTimestampString("%y%m%d")+".lua";
380+
if(ImGuiEx::getFileDialog(fileDialog, saveLuaScriptFlag, "Save new Lua script as", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ".lua", newFileName, scaleFactor)){
381+
lastLuaScript = fileDialog.selected_path;
382+
luaScriptSaved = true;
383+
}
384+
385+
if(ImGuiEx::getFileDialog(fileDialog, loadLuaScriptFlag, "Select a lua script", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".lua", "", scaleFactor)){
386+
lastLuaScript = fileDialog.selected_path;
387+
luaScriptLoaded = true;
388+
}
374389
}
375390

376391
//--------------------------------------------------------------

src/objects/scripting/PythonScript.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ void PythonScript::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRend
156156

157157
//--------------------------------------------------------------
158158
void PythonScript::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
159+
loadPythonScriptFlag = false;
160+
savePythonScriptFlag = false;
159161

160162
// CONFIG GUI inside Menu
161163
if(_nodeCanvas.BeginNodeMenu()){
@@ -249,6 +251,26 @@ void PythonScript::drawObjectNodeConfig(){
249251
ImGuiEx::ObjectInfo(
250252
"Load and run a python ( 2.7 ) script files. You can type code with the Mosaic code editor, or with the default code editor on your computer.",
251253
"https://mosaic.d3cod3.org/reference.php?r=python-script", scaleFactor);
254+
255+
// file dialog
256+
string newFileName = "pythonScript_"+ofGetTimestampString("%y%m%d")+".py";
257+
if(ImGuiEx::getFileDialog(fileDialog, savePythonScriptFlag, "Save new python script as", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ".py", newFileName, scaleFactor)){
258+
lastPythonScript = fileDialog.selected_path;
259+
260+
ofFile fileToRead(ofToDataPath("scripts/empty.py"));
261+
ofFile newPyFile (lastPythonScript);
262+
ofFile::copyFromTo(fileToRead.getAbsolutePath(),checkFileExtension(newPyFile.getAbsolutePath(), ofToUpper(newPyFile.getExtension()), "PY"),true,true);
263+
filepath = copyFileToPatchFolder(this->patchFolderPath,checkFileExtension(newPyFile.getAbsolutePath(), ofToUpper(newPyFile.getExtension()), "PY"));
264+
reloadScript();
265+
}
266+
267+
if(ImGuiEx::getFileDialog(fileDialog, loadPythonScriptFlag, "Select a python script", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".py", "", scaleFactor)){
268+
lastPythonScript = fileDialog.selected_path;
269+
270+
ofFile file (lastPythonScript);
271+
filepath = copyFileToPatchFolder(this->patchFolderPath,file.getAbsolutePath());
272+
reloadScript();
273+
}
252274
}
253275

254276
//--------------------------------------------------------------

src/objects/scripting/ShaderObject.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ void ShaderObject::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRend
307307

308308
//--------------------------------------------------------------
309309
void ShaderObject::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
310-
310+
loadShaderScriptFlag = false;
311+
saveShaderScriptFlag = false;
311312

312313
// CONFIG GUI inside Menu
313314
if(_nodeCanvas.BeginNodeMenu()){
@@ -422,6 +423,18 @@ void ShaderObject::drawObjectNodeConfig(){
422423
ImGuiEx::ObjectInfo(
423424
"This object is a live-coding lua script container, with OF bindings mimicking the OF programming structure. You can type code with the Mosaic code editor, or with the default code editor on your computer",
424425
"https://mosaic.d3cod3.org/reference.php?r=lua-script", scaleFactor);
426+
427+
// file dialog
428+
string newFileName = "glslshader_"+ofGetTimestampString("%y%m%d")+".frag";
429+
if(ImGuiEx::getFileDialog(fileDialog, saveShaderScriptFlag, "Save new GLSL shader as", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ".frag", newFileName, scaleFactor)){
430+
lastShaderScript = fileDialog.selected_path;
431+
shaderScriptSaved = true;
432+
}
433+
434+
if(ImGuiEx::getFileDialog(fileDialog, loadShaderScriptFlag, "Select a GLSL shader", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ".frag,.vert", "", scaleFactor)){
435+
lastShaderScript = fileDialog.selected_path;
436+
shaderScriptLoaded = true;
437+
}
425438
}
426439

427440
//--------------------------------------------------------------

src/objects/sound/AudioExporter.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void AudioExporter::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRen
119119
//--------------------------------------------------------------
120120
void AudioExporter::drawObjectNodeGui( ImGuiEx::NodeCanvas& _nodeCanvas ){
121121

122-
122+
exportAudioFlag = false;
123123

124124
// CONFIG GUI inside Menu
125125
if(_nodeCanvas.BeginNodeMenu()){
@@ -238,6 +238,33 @@ void AudioExporter::drawObjectNodeConfig(){
238238
ImGuiEx::ObjectInfo(
239239
"Export audio from every sound buffer cable (yellow ones). Export format is fixed to 320 kb mp3.",
240240
"https://mosaic.d3cod3.org/reference.php?r=audio-exporter", scaleFactor);
241+
242+
// file dialog
243+
#if defined(TARGET_WIN32)
244+
if(ImGuiEx::getFileDialog(fileDialog, exportAudioFlag, "Export audio", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ".mp3", "audioExport.mp3", scaleFactor)){
245+
filepath = fileDialog.selected_path;
246+
// check extension
247+
if(fileDialog.ext != "mp3"){
248+
filepath += ".mp3";
249+
}
250+
recorder.setOutputPath(filepath);
251+
// prepare blank audio file
252+
recorder.startCustomAudioRecord();
253+
recorder.stop();
254+
}
255+
#else
256+
if(ImGuiEx::getFileDialog(fileDialog, exportAudioFlag, "Export audio", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ".mp3", "audioExport.mp3", scaleFactor)){
257+
filepath = fileDialog.selected_path;
258+
// check extension
259+
if(fileDialog.ext != "mp3"){
260+
filepath += ".mp3";
261+
}
262+
recorder.setOutputPath(filepath);
263+
// prepare blank audio file
264+
recorder.startCustomAudioRecord();
265+
recorder.stop();
266+
}
267+
#endif
241268
}
242269

243270
//--------------------------------------------------------------

0 commit comments

Comments
 (0)