-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWireJoin.py
135 lines (103 loc) · 5.22 KB
/
WireJoin.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
# -*- coding: utf-8 -*-
__title__ = "Join 2 points with path"
__author__ = "Andrew Shkolik & Andrei Bezborodov LGPL"
__license__ = "LGPL 2.1"
__doc__ = "Join 2 selected points with path."
__usage__ = """Select two points on left or right plane and activate tool."""
import FreeCAD
App=FreeCAD
import FreeCADGui
Gui=FreeCADGui
import Part
import FoamCutViewProviders
import FoamCutBase
import utilities
from utilities import getAllSelectedObjects, isCommonPoint, isMovement
class WireJoin(FoamCutBase.FoamCutMovementBaseObject):
def __init__(self, obj, start, end, jobName):
super().__init__(obj, jobName)
obj.Type = "Join"
obj.addProperty("App::PropertyLength", "FieldWidth","","",5)
# - Options
obj.addProperty("App::PropertySpeed", "FeedRate", "Options", "Feed rate" )
obj.addProperty("App::PropertyInteger", "WirePower", "Options", "Wire power")
obj.addProperty("App::PropertyLinkSub", "StartPoint", "Task", "Start Point").StartPoint = start
obj.addProperty("App::PropertyLinkSub", "EndPoint", "Task", "Start Point").EndPoint = end
config = self.getConfigName(obj)
obj.setExpression(".FeedRate", u"<<{}>>.FeedRateCut".format(config))
obj.setExpression(".WirePower", u"<<{}>>.WireMinPower".format(config))
obj.setExpression(".FieldWidth", u"<<{}>>.FieldWidth".format(config))
obj.Proxy = self
self.execute(obj)
def execute(self, obj):
(isLeftA, vertexA, oppositeVertexA, wp) = self.findOppositeVertexes(obj, obj.StartPoint[0], obj.StartPoint[0].getSubObject(obj.StartPoint[1][0]))
(isLeftB, vertexB, oppositeVertexB, wp) = self.findOppositeVertexes(obj, obj.EndPoint[0], obj.EndPoint[0].getSubObject(obj.EndPoint[1][0]))
if oppositeVertexA is None:
App.Console.PrintError("ERROR:\n Unable to locate opposite vertex for the start point.\n")
if oppositeVertexB is None:
App.Console.PrintError("ERROR:\n Unable to locate opposite vertex for the end point.\n")
if isLeftA != isLeftB:
App.Console.PrintError("ERROR:\n Start and End points should be on one side.\n")
edges = []
if isCommonPoint(vertexA, oppositeVertexA):
edges.append(Part.makeLine(vertexA.Point, vertexB.Point))
else:
edges.append(Part.makeLine(vertexA.Point, vertexB.Point))
edges.append(Part.makeLine(oppositeVertexA.Point, oppositeVertexB.Point))
self.createShape(obj, edges, wp, (35, 0, 205))
class WireJoinVP(FoamCutViewProviders.FoamCutMovementViewProvider):
def getIcon(self):
return utilities.getIconPath("join.svg")
def claimChildren(self):
if (self.Object.StartPoint is not None and len(self.Object.StartPoint) > 0
and self.Object.EndPoint is not None and len(self.Object.EndPoint) > 0 ):
return [self.Object.StartPoint[0], self.Object.EndPoint[0]]
return None
class MakeJoin():
"""Make Join"""
def GetResources(self):
return {"Pixmap" : utilities.getIconPath("join.svg"), # the name of a svg file available in the resources
'Accel' : "", # a default shortcut (optional)
"MenuText": "Join 2 points",
"ToolTip" : "Join 2 selected points"}
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 = getAllSelectedObjects()
# - Create object
join = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Join")
WireJoin(join, objects[0], objects[1], group.Name)
WireJoinVP(join.ViewObject)
join.ViewObject.PointSize = 4
group.addObject(join)
Gui.Selection.clearSelection()
FreeCAD.ActiveDocument.recompute()
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) < 2:
return False
parentA = objects[0][0]
parentB = objects[1][0]
# - Check object type
if isMovement(parentA) or isMovement(parentB):
return True
return False
Gui.addCommand("Join", MakeJoin())