-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWireExit.py
125 lines (95 loc) · 4.89 KB
/
WireExit.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
# -*- coding: utf-8 -*-
__title__ = "Create Exit path"
__author__ = "Andrew Shkolik & Andrei Bezborodov"
__license__ = "LGPL 2.1"
__doc__ = "Create Exit path from selected point."
__usage__ = """Select start point on left or right working plane and activate tool."""
import FreeCAD
App=FreeCAD
import FreeCADGui
Gui=FreeCADGui
import Part
import FoamCutViewProviders
import FoamCutBase
import utilities
from utilities import getWorkingPlanes, getAllSelectedObjects, isCommonPoint
class WireExit(FoamCutBase.FoamCutMovementBaseObject):
def __init__(self, obj, exit, jobName):
super().__init__(obj, jobName)
obj.Type = "Exit"
obj.addProperty("App::PropertyDistance", "SafeHeight", "Task", "Safe height")
obj.addProperty("App::PropertyLinkSub", "ExitPoint", "Task", "Exit Point").ExitPoint = exit
config = self.getConfigName(obj)
obj.setExpression(".SafeHeight", u"<<{}>>.SafeHeight".format(config))
obj.Proxy = self
self.execute(obj)
def execute(self, obj):
if obj.SafeHeight > 0:
(isLeft, vertex, oppositeVertex, wp) = self.findOppositeVertexes(obj, obj.ExitPoint[0], obj.ExitPoint[0].getSubObject(obj.ExitPoint[1][0]))
if oppositeVertex is None:
App.Console.PrintError("ERROR:\n Unable to locate opposite vertex.\n")
edges = []
if isCommonPoint(vertex, oppositeVertex):
edges.append(Part.makeLine(App.Vector(vertex.X, vertex.Y, obj.SafeHeight), vertex.Point))
else:
edges.append(Part.makeLine(App.Vector(vertex.X, vertex.Y, obj.SafeHeight), vertex.Point) if isLeft else Part.makeLine(App.Vector(oppositeVertex.X, oppositeVertex.Y, obj.SafeHeight), oppositeVertex.Point))
edges.append(Part.makeLine(App.Vector(vertex.X, vertex.Y, obj.SafeHeight), vertex.Point) if not isLeft else Part.makeLine(App.Vector(oppositeVertex.X, oppositeVertex.Y, obj.SafeHeight), oppositeVertex.Point))
self.createShape(obj, edges, wp, (255, 0, 0))
class WireExitVP(FoamCutViewProviders.FoamCutMovementViewProvider):
def getIcon(self):
return utilities.getIconPath("exit.svg")
def claimChildren(self):
return [self.Object.ExitPoint[0]] if self.Object.ExitPoint is not None and len(self.Object.ExitPoint) > 0 else None
class MakeExit():
"""Make Exit"""
def GetResources(self):
return {"Pixmap" : utilities.getIconPath("exit.svg"), # the name of a svg file available in the resources
'Accel' : "", # a default shortcut (optional)
"MenuText": "Create exit",
"ToolTip" : "Create exit path object from selected entry point"}
def Activated(self):
group = Gui.ActiveDocument.ActiveView.getActiveObject("group")
setActive = False
# - if machine is not active, try to select first one in a document
if group is None or group.Type != "Job":
group = App.ActiveDocument.getObject("Job")
setActive = True
if group is not None and group.Type == "Job":
if setActive:
Gui.ActiveDocument.ActiveView.setActiveObject("group", group)
# - Get selecttion
objects = utilities.getAllSelectedObjects()
# - Create object
exit = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Exit")
WireExit(exit, objects[0], group.Name)
WireExitVP(exit.ViewObject)
exit.ViewObject.PointSize = 4
group.addObject(exit)
App.ActiveDocument.recompute()
Gui.Selection.clearSelection()
def IsActive(self):
if FreeCAD.ActiveDocument is None:
return False
else:
group = Gui.ActiveDocument.ActiveView.getActiveObject("group")
# - if machine is not active, try to select first one in a document
if group is None or group.Type != "Job":
group = App.ActiveDocument.getObject("Job")
if group is not None and group.Type == "Job":
# - Get selecttion
objects = getAllSelectedObjects()
# - nothing selected
if len(objects) == 0:
return False
object = objects[0]
parent = object[0]
vertex = parent.getSubObject(object[1][0])
# - Check object type
if not issubclass(type(vertex), Part.Vertex):
return False
wp = getWorkingPlanes(group, App.ActiveDocument)
if wp is None or len(wp) != 2:
return False
return True
return False
Gui.addCommand("MakeExit", MakeExit())