123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- #include "CameraBind.h"
- #include "common/JLogAllOutput.h"
- #include "OriginalWnd/JOriginalMainWnd.h"
- #pragma comment(lib,"JSMotion.lib")
- #pragma comment(lib,"JVisionLib.lib")
- #pragma comment(lib,"CLog.lib")
- #pragma comment(lib,"Module.lib")
- #pragma comment(lib,"Control.lib")
- /**图像窗口放置区域
- */
- static JOriginalMainWnd* g_pImageWnd = nullptr;
- CameraBind::CameraBind()
- {
- InitAllCamera();
- }
- CameraBind::~CameraBind()
- {
- // m_pCViewInterface = nullptr;
- }
- void CameraBind::SetImageWnd(QWidget* pImageWnd)
- {
- g_pImageWnd = (JOriginalMainWnd*)pImageWnd;
- }
- void CameraBind::InitAllCamera()
- {
- m_pCViewInterface.reset(ns_module::CViewInterface::GetInstance());
- if (m_pCViewInterface == nullptr)
- {
- JLogAllOutput::cmd_debug("相机初始化失败");
- return;
- }
- //获取相机列表
- m_pCViewInterface->GetCameraList(m_vecCamera);
- m_vecCAxis = m_pCViewInterface->GetAxisList();
- // 注册相机回调
- std::vector<CallVideoBack> veCallBack;
- /*#define OnFrameCallbackFun(int iCameraId, ImageInfo imageData) \
- OnFrameCallbackFun##(int iCameraId, ImageInfo imageData)*/
- veCallBack.push_back(OnFrameCallbackFun0);//TODO: 可以继续封装?
- veCallBack.push_back(OnFrameCallbackFun1);
- veCallBack.push_back(OnFrameCallbackFun2);
- veCallBack.push_back(OnFrameCallbackFun3);
- veCallBack.push_back(OnFrameCallbackFun4);
- for (int i = 0; i < m_vecCamera.size(); i++)
- {
- if (m_pCViewInterface)
- {
- m_pCViewInterface->SetVideoCallBackFunc(m_vecCamera[i].iCameraId /*CameraList::BondLowCamera*/,
- veCallBack[i]);
- }
- else
- {
- JLogAllOutput::cmd_debug("相机回调注册失败%d!\n", i);
- }
- }
- }
- void CameraBind::SetModuleMove(const std::string& strModuleType, const std::string& enAxisType, double pos, bool bMoveTo)
- {
- if (m_pCViewInterface == nullptr)
- {
- return;
- }
- for (auto& a : m_vecCAxis)
- {
- if (a->GetModuleType() == strModuleType)
- {
- if (bMoveTo)
- {
- m_pCViewInterface->ModuleMoveTo(strModuleType, enAxisType, pos);
- }
- else
- {
- m_pCViewInterface->ModuleMove(strModuleType, enAxisType, pos);
- }
-
- return;
- }
- }
- }
- void CameraBind::JToHome()
- {
- if (m_pCViewInterface == nullptr)
- {
- return;
- }
- m_pCViewInterface->ToHome();
- }
- CXYCalib* CameraBind::YGetCalibXY(int iCameraId)
- {
- // m_pCViewInterface->GetCalibXY(iCameraId);
- return {};
- }
- long CameraBind::OnFrameCallbackFun0(int iCameraId, JVision::ImageInfo imageData)
- {
- if (g_pImageWnd)
- {
- g_pImageWnd->UpdateCameraDisplay0(iCameraId, imageData);
- }
- return 0;
- }
- long CameraBind::OnFrameCallbackFun1(int iCameraId, JVision::ImageInfo imageData)
- {
- if (g_pImageWnd)
- {
- g_pImageWnd->UpdateCameraDisplay1(iCameraId, imageData);
- }
-
- return 0;
- }
- long CameraBind::OnFrameCallbackFun2(int iCameraId, JVision::ImageInfo imageData)
- {
- if (g_pImageWnd)
- {
- g_pImageWnd->UpdateCameraDisplay2(iCameraId, imageData);
- }
- return 0;
- }
- long CameraBind::OnFrameCallbackFun3(int iCameraId, JVision::ImageInfo imageData)
- {
- if (g_pImageWnd)
- {
- g_pImageWnd->UpdateCameraDisplay3(iCameraId, imageData);
- }
- return 0;
- }
- long CameraBind::OnFrameCallbackFun4(int iCameraId, JVision::ImageInfo imageData)
- {
- if (g_pImageWnd)
- {
- g_pImageWnd->UpdateCameraDisplay4(iCameraId, imageData);
- }
- return 0;
- }
- void CameraBind::SendImage(int iCameraId, ImageInfo imageData)
- {
- emit SendImageDispSignal(iCameraId, imageData);
- }
- void CameraBind::JSetRedLight(int iCameraId, EN_LIGHT_INDEX nLightIndex, int LightValue)
- {
- if (m_pCViewInterface == nullptr)
- {
- return;
- }
- switch (nLightIndex)
- {
- case EN_LIGHT_INDEX::Red:
- {
- m_pCViewInterface->SetRedLight(iCameraId, LightValue);
- }
- break;
- case EN_LIGHT_INDEX::Green:
- {
- m_pCViewInterface->SetGreenLight(iCameraId, LightValue);
- }
- break;
- case EN_LIGHT_INDEX::Blue:
- {
- m_pCViewInterface->SetBlueLight(iCameraId, LightValue);
- }
- break;
- case EN_LIGHT_INDEX::Point:
- {
- m_pCViewInterface->SetPointLight(iCameraId, LightValue);
- }
- break;
- default:
- break;
- }
- }
- ST_LIGHT_VAL CameraBind::JGetLight(int iCameraId)
- {
- if (m_pCViewInterface == nullptr)
- {
- return {};
- }
- ST_LIGHT_VAL _val = {};
- m_pCViewInterface->GetLight(iCameraId,
- _val.redLightValue,
- _val.greenLightValue,
- _val.blueLightValue,
- _val.pointLightValue);
- return _val;
- }
- long CameraBind::YGetAxisPosition(std::string ModuleType, std::string AxisType, double& pos)
- {
- if (m_pCViewInterface == nullptr)
- {
- return -1;
- }
- return m_pCViewInterface->GetAxisPosition(ModuleType, AxisType, pos);
- }
- long CameraBind::JRunButton(const ns_module::ST_BUTTON_FUN stInfo)
- {
- if (m_pCViewInterface == nullptr)
- {
- return -1;
- }
- return m_pCViewInterface->RunButton(stInfo);
- }
- long CameraBind::JRunStop()
- {
- if (m_pCViewInterface == nullptr)
- {
- return -1;
- }
- return m_pCViewInterface->RunStop();
- }
- long CameraBind::JRunAutoBond()
- {
- if (m_pCViewInterface == nullptr)
- {
- return -1;
- }
- return m_pCViewInterface->RunAutoBond();
- }
- long CameraBind::JViewExit()
- {
- if (m_pCViewInterface == nullptr)
- {
- return -1;
- }
- return m_pCViewInterface->ViewExit();
- }
- long CameraBind::JCameraMove(int iCameraId, double x, double y)
- {
- if (m_pCViewInterface == nullptr)
- {
- return -1;
- }
- return m_pCViewInterface->CameraMove(iCameraId, x, y);
- }
|