mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Add import dxf feature
Use dxf2elmt to import dxf. See https://github.com/antonioaja/dxf2elmt
This commit is contained in:
parent
2a7848e1ca
commit
6e81451b46
@ -159,7 +159,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \
|
|||||||
$$files(sources/print/*.h) \
|
$$files(sources/print/*.h) \
|
||||||
$$files(sources/TerminalStrip/*.h) \
|
$$files(sources/TerminalStrip/*.h) \
|
||||||
$$files(sources/TerminalStrip/ui/*.h) \
|
$$files(sources/TerminalStrip/ui/*.h) \
|
||||||
$$files(sources/TerminalStrip/UndoCommand/*.h)
|
$$files(sources/TerminalStrip/UndoCommand/*.h) \
|
||||||
|
$$files(sources/dxf/*.h)
|
||||||
|
|
||||||
SOURCES += $$files(sources/*.cpp) \
|
SOURCES += $$files(sources/*.cpp) \
|
||||||
$$files(sources/editor/*.cpp) \
|
$$files(sources/editor/*.cpp) \
|
||||||
@ -195,7 +196,8 @@ SOURCES += $$files(sources/*.cpp) \
|
|||||||
$$files(sources/print/*.cpp) \
|
$$files(sources/print/*.cpp) \
|
||||||
$$files(sources/TerminalStrip/*.cpp) \
|
$$files(sources/TerminalStrip/*.cpp) \
|
||||||
$$files(sources/TerminalStrip/ui/*.cpp) \
|
$$files(sources/TerminalStrip/ui/*.cpp) \
|
||||||
$$files(sources/TerminalStrip/UndoCommand/*.cpp)
|
$$files(sources/TerminalStrip/UndoCommand/*.cpp) \
|
||||||
|
$$files(sources/dxf/*.cpp)
|
||||||
|
|
||||||
# Needed for use promote QTreeWidget in terminalstripeditor.ui
|
# Needed for use promote QTreeWidget in terminalstripeditor.ui
|
||||||
INCLUDEPATH += sources/TerminalStrip/ui
|
INCLUDEPATH += sources/TerminalStrip/ui
|
||||||
|
102
sources/dxf/dxftoelmt.cpp
Normal file
102
sources/dxf/dxftoelmt.cpp
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2022 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/>.
|
||||||
|
*/
|
||||||
|
#include "dxftoelmt.h"
|
||||||
|
#include "../ui/thirdpartybinaryinstalldialog.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief dxftoElmt
|
||||||
|
* Return the dxf at @a file_path converted to elmt.
|
||||||
|
* The returned value is a QByteArray, instead of a
|
||||||
|
* QDomDocument or QString, to let user do what they want with that.
|
||||||
|
* @param file_path
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
QByteArray dxfToElmt(const QString &file_path)
|
||||||
|
{
|
||||||
|
if (!dxf2ElmtIsPresent(false)) {
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
QProcess process_;
|
||||||
|
const QString program{dxf2ElmtBinaryPath()};
|
||||||
|
const QStringList arguments{file_path, QStringLiteral("-v")};
|
||||||
|
|
||||||
|
process_.start(program, arguments);
|
||||||
|
process_.waitForFinished();
|
||||||
|
|
||||||
|
const auto byte_array{process_.readAll()};
|
||||||
|
process_.close();
|
||||||
|
return byte_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString dxf2ElmtDirPath()
|
||||||
|
{
|
||||||
|
#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
|
||||||
|
return (QDir::homePath() + QStringLiteral("/Application Data/qet/binary"));
|
||||||
|
#elif defined(Q_OS_MAC)
|
||||||
|
return (QDir::homePath() + QStringLiteral("/.qet/binary"));
|
||||||
|
#else
|
||||||
|
return (QDir::homePath() + QStringLiteral("/.qet/binary"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief dxf2ElmtBinaryPath
|
||||||
|
* @return the path to the dxf2elmt program
|
||||||
|
*/
|
||||||
|
QString dxf2ElmtBinaryPath()
|
||||||
|
{
|
||||||
|
#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
|
||||||
|
return dxf2ElmtDirPath() + QStringLiteral("/dxf2elmt.exe");
|
||||||
|
#elif defined(Q_OS_MAC)
|
||||||
|
return dxf2ElmtDirPath() + QStringLiteral("/dxf2elmt.app");
|
||||||
|
#else
|
||||||
|
return dxf2ElmtDirPath() + QStringLiteral("/dxf2elmt");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief dxf2ElmtIsPresent
|
||||||
|
* Return true if dxf2elmt is present in the system
|
||||||
|
* @param install_dialog
|
||||||
|
* True to display a dialog with the explanations
|
||||||
|
* of how to install the dxf2elmt program
|
||||||
|
* if not present in the system.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool dxf2ElmtIsPresent(bool install_dialog, QWidget *parent)
|
||||||
|
{
|
||||||
|
const bool exist{QFile::exists(dxf2ElmtBinaryPath())};
|
||||||
|
if (!exist && install_dialog)
|
||||||
|
{
|
||||||
|
auto string_{QStringLiteral("L'import dxf nécessite le logiciel dxf2elmt. \n"
|
||||||
|
"Veuillez télécharger celui-ci en suivant le lien ci dessous et le dézipper dans le dossier d'installation")};
|
||||||
|
|
||||||
|
ThirdPartyBinaryInstallDialog dialog_(string_,
|
||||||
|
QStringLiteral("https://github.com/antonioaja/dxf2elmt/releases"),
|
||||||
|
dxf2ElmtDirPath(),
|
||||||
|
parent);
|
||||||
|
dialog_.exec();
|
||||||
|
}
|
||||||
|
return exist;
|
||||||
|
}
|
30
sources/dxf/dxftoelmt.h
Normal file
30
sources/dxf/dxftoelmt.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2022 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 DXFTOELMT_H
|
||||||
|
#define DXFTOELMT_H
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
|
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
|
QByteArray dxfToElmt(const QString &file_path);
|
||||||
|
QString dxf2ElmtDirPath();
|
||||||
|
QString dxf2ElmtBinaryPath();
|
||||||
|
bool dxf2ElmtIsPresent(bool install_dialog = true, QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
#endif // DXFTOELMT_H
|
@ -46,6 +46,7 @@
|
|||||||
#include "dynamictextfieldeditor.h"
|
#include "dynamictextfieldeditor.h"
|
||||||
#include "../../newelementwizard.h"
|
#include "../../newelementwizard.h"
|
||||||
#include "../editorcommands.h"
|
#include "../editorcommands.h"
|
||||||
|
#include "../../dxf/dxftoelmt.h"
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QActionGroup>
|
#include <QActionGroup>
|
||||||
@ -1490,3 +1491,31 @@ void QETElementEditor::on_m_donate_action_triggered() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QETElementEditor::on_m_about_qt_action_triggered() { qApp->aboutQt(); }
|
void QETElementEditor::on_m_about_qt_action_triggered() { qApp->aboutQt(); }
|
||||||
|
|
||||||
|
void QETElementEditor::on_m_import_dxf_triggered()
|
||||||
|
{
|
||||||
|
if (dxf2ElmtIsPresent(true, this))
|
||||||
|
{
|
||||||
|
QString file_path{QFileDialog::getOpenFileName(this,
|
||||||
|
QObject::tr("Importer un fichier dxf"),
|
||||||
|
"/home",
|
||||||
|
"DXF (*.dxf)")};
|
||||||
|
if (file_path.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox::information(this, tr("Avertissement"), tr("L'import d'un dxf volumineux peut prendre du temps \n"
|
||||||
|
"veuillez patienter durant l'import..."));
|
||||||
|
|
||||||
|
const QByteArray array_{dxfToElmt(file_path)};
|
||||||
|
if (array_.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QDomDocument xml_;
|
||||||
|
xml_.setContent(array_);
|
||||||
|
|
||||||
|
m_elmt_scene->fromXml(xml_);
|
||||||
|
fillPartsList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -110,6 +110,7 @@ class QETElementEditor : public QMainWindow
|
|||||||
void on_m_youtube_action_triggered();
|
void on_m_youtube_action_triggered();
|
||||||
void on_m_donate_action_triggered();
|
void on_m_donate_action_triggered();
|
||||||
void on_m_about_qt_action_triggered();
|
void on_m_about_qt_action_triggered();
|
||||||
|
void on_m_import_dxf_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool canClose();
|
bool canClose();
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
<addaction name="m_new_action"/>
|
<addaction name="m_new_action"/>
|
||||||
<addaction name="m_open_action"/>
|
<addaction name="m_open_action"/>
|
||||||
<addaction name="m_open_from_file_action"/>
|
<addaction name="m_open_from_file_action"/>
|
||||||
|
<addaction name="m_import_dxf"/>
|
||||||
<addaction name="m_open_dxf_action"/>
|
<addaction name="m_open_dxf_action"/>
|
||||||
<addaction name="m_save_action"/>
|
<addaction name="m_save_action"/>
|
||||||
<addaction name="m_save_as_action"/>
|
<addaction name="m_save_as_action"/>
|
||||||
@ -501,6 +502,15 @@
|
|||||||
<string>Space</string>
|
<string>Space</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="m_import_dxf">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/run-dxf.png</normaloff>:/ico/16x16/run-dxf.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Importer un dxf</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../../qelectrotech.qrc"/>
|
<include location="../../../qelectrotech.qrc"/>
|
||||||
|
51
sources/ui/thirdpartybinaryinstalldialog.cpp
Normal file
51
sources/ui/thirdpartybinaryinstalldialog.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2022 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/>.
|
||||||
|
*/
|
||||||
|
#include "thirdpartybinaryinstalldialog.h"
|
||||||
|
#include "ui_thirdpartybinaryinstalldialog.h"
|
||||||
|
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
ThirdPartyBinaryInstallDialog::ThirdPartyBinaryInstallDialog(const QString &text,
|
||||||
|
const QString &downloadLink,
|
||||||
|
const QString &binaryFolderPath,
|
||||||
|
QWidget *parent) :
|
||||||
|
QDialog{parent},
|
||||||
|
ui{new Ui::ThirdPartyBinaryInstallDialog}
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
ui->m_label->setText(text);
|
||||||
|
|
||||||
|
connect(ui->m_download_pb, &QPushButton::clicked, [downloadLink](){
|
||||||
|
QDesktopServices::openUrl(QUrl(downloadLink));
|
||||||
|
});
|
||||||
|
connect(ui->m_install_dir_pb, &QPushButton::clicked, [binaryFolderPath]() {
|
||||||
|
//Make sure the path exist
|
||||||
|
QDir dir_;
|
||||||
|
dir_.mkpath(binaryFolderPath);
|
||||||
|
QDesktopServices::openUrl(QUrl("file:///" + binaryFolderPath));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ThirdPartyBinaryInstallDialog::~ThirdPartyBinaryInstallDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
42
sources/ui/thirdpartybinaryinstalldialog.h
Normal file
42
sources/ui/thirdpartybinaryinstalldialog.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2022 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 THIRDPARTYBINARYINSTALLDIALOG_H
|
||||||
|
#define THIRDPARTYBINARYINSTALLDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class ThirdPartyBinaryInstallDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ThirdPartyBinaryInstallDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ThirdPartyBinaryInstallDialog(const QString &text,
|
||||||
|
const QString &downloadLink,
|
||||||
|
const QString &binaryFolderPath,
|
||||||
|
QWidget *parent = nullptr);
|
||||||
|
~ThirdPartyBinaryInstallDialog();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::ThirdPartyBinaryInstallDialog *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // THIRDPARTYBINARYINSTALLDIALOG_H
|
104
sources/ui/thirdpartybinaryinstalldialog.ui
Normal file
104
sources/ui/thirdpartybinaryinstalldialog.ui
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ThirdPartyBinaryInstallDialog</class>
|
||||||
|
<widget class="QDialog" name="ThirdPartyBinaryInstallDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>373</width>
|
||||||
|
<height>64</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Logiciel tiers requis</string>
|
||||||
|
</property>
|
||||||
|
<property name="modal">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QDialogButtonBox" name="m_button_box">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QPushButton" name="m_download_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Télechargement</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/edit-download.png</normaloff>:/ico/16x16/edit-download.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QPushButton" name="m_install_dir_pb">
|
||||||
|
<property name="text">
|
||||||
|
<string>Dossier installation</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/folder-open.png</normaloff>:/ico/16x16/folder-open.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" colspan="3">
|
||||||
|
<widget class="QLabel" name="m_label">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
|
<property name="margin">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="../../qelectrotech.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>m_button_box</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>ThirdPartyBinaryInstallDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>m_button_box</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>ThirdPartyBinaryInstallDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
Loading…
x
Reference in New Issue
Block a user