mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
DXF - Add Polylines, use for conductors and rectangles
This commit is contained in:
@@ -650,92 +650,18 @@ void Createdxf::drawRectangle (
|
|||||||
double height,
|
double height,
|
||||||
const int &colour)
|
const int &colour)
|
||||||
{
|
{
|
||||||
if (!fileName.isEmpty()) {
|
QRectF rect(x1,y1,width,height);
|
||||||
QFile file(fileName);
|
QPolygonF poly(rect);
|
||||||
if (!file.open(QFile::Append)) {
|
drawPolyline(fileName,poly,colour,true);
|
||||||
// error message
|
}
|
||||||
QMessageBox errorFileOpen;
|
|
||||||
errorFileOpen.setText("Error: File "+fileName+" was not written correctly.");
|
static QRectF scaleRect(QRectF rect)
|
||||||
errorFileOpen.setInformativeText("Close all Files and Re-Run");
|
{
|
||||||
errorFileOpen.exec();
|
QRectF ro(rect.bottomLeft().x() * Createdxf::xScale,
|
||||||
} else {
|
Createdxf::sheetHeight - (rect.bottomLeft().y() * Createdxf::yScale),
|
||||||
QTextStream To_Dxf(&file);
|
rect.width() * Createdxf::xScale,
|
||||||
// Draw the Rectangle
|
rect.height() * Createdxf::yScale);
|
||||||
To_Dxf << 0 << "\r\n";
|
return ro;
|
||||||
To_Dxf << "LINE" << "\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";
|
|
||||||
To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 20 << "\r\n";
|
|
||||||
To_Dxf << y1 << "\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 << 11 << "\r\n";
|
|
||||||
To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 21 << "\r\n";
|
|
||||||
To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 31 << "\r\n";
|
|
||||||
To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 0 << "\r\n";
|
|
||||||
To_Dxf << "LINE" << "\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";
|
|
||||||
To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 20 << "\r\n";
|
|
||||||
To_Dxf << y1 << "\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 << 11 << "\r\n";
|
|
||||||
To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 21 << "\r\n";
|
|
||||||
To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 31 << "\r\n";
|
|
||||||
To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 0 << "\r\n";
|
|
||||||
To_Dxf << "LINE" << "\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";
|
|
||||||
To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 20 << "\r\n";
|
|
||||||
To_Dxf << y1 << "\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 << 11 << "\r\n";
|
|
||||||
To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 21 << "\r\n";
|
|
||||||
To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 31 << "\r\n";
|
|
||||||
To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 0 << "\r\n";
|
|
||||||
To_Dxf << "LINE" << "\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";
|
|
||||||
To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 20 << "\r\n";
|
|
||||||
To_Dxf << y1+height << "\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 << 11 << "\r\n";
|
|
||||||
To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 21 << "\r\n";
|
|
||||||
To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates
|
|
||||||
To_Dxf << 31 << "\r\n";
|
|
||||||
To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -749,13 +675,8 @@ void Createdxf::drawRectangle(
|
|||||||
const QString &filepath,
|
const QString &filepath,
|
||||||
const QRectF &rect,
|
const QRectF &rect,
|
||||||
const int &colorcode) {
|
const int &colorcode) {
|
||||||
drawRectangle(
|
QPolygonF poly(scaleRect(rect));
|
||||||
filepath,
|
drawPolyline(filepath,poly,colorcode);
|
||||||
rect.bottomLeft().x() * xScale,
|
|
||||||
sheetHeight - (rect.bottomLeft().y() * yScale),
|
|
||||||
rect.width() * xScale,
|
|
||||||
rect.height() * yScale,
|
|
||||||
colorcode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -770,17 +691,7 @@ void Createdxf::drawPolygon(
|
|||||||
const QPolygonF &poly,
|
const QPolygonF &poly,
|
||||||
const int &colorcode)
|
const int &colorcode)
|
||||||
{
|
{
|
||||||
int lc = 0;
|
drawPolyline(filepath,poly,colorcode);
|
||||||
QPointF plast;
|
|
||||||
foreach(QPointF p, poly)
|
|
||||||
{
|
|
||||||
if(lc++)
|
|
||||||
{
|
|
||||||
QLineF ql(plast,p);
|
|
||||||
drawLine(filepath,ql,colorcode);
|
|
||||||
}
|
|
||||||
plast = p;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@brief Createdxf::drawArc
|
@brief Createdxf::drawArc
|
||||||
@@ -893,61 +804,6 @@ void Createdxf::drawText(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
/**
|
|
||||||
@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
|
|
||||||
*/
|
|
||||||
void Createdxf::drawText(
|
|
||||||
const QString& fileName,
|
|
||||||
const QString& text,
|
|
||||||
double x,
|
|
||||||
double y,
|
|
||||||
double height,
|
|
||||||
double rotation,
|
|
||||||
int colour)
|
|
||||||
{
|
|
||||||
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 << 1 << "\r\n";
|
|
||||||
To_Dxf << text << "\r\n"; // Text Value
|
|
||||||
To_Dxf << 50 << "\r\n";
|
|
||||||
To_Dxf << rotation << "\r\n"; // Text Rotation
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#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,
|
||||||
@@ -1033,3 +889,75 @@ void Createdxf::drawTextAligned(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
@brief Createdxf::drawPolyline
|
||||||
|
Convenience function for draw polyline
|
||||||
|
@param filepath
|
||||||
|
@param poly
|
||||||
|
@param colorcode
|
||||||
|
*/
|
||||||
|
void Createdxf::drawPolyline(const QString &filepath,
|
||||||
|
const QPolygonF &poly,
|
||||||
|
const int &colorcode, bool preScaled)
|
||||||
|
{
|
||||||
|
qreal x,y;
|
||||||
|
if (!filepath.isEmpty()) {
|
||||||
|
QFile file(filepath);
|
||||||
|
if (!file.open(QFile::Append)) {
|
||||||
|
// error message
|
||||||
|
QMessageBox errorFileOpen;
|
||||||
|
errorFileOpen.setText("Error: File "+filepath+" was not written correctly.");
|
||||||
|
errorFileOpen.setInformativeText("Close all Files and Re-Run");
|
||||||
|
errorFileOpen.exec();
|
||||||
|
} else {
|
||||||
|
QTextStream To_Dxf(&file);
|
||||||
|
// Draw the Line
|
||||||
|
To_Dxf << 0 << "\r\n";
|
||||||
|
To_Dxf << "POLYLINE" << "\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 << colorcode << "\r\n"; // Colour Code
|
||||||
|
To_Dxf << 66 << "\r\n";
|
||||||
|
To_Dxf << 1 << "\r\n";
|
||||||
|
To_Dxf << 70 << "\r\n";
|
||||||
|
To_Dxf << 8 << "\r\n";
|
||||||
|
To_Dxf << 10 << "\r\n";
|
||||||
|
To_Dxf << 0 << "\r\n";
|
||||||
|
To_Dxf << 20 << "\r\n";
|
||||||
|
To_Dxf << 0 << "\r\n";
|
||||||
|
To_Dxf << 30 << "\r\n";
|
||||||
|
To_Dxf << 0 << "\r\n";
|
||||||
|
foreach(QPointF p, poly)
|
||||||
|
{
|
||||||
|
if(preScaled) {
|
||||||
|
x = p.x();
|
||||||
|
y = p.y();
|
||||||
|
} else {
|
||||||
|
x = p.x() * xScale;
|
||||||
|
y = sheetHeight - (p.y() * yScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
To_Dxf << 0 << "\r\n";
|
||||||
|
To_Dxf << "VERTEX" << "\r\n";
|
||||||
|
To_Dxf << 8 << "\r\n";
|
||||||
|
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||||
|
To_Dxf << 70 << "\r\n";
|
||||||
|
To_Dxf << 32 << "\r\n";
|
||||||
|
To_Dxf << 10 << "\r\n";
|
||||||
|
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 << 0 << "\r\n";
|
||||||
|
To_Dxf << "SEQEND" << "\r\n";
|
||||||
|
To_Dxf << 8 << "\r\n";
|
||||||
|
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -117,6 +117,11 @@ class Createdxf
|
|||||||
double xScale,
|
double xScale,
|
||||||
int colour);
|
int colour);
|
||||||
|
|
||||||
|
static void drawPolyline(
|
||||||
|
const QString &filepath,
|
||||||
|
const QPolygonF &poly,
|
||||||
|
const int &colorcode,
|
||||||
|
bool preScaled = false);
|
||||||
|
|
||||||
static int getcolorCode (
|
static int getcolorCode (
|
||||||
const long red,
|
const long red,
|
||||||
|
|||||||
@@ -639,9 +639,17 @@ void ExportDialog::generateDxf(
|
|||||||
|
|
||||||
//Draw conductors
|
//Draw conductors
|
||||||
foreach(Conductor *cond, list_conductors) {
|
foreach(Conductor *cond, list_conductors) {
|
||||||
|
QPolygonF poly;
|
||||||
|
bool firstseg = true;
|
||||||
foreach(ConductorSegment *segment, cond -> segmentsList()) {
|
foreach(ConductorSegment *segment, cond -> segmentsList()) {
|
||||||
Createdxf::drawLine(file_path,QLineF(cond->pos()+segment->firstPoint(),cond->pos()+segment->secondPoint()),0);
|
//Createdxf::drawLine(file_path,QLineF(cond->pos()+segment->firstPoint(),cond->pos()+segment->secondPoint()),0);
|
||||||
|
if(firstseg){
|
||||||
|
poly << cond->pos()+segment->firstPoint();
|
||||||
|
firstseg = false;
|
||||||
|
}
|
||||||
|
poly << cond->pos()+segment->secondPoint();
|
||||||
}
|
}
|
||||||
|
Createdxf::drawPolyline(file_path,poly,0);
|
||||||
//Draw conductor text item
|
//Draw conductor text item
|
||||||
ConductorTextItem *textItem = cond -> textItem();
|
ConductorTextItem *textItem = cond -> textItem();
|
||||||
if (textItem) {
|
if (textItem) {
|
||||||
|
|||||||
@@ -657,7 +657,7 @@ bool QetGraphicsTableItem::toDXF(const QString &filepath)
|
|||||||
//QRectF rect = boundingRect();
|
//QRectF rect = boundingRect();
|
||||||
QRectF rect(0,0, m_header_item->rect().width(), m_current_size.height());
|
QRectF rect(0,0, m_header_item->rect().width(), m_current_size.height());
|
||||||
QPolygonF poly(rect);
|
QPolygonF poly(rect);
|
||||||
Createdxf::drawPolygon(filepath,mapToScene(poly),0);
|
Createdxf::drawPolygon(filepath,mapToScene(poly),0);
|
||||||
|
|
||||||
//Draw vertical lines
|
//Draw vertical lines
|
||||||
auto offset= 0;
|
auto offset= 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user