Tests for complex data for meta info, doc updates

This commit is contained in:
Matthias Koefferlein 2023-04-22 00:16:12 +02:00
parent d9e0d107b1
commit 70b6306635
2 changed files with 56 additions and 7 deletions

View File

@ -86,26 +86,26 @@ Class<MetaInfo> decl_LayoutMetaInfo ("db", "LayoutMetaInfo",
gsi::method_ext ("name", &layout_meta_get_name, gsi::method_ext ("name", &layout_meta_get_name,
"@brief Gets the name of the layout meta info object\n" "@brief Gets the name of the layout meta info object\n"
) + ) +
gsi::method_ext ("name=", &layout_meta_set_name, gsi::method_ext ("name=", &layout_meta_set_name, gsi::arg ("name"),
"@brief Sets the name of the layout meta info object\n" "@brief Sets the name of the layout meta info object\n"
) + ) +
gsi::method_ext ("value", &layout_meta_get_value, gsi::method_ext ("value", &layout_meta_get_value,
"@brief Gets the value of the layout meta info object\n" "@brief Gets the value of the layout meta info object\n"
) + ) +
gsi::method_ext ("value=", &layout_meta_set_value, gsi::method_ext ("value=", &layout_meta_set_value, gsi::arg ("value"),
"@brief Sets the value of the layout meta info object\n" "@brief Sets the value of the layout meta info object\n"
) + ) +
gsi::method_ext ("description", &layout_meta_get_description, gsi::method_ext ("description", &layout_meta_get_description,
"@brief Gets the description of the layout meta info object\n" "@brief Gets the description of the layout meta info object\n"
) + ) +
gsi::method_ext ("description=", &layout_meta_set_description, gsi::method_ext ("description=", &layout_meta_set_description, gsi::arg ("description"),
"@brief Sets the description of the layout meta info object\n" "@brief Sets the description of the layout meta info object\n"
) + ) +
gsi::method_ext ("is_persisted?", &layout_meta_get_persisted, gsi::method_ext ("is_persisted?", &layout_meta_get_persisted,
"@brief Gets a value indicating whether the meta information will be persisted\n" "@brief Gets a value indicating whether the meta information will be persisted\n"
"This predicate was introduced in version 0.28.8.\n" "This predicate was introduced in version 0.28.8.\n"
) + ) +
gsi::method_ext ("persisted=", &layout_meta_set_persisted, gsi::method_ext ("persisted=", &layout_meta_set_persisted, gsi::arg ("flag"),
"@brief Sets a value indicating whether the meta information will be persisted\n" "@brief Sets a value indicating whether the meta information will be persisted\n"
"This predicate was introduced in version 0.28.8.\n" "This predicate was introduced in version 0.28.8.\n"
), ),
@ -131,12 +131,37 @@ Class<MetaInfo> decl_LayoutMetaInfo ("db", "LayoutMetaInfo",
" keys for user properties. @/li\n" " keys for user properties. @/li\n"
"@/ul\n" "@/ul\n"
"\n" "\n"
"Note that only meta information marked with \\is_persisted? == true are stored in GDS or OASIS files. " "Elementary (serializable) objects are: \\Box, \\DBox, \\Edge, \\DEdge, \\EdgePair, \\DEdgePair, "
"\\EdgePairs, \\Edges, \\LayerProperties, \\Matrix2d, \\Matrix3d, \\Path, \\DPath, \\Point, \\DPoint, "
"\\Polygon, \\DPolygon, \\SimplePolygon, \\DSimplePolygon, \\Region, \\Text, \\DText, \\Texts, "
"\\Trans, \\DTrans, \\CplxTrans, \\ICplxTrans, \\DCplxTrans, \\VCplxTrans, \\Vector, \\DVector "
"(list may not be complete).\n"
"\n"
"KLayout itself also generates meta information with specific keys. "
"For disambiguation, namespaces can be established by prefixing "
"the key strings with some unique identifier in XML fashion, like a domain name - "
"e.g. 'example.com:key'.\n"
"\n"
"@b Note: @/b only meta information marked with \\is_persisted? == true is stored in GDS or OASIS files. "
"This is not the default setting, so you need to explicitly set that flag.\n" "This is not the default setting, so you need to explicitly set that flag.\n"
"\n" "\n"
"See also \\Layout#each_meta_info, \\Layout#meta_info_value, \\Layout#meta_info and \\Layout#remove_meta_info as " "See also \\Layout#each_meta_info, \\Layout#meta_info_value, \\Layout#meta_info and \\Layout#remove_meta_info as "
"well as the corresponding \\Cell methods.\n" "well as the corresponding \\Cell methods.\n"
"\n" "\n"
"An example of how to attach persisted meta information to a cell is here:\n"
"\n"
"@code\n"
"ly = RBA::Layout::new\n"
"c1 = ly.create_cell(\"C1\")\n"
"\n"
"mi = RBA::LayoutMetaInfo::new(\"the-answer\", 42.0)\n"
"mi.persisted = true\n"
"c1.add_meta_info(mi)\n"
"\n"
"# will now hold this piece of meta information attached to cell 'C1':\n"
"ly.write(\"to.gds\")\n"
"@/code\n"
"\n"
"This class has been introduced in version 0.25 and was extended in version 0.28.8." "This class has been introduced in version 0.25 and was extended in version 0.28.8."
); );

