void SplineEditorWidget::mousePressEvent(QMouseEvent *event) { QGraphicsView::mousePressEvent(event); QList<QGraphicsItem *> items = _scene->selectedItems(); if(items.size() > 0) { SplinePointWidget *splinePoint = dynamic_cast<SplinePointWidget*>( items.at(0) ); emit pressedPoint( _spline->pointAt( splinePoint->pointIndex ) ); } if(_is_shift_pressed) { std::cout << mapToScene(event->pos()).x() << "|" << mapToScene(event->pos()).y() << std::endl; if(event->buttons() == Qt::LeftButton) { if( isSplineExist() ) { Spline &spline = getSpline(); spline.push_back( QVector2D( mapToScene(event->pos()).x(), mapToScene(event->pos()).y() ) ); setSpline( spline ); } } if(event->buttons() == Qt::RightButton) { if( isSplineExist() ) { if( isPointSelected() ) { Spline &spline = getSpline(); SplinePoint& selectedPoint = getSelectedPoint(); spline.remove( selectedPoint ); setSpline( spline ); } } } } }
bool TerrainBlock::calcSplines(){ // prepare: const Foam::vector & n_up = cooSys->e(UP); // loop over ground spline labels: for(label i = 0; i < 4; i++){ // prepare: const label splinePoints = splinePointNrs[getSplineDirection(i)]; pointField spline(splinePoints); // grab spline end points: const labelList verticesI = getSplineVerticesI(i); point & pointA = getVertex(verticesI[0]); point & pointB = getVertex(verticesI[1]); // calc delta in x,y: point delta = (pointB - pointA) / (splinePoints + 1); // loop over spline points: for(label u = 0; u < splinePoints; u++){ point splinePoint = pointA + (1 + u) * delta; // make sure point is above surface: splinePoint += dot(p_above - splinePoint,n_up) * n_up; // project to stl: if(!attachPoint(splinePoint,splinePoint - maxProjDist * n_up)){ Info << "TerrainBlock: Error: Cannot project point p = " << splinePoint << " onto stl.\n" << endl; return false; } // add: spline[u] = splinePoint; } // set it: setSpline(i,spline); } return true; }