| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2012 Jürgen Riegel <[email protected]> * |
| 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 <sstream> |
| 25 |
#include <Inventor/SoPickedPoint.h> |
| 26 |
#include <Inventor/nodes/SoDrawStyle.h> |
| 27 |
|
| 28 |
|
| 29 |
#include <App/DocumentObject.h> |
| 30 |
|
| 31 |
#include "ViewProviderPlacement.h" |
| 32 |
#include "SoFCSelection.h" |
| 33 |
#include "SoFCUnifiedSelection.h" |
| 34 |
|
| 35 |
|
| 36 |
using namespace Gui; |
| 37 |
|
| 38 |
PROPERTY_SOURCE(Gui::ViewProviderPlacement, Gui::ViewProviderGeometryObject) |
| 39 |
|
| 40 |
ViewProviderPlacement::ViewProviderPlacement() |
| 41 |
{ |
| 42 |
// Change root node to SoFCSelectionRoot because we share the same |
| 43 |
// AxisOrigin node for all instances of Placement |
| 44 |
auto newRoot = new SoFCSelectionRoot(true); |
| 45 |
for (int i = 0; i < pcRoot->getNumChildren(); ++i) { |
| 46 |
newRoot->addChild(pcRoot->getChild(i)); |
| 47 |
} |
| 48 |
pcRoot->unref(); |
| 49 |
pcRoot = newRoot; |
| 50 |
pcRoot->ref(); |
| 51 |
sPixmap = "Std_Placement"; |
| 52 |
|
| 53 |
OnTopWhenSelected.setValue(1); |
| 54 |
} |
| 55 |
|
| 56 |
ViewProviderPlacement::~ViewProviderPlacement() = default; |
| 57 |
|
| 58 |
void ViewProviderPlacement::onChanged(const App::Property* prop) |
| 59 |
{ |
| 60 |
ViewProviderGeometryObject::onChanged(prop); |
| 61 |
} |
| 62 |
|
| 63 |
std::vector<std::string> ViewProviderPlacement::getDisplayModes() const |
| 64 |
{ |
| 65 |
// add modes |
| 66 |
std::vector<std::string> StrList; |
| 67 |
StrList.emplace_back("Base"); |
| 68 |
return StrList; |
| 69 |
} |
| 70 |
|
| 71 |
void ViewProviderPlacement::setDisplayMode(const char* ModeName) |
| 72 |
{ |
| 73 |
if (strcmp(ModeName, "Base") == 0) { |
| 74 |
setDisplayMaskMode("Base"); |
| 75 |
} |
| 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 |
{ |
| 106 |
if (!Axis) { |
| 107 |
return false; |
| 108 |
} |
| 109 |
return Axis->getElementPicked(pp, subname); |
| 110 |
} |
| 111 |
|
| 112 |
bool ViewProviderPlacement::getDetailPath( |
| 113 |
const char* subname, |
| 114 |
SoFullPath* pPath, |
| 115 |
bool append, |
| 116 |
SoDetail*& det |
| 117 |
) const |
| 118 |
{ |
| 119 |
if (!Axis) { |
| 120 |
return false; |
| 121 |
} |
| 122 |
int length = pPath->getLength(); |
| 123 |
if (append) { |
| 124 |
pPath->append(pcRoot); |
| 125 |
pPath->append(pcModeSwitch); |
| 126 |
} |
| 127 |
if (!Axis->getDetailPath(subname, pPath, det)) { |
| 128 |
pPath->truncate(length); |
| 129 |
return false; |
| 130 |
} |
| 131 |
return true; |
| 132 |
} |
| 133 |
|
| 134 |
bool ViewProviderPlacement::isSelectable() const |
| 135 |
{ |
| 136 |
return true; |
| 137 |
} |
| 138 |
// ---------------------------------------------------------------------------- |
| 139 |
|
| 140 |
// Python feature ----------------------------------------------------------------------- |
| 141 |
|
| 142 |
namespace Gui |
| 143 |
{ |
| 144 |
/// @cond DOXERR |
| 145 |
PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderPlacementPython, Gui::ViewProviderPlacement) |
| 146 |
/// @endcond |
| 147 |
|
| 148 |
// explicit template instantiation |
| 149 |
template class GuiExport ViewProviderFeaturePythonT<ViewProviderPlacement>; |
| 150 |
} // namespace Gui |