mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-12 15:25:34 +08:00
Ref T578, allow to search gliders in parallel branch
* utility functions * logs * fixed returning wrong result
This commit is contained in:
committed by
Mat Sutcliffe
parent
b13035b3f9
commit
f54d85dfbc
@@ -83,6 +83,23 @@ namespace BlackMisc
|
||||
m_l3 = l3;
|
||||
}
|
||||
|
||||
bool CAircraftCategory::isLevel(int l1, int l2, int l3) const
|
||||
{
|
||||
return l1 == m_l1 && l2 == m_l2 && l3 == m_l3;
|
||||
}
|
||||
|
||||
bool CAircraftCategory::isLevel(const QList<int> &level) const
|
||||
{
|
||||
if (level.size() != 3) { return false;}
|
||||
return m_l1 == level[0] && m_l2 == level[1] && m_l3 == level[2];
|
||||
}
|
||||
|
||||
bool CAircraftCategory::isLevel(const CAircraftCategory &category) const
|
||||
{
|
||||
if (category.isNull()) { return false; }
|
||||
return category.m_l1 == m_l1 && category.m_l2 == m_l2 && category.m_l3 == m_l3;
|
||||
}
|
||||
|
||||
QList<int> CAircraftCategory::getLevel() const
|
||||
{
|
||||
QList<int> l;
|
||||
|
||||
@@ -78,12 +78,24 @@ namespace BlackMisc
|
||||
//! Level
|
||||
void setLevel(int l1, int l2, int l3);
|
||||
|
||||
//! Is that given level?
|
||||
bool isLevel(int l1, int l2, int l3) const;
|
||||
|
||||
//! Is that given level?
|
||||
bool isLevel(const QList<int> &level) const;
|
||||
|
||||
//! Is that given level?
|
||||
bool isLevel(const CAircraftCategory &category) const;
|
||||
|
||||
//! Levels depending on depth, 3.2 -> 3,2 / 1.0 -> 1 / 4.3.1 -> 4,3,1
|
||||
QList<int> getLevel() const;
|
||||
|
||||
//! First level
|
||||
int getFirstLevel() const { return m_l1; }
|
||||
|
||||
//! Second level
|
||||
int getSecondLevel() const { return m_l2; }
|
||||
|
||||
//! First level
|
||||
bool isFirstLevel() const;
|
||||
|
||||
|
||||
@@ -71,6 +71,20 @@ namespace BlackMisc
|
||||
{
|
||||
levels.insert(category.getFirstLevel());
|
||||
}
|
||||
levels.remove(0);
|
||||
QList<int> ll = levels.toList();
|
||||
std::sort(ll.begin(), ll.end());
|
||||
return ll;
|
||||
}
|
||||
|
||||
QList<int> CAircraftCategoryList::getSecondLevels() const
|
||||
{
|
||||
QSet<int> levels;
|
||||
for (const CAircraftCategory &category : *this)
|
||||
{
|
||||
levels.insert(category.getSecondLevel());
|
||||
}
|
||||
levels.remove(0);
|
||||
QList<int> ll = levels.toList();
|
||||
std::sort(ll.begin(), ll.end());
|
||||
return ll;
|
||||
@@ -117,12 +131,14 @@ namespace BlackMisc
|
||||
return categories;
|
||||
}
|
||||
|
||||
CAircraftCategoryList CAircraftCategoryList::findByLevel(const QList<int> &level) const
|
||||
CAircraftCategoryList CAircraftCategoryList::findByLevel(const QList<int> &level, bool noRootNode) const
|
||||
{
|
||||
CAircraftCategoryList categories;
|
||||
if (level.isEmpty()) { return categories; }
|
||||
const int ls = level.size();
|
||||
for (const CAircraftCategory &category : *this)
|
||||
{
|
||||
if (noRootNode && ls == category.getDepth()) { continue; } // ignore root nodes
|
||||
if (category.matchesLevel(level))
|
||||
{
|
||||
categories.push_back(category);
|
||||
@@ -131,6 +147,16 @@ namespace BlackMisc
|
||||
return categories;
|
||||
}
|
||||
|
||||
CAircraftCategory CAircraftCategoryList::findByFullLevel(const QList<int> &level) const
|
||||
{
|
||||
if (level.size() != 3) { return {}; }
|
||||
for (const CAircraftCategory &category : *this)
|
||||
{
|
||||
if (category.isLevel(level[0], level[1], level[2])) { return category; }
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
CAircraftCategoryList CAircraftCategoryList::findFirstLevels() const
|
||||
{
|
||||
return this->findBy(&CAircraftCategory::isFirstLevel, true);
|
||||
@@ -147,12 +173,32 @@ namespace BlackMisc
|
||||
else
|
||||
{
|
||||
levels.removeLast();
|
||||
categories = this->findByLevel(levels);
|
||||
categories = this->findByLevel(levels, true);
|
||||
}
|
||||
categories.remove(category);
|
||||
return categories;
|
||||
}
|
||||
|
||||
CAircraftCategoryList CAircraftCategoryList::findInParallelBranch(const CAircraftCategory &category) const
|
||||
{
|
||||
if (category.isNull() || this->isEmpty()) { return {}; }
|
||||
if (category.isFirstLevel()) { return {}; }
|
||||
const bool isL2 = category.getDepth() == 2;
|
||||
const QList<int> loopLevels = isL2 ? this->getFirstLevels() : this->getSecondLevels();
|
||||
if (loopLevels.isEmpty()) { return {}; }
|
||||
|
||||
QList<int> level = category.getLevel();
|
||||
CAircraftCategoryList result;
|
||||
for (int l = loopLevels.front(); loopLevels.back() >= l; ++l)
|
||||
{
|
||||
level[isL2 ? 0 : 1] = l;
|
||||
if (category.isLevel(level)) { continue; } // ignore category itself
|
||||
const CAircraftCategory cat = this->findByFullLevel(level);
|
||||
if (!cat.isNull()) { result.push_back(cat); }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int CAircraftCategoryList::removeIfLevel(const QList<int> &level)
|
||||
{
|
||||
if (level.isEmpty()) { return 0; }
|
||||
|
||||
@@ -61,6 +61,9 @@ namespace BlackMisc
|
||||
//! All levels sorted
|
||||
QList<int> getFirstLevels() const;
|
||||
|
||||
//! All levels sorted
|
||||
QList<int> getSecondLevels() const;
|
||||
|
||||
//! Find highest (top) level of categories
|
||||
CAircraftCategoryList findHighestLevels(const CAircraftCategoryList &categories);
|
||||
|
||||
@@ -68,7 +71,10 @@ namespace BlackMisc
|
||||
CAircraftCategoryList findByFirstLevel(int level) const;
|
||||
|
||||
//! Find by levels
|
||||
CAircraftCategoryList findByLevel(const QList<int> &level) const;
|
||||
CAircraftCategoryList findByLevel(const QList<int> &level, bool noRootNode = false) const;
|
||||
|
||||
//! Find by exact levels
|
||||
CAircraftCategory findByFullLevel(const QList<int> &level) const;
|
||||
|
||||
//! Find first levels
|
||||
CAircraftCategoryList findFirstLevels() const;
|
||||
@@ -77,6 +83,10 @@ namespace BlackMisc
|
||||
//! \remark if level is 3.2, siblings are 3.1 and 3.3
|
||||
CAircraftCategoryList findSiblings(const CAircraftCategory &category) const;
|
||||
|
||||
//! Find siblings
|
||||
//! \remark if level is 3.2, finds 1.2, 2.2, and 4.2
|
||||
CAircraftCategoryList findInParallelBranch(const CAircraftCategory &category) const;
|
||||
|
||||
//! Remove by level
|
||||
int removeIfLevel(const QList<int> &level);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user