Skip to content

Commit

Permalink
#5746: Add some stub textool::INode implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 13, 2021
1 parent 3e263a3 commit 0bfb0de
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 3 deletions.
4 changes: 1 addition & 3 deletions include/itexturetoolmodel.h
Expand Up @@ -13,9 +13,6 @@ class INode
virtual ~INode() {}

using Ptr = std::shared_ptr<INode>;

// The scene node this texture tool node is relating to
virtual scene::INodePtr getSceneNode() = 0;
};

/**
Expand All @@ -37,6 +34,7 @@ class ITextureToolSceneGraph :
virtual ~ITextureToolSceneGraph() {}

// Iterate over every node in this graph calling the given functor
// Collection should not be modified during iteration
virtual void foreachNode(const std::function<bool(const INode::Ptr&)>& functor) = 0;
};

Expand Down
21 changes: 21 additions & 0 deletions radiantcore/selection/textool/FaceNode.h
@@ -0,0 +1,21 @@
#pragma once

#include "ibrush.h"
#include "NodeBase.h"

namespace textool
{

class FaceNode :
public NodeBase
{
private:
IFace& _face;

public:
FaceNode(IFace& face) :
_face(face)
{}
};

}
13 changes: 13 additions & 0 deletions radiantcore/selection/textool/NodeBase.h
@@ -0,0 +1,13 @@
#pragma once

#include "itexturetoolmodel.h"

namespace textool
{

class NodeBase :
public INode
{
};

}
21 changes: 21 additions & 0 deletions radiantcore/selection/textool/PatchNode.h
@@ -0,0 +1,21 @@
#pragma once

#include "ipatch.h"
#include "NodeBase.h"

namespace textool
{

class PatchNode :
public NodeBase
{
private:
IPatch& _patch;

public:
PatchNode(IPatch& patch) :
_patch(patch)
{}
};

}
62 changes: 62 additions & 0 deletions radiantcore/selection/textool/TextureToolSceneGraph.cpp
@@ -1,11 +1,21 @@
#include "TextureToolSceneGraph.h"

#include "iselection.h"
#include "ibrush.h"
#include "ipatch.h"
#include "module/StaticModule.h"
#include "selectionlib.h"

#include "FaceNode.h"
#include "PatchNode.h"

namespace textool
{

TextureToolSceneGraph::TextureToolSceneGraph() :
_selectionNeedsRescan(true)
{}

const std::string& TextureToolSceneGraph::getName() const
{
static std::string _name(MODULE_TEXTOOL_SCENEGRAPH);
Expand All @@ -29,17 +39,69 @@ void TextureToolSceneGraph::initialiseModule(const IApplicationContext& ctx)

void TextureToolSceneGraph::shutdownModule()
{
_selectionNeedsRescan = false;
_nodes.clear();
_sceneSelectionChanged.disconnect();
}

void TextureToolSceneGraph::foreachNode(const std::function<bool(const INode::Ptr&)>& functor)
{
ensureSceneIsAnalysed();

for (const auto& node : _nodes)
{
if (!functor(node))
{
break;
}
}
}

void TextureToolSceneGraph::ensureSceneIsAnalysed()
{
if (!_selectionNeedsRescan) return;

_selectionNeedsRescan = false;

_nodes.clear();

auto selectedShader = selection::getShaderFromSelection();
if (selectedShader.empty()) return;

if (GlobalSelectionSystem().countSelectedComponents() > 0)
{
// Check each selected face
GlobalSelectionSystem().foreachFace([&](IFace& face)
{
_nodes.emplace_back(std::make_shared<FaceNode>(face));
});
}
else
{
GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node)
{
if (Node_isBrush(node))
{
auto brush = Node_getIBrush(node);
assert(brush);

for (auto i = 0; i < brush->getNumFaces(); ++i)
{
_nodes.emplace_back(std::make_shared<FaceNode>(brush->getFace(i)));
}
}
else if (Node_isPatch(node))
{
_nodes.emplace_back(std::make_shared<PatchNode>(*Node_getIPatch(node)));
}
});
}
}

void TextureToolSceneGraph::onSceneSelectionChanged(const ISelectable& selectable)
{
// Mark our own selection as dirty
_selectionNeedsRescan = true;
}

module::StaticModule<TextureToolSceneGraph> _textureToolSceneGraphModule;
Expand Down
8 changes: 8 additions & 0 deletions radiantcore/selection/textool/TextureToolSceneGraph.h
@@ -1,5 +1,6 @@
#pragma once

#include <list>
#include <sigc++/connection.h>
#include "itexturetoolmodel.h"

Expand All @@ -12,7 +13,13 @@ class TextureToolSceneGraph :
private:
sigc::connection _sceneSelectionChanged;

bool _selectionNeedsRescan;

std::list<INode::Ptr> _nodes;

public:
TextureToolSceneGraph();

const std::string& getName() const override;
const StringSet& getDependencies() const override;
void initialiseModule(const IApplicationContext& ctx) override;
Expand All @@ -22,6 +29,7 @@ class TextureToolSceneGraph :

private:
void onSceneSelectionChanged(const ISelectable& selectable);
void ensureSceneIsAnalysed();
};

}
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -1025,6 +1025,9 @@
<ClInclude Include="..\..\radiantcore\selection\shaderclipboard\ClosestTexturableFinder.h" />
<ClInclude Include="..\..\radiantcore\selection\shaderclipboard\ShaderClipboard.h" />
<ClInclude Include="..\..\radiantcore\selection\shaderclipboard\Texturable.h" />
<ClInclude Include="..\..\radiantcore\selection\textool\FaceNode.h" />
<ClInclude Include="..\..\radiantcore\selection\textool\NodeBase.h" />
<ClInclude Include="..\..\radiantcore\selection\textool\PatchNode.h" />
<ClInclude Include="..\..\radiantcore\selection\textool\TextureToolSceneGraph.h" />
<ClInclude Include="..\..\radiantcore\selection\TransformationVisitors.h" />
<ClInclude Include="..\..\radiantcore\settings\ColourScheme.h" />
Expand Down
9 changes: 9 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -2208,5 +2208,14 @@
<ClInclude Include="..\..\radiantcore\selection\textool\TextureToolSceneGraph.h">
<Filter>src\selection\textool</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\selection\textool\FaceNode.h">
<Filter>src\selection\textool</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\selection\textool\NodeBase.h">
<Filter>src\selection\textool</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\selection\textool\PatchNode.h">
<Filter>src\selection\textool</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 0bfb0de

Please sign in to comment.