xref: switch contact is managed by cross ref

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3201 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-07-07 14:36:53 +00:00
parent bf4a2bbaec
commit 844167f181
8 changed files with 194 additions and 96 deletions

View File

@@ -0,0 +1,31 @@
<definition width="30" version="0.4" hotspot_x="25" hotspot_y="25" height="50" link_type="slave" type="element" ic="true" orientation="dyyy">
<names>
<name lang="ar">مُلامس NO-NC</name>
<name lang="de">Wechselkontakt (NO/NC)</name>
<name lang="ru">Проктой контакт (НР)</name>
<name lang="el">Απλή μεταγωγική επαφή</name>
<name lang="en">Simple contact</name>
<name lang="it">Contatto semplice (NC/NO)</name>
<name lang="fr">Contact NO - NC</name>
<name lang="pl">Zestyk przełączny przerwowy</name>
<name lang="es">Contacto simple</name>
<name lang="nl">enkel contact (NC/NO)</name>
<name lang="cs">Jednoduchý kontakt</name>
</names>
<kindInformations>
<kindInformation name="number" show="1">1</kindInformation>
<kindInformation name="type" show="1">simple</kindInformation>
<kindInformation name="state" show="1">SW</kindInformation>
</kindInformations>
<informations>Author: The QElectroTech team
License: see http://qelectrotech.org/wiki/doc/elements_license</informations>
<description>
<polygon antialias="true" style="line-style:normal;line-weight:normal;filling:none;color:black" closed="false" y1="-10" x1="-15" y2="10" x2="0" y3="20" x3="0"/>
<input x="13" y="-3" size="9" text="_" tagg="label"/>
<line length1="1.5" length2="1.5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="-20" x1="0" y2="-10" x2="0"/>
<polygon antialias="false" style="line-style:normal;line-weight:normal;filling:none;color:black" closed="false" y1="-20" x1="-20" y2="-8" x2="-20" y3="-8" x3="-12"/>
<terminal x="0" y="-20" orientation="n"/>
<terminal x="0" y="20" orientation="s"/>
<terminal x="-20" y="-20" orientation="n"/>
</description>
</definition>

View File

