-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolRoadAdd.cpp
More file actions
113 lines (100 loc) · 2.59 KB
/
ToolRoadAdd.cpp
File metadata and controls
113 lines (100 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "stdafx.h"
#include "ToolRoadAdd.h"
#include "WorldRoad.h"
#include "WorldNode.h"
#include "WorldFrame.h"
using namespace Ogre;
ToolRoadAdd::ToolRoadAdd(WorldFrame* wf, SceneManager* sm, RoadGraph &g, RoadGraph &s)
: ToolView(wf),
_roadGraph(g),
_simpleRoadGraph(s)
{
_sceneManager = sm;
}
void ToolRoadAdd::OnMouseMove(wxMouseEvent &e)
{
if(alternate(e) == true)
{
_worldFrame->highlightNode(0);
ToolView::OnMouseMove(e);
return;
}
WorldNode *wn;
if(_worldFrame->pickNode(e, 7, wn)) _worldFrame->highlightNode(wn);
else _worldFrame->highlightNode(0);
_worldFrame->Refresh();
}
void ToolRoadAdd::OnLeftPressed(wxMouseEvent &e)
{
if(alternate(e) == true)
{
_worldFrame->highlightNode(0);
ToolView::OnLeftPressed(e);
return;
}
//TODO:
if(_worldFrame->getSelectedNode())
{
// delete a road
WorldNode *wn;
if(_worldFrame->pickNode(e, 7, wn))
{
if(wn == _worldFrame->getSelectedNode())
{
// deselect node
_worldFrame->selectNode(0);
_worldFrame->Refresh();
return;
}
// need to check this road can't create it willy nilly
WorldNode* proposedNode = _worldFrame->createNode();
proposedNode->setPosition3D(wn->getPosition3D());
WorldRoad* wr = new WorldRoad(_worldFrame->getSelectedNode(),
wn, _roadGraph, _simpleRoadGraph, _sceneManager);
int snapState;
WorldRoad* intersectingRoad;
WorldNode* snapNode;
Ogre::Vector2 newPos;
// needs a good studying
snapState = wr->snapInfo(5, newPos, snapNode, intersectingRoad);
delete wr;
_worldFrame->deleteNode(proposedNode);
if(snapState != 0)
{
Ogre::LogManager::getSingleton().logMessage("INVALID OPERATION: Cannot add a road that intersect with others. Try reducing the road deviation or use the add node tool.");
//if(snapState == 1) _worldFrame->selectRoad(intersectingRoad);
}
else
{
_worldFrame->createRoad(_worldFrame->getSelectedNode(), wn);
_worldFrame->selectNode(wn);
}
_worldFrame->Refresh();
}
}
else
{
// just select a node
WorldNode *wn;
if(_worldFrame->pickNode(e, 7, wn))
{
_worldFrame->selectNode(wn);
_worldFrame->Refresh();
}
}
}
bool ToolRoadAdd::alternate(wxMouseEvent &e)
{
if(e.ControlDown()) return true;
else return false;
}
void ToolRoadAdd::OnMiddlePressed(wxMouseEvent &e)
{
if(alternate(e) == true)
return ToolView::OnMiddlePressed(e);
}
void ToolRoadAdd::OnRightPressed(wxMouseEvent &e)
{
if(alternate(e) == true)
return ToolView::OnRightPressed(e);
}