Added Sample and Import AsciiFile plugin, fully functional

This commit is contained in:
Rallaz
2011-05-04 19:55:23 +02:00
parent 41a2393223
commit 5d21fb7bb9
10 changed files with 1226 additions and 1 deletions

3
.gitignore vendored
View File

@ -13,4 +13,5 @@ Makefile
qmake_image_collection.cpp
librecad.pro.user
*.qch
*.qhc
*.qhc
plugins.pro.user

6
plugins/README.plugins Normal file
View File

@ -0,0 +1,6 @@
First build Librecad, then goto plugins directory
qmake
make
If you want to create a plugin copy directory sample, rename and modify it (or write from scratch).
edit plugins.pro add the directory name in SUBDIRS

643
plugins/asciifile/asciifile.cpp Executable file
View File

@ -0,0 +1,643 @@
#include <QtPlugin>
#include <QPicture>
#include <QPainter>
#include <QMouseEvent>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFormLayout>
#include <QPushButton>
#include <QFileDialog>
#include <QSettings>
#include <math.h>
#include <QMessageBox>
#include "document_interface.h"
#include "asciifile.h"
QString AsciiFile::menu() const
{
return ("File/Import");
}
QString AsciiFile::name() const
{
return (tr("Read ascii points"));
}
void AsciiFile::execComm(Document_Interface *doc,
QWidget *parent)
{
dibPunto pdt(parent);
int result = pdt.exec();
if (result == QDialog::Accepted)
pdt.procesFile(doc);
}
#define POINT 12
imgLabel::imgLabel(QWidget * parent, Qt::WindowFlags f) :
QLabel(parent, f)
{
posimage = new QPicture;
posimage->setBoundingRect(QRect(0,0,POINT*8,POINT*8));
currPos = DPT::N;
drawImage();
setPicture(*posimage);
}
void imgLabel::drawImage()
{
int a1, a2, a3, a4;
int b1, b2, b3, b4;
QPainter painter;
painter.begin(posimage);
painter.fillRect ( 0, 0, POINT*8,POINT*8, Qt::black );
a1 = POINT*1.75;
a2 = POINT*3.5;
a3 = POINT*5.25;
a4 = POINT*6;
painter.fillRect ( a1, a1, POINT, POINT, Qt::white );//NO
painter.fillRect ( a2, POINT, POINT, POINT, Qt::white );//N
painter.fillRect ( POINT, a2, POINT, POINT, Qt::white );//O
painter.fillRect ( a3, a1, POINT, POINT, Qt::white );//NE
painter.fillRect ( a1, a3, POINT, POINT, Qt::white );//SO
painter.fillRect ( a3, a3, POINT, POINT, Qt::white );//SE
painter.fillRect ( a4, a2, POINT, POINT, Qt::white );//E
painter.fillRect ( a2, a4, POINT, POINT, Qt::white );//S
painter.setPen ( Qt::white );
b1 = POINT*3.2;
b2 = POINT*3.6;
b3 = POINT*4;
b4 = POINT*4.4;
painter.drawLine ( b2, b2, b4, b2 );
painter.drawLine ( b2, b2, b2, b4 );
painter.drawLine ( b4, b2, b4, b4 );
painter.drawLine ( b2, b4, b4, b4 );
b4 = POINT*4.8;
painter.drawLine ( b1, b3, b4, b3 );
painter.drawLine ( b3, b1, b3, b4 );
switch (currPos) {
case DPT::NO:
a2 = a1 = POINT*1.75;
break;
case DPT::O:
a1 = POINT;
a2 = POINT*3.5;
break;
case DPT::NE:
a1 = POINT*5.25;
a2 = POINT*1.75;
break;
case DPT::SO:
a1 = POINT*1.75;
a2 = POINT*5.25;
break;
case DPT::SE:
a2 = a1 = POINT*5.25;
break;
case DPT::E:
a1 = POINT*6;
a2 = POINT*3.5;
break;
case DPT::S:
a1 = POINT*3.5;
a2 = POINT*6;
break;
default: //N
a1 = POINT*3.5;
a2 = POINT;
}
painter.fillRect ( a1, a2, POINT, POINT, Qt::red );
painter.end();
update ();
}
void imgLabel::changePos(int x, int y)
{
if (x < POINT*3.1) {
if (y < POINT*3.1) { setPos(DPT::NO); }
else if (y < POINT*4.9) { setPos(DPT::O); }
else { setPos(DPT::SO); }
} else if (x < POINT*4.9) {
if (y < POINT*4) { setPos(DPT::N); }
else { setPos(DPT::S); }
} else {
if (y < POINT*3.1) { setPos(DPT::NE); }
else if (y < POINT*4.9) { setPos(DPT::E); }
else { setPos(DPT::SE); }
}
}
void imgLabel::setPos(DPT::txtposition pos)
{
currPos = pos;
drawImage();
}
void imgLabel::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
changePos(event->x(), event->y());
} else {
QLabel::mousePressEvent(event);
}
}
/*****************************/
pointBox::pointBox(const QString & title, const QString & label, QWidget * parent ) :
QGroupBox(title, parent)
{
rb = new QRadioButton(label);
vbox = new QVBoxLayout;
vbox->addWidget(rb);
QLabel *but = new QLabel(tr("Layer:"));
layedit = new QLineEdit();
QHBoxLayout *lolayer = new QHBoxLayout;
lolayer->addWidget(but);
lolayer->addWidget(layedit);
vbox->addLayout(lolayer);
setLayout(vbox);
}
void pointBox::setInLayout(QLayout *lo)
{
vbox->addLayout(lo);
}
pointBox::~pointBox()
{
}
/*****************************/
textBox::textBox(const QString & title, const QString & label, QWidget * parent) :
pointBox(title, label, parent)
{
combostyle = new QComboBox();
QStringList txtstyles;
txtstyles << "txt" << "simplex" << "romans";
combostyle->addItems(txtstyles);
QDoubleValidator *val = new QDoubleValidator(0);
val->setBottom ( 0.0 );
heightedit = new QLineEdit();
heightedit->setValidator(val);
sepedit = new QLineEdit();
sepedit->setValidator(val);
QFormLayout *flo = new QFormLayout;
flo->addRow( tr("Style:"), combostyle);
flo->addRow( tr("Heigth:"), heightedit);
flo->addRow( tr("Separation"), sepedit);
// posimage.fill(Qt::black);
img = new imgLabel();
QHBoxLayout *loimage = new QHBoxLayout;
loimage->addLayout(flo);
loimage->addWidget(img);
setInLayout(loimage);
}
textBox::~textBox()
{
}
/*****************************/
dibPunto::dibPunto(QWidget *parent) : QDialog(parent)
{
// setParent(parent);
QStringList txtformats;
QGridLayout *mainLayout = new QGridLayout;
//readSettings();
QPushButton *filebut = new QPushButton(tr("File..."));
fileedit = new QLineEdit();
QHBoxLayout *lofile = new QHBoxLayout;
lofile->addWidget(filebut);
lofile->addWidget(fileedit);
mainLayout->addLayout(lofile, 0, 0);
QLabel *formatlabel = new QLabel(tr("Format:"));
formatedit = new QComboBox();
txtformats << tr("Space Separator") << tr("Tab Separator") << tr("Comma Separator") << tr("*.odb for Psion 2");
formatedit->addItems(txtformats);
QHBoxLayout *loformat = new QHBoxLayout;
loformat->addWidget(formatlabel);
loformat->addWidget(formatedit);
mainLayout->addLayout(loformat, 0, 1);
pt2d = new pointBox(tr("2D Point"),tr("Draw 2D Point"));
pt3d = new pointBox(tr("3D Point"),tr("Draw 3D Point"));
ptnumber = new textBox(tr("Point Number"),tr("Draw point number"));
ptelev = new textBox(tr("Point Elevation"),tr("Draw point elevation"));
ptcode = new textBox(tr("Point Code"),tr("Draw point code"));
ptnumber->setPos(DPT::NO);
QVBoxLayout *lo2d3d = new QVBoxLayout;
lo2d3d->addWidget(pt2d);
lo2d3d->addWidget(pt3d);
mainLayout->addLayout(lo2d3d, 1, 0);
mainLayout->addWidget(ptnumber, 1, 1);
mainLayout->addWidget(ptelev, 2, 0);
mainLayout->addWidget(ptcode, 2, 1);
QHBoxLayout *loaccept = new QHBoxLayout;
QPushButton *acceptbut = new QPushButton(tr("Accept"));
loaccept->addStretch();
loaccept->addWidget(acceptbut);
mainLayout->addLayout(loaccept, 3, 0);
QPushButton *cancelbut = new QPushButton(tr("Cancel"));
QHBoxLayout *locancel = new QHBoxLayout;
locancel->addWidget(cancelbut);
locancel->addStretch();
mainLayout->addLayout(locancel, 3, 1);
setLayout(mainLayout);
readSettings();
connect(cancelbut, SIGNAL(clicked()), this, SLOT(reject()));
connect(acceptbut, SIGNAL(clicked()), this, SLOT(checkAccept()));
connect(filebut, SIGNAL(clicked()), this, SLOT(dptFile()));
}
void dibPunto::checkAccept()
{
errmsg.clear();
if (failGUI(&errmsg)) {
QMessageBox::critical ( this, "Sample plugin", errmsg );
errmsg.clear();
return;
}
writeSettings();
accept();
}
void dibPunto::dptFile()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Select file"));
fileedit->setText(fileName);
}
bool dibPunto::failGUI(QString *msg)
{
if (pt2d->checkOn() == true) {
if (pt2d->getLayer().isEmpty()) {msg->insert(0, tr("Point 2D layer is empty")); return true;}
}
if (pt3d->checkOn() == true) {
if (pt3d->getLayer().isEmpty()) {msg->insert(0, tr("Point 3D layer is empty")); return true;}
}
if (ptelev->checkOn() == true) {
if (ptelev->getLayer().isEmpty()) {msg->insert(0, tr("Point elevation layer is empty")); return true;}
if (ptelev->getHeightStr().isEmpty()) {msg->insert(0, tr("Point elevation height is empty")); return true;}
if (ptelev->getSeparationStr().isEmpty()) {msg->insert(0, tr("Point elevation separation is empty")); return true;}
}
if (ptnumber->checkOn() == true) {
if (ptnumber->getLayer().isEmpty()) {msg->insert(0, tr("Point number layer is empty")); return true;}
if (ptnumber->getHeightStr().isEmpty()) {msg->insert(0, tr("Point number height is empty")); return true;}
if (ptnumber->getSeparationStr().isEmpty()) {msg->insert(0, tr("Point number separation is empty")); return true;}
}
if (ptcode->checkOn() == true) {
if (ptcode->getLayer().isEmpty()) {msg->insert(0, tr("Point code layer is empty")); return true;}
if (ptcode->getHeightStr().isEmpty()) {msg->insert(0, tr("Point code height is empty")); return true;}
if (ptcode->getSeparationStr().isEmpty()) {msg->insert(0, tr("Point code separation is empty")); return true;}
}
return false;
}
void dibPunto::procesFile(Document_Interface *doc)
{
QString sep;
QMessageBox::information(this, "Info", "dibpunto procesFile");
currDoc = doc;
//Warning, can change ading or reordering "formatedit"
switch (formatedit->currentIndex()) {
case 0:
sep = " ";
break;
case 2:
sep = ",";
break;
default:
sep = "\t";
}
if (!QFile::exists(fileedit->text()) ) {
QMessageBox::critical ( this, "DibPunto", QString(tr("The file %1 not exist")).arg(fileedit->text()) );
return;
}
QFile infile(fileedit->text());
if (!infile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::critical ( this, "DibPunto", QString(tr("Can't open the file %1")).arg(fileedit->text()) );
return;
}
//Warning, can change ading or reordering "formatedit"
if (formatedit->currentIndex() == 3)
procesfileODB(&infile, sep);
else
procesfileNormal(&infile, sep);
infile.close ();
QString currlay = currDoc->getCurrentLayer();
if (pt2d->checkOn() == true)
draw2D();
if (pt3d->checkOn() == true)
draw3D();
if (ptelev->checkOn() == true)
drawElev();
if (ptnumber->checkOn() == true)
drawNumber();
if (ptcode->checkOn() == true)
drawCode();
currDoc->setLayer(currlay);
currDoc = NULL;
}
void dibPunto::draw2D()
{
QPointF pt;
currDoc->setLayer(pt2d->getLayer());
for (int i = 0; i < dataList.size(); ++i) {
pointData *pd = dataList.at(i);
if (!pd->x.isEmpty() && !pd->y.isEmpty()){
pt.setX(pd->x.toDouble());
pt.setY(pd->y.toDouble());
currDoc->addPoint(&pt);
}
}
}
void dibPunto::draw3D()
{
QPointF pt;
currDoc->setLayer(pt3d->getLayer());
for (int i = 0; i < dataList.size(); ++i) {
pointData *pd = dataList.at(i);
if (!pd->x.isEmpty() && !pd->y.isEmpty()){
pt.setX(pd->x.toDouble());
pt.setY(pd->y.toDouble());
/*RLZ:3d support if (pd->z.isEmpty()) pt.setZ(0.0);
else pt.setZ(pd->z.toDouble());*/
currDoc->addPoint(&pt);
}
}
}
void dibPunto::calcPos(DPI::VAlign *v, DPI::HAlign *h, double sep,
double *x, double *y, DPT::txtposition sit)
{
double inc, incx, incy;
DPI::VAlign va;
DPI::HAlign ha;
incx = incy = sep;
inc = sqrt(incx*incx/2);
switch (sit) {
case DPT::NO:
va = DPI::VAlignBottom;
ha = DPI::HAlignRight;
incx = -1.0*inc; incy = inc;
break;
case DPT::O:
va = DPI::VAlignMiddle;
ha = DPI::HAlignRight;
incx = -1.0*incx; incy = 0.0;
break;
case DPT::NE:
va = DPI::VAlignBottom;
ha = DPI::HAlignLeft;
incx = inc; incy = inc;
break;
case DPT::SO:
va = DPI::VAlignTop;
ha = DPI::HAlignRight;
incx = -1.0*inc; incy = -1.0*inc;
break;
case DPT::SE:
va = DPI::VAlignTop;
ha = DPI::HAlignLeft;
incx = inc; incy = -1.0*inc;
break;
case DPT::E:
va = DPI::VAlignMiddle;
ha = DPI::HAlignLeft;
incy = 0.0;
break;
case DPT::S:
va = DPI::VAlignMiddle;
ha = DPI::HAlignCenter;
incx = 0.0; incy = -1.0*incy;
break;
default: //N
va = DPI::VAlignBottom;
ha = DPI::HAlignCenter;
incx = 0.0;
}
*x =incx;
*y =incy;
*v =va;
*h =ha;
}
void dibPunto::drawNumber()
{
double incx, incy, newx, newy;
DPI::VAlign va;
DPI::HAlign ha;
calcPos(&va, &ha, ptnumber->getSeparation(),
&incx, &incy, ptnumber->getPosition());
currDoc->setLayer(ptnumber->getLayer());
QString sty = ptnumber->getStyleStr();
for (int i = 0; i < dataList.size(); ++i) {
pointData *pd = dataList.at(i);
if (!pd->x.isEmpty() && !pd->y.isEmpty() && !pd->number.isEmpty()){
newx = pd->x.toDouble() + incx;
newy = pd->y.toDouble() + incy;
QPointF pt(newx,newy);
currDoc->addText(pd->number, sty, &pt, ptnumber->getHeightStr().toDouble(), 0.0, ha, va);
}
}
}
void dibPunto::drawElev()
{
double incx, incy, newx, newy;
DPI::VAlign va;
DPI::HAlign ha;
calcPos(&va, &ha, ptelev->getSeparation(),
&incx, &incy, ptelev->getPosition());
currDoc->setLayer(ptelev->getLayer());
QString sty = ptelev->getStyleStr();
for (int i = 0; i < dataList.size(); ++i) {
pointData *pd = dataList.at(i);
if (!pd->x.isEmpty() && !pd->x.isEmpty() && !pd->z.isEmpty()){
newx = pd->x.toDouble() + incx;
newy = pd->y.toDouble() + incy;
QPointF pt(newx,newy);
currDoc->addText(pd->z, sty, &pt, ptelev->getHeightStr().toDouble(), 0.0, ha, va);
}
}
}
void dibPunto::drawCode()
{
double incx, incy, newx, newy;
DPI::VAlign va;
DPI::HAlign ha;
calcPos(&va, &ha, ptcode->getSeparation(),
&incx, &incy, ptcode->getPosition());
currDoc->setLayer(ptcode->getLayer());
QString sty = ptcode->getStyleStr();
for (int i = 0; i < dataList.size(); ++i) {
pointData *pd = dataList.at(i);
if (!pd->x.isEmpty() && !pd->x.isEmpty() && !pd->code.isEmpty()){
newx = pd->x.toDouble() + incx;
newy = pd->y.toDouble() + incy;
QPointF pt(newx,newy);
currDoc->addText(pd->code, sty, &pt, ptcode->getHeightStr().toDouble(), 0.0, ha, va);
}
}
}
void dibPunto::procesfileODB(QFile* file, QString sep)
{
QStringList data;
pointData *pd;
while (!file->atEnd()) {
QString line = file->readLine();
line.remove ( line.size()-2, 1);
data = line.split(sep);
pd = new pointData;
int i = 0;
int j = data.size();
if (i<j && data.at(i).compare("4")==0 ){
i = i+2;
if (i<j) pd->x = data.at(i); else pd->x = QString();
i++;
if (i<j) pd->y = data.at(i); else pd->y = QString();
i++;
if (i<j) pd->z = data.at(i); else pd->z = QString();
i++;
if (i<j) pd->number = data.at(i); else pd->number = QString();
i++;
if (i<j) pd->code = data.at(i); else pd->code = QString();
}
dataList.append(pd);
}
}
void dibPunto::procesfileNormal(QFile* file, QString sep)
{
// QString outname, sep;
QStringList data;
pointData *pd;
while (!file->atEnd()) {
QString line = file->readLine();
line.remove ( line.size()-1, 1);
data = line.split(sep);
pd = new pointData;
int i = 0;
int j = data.size();
if (i<j) pd->number = data.at(i); else pd->number = QString ();
i++;
if (i<j) pd->x = data.at(i); else pd->x = QString();
i++;
if (i<j) pd->y = data.at(i); else pd->y = QString();
i++;
if (i<j) pd->z = data.at(i); else pd->z = QString();
i++;
if (i<j) pd->code = data.at(i); else pd->code = QString ();
dataList.append(pd);
}
}
dibPunto::~dibPunto()
{
while (!dataList.isEmpty())
delete dataList.takeFirst();
}
void dibPunto::readSettings()
{
QString str;
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "LibreCAD", "asciifile");
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
QSize size = settings.value("size", QSize(500,300)).toSize();
str = settings.value("lastfile").toString();
fileedit->setText(str);
formatedit->setCurrentIndex( settings.value("format", 0).toInt() );
pt2d->setCheck( settings.value("draw2d", false).toBool() );
str = settings.value("layer2d").toString();
pt2d->setLayer(str);
pt3d->setCheck( settings.value("draw3d", false).toBool() );
str = settings.value("layer3d").toString();
pt3d->setLayer(str);
ptelev->setCheck( settings.value("drawelev", false).toBool() );
str = settings.value("layerelev").toString();
ptelev->setLayer(str);
ptnumber->setCheck( settings.value("drawnumber", false).toBool() );
str = settings.value("layernumber").toString();
ptnumber->setLayer(str);
ptcode->setCheck( settings.value("drawcode", false).toBool() );
str = settings.value("layercode").toString();
ptcode->setLayer(str);
ptelev->setStyleIdx( settings.value("styleelev", 0).toInt() );
ptnumber->setStyleIdx( settings.value("stylenumber", 0).toInt() );
ptcode->setStyleIdx(settings.value("stylecode", 0).toInt() );
ptelev->setHeight( settings.value("heightelev", 0.5).toDouble() );
ptnumber->setHeight( settings.value("heightnumber", 0.5).toDouble() );
ptcode->setHeight( settings.value("heightcode", 0.5).toDouble() );
ptelev->setSeparation( settings.value("separationelev", 0.3).toDouble() );
ptnumber->setSeparation( settings.value("separationnumber", 0.3).toDouble() );
ptcode->setSeparation( settings.value("separationcode", 0.3).toDouble() );
ptelev->setPosition( static_cast<DPT::txtposition>( settings.value("positionelev", DPT::S).toInt() ) );
ptnumber->setPosition( static_cast<DPT::txtposition>( settings.value("positionnumber", DPT::N).toInt() ) );
ptcode->setPosition( static_cast<DPT::txtposition>( settings.value("positioncode", DPT::E).toInt() ) );
resize(size);
move(pos);
}
void dibPunto::writeSettings()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "LibreCAD", "asciifile");
settings.setValue("pos", pos());
settings.setValue("size", size());
settings.setValue("lastfile", fileedit->text());
settings.setValue("format", formatedit->currentIndex());
settings.setValue("draw2d", pt2d->checkOn());
settings.setValue("draw3d", pt3d->checkOn());
settings.setValue("drawelev", ptelev->checkOn());
settings.setValue("drawnumber", ptnumber->checkOn());
settings.setValue("drawcode", ptcode->checkOn());
settings.setValue("layer2d", pt2d->getLayer());
settings.setValue("layer3d", pt3d->getLayer());
settings.setValue("layerelev", ptelev->getLayer());
settings.setValue("layernumber", ptnumber->getLayer());
settings.setValue("layercode", ptcode->getLayer());
settings.setValue("styleelev", ptelev->getStyleIdx());
settings.setValue("stylenumber", ptnumber->getStyleIdx());
settings.setValue("stylecode", ptcode->getStyleIdx());
settings.setValue("heightelev", ptelev->getHeightStr());
settings.setValue("heightnumber", ptnumber->getHeightStr());
settings.setValue("heightcode", ptcode->getHeightStr());
settings.setValue("separationelev", ptelev->getSeparationStr());
settings.setValue("separationnumber", ptnumber->getSeparationStr());
settings.setValue("separationcode", ptcode->getSeparationStr());
settings.setValue("positionelev", ptelev->getPosition());
settings.setValue("positionnumber", ptnumber->getPosition());
settings.setValue("positioncode", ptcode->getPosition());
}
Q_EXPORT_PLUGIN2(asciifile, AsciiFile);

