mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Multipaste : improve the conductor autonum, conductors are numerated from top to bottom, and left to right
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5340 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -249,10 +249,19 @@ QList<Terminal *> CustomElement::terminals() const {
|
|||||||
return(m_terminals);
|
return(m_terminals);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return la liste des conducteurs rattaches a cet element
|
/**
|
||||||
QList<Conductor *> CustomElement::conductors() const {
|
* @brief CustomElement::conductors
|
||||||
|
* @return The list of conductor docked to this element
|
||||||
|
* the list is sorted according to the position of the terminal where the conductor is docked
|
||||||
|
* from top to bottom, and left to right.
|
||||||
|
*/
|
||||||
|
QList<Conductor *> CustomElement::conductors() const
|
||||||
|
{
|
||||||
QList<Conductor *> conductors;
|
QList<Conductor *> conductors;
|
||||||
foreach(Terminal *t, m_terminals) conductors << t -> conductors();
|
|
||||||
|
for(Terminal *t : m_terminals)
|
||||||
|
conductors << t -> conductors();
|
||||||
|
|
||||||
return(conductors);
|
return(conductors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -803,6 +812,16 @@ Terminal *CustomElement::parseTerminal(QDomElement &e) {
|
|||||||
Terminal *new_terminal = new Terminal(terminalx, terminaly, terminalo, this);
|
Terminal *new_terminal = new Terminal(terminalx, terminaly, terminalo, this);
|
||||||
new_terminal -> setZValue(420); // valeur arbitraire pour maintenir les bornes au-dessus des champs de texte
|
new_terminal -> setZValue(420); // valeur arbitraire pour maintenir les bornes au-dessus des champs de texte
|
||||||
m_terminals << new_terminal;
|
m_terminals << new_terminal;
|
||||||
|
|
||||||
|
//Sort from top to bottom and left to rigth
|
||||||
|
std::sort(m_terminals.begin(), m_terminals.end(), [](Terminal *a, Terminal *b)
|
||||||
|
{
|
||||||
|
if(a->dockConductor().y() == b->dockConductor().y())
|
||||||
|
return (a->dockConductor().x() < b->dockConductor().x());
|
||||||
|
else
|
||||||
|
return (a->dockConductor().y() < b->dockConductor().y());
|
||||||
|
});
|
||||||
|
|
||||||
return(new_terminal);
|
return(new_terminal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ void MultiPasteDialog::updatePreview()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_pasted_content.clear();
|
m_pasted_content.clear();
|
||||||
|
m_pasted_content_list.clear();
|
||||||
|
|
||||||
QPointF offset(ui->m_x_sb->value(), ui->m_y_sb->value());
|
QPointF offset(ui->m_x_sb->value(), ui->m_y_sb->value());
|
||||||
QPointF pos = m_origin+offset;
|
QPointF pos = m_origin+offset;
|
||||||
@@ -82,6 +83,7 @@ void MultiPasteDialog::updatePreview()
|
|||||||
m_diagram->fromXml(m_document, pos, false, &dc);
|
m_diagram->fromXml(m_document, pos, false, &dc);
|
||||||
|
|
||||||
m_pasted_content += dc;
|
m_pasted_content += dc;
|
||||||
|
m_pasted_content_list << dc;
|
||||||
pos += offset;
|
pos += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,77 +111,94 @@ void MultiPasteDialog::on_m_button_box_accepted()
|
|||||||
m_diagram->clearSelection();
|
m_diagram->clearSelection();
|
||||||
m_diagram->undoStack().push(new PasteDiagramCommand(m_diagram, m_pasted_content));
|
m_diagram->undoStack().push(new PasteDiagramCommand(m_diagram, m_pasted_content));
|
||||||
|
|
||||||
//Auto-connection
|
for(DiagramContent dc : m_pasted_content_list)
|
||||||
if(ui->m_auto_connection_cb->isChecked())
|
|
||||||
{
|
{
|
||||||
for(Element *elmt : m_pasted_content.m_elements)
|
QList<Element *> pasted_elements = dc.m_elements;
|
||||||
|
//Sort the list element by there pos (top -> bottom)
|
||||||
|
std::sort(pasted_elements.begin(), pasted_elements.end(), [](Element *a, Element *b){return (a->pos().y() < b->pos().y());});
|
||||||
|
|
||||||
|
//Auto-connection
|
||||||
|
if(ui->m_auto_connection_cb->isChecked())
|
||||||
{
|
{
|
||||||
while (!elmt->AlignedFreeTerminals().isEmpty())
|
for(Element *elmt : pasted_elements)
|
||||||
{
|
{
|
||||||
QPair <Terminal *, Terminal *> pair = elmt->AlignedFreeTerminals().takeFirst();
|
while (!elmt->AlignedFreeTerminals().isEmpty())
|
||||||
|
|
||||||
Conductor *conductor = new Conductor(pair.first, pair.second);
|
|
||||||
m_diagram->undoStack().push(new AddItemCommand<Conductor *>(conductor, m_diagram, QPointF()));
|
|
||||||
|
|
||||||
//Autonum the new conductor, the undo command associated for this, have for parent undo_object
|
|
||||||
ConductorAutoNumerotation can (conductor, m_diagram);
|
|
||||||
can.numerate();
|
|
||||||
if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors()) {
|
|
||||||
conductor->setFreezeLabel(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set up the label of element
|
|
||||||
//Instead of use the current autonum of project,
|
|
||||||
//we try to fetch the same formula of the pasted element, in the several autonum of the project
|
|
||||||
//for apply the good formula for each elements
|
|
||||||
if(ui->m_auto_num_cb->isChecked())
|
|
||||||
{
|
|
||||||
for(Element *elmt : m_pasted_content.m_elements)
|
|
||||||
{
|
|
||||||
QString formula = elmt->elementInformations()["formula"].toString();
|
|
||||||
if(!formula.isEmpty())
|
|
||||||
{
|
|
||||||
QHash <QString, NumerotationContext> autonums = m_diagram->project()->elementAutoNum();
|
|
||||||
QHashIterator<QString, NumerotationContext> hash_iterator(autonums);
|
|
||||||
|
|
||||||
while(hash_iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
hash_iterator.next();
|
QPair <Terminal *, Terminal *> pair = elmt->AlignedFreeTerminals().takeFirst();
|
||||||
if(autonum::numerotationContextToFormula(hash_iterator.value()) == formula)
|
|
||||||
{
|
Conductor *conductor = new Conductor(pair.first, pair.second);
|
||||||
m_diagram->project()->setCurrrentElementAutonum(hash_iterator.key());
|
m_diagram->undoStack().push(new AddItemCommand<Conductor *>(conductor, m_diagram, QPointF()));
|
||||||
elmt->setUpFormula();
|
|
||||||
|
//Autonum the new conductor, the undo command associated for this, have for parent undo_object
|
||||||
|
ConductorAutoNumerotation can (conductor, m_diagram);
|
||||||
|
can.numerate();
|
||||||
|
if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors()) {
|
||||||
|
conductor->setFreezeLabel(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//Like elements, we compare formula of pasted conductor with the autonums available in the project.
|
//Set up the label of element
|
||||||
if(ui->m_auto_num_cond_cb->isChecked())
|
//Instead of use the current autonum of project,
|
||||||
{
|
//we try to fetch the same formula of the pasted element, in the several autonum of the project
|
||||||
for(Conductor *c : m_pasted_content.conductors())
|
//for apply the good formula for each elements
|
||||||
|
if(ui->m_auto_num_cb->isChecked())
|
||||||
{
|
{
|
||||||
QString formula = c->properties().m_formula;
|
for(Element *elmt : pasted_elements)
|
||||||
if(!formula.isEmpty())
|
|
||||||
{
|
{
|
||||||
QHash <QString, NumerotationContext> autonums = m_diagram->project()->conductorAutoNum();
|
QString formula = elmt->elementInformations()["formula"].toString();
|
||||||
QHashIterator <QString, NumerotationContext> hash_iterator(autonums);
|
if(!formula.isEmpty())
|
||||||
|
|
||||||
while (hash_iterator.hasNext())
|
|
||||||
{
|
{
|
||||||
hash_iterator.next();
|
QHash <QString, NumerotationContext> autonums = m_diagram->project()->elementAutoNum();
|
||||||
if(autonum::numerotationContextToFormula(hash_iterator.value()) == formula)
|
QHashIterator<QString, NumerotationContext> hash_iterator(autonums);
|
||||||
|
|
||||||
|
while(hash_iterator.hasNext())
|
||||||
{
|
{
|
||||||
m_diagram->project()->setCurrentConductorAutoNum(hash_iterator.key());
|
hash_iterator.next();
|
||||||
c->rSequenceNum().clear();
|
if(autonum::numerotationContextToFormula(hash_iterator.value()) == formula)
|
||||||
ConductorAutoNumerotation can(c, m_diagram);
|
|
||||||
can.numerate();
|
|
||||||
if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors())
|
|
||||||
{
|
{
|
||||||
c->setFreezeLabel(true);
|
m_diagram->project()->setCurrrentElementAutonum(hash_iterator.key());
|
||||||
|
elmt->setUpFormula();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Like elements, we compare formula of pasted conductor with the autonums available in the project.
|
||||||
|
if(ui->m_auto_num_cond_cb->isChecked())
|
||||||
|
{
|
||||||
|
//This list is to ensure we not numerate twice the same conductor
|
||||||
|
QList<Conductor *> numerated;
|
||||||
|
//Start with the element at top
|
||||||
|
for(Element *elmt : pasted_elements)
|
||||||
|
{
|
||||||
|
for(Conductor *c : elmt->conductors())
|
||||||
|
{
|
||||||
|
if(numerated.contains(c))
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
numerated << c;
|
||||||
|
QString formula = c->properties().m_formula;
|
||||||
|
if(!formula.isEmpty())
|
||||||
|
{
|
||||||
|
QHash <QString, NumerotationContext> autonums = m_diagram->project()->conductorAutoNum();
|
||||||
|
QHashIterator <QString, NumerotationContext> hash_iterator(autonums);
|
||||||
|
|
||||||
|
while (hash_iterator.hasNext())
|
||||||
|
{
|
||||||
|
hash_iterator.next();
|
||||||
|
if(autonum::numerotationContextToFormula(hash_iterator.value()) == formula)
|
||||||
|
{
|
||||||
|
m_diagram->project()->setCurrentConductorAutoNum(hash_iterator.key());
|
||||||
|
c->rSequenceNum().clear();
|
||||||
|
ConductorAutoNumerotation can(c, m_diagram);
|
||||||
|
can.numerate();
|
||||||
|
if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors())
|
||||||
|
{
|
||||||
|
c->setFreezeLabel(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user