# coyote: CGWINDOW

- coyote/Graphics
- [Source code]

Description

      Creates a resizeable graphics window for IDL traditional commands (Plot, Contour,
      Surface, etc. or for Coyote Graphics routines, `cgPlot`, `cgContour`, `cgSurf`, etc.).
      In addition, the window contents can be saved as PostScript, PDF, or raster image
      files. If ImageMagick is installed on your machine, the raster image files can be
      created in very high quality from PostScript files.
      The program is designed to work with any IDL traditional graphics routine
      that is a procedure and includes no more than three positional parameters.
      Any number of keywords can be used to specify properties of the graphical
      output. Any number of graphics commands can be "added" the the cgWindow.
      Simply use the `AddCmd` keyword to add commands.
      If your program does not load its own color tables, the color tables in
      effect when cgWindow is first called are used to display the graphics
      commands.
      To create PostScript output from within cgWindow, your graphics program
      has to be written in such a way that it can work properly in the PostScript
      device. This means there are no Window commands, WSet commands, and the like
      that are not allowed in the PostScript device. Such commands are allowed in
      programs, of course, if they are "protected". Usually such protection looks
      like this::
         IF (!D.Flags AND 256) NE 0 THEN Window, ...
      The Coyote Graphics program `cgDisplay` is a good program for opening graphics
      "windows", because such PostScript protection is built into the program. In a PostScript
      device, cgDisplay produces a "window" with the same aspect ratio as the current
      display graphics window, which is an aid in producing PostScript output that
      looks like the same output in the display window.
      Much better looking raster files can be created from the cgWindow contents,
      if the raster files are created by converting PostScript files to the raster
      file. If the ImageMagick "convert" command can be found on your machine, you
      will have the option to create raster files using this method. I *highly*
      recommend doing so, as fonts and other plot annotation will be of much higher
      quality using this method.
      cgWindow has been designed to work with other Coyote Graphics routines: `cgPlot`,
      `cgContour`, `cgSurf`, and so on, although I expect it to work with any IDL
      traditional graphics routine, if the routine is well written.

Categories

      Graphics

Author

      FANNING SOFTWARE CONSULTING::
         David W. Fanning
         1645 Sheely Drive
         Fort Collins, CO 80526 USA
         Phone: 970-221-0438
         E-mail: david@idlcoyote.com
         Coyote's Guide to IDL Programming: http://www.idlcoyote.com

Copyright

      Copyright (c) 2011, Fanning Software Consulting, Inc.
      eates a resizeable graphics window for IDL traditional commands (Plot, Contour,
      rface, etc. or for Coyote Graphics routines, cgPlot, cgContour, cgSurf, etc.).
       addition, the window contents can be saved as PostScript files or as raster image
      les. If ImageMagick is installed on your machine, the raster image files can be
      eated in very high quality from PostScript files.

Params

      command: in, required, type=string
         The graphics procedure command to be executed. This parameter
         must be a string and the the command must be a procedure. Examples
         are 'Surface', 'Contour', 'Plot', 'cgPlot', cgContour, etc.
      p1: in, optional, type=any
         The first positional parameter appropriate for the graphics command.
      p2: in, optional, type=any
         The second positional parameter appropriate for the graphics command.
      p3: in, optional, type=any
         The third positional parameter appropriate for the graphics command.
      p4: in, optional, type=any
         The fourth positional parameter appropriate for the graphics command.