173
plugins/asciifile/asciifile.h Executable file
View File

@ -0,0 +1,173 @@
/*****************************************************************************/
/* DibPunto - Conversor de ascii a dxf */
/* */
/* Copyright (C) 2011 Rallaz, rallazz@gmail.com */
/* */
/* This library is free software, licensed under the terms of the GNU */
/* General Public License as published by the Free Software Foundation, */
/* either version 3 of the License, or (at your option) any later version. */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/*****************************************************************************/
#ifndef DRAWPOINTS_H
#define DRAWPOINTS_H
#include <QWidget>
#include <QFile>
#include <QLabel>
#include <QGroupBox>
#include <QRadioButton>
#include <QLineEdit>
#include <QComboBox>
#include <QDialog>
#include "qc_plugininterface.h"
#include "document_interface.h"
class pointBox;
class textBox;
class pointData;
class QVBoxLayout;
class AsciiFile : public QObject, QC_PluginInterface
{
Q_OBJECT
Q_INTERFACES(QC_PluginInterface)
public:
virtual QString menu() const;
virtual QString name() const;
virtual void execComm(Document_Interface *doc,
QWidget *parent);
};
namespace DPT {
enum txtposition {N, S, E, O, NE, SE, SO, NO};
}
class dibPunto : public QDialog
{
Q_OBJECT
public:
explicit dibPunto(QWidget *parent = 0);
~dibPunto();
void SetupUI(QWidget *parent);
public slots:
void dptFile();
void procesFile(Document_Interface *doc);
void checkAccept();
private:
void readSettings();
void writeSettings();
void procesfileODB(QFile* file, QString sep);
void procesfileNormal(QFile* file, QString sep);
void draw2D();
void draw3D();
void drawNumber();
void drawElev();
void drawCode();
bool failGUI(QString *msg);
void calcPos(DPI::VAlign *v, DPI::HAlign *h, double sep,
double *x, double *y, DPT::txtposition sit);
private:
QString errmsg;
pointBox *pt2d;
pointBox *pt3d;
textBox *ptnumber;
textBox *ptelev;
textBox *ptcode;
QLineEdit *fileedit;
QComboBox *formatedit;
QList<pointData*> dataList;
Document_Interface *currDoc;
};
class imgLabel : public QLabel
{
Q_OBJECT
public:
imgLabel(QWidget * parent = 0, Qt::WindowFlags f = 0 );
~imgLabel(){}
void setPos(DPT::txtposition pos = DPT::N);
DPT::txtposition getPos() { return currPos;}
protected:
void mouseReleaseEvent(QMouseEvent *event);
private:
void drawImage();
void changePos(int x, int y);
private:
QPicture *posimage;
DPT::txtposition currPos;
};
/***********/
class pointBox : public QGroupBox
{
Q_OBJECT
public:
pointBox(const QString & title, const QString & label, QWidget * parent = 0 );
~pointBox();
void setInLayout(QLayout *lo);
bool checkOn() { return rb->isChecked();}
void setCheck(bool val) { rb->setChecked(val);}
QString getLayer() { return layedit->text();}
void setLayer(QString l) { layedit->setText(l);}
private:
QRadioButton *rb;
QLineEdit *layedit;
QVBoxLayout *vbox;
};
/***********/
class textBox : public pointBox
{
Q_OBJECT
public:
textBox(const QString & title, const QString & label, QWidget * parent = 0 );
~textBox();
void setPos(DPT::txtposition p) { img->setPos(p); }
QString getStyleStr() { return combostyle->currentText();}
void setStyleIdx(int idx) { combostyle->setCurrentIndex(idx);}
int getStyleIdx() { return combostyle->currentIndex();}
void setHeight(double data) { heightedit->setText( QString::number(data,'f'));}
// double getHeight();
QString getHeightStr() { return heightedit->text();}
double getHeight() { return heightedit->text().toDouble();}
void setSeparation(double data) { sepedit->setText( QString::number(data,'f'));}
QString getSeparationStr() { return sepedit->text();}
double getSeparation() { return sepedit->text().toDouble();}
void setPosition(DPT::txtposition p) { img->setPos(p);}
DPT::txtposition getPosition() { return img->getPos();}
private:
QComboBox *combostyle;
QLineEdit *heightedit;
QLineEdit *sepedit;
imgLabel *img;
};
/***********/
class pointData
{
public:
QString number;
QString x;
QString y;
QString z;
QString code;
};
/***********/
#endif // ECHOPLUG_H

