Blame view

src/ParamOutputImpl/Plot/AxisLegendManager.cc 22.8 KB
fbe3c2bb   Benjamin Renard   First commit
1
#include "AxisLegendManager.hh"
07bf1e7c   Menouard AZIB   EveryThing works ...
2
3
#include <iostream> // std::cout
#include <string>
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
4
#include <vector>
fbe3c2bb   Benjamin Renard   First commit
5

fbe3c2bb   Benjamin Renard   First commit
6
7
using namespace AMDA::Info;

07bf1e7c   Menouard AZIB   EveryThing works ...
8
9
namespace plot
{
fbe3c2bb   Benjamin Renard   First commit
10

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
11
    void AxisLegendManager::configureXAxisLegendForSeries(
07bf1e7c   Menouard AZIB   EveryThing works ...
12
13
        XYPlot *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
14
15
        // Build list of all indexes used by each parameters for each x axes
        std::map<std::string, AxisParamsComponents> axesParamsComponents;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
16

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
17
18
        // Compute nb series to draw by y axis
        std::map<std::string, int> nbSeriesByYAxisMap = plot->getNbSeriesByYAxis();
21ddb9f2   Benjamin Renard   Set legend color ...
19

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
20
        SeriesProperties lSeriesProperties;
07bf1e7c   Menouard AZIB   EveryThing works ...
21
22
23
24
        for (auto param : plot->_parameterAxesList)
        {
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
25
26
                if (!lSeriesProperties.hasYAxis() || !lSeriesProperties.hasXAxis())
                    continue;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
27

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
28
                bool moreThanOneSerieForAxis = (nbSeriesByYAxisMap[lSeriesProperties.getYAxisId()] > 1);
21ddb9f2   Benjamin Renard   Set legend color ...
29

07bf1e7c   Menouard AZIB   EveryThing works ...
30
                ParameterAxes *xParameter = plot->getParameterAxesByXSerieId(lSeriesProperties.getXId());
5ee90a58   Benjamin Renard   Use AxisLegendMan...
31

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
32
                XSeriesProperties xSerie = xParameter->getXSeriePropertiesById(lSeriesProperties.getXId());
5ee90a58   Benjamin Renard   Use AxisLegendMan...
33

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
34
                std::string xAxisId = lSeriesProperties.getXAxisId();
5ee90a58   Benjamin Renard   Use AxisLegendMan...
35

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
36
                boost::shared_ptr<Axis> lXAxis = plot->_panel->getAxis(xAxisId);
07bf1e7c   Menouard AZIB   EveryThing works ...
37
38
                if (lXAxis.get() == nullptr)
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
39
40
41
42
                    continue;
                }

                Color compLegendColor = lXAxis->_color;
07bf1e7c   Menouard AZIB   EveryThing works ...
43
44
                if (moreThanOneSerieForAxis && (lSeriesProperties.getColorSerieId() == -1) && (!plot->_panel->_page->_superposeMode))
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
45
46
47
48
49
50
51
52
                    compLegendColor = plot->getSerieLineColor(lSeriesProperties, moreThanOneSerieForAxis);
                }

                ParameterIndexComponentColor xIndex = ParameterIndexComponentColor(xSerie.getIndex(), compLegendColor);
                pushComponentInList(xSerie.getParamId(), xIndex, axesParamsComponents[xAxisId]);
            }
        }

07bf1e7c   Menouard AZIB   EveryThing works ...
53
54
        if (!plot->_panel->_page->_superposeMode)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
55
56
57
58
            plot->resetAutomaticSerieColorCursor();
        }

        std::list<std::string> legendLines;
