FreeCAD

Форк
0
/
ViewProviderPlane.cpp 
118 строк · 4.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2012 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *   Copyright (c) 2015 Alexander Golubev (Fat-Zer) <fatzer2@gmail.com>    *
4
 *                                                                         *
5
 *   This file is part of the FreeCAD CAx development system.              *
6
 *                                                                         *
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.      *
11
 *                                                                         *
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.                  *
16
 *                                                                         *
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                                *
21
 *                                                                         *
22
 ***************************************************************************/
23

24
#include "PreCompiled.h"
25

26
#ifndef _PreComp_
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>
37
#endif
38

39
#include "ViewProviderPlane.h"
40
#include "ViewProviderOrigin.h"
41

42

43
using namespace Gui;
44

45
PROPERTY_SOURCE(Gui::ViewProviderPlane, Gui::ViewProviderOriginFeature)
46

47

48
ViewProviderPlane::ViewProviderPlane()
49
{
50
    sPixmap = "Std_Plane";
51
}
52

53
ViewProviderPlane::~ViewProviderPlane() = default;
54

55
void ViewProviderPlane::attach ( App::DocumentObject *obj ) {
56
    ViewProviderOriginFeature::attach ( obj );
57
    static const float size = ViewProviderOrigin::defaultSize ();
58

59
    static const SbVec3f verts[4] = {
60
        SbVec3f(size,size,0),   SbVec3f(size,-size,0),
61
        SbVec3f(-size,-size,0), SbVec3f(-size,size,0),
62
    };
63

64
    // indexes used to create the edges
65
    static const int32_t lines[6] = { 0, 1, 2, 3, 0, -1 };
66

67
    SoSeparator *sep = getOriginFeatureRoot ();
68

69
    auto pCoords = new SoCoordinate3 ();
70
    pCoords->point.setNum (4);
71
    pCoords->point.setValues ( 0, 4, verts );
72
    sep->addChild ( pCoords );
73

74
    auto pLines  = new SoIndexedLineSet ();
75
    pLines->coordIndex.setNum(6);
76
    pLines->coordIndex.setValues(0, 6, lines);
77
    sep->addChild ( pLines );
78

79
    // add semi transparent face
80
    auto faceSeparator = new SoSeparator();
81
    sep->addChild(faceSeparator);
82

83
    auto material = new SoMaterial();
84
    material->transparency.setValue(0.95f);
85
    SbColor color;
86
    float alpha = 0.0f;
87
    color.setPackedValue(ViewProviderOrigin::defaultColor, alpha);
88
    material->ambientColor.setValue(color);
89
    material->diffuseColor.setValue(color);
90
    faceSeparator->addChild(material);
91

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);
97

98
    // disable picking
99
    auto pickStyle = new SoPickStyle();
100
    pickStyle->style = SoPickStyle::UNPICKABLE;
101
    faceSeparator->addChild(pickStyle);
102

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);
108

109
    auto textTranslation = new SoTranslation ();
110
    textTranslation->translation.setValue ( SbVec3f ( -size * 49. / 50., size * 9./10., 0 ) );
111
    sep->addChild ( textTranslation );
112

113
    auto ps = new SoPickStyle();
114
    ps->style.setValue(SoPickStyle::BOUNDING_BOX);
115
    sep->addChild(ps);
116

117
    sep->addChild ( getLabel () );
118
}
119

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

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

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

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