2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2013-06-18 11:10:19 +00:00
|
|
|
Copyright 2006-2013 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/>.
|
|
|
|
*/
|
2009-04-03 19:30:25 +00:00
|
|
|
#ifndef CUSTOM_ELEMENT_H
|
|
|
|
#define CUSTOM_ELEMENT_H
|
2007-04-12 03:13:13 +00:00
|
|
|
#include "fixedelement.h"
|
|
|
|
#include <QtGui>
|
2007-04-16 20:38:58 +00:00
|
|
|
#include "nameslist.h"
|
2009-04-03 19:30:25 +00:00
|
|
|
#include "elementslocation.h"
|
|
|
|
class ElementTextItem;
|
|
|
|
class Terminal;
|
2007-04-12 03:13:13 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This class represents an electrical element; it may be used like a fixed
|
|
|
|
element, the difference being that the CustomElement reads its description
|
|
|
|
(names, drawing, behavior) from an XML document.
|
2007-04-12 03:13:13 +00:00
|
|
|
*/
|
|
|
|
class CustomElement : public FixedElement {
|
2009-04-03 19:30:25 +00:00
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2009-04-03 19:30:25 +00:00
|
|
|
CustomElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
|
|
|
|
CustomElement(const QDomElement &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual ~CustomElement();
|
|
|
|
|
|
|
|
private:
|
|
|
|
CustomElement(const CustomElement &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2009-04-03 19:30:25 +00:00
|
|
|
protected:
|
2012-11-09 21:09:24 +00:00
|
|
|
int elmt_state; // hold the error code in case the instanciation fails, or 0 if everything went well
|
2007-04-16 20:38:58 +00:00
|
|
|
NamesList names;
|
2009-04-03 19:30:25 +00:00
|
|
|
ElementsLocation location_;
|
|
|
|
QPicture drawing;
|
2009-04-05 11:48:26 +00:00
|
|
|
QPicture low_zoom_drawing;
|
2007-09-05 20:42:08 +00:00
|
|
|
QList<Terminal *> list_terminals;
|
2009-04-04 21:47:07 +00:00
|
|
|
QList<ElementTextItem *> list_texts_;
|
2009-04-05 11:48:26 +00:00
|
|
|
bool forbid_antialiasing;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2007-04-12 03:13:13 +00:00
|
|
|
public:
|
2007-09-05 20:42:08 +00:00
|
|
|
virtual QList<Terminal *> terminals() const;
|
2007-10-03 17:02:39 +00:00
|
|
|
virtual QList<Conductor *> conductors() const;
|
2009-04-04 21:47:07 +00:00
|
|
|
virtual QList<ElementTextItem *> texts() const;
|
2009-04-03 19:30:25 +00:00
|
|
|
virtual int terminalsCount() const;
|
2007-04-12 03:13:13 +00:00
|
|
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *);
|
|
|
|
QString typeId() const;
|
2009-04-03 19:30:25 +00:00
|
|
|
ElementsLocation location() const;
|
2007-04-12 03:13:13 +00:00
|
|
|
bool isNull() const;
|
2009-04-03 19:30:25 +00:00
|
|
|
int state() const;
|
|
|
|
QString name() const;
|
2007-04-12 03:13:13 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
protected:
|
|
|
|
virtual bool buildFromXml(const QDomElement &, int * = 0);
|
|
|
|
virtual bool parseElement(QDomElement &, QPainter &);
|
|
|
|
virtual bool parseLine(QDomElement &, QPainter &);
|
|
|
|
virtual bool parseRect(QDomElement &, QPainter &);
|
|
|
|
virtual bool parseEllipse(QDomElement &, QPainter &);
|
|
|
|
virtual bool parseCircle(QDomElement &, QPainter &);
|
|
|
|
virtual bool parseArc(QDomElement &, QPainter &);
|
|
|
|
virtual bool parsePolygon(QDomElement &, QPainter &);
|
|
|
|
virtual bool parseText(QDomElement &, QPainter &);
|
|
|
|
virtual ElementTextItem *parseInput(QDomElement &);
|
|
|
|
virtual Terminal *parseTerminal(QDomElement &);
|
|
|
|
virtual void setQPainterAntiAliasing(QPainter &, bool);
|
|
|
|
virtual bool validOrientationAttribute(const QDomElement &);
|
|
|
|
virtual void setPainterStyle(QDomElement &, QPainter &);
|
2007-04-12 03:13:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return The element type ID; considering a CustomElement, this means the
|
|
|
|
@location of its XML description.
|
2009-04-03 19:30:25 +00:00
|
|
|
@see location()
|
2007-04-12 03:13:13 +00:00
|
|
|
*/
|
|
|
|
inline QString CustomElement::typeId() const {
|
2009-04-03 19:30:25 +00:00
|
|
|
return(location_.path());
|
2007-04-12 03:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return the location of the XML document describing this element.
|
2007-04-12 03:13:13 +00:00
|
|
|
*/
|
2009-04-03 19:30:25 +00:00
|
|
|
inline ElementsLocation CustomElement::location() const {
|
|
|
|
return(location_);
|
2007-04-12 03:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return true if this element is null, i.e. if its XML description could not
|
|
|
|
be loaded.
|
2007-04-12 03:13:13 +00:00
|
|
|
*/
|
|
|
|
inline bool CustomElement::isNull() const {
|
2009-04-03 19:30:25 +00:00
|
|
|
return(elmt_state);
|
2007-04-12 03:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return An integer representing the state of this element:
|
|
|
|
- 0: instantiation succeeded
|
|
|
|
- 1: the file does not exist
|
|
|
|
- 2: the file could not be opened
|
|
|
|
- 3: The file is not a valid XML document
|
|
|
|
- 4: The XML document does not have a "definition" root element.
|
|
|
|
- 5: The definition attributes are missing or invalid
|
|
|
|
- 6: The definition is empty
|
|
|
|
- 7: The parsing of an XML element describing an element drawing primitive failed
|
|
|
|
- 8: No primitive could be loadedAucune partie du dessin n'a pu etre chargee
|
2007-04-12 03:13:13 +00:00
|
|
|
*/
|
2009-04-03 19:30:25 +00:00
|
|
|
inline int CustomElement::state() const {
|
|
|
|
return(elmt_state);
|
2007-04-12 03:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
@return The name of this element.
|
2007-04-12 03:13:13 +00:00
|
|
|
*/
|
2009-04-03 19:30:25 +00:00
|
|
|
inline QString CustomElement::name() const {
|
|
|
|
return(names.name(location_.baseName()));
|
2007-04-12 03:13:13 +00:00
|
|
|
}
|
|
|
|
|
2006-10-27 15:47:22 +00:00
|
|
|
#endif
|