37
plugins/asciifile/asciifile.pro Executable file
View File

@ -0,0 +1,37 @@
#-------------------------------------------------
#
# Project created by QtCreator 2011-03-22T19:33:11
#
#-------------------------------------------------
QT += gui
TEMPLATE = lib
CONFIG += plugin
VERSION = 1.0.0
win32 {
debug {
TARGET = ../../debug/resources/plugins/asciifile
} else {
TARGET = ../../release/resources/plugins/asciifile
}
}
unix {
TARGET = ../../unix/resources/plugins/asciifile
}
INCLUDEPATH += ../../src/plugins
# Store intermedia stuff somewhere else
OBJECTS_DIR = ../intermediate/obj
MOC_DIR = ../intermediate/moc
RCC_DIR = ../intermediate/rcc
TS_DIR = ../intermediate/ts
UI_DIR = ../intermediate/ui
UI_HERADERS_DIR = ../intermediate/ui
UI_SOURCES_DIR = ../intermediate/ui
SOURCES += asciifile.cpp
HEADERS += asciifile.h

View File

@ -0,0 +1,46 @@
101 100.0000 100.0000 3.5000 E-1
1 96.7489 115.7626 4.7843
2 97.8836 114.1813 3.8585
3 96.0069 109.1310 3.3841
4 93.2663 109.1474 2.7956
5 93.5579 109.4581 3.4924
6 91.9150 117.4389 3.5442
7 89.6679 107.2924 1.8785
8 89.7550 102.4185 1.8601
9 86.9725 100.1201 0.9824
10 86.7972 109.4477 1.6099
11 95.4141 83.9169 0.5911
12 97.0318 86.7990 1.0882
13 98.1628 89.1308 1.5648
14 99.7478 93.4150 2.4087
15 101.0426 96.4195 2.9927
16 102.3991 97.1479 3.1881
17 101.7184 97.8495 3.2503
18 98.5573 97.1676 2.8797
19 96.9225 102.6942 3.0276
20 98.8866 111.4297 3.8100
21 105.0832 103.9690 4.7065
22 111.8276 104.0788 5.2617
23 102.9928 103.0377 3.8572
24 109.0816 95.0818 4.6732
25 109.8411 92.9588 4.0459
26 106.4783 92.9087 3.4394
27 102.8864 93.6489 2.9843
28 115.0306 87.5107 4.0234
29 119.2955 82.5127 3.3044
102 108.9816 87.1408 2.9063 E-2
30 109.8670 87.5096 2.9551
31 110.0912 81.4451 2.1972
32 120.3599 73.3924 2.3200
33 120.3354 69.1418 1.8899
34 118.2818 68.7667 0.9380
35 106.2704 75.3276 1.0458
36 101.8516 75.2145 0.4556
37 105.8550 77.8586 1.1454
38 107.5263 80.2858 1.9919
39 106.1929 82.7569 2.1709
40 95.1114 80.9960 0.3350
41 97.8808 85.2507 1.0078
42 99.3784 88.1488 1.5959
43 102.9824 82.7499 2.0633
44 103.5828 82.4412 2.0641

