FreeCAD

Форк
0
/
CommandStd.cpp 
960 строк · 32.8 Кб
1
 // SPDX-License-Identifier: LGPL-2.1-or-later
2

3
  /****************************************************************************
4
   *   Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de>               *
5
   *   Copyright (c) 2023 FreeCAD Project Association                         *
6
   *                                                                          *
7
   *   This file is part of FreeCAD.                                          *
8
   *                                                                          *
9
   *   FreeCAD is free software: you can redistribute it and/or modify it     *
10
   *   under the terms of the GNU Lesser General Public License as            *
11
   *   published by the Free Software Foundation, either version 2.1 of the   *
12
   *   License, or (at your option) any later version.                        *
13
   *                                                                          *
14
   *   FreeCAD is distributed in the hope that it will be useful, but         *
15
   *   WITHOUT ANY WARRANTY; without even the implied warranty of             *
16
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU       *
17
   *   Lesser General Public License for more details.                        *
18
   *                                                                          *
19
   *   You should have received a copy of the GNU Lesser General Public       *
20
   *   License along with FreeCAD. If not, see                                *
21
   *   <https://www.gnu.org/licenses/>.                                       *
22
   *                                                                          *
23
   ***************************************************************************/
24

25
#include "PreCompiled.h"
26
#ifndef _PreComp_
27
# include <QApplication>
28
# include <QMessageBox>
29
# include <QRegularExpression>
30
# include <QRegularExpressionMatch>
31
# include <QWhatsThis>
32
#endif
33

34
#include <App/Document.h>
35
#include <Base/Exception.h>
36
#include <Base/Interpreter.h>
37
#include <Base/Sequencer.h>
38

39
#include "Action.h"
40
#include "BitmapFactory.h"
41
#include "Command.h"
42
#include "DlgCustomizeImp.h"
43
#include "DlgParameterImp.h"
44
#include "DlgPreferencesImp.h"
45
#include "DlgUnitsCalculatorImp.h"
46
#include "GuiConsole.h"
47
#include "MainWindow.h"
48
#include "OnlineDocumentation.h"
49
#include "Selection.h"
50
#include "Splashscreen.h"
51
#include "WhatsThis.h"
52
#include "Workbench.h"
53
#include "WorkbenchManager.h"
54

55

56
using Base::Console;
57
using Base::Sequencer;
58
using namespace Gui;
59
namespace sp = std::placeholders;
60

61

62
//===========================================================================
63
// Std_Workbench
64
//===========================================================================
65

66
DEF_STD_CMD_AC(StdCmdWorkbench)
67

68
StdCmdWorkbench::StdCmdWorkbench()
69
  : Command("Std_Workbench")
70
{
71
    sGroup        = "View";
72
    sMenuText     = QT_TR_NOOP("Workbench");
73
    sToolTipText  = QT_TR_NOOP("Switch between workbenches");
74
    sWhatsThis    = "Std_Workbench";
75
    sStatusTip    = QT_TR_NOOP("Switch between workbenches");
76
    sPixmap       = "freecad";
77
    eType         = 0;
78
}
79

80
void StdCmdWorkbench::activated(int i)
81
{
82
    try {
83
        Workbench* w = WorkbenchManager::instance()->active();
84
        QList<QAction*> items = static_cast<WorkbenchGroup*>(_pcAction)->actions();
85
        std::string switch_to = (const char*)items[i]->objectName().toLatin1();
86
        if (w) {
87
            std::string current_w = w->name();
88
            if (switch_to == current_w)
89
                return;
90
        }
91
        doCommand(Gui, "Gui.activateWorkbench(\"%s\")", switch_to.c_str());
92
    }
93
    catch(const Base::PyException& e) {
94
        QString msg(QLatin1String(e.what()));
95
        // ignore '<type 'exceptions.*Error'>' prefixes
96
        QRegularExpression rx;
97
        rx.setPattern(QLatin1String(R"(^\s*<type 'exceptions.\w*'>:\s*)"));
98
        auto match = rx.match(msg);
99
        if (match.hasMatch())
100
            msg = msg.mid(match.capturedLength());
101
        QMessageBox::critical(getMainWindow(), QObject::tr("Cannot load workbench"), msg);
102
    }
103
    catch(...) {
104
        QMessageBox::critical(getMainWindow(), QObject::tr("Cannot load workbench"),
105
            QObject::tr("A general error occurred while loading the workbench"));
106
    }
107
}
108

109
bool StdCmdWorkbench::isActive()
110
{
111
    return true;
112
}
113

114
Action * StdCmdWorkbench::createAction()
115
{
116
    Action *pcAction;
117

118
    pcAction = new WorkbenchGroup(this,getMainWindow());
119
    pcAction->setShortcut(QString::fromLatin1(getAccel()));
120
    applyCommandData(this->className(), pcAction);
121
    if (getPixmap())
122
        pcAction->setIcon(Gui::BitmapFactory().iconFromTheme(getPixmap()));
123

124
    return pcAction;
125
}
126

