936 lines
27 KiB
C++
936 lines
27 KiB
C++
/*
|
||
* ParameterItem.cpp
|
||
*
|
||
* Created on: 2011-8-29
|
||
* Author: dev
|
||
*/
|
||
#include "ParameterItem.h"
|
||
#include <cassert>
|
||
#include <iostream>
|
||
#include <set>
|
||
//#include <QString>
|
||
|
||
namespace pai {
|
||
namespace module {
|
||
|
||
CParameterItem::CParameterItem()
|
||
: m_eType(ParmType_STRING)//参数项类型
|
||
, m_eInputType(TEXTEDIT)//参数项输入类型
|
||
, m_strId("")
|
||
, m_strValue("")//参数项值
|
||
, m_strName("")//参数项名字
|
||
, m_strDescription("")//参数项描述
|
||
, m_strDefault("")//参数项缺省值
|
||
, m_strCategory("General")//参数项分类
|
||
, m_strMax("")//参数项最大值
|
||
, m_strMin("")//参数项最小值
|
||
, m_strInputMetaData("")
|
||
, m_strInputData("")
|
||
, m_strInOut("")
|
||
, m_strDataType("")
|
||
, m_strDisplayValue("")
|
||
, m_iAccptDropTypes(0)
|
||
, m_bNecessary(false)//是否必填参数
|
||
, m_pParent(NULL)
|
||
{
|
||
// TODO Auto-generated constructor stub
|
||
|
||
|
||
|
||
}
|
||
|
||
CParameterItem::CParameterItem(const CParameterItem& srcItem)
|
||
: m_eType(ParmType_STRING)//参数项类型
|
||
, m_eInputType(TEXTEDIT)//参数项输入类型
|
||
, m_strId("")
|
||
, m_strValue("")//参数项值
|
||
, m_strName("")//参数项名字
|
||
, m_strDescription("")//参数项描述
|
||
, m_strDefault("")//参数项缺省值
|
||
, m_strCategory("General")//参数项分类
|
||
, m_strMax("")//参数项最大值
|
||
, m_strMin("")//参数项最小值
|
||
, m_strInputMetaData("")
|
||
, m_strInputData("")
|
||
, m_strInOut("")
|
||
, m_strDataType("")
|
||
, m_strDisplayValue("")
|
||
, m_iAccptDropTypes(0)
|
||
, m_bNecessary(false)//是否必填参数
|
||
, m_pParent(NULL)
|
||
{
|
||
Copy(srcItem);
|
||
|
||
}
|
||
|
||
void CParameterItem::Copy(const CParameterItem& srcItem)
|
||
{
|
||
m_eType = srcItem.m_eType;
|
||
m_eInputType = srcItem.m_eInputType;
|
||
m_strId = srcItem.m_strId;
|
||
m_strValue = srcItem.m_strValue;
|
||
m_strName = srcItem.m_strName;
|
||
m_strDescription = srcItem.m_strDescription;
|
||
m_strDefault = srcItem.m_strDefault;
|
||
m_strCategory = srcItem.m_strCategory;
|
||
m_strMax = srcItem.m_strMax;
|
||
m_strMin = srcItem.m_strMin;
|
||
m_strInputMetaData = srcItem.m_strInputMetaData;
|
||
m_strInputData = srcItem.m_strInputData;
|
||
m_iAccptDropTypes = srcItem.m_iAccptDropTypes;
|
||
m_bNecessary = srcItem.m_bNecessary;
|
||
m_pParent = srcItem.m_pParent;
|
||
m_strInOut= srcItem.m_strInOut;
|
||
m_strDataType= srcItem.m_strDataType;
|
||
m_strDisplayValue= srcItem.m_strDisplayValue;
|
||
}
|
||
|
||
CParameterItem::~CParameterItem() {
|
||
// TODO Auto-generated destructor stub
|
||
}
|
||
|
||
CParameterItem& CParameterItem::operator=(const CParameterItem& otherItem)
|
||
{
|
||
if(&otherItem == this)
|
||
return *this;
|
||
Copy(otherItem);
|
||
return *this;
|
||
}
|
||
|
||
bool CParameterItem::operator==(const CParameterItem& otherItem) const
|
||
{
|
||
return (m_eType == otherItem.m_eType &&
|
||
m_eInputType == otherItem.m_eInputType &&
|
||
m_strId == otherItem.m_strId &&
|
||
m_strValue == otherItem.m_strValue &&
|
||
m_strInputData == otherItem.m_strInputData);
|
||
}
|
||
bool CParameterItem::ValueToBool(bool* bOK) const
|
||
{
|
||
if(m_strValue == "false" || m_strValue == "FALSE" || m_strValue == "0")
|
||
{
|
||
if(bOK != NULL)
|
||
{
|
||
*bOK = true;
|
||
}
|
||
return false;
|
||
}
|
||
else if(m_strValue == "true" || m_strValue == "TRUE" || m_strValue == "1")
|
||
{
|
||
if(bOK != NULL)
|
||
{
|
||
*bOK = true;
|
||
}
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return ValueToT<bool>(ParmType_BOOL,false,bOK);
|
||
}
|
||
}
|
||
int CParameterItem::ValueToInt(bool* bOK) const
|
||
{
|
||
return ValueToT<int>(ParmType_INT,0,bOK);
|
||
}
|
||
long CParameterItem::ValueToLong(bool* bOK) const
|
||
{
|
||
return ValueToT<long>(ParmType_LONG,0,bOK);
|
||
}
|
||
|
||
float CParameterItem::ValueToFloat(bool* bOK) const
|
||
{
|
||
return ValueToT<float>(ParmType_FLOAT,0.f,bOK);
|
||
}
|
||
|
||
double CParameterItem::ValueToDouble(bool* bOK) const
|
||
{
|
||
return ValueToT<double>(ParmType_DOUBLE,0,bOK);
|
||
}
|
||
|
||
std::string CParameterItem::ValueToString() const
|
||
{
|
||
return m_strValue;
|
||
}
|
||
|
||
|
||
void CParameterItem::SetStringValue(const std::string& strValue)
|
||
{
|
||
m_strValue=strValue;
|
||
}
|
||
std::string CParameterItem::GetStringValue() const
|
||
{
|
||
return m_strValue;
|
||
}
|
||
bool CParameterItem::Validate()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
|
||
void CParameterItem::SetId(const std::string& strId)
|
||
{
|
||
m_strId = strId;
|
||
}
|
||
|
||
std::string CParameterItem::GetId() const
|
||
{
|
||
return m_strId;
|
||
}
|
||
|
||
std::string CParameterItem::GetShortID() const
|
||
{
|
||
std::string strShortID(m_strId);
|
||
size_t iDotPos = m_strId.rfind(".");
|
||
if(iDotPos != std::string::npos)
|
||
{
|
||
strShortID = m_strId.substr(iDotPos+1);
|
||
}
|
||
return strShortID;
|
||
}
|
||
|
||
void CParameterItem::SetName(const QString strName)
|
||
{
|
||
m_strName=strName;
|
||
}
|
||
void CParameterItem::SetName(const std::string& strName)
|
||
{
|
||
m_strName=strName.c_str();
|
||
}
|
||
|
||
QString CParameterItem::GetName() const
|
||
{
|
||
return m_strName;
|
||
}
|
||
QString CParameterItem::GetStringName() const
|
||
{
|
||
return m_strName;
|
||
}
|
||
|
||
void CParameterItem::SetDescription(const std::string& strDescription)
|
||
{
|
||
m_strDescription = strDescription;
|
||
}
|
||
|
||
std::string CParameterItem::GetDescription() const
|
||
{
|
||
return m_strDescription;
|
||
}
|
||
|
||
void CParameterItem::SetType(ParameterType eType)
|
||
{
|
||
m_eType = eType;
|
||
}
|
||
|
||
ParameterType CParameterItem::GetType() const
|
||
{
|
||
return m_eType;
|
||
}
|
||
|
||
void CParameterItem::SetInputType(ParameterInputType eType)
|
||
{
|
||
m_eInputType=eType;
|
||
}
|
||
|
||
ParameterInputType CParameterItem::GetInputType() const
|
||
{
|
||
return m_eInputType;
|
||
}
|
||
|
||
void CParameterItem::SetCategory(const std::string& strCategory)
|
||
{
|
||
m_strCategory = strCategory;
|
||
}
|
||
|
||
std::string CParameterItem::GetCategory() const
|
||
{
|
||
return m_strCategory;
|
||
}
|
||
|
||
void CParameterItem::SetInputMetaData(const std::string& strInputMetaData)
|
||
{
|
||
m_strInputMetaData = strInputMetaData;
|
||
}
|
||
|
||
std::string CParameterItem::GetInputMetaData() const
|
||
{
|
||
return m_strInputMetaData;
|
||
}
|
||
|
||
void CParameterItem::SetInputData(const std::string& strInputData)
|
||
{
|
||
m_strInputData = strInputData;
|
||
}
|
||
|
||
std::string CParameterItem::GetInputData() const
|
||
{
|
||
return m_strInputData;
|
||
}
|
||
|
||
void CParameterItem::AddAcceptDropType(AcceptDropType acceptDropType)
|
||
{
|
||
m_iAccptDropTypes |= acceptDropType;
|
||
}
|
||
|
||
std::vector<AcceptDropType> CParameterItem::GetAcceptDropTypes() const
|
||
{
|
||
std::vector<AcceptDropType> vecResult;
|
||
if(m_iAccptDropTypes == 0)
|
||
{
|
||
return vecResult;
|
||
}
|
||
std::map<std::string,AcceptDropType> mapAcceptTypes = GetAcceptDropTypeMap();
|
||
std::map<std::string,AcceptDropType>::const_iterator it;
|
||
for(it = mapAcceptTypes.begin(); it != mapAcceptTypes.end(); ++it )
|
||
{
|
||
if((m_iAccptDropTypes & it->second) == it->second )
|
||
{
|
||
vecResult.push_back(it->second);
|
||
}
|
||
}
|
||
return vecResult;
|
||
}
|
||
CParameterItem* CParameterItem::GetParentItem() const
|
||
{
|
||
return m_pParent;
|
||
}
|
||
|
||
|
||
void CParameterItem::SetInOut(const std::string& strInOut)
|
||
{
|
||
m_strInOut = strInOut;
|
||
}
|
||
|
||
std::string CParameterItem::GetInOut() const
|
||
{
|
||
return m_strInOut;
|
||
}
|
||
|
||
void CParameterItem::SetDataType(const std::string& strDataType)
|
||
{
|
||
m_strDataType = strDataType;
|
||
}
|
||
|
||
std::string CParameterItem::GetDataType() const
|
||
{
|
||
return m_strDataType;
|
||
}
|
||
|
||
|
||
void CParameterItem::SetDisplayValue(const std::string& strDisplayValue)
|
||
{
|
||
m_strDisplayValue = strDisplayValue;
|
||
}
|
||
|
||
std::string CParameterItem::GetDisplayValue() const
|
||
{
|
||
return m_strDisplayValue;
|
||
}
|
||
|
||
|
||
void CParameterItem::SetParentItem(CParameterItem* pParentItem)
|
||
{
|
||
if(pParentItem!=NULL && (pParentItem->GetType()==ParmType_ARRAY || pParentItem->GetType()==ParmType_CUSTOM))
|
||
{
|
||
m_pParent = pParentItem;
|
||
}
|
||
else
|
||
{
|
||
assert(false);
|
||
}
|
||
}
|
||
|
||
std::map<std::string,ParameterType> CParameterItem::GetTypeMap() const
|
||
{
|
||
|
||
std::map<std::string,ParameterType> ParamTypeMap;
|
||
ParamTypeMap.insert(std::make_pair("INT",ParmType_INT));
|
||
ParamTypeMap.insert(std::make_pair("FLOAT",ParmType_FLOAT));
|
||
ParamTypeMap.insert(std::make_pair("DOUBLE",ParmType_DOUBLE));
|
||
ParamTypeMap.insert(std::make_pair("STRING",ParmType_STRING));
|
||
ParamTypeMap.insert(std::make_pair("BOOL",ParmType_BOOL));
|
||
ParamTypeMap.insert(std::make_pair("LONG",ParmType_LONG));
|
||
ParamTypeMap.insert(std::make_pair("ARRAY",ParmType_ARRAY));
|
||
ParamTypeMap.insert(std::make_pair("CUSTOM",ParmType_CUSTOM));
|
||
return ParamTypeMap;
|
||
}
|
||
|
||
std::map<std::string,ParameterInputType> CParameterItem::GetInputTypeMap() const
|
||
{
|
||
std::map<std::string,ParameterInputType> ParamInputTypeMap;
|
||
ParamInputTypeMap.insert(std::make_pair("TEXTEDIT",TEXTEDIT));
|
||
ParamInputTypeMap.insert(std::make_pair("FILESAVEBROWER",FILESAVEBROWER));
|
||
ParamInputTypeMap.insert(std::make_pair("COMBOX",COMBOX));
|
||
ParamInputTypeMap.insert(std::make_pair("RADIOBOX",RADIOBOX));
|
||
ParamInputTypeMap.insert(std::make_pair("CHECKBOX",CHECKBOX));
|
||
ParamInputTypeMap.insert(std::make_pair("RADIOBUTTON",RADIOBUTTON));
|
||
ParamInputTypeMap.insert(std::make_pair("FILEBROWSER",FILEBROWSER));
|
||
ParamInputTypeMap.insert(std::make_pair("HDFSFILEBROWSER",HDFSFILEBROWSER));
|
||
ParamInputTypeMap.insert(std::make_pair("HDFSFILEEDITOR",HDFSFILEEDITOR));
|
||
ParamInputTypeMap.insert(std::make_pair("EDITABLEDGRID",EDITABLEDGRID));
|
||
ParamInputTypeMap.insert(std::make_pair("SPINBOX",SPINBOX));
|
||
ParamInputTypeMap.insert(std::make_pair("SPLIT",SPLIT));
|
||
ParamInputTypeMap.insert(std::make_pair("NONEINPUT",NONEINPUT));
|
||
return ParamInputTypeMap;
|
||
}
|
||
|
||
std::map<std::string,AcceptDropType> CParameterItem::GetAcceptDropTypeMap() const
|
||
{
|
||
std::map<std::string,AcceptDropType> ParamAccptDropTypeMap;
|
||
ParamAccptDropTypeMap.insert(std::make_pair("SEISMIC",SEISMIC));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("SPS",SPS));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("VELOCITYPAIR",VELOCITYPAIR));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("VELOCITYMODEL",VELOCITYMODEL));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("GRID",GRID));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("MUTE",MUTE));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("TRACEEDIT",TRACEEDIT));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("FIRSTBREAK",FIRSTBREAK));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("STATICS",STATICS));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("HORIZON",HORIZON));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("SPECTRUMDATA",SPECTRUMDATA));
|
||
ParamAccptDropTypeMap.insert(std::make_pair("SPATIALATTRIBUTE",SPATIALATTRIBUTE));
|
||
return ParamAccptDropTypeMap;
|
||
}
|
||
|
||
bool CParameterItem::IsEffective() const
|
||
{
|
||
if((!m_bNecessary) && m_strDefault=="" && m_strValue=="")
|
||
{
|
||
return false;
|
||
}
|
||
bool bOK = true;
|
||
switch(m_eType)
|
||
{
|
||
case ParmType_INT:
|
||
{
|
||
ValueToInt(&bOK);
|
||
}
|
||
break;
|
||
case ParmType_FLOAT:
|
||
{
|
||
ValueToFloat(&bOK);
|
||
}
|
||
break;
|
||
case ParmType_DOUBLE:
|
||
{
|
||
ValueToDouble(&bOK);
|
||
}
|
||
break;
|
||
case ParmType_LONG:
|
||
{
|
||
ValueToLong(&bOK);
|
||
}
|
||
break;
|
||
case ParmType_BOOL:
|
||
{
|
||
ValueToBool(&bOK);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return bOK;
|
||
}
|
||
|
||
bool CParameterItem::SameAsDefault()
|
||
{
|
||
if ((GetInputType() != HDFSFILEBROWSER) && (GetInputType() != HDFSFILEEDITOR))
|
||
{
|
||
return GetDefault() == GetStringValue() || GetInputType()==COMBOX;//ToDo 下一步,Combox需要特殊分析
|
||
}
|
||
return true;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
||
CCompositeParameterItem::CCompositeParameterItem()
|
||
:CParameterItem(),m_vecChildItems()
|
||
{
|
||
SetType(ParmType_CUSTOM);
|
||
SetInputType(NONEINPUT);
|
||
m_vecChildItems.reserve(10);
|
||
}
|
||
|
||
CCompositeParameterItem::~CCompositeParameterItem()
|
||
{
|
||
Clear();
|
||
}
|
||
|
||
void CCompositeParameterItem::Clear()
|
||
{
|
||
//释放所有子参数项的内存
|
||
for(size_t i=0; i<m_vecChildItems.size(); ++i)
|
||
{
|
||
delete m_vecChildItems[i];
|
||
m_vecChildItems[i] = NULL;
|
||
}
|
||
m_vecChildItems.clear();
|
||
}
|
||
|
||
CCompositeParameterItem::CCompositeParameterItem(const CCompositeParameterItem& src)
|
||
:CParameterItem(src),m_vecChildItems()
|
||
{
|
||
//拷贝所有子参数项
|
||
for(size_t i=0; i<src.m_vecChildItems.size(); ++i)
|
||
{
|
||
CParameterItem* pSrcChildItem = src.m_vecChildItems[i];
|
||
if(pSrcChildItem->GetType() == ParmType_CUSTOM || pSrcChildItem->GetType() == ParmType_ARRAY)
|
||
{
|
||
CCompositeParameterItem* pCompositeSrcChildItem = dynamic_cast<CCompositeParameterItem*>(pSrcChildItem);
|
||
_AddChildItem(new CCompositeParameterItem(*pCompositeSrcChildItem));
|
||
}
|
||
else
|
||
{
|
||
_AddChildItem(new CParameterItem(*pSrcChildItem));
|
||
}
|
||
//AddParameterItem(*(src.m_vecChildItems.at(i)));//这个函数将src中的某个子项拷贝一份,并且将拷贝值加入子参数项列表。(如果该子项也是CCompositeParameterItem类型的,会产生一个深拷贝,即递归进入本函数)
|
||
}
|
||
}
|
||
|
||
CCompositeParameterItem& CCompositeParameterItem::operator=(const CCompositeParameterItem& src)
|
||
{
|
||
Clear();
|
||
//拷贝所有子参数项
|
||
for(size_t i=0; i<src.m_vecChildItems.size(); ++i)
|
||
{
|
||
CParameterItem* pSrcChildItem = src.m_vecChildItems[i];
|
||
if(pSrcChildItem->GetType() == ParmType_CUSTOM || pSrcChildItem->GetType() == ParmType_ARRAY)
|
||
{
|
||
CCompositeParameterItem* pCompositeSrcChildItem = dynamic_cast<CCompositeParameterItem*>(pSrcChildItem);
|
||
_AddChildItem(new CCompositeParameterItem(*pCompositeSrcChildItem));
|
||
}
|
||
else
|
||
{
|
||
_AddChildItem(new CParameterItem(*pSrcChildItem));
|
||
}
|
||
//AddParameterItem(*(src.m_vecChildItems.at(i)));//这个函数将src中的某个子项拷贝一份,并且将拷贝值加入子参数项列表。(如果该子项也是CCompositeParameterItem类型的,会产生一个深拷贝,即递归进入本函数)
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
bool CCompositeParameterItem::operator==(const CCompositeParameterItem& otherItem) const
|
||
{
|
||
if(!CParameterItem::operator ==(otherItem))
|
||
{
|
||
return false;
|
||
}
|
||
if(GetChildCount()!=otherItem.GetChildCount())
|
||
{
|
||
return false;
|
||
}
|
||
//判断所有子参数项是否相等
|
||
for(size_t i=0; i<otherItem.m_vecChildItems.size(); ++i)
|
||
{
|
||
CParameterItem* pOtherChildItem = otherItem.m_vecChildItems[i];
|
||
|
||
if(pOtherChildItem->GetType() == ParmType_CUSTOM || pOtherChildItem->GetType() == ParmType_ARRAY)
|
||
{
|
||
CCompositeParameterItem* pCompositeOtherChildItem = dynamic_cast<CCompositeParameterItem*>(pOtherChildItem);
|
||
CCompositeParameterItem* pCompositeChildItem = dynamic_cast<CCompositeParameterItem*>(this->m_vecChildItems[i]);
|
||
if(!((*pCompositeOtherChildItem) == (*pCompositeChildItem)))
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(!((*pOtherChildItem) == (*(this->m_vecChildItems[i]))))
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
std::string CCompositeParameterItem::GetStringValue() const
|
||
{
|
||
return "";
|
||
}
|
||
|
||
void CCompositeParameterItem::AddParameterItem(const CParameterItem& childItem,bool bAmendID)
|
||
{
|
||
InsertParameterItem(-1, childItem, bAmendID);
|
||
}
|
||
|
||
void CCompositeParameterItem::InsertParameterItem(const int index,const CParameterItem& childItem,bool bAmendID)
|
||
{
|
||
if(GetParameterItem(childItem.GetId())!=NULL)
|
||
{
|
||
return;
|
||
}
|
||
if(childItem.GetType() == ParmType_CUSTOM || childItem.GetType() == ParmType_ARRAY)
|
||
{
|
||
const CCompositeParameterItem* pSrcChildItem = dynamic_cast<const CCompositeParameterItem*>(&childItem);
|
||
if(NULL != pSrcChildItem)
|
||
{
|
||
//如果该子项也是CCompositeParameterItem类型的,会产生一个对子项的深拷贝
|
||
CCompositeParameterItem* pCopiedChildItem = new CCompositeParameterItem(*pSrcChildItem);
|
||
_InsertItemAndAmendItemID(index,pCopiedChildItem,bAmendID);//将拷贝后的组合型子项加入子参数项列表并修改该组合型子项以及它所有后代的ID(目的是把父亲(this)的id也附加到子项及其后代的ID里)
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
std::cout << "Can not convert a CUSTOM parameter item to CCompositeParameterItem!" << std::endl;
|
||
}
|
||
}
|
||
CParameterItem* pCopiedChildItem = new CParameterItem(childItem);//对普通类型子项的拷贝
|
||
_InsertItemAndAmendItemID(index,pCopiedChildItem,bAmendID);//将拷贝后的普通类型子项加入子参数项列表并修改该普通类型子项的ID(目的是把父亲的id也附加到子项的ID里)
|
||
|
||
}
|
||
|
||
bool CCompositeParameterItem::RemoveParameterItem(const std::string& strItemID)
|
||
{
|
||
for(size_t i=0; i<m_vecChildItems.size(); ++i)
|
||
{
|
||
if(m_vecChildItems[i]->GetId() == strItemID)
|
||
{
|
||
delete m_vecChildItems[i];
|
||
m_vecChildItems[i] = NULL;
|
||
m_vecChildItems.erase(m_vecChildItems.begin() + ptrdiff_t(i));
|
||
if(IsArray())
|
||
{
|
||
for(size_t j= i; j<m_vecChildItems.size(); ++j)
|
||
{
|
||
_AmendChildItemID(m_vecChildItems.at(j),int(j));
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
CParameterItem* CCompositeParameterItem::GetParameterItem(const std::string& strItemID) const
|
||
{
|
||
if(std::string::npos == strItemID.rfind(".") && std::string::npos == strItemID.rfind("]"))
|
||
{
|
||
for(size_t i=0; i<m_vecChildItems.size(); ++i)
|
||
{
|
||
|
||
std::string strShortID = m_vecChildItems[i]->GetShortID();
|
||
|
||
if(strShortID == strItemID)
|
||
{
|
||
return m_vecChildItems[i];
|
||
}
|
||
}
|
||
return NULL;
|
||
}
|
||
else
|
||
{
|
||
if(GetId() == strItemID)
|
||
{
|
||
return const_cast<CCompositeParameterItem*>(this);
|
||
}
|
||
int count=m_vecChildItems.size();
|
||
for(int i=0; i<count; ++i)
|
||
{
|
||
if(m_vecChildItems[i]->GetId() == strItemID)
|
||
{
|
||
return m_vecChildItems[i];
|
||
}
|
||
if(m_vecChildItems[i]->GetType() == ParmType_CUSTOM || m_vecChildItems[i]->GetType() == ParmType_ARRAY)
|
||
{
|
||
CCompositeParameterItem* pChildItem = dynamic_cast<CCompositeParameterItem*>(m_vecChildItems[i]);
|
||
if(NULL != pChildItem)
|
||
{
|
||
CParameterItem* pResultItem = pChildItem->GetParameterItem(strItemID);
|
||
if(NULL != pResultItem)
|
||
{
|
||
return pResultItem;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
return NULL;
|
||
}
|
||
}
|
||
|
||
CParameterItem* CCompositeParameterItem::GetParameterItem(int iIndex) const
|
||
{
|
||
return *(m_vecChildItems.begin()+iIndex);
|
||
}
|
||
|
||
void CCompositeParameterItem::GetCategoryNames(std::vector<std::string>& vecCategoryNames)
|
||
{
|
||
std::set<std::string> categorySet;
|
||
for(std::vector<CParameterItem*>::const_iterator it = m_vecChildItems.begin(); it != m_vecChildItems.end(); ++it)
|
||
{
|
||
if(categorySet.find((*it)->GetCategory())==categorySet.end())
|
||
{
|
||
vecCategoryNames.push_back((*it)->GetCategory());
|
||
}
|
||
categorySet.insert((*it)->GetCategory());
|
||
}
|
||
|
||
}
|
||
|
||
std::vector<CParameterItem*> CCompositeParameterItem::GetParameterItemsByCategory(const std::string& strCategory) const
|
||
{
|
||
std::vector<CParameterItem*> vecItemsWithSameCategory;
|
||
std::vector<CParameterItem*>::const_iterator it;
|
||
for(it = m_vecChildItems.begin(); it != m_vecChildItems.end(); ++it)
|
||
{
|
||
if((*it)->GetCategory() == strCategory)
|
||
{
|
||
vecItemsWithSameCategory.push_back(*it);
|
||
}
|
||
}
|
||
return vecItemsWithSameCategory;
|
||
}
|
||
|
||
int CCompositeParameterItem::GetChildCount() const
|
||
{
|
||
return int(m_vecChildItems.size());
|
||
}
|
||
bool CCompositeParameterItem::IsArray() const
|
||
{
|
||
return GetType() == ParmType_ARRAY;
|
||
}
|
||
|
||
void CCompositeParameterItem::_InsertItemAndAmendItemID(const int index ,CParameterItem* pChildItem,bool bAmendID)
|
||
{
|
||
//插入到子参数项列表
|
||
pChildItem->SetParentItem(this);
|
||
if(index >= 0)
|
||
{
|
||
m_vecChildItems.insert(m_vecChildItems.begin()+index,pChildItem);
|
||
}
|
||
else
|
||
{
|
||
m_vecChildItems.push_back(pChildItem);
|
||
}
|
||
if(bAmendID)
|
||
{
|
||
// size_t curIndex = (index>=0)?size_t(index):(m_vecChildItems.size()-1);
|
||
// for(size_t i = curIndex; i< m_vecChildItems.size(); ++i)
|
||
int count=m_vecChildItems.size();
|
||
int curIndex = (index>=0)?index:count-1;
|
||
for(int i = curIndex; i< count; ++i)
|
||
{
|
||
_AmendChildItemID(m_vecChildItems.at(i),int(i));
|
||
}
|
||
}
|
||
}
|
||
|
||
void CCompositeParameterItem::_AddItemAndAmendItemID(CParameterItem* pChildItem,bool bAmendID)
|
||
{
|
||
_AddChildItem(pChildItem);
|
||
if(bAmendID)
|
||
{
|
||
_AmendChildItemID(pChildItem,GetChildCount()-1);
|
||
}
|
||
}
|
||
|
||
void CCompositeParameterItem::_AddChildItem(CParameterItem* pChildItem)
|
||
{
|
||
//加入到子参数项列表
|
||
pChildItem->SetParentItem(this);
|
||
m_vecChildItems.push_back(pChildItem);
|
||
}
|
||
|
||
void CCompositeParameterItem::_AmendChildItemID(CParameterItem* pChildItem, int iChildIndex)
|
||
{
|
||
assert(pChildItem != NULL);
|
||
|
||
std::string strThisID = GetId();
|
||
std::string strOldChildID = pChildItem->GetShortID();
|
||
std::string strNewChildID = pChildItem->GetId();
|
||
|
||
if(IsArray())//如果是数组类型的子项它的ID格式是父亲ID[索引]
|
||
{
|
||
char buf[100];
|
||
sprintf(buf,"%s[%d]",strThisID.c_str(),iChildIndex);
|
||
strNewChildID=buf;//strThisID+"["+_itoa(iChildIndex)+"]";
|
||
// std::stringstream ss;
|
||
// ss << strThisID;
|
||
// ss << "[";
|
||
// ss << iChildIndex;
|
||
// ss << "]";
|
||
// strNewChildID = ss.str();//重新赋予【n】类型的id
|
||
}
|
||
else
|
||
{
|
||
if(strThisID != "")
|
||
{
|
||
strNewChildID = strThisID +"."+ strOldChildID;//加上父亲ID
|
||
}
|
||
}
|
||
|
||
if(strNewChildID != strOldChildID)
|
||
{
|
||
pChildItem->SetId(strNewChildID);
|
||
|
||
if(pChildItem->GetType() == ParmType_CUSTOM || pChildItem->GetType() == ParmType_ARRAY)
|
||
{
|
||
CCompositeParameterItem* pCompositeChildItem = dynamic_cast<CCompositeParameterItem*>(pChildItem);
|
||
// assert(pCompositeChildItem != NULL);
|
||
int count=pCompositeChildItem->GetChildCount();
|
||
for(int i=0; i<count ; ++i)
|
||
{
|
||
pCompositeChildItem->_AmendChildItemID(pCompositeChildItem->GetParameterItem(i),i);//递归修改子项ID
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void CCompositeParameterItem::GetParameterItemsWithValidInputType(std::vector<CParameterItem*>& vecResultItems) const
|
||
{
|
||
//这个函数为界面收集具有合法输入控件(即不是NONEINPUT输入类型)的参数项
|
||
if(GetInputType() == NONEINPUT)
|
||
{
|
||
for(unsigned int i=0 ; i<m_vecChildItems.size(); ++i)
|
||
{
|
||
if(m_vecChildItems[i]->GetType() == ParmType_CUSTOM || m_vecChildItems[i]->GetType() == ParmType_ARRAY)
|
||
{
|
||
CCompositeParameterItem* pChildItem = dynamic_cast<CCompositeParameterItem*>(m_vecChildItems[i]);
|
||
if(NULL != pChildItem)
|
||
{
|
||
pChildItem->GetParameterItemsWithValidInputType(vecResultItems);//递归收集
|
||
}
|
||
}
|
||
else
|
||
{
|
||
vecResultItems.push_back(m_vecChildItems[i]);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
vecResultItems.push_back(const_cast<CCompositeParameterItem*>(this));
|
||
}
|
||
}
|
||
|
||
void CCompositeParameterItem::GetAllLeafParameterItems(std::vector<CParameterItem>& vecLeafItems) const
|
||
{
|
||
for(unsigned int i=0 ; i<m_vecChildItems.size(); ++i)
|
||
{
|
||
if(m_vecChildItems[i]->GetType() == ParmType_CUSTOM || m_vecChildItems[i]->GetType() == ParmType_ARRAY)
|
||
{
|
||
CCompositeParameterItem* pChildItem = dynamic_cast<CCompositeParameterItem*>(m_vecChildItems[i]);
|
||
if(NULL != pChildItem)
|
||
{
|
||
pChildItem->GetAllLeafParameterItems(vecLeafItems);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
std::string strLongID = m_vecChildItems[i]->GetId();
|
||
// std::cout << strLongID << std::endl;
|
||
CParameterItem leafItem(*(m_vecChildItems[i]));
|
||
leafItem.SetId(strLongID);
|
||
vecLeafItems.push_back(leafItem);
|
||
}
|
||
}
|
||
}
|
||
void CCompositeParameterItem::InitializeToShortIDs()
|
||
{
|
||
std::string strLongID = GetId();
|
||
size_t iLastPointPos = strLongID.rfind('.');
|
||
SetId(strLongID.substr(iLastPointPos+1));//设置短ID
|
||
int count=m_vecChildItems.size();
|
||
for(unsigned int i=0 ; i<count; ++i)
|
||
{
|
||
if(m_vecChildItems[i]->GetType() == ParmType_CUSTOM || m_vecChildItems[i]->GetType() == ParmType_ARRAY)
|
||
{
|
||
CCompositeParameterItem* pChildItem = dynamic_cast<CCompositeParameterItem*>(m_vecChildItems[i]);
|
||
|
||
if(NULL != pChildItem)
|
||
{
|
||
pChildItem->InitializeToShortIDs();//递归
|
||
}
|
||
if(IsArray())
|
||
{
|
||
m_vecChildItems[i]->SetId("");//对于数组项的子参数项,ID一律置为空
|
||
}
|
||
}
|
||
else
|
||
{
|
||
std::string strLongID_ = m_vecChildItems[i]->GetId();
|
||
size_t iLastPointPos_ = strLongID_.rfind('.');
|
||
m_vecChildItems[i]->SetId(strLongID_.substr(iLastPointPos_+1));//设置短ID
|
||
if(IsArray())
|
||
{
|
||
m_vecChildItems[i]->SetId("");//对于数组项的子参数项,ID一律置为空
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
bool CCompositeParameterItem::SameAsDefault()
|
||
{
|
||
int count=m_vecChildItems.size();
|
||
for(unsigned int i=0 ; i<count; ++i)
|
||
{
|
||
if(!m_vecChildItems[i]->SameAsDefault())
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
bool CCompositeParameterItem::IsReady(ParameterCompleteIndex& completeIndex) const
|
||
{
|
||
bool bReady =true;
|
||
int count=m_vecChildItems.size();
|
||
for(unsigned int i=0 ; i<count; ++i)
|
||
{
|
||
if(bReady)
|
||
{
|
||
if(m_vecChildItems[i]->GetType() == ParmType_CUSTOM || m_vecChildItems[i]->GetType() == ParmType_ARRAY)
|
||
{
|
||
CCompositeParameterItem* pChildItem = dynamic_cast<CCompositeParameterItem*>(m_vecChildItems[i]);
|
||
if(NULL != pChildItem)
|
||
{
|
||
if(!pChildItem->IsReady(completeIndex))
|
||
{
|
||
bReady = false;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
CParameterItem* pChildItem = m_vecChildItems[i];
|
||
if(NULL != pChildItem)
|
||
{
|
||
std::string strInvisible("Invisible;");
|
||
size_t nKeyPos = pChildItem->GetInputData().find(strInvisible);
|
||
if(pChildItem->IsNessary() && nKeyPos == std::string::npos && pChildItem->GetStringValue().empty())
|
||
{
|
||
completeIndex = ParamWarning;
|
||
bReady = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(completeIndex == ParamError)
|
||
{
|
||
return false;
|
||
}
|
||
/*
|
||
* ToDo
|
||
* 咨询过海东,最初的设计:上面的参数没有填写,修改了后边的参数,这种情况提示paramerror
|
||
* 现在为了解决defect30530添加completeIndex != ParamWarning判断,但是,这样修改后,
|
||
* 这个方法现在只能提示参数没有填写的情况
|
||
*
|
||
*/
|
||
if(completeIndex != ParamWarning && !m_vecChildItems[i]->SameAsDefault())
|
||
{
|
||
completeIndex = ParamError;
|
||
}
|
||
}
|
||
}
|
||
if (completeIndex != ParamError && bReady == false)
|
||
{
|
||
completeIndex = ParamWarning;
|
||
}
|
||
return bReady;
|
||
}
|
||
|
||
|
||
}
|
||
}
|