diff --git a/cmake/qet_compilation_vars.cmake b/cmake/qet_compilation_vars.cmake index 8230965b1..d7f9cbe06 100644 --- a/cmake/qet_compilation_vars.cmake +++ b/cmake/qet_compilation_vars.cmake @@ -258,6 +258,9 @@ set(QET_SRC_FILES ${QET_DIR}/sources/dxf/dxftoelmt.cpp ${QET_DIR}/sources/dxf/dxftoelmt.h + ${QET_DIR}/sources/qet_elementscaler/qet_elementscaler.cpp + ${QET_DIR}/sources/qet_elementscaler/qet_elementscaler.h + ${QET_DIR}/sources/editor/arceditor.cpp ${QET_DIR}/sources/editor/arceditor.h ${QET_DIR}/sources/editor/editorcommands.cpp diff --git a/lang/qet_de.qm b/lang/qet_de.qm index 9361741ee..a6e6e3199 100644 Binary files a/lang/qet_de.qm and b/lang/qet_de.qm differ diff --git a/lang/qet_de.ts b/lang/qet_de.ts index 5dbb0831f..ec5d8e7f3 100644 --- a/lang/qet_de.ts +++ b/lang/qet_de.ts @@ -6808,47 +6808,47 @@ Verfügbare Optionen: QETElementEditor - + &Nouveau &Neu - + &Ouvrir &Öffnen - + &Ouvrir depuis un fichier Aus &Datei öffnen - + &Lancer le plugin convertisseur DXF DXF Konverter-&Plugin ausführen - + &Enregistrer &Speichern - + Enregistrer sous Speichern &unter - + Enregistrer dans un fichier In einer Datei speichern - + Recharger Neu laden - + Tout sélectionner Alles auswählen @@ -6858,187 +6858,192 @@ Verfügbare Optionen: QElectroTech - Bauteileditor - + &Aide &Hilfe - + Annulations Arbeitsschritte - + Parties Bestandteile - + Informations Informationen - + Outils Werkzeuge - + Affichage Anzeige - + Élément Bauteil - + Annulation Rückgängig: - + &Fermer cet éditeur &Editor schließen - + Fermer cet éditeur Editor schließen - + Désélectionner tout Auswahl aufheben - + Co&uper &Ausschneiden - + Cop&ier Kop&ieren - + C&oller E&infügen - + C&oller dans la zone In einen Bereich einfügen... - + Un fichier einer Datei - + Un élément einem Bauteil - + À &propos de QElectroTech Ü&ber QElectroTech - + Affiche des informations sur QElectroTech Informationen zu QElectroTech anzeigen - + Manuel en ligne Online-Dokumentation (englisch) - + Lance le navigateur par défaut vers le manuel en ligne de QElectroTech Online-Dokumentation von QElectroTech im Standard Webbrowser öffnen - + Chaine Youtube Youtube-Kanal - + Lance le navigateur par défaut vers la chaine Youtube de QElectroTech Den Youtube-Kanal von QElectroTech im Standard Webbrowser öffnen - + Soutenir le projet par un don QElectroTech durch eine Spende unterstützen - + Soutenir le projet QElectroTech par un don Das QElectroTech-Projekt durch eine Spende unterstützen - + À propos de &Qt Über &Qt - + Affiche des informations sur la bibliothèque Qt Informationen zur Qt-Bibliothek anzeigen - + Rotation Drehen - + Space - + Importer un dxf DXF &importieren - + + importer un élément à redimensionner + Importiere skaliertes Element + + + Inverser la sélection Auswahl umkehren - + &Supprimer &Löschen - + Zoom avant Vergrößern - + Zoom arrière Verkleinern - + Zoom adapté Folie einpassen - + Pas de zoom Kein Zoom - + Éditer les informations sur l'auteur Informationen über Autoren bearbeiten @@ -7078,23 +7083,23 @@ Verfügbare Optionen: Anschluss einfügen - + Annuler Rückgängig - + Afficher menu entry Werkzeugsleisten anzeigen - + Trop de primitives, liste non générée: %1 Zu viele Einzelteile, Liste nicht generiert: %1 - + To install the plugin DXFtoQET Visit https://download.qelectrotech.org/qet/builds/dxf_to_elmt/ @@ -7104,7 +7109,7 @@ Put DXFtoQET.exe binary on C:\Users\user_name\AppData\Roaming\qet\ directory - + To install the plugin DXFtoQET Visit https://download.qelectrotech.org/qet/builds/dxf_to_elmt/ @@ -7114,7 +7119,7 @@ Put DXFtoQET.app binary on /Users/user_name/.qet/ directory - + To install the plugin DXFtoQET Visit https://download.qelectrotech.org/qet/builds/dxf_to_elmt/ @@ -7125,7 +7130,7 @@ make it executable : chmod +x ./DXFtoQET - + To install the plugin DXFtoQET Visit https://download.qelectrotech.org/qet/builds/dxf_to_elmt/ @@ -7141,22 +7146,21 @@ Put DXFtoQET.app binary on /Users/user_name/.qet/ directory - + Refaire Wiederholen - + Ctrl+Shift+O Strg+Umschalt+O - + Ctrl+Shift+S Strg+Umschalt+S - Ctrl+Q Strg+Q @@ -7197,12 +7201,12 @@ Put DXFtoQET.app binary on /Users/user_name/.qet/ directory Strg+0 - + Avertissement Warnung - + L'import d'un dxf volumineux peut prendre du temps veuillez patienter durant l'import... Das Importieren einer großen DXF-Datei kann einige Zeit in Anspruch nehmen. @@ -7230,12 +7234,12 @@ veuillez patienter durant l'import... Tiefe - + Éditer le nom et les traductions de l'élément Bauteilname und Übersetzungen bearbeiten - + Éditer les propriétés de l'élément Bauteileigenschaften bearbeiten @@ -7250,28 +7254,28 @@ veuillez patienter durant l'import... &Datei - + &Édition &Bearbeiten - + Afficha&ge &Anzeige - + Coller depuis... Einfügen aus... - + [Modifié] window title tag [geändert] - + [lecture seule] window title tag [schreibgeschützt] @@ -7288,8 +7292,8 @@ veuillez patienter durant l'import... Bauteileditor - - + + %n partie(s) sélectionnée(s). %n ausgewähltes Teil. @@ -7297,18 +7301,18 @@ veuillez patienter durant l'import... - + Absence de borne warning title Anschluss nicht vorhanden - + Absence de borne Anschluss nicht vorhanden - + <br>En l'absence de borne, l'élément ne pourra être relié à d'autres éléments par l'intermédiaire de conducteurs. warning description <br>Ohne Anschlüsse kann das Bauteil nicht mit anderen Bauteilen mittels Leiter verbunden werden. @@ -7329,18 +7333,18 @@ veuillez patienter durant l'import... Fügt einen Bauteiltext ein, der im Schaltplaneditor bearbeitet werden kann - + <br><b>Erreur</b> :<br>Les reports de folio doivent posséder une seul borne.<br><b>Solution</b> :<br>Verifier que l'élément ne possède qu'une seul borne <br><b>Fehler</b>: <br>Folienverweise dürfen nur einen Anschluss haben.<br><b>Lösung</b>: <br>Prüfen, dass das Bauteil nur einen Anschluss hat - + La vérification de cet élément a généré message box content Die Überprüfung dieses Bauteils generierte - + %n erreur(s) errors @@ -7349,88 +7353,88 @@ veuillez patienter durant l'import... - + et und - + <b>%1</b> : %2 warning title: warning description <b>%1</b>: %2 - + Erreurs Fehler - + Avertissements Warnungen - + Le fichier %1 n'existe pas. message box content Die Datei %1 existiert nicht. - - + + Impossible d'ouvrir le fichier %1. message box content Öffnen der Datei %1 nicht möglich. - - + + Ce fichier n'est pas un document XML valide message box content Diese Datei ist kein gültiges XML-Dokument - - + + Erreur toolbar title Fehler - - + + Édition en lecture seule message box title Schreibgeschützte Bearbeitung - - + + Vous n'avez pas les privilèges nécessaires pour modifier cet élement. Il sera donc ouvert en lecture seule. message box content Sie haben nicht die Schreibrechte, um dieses Bauteil zu verändern: es wird schreibgeschützt geöffnet. - - + + Erreur message box title Fehler - + Impossible d'écrire dans ce fichier message box content Schreiben in diese Datei nicht möglich - + Impossible d'enregistrer l'élément message box content Dieses Bauteil kann nicht gespeichert werden - + %n avertissement(s) warnings @@ -7439,98 +7443,108 @@ veuillez patienter durant l'import... - + Impossible d'ouvrir le fichier message box title Öffnen der Datei nicht möglich - + Il semblerait que le fichier %1 que vous essayez d'ouvrir n'existe pas ou plus. Die zu öffnende Datei %1 existiert nicht. - + Recharger l'élément dialog title Bauteil neu laden - + Vous avez efffectué des modifications sur cet élément. Si vous le rechargez, ces modifications seront perdues. Voulez-vous vraiment recharger l'élément ? dialog content Das Bauteil wurde verändert. Beim neu Laden gehen die Änderungen verloren. Möchten Sie wirklich das Bauteil neu laden? + + + Importer un élément à redimensionner + Importiere Element zum Skalieren + + + + Éléments QElectroTech (*.elmt) + QElectroTech-Bauteil (*.elmt) + - + Echec de l'enregistrement Speichervorgang gescheitert - + L'enregistrement à échoué, les conditions requises ne sont pas valides Speichervorgang gescheitert\nDie erforderlichen Bedingungen wurden nicht erfüllt - + Enregistrer sous dialog title Speichern unter - + Éléments QElectroTech (*.elmt) filetypes allowed when saving an element file QElectroTech-Bauteil (*.elmt) - + Enregistrer l'élément en cours ? dialog title Aktuelles Bauteil speichern? - + Voulez-vous enregistrer l'élément %1 ? dialog content - %1 is an element name Bauteil %1 speichern? - + Ouvrir un fichier dialog title Datei öffnen - + Éléments QElectroTech (*.elmt);;Fichiers XML (*.xml);;Tous les fichiers (*) filetypes allowed when opening an element file QElectroTech-Bauteile (*.elmt);;XML-Dateien (*.xml);;Alle Dateien (*) - - - - + + + + Élément inexistant. message box title Bauteil nicht vorhanden. - - + + L'élément n'existe pas. message box content Bauteil existiert nicht. - - + + Le chemin virtuel choisi ne correspond pas à un élément. message box content Der gewählte virtuelle Pfad passt nicht zu einem Bauteil. @@ -9430,7 +9444,7 @@ Möchten Sie sie ersetzen? Element öffnen - + Importer un fichier dxf DXF-Datei importieren @@ -9439,6 +9453,29 @@ Möchten Sie sie ersetzen? Disposition par défaut Standard-Layout + + + + Entrer le facteur d'échelle + Skalierungsfaktor eingeben + + + + Facteur X: + Faktor X: + + + + Facteur Y: + Faktor Y: + + + + Le logiciel QET_ElementScaler est nécessaire pour mettre les éléments à l'échelle. +Veuillez télécharger celui-ci en suivant le lien ci dessous et le dézipper dans le dossier d'installation + Die Software QET_ElementScaler wird benötigt, um Elemente zu skalieren. +Bitte laden Sie diese über den unten stehenden Link herunter und entpacken Sie sie in den Installationsordner. + QTextOrientationWidget diff --git a/qelectrotech.pro b/qelectrotech.pro index d3cbfcf6d..092f3c6cb 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -166,7 +166,8 @@ HEADERS += $$files(sources/*.h) \ $$files(sources/TerminalStrip/GraphicsItem/*.h) \ $$files(sources/TerminalStrip/GraphicsItem/properties/*.h) \ $$files(sources/xml/*.h) \ - $$files(sources/dxf/*.h) + $$files(sources/dxf/*.h) \ + $$files(sources/qet_elementscaler/*.h) SOURCES += $$files(sources/*.cpp) \ $$files(sources/editor/*.cpp) \ @@ -208,7 +209,8 @@ SOURCES += $$files(sources/*.cpp) \ $$files(sources/TerminalStrip/GraphicsItem/*.cpp) \ $$files(sources/TerminalStrip/GraphicsItem/properties/*.cpp) \ $$files(sources/xml/*.cpp) \ - $$files(sources/dxf/*.cpp) + $$files(sources/dxf/*.cpp) \ + $$files(sources/qet_elementscaler/*.cpp) # Needed for use promote QTreeWidget in terminalstripeditor.ui INCLUDEPATH += sources/TerminalStrip/ui diff --git a/sources/editor/ui/qetelementeditor.cpp b/sources/editor/ui/qetelementeditor.cpp index 2ea93df0f..6fbfd5708 100644 --- a/sources/editor/ui/qetelementeditor.cpp +++ b/sources/editor/ui/qetelementeditor.cpp @@ -47,6 +47,7 @@ #include "../../newelementwizard.h" #include "../editorcommands.h" #include "../../dxf/dxftoelmt.h" +#include "../../qet_elementscaler/qet_elementscaler.h" #include "../UndoCommand/openelmtcommand.h" #include @@ -1332,6 +1333,24 @@ void QETElementEditor::on_m_open_dxf_action_triggered() DXF -> start(program,arguments); } +void QETElementEditor::on_m_open_scaled_element_action_triggered() +{ +#ifdef TODO_LIST +# pragma message("@TODO Merge 'Element-Scaling' code into QET") +# pragma message("https://github.com/plc-user/QET_ElementScaler") +#endif +#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) + QString program = (QDir::homePath() + "/Application Data/qet/QET_ElementScaler.exe"); +#elif defined(Q_OS_MAC) + QString program = (QDir::homePath() + "/.qet/QET_ElementScaler.app"); +#else + QString program = (QDir::homePath() + "/.qet/QET_ElementScaler"); +#endif + QStringList arguments; + QProcess *ES = new QProcess(qApp); + ES -> start(program,arguments); +} + bool QETElementEditor::on_m_save_as_file_action_triggered() { // Check element before writing @@ -1504,7 +1523,7 @@ void QETElementEditor::on_m_import_dxf_triggered() { QString file_path{QFileDialog::getOpenFileName(this, QObject::tr("Importer un fichier dxf"), - "/home", + QDir::homePath(), "DXF (*.dxf)")}; if (file_path.isEmpty()) { return; @@ -1524,3 +1543,26 @@ void QETElementEditor::on_m_import_dxf_triggered() } } +void QETElementEditor::on_m_import_scaled_element_triggered() +{ + if (ElementScalerIsPresent(true, this)) + { + QString file_path{QFileDialog::getOpenFileName(this, + tr("Importer un élément à redimensionner"), + QDir::homePath(), + tr("Éléments QElectroTech (*.elmt)"))}; + if (file_path.isEmpty()) { + return; + } + + const QByteArray array_{ElementScaler(file_path, this)}; + if (array_.isEmpty()) { + return; + } + QDomDocument xml_; + xml_.setContent(array_); + + m_elmt_scene->undoStack().push(new OpenElmtCommand(xml_, m_elmt_scene)); + } +} + diff --git a/sources/editor/ui/qetelementeditor.h b/sources/editor/ui/qetelementeditor.h index b16b204f4..67e657d9b 100644 --- a/sources/editor/ui/qetelementeditor.h +++ b/sources/editor/ui/qetelementeditor.h @@ -87,6 +87,7 @@ class QETElementEditor : public QMainWindow void on_m_open_action_triggered(); void on_m_open_from_file_action_triggered(); void on_m_open_dxf_action_triggered(); + void on_m_open_scaled_element_action_triggered(); bool on_m_save_as_file_action_triggered(); void on_m_reload_action_triggered(); void on_m_quit_action_triggered(); @@ -111,6 +112,7 @@ class QETElementEditor : public QMainWindow void on_m_donate_action_triggered(); void on_m_about_qt_action_triggered(); void on_m_import_dxf_triggered(); + void on_m_import_scaled_element_triggered(); private: bool canClose(); diff --git a/sources/editor/ui/qetelementeditor.ui b/sources/editor/ui/qetelementeditor.ui index ef99d1683..15609cda0 100644 --- a/sources/editor/ui/qetelementeditor.ui +++ b/sources/editor/ui/qetelementeditor.ui @@ -35,6 +35,7 @@ + @@ -514,6 +515,15 @@ Importer un dxf + + + + :/ico/22x22/folder-open.png:/ico/22x22/folder-open.png + + + importer un élément à redimensionner + + diff --git a/sources/qet_elementscaler/qet_elementscaler.cpp b/sources/qet_elementscaler/qet_elementscaler.cpp new file mode 100644 index 000000000..5cba108ef --- /dev/null +++ b/sources/qet_elementscaler/qet_elementscaler.cpp @@ -0,0 +1,132 @@ +/* + Copyright 2024 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 . +*/ +#include "qet_elementscaler.h" +#include "../ui/thirdpartybinaryinstalldialog.h" + +#include +#include +#include +#include + +/** + * @brief QET_ElementScaler + * Return the scaled element from @a file_path. + * The returned value is a QByteArray, instead of a + * QDomDocument or QString, to let user do what he/she wants. + * If something goes wrong the QByteArray returned is empty. + * @param file_path + * @return + */ +QByteArray ElementScaler(const QString &file_path, QWidget *parent) +{ + if (!ElementScalerIsPresent(false)) { + return QByteArray(); + } + + bool ok; + double fx = QInputDialog::getDouble(parent, QObject::tr("Entrer le facteur d'échelle"), + QObject::tr("Facteur X:"), 1.0, 0.1, 100, 5, &ok, + Qt::WindowFlags(), 1); + QString sFactorX = "1.0"; + if (ok) + sFactorX = (QString::number(fx, 'f', 5)); + else + return QByteArray(); + + double fy = QInputDialog::getDouble(parent, QObject::tr("Entrer le facteur d'échelle"), + QObject::tr("Facteur Y:"), fx, 0.1, 100, 5, &ok, + Qt::WindowFlags(), 1); + QString sFactorY = "1.0"; + if (ok) + sFactorY = (QString::number(fy, 'f', 5)); + else + return QByteArray(); + + QProcess process_; + const QString program{ElementScalerBinaryPath()}; + const QStringList arguments{QStringLiteral("-x"), sFactorX, + QStringLiteral("-y"), sFactorY, + QStringLiteral("-o"), QStringLiteral("-f"), file_path}; + + process_.start(program, arguments); + + if (process_.waitForFinished()) + { + const auto byte_array{process_.readAll()}; + process_.close(); + return byte_array; + } + else + { + //If something went wrong we return an empty QByteArray + return QByteArray(); + } +} + +QString ElementScalerDirPath() +{ +#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) + return (QDir::homePath() + QStringLiteral("/Application Data/qet/binary")); +#elif defined(Q_OS_MACOS) + return (QDir::homePath() + QStringLiteral("/.qet/binary")); +#else + return (QDir::homePath() + QStringLiteral("/.qet/binary")); +#endif +} + +/** + * @brief ElementScalerBinaryPath + * @return the path to the QET_ElementScaler program + */ +QString ElementScalerBinaryPath() +{ +#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) + return ElementScalerDirPath() + QStringLiteral("/QET_ElementScaler.exe"); +#elif defined(Q_OS_MACOS) + return ElementScalerDirPath() + QStringLiteral("/./QET_ElementScaler"); +#else + return ElementScalerDirPath() + QStringLiteral("/QET_ElementScaler"); +#endif +} + +/** + * @brief ElementScalerIsPresent + * Return true if QET_ElementScaler is present in the system + * @param install_dialog + * True to display a dialog with the explanations + * of how to install the QET_ElementScaler program + * if not present in the system. + * @return + */ +bool ElementScalerIsPresent(bool install_dialog, QWidget *parent) +{ + const bool exist{QFile::exists(ElementScalerBinaryPath())}; + + if (!exist && install_dialog) + { + auto string_{QObject::tr("Le logiciel QET_ElementScaler est nécessaire pour mettre les éléments à l'échelle.\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/plc-user/QET_ElementScaler/releases"), + ElementScalerDirPath(), + parent); + dialog_.exec(); + } + return exist; +} diff --git a/sources/qet_elementscaler/qet_elementscaler.h b/sources/qet_elementscaler/qet_elementscaler.h new file mode 100644 index 000000000..31bf34374 --- /dev/null +++ b/sources/qet_elementscaler/qet_elementscaler.h @@ -0,0 +1,30 @@ +/* + Copyright 2024 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 . +*/ +#ifndef QET_ELEMENTSCALER_H +#define QET_ELEMENTSCALER_H + +#include + +class QWidget; + +QByteArray ElementScaler(const QString &file_path, QWidget *parent); +QString ElementScalerDirPath(); +QString ElementScalerBinaryPath(); +bool ElementScalerIsPresent(bool install_dialog = true, QWidget *parent = nullptr); + +#endif // QET_ELEMENTSCALER_H