source: trunk/IPs/systemC/processor/Morpheo/Tools/Viewer/Graphics/src/Graphics_file_actions.cpp @ 32

Last change on this file since 32 was 32, checked in by chou, 17 years ago

Morpheo Viewer Release 5.0
Réalisation des étapes 3 (fin) et 4.

  • Property svn:executable set to *
File size: 5.0 KB
RevLine 
[21]1#include "window.h"
2
3using namespace std;
4using namespace morpheo::tools::viewer::parser;
5using namespace morpheo::tools::viewer::bdd;
6using namespace morpheo::tools::viewer::graphics;
7
8
9/*signals actions implementation*/
10
[32]11/*open function*/
[21]12void Window::_open(){
[30]13  QString current2;
14  if(!file_open && is_save){//if no file open or if the file opened has been saved -> open other file, else -> ask for saving file
15    current2 = QFileDialog::getOpenFileName(this,"", "./data");
[32]16    this->setDisabled(true);
17    /*if a file has been opened*/
[30]18    if(current2!=""){
19      current_name = current2;
20      if(parse->open_file( current_name.toStdString(),0)==-1)
21        _open_error();
22      else{
23        paint = false;
24        repaint();
25        _init_file();
26      }
27    }
[21]28  }
29  else{
30    file_open = false;
[30]31    if(!is_save){
32      wa_open = true;
33      wa = new QWidget();
34      QBoxLayout *other_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
35      wa->setFixedSize(500,60);
36      wa->move(50,100);
37      QLabel *label = new QLabel("do you want to save this file?");
38      QPushButton *yes_save = new QPushButton("yes",wa);
39      QPushButton *no_save = new QPushButton("no",wa);
40      if(current_name!=NULL)
41        connect(yes_save,SIGNAL(clicked()),this,SLOT(_save()));
42      else 
43        connect(yes_save,SIGNAL(clicked()),this,SLOT(_saveAs()));
44      connect(no_save,SIGNAL(clicked()),this,SLOT(_open()));
45      other_box->addWidget(label);
46      other_box->addWidget(yes_save);
47      other_box->addWidget(no_save);
48      wa->setLayout(other_box);
49      wa->show();
50    }
51    else{
52      parse->closeBaseV();
53      _open();
54    }
[21]55  }
56}
57
[32]58/*initialize the database when a file has been opened*/
[21]59void Window::_init_file(){
60  is_save = true;
61  base = parse->getBaseV();//parse the base and open the file
[32]62  //#ifdef DEBUG_ALL
[26]63  base->afficheBaseConsole();
[32]64  //#endif
[26]65  cpt_level = 0;
66 
67  tab[cpt_level] = "";
[21]68  file_open = true;
69  QList <BaseP> *liste_compo = base->getBaseP();
70  p = liste_compo->at(0);
71  entity = p.getEntity();
[26]72  current = QString::fromStdString(entity->getName());
[21]73  c = new Coord(250,250,250,250);
74  port_east = entity->getPortEast(c);
75  port_west = entity->getPortWest(c);
76  port_north = entity->getPortNorth(c);
77  port_south = entity->getPortSouth(c);
78  paint = true;
79  repaint();
[32]80  display_param();
[30]81  this->setDisabled(false);
[26]82  setMouseTracking(true);
[21]83}
84
[32]85/*if user entered a wrong file name*/
[21]86void Window::_open_error(){
87  QMessageBox *error = new QMessageBox(this);
88  error->setText("error : file doesn't exist or is not a valid format");
89  error->addButton("ok",QMessageBox::YesRole);
90  error->show(); 
[32]91  this->setDisabled(false);
[21]92} 
93
[32]94/*save functions*/
[21]95void Window::_save(){
96  if(file_open){
97    if (wa_open)
98      wa->close();
[32]99    if(save_as){//if "save as"
[30]100      current_name = QFileDialog::getSaveFileName(this,"","./data");
[21]101      save_as = false;
[32]102      parse->save_file(current_name.toStdString(),0);
[21]103    }
104    else {
[32]105      parse->save_file(current.toStdString(),0);
106      status->showMessage("file " + current + " saved",900);
[21]107      is_save = true;//file saved
108    }
109    if(wa_open){
110      wa_open = false;
111      _open();
112    }
113  }
114  else{
115    QMessageBox *mess = new QMessageBox(this);
116    mess->setText("no file opened");
117    mess->addButton("ok",QMessageBox::YesRole);
118    mess->show(); 
119  }
120}
121
122void Window::_saveAs(){
123  if (wq_open){//if "quit" window is open, close it
124    wq->close();
125    wq_open = false;
126  }
127  save_as = true;
128  _save();
129}
130
131void Window::_saveAsOk(){
132  is_save = true;
133  status->showMessage("file " + current_name + " saved",900);
134  if(wa_open){
135    wa_open = false;
136    _open();
137  }
138  if(quit_demand)//if the user clicked on "quit" (but saved the file just before) -> quit the application
139    _quit2();
140}
141
[32]142/*close function*/
[21]143void Window::_close(){
144  paint = false;
[32]145  repaint();
[30]146  parse->closeBaseV();
[32]147  erase_line(ln,lname);
148  erase_line(lt,ltype);
149  erase_comment();
[21]150  winfo->show();
[32]151  wscroll->hide();
152  scroll_hide = true;
153  wparam->show();
[21]154  file_open = false;
155}
156
[32]157/*quit functions*/
[21]158void Window::_quit(){
159  //if the file is not saved -> ask to the user if he wants to save it. If yes -> save, else quit.
160  if(file_open && !is_save){
161    wq_open = true;
162    quit_demand = true;
163    wq = new QWidget();
164    QBoxLayout *quit_box = new QBoxLayout(QBoxLayout::LeftToRight,0);
165    wq->setWindowTitle("save : file name");
166    wq->setFixedSize(500,60);
167    wq->move(50,100);
168    QLabel *label = new QLabel("do you want to save this file?");
169    QPushButton *yes_save = new QPushButton("yes",wq);
170    QPushButton *no_save = new QPushButton("no",wq);
171    connect(yes_save,SIGNAL(clicked()),this,SLOT(_saveAs()));
172    connect(no_save,SIGNAL(clicked()),this,SLOT(_quit2()));
173    quit_box->addWidget(label);
174    quit_box->addWidget(yes_save);
175    quit_box->addWidget(no_save);
176    wq->setLayout(quit_box);
177    wq->show();
178  }
179  else
180    _quit2();
181}
[32]182/*close all the windows opened*/
[21]183void Window::_quit2(){
184  /*test if there are windows (other than the main window) opened*/
185
186  if(wq_open)
187    wq->close();
188  if(wa_open)
189    wa->close();
190  if(param_open)
191    wparam->close();
192  if(info_open)
193    winfo->close();
194  close();
195}
196
197
198
199
Note: See TracBrowser for help on using the repository browser.