diff --git a/src/db/db/gsiDeclDbLibrary.cc b/src/db/db/gsiDeclDbLibrary.cc index 08bb090dc..8fd578392 100644 --- a/src/db/db/gsiDeclDbLibrary.cc +++ b/src/db/db/gsiDeclDbLibrary.cc @@ -773,26 +773,7 @@ static unsigned int pd_type_none () return (unsigned int) db::PCellParameterDeclaration::t_none; } -db::PCellParameterDeclaration *ctor_pcell_parameter (const std::string &name, unsigned int type, const std::string &description) -{ - db::PCellParameterDeclaration *pd = new db::PCellParameterDeclaration (); - pd->set_name (name); - pd->set_type (db::PCellParameterDeclaration::type (type)); - pd->set_description (description); - return pd; -} - -db::PCellParameterDeclaration *ctor_pcell_parameter_2 (const std::string &name, unsigned int type, const std::string &description, const tl::Variant &def) -{ - db::PCellParameterDeclaration *pd = new db::PCellParameterDeclaration (); - pd->set_name (name); - pd->set_type (db::PCellParameterDeclaration::type (type)); - pd->set_description (description); - pd->set_default (def); - return pd; -} - -db::PCellParameterDeclaration *ctor_pcell_parameter_3 (const std::string &name, unsigned int type, const std::string &description, const tl::Variant &def, const std::string &unit) +db::PCellParameterDeclaration *ctor_pcell_parameter (const std::string &name, unsigned int type, const std::string &description, const tl::Variant &def, const std::string &unit) { db::PCellParameterDeclaration *pd = new db::PCellParameterDeclaration (); pd->set_name (name); @@ -804,20 +785,7 @@ db::PCellParameterDeclaration *ctor_pcell_parameter_3 (const std::string &name, } Class decl_PCellParameterDeclaration ("db", "PCellParameterDeclaration", - gsi::constructor ("new", &ctor_pcell_parameter, gsi::arg ("name"), gsi::arg ("type"), gsi::arg ("description"), - "@brief Create a new parameter declaration with the given name and type\n" - "@param name The parameter name\n" - "@param type One of the Type... constants describing the type of the parameter\n" - "@param description The description text\n" - ) + - gsi::constructor ("new", &ctor_pcell_parameter_2, gsi::arg ("name"), gsi::arg ("type"), gsi::arg ("description"), gsi::arg ("default"), - "@brief Create a new parameter declaration with the given name, type and default value\n" - "@param name The parameter name\n" - "@param type One of the Type... constants describing the type of the parameter\n" - "@param description The description text\n" - "@param default The default (initial) value\n" - ) + - gsi::constructor ("new", &ctor_pcell_parameter_3, gsi::arg ("name"), gsi::arg ("type"), gsi::arg ("description"), gsi::arg ("default"), gsi::arg ("unit"), + gsi::constructor ("new", &ctor_pcell_parameter, gsi::arg ("name"), gsi::arg ("type"), gsi::arg ("description"), gsi::arg ("default", tl::Variant (), "nil"), gsi::arg ("unit", std::string ()), "@brief Create a new parameter declaration with the given name, type, default value and unit string\n" "@param name The parameter name\n" "@param type One of the Type... constants describing the type of the parameter\n" @@ -877,6 +845,12 @@ Class decl_PCellParameterDeclaration ("db", "PCel "entry field in the parameter user interface.\n" "If a range is already set for this parameter the choice will not be added and a warning message is showed.\n" ) + + gsi::method ("choice_values", &db::PCellParameterDeclaration::get_choices, + "@brief Returns a list of choice values\n" + ) + + gsi::method ("choice_descriptions", &db::PCellParameterDeclaration::get_choice_descriptions, + "@brief Returns a list of choice descriptions\n" + ) + gsi::method ("min_value", &db::PCellParameterDeclaration::min_value, "@brief Gets the minimum value allowed\n" "See \\min_value= for a description of this attribute.\n" @@ -915,12 +889,6 @@ Class decl_PCellParameterDeclaration ("db", "PCel "\n" "This attribute has been added in version 0.29." ) + - gsi::method ("choice_values", &db::PCellParameterDeclaration::get_choices, - "@brief Returns a list of choice values\n" - ) + - gsi::method ("choice_descriptions", &db::PCellParameterDeclaration::get_choice_descriptions, - "@brief Returns a list of choice descriptions\n" - ) + gsi::method ("default", &db::PCellParameterDeclaration::get_default, "@brief Gets the default value\n" ) + diff --git a/testdata/ruby/dbPCells.rb b/testdata/ruby/dbPCells.rb index ac96c68d3..d65150618 100644 --- a/testdata/ruby/dbPCells.rb +++ b/testdata/ruby/dbPCells.rb @@ -190,6 +190,78 @@ def norm_hash(hash) end +class DBPCellAPI_TestClass < TestBase + + def test_1 + + # PCellParameterDeclaration + + decl = RBA::PCellParameterDeclaration::new("name", RBA::PCellParameterDeclaration::TypeString, "description") + + assert_equal(decl.name, "name") + assert_equal(decl.description, "description") + assert_equal(decl.default.inspect, "nil") + assert_equal(decl.unit, "") + assert_equal(decl.type, RBA::PCellParameterDeclaration::TypeString) + + decl = RBA::PCellParameterDeclaration::new("name", RBA::PCellParameterDeclaration::TypeString, "description", "17") + + assert_equal(decl.name, "name") + assert_equal(decl.description, "description") + assert_equal(decl.type, RBA::PCellParameterDeclaration::TypeString) + assert_equal(decl.default.to_s, "17") + assert_equal(decl.unit, "") + + decl = RBA::PCellParameterDeclaration::new("name", RBA::PCellParameterDeclaration::TypeString, "description", "17", "unit") + + assert_equal(decl.name, "name") + assert_equal(decl.description, "description") + assert_equal(decl.type, RBA::PCellParameterDeclaration::TypeString) + assert_equal(decl.default.to_s, "17") + assert_equal(decl.unit, "unit") + + decl.name = "n" + assert_equal(decl.name, "n") + decl.description = "d" + assert_equal(decl.description, "d") + decl.unit = "u" + assert_equal(decl.unit, "u") + decl.type = RBA::PCellParameterDeclaration::TypeBoolean + assert_equal(decl.type, RBA::PCellParameterDeclaration::TypeBoolean) + decl.default = true + assert_equal(decl.default.to_s, "true") + + decl.type = RBA::PCellParameterDeclaration::TypeInt + assert_equal(decl.min_value.inspect, "nil") + assert_equal(decl.max_value.inspect, "nil") + decl.min_value = "-1" + assert_equal(decl.min_value.to_s, "-1") + decl.max_value = "42" + assert_equal(decl.max_value.to_s, "42") + decl.min_value = nil + decl.max_value = nil + assert_equal(decl.min_value.inspect, "nil") + assert_equal(decl.max_value.inspect, "nil") + + assert_equal(decl.hidden?, false) + decl.hidden = true + assert_equal(decl.hidden?, true) + + assert_equal(decl.readonly?, false) + decl.readonly = true + assert_equal(decl.readonly?, true) + + decl.add_choice("first", 42) + assert_equal(decl.choice_values, [42]) + assert_equal(decl.choice_descriptions, ["first"]) + decl.clear_choices + assert_equal(decl.choice_values, []) + assert_equal(decl.choice_descriptions, []) + + end + +end + class DBPCell_TestClass < TestBase def test_1