Skip to content

Commit

Permalink
use exceptions in OpenSCAD module
Browse files Browse the repository at this point in the history
derive OpenSCADError from FreeCADError if possible
  • Loading branch information
5263 committed Sep 17, 2014
1 parent 57db95a commit 333e6e3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
7 changes: 4 additions & 3 deletions src/Mod/OpenSCAD/OpenSCAD2Dgeom.py
Expand Up @@ -59,6 +59,7 @@ def dofacesoverlapboolean(bigface,smallface):
return bigface.common(smallface).Area > 0

def builddepdict(self):
import Part
import itertools
#isinsidelist = []
self.isinsidedict = {}
Expand All @@ -67,7 +68,7 @@ def builddepdict(self):
try:
overlap = Overlappingfaces.dofacesoverlapboolean(\
self.sortedfaces[bigfacei],self.sortedfaces[smallfacei])
except:
except Part.OCCError:
overlap = Overlappingfaces.dofacesoverlapallverts(\
self.sortedfaces[bigfacei],self.sortedfaces[smallfacei])
if overlap:
Expand Down Expand Up @@ -324,7 +325,7 @@ def edgestowires(edgelist,eps=0.001):
#if not close or wire.isClosed or outerd > 0.0001:
wirelist.append(Part.Wire(path))
done = True
except:
except Part.OCCError:
pass
if not done:
comp=Part.Compound(path)
Expand Down Expand Up @@ -373,7 +374,7 @@ def edgestofaces(edges,algo=3,eps=0.001):
edges2.append(Part.Line(p1,p0).toShape())
w = Part.Wire(edges2)
#w = Part.Wire(fcgeo.sortEdges(edges2))
except:
except OCCError:
comp=Part.Compound(edges2)
w = comp.connectEdgesToWires(False,eps).Wires[0]
facel.append(Part.Face(w))
Expand Down
12 changes: 4 additions & 8 deletions src/Mod/OpenSCAD/OpenSCADFeatures.py
Expand Up @@ -57,13 +57,9 @@ def __getstate__(self):

def __setstate__(self,state):
if state is not None:
try:
import FreeCAD
doc = FreeCAD.ActiveDocument #crap
self.Object = doc.getObject(state['ObjectName'])
except:
raise
# return None
import FreeCAD
doc = FreeCAD.ActiveDocument #crap
self.Object = doc.getObject(state['ObjectName'])

def claimChildren(self):
objs = []
Expand Down Expand Up @@ -448,7 +444,7 @@ def createGeometry(self,fp):
solid.reverse()
assert(solid.Volume >= 0)
solids.append(solid)
except:
except Part.OCCError:
solids.append(Part.Compound(faces))
fp.Shape=Part.Compound(solids)

Expand Down
8 changes: 7 additions & 1 deletion src/Mod/OpenSCAD/OpenSCADUtils.py
Expand Up @@ -35,7 +35,13 @@ def translate(context,text):
return QtGui.QApplication.translate(context, text, None, \
QtGui.QApplication.UnicodeUTF8)

class OpenSCADError(Exception):
try:
import FreeCAD
BaseError = FreeCAD.Base.FreeCADError
except ImportError,AttributeError:
BaseError = RuntimeError

class OpenSCADError(BaseError):
def __init__(self,value):
self.value= value
#def __repr__(self):
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/OpenSCAD/exportDRAWEXE.py
Expand Up @@ -95,9 +95,10 @@ def saveShape(csg,filename,shape,name,hasplacement = True,cleanshape=False):
breppath=os.path.join(spath,'%s.brep'%uname)
csg.write("restore %s.brep %s\n" % (uname,name))
if cleanshape:
import Part
try:
shape = shape.cleaned()
except:
except Part.OCCError:
shape = shape.copy()
if hasplacement is None: # saved with placement
hasplacement = False # saved with placement
Expand Down
7 changes: 2 additions & 5 deletions src/Mod/OpenSCAD/importCSG.py
Expand Up @@ -92,7 +92,7 @@ def insert(filename,docname):
groupname = os.path.splitext(os.path.basename(filename))[0]
try:
doc=FreeCAD.getDocument(docname)
except:
except FreeCAD.Base.FreeCADError:
doc=FreeCAD.newDocument(docname)
#importgroup = doc.addObject("App::DocumentObjectGroup",groupname)
if filename.lower().endswith('.scad'):
Expand Down Expand Up @@ -599,10 +599,7 @@ def process_linear_extrude(obj,h) :
mylinear.Base = newobj #obj
mylinear.Dir = (0,0,h)
mylinear.Placement=FreeCAD.Placement()
try:
mylinear.Solid = True
except:
pass
mylinear.Solid = True
if gui:
newobj.ViewObject.hide()
return(mylinear)
Expand Down
15 changes: 5 additions & 10 deletions src/Mod/OpenSCAD/prototype.py
Expand Up @@ -340,8 +340,7 @@ def center(obj,x,y,z):
try:
global lastimportpath
filename=os.path.join(lastimportpath,filename)
except:
raise #no path given
except: raise #no path given
# Check for a mesh fileformat support by the Mesh mddule
if extension.lower() in reverseimporttypes()['Mesh']:
import Mesh
Expand Down Expand Up @@ -372,10 +371,7 @@ def center(obj,x,y,z):
global dxfcache
layers=dxfcache.get(id(doc),[])
if layers:
try:
groupobj=[go for go in layers if (not layera) or go.Label == layera]
except:
groupobj= None
groupobj=[go for go in layers if (not layera) or go.Label == layera]
else:
groupobj= None
if not groupobj:
Expand All @@ -392,7 +388,7 @@ def center(obj,x,y,z):
edges.extend(shapeobj.Shape.Edges)
try:
f=edgestofaces(edges)
except:
except Part.OCCError:
FreeCAD.Console.PrintError(\
'processing of dxf import faild\nPlease rework \'%s\' manualy\n' % layera)
f=Part.Shape() #empty Shape
Expand Down Expand Up @@ -507,8 +503,7 @@ def center(obj,x,y,z):
if fcpar:
try:
obj.ViewObject.hide()
except:
raise
except: raise
if True: #never refine the Shape, as it itroduces crashes
return obj
else: #refine Shape
Expand Down Expand Up @@ -684,7 +679,7 @@ def open(filename):
def insert(filename,docname):
try:
doc=FreeCAD.getDocument(docname)
except:
except NameError:
doc=FreeCAD.newDocument(docname)
readfile(filename).addtofreecad(doc)
#doc.recompute()
Expand Down

0 comments on commit 333e6e3

Please sign in to comment.