#include "stdafx.h"
|
#include "VisionRecipe.h"
|
#include "FileRecipe.h"
|
#include "SoftVisionApp.h"
|
#include <fstream> // IO ²Ù×÷
|
|
CVisionRecipe::CVisionRecipe() {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
m_pCornerDistProcess[i] = NULL;
|
m_pCornerRcutProcess[i] = NULL;
|
m_pLocProcese[i] = NULL;
|
m_pBlSideData[i] = NULL;
|
m_pCutProcess[i] = NULL;
|
m_pKDistProcess[i] = NULL;
|
m_pThresProcess[i] = NULL;
|
}
|
|
m_mScanSetting.lengthSize = 0;
|
m_mScanSetting.shortSize = 0;
|
m_mScanSetting.nStdIndex = 0;
|
m_mScanSetting.nIndex0 = 0;
|
m_mScanSetting.nIndex1 = 1;
|
m_mScanSetting.nIndex2 = 2;
|
m_mScanSetting.nIndex3 = 3;
|
m_mScanSetting.nLengthScan = 0;
|
m_mScanSetting.nShortScan = 0;
|
|
m_isInit = false;
|
m_pMainDlg = NULL;
|
|
m_visionDisplayInfo.isVisionDisplay = false;
|
m_visionDisplayInfo.isDistDisplay = false;
|
m_visionDisplayInfo.isRcutDisplay = false;
|
m_strVisionName = "system";
|
|
for (int i = 0; i < 8; i++) {
|
m_visionUseInfo[i].isVisionUse = false;
|
m_visionUseInfo[i].isLocUse = false;
|
m_visionUseInfo[i].isDistUse = false;
|
m_visionUseInfo[i].isRcutUse = false;
|
}
|
|
m_keyInfo.isDebugTool = false;
|
m_keyInfo.isInspectKey = false;
|
m_keyInfo.isLocKey = false;
|
m_keyInfo.isGrindKey = false;
|
m_keyInfo.isDistKey = false;
|
m_keyInfo.isCutLineKey = false;
|
m_keyInfo.isRcutKey = false;
|
|
//ĬÈÏÒ»¸öÅä·½Êý¾Ý
|
m_workDir = ClsVision::GetAppPathA() + "Recipe";
|
m_configVision.SetWorkDir(m_workDir.c_str(), m_strVisionName.c_str());
|
readVisionConfig();
|
m_isOpenVisionDlg = FALSE;
|
|
m_nFrameX1 = -1;
|
m_nFrameY1 = -1;
|
m_nFrameX1 = -1;
|
m_nFrameY2 = -1;
|
|
m_nStage = -1;
|
InitializeCriticalSection(&m_criticalSection);
|
}
|
|
CVisionRecipe::~CVisionRecipe() {
|
/* code */
|
release();
|
DeleteCriticalSection(&m_criticalSection);
|
}
|
|
static CVisionRecipe _gVisionRecipe;
|
CVisionRecipe* CVisionRecipe::getInstance(void) {
|
/* code */
|
return &_gVisionRecipe;
|
}
|
|
int CVisionRecipe::setWorkDir(const char *pszPath) {
|
/* code */
|
m_workDir = pszPath;
|
return 0;
|
}
|
|
int CVisionRecipe::save(void) {
|
/* code */
|
std::string filePath = m_workDir;
|
int len = (int)(filePath.length());
|
if (len < 1) return -1;
|
int pos = (int)(filePath.rfind(".dat"));
|
if (pos >= 0) return -1;
|
|
int nRet = saveRecipeFile(filePath);
|
|
return 0;
|
}
|
|
int CVisionRecipe::saveRecipeFile(std::string filePath) {
|
/* code */
|
//1. Ê×ÏÈ´´½¨ÎļþĿ¼
|
std::string strDir = filePath + "\\" + m_strVisionName + "\\";
|
CFileRecipe::makeDir(strDir);
|
|
//2. Çå¿ÕĿ¼ÏµÄËùÓÐÎļþ
|
CFileRecipe::removeDir(strDir);
|
|
//3. н¨Åä·½Îļþ
|
//std::string fileName = strDir + "vision.csv";
|
//CString strFile = CFileRecipe::toCString(fileName);
|
//if (!CFileRecipe::openRecipeFile(m_recipeFile, strFile)) return -1;
|
|
CSoftVisionApp::getInstance()->Log(1, "Trace Save Vision Recipe!");
|
|
WriteRecipeVisionFile();
|
|
// saveResolution();
|
|
//if (CStdioFile::hFileNull != m_recipeFile.m_hFile) {
|
// m_recipeFile.Close();
|
//}
|
return 0;
|
}
|
|
void CVisionRecipe::saveResolution(void) {
|
/* code */
|
std::string array_dir_use[8] = { "A TOP","B TOP", "C TOP", "D TOP", "A BOT", "B BOT","C BOT", "D BOT" };
|
std::string strSection = "";
|
for (int i = 0; i < 8; i++) {
|
strSection = array_dir_use[i];
|
m_configVision.WriteFloat(strSection.c_str(), "Pixel SizeX", m_pBlSideData[i]->m_dPixelSizeX);
|
m_configVision.WriteFloat(strSection.c_str(), "Pixel SizeY", m_pBlSideData[i]->m_dPixelSizeY);
|
}
|
}
|
|
int CVisionRecipe::WriteRecipeVisionFile(void) {
|
/* code */
|
// if (CStdioFile::hFileNull == m_recipeFile.m_hFile) return -1;
|
|
saveVisionConfig();
|
|
std::string strDir = m_workDir + "\\" + m_strVisionName + "\\";
|
Json::Value root;
|
|
int nCount = (int)(DIMENSION_NONE);
|
for (int i = 0; i < nCount; i++) {
|
CLocProcess *dot = m_pLocProcese[i];
|
if (NULL == dot) continue;
|
|
// dot->WriteToFile(m_recipeFile, strDir);
|
|
std::string name = ClsVision::FormatString("Loc%d", i);
|
root[name.c_str()] = dot->WriteToJson(strDir); //±£´æÊý¾Ý
|
}
|
|
|
for (int i = 0; i < nCount; i++) {
|
CGrindProcess *dot = m_pGrindProcess[i];
|
if (NULL == dot) continue;
|
|
// dot->WriteToFile(m_recipeFile, strDir);
|
|
std::string name = ClsVision::FormatString("Grind%d", i);
|
root[name.c_str()] = dot->WriteToJson(); //±£´æÊý¾Ý
|
}
|
|
for (int i = 0; i < nCount; i++) {
|
CCutProcess *dot = m_pCutProcess[i];
|
if (NULL == dot) continue;
|
|
// dot->WriteToFile(m_recipeFile, strDir);
|
|
std::string name = ClsVision::FormatString("Cut%d", i);
|
root[name.c_str()] = dot->WriteToJson(); //±£´æÊý¾Ý
|
}
|
|
for (int i = 0; i < nCount; i++) {
|
CKDistProcess *dot = m_pKDistProcess[i];
|
if (NULL == dot) continue;
|
|
// dot->WriteToFile(m_recipeFile, strDir);
|
|
std::string name = ClsVision::FormatString("KDist%d", i);
|
root[name.c_str()] = dot->WriteToJson(); //±£´æÊý¾Ý
|
}
|
|
for (int i = 0; i < nCount; i++) {
|
CCornerRcutProcess *dot = m_pCornerRcutProcess[i];
|
if (NULL == dot) continue;
|
|
// dot->WriteToFile(m_recipeFile, strDir);
|
|
std::string name = ClsVision::FormatString("RCut%d", i);
|
root[name.c_str()] = dot->WriteToJson(); //±£´æÊý¾Ý
|
}
|
|
for (int i = 0; i < nCount; i++) {
|
CThresProcess *dot = m_pThresProcess[i];
|
if (NULL == dot) continue;
|
|
// dot->WriteToFile(m_recipeFile, strDir);
|
|
std::string name = ClsVision::FormatString("Thres%d", i);
|
root[name.c_str()] = dot->WriteToJson(); //±£´æÊý¾Ý
|
}
|
|
for (int i = 0; i < nCount; i++) {
|
CHoleProcess* dot = m_pHoleProcess[i];
|
if (NULL == dot) continue;
|
|
// dot->WriteToFile(m_recipeFile, strDir);
|
|
std::string name = ClsVision::FormatString("Hole%d", i);
|
root[name.c_str()] = dot->WriteToJson(strDir); //±£´æÊý¾Ý
|
}
|
|
std::string fileName = strDir + "vision.json";
|
std::string strText = root.toStyledString();
|
ofstream ofs(fileName.c_str());
|
ofs << strText;
|
ofs.close();
|
|
return 0;
|
}
|
|
int CVisionRecipe::open(void) {
|
/* code */
|
std::string filePath = m_workDir;
|
if (!CFileRecipe::fileIsExist(filePath.c_str())) {
|
return -1;
|
}
|
|
CSoftVisionApp::getInstance()->Log(1, "Trace Load Vision Recipe!");
|
int nRet = openRecipeFile(filePath);
|
return 0;
|
}
|
|
int CVisionRecipe::openRecipeFile(std::string filePath) {
|
/* code */
|
readVisionConfig();
|
|
#if 0
|
std::string strDir = filePath + "\\" + m_strVisionName + "\\";
|
std::string jsFile = strDir + "vision.json";
|
bool isExist = CFileRecipe::fileIsExist(jsFile.c_str());
|
if (!isExist) {
|
if (!CFileRecipe::fileIsExist(strDir)) return -1;
|
|
std::string fileName = strDir + "vision.csv";
|
CString strFile = CFileRecipe::toCString(fileName);
|
if (!CFileRecipe::readRecileFile(m_recipeFile, strFile)) {
|
return -1;
|
}
|
}
|
|
ReadRecipeFile(isExist);
|
#endif
|
|
ReadRecipeFile();
|
|
// loadResolution();
|
|
|
#if 0
|
if (!isExist) {
|
if (CStdioFile::hFileNull != m_recipeFile.m_hFile) {
|
m_recipeFile.Close();
|
}
|
}
|
#endif
|
|
return 0;
|
}
|
|
void CVisionRecipe::loadResolution(void) {
|
/* code */
|
std::string array_dir_use[8] = { "A TOP","B TOP", "C TOP", "D TOP", "A BOT", "B BOT","C BOT", "D BOT" };
|
std::string strSection = "";
|
for (int i = 0; i < 8; i++) {
|
strSection = array_dir_use[i];
|
double dPixelSizeX = m_configVision.ReadFloat(strSection.c_str(), "Pixel SizeX", 0.0);
|
double dPixelSizeY = m_configVision.ReadFloat(strSection.c_str(), "Pixel SizeY", 0.0);
|
if (fabs(dPixelSizeX) > 0.001 || fabs(dPixelSizeY) > 0.001) {
|
m_pBlSideData[i]->m_dPixelSizeX = dPixelSizeX;
|
m_pBlSideData[i]->m_dPixelSizeY = dPixelSizeY;
|
}
|
}
|
}
|
|
void CVisionRecipe::ReadRecipeFile(void) {
|
/* code */
|
std::string strDir = m_workDir + "\\" + m_strVisionName + "\\";
|
#if 0
|
if (!isExist) {
|
if (CStdioFile::hFileNull == m_recipeFile.m_hFile) return;
|
|
while (true) {
|
CString strReadText;
|
if (!CFileRecipe::ReadString(m_recipeFile, strReadText)) break;
|
|
DecodeRecipeText(strReadText);
|
}
|
|
return;
|
}
|
#endif
|
|
std::string fileName = strDir + "vision.json";
|
if(!CFileRecipe::fileIsExist(fileName)) return;
|
|
Json::Value jsFileRoot;
|
std::ifstream ifFile(fileName.c_str());
|
Json::Reader jsReader;
|
jsReader.parse(ifFile, jsFileRoot);
|
ifFile.close();
|
|
DecodeJson(jsFileRoot);
|
jsFileRoot.clear();
|
}
|
|
void CVisionRecipe::DecodeJson(Json::Value jsFileRoot) {
|
/* code */
|
int num = (int)(jsFileRoot.size());
|
if (num < 1) return;
|
|
std::string strDir = m_workDir + "\\" + m_strVisionName + "\\";
|
|
//1. Loc
|
int nCount = (int)(DIMENSION_NONE);
|
for (int i = 0; i < nCount; i++) {
|
std::string name = ClsVision::FormatString("Loc%d", i);
|
if (!jsFileRoot.isMember(name.c_str())) continue;
|
|
Json::Value jsValue = jsFileRoot[name.c_str()];
|
if (!jsValue.isObject()) continue;
|
|
CLocProcess *dot = m_pLocProcese[i];
|
if (NULL == dot) continue;
|
dot->DecodeJson(strDir, jsValue);
|
}
|
|
//2. Grind
|
for (int i = 0; i < nCount; i++) {
|
std::string name = ClsVision::FormatString("Grind%d", i);
|
if (!jsFileRoot.isMember(name.c_str())) continue;
|
|
Json::Value jsValue = jsFileRoot[name.c_str()];
|
if (!jsValue.isObject()) continue;
|
|
CGrindProcess *dot = m_pGrindProcess[i];
|
if (NULL == dot) continue;
|
dot->DecodeJson(jsValue);
|
}
|
|
//3. Cut
|
for (int i = 0; i < nCount; i++) {
|
std::string name = ClsVision::FormatString("Cut%d", i);
|
if (!jsFileRoot.isMember(name.c_str())) continue;
|
|
Json::Value jsValue = jsFileRoot[name.c_str()];
|
if (!jsValue.isObject()) continue;
|
|
CCutProcess *dot = m_pCutProcess[i];
|
if (NULL == dot) continue;
|
dot->DecodeJson(jsValue);
|
}
|
|
//6. KDist
|
for (int i = 0; i < nCount; i++) {
|
std::string name = ClsVision::FormatString("KDist%d", i);
|
if (!jsFileRoot.isMember(name.c_str())) continue;
|
|
Json::Value jsValue = jsFileRoot[name.c_str()];
|
if (!jsValue.isObject()) continue;
|
|
CKDistProcess *dot = m_pKDistProcess[i];
|
if (NULL == dot) continue;
|
dot->DecodeJson(jsValue);
|
}
|
|
//7. RCut
|
for (int i = 0; i < nCount; i++) {
|
std::string name = ClsVision::FormatString("RCut%d", i);
|
if (!jsFileRoot.isMember(name.c_str())) continue;
|
|
Json::Value jsValue = jsFileRoot[name.c_str()];
|
if (!jsValue.isObject()) continue;
|
|
CCornerRcutProcess *dot = m_pCornerRcutProcess[i];
|
if (NULL == dot) continue;
|
dot->DecodeJson(jsValue);
|
}
|
|
//8. Thres
|
for (int i = 0; i < nCount; i++) {
|
std::string name = ClsVision::FormatString("Thres%d", i);
|
if (!jsFileRoot.isMember(name.c_str())) continue;
|
|
Json::Value jsValue = jsFileRoot[name.c_str()];
|
if (!jsValue.isObject()) continue;
|
|
CThresProcess *dot = m_pThresProcess[i];
|
if (NULL == dot) continue;
|
dot->DecodeJson(jsValue);
|
}
|
|
//9. Hole
|
for (int i = 0; i < nCount; i++) {
|
std::string name = ClsVision::FormatString("Hole%d", i);
|
if (!jsFileRoot.isMember(name.c_str())) continue;
|
|
Json::Value jsValue = jsFileRoot[name.c_str()];
|
if (!jsValue.isObject()) continue;
|
|
CHoleProcess* dot = m_pHoleProcess[i];
|
if (NULL == dot) continue;
|
dot->DecodeJson(jsValue, strDir);
|
}
|
}
|
|
#if 0
|
void CVisionRecipe::DecodeRecipeText(CString strText) {
|
/* code */
|
std::string strDir = m_workDir + "\\" + m_strVisionName + "\\";
|
std::vector<std::string> vStrings;
|
int nRet = CFileRecipe::CStringSplit(strText, ",", vStrings);
|
if (nRet < 1) return;
|
|
int nVisionType = CFileRecipe::StringToInt(vStrings[0]);
|
int idx = CFileRecipe::StringToInt(vStrings[1]);
|
switch (nVisionType){
|
case LOC_VISION_TYPE: {
|
CLocProcess *dot = m_pLocProcese[idx];
|
if (NULL == dot) return;
|
int id = CFileRecipe::StringToInt(vStrings[2]);
|
CNccDotProcess *pNccDot = dot->getDot(id);
|
if (NULL == pNccDot) return;
|
pNccDot->ReadFile(strText, strDir);
|
break;
|
}
|
|
case LOC_VISION_PROCESS: {
|
CLocProcess *dot = m_pLocProcese[idx];
|
if (NULL == dot) return;
|
dot->ReadFile(strText, strDir);
|
break;
|
}
|
|
case GRIND_VISION_TYPE: {
|
CGrindProcess *dot = m_pGrindProcess[idx];
|
if (NULL == dot) return;
|
int id = CFileRecipe::StringToInt(vStrings[2]);
|
CGrindDotProcess *pGrindDot = dot->m_dots[id - 1];
|
if (NULL == pGrindDot) return;
|
pGrindDot->ReadFile(strText, strDir);
|
break;
|
}
|
|
case GRIND_VISION_PROCESS: {
|
CGrindProcess *dot = m_pGrindProcess[idx];
|
if (NULL == dot) return;
|
dot->ReadFile(strText, strDir);
|
break;
|
}
|
|
case CUT_VISION_TYPE: {
|
CCutProcess *dot = m_pCutProcess[idx];
|
if (NULL == dot) return;
|
int id = CFileRecipe::StringToInt(vStrings[2]);
|
CCutDotProcess *pCutDot = dot->m_dots[id - 1];
|
if (NULL == pCutDot) return;
|
pCutDot->ReadFile(strText, strDir);
|
break;
|
}
|
|
case CUT_VISION_PROCESS: {
|
CCutProcess *dot = m_pCutProcess[idx];
|
if (NULL == dot) return;
|
dot->ReadFile(strText, strDir);
|
break;
|
}
|
|
case KDIST_VISION_TYPE: {
|
CKDistProcess *dot = m_pKDistProcess[idx];
|
if (NULL == dot) return;
|
int id = CFileRecipe::StringToInt(vStrings[2]);
|
CKeyDistDotProcess *pKDistDot = dot->m_dots[id - 1];
|
if (NULL == pKDistDot) return;
|
pKDistDot->ReadFile(strText, strDir);
|
break;
|
}
|
|
case KDIST_VISION_PROCESS: {
|
CKDistProcess *dot = m_pKDistProcess[idx];
|
if (NULL == dot) return;
|
dot->ReadFile(strText, strDir);
|
break;
|
}
|
|
case RCUT_VISION_TYPE: {
|
CCornerRcutProcess *dot = m_pCornerRcutProcess[idx];
|
if (NULL == dot) return;
|
int id = CFileRecipe::StringToInt(vStrings[2]);
|
CRcutDotProcess *pRcutDot = dot->m_dots[id - 1];
|
if (NULL == pRcutDot) return;
|
pRcutDot->ReadFile(strText, strDir);
|
break;
|
}
|
|
case RCUT_VISION_PROCESS: {
|
CCornerRcutProcess *dot = m_pCornerRcutProcess[idx];
|
if (NULL == dot) return;
|
dot->ReadFile(strText, strDir);
|
break;
|
}
|
|
case THRES_VISION_TYPE: {
|
CThresProcess *dot = m_pThresProcess[idx];
|
if (NULL == dot) return;
|
int id = CFileRecipe::StringToInt(vStrings[2]);
|
CThresDotProcess *pThresDot = dot->m_dots[id - 1];
|
if (NULL == pThresDot) return;
|
pThresDot->ReadFile(strText, strDir);
|
|
break;
|
}
|
|
case THRES_VISION_PROCESS: {
|
CThresProcess *dot = m_pThresProcess[idx];
|
if (NULL == dot) return;
|
dot->ReadFile(strText, strDir);
|
break;
|
}
|
|
default:
|
break;
|
}
|
}
|
#endif
|
|
CGrabberControl* CVisionRecipe::getGrabberControl(int iCam) {
|
/* code */
|
if (iCam < 0 || iCam >= MAX_CAMERA_COUNT) return nullptr;
|
|
Lock();
|
CGrabberControl *pGrabberControl = m_pGrabberControl[iCam];
|
Unlock();
|
|
return pGrabberControl;
|
}
|
|
int CVisionRecipe::setGrabberControl(CGrabberControl *pGrabberControl, int iCam) {
|
/* code */
|
if (iCam < 0 || iCam >= MAX_CAMERA_COUNT) return -1;
|
|
Lock();
|
m_pGrabberControl[iCam] = pGrabberControl;
|
Unlock();
|
|
return 0;
|
}
|
|
int CVisionRecipe::setCameraSetting(DimensionDir eDir, int iCam, int iScan) {
|
/* code */
|
if (DIMENSION_NONE == eDir) return -1;
|
|
int idx = (int)(eDir);
|
auto iter = m_mapLineCameraSetting.find(idx);
|
if (iter == m_mapLineCameraSetting.end()) {
|
LineCameraSetting *p = new LineCameraSetting();
|
p->eDir = eDir;
|
p->nCam = iCam;
|
p->nScan = iScan;
|
m_mapLineCameraSetting[idx] = p;
|
return 0;
|
}
|
|
iter->second->eDir = eDir;
|
iter->second->nCam = iCam;
|
iter->second->nScan = iScan;
|
return 0;
|
}
|
|
int CVisionRecipe::init(void) {
|
/* code */
|
if (m_isInit) return 0;
|
|
// HalconCpp::SetSystem("temporary_mem_cache", "false");
|
|
//1. ´´½¨SideData
|
createSideData();
|
|
//3. ´´½¨RCUTÊý¾Ý
|
createAllCornerRcutProcess();
|
|
//4. ´´½¨¶¨Î»
|
createAllLocProcess();
|
|
//5. ´´½¨ÇиîÏß
|
createCutProcess();
|
|
//6. ´´½¨KDist
|
createKDistProcess();
|
|
//7. ´´½¨
|
createGrindProcess();
|
|
//8. ´´½¨Thres
|
createThresProcess();
|
|
//9. ´´½¨Hole
|
createHoleProcess();
|
|
m_isInit = true;
|
|
return 0;
|
}
|
|
|
void CVisionRecipe::createSideData(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CBlSideData *pSide = m_pBlSideData[i];
|
if (NULL != pSide) {
|
delete pSide;
|
pSide = NULL;
|
m_pBlSideData[i] = NULL;
|
}
|
m_pBlSideData[i] = new CBlSideData();
|
}
|
}
|
|
int CVisionRecipe::getCameraIndex(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
auto iter = m_mapLineCameraSetting.find(idx);
|
if (iter == m_mapLineCameraSetting.end()) return -1;
|
|
int nRet = iter->second->nCam;
|
return nRet;
|
}
|
|
int CVisionRecipe::getCameraScan(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
auto iter = m_mapLineCameraSetting.find(idx);
|
if (iter == m_mapLineCameraSetting.end()) return -1;
|
|
int nRet = iter->second->nScan;
|
return nRet;
|
}
|
|
void CVisionRecipe::release(void) {
|
/* code */
|
releaseLineCameraSetting();
|
|
#if 0
|
releaaseAllCornerDistProcess();
|
#endif
|
|
releaseAllCornerRcutProcess();
|
|
releaseAllLocProcess();
|
|
releaseAllCutProcess();
|
|
releaseAllKDistProcess();
|
|
releaseAllGrindProcess();
|
|
releaseAllThresProcess();
|
|
releaseAllHoleProcess();
|
}
|
|
void CVisionRecipe::releaseLineCameraSetting(void) {
|
/* code */
|
for (auto iter = m_mapLineCameraSetting.begin(); iter != m_mapLineCameraSetting.end(); iter++) {
|
if (NULL == iter->second) continue;
|
delete iter->second;
|
iter->second = NULL;
|
}
|
|
m_mapLineCameraSetting.clear();
|
}
|
|
void CVisionRecipe::createAllCornerDistProcess(void) {
|
/* code */
|
return;
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CCornerDistProcess *pDot = m_pCornerDistProcess[i];
|
if (NULL != pDot) {
|
delete pDot;
|
pDot = NULL;
|
m_pCornerDistProcess[i] = NULL;
|
}
|
m_pCornerDistProcess[i] = new CCornerDistProcess();
|
m_pCornerDistProcess[i]->m_eDir = (DimensionDir)(i);
|
}
|
}
|
|
void CVisionRecipe::createAllLocProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CLocProcess *dot = m_pLocProcese[i];
|
if (NULL == dot) {
|
delete dot;
|
dot = NULL;
|
m_pLocProcese[i] = NULL;
|
}
|
DimensionDir edir = (DimensionDir)(i);;
|
m_pLocProcese[i] = new CLocProcess(edir);
|
}
|
}
|
|
void CVisionRecipe::createCutProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CCutProcess *dot = m_pCutProcess[i];
|
if (NULL == dot) {
|
delete dot;
|
dot = NULL;
|
m_pCutProcess[i] = NULL;
|
}
|
DimensionDir eDir = (DimensionDir)(i);
|
m_pCutProcess[i] = new CCutProcess(eDir);
|
}
|
}
|
|
void CVisionRecipe::createKDistProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CKDistProcess *dot = m_pKDistProcess[i];
|
if (NULL == dot) {
|
delete dot;
|
dot = NULL;
|
m_pKDistProcess[i] = NULL;
|
}
|
DimensionDir eDir = (DimensionDir)(i);
|
m_pKDistProcess[i] = new CKDistProcess(eDir);
|
}
|
}
|
|
void CVisionRecipe::createGrindProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CGrindProcess *dot = m_pGrindProcess[i];
|
if (NULL == dot) {
|
delete dot;
|
dot = NULL;
|
m_pGrindProcess[i] = NULL;
|
}
|
DimensionDir eDir = (DimensionDir)(i);
|
m_pGrindProcess[i] = new CGrindProcess(eDir);
|
}
|
}
|
|
void CVisionRecipe::createThresProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CThresProcess *dot = m_pThresProcess[i];
|
if (NULL == dot) {
|
delete dot;
|
dot = NULL;
|
m_pThresProcess[i] = NULL;
|
}
|
DimensionDir eDir = (DimensionDir)(i);
|
m_pThresProcess[i] = new CThresProcess(eDir);
|
}
|
}
|
|
void CVisionRecipe::createHoleProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CHoleProcess* dot = m_pHoleProcess[i];
|
if (NULL == dot) {
|
delete dot;
|
dot = NULL;
|
m_pHoleProcess[i] = NULL;
|
}
|
DimensionDir eDir = (DimensionDir)(i);
|
m_pHoleProcess[i] = new CHoleProcess(eDir);
|
}
|
}
|
|
void CVisionRecipe::createAllCornerRcutProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CCornerRcutProcess *pDot = m_pCornerRcutProcess[i];
|
if (NULL != pDot) {
|
delete pDot;
|
pDot = NULL;
|
m_pCornerRcutProcess[i] = NULL;
|
}
|
|
DimensionDir eDir = (DimensionDir)(i);
|
m_pCornerRcutProcess[i] = new CCornerRcutProcess(eDir);
|
}
|
}
|
|
void CVisionRecipe::releaaseAllCornerDistProcess(void) {
|
/* code */
|
return;
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CCornerDistProcess *pDot = m_pCornerDistProcess[i];
|
if (NULL != pDot) {
|
delete pDot;
|
pDot = NULL;
|
m_pCornerDistProcess[i] = NULL;
|
}
|
}
|
}
|
|
void CVisionRecipe::releaseAllCornerRcutProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CCornerRcutProcess *pDot = m_pCornerRcutProcess[i];
|
if (NULL != pDot) {
|
delete pDot;
|
pDot = NULL;
|
m_pCornerRcutProcess[i] = NULL;
|
}
|
}
|
}
|
|
void CVisionRecipe::releaseAllLocProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CLocProcess *pDot = m_pLocProcese[i];
|
if (NULL != pDot) {
|
delete pDot;
|
pDot = NULL;
|
m_pLocProcese[i] = NULL;
|
}
|
}
|
}
|
|
void CVisionRecipe::releaseAllCutProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CCutProcess *pDot = m_pCutProcess[i];
|
if (NULL != pDot) {
|
delete pDot;
|
pDot = NULL;
|
m_pCutProcess[i] = NULL;
|
}
|
}
|
}
|
|
void CVisionRecipe::releaseAllKDistProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CKDistProcess *pDot = m_pKDistProcess[i];
|
if (NULL != pDot) {
|
delete pDot;
|
pDot = NULL;
|
m_pKDistProcess[i] = NULL;
|
}
|
}
|
}
|
|
void CVisionRecipe::releaseAllGrindProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CGrindProcess *pDot = m_pGrindProcess[i];
|
if (NULL != pDot) {
|
delete pDot;
|
pDot = NULL;
|
m_pGrindProcess[i] = NULL;
|
}
|
}
|
}
|
|
void CVisionRecipe::releaseAllThresProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CThresProcess *pDot = m_pThresProcess[i];
|
if (NULL != pDot) {
|
delete pDot;
|
pDot = NULL;
|
m_pThresProcess[i] = NULL;
|
}
|
}
|
}
|
|
void CVisionRecipe::releaseAllHoleProcess(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CHoleProcess* pDot = m_pHoleProcess[i];
|
if (NULL != pDot) {
|
delete pDot;
|
pDot = NULL;
|
m_pThresProcess[i] = NULL;
|
}
|
}
|
}
|
|
void CVisionRecipe::releaaseAllSideData(void) {
|
/* code */
|
for (int i = 0; i < DIMENSION_NONE; i++) {
|
CBlSideData *pSide = m_pBlSideData[i];
|
if (NULL != pSide) {
|
delete pSide;
|
pSide = NULL;
|
m_pBlSideData[i] = NULL;
|
}
|
}
|
}
|
|
CCornerDistProcess* CVisionRecipe::getCornerDistProcess(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
int fz = (int)(DIMENSION_NONE);
|
if (idx < 0 || idx >= fz) return NULL;
|
|
Lock();
|
CCornerDistProcess *dot = m_pCornerDistProcess[idx];
|
Unlock();
|
|
return dot;
|
}
|
|
CBlSideData* CVisionRecipe::getSideData(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
int fz = (int)(DIMENSION_NONE);
|
if (idx < 0 || idx >= fz) return NULL;
|
|
Lock();
|
CBlSideData *pSideData = m_pBlSideData[idx];
|
Unlock();
|
|
return pSideData;
|
}
|
|
int CVisionRecipe::setRecipeType(int nType) {
|
/* code */
|
m_nRecipeType = nType;
|
return 0;
|
}
|
|
int CVisionRecipe::getRecipeType(void) {
|
/* code */
|
return m_nRecipeType;
|
}
|
|
bool CVisionRecipe::getVisionUse(void) {
|
/* code */
|
return m_visionDisplayInfo.isVisionDisplay;
|
}
|
|
int CVisionRecipe::setVisionName(const char* pszPath) {
|
/* code */
|
if (nullptr == pszPath || std::string(pszPath).length() < 1){
|
return -1;
|
}
|
|
m_strVisionName = pszPath;
|
m_configVision.SetWorkDir(m_workDir.c_str() , m_strVisionName.c_str());
|
return true;
|
}
|
|
int CVisionRecipe::setProductNo(const char* pszNo) {
|
/* code */
|
m_strProductNo = pszNo;
|
return 0;
|
}
|
|
//14. »ñÈ¡Åä·½Ãû³Æ
|
std::string CVisionRecipe::getVisionName() {
|
/* code */
|
return m_strVisionName;
|
}
|
|
std::string CVisionRecipe::getProductNo(void) {
|
/* code */
|
return m_strProductNo;
|
}
|
|
void CVisionRecipe::setGlassSize(int x, int y) {
|
/* code */
|
m_mScanSetting.lengthSize = x;
|
m_mScanSetting.shortSize = y;
|
}
|
|
void CVisionRecipe::SetMainDlg(CDialogEx *pDlg) {
|
/* code */
|
m_pMainDlg = pDlg;
|
}
|
|
CDialogEx* CVisionRecipe::GetMainDlg(void) {
|
/* code */
|
return m_pMainDlg;
|
}
|
|
CCornerRcutProcess* CVisionRecipe::getCornerRcutProcess(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
int fz = (int)(DIMENSION_NONE);
|
if (idx < 0 || idx >= fz) return NULL;
|
|
Lock();
|
CCornerRcutProcess *dot = m_pCornerRcutProcess[idx];
|
Unlock();
|
return dot;
|
}
|
|
CLocProcess* CVisionRecipe::getLocProcess(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
int fz = (int)(DIMENSION_NONE);
|
if (idx < 0 || idx >= fz) return NULL;
|
|
Lock();
|
CLocProcess *dot = m_pLocProcese[idx];
|
Unlock();
|
|
return dot;
|
}
|
|
CCutProcess* CVisionRecipe::getCutProcess(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
int fz = (int)(DIMENSION_NONE);
|
if (idx < 0 || idx >= fz) return NULL;
|
|
Lock();
|
CCutProcess *dot = m_pCutProcess[idx];
|
Unlock();
|
|
return dot;
|
}
|
|
CKDistProcess* CVisionRecipe::getKDistProcess(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
int fz = (int)(DIMENSION_NONE);
|
if (idx < 0 || idx >= fz) return NULL;
|
|
Lock();
|
CKDistProcess *dot = m_pKDistProcess[idx];
|
Unlock();
|
|
return dot;
|
}
|
|
CGrindProcess* CVisionRecipe::getGrindProcess(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
int fz = (int)(DIMENSION_NONE);
|
if (idx < 0 || idx >= fz) return NULL;
|
|
Lock();
|
CGrindProcess *dot = m_pGrindProcess[idx];
|
Unlock();
|
return dot;
|
}
|
|
CThresProcess* CVisionRecipe::getThresProcess(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
int fz = (int)(DIMENSION_NONE);
|
if (idx < 0 || idx >= fz) return NULL;
|
|
Lock();
|
CThresProcess *dot = m_pThresProcess[idx];
|
Unlock();
|
return dot;
|
}
|
|
CHoleProcess* CVisionRecipe::getHoleProcess(DimensionDir eDir) {
|
/* code */
|
int idx = (int)(eDir);
|
int fz = (int)(DIMENSION_NONE);
|
if (idx < 0 || idx >= fz) return NULL;
|
|
Lock();
|
CHoleProcess* dot = m_pHoleProcess[idx];
|
Unlock();
|
return dot;
|
}
|
|
ScanSetting CVisionRecipe::getScanSetting(void) {
|
/* code */
|
return m_mScanSetting;
|
}
|
|
void CVisionRecipe::setScanSetting(ScanSetting inf) {
|
/* code */
|
m_mScanSetting = inf;
|
}
|
|
void CVisionRecipe::saveVisionConfig(void) {
|
/* code */
|
//±£´æÏÔʾ
|
std::string strSection = "Vision Display";
|
m_configVision.WriteBool(strSection.c_str(), "Vision Show", m_visionDisplayInfo.isVisionDisplay);
|
m_configVision.WriteBool(strSection.c_str(), "Dist Show", m_visionDisplayInfo.isDistDisplay);
|
m_configVision.WriteBool(strSection.c_str(), "RCUT Show", m_visionDisplayInfo.isRcutDisplay);
|
m_configVision.WriteBool(strSection.c_str(), "Grind Show", m_visionDisplayInfo.isGrindDisplay);
|
m_configVision.WriteBool(strSection.c_str(), "CUT Show", m_visionDisplayInfo.isCutDisplay);
|
m_configVision.WriteBool(strSection.c_str(), "Thres Show", m_visionDisplayInfo.isThresDisplay);
|
m_configVision.WriteBool(strSection.c_str(), "Hole Show", m_visionDisplayInfo.isHoleDisplay);
|
|
std::string array_dir_use[8] = { "A TOP","B TOP", "C TOP", "D TOP", "A BOT", "B BOT","C BOT", "D BOT" };
|
for (int i = 0; i < 8; i++) {
|
strSection = array_dir_use[i];
|
m_configVision.WriteBool(strSection.c_str(), "Vision Use", m_visionUseInfo[i].isVisionUse);
|
m_configVision.WriteBool(strSection.c_str(), "LOC Use", m_visionUseInfo[i].isLocUse);
|
m_configVision.WriteBool(strSection.c_str(), "Dist Use", m_visionUseInfo[i].isDistUse);
|
m_configVision.WriteBool(strSection.c_str(), "RCUT Use", m_visionUseInfo[i].isRcutUse);
|
m_configVision.WriteBool(strSection.c_str(), "Grind Use", m_visionUseInfo[i].isGrindUse);
|
m_configVision.WriteBool(strSection.c_str(), "Cut Use", m_visionUseInfo[i].isCutUse);
|
m_configVision.WriteBool(strSection.c_str(), "Thres Use", m_visionUseInfo[i].isThresUse);
|
m_configVision.WriteBool(strSection.c_str(), "Hole Use", m_visionUseInfo[i].isHoleUse);
|
}
|
|
strSection = "Scan";
|
m_configVision.WriteInt(strSection.c_str(), "Length Size", m_mScanSetting.lengthSize);
|
m_configVision.WriteInt(strSection.c_str(), "Short Size", m_mScanSetting.shortSize);
|
m_configVision.WriteInt(strSection.c_str(), "Standard Point", m_mScanSetting.nStdIndex);
|
m_configVision.WriteInt(strSection.c_str(), "First Point", m_mScanSetting.nIndex0);
|
m_configVision.WriteInt(strSection.c_str(), "Second Point", m_mScanSetting.nIndex1);
|
m_configVision.WriteInt(strSection.c_str(), "Third Point", m_mScanSetting.nIndex2);
|
m_configVision.WriteInt(strSection.c_str(), "Fourth Point", m_mScanSetting.nIndex3);
|
m_configVision.WriteInt(strSection.c_str(), "Length Scan", m_mScanSetting.nLengthScan);
|
m_configVision.WriteInt(strSection.c_str(), "Short Scan", m_mScanSetting.nShortScan);
|
}
|
|
void CVisionRecipe::readVisionConfig(void) {
|
/* code */
|
std::string strSection = "Vision Display";
|
m_visionDisplayInfo.isVisionDisplay = m_configVision.ReadBool(strSection.c_str(), "Vision Show", false);
|
m_visionDisplayInfo.isDistDisplay = m_configVision.ReadBool(strSection.c_str(), "Dist Show", false);
|
m_visionDisplayInfo.isRcutDisplay = m_configVision.ReadBool(strSection.c_str(), "RCUT Show", false);
|
m_visionDisplayInfo.isGrindDisplay = m_configVision.ReadBool(strSection.c_str(), "Grind Show", false);
|
m_visionDisplayInfo.isCutDisplay = m_configVision.ReadBool(strSection.c_str(), "CUT Show", false);
|
m_visionDisplayInfo.isThresDisplay = m_configVision.ReadBool(strSection.c_str(), "Thres Show", false);
|
m_visionDisplayInfo.isHoleDisplay = m_configVision.ReadBool(strSection.c_str(), "Hole Show", false);
|
|
|
std::string array_dir_use[8] = { "A TOP","B TOP", "C TOP", "D TOP", "A BOT", "B BOT","C BOT", "D BOT" };
|
for (int i = 0; i < 8; i++) {
|
strSection = array_dir_use[i];
|
m_visionUseInfo[i].isVisionUse = m_configVision.ReadBool(strSection.c_str(), "Vision Use", false);
|
m_visionUseInfo[i].isLocUse = m_configVision.ReadBool(strSection.c_str(), "LOC Use", false);
|
m_visionUseInfo[i].isDistUse = m_configVision.ReadBool(strSection.c_str(), "Dist Use", false);
|
m_visionUseInfo[i].isRcutUse = m_configVision.ReadBool(strSection.c_str(), "RCUT Use", false);
|
m_visionUseInfo[i].isGrindUse = m_configVision.ReadBool(strSection.c_str(), "Grind Use", false);
|
m_visionUseInfo[i].isCutUse = m_configVision.ReadBool(strSection.c_str(), "Cut Use", false);
|
m_visionUseInfo[i].isThresUse = m_configVision.ReadBool(strSection.c_str(), "Thres Use", false);
|
m_visionUseInfo[i].isHoleUse = m_configVision.ReadBool(strSection.c_str(), "Hole Use", false);
|
}
|
|
strSection = "Scan";
|
m_mScanSetting.lengthSize = m_configVision.ReadInt(strSection.c_str(), "Length Size", 0);
|
m_mScanSetting.shortSize = m_configVision.ReadInt(strSection.c_str(), "Short Size",0);
|
m_mScanSetting.nStdIndex = m_configVision.ReadInt(strSection.c_str(), "Standard Point", 0);
|
m_mScanSetting.nIndex0 = m_configVision.ReadInt(strSection.c_str(), "First Point", 0);
|
m_mScanSetting.nIndex1 = m_configVision.ReadInt(strSection.c_str(), "Second Point", 0);
|
m_mScanSetting.nIndex2 = m_configVision.ReadInt(strSection.c_str(), "Third Point", 0);
|
m_mScanSetting.nIndex3 = m_configVision.ReadInt(strSection.c_str(), "Fourth Point", 0);
|
m_mScanSetting.nLengthScan = m_configVision.ReadInt(strSection.c_str(), "Length Scan", 0);
|
m_mScanSetting.nShortScan = m_configVision.ReadInt(strSection.c_str(), "Short Scan", 0);
|
}
|
|
VisionUseInfo CVisionRecipe::getVisionUse(DimensionDir eDir) {
|
/* code */
|
VisionUseInfo inf;
|
inf.isVisionUse = false;
|
inf.isLocUse = false;
|
inf.isDistUse = false;
|
inf.isRcutUse = false;
|
int index = (int)(eDir);
|
if (index < 0 || index > 7) return inf;
|
|
inf = m_visionUseInfo[index];
|
return inf;
|
}
|
|
void CVisionRecipe::setVisionUse(VisionUseInfo inf, DimensionDir eDir) {
|
/* code */
|
int index = (int)(eDir);
|
if (index < 0 || index > 7) return;
|
|
m_visionUseInfo[index] = inf;
|
}
|
|
VisionDisplayInfo CVisionRecipe::getVisionDisplay(void) {
|
/* code */
|
return m_visionDisplayInfo;
|
}
|
|
void CVisionRecipe::setVisionDisplay(VisionDisplayInfo inf) {
|
/* code */
|
m_visionDisplayInfo = inf;
|
}
|
|
KeyDebugInfo CVisionRecipe::getKeyInfo(void) {
|
/* code */
|
return m_keyInfo;
|
}
|
|
void CVisionRecipe::setKeyInfo(KeyDebugInfo info) {
|
/* code */
|
m_keyInfo = info;
|
}
|
|
void CVisionRecipe::setVisionSetOpen(BOOL isOpen) {
|
/* code */
|
m_isOpenVisionDlg = isOpen;
|
}
|
|
void CVisionRecipe::setStage(int nStage) {
|
/* code */
|
m_nStage = nStage;
|
}
|
|
int CVisionRecipe::getStage(void) {
|
/* code */
|
return m_nStage;
|
}
|
|
BOOL CVisionRecipe::getVisionSetOpen(void) {
|
/* code */
|
return m_isOpenVisionDlg;
|
}
|
|
void CVisionRecipe::setFrame(int x1, int y1, int x2, int y2) {
|
/* code */
|
m_nFrameX1 = x1;
|
m_nFrameY1 = y1;
|
m_nFrameX2 = x2;
|
m_nFrameY2 = y2;
|
}
|
|
bool CVisionRecipe::getFrame(int &x1, int &y1, int &x2, int &y2) {
|
/* code */
|
x1 = m_nFrameX1;
|
y1 = m_nFrameY1;
|
x2 = m_nFrameX2;
|
y2 = m_nFrameY2;
|
bool result = false;
|
if (x1 >= 0 && y1 >= 0 && x2 > x1 && y2 > y1) result = true;
|
return true;
|
}
|