1
/***************************************************************************
2
* Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
24
#include "PreCompiled.h"
27
# include <QApplication>
31
#include <Gui/Application.h>
32
#include <Gui/Command.h>
33
#include <Gui/Document.h>
34
#include <Gui/MDIView.h>
37
//===========================================================================
39
//===========================================================================
41
QString getAutoGroupCommandStr()
42
// Helper function to get the python code to add the newly created object to the active Part object if present
44
App::Part* activePart = Gui::Application::Instance->activeView()->getActiveObject<App::Part*>("part");
46
QString activePartName = QString::fromLatin1(activePart->getNameInDocument());
47
return QString::fromLatin1("App.ActiveDocument.getObject('%1\')."
48
"addObject(App.ActiveDocument.ActiveObject)\n")
51
return QString::fromLatin1("# Object created at document root.");
55
//===========================================================================
57
//===========================================================================
58
DEF_STD_CMD_A(CmdPartCylinder)
60
CmdPartCylinder::CmdPartCylinder()
61
: Command("Part_Cylinder")
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";
72
void CmdPartCylinder::activated(int iMsg)
76
cmd = qApp->translate("CmdPartCylinder","Cylinder");
77
openCommand((const char*)cmd.toUtf8());
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());
86
runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
89
bool CmdPartCylinder::isActive()
91
if (getActiveGuiDocument())
97
//===========================================================================
99
//===========================================================================
100
DEF_STD_CMD_A(CmdPartBox)
102
CmdPartBox::CmdPartBox()
103
: Command("Part_Box")
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";
114
void CmdPartBox::activated(int iMsg)
118
cmd = qApp->translate("CmdPartBox","Cube");
119
openCommand((const char*)cmd.toUtf8());
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());
128
runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
131
bool CmdPartBox::isActive()
133
if (getActiveGuiDocument())
139
//===========================================================================
141
//===========================================================================
142
DEF_STD_CMD_A(CmdPartSphere)
144
CmdPartSphere::CmdPartSphere()
145
: Command("Part_Sphere")
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";
156
void CmdPartSphere::activated(int iMsg)
160
cmd = qApp->translate("CmdPartSphere","Sphere");
161
openCommand((const char*)cmd.toUtf8());
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());
170
runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
173
bool CmdPartSphere::isActive()
175
if (getActiveGuiDocument())
181
//===========================================================================
183
//===========================================================================
184
DEF_STD_CMD_A(CmdPartCone)
186
CmdPartCone::CmdPartCone()
187
: Command("Part_Cone")
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";
198
void CmdPartCone::activated(int iMsg)
202
cmd = qApp->translate("CmdPartCone","Cone");
203
openCommand((const char*)cmd.toUtf8());
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());
212
runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
215
bool CmdPartCone::isActive()
217
if (getActiveGuiDocument())
223
//===========================================================================
225
//===========================================================================
226
DEF_STD_CMD_A(CmdPartTorus)
228
CmdPartTorus::CmdPartTorus()
229
: Command("Part_Torus")
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";
240
void CmdPartTorus::activated(int iMsg)
244
cmd = qApp->translate("CmdPartTorus","Torus");
245
openCommand((const char*)cmd.toUtf8());
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());
254
runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
257
bool CmdPartTorus::isActive()
259
if (getActiveGuiDocument())
266
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
268
void CreateParamPartCommands()
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());