CommandDoc.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de>              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QClipboard>
00027 # include <QStatusBar>
00028 # include <QPointer>
00029 #endif
00030 #include <algorithm>
00031 
00032 #include <Base/Exception.h>
00033 #include <Base/Interpreter.h>
00034 #include <Base/Sequencer.h>
00035 #include <App/Document.h>
00036 #include <App/DocumentObjectGroup.h>
00037 #include <App/DocumentObject.h>
00038 #include <App/GeoFeature.h>
00039 
00040 #include "Action.h"
00041 #include "Application.h"
00042 #include "Document.h"
00043 #include "Command.h"
00044 #include "Control.h"
00045 #include "FileDialog.h"
00046 #include "MainWindow.h"
00047 #include "BitmapFactory.h"
00048 #include "Selection.h"
00049 #include "DlgProjectInformationImp.h"
00050 #include "DlgProjectUtility.h"
00051 #include "Transform.h"
00052 #include "Placement.h"
00053 #include "WaitCursor.h"
00054 #include "ViewProvider.h"
00055 #include "MergeDocuments.h"
00056 
00057 using namespace Gui;
00058 
00059 
00060 //===========================================================================
00061 // Std_Open
00062 //===========================================================================
00063 
00064 DEF_STD_CMD(StdCmdOpen);
00065 
00066 StdCmdOpen::StdCmdOpen()
00067   : Command("Std_Open")
00068 {
00069     // seting the
00070     sGroup        = QT_TR_NOOP("File");
00071     sMenuText     = QT_TR_NOOP("&Open...");
00072     sToolTipText  = QT_TR_NOOP("Open a document or import files");
00073     sWhatsThis    = "Std_Open";
00074     sStatusTip    = QT_TR_NOOP("Open a document or import files");
00075     sPixmap       = "document-open";
00076     sAccel        = keySequenceToAccel(QKeySequence::Open);
00077 }
00078 
00079 void StdCmdOpen::activated(int iMsg)
00080 {
00081     // fill the list of registered endings
00082     QString formatList;
00083     const char* supported = QT_TR_NOOP("Supported formats");
00084     const char* allFiles = QT_TR_NOOP("All files (*.*)");
00085     formatList = QObject::tr(supported);
00086     formatList += QLatin1String(" (");
00087 
00088     std::vector<std::string> filetypes = App::GetApplication().getImportTypes();
00089     std::vector<std::string>::iterator it;
00090     // Make sure FCStd is the very first fileformat
00091     it = std::find(filetypes.begin(), filetypes.end(), "FCStd");
00092     if (it != filetypes.end()) {
00093         filetypes.erase(it);
00094         filetypes.insert(filetypes.begin(), "FCStd");
00095     }
00096     for (it=filetypes.begin();it != filetypes.end();++it) {
00097         formatList += QLatin1String(" *.");
00098         formatList += QLatin1String(it->c_str());
00099     }
00100 
00101     formatList += QLatin1String(");;");
00102 
00103     std::map<std::string, std::string> FilterList = App::GetApplication().getImportFilters();
00104     std::map<std::string, std::string>::iterator jt;
00105     // Make sure the format name for FCStd is the very first in the list
00106     for (jt=FilterList.begin();jt != FilterList.end();++jt) {
00107         if (jt->first.find("*.FCStd") != std::string::npos) {
00108             formatList += QLatin1String(jt->first.c_str());
00109             formatList += QLatin1String(";;");
00110             FilterList.erase(jt);
00111             break;
00112         }
00113     }
00114     for (jt=FilterList.begin();jt != FilterList.end();++jt) {
00115         formatList += QLatin1String(jt->first.c_str());
00116         formatList += QLatin1String(";;");
00117     }
00118     formatList += QObject::tr(allFiles);
00119 
00120     QString selectedFilter;
00121     QStringList fileList = FileDialog::getOpenFileNames(getMainWindow(),
00122         QObject::tr("Open document"), QString(), formatList, &selectedFilter);
00123     // load the files with the associated modules
00124     SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter);
00125     for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
00126         getGuiApplication()->open(it.key().toUtf8(), it.value().toAscii());
00127     }
00128 }
00129 
00130 //===========================================================================
00131 // Std_Import
00132 //===========================================================================
00133 
00134 DEF_STD_CMD_A(StdCmdImport);
00135 
00136 StdCmdImport::StdCmdImport()
00137   : Command("Std_Import")
00138 {
00139     // seting the
00140     sGroup        = QT_TR_NOOP("File");
00141     sMenuText     = QT_TR_NOOP("&Import...");
00142     sToolTipText  = QT_TR_NOOP("Import a file in the active document");
00143     sWhatsThis    = "Std_Import";
00144     sStatusTip    = QT_TR_NOOP("Import a file in the active document");
00145     //sPixmap       = "Open";
00146     sAccel        = "Ctrl+I";
00147 }
00148 
00149 void StdCmdImport::activated(int iMsg)
00150 {
00151     // fill the list of registered endings
00152     QString formatList;
00153     const char* supported = QT_TR_NOOP("Supported formats");
00154     const char* allFiles = QT_TR_NOOP("All files (*.*)");
00155     formatList = QObject::tr(supported);
00156     formatList += QLatin1String(" (");
00157 
00158     std::vector<std::string> filetypes = App::GetApplication().getImportTypes();
00159     std::vector<std::string>::const_iterator it;
00160     for (it=filetypes.begin();it != filetypes.end();++it) {
00161         if (*it != "FCStd") {
00162             // ignore the project file format
00163             formatList += QLatin1String(" *.");
00164             formatList += QLatin1String(it->c_str());
00165         }
00166     }
00167 
00168     formatList += QLatin1String(");;");
00169 
00170     std::map<std::string, std::string> FilterList = App::GetApplication().getImportFilters();
00171     std::map<std::string, std::string>::const_iterator jt;
00172     for (jt=FilterList.begin();jt != FilterList.end();++jt) {
00173         // ignore the project file format
00174         if (jt->first.find("(*.FCStd)") == std::string::npos) {
00175             formatList += QLatin1String(jt->first.c_str());
00176             formatList += QLatin1String(";;");
00177         }
00178     }
00179     formatList += QObject::tr(allFiles);
00180 
00181     QString selectedFilter;
00182     QStringList fileList = FileDialog::getOpenFileNames(getMainWindow(),
00183         QObject::tr("Import file"), QString(), formatList, &selectedFilter);
00184     SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter);
00185     // load the files with the associated modules
00186     for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
00187         getGuiApplication()->importFrom(it.key().toUtf8(),
00188             getActiveGuiDocument()->getDocument()->getName(),
00189             it.value().toAscii());
00190     }
00191 }
00192 
00193 bool StdCmdImport::isActive(void)
00194 {
00195     return (getActiveGuiDocument() ? true : false);
00196 }
00197 
00198 
00199 //===========================================================================
00200 // Std_Export
00201 //===========================================================================
00202 
00203 DEF_STD_CMD_A(StdCmdExport);
00204 
00205 StdCmdExport::StdCmdExport()
00206   : Command("Std_Export")
00207 {
00208     // seting the
00209     sGroup        = QT_TR_NOOP("File");
00210     sMenuText     = QT_TR_NOOP("&Export...");
00211     sToolTipText  = QT_TR_NOOP("Export an object in the active document");
00212     sWhatsThis    = "Std_Export";
00213     sStatusTip    = QT_TR_NOOP("Export an object in the active document");
00214     //sPixmap       = "Open";
00215     sAccel        = "Ctrl+E";
00216     eType         = 0;
00217 }
00218 
00219 void StdCmdExport::activated(int iMsg)
00220 {
00221     // fill the list of registered endings
00222     QString formatList;
00223     const char* supported = QT_TR_NOOP("Supported formats");
00224     formatList = QObject::tr(supported);
00225     formatList += QLatin1String(" (");
00226 
00227     std::vector<std::string> filetypes = App::GetApplication().getExportTypes();
00228     std::vector<std::string>::const_iterator it;
00229     for (it=filetypes.begin();it != filetypes.end();++it) {
00230         if (*it != "FCStd") {
00231             // ignore the project file format
00232             formatList += QLatin1String(" *.");
00233             formatList += QLatin1String(it->c_str());
00234         }
00235     }
00236 
00237     formatList += QLatin1String(");;");
00238 
00239     std::map<std::string, std::string> FilterList = App::GetApplication().getExportFilters();
00240     std::map<std::string, std::string>::const_iterator jt;
00241     for (jt=FilterList.begin();jt != FilterList.end();++jt) {
00242         // ignore the project file format
00243         if (jt->first.find("(*.FCStd)") == std::string::npos) {
00244             formatList += QLatin1String(jt->first.c_str());
00245             formatList += QLatin1String(";;");
00246         }
00247     }
00248 
00249     QString selectedFilter;
00250     QString fileName = FileDialog::getSaveFileName(getMainWindow(),
00251         QObject::tr("Export file"), QString(), formatList, &selectedFilter);
00252     if (!fileName.isEmpty()) {
00253         SelectModule::Dict dict = SelectModule::exportHandler(fileName, selectedFilter);
00254         // export the files with the associated modules
00255         for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
00256             getGuiApplication()->exportTo(it.key().toUtf8(),
00257                 getActiveGuiDocument()->getDocument()->getName(),
00258                 it.value().toAscii());
00259         }
00260     }
00261 }
00262 
00263 bool StdCmdExport::isActive(void)
00264 {
00265     // at least one object should be selected otherwise it might be confusing to the user
00266     return Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0;
00267     //return (getActiveGuiDocument() ? true : false);
00268 }
00269 
00270 //===========================================================================
00271 // Std_MergeProjects
00272 //===========================================================================
00273 
00274 DEF_STD_CMD_A(StdCmdMergeProjects);
00275 
00276 StdCmdMergeProjects::StdCmdMergeProjects()
00277   : Command("Std_MergeProjects")
00278 {
00279     sAppModule    = "File";
00280     sGroup        = QT_TR_NOOP("File");
00281     sMenuText     = QT_TR_NOOP("Merge project...");
00282     sToolTipText  = QT_TR_NOOP("Merge project");
00283     sWhatsThis    = QT_TR_NOOP("Merge project");
00284     sStatusTip    = QT_TR_NOOP("Merge project");
00285 }
00286 
00287 void StdCmdMergeProjects::activated(int iMsg)
00288 {
00289     QString exe = QString::fromUtf8(App::GetApplication().getExecutableName());
00290     QString project = QFileDialog::getOpenFileName(Gui::getMainWindow(),
00291         QString::fromUtf8(QT_TR_NOOP("Merge project")), QString(),
00292         QString::fromUtf8(QT_TR_NOOP("%1 document (*.fcstd)")).arg(exe));
00293     if (!project.isEmpty()) {
00294         App::Document* doc = App::GetApplication().getActiveDocument();
00295         QFileInfo info(QString::fromUtf8(doc->FileName.getValue()));
00296         QFileInfo proj(project);
00297         if (proj == info) {
00298             QMessageBox::critical(Gui::getMainWindow(),
00299                 QString::fromUtf8(QT_TR_NOOP("Merge project")),
00300                 QString::fromUtf8(QT_TR_NOOP("Cannot merge project with itself.")));
00301             return;
00302         }
00303 
00304         QString dir1 = proj.absoluteDir().filePath(proj.baseName());
00305         QString dir2 = info.absoluteDir().filePath(info.baseName());
00306 
00307         Base::FileInfo fi((const char*)project.toUtf8());
00308         Base::ifstream str(fi, std::ios::in | std::ios::binary);
00309         MergeDocuments md(doc);
00310         md.importObjects(str);
00311     }
00312 }
00313 
00314 bool StdCmdMergeProjects::isActive(void)
00315 {
00316     return this->hasActiveDocument();
00317 }
00318 
00319 //===========================================================================
00320 // Std_New
00321 //===========================================================================
00322 
00323 DEF_STD_CMD(StdCmdNew);
00324 
00325 StdCmdNew::StdCmdNew()
00326   :Command("Std_New")
00327 {
00328   sGroup        = QT_TR_NOOP("File");
00329   sMenuText     = QT_TR_NOOP("&New");
00330   sToolTipText  = QT_TR_NOOP("Create a new empty document");
00331   sWhatsThis    = "Std_New";
00332   sStatusTip    = QT_TR_NOOP("Create a new empty document");
00333   sPixmap       = "document-new";
00334   sAccel        = keySequenceToAccel(QKeySequence::New);
00335 }
00336 
00337 void StdCmdNew::activated(int iMsg)
00338 {
00339   doCommand(Command::Doc,"App.newDocument()");
00340 }
00341 
00342 //===========================================================================
00343 // Std_Save
00344 //===========================================================================
00345 DEF_STD_CMD_A(StdCmdSave);
00346 
00347 StdCmdSave::StdCmdSave()
00348   :Command("Std_Save")
00349 {
00350   sGroup        = QT_TR_NOOP("File");
00351   sMenuText     = QT_TR_NOOP("&Save");
00352   sToolTipText  = QT_TR_NOOP("Save the active document");
00353   sWhatsThis    = "Std_Save";
00354   sStatusTip    = QT_TR_NOOP("Save the active document");
00355   sPixmap       = "document-save";
00356   sAccel        = keySequenceToAccel(QKeySequence::Save);
00357   eType         = 0;
00358 }
00359 
00360 void StdCmdSave::activated(int iMsg)
00361 {
00362 #if 0
00363   Gui::Document* pActiveDoc = getActiveGuiDocument();
00364   if ( pActiveDoc )
00365     pActiveDoc->save();
00366   else
00367 #endif
00368     doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"Save\")");
00369 }
00370 
00371 bool StdCmdSave::isActive(void)
00372 {
00373 #if 0
00374   if( getActiveGuiDocument() )
00375     return true;
00376   else
00377 #endif
00378     return getGuiApplication()->sendHasMsgToActiveView("Save");
00379 }
00380 
00381 //===========================================================================
00382 // Std_SaveAs
00383 //===========================================================================
00384 DEF_STD_CMD_A(StdCmdSaveAs);
00385 
00386 StdCmdSaveAs::StdCmdSaveAs()
00387   :Command("Std_SaveAs")
00388 {
00389   sGroup        = QT_TR_NOOP("File");
00390   sMenuText     = QT_TR_NOOP("Save &As...");
00391   sToolTipText  = QT_TR_NOOP("Save the active document under a new file name");
00392   sWhatsThis    = "Std_SaveAs";
00393   sStatusTip    = QT_TR_NOOP("Save the active document under a new file name");
00394 #if QT_VERSION >= 0x040200
00395   sPixmap       = "document-save-as";
00396 #endif
00397   sAccel        = keySequenceToAccel(QKeySequence::SaveAs);
00398 }
00399 
00400 void StdCmdSaveAs::activated(int iMsg)
00401 {
00402 #if 0
00403   Gui::Document* pActiveDoc = getActiveGuiDocument();
00404   if ( pActiveDoc )
00405     pActiveDoc->saveAs();
00406   else
00407 #endif
00408     doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"SaveAs\")");
00409 }
00410 
00411 bool StdCmdSaveAs::isActive(void)
00412 {
00413 #if 0
00414   if( getActiveGuiDocument() )
00415     return true;
00416   else
00417 #endif
00418     return getGuiApplication()->sendHasMsgToActiveView("SaveAs");
00419 }
00420 
00421 //===========================================================================
00422 // Std_ProjectInfo
00423 //===========================================================================
00424 
00425 DEF_STD_CMD_A(StdCmdProjectInfo);
00426 
00427 StdCmdProjectInfo::StdCmdProjectInfo()
00428   :Command("Std_ProjectInfo")
00429 {
00430   // seting the 
00431   sGroup        = QT_TR_NOOP("File");
00432   sMenuText     = QT_TR_NOOP("Project i&nformation...");
00433   sToolTipText  = QT_TR_NOOP("Show details of the currently active project");
00434   sWhatsThis    = "Std_ProjectInfo";
00435   sStatusTip    = QT_TR_NOOP("Show details of the currently active project");
00436 #if QT_VERSION >= 0x040200
00437   sPixmap       = "document-properties";
00438 #endif
00439 }
00440 
00441 void StdCmdProjectInfo::activated(int iMsg)
00442 {
00443   Gui::Dialog::DlgProjectInformationImp dlg(getActiveGuiDocument()->getDocument(), getMainWindow());
00444   dlg.exec();
00445 }
00446 
00447 bool StdCmdProjectInfo::isActive(void)
00448 {
00449   return ( getActiveGuiDocument() ? true : false );
00450 }
00451 
00452 //===========================================================================
00453 // Std_ProjectUtil
00454 //===========================================================================
00455 
00456 DEF_STD_CMD_A(StdCmdProjectUtil);
00457 
00458 StdCmdProjectUtil::StdCmdProjectUtil()
00459   :Command("Std_ProjectUtil")
00460 {
00461     // seting the 
00462     sGroup        = QT_TR_NOOP("Tools");
00463     sWhatsThis    = "Std_ProjectUtil";
00464     sMenuText     = QT_TR_NOOP("Project utility...");
00465     sToolTipText  = QT_TR_NOOP("Utility to extract or create project files");
00466     sStatusTip    = QT_TR_NOOP("Utility to extract or create project files");
00467 }
00468 
00469 void StdCmdProjectUtil::activated(int iMsg)
00470 {
00471     Gui::Dialog::DlgProjectUtility dlg(getMainWindow());
00472     dlg.exec();
00473 }
00474 
00475 bool StdCmdProjectUtil::isActive(void)
00476 {
00477     return true;
00478 }
00479 
00480 //===========================================================================
00481 // Std_Print
00482 //===========================================================================
00483 DEF_STD_CMD_A(StdCmdPrint );
00484 
00485 StdCmdPrint::StdCmdPrint()
00486   :Command("Std_Print")
00487 {
00488     sGroup        = QT_TR_NOOP("File");
00489     sMenuText     = QT_TR_NOOP("&Print...");
00490     sToolTipText  = QT_TR_NOOP("Print the document");
00491     sWhatsThis    = "Std_Print";
00492     sStatusTip    = QT_TR_NOOP("Print the document");
00493     sPixmap       = "document-print";
00494     sAccel        = keySequenceToAccel(QKeySequence::Print);
00495 }
00496 
00497 void StdCmdPrint::activated(int iMsg)
00498 {
00499     if (getMainWindow()->activeWindow()) {
00500         getMainWindow()->statusBar()->showMessage(QObject::tr("Printing..."));
00501         getMainWindow()->activeWindow()->print();
00502     }
00503 }
00504 
00505 bool StdCmdPrint::isActive(void)
00506 {
00507     return getGuiApplication()->sendHasMsgToActiveView("Print");
00508 }
00509 
00510 //===========================================================================
00511 // Std_PrintPreview
00512 //===========================================================================
00513 DEF_STD_CMD_A(StdCmdPrintPreview);
00514 
00515 StdCmdPrintPreview::StdCmdPrintPreview()
00516   :Command("Std_PrintPreview")
00517 {
00518     sGroup        = QT_TR_NOOP("File");
00519     sMenuText     = QT_TR_NOOP("&Print preview...");
00520     sToolTipText  = QT_TR_NOOP("Print the document");
00521     sWhatsThis    = "Std_PrintPreview";
00522     sStatusTip    = QT_TR_NOOP("Print preview");
00523 }
00524 
00525 void StdCmdPrintPreview::activated(int iMsg)
00526 {
00527     if (getMainWindow()->activeWindow()) {
00528         getMainWindow()->activeWindow()->printPreview();
00529     }
00530 }
00531 
00532 bool StdCmdPrintPreview::isActive(void)
00533 {
00534     return getGuiApplication()->sendHasMsgToActiveView("PrintPreview");
00535 }
00536 
00537 //===========================================================================
00538 // Std_PrintPdf
00539 //===========================================================================
00540 DEF_STD_CMD_A(StdCmdPrintPdf);
00541 
00542 StdCmdPrintPdf::StdCmdPrintPdf()
00543   :Command("Std_PrintPdf")
00544 {
00545     sGroup        = QT_TR_NOOP("File");
00546     sMenuText     = QT_TR_NOOP("&Export PDF...");
00547     sToolTipText  = QT_TR_NOOP("Export the document as PDF");
00548     sWhatsThis    = "Std_PrintPdf";
00549     sStatusTip    = QT_TR_NOOP("Export the document as PDF");
00550 }
00551 
00552 void StdCmdPrintPdf::activated(int iMsg)
00553 {
00554     if (getMainWindow()->activeWindow()) {
00555         getMainWindow()->statusBar()->showMessage(QObject::tr("Exporting PDF..."));
00556         getMainWindow()->activeWindow()->printPdf();
00557     }
00558 }
00559 
00560 bool StdCmdPrintPdf::isActive(void)
00561 {
00562     return getGuiApplication()->sendHasMsgToActiveView("PrintPdf");
00563 }
00564 
00565 //===========================================================================
00566 // Std_Quit
00567 //===========================================================================
00568 
00569 DEF_STD_CMD(StdCmdQuit );
00570 
00571 StdCmdQuit::StdCmdQuit()
00572   :Command("Std_Quit")
00573 {
00574   sGroup        = QT_TR_NOOP("File");
00575   sMenuText     = QT_TR_NOOP("E&xit");
00576   sToolTipText  = QT_TR_NOOP("Quits the application");
00577   sWhatsThis    = "Std_Quit";
00578   sStatusTip    = QT_TR_NOOP("Quits the application");
00579 #if QT_VERSION >= 0x040200
00580   sPixmap       = "system-log-out";
00581 #endif
00582   sAccel        = "Alt+F4";
00583 }
00584 
00585 void StdCmdQuit::activated(int iMsg)
00586 {
00587     // close the main window and exit the event loop
00588     getMainWindow()->close();
00589 }
00590 
00591 //===========================================================================
00592 // Std_Undo
00593 //===========================================================================
00594 
00595 DEF_STD_CMD_AC(StdCmdUndo);
00596 
00597 StdCmdUndo::StdCmdUndo()
00598   :Command("Std_Undo")
00599 {
00600   sGroup        = QT_TR_NOOP("Edit");
00601   sMenuText     = QT_TR_NOOP("&Undo");
00602   sToolTipText  = QT_TR_NOOP("Undo exactly one action");
00603   sWhatsThis    = "Std_Undo";
00604   sStatusTip    = QT_TR_NOOP("Undo exactly one action");
00605   sPixmap       = "edit-undo";
00606   sAccel        = keySequenceToAccel(QKeySequence::Undo);
00607   eType         = ForEdit;
00608 }
00609 
00610 void StdCmdUndo::activated(int iMsg)
00611 {
00612 //  Application::Instance->slotUndo();
00613   getGuiApplication()->sendMsgToActiveView("Undo");
00614 }
00615 
00616 bool StdCmdUndo::isActive(void)
00617 {
00618   return getGuiApplication()->sendHasMsgToActiveView("Undo");
00619 }
00620 
00621 Action * StdCmdUndo::createAction(void)
00622 {
00623     Action *pcAction;
00624 
00625     pcAction = new UndoAction(this,getMainWindow());
00626     applyCommandData(pcAction);
00627     if (sPixmap)
00628         pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
00629     pcAction->setShortcut(QString::fromAscii(sAccel));
00630 
00631     return pcAction;
00632 }
00633 
00634 //===========================================================================
00635 // Std_Redo
00636 //===========================================================================
00637 
00638 DEF_STD_CMD_AC(StdCmdRedo );
00639 
00640 StdCmdRedo::StdCmdRedo()
00641   :Command("Std_Redo")
00642 {
00643   sGroup        = QT_TR_NOOP("Edit");
00644   sMenuText     = QT_TR_NOOP("&Redo");
00645   sToolTipText  = QT_TR_NOOP("Redoes a previously undone action");
00646   sWhatsThis    = "Std_Redo";
00647   sStatusTip    = QT_TR_NOOP("Redoes a previously undone action");
00648   sPixmap       = "edit-redo";
00649   sAccel        = keySequenceToAccel(QKeySequence::Redo);
00650   eType         = ForEdit;
00651 }
00652 
00653 void StdCmdRedo::activated(int iMsg)
00654 {
00655 //  Application::Instance->slotRedo();
00656   getGuiApplication()->sendMsgToActiveView("Redo");
00657 }
00658 
00659 bool StdCmdRedo::isActive(void)
00660 {
00661   return getGuiApplication()->sendHasMsgToActiveView("Redo");
00662 }
00663 
00664 Action * StdCmdRedo::createAction(void)
00665 {
00666     Action *pcAction;
00667 
00668     pcAction = new RedoAction(this,getMainWindow());
00669     applyCommandData(pcAction);
00670     if (sPixmap)
00671         pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
00672     pcAction->setShortcut(QString::fromAscii(sAccel));
00673 
00674     return pcAction;
00675 }
00676 
00677 //===========================================================================
00678 // Std_Cut
00679 //===========================================================================
00680 DEF_STD_CMD_A(StdCmdCut);
00681 
00682 StdCmdCut::StdCmdCut()
00683   : Command("Std_Cut")
00684 {
00685     sGroup        = QT_TR_NOOP("Edit");
00686     sMenuText     = QT_TR_NOOP("&Cut");
00687     sToolTipText  = QT_TR_NOOP("Cut out");
00688     sWhatsThis    = "Std_Cut";
00689     sStatusTip    = QT_TR_NOOP("Cut out");
00690     sPixmap       = "edit-cut";
00691     sAccel        = keySequenceToAccel(QKeySequence::Cut);
00692 }
00693 
00694 void StdCmdCut::activated(int iMsg)
00695 {
00696     getGuiApplication()->sendMsgToActiveView("Cut");
00697 }
00698 
00699 bool StdCmdCut::isActive(void)
00700 {
00701     return getGuiApplication()->sendHasMsgToActiveView("Cut");
00702 }
00703 
00704 //===========================================================================
00705 // Std_Copy
00706 //===========================================================================
00707 DEF_STD_CMD_A(StdCmdCopy);
00708 
00709 StdCmdCopy::StdCmdCopy()
00710   : Command("Std_Copy")
00711 {
00712     sGroup        = QT_TR_NOOP("Edit");
00713     sMenuText     = QT_TR_NOOP("C&opy");
00714     sToolTipText  = QT_TR_NOOP("Copy operation");
00715     sWhatsThis    = "Std_Copy";
00716     sStatusTip    = QT_TR_NOOP("Copy operation");
00717     sPixmap       = "edit-copy";
00718     sAccel        = keySequenceToAccel(QKeySequence::Copy);
00719 }
00720 
00721 void StdCmdCopy::activated(int iMsg)
00722 {
00723     bool done = getGuiApplication()->sendMsgToActiveView("Copy");
00724     if (!done) {
00725         WaitCursor wc;
00726         QMimeData * mimeData = getMainWindow()->createMimeDataFromSelection();
00727         QClipboard* cb = QApplication::clipboard();
00728         cb->setMimeData(mimeData);
00729     }
00730 }
00731 
00732 bool StdCmdCopy::isActive(void)
00733 {
00734     if (getGuiApplication()->sendHasMsgToActiveView("Copy"))
00735         return true;
00736     return Selection().hasSelection();
00737 }
00738 
00739 //===========================================================================
00740 // Std_Paste
00741 //===========================================================================
00742 DEF_STD_CMD_A(StdCmdPaste);
00743 
00744 StdCmdPaste::StdCmdPaste()
00745   : Command("Std_Paste")
00746 {
00747     sGroup        = QT_TR_NOOP("Edit");
00748     sMenuText     = QT_TR_NOOP("&Paste");
00749     sToolTipText  = QT_TR_NOOP("Paste operation");
00750     sWhatsThis    = "Std_Paste";
00751     sStatusTip    = QT_TR_NOOP("Paste operation");
00752     sPixmap       = "edit-paste";
00753     sAccel        = keySequenceToAccel(QKeySequence::Paste);
00754 }
00755 
00756 void StdCmdPaste::activated(int iMsg)
00757 {
00758     bool done = getGuiApplication()->sendMsgToActiveView("Paste");
00759     if (!done) {
00760         QClipboard* cb = QApplication::clipboard();
00761         const QMimeData* mimeData = cb->mimeData();
00762         if (mimeData) {
00763             WaitCursor wc;
00764             getMainWindow()->insertFromMimeData(mimeData);
00765         }
00766     }
00767 }
00768 
00769 bool StdCmdPaste::isActive(void)
00770 {
00771     if (getGuiApplication()->sendHasMsgToActiveView("Paste"))
00772         return true;
00773     QClipboard* cb = QApplication::clipboard();
00774     const QMimeData* mime = cb->mimeData();
00775     if (!mime) return false;
00776     return getMainWindow()->canInsertFromMimeData(mime);
00777 }
00778 
00779 DEF_STD_CMD_A(StdCmdDDuplicateSelection);
00780 
00781 StdCmdDDuplicateSelection::StdCmdDDuplicateSelection()
00782   :Command("Std_DuplicateSelection")
00783 {
00784     sAppModule    = "Edit";
00785     sGroup        = QT_TR_NOOP("Edit");
00786     sMenuText     = QT_TR_NOOP("Duplicate selection");
00787     sToolTipText  = QT_TR_NOOP("Put duplicates of the selected objects to the active document");
00788     sWhatsThis    = QT_TR_NOOP("Put duplicates of the selected objects to the active document");
00789     sStatusTip    = QT_TR_NOOP("Put duplicates of the selected objects to the active document");
00790 }
00791 
00792 void StdCmdDDuplicateSelection::activated(int iMsg)
00793 {
00794     App::Document* act = App::GetApplication().getActiveDocument();
00795     if (!act)
00796         return; // no active document found
00797     Gui::Document* doc = Gui::Application::Instance->getDocument(act);
00798     std::vector<Gui::SelectionSingleton::SelObj> sel = Gui::Selection().getCompleteSelection();
00799     for (std::vector<SelectionSingleton::SelObj>::iterator it = sel.begin(); it != sel.end(); ++it) {
00800         if (!it->pObject)
00801             continue; // should actually not happen
00802         // create a copy of the object
00803         App::DocumentObject* copy = act->copyObject(it->pObject, false);
00804         if (!copy) // continue if no copy could be created
00805             continue;
00806         // mark all properties of the copy as "touched" which are touched in the original object
00807         std::map<std::string,App::Property*> props;
00808         it->pObject->getPropertyMap(props);
00809         std::map<std::string,App::Property*> copy_props;
00810         copy->getPropertyMap(copy_props);
00811         for (std::map<std::string,App::Property*>::iterator jt = props.begin(); jt != props.end(); ++jt) {
00812             if (jt->second->isTouched()) {
00813                 std::map<std::string,App::Property*>::iterator kt;
00814                 kt = copy_props.find(jt->first);
00815                 if (kt != copy_props.end()) {
00816                     kt->second->touch();
00817                 }
00818             }
00819         }
00820 
00821         Gui::Document* parent = Gui::Application::Instance->getDocument(it->pObject->getDocument());
00822         if (!parent || !doc)
00823             continue; // should not happen
00824         // copy the properties of the associated view providers
00825         Gui::ViewProvider* view = parent->getViewProvider(it->pObject);
00826         Gui::ViewProvider* copy_view = doc->getViewProvider(copy);
00827         copy_view->addDynamicProperties(view);
00828         if (!view || !copy_view)
00829             continue; // should not happen
00830 
00831         // get the properties of the view provider
00832         props.clear();
00833         view->getPropertyMap(props);
00834         copy_props.clear();
00835         copy_view->getPropertyMap(copy_props);
00836         for (std::map<std::string,App::Property*>::iterator jt = props.begin(); jt != props.end(); ++jt) {
00837             std::map<std::string,App::Property*>::iterator kt;
00838             kt = copy_props.find(jt->first);
00839             if (kt != copy_props.end()) {
00840                 std::auto_ptr<App::Property> data(jt->second->Copy());
00841                 if (data.get()) {
00842                     kt->second->Paste(*data);
00843                 }
00844             }
00845         }
00846     }
00847 }
00848 
00849 bool StdCmdDDuplicateSelection::isActive(void)
00850 {
00851     return Gui::Selection().hasSelection();
00852 }
00853 
00854 //===========================================================================
00855 // Std_SelectAll
00856 //===========================================================================
00857 
00858 DEF_STD_CMD_A(StdCmdSelectAll);
00859 
00860 StdCmdSelectAll::StdCmdSelectAll()
00861   : Command("Std_SelectAll")
00862 {
00863     sGroup        = QT_TR_NOOP("Edit");
00864     sMenuText     = QT_TR_NOOP("Select &All");
00865     sToolTipText  = QT_TR_NOOP("Select all");
00866     sWhatsThis    = "Std_SelectAll";
00867     sStatusTip    = QT_TR_NOOP("Select all");
00868 #if QT_VERSION >= 0x040200
00869     sPixmap       = "edit-select-all";
00870 #endif
00871     //sAccel        = "Ctrl+A"; // superseeds shortcuts for text edits
00872 }
00873 
00874 void StdCmdSelectAll::activated(int iMsg)
00875 {
00876     SelectionSingleton& rSel = Selection();
00877     App::Document* doc = App::GetApplication().getActiveDocument();
00878     std::vector<App::DocumentObject*> objs = doc->getObjectsOfType(App::DocumentObject::getClassTypeId());
00879     rSel.setSelection(doc->getName(), objs);
00880 }
00881 
00882 bool StdCmdSelectAll::isActive(void)
00883 {
00884     return App::GetApplication().getActiveDocument() != 0;
00885 }
00886 
00887 //===========================================================================
00888 // Std_Delete
00889 //===========================================================================
00890 DEF_STD_CMD_A(StdCmdDelete);
00891 
00892 StdCmdDelete::StdCmdDelete()
00893   :Command("Std_Delete")
00894 {
00895   sGroup        = QT_TR_NOOP("Edit");
00896   sMenuText     = QT_TR_NOOP("&Delete");
00897   sToolTipText  = QT_TR_NOOP("Deletes the selected objects");
00898   sWhatsThis    = "Std_Delete";
00899   sStatusTip    = QT_TR_NOOP("Deletes the selected objects");
00900 #if QT_VERSION >= 0x040200
00901   sPixmap       = "edit-delete";
00902 #endif
00903   sAccel        = keySequenceToAccel(QKeySequence::Delete);
00904   eType         = ForEdit;
00905 }
00906 
00907 void StdCmdDelete::activated(int iMsg)
00908 {
00909     // go through all documents
00910     const SelectionSingleton& rSel = Selection();
00911     const std::vector<App::Document*> docs = App::GetApplication().getDocuments();
00912     for (std::vector<App::Document*>::const_iterator it = docs.begin(); it != docs.end(); ++it) {
00913         Gui::Document* pGuiDoc = Gui::Application::Instance->getDocument(*it);
00914         std::vector<Gui::SelectionObject> sel = rSel.getSelectionEx((*it)->getName());
00915         if (!sel.empty()) {
00916             (*it)->openTransaction("Delete");
00917             for (std::vector<Gui::SelectionObject>::iterator ft = sel.begin(); ft != sel.end(); ++ft) {
00918                 Gui::ViewProvider* vp = pGuiDoc->getViewProvider(ft->getObject());
00919                 if (vp) {
00920                     // ask the ViewProvider if its want to do some clean up
00921                     if (vp->onDelete(ft->getSubNames()))
00922                         doCommand(Doc,"App.getDocument(\"%s\").removeObject(\"%s\")"
00923                                  ,(*it)->getName(), ft->getFeatName());
00924                 }
00925             }
00926             (*it)->commitTransaction();
00927         }
00928     }
00929 }
00930 
00931 bool StdCmdDelete::isActive(void)
00932 {
00933     return Selection().getCompleteSelection().size() > 0;
00934 }
00935 
00936 //===========================================================================
00937 // Std_Refresh
00938 //===========================================================================
00939 DEF_STD_CMD_A(StdCmdRefresh);
00940 
00941 StdCmdRefresh::StdCmdRefresh()
00942   :Command("Std_Refresh")
00943 {
00944   sGroup        = QT_TR_NOOP("Edit");
00945   sMenuText     = QT_TR_NOOP("&Refresh");
00946   sToolTipText  = QT_TR_NOOP("Recomputes the current active document");
00947   sWhatsThis    = "Std_Refresh";
00948   sStatusTip    = QT_TR_NOOP("Recomputes the current active document");
00949   sPixmap       = "view-refresh";
00950   sAccel        = keySequenceToAccel(QKeySequence::Refresh);
00951 }
00952 
00953 void StdCmdRefresh::activated(int iMsg)
00954 {
00955   if ( getActiveGuiDocument() )
00956   {
00957     openCommand("Refresh active document");
00958     doCommand(Doc,"App.activeDocument().recompute()");
00959     commitCommand(); 
00960   }
00961 }
00962 
00963 bool StdCmdRefresh::isActive(void)
00964 {
00965   return this->getDocument() && this->getDocument()->isTouched();
00966 }
00967 
00968 //===========================================================================
00969 // Std_Transform
00970 //===========================================================================
00971 DEF_STD_CMD_A(StdCmdTransform);
00972 
00973 StdCmdTransform::StdCmdTransform()
00974   : Command("Std_Transform")
00975 {
00976     sGroup        = QT_TR_NOOP("Edit");
00977     sMenuText     = QT_TR_NOOP("Transform...");
00978     sToolTipText  = QT_TR_NOOP("Transform the geometry of selected objects");
00979     sStatusTip    = QT_TR_NOOP("Transform the geometry of selected objects");
00980     sWhatsThis    = "Std_Transform";
00981 }
00982 
00983 void StdCmdTransform::activated(int iMsg)
00984 {
00985     Gui::Control().showDialog(new Gui::Dialog::TaskTransform());
00986 }
00987 
00988 bool StdCmdTransform::isActive(void)
00989 {
00990     return (Gui::Control().activeDialog()==0);
00991 }
00992 
00993 //===========================================================================
00994 // Std_Placement
00995 //===========================================================================
00996 DEF_STD_CMD_A(StdCmdPlacement);
00997 
00998 StdCmdPlacement::StdCmdPlacement()
00999   : Command("Std_Placement")
01000 {
01001     sGroup        = QT_TR_NOOP("Edit");
01002     sMenuText     = QT_TR_NOOP("Placement...");
01003     sToolTipText  = QT_TR_NOOP("Place the selected objects");
01004     sStatusTip    = QT_TR_NOOP("Place the selected objects");
01005     sWhatsThis    = "Std_Placement";
01006 }
01007 
01008 void StdCmdPlacement::activated(int iMsg)
01009 {
01010     std::vector<App::DocumentObject*> sel = Gui::Selection().getObjectsOfType(App::GeoFeature::getClassTypeId());
01011     Gui::Dialog::TaskPlacement* plm = new Gui::Dialog::TaskPlacement();
01012     if (!sel.empty()) {
01013         App::Property* prop = sel.front()->getPropertyByName("Placement");
01014         if (prop && prop->getTypeId() == App::PropertyPlacement::getClassTypeId())
01015             plm->setPlacement(static_cast<App::PropertyPlacement*>(prop)->getValue());
01016     }
01017     Gui::Control().showDialog(plm);
01018 }
01019 
01020 bool StdCmdPlacement::isActive(void)
01021 {
01022     return (Gui::Control().activeDialog()==0);
01023 }
01024 
01025 
01026 namespace Gui {
01027 
01028 void CreateDocCommands(void)
01029 {
01030     CommandManager &rcCmdMgr = Application::Instance->commandManager();
01031 
01032     rcCmdMgr.addCommand(new StdCmdNew());
01033     rcCmdMgr.addCommand(new StdCmdOpen());
01034     rcCmdMgr.addCommand(new StdCmdImport());
01035     rcCmdMgr.addCommand(new StdCmdExport());
01036     rcCmdMgr.addCommand(new StdCmdMergeProjects());
01037 
01038     rcCmdMgr.addCommand(new StdCmdSave());
01039     rcCmdMgr.addCommand(new StdCmdSaveAs());
01040     rcCmdMgr.addCommand(new StdCmdProjectInfo());
01041     rcCmdMgr.addCommand(new StdCmdProjectUtil());
01042     rcCmdMgr.addCommand(new StdCmdUndo());
01043     rcCmdMgr.addCommand(new StdCmdRedo());
01044     rcCmdMgr.addCommand(new StdCmdPrint());
01045     rcCmdMgr.addCommand(new StdCmdPrintPreview());
01046     rcCmdMgr.addCommand(new StdCmdPrintPdf());
01047     rcCmdMgr.addCommand(new StdCmdQuit());
01048     rcCmdMgr.addCommand(new StdCmdCut());
01049     rcCmdMgr.addCommand(new StdCmdCopy());
01050     rcCmdMgr.addCommand(new StdCmdPaste());
01051     rcCmdMgr.addCommand(new StdCmdDDuplicateSelection());
01052     rcCmdMgr.addCommand(new StdCmdSelectAll());
01053     rcCmdMgr.addCommand(new StdCmdDelete());
01054     rcCmdMgr.addCommand(new StdCmdRefresh());
01055     rcCmdMgr.addCommand(new StdCmdTransform());
01056     rcCmdMgr.addCommand(new StdCmdPlacement());
01057 }
01058 
01059 } // namespace Gui
01060 

Generated on Wed Nov 23 19:00:02 2011 for FreeCAD by  doxygen 1.6.1