Developer documentation | Axl-2.5.1

axlFieldParametricCurveReader.cpp
Go to the documentation of this file.
1 /* axlFieldParametricSurfaceReader.cpp ---
2  *
3  * Author: Anais Ducoffe
4  * Copyright (C) 2013 - Anais Ducoffe, Inria.
5  */
6 
7 /* Commentary:
8  *
9  */
10 
11 /* Change log:
12  *
13  */
14 
16 #include "axlReader.h"
17 
20 
21 #include <dtkCoreSupport/dtkAbstractData.h>
22 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
23 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
24 
25 // /////////////////////////////////////////////////////////////////
26 // axlFieldParametricSurfaceReader
27 // /////////////////////////////////////////////////////////////////
28 
30 {
31  this->setObjectName(this->description());
32 }
33 
35 {
36 
37 }
38 
40 {
41  return "axlFieldParametricSurfaceReader";
42 }
43 
45 {
46  return "axlFieldParametricSurfaceReader";
47 }
48 
50 {
51  return QStringList() << "axlFieldParametricSurface";
52 }
53 
55 {
56  return dtkAbstractDataFactory::instance()->registerDataReaderType("axlFieldParametricSurfaceReader", QStringList(), createaxlFieldParametricSurfaceReader);
57 }
58 
59 bool axlFieldParametricSurfaceReader::accept(const QDomNode& node)
60 {
61  QDomElement element = node.toElement();
62 
63  if(element.tagName() != "field")
64  return false;
65 
66  return true;
67 }
68 
69 bool axlFieldParametricSurfaceReader::reject(const QDomNode& node)
70 {
71  return !this->accept(node);
72 }
73 
74 
75 //read only one special field :axlFieldParametricNormalVector.
77 {
78 
79  qDebug() << Q_FUNC_INFO << "enter";
80  QDomElement element = node.toElement();
81  axlFieldParametricSurface *field = NULL;
82 
83  // field type : the type corresponds to the identifier, use factory to initialize field.
84  QString type = element.attribute("type");
85  if(!type.isEmpty())
86  {
87  field = dynamic_cast<axlFieldParametricSurface *>(dtkAbstractDataFactory::instance()->create(type));
88  }
89 
91  QString name = element.attribute("name");
92  if(!name.isEmpty())
93  {
94  field->setObjectName(name);
95  }
96 
98  QString typeField = element.attribute("valueType");
99  if(!typeField.isEmpty()){
100  if(typeField == "int"){
102  }else if(typeField == "float"){
104  }else{
106  }
107  }
108 
109 
111  QString support = element.attribute("support");
112  if(support == "point"){
114  }else if(support == "cell"){
116  }else{
118  }
119 
121  QString kind = element.attribute("kind");
122  if(kind == "scalar"){
124  }else if(kind == "vector"){
126  }else{
128  }
129 
130 
132  QDomNodeList listFunction = element.elementsByTagName("surface");
133  QDomElement functionDescription = listFunction.at(0).toElement();
134  qDebug() << Q_FUNC_INFO << "read function description";
135 
136  dtkAbstractData *data = NULL;
137  // test for all reader registered in the factory
138  foreach(QString reader, dtkAbstractDataFactory::instance()->readers()) {
139  axlAbstractDataReader *axl_reader = dynamic_cast<axlAbstractDataReader *>(dtkAbstractDataFactory::instance()->reader(reader));
140  data = this->dataByReader(axl_reader, functionDescription);
141  delete axl_reader;
142 
143  if(data){
144  axlAbstractData *function = dynamic_cast<axlAbstractData *>(data);
145  field->setFunction(function);
146  }
147  }
148 
149 
150  field->update();
151  return field;
152 
153 
154 }
155 
156 dtkAbstractData *axlFieldParametricSurfaceReader::dataByReader(axlAbstractDataReader *axl_reader, const QDomNode& node)
157 {
158  if(!axl_reader)
159  return NULL;
160 
161  if(!axl_reader->accept(node))
162  return NULL;
163 
164  axl_reader->dtkAbstractDataReader::read(this->file());
165 
166  if(dtkAbstractData *data = axl_reader->read(node))
167  return data;
168 
169 
170  return NULL;
171 }
172 
173 
174 
175 dtkAbstractDataReader *createaxlFieldParametricSurfaceReader(void)
176 {
178 }
179 
180 
dtkAbstractData * dataByReader(axlAbstractDataReader *axl_reader, const QDomNode &node)
Class axlFieldParametricSurface defines an API for field which owns a BSpline Surface as a function a...
dtkAbstractDataReader * createaxlFieldParametricSurfaceReader(void)
void setFunction(axlAbstractData *data)
Sets the Bspline function which determines the values of the parametric field.
virtual axlAbstractData * read(const QDomNode &node)=0
axlAbstractData * read(const QDomNode &node)
virtual void setType(Type type)
Sets the type of the field which can be either int, float or double.
virtual void setSupport(Support support)
virtual bool accept(const QDomNode &node)=0
virtual void setKind(Kind kind)
Sets the kind of the field which can be either scalar, vector or tensor.
Class axlAbstractData defines an API for all type of axel data.