File size: 4,111 Bytes
a5ffdcd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | /*******************************************************************************
*
This file is part of the LibreCAD project, a 2D CAD program
Copyright (C) 2025 LibreCAD.org
Copyright (C) 2025 sand1024
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
******************************************************************************/
#include "lc_ucslist.h"
LC_UCSList::LC_UCSList() {
m_ucsList.append(m_wcs.get());
setModified(false);
}
void LC_UCSList::clear() {
m_ucsList.clear();
m_ucsList.append(m_wcs.get());
setModified(true);
}
void LC_UCSList::add(LC_UCS *ucs) {
if (ucs == nullptr) {
return;
}
// check if layer already exists:
LC_UCS *v = find(ucs->getName());
if (v == nullptr) {
m_ucsList.append(ucs);
}
}
void LC_UCSList::addNew(LC_UCS *ucs) {
if (ucs == nullptr) {
return;
}
// check if layer already exists:
LC_UCS *v = find(ucs->getName());
if (v == nullptr) {
m_ucsList.append(ucs);
setModified(true);
}
}
void LC_UCSList::remove(LC_UCS *ucs) {
if (ucs->isUCS()) {
m_ucsList.removeOne(ucs);
setModified(true);
delete ucs;
}
}
void LC_UCSList::remove(const QString &name) {
LC_UCS *v = find(name);
if (v !=nullptr) {
remove(v);
}
}
void LC_UCSList::rename(LC_UCS *ucs, const QString &newName) {
if (ucs->isUCS()) {
ucs->setName(newName);
ucs->setTemporary(false);
setModified(true);
}
}
void LC_UCSList::edited([[maybe_unused]]LC_UCS *ucs) {
setModified(true);
}
LC_UCS *LC_UCSList::find(const QString &name) const {
for (auto v: m_ucsList){
if (v->getName() == name){
return v;
}
}
return nullptr;
}
int LC_UCSList::getIndex(const QString &name) const
{
int result = -1;
for (int i = 0; i < m_ucsList.size(); i++) {
LC_UCS *v = m_ucsList.at(i);
if (v->getName() == name) {
result = i;
break;
}
}
return result;
}
int LC_UCSList::getIndex(LC_UCS *ucs) const {
return m_ucsList.indexOf(ucs);
}
void LC_UCSList::setModified(bool m) {
m_modified = m;
fireModified(m);
}
LC_UCS *LC_UCSList::tryAddUCS(LC_UCS *candidate) {
if (candidate == nullptr) {
return nullptr;
}
LC_UCS *existingUCS = findExisting(candidate);
LC_UCS* result;
if (existingUCS == nullptr){
m_ucsList.append(candidate);
setModified(true);
result = candidate;
}
else{
result = existingUCS;
}
return result;
}
LC_UCS *LC_UCSList::findExisting(LC_UCS *candidate) {// check if layer already exists:
LC_UCS *existingUCS = nullptr;
for (auto v: m_ucsList){
if (v == candidate){
existingUCS = v;
break;
}
}
if (existingUCS == nullptr){
for (auto v: m_ucsList) {
if (v->isSameTo(candidate)) {
existingUCS = v;
break;
}
}
}
return existingUCS;
}
LC_UCS *LC_UCSList::getWCS() const{
return m_wcs.get();
}
void LC_UCSList::tryToSetActive(LC_UCS *ucs) {
LC_UCS* oldActive = m_activeUCS;
m_activeUCS = findExisting(ucs);
if (oldActive != m_activeUCS) {
if (oldActive == nullptr) {
setModified(true);
}
else if (!oldActive->isSameTo(m_activeUCS)){
setModified(true);
}
}
}
|