Skip to content

Commit

Permalink
Merge commit '029f60432410f71a0a6b3a2dd84188ecd1defbdc'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Feb 5, 2025
2 parents fa6bb4c + 029f604 commit ba704e4
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 70 deletions.
19 changes: 2 additions & 17 deletions criteria1DWidget/criteria1DWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1580,30 +1580,15 @@ void Criteria1DWidget::on_actionChooseSoil(QString soilCode)
if (soilCode.isEmpty())
return;

QString errorStr;
myProject.myCase.mySoil.cleanSoil();

if (! loadSoil(myProject.dbSoil, soilCode, myProject.myCase.mySoil, myProject.texturalClassList,
myProject.geotechnicsClassList, myProject.myCase.fittingOptions, errorStr))
QString errorStr;
if (! myProject.setSoil(soilCode, errorStr))
{
QMessageBox::critical(nullptr, "Error!", errorStr);
return;
}

// warning: some soil data are wrong
if (errorStr != "")
{
QMessageBox::information(nullptr, "SOIL Warning", errorStr);
errorStr = "";
}

std::string errorStdString;
if (! myProject.myCase.initializeSoil(errorStdString))
{
QMessageBox::critical(nullptr, "Error!", QString::fromStdString(errorStdString));
return;
}

if (tabWidget->currentIndex() != 0)
{
if (isRedraw) on_actionUpdate();
Expand Down
20 changes: 14 additions & 6 deletions criteriaModel/criteria1DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ void Crit1DProject::initialize()
outputCsvFileName = "";
addDateTimeLogFile = false;

computeAllSoilDepth = true;
computationSoilDepth = NODATA;

dbCropName = "";
dbSoilName = "";
dbMeteoName = "";
Expand Down Expand Up @@ -195,10 +198,11 @@ bool Crit1DProject::readSettings()

// SETTINGS
projectSettings->beginGroup("settings");
addDateTimeLogFile = projectSettings->value("add_date_to_log","").toBool();

// TODO computation depth
addDateTimeLogFile = projectSettings->value("add_date_to_log", false).toBool();

// soil computation depth
computeAllSoilDepth = projectSettings->value("compute_all_soil_depth", true).toBool();
computationSoilDepth = projectSettings->value("computationDepth", NODATA).toDouble();
projectSettings->endGroup();

// FORECAST
Expand Down Expand Up @@ -483,11 +487,14 @@ bool Crit1DProject::setSoil(QString soilCode, QString &errorStr)
if (! loadSoil(dbSoil, soilCode, myCase.mySoil, texturalClassList, geotechnicsClassList, myCase.fittingOptions, errorStr))
return false;

// warning: some soil data are wrong
// cancel warnings (some soil data are wrong)
if (errorStr != "")
{
//logger.writeInfo("WARNING: " + errorStr);
errorStr = "";

// check soil depth (if fixed depth is required)
if (! computeAllSoilDepth)
{
myCase.mySoil.totalDepth = std::min(myCase.mySoil.totalDepth, computationSoilDepth);
}

std::string errorStdString;
Expand Down Expand Up @@ -2034,6 +2041,7 @@ QString getOutputStringNullZero(double value)
}


// variableDepth [cm] (integer numbers)
bool setVariableDepth(const QList<QString>& depthList, std::vector<int>& variableDepth)
{
int nrDepth = depthList.size();
Expand Down
27 changes: 15 additions & 12 deletions criteriaModel/criteria1DProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@

void initialize();
int initializeProject(QString settingsFileName);

int computeAllUnits();
bool computeUnit(const Crit1DCompUnit& myUnit);

bool setSoil(QString soilCode, QString &errorStr);

private:
QString projectName;
QString configFileName;
Expand All @@ -79,25 +82,27 @@
int firstMonth;
int daysOfForecast;
int nrYears;
std::vector<float> irriSeries;
std::vector<float> precSeries;
std::vector<float> irriSeries; // [mm]
std::vector<float> precSeries; // [mm]

QString outputString;
QString outputCsvFileName;
std::ofstream outputCsvFile;

bool addDateTimeLogFile;
bool computeAllSoilDepth;
double computationSoilDepth; // [m]

// specific output
bool isClimateOutput;
std::vector<int> waterContentDepth;
std::vector<int> degreeOfSaturationDepth;
std::vector<int> waterPotentialDepth;
std::vector<int> waterDeficitDepth;
std::vector<int> awcDepth;
std::vector<int> availableWaterDepth;
std::vector<int> fractionAvailableWaterDepth;
std::vector<int> factorOfSafetyDepth;
std::vector<int> waterContentDepth; // [cm]
std::vector<int> degreeOfSaturationDepth; // [cm]
std::vector<int> waterPotentialDepth; // [cm]
std::vector<int> waterDeficitDepth; // [cm]
std::vector<int> awcDepth; // [cm]
std::vector<int> availableWaterDepth; // [cm]
std::vector<int> fractionAvailableWaterDepth; // [cm]
std::vector<int> factorOfSafetyDepth; // [cm]

// DATABASE
QSqlDatabase dbForecast;
Expand All @@ -112,8 +117,6 @@
int openAllDatabase();
void checkSimulationDates();

bool setSoil(QString soilCode, QString &errorStr);

bool setMeteoSqlite(QString idMeteo, QString idForecast);
bool setMeteoXmlGrid(QString idMeteo, QString idForecast, unsigned int memberNr);

Expand Down
2 changes: 1 addition & 1 deletion criteriaModel/water1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ double assignOptimalIrrigation(std::vector<soil::Crit1DLayer> &soilLayers, unsig
* \brief getSoilWaterContentSum
* \param soilLayers
* \param computationDepth = computation soil depth [cm]
* \return sum of water content from zero to computationSoilDepth [mm]
* \return sum of water content from zero to computationDepth [mm]
*/
double getSoilWaterContentSum(const std::vector<soil::Crit1DLayer> &soilLayers, double computationDepth)
{
Expand Down
8 changes: 2 additions & 6 deletions soil/soil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ namespace soil
this->CEC = NODATA;
}

Crit3DSoil::Crit3DSoil()
{
this->cleanSoil();
}

void Crit3DSoil::initialize(const std::string &soilCode, int nrHorizons)
{
Expand All @@ -180,8 +176,8 @@ namespace soil

void Crit3DSoil::addHorizon(int nHorizon, const Crit3DHorizon &newHorizon)
{
horizon.insert(horizon.begin() + nHorizon, newHorizon);
nrHorizons = nrHorizons + 1;
this->horizon.insert(this->horizon.begin() + nHorizon, newHorizon);
this->nrHorizons++;
}

void Crit3DSoil::deleteHorizon(int nHorizon)
Expand Down
5 changes: 3 additions & 2 deletions soil/soil.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@
std::string code;
std::string name;
unsigned int nrHorizons;
double totalDepth; /*!< [m] */
double totalDepth; /*!< [m] */

std::vector <Crit3DHorizon> horizon;

Crit3DSoil();
Crit3DSoil() { this->cleanSoil(); }

void initialize(const std::string &soilCode, int nrHorizons);
void cleanSoil();
Expand Down
13 changes: 7 additions & 6 deletions soil/soilDbTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,12 @@ bool loadSoil(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DS
const std::vector<soil::Crit3DGeotechnicsClass> &geotechnicsClassList,
const soil::Crit3DFittingOptions &fittingOptions, QString& errorStr)
{
if (!loadSoilInfo(dbSoil, soilCode, mySoil, errorStr))
if (! loadSoilInfo(dbSoil, soilCode, mySoil, errorStr))
{
return false;
}
if (!loadSoilData(dbSoil, soilCode, mySoil, errorStr))

if (! loadSoilData(dbSoil, soilCode, mySoil, errorStr))
{
return false;
}
Expand Down Expand Up @@ -558,7 +559,7 @@ bool updateSoilData(const QSqlDatabase &dbSoil, const QString &soilCode, soil::C
}


bool updateWaterRetentionData(QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DSoil &mySoil, int horizon, QString &errorStr)
bool updateWaterRetentionData(QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DSoil &mySoil, int horizonNr, QString &errorStr)
{
QSqlQuery qry(dbSoil);
if (soilCode.isEmpty())
Expand All @@ -570,7 +571,7 @@ bool updateWaterRetentionData(QSqlDatabase &dbSoil, const QString &soilCode, soi
// delete all row from table horizons of soil:soilCode
qry.prepare( "DELETE FROM water_retention WHERE soil_code = :soil_code AND horizon_nr = :horizon_nr");
qry.bindValue(":soil_code", soilCode);
qry.bindValue(":horizon_nr", horizon);
qry.bindValue(":horizon_nr", horizonNr);

if( !qry.exec() )
{
Expand All @@ -587,11 +588,11 @@ bool updateWaterRetentionData(QSqlDatabase &dbSoil, const QString &soilCode, soi
QVariantList water_potential;
QVariantList water_content;

unsigned int horizon_index = unsigned(horizon-1);
unsigned int horizon_index = unsigned(horizonNr-1);
for (unsigned int i=0; i < mySoil.horizon[horizon_index].dbData.waterRetention.size(); i++)
{
soil_code << soilCode;
horizon_nr << horizon;
horizon_nr << horizonNr;
water_potential << mySoil.horizon[horizon_index].dbData.waterRetention[i].water_potential;
water_content << mySoil.horizon[horizon_index].dbData.waterRetention[i].water_content;
}
Expand Down
2 changes: 1 addition & 1 deletion soil/soilDbTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

bool updateSoilData(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DSoil &mySoil, QString& errorStr);

bool updateWaterRetentionData(QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DSoil &mySoil, int horizon, QString& errorStr);
bool updateWaterRetentionData(QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DSoil &mySoil, int horizonNr, QString& errorStr);

bool insertSoilData(QSqlDatabase &dbSoil, int soilID, const QString &soilCode,
const QString &soilName, const QString &soilInfo, QString &errorStr);
Expand Down
36 changes: 17 additions & 19 deletions soilWidget/soilWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,27 +448,25 @@ void Crit3DSoilWidget::on_actionChooseSoil(QString soilCode)
// circle inside triangle
for (unsigned int i = 0; i < mySoil.nrHorizons; i++)
{
if (soil::getUSDATextureClass(mySoil.horizon[i].dbData.sand, mySoil.horizon[i].dbData.silt, mySoil.horizon[i].dbData.clay) != NODATA)
{
if (soil::getUSDATextureClass(mySoil.horizon[i].dbData.sand, mySoil.horizon[i].dbData.silt, mySoil.horizon[i].dbData.clay) != NODATA)
{
// the pic has white space around the triangle: widthTriangle and heightTriangle define triangle size without white space
double widthOffset = (pic.width() - widthTriangle)/2;
double heightOffset = (pic.height() - heightTriangle)/2;
double factor = ( pow ( (pow(100.0, 2.0) - pow(50.0, 2.0)), 0.5) ) / 100;
// draw new point
double cx = widthTriangle * ((mySoil.horizon[i].dbData.silt + mySoil.horizon[i].dbData.clay / 2) / 100);
double cy = heightTriangle * (1 - mySoil.horizon[i].dbData.clay / 2 * pow (3, 0.5) / 100 / factor); // tg(60°)=3^0.5
painter.begin(&pic);
QPen pen(Qt::red);
painter.setPen(pen);

QPointF center(widthOffset + cx, heightOffset + cy);
painter.setBrush(Qt::transparent);
painter.drawEllipse(center,4.5,4.5);
// the pic has white space around the triangle: widthTriangle and heightTriangle define triangle size without white space
double widthOffset = (pic.width() - widthTriangle)/2;
double heightOffset = (pic.height() - heightTriangle)/2;
double factor = ( pow ( (pow(100.0, 2.0) - pow(50.0, 2.0)), 0.5) ) / 100;
// draw new point
double cx = widthTriangle * ((mySoil.horizon[i].dbData.silt + mySoil.horizon[i].dbData.clay / 2) / 100);
double cy = heightTriangle * (1 - mySoil.horizon[i].dbData.clay / 2 * pow (3, 0.5) / 100 / factor); // tg(60°)=3^0.5
painter.begin(&pic);
QPen pen(Qt::red);
painter.setPen(pen);

painter.end();
labelPic->setPixmap(pic);
}
QPointF center(widthOffset + cx, heightOffset + cy);
painter.setBrush(Qt::transparent);
painter.drawEllipse(center,4.5,4.5);

painter.end();
labelPic->setPixmap(pic);
}
}
tabChanged(tabWidget->currentIndex());
Expand Down

0 comments on commit ba704e4

Please sign in to comment.