#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 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); }