127
//===========================================================================
128
// Std_RecentFiles
129
//===========================================================================
130

131
DEF_STD_CMD_C(StdCmdRecentFiles)
132

133
StdCmdRecentFiles::StdCmdRecentFiles()
134
  :Command("Std_RecentFiles")
135
{
136
    sGroup        = "File";
137
    sMenuText     = QT_TR_NOOP("Open Recent");
138
    sToolTipText  = QT_TR_NOOP("Recent file list");
139
    sWhatsThis    = "Std_RecentFiles";
140
    sStatusTip    = QT_TR_NOOP("Recent file list");
141
    sPixmap       = "Std_RecentFiles";
142
    eType         = NoTransaction;
143
}
144

145
/**
146
 * Opens the recent file at position \a iMsg in the menu.
147
 * If the file does not exist or cannot be loaded this item is removed
148
 * from the list.
149
 */
150
void StdCmdRecentFiles::activated(int iMsg)
151
{
152
    auto act = qobject_cast<RecentFilesAction*>(_pcAction);
153
    if (act) act->activateFile( iMsg );
154
}
155

156
/**
157
 * Creates the QAction object containing the recent files.
158
 */
159
Action * StdCmdRecentFiles::createAction()
160
{
161
    auto pcAction = new RecentFilesAction(this, getMainWindow());
162
    pcAction->setObjectName(QLatin1String("recentFiles"));
163
    pcAction->setDropDownMenu(true);
164
    applyCommandData(this->className(), pcAction);
165
    return pcAction;
166
}
167

168
//===========================================================================
169
// Std_RecentMacros
170
//===========================================================================
171

172
DEF_STD_CMD_C(StdCmdRecentMacros)
173

174
StdCmdRecentMacros::StdCmdRecentMacros()
175
  :Command("Std_RecentMacros")
176
{
177
    sGroup        = "Macro";
178
    sMenuText     = QT_TR_NOOP("Recent macros");
179
    sToolTipText  = QT_TR_NOOP("Recent macro list");
180
    sWhatsThis    = "Std_RecentMacros";
181
    sStatusTip    = QT_TR_NOOP("Recent macro list");
182
    sPixmap       = "Std_RecentMacros";
183
    eType         = NoTransaction;
184
}
185

186
/**
187
 * Opens the recent macro at position \a iMsg in the menu.
188
 * If the macro does not exist or cannot be loaded this item is removed
189
 * from the list.
190
 */
191
void StdCmdRecentMacros::activated(int iMsg)
192
{
193
    auto act = qobject_cast<RecentMacrosAction*>(_pcAction);
194
    if (act) act->activateFile( iMsg );
195
}
196

197
/**
198
 * Creates the QAction object containing the recent macros.
199
 */
200
Action * StdCmdRecentMacros::createAction()
201
{
202
    auto pcAction = new RecentMacrosAction(this, getMainWindow());
203
    pcAction->setObjectName(QLatin1String("recentMacros"));
204
    pcAction->setDropDownMenu(true);
205
    applyCommandData(this->className(), pcAction);
206
    return pcAction;
207
}
208

209
//===========================================================================
210
// Std_About
211
//===========================================================================
212

213
DEF_STD_CMD_ACL(StdCmdAbout)
214

215
StdCmdAbout::StdCmdAbout()
216
  :Command("Std_About")
217
{
218
    sGroup        = "Help";
219
    sMenuText     = QT_TR_NOOP("&About %1");
220
    sToolTipText  = QT_TR_NOOP("About %1");
221
    sWhatsThis    = "Std_About";
222
    sStatusTip    = QT_TR_NOOP("About %1");
223
    eType         = 0;
224
}
225

226
Action * StdCmdAbout::createAction()
227
{
228
    Action *pcAction;
229

230
    QString exe = qApp->applicationName();
231
    pcAction = new Action(this, getMainWindow());
232
    pcAction->setText(QCoreApplication::translate(
233
        this->className(), getMenuText()).arg(exe));
234
    pcAction->setToolTip(QCoreApplication::translate(
235
        this->className(), getToolTipText()).arg(exe));
236
    pcAction->setStatusTip(QCoreApplication::translate(
237
        this->className(), getStatusTip()).arg(exe));
238
    pcAction->setWhatsThis(QLatin1String(getWhatsThis()));
239
    pcAction->setIcon(QApplication::windowIcon());
240
    pcAction->setShortcut(QString::fromLatin1(getAccel()));
241
    // Needs to have AboutRole set to avoid duplicates if adding the about action more than once on macOS
242
    pcAction->setMenuRole(QAction::AboutRole);
243
    return pcAction;
244
}
245

246
bool StdCmdAbout::isActive()
247
{
248
    return true;
249
}
250

251
/**
252
 * Shows information about the application.
253
 */
