/* * ***************************************************************** * * * * * Copyright (c) Fast Corporation, 1997 * * * * * * All Rights Reserved. Unpublished rights reserved under * * * the copyright laws of the Japan. * * * * * * The software contained on this media is proprietary to * * * and embodies the confidential technology of Fast * * * Corporation. Possession, use, duplication or * * * dissemination of the software and media is authorized only * * * pursuant to a valid written license from Fast Corporation. * * * * * ***************************************************************** */ /* CSC90X グレイサーチ(2つのグレイパタンを切り替え、各々登録/サーチを行う)GSDEF2.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 97/08/26 Ver 2.0 99/05/12 サーチエラー時にエラーメッセージが出ない不具合を修正 Ver 3.0 00/05/16 注記:m_menu.hをインクルードして下さい。 m_menu.c及びm_note.cをリンクして下さい。 */ /* * Include compiler runtime library */ #include #include /* * Include CSC90X library */ #include "f_stdlib.h" #include "f_time.h" #include "f_gui.h" #include "f_stdio.h" #include "f_graph.h" #include "f_image.h" #include "f_pinf.h" #include "f_video.h" #include "f_system.h" #include "f_search.h" #include "f_file.h" /* * Include CSC90X common local */ #include "m_menu.h" /* * プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); void gs_set( void ); void gs_joken( void ); void ptn_reg( void ); void ptn_disp( void ); void wind_set( int *, int *, int *, int * ); int alloc_ptn_area( void ); void ptn_change( void ); void ptn_search( void ); extern int message_note( void ); /* * メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 4 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " GRAY ", " 設 定 " }, { " PROC3 ", "パタン切替" }, { " EXEC ", " 実 行 " }, { " PROC4 ", " 処理4 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 #define GP_FILE1 1 #define GP_FILE2 2 #define GP_SIZE 100000 static char *select[3] = { "通常" , "高 " , "超高" }; int name1, name2; char *gray_ptn_adrs; int current_ptn_file; int gs_wxs; /* サーチ範囲始点X */ int gs_wys; /* サーチ範囲始点Y */ int gs_wxe; /* サーチ範囲終点X */ int gs_wye; /* サーチ範囲終点Y */ int seido; /* 精度 */ int complex; /* 複雑度 */ int mid_lower; /* 途中下限値 */ int last_lower; /* 最終下限値 */ /* * メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; /* パラメタ初期化 */ xpos = INIT_CUR_POS_X; ypos = INIT_CUR_POS_Y; s_xpos = INIT_CUR_POS_X; s_ypos = INIT_CUR_POS_Y; name1 = 0x314E5450; /* PTN1 */ name2 = 0x324E5450; /* PTN2 */ gs_wxs = 0; gs_wys = 0; gs_wxe = 511; gs_wye = 479; seido = 1; complex = 1; mid_lower = 5000; last_lower = 7000; current_ptn_file = GP_FILE1; /* 入力ビデオ制御 */ Lib_input_video_control( GRAY_PLANE ); /* ビデオ出力表示項目制御 */ Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* ビデオ表示項目クリア */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* カーソル初期化 */ Lib_init_cursor(); /* サーチパタン格納領域の確保 */ if ( NORMAL_RETURN == alloc_ptn_area() ) { /* メインメニューの表示 */ main_menu_disp(); /* マウスカーソルの表示 */ Lib_draw_cursor( INIT_CUR_POS_X, INIT_CUR_POS_Y ); /* メニュー制御 */ for (;;) { sts = 0; /* マウス位置読みとり */ sts = Lib_see_current_position( &xpos, &ypos ); if ( s_xpos != xpos || s_ypos != ypos ) { /* マウス表示位置移動 */ Lib_move_cursor( xpos, ypos ); s_xpos = xpos; s_ypos = ypos; } /* 処理振り分け */ if( CURSOR_EXECUTE == sts ) { if ( xpos > MENU_1_XS && xpos < MENU_1_XE && ypos > MENU_1_YS && ypos < MENU_1_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); gs_set(); /* 設定 */ main_menu_disp(); } else if ( xpos > MENU_2_XS && xpos < MENU_2_XE && ypos > MENU_2_YS && ypos < MENU_2_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); ptn_change(); /* パタン切替 */ main_menu_disp(); } else if ( xpos > MENU_3_XS && xpos < MENU_3_XE && ypos > MENU_3_YS && ypos < MENU_3_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); ptn_search(); /* パタンサーチ */ main_menu_disp(); } else if ( xpos > MENU_H_XS && xpos < MENU_H_XE && ypos > MENU_H_YS && ypos < MENU_H_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); disp_help(); /* ヘルプ */ main_menu_disp(); } else if ( xpos > MENU_E_XS && xpos < MENU_E_XE && ypos > MENU_E_YS && ypos < MENU_E_YE ) { break; /* 終了 */ } } } Lib_lfree( gray_ptn_adrs ); } } /* * メインメニュー表示 */ static void main_menu_disp( void ) { int iLanguage; /* 日本語/英語表示文字列切替情報取得 */ iLanguage = Lib_get_disp_language(); /* 整列キー表示 -> ( m_menu.c ) */ SUB_menu_disp4he( (char *)str_main_menu[0][iLanguage], (char *)str_main_menu[1][iLanguage], (char *)str_main_menu[2][iLanguage], (char *)NULL ); } /* * ヘルプ表示 */ static void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 GSDEF2" ); Lib_chrdisp( 11, 10, "2つのサーチ・パタン格納ファイルを切り替えて" ); Lib_chrdisp( 11, 12, "サーチを行うサンプルです。" ); Lib_chrdisp( 11, 14, "パタンファイルはGRAY1.PTNとGRAY2.PTNです。" ); } /************************************************************************/ /* サーチ設定 */ /************************************************************************/ void gs_set( void ) { int pad_level_ptn; int status_flag; int rtn; pad_level_ptn = Lib_view_open(); Lib_view_set_title( pad_level_ptn, "サーチ設定" ); Lib_view_set_null( pad_level_ptn, 5, 5, "サーチ条件" , 0 ); Lib_view_set_null( pad_level_ptn, 5, 35, "パタン登録" , 1 ); Lib_view_set_null( pad_level_ptn, 5, 65, "パタン表\示" , 2 ); Lib_view_set_null( pad_level_ptn, 5, 95, "サーチ範囲" , 3 ); Lib_view_set_size( pad_level_ptn, 50, 80, 30, 5 ); Lib_draw_command( pad_level_ptn ); for ( status_flag = ON; OFF != status_flag; ) { if ( ERROR_RETURN != ( rtn = Lib_process_command( pad_level_ptn ) ) ) { switch( rtn ) { case 0:/* サーチ条件 */ gs_joken(); break; case 1:/* パタン登録 */ ptn_reg(); break; case 2:/*パタン表示*/ ptn_disp(); break; case 3:/* サーチ範囲 */ wind_set( &gs_wxs, &gs_wys, &gs_wxe, &gs_wye ); break; case 102:/* 終了 */ status_flag = OFF; break; } } } Lib_erase_command( pad_level_ptn ); Lib_view_close( pad_level_ptn ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /************************************************************************/ /* サーチ条件設定 */ /************************************************************************/ void gs_joken( void ) { int pad_level_gs; PVAL value_gs[4]; int no; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); pad_level_gs = Lib_view_open(); Lib_view_set_title( pad_level_gs, "サーチ条件" ); Lib_view_set_select ( pad_level_gs, 5, 5, "精度" , seido - 1, 3 , select, 0 ); Lib_view_set_uniq_numeral( pad_level_gs, 5, 35, "複雑度" , complex, 1, 9, 1 ); Lib_view_set_uniq_numeral( pad_level_gs, 5, 65, "途中下限値", mid_lower , 1000, 9999 , 2 ); Lib_view_set_uniq_numeral( pad_level_gs, 5, 95, "最終下限値", last_lower, 1000, 9999 , 3 ); Lib_view_set_size( pad_level_gs, 100, 130, 35, 5 ); Lib_draw_menu( pad_level_gs ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level_gs, value_gs ) ) ) { switch( no ) { case 101: /*「実行」が選択された */ seido = value_gs[0].select_type + 1; complex = value_gs[1].value_type; mid_lower = value_gs[2].value_type; last_lower = value_gs[3].value_type; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_gs ); Lib_view_close( pad_level_gs ); Lib_recover_plane( idc ); } /************************************************************************/ /* パタン登録 */ /************************************************************************/ void ptn_reg( void ) { char file_name[20]; char mess1[50]; char mess2[50]; int rtn; int name; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); Lib_freeze( TRANSMIT ); if ( GP_FILE1 == current_ptn_file ) { Lib_sprintf( file_name, "\\FS0\\GRAY1.PTN" ); name = name1; Lib_sprintf( mess1, "GRAY1.PTNセーブ中..." ); Lib_sprintf( mess2, "GRAY1.PTNをセーブできません" ); } else { Lib_sprintf( file_name, "\\FS0\\GRAY2.PTN" ); name = name2; Lib_sprintf( mess1, "GRAY2.PTNセーブ中..." ); Lib_sprintf( mess2, "GRAY2.PTNをセーブできません" ); } /* パタン登録 */ if ( 0 == ( rtn = Lib_gs_defpat( name ) ) ) { Lib_chrdisp( 1, 30, mess1 ); if ( 0 == Lib_fsave( file_name, gray_ptn_adrs, GP_SIZE ) ) { Lib_cls( CHAR_PLANE, BLACK_COLOR ); Lib_display_message( 112, 200, "エラー", mess2 ); } } if ( -1 == rtn ) Lib_display_message( 150, 200, "エラー", "既に200個登録済みです" ); else if ( -2 == rtn ) Lib_display_message( 150, 200, "エラー", "パタン格納領域不足です" ); Lib_cls( CHAR_PLANE, BLACK_COLOR ); Lib_freerun(); Lib_recover_plane( idc ); } /************************************************************************/ /* パタン表示 */ /************************************************************************/ void ptn_disp( void ) { int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); Lib_gs_dsppat( ); Lib_freerun(); Lib_recover_plane( idc ); } /*********************************************************************/ /*  ウインド設定                          */ /*********************************************************************/ void wind_set( xs, ys, xe, ye ) int *xs, *ys, *xe, *ye; /* 入出力:ウインド位置 */ { int pad_level_wind; PVAL value_wind[2]; int no; int x_size,y_size; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); pad_level_wind = Lib_view_open(); Lib_view_set_title( pad_level_wind, "サーチ範囲" ); x_size = *xe - *xs + 1; y_size = *ye - *ys + 1; Lib_view_set_box( pad_level_wind, 5, 5, "始点" , *xs , *ys , 3, 1, 0 ); Lib_view_set_box( pad_level_wind, 5, 35, "サイズ", x_size, y_size, 3, 0, 1 ); Lib_view_set_size( pad_level_wind, 100, 130, 5, 5 ); Lib_draw_menu( pad_level_wind ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level_wind, value_wind ) ) ) { switch( no ) { case 101: /*「実行」が選択された */ *xs = value_wind[0].box_type.x; *ys = value_wind[0].box_type.y; *xe = value_wind[0].box_type.x + value_wind[1].box_type.x - 1; *ye = value_wind[0].box_type.y + value_wind[1].box_type.y - 1; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_wind ); Lib_view_close( pad_level_wind ); Lib_recover_plane( idc ); } /***** サーチ・パタン領域の確保(起動時)*****/ int alloc_ptn_area( void ) { char file_name[20]; int mode; int error; if ( NULL != ( gray_ptn_adrs = Lib_mlalloc( GP_SIZE ) ) ) { if ( GP_FILE1 == current_ptn_file ) Lib_sprintf( file_name, "\\FS0\\GRAY1.PTN" ); else if ( GP_FILE2 == current_ptn_file ) Lib_sprintf( file_name, "\\FS0\\GRAY2.PTN" ); if ( ( unsigned long )NULL != Lib_fload( file_name, gray_ptn_adrs, GP_SIZE ) ) mode = CONTINUE_PTN_AREA; /* パタンエリアは継続して使用する */ else mode = INITIAL_PTN_AREA; /* パタンエリアは初期化して使用する */ /* サーチ・パタン定義エリア指定 */ if ( 0 == Lib_gs_defadrs( gray_ptn_adrs, GP_SIZE, mode ) ) error = NORMAL_RETURN; else { error = ERROR_RETURN; Lib_cls( CHAR_PLANE , BLACK_COLOR ); Lib_display_message( 100, 200, "エラー", "パタンエリアは使用できません" ); } } else { error = ERROR_RETURN; Lib_display_message( 100, 200, "エラー", "パタン用メモリーが確保できません" ); } return( error ); } /************************************************************************/ /* パタン切り替え */ /************************************************************************/ void ptn_change( ) { char file_name[20]; int rtn; int mode; if ( GP_FILE1 == current_ptn_file ) rtn = Lib_display_message2( 100, 100, "パタン切替", "GRAY2.PTNに変更しますか?" ); else if ( GP_FILE2 == current_ptn_file ) rtn = Lib_display_message2( 100, 100, "パタン切替", "GRAY1.PTNに変更しますか?" ); if ( PAD_EXECUTE == rtn ) { if ( GP_FILE2 == current_ptn_file ) { /* グレイパタンファイル1に切り替える */ current_ptn_file = GP_FILE1; Lib_sprintf( file_name, "\\FS0\\GRAY1.PTN" ); } else if ( GP_FILE1 == current_ptn_file ) { /* グレイパタンファイル2に切り替える */ current_ptn_file = GP_FILE2; Lib_sprintf( file_name, "\\FS0\\GRAY2.PTN" ); } /* パタンファイルのロード */ if ( ( unsigned long )NULL != Lib_fload( file_name, gray_ptn_adrs, GP_SIZE ) ) mode = CONTINUE_PTN_AREA; /* パタンエリアは継続して使用する */ else mode = INITIAL_PTN_AREA; /* パタンエリアは初期化して使用する */ /* サーチ・パタン定義エリア指定 */ if ( 0 != Lib_gs_defadrs( gray_ptn_adrs, GP_SIZE, mode ) ) Lib_display_message( 100, 200, "エラー", "パタンエリアは使用できません" ); } } /************************************************************************/ /* パタンサーチ */ /************************************************************************/ void ptn_search( void ) { int Rslt_Buf[3]; char ss[50]; int rtn; int name; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); if ( GP_FILE1 == current_ptn_file ) name = name1; else name = name2; Lib_strtclk_count(); /*タイマーカウントモードのスタート*/ Lib_freeze( TRANSMIT ); Lib_gs_window( ON_DISPLAY, gs_wxs, gs_wys, gs_wxe, gs_wye ); if ( 0 < ( rtn = Lib_gs_search( ON_DISPLAY, name, 1, seido, complex, mid_lower, last_lower, Rslt_Buf ) ) ) { Lib_sprintf( ss, "( x, y ) = ( %5.1lf, %5.1f ) 相関値 %4d", (double)Rslt_Buf[0] / 10.0, (double)Rslt_Buf[1] / 10.0, Rslt_Buf[2] ); Lib_chrdisp( 1, 30, ss ); Lib_time_disp( 0, 0 ); Lib_display_keyinput( 460, 0, "確認" ); } else if ( 0 == rtn ) Lib_display_message( 100, 200, "エラー", "対象物がありません" ); else if ( -1 == rtn ) Lib_display_message( 100, 200, "エラー", "パタンが登録されていません" ); Lib_freerun(); Lib_cls( ( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); }