44
plugins/plugins.pro Normal file
View File

@ -0,0 +1,44 @@
#-------------------------------------------------
#
# Project created by QtCreator 2011-03-22T19:33:11
#
#-------------------------------------------------
TEMPLATE = subdirs
TARGET = plugins
QT += gui
SUBDIRS = \
asciifile \
sample
TRANSLATIONS =
# Store intermedia stuff somewhere else
OBJECTS_DIR = intermediate/obj
MOC_DIR = intermediate/moc
RCC_DIR = intermediate/rcc
TS_DIR = intermediate/ts
UI_DIR = intermediate/ui
UI_HERADERS_DIR = intermediate/ui
UI_SOURCES_DIR = intermediate/ui
# install
INSTALLDIR = ../unix/resources/plugins
win32 {
INSTALLDIR = ../release/resources/plugins
}
unix {
INSTALLDIR = ../unix/resources/plugins
}
docu.files = license.txt tetrapod.3dq data.3dq
docu.path = $$DOCUDIR
target.path = $$INSTALLDIR
sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugins.pro README.plugins
sources.path = $$INSTALLDIR/tools/recad
INSTALLS += target sources

174
plugins/sample/sample.cpp Executable file
View File

@ -0,0 +1,174 @@
/*****************************************************************************/
/* sample.cpp - plugin example for LibreCAD */
/* */
/* Copyright (C) 2011 Rallaz, rallazz@gmail.com */
/* */
/* This library is free software, licensed under the terms of the GNU */
/* General Public License as published by the Free Software Foundation, */
/* either version 3 of the License, or (at your option) any later version. */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/*****************************************************************************/
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QSettings>
#include <QMessageBox>
#include <QDoubleValidator>
#include "document_interface.h"
#include "sample.h"
QString LC_Sample::name() const
{
return (tr("Sample plugin"));
}
QString LC_Sample::menu() const
{
return ("Help");
}
void LC_Sample::execComm(Document_Interface *doc,
QWidget *parent)
{
Q_UNUSED(doc);
lc_Sampledlg pdt(parent);
int result = pdt.exec();
if (result == QDialog::Accepted)
pdt.procesAction(doc);
}
/*****************************/
lc_Sampledlg::lc_Sampledlg(QWidget *parent) : QDialog(parent)
{
setWindowTitle(tr("Draw line"));
QLabel *label;
QDoubleValidator *val = new QDoubleValidator(0);
QGridLayout *mainLayout = new QGridLayout;
label = new QLabel(tr("Start X:"));
mainLayout->addWidget(label, 0, 0);
startxedit = new QLineEdit();
startxedit->setValidator(val);
mainLayout->addWidget(startxedit, 1, 0);
label = new QLabel(tr("Start Y:"));
mainLayout->addWidget(label, 0, 1);
startyedit = new QLineEdit();
startyedit->setValidator(val);
mainLayout->addWidget(startyedit, 1, 1);
label = new QLabel(tr("End X:"));
mainLayout->addWidget(label, 2, 0);
endxedit = new QLineEdit();
endxedit->setValidator(val);
mainLayout->addWidget(endxedit, 3, 0);
label = new QLabel(tr("End Y:"));
mainLayout->addWidget(label, 2, 1);
endyedit = new QLineEdit();
endyedit->setValidator(val);
mainLayout->addWidget(endyedit, 3, 1);
QHBoxLayout *loaccept = new QHBoxLayout;
QPushButton *acceptbut = new QPushButton(tr("Accept"));
loaccept->addStretch();
loaccept->addWidget(acceptbut);
mainLayout->addLayout(loaccept, 4, 0);
QPushButton *cancelbut = new QPushButton(tr("Cancel"));
QHBoxLayout *locancel = new QHBoxLayout;
locancel->addWidget(cancelbut);
locancel->addStretch();
mainLayout->addLayout(locancel, 4, 1);
setLayout(mainLayout);
readSettings();
connect(cancelbut, SIGNAL(clicked()), this, SLOT(reject()));
connect(acceptbut, SIGNAL(clicked()), this, SLOT(checkAccept()));
}
bool lc_Sampledlg::failGUI(QString *msg)
{
if (startxedit->text().isEmpty()) {msg->insert(0, tr("Start X is empty")); return true;}
if (startyedit->text().isEmpty()) {msg->insert(0, tr("Start Y is empty")); return true;}
if (endxedit->text().isEmpty()) {msg->insert(0, tr("End X is empty")); return true;}
if (endyedit->text().isEmpty()) {msg->insert(0, tr("End Y is empty")); return true;}
return false;
}
void lc_Sampledlg::procesAction(Document_Interface *doc)
{
Q_UNUSED(doc);
QPointF start, end;
start.setX(startxedit->text().toDouble());
start.setY(startyedit->text().toDouble());
end.setX(endxedit->text().toDouble());
end.setY(endyedit->text().toDouble());
doc->addLine(&start, &end);
}
void lc_Sampledlg::checkAccept()
{
errmsg.clear();
if (failGUI(&errmsg)) {
QMessageBox::critical ( this, "Sample plugin", errmsg );
errmsg.clear();
return;
}
accept();
}
lc_Sampledlg::~lc_Sampledlg()
{
}
void lc_Sampledlg::closeEvent(QCloseEvent *event)
{
writeSettings();
QWidget::closeEvent(event);
}
void lc_Sampledlg::readSettings()
{
QString str;
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "LibreCAD", "sample_plugin");
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
QSize size = settings.value("size", QSize(430,140)).toSize();
startxedit->setText( settings.value("startx", 0.5).toString() );
startyedit->setText( settings.value("starty", 0.5).toString() );
endxedit->setText( settings.value("endx", 3.5).toString() );
endyedit->setText( settings.value("endy", 3.5).toString() );
resize(size);
move(pos);
}
void lc_Sampledlg::writeSettings()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "LibreCAD", "sample_plugin");
settings.setValue("pos", pos());
settings.setValue("size", size());
settings.setValue("startx", startxedit->text());
settings.setValue("starty", startyedit->text());
settings.setValue("endx", endxedit->text());
settings.setValue("endy", endyedit->text());
}
Q_EXPORT_PLUGIN2(lc_sample, LC_Sample);

