1
/***************************************************************************
2
* Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
30
#include <App/Document.h>
32
#include "DlgProjectUtility.h"
33
#include "ui_DlgProjectUtility.h"
34
#include "Application.h"
38
using namespace Gui::Dialog;
41
/* TRANSLATOR Gui::Dialog::DlgProjectUtility */
43
DlgProjectUtility::DlgProjectUtility(QWidget* parent, Qt::WindowFlags fl)
45
, ui(new Ui_DlgProjectUtility)
48
connect(ui->extractButton, &QPushButton::clicked, this, &DlgProjectUtility::extractButton);
49
connect(ui->createButton, &QPushButton::clicked, this, &DlgProjectUtility::createButton);
50
ui->extractSource->setFilter(QString::fromLatin1("%1 (*.FCStd)").arg(tr("Project file")));
54
* Destroys the object and frees any allocated resources
56
DlgProjectUtility::~DlgProjectUtility() = default;
58
void DlgProjectUtility::extractButton()
60
QString source = ui->extractSource->fileName();
61
QString dest = ui->extractDest->fileName();
62
if (source.isEmpty()) {
63
QMessageBox::critical(this, tr("Empty source"), tr("No source is defined."));
68
QMessageBox::critical(this, tr("Empty destination"), tr("No destination is defined."));
72
tryExtractArchive(source, dest);
75
void DlgProjectUtility::createButton()
77
QString source = ui->createSource->fileName();
78
QString dest = ui->createDest->fileName();
79
if (source.isEmpty()) {
80
QMessageBox::critical(this, tr("Empty source"), tr("No source is defined."));
84
QMessageBox::critical(this, tr("Empty destination"), tr("No destination is defined."));
88
dest = QDir(dest).absoluteFilePath(QString::fromUtf8("project.fcstd"));
90
bool openFile = ui->checkLoadProject->isChecked();
91
tryCreateArchive(source, dest, openFile);
94
void DlgProjectUtility::tryExtractArchive(const QString& source, const QString& target)
97
std::stringstream str;
98
str << "from freecad import project_utility\n";
99
str << "project_utility.extractDocument(\"" << (const char*)source.toUtf8()
100
<< "\", \"" << (const char*)target.toUtf8() << "\")";
101
Gui::Command::runCommand(Gui::Command::App, str.str().c_str());
103
catch (const Base::Exception& e) {
104
QMessageBox::critical(this, tr("Failed to extract document"), QString::fromLatin1(e.what()));
108
void DlgProjectUtility::tryCreateArchive(const QString& source, const QString& target, bool openFile)
111
std::stringstream str;
112
str << "from freecad import project_utility\n";
113
str << "project_utility.createDocument(\"" << (const char*)source.toUtf8()
114
<< "\", \"" << (const char*)target.toUtf8() << "\")";
115
Gui::Command::runCommand(Gui::Command::App, str.str().c_str());
117
Application::Instance->open((const char*)target.toUtf8(),"FreeCAD");
120
catch (const Base::Exception& e) {
121
QMessageBox::critical(this, tr("Failed to create document"), QString::fromLatin1(e.what()));
125
#include "moc_DlgProjectUtility.cpp"