Quick links: Tutorial - Examples - Files - Symbols.
Classes: Hierarchy - Index - List - Members.
Namespaces: Index - base - cs - display.

wxdisplay.cpp

Visualisation et affichage d'un graphe sous wxWidgets. Le code source de ce programme se trouve dans "samples/wxdisplay". Il n'est utilisable que dans le cas où Cogitant a été compilé avec les fonctions de dessin et d'interfacage avec wxWidgets.

See also
Graph drawing.
// ==============
// CoGITaNT 5
// ==============
#include <wx/app.h>
#include <wx/frame.h>
#include <wx/scrolwin.h>
#include <wx/menu.h>
#include <wx/msgdlg.h>
#include <wx/intl.h>
using namespace std;
/* This class is the main window of the application. It contains a pointer to the
* graph editing panel (m_panel) and the object drawn in this panel (m_drawing).
* It also contains the editor managing the events generated by the panel,
* in response to user actions which, accourding to these events, updates the drawing.
* As all "level 0" windows in wxWidgets, MyFrame is a sub-class of wxFrame. */
class MyFrame: public wxFrame
{
private:
public:
/* The class constructor takes as parameters: the Display Manager used in
* the application (declared in MyApp), the Environment which contains
* the support and graphs already loaded and the name of the file containing
* the graph to be edited. */
MyFrame(cogitantdisplay::DisplayHandler_Wx * dh, cogitant::Environment * env, string const & file);
~MyFrame();
void OnAbout(wxCommandEvent& event);
void OnQuit(wxCommandEvent & event);
DECLARE_EVENT_TABLE()
};
/* With wxWidgets, all applications must define a sub-class of wxApp and in this
* class, initialisations of the application must be done in OnInit method.
* Here, we are allocating a Display Manager (DisplayHandler_Wx) and an
* environment which contain support and graphs.
* While initialising the application, the main window (an instance of MyFrame)
* is created and displays a graph that has been previously loaded in the
* environment. */
class MyApp: public wxApp
{
private:
public:
MyApp();
~MyApp();
bool OnInit();
int OnExit();
DECLARE_EVENT_TABLE()
};
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
// *** MyFrame ***
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
END_EVENT_TABLE()
MyFrame::MyFrame(cogitantdisplay::DisplayHandler_Wx * dh, cogitant::Environment * env, string const & file)
:wxFrame((wxFrame *)NULL, -1, cs2ws("wxCoGITaNT"), wxPoint(20,20), wxSize(470,360), wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
{
// Creating the menu bar.
wxMenu *file_menu = new wxMenu();
file_menu->Append( wxID_ABOUT, cs2ws("&About..."));
file_menu->Append( wxID_EXIT, cs2ws("&Close"));
wxMenuBar *menu_bar = new wxMenuBar();
menu_bar->Append(file_menu, cs2ws("&Cogitant"));
SetMenuBar(menu_bar);
//CreateStatusBar(2);
// Loading the file containing the graph.
cogitant::iSet ig = env->readGraphs(file);
/* Creation of a drawing to display the conceptual graph. The graph
* cannot be directly displayed; it is done via DrawingGraph which
* outputs a "graphical" view of all elements that make the conceptuel
* graph. */
m_drawing = new cogitantdisplay::DrawingGraph(env, env->graphs(ig));
/* Elements of the drawing are organised to be displayed. A manually created
* graph does not contain information on the position or the size of vertices.
* It is therefore necessary to indicate a position and size to each element
* of the graph, before displaying. This is done by the runLayout method.
* Several "layout" operations can be defined. However, the default operation
* within standard Cogitant, organises concept vertices, one under the other
* and relation vertices, one under the other, next to the concept vertices. */
dh->runLayout(*m_drawing);
// Creating the drawing display panel.
m_panel = dh->newPanel(m_drawing, this, -1, wxPoint(0,0), wxSize(100,100));
/* A single panel only allows the display of a conceptual graph. As we wish
* to edit the graph, we need to create an editor which will be link to the
* previous panel. More precisely, it will intercept the user events (produced
* by wxWidgets, intercepted by Panel_Wx and sent by Editor) to modify the
* graph on the fly (creation, deletion of vertices, change of type,
* transfer, etc.). */
m_editor = dh->newEditor(1, m_panel, file, ig);
/* A tool bar is created to give access to all functions of the editor. It
* is the editor which is in charge of intercepting the events produced by
* this component and to update the tool bar (i.e.: to "grey" certain tools according
* to selected elements) */
dh->newToolbar(m_editor, this);
}
MyFrame::~MyFrame()
{
delete m_drawing;
}
void MyFrame::OnQuit(wxCommandEvent &)
{
Close(TRUE);
}
void MyFrame::OnAbout(wxCommandEvent &)
{
wxMessageBox(cs2ws("Graph display with wxWidgets"), cs2ws("wxCoGITaNT"), wxICON_INFORMATION | wxOK );
}
// *** MyApp ***
BEGIN_EVENT_TABLE(MyApp, wxApp)
END_EVENT_TABLE()
MyApp::MyApp()
m_env(new cogitant::Environment())
{
/* This call is optional. It allows adding to the environment (a class
* that belongs to the library kernel, i.e. Cogitant namespace ),
* the management of the graphical formats given by the display
* module (namespace cogitantdisplay).
* After this call, the methods of saving the environment give access
* to the graphical formats (Only the FIG format exists for now). A graph is
* simply saved in the FIG format. All there is to do, is to select the
* "save as" tool and give a filename with the "FIG" extension. */
m_dh->addFormats(*m_env);
m_env->readSupport("../bcgct/bucolic/bucolic.bcs");
}
MyApp::~MyApp()
{
delete m_dh;
delete m_env;
}
bool MyApp::OnInit()
{
SetAppName(cs2ws("wxCoGITaNT"));
/* Creating the main windows of the application. It immediately displays
* the graph which name was passed as a parameter. */
MyFrame *frame = new MyFrame(m_dh, m_env, "../bcgct/bucolic/fact_editor.bcg");
frame->Show(TRUE);
return TRUE;
}
int MyApp::OnExit()
{
return 0;
}