;+
; NAME:
;	Custom_2D
; PURPOSE: 
;	User Interface to change values of  x- and y-axes,
;	the system variables containing the titles, and the
;	print format for postscript files.
; CATEGORY
;	User  Interface
; CALLING SEQUENCE:
;	Custom_2D 
; SIDE EFFECTS:
;	On X-windows terminals, new windows will be opened.
;	On other terminals, the display is erased.
; RESTRICTION:
;	Cannot be used without enrad.
;
; MODIFICATION HISTORY:
;	Created: May 1991, A.Csillaghy
;		Institute of Astronomy, ETH Zurich
;	Modified in October 1991, A.Cs
;	Modifications in Dec. 92 for sixel printing, A.Cs
;	No minmax, Software fonts in Nov 93, A.Cs
;-

PRO Modif_Axis

  COMMON ImageReal, dummy, xAxis, yAxis

  hms = GetHMS()
  GetMarksMode, xMarkMode, yMarkMode

  n = N_Elements( xAxis )
  IF n EQ 0 THEN RETURN

  axis = xAxis
  minimum = Min( xAxis, MAX = maximum )
  IF n GT 1 THEN step = xAxis(1) - xAxis(0) ELSE step = 0
  dir = 'X'

  len = 9
  menuA = StrArr( len )
  menuA(len-2) = 'Exit Modify Axis Menu'
  menuA(len-1) = 'Redisplay ths Menu'

  choice = 0
  REPEAT BEGIN

    hmsDir = (dir  EQ 'X') AND hms
    IF choice LE 1 THEN $ 
      menuA(0) = dir + ' axis definition; Number of elements: ' + $
	StrTrim( n, 2 )
    
    IF hmsDir THEN BEGIN
      minStr = HMSConvert( minimum )
      maxStr = HMSConvert( maximum )
    ENDIF ELSE  BEGIN
      minStr = StrTrim(minimum, 2 ) 
      maxStr = StrTrim( maximum, 2 )
    ENDELSE

    menuA(1) = 'Minimum value: ' + minStr
    menuA(2) = 'Maximum value: ' + maxStr

    menuA(3) = 'Step: ' + StrTrim( step, 2 )

    IF dir EQ 'X' THEN BEGIN
      IF hms THEN menuA(4) = 'X axis in Hours:Minutes:Seconds' $
      ELSE menuA(4) = 'X Axis in Decimal Notation'
    ENDIF ELSE menuA(4) = ''

   
    IF dir EQ 'X' THEN BEGIN
      markMode =  xMarkMode 
      charSize = !x.charSize
    ENDIF  ELSE BEGIN
      markMode = yMarkMode
      charSize = !y.charSize
    ENDELSE
     
    IF charSize EQ 0 THEN charSize = 1.0

    menuA( 5 ) = 'Tickmarks mode: ' + markMode
    menuA( 6 ) = 'Relative size of axis title: ' + StrTrim( charSize, 2 )

    choice = General_Menu(menuA , $
	'Axis Definition: Choose what to Change', $
	OPAQUE = [ 0,0,0,0,0,0,1])

    CASE choice OF
      1: IF dir EQ 'X' THEN BEGIN
            dir = 'Y' & axis = yAxis
            minimum = Min( yAxis, MAX = maximum )
            n = N_Elements( yAxis )
            IF n GT 1 THEN step = yAxis(1) - yAxis(0) ELSE step = 0
            markMode = yMarkMode
          ENDIF ELSE BEGIN
            dir = 'X' & axis = xAxis
            minimum = Min( xAxis, MAX = maximum )
            n = N_Elements( xAxis )
            IF n GT 1 THEN step = xAxis(1) - xAxis(0) ELSE step = 0
            markMode = xmarkMode
          ENDELSE
      2: BEGIN
             Read_Test,'New minimum ', minimum, minVal, $
	HMS = hmsDir
             minimum = minVal
             axis = minimum + n*Abs(Step)*(step LT 0) + FIndGen( n )*step
             maximum = Max( axis )
           END 
      3: BEGIN
             Read_Test,'New maximum ', maximum, maxVal, $
	HMS = hmsDir
             maximum = maxVal
             axis = maximum - n*Abs(step)*(step LT 0) - FIndGen( n )*step
             minimum = Min( axis )
           END 
      4: BEGIN
             Read_Test,'New step, maximum value changed', step , stepNew
             step = stepNew
             axis= FIndGen( n )*Abs( step )+ minimum 
             maximum = MAX( axis )
             IF step LT 0 THEN axis = Rotate( axis, 90 ) 
           END
      5: IF (dir EQ 'X') THEN BEGIN
            IF  hms THEN hms = 0 ELSE hms = 1
          ENDIF
      6: BEGIN
            IF markMode EQ 'automatic' THEN markMode = 'range' $
            ELSE markMode = 'automatic'
            menuA(5) = 'Tickmark mode: ' + markMode
          END
      7: Read_Test, 'New relative size of axis title', charSize, charSize
      ELSE:
    ENDCASE

    IF dir EQ 'X' THEN BEGIN
      xAxis = axis
      xMarkMode = markMode
      IF choice EQ 7 THEN !x.charSize = charSize
    ENDIF  ELSE BEGIN
      yAxis = axis
      yMarkMode = markMode
      IF choice EQ 7 THEN !y.charSize = charSize
    ENDELSE

  END UNTIL choice EQ len-1 

  PutHMS, hms
  PutMarksMode, xMarkMode, yMarkMode

