////////////////////////////////////////////////////////////////////////////////
// Filename:    Plot3D.ogs
// Creation:    1/19/99
// Purpose:     To generate plots from the menu or from the 3D toolbar
// Modifications:
// JCG 03/13/03 v7.0535 SHOULD_NOT_RUN_INTO_IMAGE_MODE_AFTER_IMAGE_PLOT
// EJP 2005-09-19 v8.0308 QA70-8087 IMAGE_PLOT_WITHOUT_DATA
// EJP 2006-05-02 v8.0404 QA70-8187 GET_DATA_VALUES_DIRECT_FROM_IMAGE
// EJP 2007-09-21 v8.0706 QA70-10262 DO_NOT_SET_IMG_PLOT_LAYER_REVERSE_IN_OGS
/// ML 8/20/2009 QA70-13792 ALLOW_ANY_Z
/// Fisher 12/10/2009   MORE_3D_PLOT_TYPES
/// Kyle 07/21/2010 ORG-617-P1 CONTOUE_PLOT_BUTTONS_FOR_GRAYSCALE_AND_BW_WORK
/// Kyle 07/22/2010 ORG-619-P1 CONTOUR_BUTTONS_SHOW_MESSAGE_WHEN_NO_DATA_SELECTED
/// Kyle 07/22/2010 ORG-619-P2 SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED
////////////////////////////////////////////////////////////////////////////////

[Bar]
	//Plot the selected columns as a 3D bar graph
	worksheet -P 212 Bar3d;
	legend;

[Ribbon]
	//Plot the selected columns as a 3D ribbon graph
	worksheet -P 211 Ribbon;
	legend;

[Walls]
	//Plot the selected columns as a 3D wall graph
	worksheet -P 210 Walls;
	legend;

[Waterfall]
	//Plot the selected columns as a 3D water fall plot
	worksheet -P 210 water3d;
	legend;

/// Fisher 12/10/2009   MORE_3D_PLOT_TYPES
[ColorFillError]
    worksheet -P 242 3DMeshError;

[ColorMapError]
    worksheet -P 242 3DCmapError;

[Vector3D]
    worksheet -P 183 3DVector;

[Vector3D2]
    worksheet -P 183 3DVector2;

