Commit c3fa194e authored by Victor Poughon's avatar Victor Poughon

Merge branch '1770-remove-parameter-empty' into 'develop'

Remove ParameterType_Empty

Closes #1770

See merge request !307
parents f3f9b91e 32329844
......@@ -115,8 +115,7 @@ def GenerateChoice(app,param,paramlist, count = 0):
return output
def GenerateParameterType(app,param):
if app.GetParameterType(param) == otbApplication.ParameterType_Empty \
or app.GetParameterType(param) == otbApplication.ParameterType_Bool:
if app.GetParameterType(param) == otbApplication.ParameterType_Bool:
return "Boolean"
if app.GetParameterType(param) == otbApplication.ParameterType_Int \
or app.GetParameterType(param) == otbApplication.ParameterType_Radius \
......@@ -367,9 +366,6 @@ def GetApplicationExamplePythonSnippet(app,idx,expand = False, inputpath="",outp
if paramtype == otbApplication.ParameterType_Choice:
#app.SetParameterString(param,value)
output+= "\t" + appname + ".SetParameterString(" + EncloseString(param) + "," + EncloseString(value) + ")" + linesep
if paramtype == otbApplication.ParameterType_Empty:
app.EnableParameter(param)
output+= "\t" + appname + ".EnableParameter("+EncloseString(param)+")" + linesep
if paramtype == otbApplication.ParameterType_Bool:
output+= "\t" + appname + ".SetParameterString("+EncloseString(param)+","+EncloseString(value)+")" + linesep
if paramtype == otbApplication.ParameterType_Int \
......
......@@ -375,41 +375,3 @@ that relate to geometry, projections, and also calibration.
Future developments will probably offer a more adapted structure to import and
export images between OTB and the Python world.
Setting of EmptyParameter
^^^^^^^^^^^^^^^^^^^^^^^^^
Most of the parameters are set using functions ``SetParameterXXX()``, except for
one type of parameter: the ``EmptyParameter``. This class was the first
implementation of a boolean. It is now **deprecated**, you should use ``BoolParameter``
instead.
Let's take an example with the application ``ReadImageInfo`` when it was still
using an ``EmptyParameter`` for parameter ``keywordlist``:
.. code-block:: python
import otbApplication as otb
app = otb.Registry.CreateApplication("ReadImageInfo")
If you want the get the state of parameter ``keywordlist``, a boolean, use:
.. code-block:: python
app.IsParameterEnabled("keywordlist")
To set this parameter ON/OFF, use the functions:
.. code-block:: python
app.EnableParameter("keywordlist")
app.DisableParameter("keywordlist")
Don't try to use other functions to set the state of a boolean. For instance,
try the following commands:
.. code-block:: python
app.SetParameterInt("keywordlist", 0)
app.IsParameterEnabled("keywordlist")
You will get a state ``True`` even if you asked the opposite.
......@@ -153,7 +153,7 @@ private:
AddParameter(ParameterType_OutputImage, "out", "Output Image");
AddParameter(ParameterType_Empty, "param1", "Example of boolean parameter");
AddParameter(ParameterType_Bool, "param1", "Example of boolean parameter");
MandatoryOff("param1");
AddParameter(ParameterType_Int, "param2", "Example of integer parameter");
......
......@@ -65,7 +65,6 @@ LearningApplicationBase<TInputValue,TOutputValue>
"regression accuracy parameter, then the node will not be split further.");
//UseSurrogates : don't need to be exposed !
//AddParameter(ParameterType_Empty, "classifier.dt.sur", "Surrogate splits will be built");
//SetParameterDescription("classifier.dt.sur","These splits allow working with missing data and compute variable importance correctly.");
//MaxCategories
......
......@@ -79,9 +79,6 @@ LearningApplicationBase<TInputValue,TOutputValue>
"possible depth of the tree. The actual depth may be smaller if the other termination criteria are met, and/or "
"if the tree is pruned.");
//UseSurrogates : don't need to be exposed !
//AddParameter(ParameterType_Empty, "classifier.gbt.sur", "Surrogate splits will be built");
//SetParameterDescription("classifier.gbt.sur","These splits allow working with missing data and compute variable importance correctly.");
#endif
}
......
......@@ -59,10 +59,6 @@ LearningApplicationBase<TInputValue,TOutputValue>
"and the values of the train samples in this node are smaller than this regression accuracy parameter, "
"then the node will not be split.");
//UseSurrogates : don't need to be exposed !
//AddParameter(ParameterType_Empty, "classifier.rf.sur", "Surrogate splits will be built");
//SetParameterDescription("classifier.rf.sur","These splits allow working with missing data and compute variable importance correctly.");
//MaxNumberOfCategories
AddParameter(ParameterType_Int, "classifier.rf.cat",
"Cluster possible values of a categorical variable into K <= cat clusters to find a suboptimal split");
......
......@@ -189,10 +189,6 @@ private:
SetParameterDescription("filter.meanshift.minsize", "Minimum size of a region (in pixel unit) in segmentation. Smaller clusters will be merged to the neighboring cluster with the closest radiometry."
" If set to 0 no pruning is done.");
//AddParameter(ParameterType_Empty, "filter.meanshift.useoptim", "use optimization");
//SetParameterDescription("filter.meanshift.useoptim", "Use mode optimization.");
//MandatoryOff("filter.meanshift.useoptim");
SetDefaultParameterInt("filter.meanshift.spatialr", 5);
SetDefaultParameterFloat("filter.meanshift.ranger", 15.0);
SetDefaultParameterFloat("filter.meanshift.thres", 0.1);
......
......@@ -56,7 +56,6 @@ private:
AddDocTag("Test");
//std::cout << "TestApplication::DoInit" << std::endl;
AddParameter(ParameterType_Empty, "empty", "Boolean (old impl.)");
AddParameter(ParameterType_Bool, "boolean", "Boolean");
AddParameter(ParameterType_Int, "int", "Integer");
MandatoryOff("int");
......
......@@ -190,10 +190,6 @@ public:
* or a value set externally by user */
bool HasValue(std::string paramKey) const;
/* Get active flag of parameter with key paramKey
*/
bool GetParameterEmpty(std::string paramKey);
/** Set HasUserValue flag of parameter with key paramKey
* Note that when this function is called from DoInit, DoUpdateParameters
* or DoExecute, it will always set this flag to false, because this is
......@@ -226,6 +222,7 @@ public:
*
* Can be called for types :
* \li ParameterType_Int
* \li ParameterType_Bool
* \li ParameterType_Float
* \li ParameterType_Radius
* \li ParameterType_Choice
......@@ -271,8 +268,6 @@ public:
*/
void SetParameterStringList(std::string parameter, std::vector<std::string> values, bool hasUserValueFlag = true);
void SetParameterEmpty(std::string parameter, bool value, bool hasUserValueFlag = true);
/** Checks if the application is ready to be executed. It checks that there
* is no missing parameter
*/
......@@ -434,6 +429,7 @@ public:
*
* Can be called for types :
* \li ParameterType_Int
* \li ParameterType_Bool
* \li ParameterType_Float
* \li ParameterType_Radius
* \li ParameterType_Choice
......
......@@ -33,8 +33,6 @@ namespace Wrapper
/** \class BoolParameter
* \brief This class represent a boolean parameter for the wrapper framework
*
* It is intended to replace the deprecated EmptyParameter
*
* \ingroup OTBApplicationEngine
*/
class OTBApplicationEngine_EXPORT BoolParameter
......
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbWrapperEmptyParameter_h
#define otbWrapperEmptyParameter_h
#include "otbWrapperParameter.h"
namespace otb
{
namespace Wrapper
{
/** \class EmptyParameter
* \brief This class represent an empty parameter for the wrapper framework (boolean value)
*
* \deprecated in OTB 6.6, use BoolParameter instead
*
* \ingroup OTBApplicationEngine
*/
class OTBApplicationEngine_EXPORT EmptyParameter
: public Parameter
{
public:
/** Standard class typedef */
typedef EmptyParameter Self;
typedef Parameter Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Defining ::New() static method */
itkNewMacro(Self);
/** RTTI support */
itkTypeMacro(EmptyParameter, Parameter);
/** HasValue */
bool HasValue() const override
{
return false;
}
bool HasUserValue() const override
{
return this->m_UserValue;
}
protected:
/** Constructor */
EmptyParameter()
{
// It does not make sense for an empty parameter to be mandatory
this->MandatoryOff();
}
/** Destructor */
~EmptyParameter() override
{}
private:
EmptyParameter(const EmptyParameter &) = delete;
void operator =(const EmptyParameter&) = delete;
}; // End class Parameter
} // End namespace Wrapper
} // End namespace otb
#endif
......@@ -35,7 +35,6 @@ namespace Wrapper
typedef enum
{
ParameterType_Empty,
ParameterType_Int,
ParameterType_Float,
ParameterType_String,
......
......@@ -22,7 +22,6 @@
#include "otbWrapperChoiceParameter.h"
#include "otbWrapperListViewParameter.h"
#include "otbWrapperDirectoryParameter.h"
#include "otbWrapperEmptyParameter.h"
#include "otbWrapperInputFilenameParameter.h"
#include "otbWrapperInputFilenameListParameter.h"
#include "otbWrapperOutputFilenameParameter.h"
......@@ -380,6 +379,10 @@ void Application::SetParameterInt(std::string parameter, int value, bool hasUser
BoolParameter* paramBool = dynamic_cast<BoolParameter*>(param);
paramBool->SetValue(static_cast<bool>(value));
}
else
{
otbAppLogWARNING(<< "SetParameterInt on parameter " + parameter);
}
this->SetParameterUserValue(parameter, hasUserValueFlag);
}
......@@ -538,12 +541,6 @@ void Application::SetParameterStringList(std::string parameter, std::vector<std:
this->SetParameterUserValue(parameter, hasUserValueFlag);
}
void Application::SetParameterEmpty(std::string parameter, bool value, bool hasUserValueFlag)
{
this->SetParameterUserValue(parameter, hasUserValueFlag);
GetParameterByKey(parameter)->SetActive(value);
}
void Application::SetParameterUserValue(std::string paramKey, bool value)
{
/** UserValue is set/unset parameter must be active.
......@@ -1086,11 +1083,6 @@ Role Application::GetParameterRole(std::string paramKey) const
return GetParameterByKey(paramKey)->GetRole();
}
bool Application::GetParameterEmpty(std::string paramKey)
{
return GetParameterByKey(paramKey)->GetActive();
}
/* Return the role (input/output) of a parameter */
void Application::SetParameterRole(std::string paramKey, Role role)
{
......@@ -1116,10 +1108,6 @@ ParameterType Application::GetParameterType(std::string paramKey) const
{
type = ParameterType_Radius;
}
else if (dynamic_cast<const EmptyParameter*>(param))
{
type = ParameterType_Empty;
}
else if (dynamic_cast<const IntParameter*>(param))
{
type = ParameterType_Int;
......@@ -1550,11 +1538,6 @@ int Application::GetParameterInt(std::string parameter)
BoolParameter* paramBool = dynamic_cast<BoolParameter*>(param);
ret = static_cast<int>(paramBool->GetValue());
}
else if (dynamic_cast<EmptyParameter*>(param))
{
// This case is here for compatibility purpose with deprecated EmptyParameter
ret = static_cast<int>(this->IsParameterEnabled(parameter));
}
else
{
itkExceptionMacro(<<parameter << " parameter can't be casted to int");
......
......@@ -23,7 +23,6 @@
#include "otbWrapperChoiceParameter.h"
#include "otbWrapperListViewParameter.h"
#include "otbWrapperDirectoryParameter.h"
#include "otbWrapperEmptyParameter.h"
#include "otbWrapperInputFilenameParameter.h"
#include "otbWrapperInputFilenameListParameter.h"
#include "otbWrapperOutputFilenameParameter.h"
......@@ -419,15 +418,6 @@ InputProcessXMLParameter::Read(Application::Pointer this_)
std::stringstream(value) >> floatValue;
this_->SetParameterFloat(key, floatValue);
}
else if (type == ParameterType_Empty)
{
bool emptyValue = false;
if( value == "true")
{
emptyValue = true;
}
this_->SetParameterEmpty(key, emptyValue);
}
else if (type == ParameterType_StringList || type == ParameterType_ListView)
{
if(values.empty())
......
......@@ -23,7 +23,6 @@
#include "otbWrapperChoiceParameter.h"
#include "otbWrapperListViewParameter.h"
#include "otbWrapperDirectoryParameter.h"
#include "otbWrapperEmptyParameter.h"
#include "otbWrapperInputFilenameParameter.h"
#include "otbWrapperInputFilenameListParameter.h"
#include "otbWrapperOutputFilenameParameter.h"
......@@ -243,26 +242,6 @@ OutputProcessXMLParameter::ParseGroup(const std::string& group)
paramExists = false;
}
std::string emptyValue;
if (type == ParameterType_Empty)
{
EmptyParameter* eParam = dynamic_cast<EmptyParameter *> (param);
if(eParam!=nullptr)
{
//Don't use m_Appli->HasUserValue which returns false always because of
//EmptyParameter::HasValue() is false for EmptyParameter
if(eParam->HasUserValue())
{
paramExists = true;
emptyValue = "false";
if( eParam->GetActive() )
{
emptyValue = "true";
}
}
}
}
if(type == ParameterType_RAM)
{
paramExists = true;
......@@ -317,11 +296,6 @@ OutputProcessXMLParameter::ParseGroup(const std::string& group)
strm << m_Appli->GetParameterInt("rand");
value = strm.str();
}
else if (typeAsString == "Empty")
{
//Nothing to do. copy emptyValue
value = emptyValue;
}
else if (type == ParameterType_InputProcessXML)
{
continue;
......
......@@ -21,7 +21,6 @@
#include "otbWrapperChoiceParameter.h"
#include "otbWrapperListViewParameter.h"
#include "otbWrapperDirectoryParameter.h"
#include "otbWrapperEmptyParameter.h"
#include "otbWrapperInputFilenameParameter.h"
#include "otbWrapperInputFilenameListParameter.h"
#include "otbWrapperOutputFilenameParameter.h"
......@@ -249,10 +248,6 @@ ParameterGroup::GetSelectedItems(std::string paramKey)
{
return ParameterType_Radius;
}
else if (type == "Empty")
{
return ParameterType_Empty;
}
else if (type == "Int")
{
return ParameterType_Int;
......@@ -339,8 +334,8 @@ ParameterGroup::GetSelectedItems(std::string paramKey)
}
else
{
std::cerr << "Cannot find parameter type code for type: " << type << std::endl;
return ParameterType_Empty;
otbLogMacro(Error, << "Cannot find parameter type code for type: " << type);
throw std::invalid_argument("Cannot find parameter type code for type: " + type);
}
}
......@@ -351,11 +346,6 @@ std::string ParameterGroup::GetParameterTypeAsString(ParameterType type)
switch (type)
{
case ParameterType_Empty:
{
paramType = "Empty";
}
break;
case ParameterType_Int:
{
paramType = "Int";
......@@ -515,11 +505,6 @@ ParameterGroup::AddParameter(ParameterType type, std::string paramKey, std::stri
Parameter::Pointer newParam;
switch (type)
{
case ParameterType_Empty:
{
newParam = EmptyParameter::New();
}
break;
case ParameterType_Int:
{
newParam = IntParameter::New();
......
......@@ -23,7 +23,6 @@
// Single value parameter
#include "otbWrapperChoiceParameter.h"
#include "otbWrapperDirectoryParameter.h"
#include "otbWrapperEmptyParameter.h"
#include "otbWrapperInputFilenameParameter.h"
#include "otbWrapperOutputFilenameParameter.h"
#include "otbWrapperInputImageParameter.h"
......@@ -496,26 +495,6 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
}
}
}
else if (type == ParameterType_Empty)
{
// Set UserValue flag specific for EmptyParameter, beware that it
// should be done before Enable/Disable because SetParameterUserValue()
// may enable it by default
m_Application->SetParameterUserValue(paramKey,true);
if (values[0] == "1" || values[0] == "true")
{
m_Application->EnableParameter(paramKey);
}
else if (values[0] == "0" || values[0] == "false")
{
m_Application->DisableParameter(paramKey);
}
else
{
std::cerr << "ERROR: Wrong value for parameter -" << paramKey << "." << std::endl;
return WRONGPARAMETERVALUE;
}
}
// Call the DoUpdateParameter to update dependent params
m_Application->UpdateParameters();
}
......@@ -755,7 +734,7 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer &
{
oss << "<int32> ";
}
else if (type == ParameterType_Empty || type == ParameterType_Bool)
else if (type == ParameterType_Bool)
{
oss << "<boolean> ";
}
......
......@@ -54,7 +54,6 @@ int main(int argc, char* argv[])
assert(!group.empty());
std::map<ParameterType, std::string> parameterTypeToString;
parameterTypeToString[ParameterType_Empty] = "QgsProcessingParameterBoolean";
parameterTypeToString[ParameterType_Bool] = "QgsProcessingParameterBoolean";
parameterTypeToString[ParameterType_Int] = "QgsProcessingParameterNumber";
parameterTypeToString[ParameterType_Float] = "QgsProcessingParameterNumber";
......@@ -272,10 +271,6 @@ int main(int argc, char* argv[])
{
default_value = appli->GetParameterAsString(name);
}
else if(type == ParameterType_Empty)
{
default_value = appli->IsParameterEnabled(name)?"true":"false";
}
else if(type == ParameterType_Choice)
{
std::vector<std::string> key_list = appli->GetChoiceKeys(name);
......
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbWrapperQtWidgetEmptyParameter_h
#define otbWrapperQtWidgetEmptyParameter_h
#include <QtWidgets>
#include "otbWrapperEmptyParameter.h"
#include "otbWrapperQtWidgetParameterBase.h"
namespace otb
{
namespace Wrapper
{
/** \class QtWidgetEmptyParameter
* \brief
*
* \ingroup OTBQtWidget
*/
class OTBQtWidget_EXPORT QtWidgetEmptyParameter : public QtWidgetParameterBase
{
Q_OBJECT
public:
QtWidgetEmptyParameter(EmptyParameter*, QtWidgetModel*, QWidget*);
~QtWidgetEmptyParameter() override;
private:
QtWidgetEmptyParameter(const QtWidgetEmptyParameter&) = delete;
void operator=(const QtWidgetEmptyParameter&) = delete;
void DoCreateWidget() override;
void DoUpdateGUI() override;
};
}
}
#endif
......@@ -50,7 +50,6 @@ set(OTBQtWidget_SRC
otbWrapperQtWidgetParameterBase.cxx
otbWrapperQtWidgetInputImageParameter.cxx
otbWrapperQtWidgetStringListParameter.cxx
otbWrapperQtWidgetEmptyParameter.cxx
otbWrapperQtWidgetOutputVectorDataParameter.cxx
otbWrapperQtWidgetInputFilenameParameter.cxx
otbWrapperQtWidgetInputImageListParameter.cxx
......@@ -62,7 +61,6 @@ set(OTBQtWidget_SRC
)
set(OTBQtWidget_MOC_HDR
../include/otbWrapperQtWidgetEmptyParameter.h
../include/otbWrapperQtWidgetFloatParameter.h
../include/otbWrapperQtWidgetIntParameter.h
../include/otbWrapperQtWidgetStringParameter.h
......
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbWrapperQtWidgetEmptyParameter.h"
namespace otb
{
namespace Wrapper
{
QtWidgetEmptyParameter::QtWidgetEmptyParameter(EmptyParameter* emptyParam, QtWidgetModel* m, QWidget * parent)
: QtWidgetParameterBase(emptyParam, m, parent)
{
}
QtWidgetEmptyParameter::~QtWidgetEmptyParameter()
{
}
void QtWidgetEmptyParameter::DoUpdateGUI()
{
}
void QtWidgetEmptyParameter::DoCreateWidget()
{
// Set up input text edit
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->setSpacing(0);
hLayout->setContentsMargins(0, 0, 0, 0);
//QCheckBox* checkbox = new QCheckBox(this);
//checkbox->setToolTip(emptyParam->GetDescription());
//QString optionID(emptyParam->GetName());
//hLayout->addWidget(checkbox);
hLayout->addStretch();
this->setLayout(hLayout);
}
}
}
......@@ -83,18 +83,9 @@ QtWidgetModel* QtWidgetParameterBase::GetModel()
// current widget
void QtWidgetParameterBase::SetActivationState( bool value )
{
//filter out EmptyParameter
if(strcmp(m_Param->GetNameOfClass(), "EmptyParameter") == 0)
{
//only set user value if there is a change
if(value != m_Param->GetActive())
m_Param->SetUserValue(true);
}
this->setEnabled(value);
this->SetChecked(value);
m_Param->SetActive(value);
}
const Parameter *
......
......@@ -29,7 +29,6 @@
#include "otbWrapperQtWidgetComplexInputImageParameter.h"
#include "otbWrapperQtWidgetComplexOutputImageParameter.h"
#include "otbWrapperQtWidgetDirectoryParameter.h"
#include "otbWrapperQtWidgetEmptyParameter.h"
#include "otbWrapperQtWidgetFloatParameter.h"
#include "otbWrapperQtWidgetIntParameter.h"
#include "otbWrapperQtWidgetInputFilenameParameter.h"
......@@ -105,7 +104,6 @@ QtWidgetParameterFactory::CreateQtWidget( Parameter* param, QtWidgetModel* model
}
if (0) {}
CREATEWIDGET(EmptyParameter, QtWidgetEmptyParameter)
CREATEWIDGET(IntParameter, QtWidgetIntParameter)
CREATEWIDGET(FloatParameter, QtWidgetFloatParameter)
CREATEWIDGET(InputFilenameParameter, QtWidgetInputFilenameParameter)
......
......@@ -24,7 +24,6 @@
#include "otbWrapperQtWidgetParameterFactory.h"
#include "otbWrapperStringParameter.h"
#include "otbWrapperEmptyParameter.h"
#include "otbWrapperChoiceParameter.h"
#include "otbWrapperQtWidgetModel.h"
......@@ -84,7 +83,6 @@ int otbWrapperQtWidgetParameterFactory(int argc, char* argv[])