FreeCAD

Форк
0
/
ViewProviderProjGroupItem.cpp 
199 строк · 7.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2014 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
 #include <QMessageBox>
26
 #include <QTextStream>
27
#endif
28

29
#include <App/DocumentObject.h>
30
#include <Gui/Control.h>
31
#include <Gui/MainWindow.h>
32

33
#include <Mod/TechDraw/App/DrawProjGroup.h>
34
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
35

36
#include "ViewProviderProjGroupItem.h"
37

38
using namespace TechDrawGui;
39

40
PROPERTY_SOURCE(TechDrawGui::ViewProviderProjGroupItem, TechDrawGui::ViewProviderViewPart)
41

42
//**************************************************************************
43
// Construction/Destruction
44

45
ViewProviderProjGroupItem::ViewProviderProjGroupItem()
46
{
47

48
}
49

50
ViewProviderProjGroupItem::~ViewProviderProjGroupItem()
51
{
52
}
53

54
void ViewProviderProjGroupItem::updateData(const App::Property* prop)
55
{
56
    Gui::ViewProviderDocumentObject::updateData(prop);
57
    TechDraw::DrawProjGroupItem* proj = getObject();
58
    if(!proj) {
59
        return;
60
    }
61

62
    // Set the icon pixmap depending on the orientation
63
    std::string projType = proj->Type.getValueAsString();
64

65
    //TODO: Once we know that ProjType is valid, sPixMap = "Proj" + projType
66

67
    if(strcmp(projType.c_str(), "Front") == 0) {
68
        sPixmap = "TechDraw_ProjFront";
69
    } else if(strcmp(projType.c_str(), "Rear") == 0) {
70
        sPixmap = "TechDraw_ProjRear";
71
    } else if(strcmp(projType.c_str(), "Right") == 0) {
72
        sPixmap = "TechDraw_ProjRight";
73
    } else if(strcmp(projType.c_str(), "Left") == 0) {
74
        sPixmap = "TechDraw_ProjLeft";
75
    } else if(strcmp(projType.c_str(), "Top") == 0) {
76
        sPixmap = "TechDraw_ProjTop";
77
    } else if(strcmp(projType.c_str(), "Bottom") == 0) {
78
        sPixmap = "TechDraw_ProjBottom";
79
    } else if(strcmp(projType.c_str(), "FrontTopLeft") == 0) {
80
        sPixmap = "TechDraw_ProjFrontTopLeft";
81
    } else if(strcmp(projType.c_str(), "FrontTopRight") == 0) {
82
        sPixmap = "TechDraw_ProjFrontTopRight";
83
    } else if(strcmp(projType.c_str(), "FrontBottomRight") == 0) {
84
        sPixmap = "TechDraw_ProjFrontBottomRight";
85
    } else if(strcmp(projType.c_str(), "FrontBottomLeft") == 0) {
86
        sPixmap = "TechDraw_ProjFrontBottomLeft";
87
    }
88
 }
89

90

91
void ViewProviderProjGroupItem::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
92
{
93
    Q_UNUSED(menu);
94
    Q_UNUSED(receiver);
95
    Q_UNUSED(member);
96
    //QAction* act;
97
    //act = menu->addAction(QObject::tr("Show drawing"), receiver, member);
98
}
99

100
bool ViewProviderProjGroupItem::setEdit(int ModNum)
101
{
102
    Q_UNUSED(ModNum);
103
    doubleClicked();
104
    return true;
105
}
106

107
void ViewProviderProjGroupItem::unsetEdit(int ModNum)
108
{
109
    Q_UNUSED(ModNum);
110
    Gui::Control().closeDialog();
111
}
112

113
bool ViewProviderProjGroupItem::doubleClicked()
114
{
115
    return true;
116
}
117

118
bool ViewProviderProjGroupItem::onDelete(const std::vector<std::string> &)
119
{
120
    // we cannot delete the anchor view, thus check if the item is the front item
121
    // we also cannot delete if the item has a section or detail view
122

123
    QString bodyMessage;
124
    QTextStream bodyMessageStream(&bodyMessage);
125
    bool isAnchor = false;
126

127
    // get the item and group
128
    TechDraw::DrawProjGroupItem* dpgi = static_cast<TechDraw::DrawProjGroupItem*>(getViewObject());
129
    TechDraw::DrawProjGroup* dpg = dpgi->getPGroup();
130
    // get the projection
131
    TechDraw::DrawProjGroupItem* proj = getObject();
132
    // check if it is the anchor projection
133
    if (dpg && (dpg->hasProjection(proj->Type.getValueAsString()))
134
        && (dpg->getAnchor() == dpgi))
135
        isAnchor = true;
136

137
    // get child views
138
    auto viewSection = getObject()->getSectionRefs();
139
    auto viewDetail = getObject()->getDetailRefs();
140
    auto viewLeader = getObject()->getLeaders();
141

142
   if (isAnchor)
143
   {
144
       // generate dialog
145
        bodyMessageStream << qApp->translate("Std_Delete",
146
            "You cannot delete the anchor view of a projection group.");
147
        QMessageBox::warning(Gui::getMainWindow(),
148
            qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
149
            QMessageBox::Ok);
150
        // don't allow to delete
151
        return false;
152
   }
153
   else if (!viewSection.empty()) {
154
       bodyMessageStream << qApp->translate("Std_Delete",
155
           "You cannot delete this view because it has a section view that would become broken.");
156
       QMessageBox::warning(Gui::getMainWindow(),
157
           qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
158
           QMessageBox::Ok);
159
       return false;
160
   }
161
   else if (!viewDetail.empty()) {
162
       bodyMessageStream << qApp->translate("Std_Delete",
163
           "You cannot delete this view because it has a detail view that would become broken.");
164
       QMessageBox::warning(Gui::getMainWindow(),
165
           qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
166
           QMessageBox::Ok);
167
       return false;
168
   }
169
   else if (!viewLeader.empty()) {
170
       bodyMessageStream << qApp->translate("Std_Delete",
171
           "You cannot delete this view because it has a leader line that would become broken.");
172
       QMessageBox::warning(Gui::getMainWindow(),
173
           qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
174
           QMessageBox::Ok);
175
       return false;
176
   }
177
   else {
178
        return true;
179
   }
180
}
181

182
bool ViewProviderProjGroupItem::canDelete(App::DocumentObject *obj) const
183
{
184
    // deletions of objects from a ProjGroupItem don't necessarily destroy anything
185
    // thus we can pass this action
186
    // we can warn the user if necessary in the object's ViewProvider in the onDelete() function
187
    Q_UNUSED(obj)
188
    return true;
189
}
190

191
TechDraw::DrawProjGroupItem* ViewProviderProjGroupItem::getViewObject() const
192
{
193
    return dynamic_cast<TechDraw::DrawProjGroupItem*>(pcObject);
194
}
195

196
TechDraw::DrawProjGroupItem* ViewProviderProjGroupItem::getObject() const
197
{
198
    return getViewObject();
199
}
200

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

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

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

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