-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathArchSketchObject.py
3522 lines (2998 loc) · 148 KB
/
ArchSketchObject.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) 2018-25 Paul Lee <[email protected]> *
#* *
#* 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, FreeCADGui, Sketcher, Part, Draft, DraftVecUtils
import ArchWindow
import Arch, ArchWall, ArchCurtainWall
from FreeCAD import Vector
import SketchArchIcon
import SketchArchCommands
# for ArchWindows
from PySide.QtCore import QT_TRANSLATE_NOOP
from PySide import QtGui, QtCore
import uuid, math, time
pi = math.pi
App = FreeCAD
Gui = FreeCADGui
zeroMM = FreeCAD.Units.Quantity('0mm')
MM = FreeCAD.Units.Quantity('1mm')
tolerance = 0.000000001
#--------------------------------------------------------------------------#
# Class Definition #
#--------------------------------------------------------------------------#
class ArchSketchObject:
def __init__(self, obj):
#self.Type = "ArchSketchObject"
pass
class ArchSketch(ArchSketchObject):
''' ArchSketch - Sketcher::SketchObjectPython for Architectural Layout '''
MasterSketchSubelementTags = ['MasterSketchSubelementTag',
'MasterSketchIntersectingSubelementTag' ]
SnapPresetDict = {'AxisStart':0.0, '1/4':0.25, '1/3':1/3, 'MidPoint':0.5,
'2/3':2/3, '3/4':3/4, 'AxisEnd':1.0}
EdgeTagDicts=['EdgeTagDictArchive', 'EdgeTagDictInitial', 'EdgeTagDictSync']
GeomSupported = (Part.LineSegment, Part.Circle, Part.ArcOfCircle,
Part.Ellipse)
def __init__(self, obj):
pass
ArchSketchObject.__init__(self, obj)
''' call self.setProperties '''
self.setProperties(obj)
self.setPropertiesLinkCommon(obj)
self.initEditorMode(obj)
obj.ViewObject.Proxy=0
return None
def initEditorMode(self, obj):
''' Set DispayMode for Data Properties in Combo View Editor '''
obj.setEditorMode("MapMode",1)
obj.setEditorMode("MapReversed",1)
obj.setEditorMode("Placement",1)
def setProperties(self, fp):
''' Add self.properties '''
fp.Proxy = self
if not hasattr(self,"Type"):
self.Type = "ArchSketch"
for i in ArchSketch.EdgeTagDicts:
if not hasattr(self,i):
setattr(self, i, {})
if not hasattr(self,'PropertySetDict'):
self.PropertySetDict = {}
if not hasattr(self,"clEdgeDict"):
self.clEdgeDict = {}
if not hasattr(self,"clEdgePartnerIndexFlat"):
self.clEdgePartnerIndexFlat = []
if not hasattr(self,"clEdgeSameIndexFlat"):
self.clEdgeSameIndexFlat = []
if not hasattr(self,"clEdgeEqualIndexFlat"):
self.clEdgeEqualIndexFlat = []
''' Added ArchSketch Properties '''
ArchSkPropStr = 'Added ArchSketch Properties'
if not hasattr(fp,"Align"):
fp.addProperty("App::PropertyEnumeration","Align",ArchSkPropStr,"The default alignment for the wall with this ArchSketch as its base object")
fp.Align = ['Left','Right','Center']
fp.Align = 'Center'
if not hasattr(fp,"Offset"):
fp.addProperty("App::PropertyDistance","Offset",ArchSkPropStr,QT_TRANSLATE_NOOP("App::Property","The offset between the wall (segment) and its baseline (only for left and right alignments)"))
if not hasattr(fp,"ArchSketchWidth"):
fp.addProperty("App::PropertyLength","ArchSketchWidth",ArchSkPropStr,"ArchSketchWidth returned ")
fp.ArchSketchWidth = 200 * MM # Default
if not hasattr(fp,"DetectRoom"):
fp.addProperty("App::PropertyBool","DetectRoom",ArchSkPropStr,QT_TRANSLATE_NOOP("App::Property","Enable to detect rooms enclosed by edges/walls - For CellComplex object to work, the generated shape is not shown in the ArchSketch object, but shown by a CellComplex Object. This make recompute of this object longer !"))
if not hasattr(fp,"CellComplexElements"):
fp.addProperty('Part::PropertyPartShape', 'CellComplexElements', ArchSkPropStr, QT_TRANSLATE_NOOP("App::Property","The Shape of built CellComplexElements"),8)
if not hasattr(fp,"FloorHeight"):
fp.addProperty("App::PropertyLength","FloorHeight",ArchSkPropStr,"Global ArchSketch Floor to Next Floor Height")
fp.FloorHeight = 3000 * MM # Default
if not hasattr(fp,"PropertySet"):
fp.addProperty("App::PropertyEnumeration","PropertySet",ArchSkPropStr
,QT_TRANSLATE_NOOP("App::Property"
,"List User Defined Property Sets"))
fp.PropertySet = ['Default']
if not hasattr(self,"PropSetListPrev"):
self.PropSetListPrev = []
if not hasattr(self,"PropSetPickedUuid"):
self.PropSetPickedUuid = None
if not hasattr(fp,"ShapeList"):
sstr="The returned Shape of the ArchSkech with supported geometries"
fp.addProperty('Part::PropertyTopoShapeList', 'ShapeList',
ArchSkPropStr, QT_TRANSLATE_NOOP("App::Property",
sstr),8)
def setPropertiesLinkCommon(self, orgFp, linkFp=None, mode=None):
'''
Set properties which are :
1. common to ArchSketchObject & Arch Objects, and
2. required for Link of Arch Objects
mode='init', 'ODR' for different settings
'''
if linkFp:
fp = linkFp
else:
fp = orgFp
prop = fp.PropertiesList
for i in ArchSketch.MasterSketchSubelementTags:
if linkFp: # no Proxy
if i not in prop:
linkFp.addProperty("App::PropertyPythonObject", i)
setattr(linkFp, i, str())
else: # either ArchSketch or ArchObjects, should have Proxy
if isinstance(orgFp.Proxy, ArchSketch):
if not hasattr(fp.Proxy, i):
setattr(orgFp.Proxy, i, str())
else: # i.e. other ArchObjects
if i not in prop:
orgFp.addProperty("App::PropertyPythonObject", i)
setattr(orgFp, i, str())
if "MasterSketchSubelementIndex" not in prop:
fp.addProperty("App::PropertyInteger","MasterSketchSubelementIndex","Referenced Object","Index of MasterSketchSubelement to be synced on the fly. For output only.", 8)
fp.setEditorMode("MasterSketchSubelementIndex",1)
if "MasterSketchIntersectingSubelementIndex" not in prop:
fp.addProperty("App::PropertyInteger","MasterSketchIntersectingSubelementIndex","Referenced Object","Index of MasterSketchInteresctingSubelement to be synced on the fly. For output only.", 8)
fp.setEditorMode("MasterSketchIntersectingSubelementIndex",2)
''' Referenced Object '''
# "Host" for ArchSketch and Arch Equipment
# (currently all Objects calls except Window which has "Hosts")
if not isinstance(fp.getLinkedObject().Proxy, ArchWindow._Window):
pass
if "Host" not in prop:
fp.addProperty("App::PropertyLink","Host","Referenced Object",
"The object that host this object / this object attach to")
# "Hosts" for Window
else:
if "Hosts" not in prop:
fp.addProperty("App::PropertyLinkList","Hosts","Window",
QT_TRANSLATE_NOOP("App::Property",
"The objects that host this window"))
# Arch Window's code
if "MasterSketch" not in prop:
fp.addProperty("App::PropertyLink","MasterSketch","Referenced Object","Master Sketch to Attach on")
if "MasterSketchSubelement" not in prop:
fp.addProperty("App::PropertyString","MasterSketchSubelement","Referenced Object","Master Sketch Sub-Element to Attach on")
if "MasterSketchSubelementOffset" not in prop:
fp.addProperty("App::PropertyDistance","MasterSketchSubelementOffset","Referenced Object","Master Sketch Sub-Element Attached Offset from Startpoint")
if "MasterSketchSubelementSnapPreset" not in prop:
fp.addProperty("App::PropertyEnumeration","MasterSketchSubelementSnapPreset","Referenced Object","Preset Snap Offset from Axis Startpoint; will add ms-SubelementOffset Distance (mm)")
fp.MasterSketchSubelementSnapPreset = [ "AxisStart", "1/4", "1/3", "MidPoint", "2/3", "3/4", "AxisEnd", "CustomValue" ]
if "MasterSketchSubelementSnapCustom" not in prop:
fp.addProperty("App::PropertyFloatConstraint", "MasterSketchSubelementSnapCustom", "Referenced Object", "Custom Value: 0 to 1, Start/EndPoint of Axis (Use formula for fraction e.g 2/11")
fp.MasterSketchSubelementSnapCustom = (0.0, 0.0, 1.0, 0.001) # (Default, Start, Finish, Step)
if "MasterSketchIntersectingSubelement" not in prop:
fp.addProperty("App::PropertyString","MasterSketchIntersectingSubelement",
"Referenced Object","Master Sketch Subelement Intersecting the Sub-Element Attached on")
if "AttachToSubelementOrOffset" not in prop:
fp.addProperty("App::PropertyEnumeration","AttachToSubelementOrOffset","Referenced Object","Select MasterSketch Subelement or Specify Offset to Attach")
fp.AttachToSubelementOrOffset = [ "Attach To Edge & Alignment", "Attach to Edge", "Follow Only Offset XYZ & Rotation" ]
if "AttachmentOffsetXyzAndRotation" not in prop:
fp.addProperty("App::PropertyPlacement","AttachmentOffsetXyzAndRotation","Referenced Object","Specify XYZ and Rotation Offset")
if "AttachmentOffsetExtraRotation" not in prop:
fp.addProperty("App::PropertyEnumeration","AttachmentOffsetExtraRotation","Referenced Object","Extra Rotation about X, Y or Z Axis")
fp.AttachmentOffsetExtraRotation = [ "None", "X-Axis CW90", "X-Axis CCW90", "X-Axis CW180", "Y-Axis CW90", "Y-Axis CCW90", "Y-Axis CW180","Z-Axis CW90", "Z-Axis CCW90", "Z-Axis CW180"]
if "OriginOffsetXyzAndRotation" not in prop:
fp.addProperty("App::PropertyPlacement","OriginOffsetXyzAndRotation","Referenced Object","Specify Origin's XYZ and Rotation Offset")
if "FlipOffsetOriginToOtherEnd" not in prop:
fp.addProperty("App::PropertyBool","FlipOffsetOriginToOtherEnd","Referenced Object","Flip Offset Origin to Other End of Edge / Wall ")
if "Flip180Degree" not in prop:
fp.addProperty("App::PropertyBool","Flip180Degree","Referenced Object","Flip Orientation 180 Degree / Inside-Outside / Front-Back")
if "OffsetFromIntersectingSubelement" not in prop:
fp.addProperty("App::PropertyBool","OffsetFromIntersectingSubelement",
"Referenced Object","Offset from the Master Sketch Subelement Intersecting the Sub-Element to Attached on")
if "AttachmentAlignment" not in prop:
fp.addProperty("App::PropertyEnumeration","AttachmentAlignment","Referenced Object","If AttachToEdge&Alignment, Set (Wall)Left/Right to align to Edge of Wall")
fp.AttachmentAlignment = [ "WallLeft", "WallRight", "Left", "Right" ]
if isinstance(fp.getLinkedObject().Proxy, ArchWindow._Window):
fp.AttachmentAlignment = "WallLeft" # default for Windows which have normal 0,1,0 so somehow set to ArchWindows (updated from to 'left' after orientation of 'left/right' changed )
else:
fp.AttachmentAlignment = "WallLeft" # default for cases other than Windows
if fp.AttachmentAlignment in [ "Edge", "EdgeGroupWidthLeft", "EdgeGroupWidthRight" ]:
curAlign = fp.AttachmentAlignment
fp.AttachmentAlignment = [ "WallLeft", "WallRight", "Left", "Right" ]
if curAlign == "Edge":
fp.AttachmentAlignment = "Left"
elif curAlign == "EdgeGroupWidthLeft":
fp.AttachmentAlignment = "WallLeft"
elif curAlign == "EdgeGroupWidthRight":
fp.AttachmentAlignment = "WallRight"
else: # Should not happen
fp.AttachmentAlignment = "Left"
if "AttachmentAlignmentOffset" not in prop:
fp.addProperty("App::PropertyDistance","AttachmentAlignmentOffset","Referenced Object","Set Offset from Edge / EdgeGroupWidth +ve Right / -ve Left")
attachToAxisOrSketchExisting = None
fpLinkedObject = fp.getLinkedObject()
if "AttachToAxisOrSketch" in prop:
attachToAxisOrSketchExisting = fp.AttachToAxisOrSketch
else: # elif "AttachToAxisOrSketch" not in prop:
fp.addProperty("App::PropertyEnumeration","AttachToAxisOrSketch","Referenced Object","Select Object Type to Attach on ")
if isinstance(fpLinkedObject.Proxy, ArchSketch):
fp.AttachToAxisOrSketch = [ "Host", "Master Sketch", "Placement Axis" ]
else: # i.e. other ArchObjects
fp.AttachToAxisOrSketch = [ "None", "Host", "Master Sketch"]
# has existing selection
if attachToAxisOrSketchExisting is not None:
if attachToAxisOrSketchExisting == "Hosts":
attachToAxisOrSketchExisting = "Host" # Can attach to only 1 host
fp.AttachToAxisOrSketch = attachToAxisOrSketchExisting
# No existing selection, ie. newly added "AttachToAxisOrSketch" attribute
elif isinstance(fpLinkedObject.Proxy, ArchSketch):
fp.AttachToAxisOrSketch = "Master Sketch" # default option for ArchSketch + Link to ArchSketch
else: # other Arch Objects # elif fpLinkedObject.Proxy.Type != "ArchSketch":
# currently only if fp is Window and mode is 'ODR', not to attach to Host or otherwise it would relocate to 1st edge
if mode == 'ODR':
#if isinstance(fp.Proxy, ArchWindow._Window):
if isinstance(fpLinkedObject.Proxy, ArchWindow._Window):
fp.AttachToAxisOrSketch = "None"
else:
pass # currently no other ArchObjects use 'ODR'
else: # default 'ODR' (or None), i.e. if
fp.AttachToAxisOrSketch = "Host" # default option for Arch Objects in general
def appLinkExecute(self, fp, linkFp, index, linkElement):
self.setPropertiesLinkCommon(fp, linkFp)
updateAttachmentOffset(fp, linkFp)
def execute(self, fp):
''' Features to Run in Addition to Sketcher.execute() '''
normal = fp.getGlobalPlacement().Rotation.multVec(FreeCAD.Vector(0,0,1))
if True:
propSetPickedUuidPrev = self.PropSetPickedUuid
propSetListPrev = self.PropSetListPrev
propSetSelectedNamePrev = fp.PropertySet
propSetSelectedNameCur = None
# get full list of PropertySet
propSetListCur = self.getPropertySet(fp)
# get updated name (if any) of the selected PropertySet
propSetSelectedNameCur = self.getPropertySet(fp,
propSetUuid=propSetPickedUuidPrev)
if propSetSelectedNameCur: # True if selection is not deleted
if propSetListPrev != propSetListCur:
fp.PropertySet = propSetListCur
fp.PropertySet = propSetSelectedNameCur
self.propSetListPrev = propSetListCur
elif propSetSelectedNamePrev != propSetSelectedNameCur:
fp.PropertySet = propSetSelectedNameCur
else: # True if selection is deleted
if propSetListPrev != propSetListCur:
fp.PropertySet = propSetListCur
fp.PropertySet = 'Default'
''' (-I) - Sync EdgeTagDictSync: ArchSketch Edge Indexes against Tags '''
self.syncEdgeTagDictSync(fp)
''' (VII) - Update attachment angle and attachment point coordinate '''
updateAttachmentOffset(fp)
''' (IX or XI) - Update the order of edges by getSortedClusters '''
self.updateShapeList(fp)
self.updateSortedClustersEdgesOrder(fp)
''' (X) - Instances fp.resolve / fp.recompute - '''
fp.solve()
fp.recompute()
if fp.DetectRoom:
bb = boundBoxShape(fp, 5000)
skEdges, skEdgesF = getSketchEdges(fp)
cutEdges = selfCutEdges(skEdges)
fragmentEdgesL = flattenEdLst(cutEdges)
import BOPTools.SplitAPI
regions = BOPTools.SplitAPI.slice(bb, fragmentEdgesL, 'Standard', tolerance = 0.0)
resultFaces = removeBBFace(bb, regions.SubShapes) # assume to be faces
extv = normal.multiply(fp.FloorHeight) # WallHeight+fp.SlabThickness
resultFacesRebased = []
for f in resultFaces:
f.Placement = f.Placement.multiply(fp.Placement)
resultFacesRebased.append(f)
solids = [f.extrude(extv) for f in resultFacesRebased]
solidsCmpd = Part.Compound(solids)
fp.CellComplexElements = solidsCmpd
def updateShapeList(self, fp):
skGeom = fp.Geometry
skGeomEdgesFullSet = []
for c, i in enumerate(skGeom):
skGeomEdge = i.toShape()
skGeomEdgesFullSet.append(skGeomEdge)
fp.ShapeList = skGeomEdgesFullSet
def updateSortedClustersEdgesOrder(self, fp):
tup = getSketchSortedClEdgesOrder(fp)
(clEdgePartnerIndex,clEdgeSameIndex,clEdgeEqualIndex,
clEdgePartnerIndexFlat,clEdgeSameIndexFlat,clEdgeEqualIndexFlat) = tup
self.clEdgeDict['clEdgeSameIndexFlat'] = clEdgeSameIndexFlat
self.clEdgePartnerIndex = clEdgePartnerIndex
self.clEdgeSameIndex = clEdgeSameIndex
self.clEdgeEqualIndex = clEdgeEqualIndex
self.clEdgePartnerIndexFlat = clEdgePartnerIndexFlat
self.clEdgeSameIndexFlat = clEdgeSameIndexFlat
self.clEdgeEqualIndexFlat = clEdgeEqualIndexFlat
for key, value in iter(fp.Proxy.PropertySetDict.items()):
tupUuid = getSketchSortedClEdgesOrder(fp, propSetUuid=key)
(partnerIndex,sameIndex,equalIndex,
partnerIndexFlat,sameIndexFlat,equalIndexFlat) = tupUuid
if not self.clEdgeDict.get(key,None):
self.clEdgeDict[key] = {}
self.clEdgeDict[key]['clEdgeSameIndexFlat'] = sameIndexFlat
def onChanged(self, fp, prop):
if prop in ["MasterSketch", "PlacementAxis", "AttachToAxisOrSketch"]:
changeAttachMode(fp, prop)
if prop == "PropertySet":
uuid = self.getPropertySet(fp, propSetName=fp.PropertySet)
self.PropSetPickedUuid = uuid
def rebuildEdgeTagDicts(self, fp): # To be called by Local
self.EdgeTagDictArchive = dict(self.EdgeTagDictSync)
self.EdgeTagDictInitial = {}
self.EdgeTagDictSync = {}
i = 0
while True:
try:
tagI = fp.Geometry[i].Tag
except:
break
edgeTagDictArchiveTagDict = None
if self.EdgeTagDictArchive.values():
if isinstance (list(self.EdgeTagDictArchive.values())[0], dict):
none, tagArchive = self.getEdgeTagDictArchiveTagIndex(fp,
tag=None, index=i)
if tagArchive is not None:
edgeTagDictArchiveTagDict=self.EdgeTagDictArchive[tagArchive]
self.EdgeTagDictInitial[tagI] = edgeTagDictArchiveTagDict
else:
edgeTagDictArchiveTagDict = None
if not edgeTagDictArchiveTagDict:
self.EdgeTagDictInitial[tagI]={}
self.EdgeTagDictInitial[tagI]['index']=i
i += 1
self.EdgeTagDictSync = self.EdgeTagDictInitial.copy()
def callParentToRebuildMasterSketchTags(self, fp):
foundParentArchSketchNames = []
foundParentLnkArchSketchesNames = []
foundParentLnkArchSketches = []
foundParentArchWalls = []
foundParentArchObjectNames = []
foundParentArchObjects = []
for parent in fp.InList:
# Find ArchSketch
if Draft.getType(parent) == "ArchSketch":
if parent.MasterSketch == fp:
# Prevent duplicate and run below multiple times
if parent.Name not in foundParentArchSketchNames:
foundParentArchSketchNames.append(parent.Name)
# Find Link of ArchSketch
elif Draft.getType(parent.getLinkedObject()) == "ArchSketch":
if parent.MasterSketch == fp:
if parent.Name not in foundParentLnkArchSketchesNames:
foundParentLnkArchSketchesNames.append(parent.Name)
foundParentLnkArchSketches.append(parent)
# Find ArchWall to further find parents
elif hasattr(parent,'Base'):
if fp == parent.Base:
if parent not in foundParentArchWalls:
foundParentArchWalls.append(parent)
# Find ArchObject parents of ArchWall (Equipment, Window)
for wall in foundParentArchWalls:
for parent in wall.InList:
if hasattr(parent,'Hosts'): # Windows (and others?)
if wall in parent.Hosts:
if parent.Name not in foundParentArchObjectNames:
foundParentArchObjectNames.append(parent.Name)
foundParentArchObjects.append(parent)
elif hasattr(parent,'Host'): # (Lnk)Eqpt/Win (Lnk)AchrSketch
if wall == parent.Host:
if parent.Name not in foundParentArchObjectNames:
foundParentArchObjectNames.append(parent.Name)
foundParentArchObjects.append(parent)
# call ArchSketch parent
total = len(foundParentArchSketchNames)
for key, parentArchSketchName in enumerate(foundParentArchSketchNames):
parent = FreeCAD.ActiveDocument.getObject(parentArchSketchName)
parent.Proxy.setProperties(parent)
parent.Proxy.setPropertiesLinkCommon(parent)
lite = True
if lite:
updatePropertiesLinkCommonODR(parent, None)
# call Link of ArchSketch parent
for lnkArchSketch in foundParentLnkArchSketches:
linkedObj = lnkArchSketch.getLinkedObject()
linkedObj.Proxy.setPropertiesLinkCommon(linkedObj, lnkArchSketch)
updatePropertiesLinkCommonODR(linkedObj, lnkArchSketch)
# call Arch Objects (& Link) (Equipment, Window)
for archObject in foundParentArchObjects:
if archObject.isDerivedFrom('App::Link'):
linkedObj = archObject.getLinkedObject()
linkedObjProxy = linkedObj.Proxy
ArchSketch.setPropertiesLinkCommon(linkedObjProxy, linkedObj, archObject, mode='ODR')
updatePropertiesLinkCommonODR(linkedObj, archObject)
else:
archObject.Proxy.onDocumentRestored(archObject)
updatePropertiesLinkCommonODR(archObject, None)
#**************************************************************************#
''' Property Set Dict (self.PropertySetDict) related method() '''
def getPropertySet(self, fp, propSetUuid=None, propSetName=None):
if not propSetUuid and not propSetName:
setDicts = list(self.PropertySetDict.values())
setNames = [ d.get('name',None) for d in setDicts ]
propertySetList = ['Default'] + setNames
return propertySetList
elif propSetUuid:
setDict = self.PropertySetDict.get(propSetUuid, None)
if setDict:
setName = setDict.get('name',None)
return setName
else:
return None
elif propSetName:
if propSetName == 'Default' : return None
for k, v in self.PropertySetDict.items():
if v.get('name') == propSetName:
uuid = k
break
return uuid
#**************************************************************************#
''' edge Tag Dict (self.syncEdgeTagDictSync) related method() '''
def getWidths(self, fp, propSetUuid=None):
''' wrapper function for uniform format '''
return self.getSortedClustersEdgesWidth(fp, propSetUuid)
def getAligns(self, fp, propSetUuid=None):
''' wrapper function for uniform format '''
return self.getSortedClustersEdgesAlign(fp, propSetUuid)
def getOffsets(self, fp , propSetUuid=None):
''' wrapper function for uniform format '''
return self.getSortedClustersEdgesOffset(fp, propSetUuid)
def getUnsortedEdgesWidth(self, fp, propSetUuid=None):
widthsList = []
for j in range(0, len(fp.Geometry)):
curWidthEdgeTagDictSync = self.getEdgeTagDictSyncWidth(fp, None, j,
propSetUuid)
widthsList.append(curWidthEdgeTagDictSync)
return widthsList
def getUnsortedEdgesAlign(self, fp, propSetUuid=None):
alignsList = []
for j in range(0, len(fp.Geometry)):
curAlignEdgeTagDictSync = self.getEdgeTagDictSyncAlign(fp, None, j,
propSetUuid)
alignsList.append(curAlignEdgeTagDictSync)
return alignsList
def getSortedClustersEdgesWidth(self, fp, propSetUuid=None):
''' This method check the SortedClusters-isSame-(flat)List (omitted
construction geometry), find the corresponding edgesWidth and make
a list of (WidthX, WidthX+1 ...) '''
''' Options of data to store width (& other) information conceived
1st Option - Use self.widths: a Dict of { EdgeX : WidthX, ...}
But when Sketch is edited with some edges deleted, the
edges indexes change, the widths stored become wrong
2nd Option - Use abdullah's edge geometry
.... bugs found, not working yet
3rd Option - Use self.EdgeTagDictSync
.... convoluted object sync, restoreOnLoad '''
widthsList = []
if not propSetUuid:
clEdgeSameIndexFlat = self.clEdgeDict.get('clEdgeSameIndexFlat',None)
else:
clEdgeSameIndexFlat = None
dictUuid = self.clEdgeDict.get(propSetUuid,None)
if dictUuid:
clEdgeSameIndexFlat = dictUuid.get('clEdgeSameIndexFlat',None)
if not clEdgeSameIndexFlat:
return []
for i in clEdgeSameIndexFlat:
curWidth = self.getEdgeTagDictSyncWidth(fp, None, i, propSetUuid)
if not curWidth:
if fp.ArchSketchWidth:
curWidth = fp.ArchSketchWidth.Value
else:
curWidth = 0 # 0 follow Wall's Width
widthsList.append(curWidth)
return widthsList
def getEdgeTagDictSyncWidth(self,fp,tag=None,index=None,propSetUuid=None):
if tag is not None:
tagI = tag
elif index is not None:
try: # Cases where self.EdgeTagDictSync not updated yet ?
tagI = fp.Geometry[index].Tag
except:
self.syncEdgeTagDictSync(fp)
try: # again
tagI = fp.Geometry[index].Tag
except:
return None
else:
return None #pass
if propSetUuid:
dictI = self.EdgeTagDictSync[tagI].get(propSetUuid, None)
else:
dictI = self.EdgeTagDictSync[tagI]
if not dictI:
return None
widthI = dictI.get('width', None)
return widthI
def getSortedClustersEdgesAlign(self, fp, propSetUuid):
'''
This method check the SortedClusters-isSame-(flat)List
find the corresponding edgesAlign ...
and make a list of (AlignX, AlignX+1 ...)
'''
alignsList = []
if not propSetUuid:
clEdgeSameIndexFlat = self.clEdgeDict.get('clEdgeSameIndexFlat',None)
else:
clEdgeSameIndexFlat = None
dictUuid = self.clEdgeDict.get(propSetUuid,None)
if dictUuid:
clEdgeSameIndexFlat = dictUuid.get('clEdgeSameIndexFlat',None)
if not clEdgeSameIndexFlat:
return []
for i in clEdgeSameIndexFlat:
curAlign = self.getEdgeTagDictSyncAlign(fp, None, i, propSetUuid)
if not curAlign:
curAlign = fp.Align # default Align (set up to 'Center')
alignsList.append(curAlign)
return alignsList
def getEdgeTagDictSyncAlign(self,fp,tag=None,index=None,propSetUuid=None):
if tag is not None:
tagI = tag
elif index is not None:
try:
tagI = fp.Geometry[index].Tag
#return self.EdgeTagDictSync[tagI].get('align', None)
except:
self.syncEdgeTagDictSync(fp)
try: # again
tagI = fp.Geometry[index].Tag
#return self.EdgeTagDictSync[tagI].get('align', None)
except:
return None
if propSetUuid:
dictI = self.EdgeTagDictSync[tagI].get(propSetUuid, None)
else:
dictI = self.EdgeTagDictSync[tagI]
if not dictI:
return None
alignI = dictI.get('align', None)
return alignI
def getSortedClustersEdgesOffset(self, fp, propSetUuid=None):
offsetsList = []
if not propSetUuid:
clEdgeSameIndexFlat = self.clEdgeDict.get('clEdgeSameIndexFlat',None)
else:
clEdgeSameIndexFlat = None
dictUuid = self.clEdgeDict.get(propSetUuid,None)
if dictUuid:
clEdgeSameIndexFlat = dictUuid.get('clEdgeSameIndexFlat',None)
if not clEdgeSameIndexFlat:
return []
for i in clEdgeSameIndexFlat:
curOffset = self.getEdgeTagDictSyncOffset(fp, None, i, propSetUuid)
if not curOffset:
curOffset = fp.Offset
offsetsList.append(curOffset)
return offsetsList
def getEdgeTagDictSyncOffset(self,fp,tag=None,index=None,propSetUuid=None):
if tag is not None:
tagI = tag
elif index is not None:
try:
tagI = fp.Geometry[index].Tag
except:
self.syncEdgeTagDictSync(fp)
try: # again
tagI = fp.Geometry[index].Tag
except:
return None
else:
return None #pass
if propSetUuid:
dictI = self.EdgeTagDictSync[tagI].get(propSetUuid, None)
else:
dictI = self.EdgeTagDictSync[tagI]
if not dictI:
return None
OffsetI = dictI.get('offset', None)
return OffsetI
def getEdgeTagDictSyncRoleStatus(self, fp, tag=None, index=None,
role='wallAxis', propSetUuid=None):
if tag is not None:
pass
elif index is not None:
tag = fp.Geometry[index].Tag
if not propSetUuid:
return self.EdgeTagDictSync[tag].get(role, 'Not Set')
else:
dictPropSet = self.EdgeTagDictSync[tag].get(propSetUuid, None)
if dictPropSet:
return dictPropSet.get(role, 'Not Set')
else:
return None
def getEdgeTagDictSyncWallStatus(self,fp,tag=None,index=None,role='wallAxis',
propSetUuid=None):
roleStatus = self.getEdgeTagDictSyncRoleStatus(fp, tag, index, role,
propSetUuid)
if roleStatus == True:
wallAxisStatus = True
elif roleStatus == 'Disabled':
wallAxisStatus = False
# 'Not Set' (default)
else:
if tag != None: #elif
index, none = self.getEdgeTagIndex(fp,tag, None)
construction = fp.getConstruction(index)
if not construction: # for Wall, True if not construction
wallAxisStatus = True
else:
wallAxisStatus = False
return wallAxisStatus
def getEdgeTagDictSyncStructureStatus(self, fp, tag=None, index=None,
role='slab', propSetUuid=None):
roleStatus = self.getEdgeTagDictSyncRoleStatus(fp, tag, index, role,
propSetUuid)
if roleStatus == True:
slabStatus = True
elif roleStatus == 'Disabled':
slabStatus = False
# 'Not Set' (default) / False
else:
slabStatus = False
return slabStatus
def getEdgeTagDictSyncCurtainWallStatus(self, fp, tag=None, index=None,
role='curtainWallAxis', propSetUuid=None):
roleStatus = self.getEdgeTagDictSyncRoleStatus(fp, tag, index, role,
propSetUuid)
if roleStatus == True:
cwAxisStatus = True
elif roleStatus == 'Disabled':
cwAxisStatus = False
# 'Not Set' (default)
else:
cwAxisStatus = False
return cwAxisStatus
def getEdgeTagDictSyncStairsStatus(self, fp, tag=None, index=None,
role='flightAxis', propSetUuid=None):
roleStatus = self.getEdgeTagDictSyncRoleStatus(fp, tag, index, role,
propSetUuid)
if roleStatus == True:
stairsStatus = True
elif roleStatus == 'Disabled':
stairsStatus = False
# 'Not Set' (default)
else:
stairsStatus = False
return stairsStatus
def syncEdgeTagDictSync(self, fp):
edgeTagDictTemp = {}
i = 0
while True:
try:
tagI = fp.Geometry[i].Tag
except:
break
try:
edgeTagDictSyncTagDict = self.EdgeTagDictSync[tagI]
except:
edgeTagDictSyncTagDict = {}
edgeTagDictTemp[tagI] = edgeTagDictSyncTagDict
edgeTagDictTemp[tagI]['index']=i
i += 1
self.EdgeTagDictSync = edgeTagDictTemp.copy()
return
def getEdgeTagDictArchiveTagIndex(self, fp, tag=None, index=None):
if tag and index is None:
try:
return fp.Proxy.EdgeTagDictArchive[tag]['index'], None
except:
return None, None
elif not tag and index is not None:
try:
for key, value in iter(fp.Proxy.EdgeTagDictArchive.items()):
if value['index'] == index:
return None, key # i.e. tagArchive
return None, None
except:
return None, None
def getEdgeTagIndex(self, fp, tag=None, index=None, useEdgeTagDictSyncFindIndex=False):
''' Arguments : fp, tag=None, index=None, useEdgeTagDictSyncFindIndex=False
Return : index, tagSync (not tagInitial nor tagArchive...yet) '''
if tag and index is None:
if useEdgeTagDictSyncFindIndex == False:
i = 0
while True:
try:
if tag == fp.Geometry[i].Tag:
return i, None
except:
print (" Debug - Tag does not (/no longer) exist " + "\n")
return None, None
i += 1
elif not tag and index is not None:
try:
tagSync = fp.Geometry[index].Tag
except:
print("DEBUG - Index does not (or no longer?) exist ")
return None, None
return None, tagSync
def getEdgeGeom(self, fp, index):
return fp.Geometry[index]
#***************************************************************************#
''' ArchWall-related '''
''' ArchStructure-related '''
''' ArchCurtainWall-related '''
def getWallBaseShapeEdgesInfo(self,fp,role='wallAxis',propSetUuid=None):
edgesSortedClusters = []
skGeom = fp.GeometryFacadeList
skGeomEdges = []
skPlacement = fp.Placement # Get Sketch's placement to restore later
for i in skGeom:
if isinstance(i.Geometry, ArchSketch.GeomSupported):
wallAxisStatus = self.getEdgeTagDictSyncWallStatus(fp, tag=i.Tag,
role='wallAxis', propSetUuid=propSetUuid)
if wallAxisStatus:
skGeomEdgesI = i.Geometry.toShape()
skGeomEdges.append(skGeomEdgesI)
for cluster in Part.getSortedClusters(skGeomEdges):
clusterTransformed = []
for edge in cluster:
edge.Placement = skPlacement.multiply(edge.Placement)
clusterTransformed.append(edge)
edgesSortedClusters.append(clusterTransformed)
return {'wallAxis' : edgesSortedClusters}
def getStructureBaseShapeWires(self, fp, role='slab', propSetUuid=None):
skGeom = fp.GeometryFacadeList
skGeomEdges = []
skPlacement = fp.Placement # Get Sketch's placement to restore later
structureBaseShapeWires = []
for i in skGeom:
if isinstance(i.Geometry, ArchSketch.GeomSupported):
slabStatus = self.getEdgeTagDictSyncStructureStatus(fp,
tag=i.Tag, role='slab', propSetUuid=propSetUuid)
if slabStatus:
skGeomEdgesI = i.Geometry.toShape()
skGeomEdges.append(skGeomEdgesI)
# Sort Sketch edges consistently with below procedures same as ArchWall
clusterTransformed = []
for cluster in Part.getSortedClusters(skGeomEdges):
edgesTransformed = []
for edge in cluster:
edge.Placement = skPlacement.multiply(edge.Placement)
edgesTransformed.append(edge)
clusterTransformed.append(edgesTransformed)
for clusterT in clusterTransformed:
structureBaseShapeWires.append(Part.Wire(clusterT))
return {'slabWires':structureBaseShapeWires, 'faceMaker':'Bullseye',
'slabThickness' : 250}
def getCurtainWallBaseShapeEdgesInfo(self, fp, role='curtainWallAxis',
propSetUuid=None):
skGeom = fp.GeometryFacadeList
skGeomEdges = []
skPlacement = fp.Placement # Get Sketch's placement to restore later
curtainWallBaseShapeEdges = []
for i in skGeom:
# support Line, Arc, Circle for Sketch as Base at the moment
if isinstance(i.Geometry, (Part.LineSegment, Part.Circle,
Part.ArcOfCircle)):
cwAxisStatus = self.getEdgeTagDictSyncCurtainWallStatus(fp,
tag=i.Tag,role='curtainWallAxis',
propSetUuid=propSetUuid)
if cwAxisStatus:
skGeomEdgesI = i.Geometry.toShape()
skGeomEdges.append(skGeomEdgesI)
for edge in skGeomEdges:
edge.Placement = edge.Placement.multiply(skPlacement)
curtainWallBaseShapeEdges.append(edge)
return {'curtainWallEdges':curtainWallBaseShapeEdges}
def getStairsBaseShapeEdgesInfo(self,fp,role='wallAxis',propSetUuid=None):
edgesSortedClusters = []
skGeom = fp.GeometryFacadeList
skGeomEdges = []
skPlacement = fp.Placement # Get Sketch's placement to restore later
for i in skGeom:
if isinstance(i.Geometry, ArchSketch.GeomSupported):
flightAxisStatus = self.getEdgeTagDictSyncStairsStatus(fp,
tag=i.Tag, role='flightAxis',
propSetUuid=propSetUuid)
if flightAxisStatus:
skGeomEdgesI = i.Geometry.toShape()
skGeomEdges.append(skGeomEdgesI)
edgesTransformed = []
for edge in skGeomEdges:
edge.Placement = skPlacement.multiply(edge.Placement)
edgesTransformed.append(edge)
return {'flightAxis' : edgesTransformed}
#***************************************************************************#
''' onDocumentRestored '''
def onDocumentRestored(self, fp):