forked from easyw/kicadStepUpMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kicadStepUpCMD.py
4418 lines (3977 loc) · 204 KB
/
kicadStepUpCMD.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
#****************************************************************************
#* *
#* Kicad STEPUP (TM) (3D kicad board and models to STEP) for FreeCAD *
#* 3D exporter for FreeCAD *
#* Kicad STEPUP TOOLS (TM) (3D kicad board and models to STEP) for FreeCAD *
#* Copyright (c) 2015 *
#* Maurice easyw@katamail.com *
#* *
#* Kicad STEPUP (TM) is a TradeMark and cannot be freely usable *
#* *
import FreeCAD, FreeCADGui, Part
from FreeCAD import Base
import imp, os, sys, tempfile, re
import Draft, DraftGeomUtils #, OpenSCAD2Dgeom
from PySide import QtGui, QtCore
from PySide.QtCore import QT_TRANSLATE_NOOP
QtWidgets = QtGui
from pivy import coin
from threading import Timer
import ksu_locator
# from kicadStepUptools import onLoadBoard, onLoadFootprint
import math
from math import sqrt
import constrainator
from constrainator import add_constraints, sanitizeSkBsp
ksuCMD_version__='2.2.9'
precision = 0.1 # precision in spline or bezier conversion
q_deflection = 0.02 # quasi deflection parameter for discretization
hide_compound = True
reload_Gui=False#True
a3 = False
try:
from freecad.asm3 import assembly as asm
FreeCAD.Console.PrintWarning('A3 available\n')
a3 = True
except:
# FreeCAD.Console.PrintWarning('A3 not available\n')
a3 = False
try:
from PathScripts.PathUtils import horizontalEdgeLoop
from PathScripts.PathUtils import horizontalFaceLoop
from PathScripts.PathUtils import loopdetect
import PathCommands
except:
FreeCAD.Console.PrintError('Path WB not found\n')
def reload_lib(lib):
if (sys.version_info > (3, 0)):
import importlib
importlib.reload(lib)
else:
reload (lib)
use_outerwire = False #False #True
remove_shapes = True #False #True
hide_objects = True #False # True
use_draft = True #False # use Draft.makesketch
attach_sketch = False #True
create_plane = False# True #False
conv_started = False
global max_geo_admitted
max_geo_admitted = 1500 # after this number, no recompute is applied
from sys import platform as _platform
pt_lnx=False
# window GUI dimensions parameters
if _platform == "linux" or _platform == "linux2":
# linux
pt_lnx=True
sizeXmin=172;sizeYmin=34+34
sizeX=172;sizeY=516 #536
sizeXright=172;sizeYright=536 #556
else:
sizeXmin=172;sizeYmin=34
sizeX=172;sizeY=482#502
sizeXright=172;sizeYright=502#522
if _platform == "darwin":
pt_osx=True
def P_Line(prm1,prm2):
if hasattr(Part,"LineSegment"):
return Part.LineSegment(prm1, prm2)
else:
return Part.Line(prm1, prm2)
def fuse_objs(GuiObjSel):
objList= []
for s in GuiObjSel:
objList.append(s.Object)
FreeCAD.ActiveDocument.addObject("Part::MultiFuse","MultiFuse")
MultiFuseName = FreeCAD.ActiveDocument.ActiveObject.Name
FreeCAD.ActiveDocument.getObject(MultiFuseName).Shapes = objList
# [App.activeDocument().Part__Feature002,App.activeDocument().Part__Feature003,App.activeDocument().Part__Feature004,App.activeDocument().Part__Feature005,App.activeDocument().Part__Feature006,App.activeDocument().Part__Feature007,App.activeDocument().Part__Feature008,App.activeDocument().Part__Feature009,App.activeDocument().Part__Feature010,App.activeDocument().Part__Feature011,]
FreeCAD.ActiveDocument.recompute()
return MultiFuseName
#
def rmvsubtree(objs):
def addsubobjs(obj,toremoveset):
toremove.add(obj)
if hasattr(obj,'OutList'):
for subobj in obj.OutList:
addsubobjs(subobj,toremoveset)
import FreeCAD
toremove=set()
for obj in objs:
addsubobjs(obj,toremove)
checkinlistcomplete =False
while not checkinlistcomplete:
for obj in toremove:
if (obj not in objs) and (frozenset(obj.InList) - toremove):
toremove.remove(obj)
break
else:
checkinlistcomplete = True
for obj in toremove:
try:
obj.Document.removeObject(obj.Name)
except:
pass
###
def info_msg(msg):
QtGui.QApplication.restoreOverrideCursor()
# msg="""Select <b>a Compound</b> or <br><b>a Part Design group</b><br>or <b>more than one Part</b> object !<br>"""
spc="""<font color='white'>*******************************************************************************</font><br>
"""
msg1="Info ..."
QtGui.QApplication.restoreOverrideCursor()
#RotateXYZGuiClass().setGeometry(25, 250, 500, 500)
diag = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Information,
msg1,
msg)
diag.setWindowModality(QtCore.Qt.ApplicationModal)
diag.exec_()
##
ksuWBpath = os.path.dirname(ksu_locator.__file__)
#sys.path.append(ksuWB + '/Gui')
ksuWB_icons_path = os.path.join( ksuWBpath, 'Resources', 'icons')
#__dir__ = os.path.dirname(__file__)
#iconPath = os.path.join( __dir__, 'Resources', 'icons' )
def ksu_edges2sketch():
global conv_started, max_geo_admitted
cp_edges = [];cp_edges_names = []
cp_edges_shapes = []; cp_edges_obj = []
cp_obj = []; cp_obj_name = []
cp_points = []; cp_faces = []
wires = []
doc=FreeCAD.ActiveDocument
docG = FreeCADGui.ActiveDocument
en = None
selEx=FreeCADGui.Selection.getSelectionEx()
import Draft
if len (selEx) > 0:
for selEdge in selEx:
if not (conv_started):
doc.openTransaction('e2sk')
conv_started = True
for i,e in enumerate(selEdge.SubObjects):
if 'Edge' in selEdge.SubElementNames[i]:
cp_edges.append(e)
#cp_edges_shapes.append(e.toShape())
Part.show(Part.Wire(e))
cp = doc.ActiveObject
cp_edges_obj.append(cp)
#print(cp)
cp_edges_names.append(selEdge.ObjectName+'.'+selEdge.SubElementNames[i])
cp_obj.append(selEdge.Object)
cp_edges_shapes.append(selEdge.Object.Shape)
cp_obj_name.append(selEdge.ObjectName)
if create_plane:
for v in cp.Shape.Vertexes[:3]: #selEdge.Object.Shape.Vertexes[:3]:
if v.Point not in cp_points:
cp_points.append(v.Point)
if len (cp_points) > 2:
break
#FreeCAD.Console.PrintMessage(selEdge.ObjectName);FreeCAD.Console.PrintMessage('\n')
FreeCAD.Console.PrintMessage(selEdge.ObjectName+'.'+selEdge.SubElementNames[i])
FreeCAD.Console.PrintMessage('\n')
if hide_objects:
docG.getObject(selEdge.ObjectName).Visibility = False
#FreeCAD.Console.PrintMessage(e);FreeCAD.Console.PrintMessage('\n')
#cp_e = Part.show(Part.Wire(e))
wire = Part.Wire(e)
#cp_edges_shapes.append(wire.toShape())
wires.append (wire)
elif 'Face' in selEdge.SubElementNames[i]:
#o.Shape.Faces
cp_faces.append(e)
if use_outerwire:
ow=e.OuterWire
wires.append (ow)
#es = ow.Edges
for _e in ow.Edges:
cp_edges.append(_e)
Part.show(ow)
cp = doc.ActiveObject
cp_edges_obj.append(cp)
if create_plane:
for v in cp.Vertexes[:3]: #selEdge.Object.Shape.Vertexes[:3]:
print('point')
if v.Point not in cp_points:
cp_points.append(v.Point)
if len (cp_points) > 2:
break
else:
ws=e.Wires
wires.append (ws)
#es=e.Edges
if create_plane:
for v in e.Vertexes[:3]: #selEdge.Object.Shape.Vertexes[:3]:
print(v.Point)
if len (cp_points) > 2:
break
if v.Point not in cp_points:
cp_points.append(v.Point)
for w in ws:
for _e in w.Edges:
cp_edges.append(_e)
Part.show(w)
cp = doc.ActiveObject
cp_edges_obj.append(cp)
if hide_objects:
docG.getObject(selEdge.ObjectName).Visibility = False
#for ed in es:
# Part.show(ed)
elif 'Vertex' in selEdge.SubElementNames[i]:
#print(selEdge.SubElementNames[i])
#print(selEdge.Object.Shape.Volume)
if selEdge.Object.Shape.Volume == 0:
print('outline selected')
#for _e in selEdge.Object.Shape.Edges:
# Part.show(_e.Curve.toShape())
# cp_edges.append(_e)
# cp_edges_shapes.append(e.toShape())
# Part.show(Part.Wire(_e))
# cp = doc.ActiveObject
# cp_edges_obj.append(cp)
cp_edges_obj.append(selEdge.Object.Shape.copy())
if hide_objects:
docG.getObject(selEdge.ObjectName).Visibility = False
if len (cp_edges_obj) >0: # (wires) >0:
if not (use_draft):
FreeCAD.activeDocument().addObject('Sketcher::SketchObject','Sketch')
#FreeCAD.activeDocument().Sketch.MapMode = "ObjectXY"
#doc.recompute()
sketch = doc.ActiveObject
sketch.Label = "Sketch_converted"
if len (cp_edges_obj) > 1:
doc.addObject("Part::MultiFuse","union")
union = doc.ActiveObject
doc.union.Shapes = cp_edges_obj #cp_obj # [doc.Shape005,doc.Shape006]
if len (cp_edges_obj) < max_geo_admitted:
doc.recompute()
else:
union = cp_edges_obj[0]
#sketch.MapMode = "ObjectXZ"
#sketch.Support = [(doc.Cut,'Face2')]
#sketch.MapMode = 'FlatFace'
# doc.recompute()
#Draft.makeSketch([wire],addTo=sketch)
# points =
#print(cp_points)
triple = []
if len (cp_points) > 2:
for p in cp_points:
if p not in triple:
triple.append(p)
face= Part.Face(Part.makePolygon([p for p in triple], True))
else:
for _e in cp_edges:
if _e.isClosed():
face = Part.Face(Part.Wire(_e))
#print (triple)
#plane = Part.Plane(*[p for p in triple])
#print([p for p in triple])
if create_plane:
doc.addObject('Part::Feature','Face').Shape=face
newface = doc.ActiveObject
#[App.ActiveDocument.union.Shape.Vertex2.Point, App.ActiveDocument.union.Shape.Vertex5.Point, App.ActiveDocument.union.Shape.Vertex1.Point, ], True))
#print(plane)
## _makeSketch(plane,wires,addTo=sketch)
#Draft.makeSketch(wires,addTo=sketch)
_objs_ = []
use_workaround_1 = False
use_workaround_2 = False
active_view = FreeCADGui.ActiveDocument.activeView()
rotation_view = active_view.getCameraOrientation()
top_rotation = FreeCAD.Rotation(0.0,0.0,0.0,1.0)
if rotation_view != top_rotation and len(union.Shape.Edges) < max_geo_admitted:
use_workaround_1 = True
use_workaround_2 = True
if use_workaround_1:
FreeCAD.Console.PrintWarning('workaround to avoid issues in Draft.makeSketch from Bottom\n')
_objs_ = Draft.downgrade(FreeCAD.ActiveDocument.getObject('union'), delete=False)
FreeCAD.ActiveDocument.recompute()
_objs_ = []
_objs_ = Draft.upgrade(FreeCADGui.Selection.getSelection(), delete=True)
_objs_ = []
FreeCAD.ActiveDocument.recompute()
_objs_ = Draft.downgrade(FreeCADGui.Selection.getSelection(), delete=True)
sel_objs = FreeCADGui.Selection.getSelection()
if use_draft:
#Draft.makeSketch(union,addTo=sketch)
if use_workaround_1:
Draft.makeSketch(FreeCADGui.Selection.getSelection(),autoconstraints=True) #,addTo=sketch)
else:
Draft.makeSketch(union,autoconstraints=True) #,addTo=sketch)
sketch = doc.ActiveObject
p = sketch.Placement
# print(p)
# print(p.Rotation.Axis)
if use_workaround_2 and p.Rotation.Axis.z != 1:
FreeCAD.Console.PrintWarning('workaround on Axis to avoid issues in Draft.makeSketch\n')
p.Rotation.Axis.x = 0
p.Rotation.Axis.y = 0
p.Rotation.Axis.z = 1
p.Base.x = 0
p.Base.y = 0
p.Base.z = 1
# print(p)
sketch.Label = "Sketch_converted"
else:
for _e in union.Shape.Edges:
if isinstance(_e.Curve,Part.Line) or isinstance(_e.Curve,Part.LineSegment):
sketch.addGeometry(P_Line(Base.Vector(_e.firstVertex().Point), Base.Vector(_e.lastVertex().Point)))
#sketch.addGeometry(_e.Curve)
sk = doc.ActiveObject
if attach_sketch:
sketch.Support = [newface, 'Face1']
sketch.MapMode = 'FlatFace'
#sk.Placement = union.Placement
if remove_shapes:
rmvsubtree([union])
if use_workaround_1:
for o in sel_objs:
FreeCAD.ActiveDocument.removeObject(o.Name)
if create_plane:
rmvsubtree([newface])
sketch.MapMode = 'Deactivated'
# for e in cp_edges:
# sketch.addGeometry(e.Curve, False)
# print ('e added')
for i in range(0, len(sketch.Geometry)):
try:
g = str(sketch.Geometry[i])
if 'BSpline' in g or 'Ellipse' in g:
sketch.exposeInternalGeometry(i)
except:
#print 'error'
pass
docG.getObject(sketch.Name).LineColor = (1.00,1.00,1.00)
docG.getObject(sketch.Name).PointColor = (1.00,1.00,1.00)
#print(docG.getObject(sketch.Name).PointColor)
lg = len(sketch.Geometry)
if lg == 0:
doc.removeObject(sketch.Name)
docG.getObject(selEdge.ObjectName).Visibility = True
QtGui.QApplication.restoreOverrideCursor()
reply = QtGui.QMessageBox.information(None,"info", "All Shapes must be co-planar")
doc.abortTransaction()
else:
for s in FreeCADGui.Selection.getSelection():
FreeCADGui.Selection.removeSelection(s)
FreeCADGui.Selection.addSelection(sketch)
doc.commitTransaction()
conv_started = False
if lg < max_geo_admitted:
doc.recompute()
# for ob in FreeCAD.ActiveDocument.Objects:
# FreeCADGui.Selection.removeSelection(ob)
##
class Ui_Offset_value(object):
def setupUi(self, Offset_value):
Offset_value.setObjectName("Offset_value")
Offset_value.resize(292, 177)
Offset_value.setWindowTitle(translate("ksu","Offset value"))
Offset_value.setToolTip("")
self.buttonBoxLayer = QtWidgets.QDialogButtonBox(Offset_value)
self.buttonBoxLayer.setGeometry(QtCore.QRect(10, 130, 271, 32))
self.buttonBoxLayer.setOrientation(QtCore.Qt.Horizontal)
self.buttonBoxLayer.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBoxLayer.setObjectName("buttonBoxLayer")
self.gridLayoutWidget = QtWidgets.QWidget(Offset_value)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 271, 101))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.offset_label = QtWidgets.QLabel(self.gridLayoutWidget)
self.offset_label.setMinimumSize(QtCore.QSize(0, 0))
self.offset_label.setToolTip("")
self.offset_label.setText(translate("ksu","Offset [+/- mm]:"))
self.offset_label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.offset_label.setObjectName("offset_label")
self.gridLayout.addWidget(self.offset_label, 0, 0, 1, 1)
self.lineEdit_offset = QtWidgets.QLineEdit(self.gridLayoutWidget)
self.lineEdit_offset.setToolTip(translate("ksu","Offset value [+/- mm]"))
self.lineEdit_offset.setText("0.16")
self.lineEdit_offset.setObjectName("lineEdit_offset")
self.gridLayout.addWidget(self.lineEdit_offset, 0, 1, 1, 1)
self.checkBox = QtWidgets.QCheckBox(self.gridLayoutWidget)
self.checkBox.setToolTip(translate("ksu","Arc or Intersection Offset method"))
self.checkBox.setLayoutDirection(QtCore.Qt.RightToLeft)
self.checkBox.setText(translate("ksu","Arc"))
self.checkBox.setChecked(True)
self.checkBox.setObjectName("checkBox")
self.gridLayout.addWidget(self.checkBox, 2, 0, 1, 1)
self.offset_label_2 = QtWidgets.QLabel(self.gridLayoutWidget)
self.offset_label_2.setMinimumSize(QtCore.QSize(0, 0))
self.offset_label_2.setToolTip("")
self.offset_label_2.setText(translate("ksu","Offset Y [mm]:"))
self.offset_label_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.offset_label_2.setObjectName("offset_label_2")
self.gridLayout.addWidget(self.offset_label_2, 1, 0, 1, 1)
self.lineEdit_offset_2 = QtWidgets.QLineEdit(self.gridLayoutWidget)
self.lineEdit_offset_2.setToolTip(translate("ksu","Offset Y value [+/- mm]"))
self.lineEdit_offset_2.setText("5.0")
self.lineEdit_offset_2.setObjectName("lineEdit_offset_2")
self.gridLayout.addWidget(self.lineEdit_offset_2, 1, 1, 1, 1)
self.retranslateUi(Offset_value)
self.buttonBoxLayer.accepted.connect(Offset_value.accept)
self.buttonBoxLayer.rejected.connect(Offset_value.reject)
QtCore.QMetaObject.connectSlotsByName(Offset_value)
def retranslateUi(self, Offset_value):
pass
##
#
# class SMExtrudeCommandClass():
# """Extrude face"""
#
# def GetResources(self):
# return {'Pixmap' : os.path.join( iconPath , 'SMExtrude.svg') , # the name of a svg file available in the resources
# 'MenuText': "Extend Face" ,
# 'ToolTip' : "Extend a face along normal"}
class Ui_CDialog(object):
def setupUi(self, CDialog):
CDialog.setObjectName("CDialog")
CDialog.resize(317, 302)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("Sketcher_LockAll.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
CDialog.setWindowIcon(icon)
CDialog.setToolTip("")
CDialog.setStatusTip("")
CDialog.setWhatsThis("")
self.buttonBox = QtGui.QDialogButtonBox(CDialog)
self.buttonBox.setGeometry(QtCore.QRect(8, 255, 207, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.Label_howto = QtGui.QLabel(CDialog)
self.Label_howto.setGeometry(QtCore.QRect(20, 5, 265, 61))
self.Label_howto.setToolTip(translate("ksu","Select a Sketch and Parameters\n"
"to constraint the sketch\n"
"NB the Sketch will be modified!"))
self.Label_howto.setStatusTip("")
self.Label_howto.setWhatsThis("")
self.Label_howto.setText(translate("ksu","<b>Select a Sketch and Parameters to<br>constrain the sketch.<br>NB the Sketch will be modified!</b>"))
self.Label_howto.setObjectName("Label_howto")
self.Constraints = QtGui.QGroupBox(CDialog)
self.Constraints.setGeometry(QtCore.QRect(10, 70, 145, 166))
self.Constraints.setToolTip("")
self.Constraints.setStatusTip("")
self.Constraints.setWhatsThis("")
self.Constraints.setTitle(translate("ksu","Constraints"))
self.Constraints.setObjectName("Constraints")
self.verticalLayoutWidget = QtGui.QWidget(self.Constraints)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(12, 20, 125, 137))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtGui.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.all_constraints = QtGui.QRadioButton(self.verticalLayoutWidget)
self.all_constraints.setMinimumSize(QtCore.QSize(92, 64))
self.all_constraints.setToolTip(translate("ksu","Lock Coincident, Horizontal\n"
"and Vertical"))
self.all_constraints.setText("")
self.all_constraints.setIcon(icon)
self.all_constraints.setIconSize(QtCore.QSize(48, 48))
self.all_constraints.setChecked(True)
self.all_constraints.setObjectName("all_constraints")
self.verticalLayout.addWidget(self.all_constraints)
self.coincident = QtGui.QRadioButton(self.verticalLayoutWidget)
self.coincident.setMinimumSize(QtCore.QSize(92, 64))
self.coincident.setToolTip(translate("ksu","Lock Coincident"))
self.coincident.setText("")
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap("Sketcher_LockCoincident.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.coincident.setIcon(icon1)
self.coincident.setIconSize(QtCore.QSize(48, 48))
self.coincident.setChecked(False)
self.coincident.setObjectName("coincident")
self.verticalLayout.addWidget(self.coincident)
self.Tolerance = QtGui.QGroupBox(CDialog)
self.Tolerance.setGeometry(QtCore.QRect(166, 70, 141, 91))
self.Tolerance.setToolTip("")
self.Tolerance.setStatusTip("")
self.Tolerance.setWhatsThis("")
self.Tolerance.setTitle(translate("ksu","Tolerance"))
self.Tolerance.setObjectName("Tolerance")
self.verticalLayoutWidget_2 = QtGui.QWidget(self.Tolerance)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(8, 20, 125, 57))
self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.label = QtGui.QLabel(self.verticalLayoutWidget_2)
self.label.setToolTip("mm")
self.label.setStatusTip("")
self.label.setWhatsThis("")
self.label.setText(translate("ksu","tolerance in mm"))
self.label.setObjectName("label")
self.verticalLayout_2.addWidget(self.label)
self.tolerance = QtGui.QLineEdit(self.verticalLayoutWidget_2)
self.tolerance.setMinimumSize(QtCore.QSize(64, 22))
self.tolerance.setMaximumSize(QtCore.QSize(64, 22))
self.tolerance.setToolTip(translate("ksu","Tolerance on Constraints"))
self.tolerance.setStatusTip("")
self.tolerance.setWhatsThis("")
self.tolerance.setInputMethodHints(QtCore.Qt.ImhPreferNumbers)
self.tolerance.setInputMask("")
self.tolerance.setText("0.1")
self.tolerance.setPlaceholderText("")
self.tolerance.setObjectName("tolerance")
self.verticalLayout_2.addWidget(self.tolerance)
self.rmvXGeo = QtGui.QCheckBox(CDialog)
self.rmvXGeo.setGeometry(QtCore.QRect(170, 180, 141, 20))
self.rmvXGeo.setToolTip(translate("ksu","remove duplicated geometries"))
self.rmvXGeo.setStatusTip("")
self.rmvXGeo.setText("rmv xtr geo")
self.rmvXGeo.setObjectName("rmvXGeo")
#self.retranslateUi(CDialog)
### --------------------------------------------------------
#self.checkBox.setText("rmv xtr geo")
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), CDialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), CDialog.reject)
QtCore.QMetaObject.connectSlotsByName(CDialog)
myiconsize=48
icon = QtGui.QIcon()
myicon=os.path.join( ksuWB_icons_path , 'Sketcher_LockCoincident.svg')
icon.addPixmap(QtGui.QPixmap(myicon), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.coincident.setIcon(icon)
self.coincident.setIconSize(QtCore.QSize(myiconsize, myiconsize))
self.coincident.setChecked(True)
icon1 = QtGui.QIcon()
myicon=os.path.join( ksuWB_icons_path , 'Sketcher_LockAll.svg')
icon1.addPixmap(QtGui.QPixmap(myicon), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.all_constraints.setIcon(icon1)
self.all_constraints.setIconSize(QtCore.QSize(myiconsize, myiconsize))
icond = QtGui.QIcon()
myicon=os.path.join( ksuWB_icons_path , 'Sketcher_LockAll.svg')
icond.addPixmap(QtGui.QPixmap(myicon), QtGui.QIcon.Normal, QtGui.QIcon.Off)
CDialog.setWindowIcon(icon)
# remove question mark from the title bar
CDialog.setWindowFlags(CDialog.windowFlags() ^ QtCore.Qt.WindowContextHelpButtonHint)
#self.Label_howto.setText("<b>Select a Sketch and Parameters<br>to constraint the sketch<br>NB the Sketch will be modified!</b>")
def return_strings(self):
# Return list of values. It need map with str (self.lineedit.text() will return QString)
return map(str, [self.tolerance.text(), self.all_constraints.isChecked(), self.rmvXGeo.isChecked()])
# @staticmethod
# def get_data(parent=None):
# #dialog = Ui_CDialog()
# dialog = Ui_CDialog(parent)
# #dialog = QtGui.QDialog()
# dialog.exec_()
# return dialog.return_strings()
################ ------------------- end CD-ui #############################
class ksuTools:
"ksu tools object"
def GetResources(self):
return {'Pixmap' : os.path.join( ksuWB_icons_path , 'kicad-StepUp-icon.svg') , # the name of a svg file available in the resources
'MenuText': QT_TRANSLATE_NOOP("ksuTools","ksu Tools") ,
'ToolTip' : QT_TRANSLATE_NOOP("ksuTools","Activate the main\nkicad StepUp Tools Dialog")}
def IsActive(self):
#if FreeCAD.ActiveDocument == None:
# return False
#else:
# return True
#import kicadStepUptools
import os, sys
return True
def Activated(self):
# do something here...
import kicadStepUptools
reload_lib( kicadStepUptools )
kicadStepUptools.KSUWidget.activateWindow()
kicadStepUptools.KSUWidget.show()
kicadStepUptools.KSUWidget.raise_()
FreeCAD.Console.PrintWarning( 'active :)\n' )
#import kicadStepUptools
FreeCADGui.addCommand('ksuTools',ksuTools())
##
class ksuToolsContour2Poly:
"ksu tools Shapes Selection to PolyLine Sketch"
def GetResources(self):
mybtn_tooltip = QT_TRANSLATE_NOOP("ksuToolsContour2Poly","ksu tools \'RF PolyLined Sketch\'\nSelection\'s Shapes to PolyLine Sketch")
return {'Pixmap' : os.path.join( ksuWB_icons_path , 'Sketcher_CreatePolyline-RF.svg') , # the name of a svg file available in the resources
'MenuText': mybtn_tooltip ,
'ToolTip' : mybtn_tooltip}
def __init__(self):
self.obj = None
self.sub = []
self.active = False
def IsActive(self):
if bool(FreeCADGui.Selection.getSelection()) is False:
return False
return True
def Activated(self):
#import segments2poly
#import wires2poly
import Draft
doc=FreeCAD.ActiveDocument
docG = FreeCADGui.ActiveDocument
selEx=FreeCADGui.Selection.getSelectionEx()
dwglines =[]
dqd = 0.01 #discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the edge (faster)
class XYline:
def __init__(self, xs, ys, xe, ye):
self.start = [xs, ys]
self.end = [xe, ye]
if len (selEx) > 0:
doc.openTransaction('e2skd')
if len(selEx)>1:
mFuseNm = fuse_objs(selEx)
FuseWires = FreeCAD.ActiveDocument.getObject(mFuseNm).Shape.Wires
Vol = FreeCAD.ActiveDocument.getObject(mFuseNm).Shape.Volume
else:
FuseWires = FreeCAD.ActiveDocument.getObject(selEx[0].Object.Name).Shape.Wires
Vol = FreeCAD.ActiveDocument.getObject(selEx[0].Object.Name).Shape.Volume
mFuseNm = selEx[0].Object.Name
if Vol == 0:
EdgesContour = []
idx2rmv = []
for w in FuseWires:
for ew in w.Edges:
if 'Line object' in str(ew.Curve):
foundE = False
for i,e in enumerate (EdgesContour):
if (e.Vertexes[0].Point == ew.Vertexes[0].Point) and (e.Vertexes[1].Point == ew.Vertexes[1].Point):
#if (_Equal(e.start[0], ew.end[0]) and _Equal(e.start[1], ew.end[1])):
foundE = True
idx2rmv.append(i)
#print('found edge',i)
#elif (_Equal(e.start[1], ew.end[0]) and _Equal(e.start[0], ew.end[1])):
elif (e.Vertexes[1].Point == ew.Vertexes[0].Point) and (e.Vertexes[0].Point == ew.Vertexes[1].Point):
foundE = True
idx2rmv.append(i)
#print('found edge',i)
if foundE == False:
EdgesContour.append(ew)
else:
EdgesContour.append (ew)
#print(len(EdgesContour))
#print(idx2rmv,len(idx2rmv))
EdgesContourCleaned = []
for j,e in enumerate (EdgesContour):
if j not in idx2rmv:
EdgesContourCleaned.append (e)
sk = Draft.makeSketch(EdgesContourCleaned, autoconstraints=True)
sk.Label = 'Pads_Poly'
if len(selEx)>1:
FreeCAD.ActiveDocument.removeObject(mFuseNm)
else:
FreeCAD.ActiveDocument.addObject('Part::Refine','Refined').Source=FreeCAD.ActiveDocument.getObject(mFuseNm)
RefName = FreeCAD.ActiveDocument.ActiveObject.Name
FreeCAD.ActiveDocument.recompute()
sv0 = Draft.makeShape2DView(FreeCAD.ActiveDocument.getObject(RefName), FreeCAD.Vector(-0.0, -0.0, 1.0))
FreeCAD.ActiveDocument.recompute()
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(FreeCAD.ActiveDocument.Name,sv0.Name)
sk = Draft.makeSketch(FreeCADGui.Selection.getSelection(), autoconstraints=True)
sk.Label = 'Pads_Poly'
if 1:
### Begin command Std_Delete
FreeCAD.ActiveDocument.removeObject(RefName)
FreeCAD.ActiveDocument.removeObject(sv0.Name)
#FreeCAD.ActiveDocument.recompute()
if len(selEx)>1:
FreeCAD.ActiveDocument.removeObject(mFuseNm)
FreeCAD.ActiveDocument.recompute()
#creating an edge ordered sketch
sv0 = Draft.makeShape2DView(FreeCAD.ActiveDocument.getObject(sk.Name), FreeCAD.Vector(-0.0, -0.0, 1.0))
FreeCAD.ActiveDocument.recompute()
FreeCAD.ActiveDocument.removeObject(sk.Name)
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(FreeCAD.ActiveDocument.Name,sv0.Name)
sk = Draft.makeSketch(FreeCADGui.Selection.getSelection(), autoconstraints=True)
FreeCADGui.ActiveDocument.getObject(sk.Name).LineColor = (1.000,1.000,1.000)
FreeCADGui.ActiveDocument.getObject(sk.Name).PointColor = (1.000,1.000,1.000)
FreeCAD.ActiveDocument.removeObject(sv0.Name)
sk.Label = 'Pads_Poly'
FreeCAD.ActiveDocument.recompute()
doc.commitTransaction()
msg=translate("ksu","""PolyLine Contour generated<br><br>""")
msg+=translate("ksu","<b>For PolyLine Pads, please add \'circles\' inside each closed polyline</b><br>")
info_msg(msg)
#stop
#FreeCAD.ActiveDocument.recompute()
#
if FreeCAD.GuiUp:
FreeCADGui.addCommand('ksuToolsContour2Poly',ksuToolsContour2Poly())
##
class ksuToolsMoveSketch:
"ksu tools MoveSketch"
def GetResources(self):
return {'Pixmap' : os.path.join( ksuWB_icons_path , 'Sketcher_Move.svg') , # the name of a svg file available in the resources
'MenuText': QT_TRANSLATE_NOOP("ksuToolsMoveSketch","Move Sketch") ,
'ToolTip' : QT_TRANSLATE_NOOP("ksuToolsMoveSketch","ksu Move 2D Sketch")}
def IsActive(self):
sel = FreeCADGui.Selection.getSelection()
if len(sel) == 0:
return False
else:
return True
def Activated(self):
# do something here...
sel=FreeCADGui.Selection.getSelection()
if len (sel) == 1:
doc = FreeCAD.ActiveDocument
if 'Sketcher' in sel[0].TypeId:
s = doc.getObject(sel[0].Name)
offsetDlg = QtGui.QDialog()
ui = Ui_Offset_value()
ui.setupUi(offsetDlg)
ui.offset_label.setText(translate("ksu","Select a Sketch and Parameters to<br>move the sketch.<br>Offset X:"))
ui.lineEdit_offset.setText("10.0")
ui.offset_label_2.setText("Offset Y [mm]:")
ui.lineEdit_offset_2.setToolTip("Offset Y value [+/- mm]")
ui.lineEdit_offset_2.setText("0.0")
ui.checkBox.setText("reset Placement")
ui.checkBox.setVisible(True)
ui.checkBox.setChecked(False)
ui.checkBox.setToolTip("reset Placement of Sketch,\nmoving the internal geometry\nignoring offset imput fields")
reply=offsetDlg.exec_()
skip=False
if reply==1: # ok
if ui.checkBox.isChecked():
if s.Placement.Rotation == FreeCAD.Rotation(0.0,0.0,0.0,1.0):
offsetX=s.Placement.Base.x
offsetY=s.Placement.Base.y
else:
#print(s.Placement.Rotation)
print('available only on Angle (0,0,0)')
msg="""available only on Angle (0,0,0)"""
QtGui.QApplication.restoreOverrideCursor()
QtGui.QMessageBox.information(None,"Info ...",msg)
skip=True
else:
offsetX=float(ui.lineEdit_offset.text().replace(',','.'))
offsetY=float(ui.lineEdit_offset_2.text().replace(',','.'))
if not skip:
doc.openTransaction('moveSk')
n = doc.getObject(s.Name).GeometryCount
mv = []
for j in range (n):
mv.append(j)
doc.getObject(s.Name).addMove(mv, FreeCAD.Vector(offsetX, offsetY, 0))
if ui.checkBox.isChecked():
s.Placement.Base.x=0
s.Placement.Base.y=0
doc.recompute([s])
doc.commitTransaction()
else:
print('Cancel')
else:
print('select a Sketch')
#doc.recompute(None,True,True)
#doc.abortTransaction()
FreeCADGui.addCommand('ksuToolsMoveSketch',ksuToolsMoveSketch())
##
class ksuToolsOffset2D:
"ksu tools Offset2D"
def GetResources(self):
return {'Pixmap' : os.path.join( ksuWB_icons_path , 'Offset2D.svg') , # the name of a svg file available in the resources
'MenuText': QT_TRANSLATE_NOOP("ksuToolsOffset2D","Offset 2D") ,
'ToolTip' : QT_TRANSLATE_NOOP("ksuToolsOffset2D","ksu Offset 2D object")}
def IsActive(self):
sel = FreeCADGui.Selection.getSelection()
if len(sel) == 0:
return False
else:
return True
def Activated(self):
# do something here...
sel=FreeCADGui.Selection.getSelection()
if len (sel) == 1:
doc = FreeCAD.ActiveDocument
offsetDlg = QtGui.QDialog()
ui = Ui_Offset_value()
ui.setupUi(offsetDlg)
ui.lineEdit_offset.setText("-1.0")
ui.offset_label_2.setVisible(False)
ui.lineEdit_offset_2.setVisible(False)
reply=offsetDlg.exec_()
if reply==1: # ok
offset=float(ui.lineEdit_offset.text().replace(',','.'))
if ui.checkBox.isChecked():
offset_method = 'Arc'
else:
offset_method = 'Intersection'
doc.openTransaction('off2D')
f = doc.addObject("Part::Offset2D", "Offset2D")
f.Source = sel[0] #some object
f.Value = offset
f.Join=offset_method
doc.ActiveObject.ViewObject.LineColor = (0.00,0.0,1.0)
doc.ActiveObject.ViewObject.PointColor = (0.00,0.0,1.0)
sel[0].ViewObject.Visibility = False
doc.commitTransaction()
doc.recompute([f])
else:
print('Cancel')
#doc.recompute(None,True,True)
#doc.abortTransaction()
FreeCADGui.addCommand('ksuToolsOffset2D',ksuToolsOffset2D())
##
class ksuToolsExtrude:
"ksu tools Extrude Selection"
def GetResources(self):
mybtn_tooltip =QT_TRANSLATE_NOOP("ksuToolsExtrude","ksu tools \'Extrude\'\nExtrude selection")
return {'Pixmap' : os.path.join( ksuWB_icons_path , 'Part_Extrude.svg') , # the name of a svg file available in the resources
'MenuText': mybtn_tooltip ,
'ToolTip' : mybtn_tooltip}
def __init__(self):
self.obj = None
self.sub = []
self.active = False
def IsActive(self):
if bool(FreeCADGui.Selection.getSelection()) is False:
return False
return True
def Activated(self):
sel = FreeCADGui.Selection.getSelectionEx()[0]
FreeCADGui.runCommand('Part_Extrude',0)
if FreeCAD.GuiUp:
FreeCADGui.addCommand('ksuToolsExtrude',ksuToolsExtrude())
##
class ksuToolsSkValidate:
"ksu tools Sketcher Validate Selection"
def GetResources(self):
mybtn_tooltip =QT_TRANSLATE_NOOP("ksuToolsSkValidate","ksu tools \'Sketcher Validate\'\nValidate selected Sketch")
return {'Pixmap' : os.path.join( ksuWB_icons_path , 'Sketcher_Validate.svg') , # the name of a svg file available in the resources
'MenuText': mybtn_tooltip ,
'ToolTip' : mybtn_tooltip}
def __init__(self):
self.obj = None
self.sub = []
self.active = False
def IsActive(self):
if bool(FreeCADGui.Selection.getSelection()) is False:
return False
return True
def Activated(self):
sel = FreeCADGui.Selection.getSelectionEx()[0]
FreeCADGui.runCommand('Sketcher_ValidateSketch',0)
if FreeCAD.GuiUp:
FreeCADGui.addCommand('ksuToolsSkValidate',ksuToolsSkValidate())
##
class ksuToolsOpenBoard:
"ksu tools Open Board object"
def GetResources(self):
return {'Pixmap' : os.path.join( ksuWB_icons_path , 'importBoard.svg') , # the name of a svg file available in the resources
'MenuText': QT_TRANSLATE_NOOP("ksuToolsOpenBoard","Load Board") ,
'ToolTip' : QT_TRANSLATE_NOOP("ksuToolsOpenBoard","ksu Load KiCad PCB Board and Parts")}
def IsActive(self):
#if FreeCAD.ActiveDocument == None:
# return False
#else:
# return True
#import kicadStepUptools
return True
def Activated(self):
# do something here...
import kicadStepUptools
#if not kicadStepUptools.checkInstance():
# reload( kicadStepUptools )
if reload_Gui:
reload_lib( kicadStepUptools )
#from kicadStepUptools import onPushPCB
#FreeCAD.Console.PrintWarning( 'active :)\n' )
kicadStepUptools.onLoadBoard()
# ppcb=kicadStepUptools.KSUWidget
# ppcb.onPushPCB()
#onPushPCB()
#import kicadStepUptools
FreeCADGui.addCommand('ksuToolsOpenBoard',ksuToolsOpenBoard())
##
class ksuToolsLoadFootprint:
"ksu tools Load Footprint object"
def GetResources(self):
return {'Pixmap' : os.path.join( ksuWB_icons_path , 'importFP.svg') , # the name of a svg file available in the resources
'MenuText': QT_TRANSLATE_NOOP("ksuToolsLoadFootprint","Load FootPrint") ,
'ToolTip' : QT_TRANSLATE_NOOP("ksuToolsLoadFootprint","ksu Load KiCad PCB FootPrint")}
def IsActive(self):
#if FreeCAD.ActiveDocument == None:
# return False
#else:
# return True
#import kicadStepUptools
return True
def Activated(self):
# do something here...
import kicadStepUptools
#if not kicadStepUptools.checkInstance():
# reload( kicadStepUptools )
if 1: #reload_Gui:
reload_lib( kicadStepUptools )
#FreeCAD.Console.PrintWarning( 'active :)\n' )
kicadStepUptools.KSUWidget.activateWindow()
kicadStepUptools.KSUWidget.show()
kicadStepUptools.KSUWidget.raise_()
kicadStepUptools.onLoadFootprint()
FreeCADGui.addCommand('ksuToolsLoadFootprint',ksuToolsLoadFootprint())
##
class ksuToolsExportModel:
"ksu tools Export Model to KiCad object"
def GetResources(self):
return {'Pixmap' : os.path.join( ksuWB_icons_path , 'export3DModel.svg') , # the name of a svg file available in the resources
'MenuText': QT_TRANSLATE_NOOP("ksuToolsExportModel","Export 3D Model") ,
'ToolTip' : QT_TRANSLATE_NOOP("ksuToolsExportModel","ksu Export 3D Model to KiCad")}
def IsActive(self):
#if FreeCAD.ActiveDocument == None: