1 /*! ========================================================================
3 ** Image Import Layer Implementation
4 ** $Id: import.cpp,v 1.2 2005/03/19 04:26:42 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
17 ** === N O T E S ===========================================================
19 ** ========================================================================= */
21 /* === H E A D E R S ======================================================= */
31 #include <sinfg/string.h>
32 #include <sinfg/time.h>
33 #include <sinfg/context.h>
34 #include <sinfg/paramdesc.h>
35 #include <sinfg/renddesc.h>
36 #include <sinfg/surface.h>
37 #include <sinfg/value.h>
38 #include <sinfg/valuenode.h>
39 #include <sinfg/canvas.h>
43 using namespace sinfg;
47 /* === M A C R O S ========================================================= */
49 /* === G L O B A L S ======================================================= */
51 SINFG_LAYER_INIT(Import);
52 SINFG_LAYER_SET_NAME(Import,"import");
53 SINFG_LAYER_SET_LOCAL_NAME(Import,_("Import"));
54 SINFG_LAYER_SET_CATEGORY(Import,_("Other"));
55 SINFG_LAYER_SET_VERSION(Import,"0.1");
56 SINFG_LAYER_SET_CVS_ID(Import,"$Id: import.cpp,v 1.2 2005/03/19 04:26:42 darco Exp $");
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
72 Import::on_canvas_set()
74 if(get_canvas())set_param("filename",filename);
78 Import::set_param(const String & param, const ValueBase &value)
82 if(param=="filename" && value.same_as(filename))
86 filename=value.get(filename);
92 String newfilename=value.get(string());
93 String filename_with_path;
95 // Get rid of any %20 crap
98 while((n=newfilename.find("%20"))!=String::npos)
99 newfilename.replace(n,3," ");
102 //if(get_canvas()->get_file_path()==dirname(newfilename))
104 // sinfg::info("Image seems to be in local directory. Adjusting path...");
105 // newfilename=basename(newfilename);
109 if(is_absolute_path(newfilename))
111 string curpath(cleanup_path(absolute_path(get_canvas()->get_file_path())));
112 while(basename(curpath)==".")curpath=dirname(curpath);
114 newfilename=relative_path(curpath,newfilename);
115 sinfg::info("basename(curpath)=%s, Path adjusted to %s",basename(curpath).c_str(),newfilename.c_str());
120 filename=newfilename;
122 if(newfilename.empty())
124 filename=newfilename;
130 // If we are already loaded, don't reload
131 if(filename==newfilename && importer)
133 sinfg::warning(strprintf(_("Filename seems to already be set to \"%s\" (%s)"),filename.c_str(),newfilename.c_str()));
137 assert(get_canvas());
139 if(is_absolute_path(newfilename))
140 filename_with_path=newfilename;
142 filename_with_path=get_canvas()->get_file_path()+ETL_DIRECTORY_SEPERATOR+newfilename;
144 handle<Importer> newimporter;
146 newimporter=Importer::open(absolute_path(filename_with_path));
150 newimporter=Importer::open(get_canvas()->get_file_path()+ETL_DIRECTORY_SEPERATOR+basename(newfilename));
153 sinfg::error(strprintf("Unable to create an importer object with file \"%s\"",filename_with_path.c_str()));
160 if(!newimporter->get_frame(surface,Time(0)))
162 sinfg::warning(strprintf("Unable to get frame from \"%s\"",filename_with_path.c_str()));
165 importer=newimporter;
166 filename=newfilename;
167 abs_filename=absolute_path(filename_with_path);
171 } catch(...) { set_amount(0); return false; }
173 return Layer_Bitmap::set_param(param,value);
177 Import::get_param(const String & param)const
183 if(param=="filename")
185 string curpath(cleanup_path(absolute_path(get_canvas()->get_file_path())));
186 return relative_path(curpath,abs_filename);
195 return Layer_Bitmap::get_param(param);
199 Import::get_param_vocab()const
201 Layer::Vocab ret(Layer_Bitmap::get_param_vocab());
203 ret.push_back(ParamDesc("filename")
204 .set_local_name(_("Filename"))
205 .set_description(_("File to import"))
206 .set_hint("filename")
208 ret.push_back(ParamDesc("time_offset")
209 .set_local_name(_("Time Offset"))
216 Import::set_time(Context context, Time time)const
218 if(get_amount() && importer && importer->is_animated())importer->get_frame(surface,time+time_offset);
219 //else surface.clear();
220 context.set_time(time);
224 Import::set_time(Context context, Time time, const Point &pos)const
226 if(get_amount() && importer && importer->is_animated())importer->get_frame(surface,time+time_offset);
227 //else surface.clear();
228 context.set_time(time,pos);