254
void StdCmdAbout::activated(int iMsg)
255
{
256
    Q_UNUSED(iMsg);
257
    const Gui::Dialog::AboutDialogFactory* f = Gui::Dialog::AboutDialogFactory::defaultFactory();
258
    boost::scoped_ptr<QDialog> dlg(f->create(getMainWindow()));
259
    dlg->exec();
260
}
261

262
void StdCmdAbout::languageChange()
263
{
264
    if (_pcAction) {
265
        QString exe = qApp->applicationName();
266
        _pcAction->setText(QCoreApplication::translate(
267
            this->className(), getMenuText()).arg(exe));
268
        _pcAction->setToolTip(QCoreApplication::translate(
269
            this->className(), getToolTipText()).arg(exe));
270
        _pcAction->setStatusTip(QCoreApplication::translate(
271
            this->className(), getStatusTip()).arg(exe));
272
        _pcAction->setWhatsThis(QLatin1String(getWhatsThis()));
273
    }
274
}
275

276
//===========================================================================
277
// Std_AboutQt
278
//===========================================================================
279
DEF_STD_CMD(StdCmdAboutQt)
280

281
StdCmdAboutQt::StdCmdAboutQt()
282
  :Command("Std_AboutQt")
283
{
284
  sGroup        = "Help";
285
  sMenuText     = QT_TR_NOOP("About &Qt");
286
  sToolTipText  = QT_TR_NOOP("About Qt");
287
  sWhatsThis    = "Std_AboutQt";
288
  sStatusTip    = QT_TR_NOOP("About Qt");
289
  eType         = 0;
290
}
291

292
void StdCmdAboutQt::activated(int iMsg)
293
{
294
    Q_UNUSED(iMsg);
295
    qApp->aboutQt();
296
}
297

298
//===========================================================================
299
// Std_WhatsThis
300
//===========================================================================
301
DEF_STD_CMD(StdCmdWhatsThis)
302

303
StdCmdWhatsThis::StdCmdWhatsThis()
304
  :Command("Std_WhatsThis")
305
{
306
    sGroup        = "Help";
307
    sMenuText     = QT_TR_NOOP("&What's This?");
308
    sToolTipText  = QT_TR_NOOP("What's This");
309
    sWhatsThis    = "Std_WhatsThis";
310
    sStatusTip    = QT_TR_NOOP("What's This");
311
    sAccel        = keySequenceToAccel(QKeySequence::WhatsThis);
312
    sPixmap       = "WhatsThis";
313
    eType         = 0;
314
}
315

316
void StdCmdWhatsThis::activated(int iMsg)
317
{
318
    Q_UNUSED(iMsg);
319
    QWhatsThis::enterWhatsThisMode();
320
}
321

322
//===========================================================================
323
// Std_DlgParameter
324
//===========================================================================
325
DEF_STD_CMD(StdCmdDlgParameter)
326

327
StdCmdDlgParameter::StdCmdDlgParameter()
328
  :Command("Std_DlgParameter")
329
{
330
  sGroup        = "Tools";
331
  sMenuText     = QT_TR_NOOP("E&dit parameters ...");
332
  sToolTipText  = QT_TR_NOOP("Opens a Dialog to edit the parameters");
333
  sWhatsThis    = "Std_DlgParameter";
334
  sStatusTip    = QT_TR_NOOP("Opens a Dialog to edit the parameters");
335
  sPixmap       = "Std_DlgParameter";
336
  eType         = 0;
337
}
338

339
void StdCmdDlgParameter::activated(int iMsg)
340
{
341
    Q_UNUSED(iMsg);
342
    Gui::Dialog::DlgParameterImp cDlg(getMainWindow());
343
    cDlg.resize(QSize(800, 600));
344
    cDlg.exec();
345
}
346

347
//===========================================================================
348
// Std_DlgPreferences
349
//===========================================================================
350
DEF_STD_CMD_C(StdCmdDlgPreferences)
351

352
StdCmdDlgPreferences::StdCmdDlgPreferences()
353
  :Command("Std_DlgPreferences")
354
{
355
    sGroup        = "Tools";
356
    sMenuText     = QT_TR_NOOP("&Preferences ...");
357
    sToolTipText  = QT_TR_NOOP("Opens a Dialog to edit the preferences");
358
    sWhatsThis    = "Std_DlgPreferences";
359
    sStatusTip    = QT_TR_NOOP("Opens a Dialog to edit the preferences");
360
    sPixmap     = "preferences-system";
361
    eType         = 0;
362
}
363

364
Action * StdCmdDlgPreferences::createAction()
365
{
366
    Action *pcAction = Command::createAction();
367
    pcAction->setMenuRole(QAction::PreferencesRole);
368

369
    return pcAction;
370
}
371

