#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	reimp_import,
	reimp_direct,
	reimp_graph,
};
#include <..\originlab\theme_utils.h> ///---Sim 10-27-2008 QA80-12422 SUPPORT_SAVE_SHEET_THEME_FOR_ALL_SHEET_IMPORT_FILE
#include <..\system\oExtFile.h>
#include <..\originlab\file_utils.h>
#include <..\originlab\fu_utils.h>	///---Sim 09-11-2006 SUPPORT_MULTI_FILE
#include <sys_utils.h> ///---Sim 09-13-2006 SUPPORT_MULTI_FILES_INXF
#include <..\originlab\import_utils.h> ///---Sim 09-28-2006 FIX_IMPORT_MODE_SHOWING_ORDER
#include <oErrMsg.h>
#include <ocu.h>
#include <..\originlab\pClampImport.h>
#include <..\originlab\XFunctionEx.h> //<XFbase.h>
#include <..\originlab\grobj_utils.h> /// Hong 10/24/06 ADD_TAG_TO_GRAPH
#include <..\originlab\graph_utils.h>

///////////////////////////////////////////////////////////////////////
//////// modification log
/// Hong 03/12/07 QA80-9418-S1 ONLY_UPDATE_BINARY_INFO_WHEN_REIMPORT
///	CPY 3/16/07 STR_NEEDS_TO_BE_LOCALIZED
///---Sim 03-17-2007 CHECK_ERROR_FOR_INVALID_RANGE
/// Hong 03/21/07 v8.0586 QA80-9457-P6 MORE_CHECK_FOR_VALID_DATA
/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
/// Hong 04/12/07 DISABLE_ADD_PLOT_WHEN_REIMPORT_AVOID_CONFLICT_BETWEEN_XFBAR_AND_ORGANIZER
/// Hong 04/13/07 QA80-9614 FIX_CRASH_IF_RUN_FROM_ORGANIZER
/// Hong 04/17/07 v8.0602b ONLY_NEED_DELAY_XFBAR_WHEN_REIMPORT
/// Sim 04-30-2007 TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
/// Sim 05-04-2007 ADD_NOTE_WINDOW_SHEET
/// Sim 05-05-2007 MOVE_SKIP_POINT_OPTIONS
/// Sim 05-05-2007 NO_NEED_SUPPORT_MULTI_FILES
/// Sim 05-08-2007 FIX_GET_SWEEP_SIZE_FOR_ALL_MODE
/// Hong 05/08/07 v8.0613 DISABLE_PARTIAL_OPTION_FOR_VARIABLE_LENGTH_MODE
/// Sim 05-08-2007 ADD_OPTIONS_FOR_IMPORT_MODE_OF_1ST_FILE
/// Sim 05-10-2007 TRUN_OFF_ADD_NOTE_WINDOW_SHEET
/// Sim 05-11-2007 GOOD_EXPLAIN_FOR_USER_AS_JUSTIN_SAID
/// Sim 05-18-2007 REMOVE_UID_VARIABLE
/// Sim 05-22-2007 ADDITIONAL_OPTIONS_ID
/// Sim 05-25-2007 QA80-9821 APPLY_NEW_NODE_EVENT_MECHANISM
/// CPY 6/2/2007 ADDPLOT_CHANGED_TO_XFBAR
/// Hong 06/04/07 v8.0632 XFBAR_MISS_BOOK_WHEN_IMPORT_FROM_SCRIPT
/// Sim 06-25-2007 UPDATE_ORGANIZER
/// Sim 08-06-2007 SUPPORT_SMART_SPARKLINE
/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
/// Hong 12/06/07 v8.0762 IMPORT_SUPPORT_RELATIVE_PATH_FOR_REIMPORT_SAMPLE_REQUIREMENT
/// Hong 01/02/08 QA80-10888 ALWAYS_SHOW_EPISODE_OPTIONS
/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
/// Sim 03-11-2008 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
/// Hong 03/25/08 v8.0831 FIX_RUN_FROM_MENU_NO_OPEN_DIALOG_IF_FNAME_NOT_EMPTY
/// Hong 07/23/08 v8.0907 HIDEEN_PARTIAL_OPTIONS_IN_IWFILTER		
/// Hong 07/24/08 QA80-11869 ONLY_DRAG_AND_DROP_SUPPOORT_LT_SCRIPT_BY_NOW
/// Sim 10-27-2008 QA80-12422 SUPPORT_SAVE_SHEET_THEME_FOR_ALL_SHEET_IMPORT_FILE
/// Hong 01/15/09 FIX_PCLAMP_PLOT_FAIL_HANDLE_TIME_OFFSET_OF_HOLDING_DURATION
/// Hong 02/03/09 QA80-12413-P3 FIX_HOLDING_DURATION_OPTION_LOST_WHEN_MUTLPLE_FILES
/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
/// Hong 03/06/09 IMPROVE_PCLAMP_GUI_SHOW_KEY_OPTIONS
/// Hong 03/05/09 TURN_OFF_SHEET_RENAME_AND_ONLY_RENAME_BK_LONGNAME_ASKED_CP
/// Hong 03/12/09 IMPROVE_CODE_PUT_SOME_LOGIC_IN_IMPPCLAMP
/// Hong 04/03/09 QA80-13407 PCLAMP_BETTER_TERMS_FROM_ITS_COMPANY
/// Hong 04/07/09 FIX_PCLAMP_CONTROL_STILL_SHONW_WHEN_SHOW_TIME_COL_IN_LT
/// Hong 04/08/09 QA80-13222 ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
/// Hong 04/09/09 QA80-13318 FIX_REIMPORT_FAIL_GET_CORRECT_ROW_NUM_IF_HAVE_HOLDING_DURATION_OFFSET_AND_SHOW_TIME_COL
/// Hong 04/16/09 QA80-10360-P13 FIX_START_TIME_INCORRECT_IF_NOT_IMPORT_FROM_FIRST_SWEEP
/// Sim 04/16/09 QA80-13318 IMPROVE_HONG_FIX_REIMPORT_FAIL_GET_CORRECT_ROW_NUM
/// Hong 04/16/09 DISABLE_HOLDING_DURATION_WHEN_ADD_TIME_COL
/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
///////////////////////////////////////////////////////////////////////
///---END HANDLE_ERR_MESSAGE_USE_DLL
/// Hong 06/14/07 v8.0641 USER_KEYWORD_FOR_COMBO_STRING
///// Hong 05/18/07 v8.0621 REIMP_FROM_GRAPH_AUTO_PLOT
///  AW 01/06/09 QA80-12413 ADD_HOLDING_DURATION_TIME_IN_PCLAMP
//enum
//{
	//REIMP_IMPORT,
	//REIMP_REIMPORT,
	//REIMP_GRAPH_REIMPORT,
//};
///// end REIMP_FROM_GRAPH_AUTO_PLOT
/// end USER_KEYWORD_FOR_COMBO_STRING
//put your own support static functions here
//static pClampImport s_pClampImport; // 12/27/06 REMOVE_STATIC_OBJECT

#define PCLAMP_1ST_FILE_IMPORT_MODE_LIST 	LIST_IMPORT_MODE_REPLACE_BOOK_SHEET_COLUMN ///---Sim 05-08-2007 ADD_OPTIONS_FOR_IMPORT_MODE_OF_1ST_FILE
#define PCLAMP_IMPORT_MODE_LIST	(PCLAMP_1ST_FILE_IMPORT_MODE_LIST & (~IW_FLAG_IMPMODE_REPLACE)) ///---Sim 05-08-2007 REMOVE_REPLACE_OUT_OF_MULTI_FILE_IMPORT_MODE

///---Sim 11-16-2006 RELIABLE_OK_ENABLE
static bool s_bFileValid = true;
static bool s_bRangeValid = true; ///---Sim 03-17-2007 CHECK_ERROR_FOR_INVALID_RANGE
#define OK_SURE(_OK_ENABLE) _OK_ENABLE = s_bFileValid & s_bRangeValid; //also can be _OK_ENABLE = s_bFileValid && s_bSetting
///---END RELIABLE_OK_ENABLE

/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
enum
{
	//"nRepeatBranchID = nNodeRepeatID | nParentRepeatID;" in combine_treenode_id_with_repeat_id
	RPTID_DATASELECTION_LEVEL_OFFSET_BITS	= 6, // stand for 0x0020 maximum number of XF variable
	RPTID_FILES_LEVEL_OFFSET_BITS			=10, // give 4 bit for data selection level
};

enum
{
	RPTID_CHANNELS		= 1,
	RPTID_SWEEPS,
};

enum
{
	DATAID_STIMULUS		= 1,
	DATAID_HOLDING_DURATION,
	DATAID_ADD_TIME_COL,
};

static int _get_proper_repeat_id(int nIndex, int nOffsetBit)
{
	return nIndex << nOffsetBit;
}
/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME

/*
static bool import_mode_event(TreeNode& trGUI, int nRow, int nCol, TreeNode& trNode, DWORD dwCntrl, int nType, WndContainer& theDlg)
{
	if(!(dwCntrl & GETNEVENT_ON_INIT))
	{
		int nIndex = 0;
		foreach(TreeNode trFileNode in trGUI.trSetting.Children )
		{
			if ( 0 == nIndex++ )
				continue;
			trFileNode.Sweeps.Show = trNode.nVal;
		}
		return true;
	} 
	return false;
}
*/
static void import_mode_event(TreeNode trGUI, int nInputMode)
{
	foreach(TreeNode trFileNode in trGUI.trfiles.Children )
	{
		trFileNode.Sweeps.Show = nInputMode;
	}
}

/// AW 05/18/07 MORE_ON_REIMPORT_BY_CHANGE_OPTIONS
static void _undo_make_tree_node_readonly(TreeNode& trNode)
{
	if ( trNode.Enable == ENABLE_READ_ONLY)
		trNode.Enable = ENABLE;
	int nOldEnableValue;
	foreach(TreeNode trn in trNode.Children)
	{
		if(trn.GetNodeCount() > 0)
			_undo_make_tree_node_readonly(trn);
		else
		{
			if ( trn.Enable == ENABLE_READ_ONLY )
				trn.Enable = ENABLE;	
		}
	}
}
/// END MORE_ON_REIMPORT_BY_CHANGE_OPTIONS

/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
static void _update_xfbar_status(TreeNode& trGetN)
{
	BOOL		bShowTime = FALSE;
	if ( trGetN.trfiles.ShowTimeCol ) // single file
	{
		bShowTime = trGetN.trfiles.ShowTimeCol.nVal;
	}
	else
	{
		foreach ( TreeNode trNode in trGetN.trfiles.Children )
		{
			if ( trNode.ShowTimeCol )
			{
				bShowTime = trNode.ShowTimeCol.nVal;
				if ( bShowTime )
					break;
			}
		}
	}
	trGetN.options.XFBar.Enable = bShowTime ? DISABLE : ENABLE;
}
/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER


//static int _get_num_sweep(int nFileIndex, int nInputMode)
static int _get_num_sweep(int nFileIndex, int nInputMode, pClampImport& pciFiles)
{
	int nNum = 1;
	/// Hong 11/9/06 TEMP_OPEN_SUPPORT_GAPFREE_MODE 
	// gapfree mode have only one sweep
	//if(IMPORT_MODE_CHANNELS != nInputMode)
	//pCLAMPFile* ppClampFile = s_pClampImport.GetpClampFile(nFileIndex);
	pCLAMPFile* ppClampFile = pciFiles.GetpClampFile(nFileIndex); // 12/27/06 REMOVE_STATIC_OBJECT
	if(IMPORT_MODE_CHANNELS != nInputMode && ABF_GAPFREEFILE != ppClampFile->GetOperationMode())
		//nNum = s_pClampImport.GetSweepNum(nFileIndex);
		nNum = pciFiles.GetSweepNum(nFileIndex);
	/// end TEMP_OPEN_SUPPORT_GAPFREE_MODE
	return nNum;
}

/// Hong 06/11/07 v8.0638 ALLOW_LT_ACCESS_FOR_STIMULUS
/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
//static bool _reset_trfiles_tree(TreeNode& trFiles)
static bool _reset_trfiles_tree(TreeNode& trFiles, bool bSingleFile = true)
/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
{
	if ( !trFiles )
		return false;
	/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
	vector<string>		vsTagNameKept = {"bHoldingDuration", "InfoFileNormal", "ShowTimeCol", "Stimulus"};
	/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
	foreach (TreeNode trNode in trFiles.Children)
	{
		//if ( trNode.tagName == "Stimulus" || trNode.tagName == "InfoFileNormal" )
		/// AW 01/06/09 QA80-12413 ADD_HOLDING_DURATION_TIME_IN_PCLAMP
		//if ( bSingleFile && (trNode.tagName == "Stimulus" || trNode.tagName == "InfoFileNormal") ) /// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		//if ( bSingleFile && (trNode.tagName == "Stimulus" || trNode.tagName == "InfoFileNormal" || trNode.tagName == "bHoldingDuration") )
		if ( bSingleFile && -1 != vsTagNameKept.Find(trNode.tagName) )
		/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		/// END ADD_HOLDING_DURATION_TIME_IN_PCLAMP
			continue;
		trNode.Remove();
	}
	
	return true;
}
/// end ALLOW_LT_ACCESS_FOR_STIMULUS