END ;   modify axis


FUNCTION ChangeTitle, var

  title = ''
  Read,' Please enter the new title, <return> when no change: ', title
  IF title NE '' THEN RETURN, title $
  ELSE RETURN, var.title

END ; change title


PRO TitlesModif

  len = 6
  dMenu = StrArr( len )
  
  dMenu(0) = 'Main title: ' + !p.title
  dMenu(1) = 'X title: ' + !x.title
  dMenu(2) = 'Y title: ' + !y.title
  dMenu(3) = 'Z title: ' + !z.title
  dMenu(4) = 'Exit Titles Modification Menu'
  dMenu(5) = 'Redisplay this Menu '

  REPEAT BEGIN
    
    choice = General_Menu( dMenu, $
	'Titles: choose the one to change or Exit', $
	OPAQUE = [ 0,0,0,0,0,1] )
  
    CASE choice OF
      1: BEGIN 
            !p.title = ChangeTitle( !p )
             dMenu(0) = 'Main title: ' + !p.title
          END
      2: BEGIN 
             !x.title = ChangeTitle( !x ) 
             dMenu(1) = 'X title: ' + !x.title
          END
      3: BEGIN 
             !y.title = ChangeTitle( !y ) 
             dMenu(2) = 'Y title: ' + !y.title
          END
      4: BEGIN 
              !z.title = ChangeTitle( !z )
              dMenu(3) = 'Z title: ' + !z.title
          END
      ELSE:
    ENDCASE
  
  END UNTIL choice EQ len-1

END ;  Titles
 

