23 #include <dtkCoreSupport/dtkAbstractData.h>
24 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
41 return "axlCylinderParametricReader";
45 return "axlCylinderParametricReader";
49 return QStringList() <<
"axlCylinderParametric";
58 QDomElement element = node.toElement();
60 if(element.tagName() !=
"cylinderParam")
72 qDebug() <<
"cylinderParam read.";
78 return !this->
accept(node);
82 QDomElement element = node.toElement();
88 QString name = element.attribute(
"name");
90 currentCylinderParametric->setObjectName(name);
94 QString color = element.attribute(
"color");
95 if(!color.isEmpty()) {
96 QStringList colorList = color.split(
" ");
97 if(colorList.size() > 2)
98 currentCylinderParametric->
setColor(QColor(colorList.at(0).toInt(), colorList.at(1).toInt(), colorList.at(2).toInt()));
99 if(colorList.size() == 4)
100 currentCylinderParametric->
setOpacity(colorList.at(3).toFloat());
104 QString shader = element.attribute(
"shader");
106 if(!shader.isEmpty()) {
108 dirShader =
":axlShader/shader/"+shader;
109 if(!QFile::exists(dirShader)) {
110 QSettings settings(
"inria",
"dtk");
112 settings.beginGroup(
"shader");
113 dirShader = settings.value(
"path", defaultPath).toString();
115 dirShader.append(
"/"+shader);
117 currentCylinderParametric->
setShader(dirShader);
121 QString size = element.attribute(
"size");
123 currentCylinderParametric->
setSize(size.toFloat());
125 QDomNodeList pointNodeList = element.elementsByTagName(
"point") ;
129 QDomElement point1Element = pointNodeList.item(0).toElement() ;
131 QStringList point1Coords = point1Element.text().simplified().split(QRegExp(
"\\s+"));
132 if(point1Coords.size() == 3)
133 cylinder.
setFirstPoint(
new axlPoint(point1Coords[0].toDouble(), point1Coords[1].toDouble(), point1Coords[2].toDouble()));
135 dtkWarn() <<
"CylinderParametric data cannot be read correctly : point 1 coordinates";
138 QDomElement point2Element = pointNodeList.item(1).toElement() ;
140 QStringList point2Coords = point2Element.text().simplified().split(QRegExp(
"\\s+"));
141 if(point2Coords.size() == 3)
142 cylinder.
setSecondPoint(
new axlPoint(point2Coords[0].toDouble(), point2Coords[1].toDouble(), point2Coords[2].toDouble()));
144 dtkWarn() <<
"CylinderParametric data cannot be read correctly : point 2 coordinates";
147 QDomNodeList radiusNodeList = element.elementsByTagName(
"radius") ;
149 QDomElement radiusElement = radiusNodeList.item(0).toElement() ;
151 QStringList radiusCoords = radiusElement.text().simplified().split(QRegExp(
"\\s+"));
152 if(radiusCoords.size() == 1)
153 cylinder.
setRadius(radiusCoords[0].toDouble());
155 dtkWarn() <<
"CylinderParametric data cannot be read correctly : radius";
160 QDomNodeList refdirNodeList = element.elementsByTagName(
"refdir") ;
162 QDomElement refdirElement = refdirNodeList.item(0).toElement() ;
164 QStringList refdirCoords = refdirElement.text().simplified().split(QRegExp(
"\\s+"));
165 if(refdirCoords.size() == 3)
166 currentCylinderParametric->
setR(
new axlPoint(refdirCoords[0].toDouble(), refdirCoords[1].toDouble(), refdirCoords[2].toDouble()));
168 dtkWarn() <<
"CylinderParametric data cannot be read correctly : refdir coordinates";
172 QDomNodeList nodeListField = element.elementsByTagName(
"field");
173 if(!nodeListField.isEmpty()){
174 for(
int i =0; i < nodeListField.size(); i++){
175 QDomElement fieldElement = nodeListField.at(i).toElement();
176 QString fieldType = fieldElement.attribute(
"type");
177 if(!fieldType.isEmpty()){
181 QString newName = currentCylinderParametric->
changeFieldName(fieldToAdd->name());
182 fieldToAdd->setObjectName(newName);
183 currentCylinderParametric->
addField(fieldToAdd);
189 return currentCylinderParametric;
Class axlPoint defines 3D points.
void setFirstPoint(axlPoint *p1)
Change first point of this cylinder.
QStringList handled(void) const
void setRadius(double radius)
Change radius of this cylinder.
dtkAbstractDataReader * createaxlCylinderParametricReader(void)
Class axlCylinder defines 3D cylinders.
void setShader(const QString &shader)
void setSecondPoint(axlPoint *p2)
Change second point of this cylinder.
QString identifier(void) const
static bool registered(void)
virtual ~axlCylinderParametricReader(void)
QString changeFieldName(QString fieldName)
dtkAbstractDataReader * create(const QString &interface_name)
bool accept(const QDomNode &node)
virtual axlAbstractData * read(const QDomNode &node)=0
Class axlAbstractField defines an API for arrays of numeric data.
bool hasChildNode(QDomElement element, const QString &tag)
void setOpacity(const double &opacity)
void setCylinder(axlCylinder *cylinder)
QString description(void) const
axlCylinderParametricReader(void)
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)
bool reject(const QDomNode &node)
Class axlAbstractData defines an API for all type of axel data.
axlAbstractData * read(const QDomNode &node)