-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_repExtLanelets.cpp
More file actions
152 lines (129 loc) · 6.06 KB
/
v_repExtLanelets.cpp
File metadata and controls
152 lines (129 loc) · 6.06 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* ----------------------------------------------------------
* v_repExtLanelets plugin
* (c) Candido Otero, 2017, Universidade de Vigo
* ----------------------------------------------------------*/
#include "v_repExtLanelets.h"
#include "v_repLib.h"
#include <unistd.h>
#include <iostream>
#include "laneletsdialog.h"
#ifdef _WIN32
#include <direct.h>
#endif /* _WIN32 */
#if defined (__linux) || defined (__APPLE__)
#include <string.h>
#define _stricmp(x,y) strcasecmp(x,y)
#endif
#define PLUGIN_VERSION 1
LIBRARY vrepLib;
laneletsdialog* laneletsDialog=NULL;
// This is the plugin start routine (called just once, just after the plugin was loaded):
VREP_DLLEXPORT unsigned char v_repStart(void* reservedPointer,int reservedInt)
{
// Dynamically load and bind V-REP functions:
// ******************************************
// 1. Figure out this plugin's directory:
char curDirAndFile[1024];
#ifdef _WIN32
_getcwd(curDirAndFile, sizeof(curDirAndFile));
#elif defined (__linux) || defined (__APPLE__)
getcwd(curDirAndFile, sizeof(curDirAndFile));
#endif
std::string currentDirAndPath(curDirAndFile);
// 2. Append the V-REP library's name:
std::string temp(currentDirAndPath);
#ifdef _WIN32
temp+="/v_rep.dll";
#elif defined (__linux)
temp+="/libv_rep.so";
#elif defined (__APPLE__)
temp+="/libv_rep.dylib";
#endif /* __linux || __APPLE__ */
// 3. Load the V-REP library:
vrepLib=loadVrepLibrary(temp.c_str());
if (vrepLib==NULL)
{
std::cout << "Error, could not find or correctly load the V-REP library. Cannot start 'Lanelets' plugin.\n";
return(0); // Means error, V-REP will unload this plugin
}
if (getVrepProcAddresses(vrepLib)==0)
{
std::cout << "Error, could not find all required functions in the V-REP library. Cannot start 'Lanelets' plugin.\n";
unloadVrepLibrary(vrepLib);
return(0); // Means error, V-REP will unload this plugin
}
// ******************************************
// Check the version of V-REP:
// ******************************************
int vrepVer;
simGetIntegerParameter(sim_intparam_program_version,&vrepVer);
if (vrepVer<30200) // if V-REP version is smaller than 3.02.00
{
std::cout << "Sorry, your V-REP copy is somewhat old. Cannot start 'Lanelets' plugin.\n";
unloadVrepLibrary(vrepLib);
return(0); // Means error, V-REP will unload this plugin
}
// ******************************************
// Check if V-REP runs in headless mode:
// ******************************************
if (simGetBooleanParameter(sim_boolparam_headless)>0)
{
std::cout << "V-REP runs in headless mode. Cannot start 'Lanelets' plugin.\n";
unloadVrepLibrary(vrepLib);
return(0); // Means error, V-REP will unload this plugin
}
// ******************************************
QWidget* pMainWindow = (QWidget*)simGetMainWindow(1);
laneletsDialog = new laneletsdialog(pMainWindow); // The plugin dialog
simAddModuleMenuEntry("",1,&laneletsDialog->dialogMenuItemHandle);
simSetModuleMenuItemState(laneletsDialog->dialogMenuItemHandle,1,"Lanelets import...");
return(PLUGIN_VERSION); // initialization went fine, we return the version number of this plugin (can be queried with simGetModuleName)
}
// This is the plugin end routine (called just once, when V-REP is ending, i.e. releasing this plugin):
VREP_DLLEXPORT void v_repEnd()
{
// Here you could handle various clean-up tasks
unloadVrepLibrary(vrepLib); // release the library
}
// This is the plugin messaging routine (i.e. V-REP calls this function very often, with various messages):
VREP_DLLEXPORT void* v_repMessage(int message,int* auxiliaryData,void* customData,int* replyData)
{ // This is called quite often. Just watch out for messages/events you want to handle
// Keep following 5 lines at the beginning and unchanged:
static bool refreshDlgFlag=true;
int errorModeSaved;
simGetIntegerParameter(sim_intparam_error_report_mode,&errorModeSaved);
simSetIntegerParameter(sim_intparam_error_report_mode,sim_api_errormessage_ignore);
void* retVal=NULL;
//---------------------------------- CALLBACKS ----------------------------------------
if (message==sim_message_eventcallback_refreshdialogs)
refreshDlgFlag=true; // V-REP dialogs were refreshed. Maybe a good idea to refresh this plugin's dialog too
if (message==sim_message_eventcallback_menuitemselected)
{ // A custom menu bar entry was selected..
if (auxiliaryData[0]==laneletsDialog->dialogMenuItemHandle)
laneletsDialog->makeVisible(!laneletsDialog->getVisible()); // Toggle visibility of the dialog
}
if (message==sim_message_eventcallback_instancepass)
{ // It is important to always correctly react to events in V-REP. This message is the most convenient way to do so:
laneletsDialog->setSimulationStopped(simGetSimulationState()==sim_simulation_stopped);
int flags=auxiliaryData[0];
bool sceneContentChanged=((flags&(1+2+4+8+16+32+64+256))!=0); // object erased, created, model or scene loaded, und/redo called, instance switched, or object scaled since last sim_message_eventcallback_instancepass message
bool instanceSwitched=((flags&64)!=0);
if (instanceSwitched)
{
// React to an instance switch here!!
}
if (sceneContentChanged)
{
refreshDlgFlag=true;
}
}
if ((message==sim_message_eventcallback_guipass)&&refreshDlgFlag)
{ // handle refresh of the plugin's dialog:
laneletsDialog->refresh(); // Refresh the dialog
refreshDlgFlag=false;
}
//-------------------------------- END CALLBACKS --------------------------------------
// Keep following unchanged:
simSetIntegerParameter(sim_intparam_error_report_mode,errorModeSaved); // restore previous settings
return(retVal);
}