mirror of
https://github.com/leozide/leocad
synced 2024-11-16 07:47:27 +01:00
Array cleanup.
This commit is contained in:
parent
d2cd372428
commit
ee5ed32172
4 changed files with 32 additions and 73 deletions
|
@ -1723,16 +1723,16 @@ bool lcPiecesLibrary::PieceInCategory(PieceInfo* Info, const char* CategoryKeywo
|
|||
return lcMatchCategory(PieceName, CategoryKeywords);
|
||||
}
|
||||
|
||||
void lcPiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces)
|
||||
void lcPiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, std::vector<PieceInfo*>& SinglePieces, std::vector<PieceInfo*>& GroupedPieces)
|
||||
{
|
||||
if (CategoryIndex >= 0 && CategoryIndex < static_cast<int>(gCategories.size()))
|
||||
GetCategoryEntries(gCategories[CategoryIndex].Keywords.constData(), GroupPieces, SinglePieces, GroupedPieces);
|
||||
}
|
||||
|
||||
void lcPiecesLibrary::GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces)
|
||||
void lcPiecesLibrary::GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, std::vector<PieceInfo*>& SinglePieces, std::vector<PieceInfo*>& GroupedPieces)
|
||||
{
|
||||
SinglePieces.RemoveAll();
|
||||
GroupedPieces.RemoveAll();
|
||||
SinglePieces.clear();
|
||||
GroupedPieces.clear();
|
||||
|
||||
for (const auto& PieceIt : mPieces)
|
||||
{
|
||||
|
@ -1743,7 +1743,7 @@ void lcPiecesLibrary::GetCategoryEntries(const char* CategoryKeywords, bool Grou
|
|||
|
||||
if (!GroupPieces)
|
||||
{
|
||||
SinglePieces.Add(Info);
|
||||
SinglePieces.emplace_back(Info);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1763,73 +1763,36 @@ void lcPiecesLibrary::GetCategoryEntries(const char* CategoryKeywords, bool Grou
|
|||
if (Parent)
|
||||
{
|
||||
// Check if the parent was added as a single piece.
|
||||
int Index = SinglePieces.FindIndex(Parent);
|
||||
auto ParentIt = std::find(SinglePieces.begin(), SinglePieces.end(), Parent);
|
||||
|
||||
if (Index != -1)
|
||||
SinglePieces.RemoveIndex(Index);
|
||||
if (ParentIt != SinglePieces.end())
|
||||
SinglePieces.erase(ParentIt);
|
||||
|
||||
Index = GroupedPieces.FindIndex(Parent);
|
||||
|
||||
if (Index == -1)
|
||||
GroupedPieces.Add(Parent);
|
||||
if (std::find(GroupedPieces.begin(), GroupedPieces.end(), Parent) == GroupedPieces.end())
|
||||
GroupedPieces.emplace_back(Parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Patterned pieces should have a parent but in case they don't just add them anyway.
|
||||
SinglePieces.Add(Info);
|
||||
SinglePieces.emplace_back(Info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if this piece has already been added to this category by one of its children.
|
||||
const int Index = GroupedPieces.FindIndex(Info);
|
||||
|
||||
if (Index == -1)
|
||||
SinglePieces.Add(Info);
|
||||
if (std::find(GroupedPieces.begin(), GroupedPieces.end(), Info) == GroupedPieces.end())
|
||||
SinglePieces.emplace_back(Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lcPiecesLibrary::GetPatternedPieces(PieceInfo* Parent, lcArray<PieceInfo*>& Pieces) const
|
||||
void lcPiecesLibrary::GetParts(std::vector<PieceInfo*>& Parts) const
|
||||
{
|
||||
char Name[LC_PIECE_NAME_LEN];
|
||||
strcpy(Name, Parent->mFileName);
|
||||
char* Ext = strchr(Name, '.');
|
||||
if (Ext)
|
||||
*Ext = 0;
|
||||
strcat(Name, "P");
|
||||
strupr(Name);
|
||||
|
||||
Pieces.RemoveAll();
|
||||
|
||||
for (const auto& PieceIt : mPieces)
|
||||
if (strncmp(Name, PieceIt.first.c_str(), strlen(Name)) == 0)
|
||||
Pieces.Add(PieceIt.second);
|
||||
|
||||
// Sometimes pieces with A and B versions don't follow the same convention (for example, 3040Pxx instead of 3040BPxx).
|
||||
if (Pieces.GetSize() == 0)
|
||||
{
|
||||
strcpy(Name, Parent->mFileName);
|
||||
Ext = strchr(Name, '.');
|
||||
if (Ext)
|
||||
*Ext = 0;
|
||||
size_t Len = strlen(Name);
|
||||
if (Name[Len-1] < '0' || Name[Len-1] > '9')
|
||||
Name[Len-1] = 'P';
|
||||
|
||||
for (const auto& PieceIt : mPieces)
|
||||
if (strncmp(Name, PieceIt.first.c_str(), strlen(Name)) == 0)
|
||||
Pieces.Add(PieceIt.second);
|
||||
}
|
||||
}
|
||||
|
||||
void lcPiecesLibrary::GetParts(lcArray<PieceInfo*>& Parts) const
|
||||
{
|
||||
Parts.SetSize(0);
|
||||
Parts.AllocGrow(mPieces.size());
|
||||
Parts.clear();
|
||||
Parts.reserve(mPieces.size());
|
||||
|
||||
for (const auto& PartIt : mPieces)
|
||||
Parts.Add(PartIt.second);
|
||||
Parts.emplace_back(PartIt.second);
|
||||
}
|
||||
|
||||
std::vector<PieceInfo*> lcPiecesLibrary::GetPartsFromSet(const std::vector<std::string>& PartIds) const
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "lc_context.h"
|
||||
#include "lc_math.h"
|
||||
#include "lc_array.h"
|
||||
#include "lc_meshloader.h"
|
||||
|
||||
class PieceInfo;
|
||||
|
@ -147,10 +146,9 @@ public:
|
|||
void ReleaseTexture(lcTexture* Texture);
|
||||
|
||||
bool PieceInCategory(PieceInfo* Info, const char* CategoryKeywords) const;
|
||||
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
|
||||
void GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, lcArray<PieceInfo*>& SinglePieces, lcArray<PieceInfo*>& GroupedPieces);
|
||||
void GetPatternedPieces(PieceInfo* Parent, lcArray<PieceInfo*>& Pieces) const;
|
||||
void GetParts(lcArray<PieceInfo*>& Parts) const;
|
||||
void GetCategoryEntries(int CategoryIndex, bool GroupPieces, std::vector<PieceInfo*>& SinglePieces, std::vector<PieceInfo*>& GroupedPieces);
|
||||
void GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, std::vector<PieceInfo*>& SinglePieces, std::vector<PieceInfo*>& GroupedPieces);
|
||||
void GetParts(std::vector<PieceInfo*>& Parts) const;
|
||||
|
||||
std::vector<PieceInfo*> GetPartsFromSet(const std::vector<std::string>& PartIds) const;
|
||||
std::string GetPartId(const PieceInfo* Info) const;
|
||||
|
|
|
@ -130,7 +130,7 @@ void lcPartSelectionListModel::SetCategory(int CategoryIndex)
|
|||
beginResetModel();
|
||||
|
||||
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
||||
lcArray<PieceInfo*> SingleParts, GroupedParts;
|
||||
std::vector<PieceInfo*> SingleParts, GroupedParts;
|
||||
|
||||
if (CategoryIndex != -1)
|
||||
Library->GetCategoryEntries(CategoryIndex, false, SingleParts, GroupedParts);
|
||||
|
@ -140,14 +140,14 @@ void lcPartSelectionListModel::SetCategory(int CategoryIndex)
|
|||
|
||||
lcModel* ActiveModel = gMainWindow->GetActiveModel();
|
||||
|
||||
for (int PartIdx = 0; PartIdx < SingleParts.GetSize(); )
|
||||
for (size_t PartIndex = 0; PartIndex < SingleParts.size(); )
|
||||
{
|
||||
PieceInfo* Info = SingleParts[PartIdx];
|
||||
PieceInfo* Info = SingleParts[PartIndex];
|
||||
|
||||
if (!Info->IsModel() || !Info->GetModel()->IncludesModel(ActiveModel))
|
||||
PartIdx++;
|
||||
PartIndex++;
|
||||
else
|
||||
SingleParts.RemoveIndex(PartIdx);
|
||||
SingleParts.erase(SingleParts.begin() + PartIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,9 +158,9 @@ void lcPartSelectionListModel::SetCategory(int CategoryIndex)
|
|||
|
||||
std::sort(SingleParts.begin(), SingleParts.end(), lcPartSortFunc);
|
||||
|
||||
mParts.resize(SingleParts.GetSize());
|
||||
mParts.resize(SingleParts.size());
|
||||
|
||||
for (int PartIdx = 0; PartIdx < SingleParts.GetSize(); PartIdx++)
|
||||
for (size_t PartIdx = 0; PartIdx < SingleParts.size(); PartIdx++)
|
||||
mParts[PartIdx] = std::pair<PieceInfo*, QPixmap>(SingleParts[PartIdx], QPixmap());
|
||||
|
||||
endResetModel();
|
||||
|
|
|
@ -701,16 +701,14 @@ void lcQPreferencesDialog::updateParts()
|
|||
|
||||
if (categoryIndex != -1)
|
||||
{
|
||||
lcArray<PieceInfo*> singleParts, groupedParts;
|
||||
std::vector<PieceInfo*> SingleParts, GroupedParts;
|
||||
|
||||
Library->GetCategoryEntries(mOptions->Categories[categoryIndex].Keywords.constData(), false, singleParts, groupedParts);
|
||||
Library->GetCategoryEntries(mOptions->Categories[categoryIndex].Keywords.constData(), false, SingleParts, GroupedParts);
|
||||
|
||||
for (int partIndex = 0; partIndex < singleParts.GetSize(); partIndex++)
|
||||
for (PieceInfo* Info : SingleParts)
|
||||
{
|
||||
PieceInfo *info = singleParts[partIndex];
|
||||
|
||||
QStringList rowList(info->m_strDescription);
|
||||
rowList.append(info->mFileName);
|
||||
QStringList rowList(Info->m_strDescription);
|
||||
rowList.append(Info->mFileName);
|
||||
|
||||
new QTreeWidgetItem(tree, rowList);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue