mandatory parameters: why and how?
Description
Current state of mandatory parameter is really confusing.
Parameter class has a bool m_Mandatory and is true by default. Unless a parameter is set to off with MandatoryOff(p)
then they are really required.
This make me tip toe around in finding mandatory flag in otbQgisDescriptor.cxx. Now that doesn't solve issue and ends up in error when using otbExtractROI. Error message from QGIS is mode.fit.vect
is not set. QGIS sees this parameter as mandatory probably because otb description for ExtractROI said so!
This parameter is only required if mode = fit
. so it must be optional. But not according to param->GetMandatory()
. It says parameter is mandatory no matter what value is set for mode
parameter. This is wrong and is problematic for apps like QGIS and others who rely on descriptor files.
In QGIS description file, there is a csv field to identify that parameter as optional or not. (mandatory or not in OTB terms).
Here is the list of paramters reported by otbcli_ExtractROI
in (mandatory)
out (mandatory)
mode.fit.im (mandatory)
mode.fit.vect (mandatory)
mode.extent.ulx (mandatory, default value is 0)
mode.extent.uly (mandatory, default value is 0)
mode.extent.lrx (mandatory, default value is 0)
mode.extent.lry (mandatory, default value is 0)
mode.extent.unit (mandatory, default value is pxl)
mode.radius.r (mandatory, default value is 0)
mode.radius.unitr (mandatory, default value is pxl)
mode.radius.cx (mandatory, default value is 0)
mode.radius.cy (mandatory, default value is 0)
mode.radius.unitc (mandatory, default value is pxl)
startx (mandatory, default value is 0)
starty (mandatory, default value is 0)
sizex (mandatory, default value is 0)
sizey (mandatory, default value is 0)
cl (mandatory, no default value)
elev.dem (optional, off by default)
elev.geoid (optional, off by default)
elev.default (mandatory, default value is 0)
ram (optional, off by default, default value is 128)
inxml (optional, off by default)
my suggestion is to use below rule to find out if parameter is mandatory. A parameter is mandatory if statisfies all of the conditions:
- Must have parent parameter set.
mode.fit.vect
is mandatory only ifmode = fit
- Must not have default a value.
Below code can cover first case in this rule. Before going on to add this in otbQgisDescriptor, I would like to find out if there is a better way to deal with mandatory flag in OTBApplicationEngine so other can rely on Parameter::GetMandatory() and stick to API rather than spaghetti forever.
+ std::string optional = "false";
+ ParameterKey pName(name);
+ auto splitName = pName.Split();
+ if (splitName.size() > 2)
+ optional = "true";
+ else
+ optional = param->HasValue() ? "true" : "false";
+
we can add a check for if-default-value-exists.
Steps to reproduce
try ExtractROI application using QGIS 3.2 and OTB 6.6
Configuration information
OS, OTB version or tag, information related to build (binaries, superbuild, system libs ...)