Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
This solve such things

1.  If you create new document, it show "Unnamed" name without translations. Solved.
2.  If you open .step file create new document with "Unnamed" name without translations. Solved.
3.  If you open .iges file create new document with "Unnamed" name without translations. Solved.
4.  Add similar translation ability to AppFemPy, AppMeshPy and AppPartPy.
  • Loading branch information
Kuzma30 authored and KuzemkoA committed May 3, 2022
1 parent d2253c7 commit fd88c83
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/App/Application.cpp
Expand Up @@ -435,9 +435,11 @@ void Application::renameDocument(const char *OldName, const char *NewName)

Document* Application::newDocument(const char * Name, const char * UserName, bool createView, bool tempDoc)
{
QString L10nName = QObject::tr("UnnamedDoc");
// get a valid name anyway!
if (!Name || Name[0] == '\0')
Name = "Unnamed";
Name = qUtf8Printable(L10nName);
// Name = (L10nName.toStdString()).c_str();
string name = getUniqueDocumentName(Name, tempDoc);

// return the temporary document if it exists
Expand Down
2 changes: 2 additions & 0 deletions src/App/CMakeLists.txt
Expand Up @@ -128,8 +128,10 @@ SET(FreeCADApp_XML_SRCS
)
SOURCE_GROUP("XML" FILES ${FreeCADApp_XML_SRCS})

qt5_add_resources(FreeCADApp_QRC_SRCS Resources/App.qrc)
# The document stuff
SET(Document_CPP_SRCS
${FreeCADApp_QRC_SRCS}
Annotation.cpp
Document.cpp
DocumentObject.cpp
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Fem/App/AppFemPy.cpp
Expand Up @@ -123,7 +123,8 @@ class Module : public Py::ExtensionModule<Module>
mesh->read(EncodedName.c_str());
Base::FileInfo file(EncodedName.c_str());
// create new document and add Import feature
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
QString newDocumentName = QObject::tr("Unnamed");
App::Document *pcDoc = App::GetApplication().newDocument(qUtf8Printable(newDocumentName));
FemMeshObject *pcFeature = static_cast<FemMeshObject *>
(pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str()));
pcFeature->Label.setValue(file.fileNamePure().c_str());
Expand Down
8 changes: 4 additions & 4 deletions src/Mod/Import/App/AppImportPy.cpp
Expand Up @@ -79,7 +79,7 @@
#include <Mod/Part/App/PartFeaturePy.h>

#include "ImpExpDxf.h"

#include <QObject>
namespace Import {

class ImportOCAFExt : public Import::ImportOCAF2
Expand Down Expand Up @@ -146,17 +146,17 @@ class Module : public Py::ExtensionModule<Module>
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);

QString newDocumentName = QObject::tr("Unnamed");
try {
//Base::Console().Log("Insert in Part with %s",Name);
Base::FileInfo file(Utf8Name.c_str());


App::Document *pcDoc = nullptr;
if (DocName) {
pcDoc = App::GetApplication().getDocument(DocName);
}
if (!pcDoc) {
pcDoc = App::GetApplication().newDocument("Unnamed");
pcDoc = App::GetApplication().newDocument(qUtf8Printable(newDocumentName));
}

Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Import/Gui/AppImportGuiPy.cpp
Expand Up @@ -411,7 +411,7 @@ class Module : public Py::ExtensionModule<Module>
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);

QString newDocumentName = QObject::tr("Unnamed");
try {
//Base::Console().Log("Insert in Part with %s",Name);
Base::FileInfo file(Utf8Name.c_str());
Expand All @@ -421,7 +421,7 @@ class Module : public Py::ExtensionModule<Module>
pcDoc = App::GetApplication().getDocument(DocName);
}
if (!pcDoc) {
pcDoc = App::GetApplication().newDocument("Unnamed");
pcDoc = App::GetApplication().newDocument(qUtf8Printable(newDocumentName));
}

Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Mesh/App/AppMeshPy.cpp
Expand Up @@ -173,9 +173,9 @@ class Module : public Py::ExtensionModule<Module>

std::string EncodedName = std::string(Name);
PyMem_Free(Name);

// create new document and add Import feature
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
QString newDocumentName = QObject::tr("Unnamed");
App::Document *pcDoc = App::GetApplication().newDocument(qUtf8Printable(newDocumentName));

Mesh::Importer import(pcDoc);
import.load(EncodedName);
Expand Down
11 changes: 6 additions & 5 deletions src/Mod/Part/App/AppPartPy.cpp
Expand Up @@ -110,7 +110,7 @@
#include "TopoShapeSolidPy.h"
#include "TopoShapeWirePy.h"
#include "TopoShapeVertexPy.h"

#include <QObject>
#ifdef FCUseFreeType
# include "FT2FC.h"
#endif
Expand Down Expand Up @@ -630,14 +630,14 @@ class Module : public Py::ExtensionModule<Module>

//Base::Console().Log("Open in Part with %s",Name);
Base::FileInfo file(EncodedName.c_str());

QString newDocumentName = QObject::tr("Unnamed");
// extract ending
if (file.extension().empty())
throw Py::RuntimeError("No file extension");

if (file.hasExtension("stp") || file.hasExtension("step")) {
// create new document and add Import feature
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");

App::Document *pcDoc = App::GetApplication().newDocument(qUtf8Printable(newDocumentName));
#if 1
ImportStepParts(pcDoc,EncodedName.c_str());
#else
Expand All @@ -648,7 +648,8 @@ class Module : public Py::ExtensionModule<Module>
}
#if 1
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");

App::Document *pcDoc = App::GetApplication().newDocument(qUtf8Printable(newDocumentName));
ImportIgesParts(pcDoc,EncodedName.c_str());
pcDoc->recompute();
}
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Path/Gui/AppPathGuiPy.cpp
Expand Up @@ -103,8 +103,9 @@ class Module : public Py::ExtensionModule<Module>

std::ostringstream pre;
std::ostringstream cmd;
QString newDocumentName = QObject::tr("Unnamed");
if (processor.empty()) {
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
App::Document *pcDoc = App::GetApplication().newDocument(qUtf8Printable(newDocumentName));
Gui::Command::runCommand(Gui::Command::Gui,"import Path");
cmd << "Path.read(\"" << EncodedName << "\",\"" << pcDoc->getName() << "\")";
Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/Points/App/AppPointsPy.cpp
Expand Up @@ -45,7 +45,7 @@
#include "PointsAlgos.h"
#include "Structured.h"
#include "Properties.h"

#include <QObject>
namespace Points {
class Module : public Py::ExtensionModule<Module>
{
Expand Down Expand Up @@ -112,8 +112,8 @@ class Module : public Py::ExtensionModule<Module>
}

reader->read(EncodedName);

App::Document* pcDoc = App::GetApplication().newDocument("Unnamed");
QString newDocumentName = QObject::tr("Unnamed");
App::Document* pcDoc = App::GetApplication().newDocument(qUtf8Printable(newDocumentName));

Points::Feature* pcFeature = nullptr;
if (reader->hasProperties()) {
Expand Down

0 comments on commit fd88c83

Please sign in to comment.