Developer documentation | Axl-2.5.1

axlCompositeCurveReader.cpp
Go to the documentation of this file.
1 //Author: Hung NGUYEN - 9:17 AM 20/05/2014.
2 
3 
4 
6 
8 
9 #include <dtkCoreSupport/dtkAbstractData.h>
10 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
12 
13 #include <axlCore/axlLine.h>
14 #include <axlCore/axlLineReader.h>
15 
16 #include <QColor>
17 
18 
21 
22  this->setObjectName(this->description());
23 }
24 
26 }
27 
29  return "axlCompositeCurveReader";
30 }
31 
33  return "axlCompositeCurveReader";
34 }
35 
36 QStringList axlCompositeCurveReader::handled(void) const {
37  return QStringList() << "axlCompositeCurve";
38 }
39 
41  return dtkAbstractDataFactory::instance()->registerDataReaderType("axlCompositeCurveReader", QStringList(), createaxlCompositeCurveReader);
42 }
43 
44 bool axlCompositeCurveReader::accept(const QDomNode& node) {
45  QDomElement element = node.toElement();
46 
47  if (element.tagName() != "composite_curve")
48  return false;
49 
50  return true;
51 }
52 
53 bool axlCompositeCurveReader::reject(const QDomNode& node) {
54  return !this->accept(node);
55 }
56 
58  // Create element from given node
59  QDomElement element = node.toElement();
60 
62 
63  // Handle name
64  QString name = element.attribute("name");
65  if (!name.isEmpty()) {
66  comCur->setObjectName(name);
67  }
68 
69  // Handle color
70  QString color = element.attribute("color");
71  if (!color.isEmpty()) {
72  QStringList colorList = color.split(" ");
73  if (colorList.size() > 2) // rgb components
74  comCur->setColor(QColor(colorList.at(0).toInt(), colorList.at(1).toInt(), colorList.at(2).toInt()));
75  if (colorList.size() == 4)
76  comCur->setOpacity(colorList.at(3).toFloat());
77  }
78 
79  // Handle shader
80  QString shader = element.attribute("shader");
81  QString dirShader;
82  if (!shader.isEmpty()) {
83  // Try to read from axelShader.qrc
84  dirShader = ":axlShader/shader/" + shader;
85  if (!QFile::exists(dirShader)) {
86  QSettings settings("inria", "dtk");
87  QString defaultPath;
88  settings.beginGroup("shader");
89  dirShader = settings.value("path", defaultPath).toString();
90  dirShader.append("/" + shader);
91  }
92  comCur->setShader(dirShader);
93  }
94 
95  // Handle size
96  QString size = element.attribute("size");
97  if (!size.isEmpty())
98  comCur->setSize(size.toFloat());
99 
100  // Handle curves
101  QList<axlAbstractCurve *> curveList;
102  QDomNodeList curvelistElement = element.elementsByTagName("curve");
103  for(int i = 0; i<curvelistElement.size(); i++)
104  {
105  QDomElement curveElement = curvelistElement.at(i).toElement();
106  QString curveReaderTag = curveElement.attribute("type")+ "Reader";
107  axlAbstractDataReader* curveReader = dynamic_cast<axlAbstractDataReader*>(dtkAbstractDataFactory::instance()->reader(curveReaderTag));
108  axlAbstractCurve *curve = dynamic_cast<axlAbstractCurve *>(curveReader->read(curveElement.firstChild()));
109  curveList.append(curve);
110  }
111 
112  comCur->insert_list_curves(curveList);
113 
114  return comCur;
115 }
116 
117 
118 
119 dtkAbstractDataReader *createaxlCompositeCurveReader(void) {
120  return new axlCompositeCurveReader;
121 }
void setShader(const QString &shader)
dtkAbstractDataReader * createaxlCompositeCurveReader(void)
void insert_list_curves(const QList< axlAbstractCurve > &data_curves)
axlAbstractData * read(const QDomNode &node)
virtual axlAbstractData * read(const QDomNode &node)=0
bool reject(const QDomNode &node)
void setOpacity(const double &opacity)
QString description(void) const
void setSize(const double &size)
void setColor(double r, double g, double b)
QStringList handled(void) const
bool accept(const QDomNode &node)
Class axlAbstractData defines an API for all type of axel data.