////////////////////////////////// struc_window.cpp ////////////////////////////////////
#include "struc_window.h"
#include "ui_struc_window.h"
#include "struc_widget.h"
#include <iostream>
using namespace std;
struc_window
::struc_window(MatrixXd matrix,
QWidget *parent
) : ui(new Ui::struc_window)
{
ui->setupUi(this);
nodes = matrix;
//struc_widget *p = new struc_widget;
//connect(this,SIGNAL(mysignal()),p,SLOT(getsignal()));
}
struc_window::~struc_window()
{
delete ui;
}
////////////////////////////////// struc_window.cpp ////////////////////////////////////
#include "struc_window.h"
#include "ui_struc_window.h"
#include "struc_widget.h"
#include <iostream>
using namespace std;
struc_window::struc_window(MatrixXd matrix, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::struc_window)
{
ui->setupUi(this);
nodes = matrix;
//struc_widget *p = new struc_widget;
//connect(this,SIGNAL(mysignal()),p,SLOT(getsignal()));
}
struc_window::~struc_window()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
////////////////////////////////// struc_widget.h ////////////////////////////////////
#ifndef STRUC_WIDGET_H
#define STRUC_WIDGET_H
#include <QOpenGLWidget>
#include "struc_window.h"
#include "../../c++_fem/Eigen/Eigen/Dense"
using namespace Eigen;
class struc_widget : public QOpenGLWidget
{
Q_OBJECT
public:
explicit struc_widget
(QWidget *parent
= 0);
protected:
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
signals:
public slots:
//void getsignal();
private:
int xrot,yrot,zrot;
int h;
int b;
double norm_angle_x;
double norm_angle_y;
double norm_angle_z;
void setXRotation(int angle);
void setYRotation(int angle);
void setZRotation(int angle);
void normalize_angle_x(int angle);
void normalize_angle_y(int angle);
void normalize_angle_z(int angle);
void draw_structure();
MatrixXd node_matrix;
};
#endif // STRUC_WIDGET_H
////////////////////////////////// struc_widget.h ////////////////////////////////////
#ifndef STRUC_WIDGET_H
#define STRUC_WIDGET_H
#include <QOpenGLWidget>
#include "struc_window.h"
#include "../../c++_fem/Eigen/Eigen/Dense"
using namespace Eigen;
class struc_widget : public QOpenGLWidget
{
Q_OBJECT
public:
explicit struc_widget(QWidget *parent = 0);
protected:
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
signals:
public slots:
//void getsignal();
private:
QPoint lastPos;
int xrot,yrot,zrot;
int h;
int b;
double norm_angle_x;
double norm_angle_y;
double norm_angle_z;
void setXRotation(int angle);
void setYRotation(int angle);
void setZRotation(int angle);
void normalize_angle_x(int angle);
void normalize_angle_y(int angle);
void normalize_angle_z(int angle);
void draw_structure();
MatrixXd node_matrix;
};
#endif // STRUC_WIDGET_H
To copy to clipboard, switch view to plain text mode
////////////////////////////////// struc_widget.cpp ////////////////////////////////////
#include "struc_widget.h"
#include <QOpenGLWidget>
#include <QtOpenGL>
#include <QtWidgets>
#include <iostream>
using namespace std;
#include "struc_window.h"
struc_widget
::struc_widget(QWidget *parent
) : QOpenGLWidget
(parent
){
xrot = 0;
yrot = 0;
zrot = 0;
norm_angle_x = 0;
norm_angle_y = 0;
norm_angle_z = 0;
struc_window *struc_window_ptr = qobject_cast<struc_window*>(this->parent()); !!!!!!!!!!!!!!!!!!!!!!!!!!!! this is a zero pointer??????????????????
cout << struc_window_ptr << endl;
//struc_window_ptr->set_nodes();
//struc_window_ptr->set_nodes();
}
void struc_widget::initializeGL()
{
glClearColor(0.5,0.5,0.5,0.4);
}
void struc_widget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glLineWidth(2.5);
normalize_angle_x(xrot);
normalize_angle_y(yrot);
normalize_angle_z(zrot);
glRotatef(norm_angle_x,1,0,0);
glRotatef(norm_angle_y,0,1,0);
glRotatef(norm_angle_z,0,0,1);
glBegin(GL_TRIANGLES);
glColor3f(1,0,0);
glVertex3f(-1,-1,0);
glColor3f(0,1,0);
glVertex3f(1,-1,0);
glColor3f(0,0,1);
glVertex3f(0,1,0);
glEnd();
}
void struc_widget::resizeGL(int width, int height)
{
int side = qMin(width, height);
glViewport((width - side) / 2, (height - side) / 2, side, side);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
#ifdef QT_OPENGL_ES_1
glOrthof(-2, +2, -2, +2,-10, 10);
#else
glOrtho(-2, +2, -2, +2, -10, 10);
#endif
glMatrixMode(GL_MODELVIEW);
h = height;
b = width;
}
{
lastPos = event->pos();
}
{
int dx = event->x() - lastPos.x();
int dy = event->y() - lastPos.y();
if (event->buttons() & Qt::LeftButton)
{
setXRotation(xrot + dy);
}
else if (event->buttons() & Qt::RightButton)
{
setYRotation(yrot + dx);
}
else if (event->buttons() & Qt::MiddleButton)
{
setZRotation(zrot + dx);
}
lastPos = event->pos();
}
// x-rotation
void struc_widget::setXRotation(int angle)
{
if (angle != xrot) {
xrot = angle;
update();
}
}
// y-rotation
void struc_widget::setYRotation(int angle)
{
if (angle != yrot) {
yrot = angle;
update();
}
}
// z-rotation
void struc_widget::setZRotation(int angle)
{
if (angle != zrot) {
zrot = angle;
update();
}
}
// normalize angles
void struc_widget::normalize_angle_x(int angle)
{
norm_angle_x = 180.0 / h * angle;
}
void struc_widget::normalize_angle_y(int angle)
{
norm_angle_y = 180.0 / b * angle;
}
void struc_widget::normalize_angle_z(int angle)
{
norm_angle_z = 180.0 / b * angle;
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////// structural data /////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
void struc_widget::draw_structure()
{
}
///////////////////////////////////////////////////////
/// slot function
///////////////////////////////////////////////////////
//void struc_widget::getsignal(){
/////////////////////////////////////////////////////////// END OF THE CODE
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// struc_widget.cpp ////////////////////////////////////
#include "struc_widget.h"
#include <QOpenGLWidget>
#include <QtOpenGL>
#include <QtWidgets>
#include <iostream>
using namespace std;
#include "struc_window.h"
struc_widget::struc_widget(QWidget *parent) : QOpenGLWidget(parent)
{
xrot = 0;
yrot = 0;
zrot = 0;
norm_angle_x = 0;
norm_angle_y = 0;
norm_angle_z = 0;
struc_window *struc_window_ptr = qobject_cast<struc_window*>(this->parent()); !!!!!!!!!!!!!!!!!!!!!!!!!!!! this is a zero pointer??????????????????
cout << struc_window_ptr << endl;
//struc_window_ptr->set_nodes();
//struc_window_ptr->set_nodes();
}
void struc_widget::initializeGL()
{
glClearColor(0.5,0.5,0.5,0.4);
}
void struc_widget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glLineWidth(2.5);
normalize_angle_x(xrot);
normalize_angle_y(yrot);
normalize_angle_z(zrot);
glRotatef(norm_angle_x,1,0,0);
glRotatef(norm_angle_y,0,1,0);
glRotatef(norm_angle_z,0,0,1);
glBegin(GL_TRIANGLES);
glColor3f(1,0,0);
glVertex3f(-1,-1,0);
glColor3f(0,1,0);
glVertex3f(1,-1,0);
glColor3f(0,0,1);
glVertex3f(0,1,0);
glEnd();
}
void struc_widget::resizeGL(int width, int height)
{
int side = qMin(width, height);
glViewport((width - side) / 2, (height - side) / 2, side, side);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
#ifdef QT_OPENGL_ES_1
glOrthof(-2, +2, -2, +2,-10, 10);
#else
glOrtho(-2, +2, -2, +2, -10, 10);
#endif
glMatrixMode(GL_MODELVIEW);
h = height;
b = width;
}
void struc_widget::mousePressEvent(QMouseEvent *event)
{
lastPos = event->pos();
}
void struc_widget::mouseMoveEvent(QMouseEvent *event)
{
int dx = event->x() - lastPos.x();
int dy = event->y() - lastPos.y();
if (event->buttons() & Qt::LeftButton)
{
setXRotation(xrot + dy);
}
else if (event->buttons() & Qt::RightButton)
{
setYRotation(yrot + dx);
}
else if (event->buttons() & Qt::MiddleButton)
{
setZRotation(zrot + dx);
}
lastPos = event->pos();
}
// x-rotation
void struc_widget::setXRotation(int angle)
{
if (angle != xrot) {
xrot = angle;
update();
}
}
// y-rotation
void struc_widget::setYRotation(int angle)
{
if (angle != yrot) {
yrot = angle;
update();
}
}
// z-rotation
void struc_widget::setZRotation(int angle)
{
if (angle != zrot) {
zrot = angle;
update();
}
}
// normalize angles
void struc_widget::normalize_angle_x(int angle)
{
norm_angle_x = 180.0 / h * angle;
}
void struc_widget::normalize_angle_y(int angle)
{
norm_angle_y = 180.0 / b * angle;
}
void struc_widget::normalize_angle_z(int angle)
{
norm_angle_z = 180.0 / b * angle;
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////// structural data /////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
void struc_widget::draw_structure()
{
}
///////////////////////////////////////////////////////
/// slot function
///////////////////////////////////////////////////////
//void struc_widget::getsignal(){
/////////////////////////////////////////////////////////// END OF THE CODE
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
To copy to clipboard, switch view to plain text mode
I already tried to solve this problem by signal - slots also and I think I had a valid connection, but how to transfer the variable nodes then????????
Bookmarks