2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "debugging/debugging.h"
27 #include "iselection.h"
32 #include "stream/stringstream.h"
33 #include "signal/isignal.h"
34 #include "shaderlib.h"
37 #include "gtkutil/idledraw.h"
38 #include "gtkutil/dialog.h"
39 #include "gtkutil/widget.h"
40 #include "brushmanip.h"
42 #include "patchmanip.h"
43 #include "patchdialog.h"
44 #include "selection.h"
45 #include "texwindow.h"
47 #include "mainframe.h"
50 #include "entityinspector.h"
54 select_workzone_t g_select_workzone;
58 Loops over all selected brushes and stores their
59 world AABBs in the specified array.
61 class CollectSelectedBrushesBounds : public SelectionSystem::Visitor
63 AABB* m_bounds; // array of AABBs
64 Unsigned m_max; // max AABB-elements in array
65 Unsigned& m_count;// count of valid AABBs stored in array
68 CollectSelectedBrushesBounds(AABB* bounds, Unsigned max, Unsigned& count)
76 void visit(scene::Instance& instance) const
78 ASSERT_MESSAGE(m_count <= m_max, "Invalid m_count in CollectSelectedBrushesBounds");
80 // stop if the array is already full
84 Selectable* selectable = Instance_getSelectable(instance);
86 && instance.isSelected())
89 if(Instance_getBrush(instance) != 0)
91 m_bounds[m_count] = instance.worldAABB();
99 Selects all objects that intersect one of the bounding AABBs.
100 The exact intersection-method is specified through TSelectionPolicy
102 template<class TSelectionPolicy>
103 class SelectByBounds : public scene::Graph::Walker
105 AABB* m_aabbs; // selection aabbs
106 Unsigned m_count; // number of aabbs in m_aabbs
107 TSelectionPolicy policy; // type that contains a custom intersection method aabb<->aabb
110 SelectByBounds(AABB* aabbs, Unsigned count)
116 bool pre(const scene::Path& path, scene::Instance& instance) const
118 Selectable* selectable = Instance_getSelectable(instance);
121 Entity* entity = Node_getEntity(path.top());
124 if(string_equal(entity->getKeyValue("classname"), "worldspawn"))
128 if( (path.size() > 1) &&
129 (!path.top().get().isRoot()) &&
133 for(Unsigned i = 0; i < m_count; ++i)
135 if(policy.Evaluate(m_aabbs[i], instance))
137 selectable->setSelected(true);
146 Performs selection operation on the global scenegraph.
147 If delete_bounds_src is true, then the objects which were
148 used as source for the selection aabbs will be deleted.
150 static void DoSelection(bool delete_bounds_src = true)
152 if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
154 // we may not need all AABBs since not all selected objects have to be brushes
155 const Unsigned max = (Unsigned)GlobalSelectionSystem().countSelected();
156 AABB* aabbs = new AABB[max];
159 CollectSelectedBrushesBounds collector(aabbs, max, count);
160 GlobalSelectionSystem().foreachSelected(collector);
162 // nothing usable in selection
169 // delete selected objects
170 if(delete_bounds_src)// see deleteSelection
172 UndoableCommand undo("deleteSelected");
176 // select objects with bounds
177 GlobalSceneGraph().traverse(SelectByBounds<TSelectionPolicy>(aabbs, count));
186 SelectionPolicy for SelectByBounds
187 Returns true if box and the AABB of instance intersect
189 class SelectionPolicy_Touching
192 bool Evaluate(const AABB& box, scene::Instance& instance) const
194 const AABB& other(instance.worldAABB());
195 for(Unsigned i = 0; i < 3; ++i)
197 if(fabsf(box.origin[i] - other.origin[i]) > (box.extents[i] + other.extents[i]))
205 SelectionPolicy for SelectByBounds
206 Returns true if the AABB of instance is inside box
208 class SelectionPolicy_Inside
211 bool Evaluate(const AABB& box, scene::Instance& instance) const
213 const AABB& other(instance.worldAABB());
214 for(Unsigned i = 0; i < 3; ++i)
216 if(fabsf(box.origin[i] - other.origin[i]) > (box.extents[i] - other.extents[i]))
223 class DeleteSelected : public scene::Graph::Walker
225 mutable bool m_remove;
226 mutable bool m_removedChild;
229 : m_remove(false), m_removedChild(false)
232 bool pre(const scene::Path& path, scene::Instance& instance) const
234 m_removedChild = false;
236 Selectable* selectable = Instance_getSelectable(instance);
238 && selectable->isSelected()
240 && !path.top().get().isRoot())
244 return false;// dont traverse into child elements
248 void post(const scene::Path& path, scene::Instance& instance) const
253 m_removedChild = false;
255 // delete empty entities
256 Entity* entity = Node_getEntity(path.top());
258 && path.top().get_pointer() != Map_FindWorldspawn(g_map)
259 && Node_getTraversable(path.top())->empty())
261 Path_deleteTop(path);
265 // node should be removed
268 if(Node_isEntity(path.parent()) != 0)
270 m_removedChild = true;
274 Path_deleteTop(path);
279 void Scene_DeleteSelected(scene::Graph& graph)
281 graph.traverse(DeleteSelected());
285 void Select_Delete (void)
287 Scene_DeleteSelected(GlobalSceneGraph());
290 class InvertSelectionWalker : public scene::Graph::Walker
292 SelectionSystem::EMode m_mode;
294 InvertSelectionWalker(SelectionSystem::EMode mode)
298 bool pre(const scene::Path& path, scene::Instance& instance) const
302 void post(const scene::Path& path, scene::Instance& instance) const
304 Selectable* selectable = Instance_getSelectable(instance);
309 case SelectionSystem::eEntity:
310 if(Node_isEntity(path.top()) != 0)
311 if(path.top().get().visible())
312 selectable->setSelected(!selectable->isSelected());
314 case SelectionSystem::ePrimitive:
315 if(path.top().get().visible())
316 selectable->setSelected(!selectable->isSelected());
318 case SelectionSystem::eComponent:
325 void Scene_Invert_Selection(scene::Graph& graph)
327 graph.traverse(InvertSelectionWalker(GlobalSelectionSystem().Mode()));
332 Scene_Invert_Selection(GlobalSceneGraph());
335 class ExpandSelectionToEntitiesWalker : public scene::Graph::Walker
337 mutable std::size_t m_depth;
338 NodeSmartReference worldspawn;
340 ExpandSelectionToEntitiesWalker() : m_depth(0), worldspawn(Map_FindOrInsertWorldspawn(g_map))
343 bool pre(const scene::Path& path, scene::Instance& instance) const
348 NodeSmartReference me(path.top().get());
352 if(m_depth == 2) // entity depth
354 // traverse and select children if any one is selected
355 if(instance.childSelected())
356 Instance_setSelected(instance, true);
357 return Node_getEntity(path.top())->isContainer() && instance.isSelected();
359 else if(m_depth == 3) // primitive depth
361 Instance_setSelected(instance, true);
366 void post(const scene::Path& path, scene::Instance& instance) const
372 void Scene_ExpandSelectionToEntities()
374 GlobalSceneGraph().traverse(ExpandSelectionToEntitiesWalker());
380 void Selection_UpdateWorkzone()
382 if(GlobalSelectionSystem().countSelected() != 0)
384 Select_GetBounds(g_select_workzone.d_work_min, g_select_workzone.d_work_max);
387 typedef FreeCaller<Selection_UpdateWorkzone> SelectionUpdateWorkzoneCaller;
389 IdleDraw g_idleWorkzone = IdleDraw(SelectionUpdateWorkzoneCaller());
392 const select_workzone_t& Select_getWorkZone()
394 g_idleWorkzone.flush();
395 return g_select_workzone;
398 void UpdateWorkzone_ForSelection()
400 g_idleWorkzone.queueDraw();
403 // update the workzone to the current selection
404 void UpdateWorkzone_ForSelectionChanged(const Selectable& selectable)
406 if(selectable.isSelected())
408 UpdateWorkzone_ForSelection();
412 void Select_SetShader(const char* shader)
414 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
416 Scene_BrushSetShader_Selected(GlobalSceneGraph(), shader);
417 Scene_PatchSetShader_Selected(GlobalSceneGraph(), shader);
419 Scene_BrushSetShader_Component_Selected(GlobalSceneGraph(), shader);
422 void Select_SetTexdef(const TextureProjection& projection)
424 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
426 Scene_BrushSetTexdef_Selected(GlobalSceneGraph(), projection);
428 Scene_BrushSetTexdef_Component_Selected(GlobalSceneGraph(), projection);
431 void Select_SetFlags(const ContentsFlagsValue& flags)
433 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
435 Scene_BrushSetFlags_Selected(GlobalSceneGraph(), flags);
437 Scene_BrushSetFlags_Component_Selected(GlobalSceneGraph(), flags);
440 void Select_GetBounds (Vector3& mins, Vector3& maxs)
443 Scene_BoundsSelected(GlobalSceneGraph(), bounds);
444 maxs = vector3_added(bounds.origin, bounds.extents);
445 mins = vector3_subtracted(bounds.origin, bounds.extents);
448 void Select_GetMid (Vector3& mid)
451 Scene_BoundsSelected(GlobalSceneGraph(), bounds);
452 mid = vector3_snapped(bounds.origin);
456 void Select_FlipAxis (int axis)
458 Vector3 flip(1, 1, 1);
460 GlobalSelectionSystem().scaleSelected(flip);
464 void Select_Scale(float x, float y, float z)
466 GlobalSelectionSystem().scaleSelected(Vector3(x, y, z));
482 inline Matrix4 matrix4_rotation_for_axis90(axis_t axis, sign_t sign)
487 if(sign == eSignPositive)
489 return matrix4_rotation_for_sincos_x(1, 0);
493 return matrix4_rotation_for_sincos_x(-1, 0);
496 if(sign == eSignPositive)
498 return matrix4_rotation_for_sincos_y(1, 0);
502 return matrix4_rotation_for_sincos_y(-1, 0);
504 default://case eAxisZ:
505 if(sign == eSignPositive)
507 return matrix4_rotation_for_sincos_z(1, 0);
511 return matrix4_rotation_for_sincos_z(-1, 0);
516 inline void matrix4_rotate_by_axis90(Matrix4& matrix, axis_t axis, sign_t sign)
518 matrix4_multiply_by_matrix4(matrix, matrix4_rotation_for_axis90(axis, sign));
521 inline void matrix4_pivoted_rotate_by_axis90(Matrix4& matrix, axis_t axis, sign_t sign, const Vector3& pivotpoint)
523 matrix4_translate_by_vec3(matrix, pivotpoint);
524 matrix4_rotate_by_axis90(matrix, axis, sign);
525 matrix4_translate_by_vec3(matrix, vector3_negated(pivotpoint));
528 inline Quaternion quaternion_for_axis90(axis_t axis, sign_t sign)
534 if(sign == eSignPositive)
536 return Quaternion(c_half_sqrt2f, 0, 0, c_half_sqrt2f);
540 return Quaternion(-c_half_sqrt2f, 0, 0, -c_half_sqrt2f);
543 if(sign == eSignPositive)
545 return Quaternion(0, c_half_sqrt2f, 0, c_half_sqrt2f);
549 return Quaternion(0, -c_half_sqrt2f, 0, -c_half_sqrt2f);
551 default://case eAxisZ:
552 if(sign == eSignPositive)
554 return Quaternion(0, 0, c_half_sqrt2f, c_half_sqrt2f);
558 return Quaternion(0, 0, -c_half_sqrt2f, -c_half_sqrt2f);
562 quaternion_for_matrix4_rotation(matrix4_rotation_for_axis90((axis_t)axis, (deg > 0) ? eSignPositive : eSignNegative));
566 void Select_RotateAxis (int axis, float deg)
568 if(fabs(deg) == 90.f)
570 GlobalSelectionSystem().rotateSelected(quaternion_for_axis90((axis_t)axis, (deg > 0) ? eSignPositive : eSignNegative));
577 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_x_degrees(deg)));
580 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_y_degrees(deg)));
583 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_z_degrees(deg)));
590 void Select_ShiftTexture(float x, float y)
592 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
594 Scene_BrushShiftTexdef_Selected(GlobalSceneGraph(), x, y);
595 Scene_PatchTranslateTexture_Selected(GlobalSceneGraph(), x, y);
597 //globalOutputStream() << "shift selected face textures: s=" << x << " t=" << y << '\n';
598 Scene_BrushShiftTexdef_Component_Selected(GlobalSceneGraph(), x, y);
601 void Select_ScaleTexture(float x, float y)
603 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
605 Scene_BrushScaleTexdef_Selected(GlobalSceneGraph(), x, y);
606 Scene_PatchScaleTexture_Selected(GlobalSceneGraph(), x, y);
608 Scene_BrushScaleTexdef_Component_Selected(GlobalSceneGraph(), x, y);
611 void Select_RotateTexture(float amt)
613 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
615 Scene_BrushRotateTexdef_Selected(GlobalSceneGraph(), amt);
616 Scene_PatchRotateTexture_Selected(GlobalSceneGraph(), amt);
618 Scene_BrushRotateTexdef_Component_Selected(GlobalSceneGraph(), amt);
621 // TTimo modified to handle shader architecture:
622 // expects shader names at input, comparison relies on shader names .. texture names no longer relevant
623 void FindReplaceTextures(const char* pFind, const char* pReplace, bool bSelected)
625 if(!texdef_name_valid(pFind))
627 globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pFind << "', aborted\n";
630 if(!texdef_name_valid(pReplace))
632 globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pReplace << "', aborted\n";
636 StringOutputStream command;
637 command << "textureFindReplace -find " << pFind << " -replace " << pReplace;
638 UndoableCommand undo(command.c_str());
642 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
644 Scene_BrushFindReplaceShader_Selected(GlobalSceneGraph(), pFind, pReplace);
645 Scene_PatchFindReplaceShader_Selected(GlobalSceneGraph(), pFind, pReplace);
647 Scene_BrushFindReplaceShader_Component_Selected(GlobalSceneGraph(), pFind, pReplace);
651 Scene_BrushFindReplaceShader(GlobalSceneGraph(), pFind, pReplace);
652 Scene_PatchFindReplaceShader(GlobalSceneGraph(), pFind, pReplace);
656 typedef std::vector<const char*> PropertyValues;
658 bool propertyvalues_contain(const PropertyValues& propertyvalues, const char *str)
660 for(PropertyValues::const_iterator i = propertyvalues.begin(); i != propertyvalues.end(); ++i)
662 if(string_equal(str, *i))
670 class EntityFindByPropertyValueWalker : public scene::Graph::Walker
672 const PropertyValues& m_propertyvalues;
675 EntityFindByPropertyValueWalker(const char *prop, const PropertyValues& propertyvalues)
676 : m_propertyvalues(propertyvalues), m_prop(prop)
679 bool pre(const scene::Path& path, scene::Instance& instance) const
681 Entity* entity = Node_getEntity(path.top());
683 && propertyvalues_contain(m_propertyvalues, entity->getKeyValue(m_prop)))
685 Instance_getSelectable(instance)->setSelected(true);
691 void Scene_EntitySelectByPropertyValues(scene::Graph& graph, const char *prop, const PropertyValues& propertyvalues)
693 graph.traverse(EntityFindByPropertyValueWalker(prop, propertyvalues));
696 class EntityGetSelectedPropertyValuesWalker : public scene::Graph::Walker
698 PropertyValues& m_propertyvalues;
701 EntityGetSelectedPropertyValuesWalker(const char *prop, PropertyValues& propertyvalues)
702 : m_propertyvalues(propertyvalues), m_prop(prop)
705 bool pre(const scene::Path& path, scene::Instance& instance) const
707 Selectable* selectable = Instance_getSelectable(instance);
709 && selectable->isSelected())
711 Entity* entity = Node_getEntity(path.top());
714 if(!propertyvalues_contain(m_propertyvalues, entity->getKeyValue(m_prop)))
715 m_propertyvalues.push_back(entity->getKeyValue(m_prop));
722 void Scene_EntityGetPropertyValues(scene::Graph& graph, const char *prop, PropertyValues& propertyvalues)
724 graph.traverse(EntityGetSelectedPropertyValuesWalker(prop, propertyvalues));
727 void Select_AllOfType()
729 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
731 if(GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace)
733 GlobalSelectionSystem().setSelectedAllComponents(false);
734 Scene_BrushSelectByShader_Component(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
739 PropertyValues propertyvalues;
740 const char *prop = EntityInspector_getCurrentKey();
743 Scene_EntityGetPropertyValues(GlobalSceneGraph(), prop, propertyvalues);
744 GlobalSelectionSystem().setSelectedAll(false);
745 if(!propertyvalues.empty())
747 Scene_EntitySelectByPropertyValues(GlobalSceneGraph(), prop, propertyvalues);
751 Scene_BrushSelectByShader(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
752 Scene_PatchSelectByShader(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
757 void Select_Inside(void)
759 SelectByBounds<SelectionPolicy_Inside>::DoSelection();
762 void Select_Touching(void)
764 SelectByBounds<SelectionPolicy_Touching>::DoSelection(false);
767 void Select_FitTexture(float horizontal, float vertical)
769 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
771 Scene_BrushFitTexture_Selected(GlobalSceneGraph(), horizontal, vertical);
773 Scene_BrushFitTexture_Component_Selected(GlobalSceneGraph(), horizontal, vertical);
778 inline void hide_node(scene::Node& node, bool hide)
781 ? node.enable(scene::Node::eHidden)
782 : node.disable(scene::Node::eHidden);
785 class HideSelectedWalker : public scene::Graph::Walker
789 HideSelectedWalker(bool hide)
793 bool pre(const scene::Path& path, scene::Instance& instance) const
795 Selectable* selectable = Instance_getSelectable(instance);
797 && selectable->isSelected())
799 hide_node(path.top(), m_hide);
805 void Scene_Hide_Selected(bool hide)
807 GlobalSceneGraph().traverse(HideSelectedWalker(hide));
812 Scene_Hide_Selected(true);
819 GlobalSelectionSystem().setSelectedAll(false);
823 class HideAllWalker : public scene::Graph::Walker
827 HideAllWalker(bool hide)
831 bool pre(const scene::Path& path, scene::Instance& instance) const
833 hide_node(path.top(), m_hide);
838 void Scene_Hide_All(bool hide)
840 GlobalSceneGraph().traverse(HideAllWalker(hide));
843 void Select_ShowAllHidden()
845 Scene_Hide_All(false);
851 void Selection_Flipx()
853 UndoableCommand undo("mirrorSelected -axis x");
857 void Selection_Flipy()
859 UndoableCommand undo("mirrorSelected -axis y");
863 void Selection_Flipz()
865 UndoableCommand undo("mirrorSelected -axis z");
869 void Selection_Rotatex()
871 UndoableCommand undo("rotateSelected -axis x -angle -90");
872 Select_RotateAxis(0,-90);
875 void Selection_Rotatey()
877 UndoableCommand undo("rotateSelected -axis y -angle 90");
878 Select_RotateAxis(1, 90);
881 void Selection_Rotatez()
883 UndoableCommand undo("rotateSelected -axis z -angle -90");
884 Select_RotateAxis(2,-90);
889 void Nudge(int nDim, float fNudge)
891 Vector3 translate(0, 0, 0);
892 translate[nDim] = fNudge;
894 GlobalSelectionSystem().translateSelected(translate);
897 void Selection_NudgeZ(float amount)
899 StringOutputStream command;
900 command << "nudgeSelected -axis z -amount " << amount;
901 UndoableCommand undo(command.c_str());
906 void Selection_MoveDown()
908 Selection_NudgeZ(-GetGridSize());
911 void Selection_MoveUp()
913 Selection_NudgeZ(GetGridSize());
916 void SceneSelectionChange(const Selectable& selectable)
921 SignalHandlerId Selection_boundsChanged;
923 void Selection_construct()
925 typedef FreeCaller1<const Selectable&, SceneSelectionChange> SceneSelectionChangeCaller;
926 GlobalSelectionSystem().addSelectionChangeCallback(SceneSelectionChangeCaller());
927 typedef FreeCaller1<const Selectable&, UpdateWorkzone_ForSelectionChanged> UpdateWorkzoneForSelectionChangedCaller;
928 GlobalSelectionSystem().addSelectionChangeCallback(UpdateWorkzoneForSelectionChangedCaller());
929 typedef FreeCaller<UpdateWorkzone_ForSelection> UpdateWorkzoneForSelectionCaller;
930 Selection_boundsChanged = GlobalSceneGraph().addBoundsChangedCallback(UpdateWorkzoneForSelectionCaller());
933 void Selection_destroy()
935 GlobalSceneGraph().removeBoundsChangedCallback(Selection_boundsChanged);
940 #include <gtk/gtkbox.h>
941 #include <gtk/gtkspinbutton.h>
942 #include <gtk/gtktable.h>
943 #include <gtk/gtklabel.h>
944 #include <gdk/gdkkeysyms.h>
947 inline Quaternion quaternion_for_euler_xyz_degrees(const Vector3& eulerXYZ)
950 return quaternion_for_matrix4_rotation(matrix4_rotation_for_euler_xyz_degrees(eulerXYZ));
952 return quaternion_multiplied_by_quaternion(
953 quaternion_multiplied_by_quaternion(
954 quaternion_for_z(degrees_to_radians(eulerXYZ[2])),
955 quaternion_for_y(degrees_to_radians(eulerXYZ[1]))
957 quaternion_for_x(degrees_to_radians(eulerXYZ[0]))
960 double cx = cos(degrees_to_radians(eulerXYZ[0] * 0.5));
961 double sx = sin(degrees_to_radians(eulerXYZ[0] * 0.5));
962 double cy = cos(degrees_to_radians(eulerXYZ[1] * 0.5));
963 double sy = sin(degrees_to_radians(eulerXYZ[1] * 0.5));
964 double cz = cos(degrees_to_radians(eulerXYZ[2] * 0.5));
965 double sz = sin(degrees_to_radians(eulerXYZ[2] * 0.5));
968 cz * cy * sx - sz * sy * cx,
969 cz * sy * cx + sz * cy * sx,
970 sz * cy * cx - cz * sy * sx,
971 cz * cy * cx + sz * sy * sx
984 static gboolean rotatedlg_apply (GtkWidget *widget, RotateDialog* rotateDialog)
988 eulerXYZ[0] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->x));
989 eulerXYZ[1] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->y));
990 eulerXYZ[2] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->z));
992 StringOutputStream command;
993 command << "rotateSelectedEulerXYZ -x " << eulerXYZ[0] << " -y " << eulerXYZ[1] << " -z " << eulerXYZ[2];
994 UndoableCommand undo(command.c_str());
996 GlobalSelectionSystem().rotateSelected(quaternion_for_euler_xyz_degrees(eulerXYZ));
1000 static gboolean rotatedlg_cancel (GtkWidget *widget, RotateDialog* rotateDialog)
1002 gtk_widget_hide(GTK_WIDGET(rotateDialog->window));
1004 gtk_spin_button_set_value(rotateDialog->x, 0.0f); // reset to 0 on close
1005 gtk_spin_button_set_value(rotateDialog->y, 0.0f);
1006 gtk_spin_button_set_value(rotateDialog->z, 0.0f);
1011 static gboolean rotatedlg_ok (GtkWidget *widget, RotateDialog* rotateDialog)
1013 rotatedlg_apply(widget, rotateDialog);
1014 rotatedlg_cancel(widget, rotateDialog);
1018 static gboolean rotatedlg_delete (GtkWidget *widget, GdkEventAny *event, RotateDialog* rotateDialog)
1020 rotatedlg_cancel(widget, rotateDialog);
1024 RotateDialog g_rotate_dialog;
1027 if(g_rotate_dialog.window == NULL)
1029 g_rotate_dialog.window = create_dialog_window(MainFrame_getWindow(), "Arbitrary rotation", G_CALLBACK(rotatedlg_delete), &g_rotate_dialog);
1031 GtkAccelGroup* accel = gtk_accel_group_new();
1032 gtk_window_add_accel_group(g_rotate_dialog.window, accel);
1035 GtkHBox* hbox = create_dialog_hbox(4, 4);
1036 gtk_container_add(GTK_CONTAINER(g_rotate_dialog.window), GTK_WIDGET(hbox));
1038 GtkTable* table = create_dialog_table(3, 2, 4, 4);
1039 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(table), TRUE, TRUE, 0);
1041 GtkWidget* label = gtk_label_new (" X ");
1042 gtk_widget_show (label);
1043 gtk_table_attach(table, label, 0, 1, 0, 1,
1044 (GtkAttachOptions) (0),
1045 (GtkAttachOptions) (0), 0, 0);
1048 GtkWidget* label = gtk_label_new (" Y ");
1049 gtk_widget_show (label);
1050 gtk_table_attach(table, label, 0, 1, 1, 2,
1051 (GtkAttachOptions) (0),
1052 (GtkAttachOptions) (0), 0, 0);
1055 GtkWidget* label = gtk_label_new (" Z ");
1056 gtk_widget_show (label);
1057 gtk_table_attach(table, label, 0, 1, 2, 3,
1058 (GtkAttachOptions) (0),
1059 (GtkAttachOptions) (0), 0, 0);
1062 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 0));
1063 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1064 gtk_widget_show(GTK_WIDGET(spin));
1065 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 0, 1,
1066 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1067 (GtkAttachOptions) (0), 0, 0);
1068 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1069 gtk_spin_button_set_wrap(spin, TRUE);
1071 gtk_widget_grab_focus(GTK_WIDGET(spin));
1073 g_rotate_dialog.x = spin;
1076 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 0));
1077 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1078 gtk_widget_show(GTK_WIDGET(spin));
1079 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 1, 2,
1080 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1081 (GtkAttachOptions) (0), 0, 0);
1082 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1083 gtk_spin_button_set_wrap(spin, TRUE);
1085 g_rotate_dialog.y = spin;
1088 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 0));
1089 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1090 gtk_widget_show(GTK_WIDGET(spin));
1091 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 2, 3,
1092 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1093 (GtkAttachOptions) (0), 0, 0);
1094 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1095 gtk_spin_button_set_wrap(spin, TRUE);
1097 g_rotate_dialog.z = spin;
1101 GtkVBox* vbox = create_dialog_vbox(4);
1102 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
1104 GtkButton* button = create_dialog_button("OK", G_CALLBACK(rotatedlg_ok), &g_rotate_dialog);
1105 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1106 widget_make_default(GTK_WIDGET(button));
1107 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
1110 GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(rotatedlg_cancel), &g_rotate_dialog);
1111 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1112 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
1115 GtkButton* button = create_dialog_button("Apply", G_CALLBACK(rotatedlg_apply), &g_rotate_dialog);
1116 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1122 gtk_widget_show(GTK_WIDGET(g_rotate_dialog.window));
1141 static gboolean scaledlg_apply (GtkWidget *widget, ScaleDialog* scaleDialog)
1145 sx = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (scaleDialog->x))));
1146 sy = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (scaleDialog->y))));
1147 sz = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (scaleDialog->z))));
1149 StringOutputStream command;
1150 command << "scaleSelected -x " << sx << " -y " << sy << " -z " << sz;
1151 UndoableCommand undo(command.c_str());
1153 Select_Scale(sx, sy, sz);
1158 static gboolean scaledlg_cancel (GtkWidget *widget, ScaleDialog* scaleDialog)
1160 gtk_widget_hide(GTK_WIDGET(scaleDialog->window));
1162 gtk_entry_set_text (GTK_ENTRY(scaleDialog->x), "1.0");
1163 gtk_entry_set_text (GTK_ENTRY(scaleDialog->y), "1.0");
1164 gtk_entry_set_text (GTK_ENTRY(scaleDialog->z), "1.0");
1169 static gboolean scaledlg_ok (GtkWidget *widget, ScaleDialog* scaleDialog)
1171 scaledlg_apply(widget, scaleDialog);
1172 scaledlg_cancel(widget, scaleDialog);
1176 static gboolean scaledlg_delete (GtkWidget *widget, GdkEventAny *event, ScaleDialog* scaleDialog)
1178 scaledlg_cancel(widget, scaleDialog);
1182 ScaleDialog g_scale_dialog;
1186 if(g_scale_dialog.window == NULL)
1188 g_scale_dialog.window = create_dialog_window(MainFrame_getWindow(), "Arbitrary scale", G_CALLBACK(scaledlg_delete), &g_scale_dialog);
1190 GtkAccelGroup* accel = gtk_accel_group_new();
1191 gtk_window_add_accel_group(g_scale_dialog.window, accel);
1194 GtkHBox* hbox = create_dialog_hbox(4, 4);
1195 gtk_container_add(GTK_CONTAINER(g_scale_dialog.window), GTK_WIDGET(hbox));
1197 GtkTable* table = create_dialog_table(3, 2, 4, 4);
1198 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(table), TRUE, TRUE, 0);
1200 GtkWidget* label = gtk_label_new (" X ");
1201 gtk_widget_show (label);
1202 gtk_table_attach(table, label, 0, 1, 0, 1,
1203 (GtkAttachOptions) (0),
1204 (GtkAttachOptions) (0), 0, 0);
1207 GtkWidget* label = gtk_label_new (" Y ");
1208 gtk_widget_show (label);
1209 gtk_table_attach(table, label, 0, 1, 1, 2,
1210 (GtkAttachOptions) (0),
1211 (GtkAttachOptions) (0), 0, 0);
1214 GtkWidget* label = gtk_label_new (" Z ");
1215 gtk_widget_show (label);
1216 gtk_table_attach(table, label, 0, 1, 2, 3,
1217 (GtkAttachOptions) (0),
1218 (GtkAttachOptions) (0), 0, 0);
1221 GtkWidget* entry = gtk_entry_new();
1222 gtk_entry_set_text (GTK_ENTRY(entry), "1.0");
1223 gtk_widget_show (entry);
1224 gtk_table_attach(table, entry, 1, 2, 0, 1,
1225 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1226 (GtkAttachOptions) (0), 0, 0);
1228 g_scale_dialog.x = entry;
1231 GtkWidget* entry = gtk_entry_new();
1232 gtk_entry_set_text (GTK_ENTRY(entry), "1.0");
1233 gtk_widget_show (entry);
1234 gtk_table_attach(table, entry, 1, 2, 1, 2,
1235 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1236 (GtkAttachOptions) (0), 0, 0);
1238 g_scale_dialog.y = entry;
1241 GtkWidget* entry = gtk_entry_new();
1242 gtk_entry_set_text (GTK_ENTRY(entry), "1.0");
1243 gtk_widget_show (entry);
1244 gtk_table_attach(table, entry, 1, 2, 2, 3,
1245 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1246 (GtkAttachOptions) (0), 0, 0);
1248 g_scale_dialog.z = entry;
1252 GtkVBox* vbox = create_dialog_vbox(4);
1253 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
1255 GtkButton* button = create_dialog_button("OK", G_CALLBACK(scaledlg_ok), &g_scale_dialog);
1256 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1257 widget_make_default(GTK_WIDGET(button));
1258 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
1261 GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(scaledlg_cancel), &g_scale_dialog);
1262 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1263 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
1266 GtkButton* button = create_dialog_button("Apply", G_CALLBACK(scaledlg_apply), &g_scale_dialog);
1267 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1273 gtk_widget_show(GTK_WIDGET(g_scale_dialog.window));