1
/***************************************************************************
2
* Copyright (c) 2017 Stefan Tröger <stefantroeger@gmx.net> *
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"
26
#include <QApplication>
29
#include "App/Document.h"
32
#include "ActiveObjectList.h"
33
#include "Application.h"
35
#include "ViewProviderDocumentObject.h"
40
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42
//===========================================================================
44
//===========================================================================
45
DEF_STD_CMD_A(StdCmdPart)
47
StdCmdPart::StdCmdPart()
51
sMenuText = QT_TR_NOOP("Create part");
52
sToolTipText = QT_TR_NOOP("A Part is a general purpose container to keep together a group of objects so that they "
53
"act as a unit in the 3D view. It is meant to arrange objects that have a Part "
54
"TopoShape, like Part Primitives, PartDesign Bodies, and other Parts.");
55
sWhatsThis = "Std_Part";
56
sStatusTip = sToolTipText;
57
sPixmap = "Geofeaturegroup";
60
void StdCmdPart::activated(int iMsg)
64
openCommand(QT_TRANSLATE_NOOP("Command", "Add a part"));
65
std::string FeatName = getUniqueObjectName("Part");
68
PartName = getUniqueObjectName("Part");
69
doCommand(Doc,"App.activeDocument().Tip = App.activeDocument().addObject('App::Part','%s')",PartName.c_str());
70
// TODO We really must set label ourselves? (2015-08-17, Fat-Zer)
71
doCommand(Doc,"App.activeDocument().%s.Label = '%s'", PartName.c_str(),
72
QObject::tr(PartName.c_str()).toUtf8().data());
73
doCommand(Gui::Command::Gui, "Gui.activateView('Gui::View3DInventor', True)\n"
74
"Gui.activeView().setActiveObject('%s', App.activeDocument().%s)",
75
PARTKEY, PartName.c_str());
80
bool StdCmdPart::isActive()
82
return hasActiveDocument();
85
//===========================================================================
87
//===========================================================================
88
DEF_STD_CMD_A(StdCmdGroup)
90
StdCmdGroup::StdCmdGroup()
91
: Command("Std_Group")
94
sMenuText = QT_TR_NOOP("Create group");
95
sToolTipText = QT_TR_NOOP("A Group is a general purpose container to group objects in the "
96
"Tree view, regardless of their data type. It is a simple folder to organize "
97
"the objects in a model.");
98
sWhatsThis = "Std_Group";
99
sStatusTip = sToolTipText;
103
void StdCmdGroup::activated(int iMsg)
107
openCommand(QT_TRANSLATE_NOOP("Command", "Add a group"));
109
std::string GroupName;
110
GroupName = getUniqueObjectName("Group");
111
QString label = QApplication::translate("Std_Group", "Group");
112
doCommand(Doc,"App.activeDocument().Tip = App.activeDocument().addObject('App::DocumentObjectGroup','%s')",GroupName.c_str());
113
doCommand(Doc,"App.activeDocument().%s.Label = '%s'", GroupName.c_str(),
114
label.toUtf8().data());
117
Gui::Document* gui = Application::Instance->activeDocument();
118
App::Document* app = gui->getDocument();
119
ViewProvider* vp = gui->getViewProvider(app->getActiveObject());
120
if (vp && vp->isDerivedFrom<ViewProviderDocumentObject>())
121
gui->signalScrollToObject(*static_cast<ViewProviderDocumentObject*>(vp));
124
bool StdCmdGroup::isActive()
126
return hasActiveDocument();
131
void CreateStructureCommands()
133
CommandManager &rcCmdMgr = Application::Instance->commandManager();
135
rcCmdMgr.addCommand(new StdCmdPart());
136
rcCmdMgr.addCommand(new StdCmdGroup());