Skip to content

Commit

Permalink
#5231: Migrate Curve algorithm to throw exceptions instead of display…
Browse files Browse the repository at this point in the history
…ing Messageboxes
  • Loading branch information
codereader committed May 28, 2020
1 parent 1974572 commit cfa774f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 63 deletions.
3 changes: 3 additions & 0 deletions include/iorthoview.h
Expand Up @@ -67,6 +67,9 @@ class IXWndManager :
// Sets the origin of all available views
virtual void setOrigin(const Vector3& origin) = 0;

// Returns the origin of the currently active ortho view
virtual Vector3 getActiveViewOrigin() = 0;

// Sets the scale of all available views
virtual void setScale(float scale) = 0;

Expand Down
10 changes: 10 additions & 0 deletions radiant/xyview/GlobalXYWnd.cpp
Expand Up @@ -315,6 +315,16 @@ void XYWndManager::setOrigin(const Vector3& origin) {
}
}

Vector3 XYWndManager::getActiveViewOrigin()
{
if (!_activeXY)
{
return Vector3(0, 0, 0);
}

return _activeXY->getOrigin();
}

void XYWndManager::setScale(float scale) {
for (XYWndMap::iterator i = _xyWnds.begin();
i != _xyWnds.end();
Expand Down
1 change: 1 addition & 0 deletions radiant/xyview/GlobalXYWnd.h
Expand Up @@ -104,6 +104,7 @@ class XYWndManager :

// Sets the origin of all available views
void setOrigin(const Vector3& origin) override;
Vector3 getActiveViewOrigin() override;

// Sets the scale of all available views
void setScale(float scale) override;
Expand Down
128 changes: 65 additions & 63 deletions radiantcore/selection/algorithm/Curves.cpp
Expand Up @@ -7,12 +7,12 @@
#include "imainframe.h"
#include "itransformable.h"
#include "ientity.h"
#include "iorthoview.h"

#include "scenelib.h"
#include "wxutil/dialog/MessageBox.h"
#include "selectionlib.h"
#include "gamelib.h"
#include "xyview/GlobalXYWnd.h"
#include "command/ExecutionNotPossible.h"

namespace selection
{
Expand Down Expand Up @@ -75,7 +75,7 @@ void createCurve(const std::string& key)
ITransformablePtr transformable = Node_getTransformable(curve);
if (transformable != NULL) {
// Translate the entity to the center of the current workzone
transformable->setTranslation(GlobalXYWnd().getActiveXY()->getOrigin());
transformable->setTranslation(GlobalXYWndManager().getActiveViewOrigin());
transformable->freezeTransform();
}
}
Expand Down Expand Up @@ -169,106 +169,108 @@ class SelectedCurveVisitor :
}
};

void appendCurveControlPoint(const cmd::ArgumentList& args) {
void appendCurveControlPoint(const cmd::ArgumentList& args)
{
const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();

if (info.entityCount > 0) {
UndoableCommand command("curveAppendControlPoint");

// The functor object
CurveControlPointAppender appender;

// Traverse the selection applying the functor
GlobalSelectionSystem().foreachSelected(
SelectedCurveVisitor(appender)
);
}
else {
wxutil::Messagebox::ShowError(
if (info.entityCount == 0)
{
throw cmd::ExecutionNotPossible(
_("Can't append curve point - no entities with curve selected.")
);
}

UndoableCommand command("curveAppendControlPoint");

// The functor object
CurveControlPointAppender appender;

// Traverse the selection applying the functor
GlobalSelectionSystem().foreachSelected(
SelectedCurveVisitor(appender)
);
}

void removeCurveControlPoints(const cmd::ArgumentList& args) {
void removeCurveControlPoints(const cmd::ArgumentList& args)
{
if (GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ||
GlobalSelectionSystem().ComponentMode() != SelectionSystem::eVertex)
{
wxutil::Messagebox::ShowError(
throw cmd::ExecutionNotPossible(
_("Can't remove curve points - must be in vertex editing mode.")
);
return;
}

const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();

if (info.entityCount > 0) {
UndoableCommand command("curveRemoveControlPoints");

// The functor object
CurveControlPointRemover remover;

// Traverse the selection applying the functor
GlobalSelectionSystem().foreachSelected(
SelectedCurveVisitor(remover)
);
}
else {
wxutil::Messagebox::ShowError(
if (info.entityCount == 0)
{
throw cmd::ExecutionNotPossible(
_("Can't remove curve points - no entities with curves selected.")
);
}

UndoableCommand command("curveRemoveControlPoints");

// The functor object
CurveControlPointRemover remover;

// Traverse the selection applying the functor
GlobalSelectionSystem().foreachSelected(
SelectedCurveVisitor(remover)
);
}

void insertCurveControlPoints(const cmd::ArgumentList& args) {
void insertCurveControlPoints(const cmd::ArgumentList& args)
{
if (GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ||
GlobalSelectionSystem().ComponentMode() != SelectionSystem::eVertex)
{
wxutil::Messagebox::ShowError(
throw cmd::ExecutionNotPossible(
_("Can't insert curve points - must be in vertex editing mode.")
);
return;
}

const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();

if (info.entityCount > 0) {
UndoableCommand command("curveInsertControlPoints");

// The functor object
CurveControlPointInserter inserter;

// Traverse the selection applying the functor
GlobalSelectionSystem().foreachSelected(
SelectedCurveVisitor(inserter)
);
}
else {
wxutil::Messagebox::ShowError(
if (info.entityCount == 0)
{
throw cmd::ExecutionNotPossible(
_("Can't insert curve points - no entities with curves selected.")
);
}
}

UndoableCommand command("curveInsertControlPoints");

void convertCurveTypes(const cmd::ArgumentList& args) {
const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();
// The functor object
CurveControlPointInserter inserter;

if (info.entityCount > 0) {
UndoableCommand command("curveConvertType");
// Traverse the selection applying the functor
GlobalSelectionSystem().foreachSelected(
SelectedCurveVisitor(inserter)
);
}

// The functor object
CurveConverter converter;
void convertCurveTypes(const cmd::ArgumentList& args)
{
const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();

// Traverse the selection applying the functor
GlobalSelectionSystem().foreachSelected(
SelectedCurveVisitor(converter)
);
}
else {
wxutil::Messagebox::ShowError(
if (info.entityCount == 0)
{
throw cmd::ExecutionNotPossible(
_("Can't convert curves - no entities with curves selected.")
);
}

UndoableCommand command("curveConvertType");

// The functor object
CurveConverter converter;

// Traverse the selection applying the functor
GlobalSelectionSystem().foreachSelected(
SelectedCurveVisitor(converter)
);
}

} // namespace algorithm
Expand Down

0 comments on commit cfa774f

Please sign in to comment.