1 /* === S I N F G =========================================================== */
3 ** \brief Template File
5 ** $Id: state_normal.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "state_normal.h"
33 #include "event_mouse.h"
34 #include "event_layerclick.h"
36 #include "dialog_tooloptions.h"
37 #include <gtkmm/dialog.h>
38 #include "widget_waypointmodel.h"
39 #include <sinfg/valuenode_animated.h>
40 #include <sinfg/valuenode_composite.h>
41 #include <sinfg/valuenode_const.h>
42 #include "canvasview.h"
45 /* === U S I N G =========================================================== */
49 using namespace sinfg;
50 using namespace studio;
52 /* === M A C R O S ========================================================= */
54 /* === C L A S S E S & S T R U C T S ======================================= */
56 class studio::StateNormal_Context : public sigc::trackable
58 CanvasView *canvas_view;
60 CanvasView* get_canvas_view() { return canvas_view; }
61 Canvas::Handle get_canvas() { return canvas_view->get_canvas(); }
62 WorkArea* get_work_area() { return canvas_view->get_work_area(); }
63 etl::handle<sinfgapp::CanvasInterface> get_canvas_interface() { return canvas_view->canvas_interface(); }
66 StateNormal_Context(CanvasView *canvas_view);
67 ~StateNormal_Context();
69 Smach::event_result event_stop_handler(const Smach::event& x);
71 Smach::event_result event_refresh_handler(const Smach::event& x);
73 Smach::event_result event_refresh_ducks_handler(const Smach::event& x);
75 Smach::event_result event_undo_handler(const Smach::event& x);
77 Smach::event_result event_redo_handler(const Smach::event& x);
79 Smach::event_result event_mouse_button_down_handler(const Smach::event& x);
81 Smach::event_result event_multiple_ducks_clicked_handler(const Smach::event& x);
83 Smach::event_result event_refresh_tool_options(const Smach::event& x);
85 Smach::event_result event_layer_click(const Smach::event& x);
87 void edit_several_waypoints(std::list<sinfgapp::ValueDesc> value_desc_list);
89 void refresh_tool_options();
90 }; // END of class StateNormal_Context
92 /* === G L O B A L S ======================================================= */
94 StateNormal studio::state_normal;
96 /* === P R O C E D U R E S ================================================= */
98 /* === M E T H O D S ======================================================= */
100 StateNormal::StateNormal():
101 Smach::state<StateNormal_Context>("normal")
103 insert(event_def(EVENT_STOP,&StateNormal_Context::event_stop_handler));
104 insert(event_def(EVENT_REFRESH,&StateNormal_Context::event_refresh_handler));
105 insert(event_def(EVENT_REFRESH_DUCKS,&StateNormal_Context::event_refresh_ducks_handler));
106 insert(event_def(EVENT_UNDO,&StateNormal_Context::event_undo_handler));
107 insert(event_def(EVENT_REDO,&StateNormal_Context::event_redo_handler));
108 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateNormal_Context::event_mouse_button_down_handler));
109 insert(event_def(EVENT_WORKAREA_MULTIPLE_DUCKS_CLICKED,&StateNormal_Context::event_multiple_ducks_clicked_handler));
110 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateNormal_Context::event_refresh_tool_options));
111 insert(event_def(EVENT_WORKAREA_LAYER_CLICKED,&StateNormal_Context::event_layer_click));
114 StateNormal::~StateNormal()
118 StateNormal_Context::StateNormal_Context(CanvasView *canvas_view):
119 canvas_view(canvas_view)
121 sinfg::info("Enterted Normal State");
124 StateNormal_Context::~StateNormal_Context()
126 sinfg::info("Left Normal State");
130 StateNormal_Context::refresh_tool_options()
132 App::dialog_tool_options->clear();
133 App::dialog_tool_options->set_name("normal");
137 StateNormal_Context::event_refresh_tool_options(const Smach::event& x)
139 refresh_tool_options();
140 return Smach::RESULT_ACCEPT;
144 StateNormal_Context::event_stop_handler(const Smach::event& x)
146 sinfg::info("STATE NORMAL: Received Stop Event");
148 return Smach::RESULT_ACCEPT;
152 StateNormal_Context::event_refresh_handler(const Smach::event& x)
154 sinfg::info("STATE NORMAL: Received Refresh Event");
155 canvas_view->rebuild_tables();
156 canvas_view->work_area->queue_render_preview();
157 return Smach::RESULT_ACCEPT;
161 StateNormal_Context::event_refresh_ducks_handler(const Smach::event& x)
163 sinfg::info("STATE NORMAL: Received Refresh Ducks");
164 canvas_view->queue_rebuild_ducks();
165 return Smach::RESULT_ACCEPT;
169 StateNormal_Context::event_undo_handler(const Smach::event& x)
171 sinfg::info("STATE NORMAL: Received Undo Event");
172 canvas_view->get_instance()->undo();
173 return Smach::RESULT_ACCEPT;
177 StateNormal_Context::event_redo_handler(const Smach::event& x)
179 sinfg::info("STATE NORMAL: Received Redo Event");
180 canvas_view->get_instance()->redo();
181 return Smach::RESULT_ACCEPT;
185 StateNormal_Context::event_mouse_button_down_handler(const Smach::event& x)
187 sinfg::info("STATE NORMAL: Received mouse button down Event");
189 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
194 canvas_view->popup_main_menu();
195 return Smach::RESULT_ACCEPT;
197 return Smach::RESULT_OK;
202 StateNormal_Context::event_layer_click(const Smach::event& x)
204 const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
208 sinfg::info("STATE NORMAL: Received layer click Event, \"%s\"",event.layer->get_name().c_str());
212 sinfg::info("STATE NORMAL: Received layer click Event with an empty layer.");
218 if(!(event.modifier&Gdk::CONTROL_MASK))
219 canvas_view->get_selection_manager()->clear_selected_layers();
222 std::list<Layer::Handle> layer_list(canvas_view->get_selection_manager()->get_selected_layers());
223 std::set<Layer::Handle> layers(layer_list.begin(),layer_list.end());
224 if(layers.count(event.layer))
226 layers.erase(event.layer);
227 layer_list=std::list<Layer::Handle>(layers.begin(),layers.end());
228 canvas_view->get_selection_manager()->clear_selected_layers();
229 canvas_view->get_selection_manager()->set_selected_layers(layer_list);
233 canvas_view->get_selection_manager()->set_selected_layer(event.layer);
236 return Smach::RESULT_ACCEPT;
238 canvas_view->popup_layer_menu(event.layer);
239 return Smach::RESULT_ACCEPT;
241 return Smach::RESULT_OK;
247 StateNormal_Context::edit_several_waypoints(std::list<sinfgapp::ValueDesc> value_desc_list)
250 "Edit Multiple Waypoints", // Title
252 true // use_separator
255 Widget_WaypointModel widget_waypoint_model;
256 widget_waypoint_model.show();
258 dialog.get_vbox()->pack_start(widget_waypoint_model);
261 dialog.add_button(Gtk::StockID("gtk-apply"),1);
262 dialog.add_button(Gtk::StockID("gtk-cancel"),0);
269 sinfgapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Set Waypoints"));
271 std::list<sinfgapp::ValueDesc>::iterator iter;
272 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
274 sinfgapp::ValueDesc value_desc(*iter);
276 if(!value_desc.is_valid())
279 ValueNode_Animated::Handle value_node;
281 // If this value isn't a ValueNode_Animated, but
282 // it is somewhat constant, then go ahead and convert
283 // it to a ValueNode_Animated.
284 if(!value_desc.is_value_node() || ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node()))
287 if(value_desc.is_value_node())
288 value=ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node())->get_value();
290 value=value_desc.get_value();
292 value_node=ValueNode_Animated::create(value,get_canvas()->get_time());
294 sinfgapp::Action::Handle action;
296 if(!value_desc.is_value_node())
298 action=sinfgapp::Action::create("value_desc_connect");
299 action->set_param("dest",value_desc);
300 action->set_param("src",ValueNode::Handle(value_node));
304 action=sinfgapp::Action::create("value_node_replace");
305 action->set_param("dest",value_desc.get_value_node());
306 action->set_param("src",ValueNode::Handle(value_node));
309 action->set_param("canvas",get_canvas());
310 action->set_param("canvas_interface",get_canvas_interface());
313 if(!get_canvas_interface()->get_instance()->perform_action(action))
315 get_canvas_view()->get_ui_interface()->error(_("Unable to convert to animated waypoint"));
322 if(value_desc.is_value_node())
323 value_node=ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node());
330 sinfgapp::Action::Handle action(sinfgapp::Action::create("waypoint_set_smart"));
334 get_canvas_view()->get_ui_interface()->error(_("Unable to find waypoint_set_smart action"));
340 action->set_param("canvas",get_canvas());
341 action->set_param("canvas_interface",get_canvas_interface());
342 action->set_param("value_node",ValueNode::Handle(value_node));
343 action->set_param("time",get_canvas()->get_time());
344 action->set_param("model",widget_waypoint_model.get_waypoint_model());
346 if(!get_canvas_interface()->get_instance()->perform_action(action))
348 get_canvas_view()->get_ui_interface()->error(_("Unable to set a specific waypoint"));
355 //get_canvas_view()->get_ui_interface()->error(_("Unable to animate a specific valuedesc"));
365 StateNormal_Context::event_multiple_ducks_clicked_handler(const Smach::event& x)
367 sinfg::info("STATE NORMAL: Received multiple duck click event");
369 //const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
371 std::list<sinfgapp::ValueDesc> value_desc_list;
373 // Create a list of value_descs associated with selection
374 const DuckList selected_ducks(get_work_area()->get_selected_ducks());
375 DuckList::const_iterator iter;
376 for(iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
378 sinfgapp::ValueDesc value_desc((*iter)->get_value_desc());
380 if(!value_desc.is_valid())
383 if(value_desc.get_value_type()==ValueBase::TYPE_BLINEPOINT && value_desc.is_value_node() && ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()))
385 value_desc_list.push_back(
387 ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node())
393 value_desc_list.push_back(value_desc);
396 Gtk::Menu *menu=manage(new Gtk::Menu());
398 canvas_view->get_instance()->make_param_menu(menu,canvas_view->get_canvas(),value_desc_list);
401 sinfgapp::Action::ParamList param_list;
402 param_list=get_canvas_interface()->generate_param_list(value_desc_list);
404 canvas_view->add_actions_to_menu(menu, param_list,sinfgapp::Action::CATEGORY_VALUEDESC|sinfgapp::Action::CATEGORY_VALUENODE);
406 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Edit Waypoints"),
410 &studio::StateNormal_Context::edit_several_waypoints
416 menu->popup(3,gtk_get_current_event_time());
418 return Smach::RESULT_ACCEPT;