leocad/common/lc_model.h

354 lines
10 KiB
C
Raw Normal View History

2014-05-25 03:45:19 +02:00
#ifndef _LC_MODEL_H_
#define _LC_MODEL_H_
2014-07-03 21:10:04 +02:00
#include "lc_file.h"
2014-05-25 03:45:19 +02:00
#include "lc_math.h"
#include "object.h"
2014-08-17 22:44:12 +02:00
#define LC_SEL_NO_PIECES 0x01 // No pieces in model
#define LC_SEL_PIECE 0x02 // At last 1 piece selected
#define LC_SEL_SELECTED 0x04 // At last 1 object selected
#define LC_SEL_UNSELECTED 0x08 // At least 1 piece unselected
#define LC_SEL_HIDDEN 0x10 // At least one piece hidden
#define LC_SEL_GROUPED 0x20 // At least one piece selected is grouped
#define LC_SEL_FOCUS_GROUPED 0x40 // Focused piece is grouped
#define LC_SEL_CAN_GROUP 0x80 // Can make a new group
2014-08-27 18:17:09 +02:00
enum lcTransformType
{
LC_TRANSFORM_ABSOLUTE_TRANSLATION,
LC_TRANSFORM_RELATIVE_TRANSLATION,
LC_TRANSFORM_ABSOLUTE_ROTATION,
LC_TRANSFORM_RELATIVE_ROTATION
};
2014-05-25 03:45:19 +02:00
enum lcBackgroundType
{
LC_BACKGROUND_SOLID,
LC_BACKGROUND_GRADIENT,
2014-09-08 21:42:20 +02:00
LC_BACKGROUND_IMAGE,
LC_NUM_BACKGROUND_TYPES
2014-05-25 03:45:19 +02:00
};
class lcModelProperties
{
public:
void LoadDefaults();
void SaveDefaults();
bool operator==(const lcModelProperties& Properties)
{
if (mName != Properties.mName || mAuthor != Properties.mAuthor ||
mDescription != Properties.mDescription || mComments != Properties.mComments)
return false;
if (mBackgroundType != Properties.mBackgroundType || mBackgroundSolidColor != Properties.mBackgroundSolidColor ||
mBackgroundGradientColor1 != Properties.mBackgroundGradientColor1 || mBackgroundGradientColor2 != Properties.mBackgroundGradientColor2 ||
mBackgroundImage != Properties.mBackgroundImage || mBackgroundImageTile != Properties.mBackgroundImageTile)
return false;
if (mFogEnabled != Properties.mFogEnabled || mFogDensity != Properties.mFogDensity ||
mFogColor != Properties.mFogColor || mAmbientColor != Properties.mAmbientColor)
return false;
return true;
}
2015-02-08 04:29:42 +01:00
void SaveLDraw(QTextStream& Stream, bool MPD) const;
2014-09-08 21:42:20 +02:00
void ParseLDrawLine(QTextStream& Stream);
2014-09-06 03:34:03 +02:00
QString mName;
QString mAuthor;
QString mDescription;
QString mComments;
2014-05-25 03:45:19 +02:00
lcBackgroundType mBackgroundType;
lcVector3 mBackgroundSolidColor;
lcVector3 mBackgroundGradientColor1;
lcVector3 mBackgroundGradientColor2;
2014-09-08 21:42:20 +02:00
QString mBackgroundImage;
2014-05-25 03:45:19 +02:00
bool mBackgroundImageTile;
bool mFogEnabled;
float mFogDensity;
lcVector3 mFogColor;
lcVector3 mAmbientColor;
};
enum lcTool
{
LC_TOOL_INSERT,
LC_TOOL_LIGHT,
LC_TOOL_SPOTLIGHT,
LC_TOOL_CAMERA,
LC_TOOL_SELECT,
LC_TOOL_MOVE,
LC_TOOL_ROTATE,
LC_TOOL_ERASER,
LC_TOOL_PAINT,
LC_TOOL_ZOOM,
LC_TOOL_PAN,
LC_TOOL_ROTATE_VIEW,
LC_TOOL_ROLL,
LC_TOOL_ZOOM_REGION
};
2014-07-03 21:10:04 +02:00
struct lcModelHistoryEntry
{
2014-09-14 02:45:45 +02:00
QByteArray File;
2014-09-15 01:32:58 +02:00
QString Description;
2014-07-03 21:10:04 +02:00
};
2014-10-11 01:53:08 +02:00
struct lcPartsListEntry
{
PieceInfo* Info;
int ColorIndex;
int Count;
};
2014-12-30 17:30:12 +01:00
struct lcModelPartsEntry
{
lcMatrix44 WorldMatrix;
PieceInfo* Info;
int ColorIndex;
};
2014-05-25 03:45:19 +02:00
class lcModel
{
public:
2014-12-10 00:56:29 +01:00
lcModel(const QString& Name);
2014-05-25 03:45:19 +02:00
~lcModel();
2014-07-06 08:04:09 +02:00
bool IsModified() const
{
return mSavedHistory != mUndoHistory[0];
}
2014-12-24 16:52:52 +01:00
bool IncludesModel(const lcModel* Model) const;
2015-02-22 03:39:15 +01:00
void CreatePieceInfo(Project* Project);
void UpdatePieceInfo(lcArray<lcModel*>& UpdatedModels);
2014-12-24 16:52:52 +01:00
PieceInfo* GetPieceInfo() const
{
return mPieceInfo;
}
2014-05-27 00:58:08 +02:00
const lcArray<lcPiece*>& GetPieces() const
{
return mPieces;
}
const lcArray<lcCamera*>& GetCameras() const
{
return mCameras;
}
const lcArray<lcLight*>& GetLights() const
{
return mLights;
}
const lcArray<lcGroup*>& GetGroups() const
{
return mGroups;
}
2014-11-24 00:48:56 +01:00
const lcModelProperties& GetProperties() const
{
return mProperties;
}
2014-12-13 00:42:09 +01:00
void SetName(const QString& Name)
{
mProperties.mName = Name;
}
const QStringList& GetMeshLines() const
{
return mMeshLines;
}
2014-07-06 08:04:09 +02:00
lcStep GetLastStep() const;
2014-08-17 22:44:12 +02:00
2014-07-06 08:04:09 +02:00
lcStep GetCurrentStep() const
{
return mCurrentStep;
}
void SetActive(bool Active);
void CalculateStep(lcStep Step);
void SetCurrentStep(lcStep Step)
{
mCurrentStep = Step;
CalculateStep(Step);
}
void ShowFirstStep();
void ShowLastStep();
void ShowPreviousStep();
void ShowNextStep();
void InsertStep();
void RemoveStep();
void AddPiece();
2015-01-16 03:07:31 +01:00
void DeleteAllCameras();
void DeleteSelectedObjects();
void ShowSelectedPiecesEarlier();
void ShowSelectedPiecesLater();
2015-03-08 01:27:11 +01:00
void SetPieceSteps(const QList<QPair<lcPiece*, int>>& PieceSteps);
2014-11-10 01:06:11 +01:00
lcGroup* AddGroup(const char* Prefix, lcGroup* Parent);
lcGroup* GetGroup(const char* Name, bool CreateIfMissing);
2014-11-10 01:06:11 +01:00
void RemoveGroup(lcGroup* Group);
void GroupSelection();
void UngroupSelection();
void AddSelectedPiecesToGroup();
void RemoveFocusPieceFromGroup();
void ShowEditGroupsDialog();
2015-02-08 04:29:42 +01:00
void SaveLDraw(QTextStream& Stream, bool MPD, bool SelectedOnly) const;
2015-02-22 03:39:15 +01:00
void LoadLDraw(QIODevice& Device, Project* Project);
bool LoadBinary(lcFile* File);
2014-12-16 00:55:17 +01:00
void Merge(lcModel* Other);
void SetSaved()
{
2014-12-16 00:55:17 +01:00
if (mUndoHistory.IsEmpty())
SaveCheckpoint(QString());
mSavedHistory = mUndoHistory[0];
}
2014-12-16 00:55:17 +01:00
void Cut();
void Copy();
void Paste();
2014-11-24 00:48:56 +01:00
void GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface) const;
2014-12-26 16:44:46 +01:00
void SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, bool Focused, bool Selected) const;
void DrawBackground(lcContext* Context);
2015-01-12 05:49:30 +01:00
void SaveStepImages(const QString& BaseName, int Width, int Height, lcStep Start, lcStep End);
2014-09-15 01:32:58 +02:00
void RayTest(lcObjectRayTest& ObjectRayTest) const;
void BoxTest(lcObjectBoxTest& ObjectBoxTest) const;
2014-12-26 16:44:46 +01:00
bool SubModelMinIntersectDist(const lcVector3& WorldStart, const lcVector3& WorldEnd, float& MinDistance) const;
bool SubModelBoxTest(const lcVector4 Planes[6]) const;
2014-08-30 01:52:42 +02:00
2014-10-08 01:02:52 +02:00
bool AnyPiecesSelected() const;
bool AnyObjectsSelected() const;
2014-11-10 01:06:11 +01:00
bool GetPieceFocusOrSelectionCenter(lcVector3& Center) const;
bool GetFocusOrSelectionCenter(lcVector3& Center) const;
2014-10-08 01:02:52 +02:00
lcVector3 GetFocusOrSelectionCenter() const;
2015-02-14 21:47:50 +01:00
lcVector3 GetSelectionOrModelCenter() const;
2014-10-08 01:02:52 +02:00
bool GetFocusPosition(lcVector3& Position) const;
2014-08-17 22:44:12 +02:00
lcObject* GetFocusObject() const;
2014-10-05 07:21:51 +02:00
bool GetSelectionCenter(lcVector3& Center) const;
bool GetPiecesBoundingBox(float BoundingBox[6]) const;
2014-12-30 17:30:12 +01:00
void GetPartsList(int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;
2015-01-12 05:49:30 +01:00
void GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcArray<lcPartsListEntry>& PartsList) const;
2014-12-30 17:30:12 +01:00
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcArray<lcModelPartsEntry>& ModelParts) const;
2014-08-17 22:44:12 +02:00
void FocusOrDeselectObject(const lcObjectSection& ObjectSection);
2014-11-29 03:55:58 +01:00
void ClearSelection(bool UpdateInterface);
2014-08-17 22:44:12 +02:00
void ClearSelectionAndSetFocus(lcObject* Object, lcuint32 Section);
void ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection);
2015-03-14 22:09:10 +01:00
void SetSelectionAndFocus(const lcArray<lcObject*>& Selection, lcObject* Focus, lcuint32 Section);
2014-11-29 03:55:58 +01:00
void AddToSelection(const lcArray<lcObject*>& Objects);
2014-10-24 02:41:19 +02:00
void SelectAllPieces();
2014-11-29 03:55:58 +01:00
void InvertSelection();
2014-08-17 22:44:12 +02:00
2014-11-08 02:05:17 +01:00
void HideSelectedPieces();
void HideUnselectedPieces();
void UnhideAllPieces();
2014-09-21 03:31:01 +02:00
void FindPiece(bool FindFirst, bool SearchForward);
2014-10-24 02:41:19 +02:00
void UndoAction();
void RedoAction();
2014-10-05 07:42:38 +02:00
lcVector3 LockVector(const lcVector3& Vector) const;
lcVector3 SnapPosition(const lcVector3& Delta) const;
lcVector3 SnapRotation(const lcVector3& Delta) const;
2014-10-05 07:21:51 +02:00
lcMatrix44 GetRelativeRotation() const;
const lcVector3& GetMouseToolDistance() const
{
return mMouseToolDistance;
}
void BeginMouseTool();
void EndMouseTool(lcTool Tool, bool Accept);
void InsertPieceToolClicked(const lcMatrix44& WorldMatrix);
2014-10-05 07:21:51 +02:00
void PointLightToolClicked(const lcVector3& Position);
void BeginSpotLightTool(const lcVector3& Position, const lcVector3& Target);
2014-11-24 01:43:13 +01:00
void UpdateSpotLightTool(const lcVector3& Position);
2014-10-05 07:21:51 +02:00
void BeginCameraTool(const lcVector3& Position, const lcVector3& Target);
2014-11-24 01:43:13 +01:00
void UpdateCameraTool(const lcVector3& Position);
2014-10-05 07:21:51 +02:00
void UpdateMoveTool(const lcVector3& Distance);
void UpdateRotateTool(const lcVector3& Angles);
void EraserToolClicked(lcObject* Object);
void PaintToolClicked(lcObject* Object);
void UpdateZoomTool(lcCamera* Camera, float Mouse);
void UpdatePanTool(lcCamera* Camera, const lcVector3& Distance);
2014-10-05 07:21:51 +02:00
void UpdateOrbitTool(lcCamera* Camera, float MouseX, float MouseY);
void UpdateRollTool(lcCamera* Camera, float Mouse);
void ZoomRegionToolClicked(lcCamera* Camera, float AspectRatio, const lcVector3& Position, const lcVector3& TargetPosition, const lcVector3* Corners);
void LookAt(lcCamera* Camera);
2014-11-08 02:05:17 +01:00
void ZoomExtents(lcCamera* Camera, float Aspect);
void Zoom(lcCamera* Camera, float Amount);
2014-10-05 07:21:51 +02:00
void MoveSelectedObjects(const lcVector3& Distance, bool Relative, bool Update)
2014-12-04 02:47:28 +01:00
{
MoveSelectedObjects(Distance, Distance, Relative, Update);
2014-12-04 02:47:28 +01:00
}
void MoveSelectedObjects(const lcVector3& PieceDistance, const lcVector3& ObjectDistance, bool Relative, bool Update);
void RotateSelectedPieces(const lcVector3& Angles, bool Relative, bool Update);
2014-11-29 03:55:58 +01:00
void TransformSelectedObjects(lcTransformType TransformType, const lcVector3& Transform);
void SetObjectProperty(lcObject* Object, lcObjectPropertyType ObjectPropertyType, const void* Value);
void ShowPropertiesDialog();
void ShowSelectByNameDialog();
2014-11-10 01:06:11 +01:00
void ShowArrayDialog();
void ShowMinifigDialog();
void UpdateInterface();
2014-11-10 01:06:11 +01:00
2014-05-27 00:58:08 +02:00
protected:
2014-10-05 07:21:51 +02:00
void DeleteModel();
void DeleteHistory();
2014-09-15 01:32:58 +02:00
void SaveCheckpoint(const QString& Description);
2014-10-05 07:21:51 +02:00
void LoadCheckPoint(lcModelHistoryEntry* CheckPoint);
2014-11-10 01:06:11 +01:00
void GetGroupName(const char* Prefix, char* GroupName);
2014-10-05 07:21:51 +02:00
void RemoveEmptyGroups();
2014-10-08 01:02:52 +02:00
bool RemoveSelectedObjects();
2014-10-05 07:21:51 +02:00
void UpdateBackgroundTexture();
2014-08-17 22:44:12 +02:00
void UpdateSelection() const;
void SelectGroup(lcGroup* TopGroup, bool Select);
2015-03-14 20:07:07 +01:00
void AddPiece(lcPiece* Piece);
2014-05-25 03:45:19 +02:00
lcModelProperties mProperties;
2014-12-24 16:52:52 +01:00
PieceInfo* mPieceInfo;
2014-05-25 03:45:19 +02:00
2015-01-12 05:49:30 +01:00
bool mActive;
2014-07-06 08:04:09 +02:00
lcStep mCurrentStep;
2014-09-15 01:32:58 +02:00
lcVector3 mMouseToolDistance;
2014-10-05 07:21:51 +02:00
lcTexture* mBackgroundTexture;
2014-07-06 08:04:09 +02:00
2014-05-25 03:45:19 +02:00
lcArray<lcPiece*> mPieces;
lcArray<lcCamera*> mCameras;
lcArray<lcLight*> mLights;
lcArray<lcGroup*> mGroups;
QStringList mMeshLines;
2014-07-03 21:10:04 +02:00
lcModelHistoryEntry* mSavedHistory;
2014-07-03 21:10:04 +02:00
lcArray<lcModelHistoryEntry*> mUndoHistory;
lcArray<lcModelHistoryEntry*> mRedoHistory;
2014-10-05 07:21:51 +02:00
2014-10-11 01:53:08 +02:00
Q_DECLARE_TR_FUNCTIONS(lcModel);
2014-05-25 03:45:19 +02:00
};
#endif // _LC_MODEL_H_