/// Hong 03/21/07 v8.0586 QA80-9457-P6 MORE_CHECK_FOR_VALID_DATA
//static void _construct_branch(TreeNode& trFile, int nInputMode, pCLAMPFile* ppClampFile)
static bool _construct_branch(TreeNode& trFile, int nInputMode, pCLAMPFile* ppClampFile)
/// end MORE_CHECK_FOR_VALID_DATA
{		
	vector<string> vsChannelName;
 	TreeNode trNode, trSubNode;
//	GETN_USE(trFile)

	/// Hong 05/14/07 v8.0617 ADD_STIMULUS_SELECT_OPTION
	//string strStimulus(_L("Stimulus"));
	string strStimulus(_LE("Stimulus")); /// Hong 10/25/07 QA80-10577 MORE_COMBO_STR_STAY_AS_E_INTERNALLY_IN_DYNA_CNTRL
	/// Hong 06/11/07 v8.0638 ALLOW_LT_ACCESS_FOR_STIMULUS
	if ( !trFile.Stimulus )
	{
		trNode = trFile.AddNumericNode(1, strStimulus, TRGP_CHECK);
		//trNode.SetAttribute(STR_LABEL_ATTRIB, strStimulus);
		trNode.SetAttribute(STR_LABEL_ATTRIB, GetLocalized(strStimulus)); /// Hong 10/25/07 QA80-10577 MORE_COMBO_STR_STAY_AS_E_INTERNALLY_IN_DYNA_CNTRL
	}
	else
	{
		trNode = trFile.Stimulus;
	}
	/// end ALLOW_LT_ACCESS_FOR_STIMULUS
	/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	trNode.SetAttribute(STR_DATAID_ATTRIB, GET_USER_DATAID(DATAID_STIMULUS));
	/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	if ( !ppClampFile->IsHaveStimulus() )
	{
		trNode.nVal = 0;
		trNode.Show = 0;
	}
	/// END ADD_STIMULUS_SELECT_OPTION
	/// Hong 02/03/09 QA80-12413-P3 FIX_HOLDING_DURATION_OPTION_LOST_WHEN_MUTLPLE_FILES
	if ( !trFile.bHoldingDuration )
	{
		trNode = trFile.AddNumericNode(0, "bHoldingDuration", TRGP_CHECK);
		trNode.SetAttribute(STR_LABEL_ATTRIB, _L("Shift Time by Holding Period"));
	}
	/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	else
		trNode = trFile.bHoldingDuration;
	trNode.SetAttribute(STR_DATAID_ATTRIB, GET_USER_DATAID(DATAID_HOLDING_DURATION));
	/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	/// end FIX_HOLDING_DURATION_OPTION_LOST_WHEN_MUTLPLE_FILES
	
	/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
	trNode = trFile.ShowTimeCol;
	if ( !trNode )
	{
		GETN_USE(trFile)
		GETN_CHECK(ShowTimeCol, _L("Add Time Column"), 0)
		/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
		//trNode = GETN_CURRENT_NODE;
		trNode = GETN_CURRENT_SUBNODE;
		/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	}
	/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	trNode.SetAttribute(STR_DATAID_ATTRIB, GET_USER_DATAID(DATAID_ADD_TIME_COL));
	/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	trNode.Show = nInputMode;
	if ( !trNode.Show )
		trNode.nVal = FALSE;
	/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
	
	string strChnnels, strChannelName;
 	//strChnnels = _L("Channels");
 	strChnnels = _LE("Channels"); /// Hong 10/25/07 QA80-10577 MORE_COMBO_STR_STAY_AS_E_INTERNALLY_IN_DYNA_CNTRL
	trNode = trFile.AddNode(strChnnels, TRGP_BRANCH);
	/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	trNode.SetAttribute(STR_REPEAT_ID_ATTRIB, _get_proper_repeat_id(RPTID_CHANNELS, RPTID_DATASELECTION_LEVEL_OFFSET_BITS));
	/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	//trNode.SetAttribute(STR_LABEL_ATTRIB, strChnnels);
	/// Hong 04/03/09 QA80-13407 PCLAMP_BETTER_TERMS_FROM_ITS_COMPANY
	//trNode.SetAttribute(STR_LABEL_ATTRIB, GetLocalized(strChnnels)); /// Hong 10/25/07 QA80-10577 MORE_COMBO_STR_STAY_AS_E_INTERNALLY_IN_DYNA_CNTRL
	trNode.SetAttribute(STR_LABEL_ATTRIB, _L("Signals"));
	/// end PCLAMP_BETTER_TERMS_FROM_ITS_COMPANY
	//trNode.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);
	trNode.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_CHECK_CONTROL | GETNBRANCH_OPEN|GETNBRANCH_CHECK_CONTROL_ONE_EVENT); // Hong 12/29/06 ADD_CHECK_ALL_UNCHECK_ALL_OPTION
	int nChannels = ppClampFile->GetChannelNum();
	/// Hong 03/21/07 v8.0586 QA80-9457-P6 MORE_CHECK_FOR_VALID_DATA
	if( nChannels < 1 ) // if have no channel
		return false;
	/// end MORE_CHECK_FOR_VALID_DATA
	for (int ii = 0; ii < nChannels; ii++ )
	{
		ppClampFile->GetChannelName(ii, strChannelName);
		trSubNode = trNode.AddNumericNode(1, "ChannelName", TRGP_CHECK);
		trSubNode.SetAttribute(STR_LABEL_ATTRIB, strChannelName);
		//trSubNode.SetAttribute(STR_ATTRIB_DISPFMT, DISPLAY_EDITOR_CHECK_ON_LEFT); // Hong 03/13/07 AVOID_LABEL_TRUNCATED
		trSubNode.SetAttribute(STR_DATAID_ATTRIB, GET_USER_DATAID(ii)); /// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	}
	/// Hong 12/19/06 ADD_MATH_CHANNEL_FOR_SELECTION
	string strName, strUnit, strFormat;
	if(ppClampFile->GetMathChannelInfo(strName, strUnit, strFormat))
	{
		trSubNode = trNode.AddNumericNode(1, "MathChannelName", TRGP_CHECK);
		trSubNode.SetAttribute(STR_LABEL_ATTRIB, strName);
		//trSubNode.SetAttribute(STR_ATTRIB_DISPFMT, DISPLAY_EDITOR_CHECK_ON_LEFT); // Hong 03/13/07 AVOID_LABEL_TRUNCATED
		trSubNode.SetAttribute(STR_DATAID_ATTRIB, GET_USER_DATAID(nChannels)); /// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	}
	/// end ADD_MATH_CHANNEL_FOR_SELECTION
	string strSweeps, strSweepName;
 	strSweeps = "Sweeps";
	trNode = trFile.AddNode(strSweeps, TRGP_BRANCH);
	/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	trNode.SetAttribute(STR_REPEAT_ID_ATTRIB, _get_proper_repeat_id(RPTID_SWEEPS, RPTID_DATASELECTION_LEVEL_OFFSET_BITS));
	/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	/// Hong 04/03/09 QA80-13407 PCLAMP_BETTER_TERMS_FROM_ITS_COMPANY
	//trNode.SetAttribute(STR_LABEL_ATTRIB, _L("Episodes"));// Hong 11/16/06 USE_BETTER_NEMA
	trNode.SetAttribute(STR_LABEL_ATTRIB, _L("Sweeps"));// Hong 11/16/06 USE_BETTER_NEMA
	/// end PCLAMP_BETTER_TERMS_FROM_ITS_COMPANY
	trNode.Show = nInputMode;
	//trNode.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);
	/// Hong 03/06/09 IMPROVE_PCLAMP_GUI_SHOW_KEY_OPTIONS
	//trNode.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_CHECK_CONTROL | GETNBRANCH_OPEN|GETNBRANCH_CHECK_CONTROL_ONE_EVENT); // Hong 12/29/06 ADD_CHECK_ALL_UNCHECK_ALL_OPTION
	trNode.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_CHECK_CONTROL | GETNBRANCH_CHECK_CONTROL_ONE_EVENT);
	/// end IMPROVE_PCLAMP_GUI_SHOW_KEY_OPTIONS
	int nSweeps = ppClampFile->GetSweepNumPerChannel();
	/// Hong 03/21/07 v8.0586 QA80-9457-P6 MORE_CHECK_FOR_VALID_DATA
	if( nSweeps < 1 ) // if have no sweep
		return false;
	/// end MORE_CHECK_FOR_VALID_DATA
	/// Hong 11/9/06 TEMP_OPEN_SUPPORT_GAPFREE_MODE 
	// gapfree mode have only one sweep
	int nOpMode = ppClampFile->GetOperationMode();
	if( ABF_GAPFREEFILE == nOpMode )
		nSweeps = 1;
	// hidden sweep node in variable-length mode
	///--- Hong 05/10/07 v8.0614 hidden sweep node in gap-free mode asked by Justin
	//if( ABF_VARLENEVENTS == nOpMode )
	/// Hong 05/14/07 v8.0617 ALLOW_VARIABLE_SEGMENT_SELECTION
	//if( ABF_VARLENEVENTS == nOpMode || ABF_GAPFREEFILE == nOpMode )
	if ( ABF_VARLENEVENTS == nOpMode ) //for variable-length mode file, no Episodes, but Segments
		trNode.SetAttribute(STR_LABEL_ATTRIB, _L("Segments"));

	/// Hong 01/02/08 QA80-10888 ALWAYS_SHOW_EPISODE_OPTIONS
	/*
	if ( ABF_GAPFREEFILE == nOpMode )
	/// END ALLOW_VARIABLE_SEGMENT_SELECTION
		trNode.Show = false;
	*/
	/// end ALWAYS_SHOW_EPISODE_OPTIONS
	///---
	/// end TEMP_OPEN_SUPPORT_GAPFREE_MODE
	
	int nSweepSize;
	double dStartTime, dEndTime;
	double dSampling = ppClampFile->GetSampleInterval();
	string strStartTime, strEndTime;

	
	for (ii = 0; ii < nSweeps; ii++ )
	{
		//strSweepName.Format("#%d", ii);
		//// AW 05/04/07
		//strSweepName.Format("#%d", ii + 1);// Hong 12/19/06 SWEEP_INDEX_START_FROM_1
		ppClampFile->GetStartTime(&dStartTime, 0, ii + 1); 
		///---Sim 05-08-2007 FIX_GET_SWEEP_SIZE_FOR_ALL_MODE
		if( ABF_GAPFREEFILE == nOpMode )
			nSweepSize = ppClampFile->GetTotalSamplingNumber();
		else
		///---END FIX_GET_SWEEP_SIZE_FOR_ALL_MODE
			nSweepSize = ppClampFile->GetSweepSize(ii + 1);
		dEndTime = dSampling*nSweepSize + dStartTime;
		strStartTime = ftoa(dStartTime, "*6*");
		strEndTime = ftoa(dEndTime, "*6*");
		strSweepName.Format("#%d (%sms--%sms,%d)", ii + 1, strStartTime, strEndTime, nSweepSize);// Hong 12/19/06 SWEEP_INDEX_START_FROM_1
		/// END 
		
		trSubNode = trNode.AddNumericNode(1, "SweepName", TRGP_CHECK);
		trSubNode.SetAttribute(STR_LABEL_ATTRIB, strSweepName);
		trSubNode.SetAttribute(STR_DATAID_ATTRIB, GET_USER_DATAID(ii)); /// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
		/// Hong 05/16/07 SPEED_UP_BY_SAVE_MORE_INFO
		/*
		/// Hong 05/15/07 MORE_RELIABLE_TIME_WHEN_PLOT
		trSubNode.SetAttribute("PLCAMP_StartTime", dStartTime); // this Attribute name may move to a utility file
		/// END MORE_RELIABLE_TIME_WHEN_PLOT
		*/
		/// END SPEED_UP_BY_SAVE_MORE_INFO
		//trSubNode.SetAttribute(STR_ATTRIB_DISPFMT, DISPLAY_EDITOR_CHECK_ON_LEFT); // Hong 03/13/07 AVOID_LABEL_TRUNCATED
	}
	
	return true; /// Hong 03/21/07 v8.0586 QA80-9457-P6 MORE_CHECK_FOR_VALID_DATA
}

///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
//static void _construct_GUI_tree(TreeNode& trGUI, int nInputMode, vector<string>& vsFileNames)
static bool _construct_GUI_tree(TreeNode& trGUI, int nInputMode, vector<string>& vsFileNames, TreeNode& trPationSetting)
///---END HANDLE_ERROR_MESSAGE
{
	/// Hong 12/27/06 REMOVE_STATIC_OBJECT
	//pClampImport s_pClampImport.SetFileName(vsFileNames); 	
	pClampImport pciFiles;
	pciFiles.SetFileName(vsFileNames);
	/// end REMOVE_STATIC_OBJECT	
	int nCount = vsFileNames.GetSize();
	/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	//if ( nCount > 1 )
	//{
	//	// only support one file
	//	// show meesage here
	//	return false;
	//	
	//}	
	/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	
	TreeNode trFile;
	string strTagName; ///---Sim 11-08-2006 FIX_SET_TAGNAME_AS_FILE_NAME
//	GETN_USE(trGUI)
	/// Hong 06/11/07 v8.0638 ALLOW_LT_ACCESS_FOR_STIMULUS
	//trGUI.RemoveChildrenWithPrefix(); ///---Sim 11-20-2006 SET_ATTRIBUTE
	/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	//_reset_trfiles_tree(trGUI);
	bool bSingleFile = (1 == nCount) ? true : false;
	_reset_trfiles_tree(trGUI, bSingleFile);
	/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	/// end ALLOW_LT_ACCESS_FOR_STIMULUS
	//GETN_LIST(Importmode, "Import mode", 0, "Channels|Sweeps") GETN_OPTION_EVENT_EX(import_mode_event)
	for ( int nIndex = 0; nIndex < nCount; nIndex++ )
	{
		///---Sim 09-19-2006 MAKE_TAGNAME_OF_EACH_NODE_AS_FILE_NAME
		//trFile = trGUI.AddNode("junk");
		///---Sim 11-08-2006 FIX_SET_TAGNAME_AS_FILE_NAME
		//string strFileName = GetFileName(vsFileNames[nIndex], true);
		//strFileName.MakeValidCName('a');
		//trFile = trGUI.AddNode(strFileName);
		/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		/// Hong 05/14/07 v8.0617 MOVE_FILE_NODE_AS_SINGLE_FILE
		if ( !bSingleFile )
		{
			strTagName.Format("file%d", nIndex+1);
			trFile = trGUI.AddNode(strTagName);			
			/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
			// When signle file, there is NOT file%d branch, so no repeatid for it
			if ( 0 != nIndex )
				trFile.SetAttribute(STR_REPEAT_ID_ATTRIB, _get_proper_repeat_id(nIndex, RPTID_FILES_LEVEL_OFFSET_BITS));
			/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
		}
		//// END MOVE_FILE_NODE_AS_SINGLE_FILE
		/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT		
		///---END FIX_SET_TAGNAME_AS_FILE_NAME
		///---END MAKE_TAGNAME_OF_EACH_NODE_AS_FILE_NAME
		/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		/// Hong 05/14/07 v8.0617 MOVE_FILE_NODE_AS_SINGLE_FILE
		if ( !bSingleFile )
		{
			trFile.SetAttribute(STR_LABEL_ATTRIB, GetFileName(vsFileNames[nIndex], false));
			trFile.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);
		}
		else
		{
			trFile = trGUI;
		}
		//GETN_OPTION_BRANCH(GETNBRANCH_OPEN)
		//GETN_USE(trFile)
		/// END MOVE_FILE_NODE_AS_SINGLE_FILE
		/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		TreeNode trFileInfo;
		
		//trFileInfo = trFile.AddNode("FileInfo");
		/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		/// Hong 05/14/07 v8.0617 MOVE_FILE_NODE_AS_SINGLE_FILE
		GETN_USE(trFile)
		//GETN_USE(trGUI)
		/// END MOVE_FILE_NODE_AS_SINGLE_FILE
		/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		
		//// AW 10/10/06 MORE_ON_XF_PCLAMP_HEADER_INFO
		//GETN_MULTILINE_TEXT(Info,"HeaderInfo",s_pClampImport.GetHeaderInfo(nIndex)) GETN_INFO
		//pCLAMPFile* ppClampFile = s_pClampImport.GetpClampFile(nIndex); 
		pCLAMPFile* ppClampFile = pciFiles.GetpClampFile(nIndex); /// 12/27/06 REMOVE_STATIC_OBJECT
		///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
		if ( !ppClampFile )
		{
			//s_pClampImport.CleanUp(); /// 12/27/06 REMOVE_STATIC_OBJECT
			//XF_THROW_EX(IMPERR_INVALID_FILE, vsFileNames[nIndex]);
			return false;
		}
		///---END HANDLE_ERROR_MESSAGE
		string strValue;
		/// Hong 03/19/07 PCLAMP_INFO_TOO_MAUCH_CONTENT
		//strValue = "FILE PROPERTY: \n" + ppClampFile->GetHeaderInfo(INFO_TERSE);
		
		/// AW 05/02/07 QA80-9716 v8.0612 SUPPORT_PCLAMP_TIME_PARTIAL_IMPORT
		//string strHeaderInfo = ppClampFile->GetHeaderInfo(INFO_TERSE);
		string strHeaderInfo = ppClampFile->GetHeaderInfo(INFO_LONG);
		//out_str(strHeaderInfo);				// teting ///---Hong, comment test message
		
		// looks we did not support non_fixed_even mode, otherwise, we need check if it has fixed sampling
		double dStartTime;
		ppClampFile->GetStartTime(&dStartTime, 0, 1); 
		double dSampling = ppClampFile->GetSampleInterval();
		///---Sim 05-08-2007 FIX_GET_SWEEP_SIZE_FOR_ALL_MODE
		//int nSize = ppClampFile->GetSweepSize();
		//long nSampleCount = ppClampFile->GetTotalSamplingNumber();
		int nOpMode = ppClampFile->GetOperationMode();
		int nSize;
		if( ABF_GAPFREEFILE == nOpMode )
			nSize = ppClampFile->GetTotalSamplingNumber();
		else
			nSize = ppClampFile->GetSweepSize();
		///---END FIX_GET_SWEEP_SIZE_FOR_ALL_MODE
		
		/// Hong 05/08/07 v8.0613 DISABLE_PARTIAL_OPTION_FOR_VARIABLE_LENGTH_MODE
		//if ( ABF_VARLENEVENTS == ppClampFile->GetOperationMode() )
		trPationSetting.Show = bSingleFile; /// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		if ( !bSingleFile || ABF_VARLENEVENTS == ppClampFile->GetOperationMode() ) /// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		{
			trPationSetting.Enable = 0;			
		}
		else
		{
			trPationSetting.Enable = 1;
		}
		/// end DISABLE_PARTIAL_OPTION_FOR_VARIABLE_LENGTH_MODE
		dStartTime = 0;
		fuSetStartTime(trPationSetting, dStartTime);
		fuSetEndTime(trPationSetting, dStartTime + dSampling * nSize);
		fuSetStartPoint(trPationSetting, 0);
		fuSetEndPoint(trPationSetting, nSize);
		trPationSetting.SetAttribute(STR_PARTIAL_DURATION_TIME, dSampling * nSize);
		trPationSetting.SetAttribute(STR_PARTIAL_IMPORT_INTERVAL, dSampling);
		
		string strLabel;
		TreeNode trPartialImport	= tree_get_node_by_id(trPationSetting, IDE_XFIMP_PARTIAL_IMPORT, true);
		int nSkip = fuGetSkipPoint(trPationSetting);
		
		double dCurrentSampling = dSampling * (nSkip+1);
		
		///---Sim 05-11-2007 GOOD_EXPLAIN_FOR_USER_AS_JUSTIN_SAID
		//strLabel.Format("Partial Import: duransion(s) %sms, current interval %sms", ftoa(dSampling * nSize), ftoa(dCurrentSampling));
		strLabel.Format(_L("Duration: %sms    Interval: %sms"), ftoa(dSampling * nSize), ftoa(dCurrentSampling));
		///---AW 05/11/08 CHANGE_PARTIAL_INFO_DISPLAY
		//trPationSetting.SetAttribute(STR_LABEL_ATTRIB, strLabel);
		trPationSetting.Info.strVal = strLabel;
		///---END CHANGE_PARTIAL_INFO_DISPLAY		
		
		// has done at make_tree function
		/*
		///--- Hong 05/10/07 v8.0614 change "Skip Ponits" ==> "Skip Samples" asked by Justin
		TreeNode trSkipPoints = tree_get_node_by_id(trPationSetting, IDE_XFIMP_SKIP_POINT, true);
		trSkipPoints.SetAttribute(STR_LABEL_ATTRIB, _L("Skip Samples"));
		///---
		*/
		///---END GOOD_EXPLAIN_FOR_USER_AS_JUSTIN_SAID
