/[svn]/gigedit/trunk/src/gigedit/dimensionmanager.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/dimensionmanager.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1303 by persson, Sun Aug 26 09:29:52 2007 UTC revision 1733 by persson, Sat May 3 09:54:36 2008 UTC
# Line 1  Line 1 
1  /*                                                         -*- c++ -*-  /*                                                         -*- c++ -*-
2   * Copyright (C) 2006, 2007 Andreas Persson   * Copyright (C) 2006-2008 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 23  Line 23 
23  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
24  #include <gtkmm/dialog.h>  #include <gtkmm/dialog.h>
25  #include <gtkmm/comboboxtext.h>  #include <gtkmm/comboboxtext.h>
26    #include <gtkmm/spinbutton.h>
27    #include <gtkmm/table.h>
28    
29  // returns a human readable name of the given dimension type  // returns a human readable name of the given dimension type
30  static Glib::ustring __dimTypeAsString(gig::dimension_t d) {  static Glib::ustring __dimTypeAsString(gig::dimension_t d) {
# Line 186  addButton(Gtk::Stock::ADD), removeButton Line 188  addButton(Gtk::Stock::ADD), removeButton
188      scrolledWindow.add(treeView);      scrolledWindow.add(treeView);
189      vbox.pack_start(scrolledWindow);      vbox.pack_start(scrolledWindow);
190      scrolledWindow.show();      scrolledWindow.show();
191      vbox.pack_start(buttonBox);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
192      buttonBox.set_layout(Gtk::BUTTONBOX_END);      buttonBox.set_layout(Gtk::BUTTONBOX_END);
193      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
194      buttonBox.show();      buttonBox.show();
195      buttonBox.pack_start(addButton);      buttonBox.pack_start(addButton, Gtk::PACK_SHRINK);
196      buttonBox.pack_start(removeButton);      buttonBox.pack_start(removeButton, Gtk::PACK_SHRINK);
197      addButton.show();      addButton.show();
198      removeButton.show();      removeButton.show();
199    
# Line 218  addButton(Gtk::Stock::ADD), removeButton Line 220  addButton(Gtk::Stock::ADD), removeButton
220  // update all GUI elements according to current gig::Region informations  // update all GUI elements according to current gig::Region informations
221  void DimensionManager::refreshManager() {  void DimensionManager::refreshManager() {
222      refTableModel->clear();      refTableModel->clear();
223      for (int i = 0; i < region->Dimensions; i++) {      if (region) {
224          gig::dimension_def_t* dim = &region->pDimensionDefinitions[i];          for (int i = 0; i < region->Dimensions; i++) {
225          Gtk::TreeModel::Row row = *(refTableModel->append());              gig::dimension_def_t* dim = &region->pDimensionDefinitions[i];
226          row[tableModel.m_dim_type] = __dimTypeAsString(dim->dimension);              Gtk::TreeModel::Row row = *(refTableModel->append());
227          row[tableModel.m_bits] = dim->bits;              row[tableModel.m_dim_type] = __dimTypeAsString(dim->dimension);
228          row[tableModel.m_zones] = 1 << dim->bits; //TODO: for now we calculate it here until libgig always ensures 'zones' to be correct              row[tableModel.m_bits] = dim->bits;
229          row[tableModel.m_description] = __dimDescriptionAsString(dim->dimension);              row[tableModel.m_zones] = dim->zones;
230          row[tableModel.m_definition] = dim;              row[tableModel.m_description] = __dimDescriptionAsString(dim->dimension);
231                row[tableModel.m_definition] = dim;
232            }
233      }      }
234        set_sensitive(region);
235  }  }
236    
237  void DimensionManager::show(gig::Region* region) {  void DimensionManager::show(gig::Region* region) {
# Line 236  void DimensionManager::show(gig::Region* Line 241  void DimensionManager::show(gig::Region*
241      deiconify();      deiconify();
242  }  }
243    
244    void DimensionManager::set_region(gig::Region* region) {
245        this->region = region;
246        refreshManager();
247    }
248    
249  void DimensionManager::addDimension() {  void DimensionManager::addDimension() {
250      try {      try {
251          Gtk::Dialog dialog("New Dimension", true /*modal*/);          Gtk::Dialog dialog("New Dimension", true /*modal*/);
# Line 250  void DimensionManager::addDimension() { Line 260  void DimensionManager::addDimension() {
260                  row[comboModel.m_type_name] = sType;                  row[comboModel.m_type_name] = sType;
261              }              }
262          }          }
263            Gtk::Table table(2, 2);
264            Gtk::Label labelDimType("Dimension:", Gtk::ALIGN_LEFT);
265          Gtk::ComboBox comboDimType;          Gtk::ComboBox comboDimType;
266          comboDimType.set_model(refComboModel);          comboDimType.set_model(refComboModel);
267          comboDimType.pack_start(comboModel.m_type_id);          comboDimType.pack_start(comboModel.m_type_id);
268          comboDimType.pack_start(comboModel.m_type_name);          comboDimType.pack_start(comboModel.m_type_name);
269          dialog.get_vbox()->pack_start(comboDimType);          Gtk::Label labelZones("Zones:", Gtk::ALIGN_LEFT);
270          comboDimType.show();          table.attach(labelDimType, 0, 1, 0, 1);
271          // add zones combo box to the dialog          table.attach(comboDimType, 1, 2, 0, 1);
272            table.attach(labelZones, 0, 1, 1, 2);
273            dialog.get_vbox()->pack_start(table);
274    
275            // number of zones: use a combo box with fix values for gig
276            // v2 and a spin button for v3
277          Gtk::ComboBoxText comboZones;          Gtk::ComboBoxText comboZones;
278          for (int i = 1; i <= 7; i++) { //FIXME: is 7 the correct amount of max. bits ???          Gtk::SpinButton spinZones;
279              char buf[64];          bool version2 = false;
280              sprintf(buf, "%d Zones (%d Bits)", 1 << i, i);          if (region) {
281              comboZones.append_text(buf);              gig::File* file = (gig::File*)region->GetParent()->GetParent();
282                version2 = file->pVersion && file->pVersion->major == 2;
283            }
284            if (version2) {
285                for (int i = 1; i <= 5; i++) {
286                    char buf[3];
287                    sprintf(buf, "%d", 1 << i);
288                    comboZones.append_text(buf);
289                }
290                table.attach(comboZones, 1, 2, 1, 2);
291            } else {
292                spinZones.set_increments(1, 8);
293                spinZones.set_numeric(true);
294                spinZones.set_range(2, 128);
295                spinZones.set_value(2);
296                table.attach(spinZones, 1, 2, 1, 2);
297          }          }
298          dialog.get_vbox()->pack_start(comboZones);  
         comboZones.show();  
         // add OK and CANCEL buttons to the dialog  
