atomes 1.2.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
m_proj.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2025 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'm_proj.c'
24*
25* Contains:
26*
27
28 - The functions to create the 'View -> Projection' submenu
29
30*
31* List of functions:
32
33 G_MODULE_EXPORT void set_camera_pos (GtkWidget * widg, gpointer data);
34 G_MODULE_EXPORT void to_set_camera_pos (GSimpleAction * action, GVariant * parameter, gpointer data);
35
36 GtkWidget * menu_proj (glwin * view);
37
38 GMenu * menu_proj (glwin * view, int popm);
39
40*/
41
42#include "global.h"
43#include "glview.h"
44#include "glwindow.h"
45#include "preferences.h"
46
49 RIGHT = 0,
50 LEFT = 1,
51 TOP = 2,
52 BOTTOM = 3,
53 FRONT = 4,
54 BACK = 5
55};
56
57extern void camera_has_changed (gdouble value, gpointer data);
58
67G_MODULE_EXPORT void set_camera_pos (GtkWidget * widg, gpointer data)
68{
69 tint * id = (tint *)data;
70 double angle_x, angle_y;
71 switch (id -> b)
72 {
73 case RIGHT:
74 angle_x = 0.0;
75 angle_y = -90.0;
76 break;
77 case LEFT:
78 angle_x = 0.0;
79 angle_y = 90.0;
80 break;
81 case TOP:
82 angle_x = 90.0;
83 angle_y = 0.0;
84 break;
85 case BOTTOM:
86 angle_x = -90.0;
87 angle_y = 0.0;
88 break;
89 case FRONT:
90 angle_x = 0.0;
91 angle_y = 0.0;
92 break;
93 case BACK:
94 angle_x = 0.0;
95 angle_y = 180.0;
96 break;
97 }
98 if (preferences)
99 {
100 camera_has_changed (angle_x, & pref_pointer[3]);
101 camera_has_changed (angle_y, & pref_pointer[4]);
102 }
103 else
104 {
105 vec4_t q_a, q_b;
106 vec3_t axis;
107 axis.x = 0.0;
108 axis.y = 1.0;
109 axis.z = 0.0;
110 q_a = axis_to_quat (axis, -pi*angle_y/180.0);
111 axis.x = 1.0;
112 axis.y = 0.0;
113 axis.z = 0.0;
114 q_b = axis_to_quat (axis, -pi*angle_x/180.0);
115 glwin * view = get_project_by_id(id -> a) -> modelgl;
116 view -> anim -> last -> img -> rotation_quaternion = q4_mul (q_a, q_b);
117 update (view);
118 view -> anim -> last -> img -> c_angle[0] = - angle_x;
119 view -> anim -> last -> img -> c_angle[1] = - angle_y;
120 int i;
121 for (i=0; i<2; i++)
122 {
123 if (view -> rep_win)
124 {
125 if (view -> rep_win -> camera_widg[i+3] && GTK_IS_WIDGET(view -> rep_win -> camera_widg[i+3]))
126 {
127 gtk_spin_button_set_value ((GtkSpinButton *)view -> rep_win -> camera_widg[i+3], view -> anim -> last -> img -> c_angle[i]);
128 }
129 }
130 }
131 }
132}
133
134#ifdef GTK3
142GtkWidget * menu_proj (glwin * view)
143{
144 GtkWidget * menup = gtk_menu_new ();
145 GtkWidget * r = create_menu_item (FALSE, "Right [1, 0, 0]");
146 g_signal_connect (G_OBJECT (r), "activate", G_CALLBACK(set_camera_pos), & view -> colorp[RIGHT][0]);
147 gtk_menu_shell_append ((GtkMenuShell *)menup, r);
148 GtkWidget * l = create_menu_item (FALSE, "Left [-1, 0, 0]");
149 g_signal_connect (G_OBJECT (l), "activate", G_CALLBACK(set_camera_pos), & view -> colorp[LEFT][0]);
150 gtk_menu_shell_append ((GtkMenuShell *)menup, l);
151 GtkWidget * t = create_menu_item (FALSE, "Top [0, 1, 0]");
152 g_signal_connect (G_OBJECT (t), "activate", G_CALLBACK(set_camera_pos), & view -> colorp[TOP][0]);
153 gtk_menu_shell_append ((GtkMenuShell *)menup, t);
154 GtkWidget * b = create_menu_item (FALSE, "Bottom [0, -1, 0]");
155 g_signal_connect (G_OBJECT (b), "activate", G_CALLBACK(set_camera_pos), & view -> colorp[BOTTOM][0]);
156 gtk_menu_shell_append ((GtkMenuShell *)menup, b);
157 GtkWidget * f = create_menu_item (FALSE, "Front [0, 0, 1]");
158 g_signal_connect (G_OBJECT (f), "activate", G_CALLBACK(set_camera_pos), & view -> colorp[FRONT][0]);
159 gtk_menu_shell_append ((GtkMenuShell *)menup, f);
160 GtkWidget * a = create_menu_item (FALSE, "Back [0, 0, -1]");
161 g_signal_connect (G_OBJECT (a), "activate", G_CALLBACK(set_camera_pos), & view -> colorp[BACK][0]);
162 gtk_menu_shell_append ((GtkMenuShell *)menup, a);
163
164 return menup;
165}
166#else
176G_MODULE_EXPORT void to_set_camera_pos (GSimpleAction * action, GVariant * parameter, gpointer data)
177{
178 set_camera_pos (NULL, data);
179}
180
189GMenu * menu_proj (glwin * view, int popm)
190{
191 GMenu * menu = g_menu_new ();
192 gchar * projection[6]={"Right [1, 0, 0]", "Left [-1, 0, 0]", "Top [0, 1, 0]", "Bottom [0, -1, 0]", "Front [0, 0, 1]", "Back [0, 0, -1]"};
193 int i;
194 for (i=0; i<6; i++)
195 {
196 append_opengl_item (view, menu, projection[i], "proj", popm, i, NULL, IMG_NONE, NULL, FALSE, G_CALLBACK(to_set_camera_pos), & view -> colorp[i][0], FALSE, FALSE, FALSE, TRUE);
197 }
198 return menu;
199}
200#endif
color colorp[64]
double pi
Definition global.c:195
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_NONE
Definition global.h:262
GtkWidget * create_menu_item(gboolean add_mnemo, gchar *action)
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:450
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
action
Definition glview.h:198
struct axis axis
axis layout data structure
Definition glwin.h:331
Function declarations for the creation of the OpenGL window.
void append_opengl_item(glwin *view, GMenu *menu, const gchar *name, gchar *key, int mpop, int item_id, gchar *accel, int image_format, gpointer icon, gboolean custom, GCallback handler, gpointer data, gboolean check, gboolean status, gboolean radio, gboolean sensitive)
position
Definition m_proj.c:48
@ TOP
Definition m_proj.c:51
@ FRONT
Definition m_proj.c:53
@ BOTTOM
Definition m_proj.c:52
@ BACK
Definition m_proj.c:54
@ LEFT
Definition m_proj.c:50
@ RIGHT
Definition m_proj.c:49
void camera_has_changed(gdouble value, gpointer data)
update camera data
Definition m_rep.c:101
GMenu * menu_proj(glwin *view, int popm)
create the 'View -> Projection' submenu - GTK4
Definition m_proj.c:189
G_MODULE_EXPORT void set_camera_pos(GtkWidget *widg, gpointer data)
set camera position callback
Definition m_proj.c:67
G_MODULE_EXPORT void to_set_camera_pos(GSimpleAction *action, GVariant *parameter, gpointer data)
set camera position callback GTK4
Definition m_proj.c:176
tint * pref_pointer
gboolean preferences
Preference variable declarations.
Definition glwin.h:333
Definition glwin.h:965
Definition global.h:106
int b
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * img
Definition workspace.c:70