/* * ModuleParameter.cpp * * Created on: 2011-4-29 * Author: dev */ #include "ModuleParameter.h" #include "Algorithm.h" // #include "json/json.h" #include "Utils.h" // #include "Log.h" // #include "error.h" #include #include using namespace std; using namespace pai::utils; namespace pai { namespace module { CModuleParameter::CModuleParameter(): workflow_id(""), local_tmp_dir(""), hdfs_tmp_dir(""), m_rootParameterItem(), m_strClass(""), m_importPath("") { // TODO Auto-generated constructor stub } CModuleParameter::CModuleParameter(const CModuleParameter& srcParameter): workflow_id(srcParameter.workflow_id), local_tmp_dir(srcParameter.local_tmp_dir), hdfs_tmp_dir(srcParameter.hdfs_tmp_dir), m_rootParameterItem(srcParameter.m_rootParameterItem), m_strClass(srcParameter.m_strClass), m_importPath(srcParameter.m_importPath) { } CModuleParameter::~CModuleParameter() { // cout << "detor in ModuleParameter " << endl; } void CModuleParameter::Clone(const CModuleParameter& srcParameter) { if(&srcParameter != this) { workflow_id = srcParameter.workflow_id; local_tmp_dir = srcParameter.local_tmp_dir; hdfs_tmp_dir = srcParameter.hdfs_tmp_dir; m_rootParameterItem = srcParameter.m_rootParameterItem; //REMOVEME m_strClass = srcParameter.m_strClass; } } bool CModuleParameter::operator==(const CModuleParameter& otherParameter) const { if(m_rootParameterItem == otherParameter.m_rootParameterItem && local_tmp_dir == otherParameter.local_tmp_dir && hdfs_tmp_dir == otherParameter.hdfs_tmp_dir && workflow_id == otherParameter.workflow_id && m_strClass == otherParameter.m_strClass && m_importPath == otherParameter.m_importPath) { return true; } return false; } void CModuleParameter::AddParameterItem(const CParameterItem& item) { m_rootParameterItem.AddParameterItem(item); } void CModuleParameter::AddParameterItem(QString& paramId,const pai::module::ParameterType paramType,const std::string& paramStringValue) { CParameterItem paramItem ; paramItem.SetId(paramId.toStdString()); paramItem.SetName(paramId); paramItem.SetType(paramType); paramItem.SetStringValue(paramStringValue); this->AddParameterItem(paramItem); } void CModuleParameter::AddParameterItem(const std::string& paramId,const pai::module::ParameterType paramType,const std::string& paramStringValue) { CParameterItem paramItem ; paramItem.SetId(paramId); paramItem.SetName(paramId); paramItem.SetType(paramType); paramItem.SetStringValue(paramStringValue); this->AddParameterItem(paramItem); } void CModuleParameter::RemoveParameterItem(const std::string& paramId) { m_rootParameterItem.RemoveParameterItem(paramId); } CParameterItem* CModuleParameter::GetParameterItem(const std::string& strItemName) { return m_rootParameterItem.GetParameterItem(strItemName); } int CModuleParameter::GetParameterItemCount() const { return m_rootParameterItem.GetChildCount(); } int CModuleParameter::GetParamItemIndex(const std::string& strItemName) const { for(int i=0; i< m_rootParameterItem.GetChildCount(); ++i) { CParameterItem* pItem = m_rootParameterItem.GetParameterItem(i); if(pItem!=NULL && pItem->GetName().toStdString()==strItemName) { return i; } } std::stringstream errorMsg; errorMsg <<"\n\t "<< __FILE__ << ":" << __LINE__<< "\t the warn information:" << std::endl << "\t The child parameter named "< CModuleParameter::GetParameterItems() const { std::vector vecResultItems; // for(int i=0; i< m_rootParameterItem.GetChildCount(); ++i) // { // CParameterItem* pItem = m_rootParameterItem.GetParameterItem(i); // if(pItem->GetType() == CUSTOM) // { // CCompositeParameterItem* pChildItem = dynamic_cast(pItem); // if(pChildItem != NULL) // { // CParameterItem* pConvertedItem = CCompositeParameterItem::ConvergentToCParameterItemAsNewInstance(pChildItem); // vecResultItems.push_back(*(pConvertedItem)); // delete pConvertedItem; // pConvertedItem=NULL; // } // } // else // { // vecResultItems.push_back(*(pItem)); // } // } m_rootParameterItem.GetAllLeafParameterItems(vecResultItems); return vecResultItems; } void CModuleParameter::GetCategoryNames(std::vector& vecCategoryNames) { m_rootParameterItem.GetCategoryNames(vecCategoryNames); } std::vector CModuleParameter::GetParameterItemsByCategory(const std::string& strCategory) const { return m_rootParameterItem.GetParameterItemsByCategory(strCategory); } CCompositeParameterItem* CModuleParameter::GetRootParameterItem() const { return const_cast(&m_rootParameterItem); } // void CModuleParameter::LoadFromJson(const Json::Value& root,bool bAmendID) // { // Json::Value vParams = root["Params"]; // if(!vParams.isNull()) // { // //TODO:test // //pModuleParam = new CModuleParameter(); // for(unsigned int i=0; iGetRootParameterItem(),bAmendID); // } // } // } // void CModuleParameter::SaveToJson(Json::Value& root) // { // Json::Value vParams; // CCompositeParameterItem* pParentItem = this->GetRootParameterItem(); // if (NULL == pParentItem) // { // std::stringstream errorMsg; // errorMsg <<"\n\t "<< __FILE__ << ":" << __LINE__<< "\t the error information:" << std::endl // << "\t CModuleParameter SaveToJson() save json error!"<< std::endl // << "\t The pParentItem is NULL"<GetChildCount(); i++) // { // Json::Value vParam; // _SaveToJson(vParam,pParentItem->GetParameterItem(i)); // vParams.append(vParam); // } // root["Params"] = vParams; // } // void CModuleParameter::_LoadFromJson(const Json::Value& paramJsonNode, CCompositeParameterItem* pParentItem,bool bAmendID) // { // if(pParentItem == NULL) // { // std::stringstream errorMsg; // errorMsg <<"\n\t "<< __FILE__ << ":" << __LINE__<< "\t the error information:" << std::endl // << "\t CModuleParameter _LoadFromJson() load json error!"<< std::endl // << "\t The pParentItem is NULL"<SetType(pItem->GetTypeMap()[strType]); // } // if(pItem == NULL) // { // std::stringstream errorMsg; // errorMsg <<"\n\t "<< __FILE__ << ":" << __LINE__<< "\t the error information:" << std::endl // << "\t CModuleParameter _LoadFromJson() save json error!"<< std::endl // << "\t The pItem is NULL"< vecAcceptDropTypes; // SplitByChar(strDropTypes,';',vecAcceptDropTypes); // for(size_t i=0; i(pItem),bAmendID); // } // } // pParentItem->AddParameterItem(parameterItem,bAmendID); // delete pItem; // pItem = NULL; // } // void CModuleParameter::_SaveToJson(Json::Value& paramJsonNode, CParameterItem* pItem) // { // if(pItem == NULL) // { // std::stringstream errorMsg; // errorMsg <<"\n\t "<< __FILE__ << ":" << __LINE__<< "\t the error information:" << std::endl // << "\t CModuleParameter _SaveToJson() save json error!"<< std::endl // << "\t The pItem is NULL"<GetType(); // std::string strParameterType = MapValueToKey >(pItem->GetTypeMap(),eParameterType); // paramJsonNode["ParameterType"] = strParameterType; // paramJsonNode["Default"] = pItem->GetDefault(); // paramJsonNode["ParameterID"] = pItem->GetId(); // paramJsonNode["ParameterName"] = pItem->GetName().toStdString(); // paramJsonNode["Value"] = pItem->GetStringValue(); // std::string strParameterInputType = MapValueToKey >(pItem->GetInputTypeMap(),pItem->GetInputType()); // paramJsonNode["ParameterInputType"] = strParameterInputType; // std::vector vecAcceptDropTypes = pItem->GetAcceptDropTypes(); // std::string strAcceptDropTypes(""); // std::map allAcceptDropTypes = pItem->GetAcceptDropTypeMap(); // for(size_t i=0; i >(allAcceptDropTypes,vecAcceptDropTypes[i]); // strAcceptDropTypes += ";"; // } // paramJsonNode["ParameterAcceptDropTypes"] = strAcceptDropTypes; // paramJsonNode["ParameterInputType"] = strParameterInputType; // paramJsonNode["ParameterInputMetaData"] = pItem->GetInputMetaData(); // paramJsonNode["ParameterInputData"] = pItem->GetInputData(); // paramJsonNode["ParameterSet"] = pItem->GetCategory(); // paramJsonNode["UpLimit"] = pItem->GetMax(); // paramJsonNode["LowerLimit"] = pItem->GetMin(); // paramJsonNode["Optional"] = pItem->IsNessary()?"false":"true"; // paramJsonNode["ParameterDesc"] = pItem->GetDescription(); // paramJsonNode["InOut"] = pItem->GetInOut(); // paramJsonNode["DataType"] = pItem->GetDataType(); // paramJsonNode["DisplayValue"] = pItem->GetDisplayValue(); // if(eParameterType == ARRAY || eParameterType == CUSTOM) // { // Json::Value vParams; // CCompositeParameterItem* pCompositeItem = dynamic_cast(pItem); // if(pCompositeItem == NULL) // { // std::stringstream errorMsg; // errorMsg <<"\n\t "<< __FILE__ << ":" << __LINE__<< "\t the error information:" << std::endl // << "\t CModuleParameter _SaveToJson() save json error!"<< std::endl // << "\t The pCompositeItem is NULL"<GetChildCount(); i++) // { // Json::Value vParam; // _SaveToJson(vParam,pCompositeItem->GetParameterItem(i)); // vParams.append(vParam); // } // paramJsonNode["Params"] = vParams; // } // } // void CModuleParameter::Print() // { // Json::Value root; // this->SaveToJson(root); // string str = root.toStyledString(); // cout << str << endl; // } bool CModuleParameter::IsReady(ParameterCompleteIndex& completeIndex) const { return m_rootParameterItem.IsReady(completeIndex); } void CModuleParameter::SetImportPath(std::string importPath) { m_importPath = importPath; } } }