FreeCAD

Форк
0
/
CommandStack.cpp 
416 строк · 14.1 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2022 Wanderer Fan <wandererfan@gmail.com>               *
3
 *                                                                         *
4
 *   This library is free software; you can redistribute it and/or         *
5
 *   modify it under the terms of the GNU Library General Public           *
6
 *   License as published by the Free Software Foundation; either          *
7
 *   version 2 of the License, or (at your option) any later version.      *
8
 *                                                                         *
9
 *   This library  is distributed in the hope that it will be useful,      *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU Library General Public License for more details.                  *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU Library General Public     *
15
 *   License along with this library; see the file COPYING.LIB. If not,    *
16
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
17
 *   Suite 330, Boston, MA  02111-1307, USA                                *
18
 *                                                                         *
19
 ***************************************************************************/
20

21
#include "PreCompiled.h"
22

23
#ifndef _PreComp_
24
# include <QApplication>
25
# include <QMessageBox>
26
#endif
27

28
#include <App/DocumentObject.h>
29
#include <Base/Console.h>
30
#include <Gui/Action.h>
31
#include <Gui/Application.h>
32
#include <Gui/BitmapFactory.h>
33
#include <Gui/Command.h>
34
#include <Gui/Control.h>
35
#include <Gui/Document.h>
36
#include <Gui/MainWindow.h>
37
#include <Gui/Selection.h>
38
#include <Gui/ViewProvider.h>
39
#include <Mod/TechDraw/App/DrawPage.h>
40
#include <Mod/TechDraw/App/DrawView.h>
41

42
#include "DrawGuiUtil.h"
43
#include "ViewProviderDrawingView.h"
44

45

46
using namespace TechDrawGui;
47
using namespace TechDraw;
48

49
void execStackTop(Gui::Command* cmd);
50
void execStackBottom(Gui::Command* cmd);
51
void execStackUp(Gui::Command* cmd);
52
void execStackDown(Gui::Command* cmd);
53

54
//===========================================================================
55
// TechDraw_StackGroup
56
//===========================================================================
57

58
DEF_STD_CMD_ACL(CmdTechDrawStackGroup)
59

60
CmdTechDrawStackGroup::CmdTechDrawStackGroup()
61
  : Command("TechDraw_StackGroup")
62
{
63
    sAppModule      = "TechDraw";
64
    sGroup          = QT_TR_NOOP("TechDraw");
65
    sMenuText       = QT_TR_NOOP("Adjust stacking order of views");
66
    sToolTipText    = sMenuText;
67
    sWhatsThis      = "TechDraw_StackGroup";
68
    sStatusTip      = sToolTipText;
69
}
70

71
void CmdTechDrawStackGroup::activated(int iMsg)
72
{
73
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
74
    if (dlg) {
75
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
76
            QObject::tr("Close active task dialog and try again."));
77
        return;
78
    }
79

80
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
81
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
82
    switch(iMsg) {
83
        case 0:
84
            execStackTop(this);
85
            break;
86
        case 1:
87
            execStackBottom(this);
88
            break;
89
        case 2:
90
            execStackUp(this);
91
            break;
92
        case 3:
93
            execStackDown(this);
94
            break;
95
        default:
96
            Base::Console().Message("CMD::StackGrp - invalid iMsg: %d\n",iMsg);
97
    };
98
}
99

100
Gui::Action * CmdTechDrawStackGroup::createAction(void)
101
{
102
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
103
    pcAction->setDropDownMenu(true);
104
    applyCommandData(this->className(), pcAction);
105

106
    QAction* p1 = pcAction->addAction(QString());
107
    p1->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_StackTop"));
108
    p1->setObjectName(QString::fromLatin1("TechDraw_StackTop"));
109
    p1->setWhatsThis(QString::fromLatin1("TechDraw_StackTop"));
110
    QAction* p2 = pcAction->addAction(QString());
111
    p2->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_StackBottom"));
112
    p2->setObjectName(QString::fromLatin1("TechDraw_StackBottom"));
113
    p2->setWhatsThis(QString::fromLatin1("TechDraw_StackBottom"));
114
    QAction* p3 = pcAction->addAction(QString());
115
    p3->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_StackUp"));
116
    p3->setObjectName(QString::fromLatin1("TechDraw_StackUp"));
117
    p3->setWhatsThis(QString::fromLatin1("TechDraw_StackUp"));
118
    QAction* p4 = pcAction->addAction(QString());
119
    p4->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_StackDown"));
120
    p4->setObjectName(QString::fromLatin1("TechDraw_StackDown"));
121
    p4->setWhatsThis(QString::fromLatin1("TechDraw_StackDown"));
122

123
    _pcAction = pcAction;
124
    languageChange();
125

126
    pcAction->setIcon(p1->icon());
127
    int defaultId = 0;
128
    pcAction->setProperty("defaultAction", QVariant(defaultId));
129

130
    return pcAction;
131
}
132

