From 19135f9586b76ba8e97d8b7dd2b421f6583cbe93 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 28 Jul 2014 19:47:40 -0300 Subject: [PATCH] Draft: small bug fix in DXF importer --- src/Mod/Arch/importIFC.py | 8 +- src/Mod/Draft/importDXF.py | 155 +------------------------------------ 2 files changed, 5 insertions(+), 158 deletions(-) diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index 8ff35d1703ab..26dc8c0d83be 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -1330,14 +1330,14 @@ def getIfcBrepFacesData(obj,scale=1,sub=False,tessellation=1): if obj.Terrain.Shape: if not obj.Terrain.Shape.isNull(): if obj.Terrain.Shape.isValid(): - fcshape = obj.Terrain.Shape + shape = obj.Terrain.Shape if shape: import Part sols = [] - if fcshape.Solids: - dataset = fcshape.Solids + if shape.Solids: + dataset = shape.Solids else: - dataset = fcshape.Shells + dataset = shape.Shells print "Warning! object contains no solids" for sol in shape.Solids: s = [] diff --git a/src/Mod/Draft/importDXF.py b/src/Mod/Draft/importDXF.py index 30e07f518427..c09da118bd27 100644 --- a/src/Mod/Draft/importDXF.py +++ b/src/Mod/Draft/importDXF.py @@ -274,7 +274,7 @@ def getColor(): return (r,g,b,0.0) else: p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View") - c = params.GetUnsigned("DefaultShapeLineColor",0) + c = p.GetUnsigned("DefaultShapeLineColor",0) r = float(((c>>24)&0xFF)/255) g = float(((c>>16)&0xFF)/255) b = float(((c>>8)&0xFF)/255) @@ -303,159 +303,6 @@ def formatObject(obj,dxfobj=None): elif hasattr(obj.ViewObject,"LineColor"): obj.ViewObject.LineColor = dxfDefaultColor - - -class fcformat: - # OBSOLETED - TO BE REMOVED - "this contains everything related to color/lineweight formatting" - def __init__(self,drawing): - self.dxf = drawing - params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") - self.paramtext = params.GetBool("dxftext") - self.dxflayout = params.GetBool("dxflayouts") - self.paramstyle = params.GetInt("dxfstyle") - self.join = params.GetBool("joingeometry") - self.makeBlocks = params.GetBool("groupLayers") - self.stdSize = params.GetBool("dxfStdSize") - self.importDxfHatches = params.GetBool("importDxfHatches") - self.renderPolylineWidth = params.GetBool("renderPolylineWidth") - self.importPoints = params.GetBool("dxfImportPoints") - bparams = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View") - - if self.paramstyle > 1: - # checking if FreeCAD background is dark or bright - if bparams.GetBool("Gradient"): - c1 = bparams.GetUnsigned("BackgroundColor2") - c2 = bparams.GetUnsigned("BackgroundColor3") - r1 = float((c1>>24)&0xFF) - g1 = float((c1>>16)&0xFF) - b1 = float((c1>>8)&0xFF) - r2 = float((c2>>24)&0xFF) - g2 = float((c2>>16)&0xFF) - b2 = float((c2>>8)&0xFF) - v1 = FreeCAD.Vector(r1,g1,b1) - v2 = FreeCAD.Vector(r2,g2,b2) - v = v2.sub(v1) - v.multiply(0.5) - cv = v1.add(v) - else: - c1 = bparams.GetUnsigned("BackgroundColor") - r1 = float((c1>>24)&0xFF) - g1 = float((c1>>16)&0xFF) - b1 = float((c1>>8)&0xFF) - cv = FreeCAD.Vector(r1,g1,b1) - value = cv.x*.3 + cv.y*.59 + cv.z*.11 - if value < 128: self.brightbg = False - else: - self.brightbg = True - - if gui and draftui: - r = float(draftui.color.red()/255.0) - g = float(draftui.color.green()/255.0) - b = float(draftui.color.blue()/255.0) - self.lw = float(draftui.linewidth) - else: - self.lw = float(params.GetInt("linewidth")) - c = params.GetUnsigned("color") - r = float(((c>>24)&0xFF)/255) - g = float(((c>>16)&0xFF)/255) - b = float(((c>>8)&0xFF)/255) - self.col = (r,g,b,0.0) - - if self.paramstyle == 3: - parammappingfile = params.GetString("dxfmappingfile") - self.table = self.buildTable(parammappingfile) - - def buildTable(self,tablefile): - "builds a table for converting colors into linewidths" - try: f = pythonopen(tablefile) - except ValueError: - print "error: ",tablefile, " not found" - return None - table = {} - header = len(f.readline().split("\t")) - if header == 15: - for l in f: - s = l.split("\t") - if "Color_" in s[0]: - index = int(s[0].split("_")[1]) - if s[1] == "(Object)": color = "object" - else: - c = s[2].split(",") - color = [float(c[0])/255,float(c[1])/255,float(c[2])/255] - if (color == [0.0,0.0,0.0]) and (not self.brightbg): - color = [1.0,1.0,1.0] - if s[2] == "(Object)": width = "object" - else: width = float(s[10])*10 - table[index]=[color,width] - elif header == 3: - for l in f: - s = l.split("\t") - index = int(s[0]) - c = string.replace(s[1],'"','') - c = c.split(",") - color = [float(c[0])/255,float(c[1])/255,float(c[2])/255] - width = float(s[2]) - table[index]=[color,width] - for i in range(256): - if not i in table.keys(): - table[i]=["object","object"] - else: - print "error building mapping table: file format not recognized" - table = None - print table - return table - - def formatObject(self,obj,dxfobj=None): - "applies color and linetype to objects" - if hasattr(obj.ViewObject,"TextColor"): - obj.ViewObject.TextColor = (0.0,0.0,0.0) - if self.paramstyle == 1: - if hasattr(obj.ViewObject,"TextColor"): - obj.ViewObject.TextColor = self.col - else: - obj.ViewObject.LineColor = self.col - obj.ViewObject.LineWidth = self.lw - elif (self.paramstyle == 2) and dxfobj: - if hasattr(obj.ViewObject,"TextColor"): - if dxfobj.color_index == 256: cm = self.getGroupColor(dxfobj)[:3] - else: cm = dxfColorMap.color_map[dxfobj.color_index] - obj.ViewObject.TextColor = (cm[0],cm[1],cm[2]) - else: - if dxfobj.color_index == 256: cm = self.getGroupColor(dxfobj) - elif (dxfobj.color_index == 7) and self.brightbg: cm = [0.0,0.0,0.0] - else: cm = dxfColorMap.color_map[dxfobj.color_index] - obj.ViewObject.LineColor = (cm[0],cm[1],cm[2],0.0) - obj.ViewObject.LineWidth = self.lw - elif (self.paramstyle == 3) and dxfobj: - if hasattr(obj.ViewObject,"TextColor"): - cm = table[dxfobj.color_index][0] - wm = table[dxfobj.color_index][1] - obj.ViewObject.TextColor = (cm[0],cm[1],cm[2]) - else: - if dxfobj.color_index == 256: - cm = self.table[self.getGroupColor(dxfobj,index=True)][0] - wm = self.table[self.getGroupColor(dxfobj,index=True)][1] - else: - cm = self.table[dxfobj.color_index][0] - wm = self.table[dxfobj.color_index][1] - if cm == "object": cm = self.getGroupColor(dxfobj) - else: obj.ViewObject.LineColor = (cm[0],cm[1],cm[2],0.0) - if wm == "object": wm = self.lw - else: obj.ViewObject.LineWidth = wm - - def getGroupColor(self,dxfobj,index=False): - "get color of bylayer stuff" - name = dxfobj.layer - for table in self.dxf.tables.get_type("table"): - if table.name == "layer": - for l in table.get_type("layer"): - if l.name == name: - if index: return l.color - else: - if (l.color == 7) and self.brightbg: return [0.0,0.0,0.0] - else: return dxfColorMap.color_map[l.color] - def vec(pt): "returns a rounded Vector from a dxf point" return FreeCAD.Vector(round(pt[0],prec()),round(pt[1],prec()),round(pt[2],prec()))