Developer documentation | Axl-2.5.1

axlTabulatedCylinderWriter.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 "axlTabulatedCylinderWriter";
21 }
22 
24  return "axlTabulatedCylinderWriter";
25 }
26 
27 QStringList axlTabulatedCylinderWriter::handled(void) const {
28  return QStringList() << "axlTabulatedCylinder";
29 }
30 
32  return dtkAbstractDataFactory::instance()->registerDataWriterType("axlTabulatedCylinderWriter", QStringList(), createaxlTabulatedCylinderWriter);
33 }
34 
35 bool axlTabulatedCylinderWriter::accept(dtkAbstractData *data) {
36  axlTabulatedCylinder *TabulatedCylinder = dynamic_cast<axlTabulatedCylinder*>(data);
37  if(TabulatedCylinder)
38  return true;
39 
40  return false;
41 }
42 
43 bool axlTabulatedCylinderWriter::reject(dtkAbstractData *data) {
44  return !this->accept(data);
45 }
46 
47 QDomElement axlTabulatedCylinderWriter::write(QDomDocument *doc, dtkAbstractData *data) {
48  axlTabulatedCylinder* tabCyl = dynamic_cast<axlTabulatedCylinder*>(data);
49 
51  QDomElement surElement = doc->createElement("tabulated_cylinder");
52  surElement.setAttribute("name", tabCyl->name());
53 
55  surElement.setAttribute("size", QString::number(tabCyl->size()));
56 
58  QColor qcolor = tabCyl->color();
59  QString color ;
60  QTextStream(&color) << QString::number(qcolor.red()) << " "
61  << QString::number(qcolor.green()) << " "
62  << QString::number(qcolor.blue()) << " "
63  << QString::number(tabCyl->opacity());
64  surElement.setAttribute("color", color);
65 
67  QString shader = tabCyl->shader();
68  QFileInfo shaderFileInfo(shader);
69  surElement.setAttribute("shader", shaderFileInfo.fileName());
70 
71  //Write generatrix
72  QDomElement generatrixElement = doc->createElement("generatrix");
73  QString genWriterTag = tabCyl->get_pt_generatrix()->identifier()+"Writer";
74  axlAbstractDataWriter* genWriter = dynamic_cast<axlAbstractDataWriter*>(dtkAbstractDataFactory::instance()->writer(genWriterTag));
75  QDomElement subGenElement = genWriter->write(doc, tabCyl->get_pt_generatrix());
76  generatrixElement.appendChild(subGenElement);
77  surElement.appendChild(generatrixElement);
78  //Write
79  QDomElement directrixElement = doc->createElement("directrix");
80  QString dirWriterTag = tabCyl->get_pt_directrix()->identifier()+"Writer";
81  axlAbstractDataWriter* dirWriter = dynamic_cast<axlAbstractDataWriter*>(dtkAbstractDataFactory::instance()->writer(dirWriterTag));
82  QDomElement subDirElement = dirWriter->write(doc, tabCyl->get_pt_directrix());
83  directrixElement.appendChild(subDirElement);
84  directrixElement.setAttribute("type",tabCyl->get_pt_directrix()->identifier());
85  surElement.appendChild(directrixElement);
86  //return
87  return surElement;
88 
89 }
90 
91 QDomElement axlTabulatedCylinderWriter::elementByWriter(axlAbstractDataWriter *axl_writer, QDomDocument *doc, dtkAbstractData *data) {
92  QDomElement element;
93 
94  if(!axl_writer)
95  return element;
96 
97  if(!axl_writer->accept(data))
98  return element;
99 
100  element = axl_writer->write(doc, data);
101 
102  return element;
103 }
104 
105 dtkAbstractDataWriter *createaxlTabulatedCylinderWriter(void) {
106  return new axlTabulatedCylinderWriter;
107 }
virtual bool accept(dtkAbstractData *data)=0
bool accept(dtkAbstractData *data)
bool reject(dtkAbstractData *data)
virtual QString identifier(void) const
Definition: axlPoint.cpp:549
axlAbstractCurve * get_pt_directrix() const
dtkAbstractDataWriter * createaxlTabulatedCylinderWriter(void)
QDomElement write(QDomDocument *doc, dtkAbstractData *data)
virtual QDomElement write(QDomDocument *doc, dtkAbstractData *data)=0