Developer documentation | Axl-2.5.1

axlCylinderParametricWriter.cpp
Go to the documentation of this file.
1 /* axlCylinderParametricWriter.cpp ---
2  *
3  * Author: Valentin Michelet
4  * Copyright (C) 2008-2011 - Valentin Michelet, Inria.
5  * Created: Tue Aug 06 11:13:23 2013 (+0200)
6  */
7 
8 /* Commentary:
9  *
10  */
11 
12 /* Change log:
13  *
14  */
15 
17 
18 #include <axlCore/axlCylinder.h>
20 #include <axlCore/axlPoint.h>
22 
23 #include <dtkCoreSupport/dtkAbstractData.h>
24 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
25 
27 
28 // /////////////////////////////////////////////////////////////////
29 // axlCylinderParametricWriter
30 // /////////////////////////////////////////////////////////////////
31 
33  this->setObjectName(this->description());
34 }
35 
37 }
38 
40  return "axlCylinderParametricWriter";
41 }
42 
44  return "axlCylinderParametricWriter";
45 }
46 
47 QStringList axlCylinderParametricWriter::handled(void) const {
48  return QStringList() << "axlCylinderParametric";
49 }
50 
52  return dtkAbstractDataFactory::instance()->registerDataWriterType("axlCylinderParametricWriter", QStringList(), createaxlCylinderParametricWriter);
53 }
54 
55 bool axlCylinderParametricWriter::accept(dtkAbstractData *data) {
56  axlCylinderParametric *cylinderParam = dynamic_cast<axlCylinderParametric *>(data);
57  return cylinderParam != NULL;
58 }
59 
60 bool axlCylinderParametricWriter::reject(dtkAbstractData *data) {
61  return !this->accept(data);
62 }
63 
64 QDomElement axlCylinderParametricWriter::write(QDomDocument *doc, dtkAbstractData *data) {
65  // Get cylinder parametric
66  axlCylinderParametric *cylinderParam = dynamic_cast<axlCylinderParametric *>(data);
67  // Get cylinder
68  axlCylinder* cylinder = cylinderParam->getCylinder();
69 
70  // Create name
71  QDomElement cylinderParamElement = doc->createElement("cylinderParam");
72  cylinderParamElement.setAttribute("name",cylinder->name());
73 
74  // Create size
75  cylinderParamElement.setAttribute("size", QString::number(cylinder->size()));
76 
77  // Create color
78  QColor qcolor = cylinder->color();
79  QString color ;
80  QTextStream(&color) << QString::number(qcolor.red()) << " "
81  << QString::number(qcolor.green()) << " "
82  << QString::number(qcolor.blue()) << " "
83  << QString::number(cylinder->opacity());
84  cylinderParamElement.setAttribute("color", color);
85 
86  // Create shader
87  QString shader = cylinder->shader();
88  QFileInfo shaderFileInfo(shader);
89  cylinderParamElement.setAttribute("shader", shaderFileInfo.fileName());
90 
91  // Write cylinder
92  // Create first point
93  QDomElement firstPoint = doc->createElement("point");
94  QString firstPointStr;
95  QTextStream(&firstPointStr) << QString::number(cylinder->firstPoint()->x()) << " "<< QString::number(cylinder->firstPoint()->y()) << " "<< QString::number(cylinder->firstPoint()->z());
96  QDomText firstPointDomText = doc->createTextNode(firstPointStr);
97  firstPoint.appendChild(firstPointDomText);
98 
99  cylinderParamElement.appendChild(firstPoint);
100 
101  // Create second point
102  QDomElement secondPoint = doc->createElement("point");
103  QString secondPointStr;
104  QTextStream(&secondPointStr) << QString::number(cylinder->secondPoint()->x()) << " "<< QString::number(cylinder->secondPoint()->y()) << " "<< QString::number(cylinder->secondPoint()->z());
105  QDomText secondPointDomText = doc->createTextNode(secondPointStr);
106  secondPoint.appendChild(secondPointDomText);
107 
108  cylinderParamElement.appendChild(secondPoint);
109 
110  // Create radius
111  QDomElement radius = doc->createElement("radius");
112  QString radiusStr;
113  QTextStream(&radiusStr) << QString::number(cylinder->radius());
114  QDomText radiusDomText = doc->createTextNode(radiusStr);
115  radius.appendChild(radiusDomText);
116 
117  cylinderParamElement.appendChild(radius);
118 
119  // Create refdir
120  QDomElement refdir = doc->createElement("refdir");
121  QString refdirStr;
122  QTextStream(&refdirStr) << QString::number(cylinderParam->getR()->x()) << " "<< QString::number(cylinderParam->getR()->y()) << " "<< QString::number(cylinderParam->getR()->z());
123  QDomText refdirDomText = doc->createTextNode(refdirStr);
124  refdir.appendChild(refdirDomText);
125 
126  cylinderParamElement.appendChild(refdir);
127 
128  // Write fields if exist.
129  if(!cylinder->fields().isEmpty()){
130  foreach(axlAbstractField *field, cylinder->fields()){
132  QDomElement fieldElement = field_writer->write(doc, field);
133  cylinderParamElement.appendChild(fieldElement);
134  }
135  }
136 
137  return cylinderParamElement;
138 }
139 
140 
141 QDomElement axlCylinderParametricWriter::elementByWriter(axlAbstractDataWriter *axl_writer, QDomDocument *doc, dtkAbstractData *data) {
142  QDomElement element;
143 
144  if(!axl_writer)
145  return element;
146 
147  if(!axl_writer->accept(data))
148  return element;
149 
150  element = axl_writer->write(doc, data);
151 
152  return element;
153 }
154 
155 dtkAbstractDataWriter *createaxlCylinderParametricWriter(void) {
156  return new axlCylinderParametricWriter;
157 }
bool accept(dtkAbstractData *data)
virtual bool accept(dtkAbstractData *data)=0
axlPoint * secondPoint(void) const
Returns second point of the cylinder.
Class axlCylinder defines 3D cylinders.
Definition: axlCylinder.h:33
static axlFieldWritersFactory * instance(void)
axlPoint * firstPoint(void) const
Returns first point of the cylinder.
virtual QString identifier(void) const
bool reject(dtkAbstractData *data)
dtkAbstractDataWriter * create(const QString &interface_name)
Class axlAbstractField defines an API for arrays of numeric data.
double y
Definition: axlPoint.h:37
dtkAbstractDataWriter * createaxlCylinderParametricWriter(void)
double z
Definition: axlPoint.h:38
QDomElement write(QDomDocument *doc, dtkAbstractData *data)
QList< axlAbstractField * > fields(void)
virtual QDomElement write(QDomDocument *doc, dtkAbstractData *data)=0
axlCylinder * getCylinder(void) const
double radius
Definition: axlCylinder.h:37
double x
Definition: axlPoint.h:37
axlPoint * getR(void) const