leocad/common/pieceinf.h

177 lines
3.6 KiB
C
Raw Normal View History

#pragma once
2011-09-07 23:06:51 +02:00
#include <stdio.h>
2012-06-07 02:08:59 +02:00
#include "lc_math.h"
2014-04-23 16:53:43 +02:00
#include "lc_array.h"
2011-09-07 23:06:51 +02:00
#define LC_PIECE_HAS_DEFAULT 0x01 // Piece has triangles using the default color
#define LC_PIECE_HAS_SOLID 0x02 // Piece has triangles using a solid color
#define LC_PIECE_HAS_TRANSLUCENT 0x04 // Piece has triangles using a translucent color
#define LC_PIECE_HAS_LINES 0x08 // Piece has lines
2012-11-08 05:05:52 +01:00
#define LC_PIECE_PLACEHOLDER 0x10 // Placeholder for a piece not in the library
#define LC_PIECE_MODEL 0x20 // Piece is a model
#define LC_PIECE_PROJECT 0x40 // Piece is a project
2017-03-23 07:35:02 +01:00
#define LC_PIECE_HAS_TEXTURE 0x80 // Piece has sections using textures
2011-09-07 23:06:51 +02:00
#define LC_PIECE_NAME_LEN 256
2017-01-23 04:28:05 +01:00
enum lcPieceInfoState
{
LC_PIECEINFO_UNLOADED,
LC_PIECEINFO_LOADING,
LC_PIECEINFO_LOADED
};
2016-03-04 04:18:23 +01:00
class lcSynthInfo;
2011-09-07 23:06:51 +02:00
class PieceInfo
{
public:
PieceInfo();
~PieceInfo();
2011-09-07 23:06:51 +02:00
2016-02-19 18:53:54 +01: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 19:15:24 +01:00
Project* GetProject() const
{
return mProject;
}
2017-01-23 04:28:05 +01:00
void SetMesh(lcMesh* Mesh);
2017-01-23 04:28:05 +01:00
int AddRef()
2012-10-12 01:55:55 +02:00
{
mRefCount++;
2017-01-23 04:28:05 +01:00
return mRefCount;
2012-10-12 01:55:55 +02:00
}
2017-01-23 04:28:05 +01:00
int Release()
2012-10-12 01:55:55 +02:00
{
mRefCount--;
2017-01-23 04:28:05 +01:00
return mRefCount;
2012-10-12 01:55:55 +02:00
}
2017-01-23 04:28:05 +01:00
int GetRefCount() const
{
2017-01-23 04:28:05 +01:00
return mRefCount;
}
2015-04-26 20:41:16 +02:00
bool IsPlaceholder() const
{
return (mFlags & LC_PIECE_PLACEHOLDER) != 0;
}
2015-02-22 03:39:15 +01:00
bool IsModel() const
{
return (mFlags & LC_PIECE_MODEL) != 0;
}
bool IsProject() const
{
return (mFlags & LC_PIECE_PROJECT) != 0;
}
bool IsTemporary() const
{
return (mFlags & (LC_PIECE_PLACEHOLDER | LC_PIECE_MODEL | LC_PIECE_PROJECT)) != 0;
}
void SetZipFile(int ZipFileType, int ZipFileIndex)
{
mZipFileType = ZipFileType;
mZipFileIndex = ZipFileIndex;
}
2011-09-07 23:06:51 +02:00
bool IsPatterned() const
{
const char* Name = mFileName;
2011-09-07 23:06:51 +02:00
while (*Name)
{
if (*Name < '0' || *Name > '9')
break;
Name++;
}
if (*Name == 'P' || *Name == 'p')
2011-09-07 23:06:51 +02: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);
void AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, bool Focused, bool Selected, bool Highlight) const;
2011-09-07 23:06:51 +02:00
void CreatePlaceholder(const char* Name);
2011-09-07 23:06:51 +02:00
void SetPlaceholder();
void SetModel(lcModel* Model, bool UpdateMesh, Project* CurrentProject, bool SearchProjectFolder);
void CreateProject(Project* Project, const char* PieceName);
2014-12-24 16:52:52 +01:00
bool IncludesModel(const lcModel* Model) const;
bool MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDistance) const;
2014-12-26 16:44:46 +01:00
bool BoxTest(const lcMatrix44& WorldMatrix, const lcVector4 Planes[6]) const;
2017-11-19 23:12:27 +01:00
void GetPartsList(int DefaultColorIndex, bool IncludeSubmodels, lcPartsList& PartsList) const;
2014-12-30 17:30:12 +01:00
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcArray<lcModelPartsEntry>& ModelParts) const;
void UpdateBoundingBox(lcArray<lcModel*>& UpdatedModels);
2014-12-24 16:52:52 +01:00
2017-01-23 04:28:05 +01:00
void Load();
void Unload();
2011-09-07 23:06:51 +02:00
public:
char mFileName[LC_PIECE_NAME_LEN];
2012-09-29 02:16:43 +02:00
char m_strDescription[128];
int mZipFileType;
int mZipFileIndex;
2017-12-02 21:22:04 +01:00
quint32 mFlags;
2017-01-23 04:28:05 +01:00
lcPieceInfoState mState;
int mFolderType;
int mFolderIndex;
2011-09-07 23:06:51 +02:00
protected:
void ReleaseMesh();
2012-10-12 01:55:55 +02:00
int mRefCount;
2014-12-24 16:52:52 +01:00
lcModel* mModel;
Project* mProject;
lcMesh* mMesh;
2016-02-19 18:53:54 +01:00
lcBoundingBox mBoundingBox;
lcSynthInfo* mSynthInfo;
2011-09-07 23:06:51 +02:00
};