Skip to content

Commit

Permalink
#5231: Introduce command for scaling and rotating the current selecti…
Browse files Browse the repository at this point in the history
…on. Refactor TransformationDialog accordingly.
  • Loading branch information
codereader committed May 30, 2020
1 parent 520ff73 commit 4369d2e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
11 changes: 5 additions & 6 deletions radiant/ui/transform/TransformDialog.cpp
@@ -1,6 +1,7 @@
#include "TransformDialog.h"

#include "i18n.h"
#include "icommandsystem.h"
#include "iuimanager.h"
#include "imainframe.h"
#include "itextstream.h"
Expand All @@ -16,8 +17,6 @@
#include <wx/artprov.h>
#include <functional>

#include "selection/algorithm/Transformation.h"

namespace ui
{

Expand Down Expand Up @@ -271,7 +270,7 @@ void TransformDialog::onClickLarger(wxCommandEvent& ev, EntryRow* row)
eulerXYZ[row->axis] = step * row->direction;

// Pass the call to the algorithm functions
selection::algorithm::rotateSelected(eulerXYZ);
GlobalCommandSystem().executeCommand("RotateSelectedEulerXYZ", eulerXYZ);
}
else
{
Expand All @@ -282,7 +281,7 @@ void TransformDialog::onClickLarger(wxCommandEvent& ev, EntryRow* row)
scaleXYZ[row->axis] = step;

// Pass the call to the algorithm functions
selection::algorithm::scaleSelected(scaleXYZ);
GlobalCommandSystem().executeCommand("ScaleSelected", scaleXYZ);
}
}

Expand All @@ -301,7 +300,7 @@ void TransformDialog::onClickSmaller(wxCommandEvent& ev, EntryRow* row)
eulerXYZ[row->axis] = -step * row->direction;

// Pass the call to the algorithm functions
selection::algorithm::rotateSelected(eulerXYZ);
GlobalCommandSystem().executeCommand("RotateSelectedEulerXYZ", eulerXYZ);
}
else
{
Expand All @@ -312,7 +311,7 @@ void TransformDialog::onClickSmaller(wxCommandEvent& ev, EntryRow* row)
scaleXYZ[row->axis] = 1/step;

// Pass the call to the algorithm functions
selection::algorithm::scaleSelected(scaleXYZ);
GlobalCommandSystem().executeCommand("ScaleSelected", scaleXYZ);
}
}

Expand Down
5 changes: 4 additions & 1 deletion radiantcore/selection/RadiantSelectionSystem.cpp
Expand Up @@ -15,7 +15,7 @@
#include "ManipulateMouseTool.h"
#include "selection/algorithm/General.h"
#include "selection/algorithm/Primitives.h"
#include "xyview/GlobalXYWnd.h"
#include "selection/algorithm/Transformation.h"
#include "SceneWalkers.h"

#include "manipulators/DragManipulator.h"
Expand Down Expand Up @@ -914,6 +914,9 @@ void RadiantSelectionSystem::initialiseModule(const ApplicationContext& ctx)

GlobalCommandSystem().addCommand("UnSelectSelection", std::bind(&RadiantSelectionSystem::deselectCmd, this, std::placeholders::_1));

GlobalCommandSystem().addCommand("RotateSelectedEulerXYZ", selection::algorithm::rotateSelectedEulerXYZ, { cmd::ARGTYPE_VECTOR3 });
GlobalCommandSystem().addCommand("ScaleSelected", selection::algorithm::scaleSelected, { cmd::ARGTYPE_VECTOR3 });

IPreferencePage& page = GlobalPreferenceSystem().getPage(_("Settings/Selection"));

page.appendCheckBox(_("Ignore light volume bounds when calculating default rotation pivot location"),
Expand Down
29 changes: 25 additions & 4 deletions radiantcore/selection/algorithm/Transformation.cpp
Expand Up @@ -9,22 +9,21 @@
#include "iundo.h"
#include "imap.h"
#include "igrid.h"
#include "iorthoview.h"
#include "inamespace.h"
#include "iselection.h"
#include "imainframe.h"
#include "itextstream.h"
#include "iselectiongroup.h"

#include "scenelib.h"
#include "registry/registry.h"
#include "wxutil/dialog/MessageBox.h"
#include "xyview/GlobalXYWnd.h"
#include "map/algorithm/Clone.h"
#include "map/algorithm/Import.h"
#include "scene/BasicRootNode.h"
#include "debugging/debugging.h"
#include "selection/TransformationVisitors.h"
#include "selection/SceneWalkers.h"
#include "command/ExecutionFailure.h"

#include "string/case_conv.h"

Expand Down Expand Up @@ -70,6 +69,17 @@ void rotateSelected(const Vector3& eulerXYZ)
rotateSelected(Quaternion::createForEulerXYZDegrees(eulerXYZ));
}

void rotateSelectedEulerXYZ(const cmd::ArgumentList& args)
{
if (args.size() != 1)
{
rWarning() << "Usage: RotateSelectedEulerXYZ <eulerAngles:Vector3>" << std::endl;
return;
}

rotateSelected(args[0].getVector3());
}

// greebo: see header for documentation
void scaleSelected(const Vector3& scaleXYZ)
{
Expand Down Expand Up @@ -100,10 +110,21 @@ void scaleSelected(const Vector3& scaleXYZ)
}
else
{
wxutil::Messagebox::ShowError(_("Cannot scale by zero value."));
throw cmd::ExecutionFailure(_("Cannot scale by zero value."));
}
}

void scaleSelected(const cmd::ArgumentList& args)
{
if (args.size() != 1)
{
rWarning() << "Usage: ScaleSelected <scale:Vector3>" << std::endl;
return;
}

scaleSelected(args[0].getVector3());
}

/** greebo: A visitor class cloning the visited selected items.
*
* Use it like this:
Expand Down
10 changes: 10 additions & 0 deletions radiantcore/selection/algorithm/Transformation.h
Expand Up @@ -25,6 +25,11 @@ void rotateSelected(const Quaternion& rotation);
*/
void rotateSelected(const Vector3& eulerXYZ);

/**
* Command adapter for rotateSelected(Vector3)
*/
void rotateSelectedEulerXYZ(const cmd::ArgumentList& args);

/** greebo: Scales the current selection with the given vector.
* this emits an error if one of the vector's components
* are zero.
Expand All @@ -36,6 +41,11 @@ void rotateSelected(const Vector3& eulerXYZ);
*/
void scaleSelected(const Vector3& scaleXYZ);

/**
* Command adapter for scaleSelected(Vector3)
*/
void scaleSelected(const cmd::ArgumentList& args);

/**
* greebo: This duplicates the current selection (that's what happening
* when you hit the space bar).
Expand Down

0 comments on commit 4369d2e

Please sign in to comment.