372
void StdCmdDlgPreferences::activated(int iMsg)
373
{
374
    Q_UNUSED(iMsg);
375

376
    static QString groupName{};
377
    static int index{};
378

379
    Gui::Dialog::DlgPreferencesImp cDlg(getMainWindow());
380
    ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences");
381
    if (hGrp->GetBool("RestoreGroupPage", true)) {
382
        cDlg.activateGroupPage(groupName, index);
383
    }
384

385
    if (cDlg.exec()) {
386
        cDlg.activeGroupPage(groupName, index);
387
    }
388
}
389

390
//===========================================================================
391
// Std_DlgCustomize
392
//===========================================================================
393
DEF_STD_CMD(StdCmdDlgCustomize)
394

395
StdCmdDlgCustomize::StdCmdDlgCustomize()
396
  :Command("Std_DlgCustomize")
397
{
398
    sGroup        = "Tools";
399
    sMenuText     = QT_TR_NOOP("Cu&stomize...");
400
    sToolTipText  = QT_TR_NOOP("Customize toolbars and command bars");
401
    sWhatsThis    = "Std_DlgCustomize";
402
    sStatusTip    = QT_TR_NOOP("Customize toolbars and command bars");
403
    sPixmap       = "applications-accessories";
404
    eType         = 0;
405
}
406

407
void StdCmdDlgCustomize::activated(int iMsg)
408
{
409
    Q_UNUSED(iMsg);
410
    static QPointer<QDialog> dlg = nullptr;
411
    if (!dlg)
412
        dlg = new Gui::Dialog::DlgCustomizeImp(getMainWindow());
413
    dlg->setAttribute(Qt::WA_DeleteOnClose);
414
    dlg->show();
415
}
416

417
//===========================================================================
418
// Std_CommandLine
419
//===========================================================================
420
DEF_STD_CMD(StdCmdCommandLine)
421

422
StdCmdCommandLine::StdCmdCommandLine()
423
  :Command("Std_CommandLine")
424
{
425
    sGroup        = "Tools";
426
    sMenuText     = QT_TR_NOOP("Start command &line...");
427
    sToolTipText  = QT_TR_NOOP("Opens the command line in the console");
428
    sWhatsThis    = "Std_CommandLine";
429
    sStatusTip    = QT_TR_NOOP("Opens the command line in the console");
430
    sPixmap       = "utilities-terminal";
431
    eType         = 0;
432
}
433

434
void StdCmdCommandLine::activated(int iMsg)
435
{
436
    Q_UNUSED(iMsg);
437
    bool show = getMainWindow()->isMaximized ();
438

439
    // pop up the Gui command window
440
    GUIConsole Wnd;
441

442
    getMainWindow()->showMinimized () ;
443
    qApp->processEvents();
444

445
    // create temporary console sequencer
446
    {
447
          Base::ConsoleSequencer seq;
448
          Base::Interpreter().runCommandLine("Console mode");
449
    }
450

451
#ifdef Q_WS_X11
452
    // On X11 this may not work. For further information see QWidget::showMaximized
453
    //
454
    // workaround for X11
455
    getMainWindow()->hide();
456
    getMainWindow()->show();
457
#endif
458

459
    // pop up the main window
460
    show ? getMainWindow()->showMaximized () : getMainWindow()->showNormal () ;
461
    qApp->processEvents();
462
}
463

464
//===========================================================================
465
// Std_OnlineHelp
466
//===========================================================================
467

468
DEF_STD_CMD(StdCmdOnlineHelp)
469

470
StdCmdOnlineHelp::StdCmdOnlineHelp()
471
  :Command("Std_OnlineHelp")
472
{
473
    sGroup        = "Help";
474
    sMenuText     = QT_TR_NOOP("Help");
475
    sToolTipText  = QT_TR_NOOP("Show help to the application");
476
    sWhatsThis    = "Std_OnlineHelp";
477
    sStatusTip    = QT_TR_NOOP("Help");
478
    sPixmap       = "help-browser";
479
    sAccel        = keySequenceToAccel(QKeySequence::HelpContents);
480
    eType         = 0;
481
}
482

483
void StdCmdOnlineHelp::activated(int iMsg)
484
{
485
    Q_UNUSED(iMsg);
486
    Gui::getMainWindow()->showDocumentation(QString::fromLatin1("Online_Help_Startpage"));
487
}
488

489
//===========================================================================
490
// Std_OnlineHelpWebsite
491
//===========================================================================
492

493
DEF_STD_CMD(StdCmdOnlineHelpWebsite)
494

495
StdCmdOnlineHelpWebsite::StdCmdOnlineHelpWebsite()
496
  :Command("Std_OnlineHelpWebsite")
497
{
498
    sGroup        = "Help";
499
    sMenuText     = QT_TR_NOOP("Help Website");
500
    sToolTipText  = QT_TR_NOOP("The website where the help is maintained");
501
    sWhatsThis    = "Std_OnlineHelpWebsite";
502
    sStatusTip    = QT_TR_NOOP("Help Website");
503
    eType         = 0;
504
}
505