//		trPartialImport.SetAttribute(STR_LABEL_ATTRIB, "Partial Import, based on first episode");
		/// END SUPPORT_PCLAMP_TIME_PARTIAL_IMPORT
		
		/*
		int nPos = strHeaderInfo.Find("\r\n\r\n"); // find first empty line
		strHeaderInfo[nPos] = '\0';
		strValue = "FILE PROPERTY: \n" + strHeaderInfo;
		/// end PCLAMP_INFO_TOO_MAUCH_CONTENT
		BOOL bHasTag;
		string strTemp;
		strTemp = ppClampFile->GetTags(&bHasTag);
		if ( bHasTag )
			strValue += "\nFILE TAGS: \n"	+ strTemp;
		GETN_MULTILINE_TEXT(InfoFileNormal,"File Normal property",strValue) GETN_INFO
		*/
		/// Hong 06/11/07 v8.0638 ALLOW_LT_ACCESS_FOR_STIMULUS
		//GETN_MULTILINE_TEXT(InfoFileNormal, "File protocol", strHeaderInfo) GETN_OPTION_MUTILINE_TEXT_BOX(true, "2-15", true)
		//if ( !trGUI.InfoFileNormal )		
		if ( !trFile.InfoFileNormal ) /// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		{
			/// Hong 03/06/09 IMPROVE_PCLAMP_GUI_SHOW_KEY_OPTIONS
			//GETN_MULTILINE_TEXT(InfoFileNormal, _L("File protocol"), strHeaderInfo) GETN_OPTION_MUTILINE_TEXT_BOX(true, "2-15", true)
			GETN_MULTILINE_TEXT(InfoFileNormal, _L("File protocol"), strHeaderInfo) GETN_OPTION_MUTILINE_TEXT_BOX(true, "2-15", true) SET_EDITBOX_RESIZABLE(0)
			/// end IMPROVE_PCLAMP_GUI_SHOW_KEY_OPTIONS
		}
		else
		{
			//trGUI.InfoFileNormal.strVal = strHeaderInfo;
			trFile.InfoFileNormal.strVal = strHeaderInfo; /// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		}
		/// end ALLOW_LT_ACCESS_FOR_STIMULUS
		//// END MORE_ON_XF_PCLAMP_HEADER_INFO

		///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
		/*
		if ( ppClampFile )
			_construct_branch(trFile, nInputMode, ppClampFile);
		else
		{
			XF_THROW(XFERR_INVALID_MATOBJ);// a better global err for not matching book would be better
			return;
		}
		*/
		/// Hong 03/21/07 v8.0586 QA80-9457-P6 MORE_CHECK_FOR_VALID_DATA
		//_construct_branch(trFile, nInputMode, ppClampFile);
		//if( !_construct_branch(trFile, nInputMode, ppClampFile) )
		//if( !_construct_branch(trGUI, nInputMode, ppClampFile) )
		if( !_construct_branch(trFile, nInputMode, ppClampFile) ) /// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
			return false;
		/// end MORE_CHECK_FOR_VALID_DATA
		///---END HANDLE_ERROR_MESSAGE
	}
	/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	//trGUI.SetAttribute(STR_LABEL_ATTRIB, _L("File Info And Data Selection, file size: ") + GetFileSize(vsFileNames[0])); /// AW 05/18/07 ADD_FILE_SIZE
	if ( bSingleFile )
		trGUI.SetAttribute(STR_LABEL_ATTRIB, _L("File Info And Data Selection, file size: ") + GetFileSize(vsFileNames[0])); /// AW 05/18/07 ADD_FILE_SIZE
	else
		trGUI.SetAttribute(STR_LABEL_ATTRIB, _L("File Info And Data Selection")); 
	/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	
	trGUI.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN); ///---Sim 11-20-2006 SET_ATTRIBUTE
	return true; ///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
}

///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
//static void construct_tree_setting(string& strFileName, TreeNode& trSetting, int nInputMode)
static bool construct_tree_setting(string& strFileName, TreeNode& trSetting, int nInputMode, TreeNode& trPationSetting)
///---END HANDLE_ERROR_MESSAGE
{
	StringArray vsFileNames;
	separate_multiline_files(strFileName, vsFileNames); 
	/// Hong 06/29/07 MORE_ON_MOVE_SKIP_POINT_OPTIONS_FIX_PLOT_CONTROL_FAIL_WORK
	for (int ii = 0; ii < vsFileNames.GetSize(); ii++)
	{
		vsFileNames[ii] = cvt_predefined_path_to_real_path(vsFileNames[ii]);
	}
	/// end MORE_ON_MOVE_SKIP_POINT_OPTIONS_FIX_PLOT_CONTROL_FAIL_WORK

	//trSetting.RemoveChildrenWithPrefix(); ///---Sim 11-20-2006 SET_ATTRIBUTE no need
	///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
	//_construct_GUI_tree(trSetting, nInputMode, vsFileNames);
	//trSetting.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);
	return _construct_GUI_tree(trSetting, nInputMode, vsFileNames, trPationSetting);
	///---END HANDLE_ERROR_MESSAGE
}

///---Sim 05-05-2007 MOVE_SKIP_POINT_OPTIONS
static bool check_file_name_and_construct_tree_setting(TreeNode& trGetN, TreeNode& trFiles, string& strErrMsg, TreeNode& trPationSetting)
{
	string strFileName = trGetN.fname.strVal;
	trPationSetting.Show = true; /// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	if ( !check_imported_file_name(strFileName, strErrMsg) )
		return false;
	/// Hong 03/01/07 QA80-9418 REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION 
	/// Hong 06/11/07 v8.0638 ALLOW_LT_ACCESS_FOR_STIMULUS
	//if(trFiles && trFiles.GetNodeCount() > 0)
	if(trFiles && trFiles.Channels ) // node count is changes as moke_tree have constructor "Stimulus"
	/// end ALLOW_LT_ACCESS_FOR_STIMULUS
		return true; // no need construct tree setting
	/// REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION 
	if ( !construct_tree_setting(strFileName, trFiles, trGetN.options.inputmode.nVal, trPationSetting) )
	{
		// clean the trFiles on GUI
		/// Hong 06/11/07 v8.0638 ALLOW_LT_ACCESS_FOR_STIMULUS
		//trFiles.RemoveChildrenWithPrefix();		
		_reset_trfiles_tree(trFiles);		
		/// end ALLOW_LT_ACCESS_FOR_STIMULUS
		strErrMsg = CER_INVALID_IMPORT_DATA_FILE;
		return false;
	}
	
	return true;
}
///---END MOVE_SKIP_POINT_OPTIONS

/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
static bool _apply_theme_settings(const TreeNode& trTheme, TreeNode& trTarget)
{
	vector<int>		vnIDs;
	vector<string>	vsValues;
	vnIDs = trTheme.IDs.nVals;
	vsValues = trTheme.Values.strVals;
	tree_set_values_by_ids(trTarget, vnIDs, vsValues);
	return true;
}

static bool _get_theme_settings(const TreeNode& trSrc, TreeNode& trTheme)
{
	vector<int>		vnIDs;
	vector<string>	vsValues;
	tree_get_values_with_ids(trSrc, vnIDs, vsValues);
	trTheme.IDs.nVals = vnIDs;
	trTheme.Values.strVals = vsValues;
	return true;
}
	/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME

///---Sim 11-20-2006 SUPPORT_DND_OPEN_DIALOG
/// Hong 03/01/07 QA80-9418 REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION
//static bool file_name_event(TreeNode& trGetN, string& strErrMsg)
/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
//static bool file_name_event(TreeNode& trGetN, string& strErrMsg, bool bClearSetting = true) 
static bool file_name_event(TreeNode& trGetN, string& strErrMsg, bool bClearSetting = true, bool bThemeApplied = false)
/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
/// end REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION
{
	//string strFileName = trGetN.fname.strVal; ///---Sim 05-05-2007 MOVE_SKIP_POINT_OPTIONS
	TreeNode trFiles = trGetN.trfiles; ///---Sim 05-05-2007 MOVE_SKIP_POINT_OPTIONS

	///---Sim 05-05-2007 MOVE_SKIP_POINT_OPTIONS
	Tree trSkipPointsOptions;
	/// Hong 06/04/07 v8.0623 USE_MACRO_FOR_MORE_FRIENDLY_NAME
	//TreeNode tr = tree_get_node_by_tagname(trGetN, "SkipPointsOptions", true);
	TreeNode tr = tree_get_node_by_tagname(trGetN, STR_FILTER_PARTIAL_NODE, true);
	/// end USE_MACRO_FOR_MORE_FRIENDLY_NAME
	trSkipPointsOptions.Replace(tr);
	/// Hong 07/23/08 v8.0907 HIDEEN_PARTIAL_OPTIONS_IN_IWFILTER
	trSkipPointsOptions.Show = TRUE;
	/// end HIDEEN_PARTIAL_OPTIONS_IN_IWFILTER
	tr.Remove();
	///---END MOVE_SKIP_POINT_OPTIONS
	
	// clean the trFiles on GUI
	if( bClearSetting ) // Hong 03/01/07 QA80-9418 REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION
		/// Hong 06/11/07 v8.0638 ALLOW_LT_ACCESS_FOR_STIMULUS
		//trFiles.RemoveChildrenWithPrefix(); ///---Sim 05-05-2007 MOVE_SKIP_POINT_OPTIONS
		_reset_trfiles_tree(trFiles);
		/// end ALLOW_LT_ACCESS_FOR_STIMULUS
	
	///---Sim 05-05-2007 MOVE_SKIP_POINT_OPTIONS
	/*
	if ( !check_imported_file_name(strFileName, strErrMsg) )
		return false;
	/// Hong 03/01/07 QA80-9418 REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION 
	if(trGetN.trfiles && trGetN.trfiles.GetNodeCount() > 0)
		return true; // no need construct tree setting
	/// REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION 
	///---Sim 05-05-2007 MOVE_SKIP_POINT_OPTIONS
	//if ( !construct_tree_setting(strFileName, trNode, trGetN.options.inputmode.nVal, trGetN.options.SkipPointsOptions) )
	if ( !construct_tree_setting(strFileName, trNode, trGetN.options.inputmode.nVal, trSkipPointsOptions) )
	///---END MOVE_SKIP_POINT_OPTIONS
	{
		// clean the trFiles on GUI
		trNode.RemoveChildrenWithPrefix();
		strErrMsg = CER_INVALID_IMPORT_DATA_FILE;
		return false;
	}
	*/
	int bRet;
	bRet = check_file_name_and_construct_tree_setting(trGetN, trFiles, strErrMsg, trSkipPointsOptions);

	//tr = trFiles.FirstNode;
	//if ( !tr )
		tr = trFiles;
	/// Hong 05/15/07 v8.0618 CLEAN_PARTIAL_TO_DEFAULT_VALUE
	if ( bClearSetting ) /// Hong 06/28/07 v8.0652 FIX_REIMPOPRT_FROM_MENU_GET_DUPLICATE_PARTIAL_IMPORT_NODE
	{
		Tree trDefaultFilter;
		fuPrepareDefault(trDefaultFilter, FILTER_TYPE_XFUNC);
		tree_copy_values_by_id(trDefaultFilter, trSkipPointsOptions);
	}
	/// END CLEAN_PARTIAL_TO_DEFAULT_VALUE
	/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	//trSkipPointsOptions.Show = bRet;
	//tr.AddNode(trSkipPointsOptions);
	if ( !bRet )
		trSkipPointsOptions.Show = false;
	if ( trSkipPointsOptions.FirstNode.IsValid() )
		tr.AddNode(trSkipPointsOptions);
	/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT	
	
	/// Hong 04/08/09 QA80-13222 ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
	//_update_xfbar_status(trGetN); /// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
	/// end ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
	
	/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	if ( bThemeApplied )
		_apply_theme_settings(trGetN.thm, tr);
	_get_theme_settings(tr, trGetN.thm);
	/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	
	//return true;
	return bRet;
	///---END MOVE_SKIP_POINT_OPTIONS
}
/// Hong 02/09/07 NO_IMPORT_OUTPUT_IS_NO_DATA_SEL
/// Hong 05/16/07 SPEED_UP_BY_SAVE_MORE_INFO
//static bool is_no_data_sel(TreeNode& trSetting)
static bool is_no_data_sel(TreeNode& trSetting, int& nFirstCheckNode, int& nImpChannels, int& nImpSweeps)
/// END SPEED_UP_BY_SAVE_MORE_INFO
{
	nImpChannels = nImpSweeps = 0;
	nFirstCheckNode = -1;
	foreach(TreeNode trChannel in trSetting.Channels.Children)
	{
		if(1 == trChannel.nVal)
		{
			nImpChannels++;
		}
	}
	int nIndex = 0;
	foreach(TreeNode trSweep in trSetting.Sweeps.Children)
	{
		if(1 == trSweep.nVal)
		{
			if ( -1 == nFirstCheckNode)
				nFirstCheckNode = nIndex;
			nImpSweeps++;
		}
		nIndex++;
	}

	if ( 0 == nImpChannels && 0 == nImpSweeps )
		return true;
	
	return false;
}
/// end NO_IMPORT_OUTPUT_IS_NO_DATA_SEL