133
void CmdTechDrawStackGroup::languageChange()
134
{
135
    Command::languageChange();
136

137
    if (!_pcAction)
138
        return;
139
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
140
    QList<QAction*> a = pcAction->actions();
141

142
    QAction* arc1 = a[0];
143
    arc1->setText(QApplication::translate("CmdTechDrawStackGroup","Stack Top"));
144
    arc1->setToolTip(QApplication::translate("TechDraw_StackTop","Move view to top of stack"));
145
    arc1->setStatusTip(arc1->toolTip());
146
    QAction* arc2 = a[1];
147
    arc2->setText(QApplication::translate("CmdTechDrawStackGroup","Stack Bottom"));
148
    arc2->setToolTip(QApplication::translate("TechDraw_StackBottom","Move view to bottom of stack"));
149
    arc2->setStatusTip(arc2->toolTip());
150
    QAction* arc3 = a[2];
151
    arc3->setText(QApplication::translate("CmdTechDrawStackGroup","Stack Up"));
152
    arc3->setToolTip(QApplication::translate("TechDraw_StackUp","Move view up one level"));
153
    arc3->setStatusTip(arc3->toolTip());
154
    QAction* arc4 = a[3];
155
    arc4->setText(QApplication::translate("CmdTechDrawStackGroup","Stack Down"));
156
    arc4->setToolTip(QApplication::translate("TechDraw_StackDown","Move view down one level"));
157
    arc4->setStatusTip(arc4->toolTip());
158
}
159

160
bool CmdTechDrawStackGroup::isActive(void)
161
{
162
    bool havePage = DrawGuiUtil::needPage(this);
163
    bool haveView = DrawGuiUtil::needView(this, false);
164
    return (havePage && haveView);
165
}
166

167
//===========================================================================
168
// TechDraw_StackTop
169
//===========================================================================
170

171
DEF_STD_CMD_A(CmdTechDrawStackTop)
172

173
CmdTechDrawStackTop::CmdTechDrawStackTop()
174
  : Command("TechDraw_StackTop")
175
{
176
    sAppModule      = "TechDraw";
177
    sGroup          = QT_TR_NOOP("TechDraw");
178
    sMenuText       = QT_TR_NOOP("Move view to top of stack");
179
    sToolTipText    = sMenuText;
180
    sWhatsThis      = "TechDraw_StackTop";
181
    sStatusTip      = sToolTipText;
182
    sPixmap         = "actions/TechDraw_StackTop";
183
}
184

185
void CmdTechDrawStackTop::activated(int iMsg)
186
{
187
    Q_UNUSED(iMsg);
188

189
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
190
    if (dlg) {
191
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
192
            QObject::tr("Close active task dialog and try again."));
193
        return;
194
    }
195

196
    execStackTop(this);
197
}
198

199
bool CmdTechDrawStackTop::isActive(void)
200
{
201
    bool havePage = DrawGuiUtil::needPage(this);
202
    bool haveView = DrawGuiUtil::needView(this, false);
203
    return (havePage && haveView);
204
}
205

206
void execStackTop(Gui::Command* cmd)
207
{
208
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
209
    if (!page) {
210
        return;
211
    }
212

213
    std::vector<App::DocumentObject*> views = cmd->getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId());
214
    if (!views.empty()) {
215
        for (auto& v: views) {
216
            TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(v);
217
            Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(
218
                                    cmd->getDocument())->getViewProvider(dv);
219
            ViewProviderDrawingView* vpdv = static_cast<ViewProviderDrawingView*>(vp);
220
            if (vpdv) {
221
                vpdv->stackTop();
222
            }
223
        }
224
    }
225
}
226

227
//===========================================================================
228
// TechDraw_StackBottom
229
//===========================================================================
230

231
DEF_STD_CMD_A(CmdTechDrawStackBottom)
232

233
CmdTechDrawStackBottom::CmdTechDrawStackBottom()
234
  : Command("TechDraw_StackBottom")
235
{
236
    sAppModule      = "TechDraw";
237
    sGroup          = QT_TR_NOOP("TechDraw");
238
    sMenuText       = QT_TR_NOOP("Move view to bottom of stack");
239
    sToolTipText    = sMenuText;
240
    sWhatsThis      = "TechDraw_StackBottom";
241
    sStatusTip      = sToolTipText;
242
    sPixmap         = "actions/TechDraw_StackBottom";
243
}
244

245
void CmdTechDrawStackBottom::activated(int iMsg)
246
{
247
    Q_UNUSED(iMsg);
248

249
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
250
    if (dlg) {
251
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
252
            QObject::tr("Close active task dialog and try again."));
253
        return;
254
    }
255

256
    execStackBottom(this);
257
}
258

259
bool CmdTechDrawStackBottom::isActive(void)
260
{
261
    bool havePage = DrawGuiUtil::needPage(this);
262
    bool haveView = DrawGuiUtil::needView(this, false);
263
    return (havePage && haveView);
264
}
265

266
void execStackBottom(Gui::Command* cmd)
267
{
268
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
269
    if (!page) {
270
        return;
271
    }
272

273
    std::vector<App::DocumentObject*> views = cmd->getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId());
274
    if (!views.empty()) {
275
        for (auto& v: views) {
276
            TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(v);
277
            Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(
278
                                    cmd->getDocument())->getViewProvider(dv);
279
            ViewProviderDrawingView* vpdv = static_cast<ViewProviderDrawingView*>(vp);
280
            if (vpdv) {
281
                vpdv->stackBottom();
282
            }
283
        }
284
    }
285
}
286

287
//===========================================================================
288
// TechDraw_StackUp
289
//===========================================================================
290

291
DEF_STD_CMD_A(CmdTechDrawStackUp)
292

293
CmdTechDrawStackUp::CmdTechDrawStackUp()
294
  : Command("TechDraw_StackUp")
295
{
296
    sAppModule      = "TechDraw";
297
    sGroup          = QT_TR_NOOP("TechDraw");
298
    sMenuText       = QT_TR_NOOP("Move view up one level");
299
    sToolTipText    = sMenuText;
300
    sWhatsThis      = "TechDraw_StackUp";
301
    sStatusTip      = sToolTipText;
302
    sPixmap         = "actions/TechDraw_StackUp";
303
}
304

305
void CmdTechDrawStackUp::activated(int iMsg)
306
{
307
    Q_UNUSED(iMsg);
308

309
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
310
    if (dlg) {
311
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
312
            QObject::tr("Close active task dialog and try again."));
313
        return;
314
    }
315

316
    execStackUp(this);
317
}
318

319
bool CmdTechDrawStackUp::isActive(void)
320
{
321
    bool havePage = DrawGuiUtil::needPage(this);
322
    bool haveView = DrawGuiUtil::needView(this, false);
323
    return (havePage && haveView);
324
}
325

326
void execStackUp(Gui::Command* cmd)
327
{
328
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
329
    if (!page) {
330
        return;
331
    }
332

333
    std::vector<App::DocumentObject*> views = cmd->getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId());
334
    if (!views.empty()) {
335
        for (auto& v: views) {
336
            TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(v);
337
            Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(
338
                                    cmd->getDocument())->getViewProvider(dv);
339
            ViewProviderDrawingView* vpdv = static_cast<ViewProviderDrawingView*>(vp);
340
            if (vpdv) {
341
                vpdv->stackUp();
342
            }
343
        }
344
    }
345
}
346

347
//===========================================================================
348
// TechDraw_StackDown
349
//===========================================================================
350

351
DEF_STD_CMD_A(CmdTechDrawStackDown)
352

353
CmdTechDrawStackDown::CmdTechDrawStackDown()
354
  : Command("TechDraw_StackDown")
355
{
356
    sAppModule      = "TechDraw";
357
    sGroup          = QT_TR_NOOP("TechDraw");
358
    sMenuText       = QT_TR_NOOP("Move view down one level");
359
    sToolTipText    = sMenuText;
360
    sWhatsThis      = "TechDraw_StackDown";
361
    sStatusTip      = sToolTipText;
362
    sPixmap         = "actions/TechDraw_StackDown";
363
}
364

365
void CmdTechDrawStackDown::activated(int iMsg)
366
{
367
    Q_UNUSED(iMsg);
368

369
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
370
    if (dlg) {
371
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
372
            QObject::tr("Close active task dialog and try again."));
373
        return;
374
    }
375

376
    execStackDown(this);
377
}
378

379
bool CmdTechDrawStackDown::isActive(void)
380
{
381
    bool havePage = DrawGuiUtil::needPage(this);
382
    bool haveView = DrawGuiUtil::needView(this, false);
383
    return (havePage && haveView);
384
}
385

386
void execStackDown(Gui::Command* cmd)
387
{
388
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
389
    if (!page) {
390
        return;
391
    }
392

393
    std::vector<App::DocumentObject*> views = cmd->getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId());
394
    if (!views.empty()) {
395
        for (auto& v: views) {
396
            TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(v);
397
            Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(
398
                                    cmd->getDocument())->getViewProvider(dv);
399
            ViewProviderDrawingView* vpdv = static_cast<ViewProviderDrawingView*>(vp);
400
            if (vpdv) {
401
                vpdv->stackDown();
402
            }
403
        }
404
    }
405
}
406

407
void CreateTechDrawCommandsStack(void)
408
{
409
    Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
410

411
    rcCmdMgr.addCommand(new CmdTechDrawStackGroup());
412
    rcCmdMgr.addCommand(new CmdTechDrawStackTop());
413
    rcCmdMgr.addCommand(new CmdTechDrawStackBottom());
414
    rcCmdMgr.addCommand(new CmdTechDrawStackUp());
415
    rcCmdMgr.addCommand(new CmdTechDrawStackDown());
416
}
417

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

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

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

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