Skip to content

Commit

Permalink
#5122: Implement the DeselectObjectsByFilter command
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 29, 2020
1 parent 7b57cad commit 5ecb33e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
29 changes: 24 additions & 5 deletions radiant/filters/BasicFilterSystem.cpp
Expand Up @@ -12,7 +12,7 @@
#include "modulesystem/StaticModule.h"

#include "InstanceUpdateWalker.h"
#include "SelectByFilterWalker.h"
#include "SetObjectSelectionByFilterWalker.h"

namespace filters
{
Expand Down Expand Up @@ -73,25 +73,41 @@ void BasicFilterSystem::selectObjectsByFilterCmd(const cmd::ArgumentList& args)
{
if (args.size() != 1)
{
rMessage() << "Usage: SelectObjectsByFilter FilterName" << std::endl;
rMessage() << "Usage: SelectObjectsByFilter \"FilterName\"" << std::endl;
return;
}

setObjectSelectionByFilter(args[0].getString(), true);
}

void BasicFilterSystem::deselectObjectsByFilterCmd(const cmd::ArgumentList& args)
{
if (args.size() != 1)
{
rMessage() << "Usage: DeselectObjectsByFilter \"FilterName\"" << std::endl;
return;
}

setObjectSelectionByFilter(args[0].getString(), false);
}

void BasicFilterSystem::setObjectSelectionByFilter(const std::string& filterName, bool select)
{
if (!GlobalSceneGraph().root())
{
rError() << "No map loaded." << std::endl;
return;
}

auto f = _availableFilters.find(args[0].getString());
auto f = _availableFilters.find(filterName);

if (f == _availableFilters.end())
{
rError() << "Cannot find the filter named " << args[0].getString() << std::endl;
rError() << "Cannot find the filter named " << filterName << std::endl;
return;
}

SelectByFilterWalker walker(*this, f->second, true);
SetObjectSelectionByFilterWalker walker(f->second, select);
GlobalSceneGraph().root()->traverse(walker);
}

Expand Down Expand Up @@ -127,6 +143,9 @@ void BasicFilterSystem::initialiseModule(const ApplicationContext& ctx)

GlobalCommandSystem().addCommand("SelectObjectsByFilter",
std::bind(&BasicFilterSystem::selectObjectsByFilterCmd, this, std::placeholders::_1), { cmd::ARGTYPE_STRING });

GlobalCommandSystem().addCommand("DeselectObjectsByFilter",
std::bind(&BasicFilterSystem::deselectObjectsByFilterCmd, this, std::placeholders::_1), { cmd::ARGTYPE_STRING });
}

void BasicFilterSystem::addFiltersFromXML(const xml::NodeList& nodes, bool readOnly)
Expand Down
3 changes: 3 additions & 0 deletions radiant/filters/BasicFilterSystem.h
Expand Up @@ -52,6 +52,9 @@ class BasicFilterSystem :
void setAllFilterStatesCmd(const cmd::ArgumentList& args);

void selectObjectsByFilterCmd(const cmd::ArgumentList& args);
void deselectObjectsByFilterCmd(const cmd::ArgumentList& args);

void setObjectSelectionByFilter(const std::string& filterName, bool select);

public:
// FilterSystem implementation
Expand Down
Expand Up @@ -12,15 +12,15 @@
namespace filters
{

class SelectByFilterWalker :
class SetObjectSelectionByFilterWalker :
public scene::NodeVisitor
{
private:
XMLFilter& _filter;
bool _selectIfFiltered;

public:
SelectByFilterWalker(FilterSystem& filterSystem, XMLFilter& filter, bool selectIfFiltered) :
SetObjectSelectionByFilterWalker(XMLFilter& filter, bool selectIfFiltered) :
_filter(filter),
_selectIfFiltered(selectIfFiltered)
{}
Expand Down
2 changes: 1 addition & 1 deletion tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -1097,7 +1097,7 @@
<ClInclude Include="..\..\radiant\filetypes\FileTypeRegistry.h" />
<ClInclude Include="..\..\radiant\filters\BasicFilterSystem.h" />
<ClInclude Include="..\..\radiant\filters\InstanceUpdateWalker.h" />
<ClInclude Include="..\..\radiant\filters\SelectByFilterWalker.h" />
<ClInclude Include="..\..\radiant\filters\SetObjectSelectionByFilterWalker.h" />
<ClInclude Include="..\..\radiant\filters\XMLFilter.h" />
<ClInclude Include="..\..\radiant\fonts\FontInfo.h" />
<ClInclude Include="..\..\radiant\fonts\FontLoader.h" />
Expand Down
2 changes: 1 addition & 1 deletion tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -3222,7 +3222,7 @@
<ClInclude Include="..\..\radiant\layers\LayerManager.h">
<Filter>src\layers</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\filters\SelectByFilterWalker.h">
<ClInclude Include="..\..\radiant\filters\SetObjectSelectionByFilterWalker.h">
<Filter>src\filters</Filter>
</ClInclude>
</ItemGroup>
Expand Down

0 comments on commit 5ecb33e

Please sign in to comment.