299          dialog.add_button(Gtk::Stock::OK, 0);          dialog.add_button(Gtk::Stock::OK, 0);
300          dialog.add_button(Gtk::Stock::CANCEL, 1);          dialog.add_button(Gtk::Stock::CANCEL, 1);
301          dialog.show_all_children();          dialog.show_all_children();
302    
303          if (!dialog.run()) { // OK selected ...          if (!dialog.run()) { // OK selected ...
304              Gtk::TreeModel::iterator iterType = comboDimType.get_active();              Gtk::TreeModel::iterator iterType = comboDimType.get_active();
305              if (!iterType) return;              if (!iterType) return;
# Line 277  void DimensionManager::addDimension() { Line 308  void DimensionManager::addDimension() {
308              gig::dimension_def_t dim;              gig::dimension_def_t dim;
309              int iTypeID = rowType[comboModel.m_type_id];              int iTypeID = rowType[comboModel.m_type_id];
310              dim.dimension = static_cast<gig::dimension_t>(iTypeID);              dim.dimension = static_cast<gig::dimension_t>(iTypeID);
311              if (comboZones.get_active_row_number() < 0) return;  
312              dim.bits = comboZones.get_active_row_number() + 1;              if (version2) {
313              dim.zones = 1 << dim.bits; //TODO: support zones != pow(2,bits) - feature of gig v3                  if (comboZones.get_active_row_number() < 0) return;
314                    dim.bits = comboZones.get_active_row_number() + 1;
315                    dim.zones = 1 << dim.bits;
316                } else {
317                    dim.zones = spinZones.get_value_as_int();
318                    // Find the number of bits required to hold the
319                    // specified amount of zones.
320                    int zoneBits = dim.zones - 1;
321                    for (dim.bits = 0; zoneBits > 1; dim.bits += 2, zoneBits >>= 2);
322                    dim.bits += zoneBits;
323                }
324              printf(              printf(
325                  "Adding dimension (type=0x%x, bits=%d, zones=%d)\n",                  "Adding dimension (type=0x%x, bits=%d, zones=%d)\n",
326                  dim.dimension, dim.bits, dim.zones                  dim.dimension, dim.bits, dim.zones
327              );              );
328                // notify everybody that we're going to update the region
329                region_to_be_changed_signal.emit(region);
330              // add the new dimension to the region              // add the new dimension to the region
331              // (implicitly creates new dimension regions)              // (implicitly creates new dimension regions)
332              region->AddDimension(&dim);              region->AddDimension(&dim);
333              // let everybody know there was a change              // let everybody know there was a change
334              articulation_changed_signal.emit();              region_changed_signal.emit(region);
335              // update all GUI elements              // update all GUI elements
336              refreshManager();              refreshManager();
337          }          }
338      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
339            // notify that the changes are over (i.e. to avoid dead locks)
340            region_changed_signal.emit(region);
341            // show error message
342          Glib::ustring txt = "Could not add dimension: " + e.Message;          Glib::ustring txt = "Could not add dimension: " + e.Message;
343          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
344          msg.run();          msg.run();
# Line 304  void DimensionManager::removeDimension() Line 350  void DimensionManager::removeDimension()
350      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
351      if (it) {      if (it) {
352          try {          try {
353                // notify everybody that we're going to update the region
354                region_to_be_changed_signal.emit(region);
355              // remove selected dimension              // remove selected dimension
356              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
357              gig::dimension_def_t* dim = row[tableModel.m_definition];              gig::dimension_def_t* dim = row[tableModel.m_definition];
358              region->DeleteDimension(dim);              region->DeleteDimension(dim);
             // remove respective row from table  
             refTableModel->erase(it);  
359              // let everybody know there was a change              // let everybody know there was a change
360              articulation_changed_signal.emit();              region_changed_signal.emit(region);
361                // update all GUI elements
362                refreshManager();
363          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
364                // notify that the changes are over (i.e. to avoid dead locks)
365                region_changed_signal.emit(region);
366                // show error message
367              Glib::ustring txt = "Could not remove dimension: " + e.Message;              Glib::ustring txt = "Could not remove dimension: " + e.Message;
368              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
369              msg.run();              msg.run();

Legend:
Removed from v.1303  
changed lines
  Added in v.1733

  ViewVC Help
Powered by ViewVC