OGS
StratScene.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "StratScene.h"
5
6#include <math.h>
7
8#include <QGraphicsTextItem>
9#include <limits>
10
12#include "BaseLib/DateTools.h"
13#include "StratBar.h"
14
16 std::map<std::string, DataHolderLib::Color>* stratColors,
17 QObject* parent)
18 : QGraphicsScene(parent)
19{
20 QRectF textBounds;
21 int stratBarOffset = 250;
22
23 QFont font("Arial", 15, QFont::DemiBold, false);
24
25 QNonScalableGraphicsTextItem* boreholeTag =
26 addNonScalableText("Borehole", font);
28 "\"" + QString::fromStdString(station->getName()) + "\"", font);
29 textBounds = boreholeTag->boundingRect();
30 boreholeTag->setPos((textBounds.width() / 2.0), 80);
31 textBounds = boreholeName->boundingRect();
32 boreholeName->setPos((textBounds.width() / 2.0), 200);
33
35 "Depth: " + QString::number(station->getDepth()) + " m");
36 textBounds = totalDepth->boundingRect();
37 totalDepth->setPos((textBounds.width() / 2.0), 350);
38 /*
39 QNonScalableGraphicsTextItem* dateText = addNonScalableText("Date: " +
40 QString::fromStdString(date2string(station->getDate()))); textBounds =
41 dateText->boundingRect(); dateText->setPos(this->MARGIN +
42 (textBounds.width()/2.0), 350);
43 */
45 dot->setPos(0, 0);
46
47 StratBar* stratBar = addStratBar(station, stratColors);
48 stratBar->setPos(stratBarOffset, MARGIN);
49 QRectF stratBarBounds = stratBar->boundingRect();
50
51 addDepthLabels(station->getProfile(),
52 stratBarOffset + stratBarBounds.width());
53
54 if (!station->getSoilNames().empty())
55 {
56 addSoilNameLabels(station->getSoilNames(), station->getProfile(),
57 stratBarOffset + (stratBarBounds.width() / 2));
58 }
59}
60
61StratScene::~StratScene() = default;
62
63void StratScene::addDepthLabels(std::vector<GeoLib::Point*> profile,
64 double offset)
65{
66 QRectF textBounds;
67 double vertPos = MARGIN;
68 std::vector<QNonScalableGraphicsTextItem*> depthText;
69 depthText.push_back(
70 addNonScalableText(QString::number((*(profile[0]))[2])));
71 textBounds = depthText[0]->boundingRect();
72 depthText[0]->setPos(offset + textBounds.width() / 2, vertPos);
73
74 for (std::size_t i = 1; i < profile.size(); i++)
75 {
76 depthText.push_back(
77 addNonScalableText(QString::number((*(profile[i]))[2])));
78 vertPos += log((*(profile[i - 1]))[2] - (*(profile[i]))[2] + 1) * 100;
79 textBounds = depthText[i]->boundingRect();
80 depthText[i]->setPos(offset + textBounds.width() / 2, vertPos);
81 }
82}
83
85 const QString& text, const QFont& font)
86{
87 auto* item = new QNonScalableGraphicsTextItem(text);
88 item->setFont(font);
89 addItem(item);
90 return item;
91}
92
93void StratScene::addSoilNameLabels(std::vector<std::string> soilNames,
94 std::vector<GeoLib::Point*>
95 profile,
96 double offset)
97{
98 // QRectF textBounds;
99 double vertPos = MARGIN;
100 double halfHeight = 0;
101 std::vector<QNonScalableGraphicsTextItem*> soilText;
102 soilText.push_back(
103 addNonScalableText(QString::fromStdString(soilNames[0])));
104 // textBounds = soilText[0]->boundingRect();
105 soilText[0]->setPos(offset /* - textBounds.width() */, vertPos);
106
107 for (std::size_t i = 1; i < soilNames.size(); i++)
108 {
109 soilText.push_back(
110 addNonScalableText(QString::fromStdString(soilNames[i])));
111 halfHeight =
112 log((*(profile[i - 1]))[2] - (*(profile[i]))[2] + 1) * 100 / 2;
113 // textBounds = soilText[i]->boundingRect();
114 soilText[i]->setPos(offset /* - textBounds.width() */,
115 vertPos + halfHeight);
116 vertPos += (2 * halfHeight);
117 }
118}
119
122 std::map<std::string, DataHolderLib::Color>* stratColors)
123{
124 auto* b = new StratBar(station, stratColors);
125 addItem(b);
126 return b;
127}
A borehole as a geometric object.
const std::vector< std::string > & getSoilNames() const
const std::vector< Point * > & getProfile() const
std::string const & getName() const
Returns the name of the station.
Definition Station.h:49
A QGraphicsTextItem that will ignore all geometric transformations.
QRectF boundingRect() const override
Returns the bounding rectangle of the text item.
A 2D bar visualisation of a borehole stratigraphy.
Definition StratBar.h:19
QRectF boundingRect() const override
Returns the bounding rectangle of the bar.
Definition StratBar.cpp:19
QNonScalableGraphicsTextItem * addNonScalableText(const QString &text, const QFont &font=QFont())
Add a non-scalable text item to the scene.
void addSoilNameLabels(std::vector< std::string > soilNames, std::vector< GeoLib::Point * > profile, double offset)
Adds text labels indicating the name of each soil layer.
StratScene(GeoLib::StationBorehole *station, std::map< std::string, DataHolderLib::Color > *stratColors=nullptr, QObject *parent=nullptr)
Constructor.
~StratScene() override
void addDepthLabels(std::vector< GeoLib::Point * > profile, double offset)
Adds text labels indicating the depth at the beginning and end of each soil layer.
static const int MARGIN
The margin between the boundary of the scene and the bounding box of all items within the scene.
Definition StratScene.h:28
StratBar * addStratBar(GeoLib::StationBorehole *station, std::map< std::string, DataHolderLib::Color > *stratColors=nullptr)
Add a stratigraphy-bar to the scene.