GrpcPrint/PrintS/Config/bean/PowderEstimateCfg.cpp

206 lines
7.0 KiB
C++

#include "PowderEstimateCfg.h"
#include "BaseConfig.h"
PowderEstimateCfg::PowderEstimateCfg()
: m_PowderPerGrid(new UIntData("PowderPerGrid", u8"", 8))
, m_TotalGrids(new UIntData("TotalGrids", u8""))
, m_RemainPowderGrid(new UIntData("RemainPowderGrid", u8""))
, m_StartSupplyPos(new IntData("StartSupplyPos", u8""))
, m_StopSupplyPos(new IntData("StopSupplyPos", u8"", 2))
, m_StartSupplyQty(new FloatData("StartSupplyQty", u8"", 20.0f))
, m_StopSupplyQty(new FloatData("StopSupplyQty", u8"", 50.0f))
, m_AutoSupplyEnable(new BoolData("AutoSupplyEnable", u8""))
, m_AutoSupplyTimeoutMinute(new UIntData("AutoSupplyTimeoutMinute", u8"", 10))
{
InsertMp(&m_PowderPerGrid);
InsertMp(&m_TotalGrids);
InsertMp(&m_RemainPowderGrid);
InsertMp(&m_StartSupplyPos);
InsertMp(&m_StopSupplyPos);
InsertMp(&m_StartSupplyQty);
InsertMp(&m_StopSupplyQty);
InsertMp(&m_AutoSupplyEnable);
InsertMp(&m_AutoSupplyTimeoutMinute);
m_PE1.m_SpaceGrid->SetValue(200);
m_PE2.m_SpaceGrid->SetValue(1000);
m_PE3.m_SpaceGrid->SetValue(1000);
m_PE4.m_SpaceGrid->SetValue(1000);
m_PE5.m_SpaceGrid->SetValue(1000);
InitializeCriticalSection(&m_RemainCS);
}
PowderEstimateCfg::~PowderEstimateCfg()
{
DeleteCriticalSection(&m_RemainCS);
}
void PowderEstimateCfg::Init(int posSize)
{
vector<PowderEstimate*> pes;
pes.push_back(&m_PE1);
pes.push_back(&m_PE2);
pes.push_back(&m_PE3);
pes.push_back(&m_PE4);
pes.push_back(&m_PE5);
for (int i = 0; i < posSize; i++){
if (posSize <= pes.size()) {
m_PEVec.push_back(pes[i]);
}
}
for (int i = 0; i< m_PEVec.size(); ++i) {
InsertMp(&(m_PEVec[i]->m_SpaceGrid), 1, "_" + to_string(i));
InsertMp(&(m_PEVec[i]->m_PowderPercent), 1, "_" + to_string(i));
InsertMp(&(m_PEVec[i]->m_PowderPercentCtrl), 1, "_" + to_string(i));
}
}
void PowderEstimateCfg::GetUpdateSql(vector<string>& ups)
{
char buffer[512];
sprintf_s(buffer, sizeof(buffer), "UPDATE %s set %s=",
BaseConfig::TABLE_NAME.c_str(),
BaseConfig::FIELD_CONFIG_VALUE.c_str()
);
string strhead(buffer);
sprintf_s(buffer, sizeof(buffer), " WHERE %s='%s' AND %s=",
BaseConfig::FIELD_CONFIG_NAME.c_str(),
CONFIG_NAME.c_str(),
BaseConfig::FIELD_CONFIG_CODE.c_str()
);
string strtail(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PowderPerGrid->GetValue()).c_str(),
strtail.c_str(), FIELD_POWDER_PER_GRID.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PE1.m_SpaceGrid->GetValue()).c_str(),
strtail.c_str(), FIELD_SPACE_GRID1.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PE2.m_SpaceGrid->GetValue()).c_str(),
strtail.c_str(), FIELD_SPACE_GRID2.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PE3.m_SpaceGrid->GetValue()).c_str(),
strtail.c_str(), FIELD_SPACE_GRID3.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PE4.m_SpaceGrid->GetValue()).c_str(),
strtail.c_str(), FIELD_SPACE_GRID4.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PE5.m_SpaceGrid->GetValue()).c_str(),
strtail.c_str(), FIELD_SPACE_GRID5.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PE1.m_PowderPercent->GetValue()).c_str(),
strtail.c_str(), FIELD_POWDER_PERCENT1.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PE2.m_PowderPercent->GetValue()).c_str(),
strtail.c_str(), FIELD_POWDER_PERCENT2.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PE3.m_PowderPercent->GetValue()).c_str(),
strtail.c_str(), FIELD_POWDER_PERCENT3.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PE4.m_PowderPercent->GetValue()).c_str(),
strtail.c_str(), FIELD_POWDER_PERCENT4.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_PE5.m_PowderPercent->GetValue()).c_str(),
strtail.c_str(), FIELD_POWDER_PERCENT5.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_RemainPowderGrid->GetValue()).c_str(),
strtail.c_str(), FIELD_REMAIN_POWDER_GRID.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_StartSupplyPos->GetValue()).c_str(),
strtail.c_str(), FIELD_START_SUPPLY_POS.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_StopSupplyPos->GetValue()).c_str(),
strtail.c_str(), FIELD_STOP_SUPPLY_POS.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
m_AutoSupplyEnable->GetValue() ?"1":"0",
strtail.c_str(), FIELD_AUTO_SUPPLY_ENABLE.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_AutoSupplyTimeoutMinute->GetValue()).c_str(),
strtail.c_str(), FIELD_AUTO_SUPPLY_TIMEOUT_MINUTE.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_StartSupplyQty->GetValue()).c_str(),
strtail.c_str(), FIELD_START_SUPPLY_QTY.c_str());
ups.push_back(buffer);
sprintf_s(buffer, sizeof(buffer), "%s'%s'%s'%s'",
strhead.c_str(),
to_string(m_StopSupplyQty->GetValue()).c_str(),
strtail.c_str(), FIELD_STOP_SUPPLY_QTY.c_str());
ups.push_back(buffer);
}
const string PowderEstimateCfg::CONFIG_NAME="PowderEstimate";
const string PowderEstimateCfg::FIELD_POWDER_PER_GRID="PowderPerGrid";
const string PowderEstimateCfg::FIELD_SPACE_GRID1="SpaceGrid1";
const string PowderEstimateCfg::FIELD_SPACE_GRID2 = "SpaceGrid2";
const string PowderEstimateCfg::FIELD_SPACE_GRID3 = "SpaceGrid3";
const string PowderEstimateCfg::FIELD_SPACE_GRID4 = "SpaceGrid4";
const string PowderEstimateCfg::FIELD_SPACE_GRID5 = "SpaceGrid5";
const string PowderEstimateCfg::FIELD_POWDER_PERCENT1="PowderPercent1";
const string PowderEstimateCfg::FIELD_POWDER_PERCENT2 = "PowderPercent2";
const string PowderEstimateCfg::FIELD_POWDER_PERCENT3 = "PowderPercent3";
const string PowderEstimateCfg::FIELD_POWDER_PERCENT4 = "PowderPercent4";
const string PowderEstimateCfg::FIELD_POWDER_PERCENT5 = "PowderPercent5";
const string PowderEstimateCfg::FIELD_REMAIN_POWDER_GRID = "RemainPowderGrid";
const string PowderEstimateCfg::FIELD_START_SUPPLY_POS = "StartSupplyPos";
const string PowderEstimateCfg::FIELD_STOP_SUPPLY_POS = "StopSupplyPos";
const string PowderEstimateCfg::FIELD_AUTO_SUPPLY_ENABLE="AutoSupplyEnable";
const string PowderEstimateCfg::FIELD_AUTO_SUPPLY_TIMEOUT_MINUTE = "AutoSupplyTimeoutMinute";
const string PowderEstimateCfg::FIELD_START_SUPPLY_QTY = "StartSupplyQty";
const string PowderEstimateCfg::FIELD_STOP_SUPPLY_QTY = "StopSupplyQty";