You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

550 lines
19 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
7 years ago
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "RangeMapWidget.h"
  2. #include "../../components/base/basicCameraPTZ.h"
  3. RangeMapWidget::RangeMapWidget(QWidget *parent) : QWidget(parent), targetDisplay(), m_mImageLock(){
  4. m_dScaleFactor = 1.f;
  5. //setStyleSheet(QString::fromUtf8("border: 1px;"));
  6. setContentsMargins(0, 0, 0, 0);
  7. m_pVerticalLayout = new QVBoxLayout(this);
  8. m_pVerticalLayout->setSpacing(0);
  9. setLayout(m_pVerticalLayout);
  10. setMinimumSize(400, 325);
  11. setMaximumSize(2304, 325);
  12. setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
  13. setCursor(QCursor(Qt::CrossCursor));
  14. m_pScrollArea = new QScrollArea(parent);
  15. //m_pScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  16. m_pScrollArea->setMinimumSize(400, 310);
  17. m_pScrollArea->setMaximumSize(2304, 310);
  18. m_pScrollArea->setBackgroundRole(QPalette::Dark);
  19. m_pImageLabel = new QLabel();
  20. m_pImageLabel->setBackgroundRole(QPalette::Base);
  21. m_pImageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
  22. m_pImageLabel->setGeometry(0, 0, 2304, 288);
  23. m_pImageLabel->setScaledContents(true);
  24. m_pScrollArea->setWidget(m_pImageLabel);
  25. m_pScrollArea->viewport()->installEventFilter(this);
  26. m_pScrollArea->setMouseTracking( true );
  27. m_pVerticalLayout->addWidget(m_pScrollArea);
  28. m_bShowMinimums = true;
  29. m_pOpLabel = new QLabel(this);
  30. m_pOpLabel->setText(QString::fromUtf8(""));
  31. m_pOpLabel->setAutoFillBackground(false);
  32. m_pOpLabel->setGeometry(QRect(250, 440, 220, 13));
  33. m_pStatusTimer = new QTimer(this);
  34. if (m_pStatusTimer != NULL){
  35. connect(m_pStatusTimer, &QTimer::timeout, this, &RangeMapWidget::handleTimer);
  36. m_pStatusTimer->start(300);
  37. };
  38. m_nCursorX = -1;
  39. m_nCursorY = -1;
  40. //setVisible(false);
  41. //setMouseTracking( true );
  42. //m_pScrollArea->grabMouse();
  43. m_oImage = QImage(BASE_SCAN_COUNT*KERNEL_COUNT, Q_SCAN_COUNT+1, QImage::Format_RGB888 );
  44. m_oImage.fill(QColor(255, 255, 255));
  45. //m_oImage = QImage("rm_bgr.png");
  46. //setImage( m_oImage );
  47. m_pRanges = NULL;
  48. m_nRangesCount = 0;
  49. m_pDeviceControl = NULL;
  50. m_fMaxRange = 300.f;
  51. m_bCurrentMouseMode = 0; // No Mode;
  52. //loadPolygons("polygons.ply");
  53. //loadFromFile("test.raw");
  54. //https://www.ebay.com/itm/KKMOON-16CH-960H-D1-CCTV-Network-Standalone-H-264-HD-DVR-Security-System-Z5Z4-/161965230971
  55. //https://www.ebay.com/itm/KKmoon-1080P-PTZ-CCTV-Camera-IR-Day-Night-2MP-AHD-2-8-12mm-Auto-Focus-IP66-P1F5/112672024175
  56. //https://www.ebay.com/itm/KKMOON-960P-AHD-CCTV-CAMERA-1-3MP-HD-ANALOG-OUTDOOR-SECURITY-BULLET-METAL-Z9M4/322419271266
  57. m_pPoint = NULL;
  58. //m_mImageLock.unlock();
  59. updateBackStage();
  60. updateDisplay();
  61. };
  62. RangeMapWidget::~RangeMapWidget(){
  63. };
  64. void RangeMapWidget::updateBackStage(void){
  65. m_mImageLock.lock();
  66. try {
  67. int x, y, Range, mid, seg;
  68. uint32_t color;
  69. //QPainter painter;
  70. if (1){//painter.begin(&m_oImage)){
  71. m_oImage.fill(QColor(0, 0, 0));
  72. for (int index = 0; index < m_nRangesCount; index++){
  73. if (m_bShowMinimums){
  74. Range = m_pRanges[index].values.min;
  75. makeCoords(Range, index, x, y, mid, seg, true);
  76. #ifdef MIRROR_DIFF_COLORS
  77. switch( mid ){
  78. case 0: color = interpolate(0xFFFFFF00, 0xFF000000, RangeA / 4095.f); break;
  79. case 1: color = interpolate(0xFF00FFFF, 0xFF000000, RangeA / 4095.f); break;
  80. case 2: color = interpolate(0xFFFF00FF, 0xFF000000, RangeA / 4095.f); break;
  81. case 3: color = interpolate(0xFFFFFFFF, 0xFF000000, RangeA / 4095.f); break;
  82. };
  83. #else
  84. if (m_pRanges[index].values.cnt){
  85. color = interpolate(0xFFFFFFFF, 0xFF000000, ((float)(Range)) / 4096.f);
  86. } else color = 0xFF0000FF;
  87. #endif
  88. m_oImage.setPixel(x, y, color);
  89. //painter.drawPoint( x, y );
  90. } else {
  91. Range = m_pRanges[index].values.max;
  92. makeCoords(Range, index, x, y, mid, seg, true);
  93. #ifdef MIRROR_DIFF_COLORS
  94. switch( mid ){
  95. case 0: color = interpolate(0xFFFFFF00, 0xFF000000, RangeA / 4095.f); break;
  96. case 1: color = interpolate(0xFF00FFFF, 0xFF000000, RangeA / 4095.f); break;
  97. case 2: color = interpolate(0xFFFF00FF, 0xFF000000, RangeA / 4095.f); break;
  98. case 3: color = interpolate(0xFFFFFFFF, 0xFF000000, RangeA / 4095.f); break;
  99. };
  100. #else
  101. if (m_pRanges[index].values.cnt){
  102. color = interpolate(0xFFFFFFFF, 0xFF000000, ((float)(Range)) / 4096.f);
  103. } else color = 0xFF0000FF;
  104. #endif
  105. m_oImage.setPixel(x, y, color);
  106. //painter.drawPoint( x, y );
  107. };
  108. };
  109. //painter.end();
  110. };
  111. } catch ( exception e ){};
  112. m_mImageLock.unlock();
  113. };
  114. void RangeMapWidget::updateDisplay( void ){
  115. m_mImageLock.lock();
  116. try{
  117. m_oPixmap = QPixmap::fromImage(m_oImage);
  118. char tBuf[64];
  119. QPainter painter;
  120. if (painter.begin(&m_oPixmap)){
  121. painter.setRenderHint((QPainter::RenderHint)7);// QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing
  122. QPen BgPen(Qt::SolidPattern, 2);
  123. BgPen.setColor(QColor(255, 0, 255, 255));
  124. painter.setPen(BgPen);
  125. int Y1, Y2;
  126. Y1 = Q_SCAN_COUNT - ((Q_SCAN_COUNT*Q_SHIFT_DOWN_FOV) / Q_DEGREE_FOV);
  127. Y2 = Q_SCAN_COUNT - ((Q_SCAN_COUNT*(Q_SHIFT_DOWN_FOV + 90.f)) / Q_DEGREE_FOV);
  128. painter.drawLine(0, Y1, 2304, Y1);
  129. painter.drawLine(0, Y2, 2304, Y2);
  130. float k = 2304.f / 36.f;
  131. int cX;
  132. for (int i = 0; i < 36; i++){
  133. cX = k * i;
  134. painter.drawLine(cX, 0, cX, 288);
  135. sprintf(tBuf, "%d", 360 - (i * 10));
  136. painter.drawText(QRect(cX + 5, Y1 + 1, cX + 15, Y1 + 6), Qt::AlignLeft | Qt::AlignBaseline, tBuf);
  137. };
  138. // Draw Targets
  139. for (uint8_t index = 0; index < MAX_SIMUL_TARGETS; index++){
  140. if (m_aTargets[index].status != 0){
  141. painter.fillRect(m_aTargets[index].dX - 2, m_aTargets[index].dY - 2, 5, 5, m_aTargets[index].color);// QColor( 255, 0, 0 ) );
  142. }
  143. else break;
  144. };
  145. if (m_pDeviceControl != NULL){
  146. if (m_vAllPoly.size()){
  147. //BgPen.setColor(QColor( 0, 255, 0 ));
  148. //painter.setBrush(QColor( 0, 128, 0, 180 ));
  149. //painter.setPen( BgPen );
  150. for (vectorMasking::iterator index = m_vAllPoly.begin(); index < m_vAllPoly.end(); index++){
  151. BgPen.setColor(QColor((*index)->color[0] | 0x80, (*index)->color[1] | 0x80, (*index)->color[2] | 0x80));
  152. painter.setBrush(QColor((*index)->color[0], (*index)->color[1], (*index)->color[2], 180));
  153. //BgPen.setColor(QColor(0xFF, 0x00, 0xFF ));
  154. //painter.setBrush(QColor(0x7F, 0x00, 0x7F, 0x7F ));
  155. painter.setPen(BgPen);
  156. painter.drawPolygon((*index)->points, (*index)->count);
  157. };
  158. };
  159. // draw Edited Poly
  160. if (m_bCurrentMouseMode == 1){
  161. if (m_pNewPoly != NULL){
  162. if (m_pNewPoly->count) {
  163. BgPen.setColor(QColor(255, 0, 0));
  164. painter.setBrush(QColor(180, 0, 0, 255));
  165. painter.setPen(BgPen);
  166. painter.drawPolyline((QPoint *)m_pNewPoly->points, m_pNewPoly->count);
  167. };
  168. };
  169. };
  170. };
  171. painter.end();
  172. };
  173. m_pImageLabel->setPixmap(m_oPixmap);
  174. } catch (exception e){};
  175. m_mImageLock.unlock();
  176. //m_pImageLabel->adjustSize();
  177. //setVisible(true);
  178. //update();
  179. };
  180. void RangeMapWidget::savePicture( QString fname ){
  181. m_oImage.save( fname );
  182. };
  183. void RangeMapWidget::setMaximums( void ){
  184. m_bShowMinimums = false;
  185. if (m_nRangesCount > 0){
  186. updateBackStage();
  187. updateDisplay();
  188. };
  189. };
  190. void RangeMapWidget::setMinimums( void ){
  191. m_bShowMinimums = true;
  192. if (m_nRangesCount > 0){
  193. updateBackStage();
  194. updateDisplay();
  195. };
  196. };
  197. void RangeMapWidget::startGenerateWS( void ){
  198. int x, y, Range, mid, seg;
  199. int order, offset;
  200. uint32_t color, cNodeID, sNodeID;
  201. int cnt, cMax, cMin;
  202. thresholdNode tTN;
  203. m_oImage.fill( QColor(0,0,0));
  204. order = 3;
  205. offset = 32;
  206. Range=0;
  207. for( int index = 0; index < m_nRangesCount; index++ ){
  208. sNodeID = index - ( TH_LINE_NODES + 1 ) * order;
  209. tTN = m_pRanges[index];
  210. if( tTN.values.cnt ){
  211. cnt = 0;
  212. cMax = 0;
  213. cMin = 4095;
  214. for( int i = 0; i < (( order << 1 ) + 1 ); i++ ){
  215. cNodeID = sNodeID + ( i * TH_LINE_NODES );
  216. for( int j = 0; j < (( order << 1 ) + 1 ); j++ ){
  217. cNodeID ++;
  218. if( cNodeID < 0 ) continue;
  219. if( cNodeID < TH_SIZE_NODES ){
  220. tTN = m_pRanges[cNodeID];
  221. if( tTN.values.cnt != 0 ){
  222. if( cMax < tTN.values.max ) cMax = tTN.values.max;
  223. if( cMin > tTN.values.min ) cMin = tTN.values.min;
  224. cnt++;
  225. };
  226. };
  227. };
  228. };
  229. tTN.values.cnt = cnt;
  230. if( cMin > offset ) tTN.values.min = cMin - offset; else tTN.values.min = 0;
  231. if( cMax < ( 4095 - offset ) ) tTN.values.max = cMax + offset; else tTN.values.max = 4095;
  232. } else {
  233. // disable detection of that point
  234. tTN.values.cnt = 0;
  235. tTN.values.min = 0;
  236. tTN.values.max = 4095;
  237. };
  238. if( m_bShowMinimums ){
  239. Range = tTN.values.min;
  240. makeCoords( Range, index, x, y, mid, seg, true );
  241. #ifdef MIRROR_DIFF_COLORS
  242. switch( mid ){
  243. case 0: color = interpolate(0xFFFFFF00, 0xFF000000, RangeA / 4095.f); break;
  244. case 1: color = interpolate(0xFF00FFFF, 0xFF000000, RangeA / 4095.f); break;
  245. case 2: color = interpolate(0xFFFF00FF, 0xFF000000, RangeA / 4095.f); break;
  246. case 3: color = interpolate(0xFFFFFFFF, 0xFF000000, RangeA / 4095.f); break;
  247. };
  248. #else
  249. if( tTN.values.cnt )
  250. color = interpolate(0xFF00FF00, 0xFF000000, ((float)( Range )) / 4096.f);
  251. else
  252. color = 0xFFFF0000;
  253. #endif
  254. m_oImage.setPixel(x, y, color);
  255. } else {
  256. Range = tTN.values.max;
  257. makeCoords( Range, index, x, y, mid, seg, true );
  258. #ifdef MIRROR_DIFF_COLORS
  259. switch( mid ){
  260. case 0: color = interpolate(0xFFFFFF00, 0xFF000000, RangeA / 4095.f); break;
  261. case 1: color = interpolate(0xFF00FFFF, 0xFF000000, RangeA / 4095.f); break;
  262. case 2: color = interpolate(0xFFFF00FF, 0xFF000000, RangeA / 4095.f); break;
  263. case 3: color = interpolate(0xFFFFFFFF, 0xFF000000, RangeA / 4095.f); break;
  264. };
  265. #else
  266. if( tTN.values.cnt )
  267. color = interpolate(0xFF00FF00, 0xFF000000, ((float)( Range )) / 4096.f);
  268. else
  269. color = 0xFFFF0000;
  270. #endif
  271. m_oImage.setPixel(x, y, color);
  272. };
  273. };
  274. updateDisplay();
  275. };
  276. /*
  277. void RangeMapWidget::mouseMoveEvent(QMouseEvent* event) {
  278. qDebug() << QString::number(event->pos().x());
  279. qDebug() << QString::number(event->pos().y());
  280. };
  281. void RangeMapWidget::wheelEvent(QWheelEvent* event){
  282. // your own custom stuff
  283. // ...
  284. // if you handle the event and don't want it to
  285. // propagate any further, accept it:
  286. event->accept();
  287. };
  288. */
  289. bool RangeMapWidget::eventFilter(QObject* ZZ/*obj*/, QEvent* evt ){
  290. if( evt->type() == QEvent::MouseMove ){
  291. if( m_bCurrentMouseMode == 0 ){ // Check Values
  292. if( QApplication::mouseButtons()==Qt::LeftButton ){
  293. QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(evt);
  294. //qDebug() << QString::number(m_pScrollArea->horizontalScrollBar()->value()+mouseEvent->pos().x());
  295. //qDebug() << QString::number(m_pScrollArea->verticalScrollBar()->value()+mouseEvent->pos().y());
  296. //statusBar()->showMessage(QString("Mouse move (%1,%2)").arg(mouseEvent->pos().x()).arg(mouseEvent->pos().y()));
  297. m_nCursorX = m_pScrollArea->horizontalScrollBar()->value()+mouseEvent->pos().x();
  298. m_nCursorY = m_pScrollArea->verticalScrollBar()->value()+mouseEvent->pos().y();
  299. char tBuff[64];
  300. float tVal;
  301. int idx;
  302. idx = makeIdx( m_nCursorX, m_nCursorY );
  303. if (m_nRangesCount) {
  304. if (idx > 0 && idx < (m_nRangesCount - 1)) {
  305. tVal = m_fMaxRange * ((float)m_pRanges[idx].values.min) / 4096.f;
  306. sprintf(tBuff, "%.2f m.", tVal);
  307. //m_pStMiRaVal->setText(tBuff);
  308. sprintf(tBuff, "%d dig.", m_pRanges[idx].values.min);
  309. //m_pStMiSaVal->setText(tBuff);
  310. tVal = m_fMaxRange * ((float)m_pRanges[idx].values.max) / 4096.f;
  311. sprintf(tBuff, "%.2f m.", tVal);
  312. //m_pStMaRaVal->setText(tBuff);
  313. sprintf(tBuff, "%d dig.", m_pRanges[idx].values.max);
  314. //m_pStMaSaVal->setText(tBuff);
  315. //m_oPixmap = QPixmap::fromImage(m_oImage);
  316. //drawCords();
  317. };
  318. };
  319. //m_pImageLabel->setPixmap(m_oPixmap);
  320. if (m_pPoint == NULL){
  321. m_pPoint = new point2DWidget(m_pImageLabel);
  322. };
  323. m_pPoint->setMaxValues(BASE_SCAN_COUNT*KERNEL_COUNT, Q_SCAN_COUNT + 1);
  324. m_pPoint->create(m_nCursorX, m_nCursorY, "LIBERMAN", "DA!!!!");
  325. };
  326. };
  327. evt->ignore();
  328. };
  329. if( evt->type() == QEvent::MouseButtonPress ){
  330. if( m_bCurrentMouseMode == 2 ){ // Delete Poly
  331. QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(evt);
  332. m_nCursorX = m_pScrollArea->horizontalScrollBar()->value()+mouseEvent->pos().x();
  333. m_nCursorY = m_pScrollArea->verticalScrollBar()->value()+mouseEvent->pos().y();
  334. //Assign Polygones from Masking
  335. vector<QPolygon *> tPV;
  336. tPV.clear();
  337. for( int i = 0; i < m_vAllPoly.size(); i++ ){
  338. QPolygon *tPoly;
  339. tPoly = new QPolygon();
  340. if( tPoly != NULL ){
  341. tPoly->clear();
  342. for( int j = 0; j< m_vAllPoly.at( i )->count; j++ ){
  343. QPoint tPoint;
  344. tPoint.setX( m_vAllPoly.at( i )->points[j].x() );
  345. tPoint.setY( m_vAllPoly.at( i )->points[j].y() );
  346. tPoly->append(tPoint);
  347. };
  348. tPV.push_back( tPoly );
  349. };
  350. };
  351. for( int i = 0; i < tPV.size(); i++ ){
  352. if( tPV.at(i)->containsPoint( QPoint( m_nCursorX, m_nCursorY ), Qt::OddEvenFill) ){
  353. //free( m_vAllPoly.at( i )->points );
  354. //free( m_vAllPoly.at( i ) );
  355. if( m_pDeviceControl != NULL ){
  356. m_pDeviceControl->getMask()->deletePoly( i );
  357. };
  358. m_vAllPoly.erase( m_vAllPoly.begin() + i );
  359. m_vAllPoly.shrink_to_fit();
  360. m_bCurrentMouseMode = 0;
  361. m_pScrollArea->viewport()->setProperty("cursor", QVariant(QCursor(Qt::ArrowCursor)));
  362. updateDisplay();
  363. break;
  364. };
  365. };
  366. };
  367. evt->ignore();
  368. };
  369. if( evt->type() == QEvent::MouseButtonRelease ){
  370. if (m_bCurrentMouseMode == 0){
  371. QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(evt);
  372. m_nCursorX = m_pScrollArea->horizontalScrollBar()->value() + mouseEvent->pos().x();
  373. m_nCursorY = m_pScrollArea->verticalScrollBar()->value() + mouseEvent->pos().y();
  374. char tBuff1[64];
  375. char tBuff2[64];
  376. char tBuff3[64];
  377. float tVal;
  378. int idx;
  379. idx = makeIdx( m_nCursorX, m_nCursorY );
  380. if( idx > 0 && idx < ( m_nRangesCount -1 ) ) {
  381. if( m_nRangesCount > 0 && m_pRanges!= NULL ){
  382. tVal = m_fMaxRange * ((float) m_pRanges[idx].values.min )/ 4096.f;
  383. sprintf( tBuff1, "Min: %.2f m./ %d dig.", tVal, m_pRanges[idx].values.min );
  384. tVal = m_fMaxRange * ((float) m_pRanges[idx].values.max )/ 4096.f;
  385. sprintf( tBuff2, "Max: %.2f m./ %d dig.", tVal, m_pRanges[idx].values.max );
  386. } else {
  387. sprintf( tBuff1, "NO VALUES!");
  388. sprintf( tBuff2, "NO VALUES!");
  389. };
  390. if (m_pPoint == NULL){
  391. m_pPoint = new point2DWidget(m_pImageLabel);
  392. m_pPoint->setMaxValues(BASE_SCAN_COUNT*KERNEL_COUNT, Q_SCAN_COUNT + 1);
  393. m_pPoint->setAutoHide();
  394. };
  395. m_pPoint->create(m_nCursorX, m_nCursorY, tBuff1, tBuff2 );
  396. };
  397. };
  398. if( m_bCurrentMouseMode == 1 ){ // Add Poly
  399. QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(evt);
  400. m_nCursorX = m_pScrollArea->horizontalScrollBar()->value()+mouseEvent->pos().x();
  401. m_nCursorY = m_pScrollArea->verticalScrollBar()->value()+mouseEvent->pos().y();
  402. m_pNewPoly->points = (QPoint *) realloc( m_pNewPoly->points, ( m_pNewPoly->count+1 ) * sizeof(QPoint));
  403. m_pNewPoly->points[m_pNewPoly->count].setX( m_nCursorX );
  404. m_pNewPoly->points[m_pNewPoly->count].setY( m_nCursorY );
  405. m_pNewPoly->count++;
  406. updateDisplay();
  407. };
  408. evt->ignore();
  409. };
  410. if( evt->type() == QEvent::MouseButtonDblClick ){
  411. if( m_bCurrentMouseMode == 1 ){ // Add Poly
  412. m_vAllPoly.push_back( m_pNewPoly );
  413. //ToDo: Transfer New Poly to Device!
  414. if( m_pDeviceControl!= NULL ){
  415. m_pDeviceControl->getMask()->addPoly( m_pNewPoly );
  416. //for( int i = 0; i < m_pNewPoly->count; i++) m_pDeviceControl->getMask()->addVertex( m_vAllPoly.size(), m_pNewPoly->points[i] );
  417. };
  418. m_pNewPoly = NULL;
  419. m_bCurrentMouseMode = 0;
  420. m_pScrollArea->viewport()->setProperty("cursor", QVariant(QCursor(Qt::ArrowCursor)));
  421. //m_pButton5->setEnabled( true );
  422. //m_oPixmap = QPixmap::fromImage(m_oImage);
  423. //drawCords();
  424. //m_pImageLabel->setPixmap(m_oPixmap);
  425. updateDisplay();
  426. } else {
  427. QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(evt);
  428. m_nCursorX = m_pScrollArea->horizontalScrollBar()->value()+mouseEvent->pos().x();
  429. m_nCursorY = m_pScrollArea->verticalScrollBar()->value()+mouseEvent->pos().y();
  430. basicEvent *pEvt = NULL;
  431. basicCameraCommand *tData = NULL;
  432. C3D_DECART *tParam = NULL;
  433. tData = (basicCameraCommand*)malloc(sizeof(basicCameraCommand));
  434. if(tData!=NULL){
  435. tParam = (C3D_DECART*) malloc(sizeof(C3D_DECART));
  436. if( tParam!= NULL ){
  437. C3D_SPH_DEGREES tSph;
  438. tSph.fi = B_DEGREE_FOV - ( B_DEGREE_FOV * (C3D_FLOAT)m_nCursorX / 2304.f );
  439. tSph.tetta = 90.f - ((Q_DEGREE_FOV * (C3D_FLOAT)(288 - m_nCursorY)) / 288.f) + Q_SHIFT_DOWN_FOV;
  440. if (tSph.tetta < 0.f /* || tSph.tetta > 180.f */){
  441. tSph.tetta *= -1.f;
  442. tSph.fi += 180.f;
  443. } /* else if( tSph.tetta > 180.f ) tSph.fi += 180.f; */
  444. tSph.r = 10.f;
  445. if (m_pDeviceControl != NULL) {
  446. // Move relative to Device
  447. systemAnchor *SA = systemAnchor::getInstance();
  448. SA->convertToSystem(m_pDeviceControl->getPosition(), tSph, *tParam);
  449. } else {
  450. // Move relative to System Anchore
  451. spherical2decart(tSph, *tParam);
  452. };
  453. //char tBuffer[120];
  454. //sprintf( tBuffer, "Az: %0.3f El: %0.3f", tSph.fi, tSph.tetta );
  455. //QToolTip::showText( mouseEvent->globalPos(), QString(tBuffer) );
  456. tData->m_cCode = CMD_CAMERA_SET_PTZ;
  457. tData->m_pParam = tParam;
  458. pEvt = createBasicEvent( 0, EVT_CLASS_IMAGE, EVT_COMMAND, "GoPosition By Operator", tData );
  459. if( pEvt!= NULL){
  460. basicEventHeap::getInstance()->broadcast(pEvt);
  461. } else {
  462. free(tData);
  463. free(tParam);
  464. };
  465. } else {
  466. free( tData );
  467. };
  468. };
  469. };
  470. evt->ignore();
  471. };
  472. if( evt->type() == QEvent::Wheel ){
  473. // ignore the event (this effectively
  474. // makes it "skip" one object)
  475. evt->ignore();
  476. };
  477. // return false to continue event propagation
  478. // for all events
  479. return false;
  480. };
  481. void RangeMapWidget::setAddMaskMode( void ){
  482. if( m_bCurrentMouseMode != 1 ){
  483. m_pScrollArea->viewport()->setProperty("cursor", QVariant(QCursor(Qt::CrossCursor)));
  484. m_pNewPoly = (simplePolygone *) malloc(sizeof(simplePolygone));
  485. if( m_pNewPoly!= NULL ){
  486. m_pNewPoly->count = 0;
  487. m_pNewPoly->points = NULL;
  488. m_bCurrentMouseMode = 1;
  489. };
  490. };
  491. };
  492. void RangeMapWidget::setDeleteMaskMode( void ){
  493. if (m_vAllPoly.size()){
  494. m_pScrollArea->viewport()->setProperty("cursor", QVariant(QCursor(Qt::CrossCursor)));
  495. if (m_bCurrentMouseMode != 1) m_bCurrentMouseMode = 2; // Mode = Delete Poly
  496. };
  497. };
  498. void RangeMapWidget::attachLGS(objectLGS *ptr){
  499. m_pDeviceControl = ptr;
  500. if( m_pDeviceControl != NULL ){
  501. m_vAllPoly.clear();
  502. if( m_pDeviceControl->areMasksLoadded() ){
  503. if (m_pDeviceControl->getMask()->getMPoly(m_vAllPoly)){
  504. };
  505. };
  506. updateBackStage();
  507. updateDisplay();
  508. };
  509. };
  510. void RangeMapWidget::handleTimer(void){
  511. updateDisplay();
  512. };