-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCommandsPolar.py
165 lines (133 loc) · 6.75 KB
/
CommandsPolar.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
#(c) 2016 R. T. LGPL: part of Flamingo tools w.b. for FreeCAD
__title__="polarTools toolbar"
__author__="oddtopus"
__url__="github.com/oddtopus/flamingo"
__license__="LGPL 3"
# import FreeCAD modules
import FreeCAD, FreeCADGui,inspect , os
# helper -------------------------------------------------------------------
# FreeCAD TemplatePyMod module
# (c) 2007 Juergen Riegel LGPL
def addCommand(name,cmdObject):
(list,num) = inspect.getsourcelines(cmdObject.Activated)
pos = 0
# check for indentation
while(list[1][pos] == ' ' or list[1][pos] == '\t'):
pos += 1
source = ""
for i in range(len(list)-1):
source += list[i+1][pos:]
FreeCADGui.addCommand(name,cmdObject,source)
#---------------------------------------------------------------------------
# The command classes
#---------------------------------------------------------------------------
class drawPolygon:
def Activated(self):
import polarUtilsCmd as puc
import FreeCAD, FreeCADGui
from PySide import QtGui as qg
if (FreeCADGui.Selection.countObjectsOfType('Sketcher::SketchObject')==0):
qg.QMessageBox().information(None,'Incorrect input','First select at least one sketch.')
else:
n=int(qg.QInputDialog.getText(None,"draw a Polygon","Number of sides?")[0])
R=float(qg.QInputDialog.getText(None,"draw a Polygon","Radius of circumscribed circle?")[0])
for sk in FreeCADGui.Selection.getSelection():
if sk.TypeId=="Sketcher::SketchObject":
puc.disegna(sk,puc.cerchio(R,n))
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","poligono.svg"),'MenuText':'Make-a-polygon','ToolTip':'Draws n-polygon in a circle'}
class drawFromFile():
def Activated(self):
import polarUtilsCmd as puc
import FreeCAD
doc=FreeCAD.activeDocument()
sketch=doc.addObject("Sketcher::SketchObject","imported")
sketch.Placement = FreeCAD.Placement(FreeCAD.Vector(0.000000,0.000000,0.000000),FreeCAD.Rotation(0.000000,0.000000,0.000000,1.000000))
puc.disegna(sketch,puc.getFromFile())
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","daFile.svg"),'MenuText':'Polygon from file','ToolTip':'The file .csv must be ";" separated: column A = radius, column B = angle'}
class queryModel:
def Activated(self):
import FreeCAD, FreeCADGui, qForms
form = qForms.QueryForm(FreeCADGui.Selection)
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","query.svg"),'Accel':"Q,M",'MenuText':'query the model','ToolTip':'Click objects to print infos'}
class moveWorkPlane:
'''
Tool to set the DraftWorkingPlane according existing geometry of
the model.
The normal of plane is set:
* 1st according the selected face,
* then according the plane defined by a curved edge,
* at last according the plane defined by two straight edges.
The origin is set:
* 1st according the selected vertex,
* then according the center of curvature of a curved edge,
* at last according the intersection of two straight edges.
'''
def Activated(self):
import polarUtilsCmd
polarUtilsCmd.setWP()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","grid.svg"),'Accel':"A,W",'MenuText':'align Workplane','ToolTip':'Moves and rotates the drafting workplane with points, edges and faces'}
class rotateWorkPlane:
def Activated(self):
import FreeCAD, FreeCADGui, qForms
form = qForms.rotWPForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","rotWP.svg"),'Accel':"R,W",'MenuText':'rotate Workplane','ToolTip':'Spin the Draft working plane about one of its axes'}
class offsetWorkPlane:
def Activated(self):
if hasattr(FreeCAD,'DraftWorkingPlane') and hasattr(FreeCADGui,'Snapper'):
import polarUtilsCmd
s=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetInt("gridSize")
sc=[float(x*s) for x in [1,1,.2]]
arrow =polarUtilsCmd.arrow(FreeCAD.DraftWorkingPlane.getPlacement(),scale=sc,offset=s)
from PySide.QtGui import QInputDialog as qid
offset=qid.getInteger(None,'Offset Work Plane','Offset: ')
if offset[1]:
polarUtilsCmd.offsetWP(offset[0])
#FreeCADGui.ActiveDocument.ActiveView.getSceneGraph().removeChild(arrow.node)
arrow.closeArrow()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","offsetWP.svg"),'Accel':"O,W",'MenuText':'offset Workplane','ToolTip':'Shifts the WP alongg its normal.'}
class hackedL:
def Activated(self):
import polarUtilsCmd
form = polarUtilsCmd.hackedLine()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","hackedL.svg"),'Accel':"H,L",'MenuText':'draw a DWire','ToolTip':'WP is re-positioned at each point. Possible to spin and offset it.'}
class moveHandle:
def Activated(self):
import polarUtilsCmd
FreeCADGui.Control.showDialog(polarUtilsCmd.handleDialog())
#form = polarUtilsCmd.handleDialog()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","moveHandle.svg"),'Accel':"M,H",'MenuText':'Move objects','ToolTip':'Move quickly objects inside viewport'}
class dpCalc:
def Activated(self):
import fe_ChEDL
FreeCADGui.Control.showDialog(fe_ChEDL.dpCalcDialog())
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","delta.svg"),'MenuText':'Pressure loss calculator','ToolTip':'Calculate pressure loss in "pypes" using ChEDL libraries.\n See __doc__ of the module for futher information.'}
class selectSolids:
def Activated(self):
from frameCmd import getSolids
if FreeCADGui.Selection.getSelection(): allDoc=False
else: allDoc=True
getSolids(allDoc)
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","solids.svg"),'MenuText':'Select solids','ToolTip':'Grab all solids or those partially selected\n to export in .step format'}
#---------------------------------------------------------------------------
# Adds the commands to the FreeCAD command manager
#---------------------------------------------------------------------------
addCommand('drawPolygon',drawPolygon())
addCommand('drawFromFile',drawFromFile())
addCommand('queryModel',queryModel())
addCommand('moveWorkPlane',moveWorkPlane())
addCommand('rotateWorkPlane',rotateWorkPlane())
addCommand('offsetWorkPlane',offsetWorkPlane())
addCommand('hackedL',hackedL())
addCommand('moveHandle',moveHandle())
addCommand('dpCalc',dpCalc())
addCommand('selectSolids',selectSolids())