Revision: 14743
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14743
Author:   migius
Date:     2008-05-08 17:58:00 +0200 (Thu, 08 May 2008)

Log Message:
-----------
DXF-importer prepared for ProE files, which are outside of DXF-specification.

Modified Paths:
--------------
    trunk/blender/release/scripts/bpymodules/dxfReader.py

Modified: trunk/blender/release/scripts/bpymodules/dxfReader.py
===================================================================
--- trunk/blender/release/scripts/bpymodules/dxfReader.py       2008-05-08 
08:59:36 UTC (rev 14742)
+++ trunk/blender/release/scripts/bpymodules/dxfReader.py       2008-05-08 
15:58:00 UTC (rev 14743)
@@ -1,11 +1,12 @@
 """This module provides a function for reading dxf files and parsing them into 
a useful tree of objects and data.
 
-    The convert function is called by the readDXF fuction to convert dxf 
strings into the correct data based 
-    on their type code.  readDXF expects a (full path) file name as input.
+       The convert function is called by the readDXF fuction to convert dxf 
strings into the correct data based
+       on their type code.  readDXF expects a (full path) file name as input.
 """
 
 # --------------------------------------------------------------------------
 # DXF Reader v0.9 by Ed Blake (AKA Kitsu)
+#  2008.05.08 modif.def convert() by Remigiusz Fiedler (AKA migius)
 # --------------------------------------------------------------------------
 # ***** BEGIN GPL LICENSE BLOCK *****
 #
@@ -30,216 +31,216 @@
 #from dxfImportObjects import *
 
 class Object:
-    """Empty container class for dxf objects"""
-    
-    def __init__(self, _type='', block=False):
-        """_type expects a string value."""
-        self.type = _type
-        self.name = ''
-        self.data = []
-    
-    def __str__(self):
-        if self.name:
-            return self.name
-        else:
-            return self.type
-    
-    def __repr__(self):
-        return str(self.data)
-    
-    def get_type(self, kind=''):
-        """Despite the name, this method actually returns all objects of type 
'kind' from self.data."""
-        if type:
-            objects = []
-            for item in self.data:
-                if type(item) != list and item.type == kind:
-                    # we want this type of object
-                    objects.append(item)
-                elif type(item) == list and item[0] == kind:
-                    # we want this type of data
-                    objects.append(item[1])
-            return objects
-    
+       """Empty container class for dxf objects"""
 
+       def __init__(self, _type='', block=False):
+               """_type expects a string value."""
+               self.type = _type
+               self.name = ''
+               self.data = []
+
+       def __str__(self):
+               if self.name:
+                       return self.name
+               else:
+                       return self.type
+
+       def __repr__(self):
+               return str(self.data)
+
+       def get_type(self, kind=''):
+               """Despite the name, this method actually returns all objects 
of type 'kind' from self.data."""
+               if type:
+                       objects = []
+                       for item in self.data:
+                               if type(item) != list and item.type == kind:
+                                       # we want this type of object
+                                       objects.append(item)
+                               elif type(item) == list and item[0] == kind:
+                                       # we want this type of data
+                                       objects.append(item[1])
+                       return objects
+
+
 class InitializationError(Exception): pass
 
 class StateMachine:
-    """(finite) State Machine from the great David Mertz's great Charming 
Python article."""
-    
-    def __init__(self):
-        self.handlers = []
-        self.startState = None
-        self.endStates = []
-            
-    def add_state(self, handler, end_state=0):
-        """All states and handlers are functions which return
-        a state and a cargo."""
-        self.handlers.append(handler)
-        if end_state:
-            self.endStates.append(handler)    
-    def set_start(self, handler):
-        """Sets the starting handler function."""
-        self.startState = handler
-    
-    
-    def run(self, cargo=None):
-        if not self.startState:
-            raise InitializationError,\
-                  "must call .set_start() before .run()"
-        if not self.endStates:
-            raise InitializationError, \
-                  "at least one state must be an end_state"
-        handler = self.startState
-        while 1:
-            (newState, cargo) = handler(cargo)
-            #print cargo
-            if newState in self.endStates:
-                return newState(cargo)
-                #break
-            elif newState not in self.handlers:
-                raise RuntimeError, "Invalid target %s" % newState
-            else:
-                handler = newState
+       """(finite) State Machine from the great David Mertz's great Charming 
Python article."""
 
+       def __init__(self):
+               self.handlers = []
+               self.startState = None
+               self.endStates = []
+
+       def add_state(self, handler, end_state=0):
+               """All states and handlers are functions which return
+               a state and a cargo."""
+               self.handlers.append(handler)
+               if end_state:
+                       self.endStates.append(handler)
+       def set_start(self, handler):
+               """Sets the starting handler function."""
+               self.startState = handler
+
+
+       def run(self, cargo=None):
+               if not self.startState:
+                       raise InitializationError,\
+                                 "must call .set_start() before .run()"
+               if not self.endStates:
+                       raise InitializationError, \
+                                 "at least one state must be an end_state"
+               handler = self.startState
+               while 1:
+                       (newState, cargo) = handler(cargo)
+                       #print cargo
+                       if newState in self.endStates:
+                               return newState(cargo)
+                               #break
+                       elif newState not in self.handlers:
+                               raise RuntimeError, "Invalid target %s" % 
newState
+                       else:
+                               handler = newState
+
 def get_name(data):
