FreeCAD
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/SoIndexedLineSet.h>30# include <Inventor/nodes/SoPickStyle.h>31# include <Inventor/nodes/SoSeparator.h>32# include <Inventor/nodes/SoTranslation.h>33#endif34
35#include "ViewProviderLine.h"36#include "ViewProviderOrigin.h"37
38
39using namespace Gui;40
41PROPERTY_SOURCE(Gui::ViewProviderLine, Gui::ViewProviderOriginFeature)42
43
44ViewProviderLine::ViewProviderLine()45{
46sPixmap = "Std_Axis";47}
48
49ViewProviderLine::~ViewProviderLine() = default;50
51void ViewProviderLine::attach ( App::DocumentObject *obj ) {52ViewProviderOriginFeature::attach ( obj );53
54static const float size = ViewProviderOrigin::defaultSize ();55
56static const SbVec3f verts[2] = { SbVec3f(size, 0, 0), SbVec3f ( -size, 0, 0 ) };57
58// indexes used to create the edges59static const int32_t lines[4] = { 0, 1, -1 };60
61SoSeparator *sep = getOriginFeatureRoot ();62
63auto pCoords = new SoCoordinate3 ();64pCoords->point.setNum (2);65pCoords->point.setValues ( 0, 2, verts );66sep->addChild ( pCoords );67
68auto pLines = new SoIndexedLineSet ();69pLines->coordIndex.setNum(3);70pLines->coordIndex.setValues(0, 3, lines);71sep->addChild ( pLines );72
73auto textTranslation = new SoTranslation ();74textTranslation->translation.setValue ( SbVec3f ( -size * 49. / 50., size / 30., 0 ) );75sep->addChild ( textTranslation );76
77auto ps = new SoPickStyle();78ps->style.setValue(SoPickStyle::BOUNDING_BOX);79sep->addChild(ps);80
81sep->addChild ( getLabel () );82}
83