00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QApplication>
00027 # include <QMessageBox>
00028 # include <QSharedPointer>
00029 # include <QWhatsThis>
00030 #if QT_VERSION >= 0x040200
00031 # include <QDesktopServices>
00032 # include <QUrl>
00033 #endif
00034 #endif
00035
00036 #include <Base/Exception.h>
00037 #include <Base/FileInfo.h>
00038 #include <Base/Interpreter.h>
00039 #include <Base/Sequencer.h>
00040 #include <App/Document.h>
00041 #include "Action.h"
00042 #include "Application.h"
00043 #include "Document.h"
00044 #include "Splashscreen.h"
00045 #include "Command.h"
00046 #include "MainWindow.h"
00047 #include "WhatsThis.h"
00048 #include "DlgUndoRedo.h"
00049 #include "BitmapFactory.h"
00050 #include "View.h"
00051
00052 #include "DlgParameterImp.h"
00053 #include "DlgPreferencesImp.h"
00054 #include "DlgCustomizeImp.h"
00055 #include "Widgets.h"
00056 #include "NetworkRetriever.h"
00057 #include "OnlineDocumentation.h"
00058 #include "GuiConsole.h"
00059 #include "WorkbenchManager.h"
00060 #include "Workbench.h"
00061 #include "Selection.h"
00062
00063 using Base::Console;
00064 using Base::Sequencer;
00065 using namespace Gui;
00066
00067
00068
00069
00070
00071
00072 DEF_STD_CMD_AC(StdCmdWorkbench);
00073
00074 StdCmdWorkbench::StdCmdWorkbench()
00075 : Command("Std_Workbench")
00076 {
00077 sGroup = QT_TR_NOOP("View");
00078 sMenuText = QT_TR_NOOP("Workbench");
00079 sToolTipText = QT_TR_NOOP("Switch between workbenches");
00080 sWhatsThis = "Std_Workbench";
00081 sStatusTip = QT_TR_NOOP("Switch between workbenches");
00082 sPixmap = "freecad";
00083 eType = 0;
00084 }
00085
00086 void StdCmdWorkbench::activated(int i)
00087 {
00088 try {
00089 Workbench* w = WorkbenchManager::instance()->active();
00090 QList<QAction*> items = static_cast<WorkbenchGroup*>(_pcAction)->actions();
00091 std::string switch_to = (const char*)items[i]->objectName().toAscii();
00092 if (w) {
00093 std::string current_w = w->name();
00094 if (switch_to == current_w)
00095 return;
00096 }
00097 doCommand(Gui, "Gui.activateWorkbench(\"%s\")", switch_to.c_str());
00098 }
00099 catch(const Base::PyException& e) {
00100 QString msg(QLatin1String(e.what()));
00101
00102 QRegExp rx;
00103 rx.setPattern(QLatin1String("^\\s*<type 'exceptions.\\w*'>:\\s*"));
00104 int pos = rx.indexIn(msg);
00105 if (pos != -1)
00106 msg = msg.mid(rx.matchedLength());
00107 QMessageBox::critical(getMainWindow(), QObject::tr("Cannot load workbench"), msg);
00108 }
00109 catch(...) {
00110 QMessageBox::critical(getMainWindow(), QObject::tr("Cannot load workbench"),
00111 QObject::tr("A general error occurred while loading the workbench"));
00112 }
00113 }
00114
00115 bool StdCmdWorkbench::isActive(void)
00116 {
00117 return true;
00118 }
00119
00120 Action * StdCmdWorkbench::createAction(void)
00121 {
00122 Action *pcAction;
00123
00124 pcAction = new WorkbenchGroup(this,getMainWindow());
00125 applyCommandData(pcAction);
00126 if (sPixmap)
00127 pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
00128 pcAction->setShortcut(QString::fromAscii(sAccel));
00129
00130 return pcAction;
00131 }
00132
00133
00134
00135
00136
00137 DEF_STD_CMD_C(StdCmdRecentFiles)
00138
00139 StdCmdRecentFiles::StdCmdRecentFiles()
00140 :Command("Std_RecentFiles")
00141 {
00142 sGroup = QT_TR_NOOP("File");
00143 sMenuText = QT_TR_NOOP("Recent files");
00144 sToolTipText = QT_TR_NOOP("Recent file list");
00145 sWhatsThis = "Std_RecentFiles";
00146 sStatusTip = QT_TR_NOOP("Recent file list");
00147 eType = 0;
00148 }
00149
00155 void StdCmdRecentFiles::activated(int iMsg)
00156 {
00157 RecentFilesAction* act = qobject_cast<RecentFilesAction*>(_pcAction);
00158 if (act) act->activateFile( iMsg );
00159 }
00160
00164 Action * StdCmdRecentFiles::createAction(void)
00165 {
00166 RecentFilesAction* pcAction = new RecentFilesAction(this, getMainWindow());
00167 pcAction->setObjectName(QLatin1String("recentFiles"));
00168 pcAction->setDropDownMenu(true);
00169 applyCommandData(pcAction);
00170 return pcAction;
00171 }
00172
00173
00174
00175
00176
00177 DEF_STD_CMD_ACL(StdCmdAbout)
00178
00179 StdCmdAbout::StdCmdAbout()
00180 :Command("Std_About")
00181 {
00182 sGroup = QT_TR_NOOP("Help");
00183 sMenuText = QT_TR_NOOP("&About %1");
00184 sToolTipText = QT_TR_NOOP("About %1");
00185 sWhatsThis = "Std_About";
00186 sStatusTip = QT_TR_NOOP("About %1");
00187 eType = 0;
00188 }
00189
00190 Action * StdCmdAbout::createAction(void)
00191 {
00192 Action *pcAction;
00193
00194 QString exe;
00195 std::map<std::string,std::string>& cfg = App::Application::Config();
00196 std::map<std::string,std::string>::iterator it = cfg.find("WindowTitle");
00197 if (it != cfg.end())
00198 exe = QString::fromUtf8(it->second.c_str());
00199 else
00200 exe = QString::fromUtf8(App::GetApplication().getExecutableName());
00201 pcAction = new Action(this,getMainWindow());
00202 pcAction->setText(QCoreApplication::translate(
00203 this->className(), sMenuText, 0,
00204 QCoreApplication::CodecForTr).arg(exe));
00205 pcAction->setToolTip(QCoreApplication::translate(
00206 this->className(), sToolTipText, 0,
00207 QCoreApplication::CodecForTr).arg(exe));
00208 pcAction->setStatusTip(QCoreApplication::translate(
00209 this->className(), sStatusTip, 0,
00210 QCoreApplication::CodecForTr).arg(exe));
00211 pcAction->setWhatsThis(QLatin1String(sWhatsThis));
00212 pcAction->setIcon(QApplication::windowIcon());
00213 pcAction->setShortcut(QString::fromAscii(sAccel));
00214
00215 return pcAction;
00216 }
00217
00218 bool StdCmdAbout::isActive()
00219 {
00220 return true;
00221 }
00222
00226 void StdCmdAbout::activated(int iMsg)
00227 {
00228 const Gui::Dialog::AboutDialogFactory* f = Gui::Dialog::AboutDialogFactory::defaultFactory();
00229 QSharedPointer <QDialog> dlg(f->create(getMainWindow()));
00230 dlg->exec();
00231 }
00232
00233 void StdCmdAbout::languageChange()
00234 {
00235 if (_pcAction) {
00236 QString exe;
00237 std::map<std::string,std::string>& cfg = App::Application::Config();
00238 std::map<std::string,std::string>::iterator it = cfg.find("WindowTitle");
00239 if (it != cfg.end())
00240 exe = QString::fromUtf8(it->second.c_str());
00241 else
00242 exe = QString::fromUtf8(App::GetApplication().getExecutableName());
00243 _pcAction->setText(QCoreApplication::translate(
00244 this->className(), sMenuText, 0,
00245 QCoreApplication::CodecForTr).arg(exe));
00246 _pcAction->setToolTip(QCoreApplication::translate(
00247 this->className(), sToolTipText, 0,
00248 QCoreApplication::CodecForTr).arg(exe));
00249 _pcAction->setStatusTip(QCoreApplication::translate(
00250 this->className(), sStatusTip, 0,
00251 QCoreApplication::CodecForTr).arg(exe));
00252 _pcAction->setWhatsThis(QLatin1String(sWhatsThis));
00253 }
00254 }
00255
00256
00257
00258
00259 DEF_STD_CMD(StdCmdAboutQt);
00260
00261 StdCmdAboutQt::StdCmdAboutQt()
00262 :Command("Std_AboutQt")
00263 {
00264 sGroup = QT_TR_NOOP("Help");
00265 sMenuText = QT_TR_NOOP("About &Qt");
00266 sToolTipText = QT_TR_NOOP("About Qt");
00267 sWhatsThis = "Std_AboutQt";
00268 sStatusTip = QT_TR_NOOP("About Qt");
00269 eType = 0;
00270 }
00271
00272 void StdCmdAboutQt::activated(int iMsg)
00273 {
00274 qApp->aboutQt();
00275 }
00276
00277
00278
00279
00280 DEF_STD_CMD(StdCmdWhatsThis);
00281
00282 StdCmdWhatsThis::StdCmdWhatsThis()
00283 :Command("Std_WhatsThis")
00284 {
00285 sGroup = QT_TR_NOOP("Help");
00286 sMenuText = QT_TR_NOOP("&What's This?");
00287 sToolTipText = QT_TR_NOOP("What's This");
00288 sWhatsThis = "Std_WhatsThis";
00289 sStatusTip = QT_TR_NOOP("What's This");
00290 sAccel = keySequenceToAccel(QKeySequence::WhatsThis);
00291 sPixmap = "WhatsThis";
00292 eType = 0;
00293 }
00294
00295 void StdCmdWhatsThis::activated(int iMsg)
00296 {
00297 QWhatsThis::enterWhatsThisMode();
00298 }
00299
00300
00301
00302
00303 DEF_STD_CMD(StdCmdDlgParameter);
00304
00305 StdCmdDlgParameter::StdCmdDlgParameter()
00306 :Command("Std_DlgParameter")
00307 {
00308 sGroup = QT_TR_NOOP("Tools");
00309 sMenuText = QT_TR_NOOP("E&dit parameters ...");
00310 sToolTipText = QT_TR_NOOP("Opens a Dialog to edit the parameters");
00311 sWhatsThis = "Std_DlgParameter";
00312 sStatusTip = QT_TR_NOOP("Opens a Dialog to edit the parameters");
00313
00314 eType = 0;
00315 }
00316
00317 void StdCmdDlgParameter::activated(int iMsg)
00318 {
00319 Gui::Dialog::DlgParameterImp cDlg(getMainWindow());
00320 cDlg.resize(QSize(800, 600));
00321 cDlg.exec();
00322 }
00323
00324
00325
00326
00327 DEF_STD_CMD(StdCmdDlgPreferences);
00328
00329 StdCmdDlgPreferences::StdCmdDlgPreferences()
00330 :Command("Std_DlgPreferences")
00331 {
00332 sGroup = QT_TR_NOOP("Tools");
00333 sMenuText = QT_TR_NOOP("&Preferences ...");
00334 sToolTipText = QT_TR_NOOP("Opens a Dialog to edit the preferences");
00335 sWhatsThis = "Std_DlgPreferences";
00336 sStatusTip = QT_TR_NOOP("Opens a Dialog to edit the preferences");
00337 sPixmap = "preferences-system";
00338 eType = 0;
00339 }
00340
00341 void StdCmdDlgPreferences::activated(int iMsg)
00342 {
00343 Gui::Dialog::DlgPreferencesImp cDlg(getMainWindow());
00344 cDlg.exec();
00345 }
00346
00347
00348
00349
00350 DEF_STD_CMD(StdCmdDlgCustomize);
00351
00352 StdCmdDlgCustomize::StdCmdDlgCustomize()
00353 :Command("Std_DlgCustomize")
00354 {
00355 sGroup = QT_TR_NOOP("Tools");
00356 sMenuText = QT_TR_NOOP("Cu&stomize...");
00357 sToolTipText = QT_TR_NOOP("Customize toolbars and command bars");
00358 sWhatsThis = "Std_DlgCustomize";
00359 sStatusTip = QT_TR_NOOP("Customize toolbars and command bars");
00360 sPixmap = "applications-accessories";
00361 eType = 0;
00362 }
00363
00364 void StdCmdDlgCustomize::activated(int iMsg)
00365 {
00366 static QPointer<QDialog> dlg = 0;
00367 if (!dlg)
00368 dlg = new Gui::Dialog::DlgCustomizeImp(getMainWindow());
00369 dlg->setAttribute(Qt::WA_DeleteOnClose);
00370 dlg->show();
00371 }
00372
00373
00374
00375
00376 DEF_STD_CMD(StdCmdCommandLine);
00377
00378 StdCmdCommandLine::StdCmdCommandLine()
00379 :Command("Std_CommandLine")
00380 {
00381 sGroup = QT_TR_NOOP("Tools");
00382 sMenuText = QT_TR_NOOP("Start command &line...");
00383 sToolTipText = QT_TR_NOOP("Opens the command line in the console");
00384 sWhatsThis = "Std_CommandLine";
00385 sStatusTip = QT_TR_NOOP("Opens the command line in the console");
00386 sPixmap = "utilities-terminal";
00387 eType = 0;
00388 }
00389
00390 void StdCmdCommandLine::activated(int iMsg)
00391 {
00392 bool show = getMainWindow()->isMaximized ();
00393
00394
00395 GUIConsole Wnd;
00396
00397 getMainWindow()->showMinimized () ;
00398 qApp->processEvents();
00399
00400
00401 {
00402 Base::ConsoleSequencer seq;
00403 Base::Interpreter().runCommandLine("Console mode");
00404 }
00405
00406 #ifdef Q_WS_X11
00407
00408
00409
00410 getMainWindow()->hide();
00411 getMainWindow()->show();
00412 #endif
00413
00414
00415 show ? getMainWindow()->showMaximized () : getMainWindow()->showNormal () ;
00416 qApp->processEvents();
00417 }
00418
00419
00420
00421
00422
00423 DEF_STD_CMD(StdCmdOnlineHelp);
00424
00425 StdCmdOnlineHelp::StdCmdOnlineHelp()
00426 :Command("Std_OnlineHelp")
00427 {
00428 sGroup = QT_TR_NOOP("Help");
00429 sMenuText = QT_TR_NOOP("Help");
00430 sToolTipText = QT_TR_NOOP("Show help to the application");
00431 sWhatsThis = "Std_OnlineHelp";
00432 sStatusTip = QT_TR_NOOP("Help");
00433 sPixmap = "help-browser";
00434 sAccel = keySequenceToAccel(QKeySequence::HelpContents);
00435 eType = 0;
00436 }
00437
00438 void StdCmdOnlineHelp::activated(int iMsg)
00439 {
00440 Gui::getMainWindow()->showDocumentation();
00441 }
00442
00443
00444
00445
00446
00447 DEF_STD_CMD(StdCmdOnlineHelpPython);
00448
00449 StdCmdOnlineHelpPython::StdCmdOnlineHelpPython()
00450 :Command("Std_OnlineHelpPython")
00451 {
00452 sGroup = QT_TR_NOOP("Help");
00453 sMenuText = QT_TR_NOOP("Python Manuals");
00454 sToolTipText = QT_TR_NOOP("Show the Python documentation");
00455 sWhatsThis = "Std_OnlineHelpPython";
00456 sStatusTip = QT_TR_NOOP("Show the Python documentation");
00457 sPixmap = "python";
00458 eType = 0;
00459 }
00460
00461 void StdCmdOnlineHelpPython::activated(int iMsg)
00462 {
00463 std::string url = App::Application::getHelpDir() + "Python25.chm";
00464 #if QT_VERSION >= 0x040200
00465 bool ok = QDesktopServices::openUrl(QString::fromUtf8(url.c_str()));
00466 #elif defined(Q_WS_WIN)
00467 std::wstring wstr = Base::FileInfo(url).toStdWString();
00468 bool ok = (reinterpret_cast<int>(ShellExecuteW(NULL, NULL, wstr.c_str(), NULL,
00469 NULL, SW_SHOWNORMAL)) > 32);
00470 #else
00471
00472 #endif
00473 if (!ok) {
00474 QMessageBox::critical(getMainWindow(), QObject::tr("File not found"),
00475 QObject::tr("Cannot open file %1").arg(QString::fromUtf8(url.c_str())));
00476 }
00477 }
00478
00479
00480
00481
00482
00483 DEF_STD_CMD(StdCmdOnlineHelpWebsite);
00484
00485 StdCmdOnlineHelpWebsite::StdCmdOnlineHelpWebsite()
00486 :Command("Std_OnlineHelpWebsite")
00487 {
00488 sGroup = QT_TR_NOOP("Help");
00489 sMenuText = QT_TR_NOOP("Help Website");
00490 sToolTipText = QT_TR_NOOP("The website where the help is maintained");
00491 sWhatsThis = "Std_OnlineHelpWebsite";
00492 sStatusTip = QT_TR_NOOP("Help Website");
00493 eType = 0;
00494 }
00495
00496 void StdCmdOnlineHelpWebsite::activated(int iMsg)
00497 {
00498 ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/OnlineHelp");
00499 std::string url = hURLGrp->GetASCII("DownloadURL", "http://apps.sourceforge.net/mediawiki/free-cad/index.php?title=Online_Help_Toc");
00500 OpenURLInBrowser(url.c_str());
00501 }
00502
00503
00504
00505
00506
00507 DEF_STD_CMD(StdCmdFreeCADWebsite);
00508
00509 StdCmdFreeCADWebsite::StdCmdFreeCADWebsite()
00510 :Command("Std_FreeCADWebsite")
00511 {
00512 sGroup = QT_TR_NOOP("Help");
00513 sMenuText = QT_TR_NOOP("FreeCAD Website");
00514 sToolTipText = QT_TR_NOOP("The FreeCAD website");
00515 sWhatsThis = "Std_FreeCADWebsite";
00516 sStatusTip = QT_TR_NOOP("FreeCAD Website");
00517 eType = 0;
00518 }
00519
00520 void StdCmdFreeCADWebsite::activated(int iMsg)
00521 {
00522 OpenURLInBrowser("http://apps.sourceforge.net/mediawiki/free-cad/index.php?title=Main_Page");
00523 }
00524
00525
00526
00527
00528
00529 DEF_STD_CMD(StdCmdPythonWebsite);
00530
00531 StdCmdPythonWebsite::StdCmdPythonWebsite()
00532 :Command("Std_PythonWebsite")
00533 {
00534 sGroup = QT_TR_NOOP("Help");
00535 sMenuText = QT_TR_NOOP("Python Website");
00536 sToolTipText = QT_TR_NOOP("The official Python website");
00537 sWhatsThis = "Std_PythonWebsite";
00538 sStatusTip = QT_TR_NOOP("Python Website");
00539 sPixmap = "python";
00540 eType = 0;
00541 }
00542
00543 void StdCmdPythonWebsite::activated(int iMsg)
00544 {
00545 OpenURLInBrowser("http://python.org");
00546 }
00547
00548
00549
00550
00551
00552 DEF_STD_CMD(StdCmdMeasurementSimple);
00553
00554 StdCmdMeasurementSimple::StdCmdMeasurementSimple()
00555 :Command("Std_MeasurementSimple")
00556 {
00557 sGroup = QT_TR_NOOP("Tools");
00558 sMenuText = QT_TR_NOOP("Mesure distance");
00559 sToolTipText = QT_TR_NOOP("Measures distance between two selected objects");
00560 sWhatsThis = QT_TR_NOOP("Measures distance between two selected objects");
00561 sStatusTip = QT_TR_NOOP("Measures distance between two selected objects");
00562 sPixmap = "view-measurement";
00563 eType = 0;
00564 }
00565
00566 void StdCmdMeasurementSimple::activated(int iMsg)
00567 {
00568 unsigned int n = getSelection().countObjectsOfType(App::DocumentObject::getClassTypeId());
00569
00570 if (n == 1) {
00571 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00572 QObject::tr("Only one object selected. Please select two objects.\n"
00573 "Be aware the point where you click matters."));
00574 return;
00575 }
00576 if (n < 1 || n > 2) {
00577 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00578 QObject::tr("Please select two objects.\n"
00579 "Be aware the point where you click matters."));
00580 return;
00581 }
00582
00583 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00584
00585 std::string name;
00586 name += "Dist ";
00587 name += Sel[0].FeatName;
00588 name += "-";
00589 name += Sel[0].SubName;
00590 name += " to ";
00591 name += Sel[1].FeatName;
00592 name += "-";
00593 name += Sel[1].SubName;
00594
00595 openCommand("Insert measurement");
00596 doCommand(Doc,"_f = App.activeDocument().addObject(\"App::MeasureDistance\",\"%s\")","Measurement");
00597 doCommand(Doc,"_f.Label ='%s'",name.c_str());
00598 doCommand(Doc,"_f.P1 = FreeCAD.Vector(%f,%f,%f)",Sel[0].x,Sel[0].y,Sel[0].z);
00599 doCommand(Doc,"_f.P2 = FreeCAD.Vector(%f,%f,%f)",Sel[1].x,Sel[1].y,Sel[1].z);
00600 updateActive();
00601 commitCommand();
00602 }
00603
00604 namespace Gui {
00605
00606 void CreateStdCommands(void)
00607 {
00608 CommandManager &rcCmdMgr = Application::Instance->commandManager();
00609
00610 rcCmdMgr.addCommand(new StdCmdAbout());
00611 rcCmdMgr.addCommand(new StdCmdAboutQt());
00612
00613 rcCmdMgr.addCommand(new StdCmdDlgParameter());
00614 rcCmdMgr.addCommand(new StdCmdDlgPreferences());
00615 rcCmdMgr.addCommand(new StdCmdDlgCustomize());
00616 rcCmdMgr.addCommand(new StdCmdCommandLine());
00617 rcCmdMgr.addCommand(new StdCmdWorkbench());
00618 rcCmdMgr.addCommand(new StdCmdRecentFiles());
00619 rcCmdMgr.addCommand(new StdCmdWhatsThis());
00620 rcCmdMgr.addCommand(new StdCmdPythonHelp());
00621 rcCmdMgr.addCommand(new StdCmdOnlineHelp());
00622 rcCmdMgr.addCommand(new StdCmdOnlineHelpPython());
00623 rcCmdMgr.addCommand(new StdCmdOnlineHelpWebsite());
00624 rcCmdMgr.addCommand(new StdCmdFreeCADWebsite());
00625 rcCmdMgr.addCommand(new StdCmdPythonWebsite());
00626 rcCmdMgr.addCommand(new StdCmdMeasurementSimple());
00627
00628
00629 }
00630
00631 }