Skip to content

Commit

Permalink
Merge commit 'f90e444cf09c62968bef515bfbe5678be8149925'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Aug 6, 2024
2 parents b7d33a2 + f90e444 commit fe18807
Show file tree
Hide file tree
Showing 47 changed files with 852 additions and 724 deletions.
79 changes: 61 additions & 18 deletions agrolib/commonChartElements/dialogChangeAxis.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,57 @@
#include "dialogChangeAxis.h"

DialogChangeAxis::DialogChangeAxis(bool isLeftAxis_)
DialogChangeAxis::DialogChangeAxis(int nrAxis, bool isDate_)
{
isLeftAxis = isLeftAxis_;
isDateAxis = isDate_;

QString title;
if (isLeftAxis)
if (nrAxis == 0)
{
title = "Change X Axis";
}
else if (nrAxis == 1)
{
title = "Change Left Axis";
}
else
else if (nrAxis == 2)
{
title = "Change Right Axis";
}
this->setWindowTitle(title);

QVBoxLayout* mainLayout = new QVBoxLayout;
this->resize(200, 100);

QHBoxLayout *layoutOk = new QHBoxLayout;
QHBoxLayout *layoutEdit = new QHBoxLayout;

QLabel minValueLabel("Minimum value:");
minValueLabel.setBuddy(&minVal);
minVal.setValidator(new QDoubleValidator(-999.0, 999.0, 3));
layoutEdit->addWidget(&minValueLabel);
if (isDateAxis)
{
minValueLabel.setBuddy(&minDate);
layoutEdit->addWidget(&minDate);
}
else
{
minValueLabel.setBuddy(&minVal);
minVal.setValidator(new QDoubleValidator(-9999.0, 9999.0, 3));
layoutEdit->addWidget(&minVal);
}

QLabel maxValueLabel("Maximum value:");
maxValueLabel.setBuddy(&maxVal);
maxVal.setValidator(new QDoubleValidator(-999.0, 999.0, 3));

layoutEdit->addWidget(&minValueLabel);
layoutEdit->addWidget(&minVal);
layoutEdit->addWidget(&maxValueLabel);
layoutEdit->addWidget(&maxVal);
if (isDateAxis)
{
minValueLabel.setBuddy(&maxDate);
layoutEdit->addWidget(&maxDate);
}
else
{
maxValueLabel.setBuddy(&maxVal);
maxVal.setValidator(new QDoubleValidator(-9999.0, 9999.0, 3));
layoutEdit->addWidget(&maxVal);
}

QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);

Expand All @@ -55,16 +76,28 @@ void DialogChangeAxis::done(bool res)
{
if (res) // ok
{
if (minVal.text().isEmpty())
if (isDateAxis)
{
QMessageBox::information(nullptr, "Missing min value", "Insert min val");
return;
if (minDate.date() >= maxDate.date())
{
QMessageBox::warning(nullptr, "Wrong dates!", "Insert correct dates.");
return;
}
}
if (maxVal.text().isEmpty())
else
{
QMessageBox::information(nullptr, "Missing max value", "Insert max val");
return;
if (minVal.text().isEmpty())
{
QMessageBox::warning(nullptr, "Missing min value", "Insert minimum value.");
return;
}
if (maxVal.text().isEmpty())
{
QMessageBox::warning(nullptr, "Missing max value", "Insert maximum value.");
return;
}
}

QDialog::done(QDialog::Accepted);
return;
}
Expand All @@ -84,3 +117,13 @@ float DialogChangeAxis::getMaxVal() const
{
return maxVal.text().toFloat();
}

QDate DialogChangeAxis::getMinDate() const
{
return minDate.date();
}

QDate DialogChangeAxis::getMaxDate() const
{
return maxDate.date();
}
12 changes: 10 additions & 2 deletions agrolib/commonChartElements/dialogChangeAxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@
Q_OBJECT

private:
bool isLeftAxis;
bool isDateAxis;

QDateEdit minDate;
QLineEdit minVal;

QDateEdit maxDate;
QLineEdit maxVal;

public:
DialogChangeAxis(bool isLeftAxis);
DialogChangeAxis(int nrAxis, bool isDate_);
~DialogChangeAxis() override;
void done(bool res);

float getMinVal() const;
float getMaxVal() const;

QDate getMinDate() const;
QDate getMaxDate() const;
};