View File

@ -1194,7 +1194,7 @@ TEST(121)
} }
// Meta info // Meta info
TEST(130) TEST(130a)
{ {
db::Layout layout_org; db::Layout layout_org;
@ -1207,7 +1207,19 @@ TEST(130)
layout_org.add_meta_info (ci, "a", db::MetaInfo ("dd", true, true)); layout_org.add_meta_info (ci, "a", db::MetaInfo ("dd", true, true));
layout_org.add_meta_info (ci, "c", db::MetaInfo ("d", -1, true)); layout_org.add_meta_info (ci, "c", db::MetaInfo ("d", -1, true));
std::string tmp_file = tl::TestBase::tmp_file ("tmp_GDS2Writer_130.gds"); // complex type
tl::Variant v2;
v2.set_array ();
v2.insert ("x", "value_for_x");
v2.insert ("y", db::DBox (1.5, 2.5, 3.5, 4.5));
tl::Variant v1;
v1.set_list (0);
v1.push (-1.5);
v1.push (v2);
layout_org.add_meta_info (ci, "complex", db::MetaInfo ("", v1, true));
layout_org.add_meta_info ("complex", db::MetaInfo ("", v1, true));
std::string tmp_file = tl::TestBase::tmp_file ("tmp_GDS2Writer_130a.gds");
{ {
tl::OutputStream out (tmp_file); tl::OutputStream out (tmp_file);
@ -1224,11 +1236,19 @@ TEST(130)
reader.read (layout_read); reader.read (layout_read);
} }
EXPECT_EQ (layout_read.has_meta_info ("x"), false);
EXPECT_EQ (layout_read.has_meta_info ("a"), true);
EXPECT_EQ (layout_read.meta_info ("x").value.to_string (), "nil"); EXPECT_EQ (layout_read.meta_info ("x").value.to_string (), "nil");
EXPECT_EQ (layout_read.meta_info ("a").value.to_string (), "17.5"); EXPECT_EQ (layout_read.meta_info ("a").value.to_string (), "17.5");
EXPECT_EQ (layout_read.meta_info ("a").description, "description"); EXPECT_EQ (layout_read.meta_info ("a").description, "description");
EXPECT_EQ (layout_read.has_meta_info ("b"), true);
EXPECT_EQ (layout_read.meta_info ("b").value.to_string (), "value"); EXPECT_EQ (layout_read.meta_info ("b").value.to_string (), "value");
EXPECT_EQ (layout_read.meta_info ("b").description, ""); EXPECT_EQ (layout_read.meta_info ("b").description, "");
EXPECT_EQ (layout_read.has_meta_info ("complex"), true);
EXPECT_EQ (layout_read.meta_info ("complex").value.is_list (), true);
EXPECT_EQ (layout_read.meta_info ("complex").value.size (), size_t (2));
EXPECT_EQ (layout_read.meta_info ("complex").value.begin () [1].is_array (), true);
EXPECT_EQ (layout_read.meta_info ("complex").value.to_string (), "-1.5,x=>value_for_x,y=>(1.5,2.5;3.5,4.5)");
db::cell_index_type ci2 = layout_read.cell_by_name ("X").second; db::cell_index_type ci2 = layout_read.cell_by_name ("X").second;
@ -1237,6 +1257,10 @@ TEST(130)
EXPECT_EQ (layout_read.meta_info (ci2, "a").description, "dd"); EXPECT_EQ (layout_read.meta_info (ci2, "a").description, "dd");
EXPECT_EQ (layout_read.meta_info (ci2, "c").value.to_string (), "-1"); EXPECT_EQ (layout_read.meta_info (ci2, "c").value.to_string (), "-1");
EXPECT_EQ (layout_read.meta_info (ci2, "c").description, "d"); EXPECT_EQ (layout_read.meta_info (ci2, "c").description, "d");
EXPECT_EQ (layout_read.meta_info (ci2, "complex").value.is_list (), true);
EXPECT_EQ (layout_read.meta_info (ci2, "complex").value.size (), size_t (2));
EXPECT_EQ (layout_read.meta_info (ci2, "complex").value.begin () [1].is_array (), true);
EXPECT_EQ (layout_read.meta_info (ci2, "complex").value.to_string (), "-1.5,x=>value_for_x,y=>(1.5,2.5;3.5,4.5)");
tmp_file = tl::TestBase::tmp_file ("tmp_GDS2Writer_130b.gds"); tmp_file = tl::TestBase::tmp_file ("tmp_GDS2Writer_130b.gds");