Developer documentation | Axl-2.5.1

axlEllipsoidWriter.cpp
Go to the documentation of this file.
1 /* axlEllipsoidWriter.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008-2011 - Meriadeg Perrinel, Inria.
5  * Created: Wed Sep 21 11:36:52 2011 (+0200)
6  * Version: $Id$
7  * Last-Updated: Wed Sep 21 12:11:29 2011 (+0200)
8  * By: Meriadeg Perrinel
9  * Update #: 88
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlEllipsoidWriter.h"
21 
22 #include <axlCore/axlEllipsoid.h>
23 #include <axlCore/axlPoint.h>
25 
26 #include <dtkCoreSupport/dtkAbstractData.h>
27 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
29 
30 // /////////////////////////////////////////////////////////////////
31 // axlEllipsoidWriter
32 // /////////////////////////////////////////////////////////////////
33 
35 {
36  this->setObjectName(this->description());
37 }
38 
40 {
41 
42 }
43 
44 QString axlEllipsoidWriter::identifier(void) const
45 {
46  return "axlEllipsoidWriter";
47 }
48 
50 {
51  return "axlEllipsoidWriter";
52 }
53 
54 QStringList axlEllipsoidWriter::handled(void) const
55 {
56  return QStringList() << "axlEllipsoid";
57 }
58 
60 {
61  return dtkAbstractDataFactory::instance()->registerDataWriterType("axlEllipsoidWriter", QStringList(), createaxlEllipsoidWriter);
62 }
63 
64 bool axlEllipsoidWriter::accept(dtkAbstractData *data)
65 {
66  axlEllipsoid *ellipsoid = dynamic_cast<axlEllipsoid *>(data);
67  if(ellipsoid)
68  return true;
69 
70  return false;
71 }
72 
73 bool axlEllipsoidWriter::reject(dtkAbstractData *data)
74 {
75  return !this->accept(data);
76 }
77 
78 QDomElement axlEllipsoidWriter::write(QDomDocument *doc, dtkAbstractData *data) {
79  axlEllipsoid *ellipsoid = dynamic_cast<axlEllipsoid *>(data);
80 
82  QDomElement ellipsoidElement = doc->createElement("ellipsoid");
83  ellipsoidElement.setAttribute("name",ellipsoid->name());
84 
85 
87  ellipsoidElement.setAttribute("size", QString::number(ellipsoid->size()));
88 
89 
90 
92  QColor qcolor = ellipsoid->color();
93  QString color ;
94  QTextStream(&color) << QString::number(qcolor.red()) << " "
95  << QString::number(qcolor.green()) << " "
96  << QString::number(qcolor.blue()) << " "
97  << QString::number(ellipsoid->opacity());
98  ellipsoidElement.setAttribute("color", color);
99 
101  QString shader = ellipsoid->shader();
102  QFileInfo shaderFileInfo(shader);
103  ellipsoidElement.setAttribute("shader", shaderFileInfo.fileName());
104 
105  //Write ellipsoid
106  //center
107  QDomElement center = doc->createElement("center");
108  QString centerStr;
109  QTextStream(&centerStr) << QString::number(ellipsoid->center()->x()) << " "<< QString::number(ellipsoid->center()->y()) << " "<< QString::number(ellipsoid->center()->z());
110  QDomText centerDomText = doc->createTextNode(centerStr);
111  center.appendChild(centerDomText);
112 
113  ellipsoidElement.appendChild(center);
114 
115  //semiX
116  QDomElement semix = doc->createElement("semix");
117  QString semixStr;
118  QTextStream(&semixStr) << QString::number(ellipsoid->semiX()->x()) << " "<< QString::number(ellipsoid->semiX()->y()) << " "<< QString::number(ellipsoid->semiX()->z());
119  QDomText semixDomText = doc->createTextNode(semixStr);
120  semix.appendChild(semixDomText);
121 
122  ellipsoidElement.appendChild(semix);
123 
124  //semiY
125  QDomElement semiy = doc->createElement("semiy");
126  QString semiyStr;
127  QTextStream(&semiyStr) << QString::number(ellipsoid->semiY()->x()) << " "<< QString::number(ellipsoid->semiY()->y()) << " "<< QString::number(ellipsoid->semiY()->z());
128  QDomText semiyDomText = doc->createTextNode(semiyStr);
129  semiy.appendChild(semiyDomText);
130 
131  ellipsoidElement.appendChild(semiy);
132 
133  //semiZ
134  QDomElement semiz = doc->createElement("semiz");
135  QString semizStr;
136  QTextStream(&semizStr) << QString::number(ellipsoid->semiZ()->x()) << " "<< QString::number(ellipsoid->semiZ()->y()) << " "<< QString::number(ellipsoid->semiZ()->z());
137  QDomText semizDomText = doc->createTextNode(semizStr);
138  semiz.appendChild(semizDomText);
139 
140  ellipsoidElement.appendChild(semiz);
141 
142 
143  //Write fields if exist.
144  if(!ellipsoid->fields().isEmpty()){
145  foreach(axlAbstractField *field, ellipsoid->fields()){
147  QDomElement fieldElement = field_writer->write(doc, field);
148  ellipsoidElement.appendChild(fieldElement);
149  }
150  }
151 
152 
153  return ellipsoidElement;
154 }
155 
156 
157 QDomElement axlEllipsoidWriter::elementByWriter(axlAbstractDataWriter *axl_writer, QDomDocument *doc, dtkAbstractData *data)
158 {
159  QDomElement element;
160 
161  if(!axl_writer)
162  return element;
163 
164  if(!axl_writer->accept(data))
165  return element;
166 
167  element = axl_writer->write(doc, data);
168 
169  return element;
170 }
171 
172 dtkAbstractDataWriter *createaxlEllipsoidWriter(void)
173 {
174  return new axlEllipsoidWriter;
175 }
QString description(void) const
static bool registered(void)
virtual bool accept(dtkAbstractData *data)=0
axlPoint semiZ
Definition: axlEllipsoid.h:40
static axlFieldWritersFactory * instance(void)
virtual QString identifier(void) const
QString identifier(void) const
dtkAbstractDataWriter * createaxlEllipsoidWriter(void)
axlPoint center
Definition: axlEllipsoid.h:38
dtkAbstractDataWriter * create(const QString &interface_name)
QDomElement write(QDomDocument *doc, dtkAbstractData *data)
Class axlAbstractField defines an API for arrays of numeric data.
bool accept(dtkAbstractData *data)
double y
Definition: axlPoint.h:37
axlPoint semiX
Definition: axlEllipsoid.h:38
double z
Definition: axlPoint.h:38
QStringList handled(void) const
axlPoint semiY
Definition: axlEllipsoid.h:39
QList< axlAbstractField * > fields(void)
bool reject(dtkAbstractData *data)
virtual QDomElement write(QDomDocument *doc, dtkAbstractData *data)=0
double x
Definition: axlPoint.h:37
Class axlEllipsoid defines 3D ellipsoids.
Definition: axlEllipsoid.h:35