PRO PSAttrModif

  GetImageSizes, xPos, yPos, width, height, sch, /PS
  GetMiscPS, encaps, landscape, reverse, blFont, reducedFmt, noMinMax
  GetOffsets, axisOffs, imageOffs, /PS

  len = 15
  psMenu = StrArr( len )
  
  psMenu(0) = 'X origin: ' + StrTrim( xPos, 2 ) + ' cm'
  psMenu(1) = 'Y origin: ' + StrTrim( yPos, 2 ) + ' cm'
  psMenu(2) = 'Width ' + StrTrim( width, 2) + ' cm '
  psMenu(3) = 'Height ' + StrTrim( height, 2 ) + ' cm'
  IF landscape THEN  psMenu(4) = 'Landscape Orientation' $
  ELSE psMenu(4) = 'Portrait Orientation'
  IF reverse THEN psMenu(5) = 'Reverse Mode' $
  ELSE psMenu(5) = 'Normal Mode'
  IF encaps THEN psMenu(6) = 'Image will be Encapsulated' $
  ELSE psMenu(6) = 'Image will be printed Separately'
  IF blFont THEN psMenu(7) = 'The Background Color is Black' $
  ELSE psMenu(7) = 'No Background Color'
  psMenu(8) = 'Distance Image-Axes: ' + $
	StrTrim( axisOffs/1000, 2 ) + ' cm'
  psMenu(9) = 'Distance Between Image Parts: ' + $
	StrTrim( imageOffs/1000, 2 ) + ' cm'
  IF reducedFmt THEN psMenu(10) = 'Reduced annotations' $
  ELSE psMenu(10) = 'All annotations'
  IF !p.font EQ 0 THEN psMenu(11) = 'Hardware fonts ' $
  ELSE psMenu(11) = 'Software fonts '
  IF noMinMax THEN psMenu(12) = 'No minimum/maximum annotations' $
  ELSE psMenu(12) = 'Minimum/Maximum annotations'
  psMenu(len-2) = 'Exit Printer Attributes Definition Menu'
  psMenu(len-1) = 'Redisplay this Menu'

  REPEAT BEGIN
  
    choice = General_Menu( psMenu, $
	'PostScript Specification: choose what to change or Exit', $
	OPAQUE = [ 0,0,0,0,0,0,0,0,0,0,0,0,1] )

    CASE choice OF
      1: BEGIN
            Read_Test, 'Please enter the new X origin: ', xPos, tmp
            xPos = tmp > 0 < 100
            psMenu(0) = 'X origin: ' + StrTrim( xPos, 2 ) + ' cm'
          END
      2: BEGIN
            Read_Test, 'Please enter the new Y origin: ', yPos, tmp
            yPos = tmp > 0 < 100
            psMenu(1) = 'Y origin: ' + StrTrim( yPos, 2 ) + ' cm'
          END
      3: BEGIN
            Read_Test, 'Please enter the new width: ', width, tmp
            width = tmp > 0 < 100
            psMenu(2) = 'Width ' + StrTrim( width, 2) + ' cm '
          END
      4: BEGIN
            Read_Test, 'Please enter the new height: ', height, tmp
            height = tmp > 0 < 100
            psMenu(3) = 'Height ' + StrTrim( height, 2 ) + ' cm'
          END
       5: IF landscape THEN BEGIN
              landscape = 0
              psMenu(4) = 'Portrait Orientation'
           ENDIF ELSE BEGIN
              landscape = 1
              psMenu(4) = 'Landscape Orientation'
           ENDELSE
       6: IF reverse THEN BEGIN
              reverse = 0
              psMenu(5) = 'Normal Mode'
           ENDIF ELSE BEGIN
              reverse = 1
              psMenu(5) = 'Reverse Mode'
           ENDELSE
       7: IF encaps THEN BEGIN
              encaps = 0
              psMenu(6) = 'Image will be printed Separately'
           ENDIF ELSE BEGIN
              encaps = 1
              psMenu(6) = 'Image will be Encapsulated'
           ENDELSE
      8: IF blFont THEN BEGIN
              blFont = 0
              psMenu(7) = 'No Background Color'
           ENDIF ELSE BEGIN
              blFont = 1
              psMenu(7) = 'The Background Color is Black'
           ENDELSE
      9: BEGIN
            Read_Test, 'Please enter the new Image-Axis distance ',  $
	axisOffs/1000, tmp
            axisOffs = (tmp > 0 < 100)*1000
            psMenu(8) = 'Distance Image-Axes: ' + $
	StrTrim( axisOffs/1000, 2 ) + ' cm'
           END
      10: BEGIN
              Read_Test, 'Please enter the distance between image parts ', $
	 imageOffs/1000, tmp
              imageOffs = (tmp > 0 < 100)*1000
              psMenu(9) = 'Distance Between Image Parts: ' + $
	StrTrim( imageOffs/1000, 2 ) + ' cm'
            END
      11: IF reducedFmt THEN BEGIN
              reducedFmt = 0
              psMenu(10) = 'All annotations'
           ENDIF ELSE BEGIN
              reducedFmt = 1
              psMenu(10) = 'Reduced annotations'
           ENDELSE
       12: IF !p.font EQ 0 THEN BEGIN 
               !p.font = -1 & psMenu(11) = 'Software fonts'
             ENDIF ELSE BEGIN
               !p.font = 0 & psMenu(11) = 'Hardware fonts'
             ENDELSE
       13: IF noMinMax EQ 0 THEN BEGIN 
               noMinMax = 1 & psMenu(12) = 'No miminum/maximum annotations'
             ENDIF ELSE BEGIN
               noMinMax = 0 & psMenu(12) = 'Minimum/maximum annotations'
             ENDELSE
       ELSE:
    ENDCASE

    PutMiscPS, encaps, landscape, reverse, blFont, reducedFmt, noMinMax
    PutOffsets, axisOffs, imageOffs, /PS
    PutImageSize, xPos, yPos, width, height, sch, /PS

  END UNTIL choice EQ len - 1

END ; Ps Attributes modification