07bf1e7c   Menouard AZIB   EveryThing works ...
59
60
        for (auto axisParamsComponents : axesParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
61
62
63
64
65
66
            boost::shared_ptr<Axis> lXAxis = plot->_panel->getAxis(axisParamsComponents.first);
            setAxisLegendForSeries(plot, lXAxis, axisParamsComponents.second);
        }
    }

    void AxisLegendManager::configureYAxisLegendForSpectro(
07bf1e7c   Menouard AZIB   EveryThing works ...
67
68
69
70
        PanelPlotOutput *plot)
    {
        for (auto param : plot->_parameterAxesList)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
71
72
            std::shared_ptr<SpectroProperties> spectroPropertiesPtr = param.getSpectroProperties();
            if (spectroPropertiesPtr == nullptr)
07bf1e7c   Menouard AZIB   EveryThing works ...
73
                continue; // no spectro defined
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

            if (!spectroPropertiesPtr->hasYAxis())
                continue;

            std::string yAxisId = spectroPropertiesPtr->getYAxisId();
            boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
            if (lYAxis.get() == nullptr)
                continue;

            if (!lYAxis->_legend.isEmpty())
                continue;

            setAxisLegendForTable(plot, lYAxis, param._originalParamId, spectroPropertiesPtr->getParamId(), spectroPropertiesPtr->getIndexes(), spectroPropertiesPtr->getRelatedDim());
            return;
        }
    }

    void AxisLegendManager::configureYAxisLegendForSeries(
07bf1e7c   Menouard AZIB   EveryThing works ...
92
93
        PanelPlotOutput *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
94
95
96
97
98
99
100
        SeriesProperties lSeriesProperties;

        // Compute nb series to draw by y axis
        std::map<std::string, int> nbSeriesByYAxisMap = plot->getNbSeriesByYAxis();

        // Build list of all indexes used by each parameters for each y axes
        std::map<std::string, AxisParamsComponents> axesParamsComponents;
07bf1e7c   Menouard AZIB   EveryThing works ...
101
102
        if (!plot->_panel->_page->_superposeMode)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
103
104
            plot->resetAutomaticSerieColorCursor();
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
105
106
107
108
        for (auto param : plot->_parameterAxesList)
        {
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
109
110
111
112
113
114
115
                if (!lSeriesProperties.hasYAxis())
                    continue;

                bool moreThanOneSerieForAxis = (nbSeriesByYAxisMap[lSeriesProperties.getYAxisId()] > 1);

                std::string yAxisId = lSeriesProperties.getYAxisId();
                boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
07bf1e7c   Menouard AZIB   EveryThing works ...
116
117
                if (lYAxis.get() == nullptr)
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
118
119
120
                    continue;
                }

07bf1e7c   Menouard AZIB   EveryThing works ...
121
122
                for (auto index : lSeriesProperties.getIndexList(plot->_pParameterValues))
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
123
                    Color compLegendColor = lYAxis->_color;
07bf1e7c   Menouard AZIB   EveryThing works ...
124
125
                    if (moreThanOneSerieForAxis && (lSeriesProperties.getColorSerieId() == -1) && (!plot->_panel->_page->_superposeMode))
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
126
127
128
129
130
131
132
                        compLegendColor = plot->getSerieLineColor(lSeriesProperties, moreThanOneSerieForAxis);
                    }
                    ParameterIndexComponentColor yIndex = ParameterIndexComponentColor(index, compLegendColor);
                    pushComponentInList(lSeriesProperties.getParamId(), yIndex, axesParamsComponents[yAxisId]);
                }
            }
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
133
134
        if (!plot->_panel->_page->_superposeMode)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
135
136
137
138
            plot->resetAutomaticSerieColorCursor();
        }

        std::list<std::string> legendLines;
