00001
00002
00003
00004
00005
00006
00007 #include "CmdMediator.h"
00008 #include "DocumentModelPointMatch.h"
00009 #include "DocumentSerialize.h"
00010 #include "Logger.h"
00011 #include <QObject>
00012 #include <QTextStream>
00013 #include <QXmlStreamWriter>
00014 #include "Xml.h"
00015
00016 const double DEFAULT_MIN_POINT_SEPARATION = 20;
00017 const double DEFAULT_MAX_POINT_SIZE = 48;
00018 const ColorPalette DEFAULT_COLOR_ACCEPTED = COLOR_PALETTE_GREEN;
00019 const ColorPalette DEFAULT_COLOR_CANDIDATE = COLOR_PALETTE_YELLOW;
00020 const ColorPalette DEFAULT_COLOR_REJECTED = COLOR_PALETTE_RED;
00021
00022 DocumentModelPointMatch::DocumentModelPointMatch() :
00023 m_minPointSeparation (DEFAULT_MIN_POINT_SEPARATION),
00024 m_maxPointSize (DEFAULT_MAX_POINT_SIZE),
00025 m_paletteColorAccepted (DEFAULT_COLOR_ACCEPTED),
00026 m_paletteColorCandidate (DEFAULT_COLOR_CANDIDATE),
00027 m_paletteColorRejected (DEFAULT_COLOR_REJECTED)
00028 {
00029 }
00030
00031 DocumentModelPointMatch::DocumentModelPointMatch(const Document &document) :
00032 m_maxPointSize (document.modelPointMatch().maxPointSize()),
00033 m_paletteColorAccepted (document.modelPointMatch().paletteColorAccepted()),
00034 m_paletteColorCandidate (document.modelPointMatch().paletteColorCandidate()),
00035 m_paletteColorRejected (document.modelPointMatch().paletteColorRejected())
00036 {
00037 }
00038
00039 DocumentModelPointMatch::DocumentModelPointMatch(const DocumentModelPointMatch &other) :
00040 m_maxPointSize (other.maxPointSize()),
00041 m_paletteColorAccepted (other.paletteColorAccepted()),
00042 m_paletteColorCandidate (other.paletteColorCandidate()),
00043 m_paletteColorRejected (other.paletteColorRejected())
00044 {
00045 }
00046
00047 DocumentModelPointMatch &DocumentModelPointMatch::operator=(const DocumentModelPointMatch &other)
00048 {
00049 m_maxPointSize = other.maxPointSize();
00050 m_paletteColorAccepted = other.paletteColorAccepted();
00051 m_paletteColorCandidate = other.paletteColorCandidate();
00052 m_paletteColorRejected = other.paletteColorRejected();
00053
00054 return *this;
00055 }
00056
00057 void DocumentModelPointMatch::loadXml(QXmlStreamReader &reader)
00058 {
00059 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelPointMatch::loadXml";
00060
00061 bool success = true;
00062
00063 QXmlStreamAttributes attributes = reader.attributes();
00064
00065 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_POINT_SIZE) &&
00066 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED) &&
00067 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE) &&
00068 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED)) {
00069
00070 setMaxPointSize (attributes.value(DOCUMENT_SERIALIZE_POINT_MATCH_POINT_SIZE).toDouble());
00071 setPaletteColorAccepted ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED).toInt());
00072 setPaletteColorCandidate ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE).toInt());
00073 setPaletteColorRejected ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED).toInt());
00074
00075
00076 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
00077 (reader.name() != DOCUMENT_SERIALIZE_POINT_MATCH)){
00078 loadNextFromReader(reader);
00079 if (reader.atEnd()) {
00080 success = false;
00081 break;
00082 }
00083 }
00084 }
00085
00086 if (!success) {
00087 reader.raiseError (QObject::tr ("Cannot read point match data"));
00088 }
00089 }
00090
00091 double DocumentModelPointMatch::maxPointSize () const
00092 {
00093 return m_maxPointSize;
00094 }
00095
00096 ColorPalette DocumentModelPointMatch::paletteColorAccepted() const
00097 {
00098 return m_paletteColorAccepted;
00099 }
00100
00101 ColorPalette DocumentModelPointMatch::paletteColorCandidate() const
00102 {
00103 return m_paletteColorCandidate;
00104 }
00105
00106 ColorPalette DocumentModelPointMatch::paletteColorRejected() const
00107 {
00108 return m_paletteColorRejected;
00109 }
00110
00111 void DocumentModelPointMatch::printStream(QString indentation,
00112 QTextStream &str) const
00113 {
00114 str << indentation << "DocumentModelPointMatch\n";
00115
00116 indentation += INDENTATION_DELTA;
00117
00118 str << indentation << "minPointSeparation=" << m_minPointSeparation << "\n";
00119 str << indentation << "maxPointSize=" << m_maxPointSize << "\n";
00120 str << indentation << "colorAccepted=" << colorPaletteToString (m_paletteColorAccepted) << "\n";
00121 str << indentation << "colorCandidate=" << colorPaletteToString (m_paletteColorCandidate) << "\n";
00122 str << indentation << "colorRejected=" << colorPaletteToString (m_paletteColorRejected) << "\n";
00123 }
00124
00125 void DocumentModelPointMatch::saveXml(QXmlStreamWriter &writer) const
00126 {
00127 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelPointMatch::saveXml";
00128
00129 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_MATCH);
00130 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_POINT_SIZE, QString::number (m_maxPointSize));
00131 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED, QString::number (m_paletteColorAccepted));
00132 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_ACCEPTED_STRING, colorPaletteToString (m_paletteColorAccepted));
00133 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE, QString::number (m_paletteColorCandidate));
00134 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_CANDIDATE_STRING, colorPaletteToString (m_paletteColorCandidate));
00135 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED, QString::number (m_paletteColorRejected));
00136 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_MATCH_COLOR_REJECTED_STRING, colorPaletteToString (m_paletteColorRejected));
00137 writer.writeEndElement();
00138 }
00139
00140 void DocumentModelPointMatch::setMaxPointSize(double maxPointSize)
00141 {
00142 m_maxPointSize = maxPointSize;
00143 }
00144
00145 void DocumentModelPointMatch::setPaletteColorAccepted(ColorPalette paletteColorAccepted)
00146 {
00147 m_paletteColorAccepted = paletteColorAccepted;
00148 }
00149
00150 void DocumentModelPointMatch::setPaletteColorCandidate(ColorPalette paletteColorCandidate)
00151 {
00152 m_paletteColorCandidate = paletteColorCandidate;
00153 }
00154
00155 void DocumentModelPointMatch::setPaletteColorRejected(ColorPalette paletteColorRejected)
00156 {
00157 m_paletteColorRejected = paletteColorRejected;
00158 }