bool PolylineAnnotation::processEditingOnRelease( QMouseEvent *mouseEvent ) { static const int mouseMoveOffset = 1; if ( mouseEvent->button() != Qt::LeftButton ) { return false; } if ( m_interactingObj == InteractingNode ) { qreal x, y; m_viewport->screenCoordinates( m_movedPointCoords.longitude(), m_movedPointCoords.latitude(), x, y ); // The node gets selected only if it is clicked and not moved. if ( qFabs(mouseEvent->pos().x() - x) > mouseMoveOffset || qFabs(mouseEvent->pos().y() - y) > mouseMoveOffset ) { m_interactingObj = InteractingNothing; return true; } m_nodesList[m_clickedNodeIndex].setFlag( PolylineNode::NodeIsSelected, !m_nodesList.at(m_clickedNodeIndex).isSelected() ); m_interactingObj = InteractingNothing; return true; } else if ( m_interactingObj == InteractingPolyline ) { // Nothing special happens at polyline release. m_interactingObj = InteractingNothing; return true; } return false; }
void KinematicPoints::SetS5C5() { s[5] = ctheta * (spsi * c[1] - cpsi * s[1]); c[5] = delta5 * qSqrt(1 - qPow(s[5], 2)); fi[5] = qFabs(c[5])>qFabs(s[5])? qAsin(s[5]) : qAcos(c[5]); //if(fi[5]!=fi[5]) {emit outOfRange(); return;} }
void KinematicPoints::SetS4C4() { s[4] = s234 * c23 - c234 * s23; c[4] = c234*c23 + s234*s23; fi[4] = qFabs(c[4])>qFabs(s[4])? qAsin(s[4]) : qAcos(c[4]); //if(fi[4]!=fi[4]) {emit outOfRange(); return;} }
void forkliftPathItem::SetCurrentPoint(QPointF &point) { currentPointIndex = -1; for(int i = 0; i < m_linePoints.count(); i++){ if(qFabs(m_linePoints[i].x() - point.x()) < 5 && qFabs(m_linePoints[i].y() - point.y()) < 5){ currentPointIndex = i; break; } } }
void KinematicPoints::SetS3C3() { double zr = regionalPoint.z(); s[3] = 1/l[3] * ( zr*c[2] - a*s[2] ); c[3] = 1/l[3]* (a*c[2]+zr*s[2] - l[2]) ; fi[3] = qFabs(c[3])>qFabs(s[3])? qAsin(s[3]) : qAcos(c[3]); //if(fi[3]!=fi[3]) {emit outOfRange(); return;} }
void KinematicPoints::SetS2C2() { double zr = regionalPoint.z(); s[2] = 1/(qPow(a, 2) + qPow(zr,2)) * (zr * b + delta2 * a * qSqrt(qPow(a, 2) + qPow(zr,2) - qPow(b,2))); c[2] = 1/(qPow(a, 2) + qPow(zr,2)) * (a * b - delta2 * zr * qSqrt(qPow(a, 2) + qPow(zr,2) - qPow(b,2)) ); fi[2] = qFabs(c[2])>qFabs(s[2])? qAsin(s[2]) : qAcos(c[2]); //if(fi[2]!=fi[2]) {emit outOfRange(); return;} }
QString ChatControler::dealTime(qint64 msgtime, int type) { QString strDateTime(""); QDateTime msgDateTime; int distance = 0; if (!msgtime) { return strDateTime; } msgDateTime.setMSecsSinceEpoch(msgtime); distance = msgDateTime.daysTo(QDateTime::currentDateTime()); //今天 if (qFabs(distance) <= 0) { strDateTime = msgDateTime.toString("HH:mm"); } //昨天 else if (qFabs(distance) <= 1) { if ( 1 == type) { strDateTime = "昨天"; } else { strDateTime = "昨天" + QString::fromLocal8Bit(" ") + msgDateTime.toString("HH:mm"); } } //前天 else if (qFabs(distance) <= 2) { if (1 == type) { strDateTime = "前天"; } else { strDateTime = "前天" + QString::fromLocal8Bit(" ") + msgDateTime.toString("HH:mm"); } } else { if (1 == type) { strDateTime = msgDateTime.toString("MM月dd日"); } else { strDateTime = msgDateTime.toString("MM月dd日") +QString::fromLocal8Bit(" ")+msgDateTime.toString("HH:mm"); } } return strDateTime; }
/*! \brief Qt timer event The flying wheel effect is implemented using a timer \param event Timer event \sa updateInterval() */ void QwtWheel::timerEvent( QTimerEvent *event ) { if ( event->timerId() != d_data->timerId ) { QWidget::timerEvent( event ); return; } d_data->speed *= qExp( -d_data->updateInterval * 0.001 / d_data->mass ); d_data->flyingValue += d_data->speed * d_data->updateInterval; d_data->flyingValue = boundedValue( d_data->flyingValue ); double value = d_data->flyingValue; if ( d_data->stepAlignment ) value = alignedValue( value ); if ( qFabs( d_data->speed ) < 0.001 * d_data->singleStep ) { // stop if d_data->speed < one step per second stopFlying(); } if ( value != d_data->value ) { d_data->value = value; update(); if ( d_data->tracking || d_data->timerId == 0 ) Q_EMIT valueChanged( d_data->value ); } }
/*! Calculate a step size for a given interval \param intervalSize Interval size \param numSteps Number of steps \param base Base for the division ( usually 10 ) \return Calculated step size */ double QwtScaleArithmetic::divideInterval( double intervalSize, int numSteps, uint base ) { if ( numSteps <= 0 ) return 0.0; const double v = QwtScaleArithmetic::divideEps( intervalSize, numSteps ); if ( v == 0.0 ) return 0.0; const double lx = qwtLog( base, qFabs( v ) ); const double p = ::floor( lx ); const double fraction = qPow( base, lx - p ); uint n = base; while ( ( n > 1 ) && ( fraction <= n / 2 ) ) n /= 2; double stepSize = n * qPow( base, p ); if ( v < 0 ) stepSize = -stepSize; return stepSize; }
void QImageDrawer::mouseReleaseEvent(QMouseEvent *m) { QWidget::mouseReleaseEvent(m); if (m_image.isNull()) { return; } if (m_drawMode == -3) {//calibre, we should pop up a dialog and get the real size bool ok; qreal r = static_cast<qreal>(QInputDialog::getDouble(this, tr("Input the real size"), tr("Unit: μm"), 0, 0, 9999, 4, &ok)); if (ok) { ccSpace->setScaleValue(qMax(qFabs(m_calibreLine.dx()), qFabs(m_calibreLine.dy())), r); } } else if (m_drawMode == -4) {//gauge qreal gaugeResult = qSqrt(m_gaugeLine.dx() * m_gaugeLine.dx() + m_gaugeLine.dy() * m_gaugeLine.dy()) / ccSpace->getScaleValue(); emit gaugeLineResult(gaugeResult); } }
double ATCAbstractProfile::interval(ATCInterpolator2D &interpolator, double key, double lvlFrom, double lvlTo) { QVector<double> sites; sites << lvlFrom << lvlTo; QVector<double> results(2); interpolator.interpolate(key, sites, results); return qFabs(results.at(1) - results.at(0)); //to - from }
void QImageDrawer::mouseMoveEvent(QMouseEvent *m) { QWidget::mouseMoveEvent(m); if (m_image.isNull()) { return; } m_mouseReleased = ccSpace->getInvertedTransform().map(m->localPos()); QPointF tl(0, 0); QPointF br(m_image.width() - 1, m_image.height() - 1); if (m_mouseReleased.x() < tl.x()) { m_mouseReleased.setX(tl.x()); } else if (m_mouseReleased.x() > br.x()) { m_mouseReleased.setX(br.x()); } if (m_mouseReleased.y() < tl.y()) { m_mouseReleased.setY(tl.y()); } else if (m_mouseReleased.y() > br.y()) { m_mouseReleased.setY(br.y()); } if (m_drawMode == -4) { m_gaugeLine.setP2(m_mouseReleased); }else if (m_drawMode == -2) {//rectangle ccSpace->setRectangle(QRectF(m_mousePressed, m_mouseReleased)); } else if (m_drawMode == -3) {//calibre m_calibreLine = QLineF(m_mousePressed, m_mouseReleased); if (qFabs(m_calibreLine.dx()) > qFabs(m_calibreLine.dy())) { m_calibreLine.setP2(QPointF(m_mouseReleased.x(), m_mousePressed.y())); } else { m_calibreLine.setP2(QPointF(m_mousePressed.x(), m_mouseReleased.y())); } } this->update(); }
void forkliftPathItem::RemovePoint(QPointF &point) { int index = -1; for(int i = 0; i < m_linePoints.count(); i++){ if(qFabs(m_linePoints[i].x() - point.x()) < 5 && qFabs(m_linePoints[i].y() - point.y()) < 5){ index = i; break; } } if(index >= 0){ m_linePoints.remove(index); } for (int i=0; i < m_linePoints.count(); i++){ if (i< 2){ m_cargoPoints[i] = m_linePoints[i]; } else{ break; } } }
void GEF::toRobertson() { Robertson robertson; if(m_depth.count() <= 1){ m_errors.append(QString("[%0] only one row found.").arg(m_filename)); return; } float zprev = m_depth[0]; float ytot = 0.0; float ytot_eff = 0.0; for(int i=1; i<m_depth.count(); i++){ float z = m_depth[i]; float qc = m_qc[i]; float pw = m_pw[i]; float wg = pw / qc * 100.0; if(qc < 1.5 && wg > 5.0){ m_rs[i] = 0; //veen //verticale spanning ytot += qFabs(z - zprev) * 10.0; //effectieve spanning if(qFabs(m_z - z) > WATERDEPTH){ ytot_eff += 0.0; }else{ ytot_eff += qFabs(z - zprev) * 10.0; } }else{ float weight = getApproxWeight(wg); //verticale spanning ytot += qFabs(z - zprev) * weight; //effectieve spanning if(qFabs(m_z - z) > WATERDEPTH){ ytot_eff += qFabs(z - zprev) * (weight - 10.0); }else{ ytot_eff += qFabs(z - zprev) * weight; } //qc = 0.9; // //pw = 0.04; //ytot = 180; //ytot_eff = 90; float nqc = (qc * 1000 - ytot) / ytot_eff; float nwg = (pw * 1000) / (qc * 1000 - ytot) * 100; m_rs[i] = robertson.getSoiltype(nqc, nwg); } zprev = z; } }
bool CDoodChatManagerModel::isJudageShowTime(QDateTime date) { if(m_pChatMap.size() <= 0){ return true; }else{ CDoodChatItem* last = (CDoodChatItem*)_list->at(_list->size() -1); QDateTime lastMsgTime = last->time(); QString tmp = Common::dealTime(lastMsgTime.toMSecsSinceEpoch(),1); int64 timeDistance = lastMsgTime.secsTo(date); if(qFabs(timeDistance) >= 60 * 3 && last->timeText() != tmp){//60 * 5 return true; } } return false; }
/*! \brief Determine the value corresponding to a specified position Called by QwtAbstractSlider \param pos point */ double QwtKnob::getValue( const QPoint &pos ) { const double dx = rect().center().x() - pos.x(); const double dy = rect().center().y() - pos.y(); const double arc = qAtan2( -dx, dy ) * 180.0 / M_PI; double newValue = 0.5 * ( minValue() + maxValue() ) + ( arc + d_data->nTurns * 360.0 ) * ( maxValue() - minValue() ) / d_data->totalAngle; const double oneTurn = qFabs( maxValue() - minValue() ) * 360.0 / d_data->totalAngle; const double eqValue = value() + mouseOffset(); if ( qFabs( newValue - eqValue ) > 0.5 * oneTurn ) { if ( newValue < eqValue ) newValue += oneTurn; else newValue -= oneTurn; } return newValue; }
QString GEF::asRobertson(const float interval) { QString result = ""; QList<GEFLayer> layers; QList<int> ids; //step 1, break into interval sized soillayers and find common soiltype GEFLayer layer; layer.van = m_depth[0]; for(int i=1; i<m_depth.count(); i++){ layer.tot = m_depth[i]; if(qFabs(layer.van - layer.tot) > interval){ QSet<int> set = ids.toSet(); layer.id = -1; int maxcount = 0; foreach (int id, set){ int count = 0; for(int j=0; j<ids.count(); j++){ if(ids[j] == id) count++; } if(count > maxcount){ layer.id = id; maxcount = count; } } if(layer.id==-1){ //probably missing values (columnvoid values?) > use previous soil layer //give feedback if(layers.count()>0){ layer.id = layers[layers.count()-1].id; }else{ //first layer, we do not accept bad info there qFatal(QString("Error, id -1 found in GEF %0").arg(getShortName()).toStdString().c_str()); } } layers.append(layer); ids.clear(); layer.van = layer.tot; }else{
void CDoodChatManagerModel::judgeAddTimeTip(QDateTime dateTime) { if(m_pChatMap.size()<= 0){ return ; } QDateTime lastMsgTime = m_pChatMap.last()->time(); int64 TimeDistance = lastMsgTime.secsTo(dateTime); if (qFabs(TimeDistance) >= 60 * 2) { QString date = Common::dealTime(dateTime.toMSecsSinceEpoch(),2); if(date != ""){ CDoodChatItem* item = new CDoodChatItem(this); item->setMsgType(QString::number(MSG_TYPE_TIME)); item->setLocalId(QString::number(dateTime.toMSecsSinceEpoch())); item->setBody(date); addItem(item); m_pChatMap[item->localId()] = item; } } }
void QwtWheel::mouseReleaseEvent( QMouseEvent *event ) { Q_UNUSED( event ); if ( !d_data->isScrolling ) return; d_data->isScrolling = false; bool startFlying = false; if ( d_data->mass > 0.0 ) { const int ms = d_data->time.elapsed(); if ( ( qFabs( d_data->speed ) > 0.0 ) && ( ms < 50 ) ) startFlying = true; } if ( startFlying ) { d_data->flyingValue = boundedValue( d_data->mouseValue - d_data->mouseOffset ); d_data->timerId = startTimer( d_data->updateInterval ); } else { if ( d_data->pendingValueChanged ) Q_EMIT valueChanged( d_data->value ); } d_data->pendingValueChanged = false; d_data->mouseOffset = 0.0; Q_EMIT wheelReleased(); }
/********************************************************************************* * Function: get the keypoints of end-arrow. * Parameters: k, end-point, key-point1, key-point2 * Return: none ********************************************************************************/ void SamDrawItemBase::getEndArrowKeypoints(const qreal &dK, const QPointF &qpEndPt, LINE_KEY_POINT_T &stKeyppoints, const qreal dXdirect, const qreal dYdirect) { const qreal dL = 12.0; qreal dKFactor = 0.0; qreal dVAngle = 0.0; const qreal dDelta = 0.01; QPointF qpKpt0, qpKpt1, qpKpt2, qpKpt3, qpKpt4, qpKpt5; /*K factor -1 or +1*/ if (qFabs(dK) > 0) { dKFactor = qFabs(dK) / dK; } else { dKFactor = 1.0; } /*The angle according to K value*/ qreal dAngle = qAtan(dK); /*Calculate the key point0*/ if (dKFactor > 0) { qpKpt0.rx() = qpEndPt.x() - dKFactor * dXdirect * (dL * qCos(dAngle)); qpKpt0.ry() = qpEndPt.y() - dKFactor * dYdirect * (dL * qSin(dAngle)); } else { qpKpt0.rx() = qpEndPt.x() + dKFactor * dXdirect * (dL * qCos(dAngle)); qpKpt0.ry() = qpEndPt.y() - dKFactor * dYdirect * (dL * qSin(dAngle)); } /*The angle according to the K value of vertical line*/ if (dK >= 99999) { dVAngle = 90; } else if (dK > dDelta || dK < -dDelta) { dVAngle = qAtan(-1 / dK); } else if (dK > -dDelta && dK < dDelta) { dVAngle = 0; } /*Calculate the key point1 and key point2*/ qpKpt1.rx() = qpKpt0.x() - ((dL/2) * qCos(dVAngle)); qpKpt1.ry() = qpKpt0.y() - ((dL/2) * qSin(dVAngle)); qpKpt2.rx() = qpKpt0.x() + ((dL/2) * qCos(dVAngle)); qpKpt2.ry() = qpKpt0.y() + ((dL/2) * qSin(dVAngle)); QPointF qpCenter; qpCenter.rx() = (qpEndPt.x() + qpKpt0.x()) / 2; qpCenter.ry() = (qpEndPt.y() + qpKpt0.y()) / 2; /* qpKpt3.rx() = qpCenter.x() - ((2*dL/3) * qCos(dVAngle)); qpKpt3.ry() = qpCenter.y() - ((2*dL/3) * qSin(dVAngle)); qpKpt4.rx() = qpCenter.x() + ((2*dL/3) * qCos(dVAngle)); qpKpt4.ry() = qpCenter.y() + ((2*dL/3) * qSin(dVAngle)); */ qpKpt3.rx() = qpCenter.x() - (dL * qCos(dVAngle)); qpKpt3.ry() = qpCenter.y() - (dL * qSin(dVAngle)); qpKpt4.rx() = qpCenter.x() + (dL * qCos(dVAngle)); qpKpt4.ry() = qpCenter.y() + (dL * qSin(dVAngle)); qpKpt5.rx() = (qpCenter.x() + qpKpt0.x()) / 2; qpKpt5.ry() = (qpCenter.y() + qpKpt0.y()) / 2; stKeyppoints.qpKeyPoint0 = qpKpt0; stKeyppoints.qpKeyPoint1 = qpKpt1; stKeyppoints.qpKeyPoint2 = qpKpt2; stKeyppoints.qpKeyPoint3 = qpKpt3; stKeyppoints.qpKeyPoint4 = qpKpt4; stKeyppoints.qpKeyPoint5 = qpKpt5; }
void DistortionFXFilter::cilindricalMultithreaded(const Args& prm) { int Width = prm.orgImage->width(); int Height = prm.orgImage->height(); uchar* data = prm.orgImage->bits(); bool sixteenBit = prm.orgImage->sixteenBit(); int bytesDepth = prm.orgImage->bytesDepth(); uchar* pResBits = prm.destImage->bits(); double nh, nw; int nHalfW = Width / 2; int nHalfH = Height / 2; double lfCoeffX = 1.0; double lfCoeffY = 1.0; double lfCoeffStep = prm.Coeff / 1000.0; if (prm.Horizontal) { lfCoeffX = (double)nHalfW / qLn(qFabs(lfCoeffStep) * nHalfW + 1.0); } if (prm.Vertical) { lfCoeffY = (double)nHalfH / qLn(qFabs(lfCoeffStep) * nHalfH + 1.0); } for (int w = prm.start; runningFlag() && (w < prm.stop); ++w) { // we find the distance from the center nh = qFabs((double)(prm.h - nHalfH)); nw = qFabs((double)(w - nHalfW)); if (prm.Horizontal) { if (prm.Coeff > 0.0) { nw = (qExp(nw / lfCoeffX) - 1.0) / lfCoeffStep; } else { nw = lfCoeffX * qLn(1.0 + (-1.0 * lfCoeffStep) * nw); } } if (prm.Vertical) { if (prm.Coeff > 0.0) { nh = (qExp(nh / lfCoeffY) - 1.0) / lfCoeffStep; } else { nh = lfCoeffY * qLn(1.0 + (-1.0 * lfCoeffStep) * nh); } } nw = (double)nHalfW + ((w >= nHalfW) ? nw : -nw); nh = (double)nHalfH + ((prm.h >= nHalfH) ? nh : -nh); setPixelFromOther(Width, Height, sixteenBit, bytesDepth, data, pResBits, w, prm.h, nw, nh, prm.AntiAlias); } }
void DistortionFXFilter::fisheyeMultithreaded(const Args& prm) { int Width = prm.orgImage->width(); int Height = prm.orgImage->height(); uchar* data = prm.orgImage->bits(); bool sixteenBit = prm.orgImage->sixteenBit(); int bytesDepth = prm.orgImage->bytesDepth(); uchar* pResBits = prm.destImage->bits(); double nh, nw, tw; DColor color; int offset; int nHalfW = Width / 2; int nHalfH = Height / 2; double lfXScale = 1.0; double lfYScale = 1.0; double lfCoeffStep = prm.Coeff / 1000.0; double lfRadius, lfAngle; if (Width > Height) { lfYScale = (double)Width / (double)Height; } else if (Height > Width) { lfXScale = (double)Height / (double)Width; } double lfRadMax = (double)qMax(Height, Width) / 2.0; double lfCoeff = lfRadMax / qLn(qFabs(lfCoeffStep) * lfRadMax + 1.0); double th = lfYScale * (double)(prm.h - nHalfH); for (int w = prm.start; runningFlag() && (w < prm.stop); ++w) { tw = lfXScale * (double)(w - nHalfW); // we find the distance from the center lfRadius = qSqrt(th * th + tw * tw); if (lfRadius < lfRadMax) { lfAngle = qAtan2(th, tw); if (prm.Coeff > 0.0) { lfRadius = (qExp(lfRadius / lfCoeff) - 1.0) / lfCoeffStep; } else { lfRadius = lfCoeff * qLn(1.0 + (-1.0 * lfCoeffStep) * lfRadius); } nw = (double)nHalfW + (lfRadius / lfXScale) * qCos(lfAngle); nh = (double)nHalfH + (lfRadius / lfYScale) * qSin(lfAngle); setPixelFromOther(Width, Height, sixteenBit, bytesDepth, data, pResBits, w, prm.h, nw, nh, prm.AntiAlias); } else { // copy pixel offset = getOffset(Width, w, prm.h, bytesDepth); color.setColor(data + offset, sixteenBit); color.setPixel(pResBits + offset); } } }
/*! \param points Series of data points \return Curve points */ QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const { QStack<Line> stack; stack.reserve( 500 ); const QPointF *p = points.data(); const int nPoints = points.size(); QVector<bool> usePoint( nPoints, false ); double distToSegment; stack.push( Line( 0, nPoints - 1 ) ); while ( !stack.isEmpty() ) { const Line r = stack.pop(); // initialize line segment const double vecX = p[r.to].x() - p[r.from].x(); const double vecY = p[r.to].y() - p[r.from].y(); const double vecLength = qSqrt( vecX * vecX + vecY * vecY ); const double unitVecX = ( vecLength != 0.0 ) ? vecX / vecLength : 0.0; const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0; double maxDist = 0.0; int nVertexIndexMaxDistance = r.from + 1; for ( int i = r.from + 1; i < r.to; i++ ) { //compare to anchor const double fromVecX = p[i].x() - p[r.from].x(); const double fromVecY = p[i].y() - p[r.from].y(); const double fromVecLength = qSqrt( fromVecX * fromVecX + fromVecY * fromVecY ); if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 ) { distToSegment = fromVecLength; } if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 ) { distToSegment = fromVecLength; } else { const double toVecX = p[i].x() - p[r.to].x(); const double toVecY = p[i].y() - p[r.to].y(); const double toVecLength = qSqrt( toVecX * toVecX + toVecY * toVecY ); const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY ); if ( s < 0.0 ) distToSegment = toVecLength; else { distToSegment = qSqrt( qFabs( toVecLength * toVecLength - s * s ) ); } } if ( maxDist < distToSegment ) { maxDist = distToSegment; nVertexIndexMaxDistance = i; } } if ( maxDist <= d_data->tolerance ) { usePoint[r.from] = true; usePoint[r.to] = true; } else { stack.push( Line( r.from, nVertexIndexMaxDistance ) ); stack.push( Line( nVertexIndexMaxDistance, r.to ) ); } } int cnt = 0; QPolygonF stripped( nPoints ); for ( int i = 0; i < nPoints; i++ ) { if ( usePoint[i] ) stripped[cnt++] = p[i]; } stripped.resize( cnt ); return stripped; }
/********************************************************************** * Function: move arc handle to a new place. * Parameters: none * Return: handle id, point, bound rect **********************************************************************/ QRectF QArcItem::moveHandleTo(int iDragHandle, QPointF qpLocal, QRectF &qrcBondingRect, bool bFoursquare) { const qreal dDelta = 0.1; qreal dDeltaX = 0.0, dDeltaY = 0.0; QPointF qpDimCenter, qpEndPoint; /*If move handle is 9 or 10 (to expand the arc)*/ if (iDragHandle > 8) { QRectF rect; QList<QPolygonF> polygonfs = m_ArcPath.toSubpathPolygons(); int iSize = polygonfs.size(); if (iSize <= 0 || iSize > 1) { return rect; } QPolygonF polygonf = polygonfs.at(0); int j = polygonf.size(); if (j <= 1) { return rect; } qpDimCenter = polygonf.at(0); qpDimCenter = this->mapToScene(qpDimCenter); qpEndPoint = polygonf.at(j - 1); qpEndPoint = this->mapToScene(qpEndPoint); /*Reset the arc when draged the related handle*/ switch (iDragHandle) { /*The start angle side handle*/ case 9: { dDeltaX = qpLocal.x() - qpDimCenter.x(); if (qFabs(dDeltaX) > dDelta) { dDeltaY = qpDimCenter.y() - qpLocal.y(); qreal dAngle = getAngle(dDeltaX, dDeltaY); qreal dStartAngle = 0.0, dSpanAngle = 0.0, dDeltaStartAngle = 0.0; /*Get the start angle and span angle*/ dStartAngle = dAngle; dDeltaStartAngle = dStartAngle - this->m_dStartAngle; if (dDeltaStartAngle < 0) dDeltaStartAngle += PI_ANGLE; dSpanAngle = this->m_dSpanAngle - dDeltaStartAngle; if (dSpanAngle < 0) dSpanAngle += PI_ANGLE; /*Set start angle and span angle, refresh arc.*/ this->m_dSpanAngle = dSpanAngle; this->m_dStartAngle = dStartAngle; refreshArc(); } } break; /*The end angle side handle*/ case 10: { if (qFabs(qpLocal.x() - qpDimCenter.x()) > dDelta) { dDeltaX = qpLocal.x() - qpDimCenter.x(); dDeltaY = qpDimCenter.y() - qpLocal.y(); qreal dAngle = getAngle(dDeltaX, dDeltaY); qreal dSpanAngle = 0.0; if (this->GetSpanAngle() < 0) { dAngle = PI_ANGLE - dAngle; dSpanAngle = this->m_dStartAngle - dAngle; } else if (this->GetSpanAngle() >= 0) { /*Get the new span angle*/ if (dAngle < this->m_dStartAngle) { dSpanAngle = PI_ANGLE - (this->m_dStartAngle - dAngle); } else { dSpanAngle = dAngle - this->m_dStartAngle; } } /*Set span angle*/ this->SetSpanAngle(dSpanAngle); } } break; default : break; } return rect; } else { return SamDrawItemBase::moveHandleTo(iDragHandle, qpLocal, qrcBondingRect, bFoursquare); } }
bool dataconfigs::loadLevelBackground(obj_BG &sbg, QString section, obj_BG *merge_with, QString iniFile, QSettings *setup) { bool valid=true; bool internal=!setup; QString errStr, tmpstr, imgFile; if(internal) { setup=new QSettings(iniFile, QSettings::IniFormat); setup->setIniCodec("UTF-8"); } if(!openSection(setup, section)) return false; sbg.name = setup->value("name", (merge_with? merge_with->name : "") ).toString(); if(sbg.name.isEmpty()) { addError(QString("%1 Item name isn't defined").arg(section.toUpper())); valid=false; goto abort; } tmpstr = setup->value("type", "-1").toString(); if(tmpstr=="single-row") sbg.type = 0; else if(tmpstr=="double-row") sbg.type = 1; else if(tmpstr=="tiled") sbg.type = 2; else if(tmpstr=="-1") sbg.type = (merge_with ? merge_with->type : 0); else sbg.type = 0; sbg.repeat_h = float(qFabs(setup->value("repeat-h", (merge_with ? merge_with->repeat_h : 2.0f)).toFloat())); tmpstr = setup->value("repeat-v", "-1").toString(); if(tmpstr=="NR") sbg.repead_v = 0; else if(tmpstr=="ZR") sbg.repead_v = 1; else if(tmpstr=="RP") sbg.repead_v = 2; else if(tmpstr=="RZ") sbg.repead_v = 3; else if(tmpstr=="-1") sbg.repead_v = (merge_with ? merge_with->repead_v : 0); else sbg.repead_v = 0; sbg.image_n = setup->value("image", (merge_with ? merge_with->image_n : "") ).toString(); if(!merge_with) { if( (sbg.image_n !="") ) { GraphicsHelps::loadMaskedImage(BGPath, sbg.image_n, imgFile, sbg.image, errStr); if(!errStr.isEmpty()) { addError(QString("%1 %2").arg(section).arg(errStr)); valid=false; //goto abort; } } else { addError(QString("%1 Image filename isn't defined").arg(section)); valid=false; //goto abort; } } sbg.attached = uint(setup->value("attached", (merge_with?(merge_with->attached==1?"top":"bottom"):"bottom") ).toString()=="top"); sbg.editing_tiled = setup->value("tiled-in-editor", merge_with?merge_with->editing_tiled:false ).toBool(); sbg.magic = setup->value("magic", (merge_with?merge_with->magic:false)).toBool(); sbg.magic_strips = setup->value("magic-strips", (merge_with? merge_with->magic_strips: 1 )).toUInt(); sbg.magic_splits = setup->value("magic-splits", (merge_with? merge_with->magic_splits:"0")).toString(); sbg.magic_speeds = setup->value("magic-speeds", (merge_with? merge_with->magic_speeds:"0")).toString(); sbg.animated = setup->value("animated", (merge_with?merge_with->animated:false)).toBool();//animated sbg.frames = setup->value("frames", (merge_with?merge_with->frames:1)).toUInt(); sbg.framespeed = setup->value("framespeed", (merge_with?merge_with->framespeed : 128)).toUInt(); sbg.display_frame = setup->value("display-frame", (merge_with?merge_with->display_frame : 0)).toUInt(); //frames if(sbg.type==1) { sbg.second_image_n = setup->value("second-image", (merge_with ? merge_with->second_image_n : "")).toString(); if(!merge_with) { if( (sbg.second_image_n !="") ) { GraphicsHelps::loadMaskedImage(BGPath, sbg.second_image_n, imgFile, sbg.second_image, errStr); } else { sbg.second_image = Themes::Image(Themes::dummy_bg); } } sbg.second_repeat_h = float(qFabs(setup->value("second-repeat-h", (merge_with ? merge_with->second_repeat_h : 2.0f)).toFloat())); tmpstr = setup->value("second-repeat-v", "-1").toString(); if(tmpstr=="NR") sbg.second_repeat_v = 0; else if(tmpstr=="ZR") sbg.second_repeat_v = 1; else if(tmpstr=="RP") sbg.second_repeat_v = 2; else if(tmpstr=="RZ") sbg.second_repeat_v = 3; else if(tmpstr=="-1") sbg.second_repeat_v = (merge_with ? merge_with->second_repeat_v : 0); else sbg.second_repeat_v = 0; tmpstr = setup->value("second-attached", "-1").toString(); if(tmpstr=="overfirst") sbg.second_attached = 0; else if(tmpstr=="bottom") sbg.second_attached = 1; else if(tmpstr=="top") sbg.second_attached = 2; else if(tmpstr=="-1") sbg.second_attached = (merge_with ? merge_with->second_attached : 0); else sbg.second_repeat_v = 0; } if(sbg.animated) { int fHeight = sbg.image.height() / int(sbg.frames); sbg.image = sbg.image.copy(0, 0, sbg.image.width(), fHeight ); } sbg.isValid = true; abort: closeSection(setup); if(internal) delete setup; return valid; }
bool GEF::readFromFile(const QString filename) { m_filename = filename; m_errors.clear(); //open file for reading QFile f(filename); if (!f.open(QIODevice::ReadOnly)){ QMessageBox::information(0, "error", f.errorString()); return false; } QTextStream in(&f); //intialize some variables bool readData = false; //are we reading data char columnSeperator = ' '; //character to split the data QHash<int, int> columnInfo; //hash table om kolommen in de data te vinden columnInfo[1] = -1; //sondeerlengte columnInfo[2] = -1; //puntdruk (qc) columnInfo[3] = -1; //lokale wrijving (pw) columnInfo[11] = -1; //gecorrigeerde diepte QHash<int, int> columnVoid; columnVoid[1] = -9999; columnVoid[2] = -9999; columnVoid[3] = -9999; columnVoid[11] = -9999; //read line by line while(!in.atEnd()){ QString line = in.readLine(); //determine if we are reading the header or the data if(!readData){ //get keyword and arguments QString keyword = line.split('=')[0].trimmed(); QStringList args = line.split('=')[1].split(','); //depending on the keyword take specific actions if(keyword.compare("#COLUMNINFO")==0){ if(args.count()!=4){ m_errors.append(QString("[%0] error reading columninfo: %1").arg(filename).arg(line)); return false; } int column = args[0].trimmed().toInt() - 1; //note that the actual column is -1 because of zero indexing int id = args[3].trimmed().toInt(); columnInfo[id] = column; }else if(keyword.compare("#COLUMNSEPARATOR")==0){ if(args[0].trimmed().length()>0){ columnSeperator = args[0].trimmed().toStdString()[0]; } }else if(keyword.compare("#COLUMNVOID")==0){ if(args.count()!=2){ m_errors.append(QString("[%0] error reading columninfo: %1").arg(filename).arg(line)); return false; } int column = args[0].trimmed().toInt(); int value = args[1].trimmed().toFloat(); if((column >= 1 && column <= 3) || column == 11 ){ columnVoid[column] = int(value); } }else if(keyword.compare("#XYID")==0){ if(args.count()<3){ m_errors.append(QString("[%0] error reading xy coordinates: %1").arg(filename).arg(line)); return false; } m_x = args[1].trimmed().toFloat(); m_y = args[2].trimmed().toFloat(); }else if(keyword.compare("#ZID")==0){ if(args.count()<2){ m_errors.append(QString("[%0] error reading z coordinate: %1").arg(filename).arg(line)); return false; } m_z = args[1].trimmed().toFloat(); }else if(keyword.compare("#REPORTCODE")==0){ if(args[0].contains("GEF-BORE")){ m_errors.append(QString("[%0] is a borehole report.").arg(filename)); return false; } }else if(keyword.compare("#EOH")==0){ //end of header, now check for correct information before reading the data //check for missing columninfo if(columnInfo[1]==-1){ m_errors.append(QString("[%0] cannot find z column").arg(filename)); return false; } if(columnInfo[2]==-1){ m_errors.append(QString("[%0] cannot find qc column").arg(filename)); return false; } if(columnInfo[3]==-1){ m_errors.append(QString("[%0] cannot find pw column").arg(filename)); return false; } //if there is a column with id = 11 this overrules column 1 (as well as the void value) if(columnInfo[11]!=-1){ columnInfo[1] = columnInfo[11]; columnVoid[1] = columnVoid[11]; } //ok, done, start reading the data readData = true; } }else{ QStringList args = line.split(columnSeperator); //remove empty arguments QStringList cleanedArgs; for(int i=0; i<args.count(); i++){ if(args[i].trimmed()!=""){ cleanedArgs.append(args[i]); } } if(cleanedArgs.count()>0){ try{ float depth = cleanedArgs[columnInfo[1]].trimmed().toFloat(); float qc = cleanedArgs[columnInfo[2]].trimmed().toFloat(); float pw = cleanedArgs[columnInfo[3]].trimmed().toFloat(); if(depth < 0){ m_errors.append(QString("[%0] foutieve sondeerlengte %1").arg(filename).arg(depth)); return false; }else{ //skip void values bool skip = false; bool check = columnVoid[1] != 0 || columnVoid[2] != 0 || columnVoid[3] != 0; if(check){ skip = int(depth)==columnVoid[1] || int(qc)==columnVoid[2] || int(pw) == columnVoid[3]; } if(!skip){ m_depth.append(m_z - qFabs(depth)); m_qc.append(qc); m_pw.append(pw); m_rs.append(-1); //default every layer has no soiltype, is filled in afterwards } } }catch(...){ m_errors.append(QString("[%0] error reading line %s").arg(filename)); return false; } } } } toRobertson(); //determine the soillayers per depth //asRobertson(0.2); //close file f.close(); //we came this far so yeah.. result! return true; }
void Widget::on_pushButtonLagra_clicked() { ui->widget->clearGraphs(); // Graphf* gf = new Graphf(); gf->setStartX(ui->lineEditLagraStart->text().toDouble()); gf->setFinishX(ui->lineEditLagraFinish->text().toDouble()); gf->setPointsCount((gf->finishX - gf->startX) * 10 + 1); gf->setStepY((gf->finishX - gf->startX) / (gf->points_count - 1)); gf->calcf(); QCPGraph *graph = ui->widget->addGraph(); graph->setData(gf->fX, gf->fY); graph->setPen(QPen(Qt::red, 1)); graph->setName("f(x)"); // // Lagra* l = new Lagra(ui->lineEditLagraPointsCount->text().toInt() + 1); l->calcF(gf); graph = ui->widget->addGraph(); graph->setData(gf->fX, l->result); graph->setPen(QPen(Qt::blue, 1)); graph->setName("L(x)"); // // QVector<double> Rt(gf->points_count); for (int i = 0; i < Rt.size(); i++) Rt[i] = qFabs(gf->fY[i] - l->result[i]); qDebug() << Rt; graph = ui->widget->addGraph(); graph->setData(gf->fX, Rt); graph->setPen(QPen(Qt::black, 1)); graph->setName("R(x)"); // // LagraRp* lrp = NULL; int unit_points = l->lX.size(); if (unit_points - 1 == 5) { lrp = new LagraRp(); lrp->calcRp(gf, l); graph = ui->widget->addGraph(); graph->setData(gf->fX, lrp->result); graph->setPen(QPen(Qt::green, 1)); graph->setName("Теоретическая погрешность"); } // ui->widget->xAxis->setRange(gf->startX, gf->finishX); ui->widget->yAxis->setRange(0, 10); ui->widget->replot(); /* Рисуем */ if (lrp != NULL) delete lrp; delete l; delete gf; }
void GLWidget::createSphere(float radius, int slices, int stacks) { freeSphere(); float stackFract = 2.0f / (stacks); float centerStack = (stacks - 1) / 2.0f; float* stackR = new float[stacks]; float* stackH = new float[stacks]; for (int i = 0; i < stacks; i++) { stackR[i] = qFabs(centerStack - i) * stackFract; // высота катета из центра пропорциональная (гипотенуза = radius) stackH[i] = stackR[i] * radius; // высотра катета (слоя) реальная if (i > centerStack) stackH[i] *= -1.0f; //поправка на верх-низ stackR[i] = sqrtf(1.0f - powf(stackR[i], 2.0f)) * radius; // радиус в сечении слоя } sphereVerticesSize = (stacks * 2 - 2) * (slices + 1) * 3; sphereVertices = new float[sphereVerticesSize]; float alpha = M_PI * 2.0 / slices; // угол между медианами float alpha_2 = alpha / 2.0f; sphereConeSize = (slices + 2) * 3; upSphereCone = new float[sphereConeSize]; downSphereCone = new float[sphereConeSize]; upSphereCone += 3; //чтение координат на первом круге. потом в цикле их не нужно будет повторно считывать for (int j = 0; j < slices + 1; j++) { upSphereCone[j * 3] = sphereVertices[j * 6] = cosf(alpha * j) * stackR[0]; upSphereCone[j * 3 + 1] = sphereVertices[j * 6 + 1] = stackH[0]; upSphereCone[j * 3 + 2] = sphereVertices[j * 6 + 2] = sinf(alpha * j) * stackR[0]; } upSphereCone -= 3; for (int i = 1; i < stacks; i++) { static float delta = 0.0f; delta += alpha_2; for (int j = 0; j < slices + 1; j++) { sphereVertices[j * 6 + 3 + (slices + 1) * 6 * (i - 1)] = cosf(alpha * j + delta) * stackR[i]; sphereVertices[j * 6 + 4 + (slices + 1) * 6 * (i - 1)] = stackH[i]; sphereVertices[j * 6 + 5 + (slices + 1) * 6 * (i - 1)] = sinf(alpha * j + delta) * stackR[i]; } if (i != stacks - 1) memcpy(sphereVertices + (slices + 1) * 6 * i, sphereVertices + (slices + 1) * 6 * (i - 1) + 3, ((slices + 1) * 6 - 3) * sizeof(float)); } delete[] stackR; delete[] stackH; downSphereCone[0] = downSphereCone[2] = upSphereCone[0] = upSphereCone[2] = 0.0f; upSphereCone[1] = radius; downSphereCone[1] = -radius; float* tmp = downSphereCone + 3; for (int j = slices ; j >= 0 ; j--) { tmp[j * 3] = sphereVertices[sphereVerticesSize - 3 - j * 6]; tmp[j * 3 + 1] = sphereVertices[sphereVerticesSize - 2 - j * 6]; tmp[j * 3 + 2] = sphereVertices[sphereVerticesSize - 1 - j * 6]; } }