506
void StdCmdOnlineHelpWebsite::activated(int iMsg)
507
{
508
    Q_UNUSED(iMsg);
509
    std::string defaulturl = QCoreApplication::translate(this->className(),"https://wiki.freecad.org/Online_Help_Toc").toStdString();
510
    ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
511
    std::string url = hURLGrp->GetASCII("OnlineHelp", defaulturl.c_str());
512
    hURLGrp->SetASCII("OnlineHelp", url.c_str());
513
    OpenURLInBrowser(url.c_str());
514
}
515

516
//===========================================================================
517
// Std_FreeCADDonation
518
//===========================================================================
519

520
DEF_STD_CMD(StdCmdFreeCADDonation)
521

522
StdCmdFreeCADDonation::StdCmdFreeCADDonation()
523
  :Command("Std_FreeCADDonation")
524
{
525
    sGroup        = "Help";
526
    sMenuText     = QT_TR_NOOP("Donate");
527
    sToolTipText  = QT_TR_NOOP("Donate to FreeCAD development");
528
    sWhatsThis    = "Std_FreeCADDonation";
529
    sStatusTip    = sToolTipText;
530
    sPixmap       = "internet-web-browser";
531
    eType         = 0;
532
}
533

534
void StdCmdFreeCADDonation::activated(int iMsg)
535
{
536
    Q_UNUSED(iMsg);
537
    ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
538
    std::string url = hURLGrp->GetASCII("DonatePage", "https://wiki.freecad.org/Donate");
539
    hURLGrp->SetASCII("DonatePage", url.c_str());
540
    OpenURLInBrowser(url.c_str());
541
}
542

543
//===========================================================================
544
// Std_FreeCADWebsite
545
//===========================================================================
546

547
DEF_STD_CMD(StdCmdFreeCADWebsite)
548

549
StdCmdFreeCADWebsite::StdCmdFreeCADWebsite()
550
  :Command("Std_FreeCADWebsite")
551
{
552
    sGroup        = "Help";
553
    sMenuText     = QT_TR_NOOP("FreeCAD Website");
554
    sToolTipText  = QT_TR_NOOP("The FreeCAD website");
555
    sWhatsThis    = "Std_FreeCADWebsite";
556
    sStatusTip    = QT_TR_NOOP("FreeCAD Website");
557
    sPixmap       = "internet-web-browser";
558
    eType         = 0;
559
}
560

561
void StdCmdFreeCADWebsite::activated(int iMsg)
562
{
563
    Q_UNUSED(iMsg);
564
    std::string defaulturl = QCoreApplication::translate(this->className(),"https://www.freecad.org").toStdString();
565
    ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
566
    std::string url = hURLGrp->GetASCII("WebPage", defaulturl.c_str());
567
    hURLGrp->SetASCII("WebPage", url.c_str());
568
    OpenURLInBrowser(url.c_str());
569
}
570

571
//===========================================================================
572
// Std_FreeCADUserHub
573
//===========================================================================
574

575
DEF_STD_CMD(StdCmdFreeCADUserHub)
576

577
StdCmdFreeCADUserHub::StdCmdFreeCADUserHub()
578
  :Command("Std_FreeCADUserHub")
579
{
580
    sGroup        = "Help";
581
    sMenuText     = QT_TR_NOOP("Users documentation");
582
    sToolTipText  = QT_TR_NOOP("Documentation for users on the FreeCAD website");
583
    sWhatsThis    = "Std_FreeCADUserHub";
584
    sStatusTip    = QT_TR_NOOP("Users documentation");
585
    sPixmap       = "internet-web-browser";
586
    eType         = 0;
587
}
588

589
void StdCmdFreeCADUserHub::activated(int iMsg)
590
{
591
    Q_UNUSED(iMsg);
592
    std::string defaulturl = QCoreApplication::translate(this->className(),"https://wiki.freecad.org/User_hub").toStdString();
593
    ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
594
    std::string url = hURLGrp->GetASCII("Documentation", defaulturl.c_str());
595
    hURLGrp->SetASCII("Documentation", url.c_str());
596
    OpenURLInBrowser(url.c_str());
597
}
598

599
//===========================================================================
600
// Std_FreeCADPowerUserHub
601
//===========================================================================
602

603
DEF_STD_CMD(StdCmdFreeCADPowerUserHub)
604

605
StdCmdFreeCADPowerUserHub::StdCmdFreeCADPowerUserHub()
606
  :Command("Std_FreeCADPowerUserHub")
607
{
608
    sGroup        = "Help";
609
    sMenuText     = QT_TR_NOOP("Python scripting documentation");
610
    sToolTipText  = QT_TR_NOOP("Python scripting documentation on the FreeCAD website");
611
    sWhatsThis    = "Std_FreeCADPowerUserHub";
612
    sStatusTip    = QT_TR_NOOP("PowerUsers documentation");
613
    sPixmap       = "internet-web-browser";
614
    eType         = 0;
615
}
616

