Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1982: Can't move shared faces together #2007

Merged
merged 4 commits into from Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions common/src/View/VertexHandleManager.h
Expand Up @@ -73,6 +73,16 @@ namespace TrenchBroom {
}
};

/*
template <>
class HCmp<Polygon3> {
public:
bool operator()(const Polygon3& lhs, const Polygon3& rhs) const {
return lhs.compareUnoriented(rhs, 0.1) < 0;
}
};
*/

template <typename H>
class VertexHandleManagerBaseT : public VertexHandleManagerBase {
public:
Expand Down
38 changes: 21 additions & 17 deletions common/src/View/VertexTool.cpp
Expand Up @@ -78,27 +78,31 @@ namespace TrenchBroom {
return m_vertexHandles;
}

bool VertexTool::startMove(const Model::Hit& hit) {
if (!VertexToolBase::startMove(hit)) {
bool VertexTool::startMove(const Model::Hit::List& hits) {
if (!VertexToolBase::startMove(hits)) {
return false;
}

if (hit.hasType(EdgeHandleManager::HandleHit | FaceHandleManager::HandleHit)) {
m_vertexHandles.deselectAll();
if (hit.hasType(EdgeHandleManager::HandleHit)) {
const Edge3& handle = std::get<0>(hit.target<EdgeHandleManager::HitType>());
m_edgeHandles.select(handle);
m_mode = Mode_Split_Edge;
} else {
const Polygon3& handle = std::get<0>(hit.target<FaceHandleManager::HitType>());
m_faceHandles.select(handle);
m_mode = Mode_Split_Face;
}
refreshViews();

if (hits.size() == 1) {
const auto& hit = hits.front();
if (hit.hasType(EdgeHandleManager::HandleHit | FaceHandleManager::HandleHit)) {
m_vertexHandles.deselectAll();
if (hit.hasType(EdgeHandleManager::HandleHit)) {
const auto& handle = std::get<0>(hit.target<EdgeHandleManager::HitType>());
m_edgeHandles.select(handle);
m_mode = Mode_Split_Edge;
} else {
const auto& handle = std::get<0>(hit.target<FaceHandleManager::HitType>());
m_faceHandles.select(handle);
m_mode = Mode_Split_Face;
}
refreshViews();
} else {
m_mode = Mode_Move;
}
} else {
m_mode = Mode_Move;
}

}
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion common/src/View/VertexTool.h
Expand Up @@ -73,7 +73,7 @@ namespace TrenchBroom {
VertexHandleManager& handleManager() override;
const VertexHandleManager& handleManager() const override;
public: // Vertex moving
bool startMove(const Model::Hit& hit) override;
bool startMove(const Model::Hit::List& hits) override;
MoveResult move(const Vec3& delta) override;
void endMove() override;
void cancelMove() override;
Expand Down
29 changes: 19 additions & 10 deletions common/src/View/VertexToolBase.h
Expand Up @@ -42,6 +42,7 @@
#include "View/VertexHandleManager.h"
#include "View/ViewTypes.h"

#include <algorithm>
#include <cassert>
#include <numeric>

Expand Down Expand Up @@ -183,22 +184,30 @@ namespace TrenchBroom {
virtual HandleManager& handleManager() = 0;
virtual const HandleManager& handleManager() const = 0;
public: // performing moves
virtual bool startMove(const Model::Hit& hit) {
assert(hit.isMatch());
virtual bool startMove(const Model::Hit::List& hits) {
assert(!hits.empty());

const H& handle = getHandlePosition(hit);
if (hit.hasType(handleManager().hitType())) {
if (!handleManager().selected(handle)) {
handleManager().deselectAll();
// Delesect all handles if any of the hit handles is not already selected.
if (std::any_of(std::begin(hits), std::end(hits), [&](const auto& hit) {
const H& handle = this->getHandlePosition(hit);
return !this->handleManager().selected(handle);
})) {
handleManager().deselectAll();
}

// Now select all of the hit handles.
for (const auto& hit : hits) {
const H& handle = getHandlePosition(hit);
if (hit.hasType(handleManager().hitType())) {
handleManager().select(handle);
refreshViews();
}
}

refreshViews();

MapDocumentSPtr document = lock(m_document);
document->beginTransaction(actionName());
m_dragHandlePosition = handle;

m_dragHandlePosition = getHandlePosition(hits.front());
m_dragging = true;
return true;
}
Expand Down
23 changes: 22 additions & 1 deletion common/src/View/VertexToolController.cpp
Expand Up @@ -29,7 +29,7 @@ namespace TrenchBroom {
* it up the inheritance hierarchy either. Nor can I introduce a separate common base class for the two parts
* to contain this method due to the call to the inherited findDraggableHandle method.
*/
const Model::Hit VertexToolController::findHandleHit(const InputState& inputState, const VertexToolController::PartBase& base) {
Model::Hit VertexToolController::findHandleHit(const InputState& inputState, const VertexToolController::PartBase& base) {
const Model::Hit vertexHit = base.findDraggableHandle(inputState, VertexHandleManager::HandleHit);
if (vertexHit.isMatch())
return vertexHit;
Expand All @@ -41,6 +41,19 @@ namespace TrenchBroom {
return inputState.pickResult().query().type(FaceHandleManager::HandleHit).first();
}


Model::Hit::List VertexToolController::findHandleHits(const InputState& inputState, const VertexToolController::PartBase& base) {
const Model::Hit::List vertexHits = base.findDraggableHandles(inputState, VertexHandleManager::HandleHit);
if (!vertexHits.empty())
return vertexHits;
if (!inputState.modifierKeysDown(ModifierKeys::MKShift))
return Model::Hit::List();
const Model::Hit::List edgeHits = inputState.pickResult().query().type(EdgeHandleManager::HandleHit).all();
if (!edgeHits.empty())
return edgeHits;
return inputState.pickResult().query().type(FaceHandleManager::HandleHit).all();
}

class VertexToolController::SelectVertexPart : public SelectPartBase<Vec3> {
public:
SelectVertexPart(VertexTool* tool) :
Expand All @@ -50,6 +63,10 @@ namespace TrenchBroom {
return VertexToolController::findHandleHit(inputState, *this);
}

const Model::Hit::List doFindDraggableHandles(const InputState& inputState) const override {
return VertexToolController::findHandleHits(inputState, *this);
}

bool equalHandles(const Vec3& lhs, const Vec3& rhs) const override {
return lhs.squaredDistanceTo(rhs) < MaxHandleDistance * MaxHandleDistance;
}
Expand Down Expand Up @@ -144,6 +161,10 @@ namespace TrenchBroom {
const Model::Hit doFindDraggableHandle(const InputState& inputState) const override {
return VertexToolController::findHandleHit(inputState, *this);
}

const Model::Hit::List doFindDraggableHandles(const InputState& inputState) const override {
return VertexToolController::findHandleHits(inputState, *this);
}
};

VertexToolController::VertexToolController(VertexTool* tool) :
Expand Down
3 changes: 2 additions & 1 deletion common/src/View/VertexToolController.h
Expand Up @@ -30,7 +30,8 @@ namespace TrenchBroom {

class VertexToolController : public VertexToolControllerBase<VertexTool> {
protected:
static const Model::Hit findHandleHit(const InputState& inputState, const VertexToolController::PartBase& base);
static Model::Hit findHandleHit(const InputState& inputState, const VertexToolController::PartBase& base);
static Model::Hit::List findHandleHits(const InputState& inputState, const VertexToolController::PartBase& base);
private:
class SelectVertexPart;
class MoveVertexPart;
Expand Down
25 changes: 20 additions & 5 deletions common/src/View/VertexToolControllerBase.h
Expand Up @@ -28,6 +28,8 @@
#include "View/MoveToolController.h"
#include "View/ToolController.h"

#include <algorithm>

namespace TrenchBroom {
namespace View {
class Tool;
Expand All @@ -51,10 +53,18 @@ namespace TrenchBroom {
const Model::Hit findDraggableHandle(const InputState& inputState) const {
return doFindDraggableHandle(inputState);
}

const Model::Hit::List findDraggableHandles(const InputState& inputState) const {
return doFindDraggableHandles(inputState);
}
private:
virtual const Model::Hit doFindDraggableHandle(const InputState& inputState) const {
return findDraggableHandle(inputState, m_hitType);
}

virtual const Model::Hit::List doFindDraggableHandles(const InputState& inputState) const {
return findDraggableHandles(inputState, m_hitType);
}
public:
const Model::Hit findDraggableHandle(const InputState& inputState, const Model::Hit::HitType hitType) const {
const auto query = inputState.pickResult().query().type(hitType).occluded();
Expand All @@ -69,6 +79,10 @@ namespace TrenchBroom {
}
return Model::Hit::NoHit;
}

const Model::Hit::List findDraggableHandles(const InputState& inputState, const Model::Hit::HitType hitType) const {
return inputState.pickResult().query().type(hitType).occluded().all();
}
private:
bool selected(const Model::Hit& hit) const {
return m_tool->selected(hit);
Expand Down Expand Up @@ -219,6 +233,7 @@ namespace TrenchBroom {
protected:
using PartBase::m_tool;
using PartBase::findDraggableHandle;
using PartBase::findDraggableHandles;
protected:
Tool* doGetTool() override {
return m_tool;
Expand All @@ -239,14 +254,14 @@ namespace TrenchBroom {
)))
return MoveInfo();

const Model::Hit hit = findDraggableHandle(inputState);
if (!hit.isMatch())
const Model::Hit::List hits = findDraggableHandles(inputState);
if (hits.empty())
return MoveInfo();
if (!m_tool->startMove(hit))

if (!m_tool->startMove(hits))
return MoveInfo();

return MoveInfo(hit.hitPoint());
return MoveInfo(hits.front().hitPoint());
}

DragResult doMove(const InputState& inputState, const Vec3& lastHandlePosition, const Vec3& nextHandlePosition) override {
Expand Down