#include "stdafx.h" #include "QYMotorDoubleSlider.h" QYMotorDoubleSlider::QYMotorDoubleSlider(QWidget* pParent /*= NULL*/) :QSlider(pParent) { connect(this, SIGNAL(valueChanged(int)), this, SLOT(notifyValueChanged(int))); setSingleStep(1); setOrientation(Qt::Horizontal); setFocusPolicy(Qt::NoFocus); //配置文件 string HPPACfgFile = getPathofEXE() + "\\HPPA.cfg"; Configfile configfile; configfile.setConfigfilePath(HPPACfgFile); if (!configfile.isConfigfileExist()) configfile.createConfigFile(); configfile.parseConfigfile(); float StepAnglemar_y; float Lead_y; float ScaleFactor_y;//因机械装置的原因引入的缩放因子 int SubdivisionMultiples_y; configfile.getYMotorParm(StepAnglemar_y, Lead_y, SubdivisionMultiples_y, ScaleFactor_y); //m_Multiplier(0.000108993972),//上海农科院,修改前:0.00052734375/5=0.00010546875;修改后准确值为0.000544969862759644,近似为0.00054496986/5=0.000108993972,因为有个机械装置1脉冲距离需要除以5; //m_Multiplier(0.000108993972)//兴安盟农研所 m_Multiplier = Lead_y / (360 / StepAnglemar_y * SubdivisionMultiples_y) * ScaleFactor_y; } //向外发射 void QYMotorDoubleSlider::notifyValueChanged(int Value) { emit valueChanged((double)Value * m_Multiplier);////////// } //接收外边 void QYMotorDoubleSlider::setValue(double Value, bool BlockSignals) { QSlider::blockSignals(BlockSignals); QSlider::setValue(Value / m_Multiplier);//////////// if (!BlockSignals) emit valueChanged(Value); QSlider::blockSignals(false); } void QYMotorDoubleSlider::setRange(double Min, double Max) { QSlider::setRange(Min / m_Multiplier, Max / m_Multiplier);////// emit rangeChanged(Min, Max); } void QYMotorDoubleSlider::setMinimum(double Min) { QSlider::setMinimum(Min / m_Multiplier);////// emit rangeChanged(minimum(), maximum()); } double QYMotorDoubleSlider::minimum() const { return QSlider::minimum() * m_Multiplier;///// } void QYMotorDoubleSlider::setMaximum(double Max) { QSlider::setMaximum(Max / m_Multiplier);////// emit rangeChanged(minimum(), maximum()); } double QYMotorDoubleSlider::maximum() const { return QSlider::maximum() * m_Multiplier;/////// } double QYMotorDoubleSlider::value() const { int Value = QSlider::value(); return (double)Value * m_Multiplier;////// } double QYMotorDoubleSlider::OriginalValue() const { int Value = QSlider::value(); return (double)Value; } long QYMotorDoubleSlider::getPositionPulse(double position) { return position / m_Multiplier; } double QYMotorDoubleSlider::getDistanceFromPulse(int pulse) { return pulse * m_Multiplier; }