File size: 3,875 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
/*******************************************************************************
 *
 This file is part of the LibreCAD project, a 2D CAD program

 Copyright (C) 2024 LibreCAD.org
 Copyright (C) 2024 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_ucs.h"

#include <QObject>

#include "lc_linemath.h"
#include "rs_math.h"

LC_UCS LC_WCS::instance = LC_WCS();

LC_UCS::LC_UCS() {}

LC_UCS::LC_UCS(QString n) {
    m_name = n;
}

void LC_UCS::setElevation(double d) {
    m_ucsElevation = d;
}

void LC_UCS::setOrigin(RS_Vector o) {
  m_ucsOrigin = o;
}

void LC_UCS::setXAxis(RS_Vector pos) {
  m_ucsXAxis = pos;
}

void LC_UCS::setYAxis(RS_Vector axis) {
  m_ucsYAxis = axis;
}

void LC_UCS::setOrthoType(int type) {
  m_ucsOrthoType = type;
}

void LC_UCS::setName(const QString &name) {
    LC_UCS::m_name = name;
}

const QString LC_UCS::getName() const {
    return m_name;
}

const RS_Vector LC_UCS::getOrthoOrigin() const {
    return m_orthoOrigin;
}

void LC_UCS::setOrthoOrigin(const RS_Vector &orthoOrigin) {
    LC_UCS::m_orthoOrigin = orthoOrigin;
}

long LC_UCS::getNamedUcsId() const {
    return namedUCS_ID;
}

long LC_UCS::getBaseUcsId() const {
    return baseUCS_ID;
}

bool LC_UCS::isValidName([[maybe_unused]]const QString &nameCandidate) {
    // fixme - implement UCS name validation rule here
    return true;
}

bool LC_UCS::isSameTo(LC_UCS *other) {
    bool result = false;
    if (other != nullptr){
//        if (isUCS() == other->isUCS()) {
            if (m_ucsOrthoType == other->getOrthoType()) {
                if (LC_LineMath::isNotMeaningfulDistance(other->getOrigin(), getOrigin())) { // same origin
                    double ownAngle = RS_Math::correctAnglePlusMinusPi(getXAxisDirection());
                    double otherAngle = RS_Math::correctAnglePlusMinusPi(other->getXAxisDirection());
                    result = RS_Math::getAngleDifference(ownAngle, otherAngle) < RS_TOLERANCE_ANGLE;
                }
            }
        }
//    }
    return result;
}


RS2::IsoGridViewType LC_UCS::getIsoGridViewType() {
    RS2::IsoGridViewType isoType = RS2::Ortho;
    switch (m_ucsOrthoType){
        case LC_UCS::FRONT:
        case LC_UCS::BACK:
            break;
        case LC_UCS::LEFT:{
            isoType = RS2::IsoLeft;
            break;
        }
        case LC_UCS::RIGHT:{
            isoType = RS2::IsoRight;
            break;
        }
        case LC_UCS::TOP:
        case LC_UCS::BOTTOM:{
            isoType = RS2::IsoTop;
            break;
        }
        default:
            isoType = RS2::Ortho;
            break;
    }
    return isoType;
}

bool LC_UCS::isIsometric() {
    return m_ucsOrthoType != LC_UCS::NON_ORTHO;
}

LC_WCS::LC_WCS():
    LC_UCS(QObject::tr("WCS"))
{}

LC_UCS::~LC_UCS() = default;

LC_UCS* LC_UCS::clone() {
    auto* clone = new LC_UCS();
    clone->m_name =  m_name;
    clone->m_ucsOrigin = m_ucsOrigin;
    clone->m_ucsXAxis = m_ucsXAxis;
    clone->m_ucsYAxis = m_ucsYAxis;
    clone->m_orthoOrigin = m_orthoOrigin;
    clone->m_ucsOrthoType = m_ucsOrthoType;
    clone->m_ucsElevation = m_ucsElevation;
    return clone;
}