FreeCAD

Форк
0
/
AppMeshGui.cpp 
210 строк · 7.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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
#ifndef _PreComp_
25
#include <Inventor/SoDB.h>
26
#include <Inventor/SoInput.h>
27
#include <Inventor/annex/ForeignFiles/SoSTLFileKit.h>
28
#include <Inventor/nodes/SoSeparator.h>
29

30
#include <QApplication>
31
#endif
32

33
#include <Base/Console.h>
34
#include <Base/Interpreter.h>
35
#include <Base/PyObjectBase.h>
36
#include <Gui/Application.h>
37
#include <Gui/BitmapFactory.h>
38
#include <Gui/Language/Translator.h>
39
#include <Gui/WidgetFactory.h>
40

41
#include "DlgEvaluateMeshImp.h"
42
#include "DlgSettingsImportExportImp.h"
43
#include "DlgSettingsMeshView.h"
44
#include "PropertyEditorMesh.h"
45
#include "SoFCIndexedFaceSet.h"
46
#include "SoFCMeshObject.h"
47
#include "SoPolygon.h"
48
#include "ThumbnailExtension.h"
49
#include "ViewProvider.h"
50
#include "ViewProviderCurvature.h"
51
#include "ViewProviderDefects.h"
52
#include "ViewProviderMeshFaceSet.h"
53
#include "ViewProviderPython.h"
54
#include "ViewProviderTransform.h"
55
#include "ViewProviderTransformDemolding.h"
56
#include "Workbench.h"
57
#include "images.h"
58

59

60
// use a different name to CreateCommand()
61
void CreateMeshCommands();
62

63
void loadMeshResource()
64
{
65
    // add resources and reloads the translators
66
    Q_INIT_RESOURCE(Mesh);
67
    Q_INIT_RESOURCE(Mesh_translation);
68
    Gui::Translator::instance()->refresh();
69
}
70

71
namespace MeshGui
72
{
73
class Module: public Py::ExtensionModule<Module>
74
{
75
public:
76
    Module()
77
        : Py::ExtensionModule<Module>("MeshGui")
78
    {
79
        add_varargs_method("convertToSTL", &Module::convertToSTL, "Convert a scene into an STL.");
80
        initialize("This module is the MeshGui module.");  // register with Python
81
    }
82

83
private:
84
    Py::Object convertToSTL(const Py::Tuple& args)
85
    {
86
        char* inname {};
87
        char* outname {};
88
        if (!PyArg_ParseTuple(args.ptr(), "etet", "utf-8", &inname, "utf-8", &outname)) {
89
            throw Py::Exception();
90
        }
91
        std::string inputName = std::string(inname);
92
        PyMem_Free(inname);
93
        std::string outputName = std::string(outname);
94
        PyMem_Free(outname);
95

96
        bool ok = false;
97
        SoInput in;
98
        if (in.openFile(inputName.c_str())) {
99
            SoSeparator* node = SoDB::readAll(&in);
100
            if (node) {
101
                node->ref();
102
                SoSTLFileKit* stlKit = new SoSTLFileKit();
103
                stlKit->ref();
104
                ok = stlKit->readScene(node);
105
                stlKit->writeFile(outputName.c_str());
106
                stlKit->unref();
107
                node->unref();
108
            }
109
        }
110

111
        return Py::Boolean(ok);  // NOLINT
112
    }
113
};
114

115
PyObject* initModule()
116
{
117
    return Base::Interpreter().addModule(new Module);
118
}
119

120
}  // namespace MeshGui
121

