/
ArchWindow.py
1123 lines (1035 loc) · 51.8 KB
/
ArchWindow.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
#***************************************************************************
#* *
#* Copyright (c) 2011 *
#* Yorik van Havre <yorik@uncreated.net> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program 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 Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
import FreeCAD,Draft,ArchComponent,DraftVecUtils,ArchCommands,Units
from FreeCAD import Vector
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore, QtGui, QtSvg
from DraftTools import translate
else:
def translate(ctxt,txt):
return txt
__title__="FreeCAD Window"
__author__ = "Yorik van Havre"
__url__ = "http://www.freecadweb.org"
# presets
WindowPartTypes = ["Frame","Solid panel","Glass panel"]
AllowedHosts = ["Wall","Structure","Roof"]
WindowPresets = ["Fixed", "Open 1-pane", "Open 2-pane", "Sash 2-pane",
"Sliding 2-pane", "Simple door", "Glass door"]
Roles = ["Window","Door"]
def makeWindow(baseobj=None,width=None,height=None,parts=None,name=translate("Arch","Window")):
'''makeWindow(baseobj,[width,height,parts,name]): creates a window based on the
given base 2D object (sketch or draft).'''
if baseobj:
if Draft.getType(baseobj) == "Window":
obj = Draft.clone(baseobj)
return obj
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
_Window(obj)
if FreeCAD.GuiUp:
_ViewProviderWindow(obj.ViewObject)
obj.ViewObject.Transparency=p.GetInt("WindowTransparency",85)
if width:
obj.Width = width
if height:
obj.Height = height
if baseobj:
obj.Normal = baseobj.Placement.Rotation.multVec(FreeCAD.Vector(0,0,-1))
obj.Base = baseobj
if parts:
obj.WindowParts = parts
else:
if baseobj:
if baseobj.isDerivedFrom("Part::Part2DObject"):
if baseobj.Shape.Wires:
i = 0
ws = ''
for w in baseobj.Shape.Wires:
if w.isClosed():
if ws: ws += ","
ws += "Wire" + str(i)
i += 1
obj.WindowParts = ["Default","Frame",ws,"1","0"]
if obj.Base and FreeCAD.GuiUp:
obj.Base.ViewObject.DisplayMode = "Wireframe"
obj.Base.ViewObject.hide()
return obj
def makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,placement=None):
"""makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,[placement]): makes a
window object based on the given data. windowtype must be one of the names
defined in Arch.WindowPresets"""
def makeSketch(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2):
import Part,Sketcher
width = float(width)
height = float(height)
h1 = float(h1)
h2 = float(h2)
h3 = float(h3)
w1 = float(w1)
w2 = float(w2)
o1 = float(o1)
o2 = float(o2)
# small spacing to avoid wrong auto-wires in sketch
tol = h1/10
# glass size divider
gla = 10
s = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','Sketch')
def addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8):
"adds two rectangles to the given sketch"
idx = s.GeometryCount
s.addGeometry(Part.Line(p1,p2))
s.addGeometry(Part.Line(p2,p3))
s.addGeometry(Part.Line(p3,p4))
s.addGeometry(Part.Line(p4,p1))
s.addConstraint(Sketcher.Constraint('Coincident',idx,2,idx+1,1))
s.addConstraint(Sketcher.Constraint('Coincident',idx+1,2,idx+2,1))
s.addConstraint(Sketcher.Constraint('Coincident',idx+2,2,idx+3,1))
s.addConstraint(Sketcher.Constraint('Coincident',idx+3,2,idx,1))
s.addConstraint(Sketcher.Constraint('Horizontal',idx))
s.addConstraint(Sketcher.Constraint('Horizontal',idx+2))
s.addConstraint(Sketcher.Constraint('Vertical',idx+1))
s.addConstraint(Sketcher.Constraint('Vertical',idx+3))
s.addGeometry(Part.Line(p5,p6))
s.addGeometry(Part.Line(p6,p7))
s.addGeometry(Part.Line(p7,p8))
s.addGeometry(Part.Line(p8,p5))
s.addConstraint(Sketcher.Constraint('Coincident',idx+4,2,idx+5,1))
s.addConstraint(Sketcher.Constraint('Coincident',idx+5,2,idx+6,1))
s.addConstraint(Sketcher.Constraint('Coincident',idx+6,2,idx+7,1))
s.addConstraint(Sketcher.Constraint('Coincident',idx+7,2,idx+4,1))
s.addConstraint(Sketcher.Constraint('Horizontal',idx+4))
s.addConstraint(Sketcher.Constraint('Horizontal',idx+6))
s.addConstraint(Sketcher.Constraint('Vertical',idx+5))
s.addConstraint(Sketcher.Constraint('Vertical',idx+7))
def outerFrame(s,width,height,h1,w1,o1):
p1 = Vector(0,0,0)
p2 = Vector(width,0,0)
p3 = Vector(width,height,0)
p4 = Vector(0,height,0)
p5 = Vector(h1,h1,0)
p6 = Vector(width-h1,h1,0)
p7 = Vector(width-h1,height-h1,0)
p8 = Vector(h1,height-h1,0)
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
s.addConstraint(Sketcher.Constraint('DistanceY',1,height)) #16
s.addConstraint(Sketcher.Constraint('DistanceX',0,width)) #17
s.addConstraint(Sketcher.Constraint('DistanceY',6,2,2,2,h1))
s.addConstraint(Sketcher.Constraint('DistanceX',2,2,6,2,h1))
s.addConstraint(Sketcher.Constraint('DistanceX',4,2,0,2,h1))
s.addConstraint(Sketcher.Constraint('DistanceY',0,2,4,2,h1))
s.addConstraint(Sketcher.Constraint('Coincident',0,1,-1,1))
return ["OuterFrame","Frame","Wire0,Wire1",str(w1),str(o1)]
def doorFrame(s,width,height,h1,w1,o1):
p1 = Vector(0,0,0)
p2 = Vector(width,0,0)
p3 = Vector(width,height,0)
p4 = Vector(0,height,0)
p5 = Vector(h1,0,0)
p6 = Vector(width-h1,0,0)
p7 = Vector(width-h1,height-h1,0)
p8 = Vector(h1,height-h1,0)
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
s.addConstraint(Sketcher.Constraint('DistanceY',1,height)) #16
s.addConstraint(Sketcher.Constraint('DistanceX',0,width)) #17
s.addConstraint(Sketcher.Constraint('DistanceY',6,2,2,2,h1))
s.addConstraint(Sketcher.Constraint('DistanceX',2,2,6,2,h1))
s.addConstraint(Sketcher.Constraint('DistanceX',4,2,0,2,h1))
s.addConstraint(Sketcher.Constraint('DistanceY',0,2,4,2,0.0))
s.addConstraint(Sketcher.Constraint('Coincident',0,1,-1,1))
return ["OuterFrame","Frame","Wire0,Wire1",str(w1),str(o1)]
if windowtype == "Fixed":
wp = outerFrame(s,width,height,h1,w1,o1)
wp.extend(["Glass","Glass panel","Wire1",str(w1/gla),str(w1/2)])
elif windowtype == "Open 1-pane":
wp = outerFrame(s,width,height,h1,w1,o1)
p1 = Vector(h1+tol,h1+tol,0)
p2 = Vector(width-(h1+tol),h1+tol,0)
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
p4 = Vector(h1+tol,height-(h1+tol),0)
p5 = Vector(h1+h2,h1+h2,0)
p6 = Vector(width-(h1+h2),h1+h2,0)
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
p8 = Vector(h1+h2,height-(h1+h2),0)
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',14,1,10,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceY',14,1,10,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceX',10,1,6,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceY',10,1,6,1,tol))
wp.extend(["InnerFrame","Frame","Wire2,Wire3",str(w2),str(o1+o2)])
wp.extend(["InnerGlass","Glass panel","Wire3",str(w2/gla),str(o1+o2+w2/2)])
elif windowtype == "Open 2-pane":
wp = outerFrame(s,width,height,h1,w1,o1)
p1 = Vector(h1+tol,h1+tol,0)
p2 = Vector((width/2)-tol,h1+tol,0)
p3 = Vector((width/2)-tol,height-(h1+tol),0)
p4 = Vector(h1+tol,height-(h1+tol),0)
p5 = Vector(h1+h2,h1+h2,0)
p6 = Vector((width/2)-h2,h1+h2,0)
p7 = Vector((width/2)-h2,height-(h1+h2),0)
p8 = Vector(h1+h2,height-(h1+h2),0)
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
p1 = Vector((width/2)+tol,h1+tol,0)
p2 = Vector(width-(h1+tol),h1+tol,0)
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
p4 = Vector((width/2)+tol,height-(h1+tol),0)
p5 = Vector((width/2)+h2,h1+h2,0)
p6 = Vector(width-(h1+h2),h1+h2,0)
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
p8 = Vector((width/2)+h2,height-(h1+h2),0)
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',21,2,17,2,h2))
s.addConstraint(Sketcher.Constraint('DistanceY',21,2,17,2,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',16,1,20,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',14,1,10,1,h2))
s.addConstraint(Sketcher.Constraint('Equal',22,14))
s.addConstraint(Sketcher.Constraint('DistanceY',8,2,16,1,0.0))
s.addConstraint(Sketcher.Constraint('DistanceY',10,1,18,2,0.0))
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceX',6,1,18,1,-tol))
s.addConstraint(Sketcher.Constraint('DistanceY',6,1,18,1,-tol))
s.addConstraint(Sketcher.Constraint('DistanceX',9,1,19,2,tol))
wp.extend(["LeftFrame","Frame","Wire2,Wire3",str(w2),str(o1+o2)])
wp.extend(["LeftGlass","Glass panel","Wire3",str(w2/gla),str(o1+o2+w2/2)])
wp.extend(["RightFrame","Frame","Wire4,Wire5",str(w2),str(o1+o2)])
wp.extend(["RightGlass","Glass panel","Wire5",str(w2/gla),str(o1+o2+w2/2)])
elif windowtype == "Sash 2-pane":
wp = outerFrame(s,width,height,h1,w1,o1)
p1 = Vector(h1+tol,h1+tol,0)
p2 = Vector(width-(h1+tol),h1+tol,0)
p3 = Vector(width-(h1+tol),(height/2)-tol,0)
p4 = Vector(h1+tol,(height/2)-tol,0)
p5 = Vector(h1+h2,h1+h2,0)
p6 = Vector(width-(h1+h2),h1+h2,0)
p7 = Vector(width-(h1+h2),(height/2)-h2,0)
p8 = Vector(h1+h2,(height/2)-h2,0)
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
p1 = Vector(h1+tol,(height/2)+tol,0)
p2 = Vector(width-(h1+tol),(height/2)+tol,0)
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
p4 = Vector(h1+tol,height-(h1+tol),0)
p5 = Vector(h1+h2,(height/2)+h2,0)
p6 = Vector(width-(h1+h2),(height/2)+h2,0)
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
p8 = Vector(h1+h2,height-(h1+h2),0)
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',21,2,17,2,h2))
s.addConstraint(Sketcher.Constraint('DistanceY',21,2,17,2,h2))
s.addConstraint(Sketcher.Constraint('DistanceY',16,2,20,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceY',10,2,14,2,-h2))
s.addConstraint(Sketcher.Constraint('Equal',23,15))
s.addConstraint(Sketcher.Constraint('DistanceX',12,1,20,1,0.0))
s.addConstraint(Sketcher.Constraint('DistanceX',13,2,20,2,0.0))
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceX',6,1,18,1,-tol))
s.addConstraint(Sketcher.Constraint('DistanceY',6,1,18,1,-tol))
s.addConstraint(Sketcher.Constraint('DistanceY',10,1,16,1,tol))
wp.extend(["LowerFrame","Frame","Wire2,Wire3",str(w2),str(o1+o2+w2)])
wp.extend(["LowerGlass","Glass panel","Wire3",str(w2/gla),str(o1+o2+w2+w2/2)])
wp.extend(["UpperFrame","Frame","Wire4,Wire5",str(w2),str(o1+o2)])
wp.extend(["UpperGlass","Glass panel","Wire5",str(w2/gla),str(o1+o2+w2/2)])
elif windowtype == "Sliding 2-pane":
wp = outerFrame(s,width,height,h1,w1,o1)
p1 = Vector(h1+tol,h1+tol,0)
p2 = Vector((width/2)-tol,h1+tol,0)
p3 = Vector((width/2)-tol,height-(h1+tol),0)
p4 = Vector(h1+tol,height-(h1+tol),0)
p5 = Vector(h1+h2,h1+h2,0)
p6 = Vector((width/2)-h2,h1+h2,0)
p7 = Vector((width/2)-h2,height-(h1+h2),0)
p8 = Vector(h1+h2,height-(h1+h2),0)
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
p1 = Vector((width/2)+tol,h1+tol,0)
p2 = Vector(width-(h1+tol),h1+tol,0)
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
p4 = Vector((width/2)+tol,height-(h1+tol),0)
p5 = Vector((width/2)+h2,h1+h2,0)
p6 = Vector(width-(h1+h2),h1+h2,0)
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
p8 = Vector((width/2)+h2,height-(h1+h2),0)
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',21,2,17,2,h2))
s.addConstraint(Sketcher.Constraint('DistanceY',21,2,17,2,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',16,1,20,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',14,1,10,1,h2))
s.addConstraint(Sketcher.Constraint('Equal',22,14))
s.addConstraint(Sketcher.Constraint('DistanceY',8,2,16,1,0.0))
s.addConstraint(Sketcher.Constraint('DistanceY',10,1,18,2,0.0))
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceX',6,1,18,1,-tol))
s.addConstraint(Sketcher.Constraint('DistanceY',6,1,18,1,-tol))
s.addConstraint(Sketcher.Constraint('DistanceX',9,1,19,2,tol))
wp.extend(["LeftFrame","Frame","Wire2,Wire3",str(w2),str(o1+o2)])
wp.extend(["LeftGlass","Glass panel","Wire3",str(w2/gla),str(o1+o2+w2/2)])
wp.extend(["RightFrame","Frame","Wire4,Wire5",str(w2),str(o1+o2+w2)])
wp.extend(["RightGlass","Glass panel","Wire5",str(w2/gla),str(o1+o2+w2+w2/2)])
elif windowtype == "Simple door":
wp = doorFrame(s,width,height,h1,w1,o1)
wp.extend(["Door","Solid panel","Wire1",str(w2),str(o1+o2)])
elif windowtype == "Glass door":
wp = doorFrame(s,width,height,h1,w1,o1)
p1 = Vector(h1+tol,h1+tol,0)
p2 = Vector(width-(h1+tol),h1+tol,0)
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
p4 = Vector(h1+tol,height-(h1+tol),0)
p5 = Vector(h1+h2,h1+h3,0)
p6 = Vector(width-(h1+h2),h1+h3,0)
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
p8 = Vector(h1+h2,height-(h1+h2),0)
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h3))
s.addConstraint(Sketcher.Constraint('DistanceX',14,1,10,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceY',14,1,10,1,h2))
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceX',10,1,6,1,tol))
s.addConstraint(Sketcher.Constraint('DistanceY',10,1,6,1,tol))
wp.extend(["InnerFrame","Frame","Wire2,Wire3",str(w2),str(o1+o2)])
wp.extend(["InnerGlass","Glass panel","Wire3",str(w2/gla),str(o1+o2+w2/2)])
return (s,wp)
if windowtype in WindowPresets:
default = makeSketch(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2)
FreeCAD.ActiveDocument.recompute()
if default:
if placement:
default[0].Placement = placement
FreeCAD.ActiveDocument.recompute()
obj = makeWindow(default[0],width,height,default[1])
obj.Preset = WindowPresets.index(windowtype)+1
if "door" in windowtype:
obj.Role = "Door"
FreeCAD.ActiveDocument.recompute()
return obj
print "Arch: Unknown window type"
class _CommandWindow:
"the Arch Window command definition"
def __init__(self):
# hack for inputwidgets
global setArchWindowParamFunction
setArchWindowParamFunction = self.setParams
def GetResources(self):
return {'Pixmap' : 'Arch_Window',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Arch_Window","Window"),
'Accel': "W, N",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Window","Creates a window object from a selected object (wire, rectangle or sketch)")}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
def Activated(self):
sel = FreeCADGui.Selection.getSelection()
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
self.Thickness = p.GetFloat("WindowThickness",50)
self.Width = p.GetFloat("WindowWidth",1000)
self.Height = p.GetFloat("WindowHeight",1000)
self.Preset = 0
self.baseFace = None
self.wparams = ["Width","Height","H1","H2","H3","W1","W2","O1","O2"]
self.DECIMALS = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals",2)
import DraftGui
self.FORMAT = DraftGui.makeFormatSpec(self.DECIMALS,'Length')
# auto mode
if sel:
obj = sel[0]
if Draft.getType(obj) in AllowedHosts:
# make sure only one face is selected
sub = FreeCADGui.Selection.getSelectionEx()[0]
if len(sub.SubElementNames) == 1:
if "Face" in sub.SubElementNames[0]:
FreeCADGui.activateWorkbench("SketcherWorkbench")
FreeCADGui.runCommand("Sketcher_NewSketch")
FreeCAD.ArchObserver = ArchComponent.ArchSelectionObserver(obj,FreeCAD.ActiveDocument.Objects[-1],hide=False,nextCommand="Arch_Window")
FreeCADGui.Selection.addObserver(FreeCAD.ArchObserver)
return
elif obj.isDerivedFrom("Part::Part2DObject"):
FreeCADGui.Control.closeDialog()
host = None
if hasattr(obj,"Support"):
if obj.Support:
if isinstance(obj.Support,tuple):
host = obj.Support[0]
else:
host = obj.Support
obj.Support = None # remove
elif Draft.isClone(obj,"Window"):
if obj.Objects[0].Inlist:
host = obj.Objects[0].Inlist[0]
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Window"))
FreeCADGui.doCommand("import Arch")
FreeCADGui.doCommand("win = Arch.makeWindow(FreeCAD.ActiveDocument."+obj.Name+")")
if host:
FreeCADGui.doCommand("Arch.removeComponents(win,host=FreeCAD.ActiveDocument."+host.Name+")")
siblings = host.Proxy.getSiblings(host)
for sibling in siblings:
FreeCADGui.doCommand("Arch.removeComponents(win,host=FreeCAD.ActiveDocument."+sibling.Name+")")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
return
# interactive mode
if hasattr(FreeCAD,"DraftWorkingPlane"):
FreeCAD.DraftWorkingPlane.setup()
import DraftTrackers
self.tracker = DraftTrackers.boxTracker()
self.tracker.length(self.Width)
self.tracker.width(self.Thickness)
self.tracker.height(self.Height)
FreeCAD.Console.PrintMessage(translate("Arch","Pick a face on an existing object or select a preset\n"))
FreeCADGui.Snapper.getPoint(callback=self.getPoint,movecallback=self.update,extradlg=self.taskbox())
FreeCADGui.Snapper.setSelectMode(True)
def getPoint(self,point=None,obj=None):
"this function is called by the snapper when it has a 3D point"
self.tracker.finalize()
FreeCADGui.Control.closeDialog()
if point == None:
return
if not self.Preset:
if obj and (self.baseFace != None):
if Draft.getType(obj) in AllowedHosts:
# make sure only one face is selected
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(obj,"Face"+str(self.baseFace+1))
FreeCADGui.activateWorkbench("SketcherWorkbench")
FreeCADGui.runCommand("Sketcher_NewSketch")
FreeCAD.ArchObserver = ArchComponent.ArchSelectionObserver(obj,FreeCAD.ActiveDocument.Objects[-1],hide=False,nextCommand="Arch_Window")
FreeCADGui.Selection.addObserver(FreeCAD.ArchObserver)
else:
# preset
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Window"))
FreeCADGui.doCommand("import math,FreeCAD,Arch,WorkingPlane")
if obj and (self.baseFace != None):
FreeCADGui.doCommand("pl = WorkingPlane.getPlacementFromFace(FreeCAD.ActiveDocument." + obj.Name + ".Shape.Faces[" + str(self.baseFace) + "])")
else:
FreeCADGui.doCommand("m = FreeCAD.Matrix()")
FreeCADGui.doCommand("m.rotateX(math.pi/2)")
FreeCADGui.doCommand("pl = FreeCAD.Placement(m)")
FreeCADGui.doCommand("pl.Base = FreeCAD.Vector(" + str(point.x) + "," + str(point.y) + ","+ str(point.z) + ")")
wp = ""
for p in self.wparams:
wp += p.lower() + "=" + str(getattr(self,p)) + ","
FreeCADGui.doCommand("win = Arch.makeWindowPreset(\"" + WindowPresets[self.Preset-1] + "\"," + wp + "placement=pl)")
if obj:
if Draft.getType(obj) in AllowedHosts:
FreeCADGui.doCommand("Arch.removeComponents(win,host=FreeCAD.ActiveDocument."+obj.Name+")")
siblings = obj.Proxy.getSiblings(obj)
for sibling in siblings:
FreeCADGui.doCommand("Arch.removeComponents(win,host=FreeCAD.ActiveDocument."+sibling.Name+")")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
return
def update(self,point,info):
"this function is called by the Snapper when the mouse is moved"
delta = FreeCAD.Vector(self.Width/2,self.Thickness/2,self.Height/2)
rot = FreeCAD.Rotation()
self.baseFace = None
if info:
if "Face" in info['Component']:
import WorkingPlane
o = FreeCAD.ActiveDocument.getObject(info['Object'])
self.baseFace = int(info['Component'][4:])-1
f = o.Shape.Faces[self.baseFace]
p = WorkingPlane.getPlacementFromFace(f,rotated=True)
if p:
rot = p.Rotation
delta = rot.multVec(FreeCAD.Vector(delta.x,-delta.y,-delta.z))
self.tracker.pos(point.add(delta))
self.tracker.setRotation(rot)
def taskbox(self):
"sets up a taskbox widget"
w = QtGui.QWidget()
ui = FreeCADGui.UiLoader()
w.setWindowTitle(translate("Arch","Window options"))
grid = QtGui.QGridLayout(w)
# presets box
labelp = QtGui.QLabel(translate("Arch","Preset"))
valuep = QtGui.QComboBox()
valuep.addItems(["Create from scratch"]+WindowPresets)
valuep.setCurrentIndex(self.Preset)
grid.addWidget(labelp,0,0,1,1)
grid.addWidget(valuep,0,1,1,1)
QtCore.QObject.connect(valuep,QtCore.SIGNAL("currentIndexChanged(int)"),self.setPreset)
# image display
self.im = QtSvg.QSvgWidget(":/ui/ParametersWindowFixed.svg")
self.im.setMaximumWidth(200)
self.im.setMinimumHeight(120)
grid.addWidget(self.im,1,0,1,2)
self.im.hide()
# parameters
i = 2
for param in self.wparams:
lab = QtGui.QLabel(translate("Arch",param).decode("utf8"))
setattr(self,"val"+param,ui.createWidget("Gui::InputField"))
wid = getattr(self,"val"+param)
if param == "Width":
wid.setText(self.FORMAT % self.Width)
elif param == "Height":
wid.setText(self.FORMAT % self.Height)
else:
wid.setText(self.FORMAT % self.Thickness)
setattr(self,param,self.Thickness)
grid.addWidget(lab,i,0,1,1)
grid.addWidget(wid,i,1,1,1)
i += 1
FreeCAD.wid = wid
exec("""def valueChanged(d):
setArchWindowParamFunction('"""+param+"""',d)""")
QtCore.QObject.connect(getattr(self,"val"+param),QtCore.SIGNAL("valueChanged(double)"),valueChanged)
return w
def setParams(self,param,d):
setattr(self,param,d)
self.tracker.length(self.Width)
self.tracker.height(self.Height)
self.tracker.width(self.W1)
def setPreset(self,i):
self.Preset = i
if i > 0:
FreeCADGui.Snapper.setSelectMode(False)
self.tracker.length(self.Width)
self.tracker.width(self.Thickness)
self.tracker.height(self.Height)
self.tracker.on()
if i == 1:
self.im.load(":/ui/ParametersWindowFixed.svg")
elif i == 2:
self.im.load(":/ui/ParametersWindowSimple.svg")
elif i == 7:
self.im.load(":/ui/ParametersDoorGlass.svg")
elif i == 4:
self.im.load(":/ui/ParametersWindowStash.svg")
elif i == 6:
self.im.load(":/ui/ParametersDoorSimple.svg")
else:
self.im.load(":/ui/ParametersWindowDouble.svg")
self.im.show()
#for param in self.wparams:
# getattr(self,"val"+param).setEnabled(True)
else:
FreeCADGui.Snapper.setSelectMode(True)
self.tracker.off()
self.im.hide()
for param in self.wparams:
getattr(self,"val"+param).setEnabled(False)
class _Window(ArchComponent.Component):
"The Window object"
def __init__(self,obj):
ArchComponent.Component.__init__(self,obj)
obj.addProperty("App::PropertyStringList","WindowParts","Arch",translate("Arch","the components of this window"))
obj.addProperty("App::PropertyLength","HoleDepth","Arch",translate("Arch","The depth of the hole that this window makes in its host object. Keep 0 for automatic."))
obj.addProperty("Part::PropertyPartShape","Subvolume","Arch",translate("Arch","an optional volume to be subtracted from hosts of this window"))
obj.addProperty("App::PropertyLength","Width","Arch",translate("Arch","The width of this window (for preset windows only)"))
obj.addProperty("App::PropertyLength","Height","Arch",translate("Arch","The height of this window (for preset windows only)"))
obj.addProperty("App::PropertyVector","Normal","Arch",translate("Arch","The normal direction of this window"))
obj.addProperty("App::PropertyInteger","Preset","Arch","")
obj.addProperty("App::PropertyEnumeration","Role","Arch",translate("Arch","The role of this window"))
obj.setEditorMode("Preset",2)
self.Type = "Window"
obj.Role = Roles
obj.Proxy = self
def onChanged(self,obj,prop):
self.hideSubobjects(obj,prop)
if prop in ["Base","WindowParts"]:
self.execute(obj)
elif prop in ["HoleDepth"]:
for o in obj.InList:
if Draft.getType(o) in AllowedHosts:
o.Proxy.execute(o)
elif prop in ["Width","Height"]:
if obj.Preset != 0:
if obj.Base:
try:
if prop == "Height":
obj.Base.setDatum(16,obj.Height.Value)
elif prop == "Width":
obj.Base.setDatum(17,obj.Width.Value)
except:
# restoring constraints when loading a file fails
# because of load order, but it doesn't harm...
pass
FreeCAD.ActiveDocument.recompute()
def execute(self,obj):
import Part, DraftGeomUtils
pl = obj.Placement
base = None
if obj.Base:
if obj.Base.isDerivedFrom("Part::Feature"):
if hasattr(obj,"WindowParts"):
if obj.WindowParts and (len(obj.WindowParts)%5 == 0):
shapes = []
for i in range(len(obj.WindowParts)/5):
wires = []
wstr = obj.WindowParts[(i*5)+2].split(',')
for s in wstr:
j = int(s[4:])
if obj.Base.Shape.Wires:
if len(obj.Base.Shape.Wires) >= j:
wires.append(obj.Base.Shape.Wires[j])
if wires:
max_length = 0
for w in wires:
if w.BoundBox.DiagonalLength > max_length:
max_length = w.BoundBox.DiagonalLength
ext = w
wires.remove(ext)
shape = Part.Face(ext)
norm = shape.normalAt(0,0)
if hasattr(obj,"Normal"):
if obj.Normal:
if not DraftVecUtils.isNull(obj.Normal):
norm = obj.Normal
thk = float(obj.WindowParts[(i*5)+3])
if thk:
exv = DraftVecUtils.scaleTo(norm,thk)
shape = shape.extrude(exv)
for w in wires:
f = Part.Face(w)
f = f.extrude(exv)
shape = shape.cut(f)
if obj.WindowParts[(i*5)+4]:
zof = float(obj.WindowParts[(i*5)+4])
if zof:
zov = DraftVecUtils.scaleTo(norm,zof)
shape.translate(zov)
shapes.append(shape)
if shapes:
base = Part.makeCompound(shapes)
if not DraftGeomUtils.isNull(pl):
base.Placement = pl
elif not obj.WindowParts:
if not obj.Base.Shape.isNull():
base = obj.Base.Shape.copy()
if not DraftGeomUtils.isNull(pl):
base.Placement = base.Placement.multiply(pl)
else:
print "Arch: Bad formatting of window parts definitions"
base = self.processSubShapes(obj,base)
if base:
if not base.isNull():
obj.Shape = base
def getSubVolume(self,obj,plac=None):
"returns a subvolume for cutting in a base object"
# check if we have a custom subvolume
if hasattr(obj,"Subvolume"):
if obj.Subvolume:
if not obj.Subvolume.isNull():
return obj.Subvolume
# getting extrusion depth
base = None
if obj.Base:
base = obj.Base
width = 0
if hasattr(obj,"HoleDepth"):
if obj.HoleDepth.Value:
width = obj.HoleDepth.Value
if not width:
if base:
b = base.Shape.BoundBox
width = max(b.XLength,b.YLength,b.ZLength)
if not width:
if Draft.isClone(obj,"Window"):
orig = obj.Objects[0]
if orig.Base:
base = orig.Base
if hasattr(orig,"HoleDepth"):
if orig.HoleDepth.Value:
width = orig.HoleDepth.Value
if not width:
if base:
b = base.Shape.BoundBox
width = max(b.XLength,b.YLength,b.ZLength)
if not width:
width = 1.1112 # some weird value to have little chance to overlap with an existing face
if not base:
return None
# finding biggest wire in the base shape
max_length = 0
f = None
for w in base.Shape.Wires:
if w.BoundBox.DiagonalLength > max_length:
max_length = w.BoundBox.DiagonalLength
f = w
if f:
import Part
f = Part.Face(f)
norm = f.normalAt(0,0)
if hasattr(obj,"Normal"):
if obj.Normal:
if not DraftVecUtils.isNull(obj.Normal):
norm = obj.Normal
v1 = DraftVecUtils.scaleTo(norm,width)
f.translate(v1)
v2 = v1.negative()
v2 = Vector(v1).multiply(-2)
f = f.extrude(v2)
if plac:
f.Placement = plac
else:
f.Placement = obj.Placement
return f
return None
class _ViewProviderWindow(ArchComponent.ViewProviderComponent):
"A View Provider for the Window object"
def __init__(self,vobj):
ArchComponent.ViewProviderComponent.__init__(self,vobj)
def getIcon(self):
import Arch_rc
return ":/icons/Arch_Window_Tree.svg"
def updateData(self,obj,prop):
if (prop in ["WindowParts","Shape"]):
if obj.Shape:
if not obj.Shape.isNull():
self.colorize(obj)
def onChanged(self,vobj,prop):
if (prop == "DiffuseColor") and vobj.Object:
if len(vobj.DiffuseColor) < 2:
if vobj.Object.Shape:
if not vobj.Object.Shape.isNull():
self.colorize(vobj.Object)
def setEdit(self,vobj,mode):
taskd = _ArchWindowTaskPanel()
taskd.obj = self.Object
self.sets = [vobj.DisplayMode,vobj.Transparency]
vobj.DisplayMode = "Shaded"
vobj.Transparency = 80
if self.Object.Base:
self.Object.Base.ViewObject.show()
taskd.update()
FreeCADGui.Control.showDialog(taskd)
return True
def unsetEdit(self,vobj,mode):
vobj.DisplayMode = self.sets[0]
vobj.Transparency = self.sets[1]
if self.Object.Base:
self.Object.Base.ViewObject.hide()
FreeCADGui.Control.closeDialog()
return
def colorize(self,obj):
"setting different part colors"
solids = obj.Shape.copy().Solids
#print "Colorizing ", solids
colors = []
base = obj.ViewObject.ShapeColor
for i in range(len(solids)):
ccol = base
typeidx = (i*5)+1
if typeidx < len(obj.WindowParts):
typ = obj.WindowParts[typeidx]
if typ == WindowPartTypes[2]: # transparent parts
ccol = ArchCommands.getDefaultColor("WindowGlass")
for f in solids[i].Faces:
colors.append(ccol)
#print "colors: ",colors
if colors:
obj.ViewObject.DiffuseColor = colors
class _ArchWindowTaskPanel:
'''The TaskPanel for Arch Windows'''
def __init__(self):
self.obj = None
self.DECIMALS = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals",2)
import DraftGui
self.FORMAT = DraftGui.makeFormatSpec(self.DECIMALS,'Length')
self.form = QtGui.QWidget()
self.form.setObjectName("TaskPanel")
self.grid = QtGui.QGridLayout(self.form)
self.grid.setObjectName("grid")
self.title = QtGui.QLabel(self.form)
self.grid.addWidget(self.title, 0, 0, 1, 7)
# trees
self.tree = QtGui.QTreeWidget(self.form)
self.grid.addWidget(self.tree, 1, 0, 1, 7)
self.tree.setColumnCount(1)
self.tree.setMaximumSize(QtCore.QSize(500,24))
self.tree.header().hide()
self.wiretree = QtGui.QTreeWidget(self.form)
self.grid.addWidget(self.wiretree, 2, 0, 1, 3)
self.wiretree.setColumnCount(1)
self.wiretree.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
self.comptree = QtGui.QTreeWidget(self.form)
self.grid.addWidget(self.comptree, 2, 4, 1, 3)
self.comptree.setColumnCount(1)
# buttons
self.addButton = QtGui.QPushButton(self.form)
self.addButton.setObjectName("addButton")
self.addButton.setIcon(QtGui.QIcon(":/icons/Arch_Add.svg"))
self.grid.addWidget(self.addButton, 3, 0, 1, 1)
self.addButton.setMaximumSize(QtCore.QSize(70,40))
self.editButton = QtGui.QPushButton(self.form)
self.editButton.setObjectName("editButton")
self.editButton.setIcon(QtGui.QIcon(":/icons/Draft_Edit.svg"))
self.grid.addWidget(self.editButton, 3, 2, 1, 3)
self.editButton.setMaximumSize(QtCore.QSize(60,40))
self.editButton.setEnabled(False)
self.delButton = QtGui.QPushButton(self.form)
self.delButton.setObjectName("delButton")
self.delButton.setIcon(QtGui.QIcon(":/icons/Arch_Remove.svg"))
self.grid.addWidget(self.delButton, 3, 6, 1, 1)
self.delButton.setMaximumSize(QtCore.QSize(70,40))
self.delButton.setEnabled(False)
# add new
ui = FreeCADGui.UiLoader()
self.newtitle = QtGui.QLabel(self.form)
self.new1 = QtGui.QLabel(self.form)
self.new2 = QtGui.QLabel(self.form)
self.new3 = QtGui.QLabel(self.form)
self.new4 = QtGui.QLabel(self.form)
self.new5 = QtGui.QLabel(self.form)
self.field1 = QtGui.QLineEdit(self.form)
self.field2 = QtGui.QComboBox(self.form)
self.field3 = QtGui.QLineEdit(self.form)
self.field4 = ui.createWidget("Gui::InputField")
self.field5 = ui.createWidget("Gui::InputField")
self.createButton = QtGui.QPushButton(self.form)
self.createButton.setObjectName("createButton")
self.createButton.setIcon(QtGui.QIcon(":/icons/Arch_Add.svg"))
self.grid.addWidget(self.newtitle, 6, 0, 1, 7)
self.grid.addWidget(self.new1, 7, 0, 1, 1)
self.grid.addWidget(self.field1, 7, 2, 1, 5)
self.grid.addWidget(self.new2, 8, 0, 1, 1)
self.grid.addWidget(self.field2, 8, 2, 1, 5)
self.grid.addWidget(self.new3, 9, 0, 1, 1)
self.grid.addWidget(self.field3, 9, 2, 1, 5)
self.grid.addWidget(self.new4, 10, 0, 1, 1)
self.grid.addWidget(self.field4, 10, 2, 1, 5)
self.grid.addWidget(self.new5, 11, 0, 1, 1)
self.grid.addWidget(self.field5, 11, 2, 1, 5)
self.grid.addWidget(self.createButton, 12, 0, 1, 7)
self.newtitle.setVisible(False)
self.new1.setVisible(False)
self.new2.setVisible(False)
self.new3.setVisible(False)
self.new4.setVisible(False)
self.new5.setVisible(False)
self.field1.setVisible(False)
self.field2.setVisible(False)
for t in WindowPartTypes:
self.field2.addItem("")
self.field3.setVisible(False)
self.field3.setReadOnly(True)
self.field4.setVisible(False)
self.field5.setVisible(False)
self.createButton.setVisible(False)
QtCore.QObject.connect(self.addButton, QtCore.SIGNAL("clicked()"), self.addElement)
QtCore.QObject.connect(self.delButton, QtCore.SIGNAL("clicked()"), self.removeElement)
QtCore.QObject.connect(self.editButton, QtCore.SIGNAL("clicked()"), self.editElement)
QtCore.QObject.connect(self.createButton, QtCore.SIGNAL("clicked()"), self.create)
QtCore.QObject.connect(self.comptree, QtCore.SIGNAL("itemClicked(QTreeWidgetItem*,int)"), self.check)
QtCore.QObject.connect(self.wiretree, QtCore.SIGNAL("itemClicked(QTreeWidgetItem*,int)"), self.select)
self.update()
FreeCADGui.Selection.clearSelection()
def isAllowedAlterSelection(self):
return True
def isAllowedAlterView(self):
return True
def getStandardButtons(self):
return int(QtGui.QDialogButtonBox.Close)
def check(self,wid,col):
self.editButton.setEnabled(True)
self.delButton.setEnabled(True)
def select(self,wid,col):
FreeCADGui.Selection.clearSelection()
ws = ''
for it in self.wiretree.selectedItems():
if ws: ws += ","
ws += str(it.text(0))
w = int(str(it.text(0)[4:]))
if self.obj:
if self.obj.Base:
edges = self.obj.Base.Shape.Wires[w].Edges
for e in edges:
for i in range(len(self.obj.Base.Shape.Edges)):
if e.hashCode() == self.obj.Base.Shape.Edges[i].hashCode():
FreeCADGui.Selection.addSelection(self.obj.Base,"Edge"+str(i+1))
self.field3.setText(ws)
def getIcon(self,obj):
if hasattr(obj.ViewObject,"Proxy"):
return QtGui.QIcon(obj.ViewObject.Proxy.getIcon())
elif obj.isDerivedFrom("Sketcher::SketchObject"):
return QtGui.QIcon(":/icons/Sketcher_Sketch.svg")
else:
return QtGui.QIcon(":/icons/Tree_Part.svg")
def update(self):
'fills the tree widgets'
self.tree.clear()
self.wiretree.clear()
self.comptree.clear()
if self.obj:
if self.obj.Base:
item = QtGui.QTreeWidgetItem(self.tree)
item.setText(0,self.obj.Base.Name)
item.setIcon(0,self.getIcon(self.obj.Base))
if self.obj.Base.isDerivedFrom("Part::Feature"):
i = 0
for w in self.obj.Base.Shape.Wires:
if w.isClosed():
item = QtGui.QTreeWidgetItem(self.wiretree)
item.setText(0,"Wire" + str(i))
item.setIcon(0,QtGui.QIcon(":/icons/Draft_Draft.svg"))
i += 1
if self.obj.WindowParts:
for p in range(0,len(self.obj.WindowParts),5):
item = QtGui.QTreeWidgetItem(self.comptree)
item.setText(0,self.obj.WindowParts[p])
item.setIcon(0,QtGui.QIcon(":/icons/Tree_Part.svg"))
self.retranslateUi(self.form)
def addElement(self):
'opens the component creation dialog'
self.field1.setText('')
self.field3.setText('')
self.field4.setText('')
self.field5.setText('')
self.newtitle.setVisible(True)
self.new1.setVisible(True)
self.new2.setVisible(True)
self.new3.setVisible(True)
self.new4.setVisible(True)
self.new5.setVisible(True)
self.field1.setVisible(True)
self.field2.setVisible(True)
self.field3.setVisible(True)
self.field4.setVisible(True)