Developer documentation | Axl-2.5.1

axlCompositeCurveWriter.cpp
Go to the documentation of this file.
2 
4 
5 #include <dtkCoreSupport/dtkAbstractData.h>
6 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
7 
8 #include <QColor>
9 
12 
13  this->setObjectName(this->description());
14 }
15 
17 }
18 
20  return "axlCompositeCurveWriter";
21 }
22 
24  return "axlCompositeCurveWriter";
25 }
26 
27 QStringList axlCompositeCurveWriter::handled(void) const {
28  return QStringList() << "axlCompositeCurve";
29 }
30 
32  return dtkAbstractDataFactory::instance()->registerDataWriterType("axlCompositeCurveWriter", QStringList(), createaxlCompositeCurveWriter);
33 }
34 
35 bool axlCompositeCurveWriter::accept(dtkAbstractData *data) {
36  axlCompositeCurve *CompositeCurve = dynamic_cast<axlCompositeCurve*>(data);
37  if(CompositeCurve)
38  return true;
39 
40  return false;
41 }
42 
43 bool axlCompositeCurveWriter::reject(dtkAbstractData *data) {
44  return !this->accept(data);
45 }
46 
47 QDomElement axlCompositeCurveWriter::write(QDomDocument *doc, dtkAbstractData *data) {
48  axlCompositeCurve* comCur = dynamic_cast<axlCompositeCurve*>(data);
49 
51  QDomElement curElement = doc->createElement("composite_curve");
52  curElement.setAttribute("name", comCur->name());
53 
55  curElement.setAttribute("size", QString::number(comCur->size()));
56 
58  QColor qcolor = comCur->color();
59  QString color ;
60  QTextStream(&color) << QString::number(qcolor.red()) << " "
61  << QString::number(qcolor.green()) << " "
62  << QString::number(qcolor.blue()) << " "
63  << QString::number(comCur->opacity());
64  curElement.setAttribute("color", color);
65 
67  QString shader = comCur->shader();
68  QFileInfo shaderFileInfo(shader);
69  curElement.setAttribute("shader", shaderFileInfo.fileName());
70 
71  //Write curves
72 
73  for(int i = 0; i<comCur->count_curve(); i++)
74  {
75  QDomElement curveElement = doc->createElement("curve");
76  QString curveWriterTag = comCur->get_pt_curve_at_id(i)->identifier()+"Writer";
77  axlAbstractDataWriter* curveWriter = dynamic_cast<axlAbstractDataWriter*>(dtkAbstractDataFactory::instance()->writer(curveWriterTag));
78  QDomElement subCurveElement = curveWriter->write(doc, comCur->get_pt_curve_at_id(i));
79  curveElement.appendChild(subCurveElement);
80  curveElement.setAttribute("type",comCur->get_pt_curve_at_id(i)->identifier());
81  curElement.appendChild(curveElement);
82  }
83 
84  //return
85  return curElement;
86 
87 }
88 
89 QDomElement axlCompositeCurveWriter::elementByWriter(axlAbstractDataWriter *axl_writer, QDomDocument *doc, dtkAbstractData *data) {
90  QDomElement element;
91 
92  if(!axl_writer)
93  return element;
94 
95  if(!axl_writer->accept(data))
96  return element;
97 
98  element = axl_writer->write(doc, data);
99 
100  return element;
101 }
102 
103 dtkAbstractDataWriter *createaxlCompositeCurveWriter(void) {
104  return new axlCompositeCurveWriter;
105 }
QStringList handled(void) const
QString description(void) const
bool reject(dtkAbstractData *data)
virtual bool accept(dtkAbstractData *data)=0
int count_curve(void) const
axlAbstractCurve * get_pt_curve_at_id(int id) const
bool accept(dtkAbstractData *data)
QDomElement write(QDomDocument *doc, dtkAbstractData *data)
dtkAbstractDataWriter * createaxlCompositeCurveWriter(void)
virtual QDomElement write(QDomDocument *doc, dtkAbstractData *data)=0