00001
00002
00003 #include "Iguana/GLBrowsers/interface/Ig3DVectorBaseControl.h"
00004 #include "Iguana/GLBrowsers/interface/IgControlCategory.h"
00005 #include "Iguana/GLBrowsers/interface/IgQtRangeControlFloat.h"
00006 #include "Iguana/GLBrowsers/interface/IgQtRangeSetting.h"
00007 #include "Iguana/GLBrowsers/interface/IgQtAxisAlignment.h"
00008 #include "Iguana/GLBrowsers/pixmaps/nx_rot.xpm"
00009 #include "Iguana/GLBrowsers/pixmaps/px_rot.xpm"
00010 #include "Iguana/GLBrowsers/pixmaps/ny_rot.xpm"
00011 #include "Iguana/GLBrowsers/pixmaps/py_rot.xpm"
00012 #include "Iguana/GLBrowsers/pixmaps/nz_rot.xpm"
00013 #include "Iguana/GLBrowsers/pixmaps/pz_rot.xpm"
00014 #include <classlib/utils/DebugAids.h>
00015 #include <qlayout.h>
00016 #include <qpixmap.h>
00017 #include <qlabel.h>
00018 #include <qtoolbutton.h>
00019 #include <qwhatsthis.h>
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 Ig3DVectorBaseControl::Ig3DVectorBaseControl (IgControlCategory *pane,
00032 QString label,
00033 Style style,
00034 unsigned int size,
00035 const QString &colSepLabels)
00036 : Ig3DFieldControl (pane),
00037 m_controls (0),
00038 m_alignment (0),
00039 m_offset (3)
00040 {
00041 ASSERT (pane);
00042 ASSERT (pane->bodyArea ());
00043 ASSERT (pane->bodyLayout ());
00044 ASSERT (size);
00045
00046 std::vector<QString> labels;
00047 QString tmpLabels (colSepLabels);
00048 for(unsigned int i = 0; i < size; i++)
00049 labels.push_back (IgQtRangeControlCommon::getSettingItem (tmpLabels));
00050
00051 QWidget *area = pane->bodyArea ();
00052 int parts = AllParts;
00053 int ctlparts = IgQtRangeControlFloat::AllParts;
00054
00055
00056 QWidget *vlab = makeIndentedLabel (label, area);
00057 addGridWidget (vlab, gridRows (), 0);
00058 QString tips ("Set the \"");
00059 tips += label + "\" of the item";
00060 QWhatsThis::add (vlab, tips.latin1 ());
00061
00062
00063 switch (style)
00064 {
00065 case DirectionStyle:
00066 case PositionStyle:
00067 case PositionWOAStyle:
00068 ASSERT (size >= m_offset);
00069 if (labels[0].isEmpty ()) labels[0] = "X Axis";
00070 if (labels[1].isEmpty ()) labels[1] = "Y Axis";
00071 if (labels[2].isEmpty ()) labels[2] = "Z Axis";
00072 parts &= ~(RotatorPart | RotatorButtonPart);
00073 if (style == PositionWOAStyle)
00074 parts &= ~AlignmentPart;
00075 break;
00076
00077 case RotationStyle:
00078 ASSERT (size >= m_offset);
00079 if (labels[0].isEmpty ()) labels[0] = "Rotate X";
00080 if (labels[1].isEmpty ()) labels[1] = "Rotate Y";
00081 if (labels[2].isEmpty ()) labels[2] = "Rotate Z";
00082 parts &= ~AlignmentPart;
00083 ctlparts &= ~(IgQtRangeControlFloat::ValuePart
00084 | IgQtRangeControlFloat::SliderPart);
00085
00086 break;
00087 case Vector:
00088 parts &= ~AlignmentPart;
00089 m_offset = 0;
00090 break;
00091 }
00092
00093 for(unsigned int i = m_offset; i < size; i++)
00094 if (labels[i].isEmpty ()) labels[i] = QString("Index ")
00095 + QString::number(i-m_offset);
00096
00097 pane->pushIndent ();
00098
00099 if (m_offset)
00100 {
00101 makeControl (pane, labels[0], parts, ctlparts,
00102 QPixmap (px_rot_xpm), QPixmap (nx_rot_xpm));
00103 makeControl (pane, labels[1], parts, ctlparts,
00104 QPixmap (py_rot_xpm), QPixmap (ny_rot_xpm));
00105 makeControl (pane, labels[2], parts, ctlparts,
00106 QPixmap (pz_rot_xpm), QPixmap (nz_rot_xpm));
00107
00108
00109 if (parts & AlignmentPart)
00110 {
00111 m_alignment = new IgQtAxisAlignment (area);
00112 addGridWidget (makeSpacedBox (area,
00113 m_alignment->widget ()),
00114 gridRows (), 1);
00115
00116 connect (this, SIGNAL (editable (bool)),
00117 m_alignment->widget (),SLOT (setEnabled (bool)));
00118 connect (m_alignment, SIGNAL (dirty()),
00119 this, SLOT (alignToAxis ()));
00120 connect (this, SIGNAL (clean()),
00121 m_alignment, SLOT (setClean ()));
00122 }
00123
00124 for(unsigned int i = 0; i < m_offset; i++)
00125 m_controls[i]->updateEditSettingConnection (m_controls[0],
00126 SLOT (editSettings (void)));
00127
00128 for(unsigned int i = 1; i < m_offset; i++)
00129 m_controls[i]->setEmitSettingsChanged (false);
00130
00131 connect (m_controls[0], SIGNAL (settingsChanged (void)),
00132 this, SLOT (syncSettings1 (void)));
00133 }
00134
00135 for(unsigned int i = m_offset; i < size; i++)
00136 makeControl (pane, labels[i], parts, ctlparts,
00137 QPixmap (), QPixmap ());
00138
00139 pane->popIndent ();
00140
00141 for(unsigned int i = m_offset; i < size; i++)
00142 m_controls[i]->updateEditSettingConnection (m_controls[m_offset],
00143 SLOT (editSettings (void)));
00144
00145 for(unsigned int i = m_offset+1; i < size; i++)
00146 m_controls[i]->setEmitSettingsChanged (false);
00147
00148 if (m_offset < size)
00149 connect (m_controls[m_offset], SIGNAL (settingsChanged (void)),
00150 this, SLOT (syncSettings2 (void)));
00151
00152 connect (this, SIGNAL (editable (bool)), vlab, SLOT (setEnabled (bool)));
00153
00154 emit clean ();
00155 }
00156
00157 void
00158 Ig3DVectorBaseControl::makeControl (IgControlCategory *pane, QString label,
00159 int parts, int ctlparts,
00160 QPixmap npix, QPixmap ppix)
00161 {
00162 ASSERT (pane);
00163 ASSERT (pane->bodyArea ());
00164 ASSERT (pane->bodyLayout ());
00165
00166 QWidget *area = pane->bodyArea ();
00167 int row = gridRows ();
00168
00169 ASSERT (row >= 0);
00170
00171 IgQtRangeControlFloat *ctl = new IgQtRangeControlFloat (area, ctlparts);
00172 QWidget *vlab = makeIndentedLabel (label, area);
00173 addGridWidget (vlab, row, 0);
00174 addGridWidget (makeSpacedBox (area, ctl->widget ()), row, 1);
00175 if (! label.isEmpty())
00176 {
00177 QString tips ("Set the \"");
00178 tips += label + "\" of the item";
00179 QWhatsThis::add (vlab, tips.latin1 ());
00180 }
00181
00182 if (parts & RotatorPart)
00183 {
00184 ctl->setBoundaryHandling (IgQtRangeControlFloat::MODULATE);
00185 ctl->setRange (-180,180);
00186 ctl->setSmallStep (1);
00187 ctl->setLongStep (5);
00188 ctl->setValue (0);
00189 }
00190
00191 if (parts & RotatorButtonPart)
00192 {
00193 QToolButton *rotationButton = new QToolButton (0);
00194 rotationButton->setPixmap (QPixmap (npix));
00195 rotationButton->setAutoRaise (true);
00196 rotationButton->setAutoRepeat (true);
00197 ctl->addRevButton (rotationButton);
00198 rotationButton = new QToolButton (0);
00199 rotationButton->setPixmap (QPixmap (ppix));
00200 rotationButton->setAutoRaise (true);
00201 rotationButton->setAutoRepeat (true);
00202 ctl->addFwdButton (rotationButton);
00203 }
00204
00205 ctl->valueEditable (false);
00206
00207 connect(ctl, SIGNAL(dirty()), this, SLOT(setDirty ()));
00208 connect(this, SIGNAL(clean()), ctl, SLOT(setClean ()));
00209 connect(pane, SIGNAL(tracking(bool)), ctl, SLOT(resetChangedValue(bool)));
00210 connect(this, SIGNAL(editable(bool)), ctl->widget(),SLOT(setEnabled(bool)));
00211 connect(this, SIGNAL(editable(bool)), vlab, SLOT(setEnabled(bool)));
00212
00213 m_controls.push_back (ctl);
00214 }
00215
00219 IgQtRangeControlFloat *
00220 Ig3DVectorBaseControl::control (unsigned int index) const
00221 { ASSERT (index < m_controls.size ()); return m_controls[index]; }
00222
00223 std::vector<IgQtRangeControlFloat *>
00224 Ig3DVectorBaseControl::controls (void) const
00225 { return m_controls; }
00229 float
00230 Ig3DVectorBaseControl::value (unsigned int index) const
00231 { ASSERT (index < m_controls.size ()); return m_controls[index]->value (); }
00232
00233 std::vector<float>
00234 Ig3DVectorBaseControl::values (void) const
00235 {
00236 std::vector<float> data;
00237 for(unsigned int i =0; i < m_controls.size (); i++)
00238 data.push_back (m_controls[i]->value ());
00239 return data;
00240 }
00241
00242 void
00243 Ig3DVectorBaseControl::setValues (const float *values, unsigned int size)
00244 {
00245 for(unsigned int i = 0; i < size; i++)
00246 disconnect (m_controls[i], SIGNAL(dirty()), this, SLOT(setDirty()));
00247
00248 for(unsigned int i = 0; i < size; i++)
00249 m_controls[i]->setValue (values[i]);
00250
00251 for(unsigned int i = 0; i < size; i++)
00252 connect (m_controls[i], SIGNAL(dirty()), this, SLOT(setDirty()));
00253
00254 setDirty (true);
00255 }
00256
00257 void
00258 Ig3DVectorBaseControl::setValues (const std::vector<float> &values)
00259 { setValues (&values[0], values.size ()); }
00260
00261 void
00262 Ig3DVectorBaseControl::setValue (float value, unsigned int index)
00263 { ASSERT (index < m_controls.size ()); m_controls[index]->setValue (value);}
00264
00265 void
00266 Ig3DVectorBaseControl::setDirty (bool dirty)
00267 { Ig3DFieldControl::setDirty (dirty); }
00268
00272 bool
00273 Ig3DVectorBaseControl::isChanged (void) const
00274 {
00275 for(unsigned int i = 0; i < m_controls.size (); i++)
00276 if (m_controls[i]->isValueChanged ())
00277 return true;
00278 return false;
00279 }
00280
00281 float
00282 Ig3DVectorBaseControl::change (unsigned int index) const
00283 { ASSERT (index < m_controls.size ()); return m_controls[index]->valueChange (); }
00284
00285 std::vector<float>
00286 Ig3DVectorBaseControl::changes (void) const
00287 {
00288 std::vector<float> data;
00289 for(unsigned int i =0; i < m_controls.size (); i++)
00290 data.push_back (m_controls[i]->valueChange ());
00291 return data;
00292 }
00293
00297 float
00298 Ig3DVectorBaseControl::minAxisAlign (void) const
00299 { ASSERT (m_alignment); return m_alignment->minAxisAlign (); }
00300
00301 float
00302 Ig3DVectorBaseControl::maxAxisAlign (void) const
00303 { ASSERT (m_alignment); return m_alignment->maxAxisAlign (); }
00304
00305 void
00306 Ig3DVectorBaseControl::setMinAxisAlign (float newval)
00307 { ASSERT (m_alignment); m_alignment->setMinAxisAlign (newval); }
00308
00309 void
00310 Ig3DVectorBaseControl::setMaxAxisAlign (float newval)
00311 { ASSERT (m_alignment); m_alignment->setMaxAxisAlign (newval); }
00312
00313 void
00314 Ig3DVectorBaseControl::alignToAxis (void)
00315 { ASSERT (m_alignment); setValues (m_alignment->value ().getValue (), 3); }
00316
00320 void
00321 Ig3DVectorBaseControl::updateValue (void)
00322 { setValues (values ()); }
00323
00324 void
00325 Ig3DVectorBaseControl::applyValue (void)
00326 { ASSERT (false); }
00330 void
00331 Ig3DVectorBaseControl::syncSettings1 (void)
00332 { syncSettings (0, m_offset); }
00333
00334 void
00335 Ig3DVectorBaseControl::syncSettings2 (void)
00336 { syncSettings (m_offset, m_controls.size ()); }
00337
00338 void
00339 Ig3DVectorBaseControl::syncSettings (unsigned int start, unsigned int end)
00340 {
00341 for(unsigned int i = start+1; i < end; i++)
00342 {
00343 m_controls[i]->setPrecision (m_controls[start]->precision ());
00344 m_controls[i]->setRange (m_controls[start]->minValue (),
00345 m_controls[start]->maxValue ());
00346 m_controls[i]->setSmallStep (m_controls[start]->getSmallStep ());
00347 m_controls[i]->setLongStep (m_controls[start]->getLongStep ());
00348 }
00349 fieldSettingsChanged ();
00350 }
00351
00352 QString
00353 Ig3DVectorBaseControl::getSettingString (void) const
00354 {
00355 QString setting (m_controls[0]->getSettingString ());
00356 if (m_offset < m_controls.size())
00357 IgQtRangeControlCommon::addSettingItem (m_controls[m_offset]->
00358 getSettingString (),
00359 setting);
00360 return setting;
00361 }
00362
00363 void
00364 Ig3DVectorBaseControl::setSettingString (QString &setting)
00365 {
00366 m_controls[0]->setSettingString (setting);
00367 if (m_offset < m_controls.size())
00368 m_controls[m_offset]->setSettingString (setting);
00369 }