Buttons click method

Any question about the main GUI application (frontend)
Post Reply
snfge
Posts: 72
Joined: Thu Nov 20, 2014 4:12 am

Buttons click method

Post by snfge »

Hi
I want develope a method when I click a menus , left button click is add point to polyline and right button is end create polyline, how can I do it, I write the code like other method, but when I left button click, the code not work.
daniel
Site Admin
Posts: 7713
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Buttons click method

Post by daniel »

Then, you should refer to the way the interactive segmentation tool works. See the ccGraphicalSegmentationTool class.
Daniel, CloudCompare admin
snfge
Posts: 72
Joined: Thu Nov 20, 2014 4:12 am

Re: Buttons click method

Post by snfge »

Hi
I add the code to mainwindow.cpp, but when I click, the "addPointToPolyline" not work, please help me, thank you.

Code: Select all

void MainWindow::doActionShowHelpDialog()
{
	m_polyVertices = new ccPointCloud("vertices");
	m_segmentationPoly = new ccPolyline(m_polyVertices);
	m_segmentationPoly->setForeground(true);
	m_segmentationPoly->setColor(ccColor::green);
	m_segmentationPoly->showColors(true);
	m_segmentationPoly->set2DMode(true);

	m_associatedWin = getActiveGLWindow();
	if (m_associatedWin)
	{
		connect(m_associatedWin, SIGNAL(leftButtonClicked(int, int)), this, SLOT(addPointToPolyline(int, int)));
		connect(m_associatedWin, SIGNAL(rightButtonClicked(int, int)), this, SLOT(closePolyLine(int, int)));
		connect(m_associatedWin, SIGNAL(mouseMoved(int, int, Qt::MouseButtons)), this, SLOT(updatePolyLine(int, int, Qt::MouseButtons)));
	}
	if (m_segmentationPoly)
	{
		m_segmentationPoly->setDisplay(m_associatedWin);
	}

}
//////////////////////////////////////////////////////////////////////////添加点,左键
void MainWindow::addPointToPolyline(int x, int y)
{
	assert(m_polyVertices);
	assert(m_segmentationPoly);
	unsigned vertCount = m_polyVertices->size();

	//new point
	CCVector3 P(static_cast<PointCoordinateType>(x - m_associatedWin->width() / 2),
		static_cast<PointCoordinateType>(m_associatedWin->height() / 2 - y),
		0);

	//CTRL key pressed at the same time?
	//bool ctrlKeyPressed = m_rectangularSelection || ((QApplication::keyboardModifiers() & Qt::ControlModifier) == Qt::ControlModifier);

	//start new polyline?
	if ( vertCount == 0)
	{
		//reset state
		//m_state = (ctrlKeyPressed ? RECTANGLE : POLYLINE);
		//m_state |= (STARTED | RUNNING);
		//reset polyline
		m_polyVertices->clear();
		if (!m_polyVertices->reserve(2))
		{
			ccLog::Error("Out of memory!");
			//allowPolylineExport(false);
			return;
		}
		//we add the same point twice (the last point will be used for display only)
		m_polyVertices->addPoint(P);
		m_polyVertices->addPoint(P);
		m_segmentationPoly->clear();
		if (!m_segmentationPoly->addPointIndex(0, 2))
		{
			ccLog::Error("Out of memory!");
			//allowPolylineExport(false);
			return;
		}
	}
	else //next points in "polyline mode" only
	{
		//we were already in 'polyline' mode?
		if (m_state & POLYLINE)
		{
			if (!m_polyVertices->reserve(vertCount + 1))
			{
				ccLog::Error("Out of memory!");
				//allowPolylineExport(false);
				return;
			}

			//we replace last point by the current one
			CCVector3* lastP = const_cast<CCVector3*>(m_polyVertices->getPointPersistentPtr(vertCount - 1));
			*lastP = P;
			//and add a new (equivalent) one
			m_polyVertices->addPoint(P);
			if (!m_segmentationPoly->addPointIndex(vertCount))
			{
				ccLog::Error("Out of memory!");
				return;
			}
			m_segmentationPoly->setClosed(true);
		}
		else //we must change mode
		{
			assert(false); //we shouldn't fall here?!
			m_state &= (~RUNNING);
			addPointToPolyline(x, y);
			return;
		}
	}

	m_associatedWin->redraw(true, false);
}
daniel
Site Admin
Posts: 7713
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Buttons click method

Post by daniel »

It would have been better to add this code in another class (just as ccGraphicalSegmentationTool or ccTracePolylineTool, etc.).

And have you declared 'addPointToPolyline' as a slot? Do you at least enter inside the function? (you can use the debug mode to trace the call and run the code step by step).
Daniel, CloudCompare admin
snfge
Posts: 72
Joined: Thu Nov 20, 2014 4:12 am

Re: Buttons click method

Post by snfge »

Hi
Can I build a Class like the "ccTracePolylineTool" and can use the button click method?
daniel
Site Admin
Posts: 7713
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Buttons click method

Post by daniel »

I guess so?
Daniel, CloudCompare admin
Post Reply