-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvg_cmd.py
129 lines (105 loc) · 3.89 KB
/
vg_cmd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# -*- coding: utf-8 -*-
###################################################################################
#
# vg_cmd.py
#
# Copyright 2021 David Vachulka ([email protected])
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
###################################################################################
__title__ = "VariantGenerator"
__author__ = "David Vachulka"
__url__ = "https://github.com/archdvx/VariantGenerator"
__date__ = "2021.09.17"
__version__ = "1.01"
version = 1.01
from PySide import QtCore, QtGui
import os
import FreeCAD
from vg_bodygenerator import BodyGenerator
from vg_partgenerator import PartGenerator
if FreeCAD.GuiUp:
from FreeCAD import Gui
def QT_TRANSLATE_NOOP(scope, text):
return text
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
__dir__ = os.path.dirname(__file__)
iconPath = os.path.join(__dir__, 'icons')
keepToolbar = False
class BodyCommandClass(object):
def __init__(self):
pass
def GetResources(self):
return {'Pixmap': os.path.join(iconPath, 'body.svg'),
'MenuText': QT_TRANSLATE_NOOP("BodyGenerator", "Generate files from &bodies"),
'ToolTip': QT_TRANSLATE_NOOP("BodyGenerator",
"Generate files from bodies by variables from CSV file")}
def Activated(self):
if self.has_some_body():
dlg = BodyGenerator()
dlg.exec_()
else:
QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(), translate("VG", "Information"),
translate("VG", "Document hasn't any body"))
return
def IsActive(self):
if not FreeCAD.ActiveDocument:
return False
return True
def has_some_body(self):
objs = FreeCAD.ActiveDocument.Objects
for obj in objs:
if obj.TypeId == "PartDesign::Body":
return True
return False
class PartCommandClass(object):
def __init__(self):
pass
def GetResources(self):
return {'Pixmap': os.path.join(iconPath, 'part.svg'),
'MenuText': QT_TRANSLATE_NOOP("PartGenerator", "Generate files from &parts"),
'ToolTip': QT_TRANSLATE_NOOP("PartGenerator",
"Generate files from parts by variables from CSV file")}
def Activated(self):
if self.has_some_part():
dlg = PartGenerator()
dlg.exec_()
else:
QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(), translate("VG", "Information"),
translate("VG", "Document hasn't any part"))
return
def IsActive(self):
if not FreeCAD.ActiveDocument:
return False
return True
def has_some_part(self):
objs = FreeCAD.ActiveDocument.Objects
for obj in objs:
if obj.TypeId == "App::Part":
return True
return False
def initialize():
if FreeCAD.GuiUp:
Gui.addCommand("BodyGenerator", BodyCommandClass())
Gui.addCommand("PartGenerator", PartCommandClass())
Gui.updateLocale()
initialize()