Skip to content

Commit

Permalink
#5231: Refactor a few of the patch algorithm functions to keep the UI…
Browse files Browse the repository at this point in the history
… stuff separated
  • Loading branch information
codereader committed May 28, 2020
1 parent 7d06d68 commit 1974572
Show file tree
Hide file tree
Showing 22 changed files with 225 additions and 75 deletions.
5 changes: 5 additions & 0 deletions include/icommandsystem.h
Expand Up @@ -124,6 +124,11 @@ class Argument
return _strValue;
}

bool getBoolean() const
{
return getInt() != 0;
}

int getInt() const
{
return _intValue;
Expand Down
6 changes: 3 additions & 3 deletions install/input.xml
Expand Up @@ -120,12 +120,12 @@
<shortcut command="PatchDeleteColumnEnd" key="KP_Subtract" modifiers="SHIFT+CONTROL" />
<shortcut command="PatchDeleteRowEnd" key="KP_Subtract" modifiers="CONTROL" />
<shortcut command="TextureNatural" key="N" modifiers="CONTROL" />
<shortcut command="SimplePatchMesh" key="P" modifiers="SHIFT" />
<shortcut command="CreateSimplePatchMesh" key="P" modifiers="SHIFT" />
<shortcut command="InvertCurve" key="I" modifiers="CONTROL" />
<shortcut command="RedisperseRows" key="E" modifiers="CONTROL" />
<shortcut command="RedisperseCols" key="E" modifiers="SHIFT+CONTROL" />
<shortcut command="MatrixTranspose" key="M" modifiers="SHIFT+CONTROL" />
<shortcut command="CapCurrentCurve" key="C" modifiers="SHIFT" />
<shortcut command="PatchCapDialog" key="C" modifiers="SHIFT" />
<shortcut command="NextLeakSpot" key="K" modifiers="SHIFT+CONTROL" />
<shortcut command="PrevLeakSpot" key="L" modifiers="SHIFT+CONTROL" />
<shortcut command="SurfaceInspector" key="S" />
Expand All @@ -144,7 +144,7 @@
<shortcut command="DragVertices" key="V" />
<shortcut command="DragEdges" key="E" />
<shortcut command="DragFaces" key="F" />
<shortcut command="ThickenPatch" key="T" modifiers="CONTROL" />
<shortcut command="ThickenPatchDialog" key="T" modifiers="CONTROL" />
<shortcut command="ToggleShowAllLightRadii" key="F" modifiers="CONTROL+SHIFT+ALT" />
<shortcut command="ToggleClipper" key="X" />
<shortcut command="MouseTranslate" key="W" />
Expand Down
4 changes: 2 additions & 2 deletions install/menu.xml
Expand Up @@ -243,7 +243,7 @@
</subMenu>

<subMenu name="patch" caption="&amp;Patch">
<menuItem name="simplePatch" caption="Create Simple Patch Mesh" command="SimplePatchMesh" />
<menuItem name="simplePatch" caption="Create Simple Patch Mesh" command="CreateSimplePatchDialog" />
<menuSeparator />
<menuItem name="endcap" caption="Create End cap" command="PatchEndCap" />
<menuItem name="bevel" caption="Create Bevel" command="PatchBevel" />
Expand Down Expand Up @@ -298,7 +298,7 @@
</subMenu>

<menuSeparator />
<menuItem name="thickenPatches" caption="Thicken Selected Patches" command="ThickenPatch" />
<menuItem name="thickenPatches" caption="Thicken Selected Patches" command="ThickenPatchDialog" />
<menuItem name="capselection" caption="Cap Selection" command="PatchCapDialog" icon="curve_cap.png" />
<menuSeparator />
<menuItem name="stitchTextures" caption="Stitch Patch Textures" command="StitchPatchTexture" />
Expand Down
24 changes: 24 additions & 0 deletions libs/command/ExecutionNotPossible.h
@@ -0,0 +1,24 @@
#pragma once

#include <stdexcept>
#include "ExecutionFailure.h"

namespace cmd
{

/**
* Exception type thrown when an operation cannot be executed.
* Any function called by the CommandSystem can throw this type,
* it will be caught by the CommandSystem and possibly end up
* displayed in an error popup window.
*/
class ExecutionNotPossible :
public ExecutionFailure
{
public:
ExecutionNotPossible(const std::string& msg) :
ExecutionFailure(msg)
{}
};

}
2 changes: 1 addition & 1 deletion libs/messages/CommandExecutionFailed.h
Expand Up @@ -12,7 +12,7 @@ namespace radiant
* is stored internally and shipped with it.
*/
class CommandExecutionFailedMessage :
public radiant::IMessage
public IMessage
{
private:
const cmd::ExecutionFailure& _exception;
Expand Down
29 changes: 29 additions & 0 deletions libs/messages/TextureChanged.h
@@ -0,0 +1,29 @@
#pragma once

#include "imessagebus.h"
#include "iradiant.h"

namespace radiant
{

/**
* Message object sent when any of the texturable objects
* in the scene have been changed. Any UI dealing with
* textures might need to update their controls.
*/
class TextureChangedMessage :
public IMessage
{
public:
TextureChangedMessage()
{}

// Convenience method
static void Send()
{
TextureChangedMessage msg;
GlobalRadiantCore().getMessageBus().sendMessage(msg);
}
};

}
18 changes: 17 additions & 1 deletion radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -14,6 +14,7 @@
#include "wxutil/menu/CommandMenuItem.h"
#include "wxutil/MultiMonitor.h"
#include "wxutil/dialog/MessageBox.h"
#include "messages/TextureChanged.h"

#include "module/StaticModule.h"

Expand All @@ -39,11 +40,13 @@
#include "ui/entitylist/EntityList.h"
#include "ui/particles/ParticleEditor.h"
#include "ui/patch/CapDialog.h"
#include "ui/patch/PatchThickenDialog.h"
#include "textool/TexTool.h"
#include "modelexport/ExportAsModelDialog.h"
#include "ui/filters/FilterOrthoContextMenuItem.h"
#include "uimanager/colourscheme/ColourSchemeEditor.h"
#include "ui/layers/CreateLayerDialog.h"
#include "ui/patch/PatchCreateDialog.h"
#include "ui/patch/BulgePatchDialog.h"
#include "ui/selectionset/SelectionSetToolmenu.h"

Expand Down Expand Up @@ -145,10 +148,13 @@ void UserInterfaceModule::initialiseModule(const ApplicationContext& ctx)

initialiseEntitySettings();

GlobalRadiantCore().getMessageBus().addListener(
_execFailedListener = GlobalRadiantCore().getMessageBus().addListener(
radiant::TypeListener<radiant::CommandExecutionFailedMessage>(
sigc::mem_fun(this, &UserInterfaceModule::handleCommandExecutionFailure)));

_textureChangedListener = GlobalRadiantCore().getMessageBus().addListener(
radiant::TypeListener(UserInterfaceModule::HandleTextureChanged));

// Initialise the AAS UI
AasControlDialog::Init();

Expand All @@ -157,6 +163,9 @@ void UserInterfaceModule::initialiseModule(const ApplicationContext& ctx)

void UserInterfaceModule::shutdownModule()
{
GlobalRadiantCore().getMessageBus().removeListener(_textureChangedListener);
GlobalRadiantCore().getMessageBus().removeListener(_execFailedListener);

_coloursUpdatedConn.disconnect();
_entitySettingsConn.disconnect();

Expand Down Expand Up @@ -278,6 +287,13 @@ void UserInterfaceModule::registerUICommands()

GlobalCommandSystem().addCommand("BulgePatchDialog", BulgePatchDialog::BulgePatchCmd);
GlobalCommandSystem().addCommand("PatchCapDialog", PatchCapDialog::Show);
GlobalCommandSystem().addCommand("ThickenPatchDialog", PatchThickenDialog::Show);
GlobalCommandSystem().addCommand("CreateSimplePatchDialog", PatchCreateDialog::Show);
}

void UserInterfaceModule::HandleTextureChanged(radiant::TextureChangedMessage& msg)
{
ui::SurfaceInspector::update();
}

// Static module registration
Expand Down
5 changes: 5 additions & 0 deletions radiant/ui/UserInterfaceModule.h
Expand Up @@ -10,6 +10,7 @@
#include "LongRunningOperationHandler.h"
#include "MapFileProgressHandler.h"
#include "messages/CommandExecutionFailed.h"
#include "messages/TextureChanged.h"

namespace ui
{
Expand All @@ -32,6 +33,9 @@ class UserInterfaceModule :
sigc::connection _entitySettingsConn;
sigc::connection _coloursUpdatedConn;

std::size_t _execFailedListener;
std::size_t _textureChangedListener;

public:
// RegisterableModule
const std::string & getName() const override;
Expand All @@ -48,6 +52,7 @@ class UserInterfaceModule :
void refreshShadersCmd(const cmd::ArgumentList& args);

void handleCommandExecutionFailure(radiant::CommandExecutionFailedMessage& msg);
static void HandleTextureChanged(radiant::TextureChangedMessage& msg);
};

}
24 changes: 19 additions & 5 deletions radiant/ui/patch/CapDialog.cpp
Expand Up @@ -9,6 +9,8 @@
#include <wx/artprov.h>

#include "selectionlib.h"
#include "command/ExecutionNotPossible.h"
#include "command/ExecutionFailure.h"
#include "wxutil/dialog/MessageBox.h"

namespace ui
Expand All @@ -18,7 +20,7 @@ namespace
{
const char* WINDOW_TITLE = N_("Create Cap Patch");

const char* const CAPTYPE_NAMES[eNumCapTypes] =
const char* const CAPTYPE_NAMES[5] =
{
N_("Bevel"),
N_("End Cap"),
Expand Down Expand Up @@ -51,7 +53,7 @@ void PatchCapDialog::addItemToTable(wxFlexGridSizer* sizer, const std::string& i
wxStaticBitmap* img = new wxStaticBitmap(_dialog, wxID_ANY,
wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + image));

wxRadioButton* radioButton = new wxRadioButton(_dialog, wxID_ANY, _(CAPTYPE_NAMES[type]),
wxRadioButton* radioButton = new wxRadioButton(_dialog, wxID_ANY, _(CAPTYPE_NAMES[static_cast<std::size_t>(type)]),
wxDefaultPosition, wxDefaultSize, type == patch::CapType::Bevel ? wxRB_GROUP : 0);

sizer->Add(img, 0, wxEXPAND | wxALIGN_CENTER_VERTICAL);
Expand All @@ -76,19 +78,31 @@ patch::CapType PatchCapDialog::getSelectedCapType()
return patch::CapType::None; // invalid
}

std::string PatchCapDialog::getSelectedCapTypeString()
{
switch (getSelectedCapType())
{
case patch::CapType::Bevel: return "bevel";
case patch::CapType::EndCap: return "endcap";
case patch::CapType::InvertedBevel: return "invertedbevel";
case patch::CapType::InvertedEndCap: return "invertedendcap";
case patch::CapType::Cylinder: return "cylinder";
default: throw cmd::ExecutionFailure("Invalid cap type selected");
};
}

void PatchCapDialog::Show(const cmd::ArgumentList & args)
{
if (GlobalSelectionSystem().getSelectionInfo().patchCount == 0)
{
wxutil::Messagebox::ShowError(_("Cannot create caps, no patches selected."));
return;
throw cmd::ExecutionNotPossible(_("Cannot create caps, no patches selected."));
}

PatchCapDialog dialog;

if (dialog.run() == IDialog::RESULT_OK)
{
GlobalCommandSystem().execute("CapSelectedPatches");
GlobalCommandSystem().executeCommand("CapSelectedPatches", dialog.getSelectedCapTypeString());
}
}

Expand Down
2 changes: 2 additions & 0 deletions radiant/ui/patch/CapDialog.h
Expand Up @@ -31,6 +31,8 @@ class PatchCapDialog :
static void Show(const cmd::ArgumentList& args);

private:
std::string getSelectedCapTypeString();

void addItemToTable(wxFlexGridSizer* sizer, const std::string& image, patch::CapType type);
};

Expand Down
13 changes: 13 additions & 0 deletions radiant/ui/patch/PatchCreateDialog.cpp
Expand Up @@ -85,4 +85,17 @@ bool PatchCreateDialog::getRemoveSelectedBrush()
return findNamedObject<wxCheckBox>(_dialog, "PatchCreateRemoveSelectedBrush")->GetValue();
}

void PatchCreateDialog::Show(const cmd::ArgumentList& args)
{
PatchCreateDialog dialog;

if (dialog.run() == IDialog::RESULT_OK)
{
GlobalCommandSystem().executeCommand("CreateSimplePatchMesh",
{ cmd::Argument(dialog.getSelectedWidth()),
cmd::Argument(dialog.getSelectedHeight()),
cmd::Argument(dialog.getRemoveSelectedBrush() ? 1 : 0) });
}
}

} // namespace ui
3 changes: 3 additions & 0 deletions radiant/ui/patch/PatchCreateDialog.h
@@ -1,5 +1,6 @@
#pragma once

#include "icommandsystem.h"
#include "wxutil/dialog/Dialog.h"
#include "wxutil/XmlResourceBasedWidget.h"

Expand All @@ -25,6 +26,8 @@ class PatchCreateDialog :
int getSelectedWidth();
int getSelectedHeight();
bool getRemoveSelectedBrush();

static void Show(const cmd::ArgumentList& args);
};

} // namespace ui
21 changes: 21 additions & 0 deletions radiant/ui/patch/PatchThickenDialog.cpp
Expand Up @@ -3,6 +3,8 @@
#include "i18n.h"
#include "imainframe.h"
#include "string/convert.h"
#include "selectionlib.h"
#include "command/ExecutionNotPossible.h"