///---Sim 05-10-2007 TRUN_OFF_ADD_NOTE_WINDOW_SHEET
/////---Sim 05-04-2007 ADD_NOTE_WINDOW_SHEET
//void add_header_info_to_note_window_sheet(Worksheet& wks, int nCol, string strFileName, string strInfo)
//{
	///*
	//Worksheet wks("pClampInfo");
	//if ( !wks )
	//{
		//Layer lyActive = Project.ActiveLayer(); // hold active layer
		//WorksheetPage wp;
		//wp.Create("Origin.otw");
		//if ( !wp )
		//{
			//XF_WARN(_L("Failed to create header info sheet."));
			//return;
		//}
		//if ( lyActive ) // hold active layer
			//set_active_layer(lyActive);
		//
		//wp.SetName("pClampInfo");
		//wks = wp.Layers();
		//// set header
		//wks_set_show_labels(wks, RCLT_LONG_NAME, RCLT_COMMENT);
	//}
	//
	////// append to last of columns
	//int nCol;
	//nCol = wks_find_empty_column(wks);
	//if ( nCol < 0 )
	//{
		//nCol = wks.GetNumCols();
		//wks.AddCol();
	//}
	//
	//Column col(wks, nCol);
	//
	//col.SetLongName(GetFileName(strFileName));
	//col.SetComments("file properties");
	//*/
	//if ( !wks )
		//return;
	//
	//Column col(wks, nCol);
	//if ( !col )
		//return;
	//
	//vector<string> vsNames, vsValues;
	//get_user_parameters(col, vsNames, vsValues, true);
	//int nIndexUL;
	//nIndexUL = vsNames.Find("File Header");
	//if ( nIndexUL < 0 )
	//{
		//vsNames.Add("File Header");
		//vsValues.Add("");
		//set_user_parameters(col, vsNames, vsValues);
		//nIndexUL = vsNames.GetSize() - 1;
	//}
	//
	//int nLableID = RCLT_UDL + nIndexUL;
	//vector<int> vnTypes;
	//vnTypes.Add(nLableID);
	//wks_add_show_labels(wks, vnTypes, false);
	//
	//Grid grid;
	//grid.Attach(wks);
	//grid.GetShowLabels(vnTypes);
	//int nIndexLabel;
	//nIndexLabel = find_in_list(nLableID, vnTypes, false);
	//if ( nIndexLabel < 0 )
		//return;
	//nIndexLabel = (vnTypes.GetSize() - nIndexLabel) * -1;
	//
	//// Embed Note
	//DataRange dr;
	////dr.Add("cell", wks, 0, nCol, 0, nCol);
	//dr.Add("cell", wks, nIndexLabel, nCol, nIndexLabel, nCol);
	//
	//
	//XFBase xf("InsertNotes");
	//if ( !xf )
	//{
		//XF_WARN(_L("Failed to load InsertNotes xfunction."));
		//return;
	//}	
	//
	//xf.SetArg("str", strInfo);
	//xf.SetArg("cell", dr);
	//
	//if ( !xf.Evaluate() )
		//XF_WARN(_L("Failed to run InsertNotes xfunction."));
//}
/////---END ADD_NOTE_WINDOW_SHEET
///---END TRUN_OFF_ADD_NOTE_WINDOW_SHEET


