/
CommandStd.cpp
722 lines (623 loc) · 25.1 KB
/
CommandStd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/***************************************************************************
* Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QApplication>
# include <QMessageBox>
# include <QSharedPointer>
# include <QWhatsThis>
#if QT_VERSION >= 0x040200
# include <QDesktopServices>
# include <QUrl>
#endif
#endif
#include <boost/scoped_ptr.hpp>
#include <Base/Exception.h>
#include <Base/FileInfo.h>
#include <Base/Interpreter.h>
#include <Base/Sequencer.h>
#include <App/Document.h>
#include "Action.h"
#include "Application.h"
#include "Document.h"
#include "Splashscreen.h"
#include "Command.h"
#include "MainWindow.h"
#include "WhatsThis.h"
#include "DlgUndoRedo.h"
#include "BitmapFactory.h"
#include "View.h"
#include "DlgParameterImp.h"
#include "DlgPreferencesImp.h"
#include "DlgCustomizeImp.h"
#include "Widgets.h"
#include "OnlineDocumentation.h"
#include "GuiConsole.h"
#include "WorkbenchManager.h"
#include "Workbench.h"
#include "Selection.h"
#include "DlgUnitsCalculatorImp.h"
using Base::Console;
using Base::Sequencer;
using namespace Gui;
//===========================================================================
// Std_Workbench
//===========================================================================
DEF_STD_CMD_AC(StdCmdWorkbench);
StdCmdWorkbench::StdCmdWorkbench()
: Command("Std_Workbench")
{
sGroup = QT_TR_NOOP("View");
sMenuText = QT_TR_NOOP("Workbench");
sToolTipText = QT_TR_NOOP("Switch between workbenches");
sWhatsThis = "Std_Workbench";
sStatusTip = QT_TR_NOOP("Switch between workbenches");
sPixmap = "freecad";
eType = 0;
}
void StdCmdWorkbench::activated(int i)
{
try {
Workbench* w = WorkbenchManager::instance()->active();
QList<QAction*> items = static_cast<WorkbenchGroup*>(_pcAction)->actions();
std::string switch_to = (const char*)items[i]->objectName().toLatin1();
if (w) {
std::string current_w = w->name();
if (switch_to == current_w)
return;
}
doCommand(Gui, "Gui.activateWorkbench(\"%s\")", switch_to.c_str());
}
catch(const Base::PyException& e) {
QString msg(QLatin1String(e.what()));
// ignore '<type 'exceptions.*Error'>' prefixes
QRegExp rx;
rx.setPattern(QLatin1String("^\\s*<type 'exceptions.\\w*'>:\\s*"));
int pos = rx.indexIn(msg);
if (pos != -1)
msg = msg.mid(rx.matchedLength());
QMessageBox::critical(getMainWindow(), QObject::tr("Cannot load workbench"), msg);
}
catch(...) {
QMessageBox::critical(getMainWindow(), QObject::tr("Cannot load workbench"),
QObject::tr("A general error occurred while loading the workbench"));
}
}
bool StdCmdWorkbench::isActive(void)
{
return true;
}
Action * StdCmdWorkbench::createAction(void)
{
Action *pcAction;
pcAction = new WorkbenchGroup(this,getMainWindow());
pcAction->setShortcut(QString::fromLatin1(sAccel));
applyCommandData(this->className(), pcAction);
if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().iconFromTheme(sPixmap));
return pcAction;
}
//===========================================================================
// Std_RecentFiles
//===========================================================================
DEF_STD_CMD_C(StdCmdRecentFiles)
StdCmdRecentFiles::StdCmdRecentFiles()
:Command("Std_RecentFiles")
{
sGroup = QT_TR_NOOP("File");
sMenuText = QT_TR_NOOP("Recent files");
sToolTipText = QT_TR_NOOP("Recent file list");
sWhatsThis = "Std_RecentFiles";
sStatusTip = QT_TR_NOOP("Recent file list");
eType = 0;
}
/**
* Opens the recent file at position \a iMsg in the menu.
* If the file does not exist or cannot be loaded this item is removed
* from the list.
*/
void StdCmdRecentFiles::activated(int iMsg)
{
RecentFilesAction* act = qobject_cast<RecentFilesAction*>(_pcAction);
if (act) act->activateFile( iMsg );
}
/**
* Creates the QAction object containing the recent files.
*/
Action * StdCmdRecentFiles::createAction(void)
{
RecentFilesAction* pcAction = new RecentFilesAction(this, getMainWindow());
pcAction->setObjectName(QLatin1String("recentFiles"));
pcAction->setDropDownMenu(true);
applyCommandData(this->className(), pcAction);
return pcAction;
}
//===========================================================================
// Std_About
//===========================================================================
DEF_STD_CMD_ACL(StdCmdAbout)
StdCmdAbout::StdCmdAbout()
:Command("Std_About")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("&About %1");
sToolTipText = QT_TR_NOOP("About %1");
sWhatsThis = "Std_About";
sStatusTip = QT_TR_NOOP("About %1");
eType = 0;
}
Action * StdCmdAbout::createAction(void)
{
Action *pcAction;
QString exe = qApp->applicationName();
pcAction = new Action(this,getMainWindow());
pcAction->setText(QCoreApplication::translate(
this->className(), sMenuText, 0,
QCoreApplication::CodecForTr).arg(exe));
pcAction->setToolTip(QCoreApplication::translate(
this->className(), sToolTipText, 0,
QCoreApplication::CodecForTr).arg(exe));
pcAction->setStatusTip(QCoreApplication::translate(
this->className(), sStatusTip, 0,
QCoreApplication::CodecForTr).arg(exe));
pcAction->setWhatsThis(QLatin1String(sWhatsThis));
pcAction->setIcon(QApplication::windowIcon());
pcAction->setShortcut(QString::fromLatin1(sAccel));
//Prevent Qt from using AboutRole -- fixes issue #0001485
pcAction->setMenuRole(QAction::ApplicationSpecificRole);
return pcAction;
}
bool StdCmdAbout::isActive()
{
return true;
}
/**
* Shows information about the application.
*/
void StdCmdAbout::activated(int iMsg)
{
const Gui::Dialog::AboutDialogFactory* f = Gui::Dialog::AboutDialogFactory::defaultFactory();
boost::scoped_ptr<QDialog> dlg(f->create(getMainWindow()));
dlg->exec();
}
void StdCmdAbout::languageChange()
{
if (_pcAction) {
QString exe = qApp->applicationName();
_pcAction->setText(QCoreApplication::translate(
this->className(), sMenuText, 0,
QCoreApplication::CodecForTr).arg(exe));
_pcAction->setToolTip(QCoreApplication::translate(
this->className(), sToolTipText, 0,
QCoreApplication::CodecForTr).arg(exe));
_pcAction->setStatusTip(QCoreApplication::translate(
this->className(), sStatusTip, 0,
QCoreApplication::CodecForTr).arg(exe));
_pcAction->setWhatsThis(QLatin1String(sWhatsThis));
}
}
//===========================================================================
// Std_AboutQt
//===========================================================================
DEF_STD_CMD(StdCmdAboutQt);
StdCmdAboutQt::StdCmdAboutQt()
:Command("Std_AboutQt")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("About &Qt");
sToolTipText = QT_TR_NOOP("About Qt");
sWhatsThis = "Std_AboutQt";
sStatusTip = QT_TR_NOOP("About Qt");
eType = 0;
}
void StdCmdAboutQt::activated(int iMsg)
{
qApp->aboutQt();
}
//===========================================================================
// Std_WhatsThis
//===========================================================================
DEF_STD_CMD(StdCmdWhatsThis);
StdCmdWhatsThis::StdCmdWhatsThis()
:Command("Std_WhatsThis")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("&What's This?");
sToolTipText = QT_TR_NOOP("What's This");
sWhatsThis = "Std_WhatsThis";
sStatusTip = QT_TR_NOOP("What's This");
sAccel = keySequenceToAccel(QKeySequence::WhatsThis);
sPixmap = "WhatsThis";
eType = 0;
}
void StdCmdWhatsThis::activated(int iMsg)
{
QWhatsThis::enterWhatsThisMode();
}
//===========================================================================
// Std_DlgParameter
//===========================================================================
DEF_STD_CMD(StdCmdDlgParameter);
StdCmdDlgParameter::StdCmdDlgParameter()
:Command("Std_DlgParameter")
{
sGroup = QT_TR_NOOP("Tools");
sMenuText = QT_TR_NOOP("E&dit parameters ...");
sToolTipText = QT_TR_NOOP("Opens a Dialog to edit the parameters");
sWhatsThis = "Std_DlgParameter";
sStatusTip = QT_TR_NOOP("Opens a Dialog to edit the parameters");
//sPixmap = "settings";
eType = 0;
}
void StdCmdDlgParameter::activated(int iMsg)
{
Gui::Dialog::DlgParameterImp cDlg(getMainWindow());
cDlg.resize(QSize(800, 600));
cDlg.exec();
}
//===========================================================================
// Std_DlgPreferences
//===========================================================================
DEF_STD_CMD(StdCmdDlgPreferences);
StdCmdDlgPreferences::StdCmdDlgPreferences()
:Command("Std_DlgPreferences")
{
sGroup = QT_TR_NOOP("Tools");
sMenuText = QT_TR_NOOP("&Preferences ...");
sToolTipText = QT_TR_NOOP("Opens a Dialog to edit the preferences");
sWhatsThis = "Std_DlgPreferences";
sStatusTip = QT_TR_NOOP("Opens a Dialog to edit the preferences");
sPixmap = "preferences-system";
eType = 0;
}
void StdCmdDlgPreferences::activated(int iMsg)
{
Gui::Dialog::DlgPreferencesImp cDlg(getMainWindow());
cDlg.exec();
}
//===========================================================================
// Std_DlgCustomize
//===========================================================================
DEF_STD_CMD(StdCmdDlgCustomize);
StdCmdDlgCustomize::StdCmdDlgCustomize()
:Command("Std_DlgCustomize")
{
sGroup = QT_TR_NOOP("Tools");
sMenuText = QT_TR_NOOP("Cu&stomize...");
sToolTipText = QT_TR_NOOP("Customize toolbars and command bars");
sWhatsThis = "Std_DlgCustomize";
sStatusTip = QT_TR_NOOP("Customize toolbars and command bars");
sPixmap = "applications-accessories";
eType = 0;
}
void StdCmdDlgCustomize::activated(int iMsg)
{
static QPointer<QDialog> dlg = 0;
if (!dlg)
dlg = new Gui::Dialog::DlgCustomizeImp(getMainWindow());
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->show();
}
//===========================================================================
// Std_CommandLine
//===========================================================================
DEF_STD_CMD(StdCmdCommandLine);
StdCmdCommandLine::StdCmdCommandLine()
:Command("Std_CommandLine")
{
sGroup = QT_TR_NOOP("Tools");
sMenuText = QT_TR_NOOP("Start command &line...");
sToolTipText = QT_TR_NOOP("Opens the command line in the console");
sWhatsThis = "Std_CommandLine";
sStatusTip = QT_TR_NOOP("Opens the command line in the console");
sPixmap = "utilities-terminal";
eType = 0;
}
void StdCmdCommandLine::activated(int iMsg)
{
bool show = getMainWindow()->isMaximized ();
// pop up the Gui command window
GUIConsole Wnd;
getMainWindow()->showMinimized () ;
qApp->processEvents();
// create temporary console sequencer
{
Base::ConsoleSequencer seq;
Base::Interpreter().runCommandLine("Console mode");
}
#ifdef Q_WS_X11
// On X11 this may not work. For further information see QWidget::showMaximized
//
// workaround for X11
getMainWindow()->hide();
getMainWindow()->show();
#endif
// pop up the main window
show ? getMainWindow()->showMaximized () : getMainWindow()->showNormal () ;
qApp->processEvents();
}
//===========================================================================
// Std_OnlineHelp
//===========================================================================
DEF_STD_CMD(StdCmdOnlineHelp);
StdCmdOnlineHelp::StdCmdOnlineHelp()
:Command("Std_OnlineHelp")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("Help");
sToolTipText = QT_TR_NOOP("Show help to the application");
sWhatsThis = "Std_OnlineHelp";
sStatusTip = QT_TR_NOOP("Help");
sPixmap = "help-browser";
sAccel = keySequenceToAccel(QKeySequence::HelpContents);
eType = 0;
}
void StdCmdOnlineHelp::activated(int iMsg)
{
Gui::getMainWindow()->showDocumentation(QString::fromLatin1("Online_Help_Startpage"));
}
//===========================================================================
// Std_OnlineHelpWebsite
//===========================================================================
DEF_STD_CMD(StdCmdOnlineHelpWebsite);
StdCmdOnlineHelpWebsite::StdCmdOnlineHelpWebsite()
:Command("Std_OnlineHelpWebsite")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("Help Website");
sToolTipText = QT_TR_NOOP("The website where the help is maintained");
sWhatsThis = "Std_OnlineHelpWebsite";
sStatusTip = QT_TR_NOOP("Help Website");
eType = 0;
}
void StdCmdOnlineHelpWebsite::activated(int iMsg)
{
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
std::string url = hURLGrp->GetASCII("OnlineHelp", "http://www.freecadweb.org/wiki/index.php?title=Online_Help_Toc");
hURLGrp->SetASCII("OnlineHelp", url.c_str());
OpenURLInBrowser(url.c_str());
}
//===========================================================================
// Std_FreeCADWebsite
//===========================================================================
DEF_STD_CMD(StdCmdFreeCADWebsite);
StdCmdFreeCADWebsite::StdCmdFreeCADWebsite()
:Command("Std_FreeCADWebsite")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("FreeCAD Website");
sToolTipText = QT_TR_NOOP("The FreeCAD website");
sWhatsThis = "Std_FreeCADWebsite";
sStatusTip = QT_TR_NOOP("FreeCAD Website");
sPixmap = "internet-web-browser";
eType = 0;
}
void StdCmdFreeCADWebsite::activated(int iMsg)
{
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
std::string url = hURLGrp->GetASCII("WebPage", "http://www.freecadweb.org");
hURLGrp->SetASCII("WebPage", url.c_str());
OpenURLInBrowser(url.c_str());
}
//===========================================================================
// Std_FreeCADUserHub
//===========================================================================
DEF_STD_CMD(StdCmdFreeCADUserHub);
StdCmdFreeCADUserHub::StdCmdFreeCADUserHub()
:Command("Std_FreeCADUserHub")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("Users documentation");
sToolTipText = QT_TR_NOOP("Documentation for users on the FreeCAD website");
sWhatsThis = "Std_FreeCADUserHub";
sStatusTip = QT_TR_NOOP("Users documentation");
sPixmap = "internet-web-browser";
eType = 0;
}
void StdCmdFreeCADUserHub::activated(int iMsg)
{
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
std::string url = hURLGrp->GetASCII("Documentation", "http://www.freecadweb.org/wiki/index.php?title=User_hub");
hURLGrp->SetASCII("Documentation", url.c_str());
OpenURLInBrowser(url.c_str());
}
//===========================================================================
// Std_FreeCADPowerUserHub
//===========================================================================
DEF_STD_CMD(StdCmdFreeCADPowerUserHub);
StdCmdFreeCADPowerUserHub::StdCmdFreeCADPowerUserHub()
:Command("Std_FreeCADPowerUserHub")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("Python scripting documentation");
sToolTipText = QT_TR_NOOP("Python scripting documentation on the FreeCAD website");
sWhatsThis = "Std_FreeCADPowerUserHub";
sStatusTip = QT_TR_NOOP("PowerUsers documentation");
sPixmap = "internet-web-browser";
eType = 0;
}
void StdCmdFreeCADPowerUserHub::activated(int iMsg)
{
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
std::string url = hURLGrp->GetASCII("PowerUsers", "http://www.freecadweb.org/wiki/index.php?title=Power_users_hub");
hURLGrp->SetASCII("PowerUsers", url.c_str());
OpenURLInBrowser(url.c_str());
}
//===========================================================================
// Std_FreeCADForum
//===========================================================================
DEF_STD_CMD(StdCmdFreeCADForum);
StdCmdFreeCADForum::StdCmdFreeCADForum()
:Command("Std_FreeCADForum")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("FreeCAD Forum");
sToolTipText = QT_TR_NOOP("The FreeCAD forum, where you can find help from other users");
sWhatsThis = "Std_FreeCADForum";
sStatusTip = QT_TR_NOOP("The FreeCAD Forum");
sPixmap = "internet-web-browser";
eType = 0;
}
void StdCmdFreeCADForum::activated(int iMsg)
{
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
std::string url = hURLGrp->GetASCII("UserForum", "http://forum.freecadweb.org/");
hURLGrp->SetASCII("UserForum", url.c_str());
OpenURLInBrowser(url.c_str());
}
//===========================================================================
// Std_FreeCADFAQ
//===========================================================================
DEF_STD_CMD(StdCmdFreeCADFAQ);
StdCmdFreeCADFAQ::StdCmdFreeCADFAQ()
:Command("Std_FreeCADFAQ")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("FreeCAD FAQ");
sToolTipText = QT_TR_NOOP("Frequently Asked Questions on the FreeCAD website");
sWhatsThis = "Std_FreeCADFAQ";
sStatusTip = QT_TR_NOOP("Frequently Asked Questions");
sPixmap = "internet-web-browser";
eType = 0;
}
void StdCmdFreeCADFAQ::activated(int iMsg)
{
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
std::string url = hURLGrp->GetASCII("FAQ", "http://www.freecadweb.org/wiki/index.php?title=FAQ");
hURLGrp->SetASCII("FAQ", url.c_str());
OpenURLInBrowser(url.c_str());
}
//===========================================================================
// Std_PythonWebsite
//===========================================================================
DEF_STD_CMD(StdCmdPythonWebsite);
StdCmdPythonWebsite::StdCmdPythonWebsite()
:Command("Std_PythonWebsite")
{
sGroup = QT_TR_NOOP("Help");
sMenuText = QT_TR_NOOP("Python Website");
sToolTipText = QT_TR_NOOP("The official Python website");
sWhatsThis = "Std_PythonWebsite";
sStatusTip = QT_TR_NOOP("Python Website");
sPixmap = "applications-python";
eType = 0;
}
void StdCmdPythonWebsite::activated(int iMsg)
{
OpenURLInBrowser("http://python.org");
}
//===========================================================================
// Std_MeasurementSimple
//===========================================================================
DEF_STD_CMD(StdCmdMeasurementSimple);
StdCmdMeasurementSimple::StdCmdMeasurementSimple()
:Command("Std_MeasurementSimple")
{
sGroup = QT_TR_NOOP("Tools");
sMenuText = QT_TR_NOOP("Measure distance");
sToolTipText = QT_TR_NOOP("Measures distance between two selected objects");
sWhatsThis = QT_TR_NOOP("Measures distance between two selected objects");
sStatusTip = QT_TR_NOOP("Measures distance between two selected objects");
sPixmap = "view-measurement";
eType = 0;
}
void StdCmdMeasurementSimple::activated(int iMsg)
{
unsigned int n = getSelection().countObjectsOfType(App::DocumentObject::getClassTypeId());
if (n == 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Only one object selected. Please select two objects.\n"
"Be aware the point where you click matters."));
return;
}
if (n < 1 || n > 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Please select two objects.\n"
"Be aware the point where you click matters."));
return;
}
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
std::string name;
name += "Dist ";
name += Sel[0].FeatName;
name += "-";
name += Sel[0].SubName;
name += " to ";
name += Sel[1].FeatName;
name += "-";
name += Sel[1].SubName;
openCommand("Insert measurement");
doCommand(Doc,"_f = App.activeDocument().addObject(\"App::MeasureDistance\",\"%s\")","Measurement");
doCommand(Doc,"_f.Label ='%s'",name.c_str());
doCommand(Doc,"_f.P1 = FreeCAD.Vector(%f,%f,%f)",Sel[0].x,Sel[0].y,Sel[0].z);
doCommand(Doc,"_f.P2 = FreeCAD.Vector(%f,%f,%f)",Sel[1].x,Sel[1].y,Sel[1].z);
updateActive();
commitCommand();
}
//===========================================================================
// Std_UnitsCalculator
//===========================================================================
DEF_STD_CMD(StdCmdUnitsCalculator);
StdCmdUnitsCalculator::StdCmdUnitsCalculator()
: Command("Std_UnitsCalculator")
{
sGroup = QT_TR_NOOP("Tools");
sMenuText = QT_TR_NOOP("&Units calculator...");
sToolTipText = QT_TR_NOOP("Start the units calculator");
sWhatsThis = QT_TR_NOOP("Start the units calculator");
sStatusTip = QT_TR_NOOP("Start the units calculator");
sPixmap = "accessories-calculator";
eType = 0;
}
void StdCmdUnitsCalculator::activated(int iMsg)
{
Gui::Dialog::DlgUnitsCalculator *dlg = new Gui::Dialog::DlgUnitsCalculator( getMainWindow() );
dlg->show();
}
namespace Gui {
void CreateStdCommands(void)
{
CommandManager &rcCmdMgr = Application::Instance->commandManager();
rcCmdMgr.addCommand(new StdCmdAbout());
rcCmdMgr.addCommand(new StdCmdAboutQt());
rcCmdMgr.addCommand(new StdCmdDlgParameter());
rcCmdMgr.addCommand(new StdCmdDlgPreferences());
rcCmdMgr.addCommand(new StdCmdDlgCustomize());
rcCmdMgr.addCommand(new StdCmdCommandLine());
rcCmdMgr.addCommand(new StdCmdWorkbench());
rcCmdMgr.addCommand(new StdCmdRecentFiles());
rcCmdMgr.addCommand(new StdCmdWhatsThis());
rcCmdMgr.addCommand(new StdCmdPythonHelp());
rcCmdMgr.addCommand(new StdCmdOnlineHelp());
rcCmdMgr.addCommand(new StdCmdOnlineHelpWebsite());
rcCmdMgr.addCommand(new StdCmdFreeCADWebsite());
rcCmdMgr.addCommand(new StdCmdFreeCADUserHub());
rcCmdMgr.addCommand(new StdCmdFreeCADPowerUserHub());
rcCmdMgr.addCommand(new StdCmdFreeCADForum());
rcCmdMgr.addCommand(new StdCmdFreeCADFAQ());
rcCmdMgr.addCommand(new StdCmdPythonWebsite());
rcCmdMgr.addCommand(new StdCmdUnitsCalculator());
//rcCmdMgr.addCommand(new StdCmdMeasurementSimple());
//rcCmdMgr.addCommand(new StdCmdDownloadOnlineHelp());
//rcCmdMgr.addCommand(new StdCmdDescription());
}
} // namespace Gui