#endif // DIALOGCHANGEAXIS_H
2 changes: 1 addition & 1 deletion agrolib/crop/crop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Crit3DCrop::Crit3DCrop()
void Crit3DCrop::clear()
{
idCrop = "";
type = HERBACEOUS_ANNUAL;
type = BARESOIL;

roots.clear();

Expand Down
10 changes: 0 additions & 10 deletions agrolib/crop/landUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,3 @@ bool loadLandUnitList(const QSqlDatabase &dbCrop, std::vector<Crit3DLandUnit> &l

return true;
}


int getLandUnitIndex(const std::vector<Crit3DLandUnit> &landUnitList, int idLandUnit)
{
for (int index = 0; index < int(landUnitList.size()); index++)
if (landUnitList[index].id == idLandUnit)
return index;

return NODATA;
}
2 changes: 0 additions & 2 deletions agrolib/crop/landUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@

bool loadLandUnitList(const QSqlDatabase &dbCrop, std::vector<Crit3DLandUnit> &landUnitList, QString &errorStr);

int getLandUnitIndex(const std::vector<Crit3DLandUnit> &landUnitList, int idLandUnit);


#endif // LANDUNIT_H
2 changes: 1 addition & 1 deletion agrolib/dbMeteoGrid/dbMeteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2501,7 +2501,7 @@ std::vector<float> Crit3DMeteoGridDbHandler::loadGridDailyVar(QString *errorStr,

// read last date
qry.last();
if (!getValue(qry.value(_tableDaily.fieldTime), &lastDateDB))
if (! getValue(qry.value(_tableDaily.fieldTime), &lastDateDB))
{
*errorStr = "Missing last date";
return dailyVarList;
Expand Down
1 change: 0 additions & 1 deletion agrolib/dbMeteoPoints/dbAggregationsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ bool Crit3DAggregationsDbHandler::writePointProperties(int numZones, QString agg

QSqlQuery qry(_db);
for (int i = 1; i <= numZones; i++)

{
QString id = QString::number(i) + "_" + aggrType;
QString name = id;
Expand Down
93 changes: 18 additions & 75 deletions agrolib/gis/gis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,26 +287,26 @@ namespace gis

bool Crit3DRasterGrid::initializeParameters(const Crit3DRasterHeader& initHeader)
{
parametersCell.clear();
parametersCell.resize(initHeader.nrRows*initHeader.nrCols);
for (int i = 0; i < int(parametersCell.size()); i++)
singleCell.clear();
singleCell.resize(initHeader.nrRows*initHeader.nrCols);
for (int i = 0; i < int(singleCell.size()); i++)
{
parametersCell[i].row = i / initHeader.nrCols;
parametersCell[i].col = i % initHeader.nrCols;
parametersCell[i].fittingParameters.clear();
singleCell[i].row = i / initHeader.nrCols;
singleCell[i].col = i % initHeader.nrCols;
singleCell[i].fittingParameters.clear();
}

return true;
}

bool Crit3DRasterGrid::initializeParametersLatLonHeader(const Crit3DLatLonHeader& latLonHeader)
{
parametersCell.resize(latLonHeader.nrRows*latLonHeader.nrCols);
for (int i = 0; i < int(parametersCell.size()); i++)
singleCell.resize(latLonHeader.nrRows*latLonHeader.nrCols);
for (int i = 0; i < int(singleCell.size()); i++)
{
parametersCell[i].row = i / latLonHeader.nrCols;
parametersCell[i].col = i % latLonHeader.nrCols;
parametersCell[i].fittingParameters.clear();
singleCell[i].row = i / latLonHeader.nrCols;
singleCell[i].col = i % latLonHeader.nrCols;
singleCell[i].fittingParameters.clear();
}

return true;
Expand Down Expand Up @@ -497,8 +497,8 @@ namespace gis

int index = row * header->nrCols + col;

if (index < int(parametersCell.size()))
parameters = parametersCell[index].fittingParameters;
if (index < int(singleCell.size()))
parameters = singleCell[index].fittingParameters;

return parameters;

Expand All @@ -511,7 +511,7 @@ namespace gis
return false;

int index = row * header->nrCols + col;
parametersCell[index].fittingParameters = parameters;
singleCell[index].fittingParameters = parameters;

return true;
}
Expand Down Expand Up @@ -542,7 +542,7 @@ namespace gis
for (m = col-1; m < col+2; m++)
{
index = l * header->nrCols + m;
if (index >= 0 && index < int(parametersCell.size()) && (parametersCell[index].fittingParameters.size() > i && !parametersCell[index].fittingParameters[i].empty()) && (l != row || m !=col)) {
if (index >= 0 && index < int(singleCell.size()) && (singleCell[index].fittingParameters.size() > i && !singleCell[index].fittingParameters[i].empty()) && (l != row || m !=col)) {
findFirst = 1;
}
if (findFirst==1) break;
Expand All @@ -555,18 +555,18 @@ namespace gis

//you're on a specific proxy rn. cycle through the cells, calculate the avg
avg.clear();
avg.resize(parametersCell[index].fittingParameters[i].size());
avg.resize(singleCell[index].fittingParameters[i].size());
counter = 0;

for (k = l; k < row+2; k++)
{
for (p = m; p < col+2; p++)
{
index = k * header->nrCols + p;
if (index >= 0 && index < int(parametersCell.size()) && parametersCell[index].fittingParameters.size() > i && !parametersCell[index].fittingParameters[i].empty()) {
if (index >= 0 && index < int(singleCell.size()) && singleCell[index].fittingParameters.size() > i && !singleCell[index].fittingParameters[i].empty()) {
for (unsigned int o = 0; o < avg.size(); o++)
{
avg[o] += parametersCell[index].fittingParameters[i][o];
avg[o] += singleCell[index].fittingParameters[i][o];

}
counter++;
Expand All @@ -583,63 +583,6 @@ namespace gis
return tempProxyVector;
}

std::vector<std::vector<double>> Crit3DRasterGrid::prepareParametersOld(int row, int col, unsigned int activeProxyNr)
{
std::vector<std::vector<double>> tempProxyVector;
std::vector<double> tempParVector;
tempProxyVector.clear();
tempParVector.clear();
double avg;
int counter;
int l, i, j, k;
int index;
bool findFirst = 0;

if (isOutOfGrid(row, col))
return tempProxyVector;

//look for the first cell that has data in it. if there isn't any, return empty vector
for (i = row-1; i < row+2; i++)
{
for (j = col-1; j < col+2; j++)
{
index = i * header->nrCols + j;
if (index >= 0 && index < int(parametersCell.size()) && (parametersCell[index].fittingParameters.size() == activeProxyNr) && (i != row || j !=col))
findFirst = 1;
if (findFirst==1) break;
}
if (findFirst==1) break;
}

for (k = 0; k < int(parametersCell[index].fittingParameters.size()); k++)
{
for (l = 0; l < int(parametersCell[index].fittingParameters[k].size()); l++)
{
avg = 0;
counter = 0;
for (int h = i; h < row+2; h++)
{
for (int m = j; m < col+2; m++)
{
index = h * header->nrCols + m;
if (index >= 0 && index < int(parametersCell.size()) && (parametersCell[index].fittingParameters.size() == activeProxyNr) && (i != row || j !=col))
{
avg += parametersCell[index].fittingParameters[k][l];
counter++;
}
}
}
tempParVector.push_back(avg/counter);
index = i*header->nrCols+j;
}
tempProxyVector.push_back(tempParVector);
tempParVector.clear();
}

return tempProxyVector;

}

void convertFlagToNodata(Crit3DRasterGrid& myGrid)
{
if (myGrid.header->flag == NODATA)
Expand Down
9 changes: 4 additions & 5 deletions agrolib/gis/gis.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
Crit3DRasterCell();
};

struct RasterGridParameters {
struct RasterGridCell {
public:
int row;
int col;
Expand All @@ -155,7 +155,7 @@
float minimum, maximum;
bool isLoaded;
Crit3DTime mapTime;
std::vector<RasterGridParameters> parametersCell;
std::vector<RasterGridCell> singleCell;

Crit3DUtmPoint* utmPoint(int myRow, int myCol);
void getXY(int myRow, int myCol, double &x, double &y) const;
Expand Down Expand Up @@ -192,7 +192,6 @@
std::vector<std::vector<double>> getParametersFromRowCol(int row, int col);
bool setParametersForRowCol(int row, int col, std::vector<std::vector<double>> parameters);
std::vector<std::vector<double>> prepareParameters(int row, int col, std::vector<bool> activeList);
std::vector<std::vector<double>> prepareParametersOld(int row, int col, unsigned int activeProxyNr);

Crit3DTime getMapTime() const;
void setMapTime(const Crit3DTime &value);
Expand Down Expand Up @@ -255,8 +254,8 @@

bool openRaster(std::string fileName, Crit3DRasterGrid *rasterGrid, int currentUtmZone, std::string &errorStr);

bool readEsriGrid(std::string fileName, Crit3DRasterGrid* rasterGrid, std::string &errorStr);
bool writeEsriGrid(std::string fileName, Crit3DRasterGrid *rasterGrid, std::string &errorStr);
bool readEsriGrid(const std::string &fileName, Crit3DRasterGrid* rasterGrid, std::string &errorStr);
bool writeEsriGrid(const std::string &fileName, Crit3DRasterGrid *rasterGrid, std::string &errorStr);

bool readEnviGrid(std::string fileName, Crit3DRasterGrid* rasterGrid, int currentUtmZone, std::string &errorStr);
bool writeEnviGrid(std::string fileName, int utmZone, Crit3DRasterGrid *rasterGrid, std::string &errorStr);
Expand Down
Loading

0 comments on commit fe18807

Please sign in to comment.