void imppClamp(const string& fname, const TreeNode& trfiles, const TreeNode& options, Range& orng, TreeNode& trheader, const int& reimp, const TreeNode& thm)
{
	int nRet = 0; 
	
	///---Sim 10-30-2006 MAKE_INDIVIDUAL_FILE_INFO_FOR_EACH_FILE	
	/*
	Tree trInfo;
	if ( finfo )
		trInfo = finfo;
	*/
	Tree trBaseInfo; 
	/// Hong 01/08/06 FINFO_IS_ONLY_OUTPUT
	//if ( finfo )
		//trBaseInfo = finfo;
	/// end FINFO_IS_ONLY_OUTPUT
	///---END MAKE_INDIVIDUAL_FILE_INFO_FOR_EACH_FILE	
	
	//vector vImportedRangeUID; ///---Sim 02-06-2007 GET_RANGE_UID_OF_IMPORTED_FILE ///---Sim 05-18-2007 REMOVE_UID_VARIABLE remove
	
	int c1,c2; 
	Datasheet lyTarget;	
	/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
	//orng.GetRange(lyTarget, c1, c2);
	Page pgTarget;
	if ( !GetRangeInfo(orng, lyTarget, pgTarget, c1, c2) )
		XF_THROW(XFERR_INVALID_RANGE);
	/// end CENTRALIZE_CHECK_CALID_RANGE
	Worksheet wksTarget(lyTarget);
	if(!wksTarget.IsValid())
		XF_THROW(CER_INVALID_WKS);///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
	//s_pClampImport.ImportPClamp(wksTarget, trSetting, InputMode );
	/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
	//Page pgTarget;
	//wksTarget.GetParent(pgTarget);
	/// end CENTRALIZE_CHECK_CALID_RANGE
	/// Hong 01 25/07 REMOVE_AUTO_IMPORT_MODE
	/*
	///---Sim 09-28-2006 FIX_IMPORT_MODE_SHOWING_ORDER
	int nFileImportMode = _GetImportModeFromListIndex(impmode);
	///---END FIX_IMPORT_MODE_SHOWING_ORDER
	///---Sim 11-3-2006 SUPPORT_AUTO_MODE
	if ( ASCIMP_MODE_AUTO == nFileImportMode )
		nFileImportMode = ASCIMP_MODE_NEW_SHEETS;
	///---END SUPPORT_AUTO_MODE
	*/
	//int nFileImportMode = _GetImportModeFromListIndex(impmode + 1);///---Sim 01-29-2007 MORE_OPTIONS_FOR_IMPORT remove
	/// end REMOVE_AUTO_IMPORT_MODE
	
	///---Sim 01-29-2007 MORE_OPTIONS_FOR_IMPORT
	TreeNode tnUsingFilter;
	double dDefault = 0.;
	if ( fuGetDouble(options, IDE_DISP_IMP_ORIGINVER, dDefault) )
		tnUsingFilter = options;
	
	int nFileImportMode = fuGetImportMode(tnUsingFilter);
	
	///---Sim 08-06-2007 SUPPORT_SMART_SPARKLINE
	/*
	bool bSparkLines = fuGetSparkLine(tnUsingFilter);
	
	XFunction xfSparkLine;
	TreeNode trXFSparkLine;
	
	if ( bSparkLines )
	{
		if(!xfSparkLine.Load(&trXFSparkLine, "sparklines", 0, true, true, true))
		{
			XF_THROW(CER_FAILED_LOAD_SPK_LINE_XF);///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
			return;
		}
		xfSparkLine.SetArg("sel", 0);
	}
	*/
	int nSparklines = fuGetSparkLine(tnUsingFilter);
	///---END SUPPORT_SMART_SPARKLINE
	
	bool bTimeCol = fuGetShowTime(tnUsingFilter);
	//----- CPY 6/2/2007 ADDPLOT_CHANGED_TO_XFBAR
	#define STR_ADD_XFBAR "XFBar"
	// all usage of this is replaced below without comments
	//bool bAddPlot = true;
	//if ( options.addplot )
	//	bAddPlot = options.addplot.nVal;
	bool bAddXFBar = true;
	if(options.XFBar)
	{
		/// Hong 04/08/09 QA80-13222 ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
		///// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		bAddXFBar = options.XFBar.nVal;
		//TreeNode	trXFBar = options.XFBar;
		//bAddXFBar = trXFBar.nVal && tree_is_editable(trXFBar);
		///// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		/// end ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
	}
	//-----
	
	///---Sim 05-10-2007 TRUN_OFF_ADD_NOTE_WINDOW_SHEET
	/////---Sim 05-04-2007 ADD_NOTE_WINDOW_SHEET
	//bool bAddInfo = true;
	//if ( options.addinfo )
		//bAddInfo = options.addinfo.nVal;
	/////---END ADD_NOTE_WINDOW_SHEET
	///---END TRUN_OFF_ADD_NOTE_WINDOW_SHEET
	
	int nInputMode = 1;
	if ( options.inputmode )
		nInputMode = options.inputmode.nVal;
	
	///---END MORE_OPTIONS_FOR_IMPORT
	/// Hong 05/30/07 v8.0629b MORE_CHECK_FOR_DATA_SELECTION_SETTING
	//if ( trfiles.IsEmpty() && !fname.IsEmpty() )
	/// Hong 06/12/07 v8.0638 ALLOW_LT_ACCESS_FOR_STIMULUS
	//if ( (trfiles.IsEmpty() || 0 == trfiles.GetNodeCount() ) && !fname.IsEmpty() )
	/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT	
	//if ( (trfiles.IsEmpty() || !trfiles.Channels ) && !fname.IsEmpty() )		
	if ( (trfiles.IsEmpty() || (!trfiles.Channels && !trfiles.file1 ) ) && !fname.IsEmpty() )
	/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	/// end ALLOW_LT_ACCESS_FOR_STIMULUS
	/// end MORE_CHECK_FOR_DATA_SELECTION_SETTING
	{
		///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
		/// Hong 06/04/07 v.80634 USE_MACRO_FOR_MORE_FRIENDLY_NAME
		//if ( !construct_tree_setting(fname, trfiles, nInputMode,options.SkipPointsOptions) )
		/// Hong 06/29/07 MORE_ON_MOVE_SKIP_POINT_OPTIONS_FIX_PLOT_CONTROL_FAIL_WORK
		//if ( !construct_tree_setting(fname, trfiles, nInputMode,options.GetNode(STR_FILTER_PARTIAL_NODE)) )
		TreeNode trPartialOption = options.GetNode(STR_FILTER_PARTIAL_NODE);
		if ( !trPartialOption || !construct_tree_setting(fname, trfiles, nInputMode,trPartialOption) )
		/// end MORE_ON_MOVE_SKIP_POINT_OPTIONS_FIX_PLOT_CONTROL_FAIL_WORK
		/// end USE_MACRO_FOR_MORE_FRIENDLY_NAME
		{
			XF_THROW(CER_INVALID_IMPORT_DATA_FILE);
			return ;
		}
		///---END HANDLE_ERROR_MESSAGE
		/// Hong 06/29/07 MORE_ON_MOVE_SKIP_POINT_OPTIONS_FIX_PLOT_CONTROL_FAIL_WORK
		trfiles.AddNode( trPartialOption.Clone() );
		trPartialOption.Remove();
		/// end MORE_ON_MOVE_SKIP_POINT_OPTIONS_FIX_PLOT_CONTROL_FAIL_WORK
	}
	/// Hong 9/28/06 ADD_ERROR_MESSAGE_IF_FILE_INVALID
	/// Hong 05/30/07 v8.0629b MORE_CHECK_FOR_DATA_SELECTION_SETTING
	//if( trfiles.IsEmpty())//trSetting was constructed by file
	if( trfiles.IsEmpty() || 0 == trfiles.GetNodeCount() )
	/// end MORE_CHECK_FOR_DATA_SELECTION_SETTING
		XF_THROW(CER_INVALID_IMPORT_DATA_FILE);
	/// END ADD_ERROR_MESSAGE_IF_FILE_INVALID
	
	/// Hong 11/13/06 REMOVE_ONE_FILE_PER_GRAPH_FROM_GUI_TREE
	/*
	//// AW 10/24/06 ADD_MORE_OPTIONS_IN_PCLAMP
	GraphPage gp;
	GraphLayer gl;	
	if ( AddPlot && !OneFilePerGraph )
		/// SY 2006-11-03 v8.0505 ADD_SCALER_OBJECT
		///	{
		///		gp.Create(PlotTemplateName);
		///		gl = gp.Layers();	
		///	}
		_prepare_graph_page(gp, PlotTemplateName);
		/// end ADD_SCALER_OBJECT
	/// END ADD_MORE_OPTIONS_IN_PCLAMP	
	*/
	/// end REMOVE_ONE_FILE_PER_GRAPH_FROM_GUI_TREE
	
	/*
	/// SY 2006-11-03 v8.0505 ADD_SCALER_OBJECT
	int nCurCol, nChIndex, nChannels, nSweeps, nLayers = 0;
	string strUnits;
	StringArray saStrUnits;
	int nNumStimulus, nLyStimulus = -1; // the 1st stimulus layer
	/// end ADD_SCALER_OBJECT
	*/
	
	//// AW 11/07/06 MORE_WORK_ON_SHOW_TIME_COL
	// data has second sample rate, need add time column
	//bool bTimeCol = timecol; 	///---Sim 01-29-2007 MORE_OPTIONS_FOR_IMPORT remove
	/// Hong 12/09/06 NO_NEED_ADD_TIME_COLUMN
	//in pclamp2.0, all data will be convert to one sample rate
	//if ( !bTimeCol )
	//{
		//if ( s_pClampImport.HasSecondSamepleInterval() )
		//{
			//bTimeCol	= true;
		//}
	//}
	/// end NO_NEED_ADD_TIME_COLUMN
	/// END MORE_WORK_ON_SHOW_TIME_COL
	
	int nFileIndex = 0;
	int nIndexLayer = wksTarget.GetIndex();
	string strFileName, strColPre;
	BOOL bOK;
	/// Hong 05/18/07 v8.0621 REIMP_FROM_GRAPH_AUTO_PLOT
	bool bUpdateInfo = ( reimp_direct == reimp ) ? true : false;
	/// end REIMP_FROM_GRAPH_AUTO_PLOT
	/// 12/27/06 REMOVE_STATIC_OBJECT	
	StringArray vsFileNames, vsOriginFnames; 
	separate_multiline_files(fname, vsFileNames); 
	/// Hong 12/06/07 v8.0762 IMPORT_SUPPORT_RELATIVE_PATH_FOR_REIMPORT_SAMPLE_REQUIREMENT
	vsOriginFnames = vsFileNames;
	for (int ii = 0; ii < vsFileNames.GetSize(); ii++)
	{
		vsFileNames[ii] = cvt_predefined_path_to_real_path(vsFileNames[ii]);
	}
	/// end IMPORT_SUPPORT_RELATIVE_PATH_FOR_REIMPORT_SAMPLE_REQUIREMENT
	pClampImport pciFiles;
	pciFiles.SetFileName(vsFileNames);
	/// end REMOVE_STATIC_OBJECT
	/// Hong 02/03/09 QA80-12413-P3 FIX_HOLDING_DURATION_OPTION_LOST_WHEN_MUTLPLE_FILES
	// Hong code below will NOT work in multiple files case
	//if(trfiles.bHoldingDuration)
	//	pciFiles.UseHoldingDuration(trfiles.bHoldingDuration.nVal);
	/// end FIX_HOLDING_DURATION_OPTION_LOST_WHEN_MUTLPLE_FILES
	/// Fisher 01/07/09 QA80-12413 ADD_HOLDING_DURATION_TIME_IN_PCLAMP
	
	/// End ADD_HOLDING_DURATION_TIME_IN_PCLAMP
	
	/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	/// Hong 05/14/07 v8.0617 MOVE_FILE_NODE_AS_SINGLE_FILE
	bool bSingleFile = (1 == vsFileNames.GetSize()) ? true : false;
	// in multiple files case, remove Partial option from trfiles as not used, later we may think about each file setting own a Partial option 
	if ( !bSingleFile )
	{
		TreeNode tr = tree_get_node_by_tagname(trfiles, STR_FILTER_PARTIAL_NODE, true);
		if ( tr.IsValid() )
			tr.Remove();
	}
	///---Sim 03-11-2008 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	//foreach(TreeNode trFileNode in trfiles.Children )	
	TreeNode trFileNode;
	int nNumFiles = bSingleFile ? 1 : trfiles.Children.Count();
	for ( nFileIndex = 0; nFileIndex < nNumFiles; nFileIndex++ )
	///---END QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	//TreeNode trFileNode;
	//trFileNode = trfiles;
	/// END MOVE_FILE_NODE_AS_SINGLE_FILE
	/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	{
		/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT		
		if ( bSingleFile )
			trFileNode = trfiles;
		///---Sim 03-11-2008 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		else
			trFileNode = trfiles.Children.Item(nFileIndex);
		///---END QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		/// Hong 02/09/07 NO_IMPORT_OUTPUT_IS_NO_DATA_SEL
		/// Hong 05/16/07 SPEED_UP_BY_SAVE_MORE_INFO
		//if( is_no_data_sel(trFileNode) )
		int nFirstCheckNode, nImpChannels, nImpSweeps;
		if( is_no_data_sel(trFileNode, nFirstCheckNode, nImpChannels, nImpSweeps) )
		/// END SPEED_UP_BY_SAVE_MORE_INFO
		{
			/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
			/// Hong 05/14/07 v8.0617 MOVE_FILE_NODE_AS_SINGLE_FILE
			XF_WARN_EX(XFERR_NO_DATA_SELECT, vsFileNames[nFileIndex]);
			///---Sim 03-11-2008 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
			/*
			nFileIndex++;
			if ( !bSingleFile )
				continue;
			else
				return ;
			*/
			continue;
			///---END QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
			//XF_THROW_EX(XFERR_NO_DATA_SELECT, vsFileNames[nFileIndex]);
			//return ;
			/// END MOVE_FILE_NODE_AS_SINGLE_FILE
			/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		}
		/// end NO_IMPORT_OUTPUT_IS_NO_DATA_SEL
		///---Sim 02-28-2007 TEMPLATE_FILE_IN_DATA_FOLDER
		//wksTarget = GetTargetLayer(pgTarget, nIndexLayer, nFileIndex, tnUsingFilter, true, orng, nFileImportMode, c1, bTimeCol); ///---Sim 09-28-2006 FIX_IMPORT_MODE_SHOWING_ORDER
		//trFileNode.GetAttribute(STR_LABEL_ATTRIB, strFileName);
		//if ( !s_pClampImport.GetpClampFileName(nFileIndex, strFileName) ) 
		if ( !pciFiles.GetpClampFileName(nFileIndex, strFileName) )// 12/27/06 REMOVE_STATIC_OBJECT
		{
			XF_THROW(CER_INVALID_IMPORT_DATA_FILE); ///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
				return;
		}	
		
		/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		if ( trFileNode.ShowTimeCol )
			bTimeCol = trFileNode.ShowTimeCol.nVal;
		/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		
		///---Sim 04-30-2007 TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
		//if ( 0 == nFileIndex && !reimp )
		//{
			//int nImportMode = get_first_file_import_mode(FILE_TYPE_PCLAMP);
			//TreeNode trInValid;
			//
			//wksTarget = GetTargetLayer(pgTarget, nIndexLayer, nFileIndex, trInValid, true, orng, nImportMode, c1, bTimeCol, c2, GetFilePath(strFileName));
		//}
		//else
		//{
		wksTarget = GetTargetLayer(pgTarget, nIndexLayer, nFileIndex, tnUsingFilter, true, orng, nFileImportMode, c1, bTimeCol, c2, GetFilePath(strFileName));
		//}
		///---END TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
		///---END TEMPLATE_FILE_IN_DATA_FOLDER
		/// Hong 10/18/06 QA80-9058 MORE_ADD_PLOT_IN_PCLAMP
		//int nStartCol = c1;
		/// end MORE_ADD_PLOT_IN_PCLAMP
		///---turn on rename
		/// Hong 12/06/06 TEMP_DISABLE_RENAME_TO_FIX_DATA_RANGE_INVALID
		// for Append-col mode, first file's DataRange save in organizer will
		// become invalid after rename
		strColPre = GetFileName(strFileName);
		//if ( fuIsFileNameToWksLabel(trFilter) )
		//if ( fuIsRenameWks(trFilter) ) // Hong 01/23/07 FIX_ERROR_GET_RENAME_FROM_FILTER
			//wksTarget.SetName(strColPre, OCD_ENUM_NEXT);/// Hong 11/30/06 FIX_WKS_SHORT_NAME_NOT_UNIQUE	
		/// end TEMP_DISABLE_RENAME_TO_FIX_DATA_RANGE_INVALID
		///---
		///---Sim 10-30-2006 MAKE_INDIVIDUAL_FILE_INFO_FOR_EACH_FILE
		/// Hong 01/08/06 FINFO_IS_ONLY_OUTPUT
		//Tree trInfo;
		//trInfo.Replace(trBaseInfo);
		string strFile;
		strFile.Format("File%d", nFileIndex + 1); // file index to be 1
		TreeNode trInfo = trBaseInfo.AddNode(strFile);
		/// end FINFO_IS_ONLY_OUTPUT
		///---END MAKE_INDIVIDUAL_FILE_INFO_FOR_EACH_FILE		
		/// Hong 12/19/06 ADD_MATH_CHANNEL_FOR_SELECTION
		bool bAddMathChannel = false;
		if(trFileNode.Channels.MathChannelName)
		{
			bAddMathChannel = trFileNode.Channels.MathChannelName.nVal;
			trFileNode.Channels.MathChannelName.nVal = 0; // disable math import in ImportOnepClampFile
		}
		/// end ADD_MATH_CHANNEL_FOR_SELECTION		
		
		/// Hong 02/03/09 QA80-12413-P3 FIX_HOLDING_DURATION_OPTION_LOST_WHEN_MUTLPLE_FILES		
		if ( trFileNode.bHoldingDuration )
			pciFiles.UseHoldingDuration(trFileNode.bHoldingDuration.nVal);
		/// end FIX_HOLDING_DURATION_OPTION_LOST_WHEN_MUTLPLE_FILES
	
		waitCursor junk; /// Hong 05/15/07 v8.0617 add wait Cursor indicated importing
		///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
		int nRet;
		
		//bTimeCol = 1; // Should not turn on time column
		//if ( nRet = s_pClampImport.ImportOnepClampFile(wksTarget, nFileIndex, trFileNode, trInfo, InputMode, bTimeCol, c1, strColPre ) ) 
		if ( nRet = pciFiles.ImportOnepClampFile(wksTarget, nFileIndex, trFileNode, trInfo, nInputMode, bTimeCol, c1, c2, strColPre ) )// 12/27/06 REMOVE_STATIC_OBJECT
		{
			XF_THROW_EX(nRet, strColPre);
			return;
		}
		///---END HANDLE_ERROR_MESSAGE
		/// Hong 11/9/06 TEMP_OPEN_SUPPORT_GAPFREE_MODE 
		// always imported gapfree mode file in channel mode
		//pCLAMPFile* ppClampFile = s_pClampImport.GetpClampFile(nFileIndex); 
		pCLAMPFile* ppClampFile = pciFiles.GetpClampFile(nFileIndex);// 12/27/06 REMOVE_STATIC_OBJECT
		int nCurInputMode = nInputMode;
		if( ABF_GAPFREEFILE == ppClampFile->GetOperationMode() )
			nCurInputMode = 0;
		/// end TEMP_OPEN_SUPPORT_GAPFREE_MODE
		/// Hong 12/20/06 SAVE_INFO_AS_TREE
		/*
		///---Sim 10-18-2006 PUT_TAG_INTO_FILE_INFO
		pCLAMPFile* ppClampFile = s_pClampImport.GetpClampFile(nFileIndex);
		BOOL bHasTag;
		
		string strTag;
		strTag = ppClampFile->GetTags(&bHasTag);
		if ( bHasTag )
		{
			TreeNode trTag = trInfo.AddNode("FileTags");
			trTag.strVal = strTag;
			trTag.ID = TRGP_MULTILINE_TEXT;
		}
		///---END PUT_TAG_INTO_FILE_INFO
		*/
		Tree tr; 
		//if( s_pClampImport.GetTagsToPlot(tr, nFileIndex, InputMode) ) 
		if( pciFiles.GetTagsToPlot(tr, nFileIndex, nInputMode) )// 12/27/06 REMOVE_STATIC_OBJECT
		{
			TreeNode trTag = trInfo.AddNode("FileTags");
			trTag.Replace(tr.Clone(), true, true);
		}
		/// end SAVE_INFO_AS_TREE
		
		int nMath = 0;
		if(bAddMathChannel)
		{
			//s_pClampImport.GetMath(trFileNode, nFileIndex, nInputMode); // Hong 12/09/06 READ_MATH_CHANNEL 
			/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
			//pciFiles.GetMath(trFileNode, nFileIndex, nCurInputMode);// 12/27/06 REMOVE_STATIC_OBJECT
			pciFiles.GetMath(trFileNode, nFileIndex, nCurInputMode, bTimeCol);
			/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
			trFileNode.Channels.MathChannelName.nVal = 1;
			nImpChannels++; /// Hong 05/16/07 SPEED_UP_BY_SAVE_MORE_INFO
		}
		/// Hong 11/30/06 DEFAULT_TO_ADD_STIMULUS_INTO_WORKSHEET
		int nWavStimulus = 0, nDigitStimulus = 0;
		//nWavStimulus = s_pClampImport.GetStimulus(nDigitStimulus, nFileIndex, nInputMode); 
		//nWavStimulus = pciFiles.GetStimulus(nDigitStimulus, nFileIndex, nCurInputMode);// 12/27/06 REMOVE_STATIC_OBJECT
		/// Hong 05/14/07 v8.0617 ADD_STIMULUS_SELECT_OPTION
		if ( trFileNode.Stimulus.nVal )
		/// END ADD_STIMULUS_SELECT_OPTION
			/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
			//nWavStimulus = pciFiles.GetStimulus(nDigitStimulus, nFileIndex, nCurInputMode, trFileNode);// Hong 02/08/07 ADD_DATA_SELECTION_SUPPORT
			nWavStimulus = pciFiles.GetStimulus(nDigitStimulus, nFileIndex, nCurInputMode, trFileNode, true, bTimeCol);
			/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		/// end DEFAULT_TO_ADD_STIMULUS_INTO_WORKSHEET
		// ------Import one file finish	
		
		/// Hong 12/07/07 FIX_SPARK_LINE_DISAPPEAR
		//int nLine4 = -1;
		//int nLine5 = -1;
		int nColNum = wksTarget.GetNumCols();
		/// end FIX_SPARK_LINE_DISAPPEAR
		pciFiles.GetImportRange(c1, c2); // Hong 02/06/07 GET_MORE_SAFE_IMPORT_RANGE
		///---Sim 05-05-2007 MOVE_SKIP_POINT_OPTIONS
		//reduce_data(wksTarget, c1, c2, tnUsingFilter); ///---Sim 02-28-2007 QA80-9391 IMPORT_FILE_SKIP_DATA_POINTS
		reduce_data(wksTarget, c1, c2, trFileNode); ///---Sim 02-28-2007 QA80-9391 IMPORT_FILE_SKIP_DATA_POINTS
		///---END MOVE_SKIP_POINT_OPTIONS
		///---Sim 08-06-2007 SUPPORT_SMART_SPARKLINE
		/*
		if( bSparkLines )
		{
			/#
			XFunction xfSparkLine;
			TreeNode trXFSparkLine;
	
			if(!xfSparkLine.Load(&trXFSparkLine, "sparklines", 0, true, true, true))
			{
				XF_THROW(IMPERR_IMPORT_FUNC_ERR);// a better global err for not matching book would be better
					return;
			}
			xfSparkLine.SetArg("sel", 0);
			#/
			/// Hong 12/07/07 FIX_SPARK_LINE_DISAPPEAR
			xfSparkLine.SetArg("c1", c1+1);
			//xfSparkLine.SetArg("c2", nColNum);
			xfSparkLine.SetArg("c2", c2+1); // Hong 02/06/07 GET_MORE_SAFE_IMPORT_RANGE		
			/// end FIX_SPARK_LINE_DISAPPEAR
			xfSparkLine.SetArg("wks", wksTarget);
			if ( !xfSparkLine.Evaluate() )
			{
				XF_THROW(CER_SPK_LINE_RUN_ERROR); ///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
				return;	
			}
		}
		*/
		bool bSparklines = update_sparkline(nSparklines, wksTarget, c1, c2);
		///---END SUPPORT_SMART_SPARKLINE
		/// Hong 12/07/07 FIX_SPARK_LINE_DISAPPEAR
		/*
		if( bTimeCol )
		{
			if ( sparklines )
				nLine4 = RCLT_SPARKLINE;	
		}
		else
		{
			nLine4 = RCLT_SAMPLE_RATE;		
			if ( sparklines ) 
				nLine5 = RCLT_SPARKLINE;	
		}
		wks_set_show_labels(wksTarget, RCLT_LONG_NAME, RCLT_UNIT, RCLT_COMMENT, nLine4, nLine5);
		*/
		vector<int> vn = {RCLT_LONG_NAME, RCLT_UNIT, RCLT_COMMENT}; 
		/*
		if( bTimeCol )
		{
			if ( bSparkLines )
				vn.Add(RCLT_SPARKLINE);	
		}
		else
		{
			vn.Add(RCLT_SAMPLE_RATE);
			if ( bSparkLines ) 
				vn.Add(RCLT_SPARKLINE);	
		}
		*/
		if( !bTimeCol )
			vn.Add(RCLT_SAMPLE_RATE);
		///---Sim 08-06-2007 SUPPORT_SMART_SPARKLINE
		//if ( bSparkLines ) 
		if ( bSparklines )
		///---END SUPPORT_SMART_SPARKLINE
			vn.Add(RCLT_SPARKLINE);
		wks_add_show_labels(wksTarget, vn, false);
		/// end FIX_SPARK_LINE_DISAPPEAR
		
		///---Sim 02-06-2007 CORRECT_RANGE_STRING_DISPLAY
		/// Hong 11/30/06 STORAGE_MORE_INFO_FOR_PLOT
		// later should make this a static function
		DataRange drImported;
		//drImported.Add(wksTarget, c1, "Y");
		//drImported.SetRange(0, wksTarget, 0, c1, -1, nColNum - 1);
		//drImported.SetRange(0, wksTarget, 0, c1, -1, c2); // Hong 02/06/07 GET_MORE_SAFE_IMPORT_RANGE
		drImported.Add(wksTarget, c1, STR_RANGE_STR, c2);
		///---END CORRECT_RANGE_STRING_DISPLAY
		Tree trTemp;
		drImported.GetTree(trTemp);
		TreeNode trPlot, trSeclect, trRange;
		
		//trPlot = trInfo.AddNode("Plot");
		trPlot = trInfo.AddNode("Import");
		trPlot.Show = 0; // Hong 05/24/07 HIDDEN_FROM_ORGANIZER
		trSeclect = trPlot.AddNode("trSetting");
		
		trSeclect.Replace(trFileNode.Clone(), true, true);
		/// Hong 05/18/07 v8.0621 ENABLE_PARTIAL_OPTION_WHEN_REIMP
			if (reimp_import != reimp) // re-enable for plot
		{
			trSeclect.Channels.Enable = 1;
			trSeclect.Sweeps.Enable = 1;
		}
		/// end ENABLE_PARTIAL_OPTION_WHEN_REIMP
		//trRange = trPlot.AddNode("DataRange");
		//trRange.Replace(trTemp.Clone(), true, true);
		/// Hong 05/15/07 INFO_NODE_IS_NEEDED_WHEN_REIMPORT
		//trSeclect.RemoveChild("InfoFileNormal");	/// AW 05/11/07 REMOVE_EXTRA_INFO
		trSeclect.InfoFileNormal.Show = 0; // only NOT show in plot and plot control GUI, but reshow in reimport with dialog
		/// END INFO_NODE_IS_NEEDED_WHEN_REIMPORT
		/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		if ( trSeclect.ShowTimeCol )
			trSeclect.ShowTimeCol.Show = 0; // only NOT show in plot and plot control GUI, but reshow in reimport with dialog
		/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		
		trPlot.AddNumericNode(nCurInputMode, "InputMode");
		trPlot.AddNumericNode(nMath, "Math");
		trPlot.AddNumericNode(nWavStimulus, "WavStimulu");
		trPlot.AddNumericNode(nDigitStimulus, "DigStimulu");
		/// Hong 05/16/07 SPEED_UP_BY_SAVE_MORE_INFO
		/// Hong 04/08/09 QA80-13222 ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
		//int nColIndex = c1;
		int nColIndex = bTimeCol ? c1 + 1 : c1;
		/// end ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
		foreach (TreeNode trSweep in trSeclect.Sweeps.Children)
		{
			if (trSweep.nVal)
				trSweep.SetAttribute("PCLAMP_ColIndex", nColIndex++);
		}
		
		///---Sim 04-16-2009 QA80-13318 IMPROVE_HONG_FIX_REIMPORT_FAIL_GET_CORRECT_ROW_NUM
		///// Hong 04/16/09 QA80-10360-P13 FIX_START_TIME_INCORRECT_IF_NOT_IMPORT_FROM_FIRST_SWEEP
		//// Hong, dEpisode index start from 1, NOT 0.
		////double dX0 = pciFiles.GetStartTime(nFileIndex, 0, nFirstCheckNode);
		//double dX0 = pciFiles.GetStartTime(nFileIndex, 0, nFirstCheckNode + 1);
		///// end FIX_START_TIME_INCORRECT_IF_NOT_IMPORT_FROM_FIRST_SWEEP
		//double dTempX = 0, dTempInc = 0;
		//Column col(wksTarget, c1);		
		///---END QA80-13318 IMPROVE_HONG_FIX_REIMPORT_FAIL_GET_CORRECT_ROW_NUM
		/// Hong 01/15/09 FIX_PCLAMP_PLOT_FAIL_HANDLE_TIME_OFFSET_OF_HOLDING_DURATION
		double	dHoldingDuration = pciFiles.GetHoldingDuration(nFileIndex);
		if ( trSeclect.bHoldingDuration )
		{
			trSeclect.bHoldingDuration.SetAttribute(STR_HOLDING_DURATION, dHoldingDuration);
			/// Hong 04/16/09 DISABLE_HOLDING_DURATION_WHEN_ADD_TIME_COL
			trSeclect.bHoldingDuration.Enable = bTimeCol ? ENABLE_READ_ONLY : ENABLE;
			/// end DISABLE_HOLDING_DURATION_WHEN_ADD_TIME_COL
		}
		/// end FIX_PCLAMP_PLOT_FAIL_HANDLE_TIME_OFFSET_OF_HOLDING_DURATION
		///---Sim 04-16-2009 QA80-13318 IMPROVE_HONG_FIX_REIMPORT_FAIL_GET_CORRECT_ROW_NUM
		///// Hong 04/08/09 QA80-13222 ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
		////col.IsEvenSampling(&dTempX, &dTempInc);
		////double dXOffset = dTempX - dX0;
		//double dXOffset = dX0;
		///// Hong 04/09/09 QA80-13318 FIX_REIMPORT_FAIL_GET_CORRECT_ROW_NUM_IF_HAVE_HOLDING_DURATION_OFFSET_AND_SHOW_TIME_COL
		//if ( trSeclect.bHoldingDuration && 1 == trFileNode.bHoldingDuration.nVal )
			//dXOffset -= dHoldingDuration;
		///// end FIX_REIMPORT_FAIL_GET_CORRECT_ROW_NUM_IF_HAVE_HOLDING_DURATION_OFFSET_AND_SHOW_TIME_COL
		//if ( col.IsEvenSampling(&dTempX, &dTempInc) )
		 	//dXOffset = dTempX - dX0;
		///// end ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
		///---END QA80-13318 IMPROVE_HONG_FIX_REIMPORT_FAIL_GET_CORRECT_ROW_NUM
		
		
		///---Sim 04-16-2009 QA80-13318 IMPROVE_HONG_FIX_REIMPORT_FAIL_GET_CORRECT_ROW_NUM
		///// AW 05/17/07 FIX_REIMPORT_PROBELM
		////trPlot.AddNumericNode(dXOffset, "XOffset");
		///// Hong 06/04/07 v.80634 USE_MACRO_FOR_MORE_FRIENDLY_NAME
		////TreeNode trSkipPointsOptions = trSeclect.SkipPointsOptions;
		//TreeNode trSkipPointsOptions = trSeclect.GetNode(STR_FILTER_PARTIAL_NODE);
		///// end USE_MACRO_FOR_MORE_FRIENDLY_NAME
		//if ( trSkipPointsOptions )
			//trSkipPointsOptions.SetAttribute(STR_PARTIAL_START_TIME, dXOffset);
		///// END FIX_REIMPORT_PROBELM
		///---END QA80-13318 IMPROVE_HONG_FIX_REIMPORT_FAIL_GET_CORRECT_ROW_NUM
	
		
		trPlot.AddNumericNode(nImpChannels, "ImpChannels");
		trPlot.AddNumericNode(nImpSweeps, "ImpSweeps");
		/// end SPEED_UP_BY_SAVE_MORE_INFO
		
		//int nSweepNum = _get_num_sweep(nFileIndex, nInputMode); 
		int nSweepNum = _get_num_sweep(nFileIndex, nCurInputMode, pciFiles);// 12/27/06 REMOVE_STATIC_OBJECT
		trPlot.AddNumericNode(nSweepNum, "SweepNum");
		//double dEndTiem = s_pClampImport.GetEndTime(nFileIndex, nInputMode);
		//trPlot.AddNumericNode(dEndTiem, "EndTime");
		/// end STORAGE_MORE_INFO_FOR_PLOT
		/// Hong 02/12/07 START_TIME_ALREADY_IN_SAMPLING_INTERVAL
		/*
		vector vdTime;
		//s_pClampImport.GetSweepStartTime(vdTime, nFileIndex); 
		pciFiles.GetSweepStartTime(vdTime, nFileIndex);// 12/27/06 REMOVE_STATIC_OBJECT
		TreeNode trStartTime = trPlot.AddNode("StartTime");
		trStartTime.dVals = vdTime;
		trStartTime.SetAttribute(STR_LABEL_ATTRIB, "Sweep Start Times");
		trStartTime.Show = 0; // hidden from GUI
		*/
		/// end START_TIME_ALREADY_IN_SAMPLING_INTERVAL
		
		///---Sim 02-01-2007 RENAME_CENTRALIZED
		// rename 
		///---Sim 03-20-2007 FIX_APPEND_COMMENT_WHEN_REIMPORT
		DWORD dwCtrl = 0;
		/// Hong 05/18/07 v8.0621 REIMP_FROM_GRAPH_AUTO_PLOT
		//dwCtrl |= (reimp) ? COVER_LAST_ADDED_COMMENT : 0;
		dwCtrl |= ( !bUpdateInfo ) ? COVER_LAST_ADDED_COMMENT : 0;
		/// end REIMP_FROM_GRAPH_AUTO_PLOT
		setPageAndLayerName(drImported, vsFileNames[nFileIndex], tnUsingFilter, dwCtrl);
		///---END FIX_APPEND_COMMENT_WHEN_REIMPORT
		///---END RENAME_CENTRALIZED
	
		/// Hong 07/24/08 QA80-11869 ONLY_DRAG_AND_DROP_SUPPOORT_LT_SCRIPT_BY_NOW
		/* CP said it's OK to disable XF LT script support, otherwise too much code needed for SR3
		///---Sim 03-09-2007 ADD_SCRIPT_TO_IMPORT_XF
		string strLTScript;
		if( fuGetPostImportScript(tnUsingFilter, strLTScript) && !strLTScript.IsEmpty() )
		{
			wksTarget.LT_execute(strLTScript);
		}
		///---END ADD_SCRIPT_TO_IMPORT_XF
		*/
		/// end ONLY_DRAG_AND_DROP_SUPPOORT_LT_SCRIPT_BY_NOW
		
		///---Sim 02-01-2007 ADD_RANGE_INFO
		// add data range info
		//addRangeInfo(trInfo, wksTarget, c1);
		Tree trDataRange;
		///---Sim 05-18-2007 REMOVE_UID_VARIABLE
		//int UID = getRangeInfo(trDataRange, drImported);
		getRangeInfo(trDataRange, drImported);
		//vImportedRangeUID.Add(UID);
		///---END REMOVE_UID_VARIABLE
		
		// if current file cover existing file data, need update info of that files
		/// Hong 05/18/07 v8.0621 REIMP_FROM_GRAPH_AUTO_PLOT
		//if (!reimp)
		if ( !bUpdateInfo )
		/// end REIMP_FROM_GRAPH_AUTO_PLOT
			impinfo_UpdateExistingData(pgTarget, drImported);
	
		//impinfo_AddFile(wksTarget, strFileName, trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter); ///---Sim 02-01-2007 UPDATE_FILTER_TREE
		/// Hong 03/12/07 QA80-9418-S1 ONLY_UPDATE_BINARY_INFO_WHEN_REIMPORT
		//impinfo_AddFile(wksTarget, strFileName, trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter, nFileIndex + 1, trDataRange);
		/// Hong 05/18/07 v8.0621 REIMP_FROM_GRAPH_AUTO_PLOT
		//impinfo_AddFile(wksTarget, strFileName, trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter, nFileIndex + 1, trDataRange, reimp);
		/// Hong 12/06/07 v8.0762 IMPORT_SUPPORT_RELATIVE_PATH_FOR_REIMPORT_SAMPLE_REQUIREMENT
		//impinfo_AddFile(wksTarget, strFileName, trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter, nFileIndex + 1, trDataRange, bUpdateInfo);
		impinfo_AddFile(wksTarget, vsOriginFnames[nFileIndex], trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter, nFileIndex + 1, trDataRange, bUpdateInfo);
		/// end IMPORT_SUPPORT_RELATIVE_PATH_FOR_REIMPORT_SAMPLE_REQUIREMENT
		/// end REIMP_FROM_GRAPH_AUTO_PLOT
		/// end ONLY_UPDATE_BINARY_INFO_WHEN_REIMPORT
		///---END ADD_RANGE_INFO
		
		///---Sim 05-10-2007 TRUN_OFF_ADD_NOTE_WINDOW_SHEET
		/*
		///---Sim 05-04-2007 ADD_NOTE_WINDOW_SHEET
		if ( bAddInfo )
			add_header_info_to_note_window_sheet(wksTarget, c1, strFileName, ppClampFile->GetHeaderInfo(INFO_LONG));
		///---END ADD_NOTE_WINDOW_SHEET
		*/
		///---END TRUN_OFF_ADD_NOTE_WINDOW_SHEET
		
		///---Sim 03-11-2008 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		//nFileIndex++;
		///---END QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	
		/// Hong 04/08/09 QA80-13222 ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
		///// Hong 04/07/09 FIX_PCLAMP_CONTROL_STILL_SHONW_WHEN_SHOW_TIME_COL_IN_LT
		if( bAddXFBar )
		//if( bAddXFBar && !bTimeCol )
		///// end FIX_PCLAMP_CONTROL_STILL_SHONW_WHEN_SHOW_TIME_COL_IN_LT
		/// end ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
		{
			/// Hong 04/13/07 QA80-9614 FIX_CRASH_IF_RUN_FROM_ORGANIZER
			//LT_execute("plotpclamp -db");// Hong 12/02/06 ATTACH_XF_TO_WKS
			/// Hong 04/17/07 v8.0602b ONLY_NEED_DELAY_XFBAR_WHEN_REIMPORT
			/// Hong 05/18/07 v8.0621 REIMP_FROM_GRAPH_AUTO_PLOT
			//if ( reimp )
				//LT_execute(";plotpclamp -db");
			//else
				//LT_execute("plotpclamp -db");
			string strLTPlot;
			/// Hong 05/31/07 v8.0630 FIX_ORIGIN_CRASH_IF_RUN_FROM_LT
			/* delay is always needed if XF try to run another XF by LT_, window name is needed too to indicate which page to run this XF
			switch ( reimp )
			{
			case REIMP_IMPORT:
				LT_execute("plotpclamp -db");
				break;
			case REIMP_REIMPORT:
				LT_execute(";plotpclamp -db");
				break;
			case REIMP_GRAPH_REIMPORT:
				// this code fail to active Graph Page, don't know why
				//XFBase xfPlot("plotpclamp");
				//if (xfPlot)
				//{
					//xfPlot.SetArg("ctrl", 0);
					//int nErr;
					//xfPlot.ExecuteLabTalk(NULL, NULL, NULL, 0, &nErr, 0);
				//}
				LT_execute(";plotpclamp ctrl:=0");
				break;
			}
			*/			
			string strName = pgTarget.GetName();
			/// Hong 06/12/07 v8.0639 UPDATE_WITH_UID_SUPPORT_IN_LT
			string strScript;
			strScript.Format("int nUID = range2uid([%s]);", strName);
			LT_execute(strScript);
			double dUID;
			LT_get_var("nUID",  &dUID);
			strLTPlot.Format(";string strPageName$ = uid2name(%d)$; win -o strPageName$ {plotpclamp -db}", (int)dUID);
			/// end UPDATE_WITH_UID_SUPPORT_IN_LT
			switch ( reimp )
			{
			case reimp_import:
				/// Hong 06/04/07 v8.0632 XFBAR_MISS_BOOK_WHEN_IMPORT_FROM_SCRIPT
				show_xf_bar(pgTarget, SXFB_OPEN_INDEPENDENT, "plotpclamp");
				break;
				/// end XFBAR_MISS_BOOK_WHEN_IMPORT_FROM_SCRIPT
			case reimp_direct:
				/// Hong 06/12/07 v8.0639 UPDATE_WITH_UID_SUPPORT_IN_LT
				//strLTPlot.Format(";win -o %s {plotpclamp -db}", strName);
				strLTPlot.Format(";string strPageName$ = uid2name(%d)$; win -o strPageName$ {plotpclamp -db}", (int)dUID);
				/// end UPDATE_WITH_UID_SUPPORT_IN_LT
				LT_execute(strLTPlot); /// Hong 06/04/07 v8.0632 XFBAR_MISS_BOOK_WHEN_IMPORT_FROM_SCRIPT
				break;
			case reimp_graph:
				/// Hong 06/12/07 v8.0639 UPDATE_WITH_UID_SUPPORT_IN_LT
				//strLTPlot.Format(";win -o %s {plotpclamp ctrl:=0}", strName);
				strLTPlot.Format(";string strPageName$ = uid2name(%d)$; win -o strPageName$ {plotpclamp ctrl:=0}", (int)dUID);
				/// end UPDATE_WITH_UID_SUPPORT_IN_LT
				LT_execute(strLTPlot); /// Hong 06/04/07 v8.0632 XFBAR_MISS_BOOK_WHEN_IMPORT_FROM_SCRIPT
				break;
			}
			/// Hong 06/04/07 v8.0632 XFBAR_MISS_BOOK_WHEN_IMPORT_FROM_SCRIPT
			//LT_execute(strLTPlot);
			/// end XFBAR_MISS_BOOK_WHEN_IMPORT_FROM_SCRIPT
			/// end FIX_ORIGIN_CRASH_IF_RUN_FROM_LT
			/// end REIMP_FROM_GRAPH_AUTO_PLOT
			/// end ONLY_NEED_DELAY_XFBAR_WHEN_REIMPORT
			/// end FIX_CRASH_IF_RUN_FROM_ORGANIZER
		}
		/// Hong 05/25/07 ATTACH_XF_NAME_ALLOW_REOPEN_EVEN_UNCHECK_ADDPLOT
		/// Hong 04/08/09 QA80-13222 ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
		///// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		if ( !bAddXFBar || reimp_graph == reimp ) 
		///// Hong 04/07/09 FIX_PCLAMP_CONTROL_STILL_SHONW_WHEN_SHOW_TIME_COL_IN_LT
		////TreeNode		trXFBar = options.XFBar;
		////if ( (!bAddXFBar || reimp_graph == reimp) && (tree_is_editable(trXFBar) || !bTimeCol) )
		//if ( (!bAddXFBar || reimp_graph == reimp) && !bTimeCol )
		///// end FIX_PCLAMP_CONTROL_STILL_SHONW_WHEN_SHOW_TIME_COL_IN_LT
		///// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		/// end ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
		{
			LT_execute(";xfbar c"); // Hong 06/19/07 QA80-9709-P5 CLOSE_XFBAR_IF_UNCHECK
			string strPageXFName;
			if ( !get_page_xf_bar(pgTarget, strPageXFName) || strPageXFName.IsEmpty() )
			{
				set_page_xf_bar(pgTarget, "plotpclamp", SXFB_OPEN_INDEPENDENT);
			}
		}
		/// end ATTACH_XF_NAME_ALLOW_REOPEN_EVEN_UNCHECK_ADDPLOT
		///---Sim 03-11-2008 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		///// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		//if ( bSingleFile )
			//break;
		///// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		///---END QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	}
	//s_pClampImport.CleanUp();	//// AW 10/10/06 MORE_ON_XF_PCLAMP_HEADER_INFO // 12/27/06 REMOVE_STATIC_OBJECT
	//refresh_organizer_gui(pgTarget); ///---Sim 06-25-2007 UPDATE_ORGANIZER
	///---Sim 05-18-2007 REMOVE_UID_VARIABLE
	//if ( uid )
		//uid = vImportedRangeUID;
	///---END REMOVE_UID_VARIABLE
	if ( trheader )
		trheader.Replace(trBaseInfo.Clone(), true, true);/// Hong 01/08/06 FINFO_IS_ONLY_OUTPUT
}

//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int imppClamp_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return imppClamp_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	//OK_SURE(bOKEnable); ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
	
	///---Sim 11-20-2006 SUPPORT_DND_OPEN_DIALOG
	if ( GETNE_ON_INIT == nEventID || GETNE_ON_THEME == nEventID )
	{
		//s_bFileValid = file_name_event(trGetN, strErrMsg);
		/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
		//s_bFileValid = file_name_event(trGetN, strErrMsg, false); // Hong 03/01/07 QA80-9418 REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION
		s_bFileValid = file_name_event(trGetN, strErrMsg, false, GETNE_ON_THEME == nEventID);
		/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
		///---Sim 03-17-2007 CHECK_ERROR_FOR_INVALID_RANGE
		s_bRangeValid = !trGetN.orng.strVal.IsEmpty();
		if(!s_bRangeValid)
			strErrMsg = XFERR_INVALID_RANGE;
		///---END CHECK_ERROR_FOR_INVALID_RANGE
		OK_SURE(bOKEnable);
		
		//import_mode_event(trGetN, trGetN.options.inputmode.nVal);	// Hong 03/05/07 COMMENT_OUT_AS_ALWAYS_USE_SWEEP_MODE
		///---Sim 05-25-2007 QA80-9821 APPLY_NEW_NODE_EVENT_MECHANISM
		tree_set_attribute_to_all_nodes(trGetN.trfiles, STR_ATTRIB_FORCE_NODE_EVENT_ON, "1");
		trGetN.SetAttribute(STR_ATTRIB_FORCE_CALL_NODE_EVENTS, 1);
		///---END QA80-9821 APPLY_NEW_NODE_EVENT_MECHANISM
		return true;
	}
	///---END SUPPORT_DND_OPEN_DIALOG
	
	if ( 0 == lstrcmp(lpcszNodeName, "fname") )
	{
		///---Sim 11-20-2006 SUPPORT_DND_OPEN_DIALOG
		s_bFileValid = file_name_event(trGetN, strErrMsg);
		OK_SURE(bOKEnable);
		///---Sim 05-25-2007 QA80-9821 APPLY_NEW_NODE_EVENT_MECHANISM
		tree_set_attribute_to_all_nodes(trGetN.trfiles, STR_ATTRIB_FORCE_NODE_EVENT_ON, "1");
		trGetN.SetAttribute(STR_ATTRIB_FORCE_CALL_NODE_EVENTS, 1);
		///---END QA80-9821 APPLY_NEW_NODE_EVENT_MECHANISM
		return true;
		/*
		s_bFileValid = true; ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
		OK_SURE(bOKEnable); ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
		
		TreeNode trFName =  tree_get_node_by_tagname(trGetN, "fname", true, false, false);
		Tree trFileInfo;
		string strFileName = trFName.strVal;
		/// Hong 11/1/06 ERROR_MESSAGE
		int nErrCode = CER_NO_ERROR;
		int nInvalidFileIdx = 0;
		if( strFileName.IsEmpty ())
		{
			nErrCode = CER_EMPTY_FILENAME;
		}
		else if( !is_valid_filename(strFileName, nInvalidFileIdx) )
		{
			nErrCode = CER_INVALID_FILENAME_INDEX;
		}
		if(CER_NO_ERROR != nErrCode)
		{
			strErrMsg = nErrCode;
			
			if ( CER_INVALID_FILENAME_INDEX == nErrCode )
			{
				strErrMsg += ":";
				strErrMsg += nInvalidFileIdx;
			}
		
			s_bFileValid = false; ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
			OK_SURE(bOKEnable); ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
			//clear trSetting
			trGetN.trSetting.RemoveChildrenWithPrefix();
			return true;
		}
		*/
		/// end ERROR_MESSAGE
		/*
		TreeNode trGUI;
		StringArray vsFileNames;
		separate_multiline_files(strFileName, vsFileNames); 
	
		trGUI = trGetN.trSetting;
		trGUI.Reset();
		_construct_GUI_tree(trGUI, trGetN.InputMode.nVal, vsFileNames);
		trGUI.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN);	
		*/
		/*
		///---Sim 11-09-2006 HANDLE_ERROR_MESSAGE
		//construct_tree_setting(strFileName, trGetN.trSetting, trGetN.InputMode.nVal );
		if ( !construct_tree_setting(strFileName, trGetN.trSetting, trGetN.InputMode.nVal ) )
		{
			// clean the trFiles on GUI
			trGetN.trSetting.RemoveChildrenWithPrefix();
			
			strErrMsg = CER_INVALID_IMPORT_DATA_FILE;
			s_bFileValid = false; ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
			OK_SURE(bOKEnable); ///---Sim 11-16-2006 RELIABLE_OK_ENABLE
			
			return true;
		}
		///---END HANDLE_ERROR_MESSAGE
		return true; ///---Sim 11-06-2006 UPDATE_GUI
		*/
		///---END SUPPORT_DND_OPEN_DIALOG
	}
	
	///---Sim 03-17-2007 CHECK_ERROR_FOR_INVALID_RANGE
	//check range if is invalid
	if( 0 == lstrcmp(lpcszNodeName, "orng") )
	{
		s_bRangeValid = !trGetN.orng.strVal.IsEmpty();
		if(!s_bRangeValid)
			strErrMsg = CER_INVALID_PAGE;
		
		OK_SURE(bOKEnable);
		return true;
	}
	///---END CHECK_ERROR_FOR_INVALID_RANGE
	
	if ( 0 == lstrcmp(lpcszNodeName, "inputmode") )
	{
		//import_mode_event(trGetN, trGetN.options.inputmode.nVal);	// Hong 03/05/07 COMMENT_OUT_AS_ALWAYS_USE_SWEEP_MODE
		return true; ///---Sim 11-06-2006 UPDATE_GUI
	}
	/// END ADD_PLOT_TAG_IN_PCLAMP
	
	/// Hong 04/08/09 QA80-13222 ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
	/*
	/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
	if ( 0 == lstrcmp(lpcszNodeName, "ShowTimeCol") )
	{
		_update_xfbar_status(trGetN);
		return true;
	}
	/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
	*/
	/// end ALLOW_PLOT_PCLAMP_EVEN_SHOW_TIME_COL
	
	/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	_get_theme_settings(trGetN.trfiles, trGetN.thm);
	/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
		
	return false;		

}