[MeshScatter]
	///Kyle 07/22/2010 ORG-619-P2 SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED
	if( Exist(%H,2)==2 && %(%H,@Z#,2)!=0 )		// wks && z
	{
		type -b $General.SurfacePlotWithZ;
		return;
	}
	///End SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED

	//worksheet -p 101 3DScatterMat;
	run.section(,GenericSurface,101 3DScatterMat 0);

[Scatter3DError]
    worksheet -P 184 3DError;

[MeshScatterError]
    worksheet -P 101 3DScatterMatErr;

[mmesh]
    plotms type:=mesh;
	
[mcmap]
    plotms type:=cmap;
	
/// End MORE_3D_PLOT_TYPES


/// Fisher 01/05/10 QA80-13770  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
[GenericSurface]
	if (exist(%H)==2)	// wks
	{
		plotvm type:=%1 ogl:= <new template:=%2> -d
	}
	else if (exist(%H)==5)	// matrix
	{
		matrix -ig;
		worksheet -p %1 %2;
	}	
/// End VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK

[Scatter]
	/// ML 8/20/2009 QA70-13792 ALLOW_ANY_Z
	////Create a 3D scatter plot with the selected Z column
	//if (%(%H,@Z#,2) != 1)
	//{
	//	type -b $General.Only1ZColumn;
	//	break 1;
	//}
	/// end ALLOW_ANY_Z
	worksheet -P 240 3d;

[Trajectory]
	/// ML 8/20/2009 QA70-13792 ALLOW_ANY_Z
	////Create a 3D trajectory plot with the selected Z column
	//if (%(%H,@Z#,2) != 1)
	//{
	//	type -b $General.Only1ZColumn;
	//	break 1;
	//};
	/// end ALLOW_ANY_Z
	worksheet -P 240 Traject;


[ColorFill]
	//Create a 3D color filled surface plot with the selected Z column
	///Kyle 07/22/2010 ORG-619-P2 SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED
	if( Exist(%H,2)==2 && %(%H,@Z#,2)!=0 )		// wks && z
	{
		type -b $General.SurfacePlotWithZ;
		return;
	}
	///End SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED

	/// Fisher 01/05/10 QA80-13770  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK 
	//matrix -ig;
	//worksheet -p 242 mesh;	
	run.section(,GenericSurface,242 mesh 0);
	/// End  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  

[XConstant]
	//Create a 3D surface plot with constant slices in X
	///Kyle 07/22/2010 ORG-619-P2 SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED
	if( Exist(%H,2)==2 && %(%H,@Z#,2)!=0 )		// wks && z
	{
		type -b $General.SurfacePlotWithZ;
		return;
	}
	///End SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED

	/// Fisher 01/05/10 QA80-13770  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
	//matrix -ig;
	//worksheet -p 242 xconst;
	run.section(,GenericSurface,242 xconst 0);	
	/// End  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
	
[YConstant]
	//Create a 3D surface plot with constant slices in Y
	///Kyle 07/22/2010 ORG-619-P2 SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED
	if( Exist(%H,2)==2 && %(%H,@Z#,2)!=0 )		// wks && z
	{
		type -b $General.SurfacePlotWithZ;
		return;
	}
	///End SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED

	/// Fisher 01/05/10 QA80-13770  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
	//matrix -ig;
	//worksheet -p 242 yconst;
	run.section(,GenericSurface,242 yconst 0);	
	/// End  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
	
[ColorMap]
	//Create a 3D color map surface plot with the selected Z column
	///Kyle 07/22/2010 ORG-619-P2 SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED
	if( Exist(%H,2)==2 && %(%H,@Z#,2)!=0 )		// wks && z
	{
		type -b $General.SurfacePlotWithZ;
		return;
	}
	///End SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED

	/// Fisher 01/05/10 QA80-13770  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
	//matrix -ig;
	//worksheet -p 242 cmap;
	run.section(,GenericSurface,242 cmap 0);	
	/// End  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
	
[3DBars]
	//Create a 3D bars plot
	///Kyle 07/22/2010 ORG-619-P2 SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED
	if( Exist(%H,2)==2 && %(%H,@Z#,2)!=0 )		// wks && z
	{
		type -b $General.SurfacePlotWithZ;
		return;
	}
	///End SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED

	/// Fisher 01/05/10 QA80-13770  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
	//matrix -ig;
	//worksheet -p 242 3Dbars;
	run.section(,GenericSurface,242 3Dbars 0);	
	/// End  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
	
[WireFrame]
	//Create a 3D wire frame plot with the selected Z column
	///Kyle 07/22/2010 ORG-619-P2 SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED
	if( Exist(%H,2)==2 && %(%H,@Z#,2)!=0 )		// wks && z
	{
		type -b $General.SurfacePlotWithZ;
		return;
	}
	///End SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED

	/// Fisher 01/05/10 QA80-13770  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
	//matrix -ig;
	//worksheet -p 242 wirefrm;
	run.section(,GenericSurface,242 wirefrm 0);	
	/// End  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  

[WireSurface]
	//Create a 3D wire frame plot with semi-transparent nets
	///Kyle 07/22/2010 ORG-619-P2 SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED
	if( Exist(%H,2)==2 && %(%H,@Z#,2)!=0 )		// wks && z
	{
		type -b $General.SurfacePlotWithZ;
		return;
	}
	///End SURFACE_PLOT_SHOW_MESSAGE_WHEN_Z_COLUMN_SELECTED

	/// Fisher 01/05/10 QA80-13770  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  
	//matrix -ig;
	//worksheet -p 242 wireface;
	run.section(,GenericSurface,242 wireface 0);	
	/// End  VIRTUAL_MATRIX_FOR_3D_SURFACE_WORK  



//---- CPY 10/21/04 QA70-6954 CONTOUR_TRIANGULATION_PLOT
[TriContourPlot]
	///Kyle 07/22/2010 ORG-619-P1 CONTOUR_BUTTONS_SHOW_MESSAGE_WHEN_NO_DATA_SELECTED
	if( (!wks.sel) || (wks.sel & 128) )		// no selection or label selected
	{
		type -b $General.PlotContourNoData;
		return;
	}
	///End CONTOUR_BUTTONS_SHOW_MESSAGE_WHEN_NO_DATA_SELECTED

	/// Fisher 01/04/10 VIRTUAL_MATRIX_FOR_3D_CONTOUR_WORK
	if( wks.c2-wks.c1 > 3 || %(%H,@Z#,2)==0 )
	{
		run.section(,GenericSurface,226 contour 0);
		return;
	}
	/// End VIRTUAL_MATRIX_FOR_3D_CONTOUR_WORK	
	worksheet -p 243 TriContour;
	Spectrum;

//---- end  QA70-6954

[ContourColor]
	//---- CPY 4/14/05 QA70-6954 XYZ_CONTOUR_USE_SAME_ICON_AS_CONTOUR_COLOR_FILL
	if(Exist(%H,2)==2) // wks
		return run.section(,TriContourPlot);
	//----
	//Create a 2D color filled contour plot
	/// EJP 2006-05-02 v8.0404 QA70-8187 GET_DATA_VALUES_DIRECT_FROM_IMAGE
	///matrix -id;
	matrix -ig; // convert image to gray
	/// end GET_DATA_VALUES_DIRECT_FROM_IMAGE
	worksheet -p 226 contour;
	Spectrum;

///Kyle 07/21/2010 ORG-617-P1 CONTOUE_PLOT_BUTTONS_FOR_GRAYSCALE_AND_BW_WORK
[TriContourBW]
	///Kyle 07/22/2010 ORG-619-P1 CONTOUR_BUTTONS_SHOW_MESSAGE_WHEN_NO_DATA_SELECTED
	if( (!wks.sel) || (wks.sel & 128) )		// no selection or label selected
	{
		type -b $General.PlotContourNoData;
		return;
	}
	///End CONTOUR_BUTTONS_SHOW_MESSAGE_WHEN_NO_DATA_SELECTED

	if( wks.c2-wks.c1 > 3 || %(%H,@Z#,2)==0 )
	{
		run.section(,GenericSurface,226 contline 0);
		return;
	}
	worksheet -p 243 TriContline;
///End CONTOUE_PLOT_BUTTONS_FOR_GRAYSCALE_AND_BW_WORK

[ContourBW]
	//Create a 2D black and white contour plot with labels
	///Kyle 07/21/2010 ORG-617-P1 CONTOUE_PLOT_BUTTONS_FOR_GRAYSCALE_AND_BW_WORK
	/*
	/// EJP 2006-05-02 v8.0404 QA70-8187 GET_DATA_VALUES_DIRECT_FROM_IMAGE
	///matrix -id;
	/// Fisher 01/04/10 VIRTUAL_MATRIX_FOR_3D_CONTOUR_WORK
	//matrix -ig; // convert image to gray
	if( wks.c2-wks.c1 > 3 || %(%H,@Z#,2)==0 )
	{
		run.section(,GenericSurface,226 contline 0);
		return;
	}
	/// --------------
	/// end GET_DATA_VALUES_DIRECT_FROM_IMAGE
	worksheet -p 226 contline;
	*/

	if(Exist(%H,2)==2) // wks
		return run.section(,TriContourBW);

	matrix -ig; // convert image to gray
	worksheet -p 226 contline;
	///End CONTOUE_PLOT_BUTTONS_FOR_GRAYSCALE_AND_BW_WORK

///Kyle 07/21/2010 ORG-617-P1 CONTOUE_PLOT_BUTTONS_FOR_GRAYSCALE_AND_BW_WORK
[TriGrayScaleMap]
	///Kyle 07/22/2010 ORG-619-P1 CONTOUR_BUTTONS_SHOW_MESSAGE_WHEN_NO_DATA_SELECTED
	if( (!wks.sel) || (wks.sel & 128) )		// no selection or label selected
	{
		type -b $General.PlotContourNoData;
		return;
	}
	///End CONTOUR_BUTTONS_SHOW_MESSAGE_WHEN_NO_DATA_SELECTED

	if( wks.c2-wks.c1 > 3 || %(%H,@Z#,2)==0 )
	{
		run.section(,GenericSurface,226 contgray 0);
		return;
	}
	worksheet -p 243 TriContgray;

///End CONTOUE_PLOT_BUTTONS_FOR_GRAYSCALE_AND_BW_WORK

[GrayScaleMap]
	#Create a 2D gray scale map
	///Kyle 07/21/2010 ORG-617-P1 CONTOUE_PLOT_BUTTONS_FOR_GRAYSCALE_AND_BW_WORK
	/*
	/// EJP 2006-05-02 v8.0404 QA70-8187 GET_DATA_VALUES_DIRECT_FROM_IMAGE
	///matrix -id;
	/// Fisher 01/04/10 VIRTUAL_MATRIX_FOR_3D_CONTOUR_WORK
	//matrix -ig; // convert image to gray
	if( wks.c2-wks.c1 > 3 || %(%H,@Z#,2)==0 )
	{
		run.section(,GenericSurface,226 contgray 0);
		return;
	}
	/// --------------
	/// end GET_DATA_VALUES_DIRECT_FROM_IMAGE
	worksheet -p 226 contgray;
	Spectrum;
	*/
	if(Exist(%H,2)==2) // wks
		return run.section(,TriGrayScaleMap);

	matrix -ig; // convert image to gray
	worksheet -p 226 contgray;
	///End CONTOUE_PLOT_BUTTONS_FOR_GRAYSCALE_AND_BW_WORK


[ImagePlot]
	/// EJP 2005-09-19 v8.0308 QA70-8087 IMAGE_PLOT_WITHOUT_DATA
	///matrix -id;// make sure we have gray+data
	/// end IMAGE_PLOT_WITHOUT_DATA
	/// JCG 03/13/03 v7.0535 SHOULD_NOT_RUN_INTO_IMAGE_MODE_AFTER_IMAGE_PLOT
	//matrix -ii;// make sure we have image
	/// end SHOULD_NOT_RUN_INTO_IMAGE_MODE_AFTER_IMAGE_PLOT
	// check XY mapping and see if reserve
	xreverse=0;
	yreverse=0;
	matrix -pg X v1 v2;
	if(v1 > v2) xreverse = 1;
	matrix -pg Y v1 v2;
	if(v1 > v2) yreverse = 1;
	get %C -it internalData;
	if(10 == internalData)
		run.Section(,ComplexImagePlot);
	else
	{
		worksheet -p 220 image;
		/// EJP 2007-09-21 v8.0706 QA70-10262 DO_NOT_SET_IMG_PLOT_LAYER_REVERSE_IN_OGS, this is done in template
		///run.Section(,SetupImagePlotLayer);
		/// end DO_NOT_SET_IMG_PLOT_LAYER_REVERSE_IN_OGS
	}
	del -v xreverse;
	del -v yreverse;
	del -v internalData;
	
//---- CPY v7.5846 QA70-5860 3/28/04 COMPLEX_DATA_TYPE
// [ImagePlot] section were directly modified to call these routines
//
[SetupImagePlotLayer]
	/// EJP 2005-09-19 v8.0308 QA70-8087 IMAGE_PLOT_WITHOUT_DATA
	///set %(1,@D) -tb 3;// turn off plot object level caching to directly draw image
	/// end IMAGE_PLOT_WITHOUT_DATA
	if(xreverse ==1)
		layer.x.reverse=1;
	// default template y is reverse
	if(yreverse ==1)
		layer.y.reverse=0;
	else
		layer.y.reverse=1;
	
	return 0;
[ComplexImagePlot]
	%A=%C; // save active matrix
	win -t plot cimage;
	for(ii = 1; ii <= page.nLayers; ii++)
	{
		
		layer -o ii {
			layer -i220 %A;
			layer -a;
			/// EJP 2007-09-21 v8.0706 QA70-10262 DO_NOT_SET_IMG_PLOT_LAYER_REVERSE_IN_OGS, this is done in template
			///run.Section(,SetupImagePlotLayer);
			/// end DO_NOT_SET_IMG_PLOT_LAYER_REVERSE_IN_OGS
		}
	}
			

















