FreeCAD

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

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
# ifdef FC_OS_WIN32
26
#  include <windows.h>
27
# endif
28
# include <QMenu>
29
# include <QMessageBox>
30
# include <QTextStream>
31
#endif
32

33
#include <App/DocumentObject.h>
34
#include <Gui/Control.h>
35
#include <Gui/MainWindow.h>
36
#include <Gui/Selection.h>
37

38
#include <Mod/TechDraw/App/DrawLeaderLine.h>
39
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
40
#include <Mod/TechDraw/App/DrawViewDetail.h>
41
#include <Mod/TechDraw/App/DrawViewSection.h>
42

43
#include "TaskProjGroup.h"
44
#include "ViewProviderProjGroup.h"
45

46
using namespace TechDrawGui;
47

48
PROPERTY_SOURCE(TechDrawGui::ViewProviderProjGroup, TechDrawGui::ViewProviderDrawingView)
49

50
//**************************************************************************
51
// Construction/Destruction
52

53
ViewProviderProjGroup::ViewProviderProjGroup()
54
{
55
    sPixmap = "TechDraw_TreeProjGroup";
56
}
57

58
ViewProviderProjGroup::~ViewProviderProjGroup()
59
{
60
}
61

62
void ViewProviderProjGroup::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
63
{
64
    Q_UNUSED(menu);
65
    Q_UNUSED(receiver);
66
    Q_UNUSED(member);
67
}
68

69
bool ViewProviderProjGroup::setEdit(int ModNum)
70
{
71
    Q_UNUSED(ModNum);
72
    // When double-clicking on the item for this sketch the
73
    // object unsets and sets its edit mode without closing
74
    // the task panel
75
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
76
    TaskDlgProjGroup *projDlg = qobject_cast<TaskDlgProjGroup *>(dlg);
77
    if (projDlg && projDlg->getViewProvider() != this)
78
        projDlg = nullptr; // another sketch left open its task panel
79

80
    // clear the selection (convenience)
81
    Gui::Selection().clearSelection();
82

83
    // start the edit dialog
84
    if (projDlg) {
85
        projDlg->setCreateMode(false);
86
        Gui::Control().showDialog(projDlg);
87
    } else {
88
        Gui::Control().showDialog(new TaskDlgProjGroup(getObject(), false));
89
    }
90

91
    return true;
92
}
93

94
bool ViewProviderProjGroup::doubleClicked()
95
{
96
    setEdit(0);
97
    return true;
98
}
99

100
bool ViewProviderProjGroup::onDelete(const std::vector<std::string> &)
101
{
102
    // warn the user if the ProjGroup is not empty
103

104
    QString bodyMessage;
105
    QTextStream bodyMessageStream(&bodyMessage);
106
    TechDraw::DrawProjGroupItem* Item = nullptr;
107
    std::vector<std::string> ViewList;
108

109
    // get the items in the group
110
    auto objs = claimChildren();
111

112
    // iterate over all item to check which ones have a section or detail view
113
    for (auto ObjectIterator : objs) {
114
        // get item
115
        Item = static_cast<TechDraw::DrawProjGroupItem*>(ObjectIterator);
116
        // get its section views
117
        auto viewSection = Item->getSectionRefs();
118
        // add names to a list
119
        if (!viewSection.empty()) {
120
            for (auto SecIterator : viewSection) {
121
                ViewList.emplace_back(SecIterator->Label.getValue());
122
            }
123
        }
124
        // get its detail views
125
        auto viewDetail = Item->getDetailRefs();
126
        if (!viewDetail.empty()) {
127
            for (auto DetIterator : viewDetail) {
128
                ViewList.emplace_back(DetIterator->Label.getValue());
129
            }
130
        }
131
        // get its leader lines
132
        auto viewLead = Item->getLeaders();
133
        if (!viewLead.empty()) {
134
            for (auto LeadIterator : viewLead) {
135
                ViewList.emplace_back(LeadIterator->Label.getValue());
136
            }
137
        }
138
    }
139

140
    // if there are section or detail views we cannot delete because this would break them
141
    if (!ViewList.empty()) {
142
        bodyMessageStream << qApp->translate("Std_Delete",
143
            "The group cannot be deleted because its items have the following\nsection or detail views, or leader lines that would get broken:");
144
        bodyMessageStream << '\n';
145
        for (const auto& ListIterator : ViewList)
146
            bodyMessageStream << '\n' << QString::fromUtf8(ListIterator.c_str());
147
        QMessageBox::warning(Gui::getMainWindow(),
148
            qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
149
            QMessageBox::Ok);
150
        return false;
151
    }
152

153
    if (!objs.empty())
154
    {
155
        // generate dialog
156
        bodyMessageStream << qApp->translate("Std_Delete",
157
            "The projection group is not empty, therefore\nthe following referencing objects might be lost:");
158
        bodyMessageStream << '\n';
159
        for (auto ObjIterator : objs)
160
            bodyMessageStream << '\n' << QString::fromUtf8(ObjIterator->Label.getValue());
161
        bodyMessageStream << "\n\n" << QObject::tr("Are you sure you want to continue?");
162
        // show and evaluate dialog
163
        int DialogResult = QMessageBox::warning(Gui::getMainWindow(),
164
            qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
165
            QMessageBox::Yes, QMessageBox::No);
166
        if (DialogResult == QMessageBox::Yes)
167
            return true;
168
        else
169
            return false;
170
    }
171
    else
172
        return true;
173
}
174

175
bool ViewProviderProjGroup::canDelete(App::DocumentObject *obj) const
176
{
177
    // deletions of views from a ProjGroup don't necessarily destroy anything
178
    // thus we can pass this action
179
    // we can warn the user if necessary in the object's ViewProvider in the onDelete() function
180
    Q_UNUSED(obj)
181
    return true;
182
}
183

184
std::vector<App::DocumentObject*> ViewProviderProjGroup::claimChildren() const
185
{
186
    // Collect any child fields
187
    std::vector<App::DocumentObject*> temp;
188
    const std::vector<App::DocumentObject *> &views = getObject()->Views.getValues();
189
    try {
190
      for (std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
191
          temp.push_back(*it);
192
      }
193
      return temp;
194
    } catch (...) {
195
        std::vector<App::DocumentObject*> tmp;
196
        return tmp;
197
    }
198
}
199

200
TechDraw::DrawProjGroup* ViewProviderProjGroup::getViewObject() const
201
{
202
    return dynamic_cast<TechDraw::DrawProjGroup*>(pcObject);
203
}
204

205
TechDraw::DrawProjGroup* ViewProviderProjGroup::getObject() const
206
{
207
    return getViewObject();
208
}
209

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

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

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

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