def test_4(self): app = pya.Application.instance() mw = app.main_window() mw.close_all() mw.load_layout(os.getenv("TESTSRC") + "/testdata/gds/t11.gds", 1) mw.load_layout(os.getenv("TESTSRC") + "/testdata/gds/t10.gds", 2) cv = mw.current_view() cv.clear_layers() pos = cv.end_layers() self.assertEqual(pos.current().is_valid(), False) cv.insert_layer(pos, pya.LayerProperties()) new_p = pya.LayerProperties() new_p.source = "1/0@1" pos.current().add_child(new_p) self.assertEqual(pos.current().visible_(True), True) self.assertEqual(pos.current().visible_(False), True) self.assertEqual(pos.first_child().current().visible_(True), True) self.assertEqual(pos.first_child().current().visible_(False), True) pos.current().visible = False self.assertEqual(pos.current().visible_(True), False) self.assertEqual(pos.current().visible_(False), False) self.assertEqual(pos.first_child().current().visible_(True), False) self.assertEqual(pos.first_child().current().visible_(False), True) mw.close_all()
def test_5(self): app = pya.Application.instance() mw = app.main_window() mw.close_all() mw.load_layout(os.getenv("TESTSRC") + "/testdata/gds/t11.gds", 1) cv = mw.current_view() cv.clear_layers() new_p = pya.LayerProperties() new_p.source = "1/0@1" cv.insert_layer(0, cv.end_layers(), new_p) new_p = pya.LayerProperties() new_p.source = "2/0@1" cv.insert_layer(0, cv.end_layers(), new_p) pos = cv.begin_layers() self.assertEqual(self.lnodes_str("", cv.begin_layers()), "1/0@1\n2/0@1\n") self.assertEqual(pos.at_end(), False) self.assertEqual(pos.current().source, "1/0@1") self.assertEqual(pos.current().is_valid(), True) pos.current().delete() self.assertEqual(pos.current().source, "2/0@1") self.assertEqual(pos.current().is_valid(), True) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "2/0@1\n") self.assertEqual(pos.at_end(), False) pos.current().delete() self.assertEqual(pos.current().is_valid(), False) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "") self.assertEqual(pos.at_end(), True) pos.current().delete() self.assertEqual(pos.current().is_valid(), False) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "") self.assertEqual(pos.at_end(), True) # With hierarchy cv.clear_layers() new_p = pya.LayerProperties() new_p.source = "1/0@1" cv.insert_layer(0, cv.end_layers(), new_p) new_p = pya.LayerProperties() new_p.source = "2/0@1" cv.insert_layer(0, cv.end_layers(), new_p) new_p = pya.LayerProperties() new_p.source = "3/0@1" cv.insert_layer(0, cv.end_layers(), new_p) pos = cv.begin_layers() pos.next_sibling(1) c1 = pos.current().add_child() c1.source = "21/0@1" c2 = pos.current().add_child() c2.source = "22/0@1" posn = cv.begin_layers() posn.next_sibling(2) c3 = posn.current().add_child() c3.source = "31/0@1" self.assertEqual(self.lnodes_str("", cv.begin_layers()), "1/0@1\n2/0@1\n 21/0@1\n 22/0@1\n3/0@1\n 31/0@1\n") pc = pos.first_child() self.assertEqual(pc.current().source, "21/0@1") self.assertEqual(pc.current().is_valid(), True) self.assertEqual(pc.at_end(), False) pc.current().delete() self.assertEqual(pc.current().source, "22/0@1") self.assertEqual(pc.current().is_valid(), True) self.assertEqual(pc.at_end(), False) pc.current().delete() self.assertEqual(pc.at_end(), True) self.assertEqual(pc.current().is_valid(), False) mw.close_all()
def test_1(self): app = pya.Application.instance() mw = app.main_window() mw.close_all() mw.load_layout(os.getenv("TESTSRC") + "/testdata/gds/t11.gds", 1) mw.load_layout(os.getenv("TESTSRC") + "/testdata/gds/t10.gds", 2) cv = mw.current_view() cv.clear_layers() self.assertEqual(self.lnodes_str("", cv.begin_layers()), "") pos = cv.end_layers() self.assertEqual(pos.parent().is_null(), True) p = pos.dup() p.up() self.assertEqual(p.is_null(), True) self.assertEqual(pos.is_null(), False) self.assertEqual(pos == cv.begin_layers(), True) self.assertEqual(pos != cv.begin_layers(), False) l1 = cv.insert_layer(pos, pya.LayerProperties()) self.assertEqual(pos == cv.begin_layers(), True) self.assertEqual(pos != cv.begin_layers(), False) self.assertEqual(pos == cv.end_layers(), False) self.assertEqual(pos != cv.end_layers(), True) self.assertEqual(pos < cv.end_layers(), True) self.assertEqual(cv.end_layers() < pos, False) self.assertEqual(pos < cv.begin_layers(), False) self.assertEqual(cv.begin_layers() < pos, False) self.assertEqual(pos.at_top(), True) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n") new_p = pya.LayerProperties() new_p.source = "1/0@1" l11 = cv.insert_layer(pos.last_child(), new_p) p12 = pos.last_child() self.assertEqual(p12.parent().is_null(), False) self.assertEqual(p12.parent() == pos, True) pp = pos.dup() pp.down_last_child() self.assertEqual(pp == p12, True) self.assertEqual(pp == pos, False) self.assertEqual(pp.parent() == pos, True) pp.up() self.assertEqual(pp == pos, True) self.assertEqual(p12.at_top(), False) p12.to_sibling(0) self.assertEqual(p12 == pos.first_child(), True) self.assertEqual(p12.child_index(), 0) p12.to_sibling(1) self.assertEqual(p12.child_index(), 1) self.assertEqual(p12 == pos.last_child(), True) self.assertEqual(p12.num_siblings(), 1) l12 = cv.insert_layer(p12, pya.LayerProperties()) l12_new = pya.LayerProperties() l12_new.source = "1/0@2" cv.set_layer_properties(p12, l12_new) self.assertEqual(p12.current().cellview(), 1) self.assertEqual(p12.current().has_upper_hier_level(True), False) self.assertEqual(p12.current().has_lower_hier_level(True), False) l12_new.source = "@* #1..2" cv.set_layer_properties(p12, l12_new) self.assertEqual(p12.current().cellview(), 0) self.assertEqual(p12.current().has_upper_hier_level(True), True) self.assertEqual(p12.current().has_upper_hier_level(), True) self.assertEqual(p12.current().upper_hier_level_(True), 2) self.assertEqual(p12.current().upper_hier_level, 2) self.assertEqual(p12.current().has_lower_hier_level(True), True) self.assertEqual(p12.current().has_lower_hier_level(), True) self.assertEqual(p12.current().lower_hier_level_(True), 1) self.assertEqual(p12.current().lower_hier_level, 1) l12_new.source = "@* (0,0 *0.5) (0,5 r45 *2.5)" cv.set_layer_properties(p12, l12_new) trans = p12.current().trans_(True) self.assertEqual(str(trans), str(p12.current().trans)) self.assertEqual(len(trans), 2) self.assertEqual(str(trans [0]), "r0 *0.5 0,0") self.assertEqual(str(trans [1]), "r45 *2.5 0,5") l12_new.source = "1/0@2" cv.set_layer_properties(p12, l12_new) self.assertEqual(p12.num_siblings(), 2) pos = cv.end_layers() new_p = pya.LayerProperties() new_p.source = "@1" l2 = cv.insert_layer(pos, new_p) new_p = pya.LayerProperties() new_p.source = "7/0@*" l21 = cv.insert_layer(pos.first_child(), new_p) p22 = pos.last_child() new_p = pya.LayerProperties() l22 = cv.insert_layer(pos.last_child(), new_p) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n*/*@1\n 7/0@1\n */*@1\n") new_p = l2.dup() new_p.source = "@2" cv.set_layer_properties(pos, new_p) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n*/*@2\n 7/0@2\n */*@2\n") pos.first_child().current().source = "7/0@1" self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n*/*@2\n 7/0@1\n */*@2\n") pos.current().source = "@*" self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n*/*@*\n 7/0@1\n */*@*\n") pos.current().source = "@2" self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n*/*@2\n 7/0@1\n */*@2\n") pos.first_child().current().source = "7/1@*" self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n*/*@2\n 7/1@2\n */*@2\n") pos.first_child().current().source = "7/0@*" self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n*/*@2\n 7/0@2\n */*@2\n") l22_new = pya.LayerProperties() l22_new.source = "7/1@*" cv.replace_layer_node(p22, l22_new) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n*/*@2\n 7/0@2\n 7/1@2\n") cv.delete_layer(p22) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n*/*@2\n 7/0@2\n") new_p = l2.dup() new_p.source = "%5@2" cv.set_layer_properties(pos, new_p) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n%5@2\n %5@2\n") mw.close_all()
def test_3(self): app = pya.Application.instance() mw = app.main_window() mw.close_all() mw.load_layout(os.getenv("TESTSRC") + "/testdata/gds/t11.gds", pya.LoadLayoutOptions(), "", 1) mw.load_layout(os.getenv("TESTSRC") + "/testdata/gds/t10.gds", pya.LoadLayoutOptions(), "", 2) cv = mw.current_view() self.assertEqual(self.lnodes_str("", cv.begin_layers()), "1/0@1\n2/0@1\n1/0@2\n2/0@2\n3/0@2\n3/1@2\n4/0@2\n5/0@2\n6/0@2\n6/1@2\n7/0@2\n8/0@2\n8/1@2\n") cv.clear_layers() pos = cv.end_layers() self.assertEqual(pos.current().is_valid(), False) cv.insert_layer(pos, pya.LayerProperties()) self.assertEqual(pos.current().is_valid(), True) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n") self.assertEqual(self.lnodes_str2(cv), "*/*@*") self.assertEqual(cv.begin_layers().current().name, "") self.assertEqual(cv.begin_layers().current().visible, True) self.assertEqual(cv.begin_layers().current().dither_pattern, -1) self.assertEqual(cv.begin_layers().current().line_style, -1) self.assertEqual(cv.begin_layers().current().valid, True) self.assertEqual(cv.begin_layers().current().transparent, False) # test LayerPropertiesNodeRef pos.current().name = "NAME" pos.current().visible = False pos.current().fill_color = 0xff012345 pos.current().frame_color = 0xff123456 pos.current().fill_brightness = 42 pos.current().frame_brightness = 17 pos.current().dither_pattern = 4 pos.current().line_style = 3 pos.current().valid = False pos.current().transparent = True pos.current().marked = False pos.current().xfill = False pos.current().width = 2 pos.current().animation = 2 self.assertEqual(cv.begin_layers().current().name, "NAME") self.assertEqual(cv.begin_layers().current().visible, False) self.assertEqual(cv.begin_layers().current().fill_color, 0xff012345) self.assertEqual(cv.begin_layers().current().frame_color, 0xff123456) self.assertEqual(cv.begin_layers().current().fill_brightness, 42) self.assertEqual(cv.begin_layers().current().frame_brightness, 17) self.assertEqual(cv.begin_layers().current().dither_pattern, 4) self.assertEqual(cv.begin_layers().current().line_style, 3) self.assertEqual(cv.begin_layers().current().valid, False) self.assertEqual(cv.begin_layers().current().transparent, True) self.assertEqual(cv.begin_layers().current().marked, False) self.assertEqual(cv.begin_layers().current().xfill, False) self.assertEqual(cv.begin_layers().current().width, 2) self.assertEqual(cv.begin_layers().current().animation, 2) pos.current().valid = True new_p = pya.LayerProperties() new_p.source = "1/0@1" self.assertEqual(new_p.flat().source, "1/0@1") self.assertEqual(new_p == new_p.flat(), True) self.assertEqual(new_p != new_p.flat(), False) new_p_ref = pos.current().add_child(new_p) self.assertEqual(new_p_ref.layer_index(), cv.cellview(0).layout().layer(1, 0)) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n") self.assertEqual(self.lnodes_str2(cv), "*/*@*\n1/0@1") p = pos.current().add_child() p.source = "1/0@2" self.assertEqual(p.is_valid(), True) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n 1/0@2\n") self.assertEqual(self.lnodes_str2(cv), "*/*@*\n1/0@1\n1/0@2") self.assertEqual(p.layer_index(), cv.cellview(1).layout().layer(1, 0)) self.assertEqual(str(p.bbox()), "(-1.4,1.8;25.16,3.8)") self.assertEqual(p.view() == cv, True) self.assertEqual(p.list_index(), 0) l12_new = pya.LayerProperties() l12_new.source = "@* #1..2" self.assertEqual(l12_new.flat().source, "*/*@* #1..2") self.assertEqual(pos.first_child().current().source, "1/0@1") self.assertEqual(pos.first_child().current().is_valid(), True) self.assertEqual(pos.last_child().current().is_valid(), False) pos.first_child().next().current().assign(l12_new) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n */*@* #1..2\n") self.assertEqual(self.lnodes_str2(cv), "*/*@*\n1/0@1\n*/*@* #1..2") pos.first_child().next_sibling(1).current().source = "@* #3..4" self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 1/0@1\n */*@* #3..4\n") self.assertEqual(self.lnodes_str2(cv), "*/*@*\n1/0@1\n*/*@* #3..4") pos.first_child().to_sibling(1).next_sibling(-1).current().source = "7/0" self.assertEqual(self.lnodes_str("", cv.begin_layers()), "*/*@*\n 7/0@1\n */*@* #3..4\n") self.assertEqual(self.lnodes_str2(cv), "*/*@*\n7/0@1\n*/*@* #3..4") self.assertEqual(self.lnodes_str3(cv, 0), "*/*@*\n7/0@1\n*/*@* #3..4") self.assertEqual(self.lnodes_str3(cv, 1), "") nn = pya.LayerPropertiesNode() nn.source = "TOP" nn1 = pya.LayerPropertiesNode() nn1.source = "nn1" nn2 = pya.LayerProperties() nn2.source = "nn1" nn1.add_child(nn2) nn.add_child(nn1) pos.current().assign(nn) self.assertEqual(pos.current().id(), nn.id()) self.assertEqual(self.lnodes_str("", cv.begin_layers()), "TOP@1\n nn1@1\n nn1@1\n") self.assertEqual(self.lnodes_str2(cv), "TOP@1\nnn1@1\nnn1@1") mw.close_all()
def test_1a(self): app = pya.Application.instance() mw = app.main_window() mw.close_all() mw.load_layout(os.getenv("TESTSRC") + "/testdata/gds/t11.gds", 1) mw.load_layout(os.getenv("TESTSRC") + "/testdata/gds/t10.gds", 2) cv = mw.current_view() cv.clear_layers() cv.insert_layer_list(1) cv.rename_layer_list(1, "x") self.assertEqual(cv.current_layer_list, 1) cv.set_current_layer_list(0) self.assertEqual(cv.current_layer_list, 0) cv.set_current_layer_list(1) self.assertEqual(cv.current_layer_list, 1) self.assertEqual(self.lnodes_str("", cv.begin_layers(0)), "") self.assertEqual(self.lnodes_str("", cv.begin_layers(1)), "") pos = cv.end_layers(0) self.assertEqual(pos.parent().is_null(), True) p = pos.dup() p.up() self.assertEqual(p.is_null(), True) self.assertEqual(pos.is_null(), False) self.assertEqual(pos == cv.begin_layers(0), True) self.assertEqual(pos != cv.begin_layers(0), False) l1 = cv.insert_layer(0, pos, pya.LayerProperties()) self.assertEqual(pos == cv.begin_layers(0), True) self.assertEqual(pos != cv.begin_layers(0), False) self.assertEqual(pos == cv.end_layers(0), False) self.assertEqual(pos != cv.end_layers(0), True) self.assertEqual(pos < cv.end_layers(0), True) self.assertEqual(cv.end_layers(0) < pos, False) self.assertEqual(pos < cv.begin_layers(0), False) self.assertEqual(cv.begin_layers(0) < pos, False) self.assertEqual(pos.at_top(), True) self.assertEqual(self.lnodes_str("", cv.begin_layers(0)), "*/*@*\n") self.assertEqual(self.lnodes_str("", cv.begin_layers(1)), "") self.assertEqual(self.lnodes_str("", cv.begin_layers()), "") new_p = pya.LayerProperties() new_p.source = "1/0@1" l11 = cv.insert_layer(0, pos.last_child(), new_p) p12 = pos.last_child() self.assertEqual(p12.parent().is_null(), False) self.assertEqual(p12.parent() == pos, True) pp = pos.dup() pp.down_last_child() self.assertEqual(pp == p12, True) self.assertEqual(pp == pos, False) self.assertEqual(pp.parent() == pos, True) pp.up() self.assertEqual(pp == pos, True) self.assertEqual(p12.at_top(), False) p12.to_sibling(0) self.assertEqual(p12 == pos.first_child(), True) self.assertEqual(p12.child_index(), 0) p12.to_sibling(1) self.assertEqual(p12.child_index(), 1) self.assertEqual(p12 == pos.last_child(), True) self.assertEqual(p12.num_siblings(), 1) l12 = cv.insert_layer(0, p12, pya.LayerProperties()) l12_new = pya.LayerProperties() l12_new.source = "1/0@2" cv.set_layer_properties(0, p12, l12_new) self.assertEqual(p12.current().cellview(), 1) self.assertEqual(p12.current().has_upper_hier_level(True), False) self.assertEqual(p12.current().has_upper_hier_level(), False) self.assertEqual(p12.current().has_lower_hier_level(True), False) self.assertEqual(p12.current().has_lower_hier_level(), False) l12_new.source = "@* #1..2" cv.set_layer_properties(0, p12, l12_new) self.assertEqual(p12.current().cellview(), 0) self.assertEqual(p12.current().has_upper_hier_level(True), True) self.assertEqual(p12.current().has_upper_hier_level(), True) self.assertEqual(p12.current().upper_hier_level_(True), 2) self.assertEqual(p12.current().upper_hier_level, 2) self.assertEqual(p12.current().has_lower_hier_level(True), True) self.assertEqual(p12.current().has_lower_hier_level(), True) self.assertEqual(p12.current().lower_hier_level_(True), 1) self.assertEqual(p12.current().lower_hier_level, 1) l12_new.source = "@* (0,0 *0.5) (0,5 r45 *2.5)" cv.set_layer_properties(0, p12, l12_new) trans = p12.current().trans_(True) self.assertEqual(len(trans), 2) self.assertEqual(str(trans [0]), "r0 *0.5 0,0") self.assertEqual(str(trans [1]), "r45 *2.5 0,5") l12_new.source = "1/0@2" cv.set_layer_properties(0, p12, l12_new) self.assertEqual(p12.num_siblings(), 2) pos = cv.end_layers(0) new_p = pya.LayerProperties() new_p.source = "@1" l2 = cv.insert_layer(0, pos, new_p) new_p = pya.LayerProperties() new_p.source = "7/0@*" l21 = cv.insert_layer(0, pos.first_child(), new_p) p22 = pos.last_child() new_p = pya.LayerProperties() l22 = cv.insert_layer(0, pos.last_child(), new_p) self.assertEqual(self.lnodes_str("", cv.begin_layers(0)), "*/*@*\n 1/0@1\n 1/0@2\n*/*@1\n 7/0@1\n */*@1\n") self.assertEqual(self.lnodes_str("", cv.begin_layers(1)), "") self.assertEqual(self.lnodes_str("", cv.begin_layers()), "") new_p = l2.dup() new_p.source = "@2" cv.set_layer_properties(0, pos, new_p) self.assertEqual(self.lnodes_str("", cv.begin_layers(0)), "*/*@*\n 1/0@1\n 1/0@2\n*/*@2\n 7/0@2\n */*@2\n") l22_new = pya.LayerProperties() l22_new.source = "7/1@*" cv.replace_layer_node(0, p22, l22_new) self.assertEqual(self.lnodes_str("", cv.begin_layers(0)), "*/*@*\n 1/0@1\n 1/0@2\n*/*@2\n 7/0@2\n 7/1@2\n") cv.delete_layer(0, p22) self.assertEqual(self.lnodes_str("", cv.begin_layers(0)), "*/*@*\n 1/0@1\n 1/0@2\n*/*@2\n 7/0@2\n") new_p = l2.dup() new_p.source = "%5@2" cv.set_layer_properties(0, pos, new_p) self.assertEqual(self.lnodes_str("", cv.begin_layers(0)), "*/*@*\n 1/0@1\n 1/0@2\n%5@2\n %5@2\n") # build a tree by building a separate tree new_p = pya.LayerPropertiesNode() self.assertEqual(new_p.has_children(), False) n1 = new_p.add_child(pya.LayerProperties()) self.assertEqual(n1.has_children(), False) n1.source = "101/0" n2 = pya.LayerPropertiesNode() self.assertEqual(n2.has_children(), False) n21 = n2.add_child(pya.LayerProperties()) n21.source = "102/0" self.assertEqual(n2.has_children(), True) n22 = n2.add_child(pya.LayerProperties()) self.assertEqual(n2.has_children(), True) n22.source = "103/0" new_p.add_child(n2) self.assertEqual(new_p.has_children(), True) p = pos.last_child() ll = cv.insert_layer(0, p, new_p) self.assertEqual(p.current().has_children(), True) self.assertEqual(p.first_child().current().has_children(), False) self.assertEqual(p.first_child().current().source_(False), "101/0@1") self.assertEqual(p.first_child().current().source, "%5@1") # (test clear_children): new_p.clear_children() self.assertEqual(new_p.has_children(), False) self.assertEqual(ll.has_children(), False) cv.transaction("Delete") li = cv.begin_layers(0) a = [] while not li.at_end(): a.append(li.dup()) li.next() self.assertEqual(len(a), 10) cv.delete_layers(0, a) self.assertEqual(cv.begin_layers(0).at_end(), True) cv.commit() mw.cm_undo() self.assertEqual(cv.begin_layers(0).at_end(), False) cv.transaction("Delete") i = 0 while not cv.begin_layers(0).at_end(): cv.delete_layer(0, cv.begin_layers(0)) i += 1 self.assertEqual(i, 2) self.assertEqual(cv.begin_layers(0).at_end(), True) cv.commit() mw.cm_undo() self.assertEqual(cv.begin_layers(0).at_end(), False) mw.close_all()