Do not throw error when open an already opened document
This commit is contained in:
committed by
Yorik van Havre
parent
428c9005ac
commit
992dc49ece
@@ -776,9 +776,8 @@ Document* Application::openDocumentPrivate(const char * FileName,
|
||||
|
||||
if(!isMainDoc)
|
||||
return 0;
|
||||
std::stringstream str;
|
||||
str << "The project '" << FileName << "' is already open!";
|
||||
throw Base::FileSystemError(str.str().c_str());
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::string name;
|
||||
|
||||
@@ -518,18 +518,34 @@ void Application::open(const char* FileName, const char* Module)
|
||||
|
||||
if (Module != 0) {
|
||||
try {
|
||||
// issue module loading
|
||||
Command::doCommand(Command::App, "import %s", Module);
|
||||
if(File.hasExtension("FCStd")) {
|
||||
bool handled = false;
|
||||
std::string filepath = File.filePath();
|
||||
for(auto &v : d->documents) {
|
||||
auto doc = v.second->getDocument();
|
||||
std::string fi = Base::FileInfo(doc->FileName.getValue()).filePath();
|
||||
if(filepath == fi) {
|
||||
handled = true;
|
||||
Command::doCommand(Command::App, "FreeCADGui.reload('%s')", doc->getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!handled)
|
||||
Command::doCommand(Command::App, "FreeCAD.openDocument('%s')", FileName);
|
||||
} else {
|
||||
// issue module loading
|
||||
Command::doCommand(Command::App, "import %s", Module);
|
||||
|
||||
// load the file with the module
|
||||
Command::doCommand(Command::App, "%s.open(u\"%s\")", Module, unicodepath.c_str());
|
||||
// load the file with the module
|
||||
Command::doCommand(Command::App, "%s.open(u\"%s\")", Module, unicodepath.c_str());
|
||||
|
||||
// ViewFit
|
||||
if (!File.hasExtension("FCStd") && sendHasMsgToActiveView("ViewFit")) {
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/View");
|
||||
if (hGrp->GetBool("AutoFitToView", true))
|
||||
Command::doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
|
||||
// ViewFit
|
||||
if (sendHasMsgToActiveView("ViewFit")) {
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/View");
|
||||
if (hGrp->GetBool("AutoFitToView", true))
|
||||
Command::doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
|
||||
}
|
||||
}
|
||||
|
||||
// the original file name is required
|
||||
@@ -2266,6 +2282,17 @@ App::Document *Application::reopen(App::Document *doc) {
|
||||
|| d->testStatus(App::Document::PartialRestore) )
|
||||
docs.push_back(d->FileName.getValue());
|
||||
}
|
||||
|
||||
if(docs.empty()) {
|
||||
Document *gdoc = getDocument(doc);
|
||||
if(gdoc) {
|
||||
setActiveDocument(gdoc);
|
||||
if(!gdoc->setActiveView())
|
||||
gdoc->setActiveView(0,View3DInventor::getClassTypeId());
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
for(auto &file : docs)
|
||||
App::GetApplication().openDocument(file.c_str(),false);
|
||||
}
|
||||
|
||||
@@ -264,7 +264,8 @@ public:
|
||||
static PyObject* sOpen (PyObject *self,PyObject *args); // open Python scripts
|
||||
static PyObject* sInsert (PyObject *self,PyObject *args); // open Python scripts
|
||||
static PyObject* sExport (PyObject *self,PyObject *args);
|
||||
static PyObject* sReload (PyObject *self,PyObject *args);
|
||||
static PyObject* sReload (PyObject *self,PyObject *args); // reload FCStd file
|
||||
static PyObject* sLoadFile (PyObject *self,PyObject *args); // open all types of files
|
||||
|
||||
static PyObject* sCoinRemoveAllChildren (PyObject *self,PyObject *args);
|
||||
|
||||
|
||||
@@ -218,6 +218,13 @@ PyMethodDef Application::Methods[] = {
|
||||
"reload(name) -> doc\n\n"
|
||||
"Reload a partial opened document"},
|
||||
|
||||
{"loadFile", (PyCFunction) Application::sLoadFile, METH_VARARGS,
|
||||
"loadFile(string=filename,[string=module]) -> None\n\n"
|
||||
"Loads an arbitrary file by delegating to the given Python module:\n"
|
||||
"* If no module is given it will be determined by the file extension.\n"
|
||||
"* If more than one module can load a file the first one one will be taken.\n"
|
||||
"* If no module exists to load the file an exception will be raised."},
|
||||
|
||||
{"coinRemoveAllChildren", (PyCFunction) Application::sCoinRemoveAllChildren, METH_VARARGS,
|
||||
"Remove all children from a group node"},
|
||||
|
||||
@@ -1470,6 +1477,37 @@ PyObject* Application::sReload(PyObject * /*self*/, PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* Application::sLoadFile(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *path, *mod="";
|
||||
if (!PyArg_ParseTuple(args, "s|s", &path, &mod)) // convert args: Python->C
|
||||
return 0; // NULL triggers exception
|
||||
PY_TRY {
|
||||
Base::FileInfo fi(path);
|
||||
if (!fi.isFile() || !fi.exists()) {
|
||||
PyErr_Format(PyExc_IOError, "File %s doesn't exist.", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string module = mod;
|
||||
if (module.empty()) {
|
||||
std::string ext = fi.extension();
|
||||
std::vector<std::string> modules = App::GetApplication().getImportModules(ext.c_str());
|
||||
if (modules.empty()) {
|
||||
PyErr_Format(PyExc_IOError, "Filetype %s is not supported.", ext.c_str());
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
module = modules.front();
|
||||
}
|
||||
}
|
||||
|
||||
Application::Instance->open(path,mod);
|
||||
|
||||
Py_Return;
|
||||
} PY_CATCH
|
||||
}
|
||||
|
||||
PyObject* Application::sAddDocObserver(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
PyObject* o;
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import FreeCAD,sys
|
||||
import FreeCADGui,sys
|
||||
# MRU will be given before this script is run
|
||||
rf=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/RecentFiles")
|
||||
FreeCAD.loadFile(rf.GetString("MRU"+str(MRU)))
|
||||
FreeCADGui.loadFile(rf.GetString("MRU"+str(MRU)))
|
||||
|
||||
from StartPage import StartPage
|
||||
StartPage.postStart()
|
||||
|
||||
Reference in New Issue
Block a user