2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2009-04-03 19:30:25 +00:00
|
|
|
Copyright 2006-2009 Xavier Guerrin
|
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/>.
|
|
|
|
*/
|
2006-10-27 15:47:22 +00:00
|
|
|
#ifndef SCHEMA_H
|
2007-04-09 02:56:47 +00:00
|
|
|
#define SCHEMA_H
|
|
|
|
#include <QtGui>
|
|
|
|
#include <QtXml>
|
|
|
|
#include "borderinset.h"
|
2007-09-25 23:24:36 +00:00
|
|
|
#include "qgimanager.h"
|
2007-10-14 15:16:37 +00:00
|
|
|
#include "conductorproperties.h"
|
2007-04-09 02:56:47 +00:00
|
|
|
class Element;
|
2009-04-03 19:30:25 +00:00
|
|
|
class CustomElement;
|
2007-04-09 02:56:47 +00:00
|
|
|
class Terminal;
|
2007-10-03 17:02:39 +00:00
|
|
|
class Conductor;
|
2007-10-27 13:18:17 +00:00
|
|
|
class DiagramTextItem;
|
2007-11-09 13:06:51 +00:00
|
|
|
class DiagramContent;
|
2009-04-03 19:30:25 +00:00
|
|
|
class QETProject;
|
|
|
|
class ElementsLocation;
|
2007-10-10 17:50:26 +00:00
|
|
|
/**
|
|
|
|
Cette classe represente un schema electrique.
|
|
|
|
Elle gere les differents elements et conducteurs qui le composent
|
|
|
|
et en effectue le rendu graphique.
|
|
|
|
*/
|
2007-04-09 02:56:47 +00:00
|
|
|
class Diagram : public QGraphicsScene {
|
|
|
|
Q_OBJECT
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
// constructeurs, destructeur
|
2007-04-09 02:56:47 +00:00
|
|
|
public:
|
|
|
|
Diagram(QObject * = 0);
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual ~Diagram();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Diagram(const Diagram &diagram);
|
|
|
|
|
|
|
|
// attributs
|
|
|
|
public:
|
2007-10-21 16:10:21 +00:00
|
|
|
/**
|
|
|
|
Represente les options possibles pour l'affichage du schema :
|
|
|
|
* EmptyBorder : N'afficher que la bordure
|
|
|
|
* Inset : Afficher le cartouche
|
|
|
|
* Columns : Afficher les colonnes
|
|
|
|
*/
|
2007-04-12 03:13:13 +00:00
|
|
|
enum BorderOptions { EmptyBorder, Inset, Columns };
|
2007-10-14 15:16:37 +00:00
|
|
|
/// Proprietes par defaut des nouveaux conducteurs
|
|
|
|
ConductorProperties defaultConductorProperties;
|
|
|
|
/// Dimensions et cartouches du schema
|
2007-04-12 03:13:13 +00:00
|
|
|
BorderInset border_and_inset;
|
2007-10-21 16:10:21 +00:00
|
|
|
/// Mouvement en cours lors d'un deplacement d'elements et conducteurs
|
2007-09-26 17:14:09 +00:00
|
|
|
QPointF current_movement;
|
2007-10-10 22:35:32 +00:00
|
|
|
/// taille de la grille en abscisse
|
|
|
|
static const int xGrid;
|
|
|
|
/// taille de la grille en ordonnee
|
|
|
|
static const int yGrid;
|
|
|
|
/// marge autour du schema
|
|
|
|
static const qreal margin;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
private:
|
2007-10-03 17:02:39 +00:00
|
|
|
QGraphicsLineItem *conductor_setter;
|
2007-04-12 03:13:13 +00:00
|
|
|
bool draw_grid;
|
|
|
|
bool use_border;
|
2007-09-15 22:14:23 +00:00
|
|
|
bool moved_elements_fetched;
|
|
|
|
QSet<Element *> elements_to_move;
|
2007-10-03 17:02:39 +00:00
|
|
|
QSet<Conductor *> conductors_to_move;
|
|
|
|
QHash<Conductor *, Terminal *> conductors_to_update;
|
2007-10-27 13:18:17 +00:00
|
|
|
QSet<DiagramTextItem *> texts_to_move;
|
2008-07-17 22:57:50 +00:00
|
|
|
QGIManager *qgi_manager;
|
|
|
|
QUndoStack *undo_stack;
|
2007-09-30 12:35:25 +00:00
|
|
|
bool draw_terminals;
|
2009-04-03 19:30:25 +00:00
|
|
|
QDomDocument xml_document;
|
|
|
|
QETProject *project_;
|
|
|
|
bool read_only_;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
|
|
|
// methodes
|
2007-11-03 20:20:34 +00:00
|
|
|
protected:
|
|
|
|
virtual void drawBackground(QPainter *, const QRectF &);
|
|
|
|
virtual void keyPressEvent(QKeyEvent *);
|
|
|
|
virtual void keyReleaseEvent(QKeyEvent *);
|
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2007-11-03 20:20:34 +00:00
|
|
|
static bool clipboardMayContainDiagram();
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// fonctions relatives au projet parent
|
|
|
|
QETProject *project() const;
|
|
|
|
void setProject(QETProject *);
|
|
|
|
|
|
|
|
// fonctions relatives a la lecture seule
|
|
|
|
bool isReadOnly() const;
|
|
|
|
void setReadOnly(bool);
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
// fonctions relatives a la pose de conducteurs
|
2007-10-03 17:02:39 +00:00
|
|
|
void setConductor(bool);
|
|
|
|
void setConductorStart (QPointF);
|
|
|
|
void setConductorStop(QPointF);
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
// fonctions relatives a l'import / export XML
|
|
|
|
QDomDocument toXml(bool = true);
|
2009-04-28 18:04:29 +00:00
|
|
|
bool initFromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
|
|
|
|
bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
|
|
|
|
bool fromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = 0);
|
2009-04-03 19:30:25 +00:00
|
|
|
void write();
|
|
|
|
void write(const QDomElement &);
|
|
|
|
bool wasWritten() const;
|
|
|
|
QDomElement writeXml(QDomDocument &) const;
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2009-04-04 21:47:07 +00:00
|
|
|
// fonctions relative a l'ajout et a l'enlevement d'elements graphiques sur le schema
|
|
|
|
void addElement(Element *);
|
|
|
|
void addConductor(Conductor *);
|
|
|
|
void addDiagramTextItem(DiagramTextItem *);
|
|
|
|
|
|
|
|
void removeElement(Element *);
|
|
|
|
void removeConductor(Conductor *);
|
|
|
|
void removeDiagramTextItem(DiagramTextItem *);
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
// fonctions relatives aux options graphiques
|
2007-04-12 03:13:13 +00:00
|
|
|
void setDisplayGrid(bool);
|
2007-04-09 02:56:47 +00:00
|
|
|
bool displayGrid();
|
|
|
|
void setUseBorder(bool);
|
|
|
|
bool useBorder();
|
|
|
|
void setBorderOptions(BorderOptions);
|
|
|
|
BorderOptions borderOptions();
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2007-09-30 12:35:25 +00:00
|
|
|
bool drawTerminals() const;
|
|
|
|
void setDrawTerminals(bool);
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
QRectF border() const;
|
2009-04-03 19:30:25 +00:00
|
|
|
QString title() const;
|
2007-10-05 12:06:39 +00:00
|
|
|
bool toPaintDevice(QPaintDevice &, int = -1, int = -1, Qt::AspectRatioMode = Qt::KeepAspectRatio);
|
2007-04-09 02:56:47 +00:00
|
|
|
QSize imageSize() const;
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
bool isEmpty() const;
|
|
|
|
|
|
|
|
QList<CustomElement *> customElements() const;
|
2007-09-15 22:14:23 +00:00
|
|
|
void invalidateMovedElements();
|
|
|
|
void fetchMovedElements();
|
|
|
|
const QSet<Element *> &elementsToMove();
|
2007-10-03 17:02:39 +00:00
|
|
|
const QSet<Conductor *> &conductorsToMove();
|
|
|
|
const QHash<Conductor *, Terminal *> &conductorsToUpdate();
|
2007-10-27 13:18:17 +00:00
|
|
|
const QSet<DiagramTextItem *> &textsToMove();
|
2007-10-03 17:02:39 +00:00
|
|
|
QSet<Conductor *> selectedConductors() const;
|
2007-11-09 13:06:51 +00:00
|
|
|
DiagramContent content() const;
|
|
|
|
DiagramContent selectedContent();
|
2009-04-28 18:04:29 +00:00
|
|
|
void moveElements(const QPointF &, QGraphicsItem * = 0);
|
2009-04-03 19:30:25 +00:00
|
|
|
bool usesElement(const ElementsLocation &);
|
2007-09-15 22:14:23 +00:00
|
|
|
|
2007-09-25 23:24:36 +00:00
|
|
|
QUndoStack &undoStack();
|
|
|
|
QGIManager &qgiManager();
|
|
|
|
|
2008-07-09 21:14:30 +00:00
|
|
|
public slots:
|
|
|
|
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
|
|
|
|
|
2009-04-18 15:30:44 +00:00
|
|
|
// fonctions relative a la selection sur le schema
|
|
|
|
void selectAll();
|
|
|
|
void deselectAll();
|
|
|
|
void invertSelection();
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
signals:
|
2009-04-03 19:30:25 +00:00
|
|
|
void written();
|
|
|
|
void readOnlyChanged(bool);
|
2007-04-09 02:56:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2009-04-11 13:09:47 +00:00
|
|
|
Permet d'ajouter ou enlever le "poseur de conducteur", c'est-a-dire la
|
2007-04-09 02:56:47 +00:00
|
|
|
droite en pointilles qui apparait lorsqu'on pose un conducteur entre deux
|
|
|
|
bornes.
|
2007-10-21 16:10:21 +00:00
|
|
|
@param pf true pour ajouter le poseur de conducteur, false pour l'enlever
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
inline void Diagram::setConductor(bool pf) {
|
2007-04-09 02:56:47 +00:00
|
|
|
if (pf) {
|
2007-10-03 17:02:39 +00:00
|
|
|
if (!conductor_setter -> scene()) addItem(conductor_setter);
|
2007-04-09 02:56:47 +00:00
|
|
|
} else {
|
2007-10-03 17:02:39 +00:00
|
|
|
if (conductor_setter -> scene()) removeItem(conductor_setter);
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Specifie les coordonnees du point de depart du poseur de conducteur
|
|
|
|
@param d Le nouveau point de depart du poseur de conducteur
|
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
inline void Diagram::setConductorStart(QPointF d) {
|
|
|
|
conductor_setter -> setLine(QLineF(d, conductor_setter -> line().p2()));
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Specifie les coordonnees du point d'arrivee du poseur de conducteur
|
2007-10-21 16:10:21 +00:00
|
|
|
@param a Le nouveau point d'arrivee du poseur de conducteur
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2007-10-03 17:02:39 +00:00
|
|
|
inline void Diagram::setConductorStop(QPointF a) {
|
|
|
|
conductor_setter -> setLine(QLineF(conductor_setter -> line().p1(), a));
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de specifier si la grille du schema doit etre dessinee ou non
|
|
|
|
@param dg true pour afficher la grille, false pour ne pas l'afficher
|
|
|
|
*/
|
2007-04-12 03:13:13 +00:00
|
|
|
inline void Diagram::setDisplayGrid(bool dg) {
|
2007-04-09 02:56:47 +00:00
|
|
|
draw_grid = dg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de savoir si la grille du schema est dessinee ou non
|
|
|
|
@return true si la grille est affichee , false sinon
|
|
|
|
*/
|
|
|
|
inline bool Diagram::displayGrid() {
|
|
|
|
return(draw_grid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de specifier si le cadre du schema doit etre pris en compte pour
|
|
|
|
determiner le contour du schema.
|
|
|
|
@param ub true pour prendre le schema en compte, false sinon
|
|
|
|
*/
|
|
|
|
inline void Diagram::setUseBorder(bool ub) {
|
|
|
|
use_border = ub;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de savoir si le cadre du schema est pris en compte pour
|
|
|
|
determiner le contour du schema.
|
|
|
|
*/
|
|
|
|
inline bool Diagram::useBorder() {
|
|
|
|
return(use_border);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de definir les options du cadre, des colonnes et du cartouche.
|
|
|
|
@param bo Un OU binaire entre les options possibles
|
|
|
|
@see BorderOptions
|
|
|
|
*/
|
|
|
|
inline void Diagram::setBorderOptions(Diagram::BorderOptions bo) {
|
|
|
|
border_and_inset.displayBorder(!(bo & EmptyBorder));
|
|
|
|
border_and_inset.displayColumns(bo & Columns);
|
|
|
|
border_and_inset.displayInset(bo & Inset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de savoir les options du cadre, des colonnes et du cartouche.
|
|
|
|
@return Un OU binaire entre les options possibles
|
|
|
|
@see BorderOptions
|
|
|
|
*/
|
|
|
|
inline Diagram::BorderOptions Diagram::borderOptions() {
|
|
|
|
BorderOptions retour = EmptyBorder;
|
|
|
|
if (border_and_inset.insetIsDisplayed()) retour = (BorderOptions)(retour|Inset);
|
|
|
|
if (border_and_inset.columnsAreDisplayed()) retour = (BorderOptions)(retour|Columns);
|
|
|
|
return(retour);
|
|
|
|
}
|
|
|
|
|
2007-09-15 22:14:23 +00:00
|
|
|
/// @return la liste des elements a deplacer
|
|
|
|
inline const QSet<Element *> &Diagram::elementsToMove() {
|
|
|
|
if (!moved_elements_fetched) fetchMovedElements();
|
|
|
|
return(elements_to_move);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @return la liste des conducteurs a deplacer
|
2007-10-03 17:02:39 +00:00
|
|
|
inline const QSet<Conductor *> &Diagram::conductorsToMove() {
|
2007-09-15 22:14:23 +00:00
|
|
|
if (!moved_elements_fetched) fetchMovedElements();
|
2007-10-03 17:02:39 +00:00
|
|
|
return(conductors_to_move);
|
2007-09-15 22:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @return la liste des conducteurs a modifier (typiquement les conducteurs dont seul un element est deplace)
|
2007-10-03 17:02:39 +00:00
|
|
|
inline const QHash<Conductor *, Terminal *> &Diagram::conductorsToUpdate() {
|
2007-09-15 22:14:23 +00:00
|
|
|
if (!moved_elements_fetched) fetchMovedElements();
|
2007-10-03 17:02:39 +00:00
|
|
|
return(conductors_to_update);
|
2007-09-15 22:14:23 +00:00
|
|
|
}
|
|
|
|
|
2007-10-27 13:18:17 +00:00
|
|
|
/// @return la liste des textes a deplacer
|
|
|
|
inline const QSet<DiagramTextItem *> &Diagram::textsToMove() {
|
|
|
|
if (!moved_elements_fetched) fetchMovedElements();
|
|
|
|
return(texts_to_move);
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:24:36 +00:00
|
|
|
/// @return la pile d'annulations de ce schema
|
|
|
|
inline QUndoStack &Diagram::undoStack() {
|
2008-07-17 22:57:50 +00:00
|
|
|
return(*undo_stack);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @return le egstionnaire de QGraphicsItem de ce schema
|
|
|
|
inline QGIManager &Diagram::qgiManager() {
|
2008-07-17 22:57:50 +00:00
|
|
|
return(*qgi_manager);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/// @return true si les bornes sont affichees, false sinon
|
2007-09-30 12:35:25 +00:00
|
|
|
inline bool Diagram::drawTerminals() const {
|
|
|
|
return(draw_terminals);
|
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|