text: #include "ReplayView.h"
  #include "ui_ReplayView.h"
  
  #include <QWebFrame>
  
  #include <opencv2/opencv.hpp>
  
  ReplayView::ReplayView(QWidget *parent) :
  	QDockWidget(parent),
  	ui(new Ui::ReplayView)
  {
  	ui->setupUi(this);
  
  	ui->webView->setUrl(QUrl::fromLocalFile(QFileInfo("/usr/local/src/stryx-mms_capturehw_1.0.0/Resources/map/naver/naver_map.html").absoluteFilePath()));
  	connect(ui->webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJSObject()));
  
  	ui->openGLWidget->initGLList(100,2);
  }
  
  ReplayView::~ReplayView()
  {
  	delete ui;
  }
  
  void ReplayView::addPoint(double lat, double lng)
  {
  	_naverMapHandler.addPointNColor(3, lat, lng, "BLACK");
  }
  
  void ReplayView::setImageCount(int count)
  {
  	if(_imageUnit.empty() == false)
  	{
  		for(int i = 0; i < (int)_imageUnit.size(); i++)
  		{
  			ui->g_layout_image->removeWidget(_imageUnit[i]);
  			delete _imageUnit[i];
  		}
  		_imageUnit.clear();
  	}
  
  
  	for(int i = 0; i < count; i++)
  	{
  		_imageUnit.push_back(new ImageUnit());
  		if(count % 2 == 0 && count / 2 > 1)
  		{
  			ui->g_layout_image->addWidget(_imageUnit.back(), i/2, i%2, 1, 1);
  		}
  		else
  		{
  			ui->g_layout_image->addWidget(_imageUnit.back(), i, 0, 1, 1);
  		}
  		connect(this, SIGNAL(sendDraw(uchar*,int,int,QWidget*)),    _imageUnit.back(), SLOT(recvDraw(uchar*,int,int,QWidget*)));
  		_imageUnit.back()->setTitle(QString().sprintf("Image[%02d]", i));
  	}
  
  
  	_unitCount = count;
  	_beforePath.resize(count);
  }
  
  void ReplayView::addPCD(std::deque<POINT_TYPE::XYZRGBT> pcd)
  {
  	if(pcd.empty() != true)
  	{
  		ui->openGLWidget->addPoint(pcd);
  	}
  }
  
  void ReplayView::pushPcd(std::deque<POINT_TYPE::XYZRGBT> pcd, MARKPVA pos)
  {
  	if(pcd.empty() == true)
  	{
  		return;
  	}
  	movement move;
  	double x, y;
  	PosHandler().LatLonToUTMXY(pos.lat, pos.lon, 0, x, y);
  	move.transrationX = x - _x;
  	move.transrationY = y - _y;
  	move.transrationZ = pos.height - _z;
  
  	move.rotationX = pos.roll;
  	move.rotationY = pos.pitch;
  	move.rotationZ = -pos.azimuth;
  	ui->openGLWidget->pushPCDList(pcd, move);
  }
  
  void ReplayView::setPCD()
  {
  	ui->openGLWidget->setPoint();
  }
  
  void ReplayView::updatePCD(std::deque<POINT_TYPE::XYZRGBT> pcd)
  {
  	if(pcd.empty() != true)
  	{
  		ui->openGLWidget->updatePoint(pcd);
  	}
  }
  
  void ReplayView::initPos(double x, double y, double z)
  {
  	this->_x = x;
  	this->_y = y;
  	this->_z = z;
  }
  
  void ReplayView::recvGNSSStatus(void* stat)
  {
  	PwrpakStatus *status = (PwrpakStatus*)stat;
  
  	ui->le_ins_acc->setText(status->accuracy.c_str());
  	ui->le_ins_pos->setText(status->posType.c_str());
  	ui->le_ins_sol->setText(status->solType.c_str());
  	ui->le_ins_stat->setText(status->insStat.c_str());
  	ui->le_ins_svs->setText(QString::number(status->multiSVs));
  	ui->le_ins_time->setText(status->timeStat.c_str());
  
  	_naverMapHandler.updateMarker(status->currentPos[0], status->currentPos[1]);
  	_naverMapHandler.updateFocus(status->currentPos[0], status->currentPos[1]);
  }
  
  void ReplayView::recvPoint(double lat, double lng)
  {
  	_naverMapHandler.addPoint(lat, lng);
  }
  
  void ReplayView::recvImagePath(int id, QString path)
  {
  	if(path.isEmpty() == true)
  	{
  		emit sendDraw(0, 0, 0, _imageUnit[id]);
  	}
  	if(_beforePath[id] == path)
  		return;
  
  	cv::Mat originalImage;
  	originalImage = cv::imread(path.toStdString().c_str());
  
  	if (originalImage.data)
  	{
  		cv::cvtColor(originalImage, originalImage, cv::COLOR_BGR2RGB);
  
  		//Rotate 90 degree
  //        cv::Point2f pc(originalImage.cols/2., originalImage.rows/2.);
  //        cv::Mat r = cv::getRotationMatrix2D(pc, 90, 1.0);
  //        cv::warpAffine(originalImage, originalImage, r, originalImage.size());
  
  		cv::resize(originalImage, originalImage, cv::Size( originalImage.cols/4, originalImage.rows/4 ), 0, 0, CV_INTER_NN );
  
  //		_imageUnit[id].setDraw(originalImage.data, originalImage.cols, originalImage.rows);
  		emit sendDraw(originalImage.data, originalImage.cols, originalImage.rows, _imageUnit[id]);
  		_beforePath[id] = path;
  	}
  //    if(path.isEmpty()==false)
  	//        _imageUnit[id].setImage(path);
  
  }
  
  void ReplayView::recvSetTime(QString time, int pos)
  {
  	switch (pos) {
  	case 0:
  		ui->lb_time_start->setText(time);
  		break;
  	case 1:
  		ui->lb_time_current->setText(time);
  		break;
  	case 2:
  		ui->lb_time_end->setText(time);
  		break;
  	default:
  		break;
  	}
  }
  
  void ReplayView::addJSObject()
  {
  	ui->webView->page()->mainFrame()->addToJavaScriptWindowObject(QString("naver_map"), &_naverMapHandler);
  }
  
  void ReplayView::on_pb_player_play_clicked(bool checked)
  {
  	emit sendPlayOn(checked);
  }
  