Commit 60431893 authored by Florent D'Halluin's avatar Florent D'Halluin
Browse files

[yavgui] Change GStateAdder into GVcsnHandler.

GVcsnHandler handles automaton structure modifications.

* yavgui/src/Makefile.am,
* yavgui/src/automaton_instance.cc,
* yavgui/src/vcsn_automaton.cc,
* yavgui/src/vcsn_automaton.hh,
* yavgui/src/vcsn_automaton.hxx: Update references.
* yavgui/src/g_state_adder.cc: Rename into ->
* yavgui/src/g_vcsn_handler.cc: .
* yavgui/src/g_state_adder.hh: Rename into ->
* yavgui/src/g_vcsn_handler.hh: .
* yavgui/src/g_state_adder.hxx: Rename into ->
* yavgui/src/g_vcsn_handler.hxx: .
parent da09b4b0
2009-08-04 d-halluin <d-halluin@lrde.epita.fr>
[yavgui] Change GStateAdder into GVcsnHandler.
GVcsnHandler handles automaton structure modifications.
* yavgui/src/Makefile.am,
* yavgui/src/automaton_instance.cc,
* yavgui/src/vcsn_automaton.cc,
* yavgui/src/vcsn_automaton.hh,
* yavgui/src/vcsn_automaton.hxx: Update references.
* yavgui/src/g_state_adder.cc: Rename into ->
* yavgui/src/g_vcsn_handler.cc: .
* yavgui/src/g_state_adder.hh: Rename into ->
* yavgui/src/g_vcsn_handler.hh: .
* yavgui/src/g_state_adder.hxx: Rename into ->
* yavgui/src/g_vcsn_handler.hxx: .
2009-08-04 d-halluin <d-halluin@lrde.epita.fr>
 
