Compare commits

...

3 Commits

Author SHA1 Message Date
plc-user 410c9293d1 adjust variable-names and comments; minor change in length-compare of conductor-segments 2025-10-19 15:48:03 +02:00
plc-user 07c34d7358 add and correct English comments 2025-10-19 15:37:07 +02:00
plc-user 6d7d1ea23b NamesList: Set empty string for name, when no name is set
This should fix an issue with empty fields in titleblocks.
2025-10-19 15:09:24 +02:00
2 changed files with 38 additions and 37 deletions
+1 -3
View File
@@ -174,11 +174,9 @@ void NamesList::fromXml(const pugi::xml_node &xml_element, const QHash<QString,
/** /**
Exports the list of names to an XML element. Exports the list of names to an XML element.
Make sure that the list of names is not empty before exporting. Make sure that the list of names is not empty before exporting.
If list is empty, set name to "en" / "NoName"
French: French:
Exporte la liste des noms vers un element XML. Veillez a verifier que la Exporte la liste des noms vers un element XML. Veillez a verifier que la
liste de noms n'est pas vide avant de l'exporter. liste de noms n'est pas vide avant de l'exporter.
Si la liste est vide, le nom sera "en" / "NoName".
@param xml_document Le document XML dans lequel l'element XML sera insere @param xml_document Le document XML dans lequel l'element XML sera insere
@param xml_options A set of options related to XML parsing. @param xml_options A set of options related to XML parsing.
@return L'element XML correspondant a la section "names" @return L'element XML correspondant a la section "names"
@@ -192,7 +190,7 @@ QDomElement NamesList::toXml(QDomDocument &xml_document, const QHash<QString, QS
qInfo() << " NamesList of element is empty - add default: [" << "en" << "] = " << "NoName" << ""; qInfo() << " NamesList of element is empty - add default: [" << "en" << "] = " << "NoName" << "";
QDomElement name_elmt = xml_document.createElement(xml_opt["TagName"]); QDomElement name_elmt = xml_document.createElement(xml_opt["TagName"]);
name_elmt.setAttribute(xml_opt["LanguageAttribute"], "en"); name_elmt.setAttribute(xml_opt["LanguageAttribute"], "en");
name_elmt.appendChild(xml_document.createTextNode("NoName")); name_elmt.appendChild(xml_document.createTextNode(" "));
names_elmt.appendChild(name_elmt); names_elmt.appendChild(name_elmt);
} else { } else {
QMapIterator<QString, QString> names_iterator(map_names); QMapIterator<QString, QString> names_iterator(map_names);
+34 -31
View File
@@ -229,43 +229,53 @@ void Conductor::updateConductorPath(const QPointF &p1, Qet::Orientation o1, cons
Q_ASSERT_X(!conductor_profile.isNull(), "Conductor::priv_modifieConductor", "pas de profil utilisable"); Q_ASSERT_X(!conductor_profile.isNull(), "Conductor::priv_modifieConductor", "pas de profil utilisable");
// recupere les coordonnees fournies des bornes // recupere les coordonnees fournies des bornes
// retrieve the coordinates provided for the terminals
QPointF new_p1 = mapFromScene(p1); QPointF new_p1 = mapFromScene(p1);
QPointF new_p2 = mapFromScene(p2); QPointF new_p2 = mapFromScene(p2);
QRectF new_rect = QRectF(new_p1, new_p2); QRectF new_rect = QRectF(new_p1, new_p2);
// recupere la largeur et la hauteur du profil // recupere la largeur et la hauteur du profil
// retrieve the width and height of the profile
qreal profile_width = conductor_profile.width(); qreal profile_width = conductor_profile.width();
qreal profile_height = conductor_profile.height(); qreal profile_height = conductor_profile.height();
// calcule les differences verticales et horizontales a appliquer // calcule les differences verticales et horizontales a appliquer
// calculates the vertical and horizontal differences to be applied
qreal h_diff = (qAbs(new_rect.width()) - qAbs(profile_width) ) * getSign(profile_width); qreal h_diff = (qAbs(new_rect.width()) - qAbs(profile_width) ) * getSign(profile_width);
qreal v_diff = (qAbs(new_rect.height()) - qAbs(profile_height)) * getSign(profile_height); qreal v_diff = (qAbs(new_rect.height()) - qAbs(profile_height)) * getSign(profile_height);
// applique les differences aux segments // applique les differences aux segments
// apply the differences to the segments
QMultiHash<ConductorSegmentProfile *, qreal> segments_lengths; QMultiHash<ConductorSegmentProfile *, qreal> segments_lengths;
segments_lengths.unite(shareOffsetBetweenSegments(h_diff, conductor_profile.horizontalSegments())); segments_lengths.unite(shareOffsetBetweenSegments(h_diff, conductor_profile.horizontalSegments()));
segments_lengths.unite(shareOffsetBetweenSegments(v_diff, conductor_profile.verticalSegments())); segments_lengths.unite(shareOffsetBetweenSegments(v_diff, conductor_profile.verticalSegments()));
// en deduit egalement les coefficients d'inversion (-1 pour une inversion, +1 pour conserver le meme sens) // en deduit egalement les coefficients d'inversion (-1 pour une inversion, +1 pour conserver le meme sens)
// also deduce the inversion coefficients (-1 for inversion, +1 to keep the same direction)
int horiz_coeff = getCoeff(new_rect.width(), profile_width); int horiz_coeff = getCoeff(new_rect.width(), profile_width);
int verti_coeff = getCoeff(new_rect.height(), profile_height); int verti_coeff = getCoeff(new_rect.height(), profile_height);
// genere les nouveaux points // genere les nouveaux points
// generate the new points
QList<QPointF> points; QList<QPointF> points;
points << new_p1; points << new_p1;
int limit = conductor_profile.segments.count() - 1; int limit = conductor_profile.segments.count() - 1;
for (int i = 0 ; i < limit ; ++ i) { for (int i = 0 ; i < limit ; ++ i) {
// dernier point // dernier point
// last point
QPointF previous_point = points.last(); QPointF previous_point = points.last();
// profil de segment de conducteur en cours // profil de segment de conducteur en cours
// current conductor segment profile
ConductorSegmentProfile *csp = conductor_profile.segments.at(i); ConductorSegmentProfile *csp = conductor_profile.segments.at(i);
// coefficient et offset a utiliser pour ce point // coefficient et offset a utiliser pour ce point
// coefficient and offset to be used for this point
qreal coeff = csp -> isHorizontal ? horiz_coeff : verti_coeff; qreal coeff = csp -> isHorizontal ? horiz_coeff : verti_coeff;
qreal offset_applied = segments_lengths.value(csp); qreal offset_applied = segments_lengths.value(csp);
// applique l'offset et le coeff au point // applique l'offset et le coeff au point
// apply coefficient and offset to point
if (csp -> isHorizontal) { if (csp -> isHorizontal) {
points << QPointF ( points << QPointF (
previous_point.x() + (coeff * offset_applied), previous_point.x() + (coeff * offset_applied),
@@ -989,16 +999,16 @@ void Conductor::pointsToSegments(const QList<QPointF>& points_list) {
/** /**
@brief Conductor::fromXml @brief Conductor::fromXml
Load the conductor and her information from xml element Load the conductor and its information from xml element
@param dom_element @param dom_element
@return true is loading success else return false @return true if loading succeeded else return false
*/ */
bool Conductor::fromXml(QDomElement &dom_element) bool Conductor::fromXml(QDomElement &dom_element)
{ {
setPos(dom_element.attribute("x", nullptr).toDouble(), setPos(dom_element.attribute("x", nullptr).toDouble(),
dom_element.attribute("y", nullptr).toDouble()); dom_element.attribute("y", nullptr).toDouble());
bool return_ = pathFromXml(dom_element); bool retval = pathFromXml(dom_element);
m_text_item -> fromXml(dom_element); m_text_item -> fromXml(dom_element);
ConductorProperties pr; ConductorProperties pr;
@@ -1014,7 +1024,7 @@ bool Conductor::fromXml(QDomElement &dom_element)
setProperties(pr); setProperties(pr);
return return_; return retval;
} }
/** /**
@@ -1134,13 +1144,14 @@ bool Conductor::pathFromXml(const QDomElement &e) {
} }
} }
//If there isn't segment we generate automatic path and return true // If there is no segment, we generate an automatic path and return true
if (!segments_x.size()) { if (!segments_x.size()) {
generateConductorPath(terminal1 -> dockConductor(), terminal1 -> orientation(), terminal2 -> dockConductor(), terminal2 -> orientation()); generateConductorPath(terminal1 -> dockConductor(), terminal1 -> orientation(), terminal2 -> dockConductor(), terminal2 -> orientation());
return(true); return(true);
} }
// les longueurs recueillies doivent etre coherentes avec les positions des bornes // les longueurs recueillies doivent etre coherentes avec les positions des bornes
// The collected lengths must be consistent with the positions of the terminals
qreal width = 0.0, height = 0.0; qreal width = 0.0, height = 0.0;
foreach (qreal t, segments_x) width += t; foreach (qreal t, segments_x) width += t;
foreach (qreal t, segments_y) height += t; foreach (qreal t, segments_y) height += t;
@@ -1256,65 +1267,57 @@ ConductorSegment *Conductor::middleSegment()
*/ */
QPointF Conductor::posForText(Qt::Orientations &flag) QPointF Conductor::posForText(Qt::Orientations &flag)
{ {
ConductorSegment *segment = segments; ConductorSegment *segment = segments;
bool all_segment_is_vertical = true; bool all_segments_are_vertical = true;
bool all_segment_is_horizontal = true; bool all_segments_are_horizontal = true;
//Go to first segment //Go to first segment
while (!segment->isFirstSegment()) { while (!segment->isFirstSegment()) {
segment = segment->previousSegment(); segment = segment->previousSegment();
} }
QPointF p1 = segment -> firstPoint(); //<First point of conductor QPointF p1 = segment -> firstPoint(); //<First point of conductor
ConductorSegment *biggest_segment = segment; //<biggest segment: contain the longest segment of conductor. ConductorSegment *longest_segment = segment; //<the longest segment of conductor.
// check if all segments are horizontal or vertical ... first segment:
if (segment -> firstPoint().x() != segment -> secondPoint().x()) if (segment -> firstPoint().x() != segment -> secondPoint().x())
all_segment_is_vertical = false; all_segments_are_vertical = false;
if (segment -> firstPoint().y() != segment -> secondPoint().y()) if (segment -> firstPoint().y() != segment -> secondPoint().y())
all_segment_is_horizontal = false; all_segments_are_horizontal = false;
// find longest segment
while (segment -> hasNextSegment()) while (segment -> hasNextSegment())
{ {
segment = segment -> nextSegment(); segment = segment -> nextSegment();
if (segment -> firstPoint().x() != segment -> secondPoint().x()) if (segment -> firstPoint().x() != segment -> secondPoint().x())
all_segment_is_vertical = false; all_segments_are_vertical = false;
if (segment -> firstPoint().y() != segment -> secondPoint().y()) if (segment -> firstPoint().y() != segment -> secondPoint().y())
all_segment_is_horizontal = false; all_segments_are_horizontal = false;
//We must compare length segment, but they can be negative if (qAbs(segment->length()) > qAbs(longest_segment -> length()))
//so we multiply by -1 to make it positive. longest_segment = segment;
int saved = biggest_segment -> length();
if (saved < 0) saved *= -1;
int curent = segment->length();
if (curent < 0) curent *= -1;
if (curent > saved) biggest_segment = segment;
} }
QPointF p2 = segment -> secondPoint(); //<Last point of conductor QPointF p2 = segment -> secondPoint(); //<Last point of conductor
//If the conductor is horizontal or vertical //If the conductor is horizontal or vertical
//Return the point at the middle of conductor //Return the point at the middle of conductor
if (all_segment_is_vertical) { //<Vertical if (all_segments_are_vertical) { //<Vertical
flag = Qt::Vertical; flag = Qt::Vertical;
if (p1.y() > p2.y()) { if (p1.y() > p2.y()) {
p1.setY(p1.y() - (length()/2)); p1.setY(p1.y() - (length()/2));
} else { } else {
p1.setY(p1.y() + (length()/2)); p1.setY(p1.y() + (length()/2));
} }
} else if (all_segment_is_horizontal) { //<Horizontal } else if (all_segments_are_horizontal) { //<Horizontal
flag = Qt::Horizontal; flag = Qt::Horizontal;
if (p1.x() > p2.x()) { if (p1.x() > p2.x()) {
p1.setX(p1.x() - (length()/2)); p1.setX(p1.x() - (length()/2));
} else { } else {
p1.setX(p1.x() + (length()/2)); p1.setX(p1.x() + (length()/2));
} }
} else { //Return the point at the middle of biggest segment. } else { //Return the point at the middle of longest segment.
p1 = biggest_segment->middle(); p1 = longest_segment->middle();
flag = (biggest_segment->isHorizontal())? Qt::Horizontal : Qt::Vertical; flag = (longest_segment->isHorizontal())? Qt::Horizontal : Qt::Vertical;
} }
return p1; return p1;
} }
@@ -1420,7 +1423,7 @@ void Conductor::calculateTextItemPosition()
/** /**
Sauvegarde le profil courant du conducteur pour l'utiliser ulterieurement Sauvegarde le profil courant du conducteur pour l'utiliser ulterieurement
dans priv_modifieConductor. dans priv_modifieConductor.
Save the current conductors profile for later use in priv_modifiedConductor. Save the current conductors profile for later use in priv_modifieConductor.
*/ */
void Conductor::saveProfile(bool undo) { void Conductor::saveProfile(bool undo) {
Qt::Corner current_path_type = currentPathType(); Qt::Corner current_path_type = currentPathType();
@@ -1487,7 +1490,7 @@ ConductorProfile Conductor::profile(Qt::Corner path_type) const
/** /**
@brief Conductor::refreshText @brief Conductor::refreshText
Refresh the text of this conductor. Refresh the text of this conductor.
recalcule and set the text according to the formula. recalculate and set the text according to the formula.
*/ */
void Conductor::refreshText() void Conductor::refreshText()
{ {