Developer documentation | Axl-2.5.1

axlFieldReader.cpp
Go to the documentation of this file.
1 /* axlFieldReader.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 
15 #include "axlFieldReader.h"
16 #include "axlReader.h"
17 
19 #include <axlCore/axlInteger.h>
20 #include <axlCore/axlDouble.h>
21 
22 #include <dtkCoreSupport/dtkAbstractData.h>
23 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
24 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
25 
26 //#include <axlGui/axlInspectorToolFactory.h>
27 
28 // /////////////////////////////////////////////////////////////////
29 // axlFieldReader
30 // /////////////////////////////////////////////////////////////////
31 
33 {
34  this->setObjectName(this->description());
35 }
36 
38 {
39 
40 }
41 
42 QString axlFieldReader::identifier(void) const
43 {
44  return "axlFieldReader";
45 }
46 
47 QString axlFieldReader::description(void) const
48 {
49  return "axlFieldReader";
50 }
51 
52 QStringList axlFieldReader::handled(void) const
53 {
54  return QStringList() << "axlAbstractField";
55 }
56 
58 {
59  return dtkAbstractDataFactory::instance()->registerDataReaderType("axlFieldReader", QStringList(), createaxlFieldReader);
60 }
61 
62 bool axlFieldReader::accept(const QDomNode& node)
63 {
64  QDomElement element = node.toElement();
65 
66  if(element.tagName() != "field")
67  return false;
68 
69  return true;
70 }
71 
72 bool axlFieldReader::reject(const QDomNode& node)
73 {
74  return !this->accept(node);
75 }
76 
77 
78 //read only one special field :axlFieldSpatialPointDistance.
79 axlAbstractData *axlFieldReader::read(const QDomNode& node)
80 {
81 
82  QDomElement element = node.toElement();
83  axlAbstractField *field = NULL;
84 
85  // //initialize the field with the factory
86  // QString status = element.attribute("status");
87  // if(!status.isEmpty())
88  // field = dynamic_cast<axlAbstractField *>(dtkAbstractDataFactory::instance()->create(status));
89  // qDebug() << Q_FUNC_INFO << status;
90 
91 
92  // field name : the name corresponds to the identifier, use factory to initialize field.
93  QString name = element.attribute("name");
94  if(!name.isEmpty())
95  {
96  field = dynamic_cast<axlAbstractField *>(dtkAbstractDataFactory::instance()->create(name));
97  }
98 
99  //field type
100  QString type = element.attribute("type");
101  if(type == "int"){
103  }else if(type == "float"){
105  }else if(type == "double"){
107  }
108 
109 
110  //field kind
111  QString kind = element.attribute("kind");
112  if(kind == "scalar"){
114  }else if(type == "vector"){
116  }else if(type == "tensor"){
118 
119  }
120 
121  //field support
122  QString support = element.attribute("support");
123  if(kind == "point"){
125  }else if(type == "cell"){
127  }else if(type == "custom"){
129 
130  }
131 
132  // //find the parents name, ie the object on which the field is applied.
133  // QString dataSupportName = element.attribute("parent");
134  // //we search this data in the list (inserted before its fields !)
135  // foreach(dtkAbstractData *data, list){
136  // if(data->name() == dataSupportName)
137  // dynamic_cast<axlAbstractData *>(data)->addField(field);
138  // }
139 
140 
141 
142  field->update();
143  return field;
144 
145 
146 }
147 
148 dtkAbstractData *axlFieldReader::dataByReader(axlAbstractDataReader *axl_reader, const QDomNode& node)
149 {
150  if(!axl_reader)
151  return NULL;
152 
153  if(!axl_reader->accept(node))
154  return NULL;
155 
156  axl_reader->dtkAbstractDataReader::read(this->file());
157 
158  if(dtkAbstractData *data = axl_reader->read(node))
159  return data;
160 
161 
162  return NULL;
163 }
164 
165 dtkAbstractDataReader *createaxlFieldReader(void)
166 {
167  return new axlFieldReader;
168 }
169 
bool reject(const QDomNode &node)
dtkAbstractData * dataByReader(axlAbstractDataReader *axl_reader, const QDomNode &node)
dtkAbstractDataReader * createaxlFieldReader(void)
static bool registered(void)
virtual void update(void)
QString identifier(void) const
virtual axlAbstractData * read(const QDomNode &node)=0
QStringList handled(void) const
Class axlAbstractField defines an API for arrays of numeric data.
virtual void setType(Type type)
Sets the type of the field which can be either int, float or double.
QString description(void) const
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.
axlAbstractData * read(const QDomNode &node)
Class axlAbstractData defines an API for all type of axel data.
bool accept(const QDomNode &node)