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"
53 select_workzone_t g_select_workzone;
57 Loops over all selected brushes and stores their
58 world AABBs in the specified array.
60 class CollectSelectedBrushesBounds : public SelectionSystem::Visitor
62 AABB* m_bounds; // array of AABBs
63 Unsigned m_max; // max AABB-elements in array
64 Unsigned& m_count;// count of valid AABBs stored in array
67 CollectSelectedBrushesBounds(AABB* bounds, Unsigned max, Unsigned& count)
75 void visit(scene::Instance& instance) const
77 ASSERT_MESSAGE(m_count <= m_max, "Invalid m_count in CollectSelectedBrushesBounds");
79 // stop if the array is already full
83 Selectable* selectable = Instance_getSelectable(instance);
85 && instance.isSelected())
88 if(Instance_getBrush(instance) != 0)
90 m_bounds[m_count] = instance.worldAABB();
98 Selects all objects that intersect one of the bounding AABBs.
99 The exact intersection-method is specified through TSelectionPolicy
101 template<class TSelectionPolicy>
102 class SelectByBounds : public scene::Graph::Walker
104 AABB* m_aabbs; // selection aabbs
105 Unsigned m_count; // number of aabbs in m_aabbs
106 TSelectionPolicy policy; // type that contains a custom intersection method aabb<->aabb
109 SelectByBounds(AABB* aabbs, Unsigned count)
115 bool pre(const scene::Path& path, scene::Instance& instance) const
117 Selectable* selectable = Instance_getSelectable(instance);
120 Entity* entity = Node_getEntity(path.top());
123 if(string_equal(entity->getKeyValue("classname"), "worldspawn"))
127 if( (path.size() > 1) &&
128 (!path.top().get().isRoot()) &&
132 for(Unsigned i = 0; i < m_count; ++i)
134 if(policy.Evaluate(m_aabbs[i], instance))
136 selectable->setSelected(true);
145 Performs selection operation on the global scenegraph.
146 If delete_bounds_src is true, then the objects which were
147 used as source for the selection aabbs will be deleted.
149 static void DoSelection(bool delete_bounds_src = true)
151 if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
153 // we may not need all AABBs since not all selected objects have to be brushes
154 const Unsigned max = (Unsigned)GlobalSelectionSystem().countSelected();
155 AABB* aabbs = new AABB[max];
158 CollectSelectedBrushesBounds collector(aabbs, max, count);
159 GlobalSelectionSystem().foreachSelected(collector);
161 // nothing usable in selection
168 // delete selected objects
169 if(delete_bounds_src)// see deleteSelection
171 UndoableCommand undo("deleteSelected");
175 // select objects with bounds
176 GlobalSceneGraph().traverse(SelectByBounds<TSelectionPolicy>(aabbs, count));
185 SelectionPolicy for SelectByBounds
186 Returns true if box and the AABB of instance intersect
188 class SelectionPolicy_Touching
191 bool Evaluate(const AABB& box, scene::Instance& instance) const
193 const AABB& other(instance.worldAABB());
194 for(Unsigned i = 0; i < 3; ++i)
196 if(fabsf(box.origin[i] - other.origin[i]) > (box.extents[i] + other.extents[i]))
204 SelectionPolicy for SelectByBounds
205 Returns true if the AABB of instance is inside box
207 class SelectionPolicy_Inside
210 bool Evaluate(const AABB& box, scene::Instance& instance) const
212 const AABB& other(instance.worldAABB());
213 for(Unsigned i = 0; i < 3; ++i)
215 if(fabsf(box.origin[i] - other.origin[i]) > (box.extents[i] - other.extents[i]))
222 class DeleteSelected : public scene::Graph::Walker
224 mutable bool m_remove;
225 mutable bool m_removedChild;
228 : m_remove(false), m_removedChild(false)
231 bool pre(const scene::Path& path, scene::Instance& instance) const
233 m_removedChild = false;
235 Selectable* selectable = Instance_getSelectable(instance);
237 && selectable->isSelected()
239 && !path.top().get().isRoot())
243 return false;// dont traverse into child elements
247 void post(const scene::Path& path, scene::Instance& instance) const
252 m_removedChild = false;
254 // delete empty entities
255 Entity* entity = Node_getEntity(path.top());
257 && path.top().get_pointer() != Map_FindWorldspawn(g_map)
258 && Node_getTraversable(path.top())->empty())
260 Path_deleteTop(path);
264 // node should be removed
267 if(Node_isEntity(path.parent()) != 0)
269 m_removedChild = true;
273 Path_deleteTop(path);
278 void Scene_DeleteSelected(scene::Graph& graph)
280 graph.traverse(DeleteSelected());
284 void Select_Delete (void)
286 Scene_DeleteSelected(GlobalSceneGraph());
289 class InvertSelectionWalker : public scene::Graph::Walker
291 SelectionSystem::EMode m_mode;
292 mutable Selectable* m_selectable;
294 InvertSelectionWalker(SelectionSystem::EMode mode)
295 : m_mode(mode), m_selectable(0)
298 bool pre(const scene::Path& path, scene::Instance& instance) const
300 Selectable* selectable = Instance_getSelectable(instance);
305 case SelectionSystem::eEntity:
306 if(Node_isEntity(path.top()) != 0)
308 m_selectable = path.top().get().visible() ? selectable : 0;
311 case SelectionSystem::ePrimitive:
312 m_selectable = path.top().get().visible() ? selectable : 0;
314 case SelectionSystem::eComponent:
320 void post(const scene::Path& path, scene::Instance& instance) const
322 if(m_selectable != 0)
324 m_selectable->setSelected(!m_selectable->isSelected());
330 void Scene_Invert_Selection(scene::Graph& graph)
332 graph.traverse(InvertSelectionWalker(GlobalSelectionSystem().Mode()));
337 Scene_Invert_Selection(GlobalSceneGraph());
340 class ExpandSelectionToEntitiesWalker : public scene::Graph::Walker
342 mutable std::size_t m_depth;
344 ExpandSelectionToEntitiesWalker() : m_depth(0)
347 bool pre(const scene::Path& path, scene::Instance& instance) const
350 if(m_depth == 2) // entity depth
352 // traverse and select children if any one is selected
353 return Node_getEntity(path.top())->isContainer() && instance.childSelected();
355 else if(m_depth == 3) // primitive depth
357 Instance_setSelected(instance, true);
362 void post(const scene::Path& path, scene::Instance& instance) const
368 void Scene_ExpandSelectionToEntities()
370 GlobalSceneGraph().traverse(ExpandSelectionToEntitiesWalker());
376 void Selection_UpdateWorkzone()
378 if(GlobalSelectionSystem().countSelected() != 0)
380 Select_GetBounds(g_select_workzone.d_work_min, g_select_workzone.d_work_max);
383 typedef FreeCaller<Selection_UpdateWorkzone> SelectionUpdateWorkzoneCaller;
385 IdleDraw g_idleWorkzone = IdleDraw(SelectionUpdateWorkzoneCaller());
388 const select_workzone_t& Select_getWorkZone()
390 g_idleWorkzone.flush();
391 return g_select_workzone;
394 void UpdateWorkzone_ForSelection()
396 g_idleWorkzone.queueDraw();
399 // update the workzone to the current selection
400 void UpdateWorkzone_ForSelectionChanged(const Selectable& selectable)
402 if(selectable.isSelected())
404 UpdateWorkzone_ForSelection();
408 void Select_SetShader(const char* shader)
410 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
412 Scene_BrushSetShader_Selected(GlobalSceneGraph(), shader);
413 Scene_PatchSetShader_Selected(GlobalSceneGraph(), shader);
415 Scene_BrushSetShader_Component_Selected(GlobalSceneGraph(), shader);
418 void Select_SetTexdef(const TextureProjection& projection)
420 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
422 Scene_BrushSetTexdef_Selected(GlobalSceneGraph(), projection);
424 Scene_BrushSetTexdef_Component_Selected(GlobalSceneGraph(), projection);
427 void Select_SetFlags(const ContentsFlagsValue& flags)
429 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
431 Scene_BrushSetFlags_Selected(GlobalSceneGraph(), flags);
433 Scene_BrushSetFlags_Component_Selected(GlobalSceneGraph(), flags);
436 void Select_GetBounds (Vector3& mins, Vector3& maxs)
439 Scene_BoundsSelected(GlobalSceneGraph(), bounds);
440 maxs = vector3_added(bounds.origin, bounds.extents);
441 mins = vector3_subtracted(bounds.origin, bounds.extents);
444 void Select_GetMid (Vector3& mid)
447 Scene_BoundsSelected(GlobalSceneGraph(), bounds);
448 mid = vector3_snapped(bounds.origin);
452 void Select_FlipAxis (int axis)
454 Vector3 flip(1, 1, 1);
456 GlobalSelectionSystem().scaleSelected(flip);
460 void Select_Scale(float x, float y, float z)
462 GlobalSelectionSystem().scaleSelected(Vector3(x, y, z));
478 inline Matrix4 matrix4_rotation_for_axis90(axis_t axis, sign_t sign)
483 if(sign == eSignPositive)
485 return matrix4_rotation_for_sincos_x(1, 0);
489 return matrix4_rotation_for_sincos_x(-1, 0);
492 if(sign == eSignPositive)
494 return matrix4_rotation_for_sincos_y(1, 0);
498 return matrix4_rotation_for_sincos_y(-1, 0);
500 default://case eAxisZ:
501 if(sign == eSignPositive)
503 return matrix4_rotation_for_sincos_z(1, 0);
507 return matrix4_rotation_for_sincos_z(-1, 0);
512 inline void matrix4_rotate_by_axis90(Matrix4& matrix, axis_t axis, sign_t sign)
514 matrix4_multiply_by_matrix4(matrix, matrix4_rotation_for_axis90(axis, sign));
517 inline void matrix4_pivoted_rotate_by_axis90(Matrix4& matrix, axis_t axis, sign_t sign, const Vector3& pivotpoint)
519 matrix4_translate_by_vec3(matrix, pivotpoint);
520 matrix4_rotate_by_axis90(matrix, axis, sign);
521 matrix4_translate_by_vec3(matrix, vector3_negated(pivotpoint));
524 inline Quaternion quaternion_for_axis90(axis_t axis, sign_t sign)
530 if(sign == eSignPositive)
532 return Quaternion(c_half_sqrt2f, 0, 0, c_half_sqrt2f);
536 return Quaternion(-c_half_sqrt2f, 0, 0, -c_half_sqrt2f);
539 if(sign == eSignPositive)
541 return Quaternion(0, c_half_sqrt2f, 0, c_half_sqrt2f);
545 return Quaternion(0, -c_half_sqrt2f, 0, -c_half_sqrt2f);
547 default://case eAxisZ:
548 if(sign == eSignPositive)
550 return Quaternion(0, 0, c_half_sqrt2f, c_half_sqrt2f);
554 return Quaternion(0, 0, -c_half_sqrt2f, -c_half_sqrt2f);
558 quaternion_for_matrix4_rotation(matrix4_rotation_for_axis90((axis_t)axis, (deg > 0) ? eSignPositive : eSignNegative));
562 void Select_RotateAxis (int axis, float deg)
564 if(fabs(deg) == 90.f)
566 GlobalSelectionSystem().rotateSelected(quaternion_for_axis90((axis_t)axis, (deg > 0) ? eSignPositive : eSignNegative));
573 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_x_degrees(deg)));
576 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_y_degrees(deg)));
579 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_z_degrees(deg)));
586 void Select_ShiftTexture(float x, float y)
588 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
590 Scene_BrushShiftTexdef_Selected(GlobalSceneGraph(), x, y);
591 Scene_PatchTranslateTexture_Selected(GlobalSceneGraph(), x, y);
593 //globalOutputStream() << "shift selected face textures: s=" << x << " t=" << y << '\n';
594 Scene_BrushShiftTexdef_Component_Selected(GlobalSceneGraph(), x, y);
597 void Select_ScaleTexture(float x, float y)
599 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
601 Scene_BrushScaleTexdef_Selected(GlobalSceneGraph(), x, y);
602 Scene_PatchScaleTexture_Selected(GlobalSceneGraph(), x, y);
604 Scene_BrushScaleTexdef_Component_Selected(GlobalSceneGraph(), x, y);
607 void Select_RotateTexture(float amt)
609 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
611 Scene_BrushRotateTexdef_Selected(GlobalSceneGraph(), amt);
612 Scene_PatchRotateTexture_Selected(GlobalSceneGraph(), amt);
614 Scene_BrushRotateTexdef_Component_Selected(GlobalSceneGraph(), amt);
617 // TTimo modified to handle shader architecture:
618 // expects shader names at input, comparison relies on shader names .. texture names no longer relevant
619 void FindReplaceTextures(const char* pFind, const char* pReplace, bool bSelected)
621 if(!texdef_name_valid(pFind))
623 globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pFind << "', aborted\n";
626 if(!texdef_name_valid(pReplace))
628 globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pReplace << "', aborted\n";
632 StringOutputStream command;
633 command << "textureFindReplace -find " << pFind << " -replace " << pReplace;
634 UndoableCommand undo(command.c_str());
638 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
640 Scene_BrushFindReplaceShader_Selected(GlobalSceneGraph(), pFind, pReplace);
641 Scene_PatchFindReplaceShader_Selected(GlobalSceneGraph(), pFind, pReplace);
643 Scene_BrushFindReplaceShader_Component_Selected(GlobalSceneGraph(), pFind, pReplace);
647 Scene_BrushFindReplaceShader(GlobalSceneGraph(), pFind, pReplace);
648 Scene_PatchFindReplaceShader(GlobalSceneGraph(), pFind, pReplace);
652 typedef std::vector<const char*> Classnames;
654 bool classnames_match_entity(const Classnames& classnames, Entity* entity)
656 for(Classnames::const_iterator i = classnames.begin(); i != classnames.end(); ++i)
658 if(string_equal(entity->getKeyValue("classname"), *i))
666 class EntityFindByClassnameWalker : public scene::Graph::Walker
668 const Classnames& m_classnames;
670 EntityFindByClassnameWalker(const Classnames& classnames)
671 : m_classnames(classnames)
674 bool pre(const scene::Path& path, scene::Instance& instance) const
676 Entity* entity = Node_getEntity(path.top());
678 && classnames_match_entity(m_classnames, entity))
680 Instance_getSelectable(instance)->setSelected(true);
686 void Scene_EntitySelectByClassnames(scene::Graph& graph, const Classnames& classnames)
688 graph.traverse(EntityFindByClassnameWalker(classnames));
691 class EntityGetSelectedClassnamesWalker : public scene::Graph::Walker
693 Classnames& m_classnames;
695 EntityGetSelectedClassnamesWalker(Classnames& classnames)
696 : m_classnames(classnames)
699 bool pre(const scene::Path& path, scene::Instance& instance) const
701 Selectable* selectable = Instance_getSelectable(instance);
703 && selectable->isSelected())
705 Entity* entity = Node_getEntity(path.top());
708 m_classnames.push_back(entity->getKeyValue("classname"));
715 void Scene_EntityGetClassnames(scene::Graph& graph, Classnames& classnames)
717 graph.traverse(EntityGetSelectedClassnamesWalker(classnames));
720 void Select_AllOfType()
722 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
724 if(GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace)
726 GlobalSelectionSystem().setSelectedAllComponents(false);
727 Scene_BrushSelectByShader_Component(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
732 Classnames classnames;
733 Scene_EntityGetClassnames(GlobalSceneGraph(), classnames);
734 GlobalSelectionSystem().setSelectedAll(false);
735 if(!classnames.empty())
737 Scene_EntitySelectByClassnames(GlobalSceneGraph(), classnames);
741 Scene_BrushSelectByShader(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
742 Scene_PatchSelectByShader(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
747 void Select_Inside(void)
749 SelectByBounds<SelectionPolicy_Inside>::DoSelection();
752 void Select_Touching(void)
754 SelectByBounds<SelectionPolicy_Touching>::DoSelection(false);
757 void Select_FitTexture(float horizontal, float vertical)
759 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
761 Scene_BrushFitTexture_Selected(GlobalSceneGraph(), horizontal, vertical);
763 Scene_BrushFitTexture_Component_Selected(GlobalSceneGraph(), horizontal, vertical);
768 inline void hide_node(scene::Node& node, bool hide)
771 ? node.enable(scene::Node::eHidden)
772 : node.disable(scene::Node::eHidden);
775 class HideSelectedWalker : public scene::Graph::Walker
779 HideSelectedWalker(bool hide)
783 bool pre(const scene::Path& path, scene::Instance& instance) const
785 Selectable* selectable = Instance_getSelectable(instance);
787 && selectable->isSelected())
789 hide_node(path.top(), m_hide);
795 void Scene_Hide_Selected(bool hide)
797 GlobalSceneGraph().traverse(HideSelectedWalker(hide));
802 Scene_Hide_Selected(true);
809 GlobalSelectionSystem().setSelectedAll(false);
813 class HideAllWalker : public scene::Graph::Walker
817 HideAllWalker(bool hide)
821 bool pre(const scene::Path& path, scene::Instance& instance) const
823 hide_node(path.top(), m_hide);
828 void Scene_Hide_All(bool hide)
830 GlobalSceneGraph().traverse(HideAllWalker(hide));
833 void Select_ShowAllHidden()
835 Scene_Hide_All(false);
841 void Selection_Flipx()
843 UndoableCommand undo("mirrorSelected -axis x");
847 void Selection_Flipy()
849 UndoableCommand undo("mirrorSelected -axis y");
853 void Selection_Flipz()
855 UndoableCommand undo("mirrorSelected -axis z");
859 void Selection_Rotatex()
861 UndoableCommand undo("rotateSelected -axis x -angle -90");
862 Select_RotateAxis(0,-90);
865 void Selection_Rotatey()
867 UndoableCommand undo("rotateSelected -axis y -angle 90");
868 Select_RotateAxis(1, 90);
871 void Selection_Rotatez()
873 UndoableCommand undo("rotateSelected -axis z -angle -90");
874 Select_RotateAxis(2,-90);
879 void Nudge(int nDim, float fNudge)
881 Vector3 translate(0, 0, 0);
882 translate[nDim] = fNudge;
884 GlobalSelectionSystem().translateSelected(translate);
887 void Selection_NudgeZ(float amount)
889 StringOutputStream command;
890 command << "nudgeSelected -axis z -amount " << amount;
891 UndoableCommand undo(command.c_str());
896 void Selection_MoveDown()
898 Selection_NudgeZ(-GetGridSize());
901 void Selection_MoveUp()
903 Selection_NudgeZ(GetGridSize());
906 void SceneSelectionChange(const Selectable& selectable)
911 SignalHandlerId Selection_boundsChanged;
913 void Selection_construct()
915 typedef FreeCaller1<const Selectable&, SceneSelectionChange> SceneSelectionChangeCaller;
916 GlobalSelectionSystem().addSelectionChangeCallback(SceneSelectionChangeCaller());
917 typedef FreeCaller1<const Selectable&, UpdateWorkzone_ForSelectionChanged> UpdateWorkzoneForSelectionChangedCaller;
918 GlobalSelectionSystem().addSelectionChangeCallback(UpdateWorkzoneForSelectionChangedCaller());
919 typedef FreeCaller<UpdateWorkzone_ForSelection> UpdateWorkzoneForSelectionCaller;
920 Selection_boundsChanged = GlobalSceneGraph().addBoundsChangedCallback(UpdateWorkzoneForSelectionCaller());
923 void Selection_destroy()
925 GlobalSceneGraph().removeBoundsChangedCallback(Selection_boundsChanged);
930 #include <gtk/gtkbox.h>
931 #include <gtk/gtkspinbutton.h>
932 #include <gtk/gtktable.h>
933 #include <gtk/gtklabel.h>
934 #include <gdk/gdkkeysyms.h>
937 inline Quaternion quaternion_for_euler_xyz_degrees(const Vector3& eulerXYZ)
940 return quaternion_for_matrix4_rotation(matrix4_rotation_for_euler_xyz_degrees(eulerXYZ));
942 return quaternion_multiplied_by_quaternion(
943 quaternion_multiplied_by_quaternion(
944 quaternion_for_z(degrees_to_radians(eulerXYZ[2])),
945 quaternion_for_y(degrees_to_radians(eulerXYZ[1]))
947 quaternion_for_x(degrees_to_radians(eulerXYZ[0]))
950 double cx = cos(degrees_to_radians(eulerXYZ[0] * 0.5));
951 double sx = sin(degrees_to_radians(eulerXYZ[0] * 0.5));
952 double cy = cos(degrees_to_radians(eulerXYZ[1] * 0.5));
953 double sy = sin(degrees_to_radians(eulerXYZ[1] * 0.5));
954 double cz = cos(degrees_to_radians(eulerXYZ[2] * 0.5));
955 double sz = sin(degrees_to_radians(eulerXYZ[2] * 0.5));
958 cz * cy * sx - sz * sy * cx,
959 cz * sy * cx + sz * cy * sx,
960 sz * cy * cx - cz * sy * sx,
961 cz * cy * cx + sz * sy * sx
973 static void rotatedlg_apply (GtkWidget *widget, RotateDialog* rotateDialog)
977 eulerXYZ[0] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->x));
978 gtk_spin_button_set_value(rotateDialog->x, 0.0f); // reset to 0 on Apply
980 eulerXYZ[1] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->y));
981 gtk_spin_button_set_value(rotateDialog->y, 0.0f);
983 eulerXYZ[2] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->z));
984 gtk_spin_button_set_value(rotateDialog->z, 0.0f);
986 StringOutputStream command;
987 command << "rotateSelectedEulerXYZ -x " << eulerXYZ[0] << " -y " << eulerXYZ[1] << " -z " << eulerXYZ[2];
988 UndoableCommand undo(command.c_str());
990 GlobalSelectionSystem().rotateSelected(quaternion_for_euler_xyz_degrees(eulerXYZ));
996 RotateDialog rotateDialog;
998 GtkWindow* window = create_dialog_window(MainFrame_getWindow(), "Arbitrary rotation", G_CALLBACK(dialog_delete_callback), &dialog);
1000 GtkAccelGroup* accel = gtk_accel_group_new();
1001 gtk_window_add_accel_group(window, accel);
1004 GtkHBox* hbox = create_dialog_hbox(4, 4);
1005 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(hbox));
1007 GtkTable* table = create_dialog_table(3, 2, 4, 4);
1008 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(table), TRUE, TRUE, 0);
1010 GtkWidget* label = gtk_label_new (" X ");
1011 gtk_widget_show (label);
1012 gtk_table_attach(table, label, 0, 1, 0, 1,
1013 (GtkAttachOptions) (0),
1014 (GtkAttachOptions) (0), 0, 0);
1017 GtkWidget* label = gtk_label_new (" Y ");
1018 gtk_widget_show (label);
1019 gtk_table_attach(table, label, 0, 1, 1, 2,
1020 (GtkAttachOptions) (0),
1021 (GtkAttachOptions) (0), 0, 0);
1024 GtkWidget* label = gtk_label_new (" Z ");
1025 gtk_widget_show (label);
1026 gtk_table_attach(table, label, 0, 1, 2, 3,
1027 (GtkAttachOptions) (0),
1028 (GtkAttachOptions) (0), 0, 0);
1031 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 10));
1032 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1033 gtk_widget_show(GTK_WIDGET(spin));
1034 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 0, 1,
1035 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1036 (GtkAttachOptions) (0), 0, 0);
1037 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1038 gtk_spin_button_set_wrap(spin, TRUE);
1040 gtk_widget_grab_focus(GTK_WIDGET(spin));
1042 rotateDialog.x = spin;
1045 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 10));
1046 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1047 gtk_widget_show(GTK_WIDGET(spin));
1048 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 1, 2,
1049 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1050 (GtkAttachOptions) (0), 0, 0);
1051 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1052 gtk_spin_button_set_wrap(spin, TRUE);
1054 rotateDialog.y = spin;
1057 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 10));
1058 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1059 gtk_widget_show(GTK_WIDGET(spin));
1060 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 2, 3,
1061 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1062 (GtkAttachOptions) (0), 0, 0);
1063 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1064 gtk_spin_button_set_wrap(spin, TRUE);
1066 rotateDialog.z = spin;
1070 GtkVBox* vbox = create_dialog_vbox(4);
1071 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
1073 GtkButton* button = create_dialog_button("OK", G_CALLBACK(dialog_button_ok), &dialog);
1074 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1075 widget_make_default(GTK_WIDGET(button));
1076 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
1079 GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(dialog_button_cancel), &dialog);
1080 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1081 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
1084 GtkButton* button = create_dialog_button("Apply", G_CALLBACK(rotatedlg_apply), &rotateDialog);
1085 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1090 if(modal_dialog_show(window, dialog) == eIDOK)
1092 rotatedlg_apply(0, &rotateDialog);
1095 gtk_widget_destroy(GTK_WIDGET(window));
1105 GtkWindow* window = create_dialog_window(MainFrame_getWindow(), "Scale", G_CALLBACK(dialog_delete_callback), &dialog);
1107 GtkAccelGroup* accel = gtk_accel_group_new();
1108 gtk_window_add_accel_group(window, accel);
1111 GtkHBox* hbox = create_dialog_hbox(4, 4);
1112 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(hbox));
1114 GtkTable* table = create_dialog_table(3, 2, 4, 4);
1115 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(table), TRUE, TRUE, 0);
1117 GtkWidget* label = gtk_label_new ("X:");
1118 gtk_widget_show (label);
1119 gtk_table_attach(table, label, 0, 1, 0, 1,
1120 (GtkAttachOptions) (GTK_FILL),
1121 (GtkAttachOptions) (0), 0, 0);
1122 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1125 GtkWidget* label = gtk_label_new ("Y:");
1126 gtk_widget_show (label);
1127 gtk_table_attach(table, label, 0, 1, 1, 2,
1128 (GtkAttachOptions) (GTK_FILL),
1129 (GtkAttachOptions) (0), 0, 0);
1130 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1133 GtkWidget* label = gtk_label_new ("Z:");
1134 gtk_widget_show (label);
1135 gtk_table_attach(table, label, 0, 1, 2, 3,
1136 (GtkAttachOptions) (GTK_FILL),
1137 (GtkAttachOptions) (0), 0, 0);
1138 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1141 GtkWidget* entry = gtk_entry_new();
1142 gtk_widget_show (entry);
1143 gtk_table_attach(table, entry, 1, 2, 0, 1,
1144 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1145 (GtkAttachOptions) (0), 0, 0);
1147 gtk_widget_grab_focus(entry);
1152 GtkWidget* entry = gtk_entry_new();
1153 gtk_widget_show (entry);
1154 gtk_table_attach(table, entry, 1, 2, 1, 2,
1155 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1156 (GtkAttachOptions) (0), 0, 0);
1161 GtkWidget* entry = gtk_entry_new();
1162 gtk_widget_show (entry);
1163 gtk_table_attach(table, entry, 1, 2, 2, 3,
1164 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1165 (GtkAttachOptions) (0), 0, 0);
1171 GtkVBox* vbox = create_dialog_vbox(4);
1172 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
1174 GtkButton* button = create_dialog_button("OK", G_CALLBACK(dialog_button_ok), &dialog);
1175 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1176 widget_make_default(GTK_WIDGET(button));
1177 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
1180 GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(dialog_button_cancel), &dialog);
1181 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1182 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
1187 // Initialize dialog
1188 gtk_entry_set_text (GTK_ENTRY (x), "1.0");
1189 gtk_entry_set_text (GTK_ENTRY (y), "1.0");
1190 gtk_entry_set_text (GTK_ENTRY (z), "1.0");
1192 if(modal_dialog_show(window, dialog) == eIDOK)
1195 sx = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (x))));
1196 sy = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (y))));
1197 sz = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (z))));
1199 if (sx > 0 && sy > 0 && sz > 0)
1201 StringOutputStream command;
1202 command << "scaleSelected -x " << sx << " -y " << sy << " -z " << sz;
1203 UndoableCommand undo(command.c_str());
1205 Select_Scale(sx, sy, sz);
1209 globalOutputStream() << "Warning.. Tried to scale by a zero value.";
1213 gtk_widget_destroy(GTK_WIDGET(window));