cm_parameter_ardev.h

00001 /* -- 2007-05-07 -- 
00002  *  ardev - an augmented reality library for robot developers
00003  *  Copyright 2005-2007 - Toby Collett (ardev _at_ plan9.net.nz)
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.1 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 #ifndef ARIDE_PARAMETER_ARDEV_H
00021 #define ARIDE_PARAMETER_ARDEV_H
00022 
00023 #include <qobject.h>
00024 #include <qlineedit.h>
00025 #include <qcheckbox.h>
00026 #include <qcombobox.h>
00027 #include <qpointer.h>
00028 
00029 #include "cm_parameter.h"
00030 #include <ardev/exception.h>
00031 #include <ardev/debug.h>
00032 
00033 class aride_object;
00034 
00035 // ARDev Object Types (ie Camera, Capture etc)
00036 
00037 class ARObjectParameterBase : public StringParameter
00038 {
00039         Q_OBJECT
00040         
00041         public:
00042                 ARObjectParameterBase(QString _Name, QString _Description, QString _DefaultValue="") 
00043                         : StringParameter(_Name,_Description,_DefaultValue) 
00044                 {
00045                         Section=-1;
00046                         wid = NULL;
00047                 };
00048                 virtual ~ARObjectParameterBase() {};
00049         
00050                 virtual QWidget * CreateTypeWidget() 
00051                 {       
00052                         dbg_print(ARDBG_VERBOSE,"creating new ardev_parameter with GUID: %s\n",static_cast<const char *> (Value.toAscii()));
00053                         
00054                         wid = new QComboBox();
00055                         id = wid->winId();
00056                         wid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
00057                         
00058                         // fill in values
00059                         for (list<aride_object *>::const_iterator itr = CurrentProject->Objects.begin(); itr != CurrentProject->Objects.end(); ++itr)
00060                         {
00061                                 if ((*itr)->Section == Section || (Section == -1 && (*itr)->Type == Type))
00062                                 {
00063                                         wid->addItem((*itr)->GetName(),(*itr)->GUID);   
00064                                 }       
00065                         }
00066                         int index;
00067                         if ((index = wid->findData(Value)) >= 0)
00068                                 wid->setCurrentIndex(index);
00069                         else if ((index = wid->currentIndex()) >= 0)
00070                                 Value = wid->itemData(index).toString();
00071                         QObject::connect(wid,SIGNAL(currentIndexChanged(int)),this,SLOT(ValueChanged(int)));
00072                         
00073                         return wid;
00074                 }; 
00075                 virtual QString toString() {return Value;};
00076                 virtual QString fromString(const QString & inString) 
00077                 { 
00078                         dbg_print(ARDBG_VERBOSE,"fromstring called on ardev_parameter with GUID: %s\n",static_cast<const char *> (inString.toAscii()));
00079                         Value = inString;
00080                         if (!wid)
00081                         {
00082                                 dbg_print(ARDBG_VERBOSE,"No Widget yet\n");
00083                                 return Value;
00084                         }
00085                         if (wid->currentIndex() == wid->findData(Value))
00086                         {
00087                                 dbg_print(ARDBG_VERBOSE,"Item already active\n");
00088                                 return Value;
00089                         }
00090                         int index;
00091                         if ((index = wid->findData(Value)) >= 0)
00092                         {
00093                                 dbg_print(ARDBG_VERBOSE,"Found item with GUID\n");
00094                                 wid->setCurrentIndex(index);
00095                         }
00096                         else if ((index = wid->currentIndex()) >= 0)
00097                         {
00098                                 dbg_print(ARDBG_VERBOSE,"Didnt find GUID so setting to current Item\n");
00099                                 Value = wid->itemData(index).toString();
00100                         }
00101                         return Value;
00102                 };
00103                 
00104                 virtual void update()
00105                 {
00106                         dbg_print(ARDBG_VERBOSE,"update called on ardev_parameter\n");
00107                         if (!wid)
00108                         {
00109                                 dbg_print(ARDBG_VERBOSE,"did not find widget to update\n");                                     
00110                                 return;
00111                         }
00112                         QString TempValue = Value; // need to preseve value accross the widget clear
00113                         wid->clear();
00114                         // fill in values
00115                         for (list<aride_object *>::const_iterator itr = CurrentProject->Objects.begin(); itr != CurrentProject->Objects.end(); ++itr)
00116                         {
00117                                 if ((*itr)->Section == Section || (Section == -1 && (*itr)->Type == Type))
00118                                 {
00119                                         wid->addItem((*itr)->GetName(),(*itr)->GUID);   
00120                                         dbg_print(ARDBG_VERBOSE,"Adding object to list: %s\n", static_cast<const char*> ((*itr)->GetName().toAscii()));
00121                                 }       
00122                         }
00123                         int index;
00124                         dbg_print(ARDBG_VERBOSE,"Looking for Value: %s\n", static_cast<const char*> (Value.toAscii()));
00125                         if ((index = wid->findData(TempValue)) >= 0)
00126                                 wid->setCurrentIndex(index);
00127                         else if ((index = wid->currentIndex()) >= 0)
00128                                 Value = wid->itemData(index).toString();
00129                 }               
00130         protected slots:
00131                 virtual void ValueChanged(int index) 
00132                 {
00133                         assert(wid);
00134                         dbg_print(ARDBG_VERBOSE, "ARObjectParameterBase Value changed to index %d\n",index);
00135                         fromString(wid->itemData(index).toString());
00136                 };
00137                 
00138         
00139         protected:
00140                 int Section;
00141                 QPointer<QComboBox> wid;
00142 };
00143 
00144 template<class T, ArideSection SectionInit>
00145 class ARObjectParameter : public ARObjectParameterBase
00146 {
00147         public:
00148                 ARObjectParameter(QString _Name, QString _Description, QString _DefaultValue="") : ARObjectParameterBase(_Name,_Description,_DefaultValue) {Section=SectionInit; Type=GetArideSectionTypeName(SectionInit);};
00149                 ~ARObjectParameter() {};
00150         
00151                 T GetClass() 
00152                 {
00153                         if (Value == "")
00154                                 throw aride_exception(ARDEV_CLASS_NOT_FOUND, __FILE__, __LINE__);
00155                         aride_object * temp = CurrentProject->GetObjectByGUID(Value);
00156                         if (temp == NULL)
00157                                 throw aride_exception(ARDEV_CLASS_NOT_FOUND, __FILE__, __LINE__);
00158                         if (temp->Section == Section)
00159                                 return reinterpret_cast<T> (temp->Handler);
00160                         throw aride_exception(ARDEV_CLASS_NOT_FOUND, __FILE__, __LINE__);
00161                 };      
00162 
00163 };
00164 
00165 template <class T>
00166 class ArideObjectHandler;
00167 
00168 typedef ArideObjectHandler<CameraObject> CameraObjectHandler;
00169 typedef ArideObjectHandler<CaptureObject> CaptureObjectHandler;
00170 typedef ArideObjectHandler<OutputObject> OutputObjectHandler;
00171 typedef ArideObjectHandler<PositionObject> PositionObjectHandler;
00172 //typedef ArideObjectHandler<RenderObject> RenderObjectHandler;
00173 
00174 class RenderObjectHandler;
00175 /*typedef CameraObjectHandler;
00176 typedef CaptureObjectHandler;
00177 typedef OutputObjectHandler;
00178 typedef PositionObjectHandler;*/
00179 
00180 typedef ARObjectParameter<CameraObjectHandler*,ARIDE_CAMERA> CameraObjectParameter;
00181 typedef ARObjectParameter<CaptureObjectHandler*,ARIDE_CAPTURE> CaptureObjectParameter;
00182 typedef ARObjectParameter<OutputObjectHandler*,ARIDE_OUTPUT> OutputObjectParameter;
00183 typedef ARObjectParameter<PositionObjectHandler*,ARIDE_POSITION> PositionObjectParameter;
00184 typedef ARObjectParameter<RenderObjectHandler*,ARIDE_RENDER> RenderObjectParameter;
00185 
00186 
00187 #endif

SourceForge.net Logo Generated on Sat May 12 15:25:43 2007 for ardev by doxygen 1.5.1