| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2015 Alexander Golubev (Fat-Zer) <[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 |
#include <Inventor/nodes/SoAnnotation.h> |
| 24 |
#include <Inventor/nodes/SoDrawStyle.h> |
| 25 |
#include <Inventor/nodes/SoFont.h> |
| 26 |
#include <Inventor/nodes/SoMaterial.h> |
| 27 |
#include <Inventor/nodes/SoMaterialBinding.h> |
| 28 |
#include <Inventor/nodes/SoScale.h> |
| 29 |
#include <Inventor/nodes/SoSeparator.h> |
| 30 |
|
| 31 |
#include <App/Document.h> |
| 32 |
#include <App/Datums.h> |
| 33 |
#include <App/Origin.h> |
| 34 |
|
| 35 |
#include "ViewProviderDatum.h" |
| 36 |
#include "Inventor/SoAxisCrossKit.h" |
| 37 |
#include "SoFCSelection.h" |
| 38 |
#include "ViewProviderCoordinateSystem.h" |
| 39 |
|
| 40 |
#include <Inventor/So3DAnnotation.h> |
| 41 |
|
| 42 |
|
| 43 |
using namespace Gui; |
| 44 |
|
| 45 |
PROPERTY_SOURCE(Gui::ViewProviderDatum, Gui::ViewProviderGeometryObject) |
| 46 |
|
| 47 |
ViewProviderDatum::ViewProviderDatum() |
| 48 |
{ |
| 49 |
// Set default color for origin (light-blue) |
| 50 |
ShapeAppearance.setDiffuseColor(ViewProviderCoordinateSystem::defaultColor); |
| 51 |
Transparency.setValue(0); |
| 52 |
BoundingBox.setStatus(App::Property::Hidden, true); // Hide Boundingbox from the user due to it |
| 53 |
// doesn't make sense |
| 54 |
|
| 55 |
// Create node for scaling the origin |
| 56 |
soScale = new SoShapeScale(); |
| 57 |
|
| 58 |
// Create the separator filled by inherited classes |
| 59 |
pRoot = new SoSeparator(); |
| 60 |
pRoot->ref(); |
| 61 |
|
| 62 |
lineThickness = 2.0; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
ViewProviderDatum::~ViewProviderDatum() |
| 67 |
{ |
| 68 |
pRoot->unref(); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
void ViewProviderDatum::attach(App::DocumentObject* pcObject) |
| 73 |
{ |
| 74 |
ViewProviderGeometryObject::attach(pcObject); |
| 75 |
|
| 76 |
|
| 77 |
// Create an external separator |
| 78 |
auto sep = new SoSeparator(); |
| 79 |
|
| 80 |
// Add material from the base class |
| 81 |
sep->addChild(pcShapeMaterial); |
| 82 |
|
| 83 |
// Bind same material to all part |
| 84 |
auto matBinding = new SoMaterialBinding; |
| 85 |
matBinding->value = SoMaterialBinding::OVERALL; |
| 86 |
sep->addChild(matBinding); |
| 87 |
|
| 88 |
// Setup font size |
| 89 |
auto font = new SoFont(); |
| 90 |
static const float size = App::GetApplication() |
| 91 |
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") |
| 92 |
->GetFloat("DatumFontSize", 15.0); |
| 93 |
font->size.setValue(size); |
| 94 |
sep->addChild(font); |
| 95 |
|
| 96 |
// Create the selection node |
| 97 |
auto highlight = new SoFCSelection(); |
| 98 |
highlight->applySettings(); |
| 99 |
if (!Selectable.getValue()) { |
| 100 |
highlight->selectionMode = Gui::SoFCSelection::SEL_OFF; |
| 101 |
} |
| 102 |
highlight->objectName = getObject()->getNameInDocument(); |
| 103 |
highlight->documentName = getObject()->getDocument()->getName(); |
| 104 |
highlight->style = SoFCSelection::EMISSIVE_DIFFUSE; |
| 105 |
|
| 106 |
// Visible features |
| 107 |
auto visible = new SoSeparator(); |
| 108 |
// Style for normal (visible) lines |
| 109 |
auto style = new SoDrawStyle(); |
| 110 |
style->lineWidth = lineThickness; |
| 111 |
visible->addChild(style); |
| 112 |
|
| 113 |
// Visible lines |
| 114 |
visible->addChild(pRoot); |
| 115 |
|
| 116 |
// Hidden features |
| 117 |
auto hidden = new So3DAnnotation(); |
| 118 |
|
| 119 |
// Style for hidden lines |
| 120 |
style = new SoDrawStyle(); |
| 121 |
style->lineWidth = lineThickness; |
| 122 |
style->linePattern.setValue(0xFF00); // (dash-skip) |
| 123 |
hidden->addChild(style); |
| 124 |
|
| 125 |
// Hidden lines |
| 126 |
hidden->addChild(pRoot); |
| 127 |
|
| 128 |
visible->addChild(hidden); |
| 129 |
|
| 130 |
sep->addChild(visible); |
| 131 |
|
| 132 |
soScale->setPart("shape", sep); |
| 133 |
resetTemporarySize(); |
| 134 |
|
| 135 |
highlight->addChild(soScale); |
| 136 |
|
| 137 |
addDisplayMaskMode(highlight, "Base"); |
| 138 |
} |
| 139 |
|
| 140 |
void ViewProviderDatum::setTemporaryScale(double factor) |
| 141 |
{ |
| 142 |
soScale->scaleFactor = soScale->scaleFactor.getValue() * factor; |
| 143 |
} |
| 144 |
|
| 145 |
void ViewProviderDatum::resetTemporarySize() |
| 146 |
{ |
| 147 |
float sz = App::GetApplication() |
| 148 |
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") |
| 149 |
->GetFloat("LocalCoordinateSystemSize", 1.0); // NOLINT |
| 150 |
|
| 151 |
soScale->scaleFactor = sz; |
| 152 |
} |
| 153 |
|
| 154 |
void ViewProviderDatum::onChanged(const App::Property* prop) |
| 155 |
{ |
| 156 |
ViewProviderGeometryObject::onChanged(prop); |
| 157 |
} |
| 158 |
|
| 159 |
std::vector<std::string> ViewProviderDatum::getDisplayModes() const |
| 160 |
{ |
| 161 |
// add modes |
| 162 |
std::vector<std::string> StrList; |
| 163 |
StrList.emplace_back("Base"); |
| 164 |
return StrList; |
| 165 |
} |
| 166 |
|
| 167 |
void ViewProviderDatum::setDisplayMode(const char* ModeName) |
| 168 |
{ |
| 169 |
if (strcmp(ModeName, "Base") == 0) { |
| 170 |
setDisplayMaskMode("Base"); |
| 171 |
} |
| 172 |
ViewProviderGeometryObject::setDisplayMode(ModeName); |
| 173 |
} |
| 174 |
|
| 175 |
bool ViewProviderDatum::onDelete(const std::vector<std::string>&) |
| 176 |
{ |
| 177 |
auto feat = static_cast<App::DatumElement*>(getObject()); |
| 178 |
// Forbid deletion if there is an origin this feature belongs to |
| 179 |
return !feat->getLCS(); |
| 180 |
} |