00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
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;
00113 wid->clear();
00114
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
00173
00174 class RenderObjectHandler;
00175
00176
00177
00178
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