Skip to content

Commit

Permalink
Migrate translateSelected code to algorithm namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 19, 2016
1 parent 4454ec6 commit cadca40
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 44 deletions.
2 changes: 0 additions & 2 deletions include/iselection.h
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion radiant/map/Map.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
31 changes: 0 additions & 31 deletions radiant/selection/RadiantSelectionSystem.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions radiant/selection/RadiantSelectionSystem.h
Expand Up @@ -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;
Expand Down
22 changes: 20 additions & 2 deletions radiant/selection/algorithm/Transformation.cpp
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions radiant/selection/algorithm/Transformation.h
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions radiant/selection/clipboard/Clipboard.cpp
Expand Up @@ -8,6 +8,7 @@
#include "camera/GlobalCamera.h"
#include "brush/FaceInstance.h"
#include "selection/algorithm/General.h"
#include "selection/algorithm/Transformation.h"

namespace selection
{
Expand Down Expand Up @@ -35,7 +36,7 @@ void copy(const cmd::ArgumentList& args)
}
else
{
selection::algorithm::pickShaderFromSelection(args);
algorithm::pickShaderFromSelection(args);
}
}

Expand All @@ -48,7 +49,7 @@ void paste(const cmd::ArgumentList& args)
}
else
{
selection::algorithm::pasteShaderToSelection(args);
algorithm::pasteShaderToSelection(args);
}
}

Expand All @@ -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
Expand Down

0 comments on commit cadca40

Please sign in to comment.