Keywords

      addcmd: in, optional, type=boolean, default=0
         Set this keyword to add an additional graphics command to an cgWindow.
         The command is added to the last created cgWindow, unless the WinID
         keyword is used to select another cgWindow. Adding a command causes
         all the commands in the window to be immediately executed. If this is
         not behavior you desire, use the LOADCMD keyword instead. If CMDINDEX
         is used to select a command index, the new command is added before
         the command currently occuping that index in the command list.
      altps_Keywords: in, optional, type=string
         A structure containing alternative keyword names (as tags) and values for
         those keywords to be used when the current device is the PostScript device.
         See http://www.idlcoyote.com/cg_tips/kwexpressions.php and the examples
         below for details on how to use this keyword.
      altps_Params: in, optional, type=IntArr(3)
         A structure containing alternative parameter values to be used when
         the current device is the PostScript device. Structure names are restricted
         to the names "P1", "P2", "P3" and "P4" to correspond to the equivalent positional
         parameter. See http://www.idlcoyote.com/cg_tips/kwexpressions.php and the
         examples below for details on how to use this keyword.
      cmddelay: in, optional, type=float
         If this keyword is set to a value other than zero, there will be a
         delay of this many seconds between command execution. This will permit
         "movies" of command sequences to be displayed.
      cmdindex: in, optional, type=integer
         This keyword is used to select which command in an cgWindow to act on
         when the AllCmd, DeleteCmd, LoadCmd and ReplaceCmd keywords are used.
         See the descriptions of these keywords for details on what happens when
         CmdIndex is missing.
      deletecmd: in, optional, type=boolean, default=0
         Set this keyword to delete a graphics command from an cgWindow.
         If CmdIndex is undefined the last command entered into the window is
         deleted. It is not possible to delete the last command in the window.
         Use WinID to identify the cgWindow you are interested in. If WinID
         is undefined, the last cgWindow created is used.
      executecmd: in, optional, type=boolean, default=0
         Set this keyword to immediate execute all the commands in an cgWindow.
         Normally, this is used after commands have been loaded with LOADCMD.
      group_leader: in, optional
         The identifier of a widget to serve as a group leader for this program.
         If the group leader is destroyed, this program is also destroyed. Used
         when calling this program from another widget program.
      listcmd: in, optional, type=boolean, default=0
         If this keyword is set, the commands currently in the cgWindow are
         listed. Use WinID to identify the cgWindow you are interested in.
         If WinID is undefined, the last cgWindow created is used.
      loadcmd: in, optional, type=boolean, default=0
         Set this keyword to add an additional graphics command to an cgWindow.
         The command is added to the last created cgWindow, unless the WinID
         keyword is used to select another cgWindow. Loaded commands are not
         automatically executed. Set the EXECUTECMD keyword at the end of loading
         to execute the loaded commands. If CMDINDEX is used to select a command
         index, the new command is loaded before the command currently occuping
         that index in the command list.
      method: in, optional, type=boolean, default=0
         Set this keyword if the command is an object method call rather than a
         procedure call. If this keyword is set, the first positional parameter, p1,
         must be present and must be a valid object reference.
      replacecmd: in, optional, type=boolean, default=0
         Set this keyword to replace a graphics command from an cgWindow.
         If CmdIndex is undefined, *all* commands in the window are replaced. Use
         WinID to identify the cgWindow you are interested in. If WinID is
         undefined, the last cgWindow created is used for the replacement.
      waspect: in, optional, type=float, default=normal
         Set this keyword to the aspect ratio you would like the window to have.
         The aspect ratio is calculated as (ysize/xsize). Must be a float value.
         If this keyword is set, the window will maintain this aspect ratio,
         even when it is resized.
      wbackground: in, optional, type=varies, default=!P.Background
         The background color of the window. Specifying a background color
         automatically sets the WErase keyword.
      wdestroyobjects: in, optional, type=boolean, default=0
         If this keyword is set, and any of the input parameters p1-p4 is an object,
         the object parameter will be destroyed when the window is destroyed.
      werase: in, optional, type=boolean, default=0
         Set this keyword to cause the window to be erased before graphics commands
         are drawn. This may need to be set, for example, to display images.
      winid: in, optional, type=integer
         Use this keyword to select a previously open and existing cgWindow identifier
         (the number between the parentheses in the title bar of cgWindow). The AddCmd,
         ReplaceCmd, ListCmd, and DeleteCmd keywords all apply to the "current" cgWindow
         unless this keyword is used to select another existing cgWindow to apply the
         commands to.
      wmulti: in, optional, type=intarr(5)
          Set this keyword in exactly the same way you would set the !P.Multi keyword.
          It will allow you to display multi-plots in the cgWindow graphics window.
      wobject: out, optional, type=object
         cgWindow creates a cgCmdWindow object. This object reference is returned
         if this keyword is present.
      woxmargin: in, optional, type=float
         A two-element array indicating the left and right X outside margins for the
         graphical display. Used only when doing multiple plots with `WMulti`.
      woymargin: in, optional, type=float
         A two-element array indicating the bottom and top Y outside margins for the
         graphical display. Used only when doing multiple plots with `WMulti`.
      wxpos: in, optional, type=integer, default=5
         The x offset in device coordinates of the cgWindow from the upper-left corner of the display.
      wypos: in, optional, type=integer, default=5
         The y offset in device coordinates of the cgWindow from the upper-left corner of the display.
      wxsize: in, optional, type=integer, default=640
         The x size in device coordinates of the graphics window.
      wysize: in, optional, type=integer, default=5
         The y size in device coordinates of the the graphics window.
      wtitle: in, optional, type=string, default='Resizeable Graphics Window'
         The title of the graphics window.