617
void StdCmdFreeCADPowerUserHub::activated(int iMsg)
618
{
619
    Q_UNUSED(iMsg);
620
    std::string defaulturl = QCoreApplication::translate(this->className(),"https://wiki.freecad.org/Power_users_hub").toStdString();
621
    ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
622
    std::string url = hURLGrp->GetASCII("PowerUsers", defaulturl.c_str());
623
    hURLGrp->SetASCII("PowerUsers", url.c_str());
624
    OpenURLInBrowser(url.c_str());
625
}
626

627
//===========================================================================
628
// Std_FreeCADForum
629
//===========================================================================
630

631
DEF_STD_CMD(StdCmdFreeCADForum)
632

633
StdCmdFreeCADForum::StdCmdFreeCADForum()
634
  :Command("Std_FreeCADForum")
635
{
636
    sGroup        = "Help";
637
    sMenuText     = QT_TR_NOOP("FreeCAD Forum");
638
    sToolTipText  = QT_TR_NOOP("The FreeCAD forum, where you can find help from other users");
639
    sWhatsThis    = "Std_FreeCADForum";
640
    sStatusTip    = QT_TR_NOOP("The FreeCAD Forum");
641
    sPixmap       = "internet-web-browser";
642
    eType         = 0;
643
}
644

645
void StdCmdFreeCADForum::activated(int iMsg)
646
{
647
    Q_UNUSED(iMsg);
648
    std::string defaulturl = QCoreApplication::translate(this->className(),"https://forum.freecad.org").toStdString();
649
    ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
650
    std::string url = hURLGrp->GetASCII("UserForum", defaulturl.c_str());
651
    hURLGrp->SetASCII("UserForum", url.c_str());
652
    OpenURLInBrowser(url.c_str());
653
}
654

655
//===========================================================================
656
// Std_FreeCADFAQ
657
//===========================================================================
658

659
DEF_STD_CMD(StdCmdFreeCADFAQ)
660

661
StdCmdFreeCADFAQ::StdCmdFreeCADFAQ()
662
  :Command("Std_FreeCADFAQ")
663
{
664
    sGroup        = "Help";
665
    sMenuText     = QT_TR_NOOP("FreeCAD FAQ");
666
    sToolTipText  = QT_TR_NOOP("Frequently Asked Questions on the FreeCAD website");
667
    sWhatsThis    = "Std_FreeCADFAQ";
668
    sStatusTip    = QT_TR_NOOP("Frequently Asked Questions");
669
    sPixmap       = "internet-web-browser";
670
    eType         = 0;
671
}
672

673
void StdCmdFreeCADFAQ::activated(int iMsg)
674
{
675
    Q_UNUSED(iMsg);
676
    std::string defaulturl = QCoreApplication::translate(this->className(),"https://wiki.freecad.org/Frequently_asked_questions").toStdString();
677
    ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
678
    std::string url = hURLGrp->GetASCII("FAQ", defaulturl.c_str());
679
    hURLGrp->SetASCII("FAQ", url.c_str());
680
    OpenURLInBrowser(url.c_str());
681
}
682

683
//===========================================================================
684
// Std_PythonWebsite
685
//===========================================================================
686

687
DEF_STD_CMD(StdCmdPythonWebsite)
688

689
StdCmdPythonWebsite::StdCmdPythonWebsite()
690
  :Command("Std_PythonWebsite")
691
{
692
    sGroup        = "Help";
693
    sMenuText     = QT_TR_NOOP("Python Website");
694
    sToolTipText  = QT_TR_NOOP("The official Python website");
695
    sWhatsThis    = "Std_PythonWebsite";
696
    sStatusTip    = QT_TR_NOOP("Python Website");
697
    sPixmap       = "applications-python";
698
    eType         = 0;
699
}
700

701
void StdCmdPythonWebsite::activated(int iMsg)
702
{
703
    Q_UNUSED(iMsg);
704
    OpenURLInBrowser("https://www.python.org");
705
}
706

707

708
//===========================================================================
709
// Std_ReportBug
710
//===========================================================================
711

712
DEF_STD_CMD(StdCmdReportBug)
713

714
StdCmdReportBug::StdCmdReportBug()
715
  :Command("Std_ReportBug")
716
{
717
    sGroup        = "Help";
718
    sMenuText     = QT_TR_NOOP("Report a bug");
719
    sToolTipText  = QT_TR_NOOP("Report a bug or suggest a feature");
720
    sWhatsThis    = "Std_ReportBug";
721
    sStatusTip    = QT_TR_NOOP("Report a bug or suggest a feature");
722
    sPixmap       = "internet-web-browser";
723
    eType         = 0;
724
}
725

726
void StdCmdReportBug::activated(int iMsg)
727
{
728
    Q_UNUSED(iMsg);
729
    ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
730
    std::string url = hURLGrp->GetASCII("IssuesPage", "https://github.com/FreeCAD/FreeCAD/issues");
731
    hURLGrp->SetASCII("IssuesPage", url.c_str());
732
    OpenURLInBrowser(url.c_str());
733
}
734

