// curvtypwin.cpp -- the curve type window // // Written by Frederic Bouvier, started August 2002. // // Copyright (C) 2002 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: curvtypwin.cpp,v 1.11 2005/05/09 07:01:51 fredb Exp $ #ifdef _MSC_VER #pragma warning( disable : 4503 ) #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "curvtypwin.hpp" #include "bobject.hpp" #include "messwin.hpp" FGSD_CurveTypeWindow::FGSD_CurveTypeWindow( FGSD_Curve *__curve ) : _curve( __curve ) { _curType = _curve->curveType(); _window = new FGSD_Window( 500, 200, "Curve type" ); _window->begin(); Fl_Group *o = new Fl_Group( 10, 10, 185, 140 ); o->box( FL_ENGRAVED_BOX ); o->begin(); _curve2D = new Fl_Round_Button( 20, 25, 150, 30, "2D curve" ); _curve2D->callback( &FGSD_CurveTypeWindow::c2d_cb, this ); _curve2D5 = new Fl_Round_Button( 20, 55, 150, 30, "2.5D curve" ); _curve2D5->callback( &FGSD_CurveTypeWindow::c2d5_cb, this ); _curve3D = new Fl_Round_Button( 20, 85, 150, 30, "3D curve" ); _curve3D->callback( &FGSD_CurveTypeWindow::c3d_cb, this ); switch ( _curType ) { case FGSD_Curve::Curve2D: _curve2D->set(); break; case FGSD_Curve::Curve2D5: _curve2D5->set(); break; case FGSD_Curve::Curve3D: _curve3D->set(); break; } o->end(); Fl_Box *w = new Fl_Box( 20, 0, 45, 20, "Type" ); w->box( FL_FLAT_BOX ); o = new Fl_Group( 205, 10, 285, 140 ); o->box( FL_ENGRAVED_BOX ); o->begin(); _altitude = new Fl_Input( 295, 25, 185, 30, "Altitude :\n(in meters)" ); _altitude->align( FL_ALIGN_LEFT ); if ( _curve->curveType() == FGSD_Curve::Curve2D5 ) { std::ostringstream str; str << _curve->height() << std::ends; _altitude->value( str.str().c_str() ); } else _altitude->deactivate(); _material = new Fl_Choice( 295, 55, 185, 30, "Material :" ); _water = new Fl_Check_Button( 295, 85, 185, 30, "Material is water" ); if ( !_curve->opened() ) { _material->add( "None" ); _material->value( 0 ); int i = 1; for ( FGSD_BaseObject::MaterialColorMap::iterator it = FGSD_BaseObject::_materialColorMap.begin(); it != FGSD_BaseObject::_materialColorMap.end(); ++it ) { _material->add( it->first.c_str() ); if ( it->first == _curve->material() ) _material->value( i ); i++; } _water->value( _curve->water() ); } else { _material->deactivate(); _water->deactivate(); } o->end(); w = new Fl_Box( 215, 0, 80, 20, "Parameters" ); w->box( FL_FLAT_BOX ); _ok = new Fl_Button( 10, 160, 40, 30, "Ok" ); _ok->callback( &FGSD_CurveTypeWindow::ok_cb, this ); _cancel = new Fl_Button( 60, 160, 60, 30, "Cancel" ); _cancel->callback( &FGSD_CurveTypeWindow::cancel_cb, this ); _window->end(); _window->callback( &FGSD_CurveTypeWindow::cancel_cb, this ); } FGSD_CurveTypeWindow::~FGSD_CurveTypeWindow() { delete _window; } void FGSD_CurveTypeWindow::c2d_cb( Fl_Widget *o, void *v ) { ((FGSD_CurveTypeWindow *)v)->button_cb( o, 0 ); } void FGSD_CurveTypeWindow::c2d5_cb( Fl_Widget *o, void *v ) { ((FGSD_CurveTypeWindow *)v)->button_cb( o, 1 ); } void FGSD_CurveTypeWindow::c3d_cb( Fl_Widget *o, void *v ) { ((FGSD_CurveTypeWindow *)v)->button_cb( o, 2 ); } void FGSD_CurveTypeWindow::button_cb( Fl_Widget *o, int n ) { switch ( n ) { case 0: _curve2D->set(); _curve2D5->clear(); _curve3D->clear(); _altitude->deactivate(); _curType = FGSD_Curve::Curve2D; break; case 1: _curve2D5->set(); _curve2D->clear(); _curve3D->clear(); _altitude->activate(); _curType = FGSD_Curve::Curve2D5; break; case 2: _curve3D->set(); _curve2D5->clear(); _curve2D->clear(); _altitude->deactivate(); _curType = FGSD_Curve::Curve3D; break; } _curve2D->redraw(); _curve2D5->redraw(); _curve3D->redraw(); } void FGSD_CurveTypeWindow::ok_cb( Fl_Widget *o, void *v ) { ((FGSD_CurveTypeWindow *)v)->button_cb( true ); } void FGSD_CurveTypeWindow::cancel_cb( Fl_Widget *o, void *v ) { ((FGSD_CurveTypeWindow *)v)->button_cb( false ); } void FGSD_CurveTypeWindow::button_cb( bool __ok ) { if ( __ok ) { bool error = false; _height = 0.0; if ( _curType == FGSD_Curve::UnSet ) { FGSD_MessageWindow mess( "FlightGear Scenery Designer", "The curve type is not set", FGSD_MessageWindow::Error, FGSD_MessageWindow::Ok ); mess.exec(); error = true; } else if ( _curType == FGSD_Curve::Curve2D5 && _altitude->value() && _altitude->value()[ 0 ] != '\0' ) { char *pt = 0; _height = strtod( _altitude->value(), &pt ); if ( *pt != '\0' ) { FGSD_MessageWindow mess( "FlightGear Scenery Designer", "Characters not valid in the altitude field", FGSD_MessageWindow::Error, FGSD_MessageWindow::Ok ); mess.exec(); error = true; } } if ( !error ) { _window->set_value(); _window->hide(); } } else { _window->clear_value(); _window->hide(); } }