[yavgui] Change yavgui into gui in the code.
......
......@@ -34,6 +34,8 @@ COMMON_SOURCES = main.cc \
g_state.cc \
g_state_adder.cc \
g_state_adder.moc.cc \
g_vcsn_handler.cc \
g_vcsn_handler.moc.cc \
g_transition.cc \
g_painter.cc \
g_state.moc.cc \
......
......@@ -37,7 +37,7 @@ namespace gui
view_->setScene (scene_);
scene_->setSceneRect(-SCENE_SIZE / 2, -SCENE_SIZE / 2,
SCENE_SIZE, SCENE_SIZE);
vcsn_automaton_.set_state_adder (&scene_, &view_);
vcsn_automaton_.set_vcsn_handler (&scene_, &view_);
}
AutomatonInstance::AutomatonInstance (const AutomatonInstance&)
......
// g_state_adder.cc: this file is part of Vaucanson.
// g_vcsn_handler.cc: this file is part of Vaucanson.
//
// Vaucanson, a generic library for finite state machines.
//
......@@ -16,13 +16,13 @@
//
/**
* @file g_state_adder.cc
* @file g_vcsn_handler.cc
* @author Florent D'Halluin <d-halluin@lrde.epita.fr>
*
* FIXME
*/
# include "g_state_adder.hh"
# include "g_vcsn_handler.hh"
using namespace gui::display;
......@@ -30,26 +30,33 @@ namespace gui
{
namespace display
{
void GStateAdder::add (QPointF pos)
GVcsnHandler::AddState::AddState(SceneInfo& i, QPointF p)
: info(i),
pos(p)
{
pos_ = pos;
if (!(*automaton_))
}
void
GVcsnHandler::add_state(QPointF pos)
{
AddState op(info_, pos);
if (! *(info_.automaton))
throw exceptions::NoAutomatonStructure ();
boost::apply_visitor (*this, **automaton_);
boost::apply_visitor (op, **(info_.automaton));
}
GStateAdder::GStateAdder (QGraphicsScene** scene,
GView** view,
automaton_variant** automaton)
: scene_ (scene),
view_ (view),
automaton_ (automaton)
GVcsnHandler::GVcsnHandler (GScene** scene,
GView** view,
automaton_variant** automaton)
{
info_.scene = scene;
info_.view = view;
info_.automaton = automaton;
}
GStateAdder::~GStateAdder ()
GVcsnHandler::~GVcsnHandler ()
{
}
......
// g_state_adder.hh: this file is part of Vaucanson.
// g_vcsn_handler.hh: this file is part of Vaucanson.
//
// Vaucanson, a generic library for finite state machines.
//
......@@ -16,24 +16,23 @@
//
/**
* @file g_state_adder.hh
* @file g_vcsn_handler.hh
* @author Florent D'Halluin <d-halluin@lrde.epita.fr>
*
* FIXME
*/
#ifndef G_STATE_ADDER_HH_
# define G_STATE_ADDER_HH_
#ifndef G_VCSN_HANDLER_HH_
# define G_VCSN_HANDLER_HH_
# include "common.hh"
# include "g_common.hh"
# include "g_state.hh"
# include "g_transition.hh"
# include "g_view.hh"
# include "g_scene.hh"
# include "vcsn_automaton_variant.hh"
# include <QGraphicsScene>
# include <boost/variant.hpp>
using namespace gui::vcsn_internal;
......@@ -42,33 +41,60 @@ namespace gui
{
namespace display
{
class GStateAdder: public QObject, public boost::static_visitor<>
/// Handle automaton structure modifications, such as add_state,
/// del_state, add_transition, ...
class GVcsnHandler: public QObject
{
Q_OBJECT
public:
GStateAdder (QGraphicsScene** scene,
struct SceneInfo
{
GScene** scene;
GView** view;
automaton_variant** automaton;
};
GVcsnHandler(GScene** scene,
GView** view,
automaton_variant** automaton);
virtual ~GStateAdder ();
template<typename Automaton>
void operator() (Automaton& automaton);
virtual ~GVcsnHandler();
public slots:
void add (QPointF pos);
void add_state(QPointF pos);
private:
QGraphicsScene** scene_;
GView** view_;
automaton_variant** automaton_;
QPointF pos_;
struct AddState: public boost::static_visitor<>
{
AddState(SceneInfo& info,
QPointF pos);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
QPointF pos;
};
struct DelState: public boost::static_visitor<>
{
DelState(SceneInfo& info,
GState* state);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GState* state;
};
SceneInfo info_;
};
} // ! namespace display
} // ! namespace gui
# include "g_state_adder.hxx"
# include "g_vcsn_handler.hxx"
#endif /* !G_STATE_ADDER_HH_ */
#endif /* !G_VCSN_HANDLER_HH_ */
// g_state_adder.hxx: this file is part of Vaucanson.
// g_vcsn_handler.hxx: this file is part of Vaucanson.
//
// Vaucanson, a generic library for finite state machines.
//
......@@ -16,17 +16,17 @@
//
/**
* @file g_state_adder.hxx
* @file g_vcsn_handler.hxx
* @author Florent D'Halluin <d-halluin@lrde.epita.fr>
*
* FIXME
*/
#ifndef G_STATE_ADDER_HXX_
# define G_STATE_ADDER_HXX_
#ifndef G_VCSN_HANDLER_HXX_
# define G_VCSN_HANDLER_HXX_
# include "exceptions.hh"
# include "g_state_adder.hh"
# include "g_vcsn_handler.hh"
# include "common.hh"
# include <cmath>
......@@ -38,18 +38,31 @@ namespace gui
namespace display
{
template<typename Automaton>
void GStateAdder::operator() (Automaton& automaton)
void
GVcsnHandler::AddState::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
automaton.add_state ();
int i = automaton.add_state();
int i = 0;
GState *state = new GState (i++, QColor ("white"));
state->setPos (pos_);
(*scene_)->addItem (state);
GState *state = new GState(i, QColor("white"));
state->setPos(pos);
(*(info.scene))->addItem(state);
}
template<typename Automaton>
void
GVcsnHandler::DelState::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
automaton.del_state(state->index());
//(*(info.scene))->removeItem(state);
delete (state);
state = 0;
}
} // ! namespace display
} // ! namespace gui
#endif /* !G_STATE_ADDER_HXX_ */
#endif /* !G_VCSN_HANDLER_HXX_ */
......@@ -47,16 +47,16 @@ namespace gui
boost::apply_visitor (p, *automaton_);
}
void VcsnAutomaton::set_state_adder (QGraphicsScene** scene,
GView** view)
void VcsnAutomaton::set_vcsn_handler (GScene** scene,
GView** view)
{
if (state_adder_)
delete state_adder_;
if (vcsn_handler_)
delete vcsn_handler_;
state_adder_ = new GStateAdder (scene, view, &automaton_);
vcsn_handler_ = new display::GVcsnHandler (scene, view, &automaton_);
// Disabled until the whole system is in place
// QObject::connect (*view, SIGNAL(rightClick (QPointF)),
// state_adder_, SLOT(add (QPointF)));
QObject::connect (*view, SIGNAL(rightClick(QPointF)),
vcsn_handler_, SLOT(add_state(QPointF)));
}
void VcsnAutomaton::load (QString filename)
......
......@@ -25,12 +25,11 @@
#ifndef VCSN_AUTOMATON_HH_
# define VCSN_AUTOMATON_HH_
# include <QGraphicsScene>
# include "common.hh"
# include "g_scene.hh"
# include "g_view.hh"
# include "g_common.hh"
# include "g_state_adder.hh"
# include "g_vcsn_handler.hh"
# include "vcsn_automaton_variant.hh"
......@@ -58,10 +57,10 @@ namespace gui
inline automaton_variant& automaton ();
void set_state_adder (QGraphicsScene** scene,
GView** view);
void set_vcsn_handler (GScene** scene,
GView** view);
void paint (QGraphicsScene** scene,
void paint (GScene** scene,
GView** view,
GLayout layout = GLAYOUT_NONE);
void load (QString filename);
......@@ -75,7 +74,7 @@ namespace gui
display::GLayout layout_;
GStateAdder* state_adder_;
display::GVcsnHandler* vcsn_handler_;
};
} // ! namespace gui
......
......@@ -38,7 +38,7 @@ namespace gui
: type_ (UNDEFINED),
automaton_ (NULL),
layout_ (display::GLAYOUT_NONE),
state_adder_ (NULL)
vcsn_handler_ (NULL)
{
}
......@@ -53,8 +53,8 @@ namespace gui
VcsnAutomaton::~VcsnAutomaton ()
{
if (state_adder_)
delete state_adder_;
if (vcsn_handler_)
delete vcsn_handler_;
if (automaton_)
delete automaton_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment