Developer documentation | Axl-2.5.1

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