Developer documentation | Axl-2.5.1

axlPointReader.cpp
Go to the documentation of this file.
1 /* axlPointReader.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 "axlPointReader.h"
22 
23 #include <axlCore/axlPoint.h>
24 
25 #include <dtkCoreSupport/dtkAbstractData.h>
26 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
29 
30 // /////////////////////////////////////////////////////////////////
31 // axlPointReader
32 // /////////////////////////////////////////////////////////////////
33 
35 {
36  this->setObjectName(this->description());
37 }
38 
40 {
41 
42 }
43 
44 QString axlPointReader::identifier(void) const
45 {
46  return "axlPointReader";
47 }
48 
49 QString axlPointReader::description(void) const
50 {
51  return "axlPointReader";
52 }
53 
54 QStringList axlPointReader::handled(void) const
55 {
56  return QStringList() << "axlPoint";
57 }
58 
60 {
61  return dtkAbstractDataFactory::instance()->registerDataReaderType("axlPointReader", QStringList(), createaxlPointReader);
62 }
63 
64 bool axlPointReader::accept(const QDomNode& node)
65 {
66  QDomElement element = node.toElement();
67 
68  if(element.tagName() != "point")
69  return false;
70 
71 
72  return true;
73 }
74 
75 bool axlPointReader::reject(const QDomNode& node)
76 {
77  return !this->accept(node);
78 }
79 
80 axlAbstractData *axlPointReader::read(const QDomNode& node)
81 {
82  QDomElement element = node.toElement();
83 
84  axlPoint *currentPoint = new axlPoint();
85 
86  QString name = element.attribute("name");
87  if(!name.isEmpty())
88  {
89  currentPoint->setObjectName(name);
90  }
91 
92  QString color = element.attribute("color");
93  if(!color.isEmpty())
94  {
95  QStringList colorList = color.split(" ");
96  if(colorList.size() > 2) // rgb components
97  currentPoint->setColor(QColor(colorList.at(0).toInt(), colorList.at(1).toInt(), colorList.at(2).toInt()));
98  if(colorList.size() == 4)
99  currentPoint->setOpacity(colorList.at(3).toFloat());
100  }
101 
102  QString shader = element.attribute("shader");
103  QString dirShader;
104  if(!shader.isEmpty())
105  {
106  // try to read from axelShader.qrc
107  dirShader = ":axlShader/shader/"+shader;
108  if(!QFile::exists(dirShader))
109  {
110  QSettings settings("inria", "dtk");
111  QString defaultPath;
112  settings.beginGroup("shader");
113  dirShader = settings.value("path", defaultPath).toString();
114 // dirShader = this->file().left(this->file().lastIndexOf("axel-data") + 9); // to Remove later
115  dirShader.append("/"+shader);
116  }
117  currentPoint->setShader(dirShader);
118  }
119 
120  QString size = element.attribute("size");
121  if(!size.isEmpty())
122  currentPoint->setSize(size.toFloat());
123 
124  QStringList coordinates = element.text().simplified().split(QRegExp("\\s+"));
125 
126  if(coordinates.size() == 3)
127  {
128  currentPoint->coordinates()[0] = coordinates[0].toFloat();
129  currentPoint->coordinates()[1] = coordinates[1].toFloat();
130  currentPoint->coordinates()[2] = coordinates[2].toFloat();
131  }
132  else
133  qDebug()<<"Point data cannot be read correctly";
134 
135 
136  //if there are some field, read them thanks to the factory.
137  QDomNodeList nodeListField = element.elementsByTagName("field");
138  if(!nodeListField.isEmpty()){
139  for(int i =0; i < nodeListField.size(); i++){
140  QDomElement fieldElement = nodeListField.at(i).toElement();
141  QString fieldType = fieldElement.attribute("type");
142  if(!fieldType.isEmpty()){
143  axlAbstractDataReader *field_reader = dynamic_cast<axlAbstractDataReader *>(axlFieldReadersFactory::instance()->create(fieldType));
144  axlAbstractField * fieldToAdd = dynamic_cast<axlAbstractField *>(field_reader->read(fieldElement));
145  if(fieldToAdd){
146  QString newName = currentPoint->changeFieldName(fieldToAdd->name());
147  fieldToAdd->setObjectName(newName);
148  currentPoint->addField(fieldToAdd);
149  }
150  }
151  }
152  }
153 
154 
155  return currentPoint;
156 
157 }
158 
159 dtkAbstractDataReader *createaxlPointReader(void)
160 {
161  return new axlPointReader;
162 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
QStringList handled(void) const
double * coordinates(void) const
Returns coordinates of this point.
Definition: axlPoint.cpp:445
bool accept(const QDomNode &node)
void setShader(const QString &shader)
QString changeFieldName(QString fieldName)
dtkAbstractDataReader * create(const QString &interface_name)
QString description(void) const
static bool registered(void)
virtual axlAbstractData * read(const QDomNode &node)=0
axlAbstractData * read(const QDomNode &node)
Class axlAbstractField defines an API for arrays of numeric data.
void setOpacity(const double &opacity)
bool reject(const QDomNode &node)
static axlFieldReadersFactory * instance(void)
void addField(axlAbstractField *field)
Add a field to the field list of the object.
void setSize(const double &size)
void setColor(double r, double g, double b)
Class axlAbstractData defines an API for all type of axel data.
QString identifier(void) const
dtkAbstractDataReader * createaxlPointReader(void)