Skip to content

Commit

Permalink
#5231: Remove UI references from a few algorithm files
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 29, 2020
1 parent cfa774f commit 0589d2c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 60 deletions.
8 changes: 8 additions & 0 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -289,6 +289,14 @@ void UserInterfaceModule::registerUICommands()
GlobalCommandSystem().addCommand("PatchCapDialog", PatchCapDialog::Show);
GlobalCommandSystem().addCommand("ThickenPatchDialog", PatchThickenDialog::Show);
GlobalCommandSystem().addCommand("CreateSimplePatchDialog", PatchCreateDialog::Show);

// Set up the CloneSelection command to react on key up events only
GlobalEventManager().addCommand("CloneSelection", "CloneSelection", true); // react on keyUp

GlobalEventManager().addRegistryToggle("ToggleRotationPivot", "user/ui/rotationPivotIsOrigin");
GlobalEventManager().addRegistryToggle("ToggleSnapRotationPivot", "user/ui/snapRotationPivotToGrid");
GlobalEventManager().addRegistryToggle("ToggleOffsetClones", "user/ui/offsetClonedObjects");
GlobalEventManager().addRegistryToggle("ToggleFreeObjectRotation", RKEY_FREE_OBJECT_ROTATION);
}

void UserInterfaceModule::HandleTextureChanged(radiant::TextureChangedMessage& msg)
Expand Down
3 changes: 2 additions & 1 deletion radiant/ui/einspector/ClassnamePropertyEditor.cpp
Expand Up @@ -11,6 +11,7 @@
#include "wxutil/dialog/MessageBox.h"

#include "selection/algorithm/Entity.h"
#include "command/ExecutionFailure.h"
#include "ui/entitychooser/EntityClassChooser.h"

namespace ui
Expand Down Expand Up @@ -44,7 +45,7 @@ void ClassnamePropertyEditor::onBrowseButtonClick()
// Apply the classname change to the entity, this requires some algorithm
selection::algorithm::setEntityClassname(selection);
}
catch (std::runtime_error& ex)
catch (cmd::ExecutionFailure & ex)
{
wxutil::Messagebox::ShowError(ex.what());
}
Expand Down
41 changes: 21 additions & 20 deletions radiantcore/selection/algorithm/Entity.cpp
Expand Up @@ -9,12 +9,12 @@
#include "itextstream.h"
#include "entitylib.h"
#include "gamelib.h"
#include "wxutil/dialog/MessageBox.h"
#include "command/ExecutionFailure.h"
#include "command/ExecutionNotPossible.h"

#include "selection/algorithm/General.h"
#include "selection/algorithm/Shader.h"
#include "selection/algorithm/Group.h"
#include "map/Map.h"
#include "eclass.h"

namespace selection
Expand Down Expand Up @@ -104,12 +104,12 @@ void setEntityClassname(const std::string& classname)
{
if (classname.empty())
{
throw std::runtime_error(_("Cannot set classname to an empty string."));
throw cmd::ExecutionFailure(_("Cannot set classname to an empty string."));
}

if (classname == "worldspawn")
{
throw std::runtime_error(_("Cannot change classname to worldspawn."));
throw cmd::ExecutionFailure(_("Cannot change classname to worldspawn."));
}

std::set<scene::INodePtr> entitiesToProcess;
Expand All @@ -128,7 +128,7 @@ void setEntityClassname(const std::string& classname)
}
else
{
throw std::runtime_error(_("Cannot change classname of worldspawn entity."));
throw cmd::ExecutionFailure(_("Cannot change classname of worldspawn entity."));
}
}
});
Expand All @@ -143,16 +143,19 @@ void setEntityClassname(const std::string& classname)
}
}

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

