#include "cmcam.h"
#include "ccamdriver.h"
CMCam::CMCam(const QString &name, int32_t id)
    :CCam(name,id)
{
}

CMCam::~CMCam()
{

}

int32_t CMCam::init_channel()
{
    CCam::init_channel();
    return RTN_SUCCESS1;
}

int32_t CMCam::exit_channel()
{
    return CCam::exit_channel();
}
#if 0
void CMCam::Serialize(QDataStream& stream,bool bwrite, int iVersion)
{
	//return CCam::Serialize(stream, bwrite);
	//NOTICE：以下为读取时采用的序列化数据的流程
	if(false == bwrite){
		MqDebug() << "Cam Name" << this->m_sName;
		QMap<int,Variant>::Iterator iter = m_Variants.m_mVariantMap.begin();
		for(;iter!=m_Variants.m_mVariantMap.end();iter++){
			//qDebug() << "Cam ID" << iter.key() << " " <<(*iter).m_sName<<" " << (*iter).m_vVar << " " << (*iter).m_iSerialStyle;
			QVariant var;
			if((*iter).m_iSerialStyle == TOFILE ||(*iter).m_iSerialStyle == TOBOTH ){
				stream>>var;
				MqDebug() <<(*iter).m_sName<< "var" <<(*iter).m_vVar<<" " <<var<< " "<< (*iter).m_iSerialStyle;
				(*iter).m_vVar = var;
			}else{
				int iSerialStyle = (*iter).m_iSerialStyle;
				MqDebug() <<(*iter).m_sName<< "var" <<(*iter).m_vVar<<" " <<var << " "<< iSerialStyle << " " << (*iter).m_iID;
			}
		}

		//算法是固定的几个算法，如果相机的固定算法变了，则所有的Recipe都会出问题
		QMap<int32_t,CAlgorithm*>::iterator iterAlgorithm =  malgorithms.begin();
		for(;iterAlgorithm!=malgorithms.end();iterAlgorithm++){
			iter = (*iterAlgorithm)->m_Variants.m_mVariantMap.begin();
			MqDebug() << "Algorithm Name" <<  (*iterAlgorithm)->m_sName;

			//if((*iterAlgorithm)->m_iID == M_KERF_HALFCUT){
			//	continue;
			//}
			//if((*iterAlgorithm)->m_iID == M_KERF_LASER){
			//	continue;
			//}
			for(;iter!=(*iterAlgorithm)->m_Variants.m_mVariantMap.end();iter++){
				//qDebug() << "Algorithm ID" << iter.key() << " " <<(*iter).m_sName<<" " << (*iter).m_vVar << " " << (*iter).m_iSerialStyle;
				QVariant var;
				if((*iter).m_iSerialStyle == TOFILE || (*iter).m_iSerialStyle == TOBOTH){
					stream>>var;
					MqDebug() <<(*iter).m_sName<< "var" <<(*iter).m_vVar<<" " <<var << " " <<(*iter).m_iSerialStyle;
					(*iter).m_vVar = var;
				}else{
					int iSerialStyle = (*iter).m_iSerialStyle;
					MqDebug() <<(*iter).m_sName<< "var" <<(*iter).m_vVar<<" " <<var << " "<< iSerialStyle;
				}
			}

			//m_lMorphology根据数据来确定的
			int count;
			stream>>count;
			MqDebug()<<"Morphology Count:"<<count;

			(*iterAlgorithm)->ClearMorphology();
			for(int i=0;i<count;i++)
			{
				CAMorphology* pMorphology=new CAMorphologyExternal(QObject::trUtf8("Morphology"),0);

				pMorphology->Serialize(stream, bwrite, iVersion);

				double param1 = 0;
				if((*iterAlgorithm)->m_iID == M_KERFCHECK){
					pMorphology->m_Variants.get_VData(Var_Morphology_Height_ID)->setValue(255.0);
					param1= pMorphology->m_Variants.get_VData(Var_Morphology_Thres_ID)->toDouble();
				}
				if((*iterAlgorithm)->m_iID == M_KERF_HALFCUT){
					pMorphology->m_Variants.get_VData(Var_Morphology_Height_ID)->setValue(255.0);
				}
				if((*iterAlgorithm)->m_iID == M_KERF_LASER){
					pMorphology->m_Variants.get_VData(Var_Morphology_Height_ID)->setValue(255.0);
				}

				(*iterAlgorithm)->m_lMorphology.push_back(pMorphology);
				/*iter = pMorphology->m_Variants.m_mVariantMap.begin();
				QVariant var;
				for(;iter!=pMorphology->m_Variants.m_mVariantMap.end();iter++)
				{
					if((*iter).m_iSerialStyle == 3){
						stream>>var;
						qDebug() <<(*iter).m_sName<< "var" <<(*iter).m_vVar<<" " <<var;
						(*iter).m_vVar = var;
					}
				}*/
			}
		
		//}

		}

		//最后这个4字节数据不知道存的是什么内容
		uint32_t dVal = 10;
		stream>>dVal;
		MqDebug() << "----" << dVal;

		if(!bwrite)
			return;
	}else{		
		//写入本地变量
		QMap<int,Variant>::Iterator iter = m_Variants.m_mVariantMap.begin();
		for(;iter!=m_Variants.m_mVariantMap.end();iter++){
			if((*iter).m_iSerialStyle == TOFILE ||(*iter).m_iSerialStyle == TOBOTH ){
				stream<<(*iter).m_vVar;
			}else{
				MqDebug() <<(*iter).m_sName<< "var" <<(*iter).m_vVar<<" " << (*iter).m_iSerialStyle << " " << (*iter).m_iID;
			}
		}

		//算法是固定的几个算法，如果相机的固定算法变了，则所有的Recipe都会出问题
		QMap<int32_t,CAlgorithm*>::iterator iterAlgorithm =  malgorithms.begin();
		for(;iterAlgorithm!=malgorithms.end();iterAlgorithm++){
			iter = (*iterAlgorithm)->m_Variants.m_mVariantMap.begin();

			//if((*iterAlgorithm)->m_iID == M_KERF_HALFCUT){
			//	continue;
			//}
			//if((*iterAlgorithm)->m_iID == M_KERF_LASER){
			//	continue;
			//}


			for(;iter!=(*iterAlgorithm)->m_Variants.m_mVariantMap.end();iter++){
				if((*iter).m_iSerialStyle == TOFILE || (*iter).m_iSerialStyle == TOBOTH){
					MqDebug() <<(*iter).m_sName<< "var" <<(*iter).m_vVar<<" " <<(*iter).m_iSerialStyle;
					stream<<(*iter).m_vVar;
				}else{
					MqDebug() <<(*iter).m_sName<< "var" <<(*iter).m_vVar<<" " << (*iter).m_iSerialStyle;
				}
			}

			//m_lMorphology根据数据来确定的
			int count = (*iterAlgorithm)->m_lMorphology.size();
			stream<<count;
			for(int i=0;i<count;i++)
			{
				double param1 = 0;
				CAMorphology* pMorphology=(*iterAlgorithm)->m_lMorphology[i];
				if((*iterAlgorithm)->m_iID == M_KERFCHECK){
					pMorphology->m_Variants.get_VData(Var_Morphology_Height_ID)->setValue(255.0);
					param1= pMorphology->m_Variants.get_VData(Var_Morphology_Thres_ID)->toDouble();
				}
				
				pMorphology->Serialize(stream, bwrite, iVersion);
			}
		}

		//最后这个4字节数据不知道存的是什么内容
		//uint32_t dVal = 10;
		stream<<0;
		//qDebug() << "----" << dVal;
		return;
	}

	return CCam::Serialize(stream, bwrite, iVersion);
	//用于生成recipe的参数
	if(bwrite){
		CCam::Serialize(stream, bwrite, iVersion);
	}else{
		if(m_iID != CAMKerf){
			CCam::Serialize(stream, bwrite, iVersion);
		}
	}
}

#endif