1
/***************************************************************************
2
* Copyright (c) 2012 Jürgen Riegel <juergen.riegel@web.de> *
3
* Copyright (c) 2015 Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> *
5
* This file is part of the FreeCAD CAx development system. *
7
* This library is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU Library General Public *
9
* License as published by the Free Software Foundation; either *
10
* version 2 of the License, or (at your option) any later version. *
12
* This library is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU Library General Public License for more details. *
17
* You should have received a copy of the GNU Library General Public *
18
* License along with this library; see the file COPYING.LIB. If not, *
19
* write to the Free Software Foundation, Inc., 59 Temple Place, *
20
* Suite 330, Boston, MA 02111-1307, USA *
22
***************************************************************************/
24
#include "PreCompiled.h"
27
# include <Inventor/nodes/SoAsciiText.h>
28
# include <Inventor/nodes/SoCoordinate3.h>
29
# include <Inventor/nodes/SoFaceSet.h>
30
# include <Inventor/nodes/SoIndexedLineSet.h>
31
# include <Inventor/nodes/SoMaterial.h>
32
# include <Inventor/nodes/SoPickStyle.h>
33
# include <Inventor/nodes/SoSeparator.h>
34
# include <Inventor/nodes/SoShapeHints.h>
35
# include <Inventor/nodes/SoTranslation.h>
36
# include <Inventor/SbColor.h>
39
#include "ViewProviderPlane.h"
40
#include "ViewProviderOrigin.h"
45
PROPERTY_SOURCE(Gui::ViewProviderPlane, Gui::ViewProviderOriginFeature)
48
ViewProviderPlane::ViewProviderPlane()
50
sPixmap = "Std_Plane";
53
ViewProviderPlane::~ViewProviderPlane() = default;
55
void ViewProviderPlane::attach ( App::DocumentObject *obj ) {
56
ViewProviderOriginFeature::attach ( obj );
57
static const float size = ViewProviderOrigin::defaultSize ();
59
static const SbVec3f verts[4] = {
60
SbVec3f(size,size,0), SbVec3f(size,-size,0),
61
SbVec3f(-size,-size,0), SbVec3f(-size,size,0),
64
// indexes used to create the edges
65
static const int32_t lines[6] = { 0, 1, 2, 3, 0, -1 };
67
SoSeparator *sep = getOriginFeatureRoot ();
69
auto pCoords = new SoCoordinate3 ();
70
pCoords->point.setNum (4);
71
pCoords->point.setValues ( 0, 4, verts );
72
sep->addChild ( pCoords );
74
auto pLines = new SoIndexedLineSet ();
75
pLines->coordIndex.setNum(6);
76
pLines->coordIndex.setValues(0, 6, lines);
77
sep->addChild ( pLines );
79
// add semi transparent face
80
auto faceSeparator = new SoSeparator();
81
sep->addChild(faceSeparator);
83
auto material = new SoMaterial();
84
material->transparency.setValue(0.95f);
87
color.setPackedValue(ViewProviderOrigin::defaultColor, alpha);
88
material->ambientColor.setValue(color);
89
material->diffuseColor.setValue(color);
90
faceSeparator->addChild(material);
92
// disable backface culling and render with two-sided lighting
93
auto shapeHints = new SoShapeHints();
94
shapeHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
95
shapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
96
faceSeparator->addChild(shapeHints);
99
auto pickStyle = new SoPickStyle();
100
pickStyle->style = SoPickStyle::UNPICKABLE;
101
faceSeparator->addChild(pickStyle);
103
auto faceSet = new SoFaceSet();
104
auto vertexProperty = new SoVertexProperty();
105
vertexProperty->vertex.setValues(0, 4, verts);
106
faceSet->vertexProperty.setValue(vertexProperty);
107
faceSeparator->addChild(faceSet);
109
auto textTranslation = new SoTranslation ();
110
textTranslation->translation.setValue ( SbVec3f ( -size * 49. / 50., size * 9./10., 0 ) );
111
sep->addChild ( textTranslation );
113
auto ps = new SoPickStyle();
114
ps->style.setValue(SoPickStyle::BOUNDING_BOX);
117
sep->addChild ( getLabel () );