-    """Get the name of an object from its object data.
-    
-    Returns a pair of (data_item, name) where data_item is the list entry 
where the name was found
-    (the data_item can be used to remove the entry from the object data).  Be 
sure to check 
-    name not None before using the returned values!
-    """
-    value = None
-    for item in data:
-        if item[0] == 2:
-            value = item[1]
-            break
-    return item, value
+       """Get the name of an object from its object data.
 
+       Returns a pair of (data_item, name) where data_item is the list entry 
where the name was found
+       (the data_item can be used to remove the entry from the object data).  
Be sure to check
+       name not None before using the returned values!
+       """
+       value = None
+       for item in data:
+               if item[0] == 2:
+                       value = item[1]
+                       break
+       return item, value
+
 def get_layer(data):
-    """Expects object data as input.
-    
-    Returns (entry, layer_name) where entry is the data item that provided the 
layer name.
-    """
-    value = None
-    for item in data:
-        if item[0] == 8:
-            value = item[1]
-            break
-    return item, value
+       """Expects object data as input.
 
+       Returns (entry, layer_name) where entry is the data item that provided 
the layer name.
+       """
+       value = None
+       for item in data:
+               if item[0] == 8:
+                       value = item[1]
+                       break
+       return item, value
 
+
 def convert(code, value):
-    """Convert a string to the correct Python type based on its dxf code.
-    code types:
-        ints = 60-79, 170-179, 270-289, 370-389, 400-409, 1060-1070
-        longs = 90-99, 420-429, 440-459, 1071
-        floats = 10-39, 40-59, 110-139, 140-149, 210-239, 460-469, 1010-1059
-        hex = 105, 310-379, 390-399
-        strings = 0-9, 100, 102, 300-309, 410-419, 430-439, 470-479, 999, 
1000-1009
-    """
-    if 59 < code < 80 or 169 < code < 180 or 269 < code < 290 or 369 < code < 
390 or 399 < code < 410 or 1059 < code < 1071:
-        value = int(value)
-    elif 89 < code < 100 or 419 < code < 430 or 439 < code < 460 or code == 
1071:
-        value = long(value)
-    elif 9 < code < 60 or 109 < code < 150 or 209 < code < 240 or 459 < code < 
470 or 1009 < code < 1060:
-        value = float(value)
-    elif code == 105 or 309 < code < 380 or 389 < code < 400:
-        value = int(value, 16) # should be left as string?
-    else: # it's already a string so do nothing
-        pass
-    return value
+       """Convert a string to the correct Python type based on its dxf code.
+       code types:
+               ints = 60-79, 170-179, 270-289, 370-389, 400-409, 1060-1070
+               longs = 90-99, 420-429, 440-459, 1071
+               floats = 10-39, 40-59, 110-139, 140-149, 210-239, 460-469, 
1010-1059
+               hex = 105, 310-379, 390-399
+               strings = 0-9, 100, 102, 300-309, 410-419, 430-439, 470-479, 
999, 1000-1009
+       """
+       if 59 < code < 80 or 169 < code < 180 or 269 < code < 290 or 369 < code 
< 390 or 399 < code < 410 or 1059 < code < 1071:
+               value = int(float(value))
+       elif 89 < code < 100 or 419 < code < 430 or 439 < code < 460 or code == 
1071:
+               value = long(float(value))
+       elif 9 < code < 60 or 109 < code < 150 or 209 < code < 240 or 459 < 
code < 470 or 1009 < code < 1060:
+               value = float(value)
+       elif code == 105 or 309 < code < 380 or 389 < code < 400:
+               value = int(value, 16) # should be left as string?
+       else: # it's already a string so do nothing
+               pass
+       return value
 
 
 def findObject(infile, kind=''):
-    """Finds the next occurance of an object."""
-    obj = False
-    while 1:
-        line = infile.readline()
-        if not line: # readline returns '' at eof
-            return False
-        if not obj: # We're still looking for our object code
-            if line.lower().strip() == '0':
-                obj = True # found it
-        else: # we are in an object definition
-            if kind: # if we're looking for a particular kind
-                if line.lower().strip() == kind:
-                    obj = Object(line.lower().strip())
-                    break
-            else: # otherwise take anything non-numeric
-                if line.lower().strip() not in string.digits:
-                    obj = Object(line.lower().strip())
-                    break
-            obj = False # whether we found one or not it's time to start over
-    return obj
+       """Finds the next occurance of an object."""
+       obj = False
+       while 1:
+               line = infile.readline()
+               if not line: # readline returns '' at eof
+                       return False
+               if not obj: # We're still looking for our object code
+                       if line.lower().strip() == '0':
+                               obj = True # found it
+               else: # we are in an object definition
+                       if kind: # if we're looking for a particular kind
+                               if line.lower().strip() == kind:
+                                       obj = Object(line.lower().strip())
+                                       break
+                       else: # otherwise take anything non-numeric
+                               if line.lower().strip() not in string.digits:
+                                       obj = Object(line.lower().strip())
+                                       break
+                       obj = False # whether we found one or not it's time to 
start over
+       return obj
 
 def handleObject(infile):

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to