FreeCAD

Форк
0
/
CommandParametric.cpp 
276 строк · 9.3 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de>              *
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

24
#include "PreCompiled.h"
25

26
#ifndef _PreComp_
27
# include <QApplication>
28
#endif
29

30
#include <App/Part.h>
31
#include <Gui/Application.h>
32
#include <Gui/Command.h>
33
#include <Gui/Document.h>
34
#include <Gui/MDIView.h>
35

36

37
//===========================================================================
38
// Utils
39
//===========================================================================
40
namespace {
41
QString getAutoGroupCommandStr()
42
// Helper function to get the python code to add the newly created object to the active Part object if present
43
{
44
    App::Part* activePart = Gui::Application::Instance->activeView()->getActiveObject<App::Part*>("part");
45
    if (activePart) {
46
        QString activePartName = QString::fromLatin1(activePart->getNameInDocument());
47
        return QString::fromLatin1("App.ActiveDocument.getObject('%1\')."
48
            "addObject(App.ActiveDocument.ActiveObject)\n")
49
            .arg(activePartName);
50
    }
51
    return QString::fromLatin1("# Object created at document root.");
52
}
53
}
54

55
//===========================================================================
56
// Part_Cylinder
57
//===========================================================================
58
DEF_STD_CMD_A(CmdPartCylinder)
59

60
CmdPartCylinder::CmdPartCylinder()
61
  : Command("Part_Cylinder")
62
{
63
    sAppModule    = "Part";
64
    sGroup        = QT_TR_NOOP("Part");
65
    sMenuText     = QT_TR_NOOP("Cylinder");
66
    sToolTipText  = QT_TR_NOOP("Create a Cylinder");
67
    sWhatsThis    = "Part_Cylinder";
68
    sStatusTip    = sToolTipText;
69
    sPixmap       = "Part_Cylinder_Parametric";
70
}
71

72
void CmdPartCylinder::activated(int iMsg)
73
{
74
    Q_UNUSED(iMsg);
75
    QString cmd;
76
    cmd = qApp->translate("CmdPartCylinder","Cylinder");
77
    openCommand((const char*)cmd.toUtf8());
78

79
    runCommand(Doc,"App.ActiveDocument.addObject(\"Part::Cylinder\",\"Cylinder\")");
80
    cmd = QString::fromLatin1("App.ActiveDocument.ActiveObject.Label = \"%1\"")
81
        .arg(qApp->translate("CmdPartCylinder","Cylinder"));
82
    runCommand(Doc,cmd.toUtf8());
83
    runCommand(Doc, getAutoGroupCommandStr().toUtf8());
84
    commitCommand();
85
    updateActive();
86
    runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
87
}
88

89
bool CmdPartCylinder::isActive()
90
{
91
    if (getActiveGuiDocument())
92
        return true;
93
    else
94
        return false;
95
}
96

97
//===========================================================================
98
// Part_Box
99
//===========================================================================
100
DEF_STD_CMD_A(CmdPartBox)
101

102
CmdPartBox::CmdPartBox()
103
  : Command("Part_Box")
104
{
105
    sAppModule    = "Part";
106
    sGroup        = QT_TR_NOOP("Part");
107
    sMenuText     = QT_TR_NOOP("Cube");
108
    sToolTipText  = QT_TR_NOOP("Create a cube solid");
109
    sWhatsThis    = "Part_Box";
110
    sStatusTip    = sToolTipText;
111
    sPixmap       = "Part_Box_Parametric";
112
}
113

114
void CmdPartBox::activated(int iMsg)
115
{
116
    Q_UNUSED(iMsg);
117
    QString cmd;
118
    cmd = qApp->translate("CmdPartBox","Cube");
119
    openCommand((const char*)cmd.toUtf8());
120

121
    runCommand(Doc,"App.ActiveDocument.addObject(\"Part::Box\",\"Box\")");
122
    cmd = QString::fromLatin1("App.ActiveDocument.ActiveObject.Label = \"%1\"")
123
        .arg(qApp->translate("CmdPartBox","Cube"));
124
    runCommand(Doc,cmd.toUtf8());
125
    runCommand(Doc, getAutoGroupCommandStr().toUtf8());
126
    commitCommand();
127
    updateActive();
128
    runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
129
}
130

131
bool CmdPartBox::isActive()
132
{
133
    if (getActiveGuiDocument())
134
        return true;
135
    else
136
        return false;
137
}
138

139
//===========================================================================
140
// Part_Sphere
141
//===========================================================================
142
DEF_STD_CMD_A(CmdPartSphere)
143

144
CmdPartSphere::CmdPartSphere()
145
  : Command("Part_Sphere")
