00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00030 NumericInput::NumericInput(MetaObject* s) : MetaObject(s), Widget(s), Input(s)
00031 {
00032 }
00033
00034
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
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
00060
00061 const string NumericInput::getType() {
00062 return string("gui:widget.input.numeric");
00063 }
00064
00065
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
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
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