alpar@174: /* -*- C++ -*-
alpar@174:  *
alpar@174:  * This file is a part of LEMON, a generic C++ optimization library
alpar@174:  *
alpar@174:  * Copyright (C) 2003-2006
alpar@174:  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@174:  * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@174:  *
alpar@174:  * Permission to use, modify and distribute this software is granted
alpar@174:  * provided that this copyright notice appears in all copies. For
alpar@174:  * precise terms see the accompanying LICENSE file.
alpar@174:  *
alpar@174:  * This software is provided "AS IS" with no warranty of any kind,
alpar@174:  * express or implied, and with no claim as to its suitability for any
alpar@174:  * purpose.
alpar@174:  *
alpar@174:  */
hegyi@96: 
hegyi@96: #ifndef NBTAB_H
hegyi@96: #define NBTAB_H
hegyi@96: 
hegyi@96: class NoteBookTab;
hegyi@96: 
hegyi@96: #include "mapstorage.h"
hegyi@96: #include "map_win.h"
hegyi@160: #include "design_win.h"
hegyi@96: #include "graph_displayer_canvas.h"
hegyi@96: #include <libgnomecanvasmm.h>
hegyi@96: #include <libgnomecanvasmm/polygon.h>
hegyi@96: 
hegyi@121: ///One tab in the Notebook that is placed in the main window (\ref MainWin).
hegyi@121: 
hegyi@121: ///One graph and all of its accessories like maps are assigned to one tab in the notebook.
hegyi@121: ///\ref NoteBookTab is responsible for the user defined display of the graph: view can be
hegyi@121: ///set by visualized maps, therefore \ref NoteBookTab must provide an interface to set the
hegyi@121: ///view of graph. This is \ref Mapwin window.
hegyi@121: ///
hegyi@121: ///\ref NoteBookTab is also
hegyi@121: ///responsible for modify the graph if it is
hegyi@121: ///requested. Therefore it is responsible for translating user events to modifications to
hegyi@121: ///do on graph, like node/edge addition/deletion, map modification, addition and so on.
hegyi@121: ///
hegyi@121: ///To be able to solve these tasks the help of \ref MainWin is also needed, for example to
hegyi@121: ///know which editor-tool is active at the moment. Therefore \ref MainWin knows \ref NoteBookTab.
hegyi@121: ///
hegyi@121: ///Some information in the other direction is needed as well: for example when new map creation is requested for this tab
hegyi@121: ///\ref NoteBookTab must ask \ref MainWin to pop-up a \ref NewMapWin. Communication in this direction is realized by signals
hegyi@121: ///therefore \ref NoteBookTab does not know \ref MainWin at all, but in this way it is not necessary.
hegyi@96: class NoteBookTab : public Gtk::VBox
hegyi@96: {
hegyi@96: public:
hegyi@121:   
hegyi@121:   ///Constructor of \ref NoteBookTab
hegyi@121: 
hegyi@121:   ///It initiates the \re GraphDisplayerCanvas, on which the graph will be drawn
hegyi@121:   ///Signals of \ref MapStorage will be bound to the appropriate callback functions here.
hegyi@96:   NoteBookTab();
hegyi@96:   
hegyi@121:   ///Maps assigned to the graph displayed in this \ref NoteBookTab of notebook.
hegyi@96:   MapStorage mapstorage;
hegyi@96:     
hegyi@121:   ///Title changement indicator.
hegyi@121: 
hegyi@121:   ///If graph is loaded from disk or saved to disk or changed its name somehow
hegyi@121:   ///this signal will be emit to let
hegyi@121:   ///\ref MainWin know that it has to modify the title of the main window.
hegyi@121:   ///It contains the new title.
hegyi@96:   sigc::signal<void, std::string> signal_title;
hegyi@96: 
hegyi@121:   ///Returns \ref signal_title to be the caller able to connect it to a callback function.
hegyi@96:   sigc::signal<void, std::string> signal_title_ch();
hegyi@96: 
hegyi@121:   ///Indicates that new map window should be popped up.
hegyi@121: 
hegyi@121:   ///\ref NoteBookTab can ask \ref MainWin to pop up a \ref NweMapWin ny emitting this signal.
hegyi@121:   ///The signal contains whether an edgemap or a nodemap should be popped up. \ref NewMapWin
hegyi@121:   ///is not popped up by \ref NoteBookTab, because not only \ref NoteBookTab needs \ref NewMapWin,
hegyi@121:   ///but for example \ref MainWin and \ref AlgoWin s as well.
hegyi@96:   sigc::signal<void, NoteBookTab *, bool> signal_newmap;
hegyi@96: 
hegyi@121:   ///Returns \ref signal_newmap to be the caller able to connect it to a callback function.
hegyi@96:   sigc::signal<void, NoteBookTab *, bool> signal_newmap_needed();
hegyi@96: 
hegyi@121:   ///Loads the given file.
hegyi@121: 
hegyi@121:   ///The given file will be load in the \ref MapStorage and afeter that
hegyi@121:   ///\ref GraphDisplayerCanvas will be requested to display the graph.
hegyi@121:   ///\ref GraphDisplayer will get datas from the recently set \ref MapStorage.
hegyi@96:   void readFile(const std::string &);
hegyi@96:     
hegyi@96:   ///The graph will be drawn on this \ref GraphDisplayerCanvas
hegyi@96:   GraphDisplayerCanvas * gd_canvas;
hegyi@96: 
hegyi@121:   ///Indicates whether the \ref MapWin is opened or not. See \ref mapwin.
hegyi@96:   bool mapwinexists;
hegyi@96: 
hegyi@160:   ///Indicates whether the \ref DesignWin is opened or not. See \ref designwin.
hegyi@160:   bool designwinexists;
hegyi@160: 
hegyi@121:   ///Address of the only \ref MapWin that the \ref NoteBookTab can open.
hegyi@121: 
hegyi@121:   ///Only one of this window can be opened at the same time (\ref mapwinexists), 
hegyi@121:   ///because there is no need for more, one per tab is enough.
hegyi@121:   ///There won1t be benefit of more than one, but it would be
hegyi@121:   ///more complicated to synchronize them.
hegyi@96:   MapWin * mapwin;
hegyi@96:     
hegyi@160:   ///Address of the only \ref DesignWin that the \ref NoteBookTab can open.
hegyi@160: 
hegyi@160:   ///Only one of this window can be opened at the same time (\ref designwinexists), 
hegyi@160:   ///because there is no need for more, one per tab is enough.
hegyi@160:   ///There won't be benefit of more than one, but it would be
hegyi@160:   ///more complicated to synchronize them.
hegyi@160:   DesignWin * designwin;
hegyi@160: 
hegyi@96: public:
hegyi@96:   ///Callback for 'FileNew' action.
hegyi@96:   virtual void newFile();
hegyi@96:   ///Callback for 'FileOpen' action.
hegyi@96:   virtual void openFile();
hegyi@96:   ///Callback for 'FileSave' action.
hegyi@96:   virtual void saveFile();
hegyi@96:   ///Callback for 'FileSaveAs' action.
hegyi@96:   virtual void saveFileAs();
hegyi@96:   ///Callback for 'Close' action.
hegyi@96:   virtual void close();
hegyi@96: 
hegyi@121:   ///Handles changement of view of graph.
hegyi@96: 
hegyi@121:   ///If the user changes the map to show by a property to a nother in \ref MapWin,
hegyi@121:   ///\ref MapWin will call this function. This function will registrate in \ref MapStorage
hegyi@121:   ///the new map to display by the changed property. After that \ref MapStorage will
hegyi@121:   ///emits a signal that will be forwarded to \ref GraphDisplayerCanvas to update the
hegyi@121:   ///appropriate parts of graph.
hegyi@121:   ///\param itiesedge whether the changed property is edge property or node property
hegyi@121:   ///\param prop id of property, see all_include.h
hegyi@121:   ///\param mapname name of the recently selected map
hegyi@121:   void propertyChange(bool itisedge, int prop, std::string mapname);
hegyi@96: 
hegyi@121:   ///Emits a signal that request \ref MainWin to pop up \ref NewMapWin
hegyi@96: 
hegyi@121:   ///This function is called by \ref MapWin.
hegyi@121:   ///\param itisedge whether the new map should be an edgemap or a nodemap.
hegyi@121:   void popupNewMapWin(bool itisedge);
hegyi@121: 
hegyi@121:   ///Returns the actually selected edgemap to visualize by the given property.
hegyi@121: 
hegyi@121:   ///\ref MapWin calls this function, beacuse it does not know \ref MapStorage.
hegyi@121:   ///\param prop property to inquire.
hegyi@121:   std::string getActiveEdgeMap(int prop);
hegyi@121: 
hegyi@121:   ///Returns the actually selected nodemap to visualize by the given property.
hegyi@121: 
hegyi@121:   ///\ref MapWin calls this function, beacuse it does not know \ref MapStorage.
hegyi@121:   ///\param prop property to inquire.
hegyi@121:   std::string getActiveNodeMap(int prop);
hegyi@121: 
hegyi@121:   ///Registers recently created edgemap in \ref MapWin.
hegyi@121: 
hegyi@121:   ///After creation of new map \ref MapStorage emits a signal.
hegyi@121:   ///This signal is bound to this callback function, that will call
hegyi@121:   ///a function with the same name and same parameterin \ref MapWin.
hegyi@121:   ///This call-forwarder function is needed, because \ref Mapstorage does not know \ref MapWin
hegyi@121:   ///\param mapname name of new map
hegyi@121:   void registerNewEdgeMap(std::string mapname);
hegyi@121: 
hegyi@121:   ///Registers recently created nodemap in \ref MapWin.
hegyi@121: 
hegyi@121:   ///After creation of new map \ref MapStorage emits a signal.
hegyi@121:   ///This signal is bound to this callback function, that will call
hegyi@121:   ///a function with the same name and same parameter in \ref MapWin.
hegyi@121:   ///This call-forwarder function is needed, because \ref Mapstorage does not know \ref MapWin
hegyi@121:   ///\param mapname name of new map
hegyi@121:   void registerNewNodeMap(std::string mapname);
hegyi@121: 
hegyi@121:   ///Pops up and registrates the \ref MapWin of \ref NoteBookTab.
hegyi@121:   
hegyi@121:   ///See also
hegyi@121:   ///\ref mapwin.
hegyi@96:   void createMapWin(std::string);
hegyi@121: 
hegyi@160:   ///Pops up and registrates the \ref DesignWin of \ref NoteBookTab.
hegyi@160:   
hegyi@160:   ///See also
hegyi@160:   ///\ref mapwin.
hegyi@160:   void createDesignWin(std::string);
hegyi@160: 
hegyi@121:   ///Closes and deregistrates the \ref MapWin of \ref NoteBookTab.
hegyi@121:   
hegyi@121:   ///See also
hegyi@121:   ///\ref mapwin.
hegyi@96:   void closeMapWin();
hegyi@154: 
hegyi@160:   bool closeDesignWin(GdkEventAny *);
hegyi@160: 
hegyi@154:   ///Sets node representation settings
hegyi@157:   void setView(bool, bool, double, double);
hegyi@154: 
hegyi@154:   ///Gets node representation settings
hegyi@157:   void getView(bool &, bool &, double&, double&);
hegyi@160: 
hegyi@172:   ///Let the graph redesign, based on gravity and edge elasticity.
hegyi@160:   void reDesignGraph();
hegyi@160: 
hegyi@172:   ///\ref MapWin calls this function when it updates the maplist in comboboxes.
hegyi@172:   void active_maps_needed();
hegyi@172: 
hegyi@172: private:
hegyi@172:   ///Signal connection from \ref MapStorage to \ref MapWin
hegyi@172: 
hegyi@172:   ///If \ref MapWin is closed this connection has to be disconnected,
hegyi@172:   ///therefore we have to store it.
hegyi@172:   sigc::connection mapst2mapwin;
hegyi@177: 
hegyi@177:   ///Signal connection from \ref MapStorage to \ref DesignWin
hegyi@177: 
hegyi@177:   ///If \ref DesignWin is closed this connection has to be disconnected,
hegyi@177:   ///therefore we have to store it.
hegyi@177:   sigc::connection mapst2designwin;
hegyi@96: };
hegyi@96: 
hegyi@96: #endif //NBTAB_H