1
/***************************************************************************
2
* Copyright (c) 2012 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
***************************************************************************/
23
#include "PreCompiled.h"
27
# include <Inventor/SoPickedPoint.h>
28
# include <Inventor/nodes/SoDrawStyle.h>
31
#include <App/DocumentObject.h>
33
#include "ViewProviderPlacement.h"
34
#include "SoFCSelection.h"
35
#include "SoFCUnifiedSelection.h"
40
PROPERTY_SOURCE(Gui::ViewProviderPlacement, Gui::ViewProviderGeometryObject)
42
ViewProviderPlacement::ViewProviderPlacement()
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));
52
sPixmap = "Std_Placement";
54
OnTopWhenSelected.setValue(1);
57
ViewProviderPlacement::~ViewProviderPlacement() = default;
59
void ViewProviderPlacement::onChanged(const App::Property* prop)
61
ViewProviderGeometryObject::onChanged(prop);
64
std::vector<std::string> ViewProviderPlacement::getDisplayModes() const
67
std::vector<std::string> StrList;
68
StrList.emplace_back("Base");
72
void ViewProviderPlacement::setDisplayMode(const char* ModeName)
74
if (strcmp(ModeName, "Base") == 0)
75
setDisplayMaskMode("Base");
76
ViewProviderGeometryObject::setDisplayMode(ModeName);
79
static std::unique_ptr<AxisOrigin> Axis;
81
void ViewProviderPlacement::attach(App::DocumentObject* pcObject)
83
ViewProviderGeometryObject::attach(pcObject);
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);
96
addDisplayMaskMode(Axis->getNode(), "Base");
99
void ViewProviderPlacement::updateData(const App::Property* prop)
101
ViewProviderGeometryObject::updateData(prop);
104
bool ViewProviderPlacement::getElementPicked(const SoPickedPoint *pp, std::string &subname) const {
107
return Axis->getElementPicked(pp,subname);
110
bool ViewProviderPlacement::getDetailPath(
111
const char *subname, SoFullPath *pPath, bool append, SoDetail *&det) const
115
int length = pPath->getLength();
117
pPath->append(pcRoot);
118
pPath->append(pcModeSwitch);
120
if(!Axis->getDetailPath(subname,pPath,det)) {
121
pPath->truncate(length);
127
bool ViewProviderPlacement::isSelectable() const
131
// ----------------------------------------------------------------------------
133
// Python feature -----------------------------------------------------------------------
137
PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderPlacementPython, Gui::ViewProviderPlacement)
140
// explicit template instantiation
141
template class GuiExport ViewProviderFeaturePythonT<ViewProviderPlacement>;