#include "StdAfx.h" #include "JsonConfig.h" #include #include #include #include #include "CJsonObject.hpp" JsonConfig::JsonConfig(void) { } JsonConfig::~JsonConfig(void) { } /************************************************************************/ /* 保存配置参数 */ /************************************************************************/ void JsonConfig::WriteToJson(PCONFIGPARAMS pConfigItem,const std::string fileNames,bool isConfigItem) { //neb::CJsonObject outJson; //outJson.AddEmptySubObject("Config");//header //outJson["Config"].Add(PIXTYPE,(int)(pConfigItem->Pixtype)); //outJson["Config"].Add(PAPARSIZE,(int)(pConfigItem->PaperSize)); //outJson["Config"].Add(RESOLUTION,(int)(pConfigItem->Resolution)); //outJson["Config"].Add(DUPLEX,(int)(pConfigItem->Duplex)); //std::ofstream os; //os.open(fileNames.c_str()); //os< cfgArray,const std::string filename) { /*neb::CJsonObject root; root.AddEmptySubObject("Distor"); root["Distor"].AddEmptySubArray(OBJVALUE1); root["Distor"].AddEmptySubArray(OBJVALUE2); root["Distor"].AddEmptySubArray(OBJVALUE3); root["Distor"].AddEmptySubArray(OBJVALUE4); root["Distor"].AddEmptySubArray(OBJVALUE5); root["Distor"].AddEmptySubArray(OBJVALUE6); root["Distor"].AddEmptySubArray(LIMITOFFSET1); root["Distor"].AddEmptySubArray(LIMITOFFSET2); root["Distor"].AddEmptySubArray(LIMITOFFSET3); root["Distor"].AddEmptySubArray(LIMITOFFSET4); root["Distor"].AddEmptySubArray(LIMITOFFSET5); root["Distor"].AddEmptySubArray(LIMITOFFSET6); for (int i=0;i cfgArray,const std::string filename) { /*neb::CJsonObject root; root.AddEmptySubObject("Match"); root["Match"].AddEmptySubArray(LOADNUM); root["Match"].AddEmptySubArray(XPOINT); root["Match"].AddEmptySubArray(YPOINT); root["Match"].AddEmptySubArray(PWIGHT); root["Match"].AddEmptySubArray(PHEIGHT); root["Match"].AddEmptySubArray(MATCHPATH); for (int i=0;i vc; vc=ReadJsonArrayFromFile(s_default.c_str()); if (vc.size()!=0) { return vc[0]; } return GetDefaultConfigParams();*/ return CONFIGPARAMS(); } DISTORTIONPARAMS JsonConfig::ReadDistorConfig() { //TCHAR szIniFile[MAX_PATH] = { 0 }; //SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE); //_tcscat(szIniFile, HUAGAO_SCAN); //_tcscat(szIniFile, PAPER_TEST); //_tcscat(szIniFile, TEXT("\\")); //_tcscat(szIniFile, DISTOR_JSON_NAME); //std::string s_default(szIniFile); //vector vc; //vc=ReadDistorJsonFromFile(s_default.c_str()); //if (vc.size()!=0) //{ // return vc[0]; //} //return GetDistorConfigParams(); return GetDistorConfigParams(); } MATCHPARAMS JsonConfig::ReadMacthConfig() { //TCHAR szIniFile[MAX_PATH] = { 0 }; //SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE); //_tcscat(szIniFile, HUAGAO_SCAN); //_tcscat(szIniFile, PAPER_TEST); //_tcscat(szIniFile, TEXT("\\")); //_tcscat(szIniFile, MATCH_JSON_NAME); //std::string s_default(szIniFile); //vector vc; //vc=ReadMacthJsonFromFile(s_default.c_str()); //if (vc.size()!=0) //{ // return vc[0]; //} //return GetMacthConfigParams(); return MATCHPARAMS(); } bool JsonConfig::DeleteJsonFile(std::string path) { return (remove(path.c_str())); } std::vector JsonConfig::ReadJsonArrayFromFile(const std::string filename) { std::vector re; /*FILE* file=fopen(filename.c_str(),"rb"); if (!file) { return re; } fseek(file,0,SEEK_END); long size=ftell(file); fseek(file,0,SEEK_SET); std::string text; char* buffer=new char[size+1]; buffer[size]=0; if (!fread(buffer,1,size,file)==(unsigned long)size) { return re; } text=buffer; fclose(file); delete []buffer; re=parseJsonFromString(text);*/ return re; } std::vector JsonConfig::ReadDistorJsonFromFile(const std::string filename) { std::vector re; //FILE* file=fopen(filename.c_str(),"rb"); //if (!file) //{ // return re; //} //fseek(file,0,SEEK_END); //long size=ftell(file); //fseek(file,0,SEEK_SET); //std::string text; //char* buffer=new char[size+1]; //buffer[size]=0; //if (!fread(buffer,1,size,file)==(unsigned long)size) //{ // return re; //} //text=buffer; //fclose(file); //delete []buffer; //re=parseDistorFromString(text); return re; } std::vector JsonConfig::ReadMacthJsonFromFile(const std::string filename) { std::vector re; /*FILE* file=fopen(filename.c_str(),"rb"); if (!file) { return re; } fseek(file,0,SEEK_END); long size=ftell(file); fseek(file,0,SEEK_SET); std::string text; char* buffer=new char[size+1]; buffer[size]=0; if (!fread(buffer,1,size,file)==(unsigned long)size) { return re; } text=buffer; fclose(file); delete []buffer; re=parseMacthFromString(text);*/ return re; } CONFIGPARAMS JsonConfig::GetDefaultConfigParams() { CONFIGPARAMS params; params.Pixtype=1;//灰度 params.PaperSize=11;//A3 params.Resolution=200;//200dpi params.Duplex=1;//双面 params.TabIndex = 1; return params; } DISTORTIONPARAMS JsonConfig::GetDistorConfigParams() { DISTORTIONPARAMS params; for(int i = 0;i < 6;i++) { params.ObjValues[i] = 10; params.LimitOffset[i] = 2; } return params; } MATCHPARAMS JsonConfig::GetMacthConfigParams() { MATCHPARAMS params; params.LoadNum = 4; params.XPoint = 10; params.YPoint = 10; params.PWight = 100; params.PHeight = 100; return params; } std::vector JsonConfig::parseJsonFromString(const std::string str) { //neb::CJsonObject root(str); vector vcConfig; /*int size=0; neb::CJsonObject itmPaparSize; root["Config"].Get(PAPARSIZE,itmPaparSize); size=itmPaparSize.GetArraySize(); if (size>0) { neb::CJsonObject itmPixType; root["Config"].Get(PIXTYPE,itmPixType); neb::CJsonObject itmRes; root["Config"].Get(RESOLUTION,itmRes); neb::CJsonObject itmDulpex; root["Config"].Get(DUPLEX,itmDulpex); neb::CJsonObject itmTabIndex; root["Config"].Get(TABINDEX,itmTabIndex); for (int i=0;i JsonConfig::parseDistorFromString(const std::string str) { //neb::CJsonObject root(str); vector vcConfig; //int size=0; //neb::CJsonObject itmObjValue1; //root["Distor"].Get(OBJVALUE1,itmObjValue1); //size = itmObjValue1.GetArraySize(); //if (size>0) //{ // neb::CJsonObject itmObjValue2; // root["Distor"].Get(OBJVALUE2,itmObjValue2); // neb::CJsonObject itmObjValue3; // root["Distor"].Get(OBJVALUE3,itmObjValue3); // neb::CJsonObject itmObjValue4; // root["Distor"].Get(OBJVALUE4,itmObjValue4); // neb::CJsonObject itmObjValue5; // root["Distor"].Get(OBJVALUE5,itmObjValue5); // neb::CJsonObject itmObjValue6; // root["Distor"].Get(OBJVALUE6,itmObjValue6); // neb::CJsonObject itmLimitOffset1; // root["Distor"].Get(LIMITOFFSET1,itmLimitOffset1); // neb::CJsonObject itmLimitOffset2; // root["Distor"].Get(LIMITOFFSET2,itmLimitOffset2); // neb::CJsonObject itmLimitOffset3; // root["Distor"].Get(LIMITOFFSET3,itmLimitOffset3); // neb::CJsonObject itmLimitOffset4; // root["Distor"].Get(LIMITOFFSET4,itmLimitOffset4); // neb::CJsonObject itmLimitOffset5; // root["Distor"].Get(LIMITOFFSET5,itmLimitOffset5); // neb::CJsonObject itmLimitOffset6; // root["Distor"].Get(LIMITOFFSET6,itmLimitOffset6); // for (int i=0;i JsonConfig::parseMacthFromString(const std::string str) { //neb::CJsonObject root(str); vector vcConfig; /*int size=0; neb::CJsonObject itmLoadNum; root["Match"].Get(LOADNUM,itmLoadNum); size=itmLoadNum.GetArraySize(); if (size>0) { neb::CJsonObject itmXPoint; root["Match"].Get(XPOINT,itmXPoint); neb::CJsonObject itmYPoint; root["Match"].Get(YPOINT,itmYPoint); neb::CJsonObject itmPWight; root["Match"].Get(PWIGHT,itmPWight); neb::CJsonObject itmPHeight; root["Match"].Get(PHEIGHT,itmPHeight); neb::CJsonObject itmMatchPath; if (!root["Match"][MATCHPATH].IsEmpty()) { root["Match"].Get(MATCHPATH,itmMatchPath); } for (int i=0;i