122
/* Python entry */
123
PyMOD_INIT_FUNC(MeshGui)
124
{
125
    if (!Gui::Application::Instance) {
126
        PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
127
        PyMOD_Return(nullptr);
128
    }
129

130
    // load dependent module
131
    try {
132
        Base::Interpreter().loadModule("Mesh");
133
    }
134
    catch (const Base::Exception& e) {
135
        PyErr_SetString(PyExc_ImportError, e.what());
136
        PyMOD_Return(nullptr);
137
    }
138
    PyObject* mod = MeshGui::initModule();
139
    Base::Console().Log("Loading GUI of Mesh module... done\n");
140

141
    // Register icons
142
    Gui::BitmapFactory().addXPM("mesh_fillhole", mesh_fillhole);
143

144
    // instantiating the commands
145
    CreateMeshCommands();
146
    if (qApp) {
147
        (void)new MeshGui::CleanupHandler;
148
    }
149

150
    // NOLINTBEGIN
151
    // try to instantiate flat-mesh commands
152
    try {
153
        Base::Interpreter().runString("import MeshFlatteningCommand");
154
    }
155
    catch (Base::PyException& err) {
156
        err.ReportException();
157
    }
158

159
    // register preferences pages
160
    (void)new Gui::PrefPageProducer<MeshGui::DlgSettingsMeshView>(
161
        QT_TRANSLATE_NOOP("QObject", "Display"));
162
    (void)new Gui::PrefPageProducer<MeshGui::DlgSettingsImportExport>(
163
        QT_TRANSLATE_NOOP("QObject", "Import-Export"));
164

165
    Mesh::Extension3MFFactory::addProducer(new MeshGui::ThumbnailExtensionProducer);
166
    // NOLINTEND
167

168
    // clang-format off
169
    MeshGui::SoFCMeshObjectElement              ::initClass();
170
    MeshGui::SoSFMeshObject                     ::initClass();
171
    MeshGui::SoFCMeshObjectNode                 ::initClass();
172
    MeshGui::SoFCMeshObjectShape                ::initClass();
173
    MeshGui::SoFCMeshSegmentShape               ::initClass();
174
    MeshGui::SoFCMeshObjectBoundary             ::initClass();
175
    MeshGui::SoFCMaterialEngine                 ::initClass();
176
    MeshGui::SoFCIndexedFaceSet                 ::initClass();
177
    MeshGui::SoFCMeshPickNode                   ::initClass();
178
    MeshGui::SoFCMeshGridNode                   ::initClass();
179
    MeshGui::SoPolygon                          ::initClass();
180
    MeshGui::PropertyMeshKernelItem             ::init();
181
    MeshGui::ViewProviderMesh                   ::init();
182
    MeshGui::ViewProviderMeshObject             ::init();
183
    MeshGui::ViewProviderIndexedFaceSet         ::init();
184
    MeshGui::ViewProviderMeshFaceSet            ::init();
185
    MeshGui::ViewProviderPython                 ::init();
186
    MeshGui::ViewProviderExport                 ::init();
187
    MeshGui::ViewProviderMeshCurvature          ::init();
188
    MeshGui::ViewProviderMeshTransform          ::init();
189
    MeshGui::ViewProviderMeshTransformDemolding ::init();
190
    MeshGui::ViewProviderMeshDefects            ::init();
191
    MeshGui::ViewProviderMeshOrientation        ::init();
192
    MeshGui::ViewProviderMeshNonManifolds       ::init();
193
    MeshGui::ViewProviderMeshNonManifoldPoints  ::init();
194
    MeshGui::ViewProviderMeshDuplicatedFaces    ::init();
195
    MeshGui::ViewProviderMeshDuplicatedPoints   ::init();
196
    MeshGui::ViewProviderMeshDegenerations      ::init();
197
    MeshGui::ViewProviderMeshIndices            ::init();
198
    MeshGui::ViewProviderMeshSelfIntersections  ::init();
199
    MeshGui::ViewProviderMeshFolds              ::init();
200
    MeshGui::Workbench                          ::init();
201
    Gui::ViewProviderBuilder::add(
202
        Mesh::PropertyMeshKernel::getClassTypeId(),
203
        MeshGui::ViewProviderMeshFaceSet::getClassTypeId());
204

205
    // add resources and reloads the translators
206
    loadMeshResource();
207
    // clang-format on
208

209
    PyMOD_Return(mod);
210
}
211

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

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

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

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