InstrumentWidgetEncoder.cpp 17.3 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
7
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetEncoder.h"
Samuel Jones's avatar
Samuel Jones committed
8
9
10
11
#include "MantidQtWidgets/InstrumentView/ColorBar.h"
#include "MantidQtWidgets/InstrumentView/InstrumentActor.h"
#include "MantidQtWidgets/InstrumentView/InstrumentTreeWidget.h"
#include "MantidQtWidgets/InstrumentView/InstrumentWidget.h"
Samuel Jones's avatar
Samuel Jones committed
12
13
14
15
16
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetMaskTab.h"
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetPickTab.h"
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetRenderTab.h"
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetTab.h"
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetTreeTab.h"
Samuel Jones's avatar
Samuel Jones committed
17
18
19
#include "MantidQtWidgets/InstrumentView/MaskBinsData.h"
#include "MantidQtWidgets/InstrumentView/ProjectionSurface.h"
#include "MantidQtWidgets/InstrumentView/Shape2D.h"
Samuel Jones's avatar
Samuel Jones committed
20
#include "MantidQtWidgets/InstrumentView/XIntegrationControl.h"
21

22
#include <QAction>
Samuel Jones's avatar
Samuel Jones committed
23
#include <QCheckBox>
24
#include <QComboBox>
Samuel Jones's avatar
Samuel Jones committed
25
26
#include <QPushButton>
#include <QRadioButton>
27

