// mainwin.hpp -- main window // // Written by Frederic Bouvier, started October 2001. // // Copyright (C) 2001 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: mainwin.hpp,v 1.73 2005/06/09 22:33:59 fredb2 Exp $ #ifndef _mainwin_hpp_ #define _mainwin_hpp_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mainglwin.hpp" #include "inputwin.hpp" #include "curve.hpp" #include "preferences.hpp" #include "actionmgr.hpp" #include "Fl_Cursor_Shape.H" #include "dynmenu.hpp" class FGSD_Fragment; class FGSD_ObjectLibraryWindow; class FGSD_AirportEditorWindow; class FGSD_ActionWindow; class FGSD_Taxiways; class FGSD_Runways; class FGSD_Airports; class FGSD_JPEGImage; class FGSD_MainWindow; class FGSD_CurveToolbar; class FGSD_SceneryToolbar; class FGSD_TriangleObject; class FGSD_ExportWindow; // We don't want to undo the content of the field but undo actions // so we have to redefine 'handle' class FGSD_FloatInput : public Fl_Float_Input { public: FGSD_FloatInput(FGSD_MainWindow *mw, int x,int y,int w,int h,const char *l = 0) : Fl_Float_Input(x,y,w,h,l), _mw( mw ) {} int handle(int); private: FGSD_MainWindow *_mw; }; class FGSD_MainWindow { public: // Datatypes typedef std::list FragmentList; typedef std::list CurveList; typedef std::map TileList; enum FragmentMvt { ToTop, ToBottom, OneUp, OneDown }; enum ToolButton { Undo, Redo, Fragment, Curve, Scenery, Tile, StaticObj, TileFrame, Vertex, Measure }; enum Cursor_Shape { ShapeHand, NbShapes }; // Contructor/destructor FGSD_MainWindow( int w, int h ); ~FGSD_MainWindow(); void show (int argc, char **argv); // OpenGL window callbacks void layout_(); void mouseMove( int x, int y, int e, int s ); void mouseLeave(); void mouseClick( int x, int y, int s ); void mouseRelease( int x, int y, int s ); void drawGL(); // File menu callbacks static void new_cb(Fl_Widget *, void *); void new_cb( Fl_Widget * ); static void open_cb(Fl_Widget *, void *); void open_cb( Fl_Widget * ); static void recentFile_cb(Fl_Widget *, void *); void recentFile_cb(Fl_Widget *); static void import_cb(Fl_Widget *, void *); void import_cb(); static void save_cb(Fl_Widget *, void *); static void saveAs_cb(Fl_Widget *, void *); bool saveProject( bool __saveAs ); static void export_cb(Fl_Widget *, void *); void export_cb( Fl_Widget * ); static void quit_cb(Fl_Widget *, void *); void quit_cb(Fl_Widget *); // Edit menu callbacks static void undo_cb(Fl_Widget *, void *); void undo_cb(Fl_Widget *); static void redo_cb(Fl_Widget *, void *); void redo_cb(Fl_Widget *); // Tool menu callbacks static void objlib_cb(Fl_Widget *, void *); void objlib_cb(Fl_Widget *); static void impscen_cb(Fl_Widget *, void *); void impscen_cb(Fl_Widget *); static void impscenfile_cb(Fl_Widget *, void *); void impscenfile_cb(Fl_Widget *); static void gotoApt_cb(Fl_Widget *, void *); void gotoApt_cb(Fl_Widget *); static void options_cb(Fl_Widget *, void *); void options_cb(Fl_Widget *); // Popup menu callbacks static void center_cb(Fl_Widget *, void *); void center_cb(Fl_Widget *); static void changeObjectHeading_cb(Fl_Widget *, void *); void changeObjectHeading_cb(Fl_Widget *); static void addNewStaticObject_cb(Fl_Widget *, void *); void addNewStaticObject_cb(Fl_Widget *); static void removeStaticObject_cb(Fl_Widget *, void *); void removeStaticObject_cb(Fl_Widget *); static void changeVertexHeight_cb(Fl_Widget *, void *); void changeVertexHeight_cb(Fl_Widget *); static void copyCurrentHeight_cb(Fl_Widget *, void *); void copyCurrentHeight_cb(Fl_Widget *); static void remCurvePoint_cb(Fl_Widget *, void *); void remCurvePoint_cb( bool selected ); static void remCurve_cb(Fl_Widget *, void *); void remCurve_cb( bool selected ); static void embedCurve_cb(Fl_Widget *, void *); void embedCurve_cb( bool selected ); static void curveType_cb(Fl_Widget *, void *); void curveType_cb( bool selected ); static void toTop_cb( Fl_Widget *w, void *v ); static void toBottom_cb( Fl_Widget *w, void *v ); static void oneUp_cb( Fl_Widget *w, void *v ); static void oneDown_cb( Fl_Widget *w, void *v ); void fragmentPopup_cb( Fl_Widget *w, FragmentMvt n ); static void remMapFragment_cb(Fl_Widget *, void *); void remMapFragment_cb(Fl_Widget *); static void startFlightGear_cb(Fl_Widget *, void *); static void addTile_cb(Fl_Widget *, void *); void addTile_cb(); void startFlightGear_cb(); static void *startFlightGear( void *param ); static void changeMaterial_cb(Fl_Widget *, void *); void changeMaterial_cb(); static void repeatChangeMaterial_cb(Fl_Widget *, void *); void repeatChangeMaterial_cb(); static void importAndFetch_cb(Fl_Widget *, void *); void importAndFetch_cb(); // Change heading dialog callbacks static void changeObjectHeading_dial_cb(Fl_Widget *, void *); static void changeObjectHeading_input_cb(Fl_Widget *, void *); static void changeObjectHeading_button_cb(Fl_Widget *, void *); // Scrollbars callbacks static void hscroll_cb(Fl_Widget *o, void *v); void hscroll_cb(Fl_Widget *o); static void vscroll_cb(Fl_Widget *o, void *v); void vscroll_cb(Fl_Widget *o); // Toolbar callbacks static void zoom_cb(Fl_Widget *o, void *v); void zoom_cb(); static void undoButton_cb( Fl_Widget *w, void *v ); static void redoButton_cb( Fl_Widget *w, void *v ); static void fragmentButton_cb( Fl_Widget *w, void *v ); static void levelButton_cb( Fl_Widget *w, void *v ); static void sceneryButton_cb( Fl_Widget *w, void *v ); static void tileButton_cb( Fl_Widget *w, void *v ); static void staticButton_cb( Fl_Widget *w, void *v ); static void tileFrameButton_cb( Fl_Widget *w, void *v ); static void vertexMode_cb( Fl_Widget *w, void *v ); static void measureMode_cb( Fl_Widget *w, void *v ); void toolButton_cb( Fl_Widget *w, ToolButton b ); static void alpha_cb(Fl_Widget *o, void *v); void alpha_cb(Fl_Widget *o); static void about_cb(Fl_Widget *o, void *v); static void closeAbout_cb(Fl_Widget *o, void *v); void closeAbout_cb(); // Utility functions void cleanProject(); bool checkModified(); void load( const char *__fileName ); TileList importTiles( const char *root, const char *base ); void save( const char *__fileName ); void refreshRecentFiles(); void refreshAirportList(); void centerPosition( double lon, double lat ); void gotoPosition( double lon, double lat, int __2x, int __2y ); void overallBoundingBox( double &x1, double &y1, double &x2, double &y2 ) const; bool propertiesUnderMouse( double lon, double lat, double &height, std::string &material, std::string &airportID ) const; FGSD_BaseObject *objectUnderMouse(); FGSD_Tile *findTile( double lon, double lat ) const; FGSD_TriangleObject *getAdjacentTerrainObject( FGSD_Tile *__tile, bool __lon, bool __min ); void setCursor( Fl_Cursor __cursor ); void setCursor( Cursor_Shape __shape ); void updateUndoMenu(); static void stepBanner_cb( size_t, void * ); void stepBanner_cb( size_t ); static void showBanner_cb( void * ); void showBanner( bool progress ); void setTitle(); void setButtonImage( Fl_Widget *w, int n, bool grayed ); void incZoomValue( int inc ); void postTileLoad( TileList &newTiles ); // static int calc_min_max( void* item, void* data ); void drawCurves( bool ); bool drawCurves() const; void setDrawType( FGSD_BaseObject::DrawType dt ); void changeMaterial( const std::string &mat, double lon, double lat ); FGSD_MapFragment *createFragment( const char *__fileName, const char *relPath ); void getFragmentBoundingBox( FGSD_MapFragment *f, double &x1, double &y1, double &x2, double &y2 ) const; bool mouseIsOverFragment( FGSD_MapFragment *f, double x, double y ) const; void drawTransformedFragment( FGSD_MapFragment *fragment, double xm, double ym, double xM, double yM ) const; void drawFragmentOutline( FGSD_MapFragment *fragment ) const; // Action related functions static void step_cb( size_t, void * ); void step_cb( size_t ); void newAction( FGSD_Action *__action ); bool moveStaticObject( const char *__name, double __lon, double __lat, double __elev, double __hdg, double __xdepl, double __ydepl ); bool rotateStaticObject( const char *__name, double __lon, double __lat, double __elev, double __hdg, double __rot ); bool moveFragment( const char *__name, bool __up, size_t nb ); bool loadMapFragment( const char *__name ); bool removeMapFragment( const char *__name ); bool addStaticObject( const char *__name, const std::vector &__textures, double __lon, double __lat, double __elev, double __hdg ); bool removeStaticObject( const char *__name, double __lon, double __lat, double __elev, double __hdg ); bool loadTiles( const std::vector &__nameList, void (*__step)( size_t, void * ) = 0 ); bool removeTiles( const std::vector &__nameList ); bool moveBaseObjectVertex( const char *__name, double __lon, double __lat, double __xdepl, double __ydepl ); bool changeBaseObjectHeight( const char *__name, double __lon, double __lat, double __zdepl ); bool changeBaseObjectMaterial( const char *__name, double __lon, double __lat, const std::string &__material ); bool getBaseObjectPointPosition( const char *__name, size_t __index, double &__lon, double &__lat ) const; bool getCurvePointPosition( double __lon, double __lat, size_t __index, double &__pLon, double &__pLat ) const; bool newCurve( const FGSD_Curve::PointList *__pointList = 0, bool __opened = false, size_t __current = -1 ); bool newCurve( double __lon, double __lat ); bool removeCurve( double __lon, double __lat ); bool addCurvePoint( double __lon, double __lat, size_t __index, double __pLon, double __pLat ); bool removeCurvePoint( double __lon, double __lat, size_t __index ); bool selectCurve( double __lon, double __lat ); bool moveCurvePoint( double __lon, double __lat, size_t __index, double __xdepl, double __ydepl, bool __undo ); bool closeCurve( double __lon, double __lat ); bool openCurve( double __lon, double __lat ); bool setCurveProperties( double __lon, double __lat, FGSD_Curve::CurveType __type, double __height, const char *__material, bool __water ); bool embedCurve( double __lon, double __lat ); private: Fl_Window *_window; Fl_Scrollbar *_vscroll; Fl_Scrollbar *_hscroll; Fl_Value_Slider *_zoom; Fl_Output *_xentry; Fl_Output *_yentry; Fl_Output *_zentry; Fl_Output *_matentry; Fl_Output *_aidentry; Fl_Button *_nbutton; Fl_Button *_obutton; Fl_Button *_vbutton; Fl_Button *_ubutton; Fl_Button *_ulbutton; Fl_Button *_rbutton; Fl_Button *_rlbutton; Fl_Button *_fbutton; Fl_Button *_cbutton; Fl_Button *_sbutton; Fl_Button *_mbutton; Flu_Progress *_progress; Fl_Menu_Bar *_menubar; FGSD_DynamicSubMenu _recentSubMenu; FGSD_DynamicMenuItem _undoItem; FGSD_DynamicMenuItem _redoItem; FGSD_DynamicSubMenu _airportSubMenu; Fl_Group *_tools; Fl_Group *_status; Fl_Group *_view; FGSD_MainGLWindow *_area; Fl_Menu_Button *_popup; FGSD_CurveToolbar *_curveTools; FGSD_SceneryToolbar *_sceneryTools; FGSD_Window *_banWindow; Fl_Box *_banImage; Fl_Box *_banText; Flu_Progress *_banProgress; Fl_RGB_Image *_banner; FGSD_JPEGImage *_jpg; FGSD_InputWindow *_input; FGSD_ObjectLibraryWindow *_objlib; FGSD_AirportEditorWindow *_aptedt; FGSD_ActionWindow *_actionWindow; FGSD_ExportWindow *_exportWindow; bool _valid; std::string _fileName; std::string _windowTitle; FragmentList _fragmentList; // "Current" (under the mouse) data FGSD_MapFragment *_outlinedFragment; bool _lockMouse; bool _popupShown; bool _dragging; Fl_Cursor _currentCursor; Fl_Cursor_Shape *_currentShape; double _curx; double _cury; double _curz; FGSD_BaseObject *_curObject; FGSD_TriangleObject *_adjObject; FGSD_Curve *_curCurve; std::string _curMaterial; bool _dragMove; double _dragOriginX; double _dragOriginY; double _dragOriginZ; std::string _lastMaterialSet; // View parameters double _posx; double _posy; double _visw; double _vish; double _zLevel; // Extents of the world double _minx; double _miny; double _maxx; double _maxy; FGSD_TriangleObject *_terrain; CurveList _curveList; FGSD_BaseObject::DrawType _drawType; bool _drawCurves; TileList _tileList; SGBucket _minBucket; SGBucket _maxBucket; std::vector _aptList; FGSD_Taxiways *_taxiways; FGSD_Runways *_runways; FGSD_Airports *_airports; bool _doPostLoad; FGSD_ActionManager _actionMgr; enum { New_i, Open_i, Save_i, Undo_i, Redo_i, Fragments_i, Curves_i, Scenery_i, Measure_i, NbImages }; static Fl_Image *_images[ NbImages ][ 2 ]; friend class FGSD_ActionWindow; }; inline void FGSD_MainWindow::show (int argc, char **argv) { if ( _window ) _window->show( argc, argv ); } inline bool FGSD_MainWindow::drawCurves() const { return _drawCurves; } inline void FGSD_MainWindow::drawCurves( bool d ) { _drawCurves = d; _area->redraw(); } inline void FGSD_MainWindow::setDrawType( FGSD_BaseObject::DrawType dt ) { _drawType = dt; _area->redraw(); } #endif