07bf1e7c   Menouard AZIB   EveryThing works ...
139
140
        for (auto axisParamsComponents : axesParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
141
142
143
144
145
146
            boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(axisParamsComponents.first);
            setAxisLegendForSeries(plot, lYAxis, axisParamsComponents.second);
        }
    }

    void AxisLegendManager::configureColorAxisLegendForSeries(
07bf1e7c   Menouard AZIB   EveryThing works ...
147
148
        PanelPlotOutput *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
149
150
151
152
        SeriesProperties lSeriesProperties;
        ColorSeriesProperties lColorSerieProperties;
        boost::shared_ptr<Axis> lZAxis = plot->_panel->getColorAxis();

07bf1e7c   Menouard AZIB   EveryThing works ...
153
154
        if (lZAxis.get() == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
155
156
157
158
159
            return;
        }

        // Build list of all indexes used by each parameters for each y axes
        AxisParamsComponents axisParamsComponents;
07bf1e7c   Menouard AZIB   EveryThing works ...
160
161
162
163
        for (auto param : plot->_parameterAxesList)
        {
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
164
165
166
167
168
                if (!lSeriesProperties.hasYAxis())
                    continue;

                std::string yParamId = lSeriesProperties.getParamId();

07bf1e7c   Menouard AZIB   EveryThing works ...
169
                // check if a colored param is defined for this serie
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
170
171
172
                if (lSeriesProperties.getColorParamId().empty())
                    continue;

07bf1e7c   Menouard AZIB   EveryThing works ...
173
                ParameterAxes *colorSerieParameterAxes = plot->getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId());
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

                if (colorSerieParameterAxes == NULL)
                    continue;

                lColorSerieProperties = colorSerieParameterAxes->getColorSeriePropertiesById(lSeriesProperties.getColorSerieId());

                ParameterIndexComponentColor colorSerieIndex = ParameterIndexComponentColor(-1, -1, lZAxis->_color);
                if (lColorSerieProperties.getIndex() > -1)
                    colorSerieIndex = ParameterIndexComponentColor(lColorSerieProperties.getIndex(), -1, lZAxis->_color);
                pushComponentInList(lColorSerieProperties.getColorParamIds()[yParamId], colorSerieIndex, axisParamsComponents);
            }
        }

        setAxisLegendForSeries(plot, lZAxis, axisParamsComponents);
    }

    void AxisLegendManager::configureColorAxisLegendForSpectro(
07bf1e7c   Menouard AZIB   EveryThing works ...
191
192
        PanelPlotOutput *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
193
194
        boost::shared_ptr<Axis> lZAxis = plot->_panel->getColorAxis();

07bf1e7c   Menouard AZIB   EveryThing works ...
195
196
        if (lZAxis.get() == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
197
198
            return;
        }
5ee90a58   Benjamin Renard   Use AxisLegendMan...
199

07bf1e7c   Menouard AZIB   EveryThing works ...
200
201
        for (auto param : plot->_parameterAxesList)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
202
203
            std::shared_ptr<SpectroProperties> spectroPropertiesPtr = param.getSpectroProperties();
            if (spectroPropertiesPtr == nullptr)
07bf1e7c   Menouard AZIB   EveryThing works ...
204
                continue; // no spectro defined
21ddb9f2   Benjamin Renard   Set legend color ...
205

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
206
207
            if (!spectroPropertiesPtr->hasZAxis())
                continue;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
208

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
209
210
211
            setAxisLegendForSpectro(plot, lZAxis, param._originalParamId);
            break;
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
212
213
214

        for (auto param : plot->_parameterAxesList)
        {
b0205fd9   Hacene SI HADJ MOHAND   plot ok reste que...
215
216
            std::shared_ptr<SauvaudProperties> sauvaudPropertiesPtr = param.getSauvaudProperties();
            if (sauvaudPropertiesPtr == nullptr)
07bf1e7c   Menouard AZIB   EveryThing works ...
217
                continue; // no sauvaud defined
b0205fd9   Hacene SI HADJ MOHAND   plot ok reste que...
218
219
220
221
222
223
224

            if (!sauvaudPropertiesPtr->hasZAxis())
                continue;

            setAxisLegendForSpectro(plot, lZAxis, param._originalParamId);
            break;
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
225
226
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
227
228
229
230
231
    void AxisLegendManager::pushComponentInList(std::string paramId, ParameterIndexComponentColor &index, AxisParamsComponents &axisParamsComponents)
    {
        if (index.getDim1Index() == -1 && index.getDim2Index() == -1)
        {
            // All indexes of this parameter are used
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
232
233
            axisParamsComponents[paramId].clear();
            axisParamsComponents[paramId].push_back(index);
07bf1e7c   Menouard AZIB   EveryThing works ...
234
235
236
237
238
239
240
241
        }
        else
        {
            if (axisParamsComponents[paramId].size() > 0)
            {
                if (axisParamsComponents[paramId].front().getDim1Index() == -1 && axisParamsComponents[paramId].front().getDim2Index() == -1)
                {
                    // Skip. All components already defined for this paramter on this axis
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
242
243
244
                    return;
                }
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
245
246
247
248
249
            for (auto crtIndex : axisParamsComponents[paramId])
            {
                if ((crtIndex.getDim1Index() == index.getDim1Index()) && (crtIndex.getDim2Index() == index.getDim2Index()))
                {
                    // Component already exists
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
250
251
252
                    return;
                }
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
253
            // Add this components for this axis
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
254
255
            axisParamsComponents[paramId].push_back(index);
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
256
257
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
258
259
260
261
    void AxisLegendManager::setAxisLegendForSeries(PanelPlotOutput *plot, boost::shared_ptr<Axis> &pAxis, AxisParamsComponents &axisParamsComponents)
    {
        if (pAxis == nullptr || !pAxis->_legend.isEmpty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
262
263
264
265
            return;
        }

        // Retrieve ParamInfo Manager
07bf1e7c   Menouard AZIB   EveryThing works ...
266
        ParamMgr *piMgr = ParamMgr::getInstance();
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
267

07bf1e7c   Menouard AZIB   EveryThing works ...
268
269
        for (auto paramsComponents : axisParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
270
271
            ParameterSPtr p = plot->_parameterManager.getParameter(paramsComponents.first);
            ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());
07bf1e7c   Menouard AZIB   EveryThing works ...
272
273
274
            if (paramsComponents.second.size() == p->getDataWriterTemplate()->getParamData()->getDim1() * p->getDataWriterTemplate()->getParamData()->getDim2())
            {
                // All components of this parameter are used by this axis => merge
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
275
276
277
278
279
                Color color = paramsComponents.second.front().getColor();
                paramsComponents.second.clear();
                paramsComponents.second.push_back(ParameterIndexComponentColor(-1, -1, color));
            }
            bool isFirstComponent = true;
07bf1e7c   Menouard AZIB   EveryThing works ...
280
281
            for (auto components : paramsComponents.second)
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
282
283
284
                if (paramInfo == nullptr)
                    continue;
                Label label(pAxis->_legend.getFont(), components.getColor());
07bf1e7c   Menouard AZIB   EveryThing works ...
285
286
287
288
                if (axisParamsComponents.size() == 1)
                {
                    if (isFirstComponent)
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
289
                        std::string info = getMissionInstrumentInfo(paramInfo);
07bf1e7c   Menouard AZIB   EveryThing works ...
290
291
                        if (!info.empty())
                        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
292
293
294
295
                            label._text = info;
                            addBreakLine(label._text);
                        }
                    }
07bf1e7c   Menouard AZIB   EveryThing works ...
296
297
298
                }
                else
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
299
                    std::string info = getMissionInfo(paramInfo);
07bf1e7c   Menouard AZIB   EveryThing works ...
300
301
                    if (!info.empty())
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
302
303
304
305
306
307
308
309
310
311
                        label._text = info + ", ";
                    }
                }
                label._text += getParamLegend(paramInfo, components);
                pAxis->_legend.pushLabel(label);
                isFirstComponent = false;
            }
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
312
313
314
315
    void AxisLegendManager::setAxisLegendForSpectro(PanelPlotOutput *plot, boost::shared_ptr<Axis> &pAxis, std::string originalParamId)
    {
        if (pAxis == nullptr || !pAxis->_legend.isEmpty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
316
317
318
319
            return;
        }

        // Retrieve ParamInfo Manager
07bf1e7c   Menouard AZIB   EveryThing works ...
320
        ParamMgr *piMgr = ParamMgr::getInstance();
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
321
322
323
324
325

        ParameterSPtr p = plot->_parameterManager.getParameter(originalParamId);
        AMDA::Info::ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());
        if (paramInfo == nullptr)
            return;
21ddb9f2   Benjamin Renard   Set legend color ...
326

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
327
328
329
330
331
332
        Label label(pAxis->_legend.getFont(), pAxis->_legend.getColor());
        addInfoPart(label._text, paramInfo->getShortName());
        addInfoPart(label._text, getTransformedUnits(paramInfo->getUnits()));
        pAxis->_legend.setLabel(label);
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
333
334
335
336
    void AxisLegendManager::setAxisLegendForTable(PanelPlotOutput *plot, boost::shared_ptr<Axis> &pAxis, std::string originalParamId, std::string paramId, AMDA::Common::ParameterIndexComponentList &indexes, int relatedDim)
    {
        if (pAxis == nullptr || !pAxis->_legend.isEmpty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
337
            return;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
338
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
339
340

        // Retrieve ParamInfo Manager
07bf1e7c   Menouard AZIB   EveryThing works ...
341
        ParamMgr *piMgr = ParamMgr::getInstance();
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
342
343
344
345
346
347
348
349
350

        ParameterSPtr p = plot->_parameterManager.getParameter(originalParamId);
        AMDA::Info::ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());

        if (paramInfo == nullptr)
            return;

        Label label(pAxis->_legend.getFont(), pAxis->_legend.getColor());
        std::string info = getMissionInstrumentInfo(paramInfo);
07bf1e7c   Menouard AZIB   EveryThing works ...
351
352
        if (!info.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
353
354
355
356
357
358
            addInfoPart(label._text, info);
            addBreakLine(label._text);
        }

        boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr;
        tableSPtr = paramInfo->getTable(relatedDim);
07bf1e7c   Menouard AZIB   EveryThing works ...
359
360
361

        if (tableSPtr == nullptr)
        {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
362
363
364
            // look for unique embedded table
            boost::shared_ptr<AMDA::Info::ParamTable> linkedTableSPtr;
            int counter = 0;
07bf1e7c   Menouard AZIB   EveryThing works ...
365
366
            for (auto pInfo : paramInfo->getLinkedParamList())
            {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
367
368
369
                linkedTableSPtr = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(pInfo)->getTable(relatedDim);
                if (linkedTableSPtr == nullptr)
                    continue;
07bf1e7c   Menouard AZIB   EveryThing works ...
370
                counter++;
0831b2cf   Hacene SI HADJ MOHAND   axis legend
371
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
372
373
            if (linkedTableSPtr == nullptr || counter != 1)
            {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
374
                LOG4CXX_DEBUG(gLogger, "table cannot be defined from linked info params");
07bf1e7c   Menouard AZIB   EveryThing works ...
375
376
377
            }
            else
            {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
378
379
                tableSPtr = linkedTableSPtr;
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
380
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
381

07bf1e7c   Menouard AZIB   EveryThing works ...
382
383
        if (tableSPtr == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
384
385
386
387
388
389
390
391
392
            std::string tableInfo = "Table ";
            tableInfo += std::to_string(relatedDim);
            tableInfo += " indexes";
            addInfoPart(label._text, tableInfo);
            pAxis->_legend.pushLabel(label);
            return;
        }

        if (((*plot->_pParameterValues)[paramId].getDim1Size() > 0) &&
07bf1e7c   Menouard AZIB   EveryThing works ...
393
394
395
            ((*plot->_pParameterValues)[paramId].getDim2Size() > 0) &&
            !indexes.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
396
397
            boost::shared_ptr<AMDA::Info::ParamTable> otherTableSPtr;
            int otherDimIndex;
07bf1e7c   Menouard AZIB   EveryThing works ...
398
399
            if (relatedDim == 0)
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
400
401
                otherTableSPtr = paramInfo->getTable(1);
                otherDimIndex = indexes.front().getDim2Index();
07bf1e7c   Menouard AZIB   EveryThing works ...
402
403
404
            }
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
405
406
407
                otherTableSPtr = paramInfo->getTable(0);
                otherDimIndex = indexes.front().getDim1Index();
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
408
409
            if ((otherTableSPtr != nullptr) && !otherTableSPtr->isVariable(&plot->_parameterManager))
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
410
411
412
413
414
415
416
417
418
                if (otherTableSPtr->getName(&plot->_parameterManager).empty())
                    addInfoPart(label._text, "Table bounds");
                else
                    addInfoPart(label._text, otherTableSPtr->getName(&plot->_parameterManager));

                AMDA::Info::t_TableBound crtBound = otherTableSPtr->getBound(&plot->_parameterManager, otherDimIndex);
                addBoundsPart(label._text, crtBound.min, crtBound.max);
                std::string rawUnit = otherTableSPtr->getUnits(&plot->_parameterManager);
                addInfoPart(label._text, getTransformedUnits(rawUnit));
07bf1e7c   Menouard AZIB   EveryThing works ...
419
420
421
            }
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
422
423
424
425
426
427
428
429
430
431
432
433
                std::string part = "Table Index: ";
                part += std::to_string(otherDimIndex);
                addInfoPart(label._text, part);
            }
            addBreakLine(label._text);
        }
        addInfoPart(label._text, tableSPtr->getName(&plot->_parameterManager));
        std::string rawUnit = tableSPtr->getUnits(&plot->_parameterManager);
        addInfoPart(label._text, getTransformedUnits(rawUnit));
        pAxis->_legend.pushLabel(label);
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
434
435
436
437
438
439
440
441
442
443
    void AxisLegendManager::addInfoPart(std::string &legend, std::string info)
    {
        if (!info.empty())
        {
            if (!legend.empty())
            {
                if (legend.length() >= Label::DELIMITER.length())
                {
                    if (legend.compare(legend.length() - Label::DELIMITER.length(), Label::DELIMITER.length(), Label::DELIMITER) != 0)
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
444
445
                        legend += ", ";
                    }
07bf1e7c   Menouard AZIB   EveryThing works ...
446
447
448
                }
                else
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
449
450
451
452
453
454
455
                    legend += ", ";
                }
            }
            legend += info;
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
456
457
    void AxisLegendManager::addIndexPart(std::string &legend, ParameterIndexComponentColor &index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
458
459
        legend += "[";
        legend += std::to_string(index.getDim1Index());
07bf1e7c   Menouard AZIB   EveryThing works ...
460
461
        if (index.getDim2Index() != -1)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
462
463
464
465
466
467
            legend += ",";
            legend += std::to_string(index.getDim2Index());
        }
        legend += "]";
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
468
469
    void AxisLegendManager::addIndexPart(std::string &legend, int index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
470
471
472
473
474
        legend += "[";
        legend += std::to_string(index);
        legend += "]";
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
475
476
    void AxisLegendManager::addBoundsPart(std::string &legend, PLFLT min, PLFLT max)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
477
478
479
480
481
        legend += " ";

        char minCount[1024];
        char maxCount[1024];

b358ee7d   Benjamin Renard   Adapt axes labels...
482
        int precision = computeScientificFormatPrecision(min, max);
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
483

b358ee7d   Benjamin Renard   Adapt axes labels...
484
485
        getDigitalLabel(min, precision, minCount, 1024);
        getDigitalLabel(max, precision, maxCount, 1024);
fbe3c2bb   Benjamin Renard   First commit
486

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
487
488
489
490
491
        legend += std::string(minCount);
        legend += ", ";
        legend += std::string(maxCount);
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
492
493
494
495
    void AxisLegendManager::addBreakLine(std::string &legend)
    {
        if (!legend.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
496
497
498
499
            legend += Label::DELIMITER;
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
500
501
    std::string AxisLegendManager::getParamLegend(AMDA::Info::ParamInfoSPtr paramInfo, ParameterIndexComponentColor &index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
502
503
504
        std::string legend;
        addInfoPart(legend, paramInfo->getShortName());

07bf1e7c   Menouard AZIB   EveryThing works ...
505
506
        if ((index.getDim1Index() != -1) || (index.getDim2Index() != -1))
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
507
508
509
            AMDA::Common::ParameterIndexComponent paramIndex(index.getDim1Index(), index.getDim2Index());
            if (paramInfo->getComponents(paramIndex).empty() == false)
                addInfoPart(legend, paramInfo->getComponents(paramIndex));
07bf1e7c   Menouard AZIB   EveryThing works ...
510
511
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
512
513
514
                addInfoPart(legend, paramInfo->getShortName());
                addIndexPart(legend, index);
            }
c2fa3b5d   Benjamin Renard   Rework of legend ...
515
516
        }

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
517
        addInfoPart(legend, getTransformedUnits(paramInfo->getUnits()));
c2fa3b5d   Benjamin Renard   Rework of legend ...
518
        addInfoPart(legend, paramInfo->getCoordinatesSystem());
5ee90a58   Benjamin Renard   Use AxisLegendMan...
519

c2fa3b5d   Benjamin Renard   Rework of legend ...
520
        return legend;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
    }

    /*std::string AxisLegendManager::getParamLegend(AMDA::Info::ParamInfoSPtr paramInfo, int index) {
            std::string legend;
            addInfoPart(legend, paramInfo->getShortName());

            if ((index.getDim1Index() != -1) || (index.getDim2Index() != -1)) {
                    if (paramInfo->getComponents(index).empty() == false)
                            addInfoPart(legend, paramInfo->getComponents(index));
                    else
                    {
                            addInfoPart(legend, paramInfo->getShortName());
                            addIndexPart(legend, index);
                    }
            }

            addInfoPart(legend, paramInfo->getUnits());
            addInfoPart(legend, paramInfo->getCoordinatesSystem());

            return legend;
    }*/

07bf1e7c   Menouard AZIB   EveryThing works ...
543
544
    std::string AxisLegendManager::getMissionInstrumentInfo(AMDA::Info::ParamInfoSPtr paramInfo)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
545
546
547
548
549
550
551
552
        std::string info = paramInfo->getInstrumentId();
        if (info.empty())
            return info;
        std::replace(info.begin(), info.end(), '_', ' ');
        std::transform(info.begin(), info.end(), info.begin(), ::toupper);
        return info;
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
553
554
    std::string AxisLegendManager::getMissionInfo(AMDA::Info::ParamInfoSPtr paramInfo)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
555
556
557
        std::string info = paramInfo->getInstrumentId();
        if (info.empty())
            return info;
07bf1e7c   Menouard AZIB   EveryThing works ...
558
559
        if (info.find('_') != std::string::npos)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
560
561
562
563
564
565
            info = info.substr(0, info.find('_'));
        }
        std::transform(info.begin(), info.end(), info.begin(), ::toupper);
        return info;
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
566
567
    std::string AxisLegendManager::getTransformedUnits(const std::string &rawUnit)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
568
569
570
571
572
573
574
575
        std::string unit = rawUnit;
        if (unit.find("^"))
            unit = transformPower(unit, "^");
        if (unit.find("**"))
            unit = transformPower(unit, "**");
        return unit;
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
576
577
    std::string AxisLegendManager::transformPower(std::string &unit, std::string pattern)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
578
579
580
        std::map<size_t, size_t> positions; // holds all the positions that pattern occurs within unit
        size_t pos_first = unit.find(pattern, 0);
        size_t pos_last;
07bf1e7c   Menouard AZIB   EveryThing works ...
581
582
        while (pos_first != std::string::npos)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
583
584
            char afterPattern = unit[pos_first + pattern.length()];
            pos_last = pos_first + pattern.length();
07bf1e7c   Menouard AZIB   EveryThing works ...
585
586
587
588
589
590
591
592
            if (afterPattern == '+' || afterPattern == '-')
            {
                afterPattern = unit[pos_first + pattern.length() + 1];
                pos_last++;
            }
            if (afterPattern == '(')
            {
                pos_last = unit.find(")", pos_first + pattern.length()) + 1;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
593
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
594
595
596
            else if (afterPattern == '|')
            {
                pos_last = unit.find("|", pos_first + pattern.length() + 2) + 1;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
597
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
598
599
600
601
602
603
            else if (isdigit(afterPattern) || afterPattern == '.')
            {
                pos_last++;
                while (isdigit(unit[pos_last]) || unit[pos_last] == '.')
                {
                    pos_last++;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
604
                }
07bf1e7c   Menouard AZIB   EveryThing works ...
605
606
607
608
            }
            else
            {
                pos_last++;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
609
610
611
612
613
            }
            positions.insert(std::pair<size_t, size_t>(pos_first, pos_last));
            pos_first = unit.find(pattern, pos_first + pattern.length());
        }
        std::map<size_t, size_t>::reverse_iterator it;
07bf1e7c   Menouard AZIB   EveryThing works ...
614
615
        for (it = positions.rbegin(); it != positions.rend(); ++it)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
616
617
618
619
620
621
622
            unit.insert(it->second, "#d");
            unit.erase(it->first, pattern.length());
            unit.insert(it->first, "#u");
        }
        return unit;
    }

fbe3c2bb   Benjamin Renard   First commit
623
} /* namespace plot */