00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2019 The Board of Trustees of the 00004 *cr University of Illinois 00005 *cr All Rights Reserved 00006 *cr 00007 ***************************************************************************/ 00008 00009 #include "RenderFltkMenu.h" 00010 #include "CmdRender.h" 00011 #include <FL/Fl.H> 00012 #include <FL/forms.H> 00013 #include <FL/Fl_Window.H> 00014 #include <FL/Fl_Choice.H> 00015 #include <FL/Fl_Input.H> 00016 #include <FL/Fl_Button.H> 00017 #include <FL/Fl_Box.H> 00018 #include "VMDApp.h" 00019 00020 00021 void RenderFltkMenu::make_window() { 00022 size(330, 200); 00023 { 00024 { Fl_Choice* o = formatchoice = new Fl_Choice(15, 25, 305, 25, "Render the current scene using:"); 00025 o->down_box(FL_BORDER_BOX); 00026 o->color(VMDMENU_CHOOSER_BG, VMDMENU_CHOOSER_SEL); 00027 o->align(FL_ALIGN_TOP_LEFT); 00028 o->callback(formatchoice_cb, this); 00029 } 00030 { Fl_Input* o = filenameinput = new Fl_Input(15, 75, 235, 25, "Filename:"); 00031 o->align(FL_ALIGN_TOP_LEFT); 00032 o->selection_color(VMDMENU_VALUE_SEL); 00033 } 00034 Fl_Button *browsebutton = new Fl_Button(255, 75, 65, 25, "Browse..."); 00035 #if defined(VMDMENU_WINDOW) 00036 browsebutton->color(VMDMENU_WINDOW, FL_GRAY); 00037 #endif 00038 browsebutton->callback(browse_cb, this); 00039 { Fl_Input* o = commandinput = new Fl_Input(15, 125, 190, 25, "Render Command:"); 00040 o->align(FL_ALIGN_TOP_LEFT); 00041 o->selection_color(VMDMENU_VALUE_SEL); 00042 o->when(FL_WHEN_CHANGED); 00043 o->callback(command_cb, this); 00044 } 00045 Fl_Button *defaultbutton = new Fl_Button(210, 125, 110, 25, "Restore default"); 00046 #if defined(VMDMENU_WINDOW) 00047 defaultbutton->color(VMDMENU_WINDOW, FL_GRAY); 00048 #endif 00049 defaultbutton->callback(default_cb, this); 00050 Fl_Button *renderbutton = new Fl_Button(15, 165, 305, 25, "Start Rendering"); 00051 #if defined(VMDMENU_WINDOW) 00052 renderbutton->color(VMDMENU_WINDOW, FL_GRAY); 00053 #endif 00054 renderbutton->callback(render_cb, this); 00055 end(); 00056 } 00057 } 00058 00059 void RenderFltkMenu::fill_render_choices() { 00060 formatchoice->clear(); 00061 00062 // add all of the active FileRenderer subclasses to the GUI 00063 for (int n=0; n<app->filerender_num(); n++) 00064 formatchoice->add(app->filerender_prettyname(n)); 00065 00066 // set the chooser to the first item initially, update from there 00067 formatchoice->value(0); 00068 00069 // Make Snapshot the default renderer, if we can find it in the menu. 00070 // XXX This should be updated to use the built-in FLTK routines 00071 // for FLTK versions 1.1.7 and newer. 00072 set_chooser_from_string("Snapshot (VMD OpenGL window)", formatchoice); 00073 00074 formatchoice_cb(NULL, this); 00075 } 00076 00077 RenderFltkMenu::RenderFltkMenu(VMDApp *vmdapp) 00078 : VMDFltkMenu("render", "File Render Controls", vmdapp) { 00079 00080 make_window(); 00081 fill_render_choices(); 00082 command_wanted(Command::RENDER_OPTION); 00083 } 00084 00085 void RenderFltkMenu::formatchoice_cb(Fl_Widget *, void *v) { 00086 RenderFltkMenu *self = (RenderFltkMenu *)v; 00087 const char *pretty = self->formatchoice->text(); 00088 const char *method = self->app->filerender_shortname_from_prettyname(pretty); 00089 const char *fname = self->app->filerender_default_filename(method); 00090 const char *opt = self->app->filerender_option(method, NULL); 00091 if (fname) self->filenameinput->value(fname); 00092 if (opt) self->commandinput->value(opt); 00093 } 00094 00095 void RenderFltkMenu::command_cb(Fl_Widget *, void *v) { 00096 RenderFltkMenu *self = (RenderFltkMenu *)v; 00097 const char *pretty = self->formatchoice->text(); 00098 const char *method = self->app->filerender_shortname_from_prettyname(pretty); 00099 const char *cmd = self->commandinput->value(); 00100 if (method && cmd) self->app->filerender_option(method, cmd); 00101 } 00102 00103 void RenderFltkMenu::default_cb(Fl_Widget *, void *v) { 00104 RenderFltkMenu *self = (RenderFltkMenu *)v; 00105 const char *pretty = self->formatchoice->text(); 00106 const char *method = self->app->filerender_shortname_from_prettyname(pretty); 00107 if (method) { 00108 const char *opt = self->app->filerender_default_option(method); 00109 self->app->filerender_option(method, opt); 00110 self->commandinput->value(opt); 00111 } 00112 } 00113 00114 void RenderFltkMenu::browse_cb(Fl_Widget *, void *v) { 00115 RenderFltkMenu *self = (RenderFltkMenu *)v; 00116 char *fname = self->app->vmd_choose_file( 00117 "Select rendering output file:", "*", "All files",1); 00118 if (fname) { 00119 self->filenameinput->value(fname); 00120 delete [] fname; 00121 } 00122 } 00123 00124 void RenderFltkMenu::render_cb(Fl_Widget *w, void *v) { 00125 RenderFltkMenu *self = (RenderFltkMenu *)v; 00126 Fl_Button *renderbutton = (Fl_Button *)w; 00127 const char *pretty = self->formatchoice->text(); 00128 const char *method = self->app->filerender_shortname_from_prettyname(pretty); 00129 const char *outfile = self->filenameinput->value(); 00130 const char *outcmd = self->commandinput->value(); 00131 if (!method || !outfile || !strlen(outfile)) { 00132 fl_alert("Please select a file format and filename before rendering."); 00133 return; 00134 } 00135 renderbutton->label("Rendering in progress..."); 00136 renderbutton->value(1); 00137 Fl::wait(0); 00138 00139 int rc = self->app->filerender_render(method, outfile, outcmd); 00140 renderbutton->label("Start Rendering"); 00141 renderbutton->value(0); 00142 if (!rc) { 00143 fl_alert("File rendering failed; check the VMD text console for errors."); 00144 } 00145 } 00146 00147 int RenderFltkMenu::act_on_command(int type, Command *cmd) { 00148 if (type == Command::RENDER_OPTION) { 00149 CmdRenderOption *cmdrender = (CmdRenderOption *)cmd; 00150 const char *pretty = formatchoice->text(); 00151 const char *method = app->filerender_shortname_from_prettyname(pretty); 00152 if (!strcmp(cmdrender->method, method) && 00153 strcmp(cmdrender->option, commandinput->value())) { 00154 commandinput->value(cmdrender->option); 00155 } 00156 return TRUE; 00157 } 00158 return FALSE; 00159 } 00160 00161