Jaehui-Lee / CLI-Excel

Excel program running in CLI environment
0 stars 0 forks source link

추가 구현 사항 #1

Open Jaehui-Lee opened 3 years ago

Jaehui-Lee commented 3 years ago

설명

추가 구현 사항 (11/12 회의)

TODO

Jaehui-Lee commented 3 years ago
plug4564 commented 3 years ago

표 출력 시, 표가 연결되게 출력하기

  1. 출력하려는 window는 excel.cpp에서 구현하기 때문에 Table에서 excel.cpp의 window *win를 가르키는 새로운 맴버 변수를 정의하여 Table 객체 자체에서 ncurses를 이용하여 출력할 수 있도록 한다. print_table() 타입 또한 string에서 void형으로 바꾸어주었다.

table.h

public:
    Table(int max_row_size, int max_col_size);
    string print_table(); //previous
public:
    Table(WINDOW* win, int max_row_size, int max_col_size);
    void print_table(); //next

excel.cpp

mvwprintw(win, 0, 0, current_table->print_table().c_str()); //prev

current_table->print_table(); //next

  1. Table::print_table() 함수 자체에서 ncurses 함수를 이용하여 기존의 문자열에서 " - "과 " | "을 각각 ACS_HLINE과 ACS_VLINE으로 바꾸어 출력하게 하고 교차점에서는 좌표를 이용하여 십자가 형태의 ACS_PLUS로 출력되게 하였다.

table.cpp

void Table::print_table()
{
    ...
    int cross_pos[max_col_size]; //represent x coordinate of cross
    cross_pos[0] = 5;

    for (int i = 0; i <= max_col_size; i++)
    {
        int max_len = max(2, col_max_wide[i]);
        cross_pos[i + 1] = max_len + 3 + cross_pos[i];
    }

    for (int i = 0; i < max_row_size; i++)
    {
        // horizontal line
        int x, y;
        whline(win, ACS_HLINE, total_wide);
        getyx(win, y, x); //return x ,y coordinates
        for (int i = 0; i <= max_col_size; i++)
        {
            wmove(win, y, cross_pos[i]); //move cursor to a coordinate that a cross will be printed at
            whline(win, ACS_PLUS, 1); //print the cross
        }
        wprintw(win, "\n");

        // data line
        wprintw(win, to_string(i + 1).c_str());
        repeat_char(4-to_string(i+1).length(), " ");

        for (int j = 0; j < max_col_size; j++)
        {
            if (col_max_wide[j])
            {
                int max_len = max(2, col_max_wide[j]);
                int x, y;

                string s = "";
                if (data_table[i][j])
                {
                    s = data_table[i][j]->stringify();
                }
                wprintw(win, " ");
                wvline(win, ACS_VLINE, 1);
                getyx(win, y, x);
                wmove(win, y, x + 1);
                wprintw(win, " ");
                wprintw(win, s.c_str());
                repeat_char(max_len-s.length(), " ");
            }
        }
        wprintw(win, "\n");
    }
}
Jaehui-Lee commented 3 years ago
void FuncCell::parse_function()
{
    /*
    ...
    similar to before
    ...
    */
    calculate();
}

// Calculate the value of the parsed function
void FuncCell::calculate()
{
    // Implemented
}
Jaehui-Lee commented 3 years ago
void ExcelList::to_txt(string to)
{
    ofstream writeFile(to.data());
    if (writeFile.is_open())
    {
        writeFile << excel_count << endl;
        list<Excel *>::iterator iter;
        int i = 1;
        for (iter = excelList.begin(); iter != excelList.end(); iter++)
        {
            (*iter)->to_txt(writeFile, i++);
        }
    }
    writeFile.close();
}
void Excel::to_txt(ofstream& writeFile, int current_excel)
{
    writeFile << current_excel << " ";
    current_table->to_txt(writeFile);
}
void Table::to_txt(ofstream& writeFile)
{
    // implemented
    // output table data
    // format : CellName DataType value ( value can be expression or function )
}
Jaehui-Lee commented 2 years ago
int main()
{
...
/*
      Get filename
      Call excelList.from_txt(filename)
      Execute Excel
*/
...
}
bool ExcelList::from_txt(string from)
{
/*
      File open and create window(excel)
*/
}
void Excel::from_txt(ifstream& readFile)
{
/* 
      Read data from file
      Create data by type 
*/ 
}
sorkrkwlsrjtemf commented 2 years ago

scroll function