2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2011-03-02 00:16:40 +00:00
|
|
|
Copyright 2006-2011 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/>.
|
|
|
|
*/
|
2010-04-18 17:59:54 +00:00
|
|
|
#ifndef DIAGRAM_H
|
|
|
|
#define DIAGRAM_H
|
2007-04-09 02:56:47 +00:00
|
|
|
#include <QtGui>
|
|
|
|
#include <QtXml>
|
2010-12-20 02:45:36 +00:00
|
|
|
#include "bordertitleblock.h"
|
2007-10-14 15:16:37 +00:00
|
|
|
#include "conductorproperties.h"
|
2009-11-22 16:12:22 +00:00
|
|
|
#include "exportproperties.h"
|
2010-04-18 17:59:54 +00:00
|
|
|
#include "qgimanager.h"
|
2007-10-03 17:02:39 +00:00
|
|
|
class Conductor;
|
2010-04-18 17:59:54 +00:00
|
|
|
class CustomElement;
|
2007-11-09 13:06:51 +00:00
|
|
|
class DiagramContent;
|
2009-05-20 21:29:17 +00:00
|
|
|
class DiagramPosition;
|
2010-04-18 17:59:54 +00:00
|
|
|
class DiagramTextItem;
|
|
|
|
class Element;
|
2009-04-03 19:30:25 +00:00
|
|
|
class ElementsLocation;
|
2010-05-08 21:24:43 +00:00
|
|
|
class ElementsMover;
|
2010-04-24 20:42:20 +00:00
|
|
|
class ElementTextItem;
|
2010-05-08 21:24:43 +00:00
|
|
|
class ElementTextsMover;
|
2010-04-18 17:59:54 +00:00
|
|
|
class IndependentTextItem;
|
|
|
|
class QETProject;
|
|
|
|
class Terminal;
|
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
|
2010-12-20 02:45:36 +00:00
|
|
|
* TitleBlock : Afficher le cartouche
|
2007-10-21 16:10:21 +00:00
|
|
|
* Columns : Afficher les colonnes
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
enum BorderOptions { EmptyBorder, TitleBlock, Columns };
|
2007-10-14 15:16:37 +00:00
|
|
|
/// Proprietes par defaut des nouveaux conducteurs
|
|
|
|
ConductorProperties defaultConductorProperties;
|
|
|
|
/// Dimensions et cartouches du schema
|
2010-12-20 02:45:36 +00:00
|
|
|
BorderTitleBlock border_and_titleblock;
|
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;
|
2010-05-08 21:24:43 +00:00
|
|
|
ElementsMover *elements_mover_;
|
|
|
|
ElementTextsMover *element_texts_mover_;
|
2007-04-12 03:13:13 +00:00
|
|
|
bool draw_grid;
|
|
|
|
bool use_border;
|
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-11-22 16:12:22 +00:00
|
|
|
bool draw_colored_conductors_;
|
2009-04-03 19:30:25 +00:00
|
|
|
QDomDocument xml_document;
|
|
|
|
QETProject *project_;
|
|
|
|
bool read_only_;
|
2011-08-29 21:50:43 +00:00
|
|
|
qreal diagram_qet_version_;
|
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 *);
|
2011-08-29 21:50:43 +00:00
|
|
|
qreal declaredQElectroTechVersion(bool = true) const;
|
2009-04-03 19:30:25 +00:00
|
|
|
|
|
|
|
// 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 *);
|
2010-04-18 17:59:54 +00:00
|
|
|
void addIndependentTextItem(IndependentTextItem *);
|
2009-04-04 21:47:07 +00:00
|
|
|
|
|
|
|
void removeElement(Element *);
|
|
|
|
void removeConductor(Conductor *);
|
2010-04-18 17:59:54 +00:00
|
|
|
void removeIndependentTextItem(IndependentTextItem *);
|
2009-04-04 21:47:07 +00:00
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
// fonctions relatives aux options graphiques
|
2009-11-22 16:12:22 +00:00
|
|
|
ExportProperties applyProperties(const ExportProperties &);
|
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();
|
2009-05-20 21:29:17 +00:00
|
|
|
DiagramPosition convertPosition(const QPointF &);
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2007-09-30 12:35:25 +00:00
|
|
|
bool drawTerminals() const;
|
|
|
|
void setDrawTerminals(bool);
|
2009-11-22 16:12:22 +00:00
|
|
|
bool drawColoredConductors() const;
|
|
|
|
void setDrawColoredConductors(bool);
|
2007-09-30 12:35:25 +00:00
|
|
|
|
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;
|
2010-02-11 23:35:04 +00:00
|
|
|
QSet<DiagramTextItem *> selectedTexts() const;
|
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-06-16 22:37:15 +00:00
|
|
|
bool canRotateSelection() const;
|
2010-05-08 21:24:43 +00:00
|
|
|
int beginMoveElements(QGraphicsItem * = 0);
|
|
|
|
void continueMoveElements(const QPointF &);
|
|
|
|
void endMoveElements();
|
|
|
|
int beginMoveElementTexts(QGraphicsItem * = 0);
|
|
|
|
void continueMoveElementTexts(const QPointF &);
|
|
|
|
void endMoveElementTexts();
|
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 &);
|
2010-12-24 21:00:11 +00:00
|
|
|
void titleBlockTemplateChanged(const QString &);
|
|
|
|
void titleBlockTemplateRemoved(const QString &, const QString & = QString());
|
2010-12-24 23:35:40 +00:00
|
|
|
void setTitleBlockTemplate(const QString &);
|
2008-07-09 21:14:30 +00:00
|
|
|
|
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) {
|
2010-12-20 02:45:36 +00:00
|
|
|
border_and_titleblock.displayBorder(!(bo & EmptyBorder));
|
|
|
|
border_and_titleblock.displayColumns(bo & Columns);
|
|
|
|
border_and_titleblock.displayTitleBlock(bo & TitleBlock);
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
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;
|
2010-12-20 02:45:36 +00:00
|
|
|
if (border_and_titleblock.titleBlockIsDisplayed()) retour = (BorderOptions)(retour|TitleBlock);
|
|
|
|
if (border_and_titleblock.columnsAreDisplayed()) retour = (BorderOptions)(retour|Columns);
|
2007-04-09 02:56:47 +00:00
|
|
|
return(retour);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-11-22 16:12:22 +00:00
|
|
|
/// @return true si les couleurs des conducteurs sont respectees, false sinon
|
|
|
|
inline bool Diagram::drawColoredConductors() const {
|
|
|
|
return(draw_colored_conductors_);
|
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|