⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matlabimportdlg.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------*
 * File Name: MatlabImportDlg.h												*
 * Creation: 																	*
 * Purpose: OriginC Source C file												*
 * Copyright (c) ABCD Corp.	2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010		*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 *		Soapy 11/12/03 7.0749 	DELETE_HIDDEN_MATRIX_WHEN_IMPORT_FAIL			*
 *		Soapy 11/20/03 7.0753   DELETE_TEMPORARY_MATRIX							*
 *------------------------------------------------------------------------------*/

#ifndef _MATLAB_IMPORTDLG_H
#define _MATLAB_IMPORTDLG_H

#include <externApps.h> 	// matlab class
#include "MatImportDlgBase.h"

#define STR_NO_MATLAB "Matlab not available"
#define STR_TEMP_WORKSPACE_NAME	"_TMP_Origin_Import_Save_.mat"
#define STR_TEMP_ARRAY_NAME	"TMP_Var__For_Type_Transfer"

#define MATLAB_OUTPUT_NUMTOKENS		4
#define MATLAB_OUTPUT_SKIP_LINES	2

enum {
	MATLAB_VAR_DOUBLE_ARRAY,
	MATLAB_VAR_COMPLEX_ARRAY,
	MATLAB_VAR_CHAR_ARRAY,
	MATLAB_VAR_INTEGER_ARRAY,
	MATLAB_VAR_SINGLE_ARRAY,
	MATLAB_VAR_UNKNOWN
};

#define MATLAB_OUTPUT_NAME_COL	0
#define MATLAB_OUTPUT_TYPE_COL	3


/*
	This class is for the import dialog of MATLAB variables from MAT file
*/
class MatlabImportDlg : public MatImportDlgBase
{
public:
	MatlabImportDlg() : MatImportDlgBase()
	{
		
	}

public:	
	int DoModalEx(HWND hWndParent = NULL, LPCSTR lpcszMatlabWkspaceName = NULL, BOOL bSingle = FALSE)
	{
		InitMsgMap();// will be called from internal later
		m_strMatlabWorkspaceFilename = lpcszMatlabWkspaceName;   // the MAT file name
		m_bSingle = bSingle;									///	DVT should be connected to m_bRestoreWorkspace
		int nRet = ResizeDialog::DoModal(hWndParent);
		
		return nRet;
	}

protected:
	
EVENTS_BEGIN
	ON_INIT(OnInitDialog) 
	ON_SIZE(OnDlgResize)
	ON_OK(OnClose)
	ON_TIMER(OnTimer)
	ON_DESTROY(OnDestroy)
	ON_BN_CLICKED(IDC_MATLAB_BTN_IMPORT, OnImportAsMatrices)
	ON_BN_CLICKED(IDC_MATLAB_BTN_IMPORT_WKS, OnImportAsSingleWks)
	ON_BN_CLICKED(IDC_MATLAB_CHK_REPLACE_MAT, OnClickReplaceMat)
	ON_BN_CLICKED(IDC_MATLAB_CHK_REPLACE_WKS, OnClickReplaceCol)
	ON_GRID_SEL_CHANGE(IDC_MATLAB_GRID, OnVsFlexSelChange)
	ON_BN_CLICKED(IDC_MATLAB_BTN_IMPORT_UPDATE, OnUpdateWorkSpace)
EVENTS_END

	//ON_BN_CLICKED(IDC_MATLAB_KEEP_RUNNING, OnCheckKeepRunning)

protected:

