Debian Codegraph @

src/Gui/ViewProviderPoint.cpp

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /****************************************************************************
3 * *
4 * Copyright (c) 2024 Ondsel (PL Boyer) <[email protected]> *
5 * *
6 * This file is part of FreeCAD. *
7 * *
8 * FreeCAD is free software: you can redistribute it and/or modify it *
9 * under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation, either version 2.1 of the *
11 * License, or (at your option) any later version. *
12 * *
13 * FreeCAD is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with FreeCAD. If not, see *
20 * <https://www.gnu.org/licenses/>. *
21 * *
22 ***************************************************************************/
23
24
25 #include <Inventor/nodes/SoSphere.h>
26 #include <Inventor/nodes/SoCoordinate3.h>
27 #include <Inventor/nodes/SoIndexedLineSet.h>
28 #include <Inventor/nodes/SoPickStyle.h>
29 #include <Inventor/nodes/SoSeparator.h>
30 #include <Inventor/nodes/SoTranslation.h>
31
32
33 #include "ViewProviderPoint.h"
34 #include "ViewProviderCoordinateSystem.h"
35
36 using namespace Gui;
37
38 PROPERTY_SOURCE(Gui::ViewProviderPoint, Gui::ViewProviderDatum)
39
40 ViewProviderPoint::ViewProviderPoint()
41 {
42 sPixmap = "Std_Point"; // Set the icon for the point
43 }
44
45 ViewProviderPoint::~ViewProviderPoint() = default;
46
47 void ViewProviderPoint::attach(App::DocumentObject* obj)
48 {
49 ViewProviderDatum::attach(obj);
50
51 // The coordinates for the point (single vertex at the origin)
52 static const SbVec3f point = SbVec3f(0, 0, 0);
53
54 SoSeparator* sep = getDatumRoot();
55
56 auto pCoords = new SoCoordinate3();
57 pCoords->point.setNum(1);
58 pCoords->point.setValue(point);
59 sep->addChild(pCoords);
60
61 static const float size = App::GetApplication()
62 .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View")
63 ->GetFloat("DatumPointSize", 2.5);
64 auto sphere = new SoSphere();
65 sphere->radius.setValue(size);
66 sep->addChild(sphere);
67
68 // Add pick style to define how the point can be selected
69 auto ps = new SoPickStyle();
70 ps->style.setValue(SoPickStyle::BOUNDING_BOX);
71 sep->addChild(ps);
72 }