2013-05-03 17:35:22 +00:00
|
|
|
/*
|
2014-02-04 18:03:02 +00:00
|
|
|
Copyright 2006-2014 The QElectroTech team
|
2013-05-03 17:35:22 +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/>.
|
|
|
|
*/
|
2013-04-04 16:57:15 +00:00
|
|
|
#include "conductorautonumerotation.h"
|
2013-05-03 17:35:22 +00:00
|
|
|
#include "numerotationcontextcommands.h"
|
2014-07-21 20:44:32 +00:00
|
|
|
#include "qetdiagrameditor.h"
|
2014-07-31 19:44:25 +00:00
|
|
|
#include "conductor.h"
|
|
|
|
#include "diagram.h"
|
2014-08-04 14:39:57 +00:00
|
|
|
#include "potentialtextsdialog.h"
|
2014-12-04 23:25:49 +00:00
|
|
|
#include "qet.h"
|
2015-08-09 12:06:31 +00:00
|
|
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
2013-04-04 16:57:15 +00:00
|
|
|
|
|
|
|
/**
|
2015-01-09 17:18:16 +00:00
|
|
|
* @brief ConductorAutoNumerotation::ConductorAutoNumerotation
|
|
|
|
* Constructor of autonum, after create a class, call numerate to apply the autonum.
|
|
|
|
* When autonum is applyed, they do with an undo command added to the stack of diagram.
|
|
|
|
* If you give a parent_undo at constructor, the undo command create in this class have parent_undo for parent,
|
|
|
|
* and wasn't added to the stack of diagram (it's the responsabillty of the parent_undo)
|
|
|
|
* @param conductor : the conductor to apply automatic numerotation
|
|
|
|
* @param diagram : the diagram of conductor
|
|
|
|
* @param parent_undo : parent undo command
|
2013-04-04 16:57:15 +00:00
|
|
|
*/
|
2015-01-09 17:18:16 +00:00
|
|
|
ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *conductor, Diagram *diagram, QUndoCommand *parent_undo) :
|
|
|
|
m_diagram (diagram),
|
|
|
|
conductor_ (conductor),
|
|
|
|
conductor_list (conductor -> relatedPotentialConductors()),
|
|
|
|
m_parent_undo (parent_undo)
|
2013-04-19 14:59:20 +00:00
|
|
|
{}
|
|
|
|
|
2013-04-04 16:57:15 +00:00
|
|
|
/**
|
|
|
|
* @brief ConductorAutoNumerotation::numerate
|
2013-04-10 19:35:47 +00:00
|
|
|
* execute the automatic numerotation
|
2013-04-04 16:57:15 +00:00
|
|
|
*/
|
|
|
|
void ConductorAutoNumerotation::numerate() {
|
2013-04-19 13:22:30 +00:00
|
|
|
if (!conductor_) return;
|
2013-05-03 17:35:22 +00:00
|
|
|
if (conductor_list.size() >= 1 ) numeratePotential();
|
2013-06-24 09:36:05 +00:00
|
|
|
else if (conductor_ -> properties().type == ConductorProperties::Multi) numerateNewConductor();
|
2013-04-10 19:35:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 18:03:02 +00:00
|
|
|
/**
|
|
|
|
* @brief ConductorAutoNumerotation::checkPotential
|
2014-08-04 14:39:57 +00:00
|
|
|
* Check if eah texts of this potential is identical.
|
2014-02-04 18:03:02 +00:00
|
|
|
* If not, ask user how to numerate
|
|
|
|
* @param conductor
|
2014-08-04 14:39:57 +00:00
|
|
|
* A conductor of the potential to check.
|
2014-02-04 18:03:02 +00:00
|
|
|
*/
|
2015-06-16 08:26:03 +00:00
|
|
|
void ConductorAutoNumerotation::checkPotential(Conductor *conductor, QUndoCommand *parent) {
|
2014-12-04 23:25:49 +00:00
|
|
|
//fill list of potential
|
2014-02-04 18:03:02 +00:00
|
|
|
QSet <Conductor *> c_list = conductor->relatedPotentialConductors();
|
|
|
|
c_list << conductor;
|
2014-12-04 23:25:49 +00:00
|
|
|
//fill list of text
|
2014-02-04 18:03:02 +00:00
|
|
|
QStringList strl;
|
|
|
|
foreach (const Conductor *c, c_list) strl<<(c->text());
|
|
|
|
|
2014-12-04 23:25:49 +00:00
|
|
|
//check text list, isn't same in potential, ask user what to do
|
|
|
|
if (!QET::eachStrIsEqual(strl)) {
|
2014-08-04 14:39:57 +00:00
|
|
|
PotentialTextsDialog ptd(conductor, conductor->diagramEditor());
|
|
|
|
if ( ptd.exec() == QDialog::Accepted ) {
|
2015-06-16 08:26:03 +00:00
|
|
|
ConductorAutoNumerotation can(conductor, conductor -> diagram(), parent);
|
2014-08-04 14:39:57 +00:00
|
|
|
can.applyText(ptd.selectedText());
|
|
|
|
}
|
2014-02-04 18:03:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-10 19:35:47 +00:00
|
|
|
/**
|
2013-05-03 17:35:22 +00:00
|
|
|
* @brief ConductorAutoNumerotation::applyText
|
|
|
|
* apply the text @t to @conductor_ and all conductors at the same potential
|
2013-04-10 19:35:47 +00:00
|
|
|
*/
|
2015-08-09 12:06:31 +00:00
|
|
|
void ConductorAutoNumerotation::applyText(QString t)
|
|
|
|
{
|
2013-04-19 13:22:30 +00:00
|
|
|
if (!conductor_) return;
|
2015-01-09 17:18:16 +00:00
|
|
|
|
2015-08-09 12:06:31 +00:00
|
|
|
QVariant old_value, new_value;
|
|
|
|
ConductorProperties cp = conductor_ -> properties();
|
|
|
|
old_value.setValue(cp);
|
|
|
|
cp.text = t;
|
|
|
|
new_value.setValue(cp);
|
|
|
|
|
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(conductor_, "properties", old_value, new_value, m_parent_undo);
|
|
|
|
undo->setText(QObject::tr("Modifier les propriétés d'un conducteur", "undo caption"));
|
2013-04-19 13:22:30 +00:00
|
|
|
|
2015-08-09 12:06:31 +00:00
|
|
|
if (!conductor_list.isEmpty())
|
|
|
|
{
|
|
|
|
undo->setText(QObject::tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
|
|
|
|
foreach (Conductor *cond, conductor_list)
|
2015-01-09 17:18:16 +00:00
|
|
|
{
|
2015-08-09 12:06:31 +00:00
|
|
|
ConductorProperties cp2 = cond -> properties();
|
|
|
|
old_value.setValue(cp2);
|
|
|
|
cp2.text = t;
|
|
|
|
new_value.setValue(cp2);
|
|
|
|
new QPropertyUndoCommand(cond, "properties", old_value, new_value, undo);
|
2013-04-19 13:22:30 +00:00
|
|
|
}
|
2013-04-18 08:00:09 +00:00
|
|
|
}
|
2015-08-09 12:06:31 +00:00
|
|
|
|
|
|
|
if (!m_parent_undo)
|
|
|
|
m_diagram->undoStack().push(undo);
|
2013-04-18 08:00:09 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 19:35:47 +00:00
|
|
|
/**
|
2013-05-03 17:35:22 +00:00
|
|
|
* @brief ConductorAutoNumerotation::numeratePotential
|
|
|
|
* Numerate a conductor on an existing potential
|
2013-04-10 19:35:47 +00:00
|
|
|
*/
|
2013-05-03 17:35:22 +00:00
|
|
|
void ConductorAutoNumerotation::numeratePotential() {
|
|
|
|
QStringList strl;
|
|
|
|
foreach (const Conductor *cc, conductor_list) strl<<(cc->text());
|
2014-12-04 23:25:49 +00:00
|
|
|
//the texts is identicals
|
|
|
|
if (QET::eachStrIsEqual(strl)) {
|
2013-06-04 23:11:05 +00:00
|
|
|
ConductorProperties cp = conductor_ -> properties();
|
2013-05-03 17:35:22 +00:00
|
|
|
cp.text = strl.at(0);
|
|
|
|
conductor_ -> setProperties(cp);
|
|
|
|
conductor_ -> setText(strl.at(0));
|
|
|
|
}
|
|
|
|
//the texts isn't identicals
|
|
|
|
else {
|
2014-08-04 14:39:57 +00:00
|
|
|
PotentialTextsDialog ptd (conductor_, conductor_ -> diagramEditor());
|
|
|
|
if (ptd.exec() == QDialog::Accepted) {
|
|
|
|
applyText(ptd.selectedText());
|
|
|
|
}
|
2013-05-03 17:35:22 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-10 09:31:51 +00:00
|
|
|
|
2013-05-03 17:35:22 +00:00
|
|
|
/**
|
|
|
|
* @brief ConductorAutoNumerotation::numerateNewConductor
|
|
|
|
* create and apply a new numerotation to @conductor_
|
|
|
|
*/
|
|
|
|
void ConductorAutoNumerotation::numerateNewConductor() {
|
2014-07-31 19:44:25 +00:00
|
|
|
if (!conductor_ || m_diagram->conductorsAutonumName().isEmpty()) return;
|
2013-05-21 16:35:50 +00:00
|
|
|
|
2014-08-12 09:41:33 +00:00
|
|
|
NumerotationContext context = m_diagram->project()->conductorAutoNum(m_diagram -> conductorsAutonumName());
|
|
|
|
if (context.isEmpty()) return;
|
|
|
|
|
|
|
|
NumerotationContextCommands ncc (context, m_diagram);
|
2013-05-03 17:35:22 +00:00
|
|
|
applyText(ncc.toRepresentedString());
|
2014-08-12 09:41:33 +00:00
|
|
|
m_diagram->project()->addConductorAutoNum(m_diagram -> conductorsAutonumName(), ncc.next());
|
2013-05-03 17:35:22 +00:00
|
|
|
}
|