real_t CDispRigidBody::findBoundR() { real_t r = FindBoundR(element(0)->cvertices(), rotationPoint()); for (ICNewton::element_t i = 1; i < elements(); i++) r = std::max(r, FindBoundR(element(i)->cvertices(), rotationPoint())); return r; }
void QgsMapToolMoveLabel::canvasPressEvent( QgsMapMouseEvent* e ) { deleteRubberBands(); if ( !labelAtPosition( e, mCurrentLabelPos ) ) { return; } QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( mCurrentLabelPos.layerID ); if ( !layer || !layer->isEditable() ) { return; } int xCol, yCol; if ( labelMoveable( layer, xCol, yCol ) || diagramMoveable( layer, xCol, yCol ) ) { mStartPointMapCoords = toMapCoordinates( e->pos() ); QgsPoint referencePoint; if ( !rotationPoint( referencePoint, !preserveRotation(), false ) ) { referencePoint.setX( mCurrentLabelPos.labelRect.xMinimum() ); referencePoint.setY( mCurrentLabelPos.labelRect.yMinimum() ); } mClickOffsetX = mStartPointMapCoords.x() - referencePoint.x(); mClickOffsetY = mStartPointMapCoords.y() - referencePoint.y(); createRubberBands(); } }
void QgsMapToolLabel::createRubberBands( ) { delete mLabelRubberBand; delete mFeatureRubberBand; //label rubber band QgsRectangle rect = mCurrentLabelPos.labelRect; mLabelRubberBand = new QgsRubberBand( mCanvas, QGis::Line ); mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMaximum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMaximum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMinimum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) ); mLabelRubberBand->setColor( QColor( 0, 255, 0, 65 ) ); mLabelRubberBand->setWidth( 3 ); mLabelRubberBand->show(); //feature rubber band QgsVectorLayer* vlayer = currentLayer(); if ( vlayer ) { QgsFeature f; if ( currentFeature( f, true ) ) { QgsGeometry* geom = f.geometry(); if ( geom ) { mFeatureRubberBand = new QgsRubberBand( mCanvas, geom->type() ); mFeatureRubberBand->setColor( QColor( 255, 0, 0, 65 ) ); mFeatureRubberBand->setToGeometry( geom, vlayer ); mFeatureRubberBand->show(); } } //fixpoint rubber band QgsPoint fixPoint; if ( rotationPoint( fixPoint, false, false ) ) { if ( mCanvas ) { const QgsMapSettings& s = mCanvas->mapSettings(); if ( s.hasCrsTransformEnabled() ) { fixPoint = s.mapToLayerCoordinates( vlayer, fixPoint ); } } QgsGeometry* pointGeom = QgsGeometry::fromPoint( fixPoint ); mFixPointRubberBand = new QgsRubberBand( mCanvas, QGis::Line ); mFixPointRubberBand->setColor( QColor( 0, 0, 255, 65 ) ); mFixPointRubberBand->setToGeometry( pointGeom, vlayer ); mFixPointRubberBand->show(); delete pointGeom; } } }
void QgsMapToolLabel::createRubberBands( ) { delete mLabelRubberBand; delete mFeatureRubberBand; //label rubber band QgsRectangle rect = mCurrentLabelPos.labelRect; mLabelRubberBand = new QgsRubberBand( mCanvas, false ); mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMaximum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMaximum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMinimum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) ); mLabelRubberBand->setColor( Qt::green ); mLabelRubberBand->setWidth( 3 ); mLabelRubberBand->show(); //feature rubber band QgsVectorLayer* vlayer = currentLayer(); if ( vlayer ) { QgsFeature f; if ( currentFeature( f, true ) ) { QgsGeometry* geom = f.geometry(); if ( geom ) { mFeatureRubberBand = new QgsRubberBand( mCanvas, geom->type() == QGis::Polygon ); mFeatureRubberBand->setColor( Qt::red ); mFeatureRubberBand->setToGeometry( geom, vlayer ); mFeatureRubberBand->show(); } } //fixpoint rubber band QgsPoint fixPoint; if ( rotationPoint( fixPoint ) ) { if ( mCanvas ) { QgsMapRenderer* r = mCanvas->mapRenderer(); if ( r && r->hasCrsTransformEnabled() ) { fixPoint = r->mapToLayerCoordinates( vlayer, fixPoint ); } } QgsGeometry* pointGeom = QgsGeometry::fromPoint( fixPoint ); mFixPointRubberBand = new QgsRubberBand( mCanvas, false ); mFixPointRubberBand->setColor( Qt::blue ); mFixPointRubberBand->setToGeometry( pointGeom, vlayer ); mFixPointRubberBand->show(); delete pointGeom; } } }
math::Vector<2> CDispRigidBody::bCoef(real_t e, const NewtonCollisionBase & bData) const { const real_t & dt = bData.dData.dt; math::Vector<2> r(bData.points.eff - rotationPoint()); rotateToGlobal(r); real_t ax = 1.0 / m() + (r(1) * r(1) / Idisp()); real_t ay = 1.0 / m() + (r(0) * r(0) / Idisp()); //compensate permanent forces //reaction to permanent force real_t bx = resultantForce(0) * dt * ax; real_t by = resultantForce(1) * dt * ay; //reaction to permanent moment real_t resultantMomentx_add = 0.0; real_t resultantMomenty_add = 0.0; if (r(1) != 0.0) resultantMomentx_add = resultantMoment() * dt * ax / r(1); if (r(0) != 0.0) resultantMomenty_add = resultantMoment() * dt * ay / r(0); bx += resultantMomentx_add; by -= resultantMomenty_add; //momentum addition bx += e * pA(0) / m(); by += e * pA(1) / m(); //angular momentum addition bx += e * LA() * -r(1) / Idisp(); by += e * LA() * r(0) / Idisp(); //L translates into force proportional to (rx, ry) real_t Lx_coef = std::abs(r(1)) / (std::abs(r(1)) + std::abs(r(0))); real_t Ly_coef = std::abs(r(0)) / (std::abs(r(1)) + std::abs(r(0))); real_t Lx_add = std::abs(LA() * r(1) / Idisp() + resultantMomentx_add); real_t Ly_add = std::abs(LA() * r(0) / Idisp() - resultantMomenty_add); real_t px_add = std::abs(pA(0) / m() + resultantForce(0) * dt * ax); real_t py_add = std::abs(pA(1) / m() + resultantForce(1) * dt * ay); //multiply bx by bx_coef if ((Lx_add + px_add) != 0.0) //do not divide by 0.0 (note: px_add and Lx_add are absolute values) bx *= (Lx_coef * Lx_add + px_add) / (Lx_add + px_add); //multiply by by by_coef if ((Ly_add + py_add) != 0.0) //do not divide by 0.0 (note: py_add and Ly_add are absolute values) by *= (Ly_coef * Ly_add + py_add) / (Ly_add + py_add); return math::Vector<2>(bx, by); }
math::Vector<2> CDispRigidBody::aCoef(const NewtonCollisionBase & bData) const { math::Vector<2> r(bData.points.eff - rotationPoint()); rotateToGlobal(r); return math::Vector<2>(1.0 / m() + (r(1) * r(1) / Idisp()), 1.0 / m() + (r(0) * r(0) / Idisp())); }
bool QgsMapToolPinLabels::pinUnpinLabel( QgsVectorLayer* vlayer, const QgsLabelPosition& labelpos, bool pin ) { // skip diagrams if ( labelpos.isDiagram ) { QgsDebugMsg( QString( "Label is diagram, skipping" ) ); return false; } // verify attribute table has x, y fields mapped int xCol, yCol; double xPosOrig, yPosOrig; bool xSuccess, ySuccess; if ( !dataDefinedPosition( vlayer, mCurrentLabelPos.featureId, xPosOrig, xSuccess, yPosOrig, ySuccess, xCol, yCol ) ) { QgsDebugMsg( QString( "Label X or Y column not mapped, skipping" ) ); return false; } // rotation field is optional, but will be used if available, unless data exists int rCol; bool rSuccess = false; double defRot; bool hasRCol = ( layerIsRotatable( vlayer, rCol ) && dataDefinedRotation( vlayer, mCurrentLabelPos.featureId, defRot, rSuccess, true ) ); // get whether to preserve predefined rotation data during label pin/unpin operations bool preserveRot = preserveRotation(); // edit attribute table int fid = labelpos.featureId; bool writeFailed = false; QString labelText = currentLabelText( 24 ); if ( pin ) { // QgsPoint labelpoint = labelpos.cornerPoints.at( 0 ); QgsPoint referencePoint; if ( !rotationPoint( referencePoint, !preserveRot, false ) ) { referencePoint.setX( mCurrentLabelPos.labelRect.xMinimum() ); referencePoint.setY( mCurrentLabelPos.labelRect.yMinimum() ); } double labelX = referencePoint.x(); double labelY = referencePoint.y(); double labelR = labelpos.rotation * 180 / M_PI; // transform back to layer crs, if on-fly on if ( mCanvas->mapSettings().hasCrsTransformEnabled() ) { QgsPoint transformedPoint = mCanvas->mapSettings().mapToLayerCoordinates( vlayer, referencePoint ); labelX = transformedPoint.x(); labelY = transformedPoint.y(); } vlayer->beginEditCommand( tr( "Pinned label" ) + QString( " '%1'" ).arg( labelText ) ); writeFailed = !vlayer->changeAttributeValue( fid, xCol, labelX ); if ( !vlayer->changeAttributeValue( fid, yCol, labelY ) ) writeFailed = true; if ( hasRCol && !preserveRot ) { if ( !vlayer->changeAttributeValue( fid, rCol, labelR ) ) writeFailed = true; } vlayer->endEditCommand(); } else { vlayer->beginEditCommand( tr( "Unpinned label" ) + QString( " '%1'" ).arg( labelText ) ); writeFailed = !vlayer->changeAttributeValue( fid, xCol, QVariant( QString::null ) ); if ( !vlayer->changeAttributeValue( fid, yCol, QVariant( QString::null ) ) ) writeFailed = true; if ( hasRCol && !preserveRot ) { if ( !vlayer->changeAttributeValue( fid, rCol, QVariant( QString::null ) ) ) writeFailed = true; } vlayer->endEditCommand(); } if ( writeFailed ) { QgsDebugMsg( QString( "Write to attribute table failed" ) ); #if 0 QgsDebugMsg( QString( "Undoing and removing failed command from layer's undo stack" ) ); int lastCmdIndx = vlayer->undoStack()->count(); const QgsUndoCommand* lastCmd = qobject_cast<const QgsUndoCommand *>( vlayer->undoStack()->command( lastCmdIndx ) ); if ( lastCmd ) { vlayer->undoEditCommand( lastCmd ); delete vlayer->undoStack()->command( lastCmdIndx ); } #endif return false; } return true; }