int imppClamp_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	
	///---Sim 01-29-2007 MORE_OPTIONS_FOR_IMPORT
	if ( 0 == strcmp(lpcszVarName, "options") )
	{
		constructOptionsForXF(tr, true, true, true, false, true, true, false, false, true);
		/// Hong 03/05/09 TURN_OFF_SHEET_RENAME_AND_ONLY_RENAME_BK_LONGNAME_ASKED_CP
		fuSetInt(tr, IDE_XFIMP_RENAMEWKS, 0);
		fuSetInt(tr, IDE_XFIMP_WKBKLNONLY, 1);
		/// end TURN_OFF_SHEET_RENAME_AND_ONLY_RENAME_BK_LONGNAME_ASKED_CP
		
		// custom import mode list
		///---Sim 05-08-2007 ADD_OPTIONS_FOR_IMPORT_MODE_OF_1ST_FILE
		TreeNode tr1stImportMode = tree_get_node_by_id(tr, IDE_DISPIMP_1STMODE, true);
		if ( tr1stImportMode )
		{
			string strCombo, strMapping;
			strCombo = getImportModeListString(strMapping, PCLAMP_1ST_FILE_IMPORT_MODE_LIST);
			tr1stImportMode.SetAttribute(STR_COMBO_ATTRIB, strCombo);
			tr1stImportMode.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
			tr1stImportMode.nVal = ASCIMP_MODE_REPLACE_DATA;
			tr1stImportMode.Show = 0;/// Hong 05/14/07 v8.0617 HIDDEN_IMPORT_MODE_ASKED_BY_JUSTIN
		}
		///---END ADD_OPTIONS_FOR_IMPORT_MODE_OF_1ST_FILE
		TreeNode trImportMode = tree_get_node_by_id(tr, IDE_IMP_IMPORTMODE, true);
		if ( trImportMode )
		{
			string strCombo, strMapping;
			strCombo = getImportModeListString(strMapping, PCLAMP_IMPORT_MODE_LIST);
			trImportMode.SetAttribute(STR_COMBO_ATTRIB, strCombo);
			trImportMode.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
			trImportMode.nVal = ASCIMP_MODE_NEW_BOOKS;
			//trImportMode.nVal = ASCIMP_MODE_REPLACE_DATA;			
		}
		///---Sim 05-05-2007 NO_NEED_SUPPORT_MULTI_FILES
		//trImportMode.Show = 0; /// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
		TreeNode trTemplate = tree_get_node_by_id(tr, IDE_DISP_IMP_PAGETEMPLATE, true);
		trTemplate.Show = 0;
		///---END NO_NEED_SUPPORT_MULTI_FILES
		
		fuSetShowTime(tr, 0); // show time column default is none
	
		/// Hong 07/23/08 v8.0907 HIDEEN_PARTIAL_OPTIONS_IN_IWFILTER		
		TreeNode trParital = tree_get_node_by_tagname(tr, STR_FILTER_PARTIAL_NODE, true);
		if ( trParital )
			trParital.Show = FALSE;		
		/// end HIDEEN_PARTIAL_OPTIONS_IN_IWFILTER
		
		///---Sim 05-11-2007 GOOD_EXPLAIN_FOR_USER_AS_JUSTIN_SAID
		TreeNode trStartPoint		= tree_get_node_by_id(tr, IDE_XFIMP_START_POINT, true);
		TreeNode trReadPoint 		= tree_get_node_by_id(tr, IDE_XFIMP_READ_POINT, true);
		TreeNode trSkipPoint 		= tree_get_node_by_id(tr, IDE_XFIMP_SKIP_POINT, true);
		TreeNode trEndPoint 		= tree_get_node_by_id(tr, IDE_XFIMP_END_POINT, true);
		
		trStartPoint.SetAttribute(STR_LABEL_ATTRIB, _L("Start Sample"));
		trReadPoint.SetAttribute(STR_LABEL_ATTRIB, _L("Read Sample"));
		trSkipPoint.SetAttribute(STR_LABEL_ATTRIB, _L("Skip Samples"));
		trEndPoint.SetAttribute(STR_LABEL_ATTRIB, _L("End Sample"));
		///---END GOOD_EXPLAIN_FOR_USER_AS_JUSTIN_SAID
		
		// add plot option
		// input mode option
		TreeNode trAddPlot;
		TreeNode trInputMode;
		//TreeNode trAddInfo; ///---Sim 05-04-2007 ADD_NOTE_WINDOW_SHEET	///---Sim 05-10-2007 TRUN_OFF_ADD_NOTE_WINDOW_SHEET
	
		/// Hong 06/04/07 v.80623 MORE_FRIENDLY_NAME
		//TreeNode trFileNameOption = tr.GetNode("FileNameOptions");
		TreeNode trFileNameOption = tr.GetNode(STR_FILTER_FILENAME_NODE); /// Hong 06/04/07 v8.0623 USE_MACRO_FOR_MORE_FRIENDLY_NAME
		/// end MORE_FRIENDLY_NAME
		if ( trFileNameOption )
		{
			trAddPlot = tr.InsertNode(trFileNameOption, STR_ADD_XFBAR);
			//trAddInfo = tr.InsertNode(trFileNameOption, "addinfo"); ///---Sim 05-04-2007 ADD_NOTE_WINDOW_SHEET	///---Sim 05-10-2007 TRUN_OFF_ADD_NOTE_WINDOW_SHEET
			trInputMode = tr.InsertNode(trFileNameOption, "inputmode");
		}
		else
		{
			trAddPlot = tr.AddNode(STR_ADD_XFBAR);
			//trAddInfo = tr.AddNode("addinfo"); ///---Sim 05-04-2007 ADD_NOTE_WINDOW_SHEET	///---Sim 05-10-2007 TRUN_OFF_ADD_NOTE_WINDOW_SHEET
			trInputMode = tr.AddNode("inputmode");
		}
			
		trAddPlot.ID = TRGP_CHECK;
		//trAddPlot.SetAttribute(STR_LABEL_ATTRIB, "Attach Plot to Target Window");
		//trAddPlot.SetAttribute(STR_LABEL_ATTRIB, "Show Control Bar to Make Plots"); // Hong 03/15/07 BETTER_LABEL_AS_CP_REQUIRED
		trAddPlot.SetAttribute(STR_LABEL_ATTRIB, _L("Show Control Panel for Making Plots")); //CPY 3/16/07 STR_NEEDS_TO_BE_LOCALIZED
		trAddPlot.DataID = GET_FILTER_USER_DATAID(1); ///---Sim 05-22-2007 ADDITIONAL_OPTIONS_ID
		trAddPlot.nVal = 1;
		
	
		///---Sim 05-10-2007 TRUN_OFF_ADD_NOTE_WINDOW_SHEET
		/*
		///---Sim 05-04-2007 ADD_NOTE_WINDOW_SHEET
		trAddInfo.ID = TRGP_CHECK;
		trAddInfo.SetAttribute(STR_LABEL_ATTRIB, _L("Show Header Info to User Parameter"));
		trAddInfo.nVal = 1;
		///---END ADD_NOTE_WINDOW_SHEET
		*/
		///---END TRUN_OFF_ADD_NOTE_WINDOW_SHEET
		
		trInputMode.ID = TRGP_ENUM_LIST;
		trInputMode.SetAttribute(STR_COMBO_ATTRIB, _L("Channel|Episode"));
		trInputMode.SetAttribute(STR_LABEL_ATTRIB, _L("Choose Input Mode"));
		trInputMode.DataID = GET_FILTER_USER_DATAID(2); ///---Sim 05-22-2007 ADDITIONAL_OPTIONS_ID
		trInputMode.nVal = 1;
		trInputMode.Show = 0; // not let user select
		
		fuSetXFunctionName(tr, "imppClamp");
		
		tr.SetAttribute(STR_ATTRIB_BRANCH, GETNBRANCH_OPEN); /// Hong 03/06/09 IMPROVE_PCLAMP_GUI_SHOW_KEY_OPTIONS
	
		return 0;
	}
	///---END MORE_OPTIONS_FOR_IMPORT
	/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	/*	trfiles structure change to
	 	single file							multiple file
	 	trfiles									trfiles
	   	  |											|	
	   	  |---InfoFileNormal						|-------------file1
	   	  |---Stimulus								|				|---InfoFileNormal
		  |---Sweeps								|				|---Stimulus		  
		  |---Channels								|				|---Sweeps
		  \---Partial								\----file..		|---Channels
	*/
	/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
	if ( 0 == lstrcmp(lpcszVarName, "trfiles") )
	{
		/// Hong 06/11/07 v8.0638 ALLOW_LT_ACCESS_FOR_STIMULUS
		GETN_USE(tr)
		/// Hong 03/06/09 IMPROVE_PCLAMP_GUI_SHOW_KEY_OPTIONS
		//GETN_MULTILINE_TEXT(InfoFileNormal, _L("File protocol"), "") GETN_OPTION_MUTILINE_TEXT_BOX(true, "2-15", true)
		GETN_MULTILINE_TEXT(InfoFileNormal, _L("File protocol"), "") GETN_OPTION_MUTILINE_TEXT_BOX(true, "2-15", true) SET_EDITBOX_RESIZABLE(0)
		/// end IMPROVE_PCLAMP_GUI_SHOW_KEY_OPTIONS
		GETN_CHECK(Stimulus, _L("Stimulus"), 1);
		GETN_CHECK(bHoldingDuration, _L("Shift Time by Holding Period"), 0);   /// AW 01/06/09 QA80-12413 ADD_HOLDING_DURATION_TIME_IN_PCLAMP
		/// end ALLOW_LT_ACCESS_FOR_STIMULUS
		/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		GETN_CHECK(ShowTimeCol, _L("Add Time Column"), 0)
		/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
		return 0;
	}
	
	/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	if ( 0 == lstrcmp(lpcszVarName, "thm") )
	{
		TreeNode			trSubNode;
		int					nBaseDataID = 1;
		trSubNode = tr.AddNode("IDs");
		vector<int>			vnJunk;
		trSubNode.nVals = vnJunk;
		trSubNode.SetAttribute(STR_DATAID_ATTRIB, GET_USER_DATAID(nBaseDataID++));
		trSubNode = tr.AddNode("Values");
		vector<string>		vsJunks;
		trSubNode.strVals = vsJunks;
		trSubNode.SetAttribute(STR_DATAID_ATTRIB, GET_USER_DATAID(nBaseDataID++));
		return 0;
	}
	/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
	
	return -1;
}
//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void imppClamp_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	if(nGetNDialog > 0)
	{
		/// AW 10/05/06 MORE_ON_PCLAMP
		//trGetN.AutoUpdate.Show = 0;
		//trGetN.AutoUpdate.nVal = AU_NONE;
		/// END MORE_ON_PCLAMP
		//trGetN.uid.Show = 0; ///---Sim 05-18-2007 REMOVE_UID_VARIABLE
		trGetN.trheader.Show = 0;			/// AW 08/15/06 NEW_DLG_OF_IMPORT 
		/// Hong 03/01/07 QA80-9418 REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION
		// disable option not allow edit when do repeat import
		trGetN.reimp.Show = 0;
		/// Hong 05/18/07 v8.0621 REIMP_FROM_GRAPH_AUTO_PLOT
		//if(1 == trGetN.reimp.nVal)
		if(reimp_import != trGetN.reimp.nVal)
		/// end REIMP_FROM_GRAPH_AUTO_PLOT
		{
			trGetN.fname.Enable = ENABLE_READ_ONLY;
			/// Hong 05/18/07 v8.0621 ENABLE_PARTIAL_OPTION_WHEN_REIMP
			//trGetN.trfiles.Enable = 2;
			if ( trGetN.trfiles.Stimulus )
				trGetN.trfiles.Stimulus.Enable = ENABLE_READ_ONLY;
			if ( trGetN.trfiles.Channels )
				trGetN.trfiles.Channels.Enable = ENABLE_READ_ONLY;
			if ( trGetN.trfiles.Sweeps )
				trGetN.trfiles.Sweeps.Enable = ENABLE_READ_ONLY;
			/// end ENABLE_PARTIAL_OPTION_WHEN_REIMP
			/// Hong 03/05/09 QA80-13222 SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
			if ( trGetN.trfiles.ShowTimeCol )
				trGetN.trfiles.ShowTimeCol.Enable = ENABLE_READ_ONLY;
			/// end SWEEP_MODE_ALLOW_SHOW_TIME_COL_AS_75_ASKED_BY_USER
			/// Hong 06/29/07 v8.0652 FIX_PARTIAL_CAN_NOT_GRAY_OUT_FOR_VARIALBEEVENT_FILE_WHEN_REIMPORT
			// seems we no need to edit enable property for partial node here, as it have no need to be changed
			///// Hong 05/25/07 ONLY_PARTIAL_OPTION_NEED_UNDO_READONLY
			//TreeNode trPartialImport	= tree_get_node_by_id(trGetN.trfiles, IDE_XFIMP_PARTIAL_IMPORT, true);
			//trPartialImport.Enable = 1;
			///// end ONLY_PARTIAL_OPTION_NEED_UNDO_READONLY
			/// end FIX_PARTIAL_CAN_NOT_GRAY_OUT_FOR_VARIALBEEVENT_FILE_WHEN_REIMPORT
			trGetN.orng.Enable = 2;
			/// Hong 03/12/09 IMPROVE_CODE_PUT_SOME_LOGIC_IN_IMPPCLAMP
			if ( trGetN.trfiles.InfoFileNormal && !trGetN.trfiles.InfoFileNormal.IsEmpty() )			
				trGetN.trfiles.InfoFileNormal.Show = 1;
			if ( trGetN.trfiles.ShowTimeCol )
				trGetN.trfiles.ShowTimeCol.Show = 1;
			/// end IMPROVE_CODE_PUT_SOME_LOGIC_IN_IMPPCLAMP
		}
		/// end REPEAR_IMPORT_NEED_ALLOW_PASS_DATA_SELECTION
		//trGetN.trFilter.Show = 0;
		///---Sim 11-08-2006 NO_SHOW_FIXED_OPTION
		//trGetN.timecol.Show = 0; // Hong 11/16/06 HIDDEN_NO_NEED_SHOW_OPTION
		///---END NO_SHOW_FIXED_OPTION
		//trGetN.InputMode.Show = 0;	// Hong 12/18/06 ALWAYS_USE_EPISODE_MODE
	}
	///---Sim 9-26-06 FILTER_TO_UPDATE_GUI_AND_LT_INVOKE
	//else if ( 0 == nGetNDialog )
	if(nGetNDialog >= 0)
	//---END FILTER_TO_UPDATE_GUI_AND_LT_INVOKE
	{
		/// Hong 03/25/08 v8.0831 FIX_RUN_FROM_MENU_NO_OPEN_DIALOG_IF_FNAME_NOT_EMPTY
		//if ( LTXF_FROM_GUI_MENU == dwCntrl )
		if ( LTXF_FROM_GUI_MENU & dwCntrl )
		/// end FIX_RUN_FROM_MENU_NO_OPEN_DIALOG_IF_FNAME_NOT_EMPTY
			trGetN.fname.strVal = "";
		
		///---Sim 01-29-2007 MORE_OPTIONS_FOR_IMPORT
		//TreeNode trFilter = trGetN.trFilter;
		//if ( trFilter.IsValid() && trFilter.GetNodeCount()>0)
		//{
			///// Hong 01/25/07 REMOVE_AUTO_IMPORT_MODE
			///*
			/////---Sim 09-28-2006 FIX_IMPORT_MODE_SHOWING_ORDER
			////trGetN.FileImpotMode.nVal = fuGetImportMode(trFilter);
			/////---Sim 09-30-2006 REMOVE_APPEND_ROWS_IMPORT_MODE_FROM_GUI
			////trGetN.impmode.nVal = _GetListIndexFromImportMode(fuGetImportMode(trFilter));
			//int nImportMode = fuGetImportMode(trFilter);
			//// alter import mode when it is append rows, default to auto
			//if ( ASCIMP_MODE_APPEND_ROWS == nImportMode )
				//nImportMode = ASCIMP_MODE_AUTO;
			///// Hong 01/23/07 REMOVE_APPEND_COL_MODE			
			//if ( ASCIMP_MODE_APPEND_COLS == nImportMode )
				//nImportMode = ASCIMP_MODE_AUTO;
			///// end REMOVE_APPEND_COL_MODE
			//trGetN.impmode.nVal = _GetListIndexFromImportMode(nImportMode);
			/////---Sim 09-30-2006 REMOVE_APPEND_ROWS_IMPORT_MODE_FROM_GUI
			/////---END FIX_IMPORT_MODE_SHOWING_ORDER
			//*/
			//int nImportMode = fuGetImportMode(trFilter);
			//// alter import mode pclamp not support, default to new sheet
			//nImportMode = _GetListIndexFromImportMode(nImportMode);
			//// trim and convert to GUI mode
			////if( nImportMode < 1 || nImportMode > 3 )
			//if( nImportMode < 1 || nImportMode > 4 ) // Hong 01/27/07 ADD_APPEND_COLUMN_MODE
				//nImportMode = 2;
			//else
				//nImportMode -= 1;
			//trGetN.impmode.nVal = nImportMode;
			///// end REMOVE_APPEND_COL_MODE
			///// end REMOVE_AUTO_IMPORT_MODE
			//trGetN.sparklines.nVal = fuGetSparkLine(trFilter);
			//trGetN.timecol.nVal = fuGetShowTime(trFilter);
		//}
		///---END MORE_OPTIONS_FOR_IMPORT
	}
	/// Hong 12/22/06 CHECK_FNAME_EMPTY_UNASSIGNED
	if(nGetNDialog > -1)
	{
		bool bResetFileInfo = false; ///---Sim 03-24-2009 QA80-13342 SUPPORT_OC_ACCESS_IMP_FILE_DATA_SELECTION
		
		/// Hong 04/13/07 QA80-9614 FIX_CRASH_IF_RUN_FROM_ORGANIZER
		/* no need this temp fix now
		/// Hong 04/12/07 DISABLE_ADD_PLOT_WHEN_REIMPORT_AVOID_CONFLICT_BETWEEN_XFBAR_AND_ORGANIZER
		if(1 == trGetN.reimp.nVal && trGetN.options)
		{
			trGetN.options.addplot.nVal = 0;
			trGetN.options.addplot.Enable = 2;
		}
		/// end DISABLE_ADD_PLOT_WHEN_REIMPORT_AVOID_CONFLICT_BETWEEN_XFBAR_AND_ORGANIZER
		*/
		/// end FIX_CRASH_IF_RUN_FROM_ORGANIZER
		string strFileName = trGetN.fname.strVal;
		if(is_empty_or_unassigned(strFileName))
		{			
			/// Hong 05/31/07 v8.0630 MORE_ON_ACCESS_TO_FDLOG
			//int nFilesRet = get_open_box_by_file_group(strFileName, "pClamp", "Open pclamp file", false); ///---Sim 05-05-2007 NO_NEED_SUPPORT_MULTI_FILES
			int nFilesRet;
			if ( 0 != nGetNDialog )
			{
				int nShowOptionsDlg = 1;
				/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				//nFilesRet = get_open_box_by_file_group(strFileName, "pClamp", _L("Open pClamp file"),
				//	0, NULL, NULL, _L("Show Options Dialog"), &nShowOptionsDlg);
				/// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
				//nFilesRet = get_open_box_by_file_group(strFileName, "pClamp", NULL,
				//	0, NULL, NULL, STR_SHOW_OPT_DLG, &nShowOptionsDlg);
				///---Sim 10-27-2008 QA80-12422 SUPPORT_SAVE_SHEET_THEME_FOR_ALL_SHEET_IMPORT_FILE
				//nFilesRet = get_open_box_by_file_group(strFileName, "pClamp", NULL,
					//true, NULL, NULL, STR_SHOW_OPT_DLG, &nShowOptionsDlg);
				nFilesRet = get_open_box_by_file_group(strFileName, "pClamp", NULL,
					true, NULL, NULL, get_show_options_label(trGetN), &nShowOptionsDlg);
				///---END QA80-12422 SUPPORT_SAVE_SHEET_THEME_FOR_ALL_SHEET_IMPORT_FILE
				/// end PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
				/// end CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				nRet = (nShowOptionsDlg ? XFEVT_PROCEED : XFEVT_PROCEED_NO_DLG);
			}
			else
			{
				/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				//nFilesRet = get_open_box_by_file_group(strFileName, "pClamp", _L("Open pClamp file"), false);
				//nFilesRet = get_open_box_by_file_group(strFileName, "pClamp", NULL, false);
				nFilesRet = get_open_box_by_file_group(strFileName, "pClamp", NULL, true); /// Hong 02/29/08 QA80-11194 PCLAMP_TAKE_BACK_MULTI_FILE_SUPPORT
				/// end CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
			}
			/// end MORE_ON_ACCESS_TO_FDLOG
			/// end THEME_FILENAME_WORKBOOK_AND_WORKSHEET
			if ( 0 == nFilesRet )
			{
				nRet = XFEVT_ABORT;
				//warning_msg_box(XFERR_UI_USER_CANCEL, false);
				return;
			}
			///---END HANDLE_USER_CANCEL_OPEN_FILE_BOX
			trGetN.fname.strVal = strFileName;
			bResetFileInfo = true; ///---Sim 03-24-2009 QA80-13342 SUPPORT_OC_ACCESS_IMP_FILE_DATA_SELECTION
		} ///---Sim 03-24-2009 QA80-13342 SUPPORT_OC_ACCESS_IMP_FILE_DATA_SELECTION
		
		string strErrMsg;
		///---Sim 03-24-2009 QA80-13342 SUPPORT_OC_ACCESS_IMP_FILE_DATA_SELECTION
		//if( !file_name_event(trGetN, strErrMsg) )
		/// Hong 03/18/10 QA80-15213 USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
		//if( !file_name_event(trGetN, strErrMsg, bResetFileInfo) )
		if( !file_name_event(trGetN, strErrMsg, bResetFileInfo, O_QUERY_BOOL(dwCntrl, LTXF_THEME_USED)) )
		/// end USER_REQUIRED_DATA_SELECTION_AVAILABLE_IN_THEME
		///---END QA80-13342 SUPPORT_OC_ACCESS_IMP_FILE_DATA_SELECTION
		{
			/// Hong 03/21/07 v8.0586 FIX_FAIL_DUMP_CORRECT_ERROR_STRING
			//nRet = XFEVT_ABORT;
			//warning_msg_box(strErrMsg, false);
			int nErrMsg = atoi(strErrMsg);
			nRet = XFEVT_ABORT;
			warning_msg_box(nErrMsg, false, 'E'); // should pass an inter ///---Sim 06-19-2007 IMPROVE_WARNING_MESSAGE_POST_FUNCTION
			/// end FIX_FAIL_DUMP_CORRECT_ERROR_STRING
			return;
		}
		///---Sim 03-24-2009 QA80-13342 SUPPORT_OC_ACCESS_IMP_FILE_DATA_SELECTION			
		//}
		///---END QA80-13342 SUPPORT_OC_ACCESS_IMP_FILE_DATA_SELECTION
		/// Hong 05/25/07 ONLY_PARTIAL_OPTION_NEED_UNDO_READONLY
		/// AW 05/18/07 MORE_ON_REIMPORT_BY_CHANGE_OPTIONS
		//else if ( 1 == trGetN.reimp.nVal )
		//{
			//_undo_make_tree_node_readonly(	trGetN.trfiles);
		//}
		/// END MORE_ON_REIMPORT_BY_CHANGE_OPTIONS
		/// end ONLY_PARTIAL_OPTION_NEED_UNDO_READONLY	
	}
	/// end CHECK_FNAME_EMPTY_UNASSIGNED
}
//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int imppClamp_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
