~cypheon/elfelli

11666b8dda48ad78219d3d23476e31bbe006e368 — Johann Rudloff 16 years ago 050b671
A file to load can be passed as first command line argument.
3 files changed, 30 insertions(+), 19 deletions(-)

M src/Application.cpp
M src/Application.h
M src/XmlLoader.cpp
M src/Application.cpp => src/Application.cpp +24 -19
@@ 55,6 55,12 @@ Application::Application(int argc, char **argv):
{
  setup_gettext();
  build_gui();
  reset_simulation();

  if(argc >= 2)
  {
    load_file(argv[1]);
  }
}

void Application::setup_gettext()


@@ 122,31 128,32 @@ void Application::on_export_png_activate()

void Application::on_open_activate()
{
  std::string filename = "";

  int result = open_dlg.run();
  if(result == RESPONSE_OK)
    {
      filename = open_dlg.get_filename();
      
  {
    load_file(open_dlg.get_filename());
  }

  open_dlg.hide();
}

void Application::load_file(std::string filename)
{
#ifdef DEBUG
      std::cerr << "Loading file `" << filename << "'." << std::endl;
  std::cerr << "Loading file `" << filename << "'." << std::endl;
#endif // DEBUG

      XmlLoader loader;

      Simulation *tmp_sim = new Simulation;
  XmlLoader loader;

      if(loader.load(filename.c_str(), tmp_sim) == 0)
      {
        sim_canvas = *tmp_sim;
        sim_canvas.refresh();
      }
  Simulation *tmp_sim = new Simulation;

      delete tmp_sim;
    }
  if(loader.load(filename.c_str(), tmp_sim) == 0)
  {
    sim_canvas = *tmp_sim;
    sim_canvas.refresh();
  }

  open_dlg.hide();
  delete tmp_sim;
}

void Application::on_save_activate()


@@ 412,8 419,6 @@ bool Application::build_gui()

int Application::main()
{
  reset_simulation();

  Main::run(main_win);

  return 0;

M src/Application.h => src/Application.h +2 -0
@@ 49,6 49,8 @@ public:
  int main();
  void quit();

  void load_file(std::string filename);

  static const std::string find_datafile(const std::string& fname);

  static const std::string appname;

M src/XmlLoader.cpp => src/XmlLoader.cpp +4 -0
@@ 130,7 130,9 @@ void XmlLoader::start_element(void *data, const XML_Char *name, const XML_Char *
      if(have_x && have_y && have_charge)
      {
        xml->sim->add_body(Vec2(x, y), charge);
#ifdef DEBUG
        std::cerr << "added body\n";
#endif // DEBUG
      }
    }
    else if(strcmp(name, "plate") == 0)


@@ 185,7 187,9 @@ void XmlLoader::start_element(void *data, const XML_Char *name, const XML_Char *
      if(have_x1 && have_y1 && have_x2 && have_y2 && have_charge)
      {
        xml->sim->add_plate(Vec2(x1, y1), Vec2(x2, y2), charge);
#ifdef DEBUG
        std::cerr << "added plate\n";
#endif // DEBUG
      }
    }
    else