mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-08 21:14:14 +02:00
9699b314b0
With symbols as blocks and the new "DXF : textes des symboles en attributs" option (--dxf-attributes on the command line), a symbol's own texts (its label, function, comment...) are attributes of its INSERT instead of loose texts, so a CAD program moves them with the symbol and can list or edit them. Each is written exactly where, and as, the text was. A text showing an information field is tagged with its name (LABEL, FUNCTION...), a typed text TEXT1, TEXT2...; a text's second line gets _2. The block defines each tag once, placed where the first symbol has it. Its own option, off by default, because LibreCAD (2.2.1.5) does not show attributes: the labels would vanish there. AutoCAD shows them. The text geometry moves into textLines(), shared with the text loop, so the attributes and the plain texts cannot drift apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
215 lines
5.1 KiB
C++
215 lines
5.1 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
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/>.
|
|
*/
|
|
#ifndef CREATEDXF_H
|
|
#define CREATEDXF_H
|
|
#include <QString>
|
|
#include <QStringList>
|
|
#include <QtCore>
|
|
#include <QtWidgets>
|
|
|
|
#include <functional>
|
|
|
|
/**
|
|
@brief The Createdxf class
|
|
This class exports the project to DXF Format
|
|
*/
|
|
class Createdxf
|
|
{
|
|
public:
|
|
Createdxf();
|
|
~Createdxf();
|
|
static void dxfBegin (const QString&, const QStringList &layers = QStringList(),
|
|
const std::function<void()> &writeBlocks = {});
|
|
static void dxfEnd(const QString&);
|
|
static void dxfBlockBegin(const QString &fileName,
|
|
const QString &name,
|
|
double x,
|
|
double y,
|
|
bool hasAttributes = false);
|
|
static void dxfBlockEnd(const QString &fileName);
|
|
/// One attribute of a placed block, in DXF units
|
|
struct Attribute
|
|
{
|
|
QString tag;
|
|
QString text;
|
|
double x = 0;
|
|
double y = 0;
|
|
double height = 0;
|
|
double rotation = 0;
|
|
double xScaleW = 1;
|
|
int colour = 0;
|
|
bool invisible = false;
|
|
QString layer; ///< empty: the INSERT's layer
|
|
};
|
|
static void drawInsert(const QString &fileName,
|
|
const QString &name,
|
|
double x,
|
|
double y,
|
|
double rotation,
|
|
const QList<Attribute> &attributes = {});
|
|
static void drawAttdef(const QString &fileName,
|
|
const Attribute &attribute);
|
|
static QString blockName(const QString &name);
|
|
// you can add more functions to create more drawings.
|
|
static void drawCircle(
|
|
const QString&,
|
|
double,
|
|
double,
|
|
double,
|
|
int);
|
|
|
|
static void drawCircle(
|
|
const QString& ,
|
|
QPointF,
|
|
double,
|
|
int );
|
|
|
|
static void drawArc(
|
|
const QString&,
|
|
double x,
|
|
double y,
|
|
double rad,
|
|
double startAngle,
|
|
double endAngle,
|
|
int color);
|
|
static void drawDonut(QString,double,double,double,int);
|
|
|
|
static void drawArcEllipse (
|
|
const QString &file_path,
|
|
qreal x,
|
|
qreal y,
|
|
qreal w,
|
|
qreal h,
|
|
qreal startAngle,
|
|
qreal spanAngle,
|
|
qreal hotspot_x,
|
|
qreal hotspot_y,
|
|
qreal rotation_angle,
|
|
const int &colorcode);
|
|
|
|
static void drawArcEllipse(
|
|
const QString &file_path,
|
|
QRectF rect,
|
|
qreal startAngle,
|
|
qreal spanAngle,
|
|
QPointF hotspot,
|
|
qreal rotation_angle,
|
|
const int &colorcode);
|
|
|
|
static void drawEllipse (const QString &filepath,
|
|
const QRectF &rect,
|
|
const int &colorcode);
|
|
|
|
static void drawRectangle(
|
|
const QString &filepath,
|
|
double,
|
|
double,
|
|
double,
|
|
double,
|
|
const int &colorcode);
|
|
static void drawRectangle(
|
|
const QString &filepath,
|
|
const QRectF &rect,
|
|
const int &colorcode);
|
|
|
|
static void drawPolygon(
|
|
const QString &filepath,
|
|
const QPolygonF &poly,
|
|
const int &colorcode);
|
|
|
|
static void drawLine(
|
|
const QString &filapath,
|
|
double,
|
|
double,
|
|
double,
|
|
double,
|
|
const int &clorcode);
|
|
static void drawLine(
|
|
const QString &filepath,
|
|
const QLineF &line,
|
|
const int &colorcode);
|
|
|
|
static void drawText(
|
|
const QString&,
|
|
const QString&,
|
|
double,double,
|
|
double,
|
|
double,
|
|
int,
|
|
double xScale=1.0);
|
|
static void drawText(
|
|
const QString&,
|
|
const QString&,
|
|
QPointF,
|
|
double,
|
|
double,
|
|
int,
|
|
double xScale=1.0);
|
|
static void drawTextAligned(
|
|
const QString& fileName,
|
|
const QString& text,
|
|
double x,
|
|
double y,
|
|
double height,
|
|
double rotation,
|
|
double oblique,
|
|
int hAlign,
|
|
int vAlign,
|
|
double xAlign,
|
|
double xScale,
|
|
int colour);
|
|
static void drawTextAligned(
|
|
const QString& fileName,
|
|
const QString& text,
|
|
double x,
|
|
double y,
|
|
double height,
|
|
double rotation,
|
|
double oblique,
|
|
int hAlign,
|
|
int vAlign,
|
|
double xAlign,
|
|
double yAlign,
|
|
double xScale,
|
|
int colour);
|
|
|
|
static void drawPolyline(
|
|
const QString &filepath,
|
|
const QPolygonF &poly,
|
|
const int &colorcode,
|
|
bool preScaled = false);
|
|
|
|
static int getcolorCode (
|
|
const long red,
|
|
const long green,
|
|
const long blue);
|
|
static long RGBcodeTable[];
|
|
static int dxfColor(QColor color);
|
|
static int dxfColor(QPen pen);
|
|
|
|
static const double sheetWidth;
|
|
static const double sheetHeight;
|
|
static double xScale;
|
|
static double yScale;
|
|
/// Layer every entity is written on, "0" unless set; the
|
|
/// layers themselves are declared by dxfBegin() (discussion #1071).
|
|
static QString layer;
|
|
};
|
|
|
|
#endif // CREATEDXF_H
|