Skip to content

Commit

Permalink
#5231: Migrate PatchInspector
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jun 14, 2020
1 parent 9a9a1e5 commit a930ae5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 134 deletions.
82 changes: 43 additions & 39 deletions radiant/ui/patch/PatchInspector.cpp
Expand Up @@ -17,8 +17,6 @@
#include "selectionlib.h"
#include "wxutil/ControlButton.h"

#include "patch/PatchNode.h"
#include "selection/algorithm/Primitives.h"
#include <functional>

namespace ui
Expand All @@ -40,15 +38,15 @@ namespace

PatchInspector::PatchInspector() :
TransientWindow(_(WINDOW_TITLE), GlobalMainFrame().getWxTopLevelWindow(), true),
_rowCombo(NULL),
_colCombo(NULL),
_rowCombo(nullptr),
_colCombo(nullptr),
_selectionInfo(GlobalSelectionSystem().getSelectionInfo()),
_patchRows(0),
_patchCols(0),
_updateActive(false),
_updateNeeded(false)
{
Connect(wxEVT_IDLE, wxIdleEventHandler(PatchInspector::onIdle), NULL, this);
Bind(wxEVT_IDLE, &PatchInspector::onIdle, this);

// Create all the widgets and pack them into the window
populateWindow();
Expand All @@ -59,9 +57,9 @@ PatchInspector::PatchInspector() :
InitialiseWindowPosition(410, 480, RKEY_WINDOW_STATE);
}

PatchInspectorPtr& PatchInspector::InstancePtr()
std::shared_ptr<PatchInspector>& PatchInspector::InstancePtr()
{
static PatchInspectorPtr _instancePtr;
static std::shared_ptr<PatchInspector> _instancePtr;
return _instancePtr;
}

Expand All @@ -81,9 +79,9 @@ void PatchInspector::onRadiantShutdown()

