void QgsCircularString::addToPainterPath( QPainterPath &path ) const { int nPoints = numPoints(); if ( nPoints < 1 ) { return; } if ( path.isEmpty() || path.currentPosition() != QPointF( mX[0], mY[0] ) ) { path.moveTo( QPointF( mX[0], mY[0] ) ); } for ( int i = 0; i < ( nPoints - 2 ) ; i += 2 ) { QgsPointSequence pt; segmentize( QgsPointV2( mX[i], mY[i] ), QgsPointV2( mX[i + 1], mY[i + 1] ), QgsPointV2( mX[i + 2], mY[i + 2] ), pt ); for ( int j = 1; j < pt.size(); ++j ) { path.lineTo( pt.at( j ).x(), pt.at( j ).y() ); } //arcTo( path, QPointF( mX[i], mY[i] ), QPointF( mX[i + 1], mY[i + 1] ), QPointF( mX[i + 2], mY[i + 2] ) ); } //if number of points is even, connect to last point with straight line (even though the circular string is not valid) if ( nPoints % 2 == 0 ) { path.lineTo( mX[ nPoints - 1 ], mY[ nPoints - 1 ] ); } }
void QgsCircularString::setPoints( const QgsPointSequence &points ) { clearCache(); if ( points.empty() ) { mWkbType = QgsWkbTypes::CircularString; mX.clear(); mY.clear(); mZ.clear(); mM.clear(); return; } //get wkb type from first point const QgsPoint &firstPt = points.at( 0 ); bool hasZ = firstPt.is3D(); bool hasM = firstPt.isMeasure(); setZMTypeFromSubGeometry( &firstPt, QgsWkbTypes::CircularString ); mX.resize( points.size() ); mY.resize( points.size() ); if ( hasZ ) { mZ.resize( points.size() ); } else { mZ.clear(); } if ( hasM ) { mM.resize( points.size() ); } else { mM.clear(); } for ( int i = 0; i < points.size(); ++i ) { mX[i] = points[i].x(); mY[i] = points[i].y(); if ( hasZ ) { double z = points.at( i ).z(); mZ[i] = std::isnan( z ) ? 0 : z; } if ( hasM ) { double m = points.at( i ).m(); mM[i] = std::isnan( m ) ? 0 : m; } } }
QgsTriangle QgsRegularPolygon::toTriangle() const { if ( isEmpty() || ( mNumberSides != 3 ) ) { return QgsTriangle(); } QgsPointSequence pts; pts = points(); return QgsTriangle( pts.at( 0 ), pts.at( 1 ), pts.at( 2 ) ); }
void QgsLineString::setPoints( const QgsPointSequence &points ) { clearCache(); //set bounding box invalid if ( points.isEmpty() ) { clear(); return; } //get wkb type from first point const QgsPointV2& firstPt = points.at( 0 ); bool hasZ = firstPt.is3D(); bool hasM = firstPt.isMeasure(); setZMTypeFromSubGeometry( &firstPt, QgsWkbTypes::LineString ); mX.resize( points.size() ); mY.resize( points.size() ); if ( hasZ ) { mZ.resize( points.size() ); } else { mZ.clear(); } if ( hasM ) { mM.resize( points.size() ); } else { mM.clear(); } for ( int i = 0; i < points.size(); ++i ) { mX[i] = points.at( i ).x(); mY[i] = points.at( i ).y(); if ( hasZ ) { mZ[i] = points.at( i ).z(); } if ( hasM ) { mM[i] = points.at( i ).m(); } } }
void QgsMapToolAddCircularString::updateCenterPointRubberBand( const QgsPointV2 &pt ) { if ( !mShowCenterPointRubberBand || !mCenterPointRubberBand || mPoints.size() < 2 ) { return; } if ( ( mPoints.size() ) % 2 != 0 ) { return; } //create circular string QgsCircularString *cs = new QgsCircularString(); QgsPointSequence csPoints; csPoints.append( mPoints.at( mPoints.size() - 2 ) ); csPoints.append( mPoints.at( mPoints.size() - 1 ) ); csPoints.append( pt ); cs->setPoints( csPoints ); QgsPointV2 center; double radius; QgsGeometryUtils::circleCenterRadius( csPoints.at( 0 ), csPoints.at( 1 ), csPoints.at( 2 ), radius, center.rx(), center.ry() ); QgsLineString *segment1 = new QgsLineString(); segment1->addVertex( center ); segment1->addVertex( csPoints.at( 0 ) ); QgsLineString *segment2 = new QgsLineString(); segment2->addVertex( csPoints.at( 2 ) ); segment2->addVertex( center ); QgsCompoundCurve *cc = new QgsCompoundCurve(); cc->addCurve( segment1 ); cc->addCurve( cs ); cc->addCurve( segment2 ); QgsCurvePolygon *cp = new QgsCurvePolygon(); cp->setExteriorRing( cc ); mCenterPointRubberBand->setGeometry( cp ); mCenterPointRubberBand->show(); }
void QgsCircularString::setPoints( const QgsPointSequence &points ) { clearCache(); if ( points.size() < 1 ) { mWkbType = QgsWkbTypes::Unknown; mX.clear(); mY.clear(); mZ.clear(); mM.clear(); return; } //get wkb type from first point const QgsPointV2 &firstPt = points.at( 0 ); bool hasZ = firstPt.is3D(); bool hasM = firstPt.isMeasure(); setZMTypeFromSubGeometry( &firstPt, QgsWkbTypes::CircularString ); mX.resize( points.size() ); mY.resize( points.size() ); if ( hasZ ) { mZ.resize( points.size() ); } else { mZ.clear(); } if ( hasM ) { mM.resize( points.size() ); } else { mM.clear(); } for ( int i = 0; i < points.size(); ++i ) { mX[i] = points[i].x(); mY[i] = points[i].y(); if ( hasZ ) { mZ[i] = points[i].z(); } if ( hasM ) { mM[i] = points[i].m(); } } }
QList<QgsTriangle> QgsRegularPolygon::triangulate() const { QList<QgsTriangle> l_tri; if ( isEmpty() ) { return l_tri; } QgsPointSequence pts; pts = points(); unsigned int n = 0; while ( n < mNumberSides - 1 ) { l_tri.append( QgsTriangle( pts.at( n ), pts.at( n + 1 ), mCenter ) ); n++; } l_tri.append( QgsTriangle( pts.at( n ), pts.at( 0 ), mCenter ) ); return l_tri; }
bool QgsEllipseSymbolLayer::writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolRenderContext &context, QPointF shift ) const { //width double symbolWidth = mSymbolWidth; if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyWidth ) ) //1. priority: data defined setting on symbol layer le { context.setOriginalValueVariable( mSymbolWidth ); symbolWidth = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyWidth, context.renderContext().expressionContext(), mSymbolWidth ); } if ( mSymbolWidthUnit == QgsUnitTypes::RenderMillimeters ) { symbolWidth *= mmMapUnitScaleFactor; } //height double symbolHeight = mSymbolHeight; if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyHeight ) ) //1. priority: data defined setting on symbol layer level { context.setOriginalValueVariable( mSymbolHeight ); symbolWidth = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyHeight, context.renderContext().expressionContext(), mSymbolHeight ); } if ( mSymbolHeightUnit == QgsUnitTypes::RenderMillimeters ) { symbolHeight *= mmMapUnitScaleFactor; } //stroke width double strokeWidth = mStrokeWidth; if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyStrokeWidth ) ) { context.setOriginalValueVariable( mStrokeWidth ); strokeWidth = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyStrokeWidth, context.renderContext().expressionContext(), mStrokeWidth ); } if ( mStrokeWidthUnit == QgsUnitTypes::RenderMillimeters ) { strokeWidth *= strokeWidth; } //fill color QColor fc = mColor; if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyFillColor ) ) { context.setOriginalValueVariable( QgsSymbolLayerUtils::encodeColor( mColor ) ); fc = mDataDefinedProperties.valueAsColor( QgsSymbolLayer::PropertyFillColor, context.renderContext().expressionContext(), mColor ); } //stroke color QColor oc = mStrokeColor; if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyStrokeColor ) ) { context.setOriginalValueVariable( QgsSymbolLayerUtils::encodeColor( mStrokeColor ) ); oc = mDataDefinedProperties.valueAsColor( QgsSymbolLayer::PropertyStrokeColor, context.renderContext().expressionContext(), mStrokeColor ); } //symbol name QString symbolName = mSymbolName; if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyName ) ) { context.setOriginalValueVariable( mSymbolName ); symbolName = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyName, context.renderContext().expressionContext(), mSymbolName ); } //offset double offsetX = 0; double offsetY = 0; markerOffset( context, offsetX, offsetY ); QPointF off( offsetX, offsetY ); //priority for rotation: 1. data defined symbol level, 2. symbol layer rotation (mAngle) double rotation = 0.0; if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyAngle ) ) { context.setOriginalValueVariable( mAngle ); rotation = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyAngle, context.renderContext().expressionContext(), mAngle ) + mLineAngle; } else if ( !qgsDoubleNear( mAngle + mLineAngle, 0.0 ) ) { rotation = mAngle + mLineAngle; } rotation = -rotation; //rotation in Qt is counterclockwise if ( rotation ) off = _rotatedOffset( off, rotation ); QTransform t; t.translate( shift.x() + offsetX, shift.y() + offsetY ); if ( !qgsDoubleNear( rotation, 0.0 ) ) t.rotate( rotation ); double halfWidth = symbolWidth / 2.0; double halfHeight = symbolHeight / 2.0; if ( symbolName == QLatin1String( "circle" ) ) { if ( qgsDoubleNear( halfWidth, halfHeight ) ) { QgsPoint pt( t.map( QPointF( 0, 0 ) ) ); e.writeFilledCircle( layerName, oc, pt, halfWidth ); } else { QgsPointSequence line; double stepsize = 2 * M_PI / 40; for ( int i = 0; i < 39; ++i ) { double angle = stepsize * i; double x = halfWidth * std::cos( angle ); double y = halfHeight * std::sin( angle ); line << QgsPoint( t.map( QPointF( x, y ) ) ); } //close ellipse with first point line << line.at( 0 ); if ( mBrush.style() != Qt::NoBrush ) e.writePolygon( QgsRingSequence() << line, layerName, QStringLiteral( "SOLID" ), fc ); if ( mPen.style() != Qt::NoPen ) e.writePolyline( line, layerName, QStringLiteral( "CONTINUOUS" ), oc, strokeWidth ); } } else if ( symbolName == QLatin1String( "rectangle" ) ) { QgsPointSequence p; p << QgsPoint( t.map( QPointF( -halfWidth, -halfHeight ) ) ) << QgsPoint( t.map( QPointF( halfWidth, -halfHeight ) ) ) << QgsPoint( t.map( QPointF( halfWidth, halfHeight ) ) ) << QgsPoint( t.map( QPointF( -halfWidth, halfHeight ) ) ); p << p[0]; if ( mBrush.style() != Qt::NoBrush ) e.writePolygon( QgsRingSequence() << p, layerName, QStringLiteral( "SOLID" ), fc ); if ( mPen.style() != Qt::NoPen ) e.writePolyline( p, layerName, QStringLiteral( "CONTINUOUS" ), oc, strokeWidth ); return true; } else if ( symbolName == QLatin1String( "cross" ) && mPen.style() != Qt::NoPen ) { e.writePolyline( QgsPointSequence() << QgsPoint( t.map( QPointF( -halfWidth, 0 ) ) ) << QgsPoint( t.map( QPointF( halfWidth, 0 ) ) ), layerName, QStringLiteral( "CONTINUOUS" ), oc, strokeWidth ); e.writePolyline( QgsPointSequence() << QgsPoint( t.map( QPointF( 0, halfHeight ) ) ) << QgsPoint( t.map( QPointF( 0, -halfHeight ) ) ), layerName, QStringLiteral( "CONTINUOUS" ), oc, strokeWidth ); return true; } else if ( symbolName == QLatin1String( "triangle" ) ) { QgsPointSequence p; p << QgsPoint( t.map( QPointF( -halfWidth, -halfHeight ) ) ) << QgsPoint( t.map( QPointF( halfWidth, -halfHeight ) ) ) << QgsPoint( t.map( QPointF( 0, halfHeight ) ) ); p << p[0]; if ( mBrush.style() != Qt::NoBrush ) e.writePolygon( QgsRingSequence() << p, layerName, QStringLiteral( "SOLID" ), fc ); if ( mPen.style() != Qt::NoPen ) e.writePolyline( p, layerName, QStringLiteral( "CONTINUOUS" ), oc, strokeWidth ); return true; } return false; //soon... }