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

vos/gui/gui/input_numeric.cc

Go to the documentation of this file.
00001 /* $Id: input_numeric.cc,v 1.6 2003/07/23 00:17:20 reed Exp $ */
00002 
00003 /*  Copyright (C) 2003 Reed Hedges <reed@interreality.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00018 
00019 */
00020 
00021 
00022 
00023 #include <vos/corelibs/vos/vos.hh>
00024 #include <vos/metaobjects/property/property.hh>
00025 #include "input_numeric.hh"
00026 
00027 using namespace VOSGUI;
00028 
00029 /* Constructor */
00030 NumericInput::NumericInput(MetaObject* s) : MetaObject(s), Widget(s), Input(s)
00031 {
00032 }
00033 
00034 /* Destructor */
00035 NumericInput::~NumericInput() {
00036 }
00037 
00038 
00039 LocalNumericInput::LocalNumericInput(MetaObject* s) : NumericInput(s), MetaObject(s), LocalWidget(s), Widget(s), Input(s), LocalInput(s)
00040 {
00041 }
00042 
00043 LocalNumericInput::~LocalNumericInput() {
00044 }
00045 
00046 /* Initialize required subobjects: */
00047 
00048 
00049 
00050 
00051 RemoteNumericInput::RemoteNumericInput(MetaObject* s) : NumericInput(s), MetaObject(s), Widget(s), RemoteWidget(s), Input(s), RemoteInput(s)
00052 {
00053 
00054 }
00055 
00056 RemoteNumericInput::~RemoteNumericInput() {
00057 }
00058 
00059 /* Return type string ("gui:widget.input.numeric") */
00060 
00061 const string NumericInput::getType() {
00062     return string("gui:widget.input.numeric");
00063 }
00064 
00065 /* Register extenders with libvos MetaFactory */
00066 void NumericInput::registerExtenders() {
00067     LocalSite::addLocalObjectExtension(typeid(LocalNumericInput).name(), &LocalNumericInput::new_LocalNumericInput);
00068     LocalSite::addLocalObjectExtension(typeid(NumericInput).name(), &LocalNumericInput::new_LocalNumericInput);
00069     LocalSite::addLocalObjectExtension("gui:widget.input.numeric", &LocalNumericInput::new_LocalNumericInput);
00070     RemoteSite::addRemoteObjectExtension(typeid(RemoteNumericInput).name(), &RemoteNumericInput::new_RemoteNumericInput);
00071     RemoteSite::addRemoteObjectExtension(typeid(NumericInput).name(), &RemoteNumericInput::new_RemoteNumericInput);
00072     RemoteSite::addRemoteObjectExtension("gui:widget.input.numeric", &RemoteNumericInput::new_RemoteNumericInput);
00073 }
00074 
00075 /* Get and set Subproperties and other Subobjects */
00076 
00077 void NumericInput::setValue(double v) {
00078     char p[32];
00079     snprintf(p, sizeof(p), "%lg", v);
00080     setTarget(p);
00081 }
00082 
00083 double NumericInput::getValue() {
00084     return Property::getFloatProperty(*this, "gui:target");
00085 }
00086  
00087 double NumericInput::getMaximum() {
00088     string s;
00089     double m;
00090     try {
00091         vRef<Vobject> v = findObject("gui:maximum");
00092         Property* p = meta_cast<Property*>(&v);
00093         if(!p)
00094             throw bad_cast();
00095         p->read(s);
00096         string mdt = p->getDataType();
00097         if(mdt == "text/x-float") {
00098             sscanf(s.c_str(), "%lg", &m);
00099         } else {
00100             LOG("VOSGUI::NumericInput", 0, "Sorry, the datatype \"" << mdt << " has not been implemented yet!");
00101             return 1.0;
00102         }
00103         return m;
00104     } catch(exception& e) {
00105         LOG("VOSGUI::NumericInput", 1, "Got exception in getMaximum: " << e.what());
00106         return 1.0;
00107     }
00108 }
00109 
00110 string NumericInput::getMaximumDatatype() {
00111     vRef<Vobject> v = findObject("gui:maximum");
00112     Property* p  = meta_cast<Property*>(&v);
00113     if(!p) throw bad_cast();
00114     return p->getDataType();
00115 }
00116 
00117 void NumericInput::setMaximum(const double value, PropertyAccessControl* ac) {
00118     if(ac == NULL)
00119         ac = accessControl;
00120     char s[32];
00121     snprintf(s, sizeof(s), "%.15g", value);
00122     Property::setProperty(*this, "gui:maximum", s, "text/x-float", ac);
00123 }
00124 
00125 void NumericInput::setRange(double min, double max, PropertyAccessControl* ac) {
00126     setMinimum(min, ac);
00127     setMaximum(max, ac);
00128 }
00129 
00130 Property* NumericInput::getMaximumObject() {
00131     return meta_cast<Property*>(&findObject("gui:maximum"));
00132 }
00133 
00134 void NumericInput::setMaximumObject(Property* newobj) {
00135     try {
00136         vRef<ParentChildRelation> pcr = findChild("gui:maximum");
00137         setChild(pcr->position, "gui:maximum", newobj);
00138     } catch (NoSuchObjectError) {
00139         insertChild(-1, "gui:maximum", newobj);
00140     }
00141 }
00142 
00143 
00144 
00145 double NumericInput::getMinimum() {
00146     string s;
00147     double m;
00148     try {
00149         vRef<Vobject> v = findObject("gui:minimum");
00150         Property* p = meta_cast<Property*>(&v);
00151         if(!p) {
00152             throw bad_cast();
00153         }
00154         p->read(s);
00155         string mdt = p->getDataType();
00156         if(mdt == "text/x-float") {
00157             sscanf(s.c_str(), "%lg", &m);
00158         } else {
00159             LOG("VOSGUI::NumericInput", 0, "Sorry, the datatype \"" << mdt << " has not been implemented yet!");
00160             return 0.0;
00161         }
00162         return m;
00163     } catch(exception& e) {
00164         LOG("VOSGUI::NumericInput", 2, "Warning: Got exception in getMinimum: " << e.what());
00165         return 0.0;
00166     }
00167 }
00168 
00169 string NumericInput::getMinimumDatatype() {
00170     vRef<Vobject> v = findObject("gui:minimum");
00171     Property* p = meta_cast<Property*>(&v);
00172     if(!p) throw bad_cast();
00173     return p->getDataType();
00174 }
00175 
00176 void NumericInput::setMinimum(const double value, PropertyAccessControl* ac) {
00177     if(ac == NULL)
00178         ac = accessControl;
00179     char s[32];
00180     snprintf(s, sizeof(s), "%.15g", value);
00181     Property::setProperty(*this, "gui:minimum", s, "text/x-float", ac);
00182 }
00183 
00184 Property* NumericInput::getMinimumObject() {
00185     return meta_cast<Property*>(&findObject("gui:minimum"));
00186 }
00187 
00188 void NumericInput::setMinimumObject(Property* newobj) {
00189     try {
00190         vRef<ParentChildRelation> pcr = findChild("gui:minimum");
00191         setChild(pcr->position, "gui:minimum", newobj);
00192     } catch (NoSuchObjectError) {
00193         insertChild(-1, "gui:minimum", newobj);
00194     }
00195 }
00196 
00197 
00198 double NumericInput::getIncrement() {
00199     string s;
00200     double i;
00201     try {
00202         vRef<Property> p = meta_cast<Property*>(&findObject("gui:increment"));
00203         if(!&p) throw bad_cast();
00204         p->read(s);
00205         string idt = p->getDataType();
00206         if(idt == "text/x-float") {
00207             sscanf(s.c_str(), "%lg", &i);
00208         } else {
00209             LOG("VOSGUI::NumericInput", 0, "Sorry, the datatype \"" << idt << " has not been implemented yet!");
00210             return 0.1;
00211         }
00212         return i;
00213     } catch(...) {
00214         return 0.1;
00215     }
00216 }
00217 
00218 string NumericInput::getIncrementDatatype() {
00219     vRef<Vobject> v = findObject("gui:increment");
00220     Property* p = meta_cast<Property*>(&v);
00221     if(!p) throw bad_cast();
00222     return p->getDataType();
00223 }
00224 
00225 void NumericInput::setIncrement(const double value, PropertyAccessControl* ac) {
00226     if(ac == NULL)
00227         ac = accessControl;
00228     char s[32];
00229     snprintf(s, sizeof(s), "%.15g", value);
00230     Property::setProperty(*this, "gui:increment", s, "text/x-float", ac);
00231 }
00232 
00233 Property* NumericInput::getIncrementObject() {
00234     return meta_cast<Property*>(&findObject("gui:increment"));
00235 }
00236 
00237 void NumericInput::setIncrementObject(Property* newobj) {
00238     try {
00239         vRef<ParentChildRelation> pcr = findChild("gui:increment");
00240         setChild(pcr->position, "gui:increment", newobj);
00241     } catch (NoSuchObjectError) {
00242         insertChild(-1, "gui:increment", newobj);
00243     }
00244 }
00245 /* Generators for factory */
00246 
00247 MetaObject* LocalNumericInput::new_LocalNumericInput(MetaObject *s, const string& type) {
00248     LocalNumericInput* o = new LocalNumericInput(s);
00249     return o;
00250 }
00251 
00252 MetaObject* RemoteNumericInput::new_RemoteNumericInput(MetaObject *s, const string& type) {
00253     return new RemoteNumericInput(s);
00254 }
00255 

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