From: ozmikepittman Date: Mon, 19 May 2008 16:28:00 +0000 (+0000) Subject: Applying several of Inductiveload's enhancements and fixes to his extensions. See... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9fefe969c78790b255996a6fa8ebe02c403761ba;p=inkscape.git Applying several of Inductiveload's enhancements and fixes to his extensions. See LP #230478. --- diff --git a/share/extensions/grid_cartesian.py b/share/extensions/grid_cartesian.py index e5450abac..b996d6e84 100644 --- a/share/extensions/grid_cartesian.py +++ b/share/extensions/grid_cartesian.py @@ -20,26 +20,23 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -''' +''' import inkex import simplestyle, sys from math import * -def log_N(base, x): #computes the base-n log of x - return log(x)/log(base) - def draw_SVG_line(x1, y1, x2, y2, width, name, parent): style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill': 'none' } line_attribs = {'style':simplestyle.formatStyle(style), - 'inkscape:label':name, + inkex.addNS('label','inkscape'):name, 'd':'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)} inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs ) def draw_SVG_rect(x,y,w,h, width, fill, name, parent): style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill':fill} rect_attribs = {'style':simplestyle.formatStyle(style), - 'inkscape:label':name, + inkex.addNS('label','inkscape'):name, 'x':str(x), 'y':str(y), 'width':str(w), 'height':str(h)} inkex.etree.SubElement(parent, inkex.addNS('rect','svg'), rect_attribs ) @@ -185,8 +182,8 @@ class Grid_Polar(inkex.Effect): if self.options.x_log: #log x subdivs for j in range (1, sd): if j>1: #the first loop is only for subsubdivs - draw_SVG_line(self.options.dx*(i+log_N(sd, j)), 0, - self.options.dx*(i+log_N(sd, j)), ymax, + draw_SVG_line(self.options.dx*(i+log(j, sd)), 0, + self.options.dx*(i+log(j, sd)), ymax, self.options.x_subdivs_th, 'MinorXDiv'+str(i)+':'+str(j), minglx) @@ -196,8 +193,8 @@ class Grid_Polar(inkex.Effect): ssd2 = ssd+1 #make even else: ssd2 = ssd #no change - draw_SVG_line(self.options.dx*(i+log_N(sd, j+k/float(ssd2) )), 0, - self.options.dx*(i+log_N(sd, j+k/float(ssd2) )), ymax, + draw_SVG_line(self.options.dx*(i+log(j+k/float(ssd2),sd )), 0, + self.options.dx*(i+log(j+k/float(ssd2),sd )), ymax, self.options.x_subsubdivs_th,'SubminorXDiv'+str(i)+':'+str(j)+':'+str(k), mminglx) else: #linear x subdivs @@ -228,8 +225,8 @@ class Grid_Polar(inkex.Effect): if self.options.y_log: #log y subdivs for j in range (1, sd): if j>1: #the first loop is only for subsubdivs - draw_SVG_line(0, self.options.dy*(i+1-log_N(sd, j)), - xmax, self.options.dy*(i+1-log_N(sd, j)), + draw_SVG_line(0, self.options.dy*(i+1-log(j,sd)), + xmax, self.options.dy*(i+1-log(j,sd)), self.options.y_subdivs_th, 'MinorXDiv'+str(i)+':'+str(j), mingly) @@ -239,8 +236,8 @@ class Grid_Polar(inkex.Effect): ssd2 = ssd+1 else: ssd2 = ssd #no change - draw_SVG_line(0, self.options.dx*(i+1-log_N(sd, j+k/float(ssd2) )), - xmax, self.options.dx*(i+1-log_N(sd, j+k/float(ssd2) )), + draw_SVG_line(0, self.options.dx*(i+1-log(j+k/float(ssd2),sd )), + xmax, self.options.dx*(i+1-log(j+k/float(ssd2),sd )), self.options.y_subsubdivs_th, 'SubminorXDiv'+str(i)+':'+str(j)+':'+str(k), mmingly) else: #linear y subdivs @@ -262,3 +259,4 @@ class Grid_Polar(inkex.Effect): e = Grid_Polar() e.affect() + diff --git a/share/extensions/grid_polar.py b/share/extensions/grid_polar.py index 93871f1b8..9da5017aa 100644 --- a/share/extensions/grid_polar.py +++ b/share/extensions/grid_polar.py @@ -18,28 +18,24 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -''' +''' import inkex import simplestyle, sys from math import * -def log_N(base, x): #computes the base-n log of x - return log(x)/log(base) - -def draw_SVG_ellipse(rx, ry, cx, cy, width, fill, name, parent): +def draw_SVG_circle(r, cx, cy, width, fill, name, parent): style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill': fill } circ_attribs = {'style':simplestyle.formatStyle(style), - 'inkscape:label':name, - 'sodipodi:cx':str(cx), 'sodipodi:cy':str(cy), - 'sodipodi:rx':str(rx), 'sodipodi:ry':str(ry), - 'sodipodi:type':'arc'} - inkex.etree.SubElement(parent, inkex.addNS('path','svg'), circ_attribs ) + 'cx':str(cx), 'cy':str(cy), + 'r':str(r), + inkex.addNS('label','inkscape'):name} + circle = inkex.etree.SubElement(parent, inkex.addNS('circle','svg'), circ_attribs ) def draw_SVG_line(x1, y1, x2, y2, width, name, parent): style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill': 'none' } line_attribs = {'style':simplestyle.formatStyle(style), - 'inkscape:label':name, + inkex.addNS('label','inkscape'):name, 'd':'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)} inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs ) @@ -49,7 +45,7 @@ def draw_SVG_label_centred(x, y, string, font_size, name, parent): 'fill-opacity': '1.0', 'stroke': 'none', 'font-weight': 'normal', 'font-style': 'normal', 'fill': '#000000'} label_attribs = {'style':simplestyle.formatStyle(style), - 'inkscape:label':name, + inkex.addNS('label','inkscape'):name, 'x':str(x), 'y':str(y)} label = inkex.etree.SubElement(parent, inkex.addNS('text','svg'), label_attribs) label.text = string @@ -138,21 +134,19 @@ class Grid_Polar(inkex.Effect): #Create SVG circles for i in range(1, self.options.r_divs+1): - draw_SVG_ellipse(i*dr, i*dr, 0, 0, #major div circles + draw_SVG_circle(i*dr, 0, 0, #major div circles self.options.r_divs_th, 'none', 'MajorDivCircle'+str(i)+':R'+str(i*dr), grid) if self.options.r_log: #logarithmic subdivisions for j in range (2, self.options.r_subdivs): - draw_SVG_ellipse(i*dr-(1-log_N(self.options.r_subdivs, j))*dr, #minor div circles - i*dr-(1-log_N(self.options.r_subdivs, j))*dr, 0, 0, - self.options.r_subdivs_th, 'none', + draw_SVG_circle(i*dr-(1-log(j, self.options.r_subdivs))*dr, #minor div circles + 0, 0, self.options.r_subdivs_th, 'none', 'MinorDivCircle'+str(i)+':Log'+str(j), grid) else: #linear subdivs for j in range (1, self.options.r_subdivs): - draw_SVG_ellipse(i*dr-j*dr/self.options.r_subdivs, #minor div circles - i*dr-j*dr/self.options.r_subdivs, 0, 0, - self.options.r_subdivs_th, 'none', + draw_SVG_circle(i*dr-j*dr/self.options.r_subdivs, #minor div circles + 0, 0, self.options.r_subdivs_th, 'none', 'MinorDivCircle'+str(i)+':R'+str(i*dr), grid) if self.options.a_divs == self.options.a_divs_cent: #the lines can go from the centre to the edge @@ -182,7 +176,7 @@ class Grid_Polar(inkex.Effect): self.options.a_subdivs_th, 'RadialMinorGridline'+str(i), grid) if self.options.c_dot_dia <> 0: #if a non-zero diameter, draw the centre dot - draw_SVG_ellipse(self.options.c_dot_dia /2.0, self.options.c_dot_dia/2.0, + draw_SVG_circle(self.options.c_dot_dia /2.0, 0, 0, 0, '#000000', 'CentreDot', grid) if self.options.a_labels == 'deg': @@ -199,3 +193,4 @@ class Grid_Polar(inkex.Effect): e = Grid_Polar() e.affect() + diff --git a/share/extensions/polyhedron_3d.inx b/share/extensions/polyhedron_3d.inx index e09311c06..6a6d4010d 100644 --- a/share/extensions/polyhedron_3d.inx +++ b/share/extensions/polyhedron_3d.inx @@ -5,7 +5,7 @@ polyhedron_3d.py inkex.py - + <_option value="cube">Cube <_option value="t_cube">Truncated Cube @@ -26,6 +26,9 @@ <_option value="from_file">Load From File great_rhombicuboct.obj + + <_option value="face">Face-Specified + <_option value="edge">Edge-Specified 0 @@ -93,4 +96,4 @@ - \ No newline at end of file + diff --git a/share/extensions/polyhedron_3d.py b/share/extensions/polyhedron_3d.py index 2b5698e74..d6bf2c5da 100644 --- a/share/extensions/polyhedron_3d.py +++ b/share/extensions/polyhedron_3d.py @@ -2,7 +2,7 @@ ''' Copyright (C) 2007 John Beard john.j.beard@gmail.com -##This extension draws 3d objects from an .obj file stored in a local folder +##This extension draws 3d objects from a Wavefront .obj 3D file stored in a local folder ##Many settings for appearance, lighting, rotation, etc are available. # ^y @@ -17,11 +17,6 @@ Copyright (C) 2007 John Beard john.j.beard@gmail.com # IMAGE PLANE SCENE| # | -#The .obj file must contain "#Name:" followed by a name, -#and "#Type:" follwed by "edge_specified" or "face-specified" -#if edge_specified is given, then faces cannot be drawn, -#if face_specified is given then faces and edges can be drawn - #Vertices are given as "v" followed by three numbers (x,y,z). #All files need a vertex list #v x.xxx y.yyy z.zzz @@ -63,29 +58,30 @@ except: inkex.debug("Failed to import the numpy module. This module is required by this extension. Please install them and try again. On a Debian-like system this can be done with the command, sudo apt-get install python-numpy.") sys.exit() -def mydir(): +def objfile(name): import os.path if __name__ == '__main__': filename = sys.argv[0] else: filename = __file__ - return os.path.abspath(os.path.dirname(filename)) + path = os.path.abspath(os.path.dirname(filename)) + path = os.path.join(path, 'Poly3DObjects', name) + return path def get_obj_data(obj, name): - infile = open(mydir() +'\\Poly3DObjects\\'+name) + infile = open(objfile(name)) #regular expressions getname = '(.[nN]ame:\\s*)(.*)' - gettype = '(.[tT]ype:\\s*)([Ff]ace|[Ee]dge)(.specified)' - getvertex = '(v\\s+)([\-\\d*\.]*)\\s+([\-\\d*\.]*)\\s+([\-\\d*\.]*)' + floating = '([\-\+\\d*\.e]*)' + getvertex = '(v\\s+)'+floating+'\\s+'+floating+'\\s+'+floating getedgeline = '(l\\s+)(.*)' getfaceline = '(f\\s+)(.*)' - getnextint = '\\s*(\\d+)(.*)' + getnextint = '(\\d+)([/\\d]*)(.*)'#we need to deal with 133\343\123 or 123\\456 as one item obj.vtx = [] obj.edg = [] obj.fce = [] - obj.type='' obj.name='' for line in infile: @@ -93,10 +89,6 @@ def get_obj_data(obj, name): m = re.search(getname, line) if m: obj.name = m.group(2) - m = re.search(gettype, line) - if m: - typestr = m.group(2).lower() - obj.type=typestr elif line[0:1] == 'v': #we have a vertex (maybe) m = re.search(getvertex, line) if m: #we have a valid vertex @@ -109,7 +101,7 @@ def get_obj_data(obj, name): m2 = re.search(getnextint, line) if m2: vtxlist.append( int(m2.group(1)) ) - line = m2.group(2)#remainder + line = m2.group(3)#remainder else: line = None if len(vtxlist) > 1:#we need at least 2 vertices to make an edge @@ -123,16 +115,19 @@ def get_obj_data(obj, name): m2 = re.search(getnextint, line) if m2: vtxlist.append( int(m2.group(1)) ) - line = m2.group(2)#remainder + line = m2.group(3)#remainder else: line = None if len(vtxlist) > 2:#we need at least 3 vertices to make an edge obj.fce.append(vtxlist) + + if obj.name == '':#no name was found, use filename, without extension + obj.name = name[0:-4] def draw_SVG_dot((cx, cy), st, name, parent): style = { 'stroke': '#000000', 'stroke-width':str(st.th), 'fill': st.fill, 'stroke-opacity':st.s_opac, 'fill-opacity':st.f_opac} circ_attribs = {'style':simplestyle.formatStyle(style), - 'inkscape:label':name, + inkex.addNS('label','inkscape'):name, 'r':str(st.r), 'cx':str(cx), 'cy':str(-cy)} inkex.etree.SubElement(parent, inkex.addNS('circle','svg'), circ_attribs ) @@ -141,7 +136,7 @@ def draw_SVG_line((x1, y1),(x2, y2), st, name, parent): #sys.stderr.write(str(p1)) style = { 'stroke': '#000000', 'stroke-width':str(st.th)} line_attribs = {'style':simplestyle.formatStyle(style), - 'inkscape:label':name, + inkex.addNS('label','inkscape'):name, 'd':'M '+str(x1)+','+str(-y1)+' L '+str(x2)+','+str(-y2)} inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs ) @@ -157,7 +152,7 @@ def draw_SVG_poly(pts, face, st, name, parent): d = d + 'z' #close the polygon line_attribs = {'style':simplestyle.formatStyle(style), - 'inkscape:label':name,'d': d} + inkex.addNS('label','inkscape'):name,'d': d} inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs ) def get_normal( pts, face): #returns the normal vector for the plane passing though the first three elements of face of pts @@ -235,13 +230,14 @@ class Obj(object): #a 3d object defined by the vertices and the faces (eg a poly def __init__(self): None -class Draw_From_Triangle(inkex.Effect): +class Poly_3D(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) self.OptionParser.add_option("--tab", action="store", type="string", dest="tab", default="object") +#MODEL FILE SETTINGS self.OptionParser.add_option("--obj", action="store", type="string", dest="obj", default='cube') @@ -251,6 +247,9 @@ class Draw_From_Triangle(inkex.Effect): self.OptionParser.add_option("--cw_wound", action="store", type="inkbool", dest="cw_wound", default='true') + self.OptionParser.add_option("--type", + action="store", type="string", + dest="type", default='face') #VEIW SETTINGS self.OptionParser.add_option("--r1_ax", action="store", type="string", @@ -350,7 +349,6 @@ class Draw_From_Triangle(inkex.Effect): st.linejoin = 'round' file = '' - obj = Obj() #create the object if so.obj == 'cube': file = 'cube.obj' elif so.obj == 't_cube': @@ -385,8 +383,24 @@ class Draw_From_Triangle(inkex.Effect): file = 'trunc_dodec.obj' elif so.obj == 'from_file': file = so.spec_file + + obj = Obj() #create the object get_obj_data(obj, file) + obj.type='' + if so.type == 'face': + if len(obj.fce) > 0: + obj.type = 'face' + else: + sys.stderr.write('No face data found in specified file\n') + obj.type = 'error' + else: + if len(obj.edg) > 0: + obj.type = 'edge' + else: + sys.stderr.write('No edge data found in specified file\n') + obj.type = 'error' + trans_mat = mat(identity(3, float)) #init. trans matrix as identity matrix #perform rotations @@ -483,10 +497,11 @@ class Draw_From_Triangle(inkex.Effect): face_no = z_list[i][3]#the number of the face to draw draw_SVG_poly(vp_pts, obj.fce[ face_no ], st, 'Face:'+str(face_no), proj) else: - sys.stderr.write('The selected file does not contain face data.\nPlease select point or edge plotting options.') + sys.stderr.write('Face Data Not Found. Ensure file contains face data, and check the file is imported as "Face-Specifed" under the "Model File" tab.\n') else: - sys.stderr.write('Internal Error. No view type selected') + sys.stderr.write('Internal Error. No view type selected\n') -e = Draw_From_Triangle() +e = Poly_3D() e.affect() + diff --git a/share/extensions/triangle.py b/share/extensions/triangle.py index 22c8633f0..a50904b3f 100644 --- a/share/extensions/triangle.py +++ b/share/extensions/triangle.py @@ -30,7 +30,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -''' +''' import inkex import simplestyle, sys @@ -39,7 +39,7 @@ from math import * def draw_SVG_tri( (x1, y1), (x2, y2), (x3, y3), (ox,oy), width, name, parent): style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill': 'none' } tri_attribs = {'style':simplestyle.formatStyle(style), - 'inkscape:label':name, + inkex.addNS('label','inkscape'):name, 'd':'M '+str(x1+ox)+','+str(y1+oy)+ ' L '+str(x2+ox)+','+str(y2+oy)+ ' L '+str(x3+ox)+','+str(y3+oy)+ @@ -192,3 +192,4 @@ class Grid_Polar(inkex.Effect): e = Grid_Polar() e.affect() +