Samuel Jones's avatar
Samuel Jones committed
28
29
namespace MantidQt {
namespace MantidWidgets {
30

31
32
InstrumentWidgetEncoder::InstrumentWidgetEncoder()
    : m_projectPath(""), m_saveMask(true) {}
33

Samuel Jones's avatar
Samuel Jones committed
34
35
QMap<QString, QVariant>
InstrumentWidgetEncoder::encode(const InstrumentWidget &obj,
36
37
                                const QString &projectPath,
                                const bool saveMask) {
Samuel Jones's avatar
Samuel Jones committed
38
  QMap<QString, QVariant> map;
39
40
41
42
43
  // there is no reference to the workspace if it is being replaced, so return
  // the empty map
  if (!obj.isWsBeingReplaced()) {
    m_projectPath = projectPath.toStdString();
    m_saveMask = saveMask;
Samuel Jones's avatar
Samuel Jones committed
44

45
    map.insert(QString("workspaceName"), QVariant(obj.getWorkspaceName()));
46

47
    map.insert(QString("surfaceType"), QVariant(obj.getSurfaceType()));
48

49
    map.insert(QString("currentTab"), QVariant(obj.getCurrentTab()));
Samuel Jones's avatar
Samuel Jones committed
50

51
    QList<QVariant> energyTransferList;
52
53
54
55

    energyTransferList.append(QVariant(obj.m_xIntegration->getMinimum()));
    energyTransferList.append(QVariant(obj.m_xIntegration->getMaximum()));

56
    map.insert(QString("energyTransfer"), QVariant(energyTransferList));
57

58
59
60
61
62
63
    map.insert(QString("surface"),
               QVariant(this->encodeSurface(obj.getSurface())));
    map.insert(QString("actor"),
               QVariant(this->encodeActor(obj.m_instrumentActor)));
    map.insert(QString("tabs"), QVariant(this->encodeTabs(obj)));
  }
64
65
66
  return map;
}

Samuel Jones's avatar
Samuel Jones committed
67
QMap<QString, QVariant>
68
InstrumentWidgetEncoder::encodeTabs(const InstrumentWidget &obj) {
Samuel Jones's avatar
Samuel Jones committed
69
  QMap<QString, QVariant> tabs;
70

Samuel Jones's avatar
Samuel Jones committed
71
72
73
74
  tabs.insert(QString("maskTab"), QVariant(encodeMaskTab(obj.m_maskTab)));
  tabs.insert(QString("renderTab"), QVariant(encodeRenderTab(obj.m_renderTab)));
  tabs.insert(QString("treeTab"), QVariant(encodeTreeTab(obj.m_treeTab)));
  tabs.insert(QString("pickTab"), QVariant(encodePickTab(obj.m_pickTab)));
75
76
77
78

  return tabs;
}

Samuel Jones's avatar
Samuel Jones committed
79
80
81
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeTreeTab(const InstrumentWidgetTreeTab *tab) {
  auto index = tab->m_instrumentTree->currentIndex();
Samuel Jones's avatar
Samuel Jones committed
82
  auto model = index.model();
Samuel Jones's avatar
Samuel Jones committed
83

Samuel Jones's avatar
Samuel Jones committed
84
  QMap<QString, QVariant> map;
Samuel Jones's avatar
Samuel Jones committed
85
86
87

  if (model) {
    auto item = model->data(index);
Samuel Jones's avatar
Samuel Jones committed
88
89
    QString name = item.value<QString>();
    map.insert(QString("selectedComponent"), QVariant(name));
Samuel Jones's avatar
Samuel Jones committed
90
91
  }

Samuel Jones's avatar
Samuel Jones committed
92
93
  QList<QString> list;
  const auto names = tab->m_instrumentTree->findExpandedComponents();
Gagik Vardanyan's avatar
Gagik Vardanyan committed
94
  for (const auto &name : names) {
Samuel Jones's avatar
Samuel Jones committed
95
96
    list.append(name);
  }
97
  map.insert(QString("expandedItems"), QVariant(list));
Samuel Jones's avatar
Samuel Jones committed
98
99
100
101

  return map;
}

102
103
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeRenderTab(const InstrumentWidgetRenderTab *tab) {
Samuel Jones's avatar
Samuel Jones committed
104
  QMap<QString, QVariant> map;
Samuel Jones's avatar
Samuel Jones committed
105
  map.insert(QString("axesView"), QVariant(tab->mAxisCombo->currentIndex()));
Samuel Jones's avatar
Samuel Jones committed
106
107
108
109
110
111
112
113
114
115
116
117
  map.insert(QString("autoScaling"), QVariant(tab->m_autoscaling->isChecked()));
  map.insert(QString("displayAxes"), QVariant(tab->m_displayAxes->isChecked()));
  map.insert(QString("flipView"), QVariant(tab->m_flipCheckBox->isChecked()));
  map.insert(QString("displayDetectorsOnly"),
             QVariant(tab->m_displayDetectorsOnly->isChecked()));
  map.insert(QString("displayWireframe"),
             QVariant(tab->m_wireframe->isChecked()));
  map.insert(QString("displayLighting"),
             QVariant(tab->m_lighting->isChecked()));
  map.insert(QString("useOpenGL"), QVariant(tab->m_GLView->isChecked()));
  map.insert(QString("useUCorrection"),
             QVariant(tab->m_UCorrection->isChecked()));
Samuel Jones's avatar
Samuel Jones committed
118
119

  const auto surface = tab->getSurface();
Samuel Jones's avatar
Samuel Jones committed
120
121
122
123
124
125
  map.insert(QString("showLabels"), QVariant(surface->getShowPeakRowsFlag()));
  map.insert(QString("showRows"), QVariant(surface->getShowPeakRowsFlag()));
  map.insert(QString("labelPrecision"),
             QVariant(surface->getPeakLabelPrecision()));
  map.insert(QString("showRelativeIntensity"),
             QVariant(surface->getShowPeakRelativeIntensityFlag()));
Samuel Jones's avatar
Samuel Jones committed
126

Samuel Jones's avatar
Samuel Jones committed
127
128
  const auto colorBar = encodeColorBar(tab->m_colorBarWidget);
  map.insert(QString("colorBar"), QVariant(colorBar));
Samuel Jones's avatar
Samuel Jones committed
129

130
131
132
  map.insert(QString("freezeRotation"),
             QVariant(tab->m_freezeRotation->isChecked()));

Samuel Jones's avatar
Samuel Jones committed
133
134
135
  return map;
}

Samuel Jones's avatar
Samuel Jones committed
136
137
138
QMap<QString, QVariant> InstrumentWidgetEncoder::encodeColorBar(
    MantidQt::MantidWidgets::ColorBar *bar) {
  QMap<QString, QVariant> map;
139

Samuel Jones's avatar
Samuel Jones committed
140
141
142
143
  map.insert(QString("scaleType"), QVariant(bar->getScaleType()));
  map.insert(QString("power"), QVariant(bar->getNthPower()));
  map.insert(QString("min"), QVariant(bar->getMinValue()));
  map.insert(QString("max"), QVariant(bar->getMaxValue()));
144

Samuel Jones's avatar
Samuel Jones committed
145
  return map;
146
147
148
149
150
}

// This is the tab labelled draw
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeMaskTab(const InstrumentWidgetMaskTab *tab) {
Samuel Jones's avatar
Samuel Jones committed
151
152
153
  QMap<QString, QVariant> map;
  QMap<QString, QVariant> activeTools;
  QMap<QString, QVariant> activeType;
154

Samuel Jones's avatar
Samuel Jones committed
155
  activeTools.insert(QString("moveButton"), QVariant(tab->m_move->isChecked()));
156
  activeTools.insert(QString("pointerButton"),
Samuel Jones's avatar
Samuel Jones committed
157
                     QVariant(tab->m_pointer->isChecked()));
158
  activeTools.insert(QString("ellipseButton"),
Samuel Jones's avatar
Samuel Jones committed
159
                     QVariant(tab->m_ellipse->isChecked()));
160
  activeTools.insert(QString("ringEllipseButton"),
Samuel Jones's avatar
Samuel Jones committed
161
                     QVariant(tab->m_ring_ellipse->isChecked()));
162
  activeTools.insert(QString("ringRectangleButton"),
Samuel Jones's avatar
Samuel Jones committed
163
                     QVariant(tab->m_ring_rectangle->isChecked()));
164
  activeTools.insert(QString("freeDrawButton"),
Samuel Jones's avatar
Samuel Jones committed
165
                     QVariant(tab->m_free_draw->isChecked()));
166
167
168
  activeTools.insert(QString("pixelButton"),
                     QVariant(tab->m_pixel->isChecked()));
  activeTools.insert(QString("tubeButton"), QVariant(tab->m_tube->isChecked()));
169
170
171
  map.insert(QString("activeTools"), QVariant(activeTools));

  activeType.insert(QString("maskingOn"),
Samuel Jones's avatar
Samuel Jones committed
172
                    QVariant(tab->m_masking_on->isChecked()));
173
  activeType.insert(QString("groupingOn"),
Samuel Jones's avatar
Samuel Jones committed
174
175
                    QVariant(tab->m_grouping_on->isChecked()));
  activeType.insert(QString("roiOn"), QVariant(tab->m_roi_on->isChecked()));
176
177
  map.insert(QString("activeType"), QVariant(activeType));

178
179
180
181
182
183
184
185
186
187
188
  if (m_saveMask) {
    // Save the masks applied to view but not saved to a workspace
    auto wsName = tab->m_instrWidget->getWorkspaceName() + "MaskView.xml";
    bool success =
        tab->saveMaskViewToProject(wsName.toStdString(), m_projectPath);
    map.insert(QString("maskWorkspaceSaved"), QVariant(success));
    if (success) {
      map.insert(QString("maskWorkspaceName"), QVariant(wsName));
    }
  } else {
    map.insert(QString("maskWorkspaceSaved"), QVariant(false));
189
  }
Samuel Jones's avatar
Samuel Jones committed
190
191

  return map;
192
193
194
}

QMap<QString, QVariant>
Samuel Jones's avatar
Samuel Jones committed
195
InstrumentWidgetEncoder::encodePickTab(const InstrumentWidgetPickTab *tab) {
Samuel Jones's avatar
Samuel Jones committed
196
  QMap<QString, QVariant> map;
Samuel Jones's avatar
Samuel Jones committed
197
198
199
200
201
202

  // Save whether a button is active or not
  map.insert(QString("zoom"), QVariant(tab->m_zoom->isChecked()));
  map.insert(QString("edit"), QVariant(tab->m_edit->isChecked()));
  map.insert(QString("ellipse"), QVariant(tab->m_ellipse->isChecked()));
  map.insert(QString("rectangle"), QVariant(tab->m_rectangle->isChecked()));
Samuel Jones's avatar
Samuel Jones committed
203
204
205
206
  map.insert(QString("ringEllipse"),
             QVariant(tab->m_ring_ellipse->isChecked()));
  map.insert(QString("ringRectangle"),
             QVariant(tab->m_ring_rectangle->isChecked()));
Samuel Jones's avatar
Samuel Jones committed
207
208
209
  map.insert(QString("freeDraw"), QVariant(tab->m_free_draw->isChecked()));
  map.insert(QString("one"), QVariant(tab->m_one->isChecked()));
  map.insert(QString("tube"), QVariant(tab->m_tube->isChecked()));
210
  map.insert(QString("peakAdd"), QVariant(tab->m_peakAdd->isChecked()));
211
  map.insert(QString("peakErase"), QVariant(tab->m_peakErase->isChecked()));
212

Samuel Jones's avatar
Samuel Jones committed
213
214
  return map;
}
215
216
217

QMap<QString, QVariant> InstrumentWidgetEncoder::encodeActor(
    const std::unique_ptr<InstrumentActor> &obj) {
Samuel Jones's avatar
Samuel Jones committed
218
  QMap<QString, QVariant> map;
219

Samuel Jones's avatar
Samuel Jones committed
220
221
222
  map.insert(QString("fileName"), QVariant(obj->getCurrentColorMap()));
  map.insert(QString("binMasks"),
             QVariant(this->encodeMaskBinsData(obj->m_maskBinsData)));
223
224
225
226
227
228

  return map;
}

QList<QVariant>
InstrumentWidgetEncoder::encodeMaskBinsData(const MaskBinsData &obj) {
Samuel Jones's avatar
Samuel Jones committed
229
  QList<QVariant> list;
230
231

  for (const auto &binMask : obj.m_masks) {
Samuel Jones's avatar
Samuel Jones committed
232
    list.append(QVariant(this->encodeBinMask(binMask)));
233
234
235
236
237
238
239
  }

  return list;
}

QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeBinMask(const BinMask &obj) {
Samuel Jones's avatar
Samuel Jones committed
240
  QMap<QString, QVariant> map;
241

Samuel Jones's avatar
Samuel Jones committed
242
  QList<QVariant> range;
243
  // Convert Doubles to QString
Samuel Jones's avatar
Samuel Jones committed
244
245
246
  range.append(QVariant(QString("%1").arg(obj.start)));
  range.append(QVariant(QString("%1").arg(obj.end)));
  map.insert(QString("range"), QVariant(range));
247

Samuel Jones's avatar
Samuel Jones committed
248
  QList<QVariant> spectra;
249
  for (const auto &spectrum : obj.spectra) {
Samuel Jones's avatar
Samuel Jones committed
250
    spectra.append(QVariant(quint64(spectrum)));
251
  }
Samuel Jones's avatar
Samuel Jones committed
252
  map.insert(QString("spectra"), QVariant(spectra));
Samuel Jones's avatar
Samuel Jones committed
253
254

  return map;
255
256
257
258
}

QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeSurface(const ProjectionSurface_sptr &obj) {
Samuel Jones's avatar
Samuel Jones committed
259
  QMap<QString, QVariant> map;
260

261
  auto projection3D = std::dynamic_pointer_cast<Projection3D>(obj);
Samuel Jones's avatar
Samuel Jones committed
262
  if (projection3D) {
263
    map.insert(QString("projection3DSuccess"), QVariant(true));
Samuel Jones's avatar
Samuel Jones committed
264
265
    map.insert(QString("projection3D"),
               QVariant(this->encodeProjection3D(*projection3D)));
266
267
268
269
  } else {
    map.insert(QString("projection3DSuccess"), QVariant(false));
  }

Samuel Jones's avatar
Samuel Jones committed
270
271
272
273
274
  map.insert(QString("backgroundColor"), QVariant(obj->m_backgroundColor));
  map.insert(QString("shapes"),
             QVariant(this->encodeMaskShapes(obj->m_maskShapes)));
  map.insert(QString("alignmentInfo"),
             QVariant(this->encodeAlignmentInfo(obj)));
275
276
277
278

  return map;
}

279
280
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeProjection3D(const Projection3D &obj) {
281
  QMap<QString, QVariant> map;
282
283
  map.insert(QString("viewport"),
             QVariant(this->encodeViewPort(obj.m_viewport)));
284
285
286
  return map;
}

287
288
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeViewPort(const Viewport &obj) {
289
290
  QMap<QString, QVariant> map;
  QMap<QString, QVariant> translationMap;
291

292
293
294
295
  translationMap.insert(QString("xTrans"), QVariant(obj.m_xTrans));
  translationMap.insert(QString("yTrans"), QVariant(obj.m_yTrans));
  map.insert(QString("translation"), QVariant(translationMap));

296
  map.insert(QString("zoom"), QVariant(obj.m_zoomFactor));
297
298

  QList<QVariant> rotation;
299
  for (auto i = 0; i < 4; ++i) {
300
301
302
    rotation.append(obj.m_quaternion[i]);
  }
  map.insert(QString("rotation"), QVariant(rotation));
303

304
305
306
  return map;
}

307
QList<QVariant>
308
InstrumentWidgetEncoder::encodeMaskShapes(const Shape2DCollection &obj) {
Samuel Jones's avatar
Samuel Jones committed
309
  QList<QVariant> list;
310
311

  for (const auto &shape : obj.m_shapes) {
Samuel Jones's avatar
Samuel Jones committed
312
    list.append(QVariant(this->encodeShape(shape)));
313
314
315
316
317
  }

  return list;
}

318
319
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeShape(const Shape2D *obj) {
Samuel Jones's avatar
Samuel Jones committed
320
  QMap<QString, QVariant> map;
321

Samuel Jones's avatar
Samuel Jones committed
322
  map.insert(QString("properties"), QVariant(this->encodeShapeProperties(obj)));
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338

  const auto color = obj->getColor();
  QMap<QString, QVariant> colorMap;
  colorMap.insert(QString("red"), QVariant(color.red()));
  colorMap.insert(QString("green"), QVariant(color.green()));
  colorMap.insert(QString("blue"), QVariant(color.blue()));
  colorMap.insert(QString("alpha"), QVariant(color.alpha()));
  map.insert(QString("color"), QVariant(colorMap));

  const auto fillColor = obj->getFillColor();
  QMap<QString, QVariant> fillColorMap;
  fillColorMap.insert(QString("red"), QVariant(fillColor.red()));
  fillColorMap.insert(QString("green"), QVariant(fillColor.green()));
  fillColorMap.insert(QString("blue"), QVariant(fillColor.blue()));
  fillColorMap.insert(QString("alpha"), QVariant(fillColor.alpha()));
  map.insert(QString("fillColor"), QVariant(fillColorMap));
339

Samuel Jones's avatar
Samuel Jones committed
340
  QMap<QString, QVariant> subShapeMap;
341
  if (obj->type() == "ellipse") {
342
    subShapeMap = this->encodeEllipse(static_cast<const Shape2DEllipse *>(obj));
Samuel Jones's avatar
Samuel Jones committed
343
    map.insert(QString("type"), QVariant(QString("ellipse")));
344
  } else if (obj->type() == "rectangle") {
345
    subShapeMap =
346
        this->encodeRectangle(static_cast<const Shape2DRectangle *>(obj));
Samuel Jones's avatar
Samuel Jones committed
347
    map.insert(QString("type"), QVariant(QString("rectangle")));
348
  } else if (obj->type() == "ring") {
349
    subShapeMap = this->encodeRing(static_cast<const Shape2DRing *>(obj));
Samuel Jones's avatar
Samuel Jones committed
350
    map.insert(QString("type"), QVariant(QString("ring")));
351
352
353
  } else if (obj->type() == "sector") {
    subShapeMap = this->encodeSector(static_cast<const Shape2DSector *>(obj));
    map.insert(QString("type"), QVariant(QString("sector")));
354
  } else if (obj->type() == "free") {
355
    subShapeMap = this->encodeFree(static_cast<const Shape2DFree *>(obj));
Samuel Jones's avatar
Samuel Jones committed
356
357
    map.insert(QString("type"), QVariant(QString("free")));
  } else {
358
    throw std::runtime_error("InstrumentView - Could not encode shape");
Samuel Jones's avatar
Samuel Jones committed
359
360
361
362
363
364
365
366
  }

  map.insert(QString("subShapeMap"), QVariant(subShapeMap));

  return map;
}

QMap<QString, QVariant>
367
InstrumentWidgetEncoder::encodeEllipse(const Shape2DEllipse *obj) {
Samuel Jones's avatar
Samuel Jones committed
368
369
370
  const double radius1 = obj->getDouble("radius1");
  const double radius2 = obj->getDouble("radius2");
  const auto centre = obj->getPoint("centre");
371
  const auto rot = obj->getBoundingRotation();
Samuel Jones's avatar
Samuel Jones committed
372
373
374
375
376
377
378

  QMap<QString, QVariant> map;

  map.insert(QString("radius1"), QVariant(radius1));
  map.insert(QString("radius2"), QVariant(radius2));
  map.insert(QString("x"), QVariant(centre.x()));
  map.insert(QString("y"), QVariant(centre.y()));
379
  map.insert(QString("rotation"), QVariant(rot));
Samuel Jones's avatar
Samuel Jones committed
380
381
382
383
384

  return map;
}

QMap<QString, QVariant>
385
InstrumentWidgetEncoder::encodeRectangle(const Shape2DRectangle *obj) {
Samuel Jones's avatar
Samuel Jones committed
386
387
388
389
  const auto x0 = obj->m_boundingRect.x0();
  const auto x1 = obj->m_boundingRect.x1();
  const auto y0 = obj->m_boundingRect.y0();
  const auto y1 = obj->m_boundingRect.y1();
390
  const auto rot = obj->getBoundingRotation();
Samuel Jones's avatar
Samuel Jones committed
391
392
393
394
395
396
397

  QMap<QString, QVariant> map;

  map.insert(QString("x0"), QVariant(x0));
  map.insert(QString("y0"), QVariant(y0));
  map.insert(QString("x1"), QVariant(x1));
  map.insert(QString("y1"), QVariant(y1));
398
  map.insert(QString("rotation"), QVariant(rot));
Samuel Jones's avatar
Samuel Jones committed
399
400
401
402

  return map;
}

403
404
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeRing(const Shape2DRing *obj) {
Samuel Jones's avatar
Samuel Jones committed
405
406
407
408
409
410
411
412
413
414
415
416
  const auto xWidth = obj->getDouble("xwidth");
  const auto yWidth = obj->getDouble("ywidth");
  auto baseShape = obj->getOuterShape()->clone();

  QMap<QString, QVariant> map;
  map.insert(QString("xWidth"), QVariant(xWidth));
  map.insert(QString("yWidth"), QVariant(yWidth));
  map.insert(QString("shape"), QVariant(this->encodeShape(baseShape)));

  return map;
}

417
418
419
420
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeSector(const Shape2DSector *obj) {
  const auto outerRadius = obj->getDouble("outerRadius");
  const auto innerRadius = obj->getDouble("innerRadius");
Mathieu Tillet's avatar
Mathieu Tillet committed
421
422
  const auto startAngle = obj->getDouble("startAngle") * M_PI / 180;
  const auto endAngle = obj->getDouble("endAngle") * M_PI / 180;
Mathieu Tillet's avatar
Mathieu Tillet committed
423
424
  const auto centerX = obj->getPoint("center").x();
  const auto centerY = obj->getPoint("center").y();
425
426
427
428
429
430

  QMap<QString, QVariant> map;
  map.insert(QString("outerRadius"), QVariant(outerRadius));
  map.insert(QString("innerRadius"), QVariant(innerRadius));
  map.insert(QString("startAngle"), QVariant(startAngle));
  map.insert(QString("endAngle"), QVariant(endAngle));
Mathieu Tillet's avatar
Mathieu Tillet committed
431
432
  map.insert(QString("centerX"), QVariant(centerX));
  map.insert(QString("centerY"), QVariant(centerY));
433
434
435
436

  return map;
}

437
438
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeFree(const Shape2DFree *obj) {
Samuel Jones's avatar
Samuel Jones committed
439
440
441
442
443
444
445
446
  const auto polygon = obj->m_polygon;

  QList<QVariant> parameters;

  for (const auto &point : polygon) {
    QList<QVariant> list;
    list.append(QVariant(point.x()));
    list.append(QVariant(point.y()));
447
    parameters.append(QVariant(list));
Samuel Jones's avatar
Samuel Jones committed
448
449
450
451
  }

  QMap<QString, QVariant> map;
  map.insert(QString("paramaters"), QVariant(parameters));
452
453
454
455
  return map;
}

QMap<QString, QVariant>
Samuel Jones's avatar
Samuel Jones committed
456
457
InstrumentWidgetEncoder::encodeShapeProperties(const Shape2D *obj) {
  QMap<QString, QVariant> map;
458

Samuel Jones's avatar
Samuel Jones committed
459
460
461
462
  map.insert(QString("scalable"), QVariant(obj->m_scalable));
  map.insert(QString("editing"), QVariant(obj->m_editing));
  map.insert(QString("selected"), QVariant(obj->m_selected));
  map.insert(QString("visible"), QVariant(obj->m_visible));
463
464
465
466

  return map;
}

Samuel Jones's avatar
Samuel Jones committed
467
QList<QVariant> InstrumentWidgetEncoder::encodeAlignmentInfo(
468
    const ProjectionSurface_sptr &obj) {
469
  QList<QVariant> list;
470

Samuel Jones's avatar
Samuel Jones committed
471
  for (const auto &item : obj->m_selectedAlignmentPlane) {
472
    const auto qLab = item.first;
473
474
475
476
477
478
479
480
481
482
    QMap<QString, QVariant> qLabMap;
    qLabMap.insert(QString("x"), QVariant(qLab.X()));
    qLabMap.insert(QString("y"), QVariant(qLab.Y()));
    qLabMap.insert(QString("z"), QVariant(qLab.Z()));

    QList<QVariant> itemList;
    itemList.append(QVariant(qLabMap));     // qLabMap
    itemList.append(QVariant(item.second)); // marker

    list.append(itemList);
483
484
  }

485
  return list;
Samuel Jones's avatar
Samuel Jones committed
486
487
}
} // namespace MantidWidgets
488
} // namespace MantidQt