mirror of https://github.com/KLayout/klayout.git
Orientation cube, some refinement.
This commit is contained in:
parent
f954afab7a
commit
7884446da1
|
|
@ -61,6 +61,24 @@
|
|||
</property>
|
||||
<item>
|
||||
<widget class="QSlider" name="zoom_slider">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-300</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>300</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
|
|
@ -91,7 +109,7 @@
|
|||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public:
|
|||
|
||||
/**
|
||||
* @brief Gets the azimuth angle
|
||||
* ...
|
||||
* A positive angle means we look from the left. A negative means we look from the right.
|
||||
*/
|
||||
double cam_azimuth () const;
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ D25View::D25View (QWidget *parent)
|
|||
connect (mp_ui->fit_right, SIGNAL (clicked ()), this, SLOT (fit_button_clicked ()));
|
||||
connect (mp_ui->fit_top, SIGNAL (clicked ()), this, SLOT (fit_button_clicked ()));
|
||||
connect (mp_ui->fit_bottom, SIGNAL (clicked ()), this, SLOT (fit_button_clicked ()));
|
||||
connect (mp_ui->zoom_slider, SIGNAL (valueChanged (int)), this, SLOT (scale_slider_changed (int)));
|
||||
connect (mp_ui->d25_view, SIGNAL (scale_factor_changed (double)), this, SLOT (scale_factor_changed (double)));
|
||||
}
|
||||
|
||||
D25View::~D25View ()
|
||||
|
|
@ -58,6 +60,31 @@ D25View::~D25View ()
|
|||
mp_ui = 0;
|
||||
}
|
||||
|
||||
static QString scale_factor_to_string (double f)
|
||||
{
|
||||
QString s;
|
||||
s.sprintf ("x %.3g", f);
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
D25View::scale_slider_changed (int value)
|
||||
{
|
||||
double f = exp (log (10.0) * -0.01 * value);
|
||||
mp_ui->zoom_factor->setText (scale_factor_to_string (f));
|
||||
mp_ui->d25_view->set_scale_factor (f);
|
||||
}
|
||||
|
||||
void
|
||||
D25View::scale_factor_changed (double f)
|
||||
{
|
||||
mp_ui->zoom_factor->setText (scale_factor_to_string (f));
|
||||
int v = floor (0.5 - log10 (f) * 100.0);
|
||||
mp_ui->zoom_slider->blockSignals (true);
|
||||
mp_ui->zoom_slider->setValue (v);
|
||||
mp_ui->zoom_slider->blockSignals (false);
|
||||
}
|
||||
|
||||
int
|
||||
D25View::exec_dialog (lay::LayoutView *view)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ protected:
|
|||
|
||||
private slots:
|
||||
void fit_button_clicked ();
|
||||
void scale_factor_changed (double f);
|
||||
void scale_slider_changed (int value);
|
||||
|
||||
private:
|
||||
Ui::D25View *mp_ui;
|
||||
|
|
|
|||
|
|
@ -240,6 +240,8 @@ D25ViewWidget::wheelEvent (QWheelEvent *event)
|
|||
m_scale_factor *= f;
|
||||
m_displacement += hp * (1.0 - f) / m_scale_factor;
|
||||
|
||||
emit scale_factor_changed (m_scale_factor);
|
||||
|
||||
} else {
|
||||
|
||||
// compute vector of line of sight
|
||||
|
|
@ -248,16 +250,16 @@ D25ViewWidget::wheelEvent (QWheelEvent *event)
|
|||
// by definition the ray goes through the camera position
|
||||
QVector3D hp = hit_point_with_scene (ray.second);
|
||||
|
||||
if (event->modifiers () & Qt::ControlModifier) {
|
||||
if (! (event->modifiers () & Qt::ControlModifier)) {
|
||||
|
||||
// "Ctrl" is closeup
|
||||
// No Ctrl is closeup
|
||||
|
||||
double f = event->angleDelta ().y () * (1.0 / (90 * 8));
|
||||
m_displacement += -((f / m_scale_factor) * std::min (cam_dist (), double ((cam_position () - hp).length ()))) * ray.second;
|
||||
|
||||
} else {
|
||||
|
||||
// No shift is zoom
|
||||
// "Ctrl" is zoom
|
||||
|
||||
double f = exp (event->angleDelta ().y () * (1.0 / (90 * 8)));
|
||||
|
||||
|
|
@ -277,6 +279,8 @@ D25ViewWidget::wheelEvent (QWheelEvent *event)
|
|||
|
||||
m_displacement = ct.inverted ().map (displacement);
|
||||
|
||||
emit scale_factor_changed (m_scale_factor);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -382,6 +386,8 @@ D25ViewWidget::fit ()
|
|||
m_displacement = (new_center_in_scene - dim * 0.5) / m_scale_factor - bll;
|
||||
|
||||
refresh ();
|
||||
|
||||
emit scale_factor_changed (m_scale_factor);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -905,6 +911,117 @@ D25ViewWidget::paintGL ()
|
|||
|
||||
vertexes.draw_to (this, positions, GL_TRIANGLES);
|
||||
|
||||
// the orientation cube
|
||||
|
||||
if (! top_view ()) {
|
||||
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
|
||||
int cube_size = 64;
|
||||
int cube_margin = 20;
|
||||
|
||||
QMatrix4x4 into_top_right_corner;
|
||||
into_top_right_corner.translate (1.0 - 2.0 / width () * (cube_margin + cube_size / 2), 1.0 - 2.0 / height () * (cube_margin + cube_size / 2));
|
||||
// into_top_right_corner.translate (0.5, 0.5, 0.0);
|
||||
into_top_right_corner.scale (2.0 * cube_size / double (height ()), 2.0 * cube_size / double (height ()), 1.0);
|
||||
|
||||
m_gridplane_program->setUniformValue ("matrix", into_top_right_corner * cam_perspective () * cam_trans ());
|
||||
|
||||
vertexes.clear ();
|
||||
|
||||
vertexes.add (-1.0, -1.0, 1.0);
|
||||
vertexes.add (-1.0, -1.0, -1.0);
|
||||
|
||||
vertexes.add (-1.0, 1.0, 1.0);
|
||||
vertexes.add (-1.0, 1.0, -1.0);
|
||||
|
||||
vertexes.add (1.0, -1.0, 1.0);
|
||||
vertexes.add (1.0, -1.0, -1.0);
|
||||
|
||||
vertexes.add (1.0, 1.0, 1.0);
|
||||
vertexes.add (1.0, 1.0, -1.0);
|
||||
|
||||
vertexes.add (-1.0, -1.0, 1.0);
|
||||
vertexes.add (-1.0, 1.0, 1.0);
|
||||
|
||||
vertexes.add (1.0, -1.0, 1.0);
|
||||
vertexes.add (1.0, 1.0, 1.0);
|
||||
|
||||
vertexes.add (-1.0, -1.0, 1.0);
|
||||
vertexes.add (1.0, -1.0, 1.0);
|
||||
|
||||
vertexes.add (-1.0, 1.0, 1.0);
|
||||
vertexes.add (1.0, 1.0, 1.0);
|
||||
|
||||
vertexes.add (-1.0, -1.0, -1.0);
|
||||
vertexes.add (-1.0, 1.0, -1.0);
|
||||
|
||||
vertexes.add (1.0, -1.0, -1.0);
|
||||
vertexes.add (1.0, 1.0, -1.0);
|
||||
|
||||
vertexes.add (-1.0, -1.0, -1.0);
|
||||
vertexes.add (1.0, -1.0, -1.0);
|
||||
|
||||
vertexes.add (-1.0, 1.0, -1.0);
|
||||
vertexes.add (1.0, 1.0, -1.0);
|
||||
|
||||
m_gridplane_program->setUniformValue ("color", 1.0, 1.0, 1.0, 0.2f);
|
||||
|
||||
vertexes.draw_to (this, positions, GL_LINES);
|
||||
|
||||
vertexes.clear ();
|
||||
|
||||
// A "K" at the front
|
||||
vertexes.add (-0.8, -0.8, 1.0);
|
||||
vertexes.add (-0.8, 0.8, 1.0);
|
||||
vertexes.add (-0.2, 0.8, 1.0);
|
||||
|
||||
vertexes.add (-0.8, -0.8, 1.0);
|
||||
vertexes.add (-0.2, -0.8, 1.0);
|
||||
vertexes.add (-0.2, 0.8, 1.0);
|
||||
|
||||
vertexes.add (0.2, 0.8, 1.0);
|
||||
vertexes.add (0.8, 0.8, 1.0);
|
||||
vertexes.add (0.8, 0.6, 1.0);
|
||||
|
||||
vertexes.add (0.2, 0.8, 1.0);
|
||||
vertexes.add (0.8, 0.6, 1.0);
|
||||
vertexes.add (0.6, 0.4, 1.0);
|
||||
|
||||
vertexes.add (-0.2, 0.4, 1.0);
|
||||
vertexes.add (0.2, 0.8, 1.0);
|
||||
vertexes.add (0.6, 0.4, 1.0);
|
||||
|
||||
vertexes.add (-0.2, 0.4, 1.0);
|
||||
vertexes.add (0.6, 0.4, 1.0);
|
||||
vertexes.add (0.2, 0.0, 1.0);
|
||||
|
||||
vertexes.add (-0.2, 0.4, 1.0);
|
||||
vertexes.add (0.2, 0.0, 1.0);
|
||||
vertexes.add (-0.2, -0.4, 1.0);
|
||||
|
||||
vertexes.add (-0.2, -0.4, 1.0);
|
||||
vertexes.add (0.6, -0.4, 1.0);
|
||||
vertexes.add (0.2, -0.0, 1.0);
|
||||
|
||||
vertexes.add (-0.2, -0.4, 1.0);
|
||||
vertexes.add (0.2, -0.8, 1.0);
|
||||
vertexes.add (0.6, -0.4, 1.0);
|
||||
|
||||
vertexes.add (0.2, -0.8, 1.0);
|
||||
vertexes.add (0.8, -0.6, 1.0);
|
||||
vertexes.add (0.6, -0.4, 1.0);
|
||||
|
||||
vertexes.add (0.2, -0.8, 1.0);
|
||||
vertexes.add (0.8, -0.8, 1.0);
|
||||
vertexes.add (0.8, -0.6, 1.0);
|
||||
|
||||
m_gridplane_program->setUniformValue ("color", 1.0, 1.0, 1.0, 0.3f);
|
||||
|
||||
vertexes.draw_to (this, positions, GL_TRIANGLES);
|
||||
|
||||
}
|
||||
|
||||
glDisableVertexAttribArray (positions);
|
||||
|
||||
m_shapes_program->release ();
|
||||
|
|
|
|||
|
|
@ -104,6 +104,9 @@ public:
|
|||
refresh ();
|
||||
}
|
||||
|
||||
signals:
|
||||
void scale_factor_changed (double f);
|
||||
|
||||
protected:
|
||||
virtual void camera_changed ();
|
||||
virtual double aspect_ratio () const;
|
||||
|
|
@ -112,7 +115,7 @@ public slots:
|
|||
void fit ();
|
||||
|
||||
private:
|
||||
typedef lay::mem_chunks<GLfloat, 1024 * 9> chunks_type;
|
||||
typedef lay::mem_chunks<GLfloat, 1024 * 18> chunks_type;
|
||||
|
||||
std::auto_ptr<D25InteractionMode> mp_mode;
|
||||
QOpenGLShaderProgram *m_shapes_program, *m_gridplane_program;
|
||||
|
|
|
|||
Loading…
Reference in New Issue