Developer documentation | Axl-2.5.1

axlTorusWriter.cpp
Go to the documentation of this file.
1 /* axlTorusWriter.cpp ---
2  *
3  * Author: Valentin Michelet
4  * Copyright (C) 2008 - Valentin Michelet, Inria.
5  * Created: Tue Nov 9 16:58:59 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Nov 9 17:09:38 2010 (+0100)
8  * By: Valentin Michelet
9  * Update #: 19
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlTorusWriter.h"
21 
22 #include <axlCore/axlTorus.h>
23 #include <axlCore/axlPoint.h>
25 
26 #include <dtkCoreSupport/dtkAbstractData.h>
27 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
29 
30 // /////////////////////////////////////////////////////////////////
31 // axlTorusWriter
32 // /////////////////////////////////////////////////////////////////
33 
35  this->setObjectName(this->description());
36 }
37 
39 }
40 
41 QString axlTorusWriter::identifier(void) const {
42  return "axlTorusWriter";
43 }
44 
45 QString axlTorusWriter::description(void) const {
46  return "axlTorusWriter";
47 }
48 
49 QStringList axlTorusWriter::handled(void) const {
50  return QStringList() << "axlTorus";
51 }
52 
54  return dtkAbstractDataFactory::instance()->registerDataWriterType("axlTorusWriter", QStringList(), createaxlTorusWriter);
55 }
56 
57 bool axlTorusWriter::accept(dtkAbstractData *data) {
58  axlTorus* torus = dynamic_cast<axlTorus*>(data);
59  if (torus)
60  return true;
61  return false;
62 }
63 
64 bool axlTorusWriter::reject(dtkAbstractData *data) {
65  return !this->accept(data);
66 }
67 
68 QDomElement axlTorusWriter::write(QDomDocument *doc, dtkAbstractData *data) {
69 
70  axlTorus* torus = dynamic_cast<axlTorus*>(data);
71 
73  QDomElement torusElement = doc->createElement("torus");
74  torusElement.setAttribute("name", torus->name());
75 
77  torusElement.setAttribute("size", QString::number(torus->size()));
78 
80  QColor qcolor = torus->color();
81  QString color;
82  QTextStream(&color) << QString::number(qcolor.red()) << " "
83  << QString::number(qcolor.green()) << " "
84  << QString::number(qcolor.blue()) << " "
85  << QString::number(torus->opacity());
86  torusElement.setAttribute("color", color);
87 
89  QString shader = torus->shader();
90  QFileInfo shaderFileInfo(shader);
91  torusElement.setAttribute("shader", shaderFileInfo.fileName());
92 
93  //Write torus
94  //Center
95  QDomElement centerElement = doc->createElement("center");
96  QString centerStr;
97  QTextStream(&centerStr) << QString::number(torus->centerPoint()->x()) << " "
98  << QString::number(torus->centerPoint()->y()) << " "
99  << QString::number(torus->centerPoint()->z());
100  QDomText centerDomText = doc->createTextNode(centerStr);
101  centerElement.appendChild(centerDomText);
102 
103  torusElement.appendChild(centerElement);
104 
105  //Direction
106  QDomElement directionElement = doc->createElement("direction");
107  QString directionStr;
108  QTextStream(&directionStr) << QString::number(torus->direction()->x()) << " "
109  << QString::number(torus->direction()->y()) << " "
110  << QString::number(torus->direction()->z());
111  QDomText directionDomText = doc->createTextNode(directionStr);
112  directionElement.appendChild(directionDomText);
113 
114  torusElement.appendChild(directionElement);
115 
116  //Ring Radius
117  QDomElement ringRadiusElement = doc->createElement("ringRadius");
118  QString ringRadiusStr;
119  QTextStream(&ringRadiusStr) << QString::number(torus->ringRadius());
120  QDomText ringRadiusDomText = doc->createTextNode(ringRadiusStr);
121  ringRadiusElement.appendChild(ringRadiusDomText);
122 
123  torusElement.appendChild(ringRadiusElement);
124 
125  //Cross Section Radius
126  QDomElement crossSectionRadiusElement = doc->createElement("crossSectionRadius");
127  QString crossSectionRadiusStr;
128  QTextStream(&crossSectionRadiusStr) << QString::number(torus->crossSectionRadius());
129  QDomText crossSectionRadiusDomText = doc->createTextNode(crossSectionRadiusStr);
130  crossSectionRadiusElement.appendChild(crossSectionRadiusDomText);
131 
132  torusElement.appendChild(crossSectionRadiusElement);
133 
134  //Write fields if exist.
135  if(!torus->fields().isEmpty()){
136  foreach(axlAbstractField *field, torus->fields()){
138  QDomElement fieldElement = field_writer->write(doc, field);
139  torusElement.appendChild(fieldElement);
140  }
141  }
142 
143  return torusElement;
144 }
145 
146 QDomElement axlTorusWriter::elementByWriter(axlAbstractDataWriter *axl_writer, QDomDocument *doc, dtkAbstractData *data) {
147  QDomElement element;
148 
149  if (!axl_writer)
150  return element;
151  if(!axl_writer->accept(data))
152  return element;
153 
154  element = axl_writer->write(doc, data);
155 
156  return element;
157 }
158 
159 dtkAbstractDataWriter *createaxlTorusWriter(void) {
160  return new axlTorusWriter;
161 }
double crossSectionRadius
Definition: axlTorus.h:32
virtual ~axlTorusWriter(void)
bool reject(dtkAbstractData *data)
axlPoint centerPoint
Definition: axlTorus.h:30
virtual bool accept(dtkAbstractData *data)=0
static axlFieldWritersFactory * instance(void)
QString description(void) const
QStringList handled(void) const
virtual QString identifier(void) const
dtkAbstractDataWriter * createaxlTorusWriter(void)
QDomElement write(QDomDocument *doc, dtkAbstractData *data)
dtkAbstractDataWriter * create(const QString &interface_name)
Class axlAbstractField defines an API for arrays of numeric data.
static bool registered(void)
double ringRadius
Definition: axlTorus.h:31
double y
Definition: axlPoint.h:37
double z
Definition: axlPoint.h:38
axlPoint direction
Definition: axlTorus.h:30
QList< axlAbstractField * > fields(void)
virtual QDomElement write(QDomDocument *doc, dtkAbstractData *data)=0
QString identifier(void) const
double x
Definition: axlPoint.h:37
bool accept(dtkAbstractData *data)