PRO DisplayModif

  GetWinSize, wWidth, wHeight
  GetImageSizes, xPos, yPos, iWidth, iHeight
  GetOffsets, axisOffs, imageOffs

  len = 10
  dMenu = StrArr( len )
  
  dMenu(0) = 'Image X origin: ' + StrTrim( xPos, 2 ) + ' pixels'
  dMenu(1) = 'Image Y origin: ' + StrTrim( yPos, 2 ) + ' pixels'
  dMenu(2) = 'Image Width: '  + StrTrim( iWidth ) + ' pixels'
  dMenu(3) = 'Image Height: '+ StrTrim( iHeight ) + ' pixels'
  dMenu(4) = 'Window Width ' + StrTrim( wWidth, 2) + ' pixels '
  dMenu(5) = 'Window Height ' + StrTrim( wHeight, 2 ) + ' pixels'
  dMenu(6) = 'Distance Image-Axes: ' + $
	StrTrim( axisOffs, 2 ) + ' pixels'
  dMenu(7) = 'Distance Between Image Parts: ' + $
	StrTrim( imageOffs, 2 ) + ' pixels'
  dMenu(8) = 'Exit Display Modification Menu'
  dMenu(9) = 'Redisplay this Menu'

  REPEAT BEGIN
    
    choice = General_Menu( dMenu, $
	 'Display Modification: choose what to change or Exit', $
	OPAQUE =  [0,0,0,0,0,0,0,0,0,1] )

    CASE choice OF 
      1: BEGIN
            Read_Test, 'Please enter the new X origin: ', xPos, tmp
            xPos = Fix(tmp) > 0 < wWidth
            dMenu(0) = 'X origin: ' + StrTrim( xPos, 2 ) + ' pixels'
          END
      2: BEGIN
            Read_Test, 'Please enter the new Y origin: ', yPos, tmp
            yPos = Fix(tmp) > 0 < wHeight
            dMenu(1) = 'Y origin: ' + StrTrim( yPos, 2 ) + ' pixels'
          END
      3: BEGIN
            Read_Test, 'Please enter the new image width ', iwidth, tmp
            iwidth = Fix(tmp) > 1 < (wWidth - xPos )
            dMenu(2) = 'Image Width ' + StrTrim( iwidth, 2) + ' pixels '
          END
      4: BEGIN
            Read_Test, 'Please enter the new image height ', iheight, tmp
            iheight = Fix(tmp) > 1 < (wHeight - yPos ) 
            dMenu(3) = 'Image Height ' + StrTrim( iheight, 2 ) + ' pixels'
          END
      5: BEGIN
            Read_Test, 'Please enter the new window width ', wWidth, tmp
            wWidth = Fix(tmp) > (iwidth+xPos) < 2000
            dMenu(4) = 'Window Width ' + StrTrim( wwidth, 2) + ' pixels '
          END
      6: BEGIN
            Read_Test, 'Please enter the new window height ', wHeight, tmp
            wHeight = Fix(tmp) > (iheight+yPos) < 1500
            dMenu(5) = 'Window Height ' + StrTrim(wHeight, 2 ) + $
	' pixels'
          END
      7: BEGIN
            Read_Test, 'Please enter the new image-axis offset ', $
	axisOffs, tmp
            axisOffs = Fix(tmp) > 0 < (wWidth < wHeight)
            dMenu( 6 ) = 'Distance Image-Axes: ' + $
	StrTrim( axisOffs, 2 ) + ' pixels'
          END
      8: BEGIN
            Read_Test,'Please enter the new distance between image parts' $
	,0, tmp
            imageOffs = Fix(tmp) > 0 < (wWidth < wHeight)
            dMenu( 7 ) =  'Distance Between Image Parts: ' + $
	StrTrim( imageOffs, 2 ) + ' pixels'
          END
      ELSE:
    ENDCASE

    PutWinSize, wWidth, wHeight
    PutImageSize, xPos, yPos, iWidth, iHeight
    PutOffsets, axisOffs, imageOffs

  END UNTIL choice EQ len-1

END ; display attr


PRO Custom_2D
	
  COMMON ImageReal, image, xAxis, yAxis, fName
  COMMON Boundaries, xMin, xMax, yMin, yMax

  mainMenuLength = 11
  mainMenu=StrArr(mainMenuLength)

  mainMenu(0)= 'Axis Definition Modification ... '
  mainMenu(1)= 'Titles Modification ...  '
  mainMenu(2)= 'Display Modification ... '
  mainMenu(3)= 'Printer  Attributes ... '
  mainMenu(4)= 'Redisplay Image '
  mainMenu(5)= 'Make PostScript File / Print'
  mainMenu(6)= 'Save Settings'
  mainMenu(7)= 'Restore Defaults'
  mainMenu(8)= 'Restore Settings'
  mainMenu(9)= 'Exit Customize Menu'
  mainMenu(10)= 'Redisplay this Menu'

  choice = 0

  REPEAT BEGIN

    change = General_Menu(mainMenu, $
	'Customize: Choose Option')
    CASE change OF
    1: Modif_Axis
    2: TitlesModif
    3: DisplayModif
    4: PSAttrModif
    5: Show_Image, image( xMin: xMax, yMin: yMax ),  $
	xAxis( xMin: xMax ), yAxis( yMin: yMax ), /SIZES_ON, $
	WINNR = GetWNr(), HMS = GetHMS()
    6: BEGIN
          PrintInterface, status
          Show_Image, image( xMin: xMax, yMin: yMax ),  $
	xAxis( xMin: xMax ), yAxis( yMin: yMax ), /SIZES_ON, $
	/PS
          PrintInterface, status, /PRINT
        END
    7: Settings, /SAVE
    8: Init_Display
    9: Settings, /RESTORE
  ELSE:
  END
END UNTIL change EQ mainMenuLength-1


END
