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
Line 
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
11/*open function*/
12void Window::_open(){
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");
16    this->setDisabled(true);
17    /*if a file has been opened*/
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    }
28  }
29  else{
30    file_open = false;
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    }
55  }
56}
57
58/*initialize the database when a file has been opened*/
59void Window::_init_file(){
60  is_save = true;
61  base = parse->getBaseV();//parse the base and open the file
62  //#ifdef DEBUG_ALL
63  base->afficheBaseConsole();
64  //#endif
65  cpt_level = 0;
66 
67  tab[cpt_level] = "";
68  file_open = true;
69  QList <BaseP> *liste_compo = base->getBaseP();
70  p = liste_compo->at(0);
71  entity = p.getEntity();
72  current = QString::fromStdString(entity->getName());
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();
80  display_param();
81  this->setDisabled(false);
82  setMouseTracking(true);
83}
84
85/*if user entered a wrong file name*/
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(); 
91  this->setDisabled(false);
92} 
93
94/*save functions*/
95void Window::_save(){
96  if(file_open){
97    if (wa_open)
98      wa->close();
99    if(save_as){//if "save as"
100      current_name = QFileDialog::getSaveFileName(this,"","./data");
101      save_as = false;
102      parse->save_file(current_name.toStdString(),0);
103    }
104    else {
105      parse->save_file(current.toStdString(),0);
106      status->showMessage("file " + current + " saved",900);
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
142/*close function*/
143void Window::_close(){
144  paint = false;
145  repaint();
146  parse->closeBaseV();
147  erase_line(ln,lname);
148  erase_line(lt,ltype);
149  erase_comment();
150  winfo->show();
151  wscroll->hide();
152  scroll_hide = true;
153  wparam->show();
154  file_open = false;
155}
156
157/*quit functions*/
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}
182/*close all the windows opened*/
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.