/* -------------------------------------------------------------------------- *
 *	File Name:		matrix.ogs                                                *
 *	Purpose:		some matrix menu implementations                          *
 *	Author:			ML                                                        *
 *	Date:			8/16/95                                                   *
 *	Copyright:		Microcal Software, Inc. 1995                              *
 *                                                                            *
 *	Modification log:
 * RKM 11/09/96 added for Origin 5.0 [Dimension][Coordinates] [Values][Transpose]
 * EJP 2006-05-11 v8.0408 QA70-8187 GET_DATA_VALUES_DIRECT_FROM_IMAGE		*
 *	CPY 9/10/06 USE_OC_SET_VALUES_DIALOG									*
 *	Max 4/4/07 MATRIX_SET_PROPERTY_USING_XF									*
 *	Max 4/4/07 MATRIX_SET_DIMENSION_AND_COORDINATES_USING_XF				*
 *	Max 10/25/07 QA70-10581 LANGUAGE_SWITCH_CRASH_IN_J_LEAD_TO_NEW_LT_WAY_TO_RUN_XF*
 * EJP 2010-06-14 ORG-259 CONTEXT_MENU_FOR_MATRIX_THUMBNAILS				*
 *	Kyle 07/29/2010 ORG-234-P8 NEW_COMMAND_TO_CONVERT_BOTH_DATA_AND_IMAGE_TO_GRAY
 *	Max 8/10/2010 ORG-736-P2 RENAME_MHEADERS_TO_MLABELS
 * -------------------------------------------------------------------------*/
 
[Rotate90]
	matrix -id;// check convert to data
	matrix -Convert R;
	return 0;
	
[Flip_V]
	matrix -id;// check convert to data
	matrix -Convert V;
	return 0;
	
[Flip_H]
	matrix -id;// check convert to data
	matrix -Convert H;
	return 0;
	
[Expand]
	matrix -id;// check convert to data
	getn  	$Matrix.ExpandColumns mat.expand.col
		$Matrix.ExpandRows mat.expand.row
		$Matrix.ExpandExpand; 
	mat.matname$ = %H;
	//mat.errout = 2;  
	mat.expand();
	return 0;

[Shrink]
	matrix -id;// check convert to data

	getn  	$Matrix.ShrinkColumns mat.shrink.col
		$Matrix.ShrinkRows mat.shrink.row
		$Matrix.ShrinkShrink; 
	mat.matname$ = %H;
	mat.shrink();
	return 0;

[Inverse]
	matrix -id;// check convert to data
	mat.matname$ = %H;
	// mat.errout = 2;  
	if(mat.inv()!=0)
	{
		switch(mat.lasterrid())
		{
			case 1220:
				type -b $Matrix.SingularError;
				break;
			case 1221:
				type -b $Matrix.SquareError;
				break;
			default:
				type -b $Matrix.GeneralInverse;
				break;
		}
	}
	return 0;

[Mat2Wks]
	matrix -id;// check convert to data

	mat.matname$ = %H;
	win -T wks;     
	mat.wksname$ = %H;
	//mat.errout = 2; 
	mat.m2w();
	return 0;

[Test]
	type -B $Plot.Matrix;
	return 0;

[Dimension]
	/// Max 4/4/07 MATRIX_SET_PROPERTY_USING_XF
	//matrix -e Dim;
	//return 0;
	/// Max 10/25/07 QA70-10581 LANGUAGE_SWITCH_CRASH_IN_J_LEAD_TO_NEW_LT_WAY_TO_RUN_XF
	//mproperty;
	run -xf mproperty;
	/// END LANGUAGE_SWITCH_CRASH_IN_J_LEAD_TO_NEW_LT_WAY_TO_RUN_XF
	/// END
/// Hong 05/17/10 ORG-131 MATRIX_ADD_GENERAL_LABEL_SUPPORT_AS_WKSHEET
[Header]
	//run -xf mheaders; /// Max 8/10/2010 ORG-736-P2 RENAME_MHEADERS_TO_MLABELS
	run -xf mlabels;
