32 #include <QKeySequence>
39 #include <MemoryX/gui-plugins/SceneEditor/gui/dialog/ui_SceneEditorConfigDialog.h>
44 loadSnapshotAction(new
OverrideAction(QIcon(
":/icons/document-open-folder.png"), tr(
"Load Snapshot"), this)),
45 saveSnapshotAction(new
OverrideAction(QIcon(
":/icons/document-save-5.ico"), tr(
"Save Snapshot"), this)),
46 openShortcutDialogAction(new
OverrideAction(QIcon(
":/images/keys.png"), tr(
"Keyboard Shortcuts"), this)),
47 openGroupEditorAction(new
OverrideAction(QIcon(
":/images/chain-pencil.png"), tr(
"Group Editor"), this)),
48 clearWorkingMemoryAction(new
OverrideAction(QIcon(
":/icons/dialog-close.ico"), tr(
"Clear Scene"), this)),
58 workingMemoryName =
"";
59 workingMemoryUpdatesTopic =
"";
60 objectInstancesSegmentName =
"";
64 connect(
this, SIGNAL(
connectComponent()),
this, SLOT(onConnectComponentQt()));
66 std::shared_ptr<gui::ShortcutController> shortcutController =
control->getShortcutController();
68 connect(loadSnapshotAction, SIGNAL(triggered()),
this, SLOT(openLoadSnapshotDialog()));
69 shortcutController->registerAction(
"General: Load Snapshot", loadSnapshotAction);
71 connect(saveSnapshotAction, SIGNAL(triggered()),
this, SLOT(openSaveSnapshotDialog()));
72 shortcutController->registerAction(
"General: Save Snapshot", saveSnapshotAction);
74 connect(openShortcutDialogAction, SIGNAL(triggered()),
this, SLOT(openShortcutDialog()));
75 shortcutController->registerAction(
"General: Edit Shortcuts", openShortcutDialogAction);
77 connect(openGroupEditorAction, SIGNAL(triggered()),
this, SLOT(openGroupEditorDialog()));
78 shortcutController->registerAction(
"General: Edit Groups", openGroupEditorAction);
80 connect(clearWorkingMemoryAction, SIGNAL(triggered()),
this, SLOT(clearScene()));
81 shortcutController->registerAction(
"General: Clear Scene", clearWorkingMemoryAction);
83 this->createLanguageMenu();
88 qobject_cast<gui::SceneEditorMainWindow*>(getWidget())->postDocking();
94 if (!settingsPath.isEmpty())
96 QSettings settings(settingsPath, QSettings::IniFormat);
98 QHash<QString, QKeySequence> shortcuts =
control->getShortcutController()->getAllShortcuts();
100 for (
auto it = shortcuts.begin(); it != shortcuts.end(); ++it)
102 settings.setValue(
"ShortcutController/shortcut/" + it.key(), it.value().toString());
105 settings.setValue(
"SceneEditorMainWindowController/language", languageSelection->itemData(languageSelection->currentIndex()));
124 usingProxy(workingMemoryName);
125 usingProxy(
"LongtermMemory");
126 usingProxy(priorMemoryName);
127 usingProxy(
"CommonStorage");
133 memoryx::LongtermMemoryInterfacePrx longtermMemoryPrx = getProxy<memoryx::LongtermMemoryInterfacePrx>(
"LongtermMemory");
134 memoryx::WorkingMemoryInterfacePrx workingMemoryPrx = getProxy<memoryx::WorkingMemoryInterfacePrx>(workingMemoryName);
135 memoryx::PriorKnowledgeInterfacePrx priorKnowledgePrx = getProxy<memoryx::PriorKnowledgeInterfacePrx>(priorMemoryName);
136 this->
control->getMemoryXController()->init(priorKnowledgePrx,
138 workingMemoryUpdatesTopic,
139 objectInstancesSegmentName,
142 getArmarXManager()->addObject(
control->getMemoryXController()->getWorkingMemoryController());
144 enableMainWidgetAsync(
true);
145 emit connectComponent();
150 shortcutDialog->close();
151 groupEditorDialog->close();
152 loadSnapshotDialog->close();
153 saveSnapshotDialog->close();
154 enableMainWidgetAsync(
false);
155 emit disconnectComponent();
158 void gui::SceneEditorMainWindowController::onConnectComponentQt()
160 qobject_cast<gui::SceneEditorMainWindow*>(getWidget())->onConnect();
161 customToolbar->setEnabled(
true);
164 void gui::SceneEditorMainWindowController::onDisconnectComponentQt()
166 qobject_cast<gui::SceneEditorMainWindow*>(getWidget())->onDisconnect();
167 customToolbar->setDisabled(
true);
175 connect(mainWindow, SIGNAL(languageChangedByUser()),
this, SLOT(slotLanguageChangedByUser()));
178 return qobject_cast<QWidget*>(mainWindow);
185 if (parent != customToolbar->parent())
187 customToolbar->setParent(parent);
190 return qobject_cast<QWidget*>(customToolbar);
193 customToolbar =
new QToolBar(parent);
194 customToolbar->setIconSize(QSize(16, 16));
196 customToolbar->addAction(loadSnapshotAction);
197 customToolbar->addAction(saveSnapshotAction);
198 customToolbar->addAction(openShortcutDialogAction);
199 customToolbar->addAction(openGroupEditorAction);
200 customToolbar->addAction(clearWorkingMemoryAction);
201 customToolbar->addWidget(languageSelection);
202 customToolbar->setDisabled(
true);
204 return qobject_cast<QWidget*>(customToolbar);
212 configDialog->setIceObjectName();
215 return qobject_cast<dialog::SceneEditorConfigDialog*>(configDialog);
220 workingMemoryName = configDialog->getWorkingMemoryName();
221 workingMemoryUpdatesTopic = configDialog->getWorkingMemoryUpdatesTopic();
222 objectInstancesSegmentName =
"objectInstances";
223 priorMemoryName = configDialog->getPriorMemoryName();
225 settingsPath = configDialog->getSettingsFilePath();
226 QSettings settings(settingsPath, QSettings::IniFormat);
227 QHash<QString, QKeySequence> shortcuts;
228 QStringList allKeys = settings.allKeys();
230 for (
auto it = allKeys.begin(); it != allKeys.end(); ++it)
232 if ((*it).startsWith(
"ShortcutController/shortcut/", Qt::CaseSensitivity::CaseSensitive))
234 shortcuts.insert((*it).replace(
"ShortcutController/shortcut/",
"", Qt::CaseSensitivity::CaseSensitive), QKeySequence(settings.value(*it).value<QString>()));
238 QString language = settings.value(
"SceneEditorMainWindowController/language", QString()).value<QString>();
240 for (
int i = 0; i < languageSelection->count(); ++i)
242 if (languageSelection->itemData(i) == language)
244 loadLanguage(language);
245 languageSelection->setCurrentIndex(i);
250 if (shortcuts.isEmpty())
252 shortcuts.insert(
"General: Clear Scene", QKeySequence(
"Ctrl+Shift+Del"));
253 shortcuts.insert(
"General: Edit Groups", QKeySequence(
"Ctrl+G"));
254 shortcuts.insert(
"General: Edit Shortcuts", QKeySequence(
"Ctrl+K"));
255 shortcuts.insert(
"General: Load Snapshot", QKeySequence(
"Ctrl+O"));
256 shortcuts.insert(
"General: Save Snapshot", QKeySequence(
"Ctrl+S"));
257 shortcuts.insert(
"Group Explorer: Add Selection to new group", QKeySequence(
"Ctrl+Shift++"));
258 shortcuts.insert(
"Object Explorer: Set Focus on Search Field", QKeySequence(
"Ctrl+Space"));
259 shortcuts.insert(
"Scene: Camera view all", QKeySequence(
"Shift+5"));
260 shortcuts.insert(
"Scene: Camera view from X", QKeySequence(
"Shift+3"));
261 shortcuts.insert(
"Scene: Camera view from Y", QKeySequence(
"Shift+7"));
262 shortcuts.insert(
"Scene: Camera view from Z", QKeySequence(
"Shift+1"));
263 shortcuts.insert(
"Scene: Camera view from negative X", QKeySequence(
"Ctrl+Shift+3"));
264 shortcuts.insert(
"Scene: Camera view from negative Y", QKeySequence(
"Ctrl+Shift+7"));
265 shortcuts.insert(
"Scene: Camera view from negative Z", QKeySequence(
"Ctrl+Shift+1"));
266 shortcuts.insert(
"Scene: Copy selection", QKeySequence(
"Ctrl+C"));
267 shortcuts.insert(
"Scene: Duplicate selection", QKeySequence(
"Ctrl+D"));
268 shortcuts.insert(
"Scene: Paste selection", QKeySequence(
"Ctrl+V"));
269 shortcuts.insert(
"Scene: Redo last Action", QKeySequence(
"Ctrl+Shift+Z"));
270 shortcuts.insert(
"Scene: Remove the selected Objects", QKeySequence(
"Del"));
271 shortcuts.insert(
"Scene: Select all or deselect all", QKeySequence(
"Ctrl+A"));
272 shortcuts.insert(
"Scene: Switch between Editor and Viewer Mode", QKeySequence(
"Z"));
273 shortcuts.insert(
"Scene: Switch to Editor Mode", QKeySequence(
"Shift+E"));
274 shortcuts.insert(
"Scene: Switch to Viewer Mode", QKeySequence(
"Shift+V"));
275 shortcuts.insert(
"Scene: Toggle Collision Meshes", QKeySequence(
"Shift+C"));
276 shortcuts.insert(
"Scene: Toggle Rotation Manipulator", QKeySequence(
"Shift+R"));
277 shortcuts.insert(
"Scene: Toggle Translation Manipulator", QKeySequence(
"Shift+T"));
278 shortcuts.insert(
"Scene: Undo last Action", QKeySequence(
"Ctrl+Z"));
279 shortcuts.insert(
"Scene: Reset rotation", QKeySequence(
"Alt+R"));
280 shortcuts.insert(
"Scene: Reset translation", QKeySequence(
"Alt+T"));
283 for (
auto it = shortcuts.begin(); it != shortcuts.end(); ++it)
285 control->getShortcutController()->updateShortcut(it.key(), it.value());
288 configDialog->getArmarXManager()->removeObjectBlocking(configDialog->getName());
291 void gui::SceneEditorMainWindowController::clearScene()
296 void gui::SceneEditorMainWindowController::openLoadSnapshotDialog()
298 loadSnapshotDialog->exec();
301 void gui::SceneEditorMainWindowController::openSaveSnapshotDialog()
303 saveSnapshotDialog->exec();
306 void gui::SceneEditorMainWindowController::openShortcutDialog()
308 shortcutDialog->exec();
311 void gui::SceneEditorMainWindowController::openGroupEditorDialog()
313 groupEditorDialog->exec();
316 void gui::SceneEditorMainWindowController::createLanguageMenu()
318 languageSelection =
new QComboBox();
320 connect(languageSelection, SIGNAL(currentIndexChanged(
int)),
this, SLOT(slotLanguageChanged(
int)));
322 QDir dir(
":/languages/");
323 QStringList fileNames = dir.entryList(QStringList(
"SceneEditorLanguages_*.qm"));
325 for (
int i = 0; i < fileNames.size(); ++i)
329 language = fileNames[i];
330 language.truncate(language.lastIndexOf(
'.'));
331 language.remove(0, language.indexOf(
'_') + 1);
333 QString languageName = QLocale(language).nativeLanguageName();
335 languageSelection->addItem(languageName, language);
338 QString defaultLocale = QLocale::system().name();
339 defaultLocale.truncate(defaultLocale.lastIndexOf(
'_'));
341 if (defaultLocale == language)
343 languageSelection->setCurrentIndex(languageSelection->count() - 1);
348 void gui::SceneEditorMainWindowController::switchTranslator(QTranslator& translator,
const QString&
filename,
const QString& directory)
351 qApp->removeTranslator(&translator);
354 if (translator.load(
filename, directory))
356 qApp->installTranslator(&translator);
360 void gui::SceneEditorMainWindowController::loadLanguage(
const QString& rLanguage)
362 if (m_currLang != rLanguage)
364 m_currLang = rLanguage;
365 QString languageFilePath = QString::fromStdString(
":/languages/");
367 switchTranslator(m_translator, QString(
"SceneEditorLanguages_%1.qm").arg(rLanguage), languageFilePath);
373 void gui::SceneEditorMainWindowController::slotLanguageChanged(
const int languageIndex)
375 if (languageIndex != -1)
377 QString language = this->languageSelection->itemData(languageIndex).toString();
378 this->loadLanguage(language);
383 void gui::SceneEditorMainWindowController::slotLanguageChangedByUser()
385 this->saveSnapshotDialog->retranslate();
386 this->loadSnapshotDialog->retranslate();
387 this->groupEditorDialog->retranslate();
388 this->shortcutDialog->retranslate();
390 this->openGroupEditorAction->setText(tr(
"Group Editor"));
391 this->openShortcutDialogAction->setText(tr(
"Keyboard Shortcuts"));
392 this->saveSnapshotAction->setText(tr(
"Save Snapshot"));
393 this->loadSnapshotAction->setText(tr(
"Load Snapshot"));
394 this->clearWorkingMemoryAction->setText(tr(
"Clear Scene"));