FreeCAD

Форк
0
/
ViewProviderPlacement.cpp 
142 строки · 4.7 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2012 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
#include "PreCompiled.h"
24

25
#ifndef _PreComp_
26
# include <sstream>
27
# include <Inventor/SoPickedPoint.h>
28
# include <Inventor/nodes/SoDrawStyle.h>
29
#endif
30

31
#include <App/DocumentObject.h>
32

33
#include "ViewProviderPlacement.h"
34
#include "SoFCSelection.h"
35
#include "SoFCUnifiedSelection.h"
36

37

38
using namespace Gui;
39

40
PROPERTY_SOURCE(Gui::ViewProviderPlacement, Gui::ViewProviderGeometryObject)
41

42
ViewProviderPlacement::ViewProviderPlacement()
43
{
44
    // Change root node to SoFCSelectionRoot because we share the same
45
    // AxisOrigin node for all instances of Placement
46
    auto newRoot = new SoFCSelectionRoot(true);
47
    for(int i=0;i<pcRoot->getNumChildren();++i)
48
        newRoot->addChild(pcRoot->getChild(i));
49
    pcRoot->unref();
50
    pcRoot = newRoot;
51
    pcRoot->ref();
52
    sPixmap = "Std_Placement";
53

54
    OnTopWhenSelected.setValue(1);
55
}
56

57
ViewProviderPlacement::~ViewProviderPlacement() = default;
58

59
void ViewProviderPlacement::onChanged(const App::Property* prop)
60
{
61
        ViewProviderGeometryObject::onChanged(prop);
62
}
63

64
std::vector<std::string> ViewProviderPlacement::getDisplayModes() const
65
{
66
    // add modes
67
    std::vector<std::string> StrList;
68
    StrList.emplace_back("Base");
69
    return StrList;
70
}
71

72
void ViewProviderPlacement::setDisplayMode(const char* ModeName)
73
{
74
    if (strcmp(ModeName, "Base") == 0)
75
        setDisplayMaskMode("Base");
76
    ViewProviderGeometryObject::setDisplayMode(ModeName);
77
}
78

79
static std::unique_ptr<AxisOrigin> Axis;
80

81
void ViewProviderPlacement::attach(App::DocumentObject* pcObject)
82
{
83
    ViewProviderGeometryObject::attach(pcObject);
84
    if(!Axis) {
85
        Axis = std::make_unique<AxisOrigin>();
86
        std::map<std::string,std::string> labels;
87
        labels["O"] = "Origin";
88
        labels["X"] = "X-Axis";
89
        labels["Y"] = "Y-Axis";
90
        labels["Z"] = "Z-Axis";
91
        labels["XY"] = "XY-Plane";
92
        labels["XZ"] = "XZ-Plane";
93
        labels["YZ"] = "YZ-Plane";
94
        Axis->setLabels(labels);
95
    }
96
    addDisplayMaskMode(Axis->getNode(), "Base");
97
}
98

99
void ViewProviderPlacement::updateData(const App::Property* prop)
100
{
101
    ViewProviderGeometryObject::updateData(prop);
102
}
103

104
bool ViewProviderPlacement::getElementPicked(const SoPickedPoint *pp, std::string &subname) const {
105
    if(!Axis)
106
        return false;
107
    return Axis->getElementPicked(pp,subname);
108
}
109

110
bool ViewProviderPlacement::getDetailPath(
111
            const char *subname, SoFullPath *pPath, bool append, SoDetail *&det) const
112
{
113
    if(!Axis)
114
        return false;
115
    int length = pPath->getLength();
116
    if(append) {
117
        pPath->append(pcRoot);
118
        pPath->append(pcModeSwitch);
119
    }
120
    if(!Axis->getDetailPath(subname,pPath,det)) {
121
        pPath->truncate(length);
122
        return false;
123
    }
124
    return true;
125
}
126

127
bool ViewProviderPlacement::isSelectable() const
128
{
129
    return true;
130
}
131
// ----------------------------------------------------------------------------
132

133
// Python feature -----------------------------------------------------------------------
134

135
namespace Gui {
136
/// @cond DOXERR
137
PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderPlacementPython, Gui::ViewProviderPlacement)
138
/// @endcond
139

140
// explicit template instantiation
141
template class GuiExport ViewProviderFeaturePythonT<ViewProviderPlacement>;
142
}
143

144

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

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

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

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