735
//===========================================================================
736
// Std_TextDocument
737
//===========================================================================
738

739
DEF_STD_CMD_A(StdCmdTextDocument)
740

741
StdCmdTextDocument::StdCmdTextDocument()
742
  :Command("Std_TextDocument")
743
{
744
    sGroup        = "Tools";
745
    sMenuText     = QT_TR_NOOP("Add text document");
746
    sToolTipText  = QT_TR_NOOP("Add text document to active document");
747
    sWhatsThis    = "Std_TextDocument";
748
    sStatusTip    = QT_TR_NOOP("Add text document to active document");
749
    sPixmap       = "TextDocument";
750
    eType         = 0;
751
}
752

753
void StdCmdTextDocument::activated(int iMsg)
754
{
755
    Q_UNUSED(iMsg);
756

757
    openCommand(QT_TRANSLATE_NOOP("Command", "Insert text document"));
758
    doCommand(Doc, "App.ActiveDocument.addObject(\"App::TextDocument\",\"%s\").Label=\"%s\"","Text document","Text document");
759
    doCommand(Gui, "Gui.ActiveDocument.ActiveObject.doubleClicked()");
760
    updateActive();
761
    commitCommand();
762
}
763

764
bool StdCmdTextDocument::isActive()
765
{
766
    return hasActiveDocument();
767
}
768

769
//===========================================================================
770
// Std_UnitsCalculator
771
//===========================================================================
772
DEF_STD_CMD(StdCmdUnitsCalculator)
773

774
StdCmdUnitsCalculator::StdCmdUnitsCalculator()
775
  : Command("Std_UnitsCalculator")
776
{
777
    sGroup        = "Tools";
778
    sMenuText     = QT_TR_NOOP("&Units converter...");
779
    sToolTipText  = QT_TR_NOOP("Start the units converter");
780
    sWhatsThis    = "Std_UnitsCalculator";
781
    sStatusTip    = QT_TR_NOOP("Start the units converter");
782
    sPixmap       = "accessories-calculator";
783
    eType         = 0;
784
}
785

786
void StdCmdUnitsCalculator::activated(int iMsg)
787
{
788
    Q_UNUSED(iMsg);
789
    auto dlg = new Gui::Dialog::DlgUnitsCalculator( getMainWindow() );
790
    dlg->show();
791
}
792

793
//===========================================================================
794
// StdCmdUserEditMode
795
//===========================================================================
796
class StdCmdUserEditMode : public Gui::Command
797
{
798
public:
799
    StdCmdUserEditMode();
800
    ~StdCmdUserEditMode() override = default;
801
    void languageChange() override;
802
    const char* className() const override {return "StdCmdUserEditMode";}
803
    void updateIcon(int mode);
804
protected:
805
    void activated(int iMsg) override;
806
    bool isActive() override;
807
    Gui::Action * createAction() override;
808
};
809

810
StdCmdUserEditMode::StdCmdUserEditMode()
811
  : Command("Std_UserEditMode")
812
{
813
    sGroup        = "Edit";
814
    sMenuText     = QT_TR_NOOP("Edit mode");
815
    sToolTipText  = QT_TR_NOOP("Defines behavior when editing an object from tree");
816
    sStatusTip    = QT_TR_NOOP("Defines behavior when editing an object from tree");
817
    sWhatsThis    = "Std_UserEditMode";
818
    sPixmap       = "Std_UserEditModeDefault";
819
    eType         = ForEdit;
820

821
    this->getGuiApplication()->signalUserEditModeChanged.connect([this](int mode) {
822
        this->updateIcon(mode);
823
    });
824
}
825

826
Gui::Action * StdCmdUserEditMode::createAction()
827
{
828
    auto pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
829
    pcAction->setDropDownMenu(true);
830
    pcAction->setIsMode(true);
831
    applyCommandData(this->className(), pcAction);
832

833
    for (auto const &uem : Gui::Application::Instance->listUserEditModes()) {
834
        QAction* act = pcAction->addAction(QString());
835
        auto modeName = QString::fromStdString(uem.second.first);
836
        act->setCheckable(true);
837
        act->setIcon(BitmapFactory().iconFromTheme(qPrintable(QString::fromLatin1("Std_UserEditMode")+modeName)));
838
        act->setObjectName(QString::fromLatin1("Std_UserEditMode")+modeName);
839
        act->setWhatsThis(QString::fromLatin1(getWhatsThis()));
840
        act->setToolTip(QString::fromStdString(uem.second.second));
841

842
        if (uem.first == 0) {
843
            pcAction->setIcon(act->icon());
844
            act->setChecked(true);
845
        }
846
    }
847

848
    _pcAction = pcAction;
849

850
    int lastMode = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
851
        GetInt("UserEditMode", 0);
852
    Gui::Application::Instance->setUserEditMode(lastMode);
853

854
    languageChange();
855
    return pcAction;
856
}
857

