Commit 3cded88c authored by Olivier Lagrasse's avatar Olivier Lagrasse

Restore the ruler

parent 3f1415b1
......@@ -140,10 +140,10 @@ Core::Core(int argc, char ** argv){
if (!useGUI){
/* if (!useGUI){
cerr << QObject::tr("Error: Graphical window cannot be displayed.").toStdString() << endl;
exit(EXIT_FAILURE);
}
}*/
_main_window = NULL;
_render_opengl = NULL;
......@@ -618,7 +618,8 @@ void Core::extract_times(const char *name) {
void Core::launch_action(int state, void* arg) {
DrawTrace/*<Render_opengl>*/ buf;
DrawTrace buf;
QGLFormat format(QGL::HasOverlay);
switch(state) {
......@@ -627,39 +628,52 @@ void Core::launch_action(int state, void* arg) {
break;
case _STATE_LAUNCH_GRAPHICAL_INTERFACE :
case _STATE_OPEN_FILE:
_main_window = new Interface_graphic(this);/* launch the window interface */
Message::set_interface(_main_window);/* define which interface will receive messages */
/* MOD */
// _render_opengl = new Render_opengl_dl(this, _main_window);
_render_opengl = new Render_opengl(this, _main_window);
if ( _STATE_OPEN_FILE == state)
message << QObject::tr("Opening the file: ").toStdString ()+_file_opened << Message::endi;
_main_window->bind_render_area((QGLWidget*)_render_opengl);
_main_window = new Interface_graphic (this);/* launch the window interface */
Message::set_interface (_main_window);/* define which interface will receive messages */
_is_window_displayed = true;
break;
// format.setOverlay(true);
_render_opengl = new Render_opengl (this, _main_window, format);
case _STATE_OPEN_FILE:
information(string("Opening the file: ")+_file_opened);
_main_window = new Interface_graphic(this);/* launch the window interface and open a file */
Message::set_interface(_main_window);/* define which interface will receive messages */
if ( NULL == _render_opengl){
message << QObject::tr("Cannot allocate memory for an OpengGL instance").toStdString () << Message::ende;
break;
}
/* MOD */
// _render_opengl = new Render_opengl_dl(this, _main_window);
_render_opengl = new Render_opengl(this, _main_window);
if (NULL == _render_opengl->context()){
message << QObject::tr("Cannot allocate an OpengGL context").toStdString () << Message::ende;
break;
}
if (false == _render_opengl->isValid()){
message << QObject::tr("Invalid context: OpenGL is not supported on your system").toStdString () << Message::ende;
}
// if (false == _render_opengl->format().hasOverlay ()){
// /* If no overlay was created, check the original format */
// if (false == _render_opengl->context()->requestedFormat().hasOverlay())
// message << QObject::tr("No overlay format originally created").toStdString () << Message::endw;
// else
// message << QObject::tr("An overlay format was originally asked, but was not created").toStdString () << Message::endw;
// }
_main_window->bind_render_area((QGLWidget*)_render_opengl);
_main_window->opening_file(_file_opened);/* Must be called after binding the render area to the main window */
if(false==draw_trace(_file_opened, _DRAW_OPENGL))
message << "Draw trace failed" << Message::ende;
if ( _STATE_OPEN_FILE == state){
_main_window->opening_file(_file_opened);/* Must be called after binding the render area to the main window */
if(false==draw_trace(_file_opened, _DRAW_OPENGL))
message << QObject::tr("Draw trace failed").toStdString () << Message::ende;
}
_is_window_displayed = true;
break;
case _STATE_OPEN_FILE_IN_AN_INTERVAL:
......
......@@ -84,9 +84,9 @@ void Hook_event::updateRender(){
*
**********************************/
Hook_event::Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent)
: QGLWidget(/*QGLFormat(QGL::HasOverlay),*/ parent){
Hook_event::Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent, const QGLFormat& format)
: QGLWidget(format, parent){
// GLenum glew_code;
......
......@@ -327,7 +327,7 @@ public:
* \brief The constructor.
* \param render_instance The instance of a drawing class.
*/
Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent);
Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent, const QGLFormat& format);
/*!
* \brief The destructor
......
This diff is collapsed.
......@@ -182,7 +182,7 @@ public:
/*!
* \brief The default constructor
*/
Render_opengl(Core* core, QWidget *parent);
Render_opengl(Core* core, QWidget *parent, const QGLFormat& format);
/*!
* \brief The destructor
......
......@@ -175,14 +175,10 @@ Element_pos Ruler::get_coeff_for_common_prefix(Element_pos min, Element_pos max)
/* 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;
int common_part = floor(n*coeff_for_common_prefix);
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 */
if ( (floor(common_part_without_coeff) != common_part_without_coeff) )/* there is a comma */
return common_part_without_coeff;
else
return (float)common_part;
......@@ -192,75 +188,67 @@ float Ruler::get_variable_part(const Element_pos n, const Element_pos coeff_for_
const int common_part = floor( (n*coeff_for_common_prefix - floor(n*coeff_for_common_prefix))*pow(10, nb_digit_after_comma));
const float common_part_without_coeff = common_part/(coeff_for_common_prefix*pow(10, nb_digit_after_comma));
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 */
if ( floor(common_part_without_coeff) != 0 )/* and there is numbers before comma */
return common_part_without_coeff;
else
return (float)common_part;
}
string Ruler::get_common_part_string(const Element_pos n, const Element_pos coeff_for_common_prefix){
ostringstream buf_txt;
float n_with_coeff;
string Ruler::get_common_part_string(const Element_pos n, Element_pos coeff_for_common_prefix){
int i, common_part;
Element_pos buf;
ostringstream buf_txt, result_txt;
string::reverse_iterator rit;
/**
*
* For n = 10.2034 and coeff_for_common_prefix = 100,
* then common_part = 1020
*
*/
common_part = floor(n*coeff_for_common_prefix);
n_with_coeff = n/coeff_for_common_prefix;
buf_txt.str("");
result_txt.str("");
/**
* First case: if n = 0.0234 and common_part is 0.023,
* Put "0.0" and after "23". (Otherwise, common_part will
* be equal to 23, ignoring "0.0"!)
*/
buf = n;
if ( (buf != 0.0) && (floor(buf) == 0) ){
result_txt << "0.";
buf *= 10;
}
if (coeff_for_common_prefix > 1){/* point is in variable part */
while ( (buf != 0.0) && (floor(buf) == 0) ){
result_txt << "0";
buf *= 10;
}
float coeff;
for (i=0 ; common_part > 0 ; common_part = floor(common_part/10)){
buf_txt << common_part%10;
coeff = coeff_for_common_prefix;
/**
* For example 102.34 with common 1**.**
*/
buf_txt << floor(n_with_coeff);
/**
* buf_txt = "1"
*/
for (;
coeff > 1;
coeff /= 10){
/**
* First loop: buf_txt = "1-"
* Second loop: buf_txt = "1--"
*/
buf_txt << "-";
}
buf_txt << ".-";
/**
* buf_txt = "1--.-"
*/
}else if (coeff_for_common_prefix < 1){/* point is in common part */
/**
* For example 10.234 with common 10.2**
*/
buf_txt << floor(n) << ".";
/**
* buf = "10"+"."
*/
buf_txt << floor(n)*coeff_for_common_prefix - n_with_coeff;
/**
* buf = "10."+10*10-102 = "10."+"2" = "10.2"
*/
buf_txt << "--";
/**
* buf = "10.2--"
*/
}else{/* point is between common and variable part */
/**
* For example 102.34 with common 102.**
*/
buf_txt << floor(n) << ".--";
/**
* buf_txt = "102.--"
*/
if (coeff_for_common_prefix < 1)
coeff_for_common_prefix *= 10.0;
else
coeff_for_common_prefix /= 10.0;
if ( (coeff_for_common_prefix == 1.0) && (floor(common_part/10)>0) )
buf_txt << ".";/* Add comma */
}
return buf_txt.str();
for ( rit=buf_txt.str().rbegin() ; rit < buf_txt.str().rend(); rit++ )
result_txt << *rit;
return result_txt.str();
}
string Ruler::get_variable_part_string(const Element_pos n, const Element_pos coeff_for_common_prefix){
}
......@@ -97,7 +97,7 @@ public:
* \return A float. The common part of n according to the common prefix coefficient got from the
* Ruler::get_coeff_for_common_prefix() method.
*/
static float get_common_part(const Element_pos n, const Element_pos coeff_for_common_prefix);
static float get_common_part(const Element_pos n, Element_pos coeff_for_common_prefix);
/*!
......@@ -117,6 +117,7 @@ public:
*/
static float get_variable_part(const Element_pos n, const Element_pos coeff_for_common_prefix, const int nb_digit_after_comma);
static std::string get_variable_part_string(const Element_pos n, const Element_pos coeff_for_common_prefix);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment