00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "PreCompiled.h"
00013 #ifndef _PreComp_
00014 # include <QMessageBox>
00015 #endif
00016
00017 #include <vector>
00018
00019 #include <Gui/Action.h>
00020 #include <Gui/Application.h>
00021 #include <Gui/BitmapFactory.h>
00022 #include <Gui/Command.h>
00023 #include <Gui/Control.h>
00024 #include <Gui/Selection.h>
00025 #include <Gui/MainWindow.h>
00026 #include <Gui/FileDialog.h>
00027
00028 #include <Mod/Part/App/PartFeature.h>
00029 #include <Mod/Drawing/App/FeaturePage.h>
00030
00031
00032 #include "DrawingView.h"
00033 #include "TaskDialog.h"
00034
00035 using namespace DrawingGui;
00036 using namespace std;
00037
00038
00039
00040
00041
00042
00043 DEF_STD_CMD(CmdDrawingOpen);
00044
00045 CmdDrawingOpen::CmdDrawingOpen()
00046 : Command("Drawing_Open")
00047 {
00048 sAppModule = "Drawing";
00049 sGroup = QT_TR_NOOP("Drawing");
00050 sMenuText = QT_TR_NOOP("Open SVG...");
00051 sToolTipText = QT_TR_NOOP("Open a scalable vector graphic");
00052 sWhatsThis = "Drawing_Open";
00053 sStatusTip = sToolTipText;
00054 sPixmap = "actions/document-new";
00055 }
00056
00057
00058 void CmdDrawingOpen::activated(int iMsg)
00059 {
00060
00061 QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QObject::tr("Choose an SVG file to open"), QString::null,
00062 QObject::tr("Scalable Vector Graphics (*.svg *.svgz)"));
00063 if (!filename.isEmpty())
00064 {
00065
00066 Command::doCommand(Command::Gui, "import Drawing, DrawingGui");
00067 Command::doCommand(Command::Gui, "DrawingGui.open(\"%s\")", (const char*)filename.toUtf8());
00068 }
00069 }
00070
00071
00072
00073
00074
00075 DEF_STD_CMD_ACL(CmdDrawingNewPage);
00076
00077 CmdDrawingNewPage::CmdDrawingNewPage()
00078 : Command("Drawing_NewPage")
00079 {
00080 sAppModule = "Drawing";
00081 sGroup = QT_TR_NOOP("Drawing");
00082 sMenuText = QT_TR_NOOP("Insert new drawing");
00083 sToolTipText = QT_TR_NOOP("Insert new drawing");
00084 sWhatsThis = "Drawing_NewPage";
00085 sStatusTip = sToolTipText;
00086 }
00087
00088 void CmdDrawingNewPage::activated(int iMsg)
00089 {
00090 std::string FeatName = getUniqueObjectName("Page");
00091
00092 if (iMsg == 3) {
00093 openCommand("Drawing create page");
00094 doCommand(Doc,"App.activeDocument().addObject('Drawing::FeaturePage','%s')",FeatName.c_str());
00095 doCommand(Doc,"App.activeDocument().%s.Template = 'A3_Landscape.svg'",FeatName.c_str());
00096 commitCommand();
00097 }
00098 else {
00099 QMessageBox::critical(Gui::getMainWindow(),
00100 QLatin1String("No template"),
00101 QLatin1String("No template available for this page size"));
00102 }
00103 }
00104
00105 Gui::Action * CmdDrawingNewPage::createAction(void)
00106 {
00107 Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
00108 pcAction->setDropDownMenu(true);
00109 applyCommandData(pcAction);
00110
00111 QAction* a0 = pcAction->addAction(QString());
00112 a0->setIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape-A0"));
00113
00114 QAction* a1 = pcAction->addAction(QString());
00115 a1->setIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape-A1"));
00116
00117 QAction* a2 = pcAction->addAction(QString());
00118 a2->setIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape-A2"));
00119
00120 QAction* a3 = pcAction->addAction(QString());
00121 a3->setIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape-A3"));
00122
00123 QAction* a4 = pcAction->addAction(QString());
00124 a4->setIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape-A4"));
00125
00126 _pcAction = pcAction;
00127 languageChange();
00128 pcAction->setIcon(a3->icon());
00129 pcAction->setProperty("defaultAction", QVariant(3));
00130
00131 return pcAction;
00132 }
00133
00134 void CmdDrawingNewPage::languageChange()
00135 {
00136 Command::languageChange();
00137
00138 if (!_pcAction)
00139 return;
00140 Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
00141 QList<QAction*> a = pcAction->actions();
00142
00143 a[0]->setText(QCoreApplication::translate(
00144 "Drawing_NewPage", "A0 landscape", 0,
00145 QCoreApplication::CodecForTr));
00146 a[0]->setToolTip(QCoreApplication::translate(
00147 "Drawing_NewPage", "Insert new A0 landscape drawing", 0,
00148 QCoreApplication::CodecForTr));
00149
00150 a[1]->setText(QCoreApplication::translate(
00151 "Drawing_NewPage", "A1 landscape", 0,
00152 QCoreApplication::CodecForTr));
00153 a[1]->setToolTip(QCoreApplication::translate(
00154 "Drawing_NewPage", "Insert new A1 landscape drawing", 0,
00155 QCoreApplication::CodecForTr));
00156
00157 a[2]->setText(QCoreApplication::translate(
00158 "Drawing_NewPage", "A2 landscape", 0,
00159 QCoreApplication::CodecForTr));
00160 a[2]->setToolTip(QCoreApplication::translate(
00161 "Drawing_NewPage", "Insert new A2 landscape drawing", 0,
00162 QCoreApplication::CodecForTr));
00163
00164 a[3]->setText(QCoreApplication::translate(
00165 "Drawing_NewPage", "A3 landscape", 0,
00166 QCoreApplication::CodecForTr));
00167 a[3]->setToolTip(QCoreApplication::translate(
00168 "Drawing_NewPage", "Insert new A3 landscape drawing", 0,
00169 QCoreApplication::CodecForTr));
00170
00171 a[4]->setText(QCoreApplication::translate(
00172 "Drawing_NewPage", "A4 landscape", 0,
00173 QCoreApplication::CodecForTr));
00174 a[4]->setToolTip(QCoreApplication::translate(
00175 "Drawing_NewPage", "Insert new A4 landscape drawing", 0,
00176 QCoreApplication::CodecForTr));
00177 }
00178
00179 bool CmdDrawingNewPage::isActive(void)
00180 {
00181 if (getActiveGuiDocument())
00182 return true;
00183 else
00184 return false;
00185 }
00186
00187
00188
00189
00190
00191 DEF_STD_CMD_A(CmdDrawingNewA3Landscape);
00192
00193 CmdDrawingNewA3Landscape::CmdDrawingNewA3Landscape()
00194 : Command("Drawing_NewA3Landscape")
00195 {
00196 sAppModule = "Drawing";
00197 sGroup = QT_TR_NOOP("Drawing");
00198 sMenuText = QT_TR_NOOP("Insert new A3 landscape drawing");
00199 sToolTipText = QT_TR_NOOP("Insert new A3 landscape drawing");
00200 sWhatsThis = "Drawing_NewA3Landscape";
00201 sStatusTip = sToolTipText;
00202 sPixmap = "actions/drawing-landscape-A3";
00203 }
00204
00205 void CmdDrawingNewA3Landscape::activated(int iMsg)
00206 {
00207 std::string FeatName = getUniqueObjectName("Page");
00208
00209 openCommand("Drawing create page");
00210 doCommand(Doc,"App.activeDocument().addObject('Drawing::FeaturePage','%s')",FeatName.c_str());
00211 doCommand(Doc,"App.activeDocument().%s.Template = 'A3_Landscape.svg'",FeatName.c_str());
00212 commitCommand();
00213 }
00214
00215 bool CmdDrawingNewA3Landscape::isActive(void)
00216 {
00217 if (getActiveGuiDocument())
00218 return true;
00219 else
00220 return false;
00221 }
00222
00223
00224
00225
00226
00227
00228 DEF_STD_CMD(CmdDrawingNewView);
00229
00230 CmdDrawingNewView::CmdDrawingNewView()
00231 : Command("Drawing_NewView")
00232 {
00233 sAppModule = "Drawing";
00234 sGroup = QT_TR_NOOP("Drawing");
00235 sMenuText = QT_TR_NOOP("Insert view in drawing");
00236 sToolTipText = QT_TR_NOOP("Insert a new View of a Part in the active drawing");
00237 sWhatsThis = "Drawing_NewView";
00238 sStatusTip = sToolTipText;
00239 sPixmap = "actions/drawing-view";
00240 }
00241
00242 void CmdDrawingNewView::activated(int iMsg)
00243 {
00244 std::vector<App::DocumentObject*> shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
00245 if (shapes.size() != 1) {
00246 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00247 QObject::tr("Select a Part object."));
00248 return;
00249 }
00250
00251 std::vector<App::DocumentObject*> pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
00252 if (pages.empty()){
00253 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page to insert"),
00254 QObject::tr("Create a page to insert."));
00255 return;
00256 }
00257
00258 std::string FeatName = getUniqueObjectName("View");
00259 std::string PageName = pages.front()->getNameInDocument();
00260
00261 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00262
00263 openCommand("Create view");
00264 doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureViewPart','%s')",FeatName.c_str());
00265 doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),shapes.front()->getNameInDocument());
00266 doCommand(Doc,"App.activeDocument().%s.Direction = (0.0,0.0,1.0)",FeatName.c_str());
00267 doCommand(Doc,"App.activeDocument().%s.X = 10.0",FeatName.c_str());
00268 doCommand(Doc,"App.activeDocument().%s.Y = 10.0",FeatName.c_str());
00269 doCommand(Doc,"App.activeDocument().%s.Scale = 1.0",FeatName.c_str());
00270 doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
00271 updateActive();
00272 commitCommand();
00273 }
00274
00275
00276
00277
00278
00279 DEF_STD_CMD_A(CmdDrawingExportPage);
00280
00281 CmdDrawingExportPage::CmdDrawingExportPage()
00282 : Command("Drawing_ExportPage")
00283 {
00284
00285 sGroup = QT_TR_NOOP("File");
00286 sMenuText = QT_TR_NOOP("&Export page...");
00287 sToolTipText = QT_TR_NOOP("Export a page to an SVG file");
00288 sWhatsThis = "Drawing_ExportPage";
00289 sStatusTip = QT_TR_NOOP("Export a page to an SVG file");
00290 sPixmap = "document-save";
00291 }
00292
00293 void CmdDrawingExportPage::activated(int iMsg)
00294 {
00295 unsigned int n = getSelection().countObjectsOfType(Drawing::FeaturePage::getClassTypeId());
00296 if (n != 1) {
00297 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00298 QObject::tr("Select one Page object."));
00299 return;
00300 }
00301
00302 QStringList filter;
00303 filter << QObject::tr("SVG(*.svg)");
00304 filter << QObject::tr("All Files (*.*)");
00305
00306 QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page"), QString(), filter.join(QLatin1String(";;")));
00307 if (!fn.isEmpty()) {
00308 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00309 openCommand("Drawing export page");
00310
00311 doCommand(Doc,"PageFile = open(App.activeDocument().%s.PageResult,'r')",Sel[0].FeatName);
00312 std::string fname = (const char*)fn.toAscii();
00313 doCommand(Doc,"OutFile = open('%s','w')",fname.c_str());
00314 doCommand(Doc,"OutFile.write(PageFile.read())");
00315 doCommand(Doc,"del OutFile,PageFile");
00316
00317 commitCommand();
00318 }
00319 }
00320
00321 bool CmdDrawingExportPage::isActive(void)
00322 {
00323 return (getActiveGuiDocument() ? true : false);
00324 }
00325
00326
00327
00328
00329
00330 DEF_STD_CMD_A(CmdDrawingProjectShape);
00331
00332 CmdDrawingProjectShape::CmdDrawingProjectShape()
00333 : Command("Drawing_ProjectShape")
00334 {
00335
00336 sGroup = QT_TR_NOOP("Drawing");
00337 sMenuText = QT_TR_NOOP("Project shape...");
00338 sToolTipText = QT_TR_NOOP("Project shape onto a user-defined plane");
00339 sStatusTip = QT_TR_NOOP("Project shape onto a user-defined plane");
00340 sWhatsThis = "Drawing_ProjectShape";
00341 }
00342
00343 void CmdDrawingProjectShape::activated(int iMsg)
00344 {
00345 Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
00346 if (!dlg) {
00347 dlg = new DrawingGui::TaskProjection();
00348 dlg->setButtonPosition(Gui::TaskView::TaskDialog::South);
00349 }
00350 Gui::Control().showDialog(dlg);
00351 }
00352
00353 bool CmdDrawingProjectShape::isActive(void)
00354 {
00355 int ct = Gui::Selection().countObjectsOfType(Part::Feature::getClassTypeId());
00356 return (ct > 0 && !Gui::Control().activeDialog());
00357 }
00358
00359
00360
00361 void CreateDrawingCommands(void)
00362 {
00363 Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
00364
00365 rcCmdMgr.addCommand(new CmdDrawingOpen());
00366 rcCmdMgr.addCommand(new CmdDrawingNewPage());
00367 rcCmdMgr.addCommand(new CmdDrawingNewA3Landscape());
00368 rcCmdMgr.addCommand(new CmdDrawingNewView());
00369 rcCmdMgr.addCommand(new CmdDrawingExportPage());
00370 rcCmdMgr.addCommand(new CmdDrawingProjectShape());
00371 }