Developer documentation | Axl-2.5.1

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