Examples

      Test code::
         data = cgDemoData(17)
         cgWindow, 'cgPlot', data, COLOR='red'
         cgWindow, 'cgPlot', data, PSYM=2, /Overplot, COLOR='dodger blue', /AddCmd
         cgWIndow, 'cgPlot', cgDemoData(17), color='olive', linestyle = 2, /Overplot, /AddCmd
         cgWindow, /ListCmd
         cgWindow, 'cgPlot', data, COLOR='purple', /ReplaceCMD, CMDINDEX=0
      Additional examples can be found here::
          http://www.idlcoyote.com/graphics_tips/cgwindow.html
      Example using different keyword parameters for the display and PostScript output::
          IDL> cgPlot, cgDemoData(1), /WINDOW, $
               THICK=1.0, XTITLE='Distance (' + cgGreek('mu') + 'm)', $
               ALTPS_KEYWORDS={THICK:4.0, XTITLE:'Distance (' + cgGreek('mu', /PS) + 'm)'}
      Example using different positional parameters::
          IDL> cgText, 0.20, 0.85, /Normal, 'Line of Text', ALIGNMENT=0.0, $
               ALTPS_KEYWORDS={ALIGNMENT:1.0}, ALTPS_PARAMS={P1:0.88}, /ADDCMD
      Additional examples can be found here::
          http://www.idlcoyote.com/cg_tips/kwexpressions.php

History

      Change History::
         Written, 17 January 2011. DWF.
         Fixed a problem with the example code, and added EMPTY to end of Draw method
            to force UNIX machines to empty the graphics buffer after CALL_PROCEDURE. 20 Jan 2011. DWF.
         Improved documentation and error handling. 19 Jan 2011. DWF.
         More improved error handling and messages. 26 Jan 2011. DWF.
         Made changes to accommodate the new cgControl routine. 27 Jan 2011. DWF.
         Added WXOMARGIN and WYOMARGIN keywords. 28 Jan 2011. DWF.
         Numerous changes leading up to official release. 4 Feb 2011. DWF.
         Added workaround for UNIX bug for draw widget creation. 5 Feb 2011. DWF.
         Corrected a window aspect ratio problem with PostScript output by making the
            window the current window before calling cgPS_Open. 17 Feb 2011. DWF.
         Added machinery for programmatically generating raster files. 18 Feb 2011. Jeremy Bailin.
         Problem with restoring visualizations fixed. 6 March 2011. DWF.
         Fixed a problem with CALL_METHOD, which requires one positional parameter. 8 March 2011. DWF.
         Added the ability to set and unset adjustable text size in the window. 24 April 2011. DWF.
         Fixed a problem in the ReplaceCommand method that had input parameters reversed. 6 May 2011. DWF.
         Added the ability to set the dimensions of the draw widget programmatically. 14 June 2011.
         Added the keywords EvalKeywords and EvalParams to allow evaluation of command parameters and
             keywords at run-time. See http://www.idlcoyote.com/cg_tips/kwexpressions.php for
             additional details and explanations of how these keywords should be used. 2 Aug 2011.
         Problem dereferencing a null pointer in DRAW method fixed. 3 Aug 2011. DWF.
         Changes to handle inability to create raster files from PS encapsulated files in
            landscape mode. 26 Aug 2011. DWF.
         Added ability to set PostScript color mode. 30 Aug 2011. DWF.
         The method I was using for evaluating keyword and argument parameters at run-time
             was just WAY too complicated and difficult to use. I have eliminated this
             method (along with the EvalKeywords and EvalParams) in favor of a method that
             allows the user to supply alternative values to use in the PostScript device.
             This uses keywords AltPS_Keywords and AltPS_Params to collect these alternative
             arguments in structures that can be used at run-time to supply alternative values.
             As before, this is explained in detail at http://www.idlcoyote.com/cg_tips/kwexpressions.php.
             1 Sept 2011. DWF.
          Missed a couple of places to set decomposition color mode. 7 Sept 2011. DWF.
          Fixed a problem with improper filename when creating raster file vis
              Imagemagick via cgControl. 10 Oct 2011. DWF.
          Added WASPECT keyword to allow window aspect ratio to be set. 9 Nov 2011. DWF.
          Added PDF file to the Save As menu. Requires Ghostscript to be installed on some machines. 6 Dec 2011. DWF.
          Added modifications to allow PDF files to be programmatically created from cgControl. 11 Dec 2011. DWF.
          Added the ability to specify a fourth positional parameter. 6 Jan 2012. DWF.
          Separated off the cgCmdWindow part of the code to make an object-widget draw widget. 19 Jan 2012. DWF.
          Fixed a small type with the Outside Margin keywords that was preventing these from being used. 19 April 2012. DWF.
          In decompling cgWindow from cgCmdWindow, I accidentally named the WASPECT keyword ASPECT. Restored
              original name in this version. 13 July 2012. DWF.
          Added WDestroyObjects keyword to destroy objects parameters, if needed. 11 November 2012. DWF.
          Restored the WMULTI keyword win calling cgCmdWindow. 11 Feb 2013. DWF.