146
{
147
    sAppModule    = "Part";
148
    sGroup        = QT_TR_NOOP("Part");
149
    sMenuText     = QT_TR_NOOP("Sphere");
150
    sToolTipText  = QT_TR_NOOP("Create a sphere solid");
151
    sWhatsThis    = "Part_Sphere";
152
    sStatusTip    = sToolTipText;
153
    sPixmap       = "Part_Sphere_Parametric";
154
}
155

156
void CmdPartSphere::activated(int iMsg)
157
{
158
    Q_UNUSED(iMsg);
159
    QString cmd;
160
    cmd = qApp->translate("CmdPartSphere","Sphere");
161
    openCommand((const char*)cmd.toUtf8());
162

163
    runCommand(Doc,"App.ActiveDocument.addObject(\"Part::Sphere\",\"Sphere\")");
164
    cmd = QString::fromLatin1("App.ActiveDocument.ActiveObject.Label = \"%1\"")
165
        .arg(qApp->translate("CmdPartSphere","Sphere"));
166
    runCommand(Doc,cmd.toUtf8());
167
    runCommand(Doc, getAutoGroupCommandStr().toUtf8());
168
    commitCommand();
169
    updateActive();
170
    runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
171
}
172

173
bool CmdPartSphere::isActive()
174
{
175
    if (getActiveGuiDocument())
176
        return true;
177
    else
178
        return false;
179
}
180

181
//===========================================================================
182
// Part_Cone
183
//===========================================================================
184
DEF_STD_CMD_A(CmdPartCone)
185

186
CmdPartCone::CmdPartCone()
187
  : Command("Part_Cone")
188
{
189
    sAppModule    = "Part";
190
    sGroup        = QT_TR_NOOP("Part");
191
    sMenuText     = QT_TR_NOOP("Cone");
192
    sToolTipText  = QT_TR_NOOP("Create a cone solid");
193
    sWhatsThis    = "Part_Cone";
194
    sStatusTip    = sToolTipText;
195
    sPixmap       = "Part_Cone_Parametric";
196
}
197

198
void CmdPartCone::activated(int iMsg)
199
{
200
    Q_UNUSED(iMsg);
201
    QString cmd;
202
    cmd = qApp->translate("CmdPartCone","Cone");
203
    openCommand((const char*)cmd.toUtf8());
204

205
    runCommand(Doc,"App.ActiveDocument.addObject(\"Part::Cone\",\"Cone\")");
206
    cmd = QString::fromLatin1("App.ActiveDocument.ActiveObject.Label = \"%1\"")
207
        .arg(qApp->translate("CmdPartCone","Cone"));
208
    runCommand(Doc,cmd.toUtf8());
209
    runCommand(Doc, getAutoGroupCommandStr().toUtf8());
210
    commitCommand();
211
    updateActive();
212
    runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
213
}
214

215
bool CmdPartCone::isActive()
216
{
217
    if (getActiveGuiDocument())
218
        return true;
219
    else
220
        return false;
221
}
222

223
//===========================================================================
224
// Part_Torus
225
//===========================================================================
226
DEF_STD_CMD_A(CmdPartTorus)
227

228
CmdPartTorus::CmdPartTorus()
229
  : Command("Part_Torus")
230
{
231
    sAppModule    = "Part";
232
    sGroup        = QT_TR_NOOP("Part");
233
    sMenuText     = QT_TR_NOOP("Torus");
234
    sToolTipText  = QT_TR_NOOP("Create a torus solid");
235
    sWhatsThis    = "Part_Torus";
236
    sStatusTip    = sToolTipText;
237
    sPixmap       = "Part_Torus_Parametric";
238
}
239

240
void CmdPartTorus::activated(int iMsg)
241
{
242
    Q_UNUSED(iMsg);
243
    QString cmd;
244
    cmd = qApp->translate("CmdPartTorus","Torus");
245
    openCommand((const char*)cmd.toUtf8());
246

247
    runCommand(Doc,"App.ActiveDocument.addObject(\"Part::Torus\",\"Torus\")");
248
    cmd = QString::fromLatin1("App.ActiveDocument.ActiveObject.Label = \"%1\"")
249
        .arg(qApp->translate("CmdPartTorus","Torus"));
250
    runCommand(Doc,cmd.toUtf8());
251
    runCommand(Doc, getAutoGroupCommandStr().toUtf8());
252
    commitCommand();
253
    updateActive();
254
    runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
255
}
256

257
bool CmdPartTorus::isActive()
258
{
259
    if (getActiveGuiDocument())
260
        return true;
261
    else
262
        return false;
263
}
264

265

266
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
267

268
void CreateParamPartCommands()
269
{
270
    Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
271
    rcCmdMgr.addCommand(new CmdPartCylinder());
272
    rcCmdMgr.addCommand(new CmdPartBox());
273
    rcCmdMgr.addCommand(new CmdPartSphere());
274
    rcCmdMgr.addCommand(new CmdPartCone());
275
    rcCmdMgr.addCommand(new CmdPartTorus());
276
}
277

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

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

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

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