138 #include <FL/Fl_Image.H> 139 #include <FL/Fl_Shared_Image.H> 140 #include <FL/Fl_PNG_Image.H> 141 #include <FL/Fl_Output.H> 142 #include <FL/Fl_Text_Display.H> 143 #include <FL/Fl_File_Chooser.H> 161 "Part of the Player Project\n" 162 "http://playerstage.org\n" 164 "Copyright 2000-2008 Richard Vaughan,\n" 165 "Brian Gerkey, Andrew Howard, Reed Hedges, \n" 166 "Toby Collett, Alex Couture-Beil, Jeremy Asher \n" 169 "Distributed under the terms of the \n" 170 "GNU General Public License v2";
173 "http://playerstage.org\n" 175 "has these resources to help you:\n" 177 "\t* A user manual including API documentation\n" 178 "\t* A bug and feature request tracking system\n" 179 "\t* Mailing lists for users and developers\n" 182 "The user manual is included with the Stage source code but\n" 183 "is not built by default. To build the manual, run \"make\"\n" 184 "in the directory \"docsrc\" to produce \"docsrc/stage/index.html\" .\n" 185 "(requires Doxygen and supporting programs to be installed first).\n";
189 canvas( new
Canvas( this,0,30,W,H-30 ) ),
194 mbar( new Fl_Menu_Bar(0,0, W, 30)),
197 real_time_interval( sim_interval ),
198 real_time_now( RealTimeNow() ),
199 real_time_recorded( real_time_now ),
200 timing_interval( 20 )
212 mbar->add(
"&File", 0, 0, 0, FL_SUBMENU );
213 mbar->add(
"File/&Load World...", FL_CTRL +
'l', (Fl_Callback*)
fileLoadCb,
this, FL_MENU_DIVIDER );
214 mbar->add(
"File/&Save World", FL_CTRL +
's', (Fl_Callback*)
fileSaveCb,
this );
217 mbar->add(
"File/E&xit", FL_CTRL+
'q', (Fl_Callback*)
fileExitCb,
this );
219 mbar->add(
"&View", 0, 0, 0, FL_SUBMENU );
223 mbar->add(
"View/Filter data...", FL_SHIFT +
'd', (Fl_Callback*)
viewOptionsCb,
this );
226 mbar->add(
"Run", 0,0,0, FL_SUBMENU );
227 mbar->add(
"Run/Pause",
'p', (Fl_Callback*)
pauseCb,
this );
228 mbar->add(
"Run/One step",
'.', (Fl_Callback*)
onceCb,
this, FL_MENU_DIVIDER );
229 mbar->add(
"Run/Faster",
']', (Fl_Callback*)
fasterCb,
this );
230 mbar->add(
"Run/Slower",
'[', (Fl_Callback*)
slowerCb,
this, FL_MENU_DIVIDER );
234 mbar->add(
"&Help", 0, 0, 0, FL_SUBMENU );
235 mbar->add(
"Help/Getting help...", 0, (Fl_Callback*)
moreHelptCb,
this, FL_MENU_DIVIDER );
236 mbar->add(
"Help/&About Stage...", 0, (Fl_Callback*)
helpAboutCb,
this );
238 callback( (Fl_Callback*)
windowCb,
this );
270 const int world_section = 0;
277 if( window_section > 0 )
279 unsigned int width = w();
280 unsigned int height = h();
281 wf->
ReadTuple(window_section,
"size", 0, 2,
"uu", &width, &height );
284 size( width,height );
285 size_range( 100, 100 );
290 std::string title = PROJECT;
296 label( title.c_str() );
299 (*it)->Load(
wf, window_section );
308 printf(
"[Load time %.3fsec]\n",
309 (load_end_time - load_start_time) / 1e6 );
324 const int world_section = 0;
331 if( window_section > 0 )
333 unsigned int width = w();
334 unsigned int height = h();
335 wf->
WriteTuple( window_section,
"size", 0, 2,
"uu", width, height );
340 (*it)->Save(
wf, window_section );
368 real_time_recorded = timenow;
376 (*it)->UpdateTrail();
391 const double localratio =
395 snprintf( buf, 32,
" [%.1f]", localratio );
399 str +=
" [ PAUSED ]";
424 snprintf( str, 255,
"Energy\n stored: %.0f / %.0f KJ\n input: %.0f KJ\n output: %.0f KJ at %.2f KW\n",
431 return std::string( str );
444 it->second->DrawOccupancy();
456 unsigned int layer(
updates % 2 );
459 it->second->DrawVoxels( layer );
464 switch ( Fl::event() ) {
466 if ( Fl::event_key() == FL_Escape )
474 puts(
"Stage: User closed window" );
480 const char* filename;
481 const char* pattern =
"World Files (*.world)";
484 worldsPath.append(
"/" );
485 Fl_File_Chooser fc( worldsPath.c_str(), pattern, Fl_File_Chooser::CREATE,
"Load World File..." );
486 fc.ok_label(
"Load" );
492 filename = fc.value();
494 if (filename != NULL) {
504 wg->
Load( filename );
508 fl_alert(
"Unable to read selected world file." );
518 const bool success = wg->
Save( NULL );
520 fl_alert(
"Error saving world file." );
533 puts(
"User exited via menu" );
542 if( Fl::event_state( FL_CTRL ) )
609 Fl::remove_timeout( (Fl_Timeout_Handler)UpdateCallback,
this );
616 Fl::add_idle( (Fl_Timeout_Handler)UpdateCallback,
this );
625 Fl::remove_idle( (Fl_Timeout_Handler)UpdateCallback,
this );
654 int x = wg->w()+wg->x() + 10;
679 switch ( Fl::event() ) {
681 if ( Fl::event_key() != FL_Escape )
702 Fl::delete_widget( oDlg );
712 btn->window()->do_callback();
717 Fl_Text_Buffer* tbuf = textDisplay->buffer();
718 textDisplay->buffer( NULL );
720 Fl::delete_widget( win );
725 const int Width = 420;
726 const int Height = 330;
728 const int ButtonH = 25;
729 const int ButtonW = 60;
733 Fl_Window* win =
new Fl_Window( Width, Height );
735 Fl_Box* box =
new Fl_Box( Spc, Spc,
740 box->image(
new Fl_PNG_Image( fullpath.c_str() ));
742 Fl_Text_Display* textDisplay =
743 new Fl_Text_Display( Spc, pngH+2*Spc,
744 Width-2*Spc, Height-pngH-ButtonH-4*Spc );
746 textDisplay->box( FL_NO_BOX );
747 textDisplay->color( win->color() );
748 win->callback( (Fl_Callback*)
aboutCloseCb, textDisplay );
750 Fl_Text_Buffer* tbuf =
new Fl_Text_Buffer;
751 tbuf->text( PROJECT );
753 tbuf->append( VERSION );
756 textDisplay->buffer( tbuf );
758 Fl_Return_Button* button =
759 new Fl_Return_Button( (Width - ButtonW)/2, Height-Spc-ButtonH,
769 const int Width = 500;
770 const int Height = 250;
773 Fl_Window* win =
new Fl_Window( Width, Height );
774 win->label(
"Getting help with Stage" );
776 Fl_Text_Display* textDisplay =
777 new Fl_Text_Display( Spc, Spc,
778 Width-2*Spc, Height-2*Spc );
780 win->resizable( textDisplay );
781 textDisplay->box( FL_NO_BOX );
782 textDisplay->color( win->color() );
784 Fl_Text_Buffer* tbuf =
new Fl_Text_Buffer();
787 textDisplay->buffer( tbuf );
795 const char* newFilename;
796 bool success =
false;
797 const char* pattern =
"World Files (*.world)";
799 Fl_File_Chooser fc(
wf->
filename.c_str(), pattern, Fl_File_Chooser::CREATE,
"Save File As..." );
800 fc.ok_label(
"Save" );
806 newFilename = fc.value();
808 if (newFilename != NULL) {
810 success =
Save( newFilename );
812 fl_alert(
"Error saving world file." );
825 choice = fl_choice(
"Quitting Stage",
828 "&Quit without saving" 854 (*it)->DrawBoundingBoxTree();
872 gettimeofday( &tv, NULL );
873 return( tv.tv_sec*1000000 + tv.tv_usec );
void aboutOKBtnCb(Fl_Return_Button *btn, void *p)
void setOptions(const std::set< Option * > &opts)
static void windowCb(Fl_Widget *w, WorldGui *wg)
static bool readable(const std::string &path)
Determine whether a file can be opened for reading.
static void moreHelptCb(Fl_Widget *w, WorldGui *wg)
static void UpdateCallback(WorldGui *world)
static void viewOptionsCb(OptionsDlg *oDlg, WorldGui *wg)
static joules_t global_input
uint64_t updates
the number of simulated time steps executed so far
int LookupEntity(const char *type)
The Stage library uses its own namespace.
virtual void AddModel(Model *mod)
static joules_t global_capacity
std::set< Option * > option_table
GUI options (toggles) registered by models.
virtual void RemoveChild(Model *mod)
void showAllOpt(Option *opt)
void DrawOccupancy() const
static void fileSaveAsCb(Fl_Widget *w, WorldGui *wg)
static const char * AboutText
static joules_t global_stored
const event_t event() const
int ReadTuple(const int entity, const char *name, const unsigned int first, const unsigned int num, const char *format,...)
static void slowerCb(Fl_Widget *w, WorldGui *wg)
void createMenuItems(Fl_Menu_Bar *menu, std::string path)
FileManager * fileMan
Used to load and save worldfiles.
void aboutCloseCb(Fl_Window *win, Fl_Text_Display *textDisplay)
static void fileLoadCb(Fl_Widget *w, WorldGui *wg)
static void optionsDlgCb(OptionsDlg *oDlg, WorldGui *wg)
virtual void Redraw(void)
virtual void RemoveChild(Model *mod)
void newWorld(const std::string &worldfile)
Update the worldfile path.
void PushColor(Color col)
static void fileExitCb(Fl_Widget *w, WorldGui *wg)
virtual void Load(const std::string &filename)
void WriteInt(int entity, const char *name, int value)
void WriteTuple(const int entity, const char *name, const unsigned int first, const unsigned int count, const char *format,...)
static void fasttimeCb(Fl_Widget *w, WorldGui *wg)
static void resetViewCb(Fl_Widget *w, WorldGui *wg)
static void pauseCb(Fl_Widget *w, WorldGui *wg)
static unsigned int trail_length
usec_t sim_time
the current sim time in this world in microseconds
virtual void AddModel(Model *mod)
virtual bool Update(void)
virtual void TogglePause()
static void realtimeCb(Fl_Widget *w, WorldGui *wg)
std::map< point_int_t, SuperRegion * > superregions
std::string EnergyString(void) const
void RemoveModel(Model *mod)
void WriteFloat(int entity, const char *name, double value)
virtual Model * RecentlySelectedModel() const
WorldGui(int W, int H, const char *L=0)
Worldfile * wf
If set, points to the worldfile used to create this world.
static void helpAboutCb(Fl_Widget *w, WorldGui *wg)
static std::string findFile(const std::string &filename)
std::vector< Model * > children
bool paused
if true, the simulation is stopped
static const char * MoreHelpText
virtual void PushColor(Color col)
static void onceCb(Fl_Widget *w, WorldGui *wg)
void AddModel(Model *mod)
#define PRINT_DEBUG1(m, a)
double ReadFloat(int entity, const char *name, double value)
usec_t real_time_recorded
void Save(Worldfile *wf, int section)
usec_t RealTimeNow(void) const
usec_t real_time_interval
void DrawBoundingBoxTree()
void Load(Worldfile *wf, int section)
int ReadInt(int entity, const char *name, int value)
std::set< ModelPosition * > active_velocity
static void fileSaveCb(Fl_Widget *w, WorldGui *wg)
virtual bool Save(const char *filename)
static uint64_t trail_interval
msec_t interval
(even if it is now unselected).
static joules_t global_dissipated
static void fasterCb(Fl_Widget *w, WorldGui *wg)
const std::string worldsRoot() const
Return the path where the current worldfile was loaded from.
virtual std::string ClockString(void) const
virtual std::string ClockString() const
virtual bool Save(const char *filename)
static void TimerCallback(Canvas *canvas)
virtual void Load(const std::string &worldfile_path)