-
Notifications
You must be signed in to change notification settings - Fork 5
/
Design456_SelectionGate.py
169 lines (142 loc) · 6.29 KB
/
Design456_SelectionGate.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
#
# ***************************************************************************
# * *
# * This file is a part of the Open Source Design456 Workbench - FreeCAD. *
# * *
# * Copyright (C) 2022 *
# * *
# * *
# * This library is free software; you can redistribute it and/or *
# * modify it under the terms of the GNU Lesser 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 *
# * Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Lesser General Public *
# * License along with this library; if not, If not, see *
# * <http://www.gnu.org/licenses/>. *
# * *
# * Author : Mariwan Jalal mariwan.jalal@gmail.com *
# **************************************************************************
# This will be used to avoid user select wrong object, Body, Face, Edges or Vertices
import os
import FreeCAD as App
import FreeCADGui as Gui
import Design456Init
from PySide import QtGui, QtCore
__updated__ = '2021-12-31 08:56:37'
# Toolbar class
class Design456_SelectionGate:
list = ["Design456_VertexSelectionMode",
"Design456_EdgesSelectionMode",
"Design456_FaceSelectionMode",
"Design456_BodySelectionMode",
"Design456_TopSideView",
"Design456_BottomView",
"Design456_LeftSideView",
"Design456_RightSideView",
"Design456_FrontSideView",
"Design456_BackSideView"
]
"""Design456_SelectionGate"""
def GetResources(self):
import Design456Init
return{
'Pixmap': Design456Init.ICON_PATH + '2D_Drawing.svg',
'MenuText': '2Ddrawing',
'ToolTip': '2Ddrawing'
}
def Activated(self):
self.appendToolbar("Design456_SelectionGate", self.list)
# Allow Everything
class GateSelect0:
def Activated(self):
import FACE_D as faced
try:
Gui.Selection.removeSelectionGate()
except Exception as err:
App.Console.PrintError("'BodySelection Mode' Failed. "
"{err}\n".format(err=str(err)))
def GetResources(self):
return {
'Pixmap': Design456Init.ICON_PATH + 'SelectionModeBody.svg',
'MenuText': 'Body Selection Mode',
'ToolTip': 'Body Selection Mode'
}
# Only Faces are allowed
class GateSelect1:
def Activated(self):
import FACE_D as faced
try:
filter = Gui.Selection.Filter(
'SELECT Part::Feature SUBELEMENT Face')
Gui.Selection.addSelectionGate(filter)
except Exception as err:
App.Console.PrintError("'FaceSelection Mode' Failed. "
"{err}\n".format(err=str(err)))
def GetResources(self):
return {
'Pixmap': Design456Init.ICON_PATH + 'SelectionModeFace.svg',
'MenuText': 'FaceSelection Mode',
'ToolTip': 'FaceSelection Mode'
}
# Only Edges are allowed
class GateSelect2:
def Activated(self):
import FACE_D as faced
try:
filter = Gui.Selection.Filter(
'SELECT Part::Feature SUBELEMENT Edge')
Gui.Selection.addSelectionGate(filter)
except Exception as err:
App.Console.PrintError("'EdgeSelection Mode' Failed. "
"{err}\n".format(err=str(err)))
def GetResources(self):
return {
'Pixmap': Design456Init.ICON_PATH + 'SelectionModeEdges.svg',
'MenuText': 'EdgeSelection Mode',
'ToolTip': 'EdgeSelection Mode'
}
# Only Vertices are allowed
class GateSelect3:
def Activated(self):
import FACE_D as faced
try:
filter = Gui.Selection.Filter(
'SELECT Part::Feature SUBELEMENT Vertex')
Gui.Selection.addSelectionGate(filter)
except Exception as err:
App.Console.PrintError("'VertexSelection Mode' Failed. "
"{err}\n".format(err=str(err)))
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
def GetResources(self):
return {
'Pixmap': Design456Init.ICON_PATH + 'SelectionModeVertex.svg',
'MenuText': 'VertexSelection Mode',
'ToolTip': 'VertexSelection Mode'
}
Gui.addCommand('Design456_BodySelectionMode', GateSelect0())
Gui.addCommand('Design456_FaceSelectionMode', GateSelect1())
Gui.addCommand('Design456_EdgesSelectionMode', GateSelect2())
Gui.addCommand('Design456_VertexSelectionMode', GateSelect3())
""" Help on how to use this class
'SELECT Part::Feature SUBELEMENT Edge',
'SELECT Robot::RobotObject'
You can also set an instance of SelectionFilter:
filter = Gui.Selection.Filter('SELECT Part::Feature SUBELEMENT Edge')
Gui.Selection.addSelectionGate(filter)
And the most flexible approach is to write your own selection gate class
that implements the method 'allow'
class Gate:
def allow(self,doc,obj,sub):
return (sub[0:4] == 'Face')
Gui.Selection.addSelectionGate(Gate())
"""