FreeCAD

Форк
0
/
CommandStructure.cpp 
139 строк · 5.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2017 Stefan Tröger <stefantroeger@gmx.net>              *
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
#ifndef _PreComp_
26
#include <QApplication>
27
#endif
28

29
#include "App/Document.h"
30

31
#include "Command.h"
32
#include "ActiveObjectList.h"
33
#include "Application.h"
34
#include "Document.h"
35
#include "ViewProviderDocumentObject.h"
36

37

38
using namespace Gui;
39

40
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41

42
//===========================================================================
43
// Std_Part
44
//===========================================================================
45
DEF_STD_CMD_A(StdCmdPart)
46

47
StdCmdPart::StdCmdPart()
48
  : Command("Std_Part")
49
{
50
    sGroup        = "Structure";
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";
58
}
59

60
void StdCmdPart::activated(int iMsg)
61
{
62
    Q_UNUSED(iMsg);
63

64
    openCommand(QT_TRANSLATE_NOOP("Command", "Add a part"));
65
    std::string FeatName = getUniqueObjectName("Part");
66

67
    std::string PartName;
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());
76

77
    updateActive();
78
}
79

80
bool StdCmdPart::isActive()
81
{
82
    return hasActiveDocument();
83
}
84

85
//===========================================================================
86
// Std_Group
87
//===========================================================================
88
DEF_STD_CMD_A(StdCmdGroup)
89

90
StdCmdGroup::StdCmdGroup()
91
  : Command("Std_Group")
92
{
93
    sGroup        = "Structure";
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;
100
    sPixmap       = "folder";
101
}
102

103
void StdCmdGroup::activated(int iMsg)
104
{
105
    Q_UNUSED(iMsg);
106

107
    openCommand(QT_TRANSLATE_NOOP("Command", "Add a group"));
108

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());
115
    commitCommand();
116

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));
122
}
123

124
bool StdCmdGroup::isActive()
125
{
126
    return hasActiveDocument();
127
}
128

129
namespace Gui {
130

131
void CreateStructureCommands()
132
{
133
    CommandManager &rcCmdMgr = Application::Instance->commandManager();
134

135
    rcCmdMgr.addCommand(new StdCmdPart());
136
    rcCmdMgr.addCommand(new StdCmdGroup());
137
}
138

139
} // namespace Gui
140

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

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

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

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