Debian Codegraph @

plugins/core/Standard/qMPlane/src/ccItemTree.cpp

raw
1 //##########################################################################
2 //# #
3 //# CLOUDCOMPARE PLUGIN: qMPlane #
4 //# #
5 //# This program is free software; you can redistribute it and/or modify #
6 //# it under the terms of the GNU General Public License as published by #
7 //# the Free Software Foundation; version 2 of the License. #
8 //# #
9 //# This program is distributed in the hope that it will be useful, #
10 //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
11 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12 //# GNU General Public License for more details. #
13 //# #
14 //# COPYRIGHT: AIT Austrian Institute of Technology GmbH #
15 //# #
16 //##########################################################################
17
18
19 // Local dependencies
20 #include "ccItemTree.h"
21 #include "ccMPlaneErrors.h"
22
23
24 bool compareObjects(QString name, ccHObject *object, CC_ITEM_TREE::CC_TYPES_MAP type) {
25 if (!object) {
26 return false;
27 }
28 if (object->isKindOf(type) && (name == nullptr || name != nullptr && (object->getName() == name))) {
29 return true;
30 }
31 return false;
32 }
33
34 ccHObject* CC_ITEM_TREE::findItemInHierarchy(ccHObject *root, CC_TYPES_MAP itemType, QString itemName) {
35 if (!root) {
36 throw MplaneInvalidArgument("root is not allowed to be nullptr");
37 }
38 auto childrenNumber = root->getChildrenNumber();
39 for (unsigned int i = 0; i < childrenNumber; ++i) {
40 ccHObject *child = root->getChild(i);
41 if (compareObjects(itemName, child, itemType)) {
42 return child;
43 }
44 if (child->getChildrenNumber() > 0) {
45 ccHObject *subChild = findItemInHierarchy(child, itemType, itemName);
46 if (compareObjects(itemName, subChild, itemType)) {
47 return subChild;
48 }
49 }
50 }
51 return nullptr;
52 }
53
54 ccHObject* CC_ITEM_TREE::findOrCreateContainer(ccHObject *parent, const QString& containerName, ccMainAppInterface *app) {
55 if (!parent) {
56 throw MplaneInvalidArgument("parent is not allowed to be nullptr");
57 }
58 if (!app) {
59 throw MplaneInvalidArgument("app is not allowed to be nullptr");
60 }
61 if (containerName.isEmpty()) {
62 throw MplaneInvalidArgument("containerName is not allowed to be empty");
63 }
64 ccHObject *container = CC_ITEM_TREE::findItemInHierarchy(parent, CC_ITEM_TREE::CC_TYPES_MAP::HIERARCHY_OBJECT, containerName);
65 if (container) {
66 return container;
67 }
68 container = new ccHObject(containerName);
69 parent->addChild(container);
70 app->addToDB(container, false, true, false, false);
71
72 return container;
73 }
74
75 cc2DLabel* CC_ITEM_TREE::createPointLabel2D(QString labelText, ccPointCloud *sourceCloud, QPoint clickPoint, unsigned int pointIdx) {
76 if (labelText.isEmpty()) {
77 throw MplaneInvalidArgument("labelText is not allowed to be empty");
78 }
79 if (!sourceCloud) {
80 throw MplaneInvalidArgument("sourceCloud is not allowed to be nullptr");
81 }
82 cc2DLabel* newLabel = nullptr;
83 ccGenericGLDisplay* display = sourceCloud->getDisplay();
84 if (display) {
85 newLabel = new cc2DLabel();
86 newLabel->addPickedPoint(sourceCloud, pointIdx);
87 newLabel->setName(labelText);
88 newLabel->setVisible(true);
89 newLabel->setDisplayedIn2D(false);
90 newLabel->displayPointLegend(true);
91 newLabel->setCollapsed(true);
92 newLabel->setDisplay(display);
93
94 QSize size = display->getScreenSize();
95 newLabel->setPosition(static_cast<float>(clickPoint.x() + 20) / size.width(),
96 static_cast<float>(clickPoint.y() + 20) / size.height());
97 display->redraw();
98 }
99 return newLabel;
100 }