1515# for detail see the LICENCE text file. *
1616#****************************************************************************
1717
18+ import dft_locator , os
19+ DefeaturingWBpath = os .path .dirname (dft_locator .__file__ )
20+ DefeaturingWB_icons_path = os .path .join ( DefeaturingWBpath , 'Resources' , 'icons' )
21+ global defeat_icon
22+ defeat_icon = os .path .join (DefeaturingWB_icons_path ,'DefeaturingParametric.svg' )
23+
1824'''
1925This Script includes python Features to represent Defeaturing Operations
2026'''
@@ -29,7 +35,29 @@ def attach(self, obj):
2935 self .Object = obj .Object
3036 return
3137
38+ def getIcon (self ):
39+ #import osc_locator, os
40+ global defeat_icon
41+ if isinstance (self .Object .Proxy ,DefeatShape ):
42+ print (defeat_icon )
43+ # try:
44+ # if self.upd: return (defeat_icon)
45+ # except: pass
46+ return (defeat_icon )
47+
3248 def updateData (self , fp , prop ):
49+ print (fp .Label )
50+ #if fp.Label.find('_ERR') != -1:
51+ # fp.touch()
52+ # #import FreeCAD
53+ # #doc = FreeCAD.ActiveDocument
54+ # #doc.getObject(fp.Name).touch()
55+ # print('touched')
56+ #self.getIcon()
57+ #try: self.upd
58+ #except: self.upd=True
59+ #self.upd=not self.upd
60+ print ('update' )
3361 return
3462
3563 def getDisplayModes (self ,obj ):
@@ -40,6 +68,10 @@ def setDisplayMode(self,mode):
4068 return mode
4169
4270 def onChanged (self , vp , prop ):
71+ #self.getIcon()
72+ print (prop )
73+ #self.getIcon()
74+ print ('change' )
4375 return
4476
4577 def __getstate__ (self ):
@@ -64,16 +96,9 @@ def claimChildren(self):
6496 objs .extend (self .Object .Components )
6597 if hasattr (self .Object ,"Children" ):
6698 objs .extend (self .Object .Children )
67-
6899 return objs
69100
70- def getIcon (self ):
71- import dft_locator , os
72- #import osc_locator, os
73- DefeaturingWB_icons_path = os .path .join ( os .path .dirname (dft_locator .__file__ ), 'Resources' , 'icons' )
74- if isinstance (self .Object .Proxy ,DefeatShape ):
75- return (os .path .join (DefeaturingWB_icons_path ,'DefeaturingParametric.svg' ))
76-
101+
77102##
78103class DefeatShape :
79104 '''return a refined shape'''
@@ -104,7 +129,8 @@ def onChanged(self, fp, prop):
104129 pass
105130
106131 def execute (self , fp ):
107- import OpenSCADUtils , FreeCAD , FreeCADGui , Part
132+ global defeat_icon
133+ import OpenSCADUtils , FreeCAD , FreeCADGui , Part , os
108134 doc = FreeCAD .ActiveDocument
109135 docG = FreeCADGui .ActiveDocument
110136 if fp .Base and fp .Base .Shape .isValid ():
@@ -123,7 +149,7 @@ def execute(self, fp):
123149 print (f .CenterOfMass )
124150 #print (f.hashCode())
125151 else :
126- oname = fp .Faces [0 ].split ('.' )[0 ]
152+ oname = fp .Base . Name #fp. Faces[0].split('.')[0]
127153 o = doc .getObject (oname )
128154 fc = []
129155 for i , c in enumerate (fp .CM ):
@@ -136,18 +162,29 @@ def execute(self, fp):
136162 if len (d_faces ) == len (fp .CM ):
137163 sh = fp .Base .Shape .defeaturing (d_faces )
138164 if fp .Base .Shape .isPartner (sh ):
139- FreeCAD .Console .PrintError ('Defeaturing failed\n ' )
140- fp .Shape = OpenSCADUtils .applyPlacement (sh )
141- if fp .Label .find ('_ERR' ) != - 1 :
142- fp .Label = fp .Label [:fp .Label .rfind ('_ERR' )]
143- docG .ActiveObject .ShapeColor = docG .getObject (fp .Base .Name ).ShapeColor
144- docG .ActiveObject .LineColor = docG .getObject (fp .Base .Name ).LineColor
145- docG .ActiveObject .PointColor = docG .getObject (fp .Base .Name ).PointColor
146- docG .ActiveObject .DiffuseColor = docG .getObject (fp .Base .Name ).DiffuseColor
147- docG .ActiveObject .Transparency = docG .getObject (fp .Base .Name ).Transparency
165+ #fp.touch()
166+ FreeCAD .Console .PrintError ('Defeaturing failed 1\n ' )
167+ defeat_icon = os .path .join (DefeaturingWB_icons_path ,'error.svg' )
168+ else :
169+ fp .Shape = OpenSCADUtils .applyPlacement (sh )
170+ if fp .Label .find ('_ERR' ) != - 1 :
171+ fp .Label = fp .Label [:fp .Label .rfind ('_ERR' )]
172+ defeat_icon = os .path .join (DefeaturingWB_icons_path ,'DefeaturingParametric.svg' )
173+ docG .ActiveObject .ShapeColor = docG .getObject (fp .Base .Name ).ShapeColor
174+ docG .ActiveObject .LineColor = docG .getObject (fp .Base .Name ).LineColor
175+ docG .ActiveObject .PointColor = docG .getObject (fp .Base .Name ).PointColor
176+ docG .ActiveObject .DiffuseColor = docG .getObject (fp .Base .Name ).DiffuseColor
177+ docG .ActiveObject .Transparency = docG .getObject (fp .Base .Name ).Transparency
148178 else :
149- FreeCAD .Console .PrintError ('Defeaturing failed\n ' )
179+ defeat_icon = os .path .join (DefeaturingWB_icons_path ,'error.svg' )
180+ #fp.touch()
181+ FreeCAD .Console .PrintError ('Defeaturing failed 2\n ' )
182+ sh = fp .Base .Shape
183+ fp .Shape = OpenSCADUtils .applyPlacement (sh )
150184 if fp .Label .find ('_ERR' ) == - 1 :
151185 fp .Label = '%s_ERR' % fp .Label
186+ docG .ActiveObject .ShapeColor = (1.00 ,0.00 ,0.00 )
187+ raise Exception ('Defeaturing FAILED!' )
188+ #doc.recompute()
152189##
153190
0 commit comments