#include <wx/stattext.h>
#include <wx/textctrl.h>
Expand Down Expand Up @@ -58,4 +60,23 @@ int PatchThickenDialog::getAxis()
}
}

void PatchThickenDialog::Show(const cmd::ArgumentList& args)
{
if (GlobalSelectionSystem().getSelectionInfo().patchCount == 0)
{
throw cmd::ExecutionNotPossible(_("Cannot thicken patch. Nothing selected."));
}

PatchThickenDialog dialog;

if (dialog.run() == IDialog::RESULT_OK)
{
GlobalCommandSystem().executeCommand("ThickenSelectedPatches",
{ cmd::Argument(dialog.getThickness()),
cmd::Argument(dialog.getCeateSeams() ? 1 : 0),
cmd::Argument(dialog.getAxis()) }
);
}
}

} // namespace ui
3 changes: 3 additions & 0 deletions radiant/ui/patch/PatchThickenDialog.h
@@ -1,5 +1,6 @@
#pragma once

#include "icommandsystem.h"
#include "wxutil/dialog/Dialog.h"
#include "wxutil/XmlResourceBasedWidget.h"

Expand All @@ -22,6 +23,8 @@ class PatchThickenDialog :
float getThickness();
bool getCeateSeams();
int getAxis();

static void Show(const cmd::ArgumentList& args);
};

} // namespace
9 changes: 9 additions & 0 deletions radiantcore/commandsystem/CommandSystem.cpp
Expand Up @@ -5,6 +5,7 @@
#include "iradiant.h"
#include "debugging/debugging.h"
#include "command/ExecutionFailure.h"
#include "command/ExecutionNotPossible.h"
#include "messages/CommandExecutionFailed.h"

#include "CommandTokeniser.h"
Expand Down Expand Up @@ -384,6 +385,14 @@ void CommandSystem::executeCommand(const std::string& name, const ArgumentList&
{
rError() << "Command '" << name << "' failed: " << ex.what() << std::endl;

// Dispatch this exception to the messagebus to potential listeners
radiant::CommandExecutionFailedMessage message(ex);
GlobalRadiantCore().getMessageBus().sendMessage(message);
}
catch (const ExecutionNotPossible & ex)
{
rError() << "Command '" << name << "' cannot be executed: " << ex.what() << std::endl;

// Dispatch this exception to the messagebus to potential listeners
radiant::CommandExecutionFailedMessage message(ex);
GlobalRadiantCore().getMessageBus().sendMessage(message);
Expand Down

0 comments on commit 1974572

Please sign in to comment.