From 0589d2c5f82e4eb482bea2e6f83b36d395b774a8 Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 29 May 2020 06:34:06 +0200 Subject: [PATCH] #5231: Remove UI references from a few algorithm files --- radiant/ui/UserInterfaceModule.cpp | 8 ++++ .../ui/einspector/ClassnamePropertyEditor.cpp | 3 +- radiantcore/selection/algorithm/Entity.cpp | 41 ++++++++++--------- radiantcore/selection/algorithm/General.cpp | 15 +------ radiantcore/selection/algorithm/Group.cpp | 38 ++++++++--------- .../selection/algorithm/Transformation.cpp | 5 +++ .../selection/algorithm/Transformation.h | 5 --- 7 files changed, 55 insertions(+), 60 deletions(-) diff --git a/radiant/ui/UserInterfaceModule.cpp b/radiant/ui/UserInterfaceModule.cpp index f2801a0008..e4eee6f575 100644 --- a/radiant/ui/UserInterfaceModule.cpp +++ b/radiant/ui/UserInterfaceModule.cpp @@ -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) diff --git a/radiant/ui/einspector/ClassnamePropertyEditor.cpp b/radiant/ui/einspector/ClassnamePropertyEditor.cpp index 4a6567c8c7..09a8ae470e 100644 --- a/radiant/ui/einspector/ClassnamePropertyEditor.cpp +++ b/radiant/ui/einspector/ClassnamePropertyEditor.cpp @@ -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 @@ -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()); } diff --git a/radiantcore/selection/algorithm/Entity.cpp b/radiantcore/selection/algorithm/Entity.cpp index cab41dd871..4144ceb2b8 100644 --- a/radiantcore/selection/algorithm/Entity.cpp +++ b/radiantcore/selection/algorithm/Entity.cpp @@ -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 @@ -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 entitiesToProcess; @@ -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.")); } } }); @@ -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(GKEY_BIND_KEY); @@ -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.")); } } @@ -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.")); } } @@ -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( @@ -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()); } } diff --git a/radiantcore/selection/algorithm/General.cpp b/radiantcore/selection/algorithm/General.cpp index a6a60a2996..b5135725b9 100644 --- a/radiantcore/selection/algorithm/General.cpp +++ b/radiantcore/selection/algorithm/General.cpp @@ -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" @@ -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 @@ -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) { @@ -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 diff --git a/radiantcore/selection/algorithm/Group.cpp b/radiantcore/selection/algorithm/Group.cpp index 1c806a36a7..d21969831b 100644 --- a/radiantcore/selection/algorithm/Group.cpp +++ b/radiantcore/selection/algorithm/Group.cpp @@ -1,16 +1,16 @@ #include "Group.h" -#include "i18n.h" #include +#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 { @@ -35,7 +35,7 @@ void convertSelectedToFuncStatic(const cmd::ArgumentList& args) } catch (EntityCreationException& e) { - wxutil::Messagebox::ShowError(e.what()); + throw cmd::ExecutionFailure(e.what()); } } @@ -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); @@ -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() @@ -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"); @@ -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) @@ -442,7 +438,7 @@ 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.)")); } @@ -450,7 +446,7 @@ void mergeSelectedEntities(const cmd::ArgumentList& args) void checkGroupSelectedAvailable() { - if (!GlobalMap().getRoot()) + if (!GlobalMapModule().getRoot()) { throw CommandNotAvailableException(_("No map loaded")); } @@ -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")); } @@ -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; @@ -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()); } } @@ -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()); } } diff --git a/radiantcore/selection/algorithm/Transformation.cpp b/radiantcore/selection/algorithm/Transformation.cpp index 39ae4f0ff2..3e8efcc950 100644 --- a/radiantcore/selection/algorithm/Transformation.cpp +++ b/radiantcore/selection/algorithm/Transformation.cpp @@ -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 diff --git a/radiantcore/selection/algorithm/Transformation.h b/radiantcore/selection/algorithm/Transformation.h index 6318f534b7..69b74c392f 100644 --- a/radiantcore/selection/algorithm/Transformation.h +++ b/radiantcore/selection/algorithm/Transformation.h @@ -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. */