PatchInspector& PatchInspector::Instance()
{
PatchInspectorPtr& instancePtr = InstancePtr();
auto& instancePtr = InstancePtr();

if (instancePtr == NULL)
if (!instancePtr)
{
// Not yet instantiated, do it now
instancePtr.reset(new PatchInspector);
Expand Down Expand Up @@ -203,9 +201,9 @@ void PatchInspector::update()
{
_updateActive = true;

PatchNodePtr patch = _patch.lock();
auto patch = _patch.lock();

if (patch != NULL)
if (patch)
{
// Check if the matrix size has changed
if (patch->getPatch().getWidth() != _patchCols ||
Expand All @@ -225,9 +223,9 @@ void PatchInspector::update()

void PatchInspector::loadControlVertex()
{
PatchNodePtr patch = _patch.lock();
auto patch = _patch.lock();

if (patch != NULL)
if (patch)
{
int row = _rowCombo->GetSelection();
int col = _colCombo->GetSelection();
Expand All @@ -253,7 +251,7 @@ void PatchInspector::_preHide()
TransientWindow::_preHide();

// Clear the patch, we don't need to observe it while hidden
setPatch(PatchNodePtr());
setPatch(IPatchNodePtr());

// A hidden PatchInspector doesn't need to listen for events
_undoHandler.disconnect();
Expand Down Expand Up @@ -301,12 +299,12 @@ void PatchInspector::clearVertexChooser()
_updateActive = false;
}

void PatchInspector::setPatch(const PatchNodePtr& newPatch)
void PatchInspector::setPatch(const IPatchNodePtr& newPatch)
{
// Detach if we had a previous patch
PatchNodePtr patch = _patch.lock();
auto patch = _patch.lock();

if (patch != NULL)
if (patch)
{
patch->getPatch().detachObserver(this);
}
Expand All @@ -316,7 +314,7 @@ void PatchInspector::setPatch(const PatchNodePtr& newPatch)

_patch = newPatch;

if (newPatch != NULL)
if (newPatch)
{
newPatch->getPatch().attachObserver(this);

Expand Down Expand Up @@ -345,41 +343,47 @@ void PatchInspector::rescanSelection()
findNamedObject<wxPanel>(this, "PatchInspectorTessPanel")->Enable(_selectionInfo.patchCount > 0);

// Clear the patch reference
setPatch(PatchNodePtr());
setPatch(IPatchNodePtr());

if (_selectionInfo.patchCount > 0)
{
// Get the list of selected patches
PatchPtrVector list = selection::algorithm::getSelectedPatches();

Subdivisions tess(UINT_MAX, UINT_MAX);
bool tessIsFixed = false;
bool continueSearching = true;
IPatchNodePtr patchNode;

// Try to find a pair of same tesselation values
for (PatchPtrVector::const_iterator i = list.begin(); i != list.end(); ++i)
{
IPatch& p = (*i)->getPatch();
GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node)
{
if (!continueSearching || !Node_isPatch(node)) return;

auto& patch = *Node_getIPatch(node);

if (!patchNode)
{
patchNode = std::dynamic_pointer_cast<IPatchNode>(node);
}

if (tess.x() == UINT_MAX)
{
{
// Not initialised yet, take these values for starters
tessIsFixed = p.subdivisionsFixed();
tess = p.getSubdivisions();
tessIsFixed = patch.subdivisionsFixed();
tess = patch.getSubdivisions();
}
else
{
// We already have a pair of divisions, compare
Subdivisions otherTess = p.getSubdivisions();
Subdivisions otherTess = patch.getSubdivisions();

if (tessIsFixed != p.subdivisionsFixed() || otherTess != tess)
if (tessIsFixed != patch.subdivisionsFixed() || otherTess != tess)
{
// Our journey ends here, we cannot find a pair of tesselations
// for all selected patches or the same fixed/variable status
tessIsFixed = false;
break;
continueSearching = false;
}
}
}
});

_updateActive = true;

Expand All @@ -400,7 +404,7 @@ void PatchInspector::rescanSelection()

if (_selectionInfo.patchCount == 1)
{
setPatch(list[0]);
setPatch(patchNode);
}

_updateActive = false;
Expand Down Expand Up @@ -432,20 +436,20 @@ void PatchInspector::repopulateVertexChooser()

void PatchInspector::emitCoords()
{
PatchNodePtr patch = _patch.lock();
auto patch = _patch.lock();

if (patch == NULL) return;
if (!patch) return;

// Save the coords into the patch
UndoableCommand emitCoordsCmd("patchAdjustControlVertex");

patch->getPatchInternal().undoSave();
patch->getPatch().undoSave();

int row = _rowCombo->GetSelection();
int col = _colCombo->GetSelection();

// Retrieve the controlvertex
PatchControl& ctrl = patch->getPatchInternal().ctrlAt(row, col);
PatchControl& ctrl = patch->getPatch().ctrlAt(row, col);

ctrl.vertex[0] = string::convert<float>(_coords["x"].value->GetValue().ToStdString());
ctrl.vertex[1] = string::convert<float>(_coords["y"].value->GetValue().ToStdString());
Expand All @@ -454,7 +458,7 @@ void PatchInspector::emitCoords()
ctrl.texcoord[0] = string::convert<float>(_coords["s"].value->GetValue().ToStdString());
ctrl.texcoord[1] = string::convert<float>(_coords["t"].value->GetValue().ToStdString());

patch->getPatchInternal().controlPointsChanged();
patch->getPatch().controlPointsChanged();

GlobalMainFrame().updateAllWindows();
}
Expand All @@ -474,7 +478,7 @@ void PatchInspector::emitTesselation()
bool fixed = findNamedObject<wxCheckBox>(this, "PatchInspectorFixedSubdivisions")->GetValue();

// Save the setting into the selected patch(es)
GlobalSelectionSystem().foreachPatch([&] (Patch& patch)
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch)
{
patch.setFixedSubdivisions(fixed, tess);
});
Expand Down
15 changes: 3 additions & 12 deletions radiant/ui/patch/PatchInspector.h
Expand Up @@ -13,11 +13,6 @@
#include "wxutil/event/SingleIdleCallback.h"
#include "wxutil/XmlResourceBasedWidget.h"

class Patch;
class PatchNode;
typedef std::shared_ptr<PatchNode> PatchNodePtr;
typedef std::weak_ptr<PatchNode> PatchNodeWeakPtr;

namespace wxutil { class ControlButton; }
class wxChoice;
class wxPanel;
Expand All @@ -27,10 +22,6 @@ class wxSizer;
namespace ui
{

// Forward declaration
class PatchInspector;
typedef std::shared_ptr<PatchInspector> PatchInspectorPtr;

class PatchInspector :
public wxutil::TransientWindow,
public SelectionSystem::Observer,
Expand Down Expand Up @@ -60,7 +51,7 @@ class PatchInspector :
std::size_t _patchCols;

// The pointer to the active patch node (only non-NULL if there is a single patch selected)
PatchNodeWeakPtr _patch;
std::weak_ptr<IPatchNode> _patch;

// If this is set to TRUE, the GTK callbacks will be disabled
bool _updateActive;
Expand Down Expand Up @@ -145,7 +136,7 @@ class PatchInspector :
void onPatchDestruction();

private:
void setPatch(const PatchNodePtr& patch);
void setPatch(const IPatchNodePtr& patch);

// Updates the widgets (this is private, use queueUpdate() instead)
void update();
Expand All @@ -157,7 +148,7 @@ class PatchInspector :
void repopulateVertexChooser();

// This is where the static shared_ptr of the singleton instance is held.
static PatchInspectorPtr& InstancePtr();
static std::shared_ptr<PatchInspector>& InstancePtr();

// Called by wxWidgets when the system is idle
void onIdle(wxIdleEvent& ev);
Expand Down
36 changes: 0 additions & 36 deletions radiantcore/selection/algorithm/ModelFinder.cpp

This file was deleted.

47 changes: 0 additions & 47 deletions radiantcore/selection/algorithm/ModelFinder.h

This file was deleted.

0 comments on commit a930ae5

Please sign in to comment.