77vp .CONFIG_MANAGER .load_config_file (str (Path (__file__ ).parent / "bundled_configs.toml" ))
88
99
10- def invert_axis (
11- document : vp .Document ,
12- invert_x : bool ,
13- invert_y : bool
14- ):
15- """ Inverts none, one or both axis of the document.
10+ def invert_axis (document : vp .Document , invert_x : bool , invert_y : bool ):
11+ """Inverts none, one or both axis of the document.
1612
1713 This applies a relative scale operation with factors of 1 or -1
1814 on the two axis to all layers. The inversion happens relative to
@@ -40,7 +36,7 @@ def invert_axis(
4036
4137
4238@click .command ()
43- @click .argument (' filename' , type = click .Path (exists = False ))
39+ @click .argument (" filename" , type = click .Path (exists = False ))
4440@click .option (
4541 "-p" ,
4642 "--profile" ,
@@ -89,9 +85,6 @@ def gwrite(document: vp.Document, filename: str, profile: str):
8985 footer = config .get ("footer" , None )
9086 unit = config .get ("unit" , "mm" )
9187
92- relative = config .get ("relative" , False )
93- negate_x = config .get ("negate_x" , False )
94- negate_y = config .get ("negate_y" , False )
9588 invert_x = config .get ("invert_x" , False )
9689 invert_y = config .get ("invert_y" , False )
9790
@@ -100,52 +93,77 @@ def gwrite(document: vp.Document, filename: str, profile: str):
10093 if invert_x or invert_y :
10194 document = invert_axis (document , invert_x , invert_y )
10295
103- with open (filename , 'w' ) as f :
96+ with open (filename , "w" ) as f :
10497 if header is not None :
105- f .write (header )
98+ f .write (header . format ( filename = filename ) )
10699 last_x = 0
107100 last_y = 0
108- for layer in document .layers .values ():
101+ xx = 0
102+ yy = 0
103+ for layer_index , layer in enumerate (document .layers .values ()):
109104 if prelayer is not None :
110- f .write (prelayer )
111- for p in layer :
105+ f .write (prelayer . format ( index = layer_index ) )
106+ for p_index , p in enumerate ( layer ) :
112107 m = p * scale
113108 first = True
114109 if preblock is not None :
115- f .write (preblock )
116- for v in m :
110+ f .write (preblock . format ( index = p_index ) )
111+ for v_index , v in enumerate ( m ) :
117112 x = v .real
118- if negate_x :
119- x = - x
120113 y = v .imag
121- if negate_y :
122- y = - y
123- if relative :
124- dx = x - last_x
125- dy = y - last_y
126- if first :
127- if move is not None :
128- f .write (move % (dx , dy ))
129- first = False
130- else :
131- if line is not None :
132- f .write (line % (dx , dy ))
114+ dx = x - last_x
115+ dy = y - last_y
116+ idx = int (round (x - xx ))
117+ idy = int (round (y - yy ))
118+ xx += idx
119+ yy += idy
120+ if first :
121+ if move is not None :
122+ f .write (
123+ move .format (
124+ x = x ,
125+ y = y ,
126+ dx = dx ,
127+ dy = dy ,
128+ _x = - x ,
129+ _y = - y ,
130+ _dx = dx ,
131+ _dy = dy ,
132+ ix = xx ,
133+ iy = yy ,
134+ idx = idx ,
135+ idy = idy ,
136+ index = v_index ,
137+ )
138+ )
139+ first = False
133140 else :
134- if first :
135- if move is not None :
136- f .write (move % (x , y ))
137- first = False
138- else :
139- if line is not None :
140- f .write (line % (x , y ))
141+ if line is not None :
142+ f .write (
143+ line .format (
144+ x = x ,
145+ y = y ,
146+ dx = dx ,
147+ dy = dy ,
148+ _x = - x ,
149+ _y = - y ,
150+ _dx = dx ,
151+ _dy = dy ,
152+ ix = xx ,
153+ iy = yy ,
154+ idx = idx ,
155+ idy = idy ,
156+ index = v_index ,
157+ )
158+ )
141159 last_x = x
142160 last_y = y
143161 if postblock is not None :
144- f .write (postblock )
162+ f .write (postblock . format ( index = p_index ) )
145163 if postlayer is not None :
146- f .write (postlayer )
164+ f .write (postlayer . format ( index = layer_index ) )
147165 if footer is not None :
148- f .write (footer )
166+ f .write (footer . format ( filename = filename ) )
149167
150168 return document
151169
0 commit comments