858
void StdCmdUserEditMode::languageChange()
859
{
860
    Command::languageChange();
861

862
    if (!_pcAction)
863
        return;
864
    auto pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
865
    QList<QAction*> a = pcAction->actions();
866

867
    for (int i = 0 ; i < a.count() ; i++) {
868
        auto modeName = Gui::Application::Instance->getUserEditModeUIStrings(i);
869
        a[i]->setText(QCoreApplication::translate(
870
        "EditMode", modeName.first.c_str()));
871
        a[i]->setToolTip(QCoreApplication::translate(
872
        "EditMode", modeName.second.c_str()));
873
    }
874
}
875

876
void StdCmdUserEditMode::updateIcon(int mode)
877
{
878
    auto actionGroup = dynamic_cast<Gui::ActionGroup *>(_pcAction);
879
    if (!actionGroup)
880
        return;
881

882
    actionGroup->setCheckedAction(mode);
883
}
884

885
void StdCmdUserEditMode::activated(int iMsg)
886
{
887
    App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
888
            SetInt("UserEditMode", iMsg);
889
    Gui::Application::Instance->setUserEditMode(iMsg);
890
}
891

892
bool StdCmdUserEditMode::isActive()
893
{
894
    return true;
895
}
896

897
//===========================================================================
898
// Std_ReloadStylesheet
899
//===========================================================================
900
DEF_STD_CMD(StdCmdReloadStyleSheet)
901

902
StdCmdReloadStyleSheet::StdCmdReloadStyleSheet()
903
  : Command("Std_ReloadStyleSheet")
904
{
905
    sGroup        = "View";
906
    sMenuText     = QT_TR_NOOP("&Reload stylesheet");
907
    sToolTipText  = QT_TR_NOOP("Reloads the current stylesheet");
908
    sWhatsThis    = "Std_ReloadStyleSheet";
909
    sStatusTip    = QT_TR_NOOP("Reloads the current stylesheet");
910
    sPixmap       = "view-refresh";
911
    sWhatsThis    = "Std_ReloadStyleSheet";
912
}
913

914
void StdCmdReloadStyleSheet::activated(int )
915
{
916
    auto mw = getMainWindow();
917

918
    auto qssFile = mw->property("fc_currentStyleSheet").toString();
919
    auto tiledBackground = mw->property("fc_tiledBackground").toBool();
920

921
    Gui::Application::Instance->setStyleSheet(qssFile, tiledBackground);
922
}
923

924
namespace Gui {
925

926
void CreateStdCommands()
927
{
928
    CommandManager &rcCmdMgr = Application::Instance->commandManager();
929

930
    rcCmdMgr.addCommand(new StdCmdAbout());
931
    rcCmdMgr.addCommand(new StdCmdAboutQt());
932

933
    rcCmdMgr.addCommand(new StdCmdDlgParameter());
934
    rcCmdMgr.addCommand(new StdCmdDlgPreferences());
935
    rcCmdMgr.addCommand(new StdCmdDlgCustomize());
936
    rcCmdMgr.addCommand(new StdCmdCommandLine());
937
    rcCmdMgr.addCommand(new StdCmdWorkbench());
938
    rcCmdMgr.addCommand(new StdCmdRecentFiles());
939
    rcCmdMgr.addCommand(new StdCmdRecentMacros());
940
    rcCmdMgr.addCommand(new StdCmdWhatsThis());
941
    rcCmdMgr.addCommand(new StdCmdPythonHelp());
942
    rcCmdMgr.addCommand(new StdCmdOnlineHelp());
943
    rcCmdMgr.addCommand(new StdCmdOnlineHelpWebsite());
944
    rcCmdMgr.addCommand(new StdCmdFreeCADWebsite());
945
    rcCmdMgr.addCommand(new StdCmdFreeCADDonation());
946
    rcCmdMgr.addCommand(new StdCmdFreeCADUserHub());
947
    rcCmdMgr.addCommand(new StdCmdFreeCADPowerUserHub());
948
    rcCmdMgr.addCommand(new StdCmdFreeCADForum());
949
    rcCmdMgr.addCommand(new StdCmdFreeCADFAQ());
950
    rcCmdMgr.addCommand(new StdCmdPythonWebsite());
951
    rcCmdMgr.addCommand(new StdCmdReportBug());
952
    rcCmdMgr.addCommand(new StdCmdTextDocument());
953
    rcCmdMgr.addCommand(new StdCmdUnitsCalculator());
954
    rcCmdMgr.addCommand(new StdCmdUserEditMode());
955
    rcCmdMgr.addCommand(new StdCmdReloadStyleSheet());
956
    //rcCmdMgr.addCommand(new StdCmdDownloadOnlineHelp());
957
    //rcCmdMgr.addCommand(new StdCmdDescription());
958
}
959

960
} // namespace Gui
961

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.