if (info.totalCount == 2 && info.entityCount == 2) {
if (info.totalCount == 2 && info.entityCount == 2)
{
UndoableCommand command("bindEntities");

Entity* first = Node_getEntity(GlobalSelectionSystem().ultimateSelected());
Entity* second = Node_getEntity(GlobalSelectionSystem().penultimateSelected());

if (first != NULL && second != NULL) {
if (first != NULL && second != NULL)
{
// Get the bind key
std::string bindKey = game::current::getValue<std::string>(GKEY_BIND_KEY);

Expand All @@ -164,13 +167,14 @@ void bindEntities(const cmd::ArgumentList& args) {
// Set the spawnarg
second->setKeyValue(bindKey, first->getKeyValue("name"));
}
else {
wxutil::Messagebox::ShowError(
_("Critical: Cannot find selected entities."));
else
{
throw cmd::ExecutionFailure(_("Critical: Cannot find selected entities."));
}
}
else {
wxutil::Messagebox::ShowError(
else
{
throw cmd::ExecutionNotPossible(
_("Exactly two entities must be selected for this operation."));
}
}
Expand Down Expand Up @@ -220,7 +224,7 @@ void connectSelectedEntities(const cmd::ArgumentList& args)
}
else
{
wxutil::Messagebox::ShowError(
throw cmd::ExecutionNotPossible(
_("Exactly two entities must be selected for this operation."));
}
}
Expand Down Expand Up @@ -360,9 +364,6 @@ scene::INodePtr createEntityFromSelection(const std::string& name, const Vector3
string::to_string(bounds.getExtents()));
}

// Flag the map as unsaved after creating the entity
GlobalMap().setModified(true);

// Check for auto-setting key values. TODO: use forEachClassAttribute
// directly here.
eclass::AttributeList list = eclass::getSpawnargsWithPrefix(
Expand All @@ -371,11 +372,11 @@ scene::INodePtr createEntityFromSelection(const std::string& name, const Vector3

if (!list.empty())
{
for (eclass::AttributeList::const_iterator i = list.begin(); i != list.end(); ++i)
for (const auto& attr : list)
{
// Cut off the "editor_setKeyValueN " string from the key to get the spawnarg name
std::string key = i->getName().substr(i->getName().find_first_of(' ') + 1);
node->getEntity().setKeyValue(key, i->getValue());
std::string key = attr.getName().substr(attr.getName().find_first_of(' ') + 1);
node->getEntity().setKeyValue(key, attr.getValue());
}
}

Expand Down
15 changes: 2 additions & 13 deletions radiantcore/selection/algorithm/General.cpp
Expand Up @@ -4,16 +4,13 @@
#include "iselection.h"
#include "iundo.h"
#include "igrid.h"
#include "ieventmanager.h"
#include "imodelsurface.h"
#include "scenelib.h"
#include "iselectiontest.h"
#include "itraceable.h"

#include "math/Ray.h"
#include "map/Map.h"
#include "selection/shaderclipboard/ShaderClipboard.h"
#include "ui/texturebrowser/TextureBrowser.h"
#include "string/convert.h"
#include "selectionlib.h"
#include "entitylib.h"
Expand Down Expand Up @@ -93,7 +90,7 @@ void selectAllOfType(const cmd::ArgumentList& args)
// fall back to the one selected in the texture browser
if (shaders.empty())
{
shaders.insert(GlobalTextureBrowser().getSelectedShader());
shaders.insert(GlobalShaderClipboard().getSource().getShader());
}

// Deselect all faces
Expand Down Expand Up @@ -146,7 +143,7 @@ void selectAllOfType(const cmd::ArgumentList& args)
{
// No entities found, select all elements with textures
// matching the one in the texture browser
const std::string& shader = GlobalTextureBrowser().getSelectedShader();
auto shader = GlobalShaderClipboard().getSource().getShader();

scene::foreachVisibleBrush([&] (Brush& brush)
{
Expand Down Expand Up @@ -1086,14 +1083,6 @@ void registerCommands()
GlobalCommandSystem().addCommand("BrushSetDetailFlag", brushSetDetailFlag, { cmd::ARGTYPE_STRING });
GlobalCommandSystem().addStatement("BrushMakeDetail", "BrushSetDetailFlag detail", false);
GlobalCommandSystem().addStatement("BrushMakeStructural", "BrushSetDetailFlag structural", false);

GlobalEventManager().addCommand("CloneSelection", "CloneSelection", true); // react on keyUp

GlobalEventManager().addRegistryToggle("ToggleRotationPivot", "user/ui/rotationPivotIsOrigin");
GlobalEventManager().addRegistryToggle("ToggleSnapRotationPivot", "user/ui/snapRotationPivotToGrid");
GlobalEventManager().addRegistryToggle("ToggleOffsetClones", RKEY_OFFSET_CLONED_OBJECTS);

GlobalEventManager().addRegistryToggle("ToggleFreeObjectRotation", RKEY_FREE_OBJECT_ROTATION);
}

} // namespace algorithm
Expand Down
38 changes: 17 additions & 21 deletions radiantcore/selection/algorithm/Group.cpp
@@ -1,16 +1,16 @@
#include "Group.h"

#include "i18n.h"
#include <set>
#include "i18n.h"
#include "igroupnode.h"
#include "imainframe.h"
#include "itextstream.h"
#include "iselectiongroup.h"
#include "imap.h"
#include "selectionlib.h"
#include "entitylib.h"
#include "map/Map.h"
#include "scene/SelectableNode.h"
#include "wxutil/dialog/MessageBox.h"
#include "command/ExecutionFailure.h"
#include "command/ExecutionNotPossible.h"
#include "selection/algorithm/Entity.h"

namespace selection {
Expand All @@ -35,7 +35,7 @@ void convertSelectedToFuncStatic(const cmd::ArgumentList& args)
}
catch (EntityCreationException& e)
{
wxutil::Messagebox::ShowError(e.what());
throw cmd::ExecutionFailure(e.what());
}
}

Expand All @@ -55,7 +55,7 @@ void revertGroupToWorldSpawn(const cmd::ArgumentList& args)
GlobalSelectionSystem().setSelectedAll(false);

// Get the worldspawn node
scene::INodePtr worldspawnNode = GlobalMap().findOrInsertWorldspawn();
scene::INodePtr worldspawnNode = GlobalMapModule().findOrInsertWorldspawn();

Entity* worldspawn = Node_getEntity(worldspawnNode);

Expand All @@ -80,9 +80,6 @@ void revertGroupToWorldSpawn(const cmd::ArgumentList& args)
// Select the reparented primitives after moving them to worldspawn
reparentor.selectReparentedPrimitives();
}

// Flag the map as changed
GlobalMap().setModified(true);
}

void ParentPrimitivesToEntityWalker::reparent()
Expand Down Expand Up @@ -246,10 +243,9 @@ void parentSelection(const cmd::ArgumentList& args)
// Retrieve the selection information structure
if (!curSelectionIsSuitableForReparent())
{
wxutil::Messagebox::ShowError(_("Cannot reparent primitives to entity. "
throw cmd::ExecutionNotPossible(_("Cannot reparent primitives to entity. "
"Please select at least one brush/patch and exactly one func_* entity. "
"(The entity has to be selected last.)"));
return;
}

UndoableCommand undo("parentSelectedPrimitives");
Expand All @@ -266,7 +262,7 @@ void parentSelection(const cmd::ArgumentList& args)
void parentSelectionToWorldspawn(const cmd::ArgumentList& args) {
UndoableCommand undo("parentSelectedPrimitives");

scene::INodePtr world = GlobalMap().findOrInsertWorldspawn();
scene::INodePtr world = GlobalMapModule().findOrInsertWorldspawn();
if (world == NULL) return;

// Take the last selected item (this should be an entity)
Expand Down Expand Up @@ -442,15 +438,15 @@ void mergeSelectedEntities(const cmd::ArgumentList& args)
}
else
{
wxutil::Messagebox::ShowError(_("Cannot merge entities, "
throw cmd::ExecutionNotPossible(_("Cannot merge entities, "
"the selection must consist of func_* entities only.\n"
"(The first selected entity will be preserved.)"));
}
}

void checkGroupSelectedAvailable()
{
if (!GlobalMap().getRoot())
if (!GlobalMapModule().getRoot())
{
throw CommandNotAvailableException(_("No map loaded"));
}
Expand Down Expand Up @@ -512,12 +508,12 @@ void groupSelected()
group->addNode(node);
});

GlobalMainFrame().updateAllWindows();
SceneChangeNotify();
}

void checkUngroupSelectedAvailable()
{
if (!GlobalMap().getRoot())
if (!GlobalMapModule().getRoot())
{
throw CommandNotAvailableException(_("No map loaded"));
}
Expand Down Expand Up @@ -584,12 +580,12 @@ void ungroupSelected()
selGroupMgr.deleteSelectionGroup(id);
});

GlobalMainFrame().updateAllWindows();
SceneChangeNotify();
}

void deleteAllSelectionGroupsCmd(const cmd::ArgumentList& args)
{
if (!GlobalMap().getRoot())
if (!GlobalMapModule().getRoot())
{
rError() << "No map loaded, cannot delete groups." << std::endl;
return;
Expand All @@ -605,10 +601,10 @@ void groupSelectedCmd(const cmd::ArgumentList& args)
{
groupSelected();
}
catch (CommandNotAvailableException & ex)
catch (CommandNotAvailableException& ex)
{
rError() << ex.what() << std::endl;
wxutil::Messagebox::ShowError(ex.what());
throw cmd::ExecutionNotPossible(ex.what());
}
}

Expand All @@ -621,7 +617,7 @@ void ungroupSelectedCmd(const cmd::ArgumentList& args)
catch (CommandNotAvailableException & ex)
{
rError() << ex.what() << std::endl;
wxutil::Messagebox::ShowError(ex.what());
throw cmd::ExecutionNotPossible(ex.what());
}
}

Expand Down
5 changes: 5 additions & 0 deletions radiantcore/selection/algorithm/Transformation.cpp
Expand Up @@ -34,6 +34,11 @@ namespace selection
namespace algorithm
{

namespace
{
const std::string RKEY_OFFSET_CLONED_OBJECTS = "user/ui/offsetClonedObjects";
}

void rotateSelected(const Quaternion& rotation)
{
// Perform the rotation according to the current mode
Expand Down
5 changes: 0 additions & 5 deletions radiantcore/selection/algorithm/Transformation.h
Expand Up @@ -10,11 +10,6 @@ namespace selection
namespace algorithm
{

namespace
{
const std::string RKEY_OFFSET_CLONED_OBJECTS = "user/ui/offsetClonedObjects";
}

/**
* Applies the given quaternion to the current selection.
*/
Expand Down

0 comments on commit 0589d2c

Please sign in to comment.