61
plugins/sample/sample.h Executable file
View File

@ -0,0 +1,61 @@
/*****************************************************************************/
/* sample.h - plugin example for LibreCAD */
/* */
/* Copyright (C) 2011 Rallaz, rallazz@gmail.com */
/* */
/* This library is free software, licensed under the terms of the GNU */
/* General Public License as published by the Free Software Foundation, */
/* either version 3 of the License, or (at your option) any later version. */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/*****************************************************************************/
#ifndef SAMPLE_H
#define SAMPLE_H
#include "qc_plugininterface.h"
#include <QDialog>
class QLineEdit;
class LC_Sample : public QObject, QC_PluginInterface
{
Q_OBJECT
Q_INTERFACES(QC_PluginInterface)
public:
virtual QString menu() const;
virtual QString name() const;
virtual void execComm(Document_Interface *doc,
QWidget *parent);
};
class lc_Sampledlg : public QDialog
{
Q_OBJECT
public:
explicit lc_Sampledlg(QWidget *parent = 0);
~lc_Sampledlg();
public slots:
// void procesAction(QStringList *commandList);
void procesAction(Document_Interface *doc);
void checkAccept();
protected:
void closeEvent(QCloseEvent *event);
private:
void readSettings();
void writeSettings();
bool failGUI(QString *msg);
private:
QString errmsg;
QLineEdit *startxedit;
QLineEdit *startyedit;
QLineEdit *endxedit;
QLineEdit *endyedit;
};
#endif // SAMPLE_H

40
plugins/sample/sample.pro Executable file
View File

@ -0,0 +1,40 @@
#-------------------------------------------------
#
# Project created by QtCreator 2011-03-22T19:33:11
#
#-------------------------------------------------
QT += gui
TEMPLATE = lib
CONFIG += plugin
VERSION = 1.0.1
# DLLDESTDIR = ../../unix/resources/plugins/
win32 {
debug {
TARGET = ../../debug/resources/plugins/sample
} else {
TARGET = ../../release/resources/plugins/sample
}
}
unix {
TARGET = ../../unix/resources/plugins/sample
}
INCLUDEPATH += ../../src/plugins
# Store intermedia stuff somewhere else
OBJECTS_DIR = ../intermediate/obj
MOC_DIR = ../intermediate/moc
RCC_DIR = ../intermediate/rcc
TS_DIR = ../intermediate/ts
UI_DIR = ../intermediate/ui
UI_HERADERS_DIR = ../intermediate/ui
UI_SOURCES_DIR = ../intermediate/ui
#DEFINES += sample_LIBRARY
SOURCES += sample.cpp
HEADERS += sample.h