Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/metaobjects/image2D/image2D.cc

Go to the documentation of this file.
00001 /* $Id: image2D.cc,v 1.1 2002/08/25 16:38:06 reed Exp $ */
00002 
00003 
00004 /*
00005     Image2D metaobject implementation
00006     Reed Hedges <reed@interreality.org> August 2002
00007 
00008     Copyright (C) 2002 Reed Hedges
00009 
00010     This library is free software; you can redistribute it and/or
00011     modify it under the terms of the GNU Lesser General Public
00012     License as published by the Free Software Foundation; either
00013     version 2 of the License, or (at your option) any later version.
00014 
00015     This library is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018     Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public
00021     License along with this library; if not, write to the Free Software
00022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00023 
00024 */
00025 
00026 /** @file image2D.cc Code: a MetaObject for Image2D object types. */
00027 
00028 #include "vos/vos.hh"
00029 #include "property/property.hh"
00030 #include "image2D.hh"
00031 
00032 /* Constructor */
00033 Image2D::Image2D(MetaObject* s) : MetaObject(s) {
00034     accessControl = &NoPropertyAccessControl::static_;
00035 }
00036 
00037 /* Destructor */
00038 Image2D::~Image2D() {
00039 }
00040 
00041 LocalImage2D::LocalImage2D(MetaObject* s) : Image2D(s), MetaObject(s)
00042 {
00043 }
00044 
00045 LocalImage2D::~LocalImage2D() {
00046 }
00047 
00048 /* Initialize required subobjects: */
00049 void LocalImage2D::initialize() {
00050 
00051     pREF(LocalSite*, localsite, Site::getDefaultPeer(),
00052     try {
00053         rREF(Vobject&, v, findObject("image2D:position"), );
00054     } catch(NoSuchObjectError) {
00055         setPosition(0, 0);
00056     }
00057     try {
00058         rREF(Vobject&, v, findObject("image2D:orientation"), );
00059     } catch(NoSuchObjectError) {
00060         setOrientation(0.0);
00061     }
00062     try {
00063         rREF(Vobject&, v, findObject("image2D:scaling"), );
00064     } catch(NoSuchObjectError) {
00065         setScaling(100, 100);
00066     }
00067     try {
00068         rREF(Vobject&, v, findObject("image2D:image"), );
00069     } catch(NoSuchObjectError) {
00070         setImage("undefined", "?");
00071     }
00072     );
00073 }
00074 
00075 void LocalImage2D::initialize(PropertyAccessControl* ac) {
00076     accessControl = ac;
00077     initialize();
00078 }
00079     
00080 
00081 RemoteImage2D::RemoteImage2D(MetaObject* s) : Image2D(s), MetaObject(s)
00082 {
00083 }
00084 
00085 RemoteImage2D::~RemoteImage2D() {
00086 }
00087 
00088 /* Return type string ("2D:image2D") */
00089 
00090 const string Image2D::getType() {
00091     return string("image2D:image2D");
00092 }
00093 
00094 /* Register extenders with libvos MetaFactory */
00095 void Image2D::registerExtenders() {
00096     LocalSite::addLocalObjectExtension(typeid(LocalImage2D).name(), &LocalImage2D::new_LocalImage2D);
00097     LocalSite::addLocalObjectExtension(typeid(Image2D).name(), &LocalImage2D::new_LocalImage2D);
00098     LocalSite::addLocalObjectExtension("image2D:image2D", &LocalImage2D::new_LocalImage2D);
00099     RemoteSite::addRemoteObjectExtension(typeid(RemoteImage2D).name(), &RemoteImage2D::new_RemoteImage2D);
00100     RemoteSite::addRemoteObjectExtension(typeid(Image2D).name(), &RemoteImage2D::new_RemoteImage2D); 
00101     RemoteSite::addRemoteObjectExtension("image2D:image2D", &RemoteImage2D::new_RemoteImage2D);     
00102 }
00103 
00104 /* Get and set Subproperties and other Subobjects */
00105 
00106 void Image2D::getPosition(double& x, double& y) {
00107     rREF(Vobject&, v, findObject("image2D:position"), 
00108         string s;
00109         meta_cast<Property&>(v).read(s); 
00110         sscanf(s.c_str(), "%lf %lf", &x, &y);
00111     );
00112 }
00113 
00114 
00115 void Image2D::setPosition(double x, double y, PropertyAccessControl* ac) {
00116     if(ac == NULL)
00117         ac = accessControl;
00118     char s[20];
00119     snprintf(s, sizeof(s), "%f %f", x, y);
00120     Property::setProperty(*this, "image2D:position", s, "text/x-vector-float", ac);
00121 }
00122 
00123 double Image2D::getOrientation() {
00124     double o = 0;
00125     rREF(Vobject&, v, findObject("image2D:orientation"), 
00126         string s;
00127         meta_cast<Property&>(v).read(s);
00128         sscanf(s.c_str(), "%lf", &o);
00129      );
00130     return o;
00131 }
00132 
00133 
00134 void Image2D::setOrientation(double o, PropertyAccessControl* ac) {
00135     if(ac == NULL)
00136         ac = accessControl;
00137     char s[40];
00138     snprintf(s, sizeof(s), "%f", o);
00139     Property::setProperty(*this, "image2D:orientation", s, "text/x-vector-float", ac);
00140 }
00141 
00142 void Image2D::getScaling(double& x, double& y) {
00143     string s;
00144     rREF(Vobject&, v, findObject("image2D:scaling"), s = meta_cast<Property&>(v).read(); 
00145         sscanf(s.c_str(), "%lf %lf", &x, &y);
00146     );
00147 }
00148 
00149 
00150 void Image2D::setScaling(double x, double y, PropertyAccessControl* ac) {
00151     if(ac == NULL)
00152         ac = accessControl;
00153     char s[40];
00154     snprintf(s, sizeof(s), "%f %f", x, y); 
00155     Property::setProperty(*this, "image2D:scaling", s, "text/x-vector-float", ac);
00156 }
00157 
00158 string Image2D::getImage() {
00159     string s;
00160     rREF(Vobject&, v, findObject("image2D:image"), 
00161         meta_cast<Property&>(v).read(s); 
00162     );
00163     return s;
00164 }
00165 
00166 void Image2D::getImage(string& s) {
00167     rREF(Vobject&, v, findObject("image2D:image"), 
00168         meta_cast<Property&>(v).read(s); 
00169     );
00170 }
00171 
00172 
00173 string Image2D::getImageDatatype() {
00174     string s;
00175     rREF(Vobject&, v, findObject("image2D:image"), s = meta_cast<Property&>(v).getDataType(); );
00176     return s;
00177 }
00178 
00179 void Image2D::setImage(const string& value, const string& datatype,
00180 PropertyAccessControl* ac) {
00181     if(ac == NULL)
00182         ac = accessControl;
00183     Property::setProperty(*this, "image2D:image", value, datatype, ac);
00184 }
00185 
00186 void Image2D::setImageFromFile(const string& filename, const string& datatype, PropertyAccessControl* ac) {
00187     cerr << "setimagefromfile: ";
00188     cerr << "reading from " << filename << endl;
00189 
00190     // not the best way: use c++ stream classes or buffered input?
00191     FILE* F = fopen(filename.c_str(), "r");
00192     string data = "";
00193     char c;
00194     while( (c = fgetc(F)) != EOF) {
00195         data += c;
00196     }
00197     fclose(F);
00198     setImage(data, datatype, ac);
00199 }
00200 
00201 int Image2D::getImageLength() {
00202     int l; 
00203     rREF(Vobject&, v, findObject("image2D:image"), l = meta_cast<Property&>(v).getLength(); );
00204     return l;
00205 }
00206 
00207 /* Process local object messages */
00208 void LocalImage2D::sendMessage(Message* m) {
00209 
00210 
00211     /* Let superclass have message */
00212     Image2D::sendMessage(m);
00213 }
00214 
00215 
00216 
00217 
00218 
00219 /* Process remote update messages */
00220 void RemoteImage2D::sendUpdateMessage(Message* m) {
00221 
00222 
00223     /* branch to update message handlers specific to RemoteImage2D */
00224 
00225     /* let superclass have message... */
00226     Image2D::sendUpdateMessage(m);
00227 }
00228 
00229 
00230 /* Generators for factory */
00231 
00232 
00233 MetaObject* LocalImage2D::new_LocalImage2D(MetaObject *s, const string& type) {
00234     LocalImage2D* o = new LocalImage2D(s);
00235     return o;
00236 }
00237 
00238 MetaObject* RemoteImage2D::new_RemoteImage2D(MetaObject *s, const string& type) {
00239     return new RemoteImage2D(s);
00240 }

Generated on Tue Aug 12 03:55:44 2003 for Interreality Project - VOS by doxygen 1.3.2