|
50 | 50 |
|
51 | 51 | params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD")
|
52 | 52 | printverbose = params.GetBool('printVerbose',False)
|
53 |
| - |
| 53 | +hassetcolor=[] |
| 54 | +alreadyhidden=[] |
54 | 55 | printverbose = True
|
55 | 56 |
|
56 | 57 | # Get the token map from the lexer. This is required.
|
57 | 58 | import tokrules
|
58 | 59 | from tokrules import tokens
|
59 | 60 |
|
| 61 | +def shallHide(subject): |
| 62 | + for obj in subject.OutListRecursive: |
| 63 | + if "Matrix_Union" in str(obj.FullName): |
| 64 | + return False |
| 65 | + if "Extrude" in str(obj.FullName): |
| 66 | + return True |
| 67 | + return False |
| 68 | + |
| 69 | +def setColorRecursively(obj,color,transp): |
| 70 | + if(obj.TypeId=="Part::Fuse" or obj.TypeId=="Part::MultiFuse"): |
| 71 | + for currentObject in obj.OutList: |
| 72 | + if (currentObject.TypeId=="Part::Fuse" or currentObject.TypeId=="Part::MultiFuse"): |
| 73 | + setColorRecursively(currentObject,color,transp) |
| 74 | + else: |
| 75 | + print("Fixing up colors for: "+str(currentObject.FullName)) |
| 76 | + if(currentObject not in hassetcolor): |
| 77 | + currentObject.ViewObject.ShapeColor=color |
| 78 | + currentObject.ViewObject.Transparency=transp |
| 79 | + setColorRecursively(currentObject,color,transp) |
| 80 | + else: |
| 81 | + setColorRecursively(currentObject,color,transp) |
| 82 | + |
| 83 | +def fixVisibility(): |
| 84 | + for obj in FreeCAD.ActiveDocument.Objects: |
| 85 | + if(( obj.TypeId=="Part::Fuse" or obj.TypeId=="Part::MultiFuse") and shallHide(obj)): |
| 86 | + if "Group" in obj.FullName: |
| 87 | + alreadyhidden.append(obj) |
| 88 | + obj.ViewObject.Visibility=False |
| 89 | + for currentObject in obj.OutList: |
| 90 | + if(currentObject not in alreadyhidden): |
| 91 | + currentObject.ViewObject.Visibility=True |
| 92 | + |
60 | 93 | if gui:
|
61 | 94 | try:
|
62 | 95 | _encoding = QtGui.QApplication.UnicodeUTF8
|
@@ -146,6 +179,9 @@ def processcsg(filename):
|
146 | 179 | if printverbose:
|
147 | 180 | print('End Parser')
|
148 | 181 | print(result)
|
| 182 | + fixVisibility() |
| 183 | + hassetcolor.clear() |
| 184 | + alreadyhidden.clear() |
149 | 185 | FreeCAD.Console.PrintMessage('End processing CSG file\n')
|
150 | 186 | doc.recompute()
|
151 | 187 |
|
@@ -179,6 +215,7 @@ def p_group_action1(p):
|
179 | 215 | else :
|
180 | 216 | p[0] = p[5]
|
181 | 217 |
|
| 218 | + |
182 | 219 | def p_group_action2(p) :
|
183 | 220 | 'group_action2 : group LPAREN RPAREN SEMICOL'
|
184 | 221 | if printverbose: print("Group2")
|
@@ -490,8 +527,27 @@ def p_color_action(p):
|
490 | 527 | transp = 100 - int(math.floor(100*float(p[3][3]))) #Alpha
|
491 | 528 | if gui:
|
492 | 529 | for obj in p[6]:
|
493 |
| - obj.ViewObject.ShapeColor =color |
494 |
| - obj.ViewObject.Transparency = transp |
| 530 | + if shallHide(obj): |
| 531 | + if "Group" in obj.FullName: |
| 532 | + obj.ViewObject.Visibility=False |
| 533 | + alreadyhidden.append(obj) |
| 534 | + if(obj.TypeId=="Part::Fuse" or obj.TypeId=="Part::MultiFuse"): |
| 535 | + for currentObject in obj.OutList: |
| 536 | + if (currentObject.TypeId=="Part::Fuse" or currentObject.TypeId=="Part::MultiFuse"): |
| 537 | + setColorRecursively(currentObject,color,transp) |
| 538 | + if(currentObject not in hassetcolor): |
| 539 | + currentObject.ViewObject.ShapeColor=color |
| 540 | + currentObject.ViewObject.Transparency=transp |
| 541 | + setColorRecursively(currentObject,color,transp) |
| 542 | + else: |
| 543 | + setColorRecursively(currentObject,color,transp) |
| 544 | + else: |
| 545 | + obj.ViewObject.ShapeColor =color |
| 546 | + obj.ViewObject.Transparency = transp |
| 547 | + else: |
| 548 | + obj.ViewObject.ShapeColor =color |
| 549 | + obj.ViewObject.Transparency = transp |
| 550 | + hassetcolor.append(obj) |
495 | 551 | p[0] = p[6]
|
496 | 552 |
|
497 | 553 | # Error rule for syntax errors
|
@@ -794,6 +850,10 @@ def p_multmatrix_action(p):
|
794 | 850 | transform_matrix = FreeCAD.Matrix()
|
795 | 851 | if printverbose: print("Multmatrix")
|
796 | 852 | if printverbose: print(p[3])
|
| 853 | + if gui: |
| 854 | + parentcolor=p[6][0].ViewObject.ShapeColor |
| 855 | + parenttransparency=p[6][0].ViewObject.Transparency |
| 856 | + |
797 | 857 | m1l=sum(p[3],[])
|
798 | 858 | if any('x' in me for me in m1l): #hexfloats
|
799 | 859 | m1l=[float.fromhex(me) for me in m1l]
|
@@ -873,6 +933,9 @@ def p_multmatrix_action(p):
|
873 | 933 | p[0] = [newobj]
|
874 | 934 | else :
|
875 | 935 | p[0] = [new_part]
|
| 936 | + if gui: |
| 937 | + new_part.ViewObject.ShapeColor=parentcolor |
| 938 | + new_part.ViewObject.Transparency = parenttransparency |
876 | 939 | if printverbose: print("Multmatrix applied")
|
877 | 940 |
|
878 | 941 | def p_matrix(p):
|
|
0 commit comments