Пример #1
0
void MyFrame::on_text_change(wxCommandEvent& evt) {
    if(!stepsGrids.empty()) {
        ClearNotebooks();
        mainSizer->SetSizeHints(this);
        Fit();
    }
}
Пример #2
0
void MyFrame::OnDelRestrButton(wxCommandEvent& evt) {
    if(restrEntries.size() <= 1) return;
    
    restrSizer->Detach(restrEntries.back());
    delete restrEntries.back();
    restrEntries.pop_back();
    
    restrSizer->SetSizeHints(this);
    Fit();
}
Пример #3
0
void MyFrame::OnNewRestrButton(wxCommandEvent& evt) {
    if(restrEntries.size() >= 6) return;
    
    auto textCtrl = new wxTextCtrl(
        this, wxID_ANY, wxT("Новое ограничение"),
        wxDefaultPosition, wxDefaultSize,
        wxTE_PROCESS_ENTER
    );
    restrEntries.emplace_back(textCtrl);
    textCtrl->Bind(wxEVT_TEXT, &MyFrame::on_text_change, this);
    restrSizer->Add(textCtrl, wxSizerFlags().Expand().Border(wxALL, 5));
    
    restrSizer->SetSizeHints(this);
    Fit();
}
Пример #4
0
void MyFrame::FillNotebook(std::vector<Solver::Step> const& steps, wxNotebook* book) {
    bool solutionValid = steps.back().valid();
    if(!solutionValid) return;
    
    using fracType = Fraction;
    
    int stepN = 1;
    for(auto const& step : steps) {
        int pageId = wxNewId();
        wxGrid* page = new wxGrid(book, pageId);
        stepsGrids.emplace_back(page, pageId);
        
        int needMPrice = 0;
        for(auto col : step.mprice.terms()) {
            if(col.coeff() != 0) {
                needMPrice = 1;
                break;
            }
        }
        
        page->CreateGrid(
            step.restrs.size() + 2 + static_cast<int>(needMPrice),
            step.goal.size() + 2
        );
        page->HideColLabels();
        page->HideRowLabels();
        page->EnableDragColSize(false);
        page->EnableDragRowSize(false);
        page->EnableDragGridSize(false);
        page->EnableEditing(false);
        page->Bind(wxEVT_GRID_CELL_LEFT_DCLICK, &MyFrame::on_cell_dclick, this);
        
        // goal row
        int row = 0;
        int col = 0;
        page->SetCellValue(row, col++, step.goal.right());
        page->SetCellValue(row, col++, "B");
        for(int j : step.goal.indices()) {
            page->SetCellValue(row, col++, to_string(step.goal.term(j)));
        }
        
        // restrictions rows
        for(auto const& restr : step.restrs) {
            ++row;
            col = 0;
            page->SetCellValue(row, col++, to_string(step.sel[row - 1]));
            page->SetCellValue(
                row, col++, 
                to_string(static_cast<fracType>(restr.right()))
            );
            for(int j : restr.indices()) {
                page->SetCellValue(
                    row, col++, 
                    to_string(static_cast<fracType>(restr.coeff(j)))
                );
            }
        }
        
        // plain price row
        ++row;
        col = 0;
        page->SetCellValue(row, col++, "W");
        page->SetCellValue(
            row, col++, 
            to_string(static_cast<fracType>(step.w))
        );
        for(int fi : step.pprice.indices()) {
            page->SetCellValue(
                row, col++, 
                to_string(static_cast<fracType>(step.pprice.coeff(fi)))
            );
        }
        
        // mega price row
        if(needMPrice) {
            ++row;
            col = 0;
            page->SetCellValue(row, col++, "M");
            page->SetCellValue(
                row, col++, 
                to_string(static_cast<fracType>(step.m))
            );
            for(int fi : step.mprice.indices()) {
                page->SetCellValue(
                    row, col++, 
                    to_string(static_cast<fracType>(step.mprice.coeff(fi)))
                );
            }
        }
        
        page->AutoSize();
        book->AddPage(page, wxString::Format(wxT("Шаг %d"), stepN++));
    }
    
    mainSizer->SetSizeHints(this);
    Fit();
}