#include "stdafx.h" #include "KDistProcess.h" #include "BlSideData.h" #include "VisionRecipe.h" #include "FileRecipe.h" #include "SoftVisionApp.h" CKDistProcess::CKDistProcess() { /* code */ m_eDir = DIMENSION_NONE; for (int i = 0; i < 50; i++) { m_dots[i] = new CKeyDistDotProcess(m_eDir, i + 1); } m_nRoiSize = 100; m_isUse = false; } CKDistProcess::CKDistProcess(DimensionDir eDir) { /* code */ m_eDir = eDir; m_isUse = false; m_nRoiSize = 100; for (int i = 0; i < 50; i++) { m_dots[i] = new CKeyDistDotProcess(m_eDir, i + 1); } } CKDistProcess::~CKDistProcess() { /* code */ for (int i = 0; i < 50; i++) { CKeyDistDotProcess *dot = m_dots[i]; if (NULL == dot) continue; delete dot; dot = NULL; m_dots[i] = NULL; } } void CKDistProcess::Execute(DimensionDir eDir) { /* code */ if (!m_isUse) return; Point2I offset; for (int i = 0; i < 50; i++) { CKeyDistDotProcess *dot = m_dots[i]; if (NULL == dot) continue; if (1 != dot->m_nUse) continue; offset.x = i; offset.y = i; dot->setRoiSize(m_nRoiSize); dot->Execute(m_eDir, offset); } } Json::Value CKDistProcess::WriteToJson(void) { /* code */ Json::Value jsValue; jsValue["type"] = KDIST_VISION_PROCESS; jsValue["side"] = (int)(m_eDir); jsValue["use"] = m_isUse; jsValue["roi size"] = m_nRoiSize; for (int i = 0; i < 50; i++) { std::string name = ClsVision::FormatString("Dot%d", i); jsValue[name.c_str()] = m_dots[i]->WriteToJson(); } return jsValue; } void CKDistProcess::DecodeJson(Json::Value &jsValue) { /* code */ int num = (int)jsValue.size(); if (num < 1) return; //1. Side std::string strName = "side"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_eDir = (DimensionDir)(jsValue[strName.c_str()].asInt()); } //2. use strName = "use"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isBool()) { m_isUse = jsValue[strName.c_str()].asBool(); } //3. roi size strName = "roi size"; if (jsValue.isMember(strName.c_str()) && jsValue[strName.c_str()].isInt()) { m_nRoiSize = jsValue[strName.c_str()].asInt(); } for (int i = 0; i < 50; i++) { std::string name = ClsVision::FormatString("Dot%d", i); if (jsValue.isMember(name.c_str()) && jsValue[name.c_str()].isObject()) { Json::Value jsData = jsValue[name.c_str()]; m_dots[i]->DecodeJson(jsData); } } }