mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 08:40:53 +01:00
DXF - fine tune text item locations
This commit is contained in:
@@ -830,6 +830,64 @@ void Createdxf::drawArc(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Createdxf::drawText
|
||||||
|
draw simple text in dxf format without any alignment specified
|
||||||
|
@param fileName
|
||||||
|
@param text
|
||||||
|
@param x
|
||||||
|
@param y
|
||||||
|
@param height
|
||||||
|
@param rotation
|
||||||
|
@param colour
|
||||||
|
@param xScale=1
|
||||||
|
*/
|
||||||
|
void Createdxf::drawText(
|
||||||
|
const QString& fileName,
|
||||||
|
const QString& text,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
double height,
|
||||||
|
double rotation,
|
||||||
|
int colour,
|
||||||
|
double xScale)
|
||||||
|
{
|
||||||
|
if (!fileName.isEmpty()) {
|
||||||
|
QFile file(fileName);
|
||||||
|
if (!file.open(QFile::Append)) {
|
||||||
|
// error message
|
||||||
|
QMessageBox errorFileOpen;
|
||||||
|
errorFileOpen.setText("Error: File "+fileName+" was not written correctly.");
|
||||||
|
errorFileOpen.setInformativeText("Close all Files and Re-Run");
|
||||||
|
errorFileOpen.exec();
|
||||||
|
} else {
|
||||||
|
QTextStream To_Dxf(&file);
|
||||||
|
// Draw the circle
|
||||||
|
To_Dxf << 0 << "\r\n";
|
||||||
|
To_Dxf << "TEXT" << "\r\n";
|
||||||
|
To_Dxf << 8 << "\r\n";
|
||||||
|
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||||
|
To_Dxf << 62 << "\r\n";
|
||||||
|
To_Dxf << colour << "\r\n"; // Colour Code
|
||||||
|
To_Dxf << 10 << "\r\n"; // XYZ
|
||||||
|
To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates
|
||||||
|
To_Dxf << 20 << "\r\n";
|
||||||
|
To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates
|
||||||
|
To_Dxf << 30 << "\r\n";
|
||||||
|
To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates
|
||||||
|
To_Dxf << 40 << "\r\n";
|
||||||
|
To_Dxf << height << "\r\n"; // Text Height
|
||||||
|
To_Dxf << 41 << "\r\n";
|
||||||
|
To_Dxf << xScale << "\r\n"; // X Scale
|
||||||
|
To_Dxf << 1 << "\r\n";
|
||||||
|
To_Dxf << text << "\r\n"; // Text Value
|
||||||
|
To_Dxf << 50 << "\r\n";
|
||||||
|
To_Dxf << rotation << "\r\n"; // Text Rotation
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
/**
|
/**
|
||||||
@brief Createdxf::drawText
|
@brief Createdxf::drawText
|
||||||
draw simple text in dxf format without any alignment specified
|
draw simple text in dxf format without any alignment specified
|
||||||
@@ -883,6 +941,7 @@ void Createdxf::drawText(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* draw aligned text in DXF Format */
|
/* draw aligned text in DXF Format */
|
||||||
// leftAlign flag added. If the alignment requested is 'fit to width' and the text length is very small,
|
// leftAlign flag added. If the alignment requested is 'fit to width' and the text length is very small,
|
||||||
|
|||||||
@@ -101,7 +101,8 @@ class Createdxf
|
|||||||
double,double,
|
double,double,
|
||||||
double,
|
double,
|
||||||
double,
|
double,
|
||||||
int);
|
int,
|
||||||
|
double xScale=1.0);
|
||||||
static void drawTextAligned(
|
static void drawTextAligned(
|
||||||
const QString& fileName,
|
const QString& fileName,
|
||||||
const QString& text,
|
const QString& text,
|
||||||
|
|||||||
@@ -515,28 +515,25 @@ void ExportDialog::generateDxf(
|
|||||||
qreal x = elem_pos_x + text->pos().x();
|
qreal x = elem_pos_x + text->pos().x();
|
||||||
qreal y = elem_pos_y + text->pos().y();
|
qreal y = elem_pos_y + text->pos().y();
|
||||||
x *= Createdxf::xScale;
|
x *= Createdxf::xScale;
|
||||||
y = Createdxf::sheetHeight - (y * Createdxf::yScale);// - fontSize;
|
y = Createdxf::sheetHeight - (y * Createdxf::yScale);
|
||||||
|
|
||||||
|
qreal angle = text -> rotation() + rotation_angle;
|
||||||
|
qreal angler = angle * M_PI/180;
|
||||||
|
int xdir = -sin(angler);
|
||||||
|
int ydir = -cos(angler);
|
||||||
|
|
||||||
QPointF transformed_point = rotation_transformed(x, y, hotspot_x, hotspot_y, rotation_angle);
|
QPointF transformed_point = rotation_transformed(x, y, hotspot_x, hotspot_y, rotation_angle);
|
||||||
x = transformed_point.x();
|
x = transformed_point.x() - ydir * fontSize * 0.5;
|
||||||
y = transformed_point.y();
|
y = transformed_point.y() + xdir * fontSize * 0.5;
|
||||||
QStringList lines = text->text().split('\n');
|
QStringList lines = text->text().split('\n');
|
||||||
y += (fontSize/2) * (lines.count()-1);
|
qreal offset = fontSize * 1.6;
|
||||||
for (QString line : lines)
|
for (QString line : lines)
|
||||||
{
|
{
|
||||||
qreal angle = 360 - (text->rotation() + rotation_angle);
|
|
||||||
if (line.size() > 0 && line != "_" ) {
|
if (line.size() > 0 && line != "_" ) {
|
||||||
Createdxf::drawText(file_path, line, x, y, fontSize, angle, 0);
|
Createdxf::drawText(file_path, line, x, y, fontSize, 360 - angle, 0, 0.72);
|
||||||
}
|
}
|
||||||
angle += 1080;
|
x += offset * xdir;
|
||||||
// coordinates for next line
|
y += offset * ydir;
|
||||||
if (int(angle) % 360 == 0) // no rotation
|
|
||||||
y -= fontSize*1.06;
|
|
||||||
else if (int(angle - 180) % 360 == 0) // 180 degrees rotation
|
|
||||||
y += fontSize*1.06;
|
|
||||||
else if (int(angle - 270) % 360 == 0) // 270 degrees rotation
|
|
||||||
x -= fontSize*1.06;
|
|
||||||
else // ((angle - 90) % 360 == 0) 90 degrees rotation
|
|
||||||
x += fontSize*1.06;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -640,24 +637,27 @@ void ExportDialog::generateDxf(
|
|||||||
qreal angler = angle * M_PI/180;
|
qreal angler = angle * M_PI/180;
|
||||||
int xdir = -sin(angler);
|
int xdir = -sin(angler);
|
||||||
int ydir = -cos(angler);
|
int ydir = -cos(angler);
|
||||||
qreal x = (cond->pos().x() + textItem -> pos().x()) * Createdxf::xScale + fontSize;
|
|
||||||
qreal y = Createdxf::sheetHeight - ((cond->pos().y() + textItem -> pos().y()) * Createdxf::yScale) - fontSize;
|
|
||||||
QStringList lines = textItem->toPlainText().split('\n');
|
|
||||||
qreal offset = fontSize * 1.3;
|
|
||||||
foreach (QString line, lines) {
|
|
||||||
|
|
||||||
|
qreal x = (cond->pos().x() + textItem -> pos().x()) * Createdxf::xScale
|
||||||
|
+ xdir * fontSize * 1.8
|
||||||
|
- ydir * fontSize;
|
||||||
|
qreal y = Createdxf::sheetHeight - ((cond->pos().y() + textItem -> pos().y()) * Createdxf::yScale)
|
||||||
|
+ ydir * fontSize * 1.8
|
||||||
|
+ xdir * fontSize * 0.9;
|
||||||
|
QStringList lines = textItem->toPlainText().split('\n');
|
||||||
|
qreal offset = fontSize * 1.6;
|
||||||
|
foreach (QString line, lines) {
|
||||||
|
if (line.size() > 0 && line != "_" )
|
||||||
|
Createdxf::drawText(file_path, line, x, y, fontSize, 360-angle, 0, 0.72 );
|
||||||
x += offset * xdir;
|
x += offset * xdir;
|
||||||
y += offset * ydir;
|
y += offset * ydir;
|
||||||
|
|
||||||
if (line.size() > 0 && line != "_" )
|
|
||||||
Createdxf::drawText(file_path, line, x, y, fontSize, 360-angle, 0 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Draw the junctions
|
// Draw the junctions
|
||||||
QList<QPointF> junctions_list = cond->junctions();
|
QList<QPointF> junctions_list = cond->junctions();
|
||||||
if (!junctions_list.isEmpty()) {
|
if (!junctions_list.isEmpty()) {
|
||||||
foreach(QPointF point, junctions_list) {
|
foreach(QPointF point, junctions_list) {
|
||||||
Createdxf::drawEllipse(file_path,QRectF(point.x() - 1.5, point.y() - 1.5, 3.0, 3.0),0);
|
Createdxf::drawEllipse(file_path,QRectF(cond->pos().x() + point.x() - 1.5, cond->pos().y() + point.y() - 1.5, 3.0, 3.0),0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -668,24 +668,23 @@ void ExportDialog::generateDxf(
|
|||||||
if (fontSize < 0)
|
if (fontSize < 0)
|
||||||
fontSize = dti -> font().pixelSize();
|
fontSize = dti -> font().pixelSize();
|
||||||
fontSize *= Createdxf::yScale;
|
fontSize *= Createdxf::yScale;
|
||||||
qreal x = (dti->scenePos().x()) * Createdxf::xScale;
|
qreal angle = dti -> rotation();
|
||||||
qreal y = Createdxf::sheetHeight - (dti->scenePos().y() * Createdxf::yScale) - fontSize*2; //1.05;
|
qreal angler = angle * M_PI/180;
|
||||||
|
int xdir = -sin(angler);
|
||||||
|
int ydir = -cos(angler);
|
||||||
|
qreal x = (dti->scenePos().x()) * Createdxf::xScale
|
||||||
|
+ xdir * fontSize * 1.8
|
||||||
|
- ydir * fontSize;
|
||||||
|
qreal y = Createdxf::sheetHeight - (dti->scenePos().y() * Createdxf::yScale)
|
||||||
|
+ ydir * fontSize * 1.8
|
||||||
|
+ xdir * fontSize * 0.9;
|
||||||
QStringList lines = dti -> toPlainText().split('\n');
|
QStringList lines = dti -> toPlainText().split('\n');
|
||||||
|
qreal offset = fontSize * 1.6;
|
||||||
foreach (QString line, lines) {
|
foreach (QString line, lines) {
|
||||||
qreal angle = 360 - (dti -> rotation());
|
|
||||||
if (line.size() > 0 && line != "_" )
|
if (line.size() > 0 && line != "_" )
|
||||||
Createdxf::drawText(file_path, line, x, y, fontSize, angle, 0);
|
Createdxf::drawText(file_path, line, x, y, fontSize, 360-angle, 0, 0.72 );
|
||||||
|
x += offset * xdir;
|
||||||
angle += 1080;
|
y += offset * ydir;
|
||||||
// coordinates for next line
|
|
||||||
if (int(angle) % 360 == 0) // no rotation
|
|
||||||
y -= fontSize*1.06;
|
|
||||||
else if (int(angle - 180) % 360 == 0) // 180 degrees rotation
|
|
||||||
y += fontSize*1.06;
|
|
||||||
else if (int(angle - 270) % 360 == 0) // 270 degrees rotation
|
|
||||||
x -= fontSize*1.06;
|
|
||||||
else // ((angle - 90) % 360 == 0) 90 degrees rotation
|
|
||||||
x += fontSize*1.06;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Createdxf::dxfEnd(file_path);
|
Createdxf::dxfEnd(file_path);
|
||||||
|
|||||||
Reference in New Issue
Block a user