diff --git a/src/common/Session.cpp b/src/common/Session.cpp new file mode 100755 index 0000000000000000000000000000000000000000..093dbbc7beeec03ccf8a529fcee9a8c28fdef68b --- /dev/null +++ b/src/common/Session.cpp @@ -0,0 +1,51 @@ +/* +** This file is part of the ViTE project. +** +** This software is governed by the CeCILL-A license under French law +** and abiding by the rules of distribution of free software. You can +** use, modify and/or redistribute the software under the terms of the +** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following +** URL: "http://www.cecill.info". +** +** As a counterpart to the access to the source code and rights to copy, +** modify and redistribute granted by the license, users are provided +** only with a limited warranty and the software's author, the holder of +** the economic rights, and the successive licensors have only limited +** liability. +** +** In this respect, the user's attention is drawn to the risks associated +** with loading, using, modifying and/or developing or reproducing the +** software by the user in light of its specific status of free software, +** that may mean that it is complicated to manipulate, and that also +** therefore means that it is reserved for developers and experienced +** professionals having in-depth computer knowledge. Users are therefore +** encouraged to load and test the software's suitability as regards +** their requirements in conditions enabling the security of their +** systems and/or data to be ensured and, more generally, to use and +** operate it in the same conditions as regards security. +** +** The fact that you are presently reading this means that you have had +** knowledge of the CeCILL-A license and that you accept its terms. +** +** +** ViTE developers are (for version 0.* to 1.0): +** +** - COULOMB Kevin +** - FAVERGE Mathieu +** - JAZEIX Johnny +** - LAGRASSE Olivier +** - MARCOUEILLE Jule +** - NOISETTE Pascal +** - REDONDY Arthur +** - VUCHENER Clément +** +*/ +/*! + *\file Session.cpp + */ + +#include "common/Session.hpp" + +const QByteArray Session::Export::DEFAULT_STATE = QByteArray::number(-1); + +QByteArray Session::Export::file_dialog_state = Session::Export::DEFAULT_STATE; diff --git a/src/common/Session.hpp b/src/common/Session.hpp new file mode 100755 index 0000000000000000000000000000000000000000..d791c9d0bab44d20fc23ea9dc78efd0747f170f3 --- /dev/null +++ b/src/common/Session.hpp @@ -0,0 +1,91 @@ +/* +** This file is part of the ViTE project. +** +** This software is governed by the CeCILL-A license under French law +** and abiding by the rules of distribution of free software. You can +** use, modify and/or redistribute the software under the terms of the +** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following +** URL: "http://www.cecill.info". +** +** As a counterpart to the access to the source code and rights to copy, +** modify and redistribute granted by the license, users are provided +** only with a limited warranty and the software's author, the holder of +** the economic rights, and the successive licensors have only limited +** liability. +** +** In this respect, the user's attention is drawn to the risks associated +** with loading, using, modifying and/or developing or reproducing the +** software by the user in light of its specific status of free software, +** that may mean that it is complicated to manipulate, and that also +** therefore means that it is reserved for developers and experienced +** professionals having in-depth computer knowledge. Users are therefore +** encouraged to load and test the software's suitability as regards +** their requirements in conditions enabling the security of their +** systems and/or data to be ensured and, more generally, to use and +** operate it in the same conditions as regards security. +** +** The fact that you are presently reading this means that you have had +** knowledge of the CeCILL-A license and that you accept its terms. +** +** +** ViTE developers are (for version 0.* to 1.0): +** +** - COULOMB Kevin +** - FAVERGE Mathieu +** - JAZEIX Johnny +** - LAGRASSE Olivier +** - MARCOUEILLE Jule +** - NOISETTE Pascal +** - REDONDY Arthur +** - VUCHENER Clément +** +*/ +/*! + *\file Session.hpp + */ + +#ifndef SESSION_HPP +#define SESSION_HPP + +#include <QObject> + +/*! + * \brief Class used to store information between two software launch. + * + */ +class Session{ + +private: + + /*! + * \brief The class constructor. + */ + Session(); + + +public: + + /*! + * \brief The class destructor. + */ + virtual ~Session(); + + + /*! + * \brief Sub structure to store export information. + */ + struct Export{ + + /*! + * \brief Store the export file dialog state. + */ + static QByteArray file_dialog_state; + + /*! + * \brief Default value of the export dialog state. + */ + const static QByteArray DEFAULT_STATE; + }; +}; + +#endif diff --git a/src/common/info.hpp b/src/common/info.hpp index 16259bf2c63658cf2b90b61c0c9cb4393e898f70..691a36ffbe4ab027d02171fa62a21051c6c10e8a 100644 --- a/src/common/info.hpp +++ b/src/common/info.hpp @@ -74,7 +74,7 @@ public: /*! - * \brief Sub structure to store screen informations. + * \brief Sub structure to store screen information. */ struct Screen{ @@ -91,7 +91,7 @@ public: /*! - * \brief Sub structure to store container informations. + * \brief Sub structure to store container information. */ struct Container{ @@ -118,7 +118,7 @@ public: }; /*! - * \brief Sub structure to store state informations. + * \brief Sub structure to store state information. */ struct Entity{ @@ -145,7 +145,7 @@ public: }; /*! - * \brief Sub structure to store render area informations. + * \brief Sub structure to store render area information. */ struct Render{ diff --git a/src/core/Core.cpp b/src/core/Core.cpp index 20b8b64a0ffaf7f155bffa8cdaac5edf6744ef8a..f2aedb140e7c5eadb28a4cb0e155fd509a082415 100644 --- a/src/core/Core.cpp +++ b/src/core/Core.cpp @@ -332,7 +332,8 @@ bool Core::draw_trace(const string & filename, const int format){ } //Interval interval(_time_start, ((0==_time_end)?_trace->get_max_date():_time_end) ); - Interval interval(Info::Entity::x_min, Info::Entity::x_max); + Interval interval(Info::Entity::x_min, Info::Entity::x_max); + // std::cout << __FILE__ << " " << __LINE__ << " " << Info::Render::_x_min_visible << " " << Info::Render::_x_max_visible << std::endl; if (_DRAW_OPENGL == format) { diff --git a/src/interface/Interface_graphic.cpp b/src/interface/Interface_graphic.cpp index 2ba9f542b73909c3c01e5da1d6b7ed56c8c0c61f..d58182b085308e2ea03ceb8c05c47d3f8a510818 100644 --- a/src/interface/Interface_graphic.cpp +++ b/src/interface/Interface_graphic.cpp @@ -55,6 +55,7 @@ #include "common/common.hpp" #include "common/info.hpp" #include "common/Tools.hpp" +#include "common/Session.hpp" /* -- */ #include "trace/values/Values.hpp" #include "trace/EntityTypes.hpp" @@ -138,7 +139,7 @@ void Interface_graphic::load_windows(){ QFile file_info( ":/window/info_window.ui"); QFile file_selection_export(":/window/option_export_window.ui"); QFile file_help(":/window/help_window.ui"); - QFile file_kind_of_export(":/window/kind_of_export.ui"); + // QFile file_kind_of_export(":/window/kind_of_export.ui"); QFile file_counter_to_export(":/window/list_of_counter_to_export.ui"); if (!QGLFormat::hasOpenGL()) @@ -167,11 +168,12 @@ void Interface_graphic::load_windows(){ file_help.close(); /* Load the export combo box choice from a .ui file */ - file_kind_of_export.open(QFile::ReadOnly); - CKFP(_ui_kind_of_export_choice = loader.load(&file_kind_of_export, this), "Cannot open the .ui file : " << ":/window/kind_of_export.ui"); + /* file_kind_of_export.open(QFile::ReadOnly); + CKFP(_ui_kind_of_export_choice = loader.load(&file_kind_of_export, this), "Cannot open the .ui file : " << ":/window/kind_of_export.ui"); CKFP(_ui_svg_export_button = qFindChild<QRadioButton*>(_ui_kind_of_export_choice, "svg_export"), "Cannot find the svg export button in the .ui file"); - CKFP(_ui_counter_export_button = qFindChild<QRadioButton*>(_ui_kind_of_export_choice, "counter_export"), "Cannot find the svg export button in the .ui file"); - file_kind_of_export.close(); + CKFP(_ui_png_export_button = qFindChild<QRadioButton*>(_ui_kind_of_export_choice, "png_export"), "Cannot find the png export button in the .ui file"); + CKFP(_ui_counter_export_button = qFindChild<QRadioButton*>(_ui_kind_of_export_choice, "counter_export"), "Cannot find the svg export button in the .ui file"); + file_kind_of_export.close();*/ /* Set some windows properties */ _ui_info_window->setWindowFlags(_ui_info_window->windowFlags() | Qt::WindowStaysOnTopHint);/* Always display info_window on top */ @@ -217,9 +219,9 @@ void Interface_graphic::load_windows(){ connect(_ui_counter_choice_to_export, SIGNAL(accepted()), this, SLOT(counter_choosed_triggered())); - connect(_ui_kind_of_export_choice, SIGNAL(accepted()), + /* connect(_ui_kind_of_export_choice, SIGNAL(accepted()), this, SLOT(choice_of_the_export_pressed())); - + */ connect(_ui_export_ok_button, SIGNAL(pressed()), this, SLOT(option_export_ok_pressed())); @@ -474,8 +476,81 @@ void Interface_graphic::on_open_triggered(){ } -void Interface_graphic::choice_of_the_export_pressed() { - if(_ui_svg_export_button->isChecked()) { +//void Interface_graphic::choice_of_the_export_pressed() { + +void Interface_graphic::on_export_file_triggered(){ + + if(_is_rendering_trace == false) + return; + + QStringList selected_files; + QFileDialog file_dialog(this); + QString filename; + QString extension; + /* + filename = QFileDialog(this)::getSaveFileName(this, tr("Save File"), + "", + tr("Vector (*.svg);;Bitmap (*.png *.xpm *.jpg);;Counter (*.txt)")); + */ + /* Try to recover the last file dialog state. */ + if (Session::Export::file_dialog_state!=Session::Export::DEFAULT_STATE){ + if (!file_dialog.restoreState(Session::Export::file_dialog_state)) + warning("Cannot restore the export file dialog state"); + } + + file_dialog.setLabelText(QFileDialog::FileName, QString(_trace_path.substr(0, _trace_path.find_last_of('.')).c_str()) + ".svg"); + file_dialog.setFileMode(QFileDialog::AnyFile);/* Allow to browse among directories */ + file_dialog.setAcceptMode(QFileDialog::AcceptSave);/* Only save file */ + file_dialog.setNameFilter(tr("Vector (*.svg);;Bitmap PNG (*.png);;Bitmap JPEG (*.jpeg *.jpg);;Counter (*.txt)")); + + // file_dialog.setDefaultSuffix("svg"); + + if (file_dialog.exec()){/* Display the file dialog */ + selected_files = file_dialog.selectedFiles();//"/tmp/test.png";//file_dialog.selectedFile(); + + if (selected_files.length()==1) + filename = selected_files[0];/* Get the first filename */ + else{ + + if (selected_files.length()==0) + warning("No file was selected."); + else + warning("Cannot save: too much files were selected."); + + return; + } + + if (filename.right(4)!="."){/* No extension or extension is not correct */ + /* Add it manually */ + const QString filter_selected = file_dialog.selectedNameFilter(); + + if ("Vector (*.svg)"==filter_selected){ + filename += ".svg"; + extension = "svg"; + }else if ("Bitmap PNG (*.png)"==filter_selected){ + filename += ".png"; + extension = "png"; + }else if ("Bitmap JPEG (*.jpeg *.jpg)"==filter_selected){ + filename += ".jpg"; + extension = "jpg"; + }else if ("Counter (*.txt)"==filter_selected){ + filename += ".txt"; + extension = "txt"; + }else + warning("Cannot recognize the filter: "+filter_selected.toStdString()); + + /* Update the _export_filename attribute which will be used in SVG or Counter export functions */ + _export_filename = filename; + + }else + extension = filename.right(3).toLower();/* in lower case */ + } + + /* Save the file dialog state (History and current directory) */ + Session::Export::file_dialog_state = file_dialog.saveState(); + + if (extension=="svg"){ + // if(_ui_svg_export_button->isChecked()) { ostringstream temp; temp.str(""); @@ -488,7 +563,8 @@ void Interface_graphic::choice_of_the_export_pressed() { _ui_max_time_export->setText(temp.str().c_str()); _ui_time_selection_export->show(); } - else if (_ui_counter_export_button->isChecked()) { + else if (extension=="txt"){ + // else if (_ui_counter_export_button->isChecked()) { // In order to easily retrieve the good variable, we store them with an index representing the container name followed by the variabletype name (because a variable has no name) _all_variables.clear(); _core->get_trace()->get_all_variables(_all_variables); @@ -508,54 +584,70 @@ void Interface_graphic::choice_of_the_export_pressed() { _ui_counter_choice_to_export->show(); } + else if (extension=="png" || extension=="jpg" || extension=="jpeg"){ + // else if (_ui_png_export_button->isChecked()) { + QImage tempImage = _ui_render_area->grabFrameBuffer(true);/* true = with alpha channel */ // new QImage( pPixelData, width, height, QImage::Format_RGB32); + + if ( !tempImage.save( filename, extension.toUpper().toStdString().c_str()) ){ + error("The trace cannot be exported into "+filename.toStdString()+" file."); + }else{ + information("The trace was exported into "+filename.toStdString()+" file."); + } + }else{ + error("Cannot recognize the file extension: "+extension.toStdString()+"."); + + } } void Interface_graphic::counter_choosed_triggered() { // Il faut faire choisir le nom du fichier! et enfin on peut lancer l'action ! - const QString path_by_default = QString(_trace_path.substr(0, _trace_path.find_last_of('.')).c_str()) + ".txt"; - QString filename = QFileDialog::getSaveFileName(this, QObject::tr("Export File"), - path_by_default, - QObject::tr("All files")); + // const QString path_by_default = QString(_trace_path.substr(0, _trace_path.find_last_of('.')).c_str()) + ".txt"; + //QString filename = QFileDialog::getSaveFileName(this, QObject::tr("Export File"), + // path_by_default, + // QObject::tr("All files")); Variable *temp = _all_variables[_counter_list_names->currentText().toStdString()]; - _core->export_variable(temp, filename.toStdString()); + // _core->export_variable(temp, filename.toStdString()); + _core->export_variable(temp, _export_filename.toStdString()); } -void Interface_graphic::on_export_file_triggered(){ +/*void Interface_graphic::on_export_file_triggered(){ if(_is_rendering_trace == false) return; _ui_kind_of_export_choice->show(); -} + }*/ void Interface_graphic::option_export_ok_pressed(){ // We have to save the option from _ui_time_selection_export and hide her if it is not do automatically _ui_time_selection_export->hide(); - const QString path_by_default = QString(_trace_path.substr(0, _trace_path.find_last_of('.')).c_str()) + ".svg"; - QString filename = QFileDialog::getSaveFileName(this, tr("Export File"), - path_by_default, - tr("Images (*.svg)")); + // const QString path_by_default = QString(_trace_path.substr(0, _trace_path.find_last_of('.')).c_str()) + ".svg"; + //QString filename = QFileDialog::getSaveFileName(this, tr("Export File"), + // path_by_default, + // tr("Images (*.svg)")); + QString filename = _export_filename; + if (!filename.isEmpty()) { // Adding .svg to the end - if(!filename.endsWith(".svg")) { + /* if(!filename.endsWith(".svg")) { filename += ".svg"; - } + }*/ information(string("Exporting trace to ")+filename.toStdString()); _core->set_path_to_export(filename.toStdString()); // _core->draw_trace(_trace_path, Core::_DRAW_SVG); - if(_ui_CheckBox_time_export->isChecked()){ - _core->set_min_value_for_export(convert_to_double(_ui_min_time_export->text().toStdString())); - _core->set_max_value_for_export(convert_to_double(_ui_max_time_export->text().toStdString())); - } + // if(_ui_CheckBox_time_export->isChecked()){ + // _core->set_min_value_for_export(convert_to_double(_ui_min_time_export->text().toStdString())); + // _core->set_max_value_for_export(convert_to_double(_ui_max_time_export->text().toStdString())); + /* } else{ _core->set_min_value_for_export(0); _core->set_max_value_for_export(Info::Entity::x_max);//TO DO TODO max_size de la trace? - } + }*/ _core->launch_action(Core::_STATE_EXPORT_FILE_IN_INTERVAL); } diff --git a/src/interface/Interface_graphic.hpp b/src/interface/Interface_graphic.hpp index c605d5041be15574bbef82a5241524e5b6ae7528..43b9673fcda0bc662ee00e43dd8e7aef0959df1d 100644 --- a/src/interface/Interface_graphic.hpp +++ b/src/interface/Interface_graphic.hpp @@ -81,7 +81,6 @@ class Interface_graphic : public QMainWindow, protected Ui::main_window, public */ void load_windows(); - /*********************************** * * Main window widget attributes. @@ -184,6 +183,11 @@ class Interface_graphic : public QMainWindow, protected Ui::main_window, public */ QComboBox* _ui_zoom_box; + /*! + * \brief Use to store the filename when the trace is exported. + */ + QString _export_filename; + /*! * \brief Contains the last zoom value. (Prevent recursive calls) */ @@ -272,6 +276,7 @@ class Interface_graphic : public QMainWindow, protected Ui::main_window, public */ QWidget* _ui_kind_of_export_choice; QRadioButton* _ui_svg_export_button; + QRadioButton* _ui_png_export_button; QRadioButton* _ui_counter_export_button; /*! @@ -484,7 +489,7 @@ protected slots: /*! *\brief A slot called when the choice of the export is done and ok. */ - void choice_of_the_export_pressed(); + // void choice_of_the_export_pressed(); /*! *\brief A slot called when the choice of the counter is done and ok. diff --git a/src/interface/kind_of_export.ui b/src/interface/kind_of_export.ui deleted file mode 100644 index 7091fa34aac48362de7d412446eacabe56b2f820..0000000000000000000000000000000000000000 --- a/src/interface/kind_of_export.ui +++ /dev/null @@ -1,104 +0,0 @@ -<ui version="4.0" > - <class>kind_of_export</class> - <widget class="QDialog" name="kind_of_export" > - <property name="geometry" > - <rect> - <x>0</x> - <y>0</y> - <width>369</width> - <height>255</height> - </rect> - </property> - <property name="windowTitle" > - <string>Kind of export</string> - </property> - <property name="windowIcon" > - <iconset resource="vite.qrc" > - <normaloff>:/icon/icon/vite.png</normaloff>:/icon/icon/vite.png</iconset> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2" > - <item> - <widget class="QGroupBox" name="groupBox" > - <property name="title" > - <string>Choose the kind of export:</string> - </property> - <property name="alignment" > - <set>Qt::AlignCenter</set> - </property> - <layout class="QHBoxLayout" name="horizontalLayout" > - <item> - <layout class="QVBoxLayout" name="verticalLayout" > - <item> - <widget class="QRadioButton" name="svg_export" > - <property name="text" > - <string>Svg export of all the trace</string> - </property> - <property name="checked" > - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="QRadioButton" name="counter_export" > - <property name="text" > - <string>Counter export</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox" > - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons" > - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - <zorder>buttonBox</zorder> - <zorder>groupBox</zorder> - </widget> - <resources> - <include location="vite.qrc" /> - </resources> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>kind_of_export</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel" > - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel" > - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>kind_of_export</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel" > - <x>184</x> - <y>229</y> - </hint> - <hint type="destinationlabel" > - <x>184</x> - <y>127</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/src/interface/vite.qrc b/src/interface/vite.qrc index 5548ed2b21c2190acd0149b45665d9b4fac0e3b0..bb261d72c0f17b726a0f02b12e36a1fe2f1103e6 100644 --- a/src/interface/vite.qrc +++ b/src/interface/vite.qrc @@ -30,7 +30,6 @@ <file>main_window.ui</file> <file>option_export_window.ui</file> <file>stats_viewer.ui</file> - <file>kind_of_export.ui</file> <file>list_of_counter_to_export.ui</file> </qresource> </RCC> diff --git a/src/render/Hook_event.cpp b/src/render/Hook_event.cpp index 7b0d52e6d3392181adc7a1c3ec50e9672de52fa8..af5e666cc3a2edde1a959fa11e8ff6279737f3d1 100644 --- a/src/render/Hook_event.cpp +++ b/src/render/Hook_event.cpp @@ -64,6 +64,11 @@ const int Hook_event::_ctrl_scroll_factor = 10; const int Hook_event::_ctrl_zoom_factor = 3; +void Hook_event::updateRender(){ + _render_instance->update(); +} + + /*********************************** * * @@ -133,7 +138,7 @@ Hook_event::Hook_event(Render_opengl* render_instance, Core* core, QWidget *pare setMouseTracking (true);/* to catch mouse events */ setFocusPolicy(Qt::StrongFocus);/* to catch keybord events (focus by tabbing or clicking) */ - //_render_instance->updateGL(); + //updateRender(); } @@ -165,7 +170,7 @@ void Hook_event::mousePressEvent(QMouseEvent * event){ to cancel the drawing */ if ( true == _mouse_pressed){ _mouse_pressed = false; - _render_instance->updateGL(); + updateRender(); return; } @@ -184,7 +189,7 @@ void Hook_event::mousePressEvent(QMouseEvent * event){ _previous_selection.pop(); refresh_scroll_bars(true); - _render_instance->updateGL(); + updateRender(); #ifdef DEBUG_MODE_RENDER_AREA_ @@ -232,7 +237,7 @@ void Hook_event::mouseDoubleClickEvent ( QMouseEvent * event ){ _core->launch_action(_core->_STATE_RENDER_DISPLAY_INFORMATION, NULL); _mouse_pressed = false; - _render_instance->updateGL(); + updateRender(); } } @@ -244,7 +249,7 @@ void Hook_event::mouseMoveEvent(QMouseEvent * event){ _new_mouse_x = event->x(); _new_mouse_y = event->y(); - _render_instance->updateGL(); + updateRender(); } @@ -387,7 +392,7 @@ void Hook_event::apply_zoom_box(Element_pos x_min, Element_pos x_max, Element_po _y_state_scale *= Info::Screen::height/(y_max - y_min); _mouse_pressed = false; - _render_instance->updateGL(); + updateRender(); refresh_scroll_bars(true); } @@ -538,7 +543,7 @@ void Hook_event::replace_scale(Element_pos new_scale){ _core->launch_action(_core->_STATE_ZOOM_BOX_VALUE, &buf); - _render_instance->updateGL(); + updateRender(); refresh_scroll_bars(true); } } @@ -559,7 +564,7 @@ void Hook_event::replace_scale_y(Element_pos new_scale){ _y_state_scale = new_scale; /* TODO add a zoom box value for y zoom */ - _render_instance->updateGL(); + updateRender(); refresh_scroll_bars(true); } } @@ -589,7 +594,7 @@ void Hook_event::replace_translate(Element_pos new_translate){ refresh_scroll_bars(); _key_scrolling = false; } - _render_instance->updateGL(); + updateRender(); } @@ -606,7 +611,7 @@ void Hook_event::replace_translate_y(Element_pos new_translate){ refresh_scroll_bars(); _key_scrolling = false; } - _render_instance->updateGL(); + updateRender(); } @@ -647,7 +652,7 @@ void Hook_event::registered_translate(int id){ } refresh_scroll_bars(); - _render_instance->updateGL(); + updateRender(); } @@ -667,7 +672,7 @@ void Hook_event::refresh_scroll_bars(bool LENGTH_CHANGED){ void Hook_event::change_scale_container_state(int view_size){ _x_scale_container_state = 0.01 * view_size; - _render_instance->updateGL(); + updateRender(); } diff --git a/src/render/Hook_event.hpp b/src/render/Hook_event.hpp index 12c1e17dce394d3e9376c348eb0cbebc2978a444..98dc2bafc23563dd619aad4ff2ab549d11048f71 100644 --- a/src/render/Hook_event.hpp +++ b/src/render/Hook_event.hpp @@ -300,8 +300,10 @@ protected: */ void keyReleaseEvent(QKeyEvent * event); - - + /*! + * Use to update the render area. + */ + void updateRender(); /*********************************** diff --git a/src/render/Render.hpp b/src/render/Render.hpp index 8f0c50aa643b580c49d3c2636fda1b9b3e153a13..56966e0d38d193127b45feb8367a3bfb7d7c14df 100755 --- a/src/render/Render.hpp +++ b/src/render/Render.hpp @@ -440,6 +440,8 @@ public: graduation_diff = Ruler::get_graduation_diff(Info::Render::_x_min_visible, Info::Render::_x_max_visible); coeff_prefix = Ruler::get_coeff_for_common_prefix(Info::Render::_x_min_visible, Info::Render::_x_max_visible); + // std::cout << __FILE__ << " " << __LINE__ << " : " << coeff_prefix << std::endl; + drawing_instance->start_ruler(); drawing_instance->set_color(1, 0, 0); for (Element_pos i = Info::Render::_x_min_visible ; i < Info::Render::_x_max_visible ; i+=graduation_diff){ diff --git a/src/render/Render_opengl.cpp b/src/render/Render_opengl.cpp index aed94c342a389dbed62e31f5a22158b1de970ab6..7d441473ac77f5fb34fa6f381d1fc34a69407228 100644 --- a/src/render/Render_opengl.cpp +++ b/src/render/Render_opengl.cpp @@ -166,9 +166,10 @@ void Render_opengl::resizeGL(int width, int height) { } -void Render_opengl::paintGL(){ - paintEvent(NULL); -} +/*void Render_opengl::paintGL(){ + // paintEvent(NULL); + cout << __FILE__ << " " << __LINE__ << endl; + }*/ void Render_opengl::paintEvent(QPaintEvent *) { @@ -201,7 +202,6 @@ void Render_opengl::paintGL(){ }else if (DRAWING_STATE_DRAWING == _state){/* A trace is drawn */ - glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -341,8 +341,7 @@ void Render_opengl::paintGL(){ if(glerror != GL_NO_ERROR) message << tr("Render area : the following OpengGL error occured: ").toStdString() << (char *)gluErrorString(glerror) << Message::endw; - - + QPainter painter(this); //painter.setPen(Qt::NoPen); //painter.setBrush(QColor(125, 125, 150)); @@ -389,6 +388,8 @@ void Render_opengl::paintGL(){ + + /*********************************** * * @@ -610,7 +611,7 @@ void Render_opengl::call_ruler(){ ){ buf_txt << "<b>"; - + if (common_part==0.0){ if (variable_part!=0.0){ diff --git a/src/render/Render_opengl.hpp b/src/render/Render_opengl.hpp index a285b333d16a08a5a22e044052a1af1394aacefe..56730aae93d3ff7a0450edf2e0d3b19e7f2b1507 100644 --- a/src/render/Render_opengl.hpp +++ b/src/render/Render_opengl.hpp @@ -218,8 +218,7 @@ public: /*! * \brief Call by the system each time the render area need to be updated. */ - void paintGL(); - + // void paintGL(); /*********************************** diff --git a/src/render/Render_svg.cpp b/src/render/Render_svg.cpp index ee595ab15427d5089e1071e4c43a2355294d7279..6328efce81960f7eefc5b800b32f1dc158b287e6 100755 --- a/src/render/Render_svg.cpp +++ b/src/render/Render_svg.cpp @@ -61,6 +61,16 @@ using namespace std; #define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): " +static int number_size(double n){ + int n_floor; + + n_floor = (int)n; + + if (n_floor==0) return 1; + + return (int)ceil(log10(n_floor)); +} + /*********************************** * @@ -100,7 +110,7 @@ void Render_svg::draw_text(const Element_pos x, const Element_pos y, const Eleme _buffer.str(""); _buffer << "<text x=\"" << render_to_screen_x(x) <<"\"" << " y=\"" << render_to_screen_y(y) << "\"" - << " font-size=\"8\"" + << " font-size=\"10\"" << " fill=\"white\">" << s << "</text>\n"; @@ -111,15 +121,15 @@ void Render_svg::draw_text(const Element_pos x, const Element_pos y, const Eleme void Render_svg::draw_quad(Element_pos x, Element_pos y, Element_pos , Element_pos w, Element_pos h){ - const Element_pos x_min = trace_to_render_x(Info::Render::_x_min_visible); - const Element_pos x_max = trace_to_render_x(Info::Render::_x_max_visible); + // const Element_pos x_min = trace_to_render_x(Info::Render::_x_min_visible); + // const Element_pos x_max = trace_to_render_x(Info::Render::_x_max_visible); if (render_to_screen_x(w) < 1)/* less than 1 pixel */ return; - if ((x+w) < x_min) - return; - if (x > x_max) - return; + // if ((x+w) < x_min) +// return; +// if (x > x_max) +// return; // std::cout << __FILE__ << " " << __LINE__ << " - " << x << " " << << std::endl; @@ -233,22 +243,101 @@ void Render_svg::end_draw_counter(){ } void Render_svg::start_ruler(){ - _buffer.str(""); - _buffer << "<text x=\"" << 0 <<"\"" - << " y=\"" << 0 << "\"" - << " font-size=\"18\"" - << " fill=\"white\">" - << Info::Render::_x_min_visible - << "</text>\n"; - - _output_file.write(_buffer.str().c_str(), _buffer.str().size()); + } void Render_svg::end_ruler(){ } void Render_svg::end_draw(){ + float intpart; + float fractpart; + int min_visible_size; + int max_visible_size; + int*j; + Element_pos k; + + if (Info::Render::_x_min_visible != Info::Render::_x_max_visible){ + + for (j = &min_visible_size, + k = Info::Render::_x_min_visible + ; + k <= Info::Render::_x_max_visible + ; + j = &max_visible_size, + k += Info::Render::_x_max_visible - Info::Render::_x_min_visible){ + + + if (k==0.0){ + *j = 1; + continue; + } + + *j = 0; + intpart = 0; + fractpart = k - floor(k);//modf(k, &intpart); + intpart = floor(k); + + // cout << __FILE__ << " " << __LINE__ << " >> " << intpart << " " << fractpart << endl; + while(floor(fractpart) != fractpart){ + // cout << __FILE__ << " " << __LINE__ << " >> " << floor(fractpart) << " " << fractpart << endl; + fractpart*=10; + (*j)++; + } + + (*j) += number_size(intpart);// + number_size(fractpart); + } + + // cout << __FILE__ << " " << __LINE__ << " >> " << Info::Render::_x_min_visible << " " << Info::Render::_x_max_visible << endl; + //cout << __FILE__ << " " << __LINE__ << " >> " << min_visible_size << " " << max_visible_size << endl; + + /* Draw the main ruler */ + const int LETTER_WIDTH = 10; + const int LETTER_HEIGHT = 14; + + const int MINVISIBLE_WIDTH = min_visible_size*LETTER_WIDTH; + const int MINVISIBLE_HEIGHT = - LETTER_HEIGHT;; + const int MINVISIBLE_X = 8; + const int MINVISIBLE_Y = - MINVISIBLE_HEIGHT; + + const int MAXVISIBLE_WIDTH = max_visible_size*LETTER_WIDTH; + const int MAXVISIBLE_HEIGHT = - LETTER_HEIGHT;; + const int MAXVISIBLE_X = Info::Screen::width - MAXVISIBLE_WIDTH; + const int MAXVISIBLE_Y = - MAXVISIBLE_HEIGHT; + + + _buffer.str(""); + _buffer << "<polygon points=\"" + << MINVISIBLE_X << "," << MINVISIBLE_Y << "," + << MINVISIBLE_X+MINVISIBLE_WIDTH << "," << MINVISIBLE_Y << "," + << MINVISIBLE_X+MINVISIBLE_WIDTH << "," << MINVISIBLE_Y+MINVISIBLE_HEIGHT << "," + << MINVISIBLE_X << "," << MINVISIBLE_Y+MINVISIBLE_HEIGHT << "\"" + << " style=\"fill:black\"" + << "/>\n"; + _buffer << "<text x=\"" << MINVISIBLE_X <<"\"" + << " y=\"" << MINVISIBLE_Y << "\"" + << " font-size=\"" << LETTER_HEIGHT << "\"" + << " fill=\"white\">" + << Info::Render::_x_min_visible + << "</text>\n"; + _buffer << "<polygon points=\"" + << MAXVISIBLE_X << "," << MAXVISIBLE_Y << "," + << MAXVISIBLE_X+MAXVISIBLE_WIDTH << "," << MAXVISIBLE_Y << "," + << MAXVISIBLE_X+MAXVISIBLE_WIDTH << "," << MAXVISIBLE_Y+MAXVISIBLE_HEIGHT << "," + << MAXVISIBLE_X << "," << MAXVISIBLE_Y+MAXVISIBLE_HEIGHT << "\"" + << " style=\"fill:black\"" + << "/>\n"; + _buffer << "<text x=\"" << MAXVISIBLE_X <<"\"" + << " y=\"" << MAXVISIBLE_Y << "\"" + << " font-size=\"" << LETTER_HEIGHT << "\"" + << " fill=\"white\">" + << Info::Render::_x_max_visible + << "</text>\n"; + + }/* end if (Info::Render::_x_min_visible != Info::Render::_x_max_visible) */ + + /* Close the svg file */ _buffer << "</svg>"; _output_file.write(_buffer.str().c_str(), _buffer.str().size()); diff --git a/src/render/Ruler.cpp b/src/render/Ruler.cpp index 90d7a4a2d3471a392a553b391c2cc426ed145036..b1a3cf3c9d7fcf55a38a86c11faa82f51b3ced8d 100755 --- a/src/render/Ruler.cpp +++ b/src/render/Ruler.cpp @@ -147,9 +147,11 @@ Element_pos Ruler::get_coeff_for_common_prefix(Element_pos min, Element_pos max) std::cout << __FILE__ << " " << __LINE__ << " Loop || floor(min): " << floor(min) << " - floor(max): " << floor(max) << std::endl;*/ } - coeff /= 10;/* adjust */ + //coeff /= 10;/* adjust */ + security_counter = 0; + } - }else{ + //else{ /* If common value differs, min and max will be divided by 10 (shift coma to the left) until their entire part are equal. */ while( (floor(min) != floor(max)) && (security_counter<20) ){ @@ -161,18 +163,24 @@ Element_pos Ruler::get_coeff_for_common_prefix(Element_pos min, Element_pos max) std::cout << __FILE__ << " " << __LINE__ << " Loop || floor(min): " << floor(min) << " - floor(max): " << floor(max) << std::endl;*/ } - coeff *= 10;/* adjust */ - } + // coeff *= 10;/* adjust */ + // } /* std::cout << __FILE__ << " " << __LINE__ << " coeff: " << coeff << std::endl << std::endl;*/ return coeff; } + +/* TODO: use cmath::modf() */ + float Ruler::get_common_part(const Element_pos n, const Element_pos coeff_for_common_prefix){ const int common_part = floor(n*coeff_for_common_prefix); const float common_part_without_coeff = common_part/coeff_for_common_prefix; + /* std::cout << __FILE__ << " " << __LINE__ << " >> n:" << n << " coeff: " << coeff_for_common_prefix + << " common_part: " << common_part << " cpwc: " << common_part_without_coeff << std::endl;*/ + if ( (floor(common_part_without_coeff) != common_part_without_coeff)/* there is a comma */ )//&& floor(common_part_without_coeff) != 0 )/* and there is numbers before comma */ return common_part_without_coeff; diff --git a/src/src.pro b/src/src.pro index c11f73e619989ea734bf17c3748cfd31c41072fe..787bd2a56f79b17febe3748d8445518b8bdcf6cd 100644 --- a/src/src.pro +++ b/src/src.pro @@ -77,6 +77,7 @@ HEADERS += common/common.hpp \ common/Errors.hpp \ common/Tools.hpp \ common/info.hpp \ + common/Session.hpp \ # Interface headers interface/interface.hpp \ interface/Interface_graphic.hpp \ @@ -150,12 +151,13 @@ HEADERS += common/common.hpp \ plugin/Command_window.hpp -FORMS += interface/info_window.ui interface/main_window.ui interface/option_export_window.ui interface/stats_viewer.ui interface/global_cmd.ui interface/kind_of_export.ui list_of_counter_to_export.ui +FORMS += interface/info_window.ui interface/main_window.ui interface/option_export_window.ui interface/stats_viewer.ui interface/global_cmd.ui list_of_counter_to_export.ui SOURCES += common/Message.cpp \ common/Errors.cpp \ common/Tools.cpp \ common/info.cpp \ + common/Session.cpp \ # Data structure code files trace/values/Color.cpp \ trace/values/Date.cpp \ diff --git a/tests/render/Makefile b/tests/render/Makefile index f2570d95c8968d9ca7b2c0845fa9553ff4b0eb59..0069c9ded672276e6b571010b354847567237dbb 100644 --- a/tests/render/Makefile +++ b/tests/render/Makefile @@ -1,3 +1,7 @@ +test_ruler: test_Ruler.cpp + g++ -c test_Ruler.cpp -o test_Ruler.o + g++ -o test_Ruler test_Ruler.o ../../bin/Ruler.o + render_test: main.cpp Render.hpp Render_opengl.hpp Trace.hpp g++ -c Render.hpp -o Render.o g++ -c Render_opengl.hpp -o Render_opengl.o @@ -7,4 +11,5 @@ render_test: main.cpp Render.hpp Render_opengl.hpp Trace.hpp clean: rm *.o rm render_test + rm test_Ruler rm *~ \ No newline at end of file diff --git a/tests/render/test_Ruler.cpp b/tests/render/test_Ruler.cpp new file mode 100755 index 0000000000000000000000000000000000000000..5bf331420f2856d03348ace117661dbf0ca3f2c7 --- /dev/null +++ b/tests/render/test_Ruler.cpp @@ -0,0 +1,40 @@ +#include <iostream> +typedef double Element_pos; +#include "../../src/render/Ruler.hpp" + + +void display_information(const Element_pos min, const Element_pos max){ + Element_pos graduation_diff, coeff_prefix; + Element_pos min_common_part, min_variable_part; + Element_pos max_common_part, max_variable_part; + + + graduation_diff = Ruler::get_graduation_diff(min, max); + coeff_prefix = Ruler::get_coeff_for_common_prefix(min, max); + + min_common_part = Ruler::get_common_part(min, coeff_prefix); + min_variable_part = Ruler::get_variable_part(min, coeff_prefix, 2); + + max_common_part = Ruler::get_common_part(max, coeff_prefix); + max_variable_part = Ruler::get_variable_part(max, coeff_prefix, 2); + + std::cout << "Display result for min=" << min << " and max=" << max << "\n" + << "Graduation difference=" << graduation_diff << "\n" + << "Coefficient for common prefix=" << coeff_prefix << "\n" + << "Minimum:\n\tCommon part=" << min_common_part << "\n" + << "\tVariable part=" << min_variable_part << "\n" + << "Maximum:\n\tCommon part=" << max_common_part << "\n" + << "\tVariable part=" << max_variable_part << "\n" << std::endl; +} + + +int main(int argc, char** argv){ + Element_pos min, max; + + display_information(1.0, 2.0); + display_information(0.0, 0.50); + display_information(0.10, 0.104); + display_information(0.9, 1.0); + + return 0; +}