// exportwin.cpp -- the export option window // // Written by Frederic Bouvier, started September 2004. // // Copyright (C) 2004 Frederic Bouvier - fredb@users.sourceforge.net // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id: exportwin.cpp,v 1.2 2005/05/09 07:01:51 fredb Exp $ #ifdef _MSC_VER # pragma warning( disable: 4800 ) #endif #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include "exportwin.hpp" #include "bobject.hpp" #include "messwin.hpp" #include "preferences.hpp" #include "sdutil.hpp" FGSD_ExportWindow::FGSD_ExportWindow( FGSD_Preferences &__prefs ) : _prefs( __prefs ) { FGSD_Util::splitPath( _prefs.outputPath(), _dirlist, ';' ); if ( _dirlist.size() > 0 ) { _dirname = *_dirlist.begin(); } _window = new FGSD_Window( 500, 260, "Export scenery" ); _window->begin(); _outputPath = new Flu_Combo_List( 100, 10, 390, 30, "Output path :" ); for ( std::list::iterator it = _dirlist.begin(); it != _dirlist.end(); ++it ) { _outputPath->list.add( it->c_str() ); } _outputPath->value( _dirname.c_str() ); _outputPath->list.add( "" ); _outputPath->list.add( "" ); _outputPath->input.when( FL_WHEN_CHANGED | FL_WHEN_NOT_CHANGED ); _outputPath->input_callback( &FGSD_ExportWindow::input_cb, this ); _outputPath->callback( &FGSD_ExportWindow::combo_cb, this ); Flu_Simple_Group *o = new Flu_Simple_Group( 10, 50, 170, 150, "Filter" ); o->box( FL_ENGRAVED_BOX ); o->begin(); _objectBase = new Fl_Check_Button( 20, 70, 150, 30, "OBJECT_BASE" ); _objectBase->value( 1 ); _object = new Fl_Check_Button( 20, 100, 150, 30, "OBJECT" ); _object->value( 1 ); _objectStatic = new Fl_Check_Button( 20, 130, 150, 30, "OBJECT_STATIC" ); _objectStatic->value( 1 ); _objectShared = new Fl_Check_Button( 20, 160, 150, 30, "OBJECT_SHARED" ); _objectShared->value( 1 ); o->end(); _format = new Flu_Combo_List( 250, 60, 240, 30, "Format :" ); _format->editable( false ); _format->pop_height( 50 ); _format->list.add( "TerraGear" ); _format->list.add( "Ascii" ); _format->value( "TerraGear" ); _force = new Fl_Check_Button( 250, 100, 150, 30, "Force" ); _force->value( 0 ); _ok = new Fl_Button( 10, 220, 40, 30, "Ok" ); _ok->callback( &FGSD_ExportWindow::ok_cb, this ); if ( _dirname.empty() ) { _ok->deactivate(); } _cancel = new Fl_Button( 60, 220, 60, 30, "Cancel" ); _cancel->callback( &FGSD_ExportWindow::cancel_cb, this ); _window->end(); _window->callback( &FGSD_ExportWindow::cancel_cb, this ); } FGSD_ExportWindow::~FGSD_ExportWindow() { delete _window; } void FGSD_ExportWindow::combo_cb( Fl_Widget *o, void *v ) { static_cast( v )->combo_cb(); } void FGSD_ExportWindow::combo_cb() { if ( strcmp( _outputPath->value(), "" ) == 0 ) { Fl::add_timeout( 0.05, timeout_cb, this ); _outputPath->value( _dirname.c_str() ); if ( _dirname != _outputPath->value() ) { _outputPath->input.value( _dirname.c_str() ); } } else if ( strcmp( _outputPath->value(), "" ) == 0 ) { int n = 0; for( int i = 1; i <= _outputPath->list.size(); i++ ) { if( strcmp( _outputPath->list.text(i), _dirname.c_str() ) == 0 ) { n = i; } } if ( n != 0 ) { _outputPath->list.remove( n ); int nb = _outputPath->list.size(); if ( nb <= 2 ) { _outputPath->input.value( "" ); _dirname = ""; _ok->deactivate(); } else { if ( n > nb - 2 ) { n -= 1; } _dirname = _outputPath->list.text( n ); _outputPath->value( _dirname.c_str() ); _ok->activate(); } } else { _dirname = ""; _outputPath->input.value( "" ); _ok->deactivate(); } } else { _dirname = _outputPath->value(); _ok->activate(); } } void FGSD_ExportWindow::input_cb( Fl_Widget *o, void *v ) { static_cast( v )->input_cb(); } void FGSD_ExportWindow::input_cb() { _dirname = _outputPath->input.value(); if ( _dirname.empty() ) { _ok->deactivate(); } else { _ok->activate(); } } void FGSD_ExportWindow::timeout_cb( void *v ) { static_cast( v )->timeout_cb(); } void FGSD_ExportWindow::timeout_cb() { const char *dirname = flu_dir_chooser( "Export directory", _dirname.c_str() ); if ( dirname != 0 ) { _dirname = dirname; _ok->activate(); size_t p; if ( ( p = _dirname.rfind( '/' ) ) == _dirname.length() - 1 && p != 0 ) { _dirname.erase( p ); } _outputPath->list.insert( 0, _dirname.c_str() ); _outputPath->value( _dirname.c_str() ); } } void FGSD_ExportWindow::ok_cb( Fl_Widget *o, void *v ) { static_cast( v )->button_cb( true ); } void FGSD_ExportWindow::cancel_cb( Fl_Widget *o, void *v ) { static_cast( v )->button_cb( false ); } void FGSD_ExportWindow::button_cb( bool __ok ) { if ( __ok ) { if ( _dirname.size() ) { std::string output; bool first = true; for ( std::list::iterator it = _dirlist.begin(); it != _dirlist.end(); ++it ) { if ( first ) { first = false; } else { output += ";"; } output += *it; } _prefs.outputPath( output ); _window->set_value(); _window->hide(); } } else { _window->clear_value(); _window->hide(); } }