Developer documentation | Axl-2.5.1

axlSurfaceRevolutionWriter.cpp
Go to the documentation of this file.
1 //Author: Hung NGUYEN 9:17 AM 20/05/2014
2 
4 
6 
7 #include <dtkCoreSupport/dtkAbstractData.h>
8 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
9 
10 #include <QtGui>
11 
14 
15  this->setObjectName(this->description());
16 }
17 
19 }
20 
22  return "axlSurfaceRevolutionWriter";
23 }
24 
26  return "axlSurfaceRevolutionWriter";
27 }
28 
29 QStringList axlSurfaceRevolutionWriter::handled(void) const {
30  return QStringList() << "axlSurfaceRevolution";
31 }
32 
34  return dtkAbstractDataFactory::instance()->registerDataWriterType("axlSurfaceRevolutionWriter", QStringList(), createaxlSurfaceRevolutionWriter);
35 }
36 
37 bool axlSurfaceRevolutionWriter::accept(dtkAbstractData *data) {
38  axlSurfaceRevolution *surfaceRevolution = dynamic_cast<axlSurfaceRevolution*>(data);
39  if(surfaceRevolution)
40  return true;
41 
42  return false;
43 }
44 
45 bool axlSurfaceRevolutionWriter::reject(dtkAbstractData *data) {
46  return !this->accept(data);
47 }
48 
49 QDomElement axlSurfaceRevolutionWriter::write(QDomDocument *doc, dtkAbstractData *data) {
50  axlSurfaceRevolution* surRev = dynamic_cast<axlSurfaceRevolution*>(data);
51 
53  QDomElement surElement = doc->createElement("surface_revolution");
54  surElement.setAttribute("name", surRev->name());
55 
57  surElement.setAttribute("size", QString::number(surRev->size()));
58 
60  QColor qcolor = surRev->color();
61  QString color ;
62  QTextStream(&color) << QString::number(qcolor.red()) << " "
63  << QString::number(qcolor.green()) << " "
64  << QString::number(qcolor.blue()) << " "
65  << QString::number(surRev->opacity());
66  surElement.setAttribute("color", color);
67 
69  QString shader = surRev->shader();
70  QFileInfo shaderFileInfo(shader);
71  surElement.setAttribute("shader", shaderFileInfo.fileName());
72 
73  // Write axe
74  QDomElement axeElement = doc->createElement("axe");
75  axlLine* axe = surRev->getAxe();
76  axlAbstractDataWriter* axeWriter = dynamic_cast<axlAbstractDataWriter*>(dtkAbstractDataFactory::instance()->writer("axlLineWriter"));
77  QDomElement lineElement = axeWriter->write(doc, axe);
78  axeElement.appendChild(lineElement);
79  surElement.appendChild(axeElement);
80 
81  //Write curve
82  QDomElement curvesElement = doc->createElement("curves");
83 
84  QList<axlAbstractCurve*> curves = surRev->getCurves();
85 
86  for(int i = 0; i<curves.size(); i++)
87  {
88  QDomElement curveElement = doc->createElement("curve");
89  QString curveWriterTag = curves.at(i)->identifier()+"Writer";
90  axlAbstractDataWriter* curveWriter = dynamic_cast<axlAbstractDataWriter*>(dtkAbstractDataFactory::instance()->writer(curveWriterTag));
91  QDomElement subCurveElement = curveWriter->write(doc, curves.at(i));
92  curveElement.appendChild(subCurveElement);
93  curveElement.setAttribute("type",curves.at(i)->identifier());
94  curvesElement.appendChild(curveElement);
95  }
96  surElement.appendChild(curvesElement);
97 
98  //Write Angle
99  QDomElement angleElement = doc->createElement("angle");
100  double startAngle = surRev->getStartAngle();
101  double endAngle = surRev->getEndAngle();
102  angleElement.setAttribute("start_angle",startAngle);
103  angleElement.setAttribute("end_angle",endAngle);
104  surElement.appendChild(angleElement);
105 
106  //return
107 
108  return surElement;
109 
110 }
111 
112 QDomElement axlSurfaceRevolutionWriter::elementByWriter(axlAbstractDataWriter *axl_writer, QDomDocument *doc, dtkAbstractData *data) {
113  QDomElement element;
114 
115  if(!axl_writer)
116  return element;
117 
118  if(!axl_writer->accept(data))
119  return element;
120 
121  element = axl_writer->write(doc, data);
122 
123  return element;
124 }
125 
126 dtkAbstractDataWriter *createaxlSurfaceRevolutionWriter(void) {
127  return new axlSurfaceRevolutionWriter;
128 }
Class axlLine defines 3D lines.
Definition: axlLine.h:35
virtual bool accept(dtkAbstractData *data)=0
QList< axlAbstractCurve * > getCurves()
bool reject(dtkAbstractData *data)
bool accept(dtkAbstractData *data)
QDomElement write(QDomDocument *doc, dtkAbstractData *data)
dtkAbstractDataWriter * createaxlSurfaceRevolutionWriter(void)
virtual QDomElement write(QDomDocument *doc, dtkAbstractData *data)=0