2024-03-26 10:33:00 +08:00
|
|
|
|
#include "JobController.h"
|
|
|
|
|
#include <commdlg.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include "../Toast.h"
|
|
|
|
|
#include "../LanguageManager.h"
|
|
|
|
|
#include "../global.h"
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
JobController::JobController()
|
|
|
|
|
:m_CurrentJob(NULL)
|
|
|
|
|
, m_LoadThead(INVALID_HANDLE_VALUE)
|
|
|
|
|
, m_LoadFlag(false)
|
|
|
|
|
, m_FilePath("")
|
|
|
|
|
, m_TempJob(NULL)
|
2024-05-22 15:58:54 +08:00
|
|
|
|
, m_PrepareJob(NULL)
|
2024-03-26 10:33:00 +08:00
|
|
|
|
, m_SavePreJobThread(INVALID_HANDLE_VALUE)
|
|
|
|
|
{
|
|
|
|
|
InitializeCriticalSection(&m_cs);
|
|
|
|
|
InitializeCriticalSection(&m_PreJobCS);
|
|
|
|
|
|
2024-05-22 15:58:54 +08:00
|
|
|
|
m_LoadProgressInfoMap[AnalyzingJobData] = g_LngManager->UI_AnalyzingJobData;
|
|
|
|
|
m_LoadProgressInfoMap[CkeckingJobData] = g_LngManager->UI_CheckingJobData;
|
2024-03-26 10:33:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JobController::~JobController()
|
|
|
|
|
{
|
|
|
|
|
RemoveAllJob();
|
|
|
|
|
DeleteCriticalSection(&m_cs);
|
|
|
|
|
DeleteCriticalSection(&m_PreJobCS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JobController::StartLoadPrepareJob()
|
|
|
|
|
{
|
|
|
|
|
HANDLE lp = AtlCreateThread(LoadPrepareJobProc, this);
|
|
|
|
|
CloseHandle(lp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DWORD WINAPI JobController::LoadPrepareJobProc(JobController* _this) {
|
|
|
|
|
if (!_this)return 0;
|
|
|
|
|
char buffer[512];
|
2024-04-24 18:12:41 +08:00
|
|
|
|
//MachineCfg* mcfg = ConfigManager::GetInstance()->GetMachineCfg();
|
|
|
|
|
//sprintf_s(buffer, sizeof(buffer), "%sPrepareJob/%d.h3d", g_AppPath.c_str(), mcfg->m_MachineType);
|
|
|
|
|
sprintf_s(buffer, sizeof(buffer), "D://jobfile//bigmodel_name.h3d");
|
2024-03-26 10:33:00 +08:00
|
|
|
|
H3DFileProcessor* fp = new H3DFileProcessor();
|
|
|
|
|
if (fp->Process(buffer) != BP_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
delete fp;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2024-05-22 15:58:54 +08:00
|
|
|
|
map<int, bool>* precfgs = ConfigManager::GetInstance()->GetPreJobParamCfg();
|
2024-03-26 10:33:00 +08:00
|
|
|
|
vector<MetaData::Layer*> layers = fp->GetMetaData()->GetLayersVec();
|
2024-05-22 15:58:54 +08:00
|
|
|
|
for (map<int, bool>::iterator it = precfgs->begin(); it != precfgs->end(); it++) {
|
2024-03-26 10:33:00 +08:00
|
|
|
|
if (it->first < layers.size()) {
|
|
|
|
|
layers[it->first]->isPrintable = it->second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EnterCriticalSection(&_this->m_PreJobCS);
|
|
|
|
|
if (_this->m_PrepareJob) {
|
|
|
|
|
delete _this->m_PrepareJob;
|
|
|
|
|
}
|
|
|
|
|
_this->m_PrepareJob = fp;
|
|
|
|
|
LeaveCriticalSection(&_this->m_PreJobCS);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool JobController::LoadJob(string filepath)
|
|
|
|
|
{
|
|
|
|
|
SetLoadProgress(0.0f);
|
|
|
|
|
JobController::m_LoadProgressInfoFlag = CkeckingJobData;
|
|
|
|
|
string filename = filepath.substr(filepath.find_last_of("\\") + 1, filepath.length() - 1);
|
|
|
|
|
EnterCriticalSection(&m_cs);
|
|
|
|
|
if (m_CurrentJob != NULL && m_CurrentJob->GetJobFileName() == filename) {
|
2024-05-22 15:58:54 +08:00
|
|
|
|
g_Toast->AddToast(new ToastBean(g_LngManager->Toast_AddTaskRepeat->ShowText(), 3000));
|
2024-03-26 10:33:00 +08:00
|
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 15:58:54 +08:00
|
|
|
|
|
2024-03-26 10:33:00 +08:00
|
|
|
|
if (m_CurrentJob != NULL) {
|
|
|
|
|
delete m_CurrentJob;
|
|
|
|
|
m_CurrentJob = NULL;
|
|
|
|
|
m_TempJob = NULL;
|
|
|
|
|
}
|
|
|
|
|
m_LoadFlag = true;
|
|
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
|
|
|
|
|
|
|
m_FilePath = filepath;
|
|
|
|
|
m_LoadThead = AtlCreateThread(LoadProc, this);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DWORD WINAPI JobController::LoadProc(JobController* _this)
|
|
|
|
|
{
|
|
|
|
|
if (_this) {
|
|
|
|
|
_this->LoadRun();
|
|
|
|
|
EnterCriticalSection(&_this->m_cs);
|
|
|
|
|
_this->m_LoadFlag = false;
|
|
|
|
|
LeaveCriticalSection(&_this->m_cs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JobController::LoadRun()
|
|
|
|
|
{
|
|
|
|
|
if (m_FilePath.find(".h3d") != string::npos)
|
|
|
|
|
{
|
|
|
|
|
m_TempJob = new H3DFileProcessor();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_TempJob = new JobFileProcessor();
|
|
|
|
|
|
|
|
|
|
if (m_TempJob->Process(m_FilePath) != BP_SUCCESS) {
|
|
|
|
|
delete m_TempJob;
|
|
|
|
|
m_TempJob = NULL;
|
2024-05-22 15:58:54 +08:00
|
|
|
|
g_Toast->AddToast(new ToastBean(g_LngManager->Toast_NotSupportData->ShowText(), 3000, Toast::COLOR_RED));
|
2024-03-26 10:33:00 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2024-05-22 15:58:54 +08:00
|
|
|
|
m_TempJob->GetMetaData()->ReCalcEvaTime();
|
2024-03-26 10:33:00 +08:00
|
|
|
|
EnterCriticalSection(&m_cs);
|
|
|
|
|
m_CurrentJob = m_TempJob;
|
|
|
|
|
m_CurrentJob->GetMetaData()->ResetIfs();
|
|
|
|
|
// 根据工艺参数设置层的默认供粉量
|
|
|
|
|
ParamSetCfg::ParamSet* ps = ConfigManager::GetInstance()->GetParamSetCfg()->ParamSetVec[0];
|
|
|
|
|
std::vector<MetaData::Layer*>& layers = m_CurrentJob->GetMetaData()->GetLayersVec();
|
|
|
|
|
for (unsigned int i = 0; i < ps->PowderSets.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned int layer = ps->PowderSets[i]->start_layer;
|
|
|
|
|
layer < m_CurrentJob->GetLayerCount() && layer <= ps->PowderSets[i]->end_layer;
|
|
|
|
|
layer++)
|
|
|
|
|
{
|
|
|
|
|
layers[layer - 1]->powder = ps->PowderSets[i]->powder * layers[layer - 1]->layer_thickness;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_CurrentJob->GetMetaData()->GetLayer(0)->scan_times = 2;
|
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float JobController::GetLoadProgress()
|
|
|
|
|
{
|
|
|
|
|
float rel = 0;
|
|
|
|
|
EnterCriticalSection(&m_LoadInfoCS);
|
|
|
|
|
rel = m_LoadProgress;
|
|
|
|
|
LeaveCriticalSection(&m_LoadInfoCS);
|
|
|
|
|
return rel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string JobController::GetLoadInfo()
|
|
|
|
|
{
|
2024-05-22 15:58:54 +08:00
|
|
|
|
return m_LoadProgressInfoMap[m_LoadProgressInfoFlag]->ShowText();
|
2024-03-26 10:33:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool JobController::IsLoadFinished()
|
|
|
|
|
{
|
|
|
|
|
bool rel = false;
|
|
|
|
|
EnterCriticalSection(&m_cs);
|
|
|
|
|
rel = !m_LoadFlag;
|
|
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
|
|
return rel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JobController::RemoveJob(string job_titel)
|
|
|
|
|
{
|
|
|
|
|
EnterCriticalSection(&m_cs);
|
|
|
|
|
if (m_CurrentJob != NULL) {
|
|
|
|
|
delete m_CurrentJob;
|
|
|
|
|
m_CurrentJob = NULL;
|
|
|
|
|
m_TempJob = NULL;
|
|
|
|
|
}
|
|
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JobController::RemoveAllJob()
|
|
|
|
|
{
|
|
|
|
|
EnterCriticalSection(&m_cs);
|
|
|
|
|
if (m_CurrentJob != NULL) {
|
|
|
|
|
delete m_CurrentJob;
|
|
|
|
|
m_CurrentJob = NULL;
|
|
|
|
|
m_TempJob = NULL;
|
|
|
|
|
}
|
|
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileProcessor* JobController::GetUnFinishedJob()
|
|
|
|
|
{
|
|
|
|
|
if (m_CurrentJob->IsFinished())
|
|
|
|
|
return m_CurrentJob;
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void JobController::StartSavePrepareJob()
|
|
|
|
|
{
|
|
|
|
|
if (m_SavePreJobThread != INVALID_HANDLE_VALUE)return;
|
|
|
|
|
m_SavePreJobThread = AtlCreateThread(SavePrepareJobProc, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DWORD WINAPI JobController::SavePrepareJobProc(JobController* _this)
|
|
|
|
|
{
|
|
|
|
|
if (!_this || !_this->m_PrepareJob) {
|
2024-05-22 15:58:54 +08:00
|
|
|
|
if (_this->m_SavePreJobThread != INVALID_HANDLE_VALUE)CloseHandle(_this->m_SavePreJobThread);
|
2024-03-26 10:33:00 +08:00
|
|
|
|
_this->m_SavePreJobThread = INVALID_HANDLE_VALUE;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
_this->m_PrepareJob->UpdateFile();
|
|
|
|
|
if (_this->m_SavePreJobThread != INVALID_HANDLE_VALUE)CloseHandle(_this->m_SavePreJobThread);
|
|
|
|
|
_this->m_SavePreJobThread = INVALID_HANDLE_VALUE;
|
|
|
|
|
ConfigManager::GetInstance()->SavePreJobParamCfg();
|
2024-05-22 15:58:54 +08:00
|
|
|
|
g_Toast->AddToast(new ToastBean(g_LngManager->Toast_WriteFileSuccess->ShowText(), 3000, Toast::COLOR_GREEN));
|
2024-03-26 10:33:00 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool JobController::IsSavingPrepareJob() {
|
2024-05-22 15:58:54 +08:00
|
|
|
|
if (m_SavePreJobThread != INVALID_HANDLE_VALUE) {
|
2024-03-26 10:33:00 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JobController::LoadProgressInfoFlag JobController::m_LoadProgressInfoFlag = CkeckingJobData;
|
|
|
|
|
//vector<string> JobController::m_LoadErrorInfo = vector<string>();
|
|
|
|
|
CRITICAL_SECTION JobController::m_LoadInfoCS;
|
|
|
|
|
|
|
|
|
|
float JobController::m_LoadProgress = 0.0f;
|