Debian Codegraph @

src/Gui/CommandView.cpp

raw
1 /***************************************************************************
2 * Copyright (c) 2002 Jürgen Riegel <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #include <sstream>
24 #include <Inventor/events/SoMouseButtonEvent.h>
25 #include <Inventor/nodes/SoOrthographicCamera.h>
26 #include <Inventor/nodes/SoPerspectiveCamera.h>
27 #include <Inventor/SoPickedPoint.h>
28 #include <QApplication>
29 #include <QDialog>
30 #include <QDomDocument>
31 #include <QDomElement>
32 #include <QFile>
33 #include <QFileInfo>
34 #include <QFont>
35 #include <QFontMetrics>
36 #include <QImageReader>
37 #include <QMessageBox>
38 #include <QPainter>
39 #include <QPointer>
40 #include <QTextStream>
41
42 #include <App/ComplexGeoDataPy.h>
43 #include <App/Document.h>
44 #include <App/DocumentObject.h>
45 #include <App/DocumentObjectGroup.h>
46 #include <App/DocumentObserver.h>
47 #include <App/GeoFeature.h>
48 #include <App/GeoFeatureGroupExtension.h>
49 #include <App/Part.h>
50 #include <App/Link.h>
51 #include <Base/Console.h>
52 #include <Base/Parameter.h>
53 #include <Base/Tools.h>
54
55 #include "Command.h"
56 #include "Action.h"
57 #include "Application.h"
58 #include "BitmapFactory.h"
59 #include "Control.h"
60 #include "Clipping.h"
61 #include "DemoMode.h"
62 #include "Dialogs/DlgSettingsImageImp.h"
63 #include "Document.h"
64 #include "FileDialog.h"
65 #include "ImageView.h"
66 #include "Inventor/SoAxisCrossKit.h"
67 #include "Macro.h"
68 #include "MainWindow.h"
69 #include "Navigation/NavigationStyle.h"
70 #include "OverlayParams.h"
71 #include "OverlayManager.h"
72 #include "SceneInspector.h"
73 #include "Selection.h"
74 #include "Selection/SelectionView.h"
75 #include "SelectionObject.h"
76 #include "SoFCOffscreenRenderer.h"
77 #include "TextureMapping.h"
78 #include "Tools.h"
79 #include "Tree.h"
80 #include "TreeParams.h"
81 #include "Utilities.h"
82 #include "View3DInventor.h"
83 #include "View3DInventorViewer.h"
84 #include "ViewParams.h"
85 #include "ViewProviderGeometryObject.h"
86 #include "WaitCursor.h"
87
88 using namespace Gui;
89 using Gui::Dialog::DlgSettingsImageImp;
90 namespace sp = std::placeholders;
91
92 namespace
93 {
94 // A helper class to open a transaction when changing properties of view providers.
95 // It uses the same parameter key as the PropertyView to control the behaviour.
96 class TransactionView
97 {
98 Gui::Document* document;
99
100 public:
101 static bool getDefault()
102 {
103 auto hGrp = App::GetApplication().GetParameterGroupByPath(
104 "User parameter:BaseApp/Preferences/PropertyView"
105 );
106 return hGrp->GetBool("AutoTransactionView", false);
107 }
108 TransactionView(Gui::Document* doc, const char* name, bool enable = getDefault())
109 : document(doc)
110 {
111 if (document && enable) {
112 document->openCommand(name);
113 }
114 else {
115 document = nullptr;
116 }
117 }
118
119 ~TransactionView()
120 {
121 if (document) {
122 document->commitCommand();
123 }
124 }
125 };
126 } // namespace
127
128 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
129
130 DEF_STD_CMD_AC(StdOrthographicCamera)
131
132 StdOrthographicCamera::StdOrthographicCamera()
133 : Command("Std_OrthographicCamera")
134 {
135 sGroup = "Standard-View";
136 sMenuText = QT_TR_NOOP("Orthographic View");
137 sToolTipText = QT_TR_NOOP("Switches to orthographic view mode");
138 sWhatsThis = "Std_OrthographicCamera";
139 sStatusTip = sToolTipText;
140 sPixmap = "view-isometric";
141 sAccel = "V, O";
142 eType = Alter3DView;
143 }
144
145 void StdOrthographicCamera::activated(int iMsg)
146 {
147 if (iMsg == 1) {
148 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
149 SoCamera* cam = view->getViewer()->getSoRenderManager()->getCamera();
150 if (!cam || cam->getTypeId() != SoOrthographicCamera::getClassTypeId()) {
151
152 doCommand(Command::Gui, "Gui.activeDocument().activeView().setCameraType(\"Orthographic\")");
153 }
154 }
155 }
156
157 bool StdOrthographicCamera::isActive()
158 {
159 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
160 if (view) {
161 // update the action group if needed
162 bool check = _pcAction->isChecked();
163 SoCamera* cam = view->getViewer()->getSoRenderManager()->getCamera();
164 bool mode = cam ? cam->getTypeId() == SoOrthographicCamera::getClassTypeId() : false;
165
166 if (mode != check) {
167 _pcAction->setChecked(mode);
168 }
169 return true;
170 }
171
172 return false;
173 }
174
175 Action* StdOrthographicCamera::createAction()
176 {
177 Action* pcAction = Command::createAction();
178 pcAction->setCheckable(true);
179 return pcAction;
180 }
181
182 DEF_STD_CMD_AC(StdPerspectiveCamera)
183
184 StdPerspectiveCamera::StdPerspectiveCamera()
185 : Command("Std_PerspectiveCamera")
186 {
187 sGroup = "Standard-View";
188 sMenuText = QT_TR_NOOP("Perspective View");
189 sToolTipText = QT_TR_NOOP("Switches to perspective view mode");
190 sWhatsThis = "Std_PerspectiveCamera";
191 sStatusTip = sToolTipText;
192 sPixmap = "view-perspective";
193 sAccel = "V, P";
194 eType = Alter3DView;
195 }
196
197 void StdPerspectiveCamera::activated(int iMsg)
198 {
199 if (iMsg == 1) {
200 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
201 SoCamera* cam = view->getViewer()->getSoRenderManager()->getCamera();
202 if (!cam || cam->getTypeId() != SoPerspectiveCamera::getClassTypeId()) {
203
204 doCommand(Command::Gui, "Gui.activeDocument().activeView().setCameraType(\"Perspective\")");
205 }
206 }
207 }
208
209 bool StdPerspectiveCamera::isActive()
210 {
211 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
212 if (view) {
213 // update the action group if needed
214 bool check = _pcAction->isChecked();
215 SoCamera* cam = view->getViewer()->getSoRenderManager()->getCamera();
216 bool mode = cam ? cam->getTypeId() == SoPerspectiveCamera::getClassTypeId() : false;
217
218 if (mode != check) {
219 _pcAction->setChecked(mode);
220 }
221
222 return true;
223 }
224
225 return false;
226 }
227
228 Action* StdPerspectiveCamera::createAction()
229 {
230 Action* pcAction = Command::createAction();
231 pcAction->setCheckable(true);
232 return pcAction;
233 }
234
235 //===========================================================================
236
237 // The two commands below are provided for convenience so that they can be bound
238 // to a button of a spacemouse
239
240 //===========================================================================
241 // Std_ViewSaveCamera
242 //===========================================================================
243
244 DEF_3DV_CMD(StdCmdViewSaveCamera)
245
246 StdCmdViewSaveCamera::StdCmdViewSaveCamera()
247 : Command("Std_ViewSaveCamera")
248 {
249 sGroup = "Standard-View";
250 sMenuText = QT_TR_NOOP("Save Current Camera");
251 sToolTipText = QT_TR_NOOP("Saves the current camera settings");
252 sStatusTip = sToolTipText;
253 sWhatsThis = "Std_ViewSaveCamera";
254 eType = Alter3DView;
255 }
256
257 void StdCmdViewSaveCamera::activated(int iMsg)
258 {
259 Q_UNUSED(iMsg);
260
261 auto view = qobject_cast<Gui::View3DInventor*>(Gui::getMainWindow()->activeWindow());
262 if (view) {
263 view->getViewer()->saveHomePosition();
264 }
265 }
266
267 //===========================================================================
268 // Std_ViewRestoreCamera
269 //===========================================================================
270 DEF_3DV_CMD(StdCmdViewRestoreCamera)
271
272 StdCmdViewRestoreCamera::StdCmdViewRestoreCamera()
273 : Command("Std_ViewRestoreCamera")
274 {
275 sGroup = "Standard-View";
276 sMenuText = QT_TR_NOOP("Restore Saved Camera");
277 sToolTipText = QT_TR_NOOP("Restores the saved camera settings");
278 sStatusTip = sToolTipText;
279 sWhatsThis = "Std_ViewRestoreCamera";
280 eType = Alter3DView;
281 }
282
283 void StdCmdViewRestoreCamera::activated(int iMsg)
284 {
285 Q_UNUSED(iMsg);
286
287 auto view = qobject_cast<Gui::View3DInventor*>(Gui::getMainWindow()->activeWindow());
288 if (view) {
289 view->getViewer()->resetToHomePosition();
290 }
291 }
292
293 //===========================================================================
294 // Std_FreezeViews
295 //===========================================================================
296 class StdCmdFreezeViews: public Gui::Command
297 {
298 public:
299 StdCmdFreezeViews();
300 ~StdCmdFreezeViews() override = default;
301 const char* className() const override
302 {
303 return "StdCmdFreezeViews";
304 }
305
306 void setShortcut(const QString&) override;
307 QString getShortcut() const override;
308
309 protected:
310 void activated(int iMsg) override;
311 bool isActive() override;
312 Action* createAction() override;
313 void languageChange() override;
314
315 private:
316 void onSaveViews();
317 void onRestoreViews();
318
319 private:
320 const int maxViews {50};
321 int savedViews {0};
322 int offset {0};
323 QAction* saveView {nullptr};
324 QAction* freezeView {nullptr};
325 QAction* clearView {nullptr};
326 QAction* separator {nullptr};
327 };
328
329 StdCmdFreezeViews::StdCmdFreezeViews()
330 : Command("Std_FreezeViews")
331 {
332 sGroup = "Standard-View";
333 sMenuText = QT_TR_NOOP("F&reeze Display");
334 sToolTipText = QT_TR_NOOP("Freezes the current view position");
335 sWhatsThis = "Std_FreezeViews";
336 sStatusTip = sToolTipText;
337 sAccel = "Shift+F";
338 eType = Alter3DView;
339 }
340
341 Action* StdCmdFreezeViews::createAction()
342 {
343 auto pcAction = new ActionGroup(this, getMainWindow());
344 pcAction->setDropDownMenu(true);
345 applyCommandData(this->className(), pcAction);
346
347 // add the action items
348 saveView = pcAction->addAction(QObject::tr("&Save Views…"));
349 saveView->setWhatsThis(QString::fromLatin1(getWhatsThis()));
350 QAction* loadView = pcAction->addAction(QObject::tr("&Load Views…"));
351 loadView->setWhatsThis(QString::fromLatin1(getWhatsThis()));
352 pcAction->addAction(QStringLiteral(""))->setSeparator(true);
353 freezeView = pcAction->addAction(QObject::tr("F&reeze View"));
354 freezeView->setShortcut(QString::fromLatin1(getAccel()));
355 freezeView->setWhatsThis(QString::fromLatin1(getWhatsThis()));
356 clearView = pcAction->addAction(QObject::tr("&Clear Views"));
357 clearView->setWhatsThis(QString::fromLatin1(getWhatsThis()));
358 separator = pcAction->addAction(QStringLiteral(""));
359 separator->setSeparator(true);
360 offset = pcAction->actions().count();
361
362 // allow up to 50 views
363 for (int i = 0; i < maxViews; i++) {
364 pcAction->addAction(QStringLiteral(""))->setVisible(false);
365 }
366
367 return pcAction;
368 }
369
370 void StdCmdFreezeViews::setShortcut(const QString& shortcut)
371 {
372 if (freezeView) {
373 freezeView->setShortcut(shortcut);
374 }
375 }
376
377 QString StdCmdFreezeViews::getShortcut() const
378 {
379 if (freezeView) {
380 return freezeView->shortcut().toString();
381 }
382 return Command::getShortcut();
383 }
384
385 void StdCmdFreezeViews::activated(int iMsg)
386 {
387 auto pcAction = qobject_cast<ActionGroup*>(_pcAction);
388
389 if (iMsg == 0) {
390 onSaveViews();
391 }
392 else if (iMsg == 1) {
393 onRestoreViews();
394 }
395 else if (iMsg == 3) {
396 // Create a new view
397 const char* ppReturn = nullptr;
398 getGuiApplication()->sendMsgToActiveView("GetCamera", &ppReturn);
399
400 QList<QAction*> acts = pcAction->actions();
401 int index = 1;
402 for (QList<QAction*>::Iterator it = acts.begin() + offset; it != acts.end(); ++it, index++) {
403 if (!(*it)->isVisible()) {
404 savedViews++;
405 QString viewnr = QString(QObject::tr("Restore view &%1")).arg(index);
406 (*it)->setText(viewnr);
407 (*it)->setToolTip(QString::fromLatin1(ppReturn));
408 (*it)->setVisible(true);
409 if (index < 10) {
410 (*it)->setShortcut(QKeySequence(QStringLiteral("CTRL+%1").arg(index)));
411 }
412 break;
413 }
414 }
415 }
416 else if (iMsg == 4) {
417 savedViews = 0;
418 QList<QAction*> acts = pcAction->actions();
419 for (QList<QAction*>::Iterator it = acts.begin() + offset; it != acts.end(); ++it) {
420 (*it)->setVisible(false);
421 }
422 }
423 else if (iMsg >= offset) {
424 // Activate a view
425 QList<QAction*> acts = pcAction->actions();
426 QString data = acts[iMsg]->toolTip();
427 QString send = QStringLiteral("SetCamera %1").arg(data);
428 getGuiApplication()->sendMsgToActiveView(send.toLatin1());
429 }
430 }
431
432 void StdCmdFreezeViews::onSaveViews()
433 {
434 // Save the views to an XML file
435 QString fn = FileDialog::getSaveFileName(
436 getMainWindow(),
437 QObject::tr("Save frozen views"),
438 QString(),
439 QStringLiteral("%1 (*.cam)").arg(QObject::tr("Frozen views"))
440 );
441 if (fn.isEmpty()) {
442 return;
443 }
444 QFile file(fn);
445 if (file.open(QFile::WriteOnly)) {
446 QTextStream str(&file);
447 auto pcAction = qobject_cast<ActionGroup*>(_pcAction);
448 QList<QAction*> acts = pcAction->actions();
449 str << "<?xml version='1.0' encoding='utf-8'?>\n"
450 << "<FrozenViews SchemaVersion=\"1\">\n";
451 str << " <Views Count=\"" << savedViews << "\">\n";
452
453 for (QList<QAction*>::Iterator it = acts.begin() + offset; it != acts.end(); ++it) {
454 if (!(*it)->isVisible()) {
455 break;
456 }
457 QString data = (*it)->toolTip();
458
459 // remove the first line because it's a comment like '#Inventor V2.1 ascii'
460 QString viewPos;
461 if (!data.isEmpty()) {
462 QStringList lines = data.split(QStringLiteral("\n"));
463 if (lines.size() > 1) {
464 lines.pop_front();
465 }
466 viewPos = lines.join(QStringLiteral(" "));
467 }
468
469 str << " <Camera settings=\"" << viewPos.toLatin1().constData() << "\"/>\n";
470 }
471
472 str << " </Views>\n";
473 str << "</FrozenViews>\n";
474 }
475 }
476
477 void StdCmdFreezeViews::onRestoreViews()
478 {
479 // Should we clear the already saved views
480 if (savedViews > 0) {
481 auto ret = QMessageBox::question(
482 getMainWindow(),
483 QObject::tr("Restore views"),
484 QObject::tr(
485 "Importing the restored views would clear the already stored views.\n"
486 "Continue?"
487 ),
488 QMessageBox::Yes | QMessageBox::No,
489 QMessageBox::Yes
490 );
491 if (ret != QMessageBox::Yes) {
492 return;
493 }
494 }
495
496 // Restore the views from an XML file
497 QString fn = FileDialog::getOpenFileName(
498 getMainWindow(),
499 QObject::tr("Restore frozen views"),
500 QString(),
501 QStringLiteral("%1 (*.cam)").arg(QObject::tr("Frozen views"))
502 );
503 if (fn.isEmpty()) {
504 return;
505 }
506 QFile file(fn);
507 if (!file.open(QFile::ReadOnly)) {
508 QMessageBox::critical(
509 getMainWindow(),
510 QObject::tr("Restore views"),
511 QObject::tr("Cannot open file '%1'.").arg(fn)
512 );
513 return;
514 }
515
516 QDomDocument xmlDocument;
517
518 #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
519 if (const auto result
520 = xmlDocument.setContent(&file, QDomDocument::ParseOption::UseNamespaceProcessing);
521 !result) {
522 std::cerr << "Parse error in XML content at line " << result.errorLine << ", column "
523 << result.errorColumn << ": " << qPrintable(result.errorMessage) << std::endl;
524 return;
525 }
526 #else
527 QString errorStr;
528 int errorLine;
529 int errorColumn;
530
531 // evaluate the XML content
532 if (!xmlDocument.setContent(&file, true, &errorStr, &errorLine, &errorColumn)) {
533 std::cerr << "Parse error in XML content at line " << errorLine << ", column "
534 << errorColumn << ": " << (const char*)errorStr.toLatin1() << std::endl;
535 return;
536 }
537 #endif
538
539 // get the root element
540 QDomElement root = xmlDocument.documentElement();
541 if (root.tagName() != QLatin1String("FrozenViews")) {
542 std::cerr << "Unexpected XML structure" << std::endl;
543 return;
544 }
545
546 bool ok;
547 int scheme = root.attribute(QStringLiteral("SchemaVersion")).toInt(&ok);
548 if (!ok) {
549 return;
550 }
551 // SchemeVersion "1"
552 if (scheme == 1) {
553 // read the views, ignore the attribute 'Count'
554 QDomElement child = root.firstChildElement(QStringLiteral("Views"));
555 QDomElement views = child.firstChildElement(QStringLiteral("Camera"));
556 QStringList cameras;
557 while (!views.isNull()) {
558 QString setting = views.attribute(QStringLiteral("settings"));
559 cameras << setting;
560 views = views.nextSiblingElement(QStringLiteral("Camera"));
561 }
562
563 // use this rather than the attribute 'Count' because it could be
564 // changed from outside
565 int ct = cameras.count();
566 auto pcAction = qobject_cast<ActionGroup*>(_pcAction);
567 QList<QAction*> acts = pcAction->actions();
568
569 int numRestoredViews = std::min<int>(ct, acts.size() - offset);
570 savedViews = numRestoredViews;
571
572 if (numRestoredViews > 0) {
573 separator->setVisible(true);
574 }
575 for (int i = 0; i < numRestoredViews; i++) {
576 QString setting = cameras[i];
577 QString viewnr = QString(QObject::tr("Restore view &%1")).arg(i + 1);
578 acts[i + offset]->setText(viewnr);
579 acts[i + offset]->setToolTip(setting);
580 acts[i + offset]->setVisible(true);
581 if (i < 9) {
582 acts[i + offset]->setShortcut(QKeySequence(QStringLiteral("CTRL+%1").arg(i + 1)));
583 }
584 }
585
586 // if less views than actions
587 for (int index = numRestoredViews + offset; index < acts.count(); index++) {
588 acts[index]->setVisible(false);
589 }
590 }
591 }
592
593 bool StdCmdFreezeViews::isActive()
594 {
595 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
596 if (view) {
597 saveView->setEnabled(savedViews > 0);
598 freezeView->setEnabled(savedViews < maxViews);
599 clearView->setEnabled(savedViews > 0);
600 separator->setVisible(savedViews > 0);
601 return true;
602 }
603 else {
604 separator->setVisible(savedViews > 0);
605 }
606
607 return false;
608 }
609
610 void StdCmdFreezeViews::languageChange()
611 {
612 Command::languageChange();
613
614 if (!_pcAction) {
615 return;
616 }
617 auto pcAction = qobject_cast<ActionGroup*>(_pcAction);
618 QList<QAction*> acts = pcAction->actions();
619 acts[0]->setText(QObject::tr("&Save Views…"));
620 acts[1]->setText(QObject::tr("&Load Views…"));
621 acts[3]->setText(QObject::tr("F&reeze View"));
622 acts[4]->setText(QObject::tr("&Clear Views"));
623 int index = 1;
624 for (QList<QAction*>::Iterator it = acts.begin() + 5; it != acts.end(); ++it, index++) {
625 if ((*it)->isVisible()) {
626 QString viewnr = QString(QObject::tr("Restore View &%1")).arg(index);
627 (*it)->setText(viewnr);
628 }
629 }
630 }
631
632
633 //===========================================================================
634 // Std_ToggleClipPlane
635 //===========================================================================
636
637 DEF_STD_CMD_AC(StdCmdToggleClipPlane)
638
639 StdCmdToggleClipPlane::StdCmdToggleClipPlane()
640 : Command("Std_ToggleClipPlane")
641 {
642 sGroup = "Standard-View";
643 sMenuText = QT_TR_NOOP("Clippin&g View");
644 sToolTipText = QT_TR_NOOP("Toggles clipping of the active view");
645 sWhatsThis = "Std_ToggleClipPlane";
646 sStatusTip = sToolTipText;
647 sPixmap = "Std_ToggleClipPlane";
648 eType = Alter3DView;
649 }
650
651 Action* StdCmdToggleClipPlane::createAction()
652 {
653 Action* pcAction = Command::createAction();
654 return pcAction;
655 }
656
657 void StdCmdToggleClipPlane::activated(int iMsg)
658 {
659 Q_UNUSED(iMsg);
660 static QPointer<Gui::Dialog::Clipping> clipping = nullptr;
661 if (!clipping) {
662 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
663 if (view) {
664 clipping = Gui::Dialog::Clipping::makeDockWidget(view);
665 }
666 }
667 }
668
669 bool StdCmdToggleClipPlane::isActive()
670 {
671 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
672 return view ? true : false;
673 }
674
675 //===========================================================================
676 // StdCmdDrawStyle
677 //===========================================================================
678 class StdCmdDrawStyle: public Gui::Command
679 {
680 public:
681 StdCmdDrawStyle();
682 ~StdCmdDrawStyle() override = default;
683 void languageChange() override;
684 const char* className() const override
685 {
686 return "StdCmdDrawStyle";
687 }
688 void updateIcon(const Gui::MDIView* view);
689
690 protected:
691 void activated(int iMsg) override;
692 bool isActive() override;
693 Gui::Action* createAction() override;
694 };
695
696 StdCmdDrawStyle::StdCmdDrawStyle()
697 : Command("Std_DrawStyle")
698 {
699 sGroup = "Standard-View";
700 sMenuText = QT_TR_NOOP("&Draw Style");
701 sToolTipText = QT_TR_NOOP("Changes the draw style of the objects");
702 sStatusTip = sToolTipText;
703 sWhatsThis = "Std_DrawStyle";
704 sPixmap = "DrawStyleAsIs";
705 eType = Alter3DView;
706
707 this->getGuiApplication()->signalActivateView.connect([this](auto view) {
708 this->updateIcon(view);
709 });
710 }
711
712 Gui::Action* StdCmdDrawStyle::createAction()
713 {
714 auto pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
715 pcAction->setDropDownMenu(true);
716 pcAction->setIsMode(true);
717 applyCommandData(this->className(), pcAction);
718
719 QAction* a0 = pcAction->addAction(QString());
720 a0->setCheckable(true);
721 a0->setIcon(BitmapFactory().iconFromTheme("DrawStyleAsIs"));
722 a0->setChecked(true);
723 a0->setObjectName(QStringLiteral("Std_DrawStyleAsIs"));
724 a0->setShortcut(QKeySequence(QStringLiteral("V,1")));
725 a0->setWhatsThis(QString::fromLatin1(getWhatsThis()));
726 QAction* a1 = pcAction->addAction(QString());
727 a1->setCheckable(true);
728 a1->setIcon(BitmapFactory().iconFromTheme("DrawStylePoints"));
729 a1->setObjectName(QStringLiteral("Std_DrawStylePoints"));
730 a1->setShortcut(QKeySequence(QStringLiteral("V,2")));
731 a1->setWhatsThis(QString::fromLatin1(getWhatsThis()));
732 QAction* a2 = pcAction->addAction(QString());
733 a2->setCheckable(true);
734 a2->setIcon(BitmapFactory().iconFromTheme("DrawStyleWireFrame"));
735 a2->setObjectName(QStringLiteral("Std_DrawStyleWireframe"));
736 a2->setShortcut(QKeySequence(QStringLiteral("V,3")));
737 a2->setWhatsThis(QString::fromLatin1(getWhatsThis()));
738 QAction* a3 = pcAction->addAction(QString());
739 a3->setCheckable(true);
740 a3->setIcon(BitmapFactory().iconFromTheme("DrawStyleHiddenLine"));
741 a3->setObjectName(QStringLiteral("Std_DrawStyleHiddenLine"));
742 a3->setShortcut(QKeySequence(QStringLiteral("V,4")));
743 a3->setWhatsThis(QString::fromLatin1(getWhatsThis()));
744 QAction* a4 = pcAction->addAction(QString());
745 a4->setCheckable(true);
746 a4->setIcon(BitmapFactory().iconFromTheme("DrawStyleNoShading"));
747 a4->setObjectName(QStringLiteral("Std_DrawStyleNoShading"));
748 a4->setShortcut(QKeySequence(QStringLiteral("V,5")));
749 a4->setWhatsThis(QString::fromLatin1(getWhatsThis()));
750 QAction* a5 = pcAction->addAction(QString());
751 a5->setCheckable(true);
752 a5->setIcon(BitmapFactory().iconFromTheme("DrawStyleShaded"));
753 a5->setObjectName(QStringLiteral("Std_DrawStyleShaded"));
754 a5->setShortcut(QKeySequence(QStringLiteral("V,6")));
755 a5->setWhatsThis(QString::fromLatin1(getWhatsThis()));
756 QAction* a6 = pcAction->addAction(QString());
757 a6->setCheckable(true);
758 a6->setIcon(BitmapFactory().iconFromTheme("DrawStyleFlatLines"));
759 a6->setObjectName(QStringLiteral("Std_DrawStyleFlatLines"));
760 a6->setShortcut(QKeySequence(QStringLiteral("V,7")));
761 a6->setWhatsThis(QString::fromLatin1(getWhatsThis()));
762
763 pcAction->setIcon(a0->icon());
764
765 _pcAction = pcAction;
766 languageChange();
767 return pcAction;
768 }
769
770 void StdCmdDrawStyle::languageChange()
771 {
772 Command::languageChange();
773
774 if (!_pcAction) {
775 return;
776 }
777 auto pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
778 QList<QAction*> a = pcAction->actions();
779
780 a[0]->setText(QCoreApplication::translate("Std_DrawStyle", "&1 As is"));
781 a[0]->setToolTip(QCoreApplication::translate("Std_DrawStyle", "Normal mode"));
782
783 a[1]->setText(QCoreApplication::translate("Std_DrawStyle", "&2 Points"));
784 a[1]->setToolTip(QCoreApplication::translate("Std_DrawStyle", "Points mode"));
785
786 a[2]->setText(QCoreApplication::translate("Std_DrawStyle", "&3 Wireframe"));
787 a[2]->setToolTip(QCoreApplication::translate("Std_DrawStyle", "Wireframe mode"));
788
789 a[3]->setText(QCoreApplication::translate("Std_DrawStyle", "&4 Hidden line"));
790 a[3]->setToolTip(QCoreApplication::translate("Std_DrawStyle", "Hidden line mode"));
791
792 a[4]->setText(QCoreApplication::translate("Std_DrawStyle", "&5 No shading"));
793 a[4]->setToolTip(QCoreApplication::translate("Std_DrawStyle", "No shading mode"));
794
795 a[5]->setText(QCoreApplication::translate("Std_DrawStyle", "&6 Shaded"));
796 a[5]->setToolTip(QCoreApplication::translate("Std_DrawStyle", "Shaded mode"));
797
798 a[6]->setText(QCoreApplication::translate("Std_DrawStyle", "&7 Flat lines"));
799 a[6]->setToolTip(QCoreApplication::translate("Std_DrawStyle", "Flat lines mode"));
800 }
801
802 void StdCmdDrawStyle::updateIcon(const MDIView* view)
803 {
804 const auto view3d = dynamic_cast<const Gui::View3DInventor*>(view);
805 if (!view3d) {
806 return;
807 }
808 Gui::View3DInventorViewer* viewer = view3d->getViewer();
809 if (!viewer) {
810 return;
811 }
812 std::string mode(viewer->getOverrideMode());
813 auto actionGroup = dynamic_cast<Gui::ActionGroup*>(_pcAction);
814 if (!actionGroup) {
815 return;
816 }
817
818 if (mode == "Point") {
819 actionGroup->setCheckedAction(1);
820 return;
821 }
822 if (mode == "Wireframe") {
823 actionGroup->setCheckedAction(2);
824 return;
825 }
826 if (mode == "Hidden Line") {
827 actionGroup->setCheckedAction(3);
828 return;
829 }
830 if (mode == "No shading") {
831 actionGroup->setCheckedAction(4);
832 return;
833 }
834 if (mode == "Shaded") {
835 actionGroup->setCheckedAction(5);
836 return;
837 }
838 if (mode == "Flat Lines") {
839 actionGroup->setCheckedAction(6);
840 return;
841 }
842 actionGroup->setCheckedAction(0);
843 }
844
845 void StdCmdDrawStyle::activated(int iMsg)
846 {
847 Gui::Document* doc = this->getActiveGuiDocument();
848 std::list<MDIView*> views = doc->getMDIViews();
849 std::list<MDIView*>::iterator viewIt;
850 bool oneChangedSignal(false);
851 for (viewIt = views.begin(); viewIt != views.end(); ++viewIt) {
852 auto view = qobject_cast<View3DInventor*>(*viewIt);
853 if (view) {
854 View3DInventorViewer* viewer;
855 viewer = view->getViewer();
856 if (viewer) {
857 switch (iMsg) {
858 case 1:
859 (oneChangedSignal) ? viewer->updateOverrideMode("Point")
860 : viewer->setOverrideMode("Point");
861 break;
862 case 2:
863 (oneChangedSignal) ? viewer->updateOverrideMode("Wireframe")
864 : viewer->setOverrideMode("Wireframe");
865 break;
866 case 3:
867 (oneChangedSignal) ? viewer->updateOverrideMode("Hidden Line")
868 : viewer->setOverrideMode("Hidden Line");
869 break;
870 case 4:
871 (oneChangedSignal) ? viewer->updateOverrideMode("No Shading")
872 : viewer->setOverrideMode("No Shading");
873 break;
874 case 5:
875 (oneChangedSignal) ? viewer->updateOverrideMode("Shaded")
876 : viewer->setOverrideMode("Shaded");
877 break;
878 case 6:
879 (oneChangedSignal) ? viewer->updateOverrideMode("Flat Lines")
880 : viewer->setOverrideMode("Flat Lines");
881 break;
882 default:
883 (oneChangedSignal) ? viewer->updateOverrideMode("As Is")
884 : viewer->setOverrideMode("As Is");
885 break;
886 }
887 oneChangedSignal = true;
888 }
889 }
890 }
891 }
892
893 bool StdCmdDrawStyle::isActive()
894 {
895 return Gui::Application::Instance->activeDocument();
896 }
897
898 //===========================================================================
899 // Std_ToggleVisibility
900 //===========================================================================
901 DEF_STD_CMD_A(StdCmdToggleVisibility)
902
903 StdCmdToggleVisibility::StdCmdToggleVisibility()
904 : Command("Std_ToggleVisibility")
905 {
906 sGroup = "Standard-View";
907 sMenuText = QT_TR_NOOP("Toggle &Visibility");
908 sToolTipText = QT_TR_NOOP("Toggles the visibility of the selection");
909 sStatusTip = sToolTipText;
910 sWhatsThis = "Std_ToggleVisibility";
911 sPixmap = "Std_ToggleVisibility";
912 sAccel = "Space";
913 eType = Alter3DView;
914 }
915
916
917 void StdCmdToggleVisibility::activated(int iMsg)
918 {
919 Q_UNUSED(iMsg);
920 TransactionView transaction(
921 getActiveGuiDocument(),
922 QT_TRANSLATE_NOOP("Command", "Toggle Visibility")
923 );
924 Selection().setVisible(SelectionSingleton::VisToggle);
925 }
926
927 bool StdCmdToggleVisibility::isActive()
928 {
929 return (Gui::Selection().size() != 0);
930 }
931
932 //===========================================================================
933 // Std_ToggleTransparency
934 //===========================================================================
935 DEF_STD_CMD_A(StdCmdToggleTransparency)
936
937 StdCmdToggleTransparency::StdCmdToggleTransparency()
938 : Command("Std_ToggleTransparency")
939 {
940 sGroup = "Standard-View";
941 sMenuText = QT_TR_NOOP("Toggle Transparenc&y");
942 static std::string toolTip = std::string("<p>")
943 + QT_TR_NOOP("Toggles the transparency of the selected objects. Transparency "
944 "can be fine-tuned in the appearance task dialog")
945 + "</p>";
946 sToolTipText = toolTip.c_str();
947 sStatusTip = sToolTipText;
948 sWhatsThis = "Std_ToggleTransparency";
949 sPixmap = "Std_ToggleTransparency";
950 sAccel = "V,T";
951 eType = Alter3DView;
952 }
953
954 void StdCmdToggleTransparency::activated(int iMsg)
955 {
956 Q_UNUSED(iMsg);
957 getActiveGuiDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Toggle Transparency"));
958
959 std::vector<Gui::SelectionSingleton::SelObj> sels = Gui::Selection().getCompleteSelection();
960
961 std::vector<Gui::ViewProvider*> viewsToToggle = {};
962
963 for (Gui::SelectionSingleton::SelObj& sel : sels) {
964 App::DocumentObject* obj = sel.pObject;
965 if (!obj) {
966 continue;
967 }
968
969 bool isGroup = dynamic_cast<App::Part*>(obj) || dynamic_cast<App::LinkGroup*>(obj)
970 || dynamic_cast<App::DocumentObjectGroup*>(obj);
971
972 auto addObjects = [](App::DocumentObject* obj, std::vector<Gui::ViewProvider*>& views) {
973 App::Document* doc = obj->getDocument();
974 Gui::ViewProvider* view = Application::Instance->getDocument(doc)->getViewProvider(obj);
975 App::Property* prop = view->getPropertyByName("Transparency");
976 if (prop && prop->isDerivedFrom<App::PropertyInteger>()) {
977 // To prevent toggling the tip of a PD body (see #11353), we check if the parent has
978 // a Tip prop.
979 const std::vector<App::DocumentObject*> parents = obj->getInList();
980 if (!parents.empty()) {
981 App::Document* parentDoc = parents[0]->getDocument();
982 Gui::ViewProvider* parentView
983 = Application::Instance->getDocument(parentDoc)->getViewProvider(parents[0]);
984 App::Property* parentProp = parents[0]->getPropertyByName("Tip");
985 if (parentProp) {
986 // Make sure it has a transparency prop too
987 parentProp = parentView->getPropertyByName("Transparency");
988 if (parentProp && parentProp->isDerivedFrom<App::PropertyInteger>()) {
989 view = parentView;
990 }
991 }
992 }
993
994 if (std::ranges::find(views, view) == views.end()) {
995 views.push_back(view);
996 }
997 }
998 };
999
1000 if (isGroup) {
1001 for (App::DocumentObject* subobj : obj->getOutListRecursive()) {
1002 addObjects(subobj, viewsToToggle);
1003 }
1004 }
1005 else {
1006 addObjects(obj, viewsToToggle);
1007 }
1008 }
1009
1010 bool oneTransparent = false;
1011 for (auto* view : viewsToToggle) {
1012 App::Property* prop = view->getPropertyByName("Transparency");
1013 if (prop && prop->isDerivedFrom<App::PropertyInteger>()) {
1014 auto* transparencyProp = dynamic_cast<App::PropertyInteger*>(prop);
1015 int transparency = transparencyProp->getValue();
1016 if (transparency != 0) {
1017 oneTransparent = true;
1018 }
1019 }
1020 }
1021
1022 auto hGrp = App::GetApplication().GetParameterGroupByPath(
1023 "User parameter:BaseApp/Preferences/View"
1024 );
1025 int userTransparency = hGrp->GetInt("ToggleTransparency", 70);
1026
1027 int transparency = oneTransparent ? 0 : userTransparency;
1028
1029 for (auto* view : viewsToToggle) {
1030 App::Property* prop = view->getPropertyByName("Transparency");
1031 if (prop && prop->isDerivedFrom<App::PropertyInteger>()) {
1032 auto* transparencyProp = dynamic_cast<App::PropertyInteger*>(prop);
1033 transparencyProp->setValue(transparency);
1034 }
1035 }
1036
1037 getActiveGuiDocument()->commitCommand();
1038 }
1039
1040 bool StdCmdToggleTransparency::isActive()
1041 {
1042 return (Gui::Selection().size() != 0);
1043 }
1044
1045 //===========================================================================
1046 // Std_ToggleSelectability
1047 //===========================================================================
1048 DEF_STD_CMD_A(StdCmdToggleSelectability)
1049
1050 StdCmdToggleSelectability::StdCmdToggleSelectability()
1051 : Command("Std_ToggleSelectability")
1052 {
1053 sGroup = "Standard-View";
1054 sMenuText = QT_TR_NOOP("Toggle Se&lectability");
1055 sToolTipText = QT_TR_NOOP("Toggles the property of the objects to get selected in the 3D view");
1056 sStatusTip = sToolTipText;
1057 sWhatsThis = "Std_ToggleSelectability";
1058 sPixmap = "view-unselectable";
1059 eType = Alter3DView;
1060 }
1061
1062 void StdCmdToggleSelectability::activated(int iMsg)
1063 {
1064 Q_UNUSED(iMsg);
1065 // go through all documents
1066 const std::vector<App::Document*> docs = App::GetApplication().getDocuments();
1067 for (const auto& doc : docs) {
1068 Document* pcDoc = Application::Instance->getDocument(doc);
1069 std::vector<App::DocumentObject*> sel
1070 = Selection().getObjectsOfType(App::DocumentObject::getClassTypeId(), doc->getName());
1071
1072 if (sel.empty()) {
1073 continue;
1074 }
1075
1076 TransactionView transaction(pcDoc, QT_TRANSLATE_NOOP("Command", "Toggle Selectability"));
1077
1078 for (const auto& ft : sel) {
1079 ViewProvider* pr = pcDoc->getViewProviderByName(ft->getNameInDocument());
1080 if (pr && pr->isDerivedFrom<ViewProviderGeometryObject>()) {
1081 if (static_cast<ViewProviderGeometryObject*>(pr)->Selectable.getValue()) {
1082 doCommand(
1083 Gui,
1084 "Gui.getDocument(\"%s\").getObject(\"%s\").Selectable=False",
1085 doc->getName(),
1086 ft->getNameInDocument()
1087 );
1088 }
1089 else {
1090 doCommand(
1091 Gui,
1092 "Gui.getDocument(\"%s\").getObject(\"%s\").Selectable=True",
1093 doc->getName(),
1094 ft->getNameInDocument()
1095 );
1096 }
1097 }
1098 }
1099 }
1100 }
1101
1102 bool StdCmdToggleSelectability::isActive()
1103 {
1104 return (Gui::Selection().size() != 0);
1105 }
1106
1107 //===========================================================================
1108 // Std_ShowSelection
1109 //===========================================================================
1110 DEF_STD_CMD_A(StdCmdShowSelection)
1111
1112 StdCmdShowSelection::StdCmdShowSelection()
1113 : Command("Std_ShowSelection")
1114 {
1115 sGroup = "Standard-View";
1116 sMenuText = QT_TR_NOOP("Sho&w Selection");
1117 sToolTipText = QT_TR_NOOP("Shows all selected objects");
1118 sStatusTip = sToolTipText;
1119 sWhatsThis = "Std_ShowSelection";
1120 sPixmap = "Std_ShowSelection";
1121 eType = Alter3DView;
1122 }
1123
1124 void StdCmdShowSelection::activated(int iMsg)
1125 {
1126 Q_UNUSED(iMsg);
1127 Selection().setVisible(SelectionSingleton::VisShow);
1128 }
1129
1130 bool StdCmdShowSelection::isActive()
1131 {
1132 return (Gui::Selection().size() != 0);
1133 }
1134
1135 //===========================================================================
1136 // Std_HideSelection
1137 //===========================================================================
1138 DEF_STD_CMD_A(StdCmdHideSelection)
1139
1140 StdCmdHideSelection::StdCmdHideSelection()
1141 : Command("Std_HideSelection")
1142 {
1143 sGroup = "Standard-View";
1144 sMenuText = QT_TR_NOOP("&Hide Selection");
1145 sToolTipText = QT_TR_NOOP("Hides all selected objects");
1146 sStatusTip = sToolTipText;
1147 sWhatsThis = "Std_HideSelection";
1148 sPixmap = "Std_HideSelection";
1149 eType = Alter3DView;
1150 }
1151
1152 void StdCmdHideSelection::activated(int iMsg)
1153 {
1154 Q_UNUSED(iMsg);
1155 Selection().setVisible(SelectionSingleton::VisHide);
1156 }
1157
1158 bool StdCmdHideSelection::isActive()
1159 {
1160 return (Gui::Selection().size() != 0);
1161 }
1162
1163 //===========================================================================
1164 // Std_SelectVisibleObjects
1165 //===========================================================================
1166 DEF_STD_CMD_A(StdCmdSelectVisibleObjects)
1167
1168 StdCmdSelectVisibleObjects::StdCmdSelectVisibleObjects()
1169 : Command("Std_SelectVisibleObjects")
1170 {
1171 sGroup = "Standard-View";
1172 sMenuText = QT_TR_NOOP("&Select Visible Objects");
1173 sToolTipText = QT_TR_NOOP("Selects all visible objects in the active document");
1174 sStatusTip = sToolTipText;
1175 sWhatsThis = "Std_SelectVisibleObjects";
1176 sPixmap = "Std_SelectVisibleObjects";
1177 eType = Alter3DView;
1178 }
1179
1180 void StdCmdSelectVisibleObjects::activated(int iMsg)
1181 {
1182 Q_UNUSED(iMsg);
1183 // go through active document
1184 Gui::Document* doc = Application::Instance->activeDocument();
1185 App::Document* app = doc->getDocument();
1186 const std::vector<App::DocumentObject*> obj = app->getObjectsOfType(
1187 App::DocumentObject::getClassTypeId()
1188 );
1189
1190 std::vector<App::DocumentObject*> visible;
1191 visible.reserve(obj.size());
1192 for (const auto& it : obj) {
1193 if (doc->isShow(it->getNameInDocument())) {
1194 visible.push_back(it);
1195 }
1196 }
1197
1198 SelectionSingleton& rSel = Selection();
1199 rSel.setSelection(app->getName(), visible);
1200 }
1201
1202 bool StdCmdSelectVisibleObjects::isActive()
1203 {
1204 return App::GetApplication().getActiveDocument();
1205 }
1206
1207 //===========================================================================
1208 // Std_ToggleObjects
1209 //===========================================================================
1210 DEF_STD_CMD_A(StdCmdToggleObjects)
1211
1212 StdCmdToggleObjects::StdCmdToggleObjects()
1213 : Command("Std_ToggleObjects")
1214 {
1215 sGroup = "Standard-View";
1216 sMenuText = QT_TR_NOOP("To&ggle All Objects");
1217 sToolTipText = QT_TR_NOOP("Toggles the visibility of all objects in the active document");
1218 sStatusTip = sToolTipText;
1219 sWhatsThis = "Std_ToggleObjects";
1220 sPixmap = "Std_ToggleObjects";
1221 eType = Alter3DView;
1222 }
1223
1224 void StdCmdToggleObjects::activated(int iMsg)
1225 {
1226 Q_UNUSED(iMsg);
1227 // go through active document
1228 Gui::Document* doc = Application::Instance->activeDocument();
1229 App::Document* app = doc->getDocument();
1230 const std::vector<App::DocumentObject*> obj = app->getObjectsOfType(
1231 App::DocumentObject::getClassTypeId()
1232 );
1233
1234 for (const auto& it : obj) {
1235 if (doc->isShow(it->getNameInDocument())) {
1236 doCommand(
1237 Gui,
1238 "Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=False",
1239 app->getName(),
1240 it->getNameInDocument()
1241 );
1242 }
1243 else {
1244 doCommand(
1245 Gui,
1246 "Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=True",
1247 app->getName(),
1248 it->getNameInDocument()
1249 );
1250 }
1251 }
1252 }
1253
1254 bool StdCmdToggleObjects::isActive()
1255 {
1256 return App::GetApplication().getActiveDocument();
1257 }
1258
1259 //===========================================================================
1260 // Std_ShowObjects
1261 //===========================================================================
1262 DEF_STD_CMD_A(StdCmdShowObjects)
1263
1264 StdCmdShowObjects::StdCmdShowObjects()
1265 : Command("Std_ShowObjects")
1266 {
1267 sGroup = "Standard-View";
1268 sMenuText = QT_TR_NOOP("Show &All Objects");
1269 sToolTipText = QT_TR_NOOP("Shows all objects in the document");
1270 sStatusTip = sToolTipText;
1271 sWhatsThis = "Std_ShowObjects";
1272 sPixmap = "Std_ShowObjects";
1273 eType = Alter3DView;
1274 }
1275
1276 void StdCmdShowObjects::activated(int iMsg)
1277 {
1278 Q_UNUSED(iMsg);
1279 // go through active document
1280 Gui::Document* doc = Application::Instance->activeDocument();
1281 App::Document* app = doc->getDocument();
1282 const std::vector<App::DocumentObject*> obj = app->getObjectsOfType(
1283 App::DocumentObject::getClassTypeId()
1284 );
1285
1286 for (const auto& it : obj) {
1287 doCommand(
1288 Gui,
1289 "Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=True",
1290 app->getName(),
1291 it->getNameInDocument()
1292 );
1293 }
1294 }
1295
1296 bool StdCmdShowObjects::isActive()
1297 {
1298 return App::GetApplication().getActiveDocument();
1299 }
1300
1301 //===========================================================================
1302 // Std_HideObjects
1303 //===========================================================================
1304 DEF_STD_CMD_A(StdCmdHideObjects)
1305
1306 StdCmdHideObjects::StdCmdHideObjects()
1307 : Command("Std_HideObjects")
1308 {
1309 sGroup = "Standard-View";
1310 sMenuText = QT_TR_NOOP("Hide All &Objects");
1311 sToolTipText = QT_TR_NOOP("Hides all objects in the document");
1312 sStatusTip = sToolTipText;
1313 sWhatsThis = "Std_HideObjects";
1314 sPixmap = "Std_HideObjects";
1315 eType = Alter3DView;
1316 }
1317
1318 void StdCmdHideObjects::activated(int iMsg)
1319 {
1320 Q_UNUSED(iMsg);
1321 // go through active document
1322 Gui::Document* doc = Application::Instance->activeDocument();
1323 App::Document* app = doc->getDocument();
1324 const std::vector<App::DocumentObject*> obj = app->getObjectsOfType(
1325 App::DocumentObject::getClassTypeId()
1326 );
1327
1328 for (const auto& it : obj) {
1329 doCommand(
1330 Gui,
1331 "Gui.getDocument(\"%s\").getObject(\"%s\").Visibility=False",
1332 app->getName(),
1333 it->getNameInDocument()
1334 );
1335 }
1336 }
1337
1338 bool StdCmdHideObjects::isActive()
1339 {
1340 return App::GetApplication().getActiveDocument();
1341 }
1342
1343 //===========================================================================
1344 // Std_ViewHome
1345 //===========================================================================
1346 DEF_3DV_CMD(StdCmdViewHome)
1347
1348 StdCmdViewHome::StdCmdViewHome()
1349 : Command("Std_ViewHome")
1350 {
1351 sGroup = "Standard-View";
1352 sMenuText = QT_TR_NOOP("&Home");
1353 sToolTipText = QT_TR_NOOP("Sets the camera to the default home view");
1354 sWhatsThis = "Std_ViewHome";
1355 sStatusTip = sToolTipText;
1356 sPixmap = "Std_ViewHome";
1357 sAccel = "Home";
1358 eType = Alter3DView;
1359 }
1360
1361 void StdCmdViewHome::activated(int iMsg)
1362 {
1363 Q_UNUSED(iMsg);
1364
1365 auto hGrp = App::GetApplication().GetParameterGroupByPath(
1366 "User parameter:BaseApp/Preferences/View"
1367 );
1368 std::string default_view = hGrp->GetASCII("NewDocumentCameraOrientation", "Top");
1369 doCommand(
1370 Command::Gui,
1371 "Gui.activeDocument().activeView().viewDefaultOrientation('%s',0)",
1372 default_view.c_str()
1373 );
1374 doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
1375 }
1376
1377 //===========================================================================
1378 // Std_ViewBottom
1379 //===========================================================================
1380 DEF_3DV_CMD(StdCmdViewBottom)
1381
1382 StdCmdViewBottom::StdCmdViewBottom()
1383 : Command("Std_ViewBottom")
1384 {
1385 sGroup = "Standard-View";
1386 sMenuText = QT_TR_NOOP("&5 Bottom");
1387 sToolTipText = QT_TR_NOOP("Sets the camera to the bottom view");
1388 sWhatsThis = "Std_ViewBottom";
1389 sStatusTip = sToolTipText;
1390 sPixmap = "view-bottom";
1391 sAccel = "5";
1392 eType = Alter3DView;
1393 }
1394
1395 void StdCmdViewBottom::activated(int iMsg)
1396 {
1397 Q_UNUSED(iMsg);
1398 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewBottom()");
1399 }
1400
1401 //===========================================================================
1402 // Std_ViewFront
1403 //===========================================================================
1404 DEF_3DV_CMD(StdCmdViewFront)
1405
1406 StdCmdViewFront::StdCmdViewFront()
1407 : Command("Std_ViewFront")
1408 {
1409 sGroup = "Standard-View";
1410 sMenuText = QT_TR_NOOP("&1 Front");
1411 sToolTipText = QT_TR_NOOP("Sets the camera to the front view");
1412 sWhatsThis = "Std_ViewFront";
1413 sStatusTip = sToolTipText;
1414 sPixmap = "view-front";
1415 sAccel = "1";
1416 eType = Alter3DView;
1417 }
1418
1419 void StdCmdViewFront::activated(int iMsg)
1420 {
1421 Q_UNUSED(iMsg);
1422 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewFront()");
1423 }
1424
1425 //===========================================================================
1426 // Std_ViewLeft
1427 //===========================================================================
1428 DEF_3DV_CMD(StdCmdViewLeft)
1429
1430 StdCmdViewLeft::StdCmdViewLeft()
1431 : Command("Std_ViewLeft")
1432 {
1433 sGroup = "Standard-View";
1434 sMenuText = QT_TR_NOOP("&6 Left");
1435 sToolTipText = QT_TR_NOOP("Sets the camera to the left view");
1436 sWhatsThis = "Std_ViewLeft";
1437 sStatusTip = sToolTipText;
1438 sPixmap = "view-left";
1439 sAccel = "6";
1440 eType = Alter3DView;
1441 }
1442
1443 void StdCmdViewLeft::activated(int iMsg)
1444 {
1445 Q_UNUSED(iMsg);
1446 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewLeft()");
1447 }
1448
1449 //===========================================================================
1450 // Std_ViewRear
1451 //===========================================================================
1452 DEF_3DV_CMD(StdCmdViewRear)
1453
1454 StdCmdViewRear::StdCmdViewRear()
1455 : Command("Std_ViewRear")
1456 {
1457 sGroup = "Standard-View";
1458 sMenuText = QT_TR_NOOP("&4 Rear");
1459 sToolTipText = QT_TR_NOOP("Sets the camera to the rear view");
1460 sWhatsThis = "Std_ViewRear";
1461 sStatusTip = sToolTipText;
1462 sPixmap = "view-rear";
1463 sAccel = "4";
1464 eType = Alter3DView;
1465 }
1466
1467 void StdCmdViewRear::activated(int iMsg)
1468 {
1469 Q_UNUSED(iMsg);
1470 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewRear()");
1471 }
1472
1473 //===========================================================================
1474 // Std_ViewRight
1475 //===========================================================================
1476 DEF_3DV_CMD(StdCmdViewRight)
1477
1478 StdCmdViewRight::StdCmdViewRight()
1479 : Command("Std_ViewRight")
1480 {
1481 sGroup = "Standard-View";
1482 sMenuText = QT_TR_NOOP("&3 Right");
1483 sToolTipText = QT_TR_NOOP("Sets the camera to the right view");
1484 sWhatsThis = "Std_ViewRight";
1485 sStatusTip = sToolTipText;
1486 sPixmap = "view-right";
1487 sAccel = "3";
1488 eType = Alter3DView;
1489 }
1490
1491 void StdCmdViewRight::activated(int iMsg)
1492 {
1493 Q_UNUSED(iMsg);
1494 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewRight()");
1495 }
1496
1497 //===========================================================================
1498 // Std_ViewTop
1499 //===========================================================================
1500 DEF_3DV_CMD(StdCmdViewTop)
1501
1502 StdCmdViewTop::StdCmdViewTop()
1503 : Command("Std_ViewTop")
1504 {
1505 sGroup = "Standard-View";
1506 sMenuText = QT_TR_NOOP("&2 Top");
1507 sToolTipText = QT_TR_NOOP("Sets the camera to the top view");
1508 sWhatsThis = "Std_ViewTop";
1509 sStatusTip = sToolTipText;
1510 sPixmap = "view-top";
1511 sAccel = "2";
1512 eType = Alter3DView;
1513 }
1514
1515 void StdCmdViewTop::activated(int iMsg)
1516 {
1517 Q_UNUSED(iMsg);
1518 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewTop()");
1519 }
1520
1521
1522 //===========================================================================
1523 // Std_ViewIsometric
1524 //===========================================================================
1525 DEF_3DV_CMD(StdCmdViewIsometric)
1526
1527 StdCmdViewIsometric::StdCmdViewIsometric()
1528 : Command("Std_ViewIsometric")
1529 {
1530 sGroup = "Standard-View";
1531 sMenuText = QT_TR_NOOP("&Isometric");
1532 sToolTipText = QT_TR_NOOP("Sets the camera to the isometric view");
1533 sWhatsThis = "Std_ViewIsometric";
1534 sStatusTip = sToolTipText;
1535 sPixmap = "view-axonometric";
1536 sAccel = "0";
1537 eType = Alter3DView;
1538 }
1539
1540 void StdCmdViewIsometric::activated(int iMsg)
1541 {
1542 Q_UNUSED(iMsg);
1543 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewIsometric()");
1544 }
1545
1546 //===========================================================================
1547 // Std_ViewDimetric
1548 //===========================================================================
1549 DEF_3DV_CMD(StdCmdViewDimetric)
1550
1551 StdCmdViewDimetric::StdCmdViewDimetric()
1552 : Command("Std_ViewDimetric")
1553 {
1554 sGroup = "Standard-View";
1555 sMenuText = QT_TR_NOOP("&Dimetric");
1556 sToolTipText = QT_TR_NOOP("Sets the camera to the dimetric view");
1557 sWhatsThis = "Std_ViewDimetric";
1558 sStatusTip = sToolTipText;
1559 sPixmap = "Std_ViewDimetric";
1560 eType = Alter3DView;
1561 }
1562
1563 void StdCmdViewDimetric::activated(int iMsg)
1564 {
1565 Q_UNUSED(iMsg);
1566 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewDimetric()");
1567 }
1568
1569 //===========================================================================
1570 // Std_ViewTrimetric
1571 //===========================================================================
1572 DEF_3DV_CMD(StdCmdViewTrimetric)
1573
1574 StdCmdViewTrimetric::StdCmdViewTrimetric()
1575 : Command("Std_ViewTrimetric")
1576 {
1577 sGroup = "Standard-View";
1578 sMenuText = QT_TR_NOOP("&Trimetric");
1579 sToolTipText = QT_TR_NOOP("Sets the camera to the trimetric view");
1580 sWhatsThis = "Std_ViewTrimetric";
1581 sStatusTip = sToolTipText;
1582 sPixmap = "Std_ViewTrimetric";
1583 eType = Alter3DView;
1584 }
1585
1586 void StdCmdViewTrimetric::activated(int iMsg)
1587 {
1588 Q_UNUSED(iMsg);
1589 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewTrimetric()");
1590 }
1591
1592 //===========================================================================
1593 // Std_ViewRotateLeft
1594 //===========================================================================
1595 DEF_3DV_CMD(StdCmdViewRotateLeft)
1596
1597 StdCmdViewRotateLeft::StdCmdViewRotateLeft()
1598 : Command("Std_ViewRotateLeft")
1599 {
1600 sGroup = "Standard-View";
1601 sMenuText = QT_TR_NOOP("Rotate &Left");
1602 sToolTipText = QT_TR_NOOP("Rotates the view by 90\xc2\xb0 counter-clockwise");
1603 sWhatsThis = "Std_ViewRotateLeft";
1604 sStatusTip = sToolTipText;
1605 sPixmap = "view-rotate-left";
1606 sAccel = "Shift+Left";
1607 eType = Alter3DView;
1608 }
1609
1610 void StdCmdViewRotateLeft::activated(int iMsg)
1611 {
1612 Q_UNUSED(iMsg);
1613 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewRotateLeft()");
1614 }
1615
1616
1617 //===========================================================================
1618 // Std_ViewRotateRight
1619 //===========================================================================
1620 DEF_3DV_CMD(StdCmdViewRotateRight)
1621
1622 StdCmdViewRotateRight::StdCmdViewRotateRight()
1623 : Command("Std_ViewRotateRight")
1624 {
1625 sGroup = "Standard-View";
1626 sMenuText = QT_TR_NOOP("Rotates &Right");
1627 sToolTipText = QT_TR_NOOP("Rotates the view by 90\xc2\xb0 clockwise");
1628 sWhatsThis = "Std_ViewRotateRight";
1629 sStatusTip = sToolTipText;
1630 sPixmap = "view-rotate-right";
1631 sAccel = "Shift+Right";
1632 eType = Alter3DView;
1633 }
1634
1635 void StdCmdViewRotateRight::activated(int iMsg)
1636 {
1637 Q_UNUSED(iMsg);
1638 doCommand(Command::Gui, "Gui.activeDocument().activeView().viewRotateRight()");
1639 }
1640
1641
1642 //===========================================================================
1643 // Std_ViewFitAll
1644 //===========================================================================
1645 DEF_STD_CMD_A(StdCmdViewFitAll)
1646
1647 StdCmdViewFitAll::StdCmdViewFitAll()
1648 : Command("Std_ViewFitAll")
1649 {
1650 sGroup = "Standard-View";
1651 sMenuText = QT_TR_NOOP("&Fit All");
1652 sToolTipText = QT_TR_NOOP("Fits all content into the 3D view");
1653 sWhatsThis = "Std_ViewFitAll";
1654 sStatusTip = sToolTipText;
1655 sPixmap = "zoom-all";
1656 sAccel = "V, F";
1657 eType = Alter3DView;
1658 }
1659
1660 void StdCmdViewFitAll::activated(int iMsg)
1661 {
1662 Q_UNUSED(iMsg);
1663 // doCommand(Command::Gui,"Gui.activeDocument().activeView().fitAll()");
1664 doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
1665 }
1666
1667 bool StdCmdViewFitAll::isActive()
1668 {
1669 // return isViewOfType(Gui::View3DInventor::getClassTypeId());
1670 return getGuiApplication()->sendHasMsgToActiveView("ViewFit");
1671 }
1672
1673 //===========================================================================
1674 // Std_ViewFitSelection
1675 //===========================================================================
1676 DEF_STD_CMD_A(StdCmdViewFitSelection)
1677
1678 StdCmdViewFitSelection::StdCmdViewFitSelection()
1679 : Command("Std_ViewFitSelection")
1680 {
1681 sGroup = "Standard-View";
1682 sMenuText = QT_TR_NOOP("Fit &Selection");
1683 sToolTipText = QT_TR_NOOP("Fits the selected content into the 3D view");
1684 sWhatsThis = "Std_ViewFitSelection";
1685 sStatusTip = sToolTipText;
1686 sAccel = "V, S";
1687 sPixmap = "zoom-selection";
1688 eType = Alter3DView;
1689 }
1690
1691 void StdCmdViewFitSelection::activated(int iMsg)
1692 {
1693 Q_UNUSED(iMsg);
1694 doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"ViewSelection\")");
1695 }
1696
1697 bool StdCmdViewFitSelection::isActive()
1698 {
1699 return getGuiApplication()->sendHasMsgToActiveView("ViewSelection");
1700 }
1701
1702 //===========================================================================
1703 // Std_ViewCommandGroup
1704 //===========================================================================
1705 class StdCmdViewGroup: public Gui::GroupCommand
1706 {
1707 public:
1708 StdCmdViewGroup()
1709 : GroupCommand("Std_ViewGroup")
1710 {
1711 sGroup = "Standard-View";
1712 sMenuText = QT_TR_NOOP("Standard &Views");
1713 sToolTipText = QT_TR_NOOP("Changes to a standard view");
1714 sStatusTip = sToolTipText;
1715 sWhatsThis = "Std_ViewGroup";
1716 sPixmap = "view-isometric";
1717 eType = Alter3DView;
1718
1719 setCheckable(false);
1720 setRememberLast(true);
1721
1722 addCommand("Std_ViewIsometric");
1723 addCommand("Std_ViewFront");
1724 addCommand("Std_ViewTop");
1725 addCommand("Std_ViewRight");
1726 addCommand("Std_ViewRear");
1727 addCommand("Std_ViewBottom");
1728 addCommand("Std_ViewLeft");
1729 }
1730
1731 const char* className() const override
1732 {
1733 return "StdCmdViewGroup";
1734 }
1735
1736 bool isActive() override
1737 {
1738 return hasActiveDocument();
1739 }
1740 };
1741
1742 //===========================================================================
1743 // Std_ViewDock
1744 //===========================================================================
1745 DEF_STD_CMD_A(StdViewDock)
1746
1747 StdViewDock::StdViewDock()
1748 : Command("Std_ViewDock")
1749 {
1750 sGroup = "Standard-View";
1751 sMenuText = QT_TR_NOOP("&Docked");
1752 sToolTipText = QT_TR_NOOP(
1753 "Displays the active view either in fullscreen, undocked, or docked mode"
1754 );
1755 sWhatsThis = "Std_ViewDock";
1756 sStatusTip = sToolTipText;
1757 sAccel = "V, D";
1758 eType = Alter3DView;
1759 bCanLog = false;
1760 }
1761
1762 void StdViewDock::activated(int iMsg)
1763 {
1764 Q_UNUSED(iMsg);
1765 }
1766
1767 bool StdViewDock::isActive()
1768 {
1769 MDIView* view = getMainWindow()->activeWindow();
1770 return view != nullptr;
1771 }
1772
1773 //===========================================================================
1774 // Std_ViewUndock
1775 //===========================================================================
1776 DEF_STD_CMD_A(StdViewUndock)
1777
1778 StdViewUndock::StdViewUndock()
1779 : Command("Std_ViewUndock")
1780 {
1781 sGroup = "Standard-View";
1782 sMenuText = QT_TR_NOOP("&Undocked");
1783 sToolTipText = QT_TR_NOOP(
1784 "Displays the active view either in fullscreen, undocked, or docked mode"
1785 );
1786 sWhatsThis = "Std_ViewUndock";
1787 sStatusTip = sToolTipText;
1788 sAccel = "V, U";
1789 eType = Alter3DView;
1790 bCanLog = false;
1791 }
1792
1793 void StdViewUndock::activated(int iMsg)
1794 {
1795 Q_UNUSED(iMsg);
1796 }
1797
1798 bool StdViewUndock::isActive()
1799 {
1800 MDIView* view = getMainWindow()->activeWindow();
1801 return view != nullptr;
1802 }
1803
1804 //===========================================================================
1805 // Std_MainFullscreen
1806 //===========================================================================
1807 DEF_STD_CMD(StdMainFullscreen)
1808
1809 StdMainFullscreen::StdMainFullscreen()
1810 : Command("Std_MainFullscreen")
1811 {
1812 sGroup = "Standard-View";
1813 sMenuText = QT_TR_NOOP("Fullscreen");
1814 sToolTipText = QT_TR_NOOP("Displays the main window in fullscreen mode");
1815 sWhatsThis = "Std_MainFullscreen";
1816 sStatusTip = sToolTipText;
1817 sPixmap = "view-fullscreen";
1818 sAccel = "Alt+F11";
1819 eType = Alter3DView;
1820 }
1821
1822 void StdMainFullscreen::activated(int iMsg)
1823 {
1824 Q_UNUSED(iMsg);
1825 MDIView* view = getMainWindow()->activeWindow();
1826
1827 if (view) {
1828 view->setCurrentViewMode(MDIView::Child);
1829 }
1830
1831 if (getMainWindow()->isFullScreen()) {
1832 getMainWindow()->showNormal();
1833 }
1834 else {
1835 getMainWindow()->showFullScreen();
1836 }
1837 }
1838
1839 //===========================================================================
1840 // Std_ViewFullscreen
1841 //===========================================================================
1842 DEF_STD_CMD_A(StdViewFullscreen)
1843
1844 StdViewFullscreen::StdViewFullscreen()
1845 : Command("Std_ViewFullscreen")
1846 {
1847 sGroup = "Standard-View";
1848 sMenuText = QT_TR_NOOP("&Fullscreen");
1849 sToolTipText = QT_TR_NOOP(
1850 "Displays the active view either in fullscreen, undocked, or docked mode"
1851 );
1852 sWhatsThis = "Std_ViewFullscreen";
1853 sStatusTip = sToolTipText;
1854 sPixmap = "view-fullscreen";
1855 sAccel = "F11";
1856 eType = Alter3DView;
1857 bCanLog = false;
1858 }
1859
1860 void StdViewFullscreen::activated(int iMsg)
1861 {
1862 Q_UNUSED(iMsg);
1863 }
1864
1865 bool StdViewFullscreen::isActive()
1866 {
1867 MDIView* view = getMainWindow()->activeWindow();
1868 return view != nullptr;
1869 }
1870
1871 //===========================================================================
1872 // Std_ViewDockUndockFullscreen
1873 //===========================================================================
1874 DEF_STD_CMD_AC(StdViewDockUndockFullscreen)
1875
1876 StdViewDockUndockFullscreen::StdViewDockUndockFullscreen()
1877 : Command("Std_ViewDockUndockFullscreen")
1878 {
1879 sGroup = "Standard-View";
1880 sMenuText = QT_TR_NOOP("D&ocument Window");
1881 sToolTipText = QT_TR_NOOP(
1882 "Displays the active view either in fullscreen, undocked, or docked mode"
1883 );
1884 sWhatsThis = "Std_ViewDockUndockFullscreen";
1885 sStatusTip = sToolTipText;
1886 eType = Alter3DView;
1887
1888 CommandManager& rcCmdMgr = Application::Instance->commandManager();
1889 rcCmdMgr.addCommand(new StdViewDock());
1890 rcCmdMgr.addCommand(new StdViewUndock());
1891 rcCmdMgr.addCommand(new StdViewFullscreen());
1892 }
1893
1894 Action* StdViewDockUndockFullscreen::createAction()
1895 {
1896 auto pcAction = new ActionGroup(this, getMainWindow());
1897 pcAction->setDropDownMenu(true);
1898 pcAction->setText(QCoreApplication::translate(this->className(), getMenuText()));
1899
1900 CommandManager& rcCmdMgr = Application::Instance->commandManager();
1901 Command* cmdD = rcCmdMgr.getCommandByName("Std_ViewDock");
1902 Command* cmdU = rcCmdMgr.getCommandByName("Std_ViewUndock");
1903 Command* cmdF = rcCmdMgr.getCommandByName("Std_ViewFullscreen");
1904 cmdD->addToGroup(pcAction, true);
1905 cmdU->addToGroup(pcAction, true);
1906 cmdF->addToGroup(pcAction, true);
1907
1908 return pcAction;
1909 }
1910
1911 void StdViewDockUndockFullscreen::activated(int iMsg)
1912 {
1913 // Check if main window is in fullscreen mode.
1914 if (getMainWindow()->isFullScreen()) {
1915 getMainWindow()->showNormal();
1916 }
1917
1918 MDIView* view = getMainWindow()->activeWindow();
1919 if (!view) { // no active view
1920 return;
1921 }
1922
1923 const auto oldmode = view->currentViewMode();
1924 auto mode = (MDIView::ViewMode)iMsg;
1925
1926 // Pressing the same button again toggles the view back to docked.
1927 if (mode == oldmode) {
1928 mode = MDIView::Child;
1929 }
1930
1931 if (mode == oldmode) {
1932 return;
1933 }
1934
1935 // Change the view mode after an mdi view was already visible doesn't
1936 // work well with Qt5 any more because of some strange OpenGL behaviour.
1937 // A workaround is to clone the mdi view, set its view mode and delete
1938 // the original view.
1939
1940 bool needsClone = mode == MDIView::Child || oldmode == MDIView::Child;
1941 Gui::MDIView* clone = needsClone ? view->clone() : nullptr;
1942
1943 if (clone) {
1944 if (mode == MDIView::Child) {
1945 getMainWindow()->addWindow(clone);
1946 }
1947 else {
1948 clone->setCurrentViewMode(mode);
1949 }
1950
1951 // destroy the old view
1952 view->deleteSelf();
1953 }
1954 else {
1955 // no clone needed, simply change the view mode
1956 view->setCurrentViewMode(mode);
1957 }
1958 }
1959
1960 bool StdViewDockUndockFullscreen::isActive()
1961 {
1962 MDIView* view = getMainWindow()->activeWindow();
1963 if (!view) {
1964 return false;
1965 }
1966
1967 // update the action group if needed
1968 auto pActGrp = qobject_cast<ActionGroup*>(_pcAction);
1969 if (pActGrp) {
1970 int index = pActGrp->checkedAction();
1971 int mode = (int)(view->currentViewMode());
1972 if (index != mode) {
1973 // active window has changed with another view mode
1974 pActGrp->setCheckedAction(mode);
1975 }
1976 }
1977
1978 return true;
1979 }
1980
1981
1982 //===========================================================================
1983 // Std_ViewVR
1984 //===========================================================================
1985 DEF_STD_CMD_A(StdCmdViewVR)
1986
1987 StdCmdViewVR::StdCmdViewVR()
1988 : Command("Std_ViewVR")
1989 {
1990 sGroup = "Standard-View";
1991 sMenuText = QT_TR_NOOP("FreeCAD VR");
1992 sToolTipText = QT_TR_NOOP("Extends the FreeCAD 3D Window to a VR device");
1993 sWhatsThis = "Std_ViewVR";
1994 sStatusTip = sToolTipText;
1995 eType = Alter3DView;
1996 }
1997
1998 void StdCmdViewVR::activated(int iMsg)
1999 {
2000 Q_UNUSED(iMsg);
2001 doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"ViewVR\")");
2002 }
2003
2004 bool StdCmdViewVR::isActive()
2005 {
2006 return getGuiApplication()->sendHasMsgToActiveView("ViewVR");
2007 }
2008
2009
2010 //===========================================================================
2011 // Std_ViewScreenShot
2012 //===========================================================================
2013 DEF_STD_CMD_A(StdViewScreenShot)
2014
2015 StdViewScreenShot::StdViewScreenShot()
2016 : Command("Std_ViewScreenShot")
2017 {
2018 sGroup = "Standard-View";
2019 sMenuText = QT_TR_NOOP("Save &Image…");
2020 sToolTipText = QT_TR_NOOP("Creates a screenshot of the active view");
2021 sWhatsThis = "Std_ViewScreenShot";
2022 sStatusTip = sToolTipText;
2023 sPixmap = "Std_ViewScreenShot";
2024 eType = Alter3DView;
2025 }
2026
2027 void StdViewScreenShot::activated(int iMsg)
2028 {
2029 Q_UNUSED(iMsg);
2030 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
2031 if (view) {
2032 QStringList formats;
2033 SbViewportRegion vp(view->getViewer()->getSoRenderManager()->getViewportRegion());
2034 {
2035 SoQtOffscreenRenderer rd(vp);
2036 formats = rd.getWriteImageFiletypeInfo();
2037 }
2038
2039 Base::Reference<ParameterGrp> hExt = App::GetApplication()
2040 .GetUserParameter()
2041 .GetGroup("BaseApp")
2042 ->GetGroup("Preferences")
2043 ->GetGroup("General");
2044 QString ext = QString::fromLatin1(hExt->GetASCII("OffscreenImageFormat").c_str());
2045 int backtype = hExt->GetInt("OffscreenImageBackground", 0);
2046
2047 Base::Reference<ParameterGrp> methodGrp = App::GetApplication().GetParameterGroupByPath(
2048 "User parameter:BaseApp/Preferences/View"
2049 );
2050 QByteArray method = methodGrp->GetASCII("SavePicture").c_str();
2051
2052 QStringList filter;
2053 QString selFilter;
2054 for (QStringList::Iterator it = formats.begin(); it != formats.end(); ++it) {
2055 filter << QStringLiteral("%1 %2 (*.%3)")
2056 .arg((*it).toUpper(), QObject::tr("files"), (*it).toLower());
2057 if (ext == *it) {
2058 selFilter = filter.last();
2059 }
2060 }
2061
2062 FileOptionsDialog fd(getMainWindow(), Qt::WindowFlags());
2063 fd.setFileMode(QFileDialog::AnyFile);
2064 fd.setAcceptMode(QFileDialog::AcceptSave);
2065 fd.setWindowTitle(QObject::tr("Save Image"));
2066 fd.setNameFilters(filter);
2067 if (!selFilter.isEmpty()) {
2068 fd.selectNameFilter(selFilter);
2069 }
2070
2071 // create the image options widget
2072 auto opt = new DlgSettingsImageImp(&fd);
2073 SbVec2s sz = vp.getWindowSize();
2074 opt->setImageSize((int)sz[0], (int)sz[1]);
2075 opt->setBackgroundType(backtype);
2076 opt->setMethod(method);
2077
2078 fd.setOptionsWidget(FileOptionsDialog::ExtensionRight, opt);
2079 fd.setOption(QFileDialog::DontConfirmOverwrite, false);
2080 opt->onSelectedFilter(fd.selectedNameFilter());
2081 QObject::connect(
2082 &fd,
2083 &FileOptionsDialog::filterSelected,
2084 opt,
2085 &DlgSettingsImageImp::onSelectedFilter
2086 );
2087
2088 if (fd.exec() == QDialog::Accepted) {
2089 selFilter = fd.selectedNameFilter();
2090 QString fn = fd.selectedFiles().constFirst();
2091 // We must convert '\' path separators to '/' before otherwise
2092 // Python would interpret them as escape sequences.
2093 fn.replace(QLatin1Char('\\'), QLatin1Char('/'));
2094
2095 Gui::WaitCursor wc;
2096
2097 // get the defined values
2098 int w = opt->imageWidth();
2099 int h = opt->imageHeight();
2100
2101 // search for the matching format
2102 QString format = formats.front(); // take the first as default
2103 for (QStringList::Iterator it = formats.begin(); it != formats.end(); ++it) {
2104 if (selFilter.startsWith((*it).toUpper())) {
2105 format = *it;
2106 break;
2107 }
2108 }
2109
2110 hExt->SetASCII("OffscreenImageFormat", (const char*)format.toLatin1());
2111
2112 method = opt->method();
2113 methodGrp->SetASCII("SavePicture", method.constData());
2114
2115 // which background chosen
2116 const char* background;
2117 switch (opt->backgroundType()) {
2118 case 0:
2119 background = "Current";
2120 break;
2121 case 1:
2122 background = "White";
2123 break;
2124 case 2:
2125 background = "Black";
2126 break;
2127 case 3:
2128 background = "Transparent";
2129 break;
2130 default:
2131 background = "Current";
2132 break;
2133 }
2134 hExt->SetInt("OffscreenImageBackground", opt->backgroundType());
2135
2136 std::string imageFile = Base::Tools::escapeEncodeFilename(fn.toStdString());
2137 QString comment = opt->comment();
2138 if (!comment.isEmpty()) {
2139 std::string escapedComment = Base::Tools::escapeEncodeString(
2140 comment.toUtf8().toStdString()
2141 );
2142 doCommand(
2143 Gui,
2144 "Gui.activeDocument().activeView().saveImage('%s',%d,%d,'%s','%s')",
2145 imageFile.c_str(),
2146 w,
2147 h,
2148 background,
2149 escapedComment.c_str()
2150 );
2151 }
2152 else {
2153 doCommand(
2154 Gui,
2155 "Gui.activeDocument().activeView().saveImage('%s',%d,%d,'%s')",
2156 imageFile.c_str(),
2157 w,
2158 h,
2159 background
2160 );
2161 }
2162
2163 // When adding a watermark check if the image could be created
2164 if (opt->addWatermark()) {
2165 QFileInfo fi(fn);
2166 QPixmap pixmap;
2167 if (fi.exists() && pixmap.load(fn)) {
2168 QString name = qApp->applicationName();
2169 std::map<std::string, std::string>& config = App::Application::Config();
2170 QString url = QString::fromLatin1(config["MaintainerUrl"].c_str());
2171 url = QUrl(url).host();
2172
2173 QPixmap appicon = Gui::BitmapFactory().pixmap(config["AppIcon"].c_str());
2174
2175 QPainter painter;
2176 painter.begin(&pixmap);
2177
2178 painter.drawPixmap(8, h - 15 - appicon.height(), appicon);
2179
2180 QFont font = painter.font();
2181 font.setPointSize(20);
2182
2183 QFontMetrics fm(font);
2184 int n = QtTools::horizontalAdvance(fm, name);
2185 int h = pixmap.height();
2186
2187 painter.setFont(font);
2188 painter.drawText(8 + appicon.width(), h - 24, name);
2189
2190 font.setPointSize(12);
2191 QFontMetrics fm2(font);
2192 int u = QtTools::horizontalAdvance(fm2, url);
2193 painter.setFont(font);
2194 painter.drawText(8 + appicon.width() + n - u, h - 6, url);
2195
2196 painter.end();
2197 pixmap.save(fn);
2198 }
2199 }
2200 }
2201 }
2202 }
2203
2204 bool StdViewScreenShot::isActive()
2205 {
2206 return isViewOfType(Gui::View3DInventor::getClassTypeId());
2207 }
2208
2209 //===========================================================================
2210 // Std_ViewLoadImage
2211 //===========================================================================
2212 DEF_STD_CMD(StdViewLoadImage)
2213
2214 StdViewLoadImage::StdViewLoadImage()
2215 : Command("Std_ViewLoadImage")
2216 {
2217 sGroup = "Standard-View";
2218 sMenuText = QT_TR_NOOP("&Load Image…");
2219 sToolTipText = QT_TR_NOOP("Loads an image");
2220 sWhatsThis = "Std_ViewLoadImage";
2221 sStatusTip = sToolTipText;
2222 sPixmap = "image-open";
2223 eType = 0;
2224 }
2225
2226 void StdViewLoadImage::activated(int iMsg)
2227 {
2228 Q_UNUSED(iMsg);
2229
2230 // add all supported QImage formats
2231 QStringList mimeTypeFilters;
2232 QList<QByteArray> supportedMimeTypes = QImageReader::supportedMimeTypes();
2233 for (const auto& mimeTypeName : supportedMimeTypes) {
2234 mimeTypeFilters.append(QString::fromLatin1(mimeTypeName));
2235 }
2236
2237 // Reading an image
2238 QFileDialog dialog(Gui::getMainWindow());
2239 dialog.setWindowTitle(QObject::tr("Choose an Image File to Open"));
2240 dialog.setMimeTypeFilters(mimeTypeFilters);
2241 dialog.selectMimeTypeFilter(QStringLiteral("image/png"));
2242 dialog.setDefaultSuffix(QStringLiteral("png"));
2243 dialog.setAcceptMode(QFileDialog::AcceptOpen);
2244 dialog.setOption(QFileDialog::DontUseNativeDialog);
2245
2246 if (dialog.exec()) {
2247 QString fileName = dialog.selectedFiles().constFirst();
2248 ImageView* view = new ImageView(Gui::getMainWindow());
2249 view->loadFile(fileName);
2250 view->resize(400, 300);
2251 Gui::getMainWindow()->addWindow(view);
2252 }
2253 }
2254
2255 //===========================================================================
2256 // Std_ViewCreate
2257 //===========================================================================
2258 DEF_STD_CMD_A(StdCmdViewCreate)
2259
2260 StdCmdViewCreate::StdCmdViewCreate()
2261 : Command("Std_ViewCreate")
2262 {
2263 sGroup = "Standard-View";
2264 sMenuText = QT_TR_NOOP("New 3D View");
2265 sToolTipText = QT_TR_NOOP("Opens a new 3D view window for the active document");
2266 sWhatsThis = "Std_ViewCreate";
2267 sStatusTip = sToolTipText;
2268 sPixmap = "window-new";
2269 eType = Alter3DView;
2270 }
2271
2272 void StdCmdViewCreate::activated(int iMsg)
2273 {
2274 Q_UNUSED(iMsg);
2275 getActiveGuiDocument()->createView(View3DInventor::getClassTypeId());
2276 getActiveGuiDocument()->getActiveView()->viewAll();
2277 }
2278
2279 bool StdCmdViewCreate::isActive()
2280 {
2281 return (getActiveGuiDocument() != nullptr);
2282 }
2283
2284 //===========================================================================
2285 // Std_ToggleNavigation
2286 //===========================================================================
2287 DEF_STD_CMD_A(StdCmdToggleNavigation)
2288
2289 StdCmdToggleNavigation::StdCmdToggleNavigation()
2290 : Command("Std_ToggleNavigation")
2291 {
2292 sGroup = "Standard-View";
2293 sMenuText = QT_TR_NOOP("Toggle Navigation/&Edit Mode");
2294 sToolTipText = QT_TR_NOOP("Toggles between navigation and edit mode");
2295 sStatusTip = sToolTipText;
2296 sWhatsThis = "Std_ToggleNavigation";
2297 // iAccel = Qt::SHIFT+Qt::Key_Space;
2298 sAccel = "Esc";
2299 sPixmap = "Std_ToggleNavigation";
2300 eType = Alter3DView;
2301 }
2302
2303 void StdCmdToggleNavigation::activated(int iMsg)
2304 {
2305 Q_UNUSED(iMsg);
2306 Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
2307 if (view && view->isDerivedFrom<Gui::View3DInventor>()) {
2308 Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
2309 SbBool toggle = viewer->isRedirectedToSceneGraph();
2310 viewer->setRedirectToSceneGraph(!toggle);
2311 }
2312 }
2313
2314 bool StdCmdToggleNavigation::isActive()
2315 {
2316 // #0001087: Inventor Navigation continues with released Mouse Button
2317 // This happens because 'Esc' is also used to close the task dialog.
2318 // Add also new method 'isRedirectToSceneGraphEnabled' to explicitly
2319 // check if this is allowed.
2320 if (Gui::Control().activeDialog()) {
2321 return false;
2322 }
2323 Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
2324 if (view && view->isDerivedFrom<Gui::View3DInventor>()) {
2325 Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
2326 return viewer->isEditing() && viewer->isRedirectToSceneGraphEnabled();
2327 }
2328 return false;
2329 }
2330
2331
2332 //===========================================================================
2333 // Std_ViewExample1
2334 //===========================================================================
2335 DEF_STD_CMD_A(StdCmdAxisCross)
2336
2337 StdCmdAxisCross::StdCmdAxisCross()
2338 : Command("Std_AxisCross")
2339 {
2340 sGroup = "Standard-View";
2341 sMenuText = QT_TR_NOOP("Toggle A&xis Cross");
2342 sToolTipText = QT_TR_NOOP("Toggles the axis cross at the origin");
2343 sStatusTip = sToolTipText;
2344 sWhatsThis = "Std_AxisCross";
2345 sPixmap = "Std_AxisCross";
2346 sAccel = "A,C";
2347 }
2348
2349 void StdCmdAxisCross::activated(int iMsg)
2350 {
2351 Q_UNUSED(iMsg);
2352 auto view = qobject_cast<View3DInventor*>(Gui::getMainWindow()->activeWindow());
2353 if (view) {
2354 if (!view->getViewer()->hasAxisCross()) {
2355 doCommand(Command::Gui, "Gui.ActiveDocument.ActiveView.setAxisCross(True)");
2356 }
2357 else {
2358 doCommand(Command::Gui, "Gui.ActiveDocument.ActiveView.setAxisCross(False)");
2359 }
2360 }
2361 }
2362
2363 bool StdCmdAxisCross::isActive()
2364 {
2365 auto view = qobject_cast<View3DInventor*>(Gui::getMainWindow()->activeWindow());
2366 if (view && view->getViewer()->hasAxisCross()) {
2367 if (!_pcAction->isChecked()) {
2368 _pcAction->setChecked(true);
2369 }
2370 }
2371 else {
2372 if (_pcAction->isChecked()) {
2373 _pcAction->setChecked(false);
2374 }
2375 }
2376 if (view) {
2377 return true;
2378 }
2379 return false;
2380 }
2381
2382 //===========================================================================
2383 // Std_ViewExample1
2384 //===========================================================================
2385 DEF_STD_CMD_A(StdCmdViewExample1)
2386
2387 StdCmdViewExample1::StdCmdViewExample1()
2388 : Command("Std_ViewExample1")
2389 {
2390 sGroup = "Standard-View";
2391 sMenuText = QT_TR_NOOP("Inventor Example #1");
2392 sToolTipText = QT_TR_NOOP("Shows a 3D texture with manipulator");
2393 sWhatsThis = "Std_ViewExample1";
2394 sStatusTip = sToolTipText;
2395 sPixmap = "Std_Tool1";
2396 eType = Alter3DView;
2397 }
2398
2399 void StdCmdViewExample1::activated(int iMsg)
2400 {
2401 Q_UNUSED(iMsg);
2402 doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"Example1\")");
2403 }
2404
2405 bool StdCmdViewExample1::isActive()
2406 {
2407 return getGuiApplication()->sendHasMsgToActiveView("Example1");
2408 }
2409
2410 //===========================================================================
2411 // Std_ViewExample2
2412 //===========================================================================
2413 DEF_STD_CMD_A(StdCmdViewExample2)
2414
2415 StdCmdViewExample2::StdCmdViewExample2()
2416 : Command("Std_ViewExample2")
2417 {
2418 sGroup = "Standard-View";
2419 sMenuText = QT_TR_NOOP("Inventor Example #2");
2420 sToolTipText = QT_TR_NOOP("Shows spheres and drag-lights");
2421 sWhatsThis = "Std_ViewExample2";
2422 sStatusTip = sToolTipText;
2423 sPixmap = "Std_Tool2";
2424 eType = Alter3DView;
2425 }
2426
2427 void StdCmdViewExample2::activated(int iMsg)
2428 {
2429 Q_UNUSED(iMsg);
2430 doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"Example2\")");
2431 }
2432
2433 bool StdCmdViewExample2::isActive()
2434 {
2435 return getGuiApplication()->sendHasMsgToActiveView("Example2");
2436 }
2437
2438 //===========================================================================
2439 // Std_ViewExample3
2440 //===========================================================================
2441 DEF_STD_CMD_A(StdCmdViewExample3)
2442
2443 StdCmdViewExample3::StdCmdViewExample3()
2444 : Command("Std_ViewExample3")
2445 {
2446 sGroup = "Standard-View";
2447 sMenuText = QT_TR_NOOP("Inventor Example #3");
2448 sToolTipText = QT_TR_NOOP("Shows an animated texture");
2449 sWhatsThis = "Std_ViewExample3";
2450 sStatusTip = sToolTipText;
2451 sPixmap = "Std_Tool3";
2452 eType = Alter3DView;
2453 }
2454
2455 void StdCmdViewExample3::activated(int iMsg)
2456 {
2457 Q_UNUSED(iMsg);
2458 doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"Example3\")");
2459 }
2460
2461 bool StdCmdViewExample3::isActive()
2462 {
2463 return getGuiApplication()->sendHasMsgToActiveView("Example3");
2464 }
2465
2466
2467 //===========================================================================
2468 // Std_ViewIvStereoOff
2469 //===========================================================================
2470 DEF_STD_CMD_A(StdCmdViewIvStereoOff)
2471
2472 StdCmdViewIvStereoOff::StdCmdViewIvStereoOff()
2473 : Command("Std_ViewIvStereoOff")
2474 {
2475 sGroup = "Standard-View";
2476 sMenuText = QT_TR_NOOP("Stereo &Off");
2477 sToolTipText = QT_TR_NOOP("Switches stereo viewing off");
2478 sWhatsThis = "Std_ViewIvStereoOff";
2479 sStatusTip = sToolTipText;
2480 sPixmap = "Std_ViewIvStereoOff";
2481 eType = Alter3DView;
2482 }
2483
2484 void StdCmdViewIvStereoOff::activated(int iMsg)
2485 {
2486 Q_UNUSED(iMsg);
2487 doCommand(Command::Gui, "Gui.activeDocument().activeView().setStereoType(\"Mono\")");
2488 }
2489
2490 bool StdCmdViewIvStereoOff::isActive()
2491 {
2492 return getGuiApplication()->sendHasMsgToActiveView("SetStereoOff");
2493 }
2494
2495
2496 //===========================================================================
2497 // Std_ViewIvStereoRedGreen
2498 //===========================================================================
2499 DEF_STD_CMD_A(StdCmdViewIvStereoRedGreen)
2500
2501 StdCmdViewIvStereoRedGreen::StdCmdViewIvStereoRedGreen()
2502 : Command("Std_ViewIvStereoRedGreen")
2503 {
2504 sGroup = "Standard-View";
2505 sMenuText = QT_TR_NOOP("Stereo Re&d/Cyan");
2506 sToolTipText = QT_TR_NOOP("Switches stereo viewing to red/cyan");
2507 sWhatsThis = "Std_ViewIvStereoRedGreen";
2508 sStatusTip = sToolTipText;
2509 sPixmap = "Std_ViewIvStereoRedGreen";
2510 eType = Alter3DView;
2511 }
2512
2513 void StdCmdViewIvStereoRedGreen::activated(int iMsg)
2514 {
2515 Q_UNUSED(iMsg);
2516 doCommand(Command::Gui, "Gui.activeDocument().activeView().setStereoType(\"Anaglyph\")");
2517 }
2518
2519 bool StdCmdViewIvStereoRedGreen::isActive()
2520 {
2521 return getGuiApplication()->sendHasMsgToActiveView("SetStereoRedGreen");
2522 }
2523
2524 //===========================================================================
2525 // Std_ViewIvStereoQuadBuff
2526 //===========================================================================
2527 DEF_STD_CMD_A(StdCmdViewIvStereoQuadBuff)
2528
2529 StdCmdViewIvStereoQuadBuff::StdCmdViewIvStereoQuadBuff()
2530 : Command("Std_ViewIvStereoQuadBuff")
2531 {
2532 sGroup = "Standard-View";
2533 sMenuText = QT_TR_NOOP("Stereo &Quad Buffer");
2534 sToolTipText = QT_TR_NOOP("Switches stereo viewing to quad buffer");
2535 sWhatsThis = "Std_ViewIvStereoQuadBuff";
2536 sStatusTip = sToolTipText;
2537 sPixmap = "Std_ViewIvStereoQuadBuff";
2538 eType = Alter3DView;
2539 }
2540
2541 void StdCmdViewIvStereoQuadBuff::activated(int iMsg)
2542 {
2543 Q_UNUSED(iMsg);
2544 doCommand(Command::Gui, "Gui.activeDocument().activeView().setStereoType(\"QuadBuffer\")");
2545 }
2546
2547 bool StdCmdViewIvStereoQuadBuff::isActive()
2548 {
2549 return getGuiApplication()->sendHasMsgToActiveView("SetStereoQuadBuff");
2550 }
2551
2552 //===========================================================================
2553 // Std_ViewIvStereoInterleavedRows
2554 //===========================================================================
2555 DEF_STD_CMD_A(StdCmdViewIvStereoInterleavedRows)
2556
2557 StdCmdViewIvStereoInterleavedRows::StdCmdViewIvStereoInterleavedRows()
2558 : Command("Std_ViewIvStereoInterleavedRows")
2559 {
2560 sGroup = "Standard-View";
2561 sMenuText = QT_TR_NOOP("Stereo Interleaved &Rows");
2562 sToolTipText = QT_TR_NOOP("Switches stereo viewing to interleaved rows");
2563 sWhatsThis = "Std_ViewIvStereoInterleavedRows";
2564 sStatusTip = sToolTipText;
2565 sPixmap = "Std_ViewIvStereoInterleavedRows";
2566 eType = Alter3DView;
2567 }
2568
2569 void StdCmdViewIvStereoInterleavedRows::activated(int iMsg)
2570 {
2571 Q_UNUSED(iMsg);
2572 doCommand(Command::Gui, "Gui.activeDocument().activeView().setStereoType(\"InterleavedRows\")");
2573 }
2574
2575 bool StdCmdViewIvStereoInterleavedRows::isActive()
2576 {
2577 return getGuiApplication()->sendHasMsgToActiveView("SetStereoInterleavedRows");
2578 }
2579
2580 //===========================================================================
2581 // Std_ViewIvStereoInterleavedColumns
2582 //===========================================================================
2583 DEF_STD_CMD_A(StdCmdViewIvStereoInterleavedColumns)
2584
2585 StdCmdViewIvStereoInterleavedColumns::StdCmdViewIvStereoInterleavedColumns()
2586 : Command("Std_ViewIvStereoInterleavedColumns")
2587 {
2588 sGroup = "Standard-View";
2589 sMenuText = QT_TR_NOOP("Stereo Interleaved &Columns");
2590 sToolTipText = QT_TR_NOOP("Switches stereo viewing to interleaved columns");
2591 sWhatsThis = "Std_ViewIvStereoInterleavedColumns";
2592 sStatusTip = sToolTipText;
2593 sPixmap = "Std_ViewIvStereoInterleavedColumns";
2594 eType = Alter3DView;
2595 }
2596
2597 void StdCmdViewIvStereoInterleavedColumns::activated(int iMsg)
2598 {
2599 Q_UNUSED(iMsg);
2600 doCommand(Command::Gui, "Gui.activeDocument().activeView().setStereoType(\"InterleavedColumns\")");
2601 }
2602
2603 bool StdCmdViewIvStereoInterleavedColumns::isActive()
2604 {
2605 return getGuiApplication()->sendHasMsgToActiveView("SetStereoInterleavedColumns");
2606 }
2607
2608
2609 //===========================================================================
2610 // Std_ViewIvIssueCamPos
2611 //===========================================================================
2612 DEF_STD_CMD_A(StdCmdViewIvIssueCamPos)
2613
2614 StdCmdViewIvIssueCamPos::StdCmdViewIvIssueCamPos()
2615 : Command("Std_ViewIvIssueCamPos")
2616 {
2617 sGroup = "Standard-View";
2618 sMenuText = QT_TR_NOOP("Issue Camera &Position");
2619 sToolTipText = QT_TR_NOOP(
2620 "Issues the camera position to the console and to a macro, to easily recall this position"
2621 );
2622 sWhatsThis = "Std_ViewIvIssueCamPos";
2623 sStatusTip = sToolTipText;
2624 sPixmap = "Std_ViewIvIssueCamPos";
2625 eType = Alter3DView;
2626 }
2627
2628 void StdCmdViewIvIssueCamPos::activated(int iMsg)
2629 {
2630 Q_UNUSED(iMsg);
2631 std::string Temp, Temp2;
2632 std::string::size_type pos;
2633
2634 const char* ppReturn = nullptr;
2635 getGuiApplication()->sendMsgToActiveView("GetCamera", &ppReturn);
2636
2637 // remove the #inventor line...
2638 Temp2 = ppReturn;
2639 pos = Temp2.find_first_of("\n");
2640 Temp2.erase(0, pos);
2641
2642 // remove all returns
2643 while ((pos = Temp2.find('\n')) != std::string::npos) {
2644 Temp2.replace(pos, 1, " ");
2645 }
2646
2647 // build up the command string
2648 Temp += "Gui.SendMsgToActiveView(\"SetCamera ";
2649 Temp += Temp2;
2650 Temp += "\")";
2651
2652 Base::Console().message("%s\n", Temp2.c_str());
2653 getGuiApplication()->macroManager()->addLine(MacroManager::Gui, Temp.c_str());
2654 }
2655
2656 bool StdCmdViewIvIssueCamPos::isActive()
2657 {
2658 return getGuiApplication()->sendHasMsgToActiveView("GetCamera");
2659 }
2660
2661
2662 //===========================================================================
2663 // Std_ViewZoomIn
2664 //===========================================================================
2665 DEF_STD_CMD_A(StdViewZoomIn)
2666
2667 StdViewZoomIn::StdViewZoomIn()
2668 : Command("Std_ViewZoomIn")
2669 {
2670 sGroup = "Standard-View";
2671 sMenuText = QT_TR_NOOP("Zoom &In");
2672 sToolTipText = QT_TR_NOOP("Increases the zoom factor by a fixed amount");
2673 sWhatsThis = "Std_ViewZoomIn";
2674 sStatusTip = sToolTipText;
2675 sPixmap = "zoom-in";
2676 sAccel = keySequenceToAccel(QKeySequence::ZoomIn);
2677 eType = Alter3DView;
2678 }
2679
2680 void StdViewZoomIn::activated(int iMsg)
2681 {
2682 Q_UNUSED(iMsg);
2683 getGuiApplication()->sendMsgToFocusView("ZoomIn");
2684 }
2685
2686 bool StdViewZoomIn::isActive()
2687 {
2688 return getGuiApplication()->sendHasMsgToActiveView("ZoomIn");
2689 }
2690
2691 //===========================================================================
2692 // Std_ViewZoomOut
2693 //===========================================================================
2694 DEF_STD_CMD_A(StdViewZoomOut)
2695
2696 StdViewZoomOut::StdViewZoomOut()
2697 : Command("Std_ViewZoomOut")
2698 {
2699 sGroup = "Standard-View";
2700 sMenuText = QT_TR_NOOP("Zoom &Out");
2701 sToolTipText = QT_TR_NOOP("Decreases the zoom factor by a fixed amount");
2702 sWhatsThis = "Std_ViewZoomOut";
2703 sStatusTip = sToolTipText;
2704 sPixmap = "zoom-out";
2705 sAccel = keySequenceToAccel(QKeySequence::ZoomOut);
2706 eType = Alter3DView;
2707 }
2708
2709 void StdViewZoomOut::activated(int iMsg)
2710 {
2711 Q_UNUSED(iMsg);
2712 getGuiApplication()->sendMsgToFocusView("ZoomOut");
2713 }
2714
2715 bool StdViewZoomOut::isActive()
2716 {
2717 return getGuiApplication()->sendHasMsgToActiveView("ZoomOut");
2718 }
2719
2720 namespace
2721 {
2722 class SelectionCallbackHandler
2723 {
2724
2725 private:
2726 static std::unique_ptr<SelectionCallbackHandler> currentSelectionHandler;
2727 QCursor prevSelectionCursor;
2728 using FnCb = void (*)(void* userdata, SoEventCallback* node);
2729 FnCb fnCb;
2730 void* userData;
2731 bool prevSelectionEn;
2732
2733 public:
2734 // Creates a selection handler used to implement the common behaviour of BoxZoom, BoxSelection
2735 // and BoxElementSelection. Takes the viewer, a selection mode, a cursor, a function pointer to
2736 // be called on success and a void pointer for user data to be passed to the given function. The
2737 // selection handler class stores all necessary previous states, registers a event callback and
2738 // starts the selection in the given mode. If there is still a selection handler active, this
2739 // call will generate a message and returns.
2740 static void Create(
2741 View3DInventorViewer* viewer,
2742 View3DInventorViewer::SelectionMode selectionMode,
2743 const QCursor& cursor,
2744 FnCb doFunction = nullptr,
2745 void* ud = nullptr
2746 )
2747 {
2748 if (currentSelectionHandler) {
2749 Base::Console().message("SelectionCallbackHandler: A selection handler already active.");
2750 return;
2751 }
2752
2753 currentSelectionHandler = std::make_unique<SelectionCallbackHandler>();
2754 if (viewer) {
2755 currentSelectionHandler->userData = ud;
2756 currentSelectionHandler->fnCb = doFunction;
2757 currentSelectionHandler->prevSelectionCursor = viewer->cursor();
2758 viewer->setEditingCursor(cursor);
2759 viewer->addEventCallback(
2760 SoEvent::getClassTypeId(),
2761 SelectionCallbackHandler::selectionCallback,
2762 currentSelectionHandler.get()
2763 );
2764 currentSelectionHandler->prevSelectionEn = viewer->isSelectionEnabled();
2765 viewer->setSelectionEnabled(false);
2766 viewer->startSelection(selectionMode);
2767 }
2768 }
2769
2770 void* getUserData() const
2771 {
2772 return userData;
2773 }
2774
2775 // Implements the event handler. In the normal case the provided function is called.
2776 // Also supports aborting the selection mode by pressing (releasing) the Escape key.
2777 static void selectionCallback(void* ud, SoEventCallback* n)
2778 {
2779 auto selectionHandler = static_cast<SelectionCallbackHandler*>(ud);
2780 auto view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
2781 const SoEvent* ev = n->getEvent();
2782 if (ev->isOfType(SoKeyboardEvent::getClassTypeId())) {
2783
2784 n->setHandled();
2785 n->getAction()->setHandled();
2786
2787 const auto ke = static_cast<const SoKeyboardEvent*>(ev);
2788 const SbBool press = ke->getState() == SoButtonEvent::DOWN ? true : false;
2789 if (ke->getKey() == SoKeyboardEvent::ESCAPE) {
2790
2791 if (!press) {
2792 view->abortSelection();
2793 restoreState(selectionHandler, view);
2794 }
2795 }
2796 }
2797 else if (ev->isOfType(SoMouseButtonEvent::getClassTypeId())) {
2798 const auto mbe = static_cast<const SoMouseButtonEvent*>(ev);
2799
2800 // Mark all incoming mouse button events as handled, especially, to deactivate the
2801 // selection node
2802 n->getAction()->setHandled();
2803
2804 if (mbe->getButton() == SoMouseButtonEvent::BUTTON1
2805 && mbe->getState() == SoButtonEvent::UP) {
2806 if (selectionHandler && selectionHandler->fnCb) {
2807 selectionHandler->fnCb(selectionHandler->getUserData(), n);
2808 }
2809 restoreState(selectionHandler, view);
2810 }
2811 // No other mouse events available from Coin3D to implement right mouse up abort
2812 }
2813 }
2814
2815 static void restoreState(SelectionCallbackHandler* selectionHandler, View3DInventorViewer* view)
2816 {
2817 if (selectionHandler) {
2818 selectionHandler->fnCb = nullptr;
2819 view->setEditingCursor(selectionHandler->prevSelectionCursor);
2820 view->removeEventCallback(
2821 SoEvent::getClassTypeId(),
2822 SelectionCallbackHandler::selectionCallback,
2823 selectionHandler
2824 );
2825 view->setSelectionEnabled(selectionHandler->prevSelectionEn);
2826 }
2827 Application::Instance->commandManager().testActive();
2828 currentSelectionHandler = nullptr;
2829 }
2830
2831 static QCursor makeCursor(
2832 [[maybe_unused]] QWidget* widget,
2833 const QSize& size,
2834 const char* svgFile,
2835 int hotX,
2836 int hotY
2837 )
2838 {
2839 qreal hotXF = hotX;
2840 qreal hotYF = hotY;
2841 #if !defined(Q_OS_WIN32) && !defined(Q_OS_MACOS)
2842 if (qApp->platformName() == QLatin1String("xcb")) {
2843 qreal pRatio = widget->devicePixelRatioF();
2844 hotXF *= pRatio;
2845 hotYF *= pRatio;
2846 }
2847 #endif
2848 QPixmap px(Gui::BitmapFactory().pixmapFromSvg(svgFile, size));
2849 return QCursor(px, static_cast<int>(hotXF), static_cast<int>(hotYF));
2850 }
2851 };
2852 } // namespace
2853
2854 std::unique_ptr<SelectionCallbackHandler> SelectionCallbackHandler::currentSelectionHandler
2855 = std::unique_ptr<SelectionCallbackHandler>();
2856 //===========================================================================
2857 // Std_ViewBoxZoom
2858 //===========================================================================
2859
2860 DEF_3DV_CMD(StdViewBoxZoom)
2861
2862 StdViewBoxZoom::StdViewBoxZoom()
2863 : Command("Std_ViewBoxZoom")
2864 {
2865 sGroup = "Standard-View";
2866 sMenuText = QT_TR_NOOP("&Box Zoom");
2867 sToolTipText = QT_TR_NOOP("Activates the box zoom tool");
2868 sWhatsThis = "Std_ViewBoxZoom";
2869 sStatusTip = sToolTipText;
2870 sPixmap = "zoom-border";
2871 sAccel = "Ctrl+B";
2872 eType = Alter3DView;
2873 }
2874
2875 void StdViewBoxZoom::activated(int iMsg)
2876 {
2877 Q_UNUSED(iMsg);
2878 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
2879 if (view) {
2880 View3DInventorViewer* viewer = view->getViewer();
2881 if (!viewer->isSelecting()) {
2882 // NOLINTBEGIN
2883 QCursor cursor
2884 = SelectionCallbackHandler::makeCursor(viewer, QSize(32, 32), "zoom-border-cross", 6, 6);
2885 SelectionCallbackHandler::Create(viewer, View3DInventorViewer::BoxZoom, cursor);
2886 // NOLINTEND
2887 }
2888 }
2889 }
2890
2891 //===========================================================================
2892 // Std_BoxSelection
2893 //===========================================================================
2894 DEF_3DV_CMD(StdBoxSelection)
2895
2896 StdBoxSelection::StdBoxSelection()
2897 : Command("Std_BoxSelection")
2898 {
2899 sGroup = "Standard-View";
2900 sMenuText = QT_TR_NOOP("&Box Selection");
2901 sToolTipText = QT_TR_NOOP("Activates the box selection tool");
2902 sWhatsThis = "Std_BoxSelection";
2903 sStatusTip = sToolTipText;
2904 sPixmap = "edit-select-box";
2905 sAccel = "Shift+B";
2906 eType = AlterSelection;
2907 }
2908
2909 using SelectionMode = enum
2910 {
2911 CENTER,
2912 INTERSECT
2913 };
2914
2915 static std::vector<std::string> getBoxSelection(
2916 ViewProviderDocumentObject* vp,
2917 SelectionMode mode,
2918 bool selectElement,
2919 const Base::ViewProjMethod& proj,
2920 const Base::Polygon2d& polygon,
2921 const Base::Matrix4D& mat,
2922 bool transform = true,
2923 int depth = 0
2924 )
2925 {
2926 std::vector<std::string> ret;
2927 auto obj = vp->getObject();
2928 if (!obj || !obj->isAttachedToDocument()) {
2929 return ret;
2930 }
2931
2932 // DO NOT check this view object Visibility, let the caller do this. Because
2933 // we may be called by upper object hierarchy that manages our visibility.
2934
2935 auto bbox3 = vp->getBoundingBox(nullptr, transform);
2936 if (!bbox3.IsValid()) {
2937 return ret;
2938 }
2939
2940 auto bbox = bbox3.Transformed(mat).ProjectBox(&proj);
2941
2942 // check if both two boundary points are inside polygon, only
2943 // valid since we know the given polygon is a box.
2944 if (polygon.Contains(Base::Vector2d(bbox.MinX, bbox.MinY))
2945 && polygon.Contains(Base::Vector2d(bbox.MaxX, bbox.MaxY))) {
2946 ret.emplace_back("");
2947 return ret;
2948 }
2949
2950 if (!bbox.Intersect(polygon)) {
2951 return ret;
2952 }
2953
2954 const auto& subs = obj->getSubObjects(App::DocumentObject::GS_SELECT);
2955 if (subs.empty()) {
2956 if (!selectElement) {
2957 if (mode == INTERSECT || polygon.Contains(bbox.GetCenter())) {
2958 ret.emplace_back("");
2959 }
2960 return ret;
2961 }
2962 Base::PyGILStateLocker lock;
2963 PyObject* pyobj = nullptr;
2964 Base::Matrix4D matCopy(mat);
2965 obj->getSubObject(nullptr, &pyobj, &matCopy, transform, depth);
2966 if (!pyobj) {
2967 return ret;
2968 }
2969 Py::Object pyobject(pyobj, true);
2970 if (!PyObject_TypeCheck(pyobj, &Data::ComplexGeoDataPy::Type)) {
2971 return ret;
2972 }
2973 auto data = static_cast<Data::ComplexGeoDataPy*>(pyobj)->getComplexGeoDataPtr();
2974 for (auto type : data->getElementTypes()) {
2975 size_t count = data->countSubElements(type);
2976 if (!count) {
2977 continue;
2978 }
2979 for (size_t i = 1; i <= count; ++i) {
2980 std::string element(type);
2981 element += std::to_string(i);
2982 std::unique_ptr<Data::Segment> segment(data->getSubElementByName(element.c_str()));
2983 if (!segment) {
2984 continue;
2985 }
2986 std::vector<Base::Vector3d> points;
2987 std::vector<Data::ComplexGeoData::Line> lines;
2988 data->getLinesFromSubElement(segment.get(), points, lines);
2989 if (lines.empty()) {
2990 if (points.empty()) {
2991 continue;
2992 }
2993 auto v = proj(points[0]);
2994 if (polygon.Contains(Base::Vector2d(v.x, v.y))) {
2995 ret.push_back(element);
2996 }
2997 continue;
2998 }
2999 Base::Polygon2d loop;
3000 // TODO: can we assume the line returned above are in proper
3001 // order if the element is a face?
3002 auto v = proj(points[lines.front().I1]);
3003 loop.Add(Base::Vector2d(v.x, v.y));
3004 for (auto& line : lines) {
3005 for (auto i = line.I1; i < line.I2; ++i) {
3006 auto v = proj(points[i + 1]);
3007 loop.Add(Base::Vector2d(v.x, v.y));
3008 }
3009 }
3010 if (!polygon.Intersect(loop)) {
3011 continue;
3012 }
3013 if (mode == CENTER && !polygon.Contains(loop.CalcBoundBox().GetCenter())) {
3014 continue;
3015 }
3016 ret.push_back(element);
3017 }
3018 break;
3019 }
3020 return ret;
3021 }
3022
3023 size_t count = 0;
3024 for (auto& sub : subs) {
3025 App::DocumentObject* parent = nullptr;
3026 std::string childName;
3027 Base::Matrix4D smat(mat);
3028 auto sobj
3029 = obj->resolve(sub.c_str(), &parent, &childName, nullptr, nullptr, &smat, transform, depth + 1);
3030 if (!sobj) {
3031 continue;
3032 }
3033 int vis;
3034 if (!parent || (vis = parent->isElementVisible(childName.c_str())) < 0) {
3035 vis = sobj->Visibility.getValue() ? 1 : 0;
3036 }
3037
3038 if (!vis) {
3039 continue;
3040 }
3041
3042 auto svp = freecad_cast<ViewProviderDocumentObject*>(
3043 Application::Instance->getViewProvider(sobj)
3044 );
3045 if (!svp) {
3046 continue;
3047 }
3048
3049 const auto& sels
3050 = getBoxSelection(svp, mode, selectElement, proj, polygon, smat, false, depth + 1);
3051 if (sels.size() == 1 && sels[0].empty()) {
3052 ++count;
3053 }
3054 for (auto& sel : sels) {
3055 ret.emplace_back(sub + sel);
3056 }
3057 }
3058 if (count == subs.size()) {
3059 ret.resize(1);
3060 ret[0].clear();
3061 }
3062 return ret;
3063 }
3064
3065 static void doSelect(void* ud, SoEventCallback* cb)
3066 {
3067 bool selectElement = ud ? true : false;
3068 auto viewer = static_cast<Gui::View3DInventorViewer*>(cb->getUserData());
3069
3070 viewer->setSelectionEnabled(true);
3071
3072 SelectionMode selectionMode = CENTER;
3073
3074 std::vector<SbVec2f> picked = viewer->getGLPolygon();
3075 SoCamera* cam = viewer->getSoRenderManager()->getCamera();
3076 SbViewVolume vv = cam->getViewVolume();
3077 Gui::ViewVolumeProjection proj(vv);
3078 Base::Polygon2d polygon;
3079 if (picked.size() == 2) {
3080 SbVec2f pt1 = picked[0];
3081 SbVec2f pt2 = picked[1];
3082 polygon.Add(Base::Vector2d(pt1[0], pt1[1]));
3083 polygon.Add(Base::Vector2d(pt1[0], pt2[1]));
3084 polygon.Add(Base::Vector2d(pt2[0], pt2[1]));
3085 polygon.Add(Base::Vector2d(pt2[0], pt1[1]));
3086
3087 // when selecting from right to left then select by intersection
3088 // otherwise if the center is inside the rectangle
3089 if (picked[0][0] > picked[1][0]) {
3090 selectionMode = INTERSECT;
3091 }
3092 }
3093 else {
3094 for (const auto& it : picked) {
3095 polygon.Add(Base::Vector2d(it[0], it[1]));
3096 }
3097 }
3098
3099 App::Document* doc = App::GetApplication().getActiveDocument();
3100 if (doc) {
3101 cb->setHandled();
3102
3103 const SoEvent* ev = cb->getEvent();
3104 if (ev && !ev->wasCtrlDown()) {
3105 Gui::Selection().clearSelection(doc->getName());
3106 }
3107
3108 const std::vector<App::DocumentObject*> objects = doc->getObjects();
3109 for (auto obj : objects) {
3110 if (App::GeoFeatureGroupExtension::getGroupOfObject(obj)) {
3111 continue;
3112 }
3113
3114 auto vp = freecad_cast<ViewProviderDocumentObject*>(
3115 Application::Instance->getViewProvider(obj)
3116 );
3117 if (!vp || !vp->isVisible()) {
3118 continue;
3119 }
3120
3121 Base::Matrix4D mat;
3122 for (auto& sub : getBoxSelection(vp, selectionMode, selectElement, proj, polygon, mat)) {
3123 Gui::Selection().addSelection(doc->getName(), obj->getNameInDocument(), sub.c_str());
3124 }
3125 }
3126 }
3127 }
3128
3129 void StdBoxSelection::activated(int iMsg)
3130 {
3131 Q_UNUSED(iMsg);
3132 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
3133 if (view) {
3134 View3DInventorViewer* viewer = view->getViewer();
3135 if (!viewer->isSelecting()) {
3136 // #0002931: Box select misbehaves with touchpad navigation style
3137 // Notify the navigation style to cleanup internal states
3138 int mode = viewer->navigationStyle()->getViewingMode();
3139 if (mode != Gui::NavigationStyle::IDLE) {
3140 SoKeyboardEvent ev;
3141 viewer->navigationStyle()->processEvent(&ev);
3142 }
3143
3144 // NOLINTBEGIN
3145 QCursor cursor = SelectionCallbackHandler::makeCursor(
3146 viewer,
3147 QSize(32, 32),
3148 "edit-select-box-cross",
3149 6,
3150 6
3151 );
3152 SelectionCallbackHandler::Create(
3153 viewer,
3154 View3DInventorViewer::Rubberband,
3155 cursor,
3156 doSelect,
3157 nullptr
3158 );
3159 viewer->setSelectionEnabled(false);
3160 // NOLINTEND
3161 }
3162 }
3163 }
3164
3165 //===========================================================================
3166 // Std_BoxElementSelection
3167 //===========================================================================
3168
3169 DEF_3DV_CMD(StdBoxElementSelection)
3170
3171 StdBoxElementSelection::StdBoxElementSelection()
3172 : Command("Std_BoxElementSelection")
3173 {
3174 sGroup = "Standard-View";
3175 sMenuText = QT_TR_NOOP("Bo&x Element Selection");
3176 sToolTipText = QT_TR_NOOP("Activates box element selection");
3177 sWhatsThis = "Std_BoxElementSelection";
3178 sStatusTip = sToolTipText;
3179 sPixmap = "edit-element-select-box";
3180 sAccel = "Shift+E";
3181 eType = AlterSelection;
3182 }
3183
3184 void StdBoxElementSelection::activated(int iMsg)
3185 {
3186 Q_UNUSED(iMsg);
3187 auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
3188 if (view) {
3189 View3DInventorViewer* viewer = view->getViewer();
3190 if (!viewer->isSelecting()) {
3191 // #0002931: Box select misbehaves with touchpad navigation style
3192 // Notify the navigation style to cleanup internal states
3193 int mode = viewer->navigationStyle()->getViewingMode();
3194 if (mode != Gui::NavigationStyle::IDLE) {
3195 SoKeyboardEvent ev;
3196 viewer->navigationStyle()->processEvent(&ev);
3197 }
3198
3199 // NOLINTBEGIN
3200 QCursor cursor = SelectionCallbackHandler::makeCursor(
3201 viewer,
3202 QSize(32, 32),
3203 "edit-element-select-box-cross",
3204 6,
3205 6
3206 );
3207 SelectionCallbackHandler::Create(
3208 viewer,
3209 View3DInventorViewer::Rubberband,
3210 cursor,
3211 doSelect,
3212 this
3213 );
3214 viewer->setSelectionEnabled(false);
3215 // NOLINTEND
3216 }
3217 }
3218 }
3219
3220
3221 //===========================================================================
3222 // Std_TreeSelection
3223 //===========================================================================
3224
3225 DEF_STD_CMD(StdTreeSelection)
3226
3227 StdTreeSelection::StdTreeSelection()
3228 : Command("Std_TreeSelection")
3229 {
3230 sGroup = "TreeView";
3231 sMenuText = QT_TR_NOOP("&Go to Selection");
3232 sToolTipText = QT_TR_NOOP("Scrolls to the first selected item");
3233 sWhatsThis = "Std_TreeSelection";
3234 sStatusTip = sToolTipText;
3235 eType = Alter3DView;
3236 sPixmap = "tree-goto-sel";
3237 sAccel = "T,G";
3238 }
3239
3240 void StdTreeSelection::activated(int iMsg)
3241 {
3242 Q_UNUSED(iMsg);
3243 TreeWidget::scrollItemToTop();
3244 }
3245
3246 //===========================================================================
3247 // Std_TreeCollapse
3248 //===========================================================================
3249
3250 DEF_STD_CMD(StdCmdTreeCollapse)
3251
3252 StdCmdTreeCollapse::StdCmdTreeCollapse()
3253 : Command("Std_TreeCollapse")
3254 {
3255 sGroup = "View";
3256 sMenuText = QT_TR_NOOP("Collapse Selected Items");
3257 sToolTipText = QT_TR_NOOP("Collapses the currently selected tree items");
3258 sWhatsThis = "Std_TreeCollapse";
3259 sStatusTip = sToolTipText;
3260 eType = Alter3DView;
3261 }
3262
3263 void StdCmdTreeCollapse::activated(int iMsg)
3264 {
3265 Q_UNUSED(iMsg);
3266 QList<TreeWidget*> tree = Gui::getMainWindow()->findChildren<TreeWidget*>();
3267 for (QList<TreeWidget*>::iterator it = tree.begin(); it != tree.end(); ++it) {
3268 (*it)->expandSelectedItems(TreeItemMode::CollapseItem);
3269 }
3270 }
3271
3272 //===========================================================================
3273 // Std_TreeExpand
3274 //===========================================================================
3275
3276 DEF_STD_CMD(StdCmdTreeExpand)
3277
3278 StdCmdTreeExpand::StdCmdTreeExpand()
3279 : Command("Std_TreeExpand")
3280 {
3281 sGroup = "View";
3282 sMenuText = QT_TR_NOOP("Expand Selected Items");
3283 sToolTipText = QT_TR_NOOP("Expands the currently selected tree items");
3284 sWhatsThis = "Std_TreeExpand";
3285 sStatusTip = sToolTipText;
3286 eType = Alter3DView;
3287 }
3288
3289 void StdCmdTreeExpand::activated(int iMsg)
3290 {
3291 Q_UNUSED(iMsg);
3292 QList<TreeWidget*> tree = Gui::getMainWindow()->findChildren<TreeWidget*>();
3293 for (QList<TreeWidget*>::iterator it = tree.begin(); it != tree.end(); ++it) {
3294 (*it)->expandSelectedItems(TreeItemMode::ExpandItem);
3295 }
3296 }
3297
3298 //===========================================================================
3299 // Std_TreeSelectAllInstance
3300 //===========================================================================
3301
3302 DEF_STD_CMD_A(StdCmdTreeSelectAllInstances)
3303
3304 StdCmdTreeSelectAllInstances::StdCmdTreeSelectAllInstances()
3305 : Command("Std_TreeSelectAllInstances")
3306 {
3307 sGroup = "View";
3308 sMenuText = QT_TR_NOOP("Select All Instances");
3309 sToolTipText = QT_TR_NOOP("Selects all instances of the currently selected object");
3310 sWhatsThis = "Std_TreeSelectAllInstances";
3311 sStatusTip = sToolTipText;
3312 sPixmap = "sel-instance";
3313 eType = AlterSelection;
3314 }
3315
3316 bool StdCmdTreeSelectAllInstances::isActive()
3317 {
3318 const auto& sels = Selection().getSelectionEx(
3319 "*",
3320 App::DocumentObject::getClassTypeId(),
3321 ResolveMode::OldStyleElement,
3322 true
3323 );
3324 if (sels.empty()) {
3325 return false;
3326 }
3327 auto obj = sels[0].getObject();
3328 if (!obj || !obj->isAttachedToDocument()) {
3329 return false;
3330 }
3331 return freecad_cast<ViewProviderDocumentObject*>(Application::Instance->getViewProvider(obj))
3332 != nullptr;
3333 }
3334
3335 void StdCmdTreeSelectAllInstances::activated(int iMsg)
3336 {
3337 Q_UNUSED(iMsg);
3338 const auto& sels = Selection().getSelectionEx(
3339 "*",
3340 App::DocumentObject::getClassTypeId(),
3341 ResolveMode::OldStyleElement,
3342 true
3343 );
3344 if (sels.empty()) {
3345 return;
3346 }
3347 auto obj = sels[0].getObject();
3348 if (!obj || !obj->isAttachedToDocument()) {
3349 return;
3350 }
3351 auto vpd = freecad_cast<ViewProviderDocumentObject*>(Application::Instance->getViewProvider(obj));
3352 if (!vpd) {
3353 return;
3354 }
3355 Selection().selStackPush();
3356 Selection().clearCompleteSelection();
3357 const auto trees = getMainWindow()->findChildren<TreeWidget*>();
3358 for (auto tree : trees) {
3359 tree->selectAllInstances(*vpd);
3360 }
3361 Selection().selStackPush();
3362 }
3363
3364
3365 //===========================================================================
3366 // Std_SceneInspector
3367 //===========================================================================
3368
3369 DEF_3DV_CMD(StdCmdSceneInspector)
3370
3371 StdCmdSceneInspector::StdCmdSceneInspector()
3372 : Command("Std_SceneInspector")
3373 {
3374 // setting the
3375 sGroup = "Tools";
3376 sMenuText = QT_TR_NOOP("Scene I&nspector");
3377 sToolTipText = QT_TR_NOOP("Opens the scene inspector");
3378 sWhatsThis = "Std_SceneInspector";
3379 sStatusTip = sToolTipText;
3380 eType = Alter3DView;
3381 sPixmap = "Std_SceneInspector";
3382 }
3383
3384 void StdCmdSceneInspector::activated(int iMsg)
3385 {
3386 Q_UNUSED(iMsg);
3387 Gui::Document* doc = Application::Instance->activeDocument();
3388 if (doc) {
3389 static QPointer<Gui::Dialog::DlgInspector> dlg = nullptr;
3390 if (!dlg) {
3391 dlg = new Gui::Dialog::DlgInspector(getMainWindow());
3392 }
3393 dlg->setDocument(doc);
3394 dlg->setAttribute(Qt::WA_DeleteOnClose);
3395 dlg->show();
3396 }
3397 }
3398
3399 //===========================================================================
3400 // Std_TextureMapping
3401 //===========================================================================
3402
3403 DEF_STD_CMD_A(StdCmdTextureMapping)
3404
3405 StdCmdTextureMapping::StdCmdTextureMapping()
3406 : Command("Std_TextureMapping")
3407 {
3408 // setting the
3409 sGroup = "Tools";
3410 sMenuText = QT_TR_NOOP("Text&ure Mapping");
3411 sToolTipText = QT_TR_NOOP("Maps textures to shapes");
3412 sWhatsThis = "Std_TextureMapping";
3413 sStatusTip = sToolTipText;
3414 sPixmap = "Std_TextureMapping";
3415 eType = Alter3DView;
3416 }
3417
3418 void StdCmdTextureMapping::activated(int iMsg)
3419 {
3420 Q_UNUSED(iMsg);
3421 Gui::Control().showDialog(new Gui::Dialog::TaskTextureMapping);
3422 }
3423
3424 bool StdCmdTextureMapping::isActive()
3425 {
3426 Gui::MDIView* view = getMainWindow()->activeWindow();
3427 return view && view->isDerivedFrom<Gui::View3DInventor>() && (!(Gui::Control().activeDialog()));
3428 }
3429
3430 DEF_STD_CMD(StdCmdDemoMode)
3431
3432 StdCmdDemoMode::StdCmdDemoMode()
3433 : Command("Std_DemoMode")
3434 {
3435 sGroup = "Standard-View";
3436 sMenuText = QT_TR_NOOP("View &Turntable");
3437 sToolTipText = QT_TR_NOOP("Opens a turntable view");
3438 sWhatsThis = "Std_DemoMode";
3439 sStatusTip = sToolTipText;
3440 eType = Alter3DView;
3441 sPixmap = "Std_DemoMode";
3442 }
3443
3444 void StdCmdDemoMode::activated(int iMsg)
3445 {
3446 Q_UNUSED(iMsg);
3447 static QPointer<QDialog> dlg = nullptr;
3448 if (!dlg) {
3449 dlg = new Gui::Dialog::DemoMode(getMainWindow());
3450 }
3451 dlg->setAttribute(Qt::WA_DeleteOnClose);
3452 dlg->show();
3453 }
3454
3455
3456 //===========================================================================
3457 // Std_SelBack
3458 //===========================================================================
3459
3460 DEF_STD_CMD_A(StdCmdSelBack)
3461
3462 StdCmdSelBack::StdCmdSelBack()
3463 : Command("Std_SelBack")
3464 {
3465 sGroup = "View";
3466 sMenuText = QT_TR_NOOP("Selection &Back");
3467 static std::string toolTip = std::string("<p>")
3468 + QT_TR_NOOP("Restores the previous tree view selection. "
3469 "Only works if tree RecordSelection mode is switched on.")
3470 + "</p>";
3471 sToolTipText = toolTip.c_str();
3472 sWhatsThis = "Std_SelBack";
3473 sStatusTip = sToolTipText;
3474 sPixmap = "sel-back";
3475 sAccel = "S, B";
3476 eType = AlterSelection;
3477 }
3478
3479 void StdCmdSelBack::activated(int iMsg)
3480 {
3481 Q_UNUSED(iMsg);
3482 Selection().selStackGoBack();
3483 }
3484
3485 bool StdCmdSelBack::isActive()
3486 {
3487 return Selection().selStackBackSize() > 1;
3488 }
3489
3490 //===========================================================================
3491 // Std_SelForward
3492 //===========================================================================
3493
3494 DEF_STD_CMD_A(StdCmdSelForward)
3495
3496 StdCmdSelForward::StdCmdSelForward()
3497 : Command("Std_SelForward")
3498 {
3499 sGroup = "View";
3500 sMenuText = QT_TR_NOOP("Selection &Forward");
3501 static std::string toolTip = std::string("<p>")
3502 + QT_TR_NOOP("Restores the next tree view selection. "
3503 "Only works if tree RecordSelection mode is switched on.")
3504 + "</p>";
3505 sToolTipText = toolTip.c_str();
3506 sWhatsThis = "Std_SelForward";
3507 sStatusTip = sToolTipText;
3508 sPixmap = "sel-forward";
3509 sAccel = "S, F";
3510 eType = AlterSelection;
3511 }
3512
3513 void StdCmdSelForward::activated(int iMsg)
3514 {
3515 Q_UNUSED(iMsg);
3516 Selection().selStackGoForward();
3517 }
3518
3519 bool StdCmdSelForward::isActive()
3520 {
3521 return !!Selection().selStackForwardSize();
3522 }
3523
3524 //=======================================================================
3525 // Std_TreeSingleDocument
3526 //===========================================================================
3527 #define TREEVIEW_DOC_CMD_DEF(_name, _v) \
3528 DEF_STD_CMD_AC(StdTree##_name) \
3529 void StdTree##_name::activated(int) \
3530 { \
3531 TreeParams::setDocumentMode(_v); \
3532 if (_pcAction) \
3533 _pcAction->setBlockedChecked(true); \
3534 } \
3535 Action* StdTree##_name::createAction(void) \
3536 { \
3537 Action* pcAction = Command::createAction(); \
3538 pcAction->setCheckable(true); \
3539 pcAction->setIcon(QIcon()); \
3540 _pcAction = pcAction; \
3541 isActive(); \
3542 return pcAction; \
3543 } \
3544 bool StdTree##_name::isActive() \
3545 { \
3546 bool checked = TreeParams::getDocumentMode() == _v; \
3547 if (_pcAction && _pcAction->isChecked() != checked) \
3548 _pcAction->setBlockedChecked(checked); \
3549 return true; \
3550 }
3551
3552 TREEVIEW_DOC_CMD_DEF(SingleDocument, 0)
3553
3554 StdTreeSingleDocument::StdTreeSingleDocument()
3555 : Command("Std_TreeSingleDocument")
3556 {
3557 sGroup = "TreeView";
3558 sMenuText = QT_TR_NOOP("&Single Document");
3559 sToolTipText = QT_TR_NOOP("Displays only the active document in the tree view");
3560 sWhatsThis = "Std_TreeSingleDocument";
3561 sStatusTip = sToolTipText;
3562 sPixmap = "tree-doc-single";
3563 eType = 0;
3564 }
3565
3566 //===========================================================================
3567 // Std_TreeMultiDocument
3568 //===========================================================================
3569 TREEVIEW_DOC_CMD_DEF(MultiDocument, 1)
3570
3571 StdTreeMultiDocument::StdTreeMultiDocument()
3572 : Command("Std_TreeMultiDocument")
3573 {
3574 sGroup = "TreeView";
3575 sMenuText = QT_TR_NOOP("&Multi Document");
3576 sToolTipText = QT_TR_NOOP("Displays all documents in the tree view");
3577 sWhatsThis = "Std_TreeMultiDocument";
3578 sStatusTip = sToolTipText;
3579 sPixmap = "tree-doc-multi";
3580 eType = 0;
3581 }
3582
3583 //===========================================================================
3584 // Std_TreeCollapseDocument
3585 //===========================================================================
3586 TREEVIEW_DOC_CMD_DEF(CollapseDocument, 2)
3587
3588 StdTreeCollapseDocument::StdTreeCollapseDocument()
3589 : Command("Std_TreeCollapseDocument")
3590 {
3591 sGroup = "TreeView";
3592 sMenuText = QT_TR_NOOP("Collapse/E&xpand");
3593 sToolTipText = QT_TR_NOOP("Expands the active document and collapses all others");
3594 sWhatsThis = "Std_TreeCollapseDocument";
3595 sStatusTip = sToolTipText;
3596 sPixmap = "tree-doc-collapse";
3597 eType = 0;
3598 }
3599
3600 //===========================================================================
3601 // Std_TreeSyncView
3602 //===========================================================================
3603 #define TREEVIEW_CMD_DEF(_name) \
3604 DEF_STD_CMD_AC(StdTree##_name) \
3605 void StdTree##_name::activated(int) \
3606 { \
3607 auto checked = !TreeParams::get##_name(); \
3608 TreeParams::set##_name(checked); \
3609 if (_pcAction) \
3610 _pcAction->setBlockedChecked(checked); \
3611 } \
3612 Action* StdTree##_name::createAction() \
3613 { \
3614 Action* pcAction = Command::createAction(); \
3615 pcAction->setCheckable(true); \
3616 pcAction->setIcon(QIcon()); \
3617 _pcAction = pcAction; \
3618 isActive(); \
3619 return pcAction; \
3620 } \
3621 bool StdTree##_name::isActive() \
3622 { \
3623 bool checked = TreeParams::get##_name(); \
3624 if (_pcAction && _pcAction->isChecked() != checked) \
3625 _pcAction->setBlockedChecked(checked); \
3626 return true; \
3627 }
3628
3629 TREEVIEW_CMD_DEF(SyncView)
3630
3631 StdTreeSyncView::StdTreeSyncView()
3632 : Command("Std_TreeSyncView")
3633 {
3634 sGroup = "TreeView";
3635 sMenuText = QT_TR_NOOP("&1 Sync View");
3636 sToolTipText = QT_TR_NOOP(
3637 "Switches to the 3D view containing the selected item from the tree view"
3638 );
3639 sStatusTip = sToolTipText;
3640 sWhatsThis = "Std_TreeSyncView";
3641 sPixmap = "tree-sync-view";
3642 sAccel = "T,1";
3643 eType = 0;
3644 }
3645
3646 //===========================================================================
3647 // Std_TreeSyncSelection
3648 //===========================================================================
3649 TREEVIEW_CMD_DEF(SyncSelection)
3650
3651 StdTreeSyncSelection::StdTreeSyncSelection()
3652 : Command("Std_TreeSyncSelection")
3653 {
3654 sGroup = "TreeView";
3655 sMenuText = QT_TR_NOOP("&2 Sync Selection");
3656 sToolTipText = QT_TR_NOOP(
3657 "Expands the tree item when the corresponding object is selected in the 3D view"
3658 );
3659 sStatusTip = sToolTipText;
3660 sWhatsThis = "Std_TreeSyncSelection";
3661 sPixmap = "tree-sync-sel";
3662 sAccel = "T,2";
3663 eType = 0;
3664 }
3665
3666 //===========================================================================
3667 // Std_TreeSyncPlacement
3668 //===========================================================================
3669 TREEVIEW_CMD_DEF(SyncPlacement)
3670
3671 StdTreeSyncPlacement::StdTreeSyncPlacement()
3672 : Command("Std_TreeSyncPlacement")
3673 {
3674 sGroup = "TreeView";
3675 sMenuText = QT_TR_NOOP("&3 Sync Placement");
3676 sToolTipText
3677 = QT_TR_NOOP("Adjusts the placement on drag-and-drop of objects across coordinate systems (e.g. in part containers)");
3678 sStatusTip = sToolTipText;
3679 sWhatsThis = "Std_TreeSyncPlacement";
3680 sPixmap = "tree-sync-pla";
3681 sAccel = "T,3";
3682 eType = 0;
3683 }
3684
3685 //===========================================================================
3686 // Std_TreePreSelection
3687 //===========================================================================
3688 TREEVIEW_CMD_DEF(PreSelection)
3689
3690 StdTreePreSelection::StdTreePreSelection()
3691 : Command("Std_TreePreSelection")
3692 {
3693 sGroup = "TreeView";
3694 sMenuText = QT_TR_NOOP("&4 Preselection");
3695 sToolTipText = QT_TR_NOOP(
3696 "Preselects the object in 3D view when hovering the cursor over the tree item"
3697 );
3698 sStatusTip = sToolTipText;
3699 sWhatsThis = "Std_TreePreSelection";
3700 sPixmap = "tree-pre-sel";
3701 sAccel = "T,4";
3702 eType = 0;
3703 }
3704
3705 //===========================================================================
3706 // Std_TreeRecordSelection
3707 //===========================================================================
3708 TREEVIEW_CMD_DEF(RecordSelection)
3709
3710 StdTreeRecordSelection::StdTreeRecordSelection()
3711 : Command("Std_TreeRecordSelection")
3712 {
3713 sGroup = "TreeView";
3714 sMenuText = QT_TR_NOOP("&5 Record Selection");
3715 sToolTipText
3716 = QT_TR_NOOP("Records the selection in the tree view in order to go back/forward using the navigation buttons");
3717 sStatusTip = sToolTipText;
3718 sWhatsThis = "Std_TreeRecordSelection";
3719 sPixmap = "tree-rec-sel";
3720 sAccel = "T,5";
3721 eType = 0;
3722 }
3723
3724 //===========================================================================
3725 // Std_TreeDrag
3726 //===========================================================================
3727 DEF_STD_CMD(StdTreeDrag)
3728
3729 StdTreeDrag::StdTreeDrag()
3730 : Command("Std_TreeDrag")
3731 {
3732 sGroup = "TreeView";
3733 sMenuText = QT_TR_NOOP("Initiate &Dragging");
3734 sToolTipText = QT_TR_NOOP("Initiates dragging of the currently selected tree items");
3735 sStatusTip = sToolTipText;
3736 sWhatsThis = "Std_TreeDrag";
3737 sPixmap = "tree-item-drag";
3738 sAccel = "T,D";
3739 eType = 0;
3740 }
3741
3742 void StdTreeDrag::activated(int)
3743 {
3744 if (Gui::Selection().hasSelection()) {
3745 const auto trees = getMainWindow()->findChildren<TreeWidget*>();
3746 for (auto tree : trees) {
3747 if (tree->isVisible()) {
3748 tree->startDragging();
3749 break;
3750 }
3751 }
3752 }
3753 }
3754
3755 //======================================================================
3756 // Std_TreeViewActions
3757 //===========================================================================
3758 //
3759 class StdCmdTreeViewActions: public GroupCommand
3760 {
3761 public:
3762 StdCmdTreeViewActions()
3763 : GroupCommand("Std_TreeViewActions")
3764 {
3765 sGroup = "TreeView";
3766 sMenuText = QT_TR_NOOP("Tree View Actions");
3767 sToolTipText = QT_TR_NOOP("Tree view behavior options and actions");
3768 sWhatsThis = "Std_TreeViewActions";
3769 sStatusTip = sToolTipText;
3770 eType = 0;
3771 bCanLog = false;
3772
3773 addCommand(new StdTreeSyncView());
3774 addCommand(new StdTreeSyncSelection());
3775 addCommand(new StdTreeSyncPlacement());
3776 addCommand(new StdTreePreSelection());
3777 addCommand(new StdTreeRecordSelection());
3778
3779 addCommand();
3780
3781 addCommand(new StdTreeSingleDocument());
3782 addCommand(new StdTreeMultiDocument());
3783 addCommand(new StdTreeCollapseDocument());
3784
3785 addCommand();
3786
3787 addCommand(new StdTreeDrag(), !cmds.empty());
3788 addCommand(new StdTreeSelection(), !cmds.empty());
3789
3790 addCommand();
3791
3792 addCommand(new StdCmdSelBack());
3793 addCommand(new StdCmdSelForward());
3794 }
3795 const char* className() const override
3796 {
3797 return "StdCmdTreeViewActions";
3798 }
3799 };
3800
3801
3802 //======================================================================
3803 // Std_SelBoundingBox
3804 //===========================================================================
3805 DEF_STD_CMD_AC(StdCmdSelBoundingBox)
3806
3807 StdCmdSelBoundingBox::StdCmdSelBoundingBox()
3808 : Command("Std_SelBoundingBox")
3809 {
3810 sGroup = "View";
3811 sMenuText = QT_TR_NOOP("&Bounding Box");
3812 sToolTipText = QT_TR_NOOP("Shows selection bounding box");
3813 sWhatsThis = "Std_SelBoundingBox";
3814 sStatusTip = sToolTipText;
3815 sPixmap = "sel-bbox";
3816 eType = Alter3DView;
3817 }
3818
3819 void StdCmdSelBoundingBox::activated(int iMsg)
3820 {
3821 bool checked = !!iMsg;
3822 if (checked != ViewParams::instance()->getShowSelectionBoundingBox()) {
3823 ViewParams::instance()->setShowSelectionBoundingBox(checked);
3824 if (_pcAction) {
3825 _pcAction->setBlockedChecked(checked);
3826 }
3827 }
3828 }
3829
3830 bool StdCmdSelBoundingBox::isActive()
3831 {
3832 if (_pcAction) {
3833 bool checked = _pcAction->isChecked();
3834 if (checked != ViewParams::instance()->getShowSelectionBoundingBox()) {
3835 _pcAction->setBlockedChecked(!checked);
3836 }
3837 }
3838 return true;
3839 }
3840
3841 Action* StdCmdSelBoundingBox::createAction()
3842 {
3843 Action* pcAction = Command::createAction();
3844 pcAction->setCheckable(true);
3845 return pcAction;
3846 }
3847
3848 //===========================================================================
3849 // Std_DockOverlayAll
3850 //===========================================================================
3851
3852 DEF_STD_CMD(StdCmdDockOverlayAll)
3853
3854 StdCmdDockOverlayAll::StdCmdDockOverlayAll()
3855 : Command("Std_DockOverlayAll")
3856 {
3857 sGroup = "View";
3858 sMenuText = QT_TR_NOOP("Toggle Overl&ay for All Panels");
3859 sToolTipText = QT_TR_NOOP("Toggled overlay mode for all docked panels");
3860 sWhatsThis = "Std_DockOverlayAll";
3861 sStatusTip = sToolTipText;
3862 eType = 0;
3863 }
3864
3865 void StdCmdDockOverlayAll::activated(int iMsg)
3866 {
3867 Q_UNUSED(iMsg);
3868 OverlayManager::instance()->setOverlayMode(OverlayManager::OverlayMode::ToggleAll);
3869 }
3870
3871 //===========================================================================
3872 // Std_DockOverlayTransparentAll
3873 //===========================================================================
3874
3875 DEF_STD_CMD(StdCmdDockOverlayTransparentAll)
3876
3877 StdCmdDockOverlayTransparentAll::StdCmdDockOverlayTransparentAll()
3878 : Command("Std_DockOverlayTransparentAll")
3879 {
3880 sGroup = "View";
3881 sMenuText = QT_TR_NOOP("Toggle Tra&nsparent Panels");
3882 sToolTipText = QT_TR_NOOP(
3883 "Toggles transparent mode for all docked overlay panels.\n"
3884 "This makes the docked panels stay transparent at all times."
3885 );
3886 sWhatsThis = "Std_DockOverlayTransparentAll";
3887 sStatusTip = sToolTipText;
3888 eType = 0;
3889 }
3890
3891 void StdCmdDockOverlayTransparentAll::activated(int iMsg)
3892 {
3893 Q_UNUSED(iMsg);
3894 OverlayManager::instance()->setOverlayMode(OverlayManager::OverlayMode::ToggleTransparentAll);
3895 }
3896
3897 //===========================================================================
3898 // Std_DockOverlayToggle
3899 //===========================================================================
3900
3901 DEF_STD_CMD(StdCmdDockOverlayToggle)
3902
3903 StdCmdDockOverlayToggle::StdCmdDockOverlayToggle()
3904 : Command("Std_DockOverlayToggle")
3905 {
3906 sGroup = "View";
3907 sMenuText = QT_TR_NOOP("Toggle &Overlay");
3908 sToolTipText = QT_TR_NOOP("Toggles overlay mode for the docked window under the cursor");
3909 sWhatsThis = "Std_DockOverlayToggle";
3910 sStatusTip = sToolTipText;
3911 eType = 0;
3912 }
3913
3914 void StdCmdDockOverlayToggle::activated(int iMsg)
3915 {
3916 Q_UNUSED(iMsg);
3917 OverlayManager::instance()->setOverlayMode(OverlayManager::OverlayMode::ToggleActive);
3918 }
3919
3920 //===========================================================================
3921 // Std_DockOverlayToggleTransparent
3922 //===========================================================================
3923
3924 DEF_STD_CMD(StdCmdDockOverlayToggleTransparent)
3925
3926 StdCmdDockOverlayToggleTransparent::StdCmdDockOverlayToggleTransparent()
3927 : Command("Std_DockOverlayToggleTransparent")
3928 {
3929 sGroup = "Standard-View";
3930 sMenuText = QT_TR_NOOP("Toggle Tran&sparent Mode");
3931 sToolTipText = QT_TR_NOOP(
3932 "Toggles transparent mode for the docked panel under cursor.\n"
3933 "This makes the docked panel stay transparent at all times."
3934 );
3935 sWhatsThis = "Std_DockOverlayToggleTransparent";
3936 sStatusTip = sToolTipText;
3937 eType = 0;
3938 }
3939
3940 void StdCmdDockOverlayToggleTransparent::activated(int iMsg)
3941 {
3942 Q_UNUSED(iMsg);
3943 OverlayManager::instance()->setOverlayMode(OverlayManager::OverlayMode::ToggleTransparent);
3944 }
3945
3946 //===========================================================================
3947 // Std_DockOverlayToggleLeft
3948 //===========================================================================
3949
3950 DEF_STD_CMD(StdCmdDockOverlayToggleLeft)
3951
3952 StdCmdDockOverlayToggleLeft::StdCmdDockOverlayToggleLeft()
3953 : Command("Std_DockOverlayToggleLeft")
3954 {
3955 sGroup = "Standard-View";
3956 sMenuText = QT_TR_NOOP("Toggle &Left");
3957 sToolTipText = QT_TR_NOOP("Toggles the visibility of the left overlay panel");
3958 sWhatsThis = "Std_DockOverlayToggleLeft";
3959 sStatusTip = sToolTipText;
3960 sAccel = "Ctrl+Left";
3961 sPixmap = "Std_DockOverlayToggleLeft";
3962 eType = 0;
3963 }
3964
3965 void StdCmdDockOverlayToggleLeft::activated(int iMsg)
3966 {
3967 Q_UNUSED(iMsg);
3968 OverlayManager::instance()->setOverlayMode(OverlayManager::OverlayMode::ToggleLeft);
3969 }
3970
3971 //===========================================================================
3972 // Std_DockOverlayToggleRight
3973 //===========================================================================
3974
3975 DEF_STD_CMD(StdCmdDockOverlayToggleRight)
3976
3977 StdCmdDockOverlayToggleRight::StdCmdDockOverlayToggleRight()
3978 : Command("Std_DockOverlayToggleRight")
3979 {
3980 sGroup = "Standard-View";
3981 sMenuText = QT_TR_NOOP("Toggle &Right");
3982 sToolTipText = QT_TR_NOOP("Toggles the visibility of the right overlay panel");
3983 sWhatsThis = "Std_DockOverlayToggleRight";
3984 sStatusTip = sToolTipText;
3985 sAccel = "Ctrl+Right";
3986 sPixmap = "Std_DockOverlayToggleRight";
3987 eType = 0;
3988 }
3989
3990 void StdCmdDockOverlayToggleRight::activated(int iMsg)
3991 {
3992 Q_UNUSED(iMsg);
3993 OverlayManager::instance()->setOverlayMode(OverlayManager::OverlayMode::ToggleRight);
3994 }
3995
3996 //===========================================================================
3997 // Std_DockOverlayToggleTop
3998 //===========================================================================
3999
4000 DEF_STD_CMD(StdCmdDockOverlayToggleTop)
4001
4002 StdCmdDockOverlayToggleTop::StdCmdDockOverlayToggleTop()
4003 : Command("Std_DockOverlayToggleTop")
4004 {
4005 sGroup = "Standard-View";
4006 sMenuText = QT_TR_NOOP("Toggle &Top");
4007 sToolTipText = QT_TR_NOOP("Toggles the visibility of the top overlay panel");
4008 sWhatsThis = "Std_DockOverlayToggleTop";
4009 sStatusTip = sToolTipText;
4010 sAccel = "Ctrl+Up";
4011 sPixmap = "Std_DockOverlayToggleTop";
4012 eType = 0;
4013 }
4014
4015 void StdCmdDockOverlayToggleTop::activated(int iMsg)
4016 {
4017 Q_UNUSED(iMsg);
4018 OverlayManager::instance()->setOverlayMode(OverlayManager::OverlayMode::ToggleTop);
4019 }
4020
4021 //===========================================================================
4022 // Std_DockOverlayToggleBottom
4023 //===========================================================================
4024
4025 DEF_STD_CMD(StdCmdDockOverlayToggleBottom)
4026
4027 StdCmdDockOverlayToggleBottom::StdCmdDockOverlayToggleBottom()
4028 : Command("Std_DockOverlayToggleBottom")
4029 {
4030 sGroup = "Standard-View";
4031 sMenuText = QT_TR_NOOP("Toggle &Bottom");
4032 sToolTipText = QT_TR_NOOP("Toggles the visibility of the bottom overlay panel");
4033 sWhatsThis = "Std_DockOverlayToggleBottom";
4034 sStatusTip = sToolTipText;
4035 sAccel = "Ctrl+Down";
4036 sPixmap = "Std_DockOverlayToggleBottom";
4037 eType = 0;
4038 }
4039
4040 void StdCmdDockOverlayToggleBottom::activated(int iMsg)
4041 {
4042 Q_UNUSED(iMsg);
4043 OverlayManager::instance()->setOverlayMode(OverlayManager::OverlayMode::ToggleBottom);
4044 }
4045
4046 //===========================================================================
4047 // Std_DockOverlayMouseTransparent
4048 //===========================================================================
4049
4050 DEF_STD_CMD_AC(StdCmdDockOverlayMouseTransparent)
4051
4052 StdCmdDockOverlayMouseTransparent::StdCmdDockOverlayMouseTransparent()
4053 : Command("Std_DockOverlayMouseTransparent")
4054 {
4055 sGroup = "View";
4056 sMenuText = QT_TR_NOOP("Bypass &Mouse Events in Overlay Panels");
4057 sToolTipText = QT_TR_NOOP("Bypasses all mouse events in docked overlay panels");
4058 sWhatsThis = "Std_DockOverlayMouseTransparent";
4059 sStatusTip = sToolTipText;
4060 sAccel = "T, T";
4061 eType = NoTransaction;
4062 }
4063
4064 void StdCmdDockOverlayMouseTransparent::activated(int iMsg)
4065 {
4066 (void)iMsg;
4067 bool checked = !OverlayManager::instance()->isMouseTransparent();
4068 OverlayManager::instance()->setMouseTransparent(checked);
4069 if (_pcAction) {
4070 _pcAction->setBlockedChecked(checked);
4071 }
4072 }
4073
4074 Action* StdCmdDockOverlayMouseTransparent::createAction()
4075 {
4076 Action* pcAction = Command::createAction();
4077 pcAction->setCheckable(true);
4078 pcAction->setIcon(QIcon());
4079 _pcAction = pcAction;
4080 isActive();
4081 return pcAction;
4082 }
4083
4084 bool StdCmdDockOverlayMouseTransparent::isActive()
4085 {
4086 bool checked = OverlayManager::instance()->isMouseTransparent();
4087 if (_pcAction && _pcAction->isChecked() != checked) {
4088 _pcAction->setBlockedChecked(checked);
4089 }
4090 return true;
4091 }
4092
4093 // ============================================================================
4094
4095 class StdCmdDockOverlay: public GroupCommand
4096 {
4097 public:
4098 StdCmdDockOverlay()
4099 : GroupCommand("Std_DockOverlay")
4100 {
4101 sGroup = "View";
4102 sMenuText = QT_TR_NOOP("Overlay Docked Panel");
4103 sToolTipText = QT_TR_NOOP("Sets the docked panel in overlay mode");
4104 sWhatsThis = "Std_DockOverlay";
4105 sStatusTip = sToolTipText;
4106 eType = 0;
4107 bCanLog = false;
4108
4109 addCommand(new StdCmdDockOverlayAll());
4110 addCommand(new StdCmdDockOverlayTransparentAll());
4111 addCommand();
4112 addCommand(new StdCmdDockOverlayToggle());
4113 addCommand(new StdCmdDockOverlayToggleTransparent());
4114 addCommand();
4115 addCommand(new StdCmdDockOverlayMouseTransparent());
4116 addCommand();
4117 addCommand(new StdCmdDockOverlayToggleLeft());
4118 addCommand(new StdCmdDockOverlayToggleRight());
4119 addCommand(new StdCmdDockOverlayToggleTop());
4120 addCommand(new StdCmdDockOverlayToggleBottom());
4121 };
4122 virtual const char* className() const
4123 {
4124 return "StdCmdDockOverlay";
4125 }
4126 };
4127
4128 //===========================================================================
4129 // Std_StoreWorkingView
4130 //===========================================================================
4131 DEF_STD_CMD_A(StdStoreWorkingView)
4132
4133 StdStoreWorkingView::StdStoreWorkingView()
4134 : Command("Std_StoreWorkingView")
4135 {
4136 sGroup = "Standard-View";
4137 sMenuText = QT_TR_NOOP("St&ore Working View");
4138 sToolTipText = QT_TR_NOOP("Stores a temporary working view for the current document");
4139 sStatusTip = sToolTipText;
4140 sWhatsThis = "Std_StoreWorkingView";
4141 sAccel = "Shift+End";
4142 eType = NoTransaction;
4143 }
4144
4145 void StdStoreWorkingView::activated(int iMsg)
4146 {
4147 Q_UNUSED(iMsg);
4148 if (auto view = dynamic_cast<Gui::View3DInventor*>(Gui::getMainWindow()->activeWindow())) {
4149 view->getViewer()->saveHomePosition();
4150 }
4151 }
4152
4153 bool StdStoreWorkingView::isActive()
4154 {
4155 return dynamic_cast<Gui::View3DInventor*>(Gui::getMainWindow()->activeWindow());
4156 }
4157
4158 //===========================================================================
4159 // Std_RecallWorkingView
4160 //===========================================================================
4161 DEF_STD_CMD_A(StdRecallWorkingView)
4162
4163 StdRecallWorkingView::StdRecallWorkingView()
4164 : Command("Std_RecallWorkingView")
4165 {
4166 sGroup = "Standard-View";
4167 sMenuText = QT_TR_NOOP("R&ecall Working View");
4168 sToolTipText = QT_TR_NOOP("Recalls a previously stored temporary working view");
4169 sStatusTip = sToolTipText;
4170 sWhatsThis = "Std_RecallWorkingView";
4171 sAccel = "End";
4172 eType = NoTransaction;
4173 }
4174
4175 void StdRecallWorkingView::activated(int iMsg)
4176 {
4177 Q_UNUSED(iMsg);
4178 if (auto view = dynamic_cast<Gui::View3DInventor*>(Gui::getMainWindow()->activeWindow())) {
4179 if (view->getViewer()->hasHomePosition()) {
4180 view->getViewer()->resetToHomePosition();
4181 }
4182 }
4183 }
4184
4185 bool StdRecallWorkingView::isActive()
4186 {
4187 auto view = dynamic_cast<Gui::View3DInventor*>(Gui::getMainWindow()->activeWindow());
4188 return view && view->getViewer()->hasHomePosition();
4189 }
4190
4191 //===========================================================================
4192 // Std_AlignToSelection
4193 //===========================================================================
4194 DEF_STD_CMD_A(StdCmdAlignToSelection)
4195
4196 StdCmdAlignToSelection::StdCmdAlignToSelection()
4197 : Command("Std_AlignToSelection")
4198 {
4199 sGroup = "View";
4200 sMenuText = QT_TR_NOOP("&Align to Selection");
4201 sToolTipText = QT_TR_NOOP("Aligns the camera view to the selected elements in the 3D view");
4202 sWhatsThis = "Std_AlignToSelection";
4203 sPixmap = "align-to-selection";
4204 eType = Alter3DView;
4205 }
4206
4207 void StdCmdAlignToSelection::activated(int iMsg)
4208 {
4209 Q_UNUSED(iMsg);
4210 doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"AlignToSelection\")");
4211 }
4212
4213 bool StdCmdAlignToSelection::isActive()
4214 {
4215 return getGuiApplication()->sendHasMsgToActiveView("AlignToSelection");
4216 }
4217
4218 //===========================================================================
4219 // Std_ClarifySelection
4220 //===========================================================================
4221
4222 DEF_STD_CMD_A(StdCmdClarifySelection)
4223
4224 StdCmdClarifySelection::StdCmdClarifySelection()
4225 : Command("Std_ClarifySelection")
4226 {
4227 sGroup = "View";
4228 sMenuText = QT_TR_NOOP("Clarify Selection");
4229 sToolTipText = QT_TR_NOOP(
4230 "Displays a context menu at the mouse cursor to select overlapping "
4231 "or obstructed geometry in the 3D view.\n"
4232 );
4233 sWhatsThis = "Std_ClarifySelection";
4234 sStatusTip = sToolTipText;
4235 sAccel = "G, G";
4236 eType = NoTransaction | AlterSelection;
4237 }
4238
4239 void StdCmdClarifySelection::activated(int iMsg)
4240 {
4241 Q_UNUSED(iMsg);
4242
4243 // Get the active view
4244 auto view3d = freecad_cast<View3DInventor*>(Application::Instance->activeView());
4245 if (!view3d) {
4246 return;
4247 }
4248
4249 auto viewer = view3d->getViewer();
4250 if (!viewer) {
4251 return;
4252 }
4253
4254 QWidget* widget = viewer->getGLWidget();
4255 if (!widget) {
4256 return;
4257 }
4258
4259 // check if we have a stored right-click position (context menu) or should use current cursor
4260 // position (keyboard shortcut)
4261 SbVec2s point;
4262 auto& storedPosition = viewer->navigationStyle()->getRightClickPosition();
4263 if (storedPosition.has_value()) {
4264 point = storedPosition.value();
4265 }
4266 else {
4267 QPoint pos = QCursor::pos();
4268 QPoint local = widget->mapFromGlobal(pos);
4269
4270 qreal devicePixelRatio = widget->devicePixelRatioF();
4271 point = SbVec2s(
4272 static_cast<short>(local.x() * devicePixelRatio),
4273 static_cast<short>((widget->height() - local.y() - 1) * devicePixelRatio)
4274 );
4275 }
4276
4277 // Use ray picking to get all objects under cursor
4278 SoRayPickAction pickAction(viewer->getSoRenderManager()->getViewportRegion());
4279 pickAction.setPoint(point);
4280
4281 constexpr double defaultMultiplier = 5.0F;
4282 double clarifyRadiusMultiplier
4283 = App::GetApplication()
4284 .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
4285 ->GetFloat("ClarifySelectionRadiusMultiplier", defaultMultiplier);
4286
4287 pickAction.setRadius(viewer->getPickRadius() * clarifyRadiusMultiplier);
4288 pickAction.setPickAll(static_cast<SbBool>(true)); // Get all objects under cursor
4289 pickAction.apply(viewer->getSoRenderManager()->getSceneGraph());
4290
4291 const SoPickedPointList& pplist = pickAction.getPickedPointList();
4292 if (pplist.getLength() == 0) {
4293 return;
4294 }
4295
4296 // Convert picked points to PickData list
4297 std::vector<PickData> selections;
4298
4299 for (int i = 0; i < pplist.getLength(); ++i) {
4300 SoPickedPoint* pp = pplist[i];
4301 if (!pp || !pp->getPath()) {
4302 continue;
4303 }
4304
4305 ViewProvider* vp = viewer->getViewProviderByPath(pp->getPath());
4306 if (!vp) {
4307 continue;
4308 }
4309
4310 // Cast to ViewProviderDocumentObject to get the object
4311 auto vpDoc = freecad_cast<Gui::ViewProviderDocumentObject*>(vp);
4312 if (!vpDoc) {
4313 continue;
4314 }
4315
4316 App::DocumentObject* obj = vpDoc->getObject();
4317 if (!obj) {
4318 continue;
4319 }
4320
4321 // Get element information - handle sub-objects like Assembly parts
4322 std::string elementName = vp->getElement(pp->getDetail());
4323 std::string subName;
4324
4325 // Try to get more detailed sub-object information
4326 bool hasSubObject = false;
4327 if (vp->getElementPicked(pp, subName)) {
4328 hasSubObject = true;
4329 }
4330
4331 // Create PickData with selection information
4332 PickData pickData {
4333 .obj = obj,
4334 .element = elementName,
4335 .docName = obj->getDocument()->getName(),
4336 .objName = obj->getNameInDocument(),
4337 .subName = hasSubObject ? subName : elementName
4338 };
4339
4340 selections.push_back(pickData);
4341 }
4342
4343 if (selections.empty()) {
4344 return;
4345 }
4346
4347 QPoint globalPos;
4348 if (storedPosition.has_value()) {
4349 qreal devicePixelRatio = widget->devicePixelRatioF();
4350 int logicalHeight = static_cast<int>(widget->height());
4351 QPoint localPos(
4352 static_cast<int>(point[0] / devicePixelRatio),
4353 logicalHeight - static_cast<int>(point[1] / devicePixelRatio) - 1
4354 );
4355 globalPos = widget->mapToGlobal(localPos);
4356 }
4357 else {
4358 globalPos = QCursor::pos();
4359 }
4360
4361 // Use SelectionMenu to display and handle the pick menu
4362 SelectionMenu contextMenu(widget);
4363 contextMenu.doPick(selections, globalPos);
4364 }
4365
4366 bool StdCmdClarifySelection::isActive()
4367 {
4368 return qobject_cast<View3DInventor*>(getMainWindow()->activeWindow()) != nullptr;
4369 }
4370
4371 //===========================================================================
4372 // Instantiation
4373 //===========================================================================
4374
4375
4376 namespace Gui
4377 {
4378
4379 void CreateViewStdCommands()
4380 {
4381 // NOLINTBEGIN
4382 CommandManager& rcCmdMgr = Application::Instance->commandManager();
4383
4384 // views
4385 rcCmdMgr.addCommand(new StdCmdViewBottom());
4386 rcCmdMgr.addCommand(new StdCmdViewHome());
4387 rcCmdMgr.addCommand(new StdCmdViewFront());
4388 rcCmdMgr.addCommand(new StdCmdViewLeft());
4389 rcCmdMgr.addCommand(new StdCmdViewRear());
4390 rcCmdMgr.addCommand(new StdCmdViewRight());
4391 rcCmdMgr.addCommand(new StdCmdViewTop());
4392 rcCmdMgr.addCommand(new StdCmdViewIsometric());
4393 rcCmdMgr.addCommand(new StdCmdViewDimetric());
4394 rcCmdMgr.addCommand(new StdCmdViewTrimetric());
4395 rcCmdMgr.addCommand(new StdCmdViewFitAll());
4396 rcCmdMgr.addCommand(new StdCmdViewVR());
4397 rcCmdMgr.addCommand(new StdCmdViewFitSelection());
4398 rcCmdMgr.addCommand(new StdCmdViewRotateLeft());
4399 rcCmdMgr.addCommand(new StdCmdViewRotateRight());
4400 rcCmdMgr.addCommand(new StdStoreWorkingView());
4401 rcCmdMgr.addCommand(new StdRecallWorkingView());
4402 rcCmdMgr.addCommand(new StdCmdViewGroup());
4403 rcCmdMgr.addCommand(new StdCmdAlignToSelection());
4404 rcCmdMgr.addCommand(new StdCmdClarifySelection());
4405
4406 rcCmdMgr.addCommand(new StdCmdViewExample1());
4407 rcCmdMgr.addCommand(new StdCmdViewExample2());
4408 rcCmdMgr.addCommand(new StdCmdViewExample3());
4409
4410 rcCmdMgr.addCommand(new StdCmdViewIvStereoQuadBuff());
4411 rcCmdMgr.addCommand(new StdCmdViewIvStereoRedGreen());
4412 rcCmdMgr.addCommand(new StdCmdViewIvStereoInterleavedColumns());
4413 rcCmdMgr.addCommand(new StdCmdViewIvStereoInterleavedRows());
4414 rcCmdMgr.addCommand(new StdCmdViewIvStereoOff());
4415
4416 rcCmdMgr.addCommand(new StdCmdViewIvIssueCamPos());
4417
4418 rcCmdMgr.addCommand(new StdCmdViewCreate());
4419 rcCmdMgr.addCommand(new StdViewScreenShot());
4420 rcCmdMgr.addCommand(new StdViewLoadImage());
4421 rcCmdMgr.addCommand(new StdMainFullscreen());
4422 rcCmdMgr.addCommand(new StdViewDockUndockFullscreen());
4423 rcCmdMgr.addCommand(new StdCmdToggleVisibility());
4424 rcCmdMgr.addCommand(new StdCmdToggleTransparency());
4425 rcCmdMgr.addCommand(new StdCmdToggleSelectability());
4426 rcCmdMgr.addCommand(new StdCmdShowSelection());
4427 rcCmdMgr.addCommand(new StdCmdHideSelection());
4428 rcCmdMgr.addCommand(new StdCmdSelectVisibleObjects());
4429 rcCmdMgr.addCommand(new StdCmdToggleObjects());
4430 rcCmdMgr.addCommand(new StdCmdShowObjects());
4431 rcCmdMgr.addCommand(new StdCmdHideObjects());
4432 rcCmdMgr.addCommand(new StdOrthographicCamera());
4433 rcCmdMgr.addCommand(new StdPerspectiveCamera());
4434 rcCmdMgr.addCommand(new StdCmdToggleClipPlane());
4435 rcCmdMgr.addCommand(new StdCmdDrawStyle());
4436 rcCmdMgr.addCommand(new StdCmdViewSaveCamera());
4437 rcCmdMgr.addCommand(new StdCmdViewRestoreCamera());
4438 rcCmdMgr.addCommand(new StdCmdFreezeViews());
4439 rcCmdMgr.addCommand(new StdViewZoomIn());
4440 rcCmdMgr.addCommand(new StdViewZoomOut());
4441 rcCmdMgr.addCommand(new StdViewBoxZoom());
4442 rcCmdMgr.addCommand(new StdBoxSelection());
4443 rcCmdMgr.addCommand(new StdBoxElementSelection());
4444 rcCmdMgr.addCommand(new StdCmdTreeExpand());
4445 rcCmdMgr.addCommand(new StdCmdTreeCollapse());
4446 rcCmdMgr.addCommand(new StdCmdTreeSelectAllInstances());
4447 rcCmdMgr.addCommand(new StdCmdSceneInspector());
4448 rcCmdMgr.addCommand(new StdCmdTextureMapping());
4449 rcCmdMgr.addCommand(new StdCmdDemoMode());
4450 rcCmdMgr.addCommand(new StdCmdToggleNavigation());
4451 rcCmdMgr.addCommand(new StdCmdAxisCross());
4452 rcCmdMgr.addCommand(new StdCmdSelBoundingBox());
4453 rcCmdMgr.addCommand(new StdCmdTreeViewActions());
4454 rcCmdMgr.addCommand(new StdCmdDockOverlay());
4455
4456 auto hGrp = App::GetApplication().GetParameterGroupByPath(
4457 "User parameter:BaseApp/Preferences/View"
4458 );
4459 if (hGrp->GetASCII("GestureRollFwdCommand").empty()) {
4460 hGrp->SetASCII("GestureRollFwdCommand", "Std_SelForward");
4461 }
4462 if (hGrp->GetASCII("GestureRollBackCommand").empty()) {
4463 hGrp->SetASCII("GestureRollBackCommand", "Std_SelBack");
4464 }
4465 // NOLINTEND
4466 }
4467
4468 } // namespace Gui