@@ -79,6 +79,7 @@ void ElementPropertiesEditorWidget::setUpInterface() {
// Slave option // Slave option
ui -> m_state_cb -> addItem(tr("Normalement ouvert"), QVariant("NO")); ui -> m_state_cb -> addItem(tr("Normalement ouvert"), QVariant("NO"));
ui -> m_state_cb -> addItem(tr("Normalement ferm\351"), QVariant("NC")); ui -> m_state_cb -> addItem(tr("Normalement ferm\351"), QVariant("NC"));
ui -> m_state_cb -> addItem(tr("Inverseur"), QVariant("SW"));
ui -> m_type_cb -> addItem(tr("Simple"), QVariant("simple")); ui -> m_type_cb -> addItem(tr("Simple"), QVariant("simple"));
ui -> m_type_cb -> addItem(tr("Puissance"), QVariant("power")); ui -> m_type_cb -> addItem(tr("Puissance"), QVariant("power"));
ui -> m_type_cb -> addItem(tr("Temporis\351 travail"), QVariant("delayOn")); ui -> m_type_cb -> addItem(tr("Temporis\351 travail"), QVariant("delayOn"));

View File

@@ -26,6 +26,7 @@ XRefProperties::XRefProperties()
m_show_power_ctc = true; m_show_power_ctc = true;
m_display = Cross; m_display = Cross;
m_snap_to = Bottom; m_snap_to = Bottom;
m_prefix_keys << "power" << "delay" << "switch";
} }
/** /**
@@ -40,8 +41,9 @@ void XRefProperties::toSettings(QSettings &settings, const QString prefix) const
settings.setValue(prefix + "displayhas", display); settings.setValue(prefix + "displayhas", display);
QString snap = m_snap_to == Bottom? "bottom" : "label"; QString snap = m_snap_to == Bottom? "bottom" : "label";
settings.setValue(prefix + "snapto", snap); settings.setValue(prefix + "snapto", snap);
settings.setValue(prefix + "powerprefix", m_prefix.value("power")); foreach (QString key, m_prefix.keys()) {
settings.setValue(prefix + "delayprefix", m_prefix.value("delay")); settings.setValue(prefix + key + "prefix", m_prefix.value(key));
}
} }
/** /**
@@ -56,8 +58,9 @@ void XRefProperties::fromSettings(const QSettings &settings, const QString prefi
display == "cross"? m_display = Cross : m_display = Contacts; display == "cross"? m_display = Cross : m_display = Contacts;
QString snap = settings.value(prefix + "snapto", "label").toString(); QString snap = settings.value(prefix + "snapto", "label").toString();
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label; snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
m_prefix.insert("power", settings.value(prefix + "powerprefix").toString()); foreach (QString key, m_prefix_keys) {
m_prefix.insert("delay", settings.value(prefix + "delayprefix").toString()); m_prefix.insert(key, settings.value(prefix + key + "prefix").toString());
}
} }
/** /**
@@ -71,8 +74,9 @@ void XRefProperties::toXml(QDomElement &xml_element) const {
xml_element.setAttribute("displayhas", display); xml_element.setAttribute("displayhas", display);
QString snap = m_snap_to == Bottom? "bottom" : "label"; QString snap = m_snap_to == Bottom? "bottom" : "label";
xml_element.setAttribute("snapto", snap); xml_element.setAttribute("snapto", snap);
xml_element.setAttribute("powerprefix", m_prefix.value("power")); foreach (QString key, m_prefix.keys()) {
xml_element.setAttribute("delayprefix", m_prefix.value("delay")); xml_element.setAttribute(key + "prefix", m_prefix.value(key));
}
} }
/** /**
@@ -86,8 +90,9 @@ void XRefProperties::fromXml(const QDomElement &xml_element) {
display == "cross"? m_display = Cross : m_display = Contacts; display == "cross"? m_display = Cross : m_display = Contacts;
QString snap = xml_element.attribute("snapto", "label"); QString snap = xml_element.attribute("snapto", "label");
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label; snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
m_prefix.insert("power", xml_element.attribute("powerprefix")); foreach (QString key, m_prefix_keys) {
m_prefix.insert("delay", xml_element.attribute("delayprefix")); m_prefix.insert(key, xml_element.attribute(key + "prefix"));
}
} }
bool XRefProperties::operator ==(const XRefProperties &xrp) const{ bool XRefProperties::operator ==(const XRefProperties &xrp) const{

View File

@@ -19,6 +19,7 @@
#define XREFPROPERTIES_H #define XREFPROPERTIES_H
#include "propertiesinterface.h" #include "propertiesinterface.h"
#include <QStringList>
/** /**
* @brief The XRefProperties class * @brief The XRefProperties class
@@ -64,6 +65,7 @@ class XRefProperties : public PropertiesInterface
DisplayHas m_display; DisplayHas m_display;
SnapTo m_snap_to; SnapTo m_snap_to;
QHash <QString, QString> m_prefix; QHash <QString, QString> m_prefix;
QStringList m_prefix_keys;
}; };
#endif // XREFPROPERTIES_H #endif // XREFPROPERTIES_H

View File

@@ -94,6 +94,7 @@ QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_p
if (add_prefix) { if (add_prefix) {
if (elmt->kindInformations()["type"].toString() == "power") txt.prepend(m_properties.prefix("power")); if (elmt->kindInformations()["type"].toString() == "power") txt.prepend(m_properties.prefix("power"));
else if (elmt->kindInformations()["type"].toString().contains("delay")) txt.prepend(m_properties.prefix("delay")); else if (elmt->kindInformations()["type"].toString().contains("delay")) txt.prepend(m_properties.prefix("delay"));
else if (elmt->kindInformations()["state"].toString() == "SW") txt.prepend(m_properties.prefix("switch"));
} }
return txt; return txt;
} }
@@ -111,12 +112,24 @@ void CrossRefItem::allElementsPositionText(QString &no_str, QString &nc_str, con
foreach (Element *elmt, m_element->linkedElements()) { foreach (Element *elmt, m_element->linkedElements()) {
QString state = elmt->kindInformations()["state"].toString(); QString state = elmt->kindInformations()["state"].toString();
//NO and NC are displayed in single place in the cross
if (state == "NO" || state == "NC") {
if (state == "NO") tmp_str = &no_str; if (state == "NO") tmp_str = &no_str;
else if (state == "NC") tmp_str = &nc_str; else if (state == "NC") tmp_str = &nc_str;
if (!tmp_str->isEmpty()) *tmp_str += "\n"; if (!tmp_str->isEmpty()) *tmp_str += "\n";
*tmp_str += elementPositionText(elmt, add_prefix); *tmp_str += elementPositionText(elmt, add_prefix);
} }
//SW are displayed in NC and NO column in the cross
else if (state == "SW") {
for (int i = 0; i < 2; i++) {
tmp_str = i==0? &no_str : &nc_str;
if (!tmp_str->isEmpty()) *tmp_str += "\n";
*tmp_str += elementPositionText(elmt, add_prefix);
}
}
}
} }
/** /**
@@ -350,7 +363,10 @@ void CrossRefItem::drawHasContacts(QPainter &painter) {
for (int i=0; i<info["number"].toInt(); i++) { for (int i=0; i<info["number"].toInt(); i++) {
int option = 0; int option = 0;
info["state"].toString() == "NO"? option = NO : option = NC; QString state = info["state"].toString();
if (state == "NO") option = NO;
else if (state == "NC") option = NC;
else if (state == "SW") option = SW;
QString type = info["type"].toString(); QString type = info["type"].toString();
if (type == "power") option += Power; if (type == "power") option += Power;
@@ -368,13 +384,16 @@ void CrossRefItem::drawHasContacts(QPainter &painter) {
/** /**
* @brief CrossRefItem::drawContact * @brief CrossRefItem::drawContact
* draw one contacte, the type of contact to draw is define in ctc. * Draw one contact, the type of contact to draw is define in @flags.
* @param painter painter to use * @param painter, painter to use
* @param ctc option for draw the contact, see enum CONTACTS * @param flags, define how to draw the contact (see enul CONTACTS)
* @param str, the text to display for this contact (the position of the contact).
*/ */
void CrossRefItem::drawContact(QPainter &painter, int flags, QString str) { void CrossRefItem::drawContact(QPainter &painter, int flags, QString str) {
int offset = m_drawed_contacts*10; int offset = m_drawed_contacts*10;
//Draw NO or NC contact
if (flags &NOC) {
//draw the basic line //draw the basic line
painter.drawLine(0, offset+6, 8, offset+6); painter.drawLine(0, offset+6, 8, offset+6);
painter.drawLine(16, offset+6, 24, offset+6); painter.drawLine(16, offset+6, 24, offset+6);
@@ -414,7 +433,7 @@ void CrossRefItem::drawContact(QPainter &painter, int flags, QString str) {
} }
// draw half circle for delay contact // draw half circle for delay contact
if(flags &DelayOn || flags &DelayOff) { if(flags &Delay) {
// for delay on contact // for delay on contact
if (flags &DelayOn) { if (flags &DelayOn) {
if (flags &NO) { if (flags &NO) {
@@ -447,6 +466,31 @@ void CrossRefItem::drawContact(QPainter &painter, int flags, QString str) {
++m_drawed_contacts; ++m_drawed_contacts;
} }
//Draw a switch contact
else if (flags &SW) {
//draw the NO side
painter.drawLine(0, offset+6, 8, offset+6);
//Draw the NC side
QPointF p1[3] = {
QPointF(0, offset+16),
QPointF(8, offset+16),
QPointF(8, offset+12)
};
painter.drawPolyline(p1, 3);
//Draw the common side
QPointF p2[3] = {
QPointF(7, offset+14),
QPointF(16, offset+11),
QPointF(24, offset+11),
};
painter.drawPolyline(p2, 3);
//Draw position text
painter.drawText(20, offset+5, 30, 10, Qt::AlignRight | Qt::AlignVCenter, str);
//a switch contact take place of two normal contact
m_drawed_contacts += 2;
}
}
/** /**
* @brief CrossRefItem::fillCrossRef * @brief CrossRefItem::fillCrossRef
* Fill the content of the cross ref * Fill the content of the cross ref

View File

@@ -48,9 +48,12 @@ class CrossRefItem : public QGraphicsObject
enum CONTACTS { enum CONTACTS {
NO = 1, NO = 1,
NC = 2, NC = 2,
Power = 4, NOC = 3,
DelayOn = 8, SW = 4,
DelayOff = 16 Power = 8,
DelayOn = 16,
DelayOff = 32,
Delay = 48
}; };
QRectF boundingRect () const; QRectF boundingRect () const;

View File

@@ -112,6 +112,7 @@ void XRefPropertiesWidget::saveProperties(int index) {
xrp.setShowPowerContac(ui->m_show_power_cb->isChecked()); xrp.setShowPowerContac(ui->m_show_power_cb->isChecked());
xrp.setPrefix("power", ui->m_power_prefix_le->text()); xrp.setPrefix("power", ui->m_power_prefix_le->text());
xrp.setPrefix("delay", ui->m_delay_prefix_le->text()); xrp.setPrefix("delay", ui->m_delay_prefix_le->text());
xrp.setPrefix("switch", ui->m_switch_prefix_le->text());
m_properties.insert(type, xrp); m_properties.insert(type, xrp);
} }
@@ -138,6 +139,7 @@ void XRefPropertiesWidget::updateDisplay() {
ui->m_show_power_cb->setChecked(xrp.showPowerContact()); ui->m_show_power_cb->setChecked(xrp.showPowerContact());
ui->m_power_prefix_le-> setText(xrp.prefix("power")); ui->m_power_prefix_le-> setText(xrp.prefix("power"));
ui->m_delay_prefix_le-> setText(xrp.prefix("delay")); ui->m_delay_prefix_le-> setText(xrp.prefix("delay"));
ui->m_switch_prefix_le->setText(xrp.prefix("switch"));
ui->m_cross_properties_gb->setDisabled(!ui->m_display_has_cross_rb->isChecked()); ui->m_cross_properties_gb->setDisabled(!ui->m_display_has_cross_rb->isChecked());
} }

View File

@@ -84,12 +84,6 @@
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QLineEdit" name="m_delay_prefix_le"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="m_power_prefix_le"/>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
@@ -104,6 +98,22 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<widget class="QLineEdit" name="m_delay_prefix_le"/>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="m_power_prefix_le"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Préfixe des contacts inverseurs :</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="m_switch_prefix_le"/>
</item>
</layout> </layout>
</item> </item>
<item> <item>