Conductor properties: added the "PEN" option, which enables users to merge neutral and ground symbols.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@1933 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-08-12 20:32:53 +00:00
parent eb2acce3b6
commit b5430118e4
4 changed files with 90 additions and 34 deletions

View File

@@ -23,6 +23,7 @@
SingleLineProperties::SingleLineProperties() : SingleLineProperties::SingleLineProperties() :
hasGround(true), hasGround(true),
hasNeutral(true), hasNeutral(true),
is_pen(false),
phases(1) phases(1)
{ {
} }
@@ -44,6 +45,15 @@ unsigned short int SingleLineProperties::phasesCount() {
return(phases); return(phases);
} }
/**
@return true if the singleline conductor should be drawn using the PEN
(Protective Earth Neutral) representation and if it features the ground and
the neutral.
*/
bool SingleLineProperties::isPen() const {
return(hasNeutral && hasGround && is_pen);
}
/** /**
Dessine les symboles propres a un conducteur unifilaire Dessine les symboles propres a un conducteur unifilaire
@param painter QPainter a utiliser pour dessiner les symboles @param painter QPainter a utiliser pour dessiner les symboles
@@ -59,38 +69,33 @@ void SingleLineProperties::draw(QPainter *painter, QET::ConductorSegmentType dir
QPen pen(painter -> pen()); QPen pen(painter -> pen());
pen.setCapStyle(Qt::FlatCap); pen.setCapStyle(Qt::FlatCap);
pen.setJoinStyle(Qt::MiterJoin); pen.setJoinStyle(Qt::MiterJoin);
pen.setStyle(Qt::SolidLine);
painter -> setPen(pen); painter -> setPen(pen);
painter -> setRenderHint(QPainter::Antialiasing, true); painter -> setRenderHint(QPainter::Antialiasing, true);
uint symbols_count = (hasNeutral ? 1 : 0) + (hasGround ? 1 : 0) + phases; uint symbols_count = (hasNeutral ? 1 : 0) + (hasGround ? 1 : 0) - (isPen() ? 1 : 0) + phases;
qreal interleave; qreal interleave_base = (direction == QET::Horizontal ? rect.width() : rect.height());
qreal symbol_width; qreal interleave = interleave_base / (symbols_count + 1);;
if (direction == QET::Horizontal) { qreal symbol_width = interleave_base / 12;
interleave = rect.width() / (symbols_count + 1);
symbol_width = rect.width() / 12;
for (uint i = 1 ; i <= symbols_count ; ++ i) { for (uint i = 1 ; i <= symbols_count ; ++ i) {
// dessine le tronc du symbole // dessine le tronc du symbole
QPointF symbol_p1(rect.x() + (i * interleave) + symbol_width, rect.y() + rect.height() * 0.75); QPointF symbol_p1, symbol_p2;
QPointF symbol_p2(rect.x() + (i * interleave) - symbol_width, rect.y() + rect.height() * 0.25); if (direction == QET::Horizontal) {
symbol_p1 = QPointF(rect.x() + (i * interleave) + symbol_width, rect.y() + rect.height() * 0.75);
symbol_p2 = QPointF(rect.x() + (i * interleave) - symbol_width, rect.y() + rect.height() * 0.25);
} else {
symbol_p2 = QPointF(rect.x() + rect.width() * 0.75, rect.y() + (i * interleave) - symbol_width);
symbol_p1 = QPointF(rect.x() + rect.width() * 0.25, rect.y() + (i * interleave) + symbol_width);
}
painter -> drawLine(QLineF(symbol_p1, symbol_p2)); painter -> drawLine(QLineF(symbol_p1, symbol_p2));
// dessine le reste des symboles terre et neutre // dessine le reste des symboles terre et neutre
if (hasGround && i == 1) { if (isPen()) {
drawGround(painter, direction, symbol_p2, symbol_width * 2.0); if (i == 1) {
} else if (hasNeutral && ((i == 1 && !hasGround) || (i == 2 && hasGround))) { drawPen(painter, direction, symbol_p2, symbol_width);
drawNeutral(painter, direction, symbol_p2, symbol_width * 1.35);
}
} }
} else { } else {
interleave = rect.height() / (symbols_count + 1);
symbol_width = rect.height() / 12;
for (uint i = 1 ; i <= symbols_count ; ++ i) {
// dessine le tronc du symbole
QPointF symbol_p2(rect.x() + rect.width() * 0.75, rect.y() + (i * interleave) - symbol_width);
QPointF symbol_p1(rect.x() + rect.width() * 0.25, rect.y() + (i * interleave) + symbol_width);
painter -> drawLine(QLineF(symbol_p1, symbol_p2));
// dessine le reste des symboles terre et neutre
if (hasGround && i == 1) { if (hasGround && i == 1) {
drawGround(painter, direction, symbol_p2, symbol_width * 2.0); drawGround(painter, direction, symbol_p2, symbol_width * 2.0);
} else if (hasNeutral && ((i == 1 && !hasGround) || (i == 2 && hasGround))) { } else if (hasNeutral && ((i == 1 && !hasGround) || (i == 2 && hasGround))) {
@@ -159,6 +164,30 @@ void SingleLineProperties::drawNeutral(QPainter *painter, QET::ConductorSegmentT
painter -> restore(); painter -> restore();
} }
/**
Draw the PEN (Protective Earth Neutral) symbol using \a painter at position \a
center, using a size hint of \a size.
@param direction Indicate the direction of the underlying conductor segment
*/
void SingleLineProperties::drawPen(QPainter *painter, QET::ConductorSegmentType direction, QPointF center, qreal size) {
painter -> save();
//painter -> setBrush(Qt::white);
// desine le cercle representant le neutre
//painter -> drawEllipse(
// QRectF(
// center - QPointF(size * 1.5 / 2.0, size * 1.5 / 2.0),
// QSizeF(size * 1.5, size * 1.5)
// )
//);
drawNeutral(painter, direction, center, size * 1.5);
int offset = (size * 1.5 / 2.0);
QPointF pos = center + (direction == QET::Horizontal ? QPointF(0.0, -offset - 0.5) : QPointF(offset + 0.5, 0.0));
drawGround(painter, direction, pos, 2.0 * size);
painter -> restore();
}
/** /**
Exporte les parametres du conducteur unifilaire sous formes d'attributs XML Exporte les parametres du conducteur unifilaire sous formes d'attributs XML
ajoutes a l'element e. ajoutes a l'element e.
@@ -168,6 +197,7 @@ void SingleLineProperties::toXml(QDomElement &e) const {
e.setAttribute("ground", hasGround ? "true" : "false"); e.setAttribute("ground", hasGround ? "true" : "false");
e.setAttribute("neutral", hasNeutral ? "true" : "false"); e.setAttribute("neutral", hasNeutral ? "true" : "false");
e.setAttribute("phase", phases); e.setAttribute("phase", phases);
if (isPen()) e.setAttribute("pen", "true");
} }
/** /**
@@ -179,6 +209,7 @@ void SingleLineProperties::fromXml(QDomElement &e) {
hasGround = e.attribute("ground") == "true"; hasGround = e.attribute("ground") == "true";
hasNeutral = e.attribute("neutral") == "true"; hasNeutral = e.attribute("neutral") == "true";
setPhasesCount(e.attribute("phase").toInt()); setPhasesCount(e.attribute("phase").toInt());
is_pen = (hasGround && hasNeutral && e.attribute("pen", "false") == "true");
} }
/** /**
@@ -378,6 +409,7 @@ int SingleLineProperties::operator==(const SingleLineProperties &other) const {
return( return(
other.hasGround == hasGround &&\ other.hasGround == hasGround &&\
other.hasNeutral == hasNeutral &&\ other.hasNeutral == hasNeutral &&\
other.is_pen == is_pen &&\
other.phases == phases other.phases == phases
); );
} }
@@ -398,6 +430,7 @@ void SingleLineProperties::toSettings(QSettings &settings, const QString &prefix
settings.setValue(prefix + "hasGround", hasGround); settings.setValue(prefix + "hasGround", hasGround);
settings.setValue(prefix + "hasNeutral", hasNeutral); settings.setValue(prefix + "hasNeutral", hasNeutral);
settings.setValue(prefix + "phases", phases); settings.setValue(prefix + "phases", phases);
settings.setValue(prefix + "pen", is_pen);
} }
/** /**
@@ -408,4 +441,5 @@ void SingleLineProperties::fromSettings(QSettings &settings, const QString &pref
hasGround = settings.value(prefix + "hasGround", true).toBool(); hasGround = settings.value(prefix + "hasGround", true).toBool();
hasNeutral = settings.value(prefix + "hasNeutral", true).toBool(); hasNeutral = settings.value(prefix + "hasNeutral", true).toBool();
phases = settings.value(prefix + "phases", 1).toInt(); phases = settings.value(prefix + "phases", 1).toInt();
is_pen = settings.value(prefix + "pen", false).toBool();
} }

View File

@@ -30,6 +30,7 @@ class SingleLineProperties {
void setPhasesCount(int); void setPhasesCount(int);
unsigned short int phasesCount(); unsigned short int phasesCount();
bool isPen() const;
void draw(QPainter *, QET::ConductorSegmentType, const QRectF &); void draw(QPainter *, QET::ConductorSegmentType, const QRectF &);
void toXml(QDomElement &) const; void toXml(QDomElement &) const;
void fromXml(QDomElement &); void fromXml(QDomElement &);
@@ -40,6 +41,8 @@ class SingleLineProperties {
bool hasGround; bool hasGround;
/// indique si le conducteur unifilaire doit afficher le symbole neutre /// indique si le conducteur unifilaire doit afficher le symbole neutre
bool hasNeutral; bool hasNeutral;
/// Protective Earth Neutral: visually merge neutral and ground
bool is_pen;
int operator==(const SingleLineProperties &) const; int operator==(const SingleLineProperties &) const;
int operator!=(const SingleLineProperties &) const; int operator!=(const SingleLineProperties &) const;
@@ -48,6 +51,7 @@ class SingleLineProperties {
unsigned short int phases; unsigned short int phases;
void drawGround (QPainter *, QET::ConductorSegmentType, QPointF, qreal); void drawGround (QPainter *, QET::ConductorSegmentType, QPointF, qreal);
void drawNeutral(QPainter *, QET::ConductorSegmentType, QPointF, qreal); void drawNeutral(QPainter *, QET::ConductorSegmentType, QPointF, qreal);
void drawPen(QPainter *, QET::ConductorSegmentType, QPointF, qreal);
}; };
/** /**

View File

@@ -68,6 +68,21 @@ void ConductorPropertiesWidget::buildInterface() {
singleline = new QRadioButton(tr("Unifilaire")); singleline = new QRadioButton(tr("Unifilaire"));
ground_checkbox = new QCheckBox(tr("terre"));
ground_checkbox -> setIcon(QET::Icons::Ground);
neutral_checkbox = new QCheckBox(tr("neutre"));
neutral_checkbox -> setIcon(QET::Icons::Neutral);
merge_checkbox = new QCheckBox(tr("PEN", "Protective Earth Neutral"));
merge_checkbox -> setToolTip(tr("Protective Earth Neutral", "Tooltip displaying the meaning of the 'PEN' acronym"));
QVBoxLayout *singleline_layout5 = new QVBoxLayout();
singleline_layout5 -> addWidget(ground_checkbox);
singleline_layout5 -> addWidget(neutral_checkbox);
QHBoxLayout *singleline_layout4 = new QHBoxLayout();
singleline_layout4 -> addLayout(singleline_layout5);
singleline_layout4 -> addWidget(merge_checkbox, 4, Qt::AlignVCenter | Qt::AlignLeft);
QHBoxLayout *singleline_layout3 = new QHBoxLayout(); QHBoxLayout *singleline_layout3 = new QHBoxLayout();
phase_checkbox = new QCheckBox(tr("phase")); phase_checkbox = new QCheckBox(tr("phase"));
phase_checkbox -> setIcon(QET::Icons::Phase); phase_checkbox -> setIcon(QET::Icons::Phase);
@@ -80,12 +95,7 @@ void ConductorPropertiesWidget::buildInterface() {
singleline_layout3 -> addWidget(phase_spinbox); singleline_layout3 -> addWidget(phase_spinbox);
QVBoxLayout *singleline_layout2 = new QVBoxLayout(); QVBoxLayout *singleline_layout2 = new QVBoxLayout();
ground_checkbox = new QCheckBox(tr("terre")); singleline_layout2 -> addLayout(singleline_layout4);
ground_checkbox -> setIcon(QET::Icons::Ground);
neutral_checkbox = new QCheckBox(tr("neutre"));
neutral_checkbox -> setIcon(QET::Icons::Neutral);
singleline_layout2 -> addWidget(ground_checkbox);
singleline_layout2 -> addWidget(neutral_checkbox);
singleline_layout2 -> addLayout(singleline_layout3); singleline_layout2 -> addLayout(singleline_layout3);
QHBoxLayout *singleline_layout1 = new QHBoxLayout(); QHBoxLayout *singleline_layout1 = new QHBoxLayout();
@@ -135,6 +145,7 @@ void ConductorPropertiesWidget::buildConnections() {
connect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int))); connect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int)));
connect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig())); connect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
connect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig())); connect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
connect(merge_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
connect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig())); connect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
connect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig())); connect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
connect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig())); connect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
@@ -178,6 +189,7 @@ void ConductorPropertiesWidget::destroyConnections() {
disconnect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int))); disconnect(phase_spinbox, SIGNAL(valueChanged(int)), phase_slider, SLOT(setValue(int)));
disconnect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig())); disconnect(ground_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
disconnect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig())); disconnect(neutral_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
disconnect(merge_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
disconnect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig())); disconnect(phase_checkbox, SIGNAL(toggled(bool)), this, SLOT(updateConfig()));
disconnect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig())); disconnect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
disconnect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig())); disconnect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
@@ -198,6 +210,7 @@ void ConductorPropertiesWidget::updateConfig() {
properties_.text = text_field -> text(); properties_.text = text_field -> text();
properties_.singleLineProperties.hasGround = ground_checkbox -> isChecked(); properties_.singleLineProperties.hasGround = ground_checkbox -> isChecked();
properties_.singleLineProperties.hasNeutral = neutral_checkbox -> isChecked(); properties_.singleLineProperties.hasNeutral = neutral_checkbox -> isChecked();
properties_.singleLineProperties.is_pen = merge_checkbox -> isChecked();
properties_.singleLineProperties.setPhasesCount(phase_checkbox -> isChecked() ? phase_spinbox -> value() : 0); properties_.singleLineProperties.setPhasesCount(phase_checkbox -> isChecked() ? phase_spinbox -> value() : 0);
updateDisplay(); updateDisplay();
@@ -213,6 +226,8 @@ void ConductorPropertiesWidget::updateDisplay() {
text_field -> setText(properties_.text); text_field -> setText(properties_.text);
ground_checkbox -> setChecked(properties_.singleLineProperties.hasGround); ground_checkbox -> setChecked(properties_.singleLineProperties.hasGround);
neutral_checkbox -> setChecked(properties_.singleLineProperties.hasNeutral); neutral_checkbox -> setChecked(properties_.singleLineProperties.hasNeutral);
merge_checkbox -> setChecked(properties_.singleLineProperties.is_pen);
merge_checkbox -> setEnabled(!isReadOnly() && ground_checkbox -> isChecked() && neutral_checkbox -> isChecked());
phase_spinbox -> setValue(properties_.singleLineProperties.phasesCount()); phase_spinbox -> setValue(properties_.singleLineProperties.phasesCount());
phase_slider -> setValue(properties_.singleLineProperties.phasesCount()); phase_slider -> setValue(properties_.singleLineProperties.phasesCount());
phase_checkbox -> setChecked(properties_.singleLineProperties.phasesCount()); phase_checkbox -> setChecked(properties_.singleLineProperties.phasesCount());
@@ -257,6 +272,7 @@ void ConductorPropertiesWidget::setConductorType(ConductorProperties::ConductorT
phase_spinbox -> setEnabled(sl); phase_spinbox -> setEnabled(sl);
ground_checkbox -> setEnabled(sl); ground_checkbox -> setEnabled(sl);
neutral_checkbox -> setEnabled(sl); neutral_checkbox -> setEnabled(sl);
merge_checkbox -> setEnabled(sl);
} }
/// @param p les nouvelles proprietes /// @param p les nouvelles proprietes
@@ -290,6 +306,7 @@ void ConductorPropertiesWidget::setReadOnly(bool ro) {
phase_spinbox -> setReadOnly(ro); phase_spinbox -> setReadOnly(ro);
ground_checkbox -> setDisabled(ro); ground_checkbox -> setDisabled(ro);
neutral_checkbox -> setDisabled(ro); neutral_checkbox -> setDisabled(ro);
merge_checkbox -> setDisabled(ro);
color_button -> setDisabled(ro); color_button -> setDisabled(ro);
dashed_checkbox -> setDisabled(ro); dashed_checkbox -> setDisabled(ro);
// if the widget is not read-only, we still need to disable some widgets for consistency // if the widget is not read-only, we still need to disable some widgets for consistency

View File

@@ -72,6 +72,7 @@ class ConductorPropertiesWidget : public QWidget {
QLabel *preview; QLabel *preview;
QPushButton *color_button; QPushButton *color_button;
QCheckBox *dashed_checkbox; QCheckBox *dashed_checkbox;
QCheckBox *merge_checkbox;
ConductorProperties properties_; ConductorProperties properties_;