00001
00002
00003
00004
00005
00006
00007 #include "CmdMediator.h"
00008 #include "ColorConstants.h"
00009 #include "ColorFilterSettings.h"
00010 #include "ColorFilterSettingsStrategyAbstractBase.h"
00011 #include "ColorFilterSettingsStrategyForeground.h"
00012 #include "ColorFilterSettingsStrategyHue.h"
00013 #include "ColorFilterSettingsStrategyIntensity.h"
00014 #include "ColorFilterSettingsStrategySaturation.h"
00015 #include "ColorFilterSettingsStrategyValue.h"
00016 #include "DocumentSerialize.h"
00017 #include "EngaugeAssert.h"
00018 #include "GridCoordDisable.h"
00019 #include "Logger.h"
00020 #include <QTextStream>
00021 #include <QXmlStreamWriter>
00022 #include "Xml.h"
00023
00024 ColorFilterSettings::ColorFilterSettings() :
00025 m_colorFilterMode (COLOR_FILTER_MODE_INTENSITY),
00026 m_intensityLow (INTENSITY_LOW_DEFAULT),
00027 m_intensityHigh (INTENSITY_HIGH_DEFAULT),
00028 m_foregroundLow (FOREGROUND_LOW_DEFAULT),
00029 m_foregroundHigh (FOREGROUND_HIGH_DEFAULT),
00030 m_hueLow (HUE_LOW_DEFAULT),
00031 m_hueHigh (HUE_HIGH_DEFAULT),
00032 m_saturationLow (SATURATION_LOW_DEFAULT),
00033 m_saturationHigh (SATURATION_HIGH_DEFAULT),
00034 m_valueLow (VALUE_LOW_DEFAULT),
00035 m_valueHigh (VALUE_HIGH_DEFAULT)
00036 {
00037 createStrategies ();
00038 }
00039
00040 ColorFilterSettings::ColorFilterSettings(ColorFilterMode colorFilterMode,
00041 int intensityLow,
00042 int intensityHigh,
00043 int foregroundLow,
00044 int foregroundHigh,
00045 int hueLow,
00046 int hueHigh,
00047 int saturationLow,
00048 int saturationHigh,
00049 int valueLow,
00050 int valueHigh) :
00051 m_colorFilterMode (colorFilterMode),
00052 m_intensityLow (intensityLow),
00053 m_intensityHigh (intensityHigh),
00054 m_foregroundLow (foregroundLow),
00055 m_foregroundHigh (foregroundHigh),
00056 m_hueLow (hueLow),
00057 m_hueHigh (hueHigh),
00058 m_saturationLow (saturationLow),
00059 m_saturationHigh (saturationHigh),
00060 m_valueLow (valueLow),
00061 m_valueHigh (valueHigh)
00062 {
00063 createStrategies ();
00064 }
00065
00066 ColorFilterSettings::ColorFilterSettings(const ColorFilterSettings &other) :
00067 m_colorFilterMode (other.colorFilterMode()),
00068 m_intensityLow (other.intensityLow()),
00069 m_intensityHigh (other.intensityHigh()),
00070 m_foregroundLow (other.foregroundLow()),
00071 m_foregroundHigh (other.foregroundHigh()),
00072 m_hueLow (other.hueLow()),
00073 m_hueHigh (other.hueHigh()),
00074 m_saturationLow (other.saturationLow()),
00075 m_saturationHigh (other.saturationHigh()),
00076 m_valueLow (other.valueLow()),
00077 m_valueHigh (other.valueHigh())
00078 {
00079 createStrategies ();
00080 }
00081
00082 ColorFilterSettings::ColorFilterSettings(QXmlStreamReader &reader)
00083 {
00084 loadXml(reader);
00085 createStrategies ();
00086 }
00087
00088 ColorFilterSettings &ColorFilterSettings::operator=(const ColorFilterSettings &other)
00089 {
00090 m_colorFilterMode = other.colorFilterMode();
00091 m_intensityLow = other.intensityLow();
00092 m_intensityHigh = other.intensityHigh();
00093 m_foregroundLow = other.foregroundLow();
00094 m_foregroundHigh = other.foregroundHigh();
00095 m_hueLow = other.hueLow();
00096 m_hueHigh = other.hueHigh();
00097 m_saturationLow = other.saturationLow();
00098 m_saturationHigh = other.saturationHigh();
00099 m_valueLow = other.valueLow();
00100 m_valueHigh = other.valueHigh();
00101
00102 createStrategies ();
00103
00104 return *this;
00105 }
00106
00107 ColorFilterMode ColorFilterSettings::colorFilterMode() const
00108 {
00109 return m_colorFilterMode;
00110 }
00111
00112 void ColorFilterSettings::createStrategies ()
00113 {
00114 m_strategies [COLOR_FILTER_MODE_FOREGROUND] = new ColorFilterSettingsStrategyForeground ();
00115 m_strategies [COLOR_FILTER_MODE_HUE ] = new ColorFilterSettingsStrategyHue ();
00116 m_strategies [COLOR_FILTER_MODE_INTENSITY ] = new ColorFilterSettingsStrategyIntensity ();
00117 m_strategies [COLOR_FILTER_MODE_SATURATION] = new ColorFilterSettingsStrategySaturation ();
00118 m_strategies [COLOR_FILTER_MODE_VALUE ] = new ColorFilterSettingsStrategyValue ();
00119 }
00120
00121 ColorFilterSettings ColorFilterSettings::defaultFilter ()
00122 {
00123 return ColorFilterSettings ();
00124 }
00125
00126 int ColorFilterSettings::foregroundHigh () const
00127 {
00128 return m_foregroundHigh;
00129 }
00130
00131 int ColorFilterSettings::foregroundLow () const
00132 {
00133 return m_foregroundLow;
00134 }
00135
00136 double ColorFilterSettings::high () const
00137 {
00138 if (m_strategies.contains (m_colorFilterMode)) {
00139 return m_strategies [m_colorFilterMode]->high (*this);
00140 } else {
00141 ENGAUGE_ASSERT (false);
00142 return m_strategies [COLOR_FILTER_MODE_INTENSITY]->high (*this);
00143 }
00144 }
00145
00146 int ColorFilterSettings::hueHigh () const
00147 {
00148 return m_hueHigh;
00149 }
00150
00151 int ColorFilterSettings::hueLow () const
00152 {
00153 return m_hueLow;
00154 }
00155
00156 int ColorFilterSettings::intensityHigh () const
00157 {
00158 return m_intensityHigh;
00159 }
00160
00161 int ColorFilterSettings::intensityLow () const
00162 {
00163 return m_intensityLow;
00164 }
00165
00166 void ColorFilterSettings::loadXml(QXmlStreamReader &reader)
00167 {
00168 LOG4CPP_INFO_S ((*mainCat)) << "ColorFilterSettings::loadXml";
00169
00170 bool success = true;
00171
00172 QXmlStreamAttributes attributes = reader.attributes();
00173
00174 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE) &&
00175 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW) &&
00176 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH) &&
00177 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW) &&
00178 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH) &&
00179 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW) &&
00180 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH) &&
00181 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW) &&
00182 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH) &&
00183 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW) &&
00184 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH)) {
00185
00186 setColorFilterMode ((ColorFilterMode) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE).toInt());
00187 setIntensityLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW).toInt());
00188 setIntensityHigh ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH).toInt());
00189 setForegroundLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW).toInt());
00190 setForegroundHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH).toInt());
00191 setHueLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW).toInt());
00192 setHueHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH).toInt());
00193 setSaturationLow ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW).toInt());
00194 setSaturationHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH).toInt());
00195 setValueLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW).toInt());
00196 setValueHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH).toInt());
00197
00198
00199 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
00200 (reader.name() != DOCUMENT_SERIALIZE_COLOR_FILTER)){
00201 loadNextFromReader(reader);
00202
00203 if (reader.atEnd()) {
00204 success = false;
00205 break;
00206 }
00207 }
00208 }
00209
00210 if (!success) {
00211 reader.raiseError (QObject::tr ("Cannot read curve filter data"));
00212 }
00213 }
00214
00215 double ColorFilterSettings::low () const
00216 {
00217 if (m_strategies.contains (m_colorFilterMode)) {
00218 return m_strategies [m_colorFilterMode]->low (*this);
00219 } else {
00220 ENGAUGE_ASSERT (false);
00221 return m_strategies [COLOR_FILTER_MODE_INTENSITY]->low (*this);
00222 }
00223 }
00224
00225 void ColorFilterSettings::printStream (QString indentation,
00226 QTextStream &str) const
00227 {
00228 str << indentation << "ColorFilterSettings\n";
00229
00230 indentation += INDENTATION_DELTA;
00231
00232 if (m_strategies.contains (m_colorFilterMode)) {
00233 return m_strategies [m_colorFilterMode]->printStream (*this,
00234 indentation,
00235 str);
00236 }
00237 }
00238
00239 int ColorFilterSettings::saturationHigh () const
00240 {
00241 return m_saturationHigh;
00242 }
00243
00244 int ColorFilterSettings::saturationLow () const
00245 {
00246 return m_saturationLow;
00247 }
00248
00249 void ColorFilterSettings::saveXml(QXmlStreamWriter &writer,
00250 const QString &curveName) const
00251 {
00252 LOG4CPP_INFO_S ((*mainCat)) << "ColorFilterSettings::saveXml";
00253
00254 writer.writeStartElement(DOCUMENT_SERIALIZE_COLOR_FILTER);
00255 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, curveName);
00256 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE, QString::number (m_colorFilterMode));
00257 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE_STRING, colorFilterModeToString (m_colorFilterMode));
00258 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW, QString::number (m_intensityLow));
00259 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH, QString::number (m_intensityHigh));
00260 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW, QString::number (m_foregroundLow));
00261 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH, QString::number (m_foregroundHigh));
00262 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW, QString::number (m_hueLow));
00263 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH, QString::number (m_hueHigh));
00264 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW, QString::number (m_saturationLow));
00265 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH, QString::number (m_saturationHigh));
00266 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW, QString::number (m_valueLow));
00267 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH, QString::number (m_valueHigh));
00268 writer.writeEndElement();
00269 }
00270
00271 void ColorFilterSettings::setColorFilterMode(ColorFilterMode colorFilterMode)
00272 {
00273 m_colorFilterMode = colorFilterMode;
00274 }
00275
00276 void ColorFilterSettings::setForegroundHigh (int foregroundHigh)
00277 {
00278 ENGAUGE_ASSERT (FOREGROUND_MIN <= foregroundHigh && foregroundHigh <= FOREGROUND_MAX);
00279 m_foregroundHigh = foregroundHigh;
00280 }
00281
00282 void ColorFilterSettings::setForegroundLow (int foregroundLow)
00283 {
00284 ENGAUGE_ASSERT (FOREGROUND_MIN <= foregroundLow && foregroundLow <= FOREGROUND_MAX);
00285 m_foregroundLow = foregroundLow;
00286 }
00287
00288 void ColorFilterSettings::setHigh (double s0To1)
00289 {
00290 if (m_strategies.contains (m_colorFilterMode)) {
00291 return m_strategies [m_colorFilterMode]->setHigh (*this,
00292 s0To1);
00293 } else {
00294 ENGAUGE_ASSERT (false);
00295 }
00296 }
00297
00298 void ColorFilterSettings::setHueHigh (int hueHigh)
00299 {
00300 ENGAUGE_ASSERT (HUE_MIN <= hueHigh && hueHigh <= HUE_MAX);
00301 m_hueHigh = hueHigh;
00302 }
00303
00304 void ColorFilterSettings::setHueLow (int hueLow)
00305 {
00306 ENGAUGE_ASSERT (HUE_MIN <= hueLow && hueLow <= HUE_MAX);
00307 m_hueLow = hueLow;
00308 }
00309
00310 void ColorFilterSettings::setIntensityHigh (int intensityHigh)
00311 {
00312 ENGAUGE_ASSERT (INTENSITY_MIN <= intensityHigh && intensityHigh <= INTENSITY_MAX);
00313 m_intensityHigh = intensityHigh;
00314 }
00315
00316 void ColorFilterSettings::setIntensityLow (int intensityLow)
00317 {
00318 ENGAUGE_ASSERT (INTENSITY_MIN <= intensityLow && intensityLow <= INTENSITY_MAX);
00319 m_intensityLow = intensityLow;
00320 }
00321
00322 void ColorFilterSettings::setLow (double s0To1)
00323 {
00324 if (m_strategies.contains (m_colorFilterMode)) {
00325 return m_strategies [m_colorFilterMode]->setLow (*this,
00326 s0To1);
00327 } else {
00328 ENGAUGE_ASSERT (false);
00329 }
00330 }
00331
00332 void ColorFilterSettings::setSaturationHigh (int saturationHigh)
00333 {
00334 ENGAUGE_ASSERT (SATURATION_MIN <= saturationHigh && saturationHigh <= SATURATION_MAX);
00335 m_saturationHigh = saturationHigh;
00336 }
00337
00338 void ColorFilterSettings::setSaturationLow (int saturationLow)
00339 {
00340 ENGAUGE_ASSERT (SATURATION_MIN <= saturationLow && saturationLow <= SATURATION_MAX);
00341 m_saturationLow = saturationLow;
00342 }
00343
00344 void ColorFilterSettings::setValueHigh (int valueHigh)
00345 {
00346 ENGAUGE_ASSERT (VALUE_MIN <= valueHigh && valueHigh <= VALUE_MAX);
00347 m_valueHigh = valueHigh;
00348 }
00349
00350 void ColorFilterSettings::setValueLow (int valueLow)
00351 {
00352 ENGAUGE_ASSERT (VALUE_MIN <= valueLow && valueLow <= VALUE_MAX);
00353 m_valueLow = valueLow;
00354 }
00355
00356 int ColorFilterSettings::valueHigh () const
00357 {
00358 return m_valueHigh;
00359 }
00360
00361 int ColorFilterSettings::valueLow () const
00362 {
00363 return m_valueLow;
00364 }