Ejemplo n.º 1
0
void SdDurationCanvas::cut_internal(int py) {
  Q3PtrListIterator<SdDurationCanvas> itd(durations);
  
  for (; itd.current(); ++itd)
    itd.current()->cut_internal(py);
  
  QRect r = rect();
  resize(width(), py - r.top());
  SdDurationCanvas * newone = 0;
  
  Q3PtrList<SdMsgBaseCanvas> ms(msgs);
  Q3PtrListIterator<SdMsgBaseCanvas> it(ms);
  
  for ( ; it.current(); ++it ) {
    if (it.current()->rect().center().y() > py) {
      // on the new duration
      if (newone == 0) { 
	// width and height to 0 on creation to not have
	// a round error because of the zoom
	newone = new SdDurationCanvas(the_canvas(), support, r.x(), py, 0, 0, 0, coregion);
	newone->resize(width(), r.bottom() - py);
	newone->itscolor = itscolor;
	newone->setZ(z());
	newone->show();
      }
      remove(it.current());
      newone->add(it.current());
      it.current()->change_duration(this, newone);
    }
  }
  
  Q3PtrList<SdDurationCanvas> durs(durations);
  Q3PtrListIterator<SdDurationCanvas> itdur(durs);
  
  for (itdur.toFirst() ; itdur.current(); ++itdur) {
    if (itdur.current()->rect().center().y() > py) {
      // on the new duration
      if (newone == 0) { 
	// width and height to 0 on creation to not have 
	// a round error because of the zoom
	newone = new SdDurationCanvas(the_canvas(), support, r.x(), py, 0, 0, 0, coregion);
	newone->resize(width(), r.bottom() - py);
	newone->itscolor = itscolor;
	newone->setZ(z());
	newone->show();
      }
      remove(itdur.current());
      newone->add(itdur.current());
      itdur.current()->support =  newone;
    }
    
    itdur.current()->update_v_to_contain(itdur.current(), TRUE);
  }
}
Ejemplo n.º 2
0
int main(int argc, char **argv) {
    wxInitializer wx_initializer;
    if ( !wx_initializer ) {
        fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
        return -1;
    }
    wxCmdLineParser cmd_parser(cmdLineDesc, argc, argv);
    
    long run_count = 10;
    wxString grid_path, dict_path;
    
    bool is_rand    = false;
    bool is_verbose = false;
    
    switch ( cmd_parser.Parse() ) {
        case -1:
            return 0;
        case 0:
            cmd_parser.Found(wxT("count"), &run_count);
            is_rand    = cmd_parser.Found(wxT("rand"));
            is_verbose = cmd_parser.Found(wxT("verbose"));
            grid_path  = cmd_parser.GetParam(0);
            dict_path  = cmd_parser.GetParam(1);
            wxLogDebug(wxT("grid_path = ") + grid_path + wxT("\n"));
            wxLogDebug(wxT("dict_path = ") + dict_path + wxT("\n"));
            wxLogDebug(wxT("run_count = %d\n"), run_count);
            break;
        default:
            return 0;
    }
    std::vector< wxLongLong > durs(run_count); // durations
    std::vector< wxString > words_out;
    DictType dict;
    GridType grid;
    AllWordsType all_words;
    CharsTransType trans_type;
    
    readDict(dict_path, dict);
    generateAllWords(dict, all_words, trans_type);
    readGrid(grid_path, grid);
    
    if ( is_rand )
        srand(time(NULL));
    
    for (long i = 0; i < run_count; ++i) {
        if ( !is_rand )
            srand(42);
        words_out.clear();
        durs.at(i) = wxGetLocalTimeMillis();
        generateCross(grid,all_words,trans_type,words_out);
        if ( words_out.size() == 0 )
            wxPrintf(wxT("Error in creating #%-2i!\n"),i+1);
        durs.at(i) = wxGetLocalTimeMillis() - durs.at(i);
        if ( is_verbose )
            wxPrintf(wxT("Time to generate  #%-2i is ") 
                + durs.at(i).ToString() + wxT(" ms\n"), i+1);
    }
    wxLongLong tm_total = std::accumulate(durs.begin(),durs.end(), wxLongLong(0,0));
    wxLongLong tm_mean  = (tm_total + run_count/2) / run_count;
    wxPrintf(wxT("Total time = ") + tm_total.ToString() + wxT(" ms.\nMean time  = ") 
        + tm_mean.ToString() + wxT(" ms.\n"));
    return 0;
}