void COptionTreeWrapper::CreateFileItem(CHashString compName, ViewFormatObject *obj, COptionTreeItem* root)
{
	IFileViewObject *fileObject = dynamic_cast<IFileViewObject*>(obj);

	if(fileObject == NULL)
	{
		StdString error = _T("Could not cast to a CFileViewObject");
		::MessageBox(NULL, error, _T("Invalid Operaton"), MB_OK);
		return;
	}

	StdString type = fileObject->GetBasicType();
	StdString name = fileObject->GetName();

	StdString fileName = fileObject->GetDefFile();
	StdString defExt = fileObject->GetDefExt();
	StdString extFilter = fileObject->GetExtFilter();

	COptionTreeItemFile *otiFile;
	otiFile = (COptionTreeItemFile*)m_mTrees[compName.GetUniqueID()].m_Tree->InsertItem( new COptionTreeItemFile(), root );
	otiFile->SetLabelText(name.c_str());
	otiFile->SetInfoText(_T(""));

	otiFile->CreateFileItem((const TCHAR*)fileName,
							defExt.c_str(),
							extFilter.c_str(),
							OT_FILE_OPENDIALOG | OT_FILE_SHOWFULLPATH,
							OFN_OVERWRITEPROMPT);

}
void CDetailObject::Serialize( IArchive &ar )
{
	StdString temp;
	if(ar.IsReading())
	{
		ar.Read(temp, "LayerLink");
		m_LayerLink = temp.c_str();
		ar.Read(temp, "ModelName");
		m_ModelName = temp.c_str();
		ar.Read(m_XCoverage, "XCoverage");
		ar.Read(m_YCoverage, "YCoverage");
		ar.Read(m_XRandomness, "XRandomness");
		ar.Read(m_YRandomness, "YRandomness");
		ar.Read(m_MinScale, "MinScale");
		ar.Read(m_MinScale, "MaxScale");
		ar.Read(m_MinYaw, "MinYaw");
		ar.Read(m_MaxYaw, "MaxYaw");
	}
	else
	{
		ar.Write(m_LayerLink.GetString(), "LayerLink");
		ar.Write(m_ModelName.GetString(), "ModelName");
		ar.Write(m_XCoverage, "XCoverage");
		ar.Write(m_YCoverage, "YCoverage");
		ar.Write(m_XRandomness, "XRandomness");
		ar.Write(m_YRandomness, "YRandomness");
		ar.Write(m_MinScale, "MinScale");
		ar.Write(m_MinScale, "MaxScale");
		ar.Write(m_MinYaw, "MinYaw");
		ar.Write(m_MaxYaw, "MaxYaw");
	}
}
void CWorldEventToolPal::UpdateWorldEventTrigger( void )
{
	static DWORD msgHash_FindObject = CHashString(_T("FindObject")).GetUniqueID();
	static DWORD msgHash_GetComponentType = CHashString(_T("GetComponentType")).GetUniqueID();
	static DWORD msgHash_CreateArchive = CHashString(_T("CreateArchive")).GetUniqueID();
	static DWORD msgHash_SerializeObject = CHashString(_T("SerializeObject")).GetUniqueID();

	static CHashString Hash_Type = CHashString(_T("CWorldEventTrigger"));

	CString buf;
	m_Name.GetLBText(m_Name.GetCurSel(), buf);
	CHashString hszName((TCHAR*)buf.GetBuffer());
	FINDOBJECTPARAMS param;
	param.hszName = &hszName;
	DWORD result = m_ToolBox->SendMessage(msgHash_FindObject, sizeof(FINDOBJECTPARAMS), &param);

	// object exists 
	if( param.bFound == true )
	{
		GETCOMPONENTTYPEPARAMS gctp;
		gctp.name = &hszName;
		m_ToolBox->SendMessage(msgHash_GetComponentType, sizeof(gctp), &gctp);

		// it is a world event, get values from it
		if ( (gctp.componenttype != NULL) && (gctp.componenttype->GetUniqueID() == Hash_Type.GetUniqueID()) )
		{
			CREATEARCHIVE ca;
			CHashString streamType(_T("Memory"));
			ca.streamData = NULL;
			ca.mode = STREAM_MODE_WRITE | STREAM_MODE_READ;
			ca.streamType = &streamType;
	 	
			m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &ca, NULL, NULL);
			IArchive *MemArchive = (ca.archive);

			MemArchive->SetIsWriting(true);
			MemArchive->SeekTo(0);

			SERIALIZEOBJECTPARAMS sop;
			sop.name = &hszName;
			sop.archive = MemArchive;
			m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sop, NULL, NULL);

			MemArchive->SetIsWriting(false);
			MemArchive->SeekTo(0);

			StdString tmp;
			MemArchive->Read( tmp );
			m_EntityName.SetWindowText( tmp.c_str() );
			MemArchive->Read( tmp );
			m_EntityType.SetWindowText( tmp.c_str() );
			MemArchive->Read( tmp );
			m_EventName.SetWindowText( tmp.c_str() );
			
			MemArchive->Close();
		}
	}
}
bool CEntityManager::CompareNames(StdString searchString, StdString compString)
{
	static StdString token(_T("\\"));
	size_t subLen;
	// if searchString is null, positive match w/ everything
	if(_tcscmp(searchString, _T("")) == 0)
	{
		return true;
	}
	// if compString is null, no match
	if(_tcscmp(compString, _T("")) == 0)
	{
		return false;
	}
	const TCHAR* searchStringArray = searchString.c_str();
	const TCHAR* compStringArray = compString.c_str();

	while( _tcscmp(searchStringArray, _T("")) != 0 )
	{
		subLen = _tcscspn(compStringArray, token); //length of substring to token

		if (subLen > 0)
		{
			// compare substrings up to token 
			if( _tcsncmp(searchStringArray, compStringArray, subLen) == 0 )
			{
				return true;
			}

			// now check if compString's substring's next char is == token 
			if( compStringArray[subLen] != token.c_str()[0] )
			{
				// did not return above, therefore does not match
				return false;			
			}		

			// continue...advance ptr
			compStringArray = _tcsninc(compStringArray, subLen+1);
		}
		else
		{
			// string out
			return false;
		}
	}
	// if exited while loop..then true
	return true;
}
void COptionTreeWrapper::SerializeRadioItem(IArchive &ar, COptionTreeItem *item, bool read)
{
	StdString szVal;
	COptionTreeItemRadio *otiRadio;
	OT_RADIO_NODE *node;
	int index;

	otiRadio = dynamic_cast<COptionTreeItemRadio*>(item);
	if (item == NULL)
	{
		//error
		StdString error = _T("Could not cast item to COptionTreeItemRadio: ");
		error += item->GetLabelText();
		::MessageBox(NULL, error, _T("Invalid Command"), MB_OK);
		return;
	}
	if (read)
	{
		ar.Read(szVal);
		node = otiRadio->Node_FindNode(szVal.c_str());
		if (node != NULL)
		{	
			otiRadio->Node_UnCheckAll();
			node->m_bChecked = true;
		}	
	}
	else
	{
		index = otiRadio->Node_GetChecked();
		node = otiRadio->Node_FindNode(index);
		ar.Write(node->m_strText);
	}
}
Example #6
0
StdString HashSHA1Impl::GetFileHash(StdString strFile)
{
	StdString strRet;

	HANDLE hFile = CreateFile(strFile.c_str(), GENERIC_READ, FILE_SHARE_READ,
		NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile != INVALID_HANDLE_VALUE)
	{
		HANDLE hMapping = CreateFileMapping(hFile, NULL, PAGE_WRITECOPY, 0, 0, NULL);
		if (hMapping != INVALID_HANDLE_VALUE)
		{
			PBYTE pByte = (PBYTE)MapViewOfFile(hMapping, FILE_MAP_COPY, 0, 0, 0);
			unsigned long dwSize = GetFileSize(hFile, NULL);			
			
			Reset();
			Input(pByte, dwSize);
			unsigned int digest[5] = {0};
			Result(digest);
			TCHAR szRes[48] = _T("");
			_sntprintf_s(szRes, 48, 48, _T("%x%x%x%x%x"),
				digest[0], digest[1], digest[2], digest[3], digest[4]);
			strRet = szRes;

			UnmapViewOfFile(pByte);
			CloseHandle(hMapping);
		}
		else
		{
			CloseHandle(hFile);
		}
	}
	return strRet;
}
void COptionTreeWrapper::SerializeEditItemString(IArchive &ar, COptionTreeItem *item, bool read)
{	
	StdString szString;
	COptionTreeItemEdit *otiEdit;
	
	CString szItem;
	otiEdit = dynamic_cast<COptionTreeItemEdit*>(item);
	if(otiEdit == NULL)
	{
		//error
		StdString error = _T("Could not cast item to COptionTreeItemEdit: ");
		error += item->GetLabelText();
		::MessageBox(NULL, error, _T("Invalid Command"), MB_OK);
		return;
	}

	otiEdit->CreateEditItem(0, NULL);

	if (read)
	{
		ar.Read(szString);
		otiEdit->SetEditText(szString.c_str());
	}
	else
	{
		otiEdit->GetWindowText(szItem);
		ar.Write(szItem);
	}
}
Example #8
0
DWORD CGUIItem::CheckMouseState(float mouseX, float mouseY, MOUSESTATE mouseState, 
							   float x, float y, float width, float height, DWORD dwLastState)
{ 
	DWORD btState;
	if (mouseState == MOUSE_OPEN)
	{
		m_pVisItem->MouseOver(mouseX, mouseY, x, y, width, height, &btState);
		return btState;
	}
	else if (mouseState == MOUSE_LEFTPRESSED)
	{
		m_pVisItem->MouseButton(mouseX, mouseY, true, false, x, y, width, height, &btState);
		return btState;
	}
	else if (mouseState == MOUSE_LEFTRELEASED)
	{
		if ( m_pVisItem->MouseButton(mouseX, mouseY, false, true, x, y, width, height, &btState) )
		{
			StdString eventName = _T("RELEASED_");
			eventName += GetName()->GetString();
			CHashString eName(eventName.c_str());
		
			GUIEVENT ge;
			ge.event = eName.GetUniqueID();
			ge.ar = NULL;
			static DWORD msgHash_QueueGUIStateEvent = CHashString(_T("QueueGUIStateEvent")).GetUniqueID();
			m_ToolBox->SendMessage(msgHash_QueueGUIStateEvent, sizeof(GUIEVENT), &ge);
		}
		return btState;
	}
	return 0; 
}
void COptionTreeWrapper::SerializeStaticItemString(IArchive &ar, COptionTreeItem *item, bool read)
{
	StdString szString;
	COptionTreeItemStatic *otiStatic = dynamic_cast<COptionTreeItemStatic*>(item);

	CString szItem;
	if(otiStatic == NULL)
	{
		//error
		StdString error = _T("Could not cast item to COptionTreeItemStatic: ");
		error += item->GetLabelText();
		::MessageBox(NULL, error, _T("Invalid Command"), MB_OK);
		return;
	}
	if(read)
	{
		ar.Read(szString);
		otiStatic->SetStaticText(szString.c_str());
	}
	else
	{
		szItem = otiStatic->GetStaticText();
		ar.Write(szItem);
	}
}
Example #10
0
void CSchemaItem::DBReadString( DATABASEDATA *value, IArchive *ar, const TCHAR *tag )
{
	value->type = DBTYPE_STRING;
	StdString szReadString;
	ar->Read( szReadString );

	value->AssignString( (TCHAR *)szReadString.c_str(), _tcslen(szReadString) );
}
DWORD CInputManager::OnLoadKeyBinding(DWORD msgSize, void *param)
{
	IHashString *szhFileName;
	VERIFY_MESSAGE_SIZE(msgSize, sizeof(IHashString*));
	szhFileName = (IHashString*)param;
	StdString szNodeName;
	
	IXMLArchive *Archive;
	CHashString streamType(_T("File"));
	CREATEARCHIVE ca;
	DWORD retVal = MSG_NOT_HANDLED;
	
	ca.streamData = (void*)szhFileName->GetString();
	ca.mode = STREAM_MODE_READ;
	ca.streamType = &streamType;

	// call the Archive factory to create an XML archive
	static DWORD msgHash_CreateXMLArchive = CHashString(_T("CreateXMLArchive")).GetUniqueID();
	if (retVal = m_ToolBox->SendMessage(msgHash_CreateXMLArchive, sizeof(CREATEARCHIVE), &ca) != MSG_HANDLED)
	{
		//log error
		m_ToolBox->SetErrorValue(WARN_INVALID_OPERATION);
		m_ToolBox->Log(LOGWARNING, _T("CInputManager: Could not create archive from: %s\n"), szhFileName->GetString());
		return MSG_NOT_HANDLED;
	}

	Archive = dynamic_cast<IXMLArchive *>(ca.archive);
	int num;
	CHashString curKeyBind(_T(""));
	StdString keybindName;
	StdString parentType;
	StdString childType;
	StdString msg;
	int		  key;
	bool	  hitOnce;

	Archive->GetNode(szNodeName);
	Archive->Read(keybindName, _T("name"));
	Archive->Read(num, _T("num"));
	
	curKeyBind = keybindName.c_str();
	
	while (num != 0)
	{
		Archive->Read( msg, _T("msg") );
		Archive->Read( key, _T("key") );
		Archive->Read( hitOnce, _T("hitOnce") );
        //Add Entry to page			
		CHashString szMessage(msg);
		KEYBINDINGMAP &curPage = m_KeyMap[ curKeyBind.GetUniqueID() ];
		curPage[ key ].msg = szMessage.GetUniqueID();
		curPage[ key ].hitOnce = hitOnce;
		num--;
	}

	Archive->Close();
	return MSG_HANDLED_STOP;
}
void COptionTreeWrapper::CreateRadioItem(CHashString compName, ViewFormatObject *obj, COptionTreeItem* root)
{
	IRadioViewObject *radioObject = dynamic_cast<IRadioViewObject*>(obj);

	if(radioObject == NULL)
	{
		StdString error = _T("Could not cast to a CRadioViewObject");
		::MessageBox(NULL, error, _T("Invalid Operaton"), MB_OK);
		return;
	}

	StdString type = radioObject->GetBasicType();
	StdString name = radioObject->GetName();
	RADIOLIST *radioList = radioObject->GetRadioList();
	StdString defSelect = radioObject->GetDefSelect();
	StdString text;
	bool checked;

	// Create COptionTreeItem
	COptionTreeItemRadio *otiRadio;
	otiRadio = (COptionTreeItemRadio*)m_mTrees[compName.GetUniqueID()].m_Tree->InsertItem(new COptionTreeItemRadio(), root);
	otiRadio->SetLabelText(name.c_str());
	otiRadio->SetInfoText(_T(""));
	otiRadio->CreateRadioItem();
	
	if(radioList->size() > 0)
	{
		RADIOLIST::iterator rlIter = radioList->begin();
		for(; rlIter != radioList->end(); rlIter++)
		{
			text = (*rlIter);
			if ( _tcscmp(text, defSelect) == 0 )
			{
				checked = true;
			}
			else
			{
				checked = false;
			}
			otiRadio->InsertNewRadio(text.c_str(), checked);
		}
	}
}
/// \brief	message handler to create zipped memory stream
/// \param	size - size of LPCTSTR
/// \param	param - pointer to string with path
/// \return	EE message return code
DWORD CZLibStreamFactory::OnAddZipFile(DWORD size, void *param)
{
	VERIFY_MESSAGE_SIZE(size, sizeof(LPCTSTR));
	StdString sPath = static_cast<LPCTSTR>(param);
	sPath.MakeSafeFileName();
	//sPath.ConformSlashesForward();
	if (!CZipFileStream::AddSearchPath(sPath.c_str()))
	{
		return MSG_ERROR;
	}
	return MSG_HANDLED_STOP;
}
void COptionTreeWrapper::CreateComboItem(CHashString compName, ViewFormatObject *obj, COptionTreeItem* root)
{
	IComboViewObject *comboObject = dynamic_cast<IComboViewObject*>(obj);

	if(comboObject == NULL)
	{
		StdString error = _T("Could not cast to a CComboViewObject");
		::MessageBox(NULL, error, _T("Invalid Operaton"), MB_OK);
		return;
	}

	int index;
	StdString type = comboObject->GetBasicType();
	StdString name = comboObject->GetName();
	StdString defSelect = comboObject->GetDefSelect();

	// create COptionTreeItem
	COptionTreeItemComboBox *otiCombo;
	COMBOLIST *comboList;
	comboList = comboObject->GetComboList();

	otiCombo = (COptionTreeItemComboBox*)m_mTrees[compName.GetUniqueID()].m_Tree->InsertItem(new COptionTreeItemComboBox(), root);
	otiCombo->SetLabelText(name.c_str());
	if (otiCombo->CreateComboItem(CBS_SORT) == TRUE)
	{
		// if we got some options
		if (comboList->size() > 0)
		{
			COMBOLIST::iterator clIter = comboList->begin();
			// throw them in the combo box
			for (; clIter != comboList->end(); clIter++)
			{
				otiCombo->AddString( (*clIter).c_str() );
			}
		}
	}

	index = otiCombo->FindStringExact(0, defSelect.c_str());
	otiCombo->SetCurSel((index >= 0) ? index : 0);
}
/// \brief	Populate the LINKMAP from an XML file
/// \param	fileName - The name of the XML file to load
void CEditorManager::LoadLinkMap( StdString &fileName )
{
	CREATEARCHIVE ca;
	IXMLArchive *ar;
	IToolBox *toolBox = EngineGetToolBox();

	StdString elementName;
	StdString source;
	StdString dest;

	CHashString streamType(_T("File"));

	ca.streamData = (void*)(fileName.c_str());
	ca.mode = STREAM_MODE_READ;
	ca.streamType = &streamType;

	// Try opening the archive
	static DWORD msgHash_CreateXMLArchive = CHashString(_T("CreateXMLArchive")).GetUniqueID();
	if (toolBox->SendMessage(msgHash_CreateXMLArchive, sizeof(CREATEARCHIVE), &ca) != MSG_HANDLED) 
	{ 
		std::string szText; 
		szText = "Failed to load xml format file: "; 
		szText += fileName; 
		::MessageBox(NULL, szText.c_str(), "Warning!", MB_OK|MB_ICONEXCLAMATION); 
	}

	// Start reading from the archive
	ar = dynamic_cast<IXMLArchive *>(ca.archive);

	// skip the header info
	ar->GetNode(elementName);

	while (ar->GetNode(elementName))
	{
		if (elementName == _T("Link"))
		{
			ar->Read(source);
			ar->Read(dest);
			CHashString hashSrc(source);
			CHashString hashDest(dest);
			m_LinkMap.insert( LINKPAIR(hashDest.GetUniqueID(), hashSrc.GetUniqueID() ) );
		}
	}

	ar->Close();
}
/*!
This function makes a request to netcdf with a id of a prent groupd and then return id of the created group, given its name
\param [in] parentNcid Id of parent groupd(or File Id)
\param [in] grpName Name of the desired group
\param [in/out] grpId Group id if this group is created sucessfully
\return Status code
*/
int CNetCdfInterface::defGrp(int parentNcid, const StdString& grpName, int& grpId)
{
  int status = nc_def_grp(parentNcid, grpName.c_str(), &grpId);
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;

    sstr << "Error when calling function nc_def_grp(parentNcid, grpName.c_str(), &grpId)" << std::endl;
    sstr << errormsg << std::endl;
    sstr << "Unable to create group Id, given its name: " << grpName << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
/*!
This function makes a request to netcdf with ncid and variable name then return ncid of the named variable
\param [in] ncid Groupd id (or File Id)
\param [in] varName Name of the desired variable
\param [in/out] varId Variable id if this variable is found
\return Status code
*/
int CNetCdfInterface::inqVarId(int ncid, const StdString& varName, int& varId)
{
  int status = nc_inq_varid(ncid, varName.c_str(), &varId);
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;

    sstr << "Error when calling function: nc_inq_varid(ncid, varName.c_str(), &varId)" << std::endl
         << (errormsg) << std::endl
         << "Unable to get id of variable with name: " << varName << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
/*!
This function opens a netcdf file, given its name and open mode, return its id
\param [in] fileName Name of the file
\param [in] oMode open mode
\param [in/out] ncId id of the opening file
\return Status code
*/
int CNetCdfInterface::open(const StdString& fileName, int oMode, int& ncId)
{
  int status = nc_open(fileName.c_str(), oMode, &ncId);
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;
    sstr << "Error when calling function: nc_open(fileName.c_str(), oMode, &ncId) "<< std::endl
         << errormsg << std::endl
         << "Unable to open file, given its name: " << fileName
         << "and its open mode " << openMode2String(oMode) << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
/*!
This function creates a new netcdf file on parallel file system
\param [in] fileName Name of the file
\param [in] cMode create mode
\param [in] comm MPI communicator
\param [in] info MPI information
\param [in/out] ncId id of the created file
\return Status code
*/
int CNetCdfInterface::createPar(const StdString& fileName, int cMode, MPI_Comm comm, MPI_Info info, int& ncId)
{
  int status = xios::nc_create_par(fileName.c_str(), cMode, comm, MPI_INFO_NULL.mpi_info, &ncId);
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;
    sstr << "Error when calling function: nc_create_par(fileName.c_str(), cMode, comm, info, &ncId) " << std::endl
         << errormsg << std::endl
         << "Unable to create file on parallel file system, given its name: " << std::endl
         << "and its creation mode " << creationMode2String(cMode) << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
/*!
This function queries the type and the size of an attribute given its name and the id of the variable to which it is attached.
\param [in] ncid Groupd id (or File Id)
\param [in] varid the id of the variable to which the attribute is attached
\param [in] name the name of the attribute
\param [out] type the type of the attribute
\param [out] len the size of the attribute
\return Status code
*/
int CNetCdfInterface::inqAtt(int ncid, int varid, const StdString& name, nc_type& type, size_t& len)
{
  int status = nc_inq_att(ncid, varid, name.c_str(), &type, &len);
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;

    sstr << "Error when calling function nc_inq_att(ncid, varid, name.c_str(), &type, &len)" << std::endl;
    sstr << errormsg << std::endl;
    sstr << "Unable to query the attribute information given its name: " << name << " and its variable id:" << varid << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
/*!
This function makes a request to netcdf with a netCdf dimension name then return ncid of the named dimension
\param [in] ncid Groupd id (or File Id)
\param [in] dimName Name of the desired dimension
\param [in/out] dimId Dimension id if this dimension is found
\return Status code
*/
int CNetCdfInterface::inqDimId(int ncid, const StdString& dimName, int& dimId)
{
  int status = nc_inq_dimid(ncid, dimName.c_str(), &dimId);
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;

    sstr << "Error when calling function nc_inq_dimid(ncid, dimName.c_str(), &dimId)" << std::endl
         << errormsg << std::endl
         << "Unable to get id of dimension, given its name: " << dimName << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
/*!
This function makes a request to netcdf with ncid and group name then return ncid of the named group
\param [in] ncid Groupd id (or File Id)
\param [in] grpName Name of the desired group (or file)
\param [in/out] grpId Group id if the group is found
\return Status code
*/
int CNetCdfInterface::inqNcId(int ncid, const StdString& grpName, int& grpId)
{
  int status = nc_inq_ncid(ncid, grpName.c_str(), &grpId);
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;

    sstr << "Error when calling function nc_inq_ncid(ncid, grpName.c_str(), &grpId)" << std::endl
         << errormsg << std::endl
         << "Unable to get id of a group (File), given its name: " << grpName << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
/*!
This function makes a request to netcdf, add a new dimension to an open netcdf in define mode
\param [in] ncid Id of groupd(or File Id)
\param [in] dimName Name of the desired dimension
\param [in/out] grpId Group id if this group is created sucessfully
\return Status code
*/
int CNetCdfInterface::defDim(int ncid, const StdString& dimName, StdSize dimLen, int& dimId)
{
  int status = nc_def_dim(ncid, dimName.c_str(), dimLen, &dimId);
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;

    sstr << "Error when calling function nc_def_dim(ncid, dimName.c_str(), dimLen, &dimId)" << std::endl;
    sstr << errormsg << std::endl;
    sstr << "Unable to create dimension with name: " << dimName
         << " and with length " << dimLen << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
/// message handler to check if a file exists
/// \param size - size of a CHECKFILEEXISTS
/// \param param - pointer to a CHECKFILEEXISTS struct
/// \return MSG_XXX return value
DWORD CZLibStreamFactory::OnCheckFileExists(DWORD size, void *param)
{
	VERIFY_MESSAGE_SIZE(size, sizeof(CHECKFILEEXISTS));
	CHECKFILEEXISTS &cfe = *(CHECKFILEEXISTS*)param;

	StdString sPath = cfe.pFilePath;
	sPath.MakeSafeFileName();
	sPath.ConformSlashesForward();

	if( CZipFileStream::CheckFileExist( sPath.c_str() ) )
	{
		cfe.bExists = true;
		return MSG_HANDLED_STOP;
	}
	
	cfe.bExists = false;
	return MSG_HANDLED_PROCEED;
}
bool CQHStateMachineManager::AddStateMachine( IHashString *afileName )
{
	bool areturn = false;
	if( afileName != NULL && 
		afileName->GetString() != NULL &&
		!afileName->IsEmpty() )
	{
		StdString file = afileName->GetString();
		file.MakeSafeFileName();
		LOADFILEEXTPARAMS lfep;
		lfep.fileName = (TCHAR*)file.c_str();
		lfep.bInternalLoad = true;

		static DWORD msgHash_LoadFileByExtension = CHashString(_T("LoadFileByExtension")).GetUniqueID();
		DWORD retVal = m_ToolBox->SendMessage(msgHash_LoadFileByExtension, sizeof(LOADFILEEXTPARAMS), &lfep);
	}

	return areturn;
}
void COptionTreeWrapper::CreateEditItem(CHashString compName, ViewFormatObject *obj, COptionTreeItem* root)
{
	IEditViewObject *editObject = dynamic_cast<IEditViewObject*>(obj);

	if(editObject == NULL)
	{
		StdString error = _T("Could not cast to a CEditViewObject");
		::MessageBox(NULL, error, _T("Invalid Operaton"), MB_OK);
		return;
	}

	StdString type = editObject->GetBasicType();
	StdString name = editObject->GetName();

	// create COptionTreeItem
	COptionTreeItemEdit *otiEdit;
	otiEdit = (COptionTreeItemEdit*)m_mTrees[compName.GetUniqueID()].m_Tree->InsertItem(new COptionTreeItemEdit(), root);
	otiEdit->SetLabelText(name.c_str());
	otiEdit->SetInfoText(_T(""));	
}
/*!
This function makes a request to netcdf with its id, to add a new variable to an open netCdf in define mode,
return a variable id, given its name, type, the number of dimensions and list of dimension id
\param [in] ncid Id of groupd(or File Id)
\param [in] varName Name of the desired dimension
\param [in] xtypes One of the set of predefined netCDF data types
\param [in] nDims Number of dimension for the variable
\param [in] dimIds List of ndims dimension ids corresponding to the variable dimensions
\param [in/out] varId Variable id if it is added sucessfully
\return Status code
*/
int CNetCdfInterface::defVar(int ncid, const StdString& varName, nc_type xtype,
                             int nDims, const int dimIds[], int& varId)
{
  int status = nc_def_var(ncid, varName.c_str(), xtype, nDims, dimIds, &varId);
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;

    sstr << "Error when calling function  nc_def_var(ncid, varName.c_str(), xtype, nDims, dimIds, &varId)" << std::endl;
    sstr << errormsg << std::endl;
    sstr << "Unable to add a new variable with name: " << varName
         << " with type " << xtype
         << " and number of dimension " << nDims << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
/*!
This function opens a new netcdf file on parallel file system
\param [in] fileName Name of the file
\param [in] oMode open mode
\param [in] comm MPI communicator
\param [in] info MPI information
\param [in/out] ncId id of the opened file
\return Status code
*/
int CNetCdfInterface::openPar(const StdString& fileName, int oMode, MPI_Comm comm, MPI_Info info, int& ncId)
{
  int status;
  #pragma omp critical (_netcdf)
  status = xios::nc_open_par(fileName.c_str(), oMode, comm, MPI_INFO_NULL.mpi_info, &ncId);
  
  if (NC_NOERR != status)
  {
    StdString errormsg(nc_strerror(status));
    StdStringStream sstr;
    sstr << "Error when calling function nc_open_par(fileName.c_str(), oMode, comm, info, &ncId) " << std::endl
         << errormsg << std::endl
         << "Unable to open file on parallel file system, given its name: " << fileName
         << "and its open mode " << openMode2String(oMode) << std::endl;
    StdString e = sstr.str();
    throw CNetCdfException(e);
  }

  return status;
}
void COptionTreeWrapper::CreateCheckBoxItem(CHashString compName, ViewFormatObject *obj, COptionTreeItem* root)
{
	ICheckBoxViewObject	*checkboxObject = dynamic_cast<ICheckBoxViewObject*>(obj);

	if(checkboxObject == NULL)
	{
		StdString error = _T("Could not cast to a CCheckBoxViewObject");
		::MessageBox(NULL, error, _T("Invalid Operaton"), MB_OK);
		return;
	}

	StdString type = checkboxObject->GetBasicType();
	StdString name = checkboxObject->GetName();

	// create COptionTreeItem
	COptionTreeItemCheckBox *otiCheckBox;
	otiCheckBox = (COptionTreeItemCheckBox*)m_mTrees[compName.GetUniqueID()].m_Tree->InsertItem(new COptionTreeItemCheckBoxEx(), root);
	otiCheckBox->SetLabelText(name.c_str());
	otiCheckBox->SetInfoText(_T(""));
	otiCheckBox->CreateCheckBoxItem( 0, OT_CHECKBOX_SHOWCHECK );
	otiCheckBox->SetCheck(false);
}
void COptionTreeWrapper::CreateColorItem(CHashString compName, ViewFormatObject *obj, COptionTreeItem* root)
{
	IColorViewObject *colorObject= dynamic_cast<IColorViewObject*>(obj);

	if(colorObject == NULL)
	{
		StdString error = _T("Could not cast to a CColorViewObject");
		::MessageBox(NULL, error, _T("Invalid Operaton"), MB_OK);
		return;
	}

	StdString type = colorObject->GetBasicType();
	StdString name = colorObject->GetName();
	int defColor = colorObject->GetDefaultColor();
	
	// create COptionTreeItem
	COptionTreeItemColor *otiColor;
	otiColor = (COptionTreeItemColor*)m_mTrees[compName.GetUniqueID()].m_Tree->InsertItem(new COptionTreeItemColor(), root);
	otiColor->SetLabelText(name.c_str());
	otiColor->SetInfoText(_T(""));
	otiColor->CreateColorItem(0, defColor, defColor);
}