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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
#include <CGAL/Three/Three.h>
#include <QDockWidget>
#include <QMetaMethod>
#include <QAction>
#include <CGAL/Three/CGAL_Lab_plugin_interface.h>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QMessageBox>
#include "Messages_interface.h"
using namespace CGAL::Three;
QMainWindow* Three::s_mainwindow = nullptr;
Viewer_interface* Three::s_mainviewer = nullptr;
Viewer_interface* Three::s_currentviewer = nullptr;
Scene_interface* Three::s_scene = nullptr;
QObject* Three::s_connectable_scene = nullptr;
Three* Three::s_three = nullptr;
RenderingMode Three::s_defaultSMRM;
RenderingMode Three::s_defaultPSRM;
int Three::default_point_size;
int Three::default_normal_length;
int Three::default_lines_width;
bool Three::s_is_locked;
QMutex* Three::s_mutex;
QWaitCondition* Three::s_wait_condition;
QWaitCondition* Three::getWaitCondition()
{
return s_wait_condition;
}
QMutex* Three::getMutex()
{
return s_mutex;
}
QMainWindow* Three::mainWindow()
{
return s_mainwindow;
}
Viewer_interface* Three::mainViewer()
{
return s_mainviewer;
}
Viewer_interface* Three::currentViewer()
{
return s_currentviewer;
}
void Three::setCurrentViewer(Viewer_interface *viewer)
{
s_currentviewer = viewer;
}
Viewer_interface* Three::activeViewer()
{
QMdiArea *mdi = mainWindow()->findChild<QMdiArea*>();
if(!mdi || !mdi->activeSubWindow())
return mainViewer();
Viewer_interface* v = qobject_cast<Viewer_interface*>(mdi->activeSubWindow()->widget());
if(!v)
return mainViewer();
return v;
}
Scene_interface* Three::scene()
{
return s_scene;
}
QObject* Three::connectableScene()
{
return s_connectable_scene;
}
Three::Three()
{
Three::s_three = this;
}
template<class SceneType>
SceneType* Three::getSelectedItem(){
for(int item_id : scene()->selectionIndices())
{
SceneType* scene_item = qobject_cast<SceneType*>(scene()->item(item_id));
if(scene_item)
return scene_item;
}
return NULL;
}
void Three::addDockWidget(QDockWidget* dock_widget)
{
mainWindow()->addDockWidget(::Qt::LeftDockWidgetArea, dock_widget);
dock_widget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
QList<QDockWidget*> dockWidgets = mainWindow()->findChildren<QDockWidget*>();
int counter = 0;
for(QDockWidget* dock : dockWidgets) {
if( mainWindow()->dockWidgetArea(dock) != ::Qt::LeftDockWidgetArea ||
dock == dock_widget )
{ continue; }
if(++counter > 1) {
mainWindow()->tabifyDockWidget(dock, dock_widget);
return;
}
}
}
void Three::autoConnectActions(CGAL_Lab_plugin_interface *plugin)
{
QObject* thisObject = dynamic_cast<QObject*>(plugin);
if(!thisObject)
return;
const QMetaObject* metaObject = thisObject->metaObject();
QVector<QMetaMethod> methods;
QVector<QString> methodsNames;
QSet<QString> connected;
for(int i = metaObject->methodOffset();
i < metaObject->methodCount();
++i)
{
const int pos = QString(metaObject->method(i).methodSignature()).indexOf('(');
methodsNames << QString(metaObject->method(i).methodSignature()).left(pos);
methods << metaObject->method(i);
}
for(QAction* action : plugin->actions())
{
bool success = false;
const QMetaObject* action_metaObject = action->metaObject();
for(int i = action_metaObject->methodOffset();
i < action_metaObject->methodCount(); ++i)
{
QMetaMethod action_method = action_metaObject->method(i);
if(action_method.methodType() == QMetaMethod::Signal)
{
const int pos = QString(action_method.methodSignature()).indexOf('(');
QString methodName = QString(action_method.methodSignature()).left(pos);
QString slotName =
QString("on_%1_%2").arg(action->objectName()).arg(methodName);
// qDebug() << thisObject->tr("Slot %1 (%2)...").arg(slotName).arg(i);
int index = methodsNames.indexOf(slotName);
if(index>=0 && !connected.contains(slotName))
{
const bool ok = QObject::connect(action,
qPrintable(QString("2%1").arg(QString(action_method.methodSignature()))),
thisObject,
qPrintable(QString("1%1").arg(QString(methods[index].methodSignature()))));
if(!ok)
{
qDebug() << thisObject->tr("Cannot connect method %1.%2 to slot %3!")
.arg(action->objectName())
.arg(QString(action_method.methodSignature()))
.arg(QString(methods[index].methodSignature()));
}
else {
success = true;
connected << slotName;
}
}
}
} // end for each method of action
if(!success)
qDebug("ERROR: Failed to autoconnect the action \"%s\"!",
action->objectName().toUtf8().data());
} // end foreach action of actions()
}
void Three::information(QString s)
{
qobject_cast<Messages_interface*>(mainWindow())->message_information(s);
}
void Three::warning(QString s)
{
qobject_cast<Messages_interface*>(mainWindow())->message_warning(s);
}
void Three::error(QString s)
{
qobject_cast<Messages_interface*>(mainWindow())->message_error(s);
}
void Three::information(QString title, QString s)
{
QMessageBox::information(mainWindow(), title, s);
}
void Three::warning(QString title, QString s)
{
QMessageBox::warning(mainWindow(), title, s);
}
void Three::error(QString title, QString s)
{
QMessageBox::critical(mainWindow(), title, s);
}
RenderingMode Three::defaultSurfaceMeshRenderingMode()
{
return s_defaultSMRM;
}
RenderingMode Three::defaultPointSetRenderingMode()
{
return s_defaultPSRM;
}
QString Three::modeName(RenderingMode mode) {
switch(mode)
{
case Points:
return QObject::tr("points");
case ShadedPoints:
return QObject::tr("shaded points");
case Wireframe:
return QObject::tr("wire");
case Flat:
return QObject::tr("flat");
case FlatPlusEdges:
return QObject::tr("flat+edges");
case Gouraud:
return QObject::tr("Gouraud");
case PointsPlusNormals:
return QObject::tr("pts+normals");
case GouraudPlusEdges:
return QObject::tr("gouraud+edges");
default:
Q_ASSERT(false);
return QObject::tr("unknown");
}
}
RenderingMode Three::modeFromName(QString name) {
if(name == "points")
return Points;
if(name == "shaded points")
return ShadedPoints;
if(name == "wire")
return Wireframe;
if(name == "flat")
return Flat;
if(name == "flat+edges")
return FlatPlusEdges;
if(name == "Gouraud")
return Gouraud;
if(name == "pts+normals")
return PointsPlusNormals;
Q_ASSERT(false);
return Points;
}
int Three::getDefaultPointSize()
{
return default_point_size;
}
int Three::getDefaultNormalLength()
{
return default_normal_length;
}
int Three::getDefaultLinesWidth()
{
return default_lines_width;
}
bool& Three::isLocked()
{
return s_is_locked;
}
|