summaryrefslogtreecommitdiff
path: root/gerberex/rs274x.py
diff options
context:
space:
mode:
authorHiroshi Murayama <opiopan@gmail.com>2019-09-12 23:44:50 +0900
committerHiroshi Murayama <opiopan@gmail.com>2019-09-12 23:44:50 +0900
commit00351ebe277aeb90e7463d1b0bd55402249c4687 (patch)
treea4c7f3e0e015a88af6770cfe9daa12cd21952b4d /gerberex/rs274x.py
parent4c4ba0762b30fdd4633a6d2868c508184d681b7d (diff)
downloadgerbonara-00351ebe277aeb90e7463d1b0bd55402249c4687.tar.gz
gerbonara-00351ebe277aeb90e7463d1b0bd55402249c4687.tar.bz2
gerbonara-00351ebe277aeb90e7463d1b0bd55402249c4687.zip
add IP command handling function
Diffstat (limited to 'gerberex/rs274x.py')
-rw-r--r--gerberex/rs274x.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/gerberex/rs274x.py b/gerberex/rs274x.py
index 42ae17d..3a3a712 100644
--- a/gerberex/rs274x.py
+++ b/gerberex/rs274x.py
@@ -53,6 +53,8 @@ class GerberFile(gerber.rs274x.GerberFile):
self.main_statements.extend(stmts)
if self.context.angle != 0:
self.rotate(self.context.angle)
+ if self.context.is_negative:
+ self.nagate_polarity()
self.context.notation = 'absolute'
self.context.zeros = 'trailing'
@@ -128,6 +130,11 @@ class GerberFile(gerber.rs274x.GerberFile):
statement.x = last_rx
statement.y = last_ry
+ def nagate_polarity(self):
+ for statement in self.main_statements:
+ if isinstance(statement, LPParamStmt):
+ statement.lp = 'dark' if statement.lp == 'clear' else 'clear'
+
def _generalize_aperture(self):
RECTANGLE = 0
LANDSCAPE_OBROUND = 1
@@ -208,6 +215,9 @@ class GerberContext(FileSettings):
1, 0,
1, 1)
+ self.is_negative = False
+ self.is_first_coordinate = True
+ self.no_polarity = True
self.in_single_quadrant_mode = False
self.op = None
self.interpolation = self.IP_LINEAR
@@ -216,6 +226,7 @@ class GerberContext(FileSettings):
self.y = 0.
def normalize_statement(self, stmt):
+ additional_stmts = None
if isinstance(stmt, INParamStmt):
self.name = stmt.name
elif isinstance(stmt, MIParamStmt):
@@ -241,14 +252,24 @@ class GerberContext(FileSettings):
elif isinstance(stmt, QuadrantModeStmt):
self.in_single_quadrant_mode = stmt.mode == 'single-quadrant'
stmt.mode = 'multi-quadrant'
+ elif isinstance(stmt, IPParamStmt):
+ self.is_negative = stmt.ip == 'negative'
+ elif isinstance(stmt, LPParamStmt):
+ self.no_polarity = False
elif isinstance(stmt, CoordStmt):
self._normalize_coordinate(stmt)
+ if self.is_first_coordinate:
+ self.is_first_coordinate = False
+ if self.no_polarity:
+ additional_stmts = [LPParamStmt('LP', 'dark'), stmt]
if type(stmt).__name__ in self.ignored_stmt:
return (self.TYPE_NONE, None)
+ elif additional_stmts is not None:
+ return (self.TYPE_MAIN, additional_stmts)
else:
return (self.TYPE_MAIN, [stmt])
-
+
def _update_matrix(self):
if self.axis == 'xy':
mx = -1 if self.mirror[0] else 1