home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_ciel_client_info.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  8.9 KB  |  433 lines

  1. unit ntc_ciel_client_info;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     StdCtrls,
  36.     ExtCtrls,
  37.     inifiles,
  38.     Buttons,
  39.  
  40.     ntc_ciel_client_form,
  41.     ntc_ciel_client_network,
  42.     ntc_ciel_client_control,
  43.     ntc_ciel_client_object;
  44.  
  45. const
  46.     default_refresh_rate=30000;
  47.  
  48. type
  49.     Tscope_info = class(tform)
  50.         info_panel: TPanel;
  51.         coord_box: TGroupBox;
  52.         ra_label: TLabel;
  53.         alt_label: TLabel;
  54.         dec_label: TLabel;
  55.         az_label: TLabel;
  56.         hours_label: TLabel;
  57.         ra_minutes_label: TLabel;
  58.         ra_seconds_label: TLabel;
  59.         degrees_label: TLabel;
  60.         minutes_label: TLabel;
  61.         seconds_label: TLabel;
  62.         refresh_rate_label: TLabel;
  63.         dec_degrees_edit: TEdit;
  64.         alt_degrees_edit: TEdit;
  65.         az_degrees_edit: TEdit;
  66.         ra_hours_edit: TEdit;
  67.         ra_minutes_edit: TEdit;
  68.         ra_seconds_edit: TEdit;
  69.         dec_minutes_edit: TEdit;
  70.         dec_seconds_edit: TEdit;
  71.         az_minutes_edit: TEdit;
  72.         az_seconds_edit: TEdit;
  73.         alt_minutes_edit: TEdit;
  74.         alt_seconds_edit: TEdit;
  75.         info_label: TLabel;
  76.         get_ra_dec_button: TBitBtn;
  77.         get_alt_az_button: TBitBtn;
  78.         get_all_button: TBitBtn;
  79.     controller_timer: TTimer;
  80.     refresh_rate_edit: TEdit;
  81.     msecs_label: TLabel;
  82.     timer_button: TBitBtn;
  83.  
  84.         { form functions }
  85.         procedure formcreate(
  86.             Sender:TObject);
  87.  
  88.         procedure form_close_query(
  89.                     Sender: TObject;
  90.             var CanClose: Boolean);
  91.  
  92.         { information retrieval }
  93.         procedure get_info;
  94.  
  95.         Procedure show_info;
  96.  
  97.         procedure get_ra_dec;
  98.  
  99.         procedure get_az_alt;
  100.  
  101.         { configuration }
  102.         procedure load_settings;
  103.  
  104.         procedure save_settings;
  105.  
  106.         { events }
  107.         procedure FormShow(
  108.             Sender: TObject);
  109.  
  110.         procedure adjust;
  111.  
  112.         procedure check_activate(
  113.             Sender: TObject);
  114.  
  115.         procedure refresh_rate_editChange(
  116.             Sender: TObject);
  117.  
  118.         procedure get_ra_dec_buttonClick(
  119.             Sender: TObject);
  120.  
  121.         procedure get_alt_az_buttonClick(
  122.             Sender: TObject);
  123.  
  124.         procedure get_all_buttonClick(
  125.             Sender: TObject);
  126.  
  127.         procedure timer_buttonClick(
  128.             Sender: TObject);
  129.  
  130.         procedure controller_timerTimer(
  131.             Sender: TObject);
  132.  
  133.     private
  134.         { global information }
  135.     public
  136.         { Public declarations }
  137.         info_string:string;
  138.         { configuration }
  139.         dimensions:dimensions_record;
  140.         refresh_rate:integer;
  141.  
  142.         { events }
  143.         procedure check_visible_and_show_hide(
  144.             sender:tobject);
  145.             
  146.         procedure hide_form;
  147.         procedure show_form;
  148.     end;
  149.  
  150. var
  151.     scope_info: Tscope_info;
  152.  
  153. implementation
  154.  
  155. uses
  156.     ntc_ciel_client_focus,
  157.     ntc_ciel_client_tracking,
  158.     ntc_ciel_client_search;
  159.  
  160. {$R *.dfm}
  161.  
  162.     { --------------
  163.         form functions
  164.         -------------- }
  165.  
  166. procedure Tscope_info.formcreate(
  167.     Sender:TObject);
  168. begin
  169.     controller_timer.enabled:=false;
  170.     load_settings;
  171.     visible:=false;
  172. end;
  173.  
  174. procedure Tscope_info.form_close_query(
  175.             Sender: TObject;
  176.     var CanClose: Boolean);
  177. begin
  178.     visible:=false;
  179.     with dimensions do
  180.         begin
  181.             form_top:=top;
  182.             form_left:=left;
  183.         end;
  184.     if ciel_closing then
  185.         canclose:=true
  186.     else
  187.         canclose:=false;
  188. end;
  189.  
  190.     { ---------------------
  191.         information retrieval
  192.         --------------------- }
  193.  
  194. Procedure tscope_info.show_info;
  195. var
  196.     h:hms;
  197.     d:dms;
  198.     a:ams;
  199. begin
  200.     with current_object do
  201.         begin
  202.             right_ascension_str(h);
  203.             with h do
  204.                 begin
  205.                     ra_hours_edit.text:=inttostr(hours);
  206.                     ra_minutes_edit.text:=inttostr(minutes);
  207.                     ra_seconds_edit.text:=inttostr(seconds);
  208.                 end;
  209.             declination_str(d);
  210.             with d do
  211.                 begin
  212.                     dec_degrees_edit.text:=inttostr(degrees);
  213.                     dec_minutes_edit.text:=inttostr(minutes);
  214.                     dec_seconds_edit.text:=inttostr(seconds);
  215.                 end;
  216.             azimuth_str(d);
  217.             with d do
  218.                 begin
  219.                     az_degrees_edit.text:=inttostr(degrees);
  220.                     az_minutes_edit.text:=inttostr(minutes);
  221.                     az_seconds_edit.text:=inttostr(seconds);
  222.                 end;
  223.             altitude_str(a);
  224.             with a do
  225.                 begin
  226.                     alt_degrees_edit.text:=inttostr(degrees);
  227.                     if (degrees<0) or (degrees>90) then
  228.                         begin
  229.                             scope_control.stop_scope;
  230.                             alt_degrees_edit.Color:=clRed
  231.                         end
  232.                     else
  233.                         alt_degrees_edit.Color:=clWindow;
  234.                     alt_minutes_edit.text:=inttostr(minutes);
  235.                     alt_seconds_edit.text:=inttostr(seconds);
  236.                 end;
  237.         end;
  238.     with info_label do
  239.         begin
  240.             caption:=info_string;
  241.             width:=240;
  242.         end;
  243. end;
  244.  
  245. procedure tscope_info.get_info;
  246. var
  247.     s:string;
  248. begin
  249.     with scope_network,scope_control,scope_focus,scope_tracking do
  250.          if (send_request_check('get_info')=[exit_ok]) and
  251.                 get_string('name',s) and
  252.                 get_boolean('can_goto',can_goto) and
  253.                 get_boolean('can_sync',can_sync) and
  254.                 get_boolean('can_slew',can_slew) and
  255.                 get_boolean('can_focus',can_focus) and
  256.                 ((can_focus and get_integer('focus_speeds',focus_speeds)) or
  257.                  not can_focus) and
  258.                 get_boolean('can_track',can_track) then
  259.         begin
  260.             name:=shortstring(s);
  261.             scope_name:=name;
  262.         end
  263.     else
  264.         begin
  265.             name:='';
  266.             scope_name:='unknown scope';
  267.         end;
  268. end;
  269.  
  270. procedure tscope_info.get_ra_dec;
  271. begin
  272.     with scope_network,scope_control,scope_focus,current_object do
  273.          if (send_request_check('get_ra_dec')=[exit_ok]) and
  274.                  get_float('ra',ra) then
  275.         get_float('dec',dec);
  276. end;
  277.  
  278. procedure tscope_info.get_az_alt;
  279. begin
  280.     with scope_network,scope_control,scope_focus,current_object do
  281.          if (send_request_check('get_az_alt')=[exit_ok]) and
  282.                  get_float('alt',alt) then
  283.         get_float('az',az);
  284. end;
  285.  
  286.     { -------------
  287.         configuration
  288.         ------------- }
  289.  
  290. procedure tscope_info.load_settings;
  291. begin
  292.     ini_file:=tinifile.create(application_path+'ciel.ini');
  293.     with ini_file do
  294.         begin
  295.             refresh_rate:=readinteger('info','refresh_rate',default_refresh_rate);
  296.             { form }
  297.             scope.get_dimensions(scope_info,@dimensions,'info',ini_file);
  298.             left:=dimensions.form_left;
  299.             top:=dimensions.form_top;
  300.             visible:=readbool('info','visible',false);
  301.         end;
  302.     ini_file.free;
  303. end;
  304.  
  305. procedure tscope_info.save_settings;
  306. begin
  307.     ini_file.writeinteger('info','refresh_rate',refresh_rate);
  308.     { form }
  309.     scope.find_vdu(scope_info,@dimensions);
  310.     scope.write_dimensions(@dimensions,left,top,'info',ini_file);
  311.     ini_file.writebool('info','visible',visible);
  312. end;
  313.  
  314.     { ------
  315.         events
  316.         ------ }
  317.  
  318. procedure Tscope_info.FormShow(
  319.     Sender: TObject);
  320. begin
  321.     with dimensions do
  322.         begin
  323.             top:=form_top;
  324.             left:=form_left;
  325.         end;
  326. end;
  327.  
  328. procedure tscope_info.adjust;
  329. begin
  330.     with dimensions do
  331.         begin
  332.             form_top:=trunc(form_top/last_screen_height*current_height);
  333.             form_left:=trunc(form_left/last_screen_width*current_width);
  334.         end;
  335.     if visible then
  336.         show;
  337. end;
  338.  
  339. procedure tscope_info.check_visible_and_show_hide(
  340.     sender:tobject);
  341. begin
  342.     if visible then
  343.         hide_form
  344.     else
  345.         show_form;
  346.     scope.show_hide(sender,visible);
  347. end;
  348.  
  349. procedure tscope_info.hide_form;
  350. begin
  351.     with dimensions do
  352.         begin
  353.             form_top:=top;
  354.             form_left:=left;
  355.         end;
  356.     Visible:=false;
  357.     formstyle:=fsnormal;
  358. end;
  359.  
  360. procedure tscope_info.show_form;
  361. begin
  362.     formstyle:=fsstayontop;
  363.     Visible:=true;
  364. end;
  365.  
  366. procedure Tscope_info.check_activate(
  367.     Sender: TObject);
  368. begin
  369.     scope.form_activate(scope_info,@dimensions);
  370. end;
  371.  
  372. procedure Tscope_info.refresh_rate_editChange(
  373.     Sender: TObject);
  374. begin
  375.     refresh_rate:=strtointdef(refresh_rate_edit.text,0);
  376.     if refresh_rate<5000 then
  377.         begin
  378.             refresh_rate:=5000;
  379.             refresh_rate_edit.text:=inttostr(refresh_rate);
  380.         end;
  381. end;
  382.  
  383. procedure Tscope_info.get_ra_dec_buttonClick(
  384.     Sender: TObject);
  385. begin
  386.     get_ra_dec;
  387.     show_info;
  388. end;
  389.  
  390. procedure Tscope_info.get_alt_az_buttonClick(
  391.     Sender: TObject);
  392. begin
  393.     get_az_alt;
  394.     show_info;
  395. end;
  396.  
  397. procedure Tscope_info.get_all_buttonClick(
  398.     Sender: TObject);
  399. begin
  400.     get_ra_dec;
  401.     get_az_alt;
  402.     show_info;
  403. end;
  404.  
  405. procedure Tscope_info.timer_buttonClick(
  406.     Sender: TObject);
  407. begin
  408.     if controller_timer.enabled then
  409.         begin
  410.             controller_timer.Enabled:=false;
  411.             timer_button.caption:='Start';
  412.         end
  413.     else
  414.         begin
  415.             timer_button.caption:='Stop';
  416.             controller_timer.Interval:=refresh_rate;
  417.             controller_timer.enabled:=true;
  418.         end;
  419. end;
  420.  
  421. procedure Tscope_info.controller_timerTimer(
  422.     Sender: TObject);
  423. begin
  424.     if scope_network.scope_client.connected and
  425.          not scope_network.network_timer.enabled then
  426.         begin
  427.             get_info;
  428.             show_info;
  429.         end;
  430. end;
  431.  
  432. end.
  433.