Hopefully a working merge with trunk (could be one error left in raytrace.c - will...
[blender.git] / release / scripts / import_dxf.py
index ceb4dd567220f89836f8f84edc61308dc7e6ae45..4de1de1ee39c525397545ba1d4959820e28c31ff 100644 (file)
@@ -311,7 +311,7 @@ import Blender
 from Blender import Mathutils, BezTriple, Draw, Registry, sys,\
 Text3d, Window, Mesh, Material, Group
 #from Blender.Mathutils import Vector, Matrix
-#import bpy #not used yet
+import bpy
 #import BPyMessages
 
 from dxfReader import readDXF
@@ -366,7 +366,7 @@ THIN_RESOLUTION = 8   #(4-64) thin_cylinder arc_resolution - number of segments
 MIN_THICK = MIN_DIST * 10.0  #minimal thickness by forced thickness
 MIN_WIDTH = MIN_DIST * 10.0  #minimal width by forced width
 TRIM_LIMIT = 3.0        #limit for triming of polylines-wide-segments (values:0.0 - 5.0)
-ELEVATION = 0.0 #standard elevation = coordinate Z value
+ELEVATION = 0.0 #standard elevation = coordinate Z
 
 BYBLOCK = 0
 BYLAYER = 256
@@ -860,7 +860,6 @@ class Line:  #-----------------------------------------------------------------
                        curve.append(BezTriple.New(points[1]))
                        for point in curve:
                                point.handleTypes = [VECT, VECT]
-                               point.radius = 1.0
                        curve.flagU = 0 # 0 sets the curve not cyclic=open
                        c.setResolu(settings.var['curve_res'])
                        c.update() #important for handles calculation
@@ -1325,11 +1324,9 @@ class Polyline:  #--------------------------------------------------------------
                                nurbs_points.append(pkt)
                        firstpoint = nurbs_points[0]
                        curve = pline.appendNurb(firstpoint)
-                       curve.setType(4) # set curve_type NURBS
-                       print 'deb: dir(curve):', dir(curve[-1]) #----------------
+                       curve.setType(4) # set curvetype NURBS
                        for point in nurbs_points[1:]:
                                curve.append(point)
-                               #TODO: what is the trick for bevel radius? curve[-1].radius = 1.0
                        if self.closed:
                                curve.flagU = 1+0 # Set curve cyclic=close and uni
                        else:
@@ -1352,7 +1349,6 @@ class Polyline:  #--------------------------------------------------------------
                                curve.append(BezTriple.New(p))
                        for point in curve:
                                point.handleTypes = [AUTO, AUTO]
-                               point.radius = 1.0
                        #curve.setType(1) #Bezier curve
                        if self.closed:
                                curve.flagU = 5 #1 # Set curve cyclic=close
@@ -1365,7 +1361,6 @@ class Polyline:  #--------------------------------------------------------------
                                        p0h1 = [p0h1[i]+begtangent[i] for i in range(3)]
                                        curve.__setitem__(0,BezTriple.New(p0h1+p0+p0h2))
                                curve[0].handleTypes = [FREE, ALIGN]   #remi--todo-----
-                               curve[0].radius = 1.0
                                if endtangent:
                                        #print 'deb:polyline2dCurve.draw curve[-1].vec:', curve[-1].vec #-----
                                        #print 'deb:polyline2dCurve.draw endtangent:', endtangent #-----
@@ -1375,7 +1370,6 @@ class Polyline:  #--------------------------------------------------------------
                                        curve.__setitem__(-1,BezTriple.New(p0h1+p0+p0h2))
                                        #print 'deb:polyline2dCurve.draw curve[-1].vec:', curve[-1].vec #-----
                                curve[-1].handleTypes = [ALIGN, FREE]   #remi--todo-----
-                               curve[-1].radius = 1.0
 
 
 
@@ -1412,7 +1406,6 @@ class Polyline:  #--------------------------------------------------------------
                                        for p in VectorTriples[1:-1]:
                                                curve.append(BezTriple.New(p))
                                                curve[-1].handleTypes = [FREE, FREE]
-                                               curve[-1].radius = 1.0
 
                                        prevHandleVect = VectorTriples[-1][:3]
                                        prevHandleType = FREE
@@ -1448,12 +1441,10 @@ class Polyline:  #--------------------------------------------------------------
                                        curve.__setitem__(0,BezTriple.New(p0h1+p0+p0h2))
 
                                        curve[0].handleTypes = [FREE,prevHandleType2]
-                                       curve[0].radius = 1.0
                                        #print 'deb:drawPlineCurve:closed curve[0].vec:', curve[0].vec #----------
                                        #print 'deb:drawPlineCurve:closed curve[0].handleTypes:', curve[0].handleTypes #----------
                                else: 
                                        curve[0].handleTypes[0] = VECT
-                                       curve[0].radius = 1.0
                        else: 
                                curve.flagU = 0 # Set curve not cyclic=open
 
@@ -2095,10 +2086,9 @@ DXF: X value; APP: 3D point, Y and Z values of control points (in WCS) (one entr
                self.ctrlpk_len = getit(obj, 73, 0) # Number of control points
                self.fit_pk_len = getit(obj, 74, 0) # Number of fit points (if any)
 
-               #TODO: import SPLINE as Bezier curve directly, possible?
                #print 'deb:Spline self.fit_pk_len=', self.fit_pk_len #------------------------
                #self.fit_pk_len = 0 # temp for debug
-               if self.fit_pk_len and settings.var['splines_as']==5:
+               if self.fit_pk_len and 'spline_as'==5:
                        self.spline = False
                        self.curved = True
                else:
@@ -2776,7 +2766,6 @@ class Arc:  #-----------------------------------------------------------------
                                curve.append(BezTriple.New(p))
                        for point in curve:
                                point.handleTypes = [FREE, FREE]
-                               point.radius = 1.0
                        curve.flagU = 0 # 0 sets the curve not cyclic=open
                        arc.setResolu(settings.var['curve_res'])
 
@@ -3308,7 +3297,6 @@ class Ellipse:  #---------------------------------------------------------------
                                        curve.append(BezTriple.New(p))
                                for point in curve:
                                        point.handleTypes = [FREE, FREE]
-                                       point.radius = 1.0
                                curve.flagU = 1 # 0 sets the curve not cyclic=open
                                if settings.var['fill_on']:
                                        arc.setFlag(6) # 2+4 set top and button caps
@@ -3319,7 +3307,6 @@ class Ellipse:  #---------------------------------------------------------------
                                        curve.append(BezTriple.New(p))
                                for point in curve:
                                        point.handleTypes = [FREE, FREE]
-                                       point.radius = 1.0
                                curve.flagU = 0 # 0 sets the curve not cyclic=open
 
                        arc.setResolu(settings.var['curve_res'])
@@ -4255,7 +4242,8 @@ def       analyzeDXF(dxfFile): #---------------------------------------
                Draw.PupMenu('DXF importer: report saved in INF-file:%t|' + '\'%s\'' %infFile)
        except:
                Draw.PupMenu('DXF importer: ERROR by writing report in INF-file:%t|' + '\'%s\'' %infFile)
-       #finally: f.close()
+       finally:
+               f.close()
 
 
 
@@ -4274,8 +4262,7 @@ def main(dxfFile):  #---------------#############################-----------
        global cur_COUNTER  #counter for progress_bar
        cur_COUNTER = 0
 
-       #try:
-       if 1:
+       try:
                #print "Getting settings..."
                global GUI_A, GUI_B, g_scale_as
                if not GUI_A['g_scale_on'].val:
@@ -4393,7 +4380,7 @@ def main(dxfFile):  #---------------#############################-----------
                #settings.write(message)
                if UI_MODE: Draw.PupMenu('DXF importer: Done!|finished in %.4f sec.' % time_text)
 
-       #finally:
+       finally:
                # restore state even if things didn't work
                #print 'deb:drawEntities finally!' #-----------------------
                Window.WaitCursor(False)
@@ -5085,7 +5072,6 @@ def drawCurveCircle(circle):  #--- no more used --------------------------------
        curve.append(p4)
        for point in curve:
                point.handleTypes = [AUTO, AUTO]
-               point.radius = 1.0
        curve.flagU = 1 # Set curve cyclic
        c.update()
 
@@ -5127,7 +5113,6 @@ def drawCurveArc(self):  #---- only for ELLIPSE --------------------------------
        curve.append(p4)
        for point in curve:
                point.handleTypes = [AUTO, AUTO]
-               point.radius = 1.0
        curve.flagU = 1 # Set curve cyclic
        a.update()
 
@@ -5167,12 +5152,12 @@ GUI_B = {}  # GUI-buttons dictionary for drawingTypes
 # settings default, initialize ------------------------
 
 points_as_menu  = "convert to: %t|empty %x1|mesh.vertex %x2|thin sphere %x3|thin box %x4|*curve.vertex %x5"
-lines_as_menu   = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|thin box %x4|Bezier-curve %x5|*NURBS-curve %x6"
+lines_as_menu   = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|thin box %x4|Bezier-curve %x5|NURBS-curve %x6"
 mlines_as_menu  = "convert to: %t|*edge %x1|*mesh %x2|*thin cylinder %x3|*thin box %x|*curve %x5"
 plines_as_menu  = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|*thin box %x4|Bezier-curve %x5|NURBS-curve %x6"
-splines_as_menu = "convert to: %t|mesh %x2|*thin cylinder %x3|*thin box %x4|*Bezier-curve %x5|NURBS-curve %x6"
+splines_as_menu = "convert to: %t|mesh %x2|*thin cylinder %x3|*thin box %x4|Bezier-curve %x5|NURBS-curve %x6"
 plines3_as_menu = "convert to: %t|*edge %x1|mesh %x2|*thin cylinder %x3|*thin box %x4|Bezier-curve %x5|NURBS-curve %x6"
-plmesh_as_menu  = "convert to: %t|*edge %x1|mesh %x2|*NURBS-surface %x6"
+plmesh_as_menu  = "convert to: %t|*edge %x1|mesh %x2|NURBS-surface %x6"
 solids_as_menu  = "convert to: %t|*edge %x1|mesh %x2"
 blocks_as_menu  = "convert to: %t|dupliGroup %x1|*real.Group %x2|*exploded %x3"
 texts_as_menu   = "convert to: %t|text %x1|*mesh %x2|*curve %x5"
@@ -5353,9 +5338,11 @@ def saveConfig():  #--todo-----------------------------------------------
                else:
                        #if BPyMessages.Warning_SaveOver(iniFile): #<- remi find it too abstarct
                        if sys.exists(iniFile):
-                               f = file(iniFile, 'r')
-                               header_str = f.readline()
-                               f.close()
+                               try:
+                                       f = file(iniFile, 'r')
+                                       try: header_str = f.readline()
+                                       finally: f.close()
+                               except: pass
                                if header_str.startswith(INIFILE_HEADER[0:13]):
                                        if Draw.PupMenu('  OK ? %t|SAVE OVER: ' + '\'%s\'' %iniFile) == 1:
                                                save_ok = True
@@ -5375,9 +5362,10 @@ def saveConfig():  #--todo-----------------------------------------------
                                output_str = '{\n'.join(output_str.split('{'))
                                try:
                                        f = file(iniFile, 'w')
-                                       f.write(INIFILE_HEADER + '\n# this is a comment line\n')
-                                       f.write(output_str)
-                                       f.close()
+                                       try:
+                                               f.write(INIFILE_HEADER + '\n# this is a comment line\n')
+                                               f.write(output_str)
+                                       finally: f.close()
                                        #Draw.PupMenu('DXF importer: INI-file: Done!%t|config-data saved in ' + '\'%s\'' %iniFile)
                                except:
                                        Draw.PupMenu('DXF importer: INI-file: Error!%t|failure by writing to ' + '\'%s\'|no config-data saved!' %iniFile)
@@ -5402,22 +5390,25 @@ def loadConfig():  #remi--todo-----------------------------------------------
        update_RegistryKey('iniFileName', iniFile)
        #print 'deb:loadConfig iniFile: ', iniFile #----------------------
        if iniFile.lower().endswith(INIFILE_EXTENSION) and sys.exists(iniFile):
-               f = file(iniFile, 'r')
-               header_str = f.readline()
-               if header_str.startswith(INIFILE_HEADER):
-                       data_str = f.read()
-                       f.close()
-                       #print 'deb:loadConfig data_str from %s: \n' %iniFile , data_str #-----------------
-                       data = eval(data_str)
-                       for k, v in data[0].iteritems():
-                               try: GUI_A[k].val = v
-                               except: GUI_A[k] = Draw.Create(v)
-                       for k, v in data[1].iteritems():
-                               try: GUI_B[k].val = v
-                               except: GUI_B[k] = Draw.Create(v)
-               else:
-                       f.close()
-                       Draw.PupMenu('DXF importer: INI-file:  Alert!%t|no valid header in INI-file: ' + '\'%s\'' %iniFile)
+               try:
+                       f = file(iniFile, 'r')
+                       try:
+                               header_str = f.readline()
+                               if header_str.startswith(INIFILE_HEADER):
+                                       data_str = f.read()
+                                       f.close()
+                                       #print 'deb:loadConfig data_str from %s: \n' %iniFile , data_str #-----------------
+                                       data = eval(data_str)
+                                       for k, v in data[0].iteritems():
+                                               try: GUI_A[k].val = v
+                                               except: GUI_A[k] = Draw.Create(v)
+                                       for k, v in data[1].iteritems():
+                                               try: GUI_B[k].val = v
+                                               except: GUI_B[k] = Draw.Create(v)
+                               else:
+                                       Draw.PupMenu('DXF importer: INI-file:  Alert!%t|no valid header in INI-file: ' + '\'%s\'' %iniFile)
+                       finally: f.close()
+               except: pass
        else:
                Draw.PupMenu('DXF importer: INI-file:  Alert!%t|no valid INI-file selected!')
                print "DXF importer: Alert!: no valid INI-file selected."