2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
#include "conductorprofile.h"
|
2013-11-14 10:11:22 +00:00
|
|
|
#include "qetgraphicsitem/conductor.h"
|
2007-10-03 17:02:39 +00:00
|
|
|
#include "conductorsegmentprofile.h"
|
2014-07-21 20:44:32 +00:00
|
|
|
#include "terminal.h"
|
2007-10-03 17:02:39 +00:00
|
|
|
|
|
|
|
/// Constructeur
|
|
|
|
ConductorProfile::ConductorProfile() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
2007-10-21 16:10:21 +00:00
|
|
|
@param conductor conducteur dont il faut extraire le profil
|
2007-10-03 17:02:39 +00:00
|
|
|
*/
|
|
|
|
ConductorProfile::ConductorProfile(Conductor *conductor) {
|
|
|
|
fromConductor(conductor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur de copie
|
|
|
|
@param c autre conducteur
|
|
|
|
*/
|
|
|
|
ConductorProfile::ConductorProfile(const ConductorProfile &c) {
|
|
|
|
beginOrientation = c.beginOrientation;
|
|
|
|
endOrientation = c.endOrientation;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ConductorSegmentProfile *csp, c.segments) {
|
2007-10-03 17:02:39 +00:00
|
|
|
segments << new ConductorSegmentProfile(*csp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Operateur =
|
|
|
|
@param c autre conducteur
|
|
|
|
*/
|
|
|
|
ConductorProfile &ConductorProfile::operator=(const ConductorProfile &c) {
|
|
|
|
if (&c == this) return(*this);
|
|
|
|
|
|
|
|
// supprime ses informations
|
|
|
|
setNull();
|
|
|
|
|
|
|
|
// copie les informations de l'autre profil de conducteur
|
|
|
|
beginOrientation = c.beginOrientation;
|
|
|
|
endOrientation = c.endOrientation;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ConductorSegmentProfile *csp, c.segments) {
|
2007-10-03 17:02:39 +00:00
|
|
|
segments << new ConductorSegmentProfile(*csp);
|
|
|
|
}
|
|
|
|
return(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// destructeur
|
|
|
|
ConductorProfile::~ConductorProfile() {
|
|
|
|
setNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @return true si le profil est nul
|
|
|
|
bool ConductorProfile::isNull() const {
|
|
|
|
return(segments.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// supprime les segments du profil de conducteur
|
|
|
|
void ConductorProfile::setNull() {
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ConductorSegmentProfile *csp, segments) delete csp;
|
2007-10-03 17:02:39 +00:00
|
|
|
segments.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @return la largeur occupee par le conducteur
|
|
|
|
qreal ConductorProfile::width() const {
|
|
|
|
qreal width = 0.0;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ConductorSegmentProfile *csp, segments) {
|
2007-10-03 17:02:39 +00:00
|
|
|
if (csp -> isHorizontal) width += csp -> length;
|
|
|
|
}
|
|
|
|
return(width);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @return la hauteur occupee par le conducteur
|
|
|
|
qreal ConductorProfile::height() const{
|
|
|
|
qreal height = 0.0;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ConductorSegmentProfile *csp, segments) {
|
2007-10-03 17:02:39 +00:00
|
|
|
if (!csp -> isHorizontal) height += csp -> length;
|
|
|
|
}
|
|
|
|
return(height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param type Type de Segments
|
|
|
|
@return Le nombre de segments composant le conducteur.
|
|
|
|
*/
|
2012-11-09 21:09:24 +00:00
|
|
|
uint ConductorProfile::segmentsCount(QET::ConductorSegmentType type) const {
|
2007-10-03 17:02:39 +00:00
|
|
|
if (type == QET::Both) return(segments.count());
|
|
|
|
uint nb_seg = 0;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ConductorSegmentProfile *csp, segments) {
|
2007-10-03 17:02:39 +00:00
|
|
|
if (type == QET::Horizontal && csp -> isHorizontal) ++ nb_seg;
|
|
|
|
else if (type == QET::Vertical && !csp -> isHorizontal) ++ nb_seg;
|
|
|
|
}
|
|
|
|
return(nb_seg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @return les segments horizontaux de ce profil
|
|
|
|
QList<ConductorSegmentProfile *> ConductorProfile::horizontalSegments() {
|
|
|
|
QList<ConductorSegmentProfile *> segments_list;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ConductorSegmentProfile *csp, segments) {
|
2007-10-03 17:02:39 +00:00
|
|
|
if (csp -> isHorizontal) segments_list << csp;
|
|
|
|
}
|
|
|
|
return(segments_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @return les segments verticaux de ce profil
|
|
|
|
QList<ConductorSegmentProfile *> ConductorProfile::verticalSegments() {
|
|
|
|
QList<ConductorSegmentProfile *> segments_list;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ConductorSegmentProfile *csp, segments) {
|
2007-10-03 17:02:39 +00:00
|
|
|
if (!csp -> isHorizontal) segments_list << csp;
|
|
|
|
}
|
|
|
|
return(segments_list);
|
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/**
|
|
|
|
Reconstruit le profil a partir d'un conducteur existant
|
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
void ConductorProfile::fromConductor(Conductor *conductor) {
|
|
|
|
// supprime les segments precedents
|
|
|
|
setNull();
|
|
|
|
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ConductorSegment *conductor_segment, conductor -> segmentsList()) {
|
2007-10-03 17:02:39 +00:00
|
|
|
segments << new ConductorSegmentProfile(conductor_segment);
|
|
|
|
}
|
|
|
|
beginOrientation = conductor -> terminal1 -> orientation();
|
|
|
|
endOrientation = conductor -> terminal2 -> orientation();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de debugger un profil de conducteur
|
|
|
|
@param d Object QDebug a utiliser pour l'affichage des informations de debug
|
|
|
|
@param t Profil de conducteur a debugger
|
|
|
|
*/
|
|
|
|
QDebug &operator<<(QDebug d, ConductorProfile &t) {
|
|
|
|
d << "ConductorProfile {";
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ConductorSegmentProfile *csp, t.segments) {
|
2007-10-03 17:02:39 +00:00
|
|
|
d << "CSP" << (csp -> isHorizontal ? "horizontal" : "vertical") << ":" << csp -> length << ",";
|
|
|
|
}
|
|
|
|
d << "}";
|
|
|
|
return(d.space());
|
|
|
|
}
|