| 1 |
#include "ClipperTool.h" |
| 2 |
|
| 3 |
#include "i18n.h" |
| 4 |
#include "igrid.h" |
| 5 |
#include "iclipper.h" |
| 6 |
#include "iselection.h" |
| 7 |
#include "ui/imainframe.h" |
| 8 |
#include "XYMouseToolEvent.h" |
| 9 |
|
| 10 |
namespace ui |
| 11 |
{ |
| 12 |
|
| 13 |
ClipperTool::ClipperTool() : |
| 14 |
_crossHairEnabled(false) |
| 15 |
{} |
| 16 |
|
| 17 |
const std::string& ClipperTool::getName() |
| 18 |
{ |
| 19 |
static std::string name("ClipperTool"); |
| 20 |
return name; |
| 21 |
} |
| 22 |
|
| 23 |
const std::string& ClipperTool::getDisplayName() |
| 24 |
{ |
| 25 |
static std::string displayName(_("Clipper")); |
| 26 |
return displayName; |
| 27 |
} |
| 28 |
|
| 29 |
MouseTool::Result ClipperTool::onMouseDown(Event& ev) |
| 30 |
{ |
| 31 |
try |
| 32 |
{ |
| 33 |
// We only operate on XY view events, so attempt to cast |
| 34 |
XYMouseToolEvent& xyEvent = dynamic_cast<XYMouseToolEvent&>(ev); |
| 35 |
|
| 36 |
// There are two possibilites for the "select" click: Clip or Select |
| 37 |
if (GlobalClipper().clipMode()) |
| 38 |
{ |
| 39 |
ClipPoint* foundClipPoint = GlobalClipper().find( |
| 40 |
xyEvent.getWorldPos(), xyEvent.getViewType(), xyEvent.getScale()); |
| 41 |
|
| 42 |
GlobalClipper().setMovingClip(foundClipPoint); |
| 43 |
|
| 44 |
if (foundClipPoint == nullptr) |
| 45 |
{ |
| 46 |
dropClipPoint(xyEvent); |
| 47 |
} |
| 48 |
|
| 49 |
return Result::Activated; |
| 50 |
} |
| 51 |
} |
| 52 |
catch (std::bad_cast&) |
| 53 |
{ |
| 54 |
} |
| 55 |
|
| 56 |
return Result::Ignored; // not handled |
| 57 |
} |
| 58 |
|
| 59 |
MouseTool::Result ClipperTool::onMouseMove(Event& ev) |
| 60 |
{ |
| 61 |
try |
| 62 |
{ |
| 63 |
// We only operate on XY view events, so attempt to cast |
| 64 |
XYMouseToolEvent& xyEvent = dynamic_cast<XYMouseToolEvent&>(ev); |
| 65 |
|
| 66 |
if (!GlobalClipper().clipMode()) |
| 67 |
{ |
| 68 |
// Check if we need to clean up the XY cursor state |
| 69 |
if (_crossHairEnabled) |
| 70 |
{ |
| 71 |
xyEvent.getView().setCursorType(IOrthoView::CursorType::Default); |
| 72 |
_crossHairEnabled = false; |
| 73 |
} |
| 74 |
|
| 75 |
return Result::Ignored; |
| 76 |
} |
| 77 |
|
| 78 |
// Check, if we have a clip point operation running |
| 79 |
if (GlobalClipper().getMovingClip() != nullptr) |
| 80 |
{ |
| 81 |
// Leave the third coordinate of the clip point untouched (#5356) |
| 82 |
auto viewType = xyEvent.getViewType(); |
| 83 |
int missingDim = viewType == OrthoOrientation::XY ? 2 : viewType == OrthoOrientation::YZ ? 0 : 1; |
| 84 |
auto& clipCoords = GlobalClipper().getMovingClipCoords(); |
| 85 |
|
| 86 |
Vector3 newWorldPos = xyEvent.getWorldPos(); |
| 87 |
newWorldPos[missingDim] = clipCoords[missingDim]; |
| 88 |
|
| 89 |
xyEvent.getView().snapToGrid(newWorldPos); |
| 90 |
|
| 91 |
GlobalClipper().getMovingClipCoords() = newWorldPos; |
| 92 |
GlobalClipper().update(); |
| 93 |
|
| 94 |
GlobalMainFrame().updateAllWindows(); |
| 95 |
|
| 96 |
return Result::Continued; |
| 97 |
} |
| 98 |
|
| 99 |
// Check the point below the cursor to detect manipulatable clip points |
| 100 |
if (GlobalClipper().find(xyEvent.getWorldPos(), xyEvent.getViewType(), xyEvent.getScale()) != NULL) |
| 101 |
{ |
| 102 |
xyEvent.getView().setCursorType(IOrthoView::CursorType::Crosshair); |
| 103 |
// Remember to clean up the cursor when clip mode is deactivated |
| 104 |
_crossHairEnabled = true; |
| 105 |
return Result::Continued; |
| 106 |
} |
| 107 |
else |
| 108 |
{ |
| 109 |
xyEvent.getView().setCursorType(IOrthoView::CursorType::Default); |
| 110 |
_crossHairEnabled = false; |
| 111 |
return Result::Continued; |
| 112 |
} |
| 113 |
} |
| 114 |
catch (std::bad_cast&) |
| 115 |
{ |
| 116 |
} |
| 117 |
|
| 118 |
return Result::Ignored; |
| 119 |
} |
| 120 |
|
| 121 |
MouseTool::Result ClipperTool::onMouseUp(Event& ev) |
| 122 |
{ |
| 123 |
try |
| 124 |
{ |
| 125 |
// We only operate on XY view events, so attempt to cast |
| 126 |
dynamic_cast<XYMouseToolEvent&>(ev).getScale(); |
| 127 |
|
| 128 |
if (GlobalClipper().clipMode()) |
| 129 |
{ |
| 130 |
GlobalClipper().setMovingClip(NULL); |
| 131 |
return Result::Finished; |
| 132 |
} |
| 133 |
} |
| 134 |
catch (std::bad_cast&) |
| 135 |
{ |
| 136 |
} |
| 137 |
|
| 138 |
return Result::Ignored; |
| 139 |
} |
| 140 |
|
| 141 |
bool ClipperTool::alwaysReceivesMoveEvents() |
| 142 |
{ |
| 143 |
return true; |
| 144 |
} |
| 145 |
|
| 146 |
void ClipperTool::dropClipPoint(XYMouseToolEvent& event) |
| 147 |
{ |
| 148 |
Vector3 point = event.getWorldPos(); |
| 149 |
Vector3 mid = GlobalSelectionSystem().getCurrentSelectionCenter(); |
| 150 |
|
| 151 |
GlobalClipper().setViewType(static_cast<OrthoOrientation>(event.getViewType())); |
| 152 |
int nDim = (GlobalClipper().getViewType() == OrthoOrientation::YZ) ? 0 : ((GlobalClipper().getViewType() == OrthoOrientation::XZ) ? 1 : 2); |
| 153 |
point[nDim] = mid[nDim]; |
| 154 |
point.snap(GlobalGrid().getGridSize()); |
| 155 |
GlobalClipper().newClipPoint(point); |
| 156 |
} |
| 157 |
|
| 158 |
} // namespace |