Files
create/src/Gui/Dialogs/DlgProjectUtility.cpp
forbes 723a8c98d5
All checks were successful
Build and Test / build (pull_request) Successful in 42m37s
feat: .kc file format — Layer 1 (format registration)
Register .kc as a recognized file type alongside .FCStd:

C++ changes:
- Document.cpp: checkFileName() accepts .kc extension
- Gui/Document.cpp: Save As and Save Copy dialogs include *.kc
- CommandDoc.cpp: Merge document dialog includes *.kc
- DlgProjectUtility.cpp: Project utility dialog includes *.kc

Python changes:
- FreeCADInit.py: register *.kc in import type system
- kc_format.py: DocumentObserver that preserves silo/ ZIP entries
  across saves (caches before save, re-injects after save)
- InitGui.py: register kc_format observer on startup

Silo integration:
- get_cad_file_path() generates .kc paths for new files
- find_file_by_part_number() finds both .kc and .FCStd, preferring .kc
- search_local_files() lists both .kc and .FCStd files

The .kc format is a superset of .FCStd with a silo/ directory
containing Kindred platform metadata. See docs/KC_SPECIFICATION.md.
2026-02-13 13:39:42 -06:00

125 lines
4.9 KiB
C++

// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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 Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include <sstream>
#include <QDir>
#include <QMessageBox>
#include <App/Document.h>
#include "Dialogs/DlgProjectUtility.h"
#include "ui_DlgProjectUtility.h"
#include "Application.h"
#include "Command.h"
using namespace Gui::Dialog;
/* TRANSLATOR Gui::Dialog::DlgProjectUtility */
DlgProjectUtility::DlgProjectUtility(QWidget* parent, Qt::WindowFlags fl)
: QDialog(parent, fl)
, ui(new Ui_DlgProjectUtility)
{
ui->setupUi(this);
connect(ui->extractButton, &QPushButton::clicked, this, &DlgProjectUtility::extractButton);
connect(ui->createButton, &QPushButton::clicked, this, &DlgProjectUtility::createButton);
ui->extractSource->setFilter(QStringLiteral("%1 (*.FCStd *.kc)").arg(tr("Project file")));
}
/**
* Destroys the object and frees any allocated resources
*/
DlgProjectUtility::~DlgProjectUtility() = default;
void DlgProjectUtility::extractButton()
{
QString source = ui->extractSource->fileName();
QString dest = ui->extractDest->fileName();
if (source.isEmpty()) {
QMessageBox::critical(this, tr("Empty source"), tr("No source is defined."));
return;
}
if (dest.isEmpty()) {
QMessageBox::critical(this, tr("Empty destination"), tr("No destination is defined."));
return;
}
tryExtractArchive(source, dest);
}
void DlgProjectUtility::createButton()
{
QString source = ui->createSource->fileName();
QString dest = ui->createDest->fileName();
if (source.isEmpty()) {
QMessageBox::critical(this, tr("Empty source"), tr("No source is defined."));
return;
}
if (dest.isEmpty()) {
QMessageBox::critical(this, tr("Empty destination"), tr("No destination is defined."));
return;
}
dest = QDir(dest).absoluteFilePath(QStringLiteral("project.fcstd"));
bool openFile = ui->checkLoadProject->isChecked();
tryCreateArchive(source, dest, openFile);
}
void DlgProjectUtility::tryExtractArchive(const QString& source, const QString& target)
{
try {
std::stringstream str;
str << "from freecad import project_utility\n";
str << "project_utility.extractDocument(\"" << (const char*)source.toUtf8() << "\", \""
<< (const char*)target.toUtf8() << "\")";
Gui::Command::runCommand(Gui::Command::App, str.str().c_str());
}
catch (const Base::Exception& e) {
QMessageBox::critical(this, tr("Failed to extract document"), QString::fromLatin1(e.what()));
}
}
void DlgProjectUtility::tryCreateArchive(const QString& source, const QString& target, bool openFile)
{
try {
std::stringstream str;
str << "from freecad import project_utility\n";
str << "project_utility.createDocument(\"" << (const char*)source.toUtf8() << "\", \""
<< (const char*)target.toUtf8() << "\")";
Gui::Command::runCommand(Gui::Command::App, str.str().c_str());
if (openFile) {
Application::Instance->open((const char*)target.toUtf8(), "FreeCAD");
}
}
catch (const Base::Exception& e) {
QMessageBox::critical(this, tr("Failed to create document"), QString::fromLatin1(e.what()));
}
}
#include "moc_DlgProjectUtility.cpp"