1
0
Fork 0
mirror of https://github.com/leozide/leocad synced 2025-01-27 19:58:20 +01:00
leocad/common/pieceinf.h

204 lines
4 KiB
C
Raw Normal View History

#pragma once
2011-09-07 21:06:51 +00:00
#include <stdio.h>
2012-06-07 00:08:59 +00:00
#include "lc_math.h"
2014-04-23 14:53:43 +00:00
#include "lc_array.h"
2011-09-07 21:06:51 +00:00
2019-07-21 09:26:36 -07:00
enum class lcPieceInfoType
{
Part,
Placeholder,
Model,
Project
};
2011-09-07 21:06:51 +00:00
#define LC_PIECE_NAME_LEN 256
2017-01-22 19:28:05 -08:00
enum lcPieceInfoState
{
LC_PIECEINFO_UNLOADED,
LC_PIECEINFO_LOADING,
LC_PIECEINFO_LOADED
};
struct lcModelPartsEntry
{
lcMatrix44 WorldMatrix;
2019-05-27 16:39:51 -07:00
const PieceInfo* Info;
lcMesh* Mesh;
int ColorIndex;
};
2016-03-04 03:18:23 +00:00
class lcSynthInfo;
2021-01-18 12:09:33 -08:00
enum class lcZipFileType;
2011-09-07 21:06:51 +00:00
class PieceInfo
{
public:
PieceInfo();
~PieceInfo();
2011-09-07 21:06:51 +00:00
2020-05-03 15:39:39 -07:00
PieceInfo(const PieceInfo&) = delete;
PieceInfo(PieceInfo&&) = delete;
PieceInfo& operator=(const PieceInfo&) = delete;
PieceInfo& operator=(PieceInfo&&) = delete;
2016-02-19 17:53:54 +00:00
const lcBoundingBox& GetBoundingBox() const
{
return mBoundingBox;
}
void SetBoundingBox(const lcVector3& Min, const lcVector3& Max)
{
mBoundingBox.Min = Min;
mBoundingBox.Max = Max;
}
lcSynthInfo* GetSynthInfo() const
{
return mSynthInfo;
}
void SetSynthInfo(lcSynthInfo* SynthInfo)
{
mSynthInfo = SynthInfo;
}
lcMesh* GetMesh() const
{
return mMesh;
}
lcModel* GetModel() const
{
return mModel;
}
2018-01-06 10:15:24 -08:00
Project* GetProject() const
{
return mProject;
}
2017-01-22 19:28:05 -08:00
void SetMesh(lcMesh* Mesh);
2017-01-22 19:28:05 -08:00
int AddRef()
2012-10-11 23:55:55 +00:00
{
mRefCount++;
2017-01-22 19:28:05 -08:00
return mRefCount;
2012-10-11 23:55:55 +00:00
}
2017-01-22 19:28:05 -08:00
int Release()
2012-10-11 23:55:55 +00:00
{
mRefCount--;
2017-01-22 19:28:05 -08:00
return mRefCount;
2012-10-11 23:55:55 +00:00
}
2017-01-22 19:28:05 -08:00
int GetRefCount() const
{
2017-01-22 19:28:05 -08:00
return mRefCount;
}
2015-04-26 18:41:16 +00:00
bool IsPlaceholder() const
{
2019-07-21 09:26:36 -07:00
return mType == lcPieceInfoType::Placeholder;
2015-04-26 18:41:16 +00:00
}
2015-02-22 02:39:15 +00:00
bool IsModel() const
{
2019-07-21 09:26:36 -07:00
return mType == lcPieceInfoType::Model;
2015-02-22 02:39:15 +00:00
}
bool IsProject() const
{
2019-07-21 09:26:36 -07:00
return mType == lcPieceInfoType::Project;
}
bool IsTemporary() const
{
2019-07-21 09:26:36 -07:00
return mType != lcPieceInfoType::Part;
}
2021-01-18 12:09:33 -08:00
void SetZipFile(lcZipFileType ZipFileType, int ZipFileIndex)
{
mZipFileType = ZipFileType;
mZipFileIndex = ZipFileIndex;
}
2011-09-07 21:06:51 +00:00
bool IsPatterned() const
{
if (mType != lcPieceInfoType::Part)
return false;
const char* Name = mFileName;
2011-09-07 21:06:51 +00:00
// Heuristic: Names matching '^[Uu]?[0-9]*[A-Za-z][^.][^.]' are patterned.
if (*Name == 'U' || *Name == 'u')
Name++;
2011-09-07 21:06:51 +00:00
while (*Name)
{
if (*Name < '0' || *Name > '9')
break;
Name++;
}
if (!*Name || !((*Name >= 'A' && *Name <= 'Z') || (*Name >= 'a' && *Name <= 'z')))
return false;
if (Name[1] && Name[1] != '.' && Name[2] && Name[2] != '.')
2011-09-07 21:06:51 +00:00
return true;
return false;
}
bool IsSubPiece() const
{
return (m_strDescription[0] == '~');
}
void ZoomExtents(float FoV, float AspectRatio, lcMatrix44& ProjectionMatrix, lcMatrix44& ViewMatrix) const;
void AddRenderMesh(lcScene& Scene);
2020-12-05 11:02:10 -08:00
void AddRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
2011-09-07 21:06:51 +00:00
void CreatePlaceholder(const char* Name);
2011-09-07 21:06:51 +00:00
void SetPlaceholder();
void SetModel(lcModel* Model, bool UpdateMesh, Project* CurrentProject, bool SearchProjectFolder);
void CreateProject(Project* Project, const char* PieceName);
bool GetPieceWorldMatrix(lcPiece* Piece, lcMatrix44& WorldMatrix) const;
2014-12-24 15:52:52 +00:00
bool IncludesModel(const lcModel* Model) const;
bool MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDistance) const;
2014-12-26 15:44:46 +00:00
bool BoxTest(const lcMatrix44& WorldMatrix, const lcVector4 Planes[6]) const;
void GetPartsList(int DefaultColorIndex, bool ScanSubModels, bool AddSubModels, lcPartsList& PartsList) const;
2019-05-27 16:39:51 -07:00
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector<lcModelPartsEntry>& ModelParts) const;
void CompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const;
void AddSubModelBoundingBoxPoints(const lcMatrix44& WorldMatrix, std::vector<lcVector3>& Points) const;
2019-03-17 13:27:57 -07:00
void UpdateBoundingBox(std::vector<lcModel*>& UpdatedModels);
2014-12-24 15:52:52 +00:00
2017-01-22 19:28:05 -08:00
void Load();
void Unload();
2011-09-07 21:06:51 +00:00
public:
char mFileName[LC_PIECE_NAME_LEN];
2012-09-29 00:16:43 +00:00
char m_strDescription[128];
2021-01-18 12:09:33 -08:00
lcZipFileType mZipFileType;
int mZipFileIndex;
2017-01-22 19:28:05 -08:00
lcPieceInfoState mState;
int mFolderType;
int mFolderIndex;
2011-09-07 21:06:51 +00:00
protected:
void ReleaseMesh();
2012-10-11 23:55:55 +00:00
int mRefCount;
2019-07-21 09:26:36 -07:00
lcPieceInfoType mType;
2014-12-24 15:52:52 +00:00
lcModel* mModel;
Project* mProject;
lcMesh* mMesh;
2016-02-19 17:53:54 +00:00
lcBoundingBox mBoundingBox;
lcSynthInfo* mSynthInfo;
2011-09-07 21:06:51 +00:00
};