1 /* === S I N F G =========================================================== */
2 /*! \file valuedescset.cpp
3 ** \brief Template File
5 ** $Id: valuedescexport.cpp,v 1.1.1.1 2005/01/07 03:34:37 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 "valuenodeadd.h"
33 #include "canvasadd.h"
34 #include "valuedescexport.h"
35 #include "layerparamconnect.h"
37 #include <sinfgapp/canvasinterface.h>
38 #include <sinfg/valuenode_const.h>
44 using namespace sinfg;
45 using namespace sinfgapp;
46 using namespace Action;
48 /* === M A C R O S ========================================================= */
50 ACTION_INIT(Action::ValueDescExport);
51 ACTION_SET_NAME(Action::ValueDescExport,"value_desc_export");
52 ACTION_SET_LOCAL_NAME(Action::ValueDescExport,"Export");
53 ACTION_SET_TASK(Action::ValueDescExport,"export");
54 ACTION_SET_CATEGORY(Action::ValueDescExport,Action::CATEGORY_VALUEDESC);
55 ACTION_SET_PRIORITY(Action::ValueDescExport,0);
56 ACTION_SET_VERSION(Action::ValueDescExport,"0.0");
57 ACTION_SET_CVS_ID(Action::ValueDescExport,"$Id: valuedescexport.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
59 /* === G L O B A L S ======================================================= */
61 /* === P R O C E D U R E S ================================================= */
63 /* === M E T H O D S ======================================================= */
65 Action::ValueDescExport::ValueDescExport()
70 Action::ValueDescExport::get_param_vocab()
72 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
74 ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC)
75 .set_local_name(_("ValueDesc"))
78 ret.push_back(ParamDesc("name",Param::TYPE_STRING)
79 .set_local_name(_("Name"))
80 .set_desc(_("The name that you want this value to be exported as"))
88 Action::ValueDescExport::is_canidate(const ParamList &x)
90 if(canidate_check(get_param_vocab(),x))
92 ValueDesc value_desc=x.find("value_desc")->second.get_value_desc();
93 if(!value_desc || value_desc.parent_is_canvas() || (value_desc.is_value_node() && value_desc.get_value_node()->is_exported()))
101 Action::ValueDescExport::set_param(const sinfg::String& param_name, const Action::Param ¶m)
103 if(param_name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC)
105 value_desc=param.get_value_desc();
110 if(param_name=="name" && param.get_type()==Param::TYPE_STRING)
112 name=param.get_string();
117 return Action::CanvasSpecific::set_param(param_name,param);
121 Action::ValueDescExport::is_ready()const
123 if(!value_desc || name.empty())
125 return Action::CanvasSpecific::is_ready();
129 Action::ValueDescExport::prepare()
133 ValueNode::Handle value_node;
135 if(value_desc.get_value_type()==ValueBase::TYPE_CANVAS)
137 if(!value_desc.is_const())
138 throw Error(_("Can only export Canvas when used as constant parameter"));
139 Canvas::Handle canvas(value_desc.get_value().get(Canvas::Handle()));
141 Action::Handle action(CanvasAdd::create());
143 action->set_param("canvas",get_canvas());
144 action->set_param("canvas_interface",get_canvas_interface());
145 action->set_param("src",canvas);
146 action->set_param("id",name);
148 assert(action->is_ready());
149 if(!action->is_ready())
150 throw Error(Error::TYPE_NOTREADY);
152 add_action_front(action);
158 if(value_desc.is_value_node())
160 if(value_desc.get_value_node()->is_exported())
161 throw Error(_("ValueBase is already exported"));
163 value_node=value_desc.get_value_node();
167 if(!value_desc.parent_is_layer_param())
168 throw Error(_("Unable to export parameter. (Bug?)"));
170 value_node=ValueNode_Const::create(value_desc.get_value());
172 Action::Handle action(LayerParamConnect::create());
174 action->set_param("canvas",get_canvas());
175 action->set_param("canvas_interface",get_canvas_interface());
176 action->set_param("layer",value_desc.get_layer());
177 action->set_param("param",value_desc.get_param_name());
178 action->set_param("value_node",value_node);
180 assert(action->is_ready());
181 if(!action->is_ready())
182 throw Error(Error::TYPE_NOTREADY);
184 add_action_front(action);
187 Action::Handle action(ValueNodeAdd::create());
189 action->set_param("canvas",get_canvas());
190 action->set_param("canvas_interface",get_canvas_interface());
191 action->set_param("new",value_node);
192 action->set_param("name",name);
194 assert(action->is_ready());
195 if(!action->is_ready())
196 throw Error(Error::TYPE_NOTREADY);
198 add_action_front(action);