+ unify DLL export defines to namespace names
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5000 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
197
src/Main/CMakeLists.txt
Normal file
197
src/Main/CMakeLists.txt
Normal file
@@ -0,0 +1,197 @@
|
||||
#add_defintions(-D_FC_GUI_ENABLED_)
|
||||
#add_defintions(-DFREECADMAINPY)
|
||||
|
||||
if(FREECAD_BUILD_GUI)
|
||||
include_directories(
|
||||
${Boost_INCLUDE_DIRS}
|
||||
${COIN3D_INCLUDE_DIR}
|
||||
${ZLIB_INCLUDE_DIR}
|
||||
${SOQT_INCLUDE_DIR}
|
||||
${QT_INCLUDE_DIR}
|
||||
${PYTHON_INCLUDE_PATH}
|
||||
${XERCESC_INCLUDE_DIR}
|
||||
)
|
||||
else(FREECAD_BUILD_GUI)
|
||||
include_directories(
|
||||
${Boost_INCLUDE_DIRS}
|
||||
${ZLIB_INCLUDE_DIR}
|
||||
${QT_INCLUDE_DIR}
|
||||
${PYTHON_INCLUDE_PATH}
|
||||
${XERCESC_INCLUDE_DIR}
|
||||
)
|
||||
endif(FREECAD_BUILD_GUI)
|
||||
|
||||
######################## FreeCADMain ########################
|
||||
if(FREECAD_BUILD_GUI)
|
||||
|
||||
SET(FreeCAD_SRCS
|
||||
freecad.rc
|
||||
icon.ico
|
||||
MainGui.cpp
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
SET(FreeCAD_LIBS
|
||||
FreeCADGui
|
||||
debug qtmaind.lib
|
||||
optimized qtmain.lib
|
||||
)
|
||||
else(MSVC)
|
||||
SET(FreeCAD_LIBS
|
||||
FreeCADGui
|
||||
)
|
||||
endif(MSVC)
|
||||
|
||||
add_executable(FreeCADMain WIN32 ${FreeCAD_SRCS})
|
||||
target_link_libraries(FreeCADMain ${FreeCAD_LIBS})
|
||||
|
||||
# Note this is IDE specific, not necessarily platform specific
|
||||
if(MSVC)
|
||||
set_target_properties(FreeCADMain PROPERTIES OUTPUT_NAME "FreeCAD")
|
||||
set_target_properties(FreeCADMain PROPERTIES DEBUG_OUTPUT_NAME "FreeCADD")
|
||||
# dirty hack to avoid Debug/Release subdirectory
|
||||
set_target_properties(FreeCADMain PROPERTIES PREFIX "../")
|
||||
set_target_properties(FreeCADMain PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
elseif(MINGW)
|
||||
set_target_properties(FreeCADMain PROPERTIES OUTPUT_NAME "FreeCAD")
|
||||
set_target_properties(FreeCADMain PROPERTIES DEBUG_OUTPUT_NAME "FreeCADD")
|
||||
set_target_properties(FreeCADMain PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
else(MSVC)
|
||||
set_target_properties(FreeCADMain PROPERTIES OUTPUT_NAME "FreeCAD")
|
||||
set_target_properties(FreeCADMain PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
endif(MSVC)
|
||||
|
||||
if(WIN32)
|
||||
INSTALL(TARGETS FreeCADMain
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
)
|
||||
else(WIN32)
|
||||
INSTALL(TARGETS FreeCADMain
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
endif(WIN32)
|
||||
endif(FREECAD_BUILD_GUI)
|
||||
######################## FreeCADMainCmd ########################
|
||||
|
||||
SET(FreeCADMainCmd_SRCS
|
||||
MainCmd.cpp
|
||||
)
|
||||
add_executable(FreeCADMainCmd ${FreeCADMainCmd_SRCS})
|
||||
|
||||
target_link_libraries(FreeCADMainCmd
|
||||
FreeCADApp
|
||||
${QT_DEBUG_LIBRARIES}
|
||||
${QT_LIBRARIES}
|
||||
)
|
||||
|
||||
# Note this is IDE specific, not necessarily platform specific
|
||||
if(MSVC)
|
||||
set_target_properties(FreeCADMainCmd PROPERTIES OUTPUT_NAME "FreeCADCmd")
|
||||
set_target_properties(FreeCADMainCmd PROPERTIES DEBUG_OUTPUT_NAME "FreeCADCmdD")
|
||||
# dirty hack to avoid Debug/Release subdirectory
|
||||
set_target_properties(FreeCADMainCmd PROPERTIES PREFIX "../")
|
||||
set_target_properties(FreeCADMainCmd PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
elseif(MINGW)
|
||||
set_target_properties(FreeCADMainCmd PROPERTIES OUTPUT_NAME "FreeCADCmd")
|
||||
set_target_properties(FreeCADMainCmd PROPERTIES DEBUG_OUTPUT_NAME "FreeCADCmdD")
|
||||
set_target_properties(FreeCADMainCmd PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
else(MSVC)
|
||||
set_target_properties(FreeCADMainCmd PROPERTIES OUTPUT_NAME "FreeCADCmd")
|
||||
set_target_properties(FreeCADMainCmd PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
endif(MSVC)
|
||||
|
||||
if(WIN32)
|
||||
INSTALL(TARGETS FreeCADMainCmd
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
)
|
||||
else(WIN32)
|
||||
INSTALL(TARGETS FreeCADMainCmd
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
endif(WIN32)
|
||||
|
||||
######################## FreeCADMainPy ########################
|
||||
|
||||
SET(FreeCADMainPy_SRCS
|
||||
MainPy.cpp
|
||||
)
|
||||
|
||||
add_library(FreeCADMainPy SHARED ${FreeCADMainPy_SRCS})
|
||||
|
||||
target_link_libraries(FreeCADMainPy FreeCADApp)
|
||||
|
||||
# Note this is IDE specific, not necessarily platform specific
|
||||
if(MSVC)
|
||||
set_target_properties(FreeCADMainPy PROPERTIES OUTPUT_NAME "FreeCAD")
|
||||
set_target_properties(FreeCADMainPy PROPERTIES DEBUG_OUTPUT_NAME "FreeCAD_d")
|
||||
set_target_properties(FreeCADMainPy PROPERTIES SUFFIX ".pyd")
|
||||
# dirty hack to avoid Debug/Release subdirectory
|
||||
set_target_properties(FreeCADMainPy PROPERTIES PREFIX "../")
|
||||
set_target_properties(FreeCADMainPy PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
elseif(MINGW)
|
||||
set_target_properties(FreeCADMainPy PROPERTIES OUTPUT_NAME "FreeCAD")
|
||||
set_target_properties(FreeCADMainPy PROPERTIES DEBUG_OUTPUT_NAME "FreeCAD_d")
|
||||
set_target_properties(FreeCADMainPy PROPERTIES SUFFIX ".pyd")
|
||||
set_target_properties(FreeCADMainPy PROPERTIES PREFIX "")
|
||||
set_target_properties(FreeCADMainPy PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
else(MSVC)
|
||||
set_target_properties(FreeCADMainPy PROPERTIES OUTPUT_NAME "FreeCAD")
|
||||
set_target_properties(FreeCADMainPy PROPERTIES PREFIX "")
|
||||
set_target_properties(FreeCADMainPy PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
endif(MSVC)
|
||||
|
||||
if(WIN32)
|
||||
INSTALL(TARGETS FreeCADMainPy
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
)
|
||||
else(WIN32)
|
||||
INSTALL(TARGETS FreeCADMainPy
|
||||
LIBRARY DESTINATION lib
|
||||
)
|
||||
endif(WIN32)
|
||||
|
||||
######################## FreeCADGuiPy ########################
|
||||
if(FREECAD_BUILD_GUI)
|
||||
|
||||
SET(FreeCADGuiPy_SRCS
|
||||
FreeCADGuiPy.cpp
|
||||
)
|
||||
|
||||
add_library(FreeCADGuiPy SHARED ${FreeCADGuiPy_SRCS})
|
||||
|
||||
target_link_libraries(FreeCADGuiPy FreeCADGui)
|
||||
|
||||
# Note this is IDE specific, not necessarily platform specific
|
||||
if(MSVC)
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES OUTPUT_NAME "FreeCADGui")
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES DEBUG_OUTPUT_NAME "FreeCADGui_d")
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES SUFFIX ".pyd")
|
||||
# dirty hack to avoid Debug/Release subdirectory
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES PREFIX "../")
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
elseif(MINGW)
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES OUTPUT_NAME "FreeCADGui")
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES DEBUG_OUTPUT_NAME "FreeCADGui_d")
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES SUFFIX ".pyd")
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES PREFIX "")
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
else(MSVC)
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES OUTPUT_NAME "FreeCADGui")
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES PREFIX "")
|
||||
set_target_properties(FreeCADGuiPy PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
endif(MSVC)
|
||||
|
||||
if(WIN32)
|
||||
INSTALL(TARGETS FreeCADGuiPy
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
)
|
||||
else(WIN32)
|
||||
INSTALL(TARGETS FreeCADGuiPy
|
||||
LIBRARY DESTINATION lib
|
||||
)
|
||||
endif(WIN32)
|
||||
endif(FREECAD_BUILD_GUI)
|
||||
316
src/Main/FreeCADGuiPy.cpp
Normal file
316
src/Main/FreeCADGuiPy.cpp
Normal file
@@ -0,0 +1,316 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2009 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 <FCConfig.h>
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <Python.h>
|
||||
#include <QApplication>
|
||||
#include <QIcon>
|
||||
#include <QThread>
|
||||
#include <Inventor/Qt/SoQt.h>
|
||||
#if defined(Q_OS_WIN)
|
||||
#include <windows.h>
|
||||
#elif defined(Q_WS_X11)
|
||||
#include <QX11EmbedWidget>
|
||||
#endif
|
||||
// FreeCAD Base header
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Factory.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <App/Application.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/SoFCDB.h>
|
||||
|
||||
|
||||
static
|
||||
QWidget* setupMainWindow();
|
||||
|
||||
class GUIThread : public QThread
|
||||
{
|
||||
public:
|
||||
GUIThread()
|
||||
{
|
||||
}
|
||||
void run()
|
||||
{
|
||||
int argc = 0;
|
||||
char **argv = {0};
|
||||
QApplication app(argc, argv);
|
||||
if (setupMainWindow()) {
|
||||
app.exec();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
HHOOK hhook;
|
||||
|
||||
LRESULT CALLBACK
|
||||
FilterProc(int nCode, WPARAM wParam, LPARAM lParam) {
|
||||
if (qApp)
|
||||
qApp->sendPostedEvents(0, -1); // special DeferredDelete
|
||||
return CallNextHookEx(hhook, nCode, wParam, lParam);
|
||||
}
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
FreeCADGui_showMainWindow(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return NULL;
|
||||
|
||||
static GUIThread* thr = 0;
|
||||
if (!qApp) {
|
||||
#if 0
|
||||
if (!thr) thr = new GUIThread();
|
||||
thr->start();
|
||||
#elif defined(Q_OS_WIN)
|
||||
static int argc = 0;
|
||||
static char **argv = {0};
|
||||
(void)new QApplication(argc, argv);
|
||||
// When QApplication is constructed
|
||||
hhook = SetWindowsHookEx(WH_GETMESSAGE,
|
||||
FilterProc, 0, GetCurrentThreadId());
|
||||
#elif !defined(QT_NO_GLIB)
|
||||
static int argc = 0;
|
||||
static char **argv = {0};
|
||||
(void)new QApplication(argc, argv);
|
||||
#else
|
||||
PyErr_SetString(PyExc_RuntimeError, "Must construct a QApplication before a QPaintDevice\n");
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
else if (!qobject_cast<QApplication*>(qApp)) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Cannot create widget when no GUI is being used\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!thr) {
|
||||
if (!setupMainWindow())
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
FreeCADGui_exec_loop(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return NULL;
|
||||
|
||||
if (!qApp) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Must construct a QApplication before a QPaintDevice\n");
|
||||
return NULL;
|
||||
}
|
||||
else if (!qobject_cast<QApplication*>(qApp)) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Cannot create widget when no GUI is being used\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
qApp->exec();
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
FreeCADGui_setupWithoutGUI(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return NULL;
|
||||
|
||||
if (!Gui::Application::Instance) {
|
||||
static Gui::Application *app = new Gui::Application(false);
|
||||
Q_UNUSED(app);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_RuntimeError, "FreeCADGui already initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!SoDB::isInitialized()) {
|
||||
// init the Inventor subsystem
|
||||
SoDB::init();
|
||||
SoQt::init("FreeCAD");
|
||||
}
|
||||
if (!Gui::SoFCDB::isInitialized()) {
|
||||
Gui::SoFCDB::init();
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
FreeCADGui_embedToWindow(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char* pointer;
|
||||
if (!PyArg_ParseTuple(args, "s", &pointer))
|
||||
return NULL;
|
||||
|
||||
QWidget* widget = Gui::getMainWindow();
|
||||
if (!widget) {
|
||||
PyErr_SetString(PyExc_Exception, "No main window");
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string pointer_str = pointer;
|
||||
std::stringstream str(pointer_str);
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
void* window = 0;
|
||||
str >> window;
|
||||
WId winid = (WId)window;
|
||||
|
||||
LONG oldLong = GetWindowLong(winid, GWL_STYLE);
|
||||
SetWindowLong(winid, GWL_STYLE,
|
||||
oldLong | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
|
||||
//SetWindowLong(widget->winId(), GWL_STYLE,
|
||||
// WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
|
||||
SetParent(widget->winId(), winid);
|
||||
|
||||
QEvent embeddingEvent(QEvent::EmbeddingControl);
|
||||
QApplication::sendEvent(widget, &embeddingEvent);
|
||||
#elif defined(Q_WS_X11)
|
||||
WId winid;
|
||||
str >> winid;
|
||||
|
||||
QX11EmbedWidget* x11 = new QX11EmbedWidget();
|
||||
widget->setParent(x11);
|
||||
x11->embedInto(winid);
|
||||
x11->show();
|
||||
#else
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented for this platform");
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
struct PyMethodDef FreeCADGui_methods[] = {
|
||||
{"showMainWindow",FreeCADGui_showMainWindow,METH_VARARGS,
|
||||
"showMainWindow() -- Show the main window\n"
|
||||
"If no main window does exist one gets created"},
|
||||
{"exec_loop",FreeCADGui_exec_loop,METH_VARARGS,
|
||||
"exec_loop() -- Starts the event loop\n"
|
||||
"Note: this will block the call until the event loop has terminated"},
|
||||
{"setupWithoutGUI",FreeCADGui_setupWithoutGUI,METH_VARARGS,
|
||||
"setupWithoutGUI() -- Uses this module without starting\n"
|
||||
"an event loop or showing up any GUI\n"},
|
||||
{"embedToWindow",FreeCADGui_embedToWindow,METH_VARARGS,
|
||||
"embedToWindow() -- Embeds the main window into another window\n"},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static
|
||||
QWidget* setupMainWindow()
|
||||
{
|
||||
if (!Gui::Application::Instance) {
|
||||
static Gui::Application *app = new Gui::Application(true);
|
||||
Q_UNUSED(app);
|
||||
}
|
||||
|
||||
if (!Gui::MainWindow::getInstance()) {
|
||||
Gui::MainWindow *mw = new Gui::MainWindow();
|
||||
QIcon icon = qApp->windowIcon();
|
||||
if (icon.isNull())
|
||||
qApp->setWindowIcon(Gui::BitmapFactory().pixmap(App::Application::Config()["AppIcon"].c_str()));
|
||||
mw->setWindowIcon(qApp->windowIcon());
|
||||
QString appName = qApp->applicationName();
|
||||
if (!appName.isEmpty())
|
||||
mw->setWindowTitle(appName);
|
||||
else
|
||||
mw->setWindowTitle(QString::fromAscii(App::Application::Config()["ExeName"].c_str()));
|
||||
|
||||
if (!SoDB::isInitialized()) {
|
||||
// init the Inventor subsystem
|
||||
SoDB::init();
|
||||
SoQt::init(mw);
|
||||
Gui::SoFCDB::init();
|
||||
}
|
||||
|
||||
static bool init = false;
|
||||
if (!init) {
|
||||
try {
|
||||
Base::Interpreter().runString(Base::ScriptFactory().ProduceScript("FreeCADGuiInit"));
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_Format(PyExc_Exception, "Error in FreeCADGuiInit.py: %s\n", e.what());
|
||||
return 0;
|
||||
}
|
||||
init = true;
|
||||
}
|
||||
|
||||
qApp->setActiveWindow(mw);
|
||||
|
||||
// Activate the correct workbench
|
||||
std::string start = App::Application::Config()["StartWorkbench"];
|
||||
Base::Console().Log("Init: Activating default workbench %s\n", start.c_str());
|
||||
start = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
|
||||
GetASCII("AutoloadModule", start.c_str());
|
||||
// if the auto workbench is not visible then force to use the default workbech
|
||||
// and replace the wrong entry in the parameters
|
||||
QStringList wb = Gui::Application::Instance->workbenches();
|
||||
if (!wb.contains(QString::fromAscii(start.c_str()))) {
|
||||
start = App::Application::Config()["StartWorkbench"];
|
||||
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
|
||||
SetASCII("AutoloadModule", start.c_str());
|
||||
}
|
||||
|
||||
Gui::Application::Instance->activateWorkbench(start.c_str());
|
||||
mw->loadWindowSettings();
|
||||
}
|
||||
else {
|
||||
Gui::getMainWindow()->show();
|
||||
}
|
||||
|
||||
return Gui::getMainWindow();
|
||||
}
|
||||
|
||||
PyMODINIT_FUNC initFreeCADGui()
|
||||
{
|
||||
try {
|
||||
Base::Interpreter().loadModule("FreeCAD");
|
||||
App::Application::Config()["AppIcon"] = "freecad";
|
||||
App::Application::Config()["SplashPicture"] = "freecadsplash";
|
||||
App::Application::Config()["ConsoleBanner"] = "\xc2\xa9 Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2011\n";
|
||||
Gui::Application::initApplication();
|
||||
Py_InitModule("FreeCADGui", FreeCADGui_methods);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_Format(PyExc_ImportError, "%s\n", e.what());
|
||||
}
|
||||
catch (...) {
|
||||
PyErr_SetString(PyExc_ImportError, "Unknown runtime error occurred");
|
||||
}
|
||||
}
|
||||
|
||||
136
src/Main/MainCmd.cpp
Normal file
136
src/Main/MainCmd.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/***************************************************************************
|
||||
* (c) Jürgen Riegel (juergen.riegel@web.de) 2008 *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License (LGPL) *
|
||||
* as published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* for detail see the LICENCE text file. *
|
||||
* *
|
||||
* FreeCAD 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 FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
* Juergen Riegel 2002 *
|
||||
***************************************************************************/
|
||||
#include "../FCConfig.h"
|
||||
|
||||
#ifdef _PreComp_
|
||||
# undef _PreComp_
|
||||
#endif
|
||||
|
||||
#ifdef FC_OS_LINUX
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sstream>
|
||||
|
||||
// FreeCAD Base header
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Factory.h>
|
||||
|
||||
// FreeCAD doc header
|
||||
#include <App/Application.h>
|
||||
|
||||
|
||||
using Base::Console;
|
||||
using App::Application;
|
||||
|
||||
const char sBanner[] = "(c) Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2011\n"\
|
||||
" ##### #### ### #### \n" \
|
||||
" # # # # # # \n" \
|
||||
" # ## #### #### # # # # # \n" \
|
||||
" #### # # # # # # # ##### # # \n" \
|
||||
" # # #### #### # # # # # \n" \
|
||||
" # # # # # # # # # ## ## ##\n" \
|
||||
" # # #### #### ### # # #### ## ## ##\n\n" ;
|
||||
|
||||
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
// Make sure that we use '.' as decimal point
|
||||
#if defined(FC_OS_LINUX)
|
||||
putenv("LANG=C");
|
||||
putenv("LC_ALL=C");
|
||||
#else
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
#endif
|
||||
|
||||
// Name and Version of the Application
|
||||
App::Application::Config()["ExeName"] = "FreeCAD";
|
||||
App::Application::Config()["ExeVendor"] = "FreeCAD";
|
||||
App::Application::Config()["AppDataSkipVendor"] = "true";
|
||||
|
||||
// set the banner (for logging and console)
|
||||
App::Application::Config()["ConsoleBanner"] = sBanner;
|
||||
|
||||
try {
|
||||
// Init phase ===========================================================
|
||||
// sets the default run mode for FC, starts with command prompt if not overridden in InitConfig...
|
||||
App::Application::Config()["RunMode"] = "Exit";
|
||||
|
||||
// Inits the Application
|
||||
App::Application::init(argc,argv);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
std::string appName = App::Application::Config()["ExeName"];
|
||||
std::stringstream msg;
|
||||
msg << "While initializing " << appName << " the following exception occurred: '" << e.what() << "'\n\n";
|
||||
msg << "Python is searching for its runtime files in the following directories:\n" << Py_GetPath() << "\n\n";
|
||||
msg << "Python version information:\n" << Py_GetVersion() << "\n";
|
||||
const char* pythonhome = getenv("PYTHONHOME");
|
||||
if ( pythonhome ) {
|
||||
msg << "\nThe environment variable PYTHONHOME is set to '" << pythonhome << "'.";
|
||||
msg << "\nSetting this environment variable might cause Python to fail. Please contact your administrator to unset it on your system.\n\n";
|
||||
}
|
||||
else {
|
||||
msg << "\nPlease contact the application's support team for more information.\n\n";
|
||||
}
|
||||
|
||||
printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str());
|
||||
exit(100);
|
||||
}
|
||||
catch (...) {
|
||||
std::string appName = App::Application::Config()["ExeName"];
|
||||
std::stringstream msg;
|
||||
msg << "Unknown runtime error occurred while initializing " << appName <<".\n\n";
|
||||
msg << "Please contact the application's support team for more information.\n\n";
|
||||
printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str());
|
||||
exit(101);
|
||||
}
|
||||
|
||||
// Run phase ===========================================================
|
||||
Application::runApplication();
|
||||
|
||||
|
||||
// Destruction phase ===========================================================
|
||||
Console().Log("FreeCAD terminating...\n");
|
||||
|
||||
// close open documents
|
||||
App::GetApplication().closeAllDocuments();
|
||||
|
||||
// cleans up
|
||||
Application::destruct();
|
||||
|
||||
Console().Log("FreeCAD completely terminated\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
373
src/Main/MainGui.cpp
Normal file
373
src/Main/MainGui.cpp
Normal file
@@ -0,0 +1,373 @@
|
||||
/***************************************************************************
|
||||
* (c) Jürgen Riegel (juergen.riegel@web.de) 2008 *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License (LGPL) *
|
||||
* as published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* for detail see the LICENCE text file. *
|
||||
* *
|
||||
* FreeCAD 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 FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
* Juergen Riegel 2002 *
|
||||
***************************************************************************/
|
||||
#include <FCConfig.h>
|
||||
|
||||
#ifdef _PreComp_
|
||||
# undef _PreComp_
|
||||
#endif
|
||||
|
||||
#ifdef FC_OS_LINUX
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <cstdio>
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
#include <QLocale>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QXmlSimpleReader>
|
||||
#include <QXmlInputSource>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
|
||||
// FreeCAD header
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Factory.h>
|
||||
#include <App/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Icons/background.xpm>
|
||||
#include <Gui/Application.h>
|
||||
|
||||
void PrintInitHelp(void);
|
||||
|
||||
const char sBanner[] = "\xc2\xa9 Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2011\n"\
|
||||
" ##### #### ### #### \n" \
|
||||
" # # # # # # \n" \
|
||||
" # ## #### #### # # # # # \n" \
|
||||
" #### # # # # # # # ##### # # \n" \
|
||||
" # # #### #### # # # # # \n" \
|
||||
" # # # # # # # # # ## ## ##\n" \
|
||||
" # # #### #### ### # # #### ## ## ##\n\n" ;
|
||||
|
||||
class Branding
|
||||
{
|
||||
public:
|
||||
struct UserDefines
|
||||
{
|
||||
std::string windowTitle;
|
||||
std::string windowIcon;
|
||||
std::string programLogo;
|
||||
std::string splashScreen;
|
||||
};
|
||||
|
||||
Branding()
|
||||
{
|
||||
}
|
||||
|
||||
bool readFile(const QString& fn)
|
||||
{
|
||||
QFile file(fn);
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
return false;
|
||||
if (!evaluateXML(&file, domDocument))
|
||||
return false;
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
UserDefines getUserDefines() const
|
||||
{
|
||||
UserDefines ud;
|
||||
QDomElement root = domDocument.documentElement();
|
||||
QDomElement child;
|
||||
if (!root.isNull()) {
|
||||
child = root.firstChildElement(QLatin1String("WindowTitle"));
|
||||
if (!child.isNull())
|
||||
ud.windowTitle = (const char*)child.text().toUtf8();
|
||||
child = root.firstChildElement(QLatin1String("WindowIcon"));
|
||||
if (!child.isNull())
|
||||
ud.windowIcon = (const char*)child.text().toUtf8();
|
||||
child = root.firstChildElement(QLatin1String("ProgramLogo"));
|
||||
if (!child.isNull())
|
||||
ud.programLogo = (const char*)child.text().toUtf8();
|
||||
child = root.firstChildElement(QLatin1String("SplashScreen"));
|
||||
if (!child.isNull())
|
||||
ud.splashScreen = (const char*)child.text().toUtf8();
|
||||
}
|
||||
return ud;
|
||||
}
|
||||
|
||||
private:
|
||||
bool evaluateXML(QIODevice *device, QDomDocument& xmlDocument)
|
||||
{
|
||||
QString errorStr;
|
||||
int errorLine;
|
||||
int errorColumn;
|
||||
|
||||
if (!xmlDocument.setContent(device, true, &errorStr, &errorLine,
|
||||
&errorColumn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement root = xmlDocument.documentElement();
|
||||
if (root.tagName() != QLatin1String("Branding")) {
|
||||
return false;
|
||||
}
|
||||
else if (root.hasAttribute(QLatin1String("version"))) {
|
||||
QString attr = root.attribute(QLatin1String("version"));
|
||||
if (attr != QLatin1String("1.0"))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
QDomDocument domDocument;
|
||||
};
|
||||
|
||||
class ProgramOptions
|
||||
{
|
||||
public:
|
||||
ProgramOptions()
|
||||
{
|
||||
newcout = new ProgramOptionsStream(out);
|
||||
oldcout = std::cout.rdbuf(newcout);
|
||||
out.reserve(80);
|
||||
newcerr = new ProgramOptionsStream(err);
|
||||
oldcerr = std::cerr.rdbuf(newcerr);
|
||||
err.reserve(80);
|
||||
|
||||
error = true;
|
||||
::atexit(ProgramOptions::failure);
|
||||
}
|
||||
~ProgramOptions()
|
||||
{
|
||||
std::cout.rdbuf(oldcout);
|
||||
delete newcout;
|
||||
std::cerr.rdbuf(oldcerr);
|
||||
delete newcerr;
|
||||
error = false;
|
||||
}
|
||||
static void failure()
|
||||
{
|
||||
if (error) {
|
||||
int argc=0;
|
||||
QApplication app(argc,0);
|
||||
QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str());
|
||||
if (!err.empty()) {
|
||||
QString msg = QString::fromAscii(err.c_str());
|
||||
QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>");
|
||||
QMessageBox::critical(0, appName, s);
|
||||
}
|
||||
else if (!out.empty()) {
|
||||
QString msg = QString::fromAscii(out.c_str());
|
||||
QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>");
|
||||
QMessageBox::information(0, appName, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
class ProgramOptionsStream : public std::streambuf
|
||||
{
|
||||
public:
|
||||
ProgramOptionsStream(std::string& s) : buf(s)
|
||||
{
|
||||
}
|
||||
int overflow(int c = EOF)
|
||||
{
|
||||
if (c != EOF)
|
||||
buf.push_back((char)c);
|
||||
return c;
|
||||
}
|
||||
int sync()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
private:
|
||||
std::string& buf;
|
||||
};
|
||||
|
||||
private:
|
||||
friend class ProgramOptionsStream;
|
||||
std::streambuf* oldcout;
|
||||
std::streambuf* newcout;
|
||||
std::streambuf* oldcerr;
|
||||
std::streambuf* newcerr;
|
||||
static std::string out, err;
|
||||
static bool error;
|
||||
};
|
||||
|
||||
bool ProgramOptions::error = false;
|
||||
std::string ProgramOptions::out;
|
||||
std::string ProgramOptions::err;
|
||||
|
||||
#if defined (FC_OS_LINUX) || defined(FC_OS_BSD)
|
||||
QString myDecoderFunc(const QByteArray &localFileName)
|
||||
{
|
||||
QTextCodec* codec = QTextCodec::codecForName("UTF-8");
|
||||
return codec->toUnicode(localFileName);
|
||||
}
|
||||
|
||||
QByteArray myEncoderFunc(const QString &fileName)
|
||||
{
|
||||
QTextCodec* codec = QTextCodec::codecForName("UTF-8");
|
||||
return codec->fromUnicode(fileName);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
#if defined (FC_OS_LINUX) || defined(FC_OS_BSD)
|
||||
// Make sure to setup the Qt locale system before setting LANG and LC_ALL to C.
|
||||
// which is needed to use the system locale settings.
|
||||
(void)QLocale::system();
|
||||
// https://sourceforge.net/apps/mantisbt/free-cad/view.php?id=399
|
||||
// Because of setting LANG=C the Qt automagic to use the correct encoding
|
||||
// for file names is broken. This is a workaround to force the use of UTF-8 encoding
|
||||
QFile::setEncodingFunction(myEncoderFunc);
|
||||
QFile::setDecodingFunction(myDecoderFunc);
|
||||
// Make sure that we use '.' as decimal point. See also
|
||||
// http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=559846
|
||||
putenv("LANG=C");
|
||||
putenv("LC_ALL=C");
|
||||
putenv("PYTHONPATH=");
|
||||
#elif defined(FC_OS_MACOSX)
|
||||
(void)QLocale::system();
|
||||
putenv("LANG=C");
|
||||
putenv("LC_ALL=C");
|
||||
putenv("PYTHONPATH=");
|
||||
#else
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
_putenv("PYTHONPATH=");
|
||||
#endif
|
||||
|
||||
// Name and Version of the Application
|
||||
App::Application::Config()["ExeName"] = "FreeCAD";
|
||||
App::Application::Config()["ExeVendor"] = "FreeCAD";
|
||||
App::Application::Config()["AppDataSkipVendor"] = "true";
|
||||
App::Application::Config()["MaintainerUrl"] = "http://apps.sourceforge.net/mediawiki/free-cad/index.php?title=Main_Page";
|
||||
|
||||
// set the banner (for logging and console)
|
||||
App::Application::Config()["ConsoleBanner"] = sBanner;
|
||||
App::Application::Config()["AppIcon"] = "freecad";
|
||||
App::Application::Config()["SplashPicture"] = "freecadsplash";
|
||||
App::Application::Config()["StartWorkbench"] = "StartWorkbench";
|
||||
//App::Application::Config()["HiddenDockWindow"] = "Property editor";
|
||||
App::Application::Config()["SplashAlignment" ] = "Bottom|Left";
|
||||
App::Application::Config()["SplashTextColor" ] = "#ffffff"; // white
|
||||
|
||||
try {
|
||||
// Init phase ===========================================================
|
||||
// sets the default run mode for FC, starts with gui if not overridden in InitConfig...
|
||||
App::Application::Config()["RunMode"] = "Gui";
|
||||
|
||||
// Inits the Application
|
||||
ProgramOptions po;
|
||||
App::Application::init(argc,argv);
|
||||
Gui::Application::initApplication();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
// Popup an own dialog box instead of that one of Windows
|
||||
QApplication app(argc,argv);
|
||||
QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str());
|
||||
QString msg;
|
||||
msg = QObject::tr("While initializing %1 the following exception occurred: '%2'\n\n"
|
||||
"Python is searching for its files in the following directories:\n%3\n\n"
|
||||
"Python version information:\n%4\n")
|
||||
.arg(appName).arg(QString::fromUtf8(e.what()))
|
||||
.arg(QString::fromUtf8(Py_GetPath())).arg(QString::fromAscii(Py_GetVersion()));
|
||||
const char* pythonhome = getenv("PYTHONHOME");
|
||||
if (pythonhome) {
|
||||
msg += QObject::tr("\nThe environment variable PYTHONHOME is set to '%1'.")
|
||||
.arg(QString::fromUtf8(pythonhome));
|
||||
msg += QObject::tr("\nSetting this environment variable might cause Python to fail. "
|
||||
"Please contact your administrator to unset it on your system.\n\n");
|
||||
} else {
|
||||
msg += QObject::tr("\nPlease contact the application's support team for more information.\n\n");
|
||||
}
|
||||
|
||||
QMessageBox::critical(0, QObject::tr("Initialization of %1 failed").arg(appName), msg);
|
||||
exit(100);
|
||||
}
|
||||
catch (...) {
|
||||
// Popup an own dialog box instead of that one of Windows
|
||||
QApplication app(argc,argv);
|
||||
QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str());
|
||||
QString msg = QObject::tr("Unknown runtime error occurred while initializing %1.\n\n"
|
||||
"Please contact the application's support team for more information.\n\n").arg(appName);
|
||||
QMessageBox::critical(0, QObject::tr("Initialization of %1 failed").arg(appName), msg);
|
||||
exit(101);
|
||||
}
|
||||
|
||||
// Now it's time to read-in the file branding.xml if it exists
|
||||
Branding brand;
|
||||
QString path = QString::fromUtf8(App::GetApplication().GetHomePath());
|
||||
QFileInfo fi(path, QString::fromAscii("branding.xml"));
|
||||
if (brand.readFile(fi.absoluteFilePath())) {
|
||||
Branding::UserDefines ud = brand.getUserDefines();
|
||||
if (!ud.windowTitle.empty())
|
||||
App::Application::Config()["WindowTitle"] = ud.windowTitle;
|
||||
if (!ud.windowIcon.empty())
|
||||
App::Application::Config()["WindowIcon"] = ud.windowIcon;
|
||||
if (!ud.programLogo.empty())
|
||||
App::Application::Config()["ProgramLogo"] = ud.programLogo;
|
||||
if (!ud.splashScreen.empty())
|
||||
App::Application::Config()["SplashPicture"] = ud.splashScreen;
|
||||
}
|
||||
|
||||
// Run phase ===========================================================
|
||||
Base::RedirectStdOutput stdcout;
|
||||
Base::RedirectStdLog stdclog;
|
||||
Base::RedirectStdError stdcerr;
|
||||
std::streambuf* oldcout = std::cout.rdbuf(&stdcout);
|
||||
std::streambuf* oldclog = std::clog.rdbuf(&stdclog);
|
||||
std::streambuf* oldcerr = std::cerr.rdbuf(&stdcerr);
|
||||
|
||||
try {
|
||||
if (App::Application::Config()["RunMode"] == "Gui")
|
||||
Gui::Application::runApplication();
|
||||
else
|
||||
App::Application::runApplication();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
}
|
||||
catch (...) {
|
||||
Base::Console().Error("Application unexpectedly terminated\n");
|
||||
}
|
||||
|
||||
std::cout.rdbuf(oldcout);
|
||||
std::clog.rdbuf(oldclog);
|
||||
std::cerr.rdbuf(oldcerr);
|
||||
|
||||
// Destruction phase ===========================================================
|
||||
Base::Console().Log("%s terminating...\n",App::Application::Config()["ExeName"].c_str());
|
||||
|
||||
// cleans up
|
||||
App::Application::destruct();
|
||||
|
||||
Base::Console().Log("%s completely terminated\n",App::Application::Config()["ExeName"].c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
166
src/Main/MainPy.cpp
Normal file
166
src/Main/MainPy.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
/***************************************************************************
|
||||
* (c) Juergen Riegel (juergen.riegel@web.de) 2008 *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License (LGPL) *
|
||||
* as published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* for detail see the LICENCE text file. *
|
||||
* *
|
||||
* FreeCAD 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 FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
* Juergen Riegel 2002 *
|
||||
***************************************************************************/
|
||||
#include <FCConfig.h>
|
||||
|
||||
#ifdef _PreComp_
|
||||
# undef _PreComp_
|
||||
#endif
|
||||
|
||||
#ifdef FC_OS_LINUX
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef FC_OS_MACOSX
|
||||
# include <mach-o/dyld.h>
|
||||
# include <string>
|
||||
#endif
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
// FreeCAD Base header
|
||||
#include <Base/Exception.h>
|
||||
#include <App/Application.h>
|
||||
|
||||
|
||||
#if defined(FC_OS_WIN32)
|
||||
# include <windows.h>
|
||||
|
||||
/** DllMain is called when DLL is loaded
|
||||
*/
|
||||
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
switch (ul_reason_for_call) {
|
||||
case DLL_PROCESS_ATTACH: {
|
||||
// This name is preliminary, we pass it to Application::init() in initFreeCAD()
|
||||
// which does the rest.
|
||||
char szFileName [MAX_PATH];
|
||||
GetModuleFileName((HMODULE)hModule, szFileName, MAX_PATH-1);
|
||||
App::Application::Config()["AppHomePath"] = szFileName;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#elif defined(FC_OS_LINUX)
|
||||
# ifndef GNU_SOURCE
|
||||
# define GNU_SOURCE
|
||||
# endif
|
||||
# include <dlfcn.h>
|
||||
#elif defined(FC_OS_CYGWIN)
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef FC_OS_WIN32
|
||||
# define MainExport __declspec(dllexport)
|
||||
#else
|
||||
# define MainExport
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void MainExport initFreeCAD() {
|
||||
|
||||
// Init phase ===========================================================
|
||||
App::Application::Config()["ExeName"] = "FreeCAD";
|
||||
App::Application::Config()["ExeVendor"] = "FreeCAD";
|
||||
App::Application::Config()["AppDataSkipVendor"] = "true";
|
||||
|
||||
|
||||
int argc=1;
|
||||
char** argv;
|
||||
argv = (char**)malloc(sizeof(char*)* (argc+1));
|
||||
|
||||
#if defined(FC_OS_WIN32)
|
||||
argv[0] = (char*)malloc(MAX_PATH);
|
||||
strncpy(argv[0],App::Application::Config()["AppHomePath"].c_str(),MAX_PATH);
|
||||
argv[0][MAX_PATH-1] = '\0'; // ensure null termination
|
||||
#elif defined(FC_OS_CYGWIN)
|
||||
HMODULE hModule = GetModuleHandle("FreeCAD.dll");
|
||||
char szFileName [MAX_PATH];
|
||||
GetModuleFileName(hModule, szFileName, MAX_PATH-1);
|
||||
argv[0] = (char*)malloc(MAX_PATH);
|
||||
strncpy(argv[0],szFileName,MAX_PATH);
|
||||
argv[0][MAX_PATH-1] = '\0'; // ensure null termination
|
||||
#elif defined(FC_OS_LINUX)
|
||||
// get whole path of the library
|
||||
Dl_info info;
|
||||
int ret = dladdr((void*)initFreeCAD, &info);
|
||||
if ((ret == 0) || (!info.dli_fname)) {
|
||||
PyErr_SetString(PyExc_ImportError, "Cannot get path of the FreeCAD module!");
|
||||
return;
|
||||
}
|
||||
|
||||
argv[0] = (char*)malloc(PATH_MAX);
|
||||
strncpy(argv[0], info.dli_fname,PATH_MAX);
|
||||
argv[0][PATH_MAX-1] = '\0'; // ensure null termination
|
||||
#elif defined(FC_OS_MACOSX)
|
||||
uint32_t sz = 0;
|
||||
char *buf;
|
||||
|
||||
_NSGetExecutablePath(NULL, &sz);
|
||||
buf = (char*) malloc(++sz);
|
||||
int err=_NSGetExecutablePath(buf, &sz);
|
||||
if (err != 0) {
|
||||
PyErr_SetString(PyExc_ImportError, "Cannot get path of the FreeCAD module!");
|
||||
return;
|
||||
}
|
||||
|
||||
argv[0] = (char*)malloc(PATH_MAX);
|
||||
strncpy(argv[0], buf, PATH_MAX);
|
||||
argv[0][PATH_MAX-1] = '\0'; // ensure null termination
|
||||
free(buf);
|
||||
#else
|
||||
# error "Implement: Retrieve the path of the module for your platform."
|
||||
#endif
|
||||
argv[argc] = 0;
|
||||
|
||||
try {
|
||||
// Inits the Application
|
||||
App::Application::init(argc,argv);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
std::string appName = App::Application::Config()["ExeName"];
|
||||
std::stringstream msg;
|
||||
msg << "While initializing " << appName << " the following exception occurred: '"
|
||||
<< e.what() << "'\n\n";
|
||||
msg << "\nPlease contact the application's support team for more information.\n\n";
|
||||
printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str());
|
||||
}
|
||||
|
||||
free(argv[0]);
|
||||
free(argv);
|
||||
|
||||
return;
|
||||
} //InitFreeCAD....
|
||||
} // extern "C"
|
||||
|
||||
72
src/Main/Makefile.am
Normal file
72
src/Main/Makefile.am
Normal file
@@ -0,0 +1,72 @@
|
||||
bin_PROGRAMS=FreeCAD FreeCADCmd
|
||||
lib_LTLIBRARIES=FreeCAD.la FreeCADGui.la
|
||||
|
||||
#--------------------------------------------------------------------------------------
|
||||
FreeCAD_SOURCES= \
|
||||
MainGui.cpp
|
||||
|
||||
# the library search path.
|
||||
FreeCAD_LDFLAGS = -L../Base -L../App -L../Gui $(QT_LIBS) $(all_libraries)
|
||||
|
||||
FreeCAD_LDADD=\
|
||||
-l@PYTHON_LIB@ \
|
||||
-lFreeCADBase \
|
||||
-lFreeCADApp \
|
||||
-lFreeCADGui
|
||||
|
||||
#--------------------------------------------------------------------------------------
|
||||
FreeCADCmd_SOURCES= \
|
||||
MainCmd.cpp
|
||||
|
||||
# the library search path.
|
||||
FreeCADCmd_LDFLAGS = -L../Base -L../App $(all_libraries)
|
||||
|
||||
FreeCADCmd_LDADD=\
|
||||
-l@PYTHON_LIB@ \
|
||||
-lFreeCADBase \
|
||||
-lFreeCADApp
|
||||
|
||||
#--------------------------------------------------------------------------------------
|
||||
FreeCAD_la_SOURCES= \
|
||||
MainPy.cpp
|
||||
|
||||
# the library search path.
|
||||
FreeCAD_la_LDFLAGS = -L../Base -L../App $(all_libraries) -version-info @LIB_CURRENT@:@LIB_REVISION@:@LIB_AGE@ -module -avoid-version
|
||||
|
||||
FreeCAD_la_LIBADD=\
|
||||
-ldl \
|
||||
-l@PYTHON_LIB@ \
|
||||
-lFreeCADBase \
|
||||
-lFreeCADApp
|
||||
#--------------------------------------------------------------------------------------
|
||||
FreeCADGui_la_SOURCES= \
|
||||
FreeCADGuiPy.cpp
|
||||
|
||||
# the library search path.
|
||||
FreeCADGui_la_LDFLAGS = -L../Base -L../App -L../Gui $(QT_LIBS) \
|
||||
$(sim_ac_coin_ldflags) $(sim_ac_coin_libs) \
|
||||
$(sim_ac_soqt_ldflags) $(sim_ac_soqt_libs) \
|
||||
$(all_libraries) -version-info @LIB_CURRENT@:@LIB_REVISION@:@LIB_AGE@ -module -avoid-version
|
||||
|
||||
FreeCADGui_la_LIBADD=\
|
||||
-ldl \
|
||||
-l@PYTHON_LIB@ \
|
||||
-lFreeCADBase \
|
||||
-lFreeCADApp \
|
||||
-lFreeCADGui
|
||||
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
# set the include path found by configure
|
||||
AM_CXXFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src \
|
||||
$(QT_CXXFLAGS) $(all_includes) \
|
||||
-I$(sim_ac_coin_includedir) -I$(sim_ac_soqt_includedir)
|
||||
|
||||
EXTRA_DIST = \
|
||||
res/FreeCAD.exe.manifest \
|
||||
res/FreeCADD.exe.manifest \
|
||||
freecad.rc \
|
||||
CMakeLists.txt \
|
||||
core-main.dox \
|
||||
icon.ico
|
||||
|
||||
2
src/Main/core-main.dox
Normal file
2
src/Main/core-main.dox
Normal file
@@ -0,0 +1,2 @@
|
||||
/** \defgroup MAIN Global application level
|
||||
* \ingroup CORE */
|
||||
4
src/Main/freecad.rc
Normal file
4
src/Main/freecad.rc
Normal file
@@ -0,0 +1,4 @@
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDI_ICON1 ICON DISCARDABLE "icon.ico"
|
||||
|
||||
BIN
src/Main/icon.ico
Normal file
BIN
src/Main/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
10
src/Main/res/FreeCAD.exe.manifest
Normal file
10
src/Main/res/FreeCAD.exe.manifest
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<assemblyIdentity version="0.7.0.0" processorArchitecture="X86" name="FreeCAD 0.7" type="win32" />
|
||||
<description>CAD Application</description>
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" />
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
</assembly>
|
||||
22
src/Main/res/FreeCADD.exe.manifest
Normal file
22
src/Main/res/FreeCADD.exe.manifest
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<assemblyIdentity
|
||||
version="1.0.0.0"
|
||||
processorArchitecture="X86"
|
||||
name="FreeCAD"
|
||||
type="win32"
|
||||
/>
|
||||
<description>CAD Application</description>
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity
|
||||
type="win32"
|
||||
name="Microsoft.Windows.Common-Controls"
|
||||
version="6.0.0.0"
|
||||
processorArchitecture="X86"
|
||||
publicKeyToken="6595b64144ccf1df"
|
||||
language="*"
|
||||
/>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
</assembly>
|
||||
Reference in New Issue
Block a user