/// end MATRIX_ADD_GENERAL_LABEL_SUPPORT_AS_WKSHEET
[Coordinates]
	/// Max 4/4/07 MATRIX_SET_DIMENSION_AND_COORDINATES_USING_XF
	//matrix -e Map;
	//return 0;
	/// Max 10/25/07 QA70-10581 LANGUAGE_SWITCH_CRASH_IN_J_LEAD_TO_NEW_LT_WAY_TO_RUN_XF
	//mdim -d;
	run -xf mdim -d;
	/// END LANGUAGE_SWITCH_CRASH_IN_J_LEAD_TO_NEW_LT_WAY_TO_RUN_XF
	/// END
[Values]
	//---- CPY 9/10/06 USE_OC_SET_VALUES_DIALOG
	//matrix -e;
	work -e v; // same as col set values dialog
	//----
	return 0;

[Transpose]
	matrix -id;// check convert to data
	matrix -Transpose;
	return 0;

[Smooth]
	matrix -id;// check convert to data
	type -C $Matrix.SmoothPrompt;
	mat.matname$ = %H;
	matrix  -pg DIM nc nr;
	if(nc < 32 || nr < 32)
	{
		mat.expand(2,2);
		mat.shrink(2,2);
	}
	else
	{		
		mat.shrink(2,2);
		mat.expand(2,2);
	};
	return 0;

[Integrate]
	matrix -id;// check convert to data
	mat.matname$ = %H;
	mat.integrate(ii);
	SaveRedirection=type.Redirection(16,3);
	type.BeginResults();
	type;
	type $Matrix.IntegResults;
	type.EndResults();
	type.Redirection=SaveRedirection; // restore previous redirection.
	delete -v SaveRedirection;
	return 0;	

[ConvXYZ]
	matrix -id;// check convert to data
	mat.matname$ = %H;
	%A=$Matrix.ConvXYZConstant;
	getn $Matrix.ConvXYZType mat.type:A
	$Matrix.ConvXYZTitle;
	win -T wks xyz; 
	mat.wksname$ = %H;
	mat.m2xyz();
	return 0;

[Tuning]
	if(dialog.status(OTools.dll,Tuning))
	{
		dialog.start(OTools.dll,Tuning);
	}
	else
	{
		dialog.close(OTools.dll,Tuning);
	}
	return 0;

[ConvertToData]
	///Kyle 07/29/2010 ORG-234-P8 NEW_COMMAND_TO_CONVERT_BOTH_DATA_AND_IMAGE_TO_GRAY
//	/// EJP 2006-05-11 v8.0408 QA70-8187 GET_DATA_VALUES_DIRECT_FROM_IMAGE
//	///matrix -in;	// check convert image to data without asking
//	matrix -ig;	// check convert to grayscale
//	/// end GET_DATA_VALUES_DIRECT_FROM_IMAGE
	matrix -g;		// matrix -ig; will only take care of image now, see ORG-234-P8
	///End NEW_COMMAND_TO_CONVERT_BOTH_DATA_AND_IMAGE_TO_GRAY
	return 0;

[Replace]
	// Open Dialog Builder Matrix Replace dialog box
	run.section(DBRoutines.OGS,SaveAndSetAtOC);

	if(run.section(DBRoutines.OGS,LoadOMatWorkspace)==0)
		OnOpenMR();
	
	run.section(DBRoutines.OGS,RestoreAtOC);
	
	return 0;

/// EJP 2010-06-14 ORG-259 CONTEXT_MENU_FOR_MATRIX_THUMBNAILS
[AddObject]
	//wks.addCol();
	work -a 1;
	return 0;

[InsertObject]
	wks.col = wks.active;//layer.plot;
	wks.insert();
	return 0;

[DeleteObject]
	delete wcol(wks.active);//layer.plot);
	return 0;

[MoveObjectToFirst]
	run -xf colmove op:=0;
	return 0;

[MoveObjectToLast]
	run -xf colmove op:=1;
	return 0;

[MoveObjectToLeft]
	run -xf colmove op:=3;
	return 0;

[MoveObjectToRight]
	run -xf colmove op:=2;
	return 0;

[Properties]
	run -xf mproperty;
	return 0;
/// end CONTEXT_MENU_FOR_MATRIX_THUMBNAILS
