FreeCAD

Форк
0
/
AppSketcherGui.cpp 
153 строки · 6.0 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#include <Base/Console.h>
26
#include <Base/Interpreter.h>
27
#include <Base/PyObjectBase.h>
28
#include <Gui/Application.h>
29
#include <Gui/BitmapFactory.h>
30
#include <Gui/Language/Translator.h>
31
#include <Gui/WidgetFactory.h>
32

33
#include "PropertyConstraintListItem.h"
34
#include "SketcherSettings.h"
35
#include "SoZoomTranslation.h"
36
#include "ViewProviderPython.h"
37
#include "ViewProviderSketch.h"
38
#include "ViewProviderSketchGeometryExtension.h"
39
#include "ViewProviderSketchGeometryExtensionPy.h"
40
#include "Workbench.h"
41

42

43
// create the commands
44
void CreateSketcherCommands();
45
void CreateSketcherCommandsCreateGeo();
46
void CreateSketcherCommandsConstraints();
47
void CreateSketcherCommandsConstraintAccel();
48
void CreateSketcherCommandsAlterGeo();
49
void CreateSketcherCommandsBSpline();
50
void CreateSketcherCommandsOverlay();
51
void CreateSketcherCommandsVirtualSpace();
52

53
void loadSketcherResource()
54
{
55
    // add resources and reloads the translators
56
    Q_INIT_RESOURCE(Sketcher);
57
    Q_INIT_RESOURCE(Sketcher_translation);
58
    Gui::Translator::instance()->refresh();
59
}
60

61
namespace SketcherGui
62
{
63
class Module: public Py::ExtensionModule<Module>
64
{
65
public:
66
    Module()
67
        : Py::ExtensionModule<Module>("SketcherGui")
68
    {
69
        initialize("This module is the SketcherGui module.");  // register with Python
70
    }
71

72
    ~Module() override
73
    {}
74

75
private:
76
};
77

78
PyObject* initModule()
79
{
80
    return Base::Interpreter().addModule(new Module);
81
}
82

83
}  // namespace SketcherGui
84

85
/* Python entry */
86
PyMOD_INIT_FUNC(SketcherGui)
87
{
88
    if (!Gui::Application::Instance) {
89
        PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
90
        PyMOD_Return(nullptr);
91
    }
92
    try {
93
        Base::Interpreter().runString("import PartGui");
94
        Base::Interpreter().runString("import Sketcher");
95
    }
96
    catch (const Base::Exception& e) {
97
        PyErr_SetString(PyExc_ImportError, e.what());
98
        PyMOD_Return(nullptr);
99
    }
100

101
    PyObject* sketcherGuiModule = SketcherGui::initModule();
102
    Base::Console().Log("Loading GUI of Sketcher module... done\n");
103

104
    Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/constraints"));
105
    Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/elements"));
106
    Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/general"));
107
    Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/geometry"));
108
    // Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/obsolete"));
109
    Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/pointers"));
110
    Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/splines"));
111
    Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/tools"));
112
    Gui::BitmapFactory().addPath(QString::fromLatin1(":/icons/overlay"));
113

114
    // instantiating the commands
115
    CreateSketcherCommands();
116
    CreateSketcherCommandsCreateGeo();
117
    CreateSketcherCommandsConstraints();
118
    CreateSketcherCommandsAlterGeo();
119
    CreateSketcherCommandsConstraintAccel();
120
    CreateSketcherCommandsBSpline();
121
    CreateSketcherCommandsOverlay();
122
    CreateSketcherCommandsVirtualSpace();
123

124
    SketcherGui::Workbench::init();
125

126
    // Add Types to module
127
    Base::Interpreter().addType(&SketcherGui::ViewProviderSketchGeometryExtensionPy ::Type,
128
                                sketcherGuiModule,
129
                                "ViewProviderSketchGeometryExtension");
130

131
    // init objects
132
    SketcherGui::ViewProviderSketch ::init();
133
    SketcherGui::ViewProviderPython ::init();
134
    SketcherGui::ViewProviderCustom ::init();
135
    SketcherGui::ViewProviderCustomPython ::init();
136
    SketcherGui::SoZoomTranslation ::initClass();
137
    SketcherGui::PropertyConstraintListItem ::init();
138
    SketcherGui::ViewProviderSketchGeometryExtension ::init();
139

140
    (void)new Gui::PrefPageProducer<SketcherGui::SketcherSettings>(
141
        QT_TRANSLATE_NOOP("QObject", "Sketcher"));
142
    (void)new Gui::PrefPageProducer<SketcherGui::SketcherSettingsGrid>(
143
        QT_TRANSLATE_NOOP("QObject", "Sketcher"));
144
    (void)new Gui::PrefPageProducer<SketcherGui::SketcherSettingsDisplay>(
145
        QT_TRANSLATE_NOOP("QObject", "Sketcher"));
146
    (void)new Gui::PrefPageProducer<SketcherGui::SketcherSettingsAppearance>(
147
        QT_TRANSLATE_NOOP("QObject", "Sketcher"));
148

149
    // add resources and reloads the translators
150
    loadSketcherResource();
151

152
    PyMOD_Return(sketcherGuiModule);
153
}
154

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.