示例#1
0
static INT_PTR CALLBACK Window_StopwatchExportDlg(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	(void)lParam; // unused
	switch(msg) {
	case WM_INITDIALOG:{
		wchar_t buf[128];
		api.GetStr(L"Timers", L"SwExT", buf, _countof(buf), L"");
		SetDlgItemText(hDlg,IDC_SWE_TOTAL,buf);
		api.GetStr(L"Timers", L"SwExL", buf, _countof(buf), L"");
		SetDlgItemText(hDlg, IDC_SWE_LAP, buf);
		SendMessage(hDlg, WM_COMMAND,IDOK, 0);
		Edit_SetSel(GetDlgItem(hDlg,IDC_SWE_OUT), 0, -1);
		SetFocus(GetDlgItem(hDlg,IDC_SWE_OUT));
		return FALSE;}
	case WM_DESTROY:{
		break;}
	case WM_COMMAND: {
			switch(LOWORD(wParam)) {
			case IDC_SWE_EXPORT:{
				wchar_t filename[MAX_PATH];
				unsigned buflen = (unsigned)SendDlgItemMessageA(hDlg,IDC_SWE_OUT,WM_GETTEXTLENGTH,0,0);
				char* buf = malloc(buflen + 1);
				if(buf && buflen){
					GetDlgItemTextA(hDlg, IDC_SWE_OUT, buf, buflen+1);
					*filename = '\0';
					if(SaveFileDialog(hDlg,filename,_countof(filename))){
						FILE* fp = _wfopen(filename, L"wb");
						if(fp){
							fwrite(buf, sizeof(buf[0]), buflen, fp);
							fclose(fp);
						}
					}
				}
				free(buf);
				break;}
			case IDOK:{
				wchar_t buf[128];
				GetDlgItemText(hDlg, IDC_SWE_TOTAL, buf, _countof(buf));
				if(!*buf){
					api.DelValue(L"Timers", L"SwExT");
					SetDlgItemText(hDlg, IDC_SWE_TOTAL, L"\\n--------------------\\n\\t");
				}else
					api.SetStr(L"Timers", L"SwExT", buf);
				GetDlgItemText(hDlg, IDC_SWE_LAP, buf, _countof(buf));
				if(!*buf){
					api.DelValue(L"Timers", L"SwExL");
					SetDlgItemText(hDlg, IDC_SWE_LAP, L"Lap \\#\\f: \\l (\\t)\\n");
				}else
					api.SetStr(L"Timers", L"SwExL", buf);
				export_text(hDlg);
				break;}
			case IDCANCEL:
				EndDialog(hDlg, TRUE);
			}
			return TRUE;
		}
	}
	return FALSE;
}
示例#2
0
BOOL CWizDlg::OnCommand(WPARAM wParam, LPARAM lParam) 
{ 
	if ( wParam>=100 &&  wParam<=100+25 )     // file history
    {
        if ( wParam-100 == popup.GetMenuItemCount()-1 ) // Click on 1st item
        {                       
            CString s1("");            
            POSITION pos = Recents.GetHeadPosition();
            while (pos)
            {         
                s1+=Recents.GetNext(pos)->GetPath();		
                s1+="\x0D\x0A";                            
            }            
            export_text(s1,&wnd);           
            return 1;            
        }        
        del_pos = Recents.GetHeadPosition();		
        for ( int x=1; x<wParam-99; x++)
            Recents.GetNext(del_pos);						

        if ( ctrl ) // delete it
        {               
            if ( wnd.isOpened() &&  wParam-100 == 0 )   { del_pos=NULL; return 1; }
            Recents.RemoveAt(del_pos);            
            Load_menu();
            del_pos=NULL;          
        } else
             wnd.RedFile((char*)(LPCTSTR)(Recents.GetAt(del_pos))->GetPath(),0);                
            load_menu_ch();		
    }
	if ( wParam>=150 && wParam<=150+50+5 )    // Bookm menu
	{
        if ( wParam-150 == bookm.GetMenuItemCount()-1 ) // Click on 1st item
        {            
            CStringList lst;
            CString s1("");
            
            Recents.GetHead()->load_menu_bm(lst);
            POSITION p=lst.GetHeadPosition();
            while (p)
            { s1+=lst.GetNext(p); s1+="\x0D\x0A";}
             Recents.GetHead()->add_memo(s1);            
            return 1;            
        }        
        if ( ctrl ) // delete it
        {   
            Recents.GetHead()->del_at(wParam-150);            
            load_menub();
            check_bookm();

        } else
        {
            Recents.GetHead()->jmp_to(wParam-150); //>first_bookm();		
            wnd.Seek_to((Recents.GetHead())->cur_pos);		
        }
    }	
	return CDialog::OnCommand(wParam, lParam);
}
//======================================================================
void sccan_point_analysis::run_anaysis(){
	
	if(sccan_point_analysis_verbosity){
		std::cout << "sccan_point_analysis -> ";
		std::cout << "analyse()";
		std::cout << " -> ";
		std::cout << std::endl;
	}
	
	std::stringstream instruction_table;
	
	calculate_global_offset();

	instruction_table << "global offset of telescope axis, i.e. star camera axis vs. mean of mirror missalignments: ";
	instruction_table << global_offset.get_print() << "\n";
	instruction_table << "global offset is substracted: ";
	if(substract_global_offset)
		instruction_table << "TRUE";
	else
		instruction_table << "FALSE";
	instruction_table << "\n";
	
	uint MIit;
	
	/*if(use_multithread){
		#pragma omp parallel shared(instruction_table) private(MIit) 
		#pragma omp for schedule(dynamic) 
		for(MIit = 0; MIit < get_number_of_mirrors(); MIit++){
			analyse_single_mirror_and_get_instructions(MIit,&instruction_table);
		}
	}else{*/
		for(uint MIit = 0; MIit < get_number_of_mirrors(); MIit++){
			analyse_single_mirror_and_get_instructions(MIit, instruction_table);
		}	
	//}
	
	// timestamp in filename
	std::stringstream instruction_table_filename;
	instruction_table_filename << "mirror_alignment_instruction_table_";
	instruction_table_filename << global_time_stamp_manager_instance.get_current_time_stamp();
	instruction_table_filename << ".txt";
	
	export_text( 
		instruction_table_filename.str(),
		instruction_table.str()
	);
}	
//======================================================================
void sccan_point_analysis::draw_mirror_response(uint mirror_iterator){
	
	if(get_number_of_sccan_points()<1){
		std::cout  <<  "sccan_point_analysis -> ";
		std::cout  <<  "draw_mirror_response() -> ";
		std::cout  <<  "no sccan points in sccan matrix !";
		std::cout  <<  std::endl;
		return;
	}
	
	if(get_number_of_mirrors()<1){
		std::cout  <<  "sccan_point_analysis -> ";
		std::cout  <<  "draw_mirror_response() -> ";
		std::cout  <<  "no mirrors in sccan matrix !";
		std::cout  <<  std::endl;
		return;
	}
	
	//==================================================================
	// filename
	//==================================================================
		
	std::string filename_extension;
	filename_extension = ".eps";
	
	std::stringstream plot_file_name;
	plot_file_name  <<  "mirror_ID"  << 
	sccan_matrix.at(0).at(mirror_iterator)->get_mirror_ID();
	plot_file_name  <<  "_response_map";
	plot_file_name  <<  filename_extension;

	std::stringstream csv_file_name;
	csv_file_name  <<  "mirror_ID"  << 
	sccan_matrix.at(0).at(mirror_iterator)->get_mirror_ID();
	csv_file_name  <<  "_response_map";
	csv_file_name  <<  ".csv";
	
	std::stringstream csv_table;
	
	if(sccan_point_analysis_verbosity){
		std::cout  <<  "sccan_point_analysis -> ";
		std::cout  <<  "draw_mirror_response() -> ";
		std::cout  <<  "filename = ";
		std::cout  <<  plot_file_name.str();
		std::cout  <<  std::endl;
	}

	//==================================================================
	// prepare data for plotting
	//==================================================================
	
	mglData rel_poi_dir_of_star_x_in_deg(sccan_matrix.size());
	mglData rel_poi_dir_of_star_y_in_deg(sccan_matrix.size());
	mglData mirror_response(sccan_matrix.size());
	
	csv_table  <<  "dir_X [deg],dir_Y [deg],";
	if(normalize_mirror_response)
	{csv_table  <<  "normalized_mirror_response [1]";}
	else
	{csv_table  <<  "mirror_response [bulbs]";}
	csv_table  <<  "\n";
	
	for(
	uint sccan_point_iterator=0;
	sccan_point_iterator<sccan_matrix.size();
	sccan_point_iterator++){
		
		rel_poi_dir_of_star_x_in_deg.a[ sccan_point_iterator ] = 
		(360.0/(2.0*M_PI)) *  
		sccan_matrix.at(sccan_point_iterator).at(mirror_iterator)->
		get_star_position_relative_to_pointing_direction().
		direction_in_x_in_radiant;
	
		csv_table  <<  
		rel_poi_dir_of_star_x_in_deg.a[ sccan_point_iterator ]  <<  ",";
	
		rel_poi_dir_of_star_y_in_deg.a[ sccan_point_iterator ] = 
		(360.0/(2.0*M_PI)) * 
		sccan_matrix.at(sccan_point_iterator).at(mirror_iterator)->
		get_star_position_relative_to_pointing_direction().
		direction_in_y_in_radiant;
	
		csv_table  <<  
		rel_poi_dir_of_star_y_in_deg.a[ sccan_point_iterator ]  <<  ",";
		
		if(normalize_mirror_response){
			mirror_response.a[ sccan_point_iterator ] = 
			sccan_matrix.at(sccan_point_iterator).at(mirror_iterator)->
			get_normalized_light_flux();
		}else{
			mirror_response.a[ sccan_point_iterator ] = 
			sccan_matrix.at(sccan_point_iterator).at(mirror_iterator)->
			get_mirror_light_flux();		
		}

		csv_table  <<  mirror_response.a[ sccan_point_iterator ];
		csv_table  <<  "\n";
		
	}
	
	export_text( csv_file_name.str(),csv_table.str());
	
	//==================================================================	
	// fit 2D gaussian
	//==================================================================	
	mglGraph gr;
	
	//~ mreal ini[5] = {mirror_response.Maximal(),0,10,0,10};
	//~ mglData Ini(5,ini);
//~ 
	//~ mglData fit_result = gr.FitS(
	//~ rel_poi_dir_of_star_x_in_deg,
	//~ rel_poi_dir_of_star_y_in_deg,
	//~ mirror_response,
	//~ "a*(exp( -( ((x-u)*(x-u))/(2*v*v) + ((y-n)*(y-n))/(2*m*m) ) ))",
	//~ "auvmn",
	//~ Ini);
	//~ 
	//~ std::cout << "Fitting mirror norm " << fit_result[0] << std::endl;
	//~ std::cout << "Fit x pos " << fit_result[1] << " pm " << fit_result[2] << std::endl;
	//~ std::cout << "Fit y pos " << fit_result[3] << " pm " << fit_result[4] << std::endl;
	//~ 
	//~ mglData best_x = fit_result[1];
	//~ mglData best_y = fit_result[3];
	//~ mglData best_z = fit_result[0]*(
	//~ exp( -( 
	//~ (best_x[0]-fit_result[1])*(best_x[0]-fit_result[1])/(2.0*fit_result[2]) + 
	//~ (best_y[0]-fit_result[3])*(best_y[0]-fit_result[3])/(2.0*fit_result[4]) ) 
	//~ )
	//~ );
	//==================================================================	
	// calculate
	//==================================================================	

	pointing_direction best_dir;
	
	if(max_only_instead_of_CoG){
		best_dir = 
		PointingDirectionOfStarAtMaxMirrorResponse(mirror_iterator);
	}else{
		best_dir = 
		CentreOfGravityPointingDirectionOfMirrorResponse(mirror_iterator);
	}
	
	mglData bM_x(1);
	mglData bM_y(1);
	mglData bM_z(1);
		
	bM_x[0] = best_dir.get_x_tilt_in_deg();
	bM_y[0] = best_dir.get_y_tilt_in_deg();
	bM_z[0] = 1.5*mirror_response.Maximal();

	//~ std::cout << "mean x pos " << bM_x[0] << std::endl;
	//~ std::cout << "mean y pos " << bM_y[0] << std::endl;
	//~ std::cout << "mean response " << bM_z[0] << std::endl;
	
	//==================================================================
	// plotting response map
	//==================================================================
	std::stringstream plot_heading;
	plot_heading  <<  "Mirror ID ";
	plot_heading  <<  sccan_matrix.at(0).at(mirror_iterator)->
	get_mirror_ID();
	plot_heading  <<  " response map";
	
	mglData xy_hist = gr.Hist(
	rel_poi_dir_of_star_x_in_deg,
	rel_poi_dir_of_star_y_in_deg,
	mirror_response);	
	
	gr.Title(plot_heading.str().c_str());
	//====================================
	gr.SubPlot(1,2,0);	
	gr.Rotate(50,60);

	gr.SetRanges(
	rel_poi_dir_of_star_x_in_deg.Minimal()*1.1,
	rel_poi_dir_of_star_x_in_deg.Maximal()*1.1,
	rel_poi_dir_of_star_y_in_deg.Minimal()*1.1,
	rel_poi_dir_of_star_y_in_deg.Maximal()*1.1,
	0.0,mirror_response.Maximal());
	
	gr.Axis();
	gr.Label('x',"x direction [deg]",0);
	gr.Label('y',"y direction [deg]",0);
	
	if(normalize_mirror_response){
		gr.Label('z',"normalized mirror response [1]",0);
	}else{
		gr.Label('z',"mirror response [bulbs]",0);
	}
	gr.Box(); 
	gr.Light(true);
	
	//gr.ContV(xy_hist);
	//gr.ContF(xy_hist);
	//gr.Cont(xy_hist,"k");
	
	gr.Stem(
	rel_poi_dir_of_star_x_in_deg,
	rel_poi_dir_of_star_y_in_deg,
	mirror_response,
	"o");
	
	// best fit result
	//~ gr.Stem(
	//~ best_x,
	//~ best_y,
	//~ best_z,
	//~ "rx");
	gr.Stem(
	bM_x,
	bM_y,
	bM_z,
	"rx");
	
	//====================================
	gr.SubPlot(1,2,1);
	gr.Rotate(50,120);
	
	gr.SetRanges(
	rel_poi_dir_of_star_x_in_deg.Minimal()*1.1,
	rel_poi_dir_of_star_x_in_deg.Maximal()*1.1,
	rel_poi_dir_of_star_y_in_deg.Minimal()*1.1,
	rel_poi_dir_of_star_y_in_deg.Maximal()*1.1,
	0.0,mirror_response.Maximal());
	
	gr.Axis();
	gr.Label('x',"x direction [deg]",0);
	gr.Label('y',"y direction [deg]",0);
	if(normalize_mirror_response){
		gr.Label('z',"normalized mirror response [1]",0);
	}else{
		gr.Label('z',"mirror response [bulbs]",0);
	}
	gr.Box(); 
	gr.Light(true);
	
	//gr.ContV(xy_hist);
	//gr.ContF(xy_hist);
	//gr.Cont(xy_hist,"k");

	gr.Stem(
	rel_poi_dir_of_star_x_in_deg,
	rel_poi_dir_of_star_y_in_deg,
	mirror_response,
	"o");
	
	gr.Stem(
	bM_x,
	bM_y,
	bM_z,
	"rx");

	gr.WriteFrame(plot_file_name.str().c_str());	// save it
}
示例#5
0
int Scene::resume(unsigned delay)
{
  Event event;
  while ((event = screen->getEvent()).type != NO_MORE_EVENTS) {
    if (event.type == QUIT)
      return 0;

    if (event.type == KEYDOWN)
      switch (event.key.keysym.sym) {
      case K_ESCAPE:
        if (active != figures.end()) {
          figures.erase(active);
          active = figures.end();
        }
        break;
      case K_SLASH:
        active = figures.begin();
        step = 0;
        break;
      case K_RIGHTBRACKET:
        if (active != figures.end())
          ++active;
        break;
      case K_LEFTBRACKET:
        if (active != figures.end())
          --active;
        break;

      case K_b:
        if (event.key.keysym.mod & K_MOD_SHIFT)
          import_binary();
        else
          export_binary();
        break;
      case K_t:
        if (event.key.keysym.mod & K_MOD_SHIFT)
          import_text();
        else
          export_text();
        break;
      case K_x:
        if (event.key.keysym.mod & K_MOD_SHIFT)
          import_xml();
        else
          export_xml();
        break;

      default:
        if (Figure *figure = figures_maker.build(event.key.keysym.sym)) {
          addFigure(figure);
          step = 0;
          active = std::find(figures.begin(), figures.end(), figure);
        }
        break;
      }

    if ((active != figures.end()) && (event.type == MOUSEMOTION))
      if ((*active)->handleMotion(step, event.motion.x, event.motion.y)) {
        step = 0;
        active = figures.end();
      }

    if ((active != figures.end()) && (event.type == MOUSEBUTTONDOWN))
      if (event.button.button == 1) ++step;
      else if (event.button.button == 3) {
	step = 0;
	(*active)->handleMotion(-1, 0, 0);
	active = figures.end();
      }
  }
  screen->sleep(delay);
  return !0;
}