Buttons click method

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

Buttons click method

Postby snfge » Fri Jul 22, 2016 11:52 am

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: 3511
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Buttons click method

Postby daniel » Fri Jul 22, 2016 1:12 pm

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

Postby snfge » Thu Jul 28, 2016 2:19 am

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: 3511
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Buttons click method

Postby daniel » Thu Jul 28, 2016 6:07 am

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

Postby snfge » Sat Aug 06, 2016 12:05 pm

Hi
Can I build a Class like the "ccTracePolylineTool" and can use the button click method?

daniel
Site Admin
Posts: 3511
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Buttons click method

Postby daniel » Mon Aug 08, 2016 5:17 pm

I guess so?
Daniel, CloudCompare admin


Return to “CloudCompare”

Who is online

Users browsing this forum: No registered users and 1 guest