	///DVT - IDOK in error is in dialog resource instead of IDCANCEL - change
	BOOL OnClose()
	{
		return TRUE;
	}
	
	
	void OnVsFlexSelChange(Control ctrl)
	{
		if ( m_bDisableImportBtnUpdate )
			return;
		
		BOOL bHasSelection = 0 < m_vsFlex.SelectedRows();
			
		//DVT:	should actualy disable/enable based on importability.
		//this is not complete version, should actualy de-select MATLAB_VAR_UNKNOWN rows
		BOOL bHasWksSelection = FALSE;
		BOOL bHasMatSelection = FALSE;
		
		if( bHasSelection )
		{
			int nRowsSelected = m_vsFlex.SelectedRows();
		    for( int ii=0; ii < nRowsSelected; ii++ )
		    {
				long nR = m_vsFlex.SelectedRow(ii);
				int nVarType = GetMatlabVarType(nR);
	
				if ((nVarType == MATLAB_VAR_DOUBLE_ARRAY )||
					(nVarType == MATLAB_VAR_INTEGER_ARRAY)||
					(nVarType == MATLAB_VAR_SINGLE_ARRAY) ||
					(nVarType == MATLAB_VAR_CHAR_ARRAY))
				{
					bHasWksSelection = TRUE;
					bHasMatSelection = TRUE;
					break;
				}
				if (nVarType == MATLAB_VAR_COMPLEX_ARRAY )
				{
					bHasMatSelection = TRUE;
				}
		    }
		}
			
		EnableImportWksBtn(bHasWksSelection);	
		EnableImportMatBtn(bHasMatSelection);	
	}
	
	
	// Initialize the MatlabImport Dialog
	BOOL OnInitDialog()
	{
		DEBUG_RETURN
		
		MatImportDlgBase::OnInitDialog();
		
		GetWindow().Text = "Connecting to Matlab...";
		
		m_bRestoreWorkspace = false;
		if(!m_strMatlabWorkspaceFilename.IsEmpty()) // file is specified
		{
			if(m_mlObj && !m_bSingle)
			{
				// save workspce and when finish, restore wkspace
				if(SaveCurrentWorkspace())
					m_bRestoreWorkspace = true;
			}
		}
		
		m_nTimerID = SetTimer(5432,300);
		
		// The Update Button
		m_btnUpdate = GetItem(IDC_MATLAB_BTN_IMPORT_UPDATE);

		//Keep Matlab alive check box
		/*
		m_chkKeepRunning = GetItem(IDC_MATLAB_KEEP_RUNNING);
		// CPY make invisible until we have better support
		m_chkKeepRunning.Visible = false;//!m_bSingle;
		
		m_bKeepMatlabAlive = m_mlObj ? m_mlObj.KeepMatlabRunning: FALSE;
		m_chkKeepRunning.Check = m_bKeepMatlabAlive;
		*/
		
		return TRUE;
	}
	
	
	BOOL OnTimer(UINT nTimerID)
	{
		ASSERT(nTimerID==m_nTimerID);
		
		KillTimer(m_nTimerID);
		m_nTimerID = 0;     
	
		//not good loose connection with static in Console!!! if(m_mlObj.Attach( FALSE, m_bSingle ))
		if(m_mlObj.Attach( TRUE, m_bSingle ))
		{
			//if ( m_bSingle )
			//	m_mlObj.Visible = FALSE;
			//not good, it hides all Matlab sessions!
			
			GetWindow().Text = "Matlab Import";
			if( !m_strMatlabWorkspaceFilename.IsEmpty() )
				LoadWorkspace(m_strMatlabWorkspaceFilename);
	
			FillTheGridWithData();
				
			m_vsFlex.ShowTheGrid( );
			m_bDisableImportBtnUpdate = false;
		}
		else
			GetWindow().Text = STR_NO_MATLAB;
		
		return TRUE;
	}
	
	
	BOOL OnDestroy(void)
	{
		DEBUG_RETURN
		
		if(!m_strMatlabWorkspaceFilename.IsEmpty()) // file is specified
		{
			ASSERT(m_mlObj);
			
			if(m_bRestoreWorkspace)
				RestoreWorkspace();
			else
				m_mlObj.Detach();
		}
		
		return TRUE;
	}
	
		
	bool SaveCurrentWorkspace(bool bCleanup = true)
	{
		if(!m_mlObj)
		{
			return false;
		}
		string strExecute;
		
		strExecute.Format("save('%s','*');"
						  "clear all;", STR_TEMP_WORKSPACE_NAME );
		string strRet = m_mlObj.Execute(strExecute);
		
		return strRet.IsEmpty();	//success
	}
	
	
	bool RestoreWorkspace()
	{
		if(!m_mlObj)
		{
			return false;
		}
		string strExecute;
		
		strExecute.Format(	"clear all;"
							"load('%s', '*');"
							"delete('%s');", STR_TEMP_WORKSPACE_NAME, STR_TEMP_WORKSPACE_NAME );
		string strRet = m_mlObj.Execute(strExecute);
		return strRet.IsEmpty();	//success
	}
	
	
	bool LoadWorkspace(LPCSTR lpcstrMatFileName)
	{
		string strExecute;
		strExecute.Format(
						"load('%s', '*');",
						lpcstrMatFileName );
		string strRet = m_mlObj.Execute(strExecute);
		return strRet.IsEmpty();	//success	
	}
	
	
	////////////////////////////////////////////////////////////////
	//this three functions are the CPY code from MatlabConsole.c
	BOOL	GetMatlabRealMatrices( StringArray &asNames, string& strResult )
	{
		//bool	bReplaceCurrent = m_bUpdateMatrix;
		
		for(int ii = 0; ii < asNames.GetSize(); ii++)
		{
			bool bNew = false;
			MatrixLayer mlay(asNames[ii]);
			
			if(!mlay || (!m_bUpdateMatrix && mlay))
			{
				if(mlay) // already existed
					mlay.Detach();
					
				mlay.Create();
				mlay.GetPage().Rename(asNames[ii]);
				bNew = true;
			}
			Matrix<double> mm(mlay);
			if(!m_mlObj.GetMatrix(asNames[ii], &mm) && bNew)
			{
				mlay.Destroy();
				strResult += asNames[ii] + " ";
			}
		}
		if(!strResult.IsEmpty())
		{
			strResult += ": matrices not found in Matlab!";
			return FALSE;
		}
		return TRUE;
	}
	//--------- Soapy 8/12/03 TEMP_SOLUTION_OTHER_DATA_TYPE_SUPPORT_BY_DOUBLE_COPYING
	//use Matlab command double() to cast integer array (int8, int16, int32, uint8, uint16, uint32) and single array to 
	//double before getting their value to Origin. This is to make things to work temporarily for Matlab Import Dialog until
	//related functions are added to Matlab Class.
	BOOL	GetMatlabOtherNumMatrices( StringArray &asNames, string& strResult )
	{
		string strExecute;
		StringArray asNamesTemp;
		
		int nSize = asNames.GetSize();
		
		asNamesTemp.SetSize( nSize );
	
		for(int ii=0; ii<nSize; ii++)
		{
			 asNamesTemp[ii] = STR_TEMP_ARRAY_NAME + ii;
			
			strExecute.Format("%s=%s;"
						  	"%s=double(%s);",
				asNamesTemp[ii], asNames[ii], asNames[ii], asNamesTemp[ii]);
				
			m_mlObj.Execute(strExecute);
		}
				
		BOOL bRet = GetMatlabRealMatrices( asNames, strResult );
		
		for( ii=0; ii<nSize; ii++)
		{
			strExecute.Format("%s=%s;"
							  "clear %s",asNames[ii], asNamesTemp[ii],asNamesTemp[ii]);
			m_mlObj.Execute(strExecute);
		}

		return bRet;		
	}
	int AddMatlabNumArray(Worksheet& wks, string strMatLabVarName, bool bReplaceCurrent)
	{
		string strExecute;

		strExecute.Format("%s=%s;"
						  "%s=double(%s);",
				STR_TEMP_ARRAY_NAME,strMatLabVarName,strMatLabVarName,STR_TEMP_ARRAY_NAME );
		string strRet = m_mlObj.Execute(strExecute);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -