1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
|
/* Copyright (c) 2020, Dyssol Development Team.
* Copyright (c) 2023, DyssolTEC GmbH.
* All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */
#pragma once
#include "DyssolTypes.h"
#include <memory>
#include <vector>
class CH5Handler;
////////////////////////////////////////////////////////////////////////////////
// CCurve
//
/**
* \brief Curve on the plot.
*/
class CCurve
{
static const unsigned m_saveVersion{ 1 }; ///< Current version of the saving procedure.
std::string m_name; ///< Name of the curve.
double m_valueZ{}; ///< Value of Z axis for which this curve is defined.
std::vector<CPoint> m_values; ///< Values stored in the curve.
public:
/**
* \private
* \brief Constructor.
* \param _name Name of the curve.
*/
CCurve(std::string _name);
/**
* \private
* \brief Constructor.
* \param _z Z-value of the curve.
*/
CCurve(double _z);
/**
* \brief Returns the name of the curve.
* \return Curve's name.
*/
std::string GetName() const;
/**
* \brief Sets new name of the curve.
* \param _name Curve's name.
*/
void SetName(const std::string& _name);
/**
* \brief Returns the value of Z axis for which this curve is defined.
* \return Z-value of the curve.
*/
double GetZValue() const;
/**
* \brief Sets a new value of Z axis for which this curve is defined.
* \param _z Z-value of the curve.
*/
void SetZValue(double _z);
/**
* \brief Adds a new point to the curve.
* \param _x X-value of the point.
* \param _y Y-value of the point.
*/
void AddPoint(double _x, double _y);
/**
* \brief Adds a new point to the curve.
* \param _point New point.
*/
void AddPoint(const CPoint& _point);
/**
* \brief Adds new points to the curve.
* \details Vectors must have the same length.
* \param _x X-values of the points.
* \param _y Y-values of the points.
*/
void AddPoints(const std::vector<double>& _x, const std::vector<double>& _y);
/**
* \brief Adds new points to the curve.
* \param _points New points.
*/
void AddPoints(const std::vector<CPoint>& _points);
/**
* \brief Returns X values of all points defined in the curve.
* \return X-values of all points.
*/
std::vector<double> GetXValues() const;
/**
* \brief Returns Y values of all points defined in the curve.
* \return Y-values of all points.
*/
std::vector<double> GetYValues() const;
/**
* \brief Returns all points defined in the curve.
* \return All points.
*/
std::vector<CPoint> GetPoints() const;
/**
* \brief Removes an existing point from the curve.
* \details If the point does not exist, does nothing.
* \param _x X-value of the point.
*/
void RemovePoint(double _x);
/**
* \brief Removes all defined points from the curve.
*/
void ClearData();
/**
* \brief Removes all data from the curve.
*/
void Clear();
/**
* \private
* \brief Saves data to file.
* \param _h5File Reference to the file handler.
* \param _path Path to data in the file.
*/
void SaveToFile(CH5Handler& _h5File, const std::string& _path) const;
/**
* \private
* \brief Loads data from file.
* \param _h5File Reference to the file handler.
* \param _path Path to data in the file.
*/
void LoadFromFile(CH5Handler& _h5File, const std::string& _path);
};
////////////////////////////////////////////////////////////////////////////////
// CPlot
//
/**
* \brief Plot in the unit.
*/
class CPlot
{
static const unsigned m_saveVersion{ 1 }; ///< Current version of the saving procedure.
protected:
std::string m_name; ///< Name of the plot.
std::string m_labelX; ///< Label of the X axis.
std::string m_labelY; ///< Label of the Y axis.
std::string m_labelZ; ///< Label of the Z axis.
std::vector<std::unique_ptr<CCurve>> m_curves; ///< Curves in this plot.
public:
/**
* \private
* \brief Constructor.
* \param _name Name of the plot.
*/
CPlot(std::string _name);
/**
* \private
* \brief Constructor.
* \param _name Name of the plot.
* \param _labelX Name of X label.
* \param _labelY Name of Y label.
*/
CPlot(std::string _name, std::string _labelX, std::string _labelY);
/**
* \private
* \brief Constructor.
* \param _name Name of the plot.
* \param _labelX Name of X label.
* \param _labelY Name of Y label.
* \param _labelZ Name of Z label.
*/
CPlot(std::string _name, std::string _labelX, std::string _labelY, std::string _labelZ);
/**
* \private
* \brief Destructor.
*/
~CPlot() = default;
/**
* \private
* \brief Copy constructor.
* \param _other Target plot.
*/
CPlot(const CPlot& _other);
/**
* \private
* \brief Move constructor.
* \param _other Target plot.
*/
CPlot(CPlot&& _other) = default;
/**
* \private
* \brief Copy assignment operator.
* \param _other Target plot.
* \return Reference to the plot.
*/
CPlot& operator=(const CPlot& _other);
/**
* \private
* \brief Move assignment operator.
* \param _other Target plot.
* \return Reference to the plot.
*/
CPlot& operator=(CPlot&& _other) = default;
/**
* \brief Returns the name of the plot.
* \return Plot's name.
*/
std::string GetName() const;
/**
* \brief Sets new name of the plot.
* \param _name Plot's name.
*/
void SetName(const std::string& _name);
/**
* \brief Returns a label of the X axis.
* \return X label of the plot.
*/
std::string GetLabelX() const;
/**
* \brief Returns a label of the Y axis.
* \return Y label of the plot.
*/
std::string GetLabelY() const;
/**
* \brief Returns a label of the Z axis.
* \return Z label of the plot.
*/
std::string GetLabelZ() const;
/**
* \brief Sets a label of the X axis.
* \param _label X label of the plot.
*/
void SetLabelX(const std::string& _label);
/**
* \brief Sets a label of the Y axis.
* \param _label Y label of the plot.
*/
void SetLabelY(const std::string& _label);
/**
* \brief Sets a label of the Z axis.
* \param _label Z label of the plot.
*/
void SetLabelZ(const std::string& _label);
/**
* \brief Sets labels of all axes.
* \param _labelX X label of the plot.
* \param _labelY Y label of the plot.
*/
void SetLabels(const std::string& _labelX, const std::string& _labelY);
/**
* \brief Sets labels of all axes.
* \param _labelX X label of the plot.
* \param _labelY Y label of the plot.
* \param _labelZ Z label of the plot.
*/
void SetLabels(const std::string& _labelX, const std::string& _labelY, const std::string& _labelZ);
/**
* \brief Adds a new curve with the specified name to the plot.
* \details If a curve with the given name already exists, does nothing, and returns nullptr.
* \param _name Plot's name.
* \return Pointer to the added curve.
*/
CCurve* AddCurve(const std::string& _name);
/**
* \brief Adds a new curve with the specified name to the plot and fills it with the given values.
* \details X and Y must have the same length. If a curve with the given name already exists, does nothing, and returns nullptr.
* \param _name Plot's name.
* \param _x X-values of the points.
* \param _y Y-values of the points.
* \return Pointer to the added curve.
*/
CCurve* AddCurve(const std::string& _name, const std::vector<double>& _x, const std::vector<double>& _y);
/**
* \brief Adds a new curve with the specified name to the plot and fills it with the given values.
* \details If a curve with the given name already exists, does nothing, and returns nullptr.
* \param _name Plot's name.
* \param _points Points on the curve.
* \return Pointer to the added curve.
*/
CCurve* AddCurve(const std::string& _name, const std::vector<CPoint>& _points);
/**
* \brief Adds several curves with the specified names to the plot.
* \details If any curve with the given name value already exists, does nothing, and returns empty vector.
* \param _names Names of the curves.
* \return Pointers to the added curves.
*/
std::vector<CCurve*> AddCurves(const std::vector<std::string>& _names);
/**
* \brief Adds a new curve with the specified Z value to the plot.
* \details If a curve with the given Z value already exists, does nothing, and returns nullptr.
* \param _z Z-value of the curve.
* \return Pointer to the added curve.
*/
CCurve* AddCurve(double _z);
/**
* \brief Adds a new curve with the specified Z value to the plot and fills it with the given values.
* \details X and Y must have the same length. If a curve with the given Z value already exists, does nothing, and returns nullptr.
* \param _z Z-value of the curve.
* \param _x X-values of the points.
* \param _y Y-values of the points.
* \return Pointer to the added curve.
*/
CCurve* AddCurve(double _z, const std::vector<double>& _x, const std::vector<double>& _y);
/**
* \brief Adds a new curve with the specified Z value to the plot and fills it with the given values.
* \details If a curve with the given Z value already exists, does nothing, and returns nullptr.
* \param _z Z-value of the curve.
* \param _points New points.
* \return Pointer to the added curve.
*/
CCurve* AddCurve(double _z, const std::vector<CPoint>& _points);
/**
* \brief Adds several curves with the specified Z values to the plot.
* \details If any curve with the given Z value already exists, does nothing, and returns empty vector.
* \param _z Z-values of the curves.
* \return Pointers to the added curves.
*/
std::vector<CCurve*> AddCurves(const std::vector<double>& _z);
/**
* \brief Returns a curve with the specified index.
* \param _index Index of the curve.
* \return Const pointer to the curve.
*/
const CCurve* GetCurve(size_t _index) const;
/**
* \brief Returns a curve with the specified index.
* \param _index Index of the curve.
* \return Pointer to the curve.
*/
CCurve* GetCurve(size_t _index);
/**
* \brief Returns a curve with the specified name.
* \param _name Name of the curve.
* \return Const pointer to the curve.
*/
const CCurve* GetCurve(const std::string& _name) const;
/**
* \brief Returns a curve with the specified name.
* \param _name Name of the curve.
* \return Pointer to the curve.
*/
CCurve* GetCurve(const std::string& _name);
/**
* \brief Returns a curve with the specified Z value.
* \param _z Z-value of the curve.
* \return Const pointer to the curve.
*/
const CCurve* GetCurve(double _z) const;
/**
* \brief Returns a curve with the specified Z value.
* \param _z Z-value of the curve.
* \return Pointer to the curve.
*/
CCurve* GetCurve(double _z);
/**
* \brief Removes a curve with the specified name from the plot.
* \param _name Name of the curve.
*/
void RemoveCurve(const std::string& _name);
/**
* \brief Removes a curve with the specified Z value from the plot.
* \param _z Z-value of the curve.
*/
void RemoveCurve(double _z);
/**
* \brief Returns all curves defined in the plot.
* \return Const pointers to the curves.
*/
std::vector<const CCurve*> GetAllCurves() const;
/**
* \brief Returns all curves defined in the plot.
* \return Pointers to the curves.
*/
std::vector<CCurve*> GetAllCurves();
/**
* \brief Returns Z values of all defined curves.
* \return Z values of the curves.
*/
std::vector<double> GetZValues() const;
/**
* \brief Checks if the plot is a 2D plot, based on the presence of Z values.
* \return Whether the curve is 2D.
*/
bool Is2D() const;
/**
* \brief Returns a number of defined curves.
* \return Number of curves.
*/
size_t GetCurvesNumber() const;
/**
* \brief Removes all defined curves from the plot.
*/
void ClearData();
/**
* \brief Removes all data from the plot.
*/
void Clear();
/**
* \private
* \brief Saves data to file.
* \param _h5File Reference to the file handler.
* \param _path Path to data.
*/
void SaveToFile(CH5Handler& _h5File, const std::string& _path) const;
/**
* \private
* \brief Loads data from file.
* \param _h5File Reference to the file handler.
* \param _path Path to data.
*/
void LoadFromFile(CH5Handler& _h5File, const std::string& _path);
private:
/**
* \brief Tries to add a new curve with the specified Z value to the plot, without setting any data, omitting name clashes.
* \details Returns nullptr on failure.
*/
CCurve* AddEmptyCurve(double _z);
};
////////////////////////////////////////////////////////////////////////////////
// CPlotManager
//
/**
* \brief Plot manager to access all plots and curves on them.
*/
class CPlotManager
{
static constexpr unsigned m_saveVersion{ 1 }; ///< Current version of the saving procedure.
std::vector<std::unique_ptr<CPlot>> m_plots; ///< Plots.
std::vector<std::unique_ptr<CPlot>> m_plotsStored; ///< A copy of plots used to store data during cyclic recalculations.
public:
/**
* \private
* \brief Default constructor.
*/
CPlotManager() = default;
/**
* \private
* \brief Copy constructor.
*/
CPlotManager(const CPlotManager& _other);
/**
* \private
* \brief Move constructor.
*/
CPlotManager(CPlotManager&& _other) noexcept;
/**
* \private
* \brief Copy assignment operator.
*/
CPlotManager& operator=(CPlotManager _other);
/**
* \private
* \brief Move assignment operator.
*/
CPlotManager& operator=(CPlotManager&& _other) noexcept;
/**
* \private
* \brief Destructor.
*/
~CPlotManager() = default;
/**
* \brief Swaps the content of two managers.
* \param _first First manager.
* \param _second Second manager.
*/
friend void swap(CPlotManager& _first, CPlotManager& _second) noexcept;
/**
* \brief Adds a new 2D plot with the specified name.
* \details If a plot with the given name already exists, does nothing, and returns nullptr.
* \param _name Plot name.
* \return Pointer to the added plot.
*/
CPlot* AddPlot(const std::string& _name);
/**
* \brief Adds a new 2D plot with the specified name and axes labels.
* \details If a plot with the given name already exists, does nothing, and returns nullptr.
* \param _name Plot name.
* \param _labelX X label of the plot.
* \param _labelY Y label of the plot.
* \return Pointer to the added plot.
*/
CPlot* AddPlot(const std::string& _name, const std::string& _labelX, const std::string& _labelY);
/**
* \brief Adds a new 3D plot with the specified name and axes labels.
* \details If a plot with the given name already exists, does nothing, and returns nullptr.
* \param _name Plot name.
* \param _labelX X label of the plot.
* \param _labelY Y label of the plot.
* \param _labelZ Z label of the plot.
* \return Pointer to the added plot.
*/
CPlot* AddPlot(const std::string& _name, const std::string& _labelX, const std::string& _labelY, const std::string& _labelZ);
/**
* \brief Returns a 2D plot with the specified index.
* \param _index Index of the plot.
* \return Const pointer to the plot.
*/
const CPlot* GetPlot(size_t _index) const;
/**
* \brief Returns a 2D plot with the specified index.
* \param _index Index of the plot.
* \return Pointer to the plot.
*/
CPlot* GetPlot(size_t _index);
/**
* \brief Returns a 2D plot with the specified name.
* \param _name Plot name.
* \return Const pointer to the plot.
*/
const CPlot* GetPlot(const std::string& _name) const;
/**
* \brief Returns a 2D plot with the specified name.
* \param _name Plot name.
* \return Pointer to the plot.
*/
CPlot* GetPlot(const std::string& _name);
/**
* \private
* \brief Removes a 2D plot with the specified name.
* \param _name Plot name.
*/
void RemovePlot(const std::string& _name);
/**
* \brief Returns all defined 2D plots.
* \return Const pointers to all plots.
*/
std::vector<const CPlot*> GetAllPlots() const;
/**
* \brief Returns all defined 2D plots.
* \return Pointers to all plots.
*/
std::vector<CPlot*> GetAllPlots();
/**
* \brief Returns a number of defined plots.
* \return Number of all plots.
*/
size_t GetPlotsNumber() const;
/**
* \private
* \brief Removes all defined plots.
*/
void ClearData();
/**
* \private
* \brief Removes all data.
*/
void Clear();
/**
* \private
* \brief Stores the current state of all plots.
*/
void SaveState();
/**
* \private
* \brief Restores previously stored state of all plots.
*/
void LoadState();
/**
* \private
* \brief Saves data to file.
* \param _h5File Reference to the file handler.
* \param _path Path to data.
*/
void SaveToFile(CH5Handler& _h5File, const std::string& _path) const;
/**
* \private
* \brief Loads data from file.
* \param _h5File Reference to the file handler.
* \param _path Path to data.
*/
void LoadFromFile(CH5Handler& _h5File, const std::string& _path);
/**
* \private
* \brief Loads data from file.
* \details A compatibility version.
* \param _h5File Reference to the file handler.
* \param _path Path to data.
*/
void LoadFromFile_v0(const CH5Handler& _h5File, const std::string& _path);
};
|