Developer documentation | Axl-2.5.1

axlPointWriter.cpp
Go to the documentation of this file.
1 /* axlPointWriter.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 "axlPointWriter.h"
21 
22 #include <axlCore/axlPoint.h>
24 
25 #include <dtkCoreSupport/dtkAbstractData.h>
26 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
28 
29 // /////////////////////////////////////////////////////////////////
30 // axlPointWriter
31 // /////////////////////////////////////////////////////////////////
32 
34 {
35  this->setObjectName(this->description());
36 }
37 
39 {
40 
41 }
42 
43 QString axlPointWriter::identifier(void) const
44 {
45  return "axlPointWriter";
46 }
47 
48 QString axlPointWriter::description(void) const
49 {
50  return "axlPointWriter";
51 }
52 
53 QStringList axlPointWriter::handled(void) const
54 {
55  return QStringList() << "axlPoint";
56 }
57 
59 {
60  return dtkAbstractDataFactory::instance()->registerDataWriterType("axlPointWriter", QStringList(), createaxlPointWriter);
61 }
62 
63 bool axlPointWriter::accept(dtkAbstractData *data)
64 {
65  axlPoint *point = dynamic_cast<axlPoint *>(data);
66  if(point)
67  return true;
68 
69  return false;
70 }
71 
72 bool axlPointWriter::reject(dtkAbstractData *data)
73 {
74  return !this->accept(data);
75 }
76 
77 QDomElement axlPointWriter::write(QDomDocument *doc, dtkAbstractData *data)
78 {
79  axlPoint *point = dynamic_cast<axlPoint *>(data);
80 
82  QDomElement pointElement = doc->createElement("point");
83  pointElement.setAttribute("name",point->name());
84 
85 
87  pointElement.setAttribute("size", QString::number(point->size()));
88 
89 
90 
92  QColor qcolor = point->color();
93  QString color ;
94  QTextStream(&color) << QString::number(qcolor.red()) << " "
95  << QString::number(qcolor.green()) << " "
96  << QString::number(qcolor.blue());
97  if(point->opacity()!=1.)
98  QTextStream(&color) << " " << QString::number(point->opacity());
99  pointElement.setAttribute("color", color);
100 
102  QString shader = point->shader();
103  QFileInfo shaderFileInfo(shader);
104  pointElement.setAttribute("shader", shaderFileInfo.fileName());
105 
106  //Write point
107  QString pointValue;
108  QTextStream(&pointValue) << QString::number(point->x()) << " "<< QString::number(point->y()) << " "<< QString::number(point->z());
109 
110  QDomText pointDomText = doc->createTextNode(pointValue);
111 
112  pointElement.appendChild(pointDomText);
113 
114  //Write fields if exist.
115  if(!point->fields().isEmpty()){
116  foreach(axlAbstractField *field, point->fields()){
118  QDomElement fieldElement = field_writer->write(doc, field);
119  pointElement.appendChild(fieldElement);
120  }
121  }
122 
123  return pointElement;
124 }
125 
126 
127 QDomElement axlPointWriter::elementByWriter(axlAbstractDataWriter *axl_writer, QDomDocument *doc, dtkAbstractData *data)
128 {
129  QDomElement element;
130 
131  if(!axl_writer)
132  return element;
133 
134  if(!axl_writer->accept(data))
135  return element;
136 
137  element = axl_writer->write(doc, data);
138 
139  return element;
140 }
141 
142 dtkAbstractDataWriter *createaxlPointWriter(void)
143 {
144  return new axlPointWriter;
145 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
virtual bool accept(dtkAbstractData *data)=0
static axlFieldWritersFactory * instance(void)
dtkAbstractDataWriter * createaxlPointWriter(void)
virtual QString identifier(void) const
QString description(void) const
QStringList handled(void) const
static bool registered(void)
dtkAbstractDataWriter * create(const QString &interface_name)
QString identifier(void) const
Class axlAbstractField defines an API for arrays of numeric data.
double y
Definition: axlPoint.h:37
bool accept(dtkAbstractData *data)
bool reject(dtkAbstractData *data)
double z
Definition: axlPoint.h:38
QList< axlAbstractField * > fields(void)
virtual QDomElement write(QDomDocument *doc, dtkAbstractData *data)=0
double x
Definition: axlPoint.h:37
QDomElement write(QDomDocument *doc, dtkAbstractData *data)