2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2016-05-13 17:40:36 +00:00
|
|
|
Copyright 2006-2016 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/>.
|
|
|
|
*/
|
2010-04-18 17:59:54 +00:00
|
|
|
#ifndef DIAGRAM_H
|
|
|
|
#define DIAGRAM_H
|
2015-03-02 20:14:56 +00:00
|
|
|
#include <QtWidgets>
|
2007-04-09 02:56:47 +00:00
|
|
|
#include <QtXml>
|
2013-05-02 11:47:14 +00:00
|
|
|
#include <QHash>
|
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"
|
2013-05-02 11:47:14 +00:00
|
|
|
#include "numerotationcontext.h"
|
2014-01-05 15:00:46 +00:00
|
|
|
#include "qetproject.h"
|
2014-04-11 09:51:21 +00:00
|
|
|
#include "properties/xrefproperties.h"
|
2013-05-02 11:47:14 +00:00
|
|
|
|
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-04-18 17:59:54 +00:00
|
|
|
class IndependentTextItem;
|
|
|
|
class QETProject;
|
|
|
|
class Terminal;
|
2013-05-28 16:50:35 +00:00
|
|
|
class ConductorTextItem;
|
2013-08-24 15:18:45 +00:00
|
|
|
class DiagramImageItem;
|
2014-10-25 21:21:52 +00:00
|
|
|
class ElementTextsMover;
|
2015-03-04 21:13:13 +00:00
|
|
|
class DiagramEventInterface;
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This class represents an electric diagram. It manages its various child
|
|
|
|
elements, conductors and texts and handles their graphic rendering.
|
2007-10-10 17:50:26 +00:00
|
|
|
*/
|
2014-12-21 12:50:26 +00:00
|
|
|
class Diagram : public QGraphicsScene
|
|
|
|
{
|
2007-04-09 02:56:47 +00:00
|
|
|
Q_OBJECT
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2014-12-21 12:50:26 +00:00
|
|
|
// constructors, destructor
|
2007-04-09 02:56:47 +00:00
|
|
|
public:
|
2014-12-21 12:50:26 +00:00
|
|
|
Diagram(QETProject *project);
|
|
|
|
virtual ~Diagram();
|
2007-04-12 03:13:13 +00:00
|
|
|
private:
|
2014-12-21 12:50:26 +00:00
|
|
|
Diagram(const Diagram &diagram);
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2014-07-31 10:02:33 +00:00
|
|
|
// ATTRIBUTES
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2014-07-31 10:02:33 +00:00
|
|
|
/**
|
|
|
|
Represents available options when rendering a particular diagram:
|
|
|
|
* EmptyBorder: display border only
|
|
|
|
* TitleBlock: display title block
|
|
|
|
* Columns: display columns
|
|
|
|
*/
|
|
|
|
enum BorderOptions { EmptyBorder, TitleBlock, Columns };
|
|
|
|
/// Represents available option of Numerotation type.
|
|
|
|
enum NumerotationType { Conductors };
|
|
|
|
/// Default properties for new conductors
|
|
|
|
ConductorProperties defaultConductorProperties;
|
|
|
|
/// Diagram dimensions and title block
|
|
|
|
BorderTitleBlock border_and_titleblock;
|
|
|
|
/// abscissa grid step size
|
|
|
|
static const int xGrid;
|
|
|
|
/// ordinate grid step size
|
|
|
|
static const int yGrid;
|
|
|
|
/// margin around the diagram
|
|
|
|
static const qreal margin;
|
|
|
|
/// background color of diagram
|
|
|
|
static QColor background_color;
|
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
private:
|
2014-07-31 10:02:33 +00:00
|
|
|
QGraphicsLineItem *conductor_setter_;
|
|
|
|
ElementsMover *elements_mover_;
|
2014-10-25 21:21:52 +00:00
|
|
|
ElementTextsMover *element_texts_mover_;
|
2014-07-31 10:02:33 +00:00
|
|
|
QGIManager *qgi_manager_;
|
2016-03-15 18:42:18 +00:00
|
|
|
QETProject *m_project;
|
2014-07-31 10:02:33 +00:00
|
|
|
|
|
|
|
QDomDocument xml_document_;
|
|
|
|
|
|
|
|
qreal diagram_qet_version_;
|
|
|
|
|
|
|
|
bool draw_grid_;
|
|
|
|
bool use_border_;
|
|
|
|
bool draw_terminals_;
|
|
|
|
bool draw_colored_conductors_;
|
|
|
|
|
|
|
|
QString m_conductors_autonum_name;
|
2015-03-04 21:13:13 +00:00
|
|
|
DiagramEventInterface *m_event_interface;
|
2014-07-31 10:02:33 +00:00
|
|
|
|
|
|
|
// METHODS
|
2007-11-03 20:20:34 +00:00
|
|
|
protected:
|
2014-07-31 10:02:33 +00:00
|
|
|
virtual void drawBackground(QPainter *, const QRectF &);
|
2015-03-04 21:13:13 +00:00
|
|
|
|
|
|
|
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
|
|
|
|
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
|
|
|
|
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event);
|
|
|
|
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
|
|
|
|
virtual void wheelEvent (QGraphicsSceneWheelEvent *event);
|
|
|
|
virtual void keyPressEvent (QKeyEvent *);
|
|
|
|
virtual void keyReleaseEvent (QKeyEvent *);
|
2007-11-03 20:20:34 +00:00
|
|
|
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2015-03-04 21:13:13 +00:00
|
|
|
void setEventInterface (DiagramEventInterface *event_interface);
|
|
|
|
|
2014-07-31 10:02:33 +00:00
|
|
|
//methods related to xref properties
|
2016-03-15 18:42:18 +00:00
|
|
|
QString defaultReportProperties () const {return m_project -> defaultReportProperties();}
|
|
|
|
XRefProperties defaultXRefProperties (const QString &str) const {return m_project -> defaultXRefProperties(str);}
|
2014-07-31 10:02:33 +00:00
|
|
|
|
|
|
|
//methods related to autonum
|
|
|
|
QString conductorsAutonumName() const;
|
|
|
|
void setConductorsAutonumName(const QString &name);
|
|
|
|
|
|
|
|
static bool clipboardMayContainDiagram();
|
|
|
|
|
|
|
|
// methods related to parent project
|
|
|
|
QETProject *project() const;
|
2014-12-21 13:17:35 +00:00
|
|
|
void setProject(QETProject *);
|
|
|
|
int folioIndex() const;
|
|
|
|
qreal declaredQElectroTechVersion(bool = true) const;
|
|
|
|
void showMe() {emit showDiagram(this);}
|
|
|
|
bool isReadOnly() const;
|
2009-04-03 19:30:25 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods related to conductor creation
|
2007-10-03 17:02:39 +00:00
|
|
|
void setConductor(bool);
|
|
|
|
void setConductorStart (QPointF);
|
|
|
|
void setConductorStop(QPointF);
|
2013-04-19 14:59:20 +00:00
|
|
|
QList < QSet <Conductor *> > potentials();
|
2007-04-09 02:56:47 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods related to XML import/export
|
2007-04-09 02:56:47 +00:00
|
|
|
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
|
|
|
|
2015-07-12 15:05:59 +00:00
|
|
|
// methods related to graphics items addition/removal on the diagram
|
2013-12-31 14:39:34 +00:00
|
|
|
void initElementsLinks();
|
2015-07-12 15:05:59 +00:00
|
|
|
virtual void addItem (QGraphicsItem *item);
|
|
|
|
virtual void removeItem (QGraphicsItem *item);
|
2009-04-04 21:47:07 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods related to graphics options
|
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 &);
|
2014-06-14 16:04:34 +00:00
|
|
|
static QPointF snapToGrid(const QPointF &p);
|
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);
|
2015-01-07 19:21:17 +00:00
|
|
|
|
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;
|
2013-12-29 13:39:48 +00:00
|
|
|
QList<Element *> elements() const;
|
2010-02-11 23:35:04 +00:00
|
|
|
QSet<DiagramTextItem *> selectedTexts() const;
|
2013-05-28 16:50:35 +00:00
|
|
|
QSet<ConductorTextItem *> selectedConductorTexts() const;
|
2014-12-23 01:51:17 +00:00
|
|
|
QSet<ElementTextItem*> selectedElementTexts() 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();
|
2014-10-25 21:21:52 +00:00
|
|
|
int beginMoveElementTexts(QGraphicsItem * = 0);
|
|
|
|
void continueMoveElementTexts(const QPointF &);
|
|
|
|
void endMoveElementTexts();
|
2009-04-03 19:30:25 +00:00
|
|
|
bool usesElement(const ElementsLocation &);
|
2012-01-23 20:36:51 +00:00
|
|
|
bool usesTitleBlockTemplate(const QString &);
|
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:
|
2015-03-30 15:58:16 +00:00
|
|
|
void adjustSceneRect ();
|
|
|
|
void titleChanged(const QString &);
|
|
|
|
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
|
|
|
|
void titleBlockTemplateChanged(const QString &);
|
|
|
|
void titleBlockTemplateRemoved(const QString &, const QString & = QString());
|
|
|
|
void setTitleBlockTemplate(const QString &);
|
|
|
|
|
|
|
|
// methods related to graphics items selection
|
|
|
|
void selectAll();
|
|
|
|
void deselectAll();
|
|
|
|
void invertSelection();
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
signals:
|
2014-12-21 13:17:35 +00:00
|
|
|
void showDiagram (Diagram *);
|
|
|
|
void written();
|
|
|
|
void usedTitleBlockTemplateChanged(const QString &);
|
|
|
|
void diagramTitleChanged(Diagram *, const QString &);
|
|
|
|
void findElementRequired(const ElementsLocation &); /// Signal emitted when users wish to locate an element from the diagram within elements collection
|
|
|
|
void editElementRequired(const ElementsLocation &); /// Signal emitted when users wish to edit an element from the diagram
|
|
|
|
void reportPropertiesChanged(QString);
|
|
|
|
void XRefPropertiesChanged();
|
2007-04-09 02:56:47 +00:00
|
|
|
};
|
2012-02-06 21:21:43 +00:00
|
|
|
Q_DECLARE_METATYPE(Diagram *)
|
2007-04-09 02:56:47 +00:00
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Display or hide the conductor setter, i.e. a dashed conductor stub which appears when creating a conductor between two terminals.
|
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
|
|
|
*/
|
2012-11-09 21:09:24 +00:00
|
|
|
inline void Diagram::setConductor(bool adding) {
|
|
|
|
if (adding) {
|
|
|
|
if (!conductor_setter_ -> scene()) addItem(conductor_setter_);
|
2007-04-09 02:56:47 +00:00
|
|
|
} else {
|
2012-11-09 21:09:24 +00:00
|
|
|
if (conductor_setter_ -> scene()) removeItem(conductor_setter_);
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Set the start point of the conductor setter.
|
|
|
|
@param start the point (in scene coordinates) which the newly created
|
|
|
|
conductor should start from.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2012-11-09 21:09:24 +00:00
|
|
|
inline void Diagram::setConductorStart(QPointF start) {
|
|
|
|
conductor_setter_ -> setLine(QLineF(start, conductor_setter_ -> line().p2()));
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Set the end point of the conductor setter.
|
|
|
|
@param end the point (in scene coordinates) upon to which the newly created
|
|
|
|
conductor should be drawn.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2012-11-09 21:09:24 +00:00
|
|
|
inline void Diagram::setConductorStop(QPointF end) {
|
|
|
|
conductor_setter_ -> setLine(QLineF(conductor_setter_ -> line().p1(), end));
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Set whether the diagram grid should be drawn.
|
|
|
|
@param dg true to render the grid, false otherwise.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
2007-04-12 03:13:13 +00:00
|
|
|
inline void Diagram::setDisplayGrid(bool dg) {
|
2012-11-09 21:09:24 +00:00
|
|
|
draw_grid_ = dg;
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return true if the grid is drawn, false otherwise.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
|
|
|
inline bool Diagram::displayGrid() {
|
2012-11-09 21:09:24 +00:00
|
|
|
return(draw_grid_);
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Set whether the diagram border (including rows/colums headers and the title
|
|
|
|
block) should be rendered along with the diagram. When set to false, the size
|
|
|
|
of the smallest rectangle containing all items is considered as the diagram
|
|
|
|
size.
|
|
|
|
@param ub true to take the border into account, false otherwise
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
|
|
|
inline void Diagram::setUseBorder(bool ub) {
|
2012-11-09 21:09:24 +00:00
|
|
|
use_border_ = ub;
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return true if the border is rendered and take into account, false
|
|
|
|
otherwise.
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
|
|
|
inline bool Diagram::useBorder() {
|
2012-11-09 21:09:24 +00:00
|
|
|
return(use_border_);
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Set the rendering options for the diagram border (including rows/colums
|
|
|
|
headers and the title block)
|
|
|
|
@param bo Enabled options ORed together
|
2007-04-09 02:56:47 +00:00
|
|
|
@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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return The rendering optios for the diagram border
|
|
|
|
@see setBorderOptions
|
2007-04-09 02:56:47 +00:00
|
|
|
*/
|
|
|
|
inline Diagram::BorderOptions Diagram::borderOptions() {
|
2012-11-09 21:09:24 +00:00
|
|
|
BorderOptions options = EmptyBorder;
|
|
|
|
if (border_and_titleblock.titleBlockIsDisplayed()) options = (BorderOptions)(options|TitleBlock);
|
|
|
|
if (border_and_titleblock.columnsAreDisplayed()) options = (BorderOptions)(options|Columns);
|
|
|
|
return(options);
|
2007-04-09 02:56:47 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return the diagram undo stack
|
2007-09-25 23:24:36 +00:00
|
|
|
inline QUndoStack &Diagram::undoStack() {
|
2014-01-05 15:00:46 +00:00
|
|
|
return *(project()->undoStack());
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return the diagram graphics item manager
|
2007-09-25 23:24:36 +00:00
|
|
|
inline QGIManager &Diagram::qgiManager() {
|
2012-11-09 21:09:24 +00:00
|
|
|
return(*qgi_manager_);
|
2007-09-25 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return true if terminals are rendered, false otherwise
|
2007-09-30 12:35:25 +00:00
|
|
|
inline bool Diagram::drawTerminals() const {
|
2012-11-09 21:09:24 +00:00
|
|
|
return(draw_terminals_);
|
2007-09-30 12:35:25 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
/// @return true if conductors colors are rendered, false otherwise.
|
2009-11-22 16:12:22 +00:00
|
|
|
inline bool Diagram::drawColoredConductors() const {
|
|
|
|
return(draw_colored_conductors_);
|
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|