From cadca404854b71fef6cbad4308415a1f9fccd331 Mon Sep 17 00:00:00 2001 From: codereader Date: Mon, 19 Dec 2016 20:30:14 +0100 Subject: [PATCH] Migrate translateSelected code to algorithm namespace --- include/iselection.h | 2 -- radiant/map/Map.cpp | 3 +- radiant/selection/RadiantSelectionSystem.cpp | 31 ------------------- radiant/selection/RadiantSelectionSystem.h | 4 --- .../selection/algorithm/Transformation.cpp | 22 +++++++++++-- radiant/selection/algorithm/Transformation.h | 5 +++ radiant/selection/clipboard/Clipboard.cpp | 9 +++--- 7 files changed, 32 insertions(+), 44 deletions(-) diff --git a/include/iselection.h b/include/iselection.h index 2912059235..f057b7aa2b 100644 --- a/include/iselection.h +++ b/include/iselection.h @@ -253,8 +253,6 @@ class SelectionSystem : /// Signal emitted when the selection is changed virtual SelectionChangedSignal signal_selectionChanged() const = 0; - virtual void translateSelected(const Vector3& translation) = 0; - virtual const Matrix4& getPivot2World() = 0; virtual void pivotChanged() = 0; diff --git a/radiant/map/Map.cpp b/radiant/map/Map.cpp index 04bed4f597..9ebd7a21fb 100644 --- a/radiant/map/Map.cpp +++ b/radiant/map/Map.cpp @@ -46,6 +46,7 @@ #include "ui/prefabselector/PrefabSelector.h" #include "selection/algorithm/Primitives.h" #include "selection/algorithm/Group.h" +#include "selection/algorithm/Transformation.h" #include "selection/shaderclipboard/ShaderClipboard.h" #include "modulesystem/ModuleRegistry.h" #include "modulesystem/StaticModule.h" @@ -724,7 +725,7 @@ void Map::loadPrefabAt(const Vector3& targetCoords) GlobalBrush().setTextureLock(true); // Translate the selection to the given point - GlobalSelectionSystem().translateSelected(targetCoords); + selection::algorithm::translateSelected(targetCoords); // Revert to previous state GlobalBrush().setTextureLock(prevTexLockState); diff --git a/radiant/selection/RadiantSelectionSystem.cpp b/radiant/selection/RadiantSelectionSystem.cpp index b25fad45b4..617b2520ff 100644 --- a/radiant/selection/RadiantSelectionSystem.cpp +++ b/radiant/selection/RadiantSelectionSystem.cpp @@ -780,25 +780,6 @@ void RadiantSelectionSystem::onManipulationEnd() requestIdleCallback(); } -// Shortcut call for an instantly applied translation of the current selection -void RadiantSelectionSystem::translateSelected(const Vector3& translation) -{ - // Apply the transformation and freeze the changes - if (Mode() == eComponent) - { - Scene_Translate_Component_Selected(GlobalSceneGraph(), translation); - } - else - { - Scene_Translate_Selected(GlobalSceneGraph(), translation); - } - - // Update the scene so that the changes are made visible - SceneChangeNotify(); - - freezeTransforms(); -} - void RadiantSelectionSystem::renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const { renderSolid(collector, volume); @@ -828,18 +809,6 @@ void RadiantSelectionSystem::releaseShaders() RotateManipulator::_pivotPointShader.reset(); } -// This actually applies the transformation to the objects -void RadiantSelectionSystem::freezeTransforms() -{ - GlobalSceneGraph().foreachNode(scene::freezeTransformableNode); - - // The selection bounds have possibly changed, request an idle callback - _requestWorkZoneRecalculation = true; - _requestSceneGraphChange = true; - - requestIdleCallback(); -} - const WorkZone& RadiantSelectionSystem::getWorkZone() { // Flush any pending idle callbacks, we need the workzone now diff --git a/radiant/selection/RadiantSelectionSystem.h b/radiant/selection/RadiantSelectionSystem.h index 8f4c70bb22..3460ffe100 100644 --- a/radiant/selection/RadiantSelectionSystem.h +++ b/radiant/selection/RadiantSelectionSystem.h @@ -142,10 +142,6 @@ class RadiantSelectionSystem : void onManipulationChanged() override; void onManipulationEnd() override; - void translateSelected(const Vector3& translation); - - void freezeTransforms(); - const WorkZone& getWorkZone(); void renderSolid(RenderableCollector& collector, const VolumeTest& volume) const override; diff --git a/radiant/selection/algorithm/Transformation.cpp b/radiant/selection/algorithm/Transformation.cpp index 0eb463b725..c1a4ad7457 100644 --- a/radiant/selection/algorithm/Transformation.cpp +++ b/radiant/selection/algorithm/Transformation.cpp @@ -318,6 +318,24 @@ Vector3 AxisBase_axisForDirection(const AxisBase& axes, ENudgeDirection directio return Vector3(0, 0, 0); } +void translateSelected(const Vector3& translation) +{ + // Apply the transformation and freeze the changes + if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent) + { + Scene_Translate_Component_Selected(GlobalSceneGraph(), translation); + } + else + { + Scene_Translate_Selected(GlobalSceneGraph(), translation); + } + + // Update the scene so that the changes are made visible + SceneChangeNotify(); + + GlobalSceneGraph().foreachNode(scene::freezeTransformableNode); +} + // Specialised overload, called by the general nudgeSelected() routine void nudgeSelected(ENudgeDirection direction, float amount, EViewType viewtype) { @@ -330,7 +348,7 @@ void nudgeSelected(ENudgeDirection direction, float amount, EViewType viewtype) GlobalSelectionSystem().getActiveManipulatorType() == selection::Manipulator::Drag || GlobalSelectionSystem().getActiveManipulatorType() == selection::Manipulator::Clip) { - GlobalSelectionSystem().translateSelected(nudge); + translateSelected(nudge); // In clip mode, update the clipping plane if (GlobalSelectionSystem().getActiveManipulatorType() == selection::Manipulator::Clip) @@ -381,7 +399,7 @@ void nudgeByAxis(int nDim, float fNudge) Vector3 translate(0, 0, 0); translate[nDim] = fNudge; - GlobalSelectionSystem().translateSelected(translate); + translateSelected(translate); } void moveSelectedAlongZ(float amount) diff --git a/radiant/selection/algorithm/Transformation.h b/radiant/selection/algorithm/Transformation.h index a2c6d1013e..6318f534b7 100644 --- a/radiant/selection/algorithm/Transformation.h +++ b/radiant/selection/algorithm/Transformation.h @@ -47,6 +47,11 @@ void scaleSelected(const Vector3& scaleXYZ); */ void cloneSelected(const cmd::ArgumentList& args); +/** + * Moves the current selection by the given translation vector. + */ +void translateSelected(const Vector3& translation); + enum ENudgeDirection { eNudgeUp = 1, diff --git a/radiant/selection/clipboard/Clipboard.cpp b/radiant/selection/clipboard/Clipboard.cpp index 0b790e3921..92ca9495c2 100644 --- a/radiant/selection/clipboard/Clipboard.cpp +++ b/radiant/selection/clipboard/Clipboard.cpp @@ -8,6 +8,7 @@ #include "camera/GlobalCamera.h" #include "brush/FaceInstance.h" #include "selection/algorithm/General.h" +#include "selection/algorithm/Transformation.h" namespace selection { @@ -35,7 +36,7 @@ void copy(const cmd::ArgumentList& args) } else { - selection::algorithm::pickShaderFromSelection(args); + algorithm::pickShaderFromSelection(args); } } @@ -48,7 +49,7 @@ void paste(const cmd::ArgumentList& args) } else { - selection::algorithm::pasteShaderToSelection(args); + algorithm::pasteShaderToSelection(args); } } @@ -61,11 +62,11 @@ void pasteToCamera(const cmd::ArgumentList& args) pasteToMap(); // Work out the delta - Vector3 mid = selection::algorithm::getCurrentSelectionCenter(); + Vector3 mid = algorithm::getCurrentSelectionCenter(); Vector3 delta = camWnd->getCameraOrigin().getSnapped(GlobalGrid().getGridSize()) - mid; // Move to camera - GlobalSelectionSystem().translateSelected(delta); + algorithm::translateSelected(delta); } } // namespace