00001
00002
00003
00004
00005
00006
00007 #include "DocumentModelGeneral.h"
00008 #include "FormatCoordsUnitsStrategyAbstractBase.h"
00009 #include "Logger.h"
00010 #include <qmath.h>
00011 #include "Transformation.h"
00012
00013 FormatCoordsUnitsStrategyAbstractBase::FormatCoordsUnitsStrategyAbstractBase ()
00014 {
00015 }
00016
00017 int FormatCoordsUnitsStrategyAbstractBase::precisionDigitsForRawNumber (double valueUnformatted,
00018 double valueUnformattedOther,
00019 bool isXTheta,
00020 const DocumentModelGeneral &modelGeneral,
00021 const Transformation &transformation) const
00022 {
00023 LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyAbstractBase::precisionDigitsForRawNumber";
00024
00025 const double PIXEL_SHIFT = 1;
00026 const int DEFAULT_PRECISION = 5;
00027
00028 if (transformation.transformIsDefined()) {
00029
00030
00031 QPointF posGraph;
00032 if (isXTheta) {
00033
00034 posGraph = QPointF (valueUnformatted,
00035 valueUnformattedOther);
00036
00037 } else {
00038
00039 posGraph = QPointF (valueUnformattedOther,
00040 valueUnformatted);
00041
00042 }
00043
00044 QPointF posScreen, posScreenShifted, posGraphShifted;
00045
00046 transformation.transformRawGraphToScreen (posGraph,
00047 posScreen);
00048
00049 posScreenShifted = posScreen + QPointF (PIXEL_SHIFT, PIXEL_SHIFT);
00050
00051 transformation.transformScreenToRawGraph (posScreenShifted,
00052 posGraphShifted);
00053
00054 double xResolutionPerPixel = (posGraphShifted.x() - posGraph.x()) / PIXEL_SHIFT;
00055 double yResolutionPerPixel = (posGraphShifted.y() - posGraph.y()) / PIXEL_SHIFT;
00056 double resolutionPerPixel = (isXTheta ? xResolutionPerPixel : yResolutionPerPixel);
00057
00058
00059 int powerValue = qFloor (qLn (qAbs (valueUnformatted)) / qLn (10.0));
00060 int powerResolution = qFloor (qLn (qAbs (resolutionPerPixel)) / qLn (10.0));
00061
00062 int numberDigitsForResolution = powerValue - powerResolution + 1 + modelGeneral.extraPrecision();
00063
00064 return numberDigitsForResolution + 1;
00065
00066 } else {
00067
00068 return DEFAULT_PRECISION;
00069 }
00070 }