mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Conductor : minor change and replace some methode by function.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3363 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
132f2a4719
commit
781a779b49
@ -286,7 +286,7 @@ void DeleteElementsCommand::redo() {
|
||||
QList <Conductor *> conductor_list;
|
||||
conductor_list << c -> relatedPotentialConductors(false).toList();
|
||||
if (conductor_list.count()) {
|
||||
conductor_list.first() -> adjustTextItemPosition();
|
||||
conductor_list.first() -> calculateTextItemPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -780,7 +780,7 @@ void RotateElementsCommand::undo() {
|
||||
if (ConductorTextItem *cti = qgraphicsitem_cast<ConductorTextItem *>(dti)) {
|
||||
cti -> forceRotateByUser(previous_rotate_by_user_[cti]);
|
||||
(cti -> wasRotateByUser()) ? cti -> rotateBy(-applied_rotation_angle_) :
|
||||
cti -> parentConductor() -> adjustTextItemPosition();
|
||||
cti -> parentConductor() -> calculateTextItemPosition();
|
||||
}
|
||||
else {dti -> rotateBy(-applied_rotation_angle_);}
|
||||
}
|
||||
|
@ -1090,18 +1090,11 @@ const QList<ConductorSegment *> Conductor::segmentsList() const {
|
||||
}
|
||||
|
||||
/**
|
||||
@return La longueur totale du conducteur
|
||||
*/
|
||||
qreal Conductor::length() {
|
||||
qreal length = 0.0;
|
||||
|
||||
ConductorSegment *s = segments;
|
||||
while (s -> hasNextSegment()) {
|
||||
length += qAbs(s -> length());
|
||||
s = s -> nextSegment();
|
||||
}
|
||||
|
||||
return(length);
|
||||
* @brief Conductor::length
|
||||
* @return the length of this conductor
|
||||
*/
|
||||
qreal Conductor::length() const{
|
||||
return path().length();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1191,15 +1184,7 @@ void Conductor::calculateTextItemPosition() {
|
||||
if (!text_item || !diagram()) return;
|
||||
|
||||
if (diagram() -> defaultConductorProperties.m_one_text_per_folio == true) {
|
||||
QSet<Conductor *> conductor_list = relatedPotentialConductors(false);
|
||||
Conductor *longuest_conductor = this;
|
||||
|
||||
//Search the longuest conductor
|
||||
foreach (Conductor *c, conductor_list) {
|
||||
if (c -> length() > longuest_conductor -> length()) {
|
||||
longuest_conductor = c;
|
||||
}
|
||||
}
|
||||
Conductor *longuest_conductor = longuestConductorInPotential(this);
|
||||
|
||||
//The longuest conductor isn't this conductor
|
||||
//we call calculateTextItemPosition of the longuest conductor
|
||||
@ -1210,7 +1195,7 @@ void Conductor::calculateTextItemPosition() {
|
||||
|
||||
//At this point this conductor is the longuest conductor
|
||||
//we hide all text of conductor_list
|
||||
foreach (Conductor *c, conductor_list) {
|
||||
foreach (Conductor *c, relatedPotentialConductors(false)) {
|
||||
c -> textItem() -> setVisible(false);
|
||||
}
|
||||
}
|
||||
@ -1350,15 +1335,6 @@ void Conductor::readProperties() {
|
||||
calculateTextItemPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
S'assure que le texte du conducteur est a une position raisonnable
|
||||
Cette methode ne fait rien si ce conducteur n'affiche pas son champ de
|
||||
texte.
|
||||
*/
|
||||
void Conductor::adjustTextItemPosition() {
|
||||
calculateTextItemPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
@return true si le conducteur est mis en evidence
|
||||
*/
|
||||
@ -1417,17 +1393,6 @@ void Conductor::displayedTextChanged() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@return les conducteurs avec lesquels ce conducteur partage des bornes
|
||||
communes
|
||||
*/
|
||||
QSet<Conductor *> Conductor::relatedConductors() const {
|
||||
QList<Conductor *> other_conductors_list = terminal1 -> conductors();
|
||||
other_conductors_list += terminal2 -> conductors();
|
||||
QSet<Conductor *> other_conductors = other_conductors_list.toSet();
|
||||
other_conductors.remove(const_cast<Conductor *>(this));
|
||||
return(other_conductors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Conductor::relatedPotentialConductors
|
||||
@ -1526,20 +1491,6 @@ void Conductor::editProperty() {
|
||||
ConductorPropertiesDialog::PropertiesDialog(this, diagramEditor());
|
||||
}
|
||||
|
||||
/**
|
||||
@param a reel
|
||||
@param b reel
|
||||
@param c reel
|
||||
@return true si a est entre b et c ou est egal a l'un des deux
|
||||
*/
|
||||
bool isBetween(qreal a, qreal b, qreal c) {
|
||||
if (b <= c) {
|
||||
return(a >= b && a <= c);
|
||||
} else {
|
||||
return(a <= b && a >= c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@param a point
|
||||
@param b point
|
||||
@ -1560,7 +1511,7 @@ QList<QPointF> Conductor::junctions() const {
|
||||
QList<QPointF> junctions_list;
|
||||
|
||||
// pour qu'il y ait des jonctions, il doit y avoir d'autres conducteurs et des bifurcations
|
||||
QSet<Conductor *> other_conductors = relatedConductors();
|
||||
QList<Conductor *> other_conductors = relatedConductors(this);
|
||||
QList<ConductorBend> bends_list = bends();
|
||||
if (other_conductors.isEmpty() || bends_list.isEmpty()) {
|
||||
return(junctions_list);
|
||||
@ -1787,3 +1738,32 @@ QPointF Conductor::movePointIntoPolygon(const QPointF &point, const QPainterPath
|
||||
return(points.at(point_index));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief longuestConductorInPotential
|
||||
* @param conductor : a conductor in the potential to search
|
||||
* @param all_diagram : true -> search in the whole project, false -> search only in the diagram of conductor
|
||||
* @return the longuest conductor in the same potential of conductor
|
||||
*/
|
||||
Conductor * longuestConductorInPotential(Conductor *conductor, bool all_diagram) {
|
||||
Conductor *longuest_conductor = conductor;
|
||||
//Search the longuest conductor
|
||||
foreach (Conductor *c, conductor -> relatedPotentialConductors(all_diagram))
|
||||
if (c -> length() > longuest_conductor -> length())
|
||||
longuest_conductor = c;
|
||||
|
||||
return longuest_conductor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief relatedConductors
|
||||
* @param conductor
|
||||
* @return return all conductors who share the same terminals of @conductor given as parametre,
|
||||
* except @conductor himself.
|
||||
*/
|
||||
QList <Conductor *> relatedConductors(const Conductor *conductor) {
|
||||
QList<Conductor *> other_conductors_list = conductor -> terminal1 -> conductors();
|
||||
other_conductors_list << conductor -> terminal2->conductors();
|
||||
other_conductors_list.removeAll(const_cast<Conductor *> (conductor));
|
||||
return(other_conductors_list);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
||||
virtual QPainterPath nearShape() const;
|
||||
virtual QPainterPath variableShape(const qreal &) const;
|
||||
virtual bool isNearConductor(const QPointF &);
|
||||
qreal length();
|
||||
qreal length() const;
|
||||
ConductorSegment *middleSegment();
|
||||
QPointF posForText(Qt::Orientations &flag);
|
||||
bool containsPoint(const QPointF &) const;
|
||||
@ -103,7 +103,7 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
||||
void setProfiles(const ConductorProfilesGroup &);
|
||||
ConductorProfilesGroup profiles() const;
|
||||
void readProperties();
|
||||
void adjustTextItemPosition();
|
||||
void calculateTextItemPosition();
|
||||
virtual Highlight highlight() const;
|
||||
virtual void setHighlighted(Highlight);
|
||||
void autoText();
|
||||
@ -165,12 +165,10 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
||||
void updateConductorPath(const QPointF &, Qet::Orientation, const QPointF &, Qet::Orientation);
|
||||
uint segmentsCount(QET::ConductorSegmentType = QET::Both) const;
|
||||
QList<QPointF> segmentsToPoints() const;
|
||||
QSet<Conductor *> relatedConductors() const;
|
||||
QList<ConductorBend> bends() const;
|
||||
QList<QPointF> junctions() const;
|
||||
void pointsToSegments(QList<QPointF>);
|
||||
bool hasClickedOn(QPointF, QPointF) const;
|
||||
void calculateTextItemPosition();
|
||||
Qt::Corner currentPathType() const;
|
||||
void deleteSegments();
|
||||
static int getCoeff(const qreal &, const qreal &);
|
||||
@ -183,4 +181,15 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
||||
static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &);
|
||||
Terminal * relatedPotentialTerminal (Terminal *, const bool all_diagram = true);
|
||||
};
|
||||
|
||||
Conductor * longuestConductorInPotential (Conductor *conductor, bool all_diagram = false);
|
||||
QList <Conductor *> relatedConductors (const Conductor *conductor);
|
||||
|
||||
|
||||
//return true if @a is between or at @b and @c.
|
||||
template <typename T>
|
||||
bool isBetween (const T a, const T b, const T c) {
|
||||
return (b <= c)? (a >= b && a <= c) : (a <= b && a >= c);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -128,7 +128,7 @@ void ConductorTextItem::forceMovedByUser(bool moved_by_user) {
|
||||
|
||||
moved_by_user_ = moved_by_user;
|
||||
if (!moved_by_user && parent_conductor_) {
|
||||
parent_conductor_ -> adjustTextItemPosition();
|
||||
parent_conductor_ -> calculateTextItemPosition();
|
||||
}
|
||||
|
||||
}
|
||||
@ -144,7 +144,7 @@ void ConductorTextItem::forceRotateByUser(bool rotate_by_user) {
|
||||
|
||||
rotate_by_user_ = rotate_by_user;
|
||||
if (!rotate_by_user && parent_conductor_) {
|
||||
parent_conductor_ -> adjustTextItemPosition();
|
||||
parent_conductor_ -> calculateTextItemPosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user