-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Helper] A static alternative to OptionsGroup: SelectableItem #5062
base: master
Are you sure you want to change the base?
Conversation
[ci-build][with-all-tests] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice ! I like it. The only down side is the need to use a macro to have something that doesn't look heavy to declare a item list... But I guess there is no other solution.
9e4825c
to
a4ba51f
Compare
@damienmarchal I managed to return a common string for all types deriving from struct TestSelectableItem final : sofa::helper::SelectableItem<TestSelectableItem> {};
TestSelectableItem item;
sofa::Data<TestSelectableItem> data;
BaseData* baseData = &data; Obviously The widget mechanism relies on
|
I was trying to find a solution but looking at the code in DataWidget.cpp makes me notice: DataWidget *DataWidget::CreateDataWidget(const DataWidget::CreatorArgument &dwarg)
{
DataWidget *datawidget_ = nullptr;
const std::string &widgetName=dwarg.data->getWidget();
if (widgetName.empty())
datawidget_ = DataWidgetFactory::CreateAnyObject(dwarg);
else
datawidget_ = DataWidgetFactory::CreateObject(widgetName, dwarg);
return datawidget_;
} And wonder if you try the getWidget() to short cut the dynamic_cast ? |
@damienmarchal I believe that the |
SelectableItem
is a new type that can replaceOptionsGroup
in some cases. The idea is the same: a list of keys + a selection of a key among the list. InOptionsGroup
, everything is dynamic, whereasSelectableItem
is designed to be static.Disadvantages of
OptionsGroup
:In
SelectableItem
:The consequences:
constexpr
:It allows to use the type in a
constexpr
context. For example:There is compile-time check that any of the
ResolutionMethod("ProjectedGaussSeidel"), ResolutionMethod("NonsmoothNonlinearConjugateGradient"), ResolutionMethod("UnbuiltGaussSeidel")
exist. If it does not exist, it does not compile.It is preferable to force the
constexpr
context:The compiler may not choose to use
constexpr
in:Therefore, no
constexpr
check ifNonsmoothNonlinearConjugateGradient
is not in the list. There is a runtime check though.The type allows to deprecate a key if desired (I am thinking about the Data
method
in the FEM force fields).There is also a description of each key. And the whole list (key + description) can be added easily in the description of the Data, hence in the documentation.
The major problem is about the GUI. More particularly, when a Data is read to be displayed in the GUI. Here, each of the
SelectableItem
is a new strong type. So there is noDataTypeName
,DataTypeInfo
etc for the new type. I tried to factorize with a common base class (BaseSelectableItem
) but without success. I tried to defineDataTypeName
,DataTypeInfo
etc forSelectedItem
but without success. The consequence is that I cannot specialize a widget for this type of Data.By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).
Reviewers will merge this pull-request only if