CameraBind.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #include "CameraBind.h"
  2. #include "common/JLogAllOutput.h"
  3. #include "OriginalWnd/JOriginalMainWnd.h"
  4. #pragma comment(lib,"JSMotion.lib")
  5. #pragma comment(lib,"JVisionLib.lib")
  6. #pragma comment(lib,"CLog.lib")
  7. #pragma comment(lib,"Module.lib")
  8. #pragma comment(lib,"Control.lib")
  9. /**图像窗口放置区域
  10. */
  11. static JOriginalMainWnd* g_pImageWnd = nullptr;
  12. CameraBind::CameraBind()
  13. {
  14. InitAllCamera();
  15. }
  16. CameraBind::~CameraBind()
  17. {
  18. // m_pCViewInterface = nullptr;
  19. }
  20. void CameraBind::SetImageWnd(QWidget* pImageWnd)
  21. {
  22. g_pImageWnd = (JOriginalMainWnd*)pImageWnd;
  23. }
  24. void CameraBind::InitAllCamera()
  25. {
  26. m_pCViewInterface.reset(ns_module::CViewInterface::GetInstance());
  27. if (m_pCViewInterface == nullptr)
  28. {
  29. JLogAllOutput::cmd_debug("相机初始化失败");
  30. return;
  31. }
  32. //获取相机列表
  33. m_pCViewInterface->GetCameraList(m_vecCamera);
  34. m_vecCAxis = m_pCViewInterface->GetAxisList();
  35. // 注册相机回调
  36. std::vector<CallVideoBack> veCallBack;
  37. /*#define OnFrameCallbackFun(int iCameraId, ImageInfo imageData) \
  38. OnFrameCallbackFun##(int iCameraId, ImageInfo imageData)*/
  39. veCallBack.push_back(OnFrameCallbackFun0);//TODO: 可以继续封装?
  40. veCallBack.push_back(OnFrameCallbackFun1);
  41. veCallBack.push_back(OnFrameCallbackFun2);
  42. veCallBack.push_back(OnFrameCallbackFun3);
  43. veCallBack.push_back(OnFrameCallbackFun4);
  44. for (int i = 0; i < m_vecCamera.size(); i++)
  45. {
  46. if (m_pCViewInterface)
  47. {
  48. m_pCViewInterface->SetVideoCallBackFunc(m_vecCamera[i].iCameraId /*CameraList::BondLowCamera*/,
  49. veCallBack[i]);
  50. }
  51. else
  52. {
  53. JLogAllOutput::cmd_debug("相机回调注册失败%d!\n", i);
  54. }
  55. }
  56. }
  57. void CameraBind::SetModuleMove(const std::string& strModuleType, const std::string& enAxisType, double pos, bool bMoveTo)
  58. {
  59. if (m_pCViewInterface == nullptr)
  60. {
  61. return;
  62. }
  63. for (auto& a : m_vecCAxis)
  64. {
  65. if (a->GetModuleType() == strModuleType)
  66. {
  67. if (bMoveTo)
  68. {
  69. m_pCViewInterface->ModuleMoveTo(strModuleType, enAxisType, pos);
  70. }
  71. else
  72. {
  73. m_pCViewInterface->ModuleMove(strModuleType, enAxisType, pos);
  74. }
  75. return;
  76. }
  77. }
  78. }
  79. void CameraBind::JToHome()
  80. {
  81. if (m_pCViewInterface == nullptr)
  82. {
  83. return;
  84. }
  85. m_pCViewInterface->ToHome();
  86. }
  87. CXYCalib* CameraBind::YGetCalibXY(int iCameraId)
  88. {
  89. // m_pCViewInterface->GetCalibXY(iCameraId);
  90. return {};
  91. }
  92. long CameraBind::OnFrameCallbackFun0(int iCameraId, JVision::ImageInfo imageData)
  93. {
  94. if (g_pImageWnd)
  95. {
  96. g_pImageWnd->UpdateCameraDisplay0(iCameraId, imageData);
  97. }
  98. return 0;
  99. }
  100. long CameraBind::OnFrameCallbackFun1(int iCameraId, JVision::ImageInfo imageData)
  101. {
  102. if (g_pImageWnd)
  103. {
  104. g_pImageWnd->UpdateCameraDisplay1(iCameraId, imageData);
  105. }
  106. return 0;
  107. }
  108. long CameraBind::OnFrameCallbackFun2(int iCameraId, JVision::ImageInfo imageData)
  109. {
  110. if (g_pImageWnd)
  111. {
  112. g_pImageWnd->UpdateCameraDisplay2(iCameraId, imageData);
  113. }
  114. return 0;
  115. }
  116. long CameraBind::OnFrameCallbackFun3(int iCameraId, JVision::ImageInfo imageData)
  117. {
  118. if (g_pImageWnd)
  119. {
  120. g_pImageWnd->UpdateCameraDisplay3(iCameraId, imageData);
  121. }
  122. return 0;
  123. }
  124. long CameraBind::OnFrameCallbackFun4(int iCameraId, JVision::ImageInfo imageData)
  125. {
  126. if (g_pImageWnd)
  127. {
  128. g_pImageWnd->UpdateCameraDisplay4(iCameraId, imageData);
  129. }
  130. return 0;
  131. }
  132. void CameraBind::SendImage(int iCameraId, ImageInfo imageData)
  133. {
  134. emit SendImageDispSignal(iCameraId, imageData);
  135. }
  136. void CameraBind::JSetRedLight(int iCameraId, EN_LIGHT_INDEX nLightIndex, int LightValue)
  137. {
  138. if (m_pCViewInterface == nullptr)
  139. {
  140. return;
  141. }
  142. switch (nLightIndex)
  143. {
  144. case EN_LIGHT_INDEX::Red:
  145. {
  146. m_pCViewInterface->SetRedLight(iCameraId, LightValue);
  147. }
  148. break;
  149. case EN_LIGHT_INDEX::Green:
  150. {
  151. m_pCViewInterface->SetGreenLight(iCameraId, LightValue);
  152. }
  153. break;
  154. case EN_LIGHT_INDEX::Blue:
  155. {
  156. m_pCViewInterface->SetBlueLight(iCameraId, LightValue);
  157. }
  158. break;
  159. case EN_LIGHT_INDEX::Point:
  160. {
  161. m_pCViewInterface->SetPointLight(iCameraId, LightValue);
  162. }
  163. break;
  164. default:
  165. break;
  166. }
  167. }
  168. ST_LIGHT_VAL CameraBind::JGetLight(int iCameraId)
  169. {
  170. if (m_pCViewInterface == nullptr)
  171. {
  172. return {};
  173. }
  174. ST_LIGHT_VAL _val = {};
  175. m_pCViewInterface->GetLight(iCameraId,
  176. _val.redLightValue,
  177. _val.greenLightValue,
  178. _val.blueLightValue,
  179. _val.pointLightValue);
  180. return _val;
  181. }
  182. long CameraBind::YGetAxisPosition(std::string ModuleType, std::string AxisType, double& pos)
  183. {
  184. if (m_pCViewInterface == nullptr)
  185. {
  186. return -1;
  187. }
  188. return m_pCViewInterface->GetAxisPosition(ModuleType, AxisType, pos);
  189. }
  190. long CameraBind::JRunButton(const ns_module::ST_BUTTON_FUN stInfo)
  191. {
  192. if (m_pCViewInterface == nullptr)
  193. {
  194. return -1;
  195. }
  196. return m_pCViewInterface->RunButton(stInfo);
  197. }
  198. long CameraBind::JRunStop()
  199. {
  200. if (m_pCViewInterface == nullptr)
  201. {
  202. return -1;
  203. }
  204. return m_pCViewInterface->RunStop();
  205. }
  206. long CameraBind::JRunAutoBond()
  207. {
  208. if (m_pCViewInterface == nullptr)
  209. {
  210. return -1;
  211. }
  212. return m_pCViewInterface->RunAutoBond();
  213. }
  214. long CameraBind::JViewExit()
  215. {
  216. if (m_pCViewInterface == nullptr)
  217. {
  218. return -1;
  219. }
  220. return m_pCViewInterface->ViewExit();
  221. }
  222. long CameraBind::JCameraMove(int iCameraId, double x, double y)
  223. {
  224. if (m_pCViewInterface == nullptr)
  225. {
  226. return -1;
  227. }
  228. return m_pCViewInterface->CameraMove(iCameraId, x, y);
  229. }