mirror of
https://github.com/leozide/leocad
synced 2024-11-17 07:47:55 +01:00
Support up to 10 control points and prevent the user from adding more.
This commit is contained in:
parent
fab6a8fa11
commit
ade7334fa1
5 changed files with 114 additions and 41 deletions
|
@ -2898,9 +2898,9 @@ void lcModel::ScaleSelectedPieces(const float Scale, bool Update, bool Checkpoin
|
|||
lcPiece* Piece = (lcPiece*)Focus;
|
||||
quint32 Section = Piece->GetFocusSection();
|
||||
|
||||
if (Section >= LC_PIECE_SECTION_CONTROL_POINT_1 && Section <= LC_PIECE_SECTION_CONTROL_POINT_8)
|
||||
if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST && Section <= LC_PIECE_SECTION_CONTROL_POINT_LAST)
|
||||
{
|
||||
int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1;
|
||||
int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST;
|
||||
Piece->SetControlPointScale(ControlPointIndex, Scale);
|
||||
|
||||
if (Update)
|
||||
|
@ -3444,16 +3444,11 @@ void lcModel::GetSelectionInformation(int* Flags, lcArray<lcObject*>& Selection,
|
|||
|
||||
*Flags |= LC_SEL_PIECE | LC_SEL_SELECTED;
|
||||
|
||||
lcSynthInfo* SynthInfo = Piece->mPieceInfo->GetSynthInfo();
|
||||
if (SynthInfo && SynthInfo->CanAddControlPoints())
|
||||
{
|
||||
if (Piece->CanAddControlPoint())
|
||||
*Flags |= LC_SEL_CAN_ADD_CONTROL_POINT;
|
||||
|
||||
quint32 Section = Piece->GetFocusSection();
|
||||
|
||||
if (Section >= LC_PIECE_SECTION_CONTROL_POINT_1 && Section <= LC_PIECE_SECTION_CONTROL_POINT_8 && Piece->GetControlPoints().GetSize() > 2)
|
||||
*Flags |= LC_SEL_CAN_REMOVE_CONTROL_POINT;
|
||||
}
|
||||
if (Piece->CanRemoveControlPoint())
|
||||
*Flags |= LC_SEL_CAN_REMOVE_CONTROL_POINT;
|
||||
|
||||
if (Piece->GetGroup() != nullptr)
|
||||
{
|
||||
|
|
|
@ -812,17 +812,33 @@ quint32 lcPiece::GetAllowedTransforms() const
|
|||
return LC_OBJECT_TRANSFORM_MOVE_Z;
|
||||
}
|
||||
|
||||
bool lcPiece::CanAddControlPoint() const
|
||||
{
|
||||
if (mControlPoints.GetSize() >= LC_MAX_CONTROL_POINTS)
|
||||
return false;
|
||||
|
||||
lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo();
|
||||
return SynthInfo && SynthInfo->CanAddControlPoints();
|
||||
}
|
||||
|
||||
bool lcPiece::CanRemoveControlPoint() const
|
||||
{
|
||||
quint32 Section = GetFocusSection();
|
||||
return Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST && Section <= LC_PIECE_SECTION_CONTROL_POINT_LAST && mControlPoints.GetSize() > 2;
|
||||
}
|
||||
|
||||
bool lcPiece::InsertControlPoint(const lcVector3& WorldStart, const lcVector3& WorldEnd)
|
||||
{
|
||||
lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo();
|
||||
if (!SynthInfo || !SynthInfo->CanAddControlPoints())
|
||||
if (!CanAddControlPoint())
|
||||
return false;
|
||||
|
||||
lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse(mModelWorld);
|
||||
lcVector3 Start = lcMul31(WorldStart, InverseWorldMatrix);
|
||||
lcVector3 End = lcMul31(WorldEnd, InverseWorldMatrix);
|
||||
|
||||
lcSynthInfo* SynthInfo = mPieceInfo->GetSynthInfo();
|
||||
int ControlPointIndex = SynthInfo->InsertControlPoint(mControlPoints, Start, End);
|
||||
|
||||
if (ControlPointIndex)
|
||||
{
|
||||
SetFocused(GetFocusSection(), false);
|
||||
|
|
110
common/piece.h
110
common/piece.h
|
@ -6,41 +6,54 @@ class PieceInfo;
|
|||
#include "lc_colors.h"
|
||||
#include "lc_math.h"
|
||||
|
||||
#define LC_PIECE_HIDDEN 0x00001
|
||||
#define LC_PIECE_PIVOT_POINT_VALID 0x00002
|
||||
#define LC_PIECE_POSITION_SELECTED 0x00004
|
||||
#define LC_PIECE_POSITION_FOCUSED 0x00008
|
||||
#define LC_PIECE_CONTROL_POINT_1_SELECTED 0x00010
|
||||
#define LC_PIECE_CONTROL_POINT_1_FOCUSED 0x00020
|
||||
#define LC_PIECE_CONTROL_POINT_2_SELECTED 0x00040
|
||||
#define LC_PIECE_CONTROL_POINT_2_FOCUSED 0x00080
|
||||
#define LC_PIECE_CONTROL_POINT_3_SELECTED 0x00100
|
||||
#define LC_PIECE_CONTROL_POINT_3_FOCUSED 0x00200
|
||||
#define LC_PIECE_CONTROL_POINT_4_SELECTED 0x00400
|
||||
#define LC_PIECE_CONTROL_POINT_4_FOCUSED 0x00800
|
||||
#define LC_PIECE_CONTROL_POINT_5_SELECTED 0x01000
|
||||
#define LC_PIECE_CONTROL_POINT_5_FOCUSED 0x02000
|
||||
#define LC_PIECE_CONTROL_POINT_6_SELECTED 0x04000
|
||||
#define LC_PIECE_CONTROL_POINT_6_FOCUSED 0x08000
|
||||
#define LC_PIECE_CONTROL_POINT_7_SELECTED 0x10000
|
||||
#define LC_PIECE_CONTROL_POINT_7_FOCUSED 0x20000
|
||||
#define LC_PIECE_CONTROL_POINT_8_SELECTED 0x40000
|
||||
#define LC_PIECE_CONTROL_POINT_8_FOCUSED 0x80000
|
||||
#define LC_PIECE_HIDDEN 0x000001
|
||||
#define LC_PIECE_PIVOT_POINT_VALID 0x000002
|
||||
#define LC_PIECE_POSITION_SELECTED 0x000004
|
||||
#define LC_PIECE_POSITION_FOCUSED 0x000008
|
||||
#define LC_PIECE_CONTROL_POINT_1_SELECTED 0x000010
|
||||
#define LC_PIECE_CONTROL_POINT_1_FOCUSED 0x000020
|
||||
#define LC_PIECE_CONTROL_POINT_2_SELECTED 0x000040
|
||||
#define LC_PIECE_CONTROL_POINT_2_FOCUSED 0x000080
|
||||
#define LC_PIECE_CONTROL_POINT_3_SELECTED 0x000100
|
||||
#define LC_PIECE_CONTROL_POINT_3_FOCUSED 0x000200
|
||||
#define LC_PIECE_CONTROL_POINT_4_SELECTED 0x000400
|
||||
#define LC_PIECE_CONTROL_POINT_4_FOCUSED 0x000800
|
||||
#define LC_PIECE_CONTROL_POINT_5_SELECTED 0x001000
|
||||
#define LC_PIECE_CONTROL_POINT_5_FOCUSED 0x002000
|
||||
#define LC_PIECE_CONTROL_POINT_6_SELECTED 0x004000
|
||||
#define LC_PIECE_CONTROL_POINT_6_FOCUSED 0x008000
|
||||
#define LC_PIECE_CONTROL_POINT_7_SELECTED 0x010000
|
||||
#define LC_PIECE_CONTROL_POINT_7_FOCUSED 0x020000
|
||||
#define LC_PIECE_CONTROL_POINT_8_SELECTED 0x040000
|
||||
#define LC_PIECE_CONTROL_POINT_8_FOCUSED 0x080000
|
||||
#define LC_PIECE_CONTROL_POINT_9_SELECTED 0x100000
|
||||
#define LC_PIECE_CONTROL_POINT_9_FOCUSED 0x200000
|
||||
#define LC_PIECE_CONTROL_POINT_10_SELECTED 0x400000
|
||||
#define LC_PIECE_CONTROL_POINT_10_FOCUSED 0x800000
|
||||
|
||||
#define LC_PIECE_SELECTION_MASK (LC_PIECE_POSITION_SELECTED | LC_PIECE_CONTROL_POINT_1_SELECTED | LC_PIECE_CONTROL_POINT_2_SELECTED | LC_PIECE_CONTROL_POINT_3_SELECTED | LC_PIECE_CONTROL_POINT_4_SELECTED | LC_PIECE_CONTROL_POINT_5_SELECTED | LC_PIECE_CONTROL_POINT_6_SELECTED | LC_PIECE_CONTROL_POINT_7_SELECTED | LC_PIECE_CONTROL_POINT_8_SELECTED)
|
||||
#define LC_PIECE_FOCUS_MASK (LC_PIECE_POSITION_FOCUSED | LC_PIECE_CONTROL_POINT_1_FOCUSED | LC_PIECE_CONTROL_POINT_2_FOCUSED | LC_PIECE_CONTROL_POINT_3_FOCUSED | LC_PIECE_CONTROL_POINT_4_FOCUSED | LC_PIECE_CONTROL_POINT_5_FOCUSED | LC_PIECE_CONTROL_POINT_6_FOCUSED | LC_PIECE_CONTROL_POINT_7_FOCUSED | LC_PIECE_CONTROL_POINT_8_FOCUSED)
|
||||
#define LC_MAX_CONTROL_POINTS 10
|
||||
|
||||
#define LC_PIECE_CONTROL_POINT_SELECTION_MASK (LC_PIECE_CONTROL_POINT_1_SELECTED | LC_PIECE_CONTROL_POINT_2_SELECTED | LC_PIECE_CONTROL_POINT_3_SELECTED | LC_PIECE_CONTROL_POINT_4_SELECTED | LC_PIECE_CONTROL_POINT_5_SELECTED | LC_PIECE_CONTROL_POINT_6_SELECTED | LC_PIECE_CONTROL_POINT_7_SELECTED | LC_PIECE_CONTROL_POINT_8_SELECTED | LC_PIECE_CONTROL_POINT_9_SELECTED | LC_PIECE_CONTROL_POINT_10_SELECTED)
|
||||
#define LC_PIECE_CONTROL_POINT_FOCUS_MASK (LC_PIECE_CONTROL_POINT_1_FOCUSED | LC_PIECE_CONTROL_POINT_2_FOCUSED | LC_PIECE_CONTROL_POINT_3_FOCUSED | LC_PIECE_CONTROL_POINT_4_FOCUSED | LC_PIECE_CONTROL_POINT_5_FOCUSED | LC_PIECE_CONTROL_POINT_6_FOCUSED | LC_PIECE_CONTROL_POINT_7_FOCUSED | LC_PIECE_CONTROL_POINT_8_FOCUSED | LC_PIECE_CONTROL_POINT_9_FOCUSED | LC_PIECE_CONTROL_POINT_10_FOCUSED)
|
||||
|
||||
#define LC_PIECE_SELECTION_MASK (LC_PIECE_POSITION_SELECTED | LC_PIECE_CONTROL_POINT_SELECTION_MASK)
|
||||
#define LC_PIECE_FOCUS_MASK (LC_PIECE_POSITION_FOCUSED | LC_PIECE_CONTROL_POINT_FOCUS_MASK)
|
||||
|
||||
enum lcPieceSection
|
||||
{
|
||||
LC_PIECE_SECTION_POSITION,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_1,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_FIRST,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_1 = LC_PIECE_SECTION_CONTROL_POINT_FIRST,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_2,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_3,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_4,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_5,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_6,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_7,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_8
|
||||
LC_PIECE_SECTION_CONTROL_POINT_8,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_9,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_10,
|
||||
LC_PIECE_SECTION_CONTROL_POINT_LAST = LC_PIECE_SECTION_CONTROL_POINT_10
|
||||
};
|
||||
|
||||
#define LC_PIECE_SECTION_INVALID (~0U)
|
||||
|
@ -144,6 +157,20 @@ public:
|
|||
else
|
||||
mState &= ~(LC_PIECE_CONTROL_POINT_8_SELECTED | LC_PIECE_CONTROL_POINT_8_FOCUSED);
|
||||
break;
|
||||
|
||||
case LC_PIECE_SECTION_CONTROL_POINT_9:
|
||||
if (Selected)
|
||||
mState |= LC_PIECE_CONTROL_POINT_9_SELECTED;
|
||||
else
|
||||
mState &= ~(LC_PIECE_CONTROL_POINT_9_SELECTED | LC_PIECE_CONTROL_POINT_9_FOCUSED);
|
||||
break;
|
||||
|
||||
case LC_PIECE_SECTION_CONTROL_POINT_10:
|
||||
if (Selected)
|
||||
mState |= LC_PIECE_CONTROL_POINT_10_SELECTED;
|
||||
else
|
||||
mState &= ~(LC_PIECE_CONTROL_POINT_10_SELECTED | LC_PIECE_CONTROL_POINT_10_FOCUSED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,6 +209,12 @@ public:
|
|||
|
||||
case LC_PIECE_SECTION_CONTROL_POINT_8:
|
||||
return (mState & LC_PIECE_CONTROL_POINT_8_FOCUSED) != 0;
|
||||
|
||||
case LC_PIECE_SECTION_CONTROL_POINT_9:
|
||||
return (mState & LC_PIECE_CONTROL_POINT_9_FOCUSED) != 0;
|
||||
|
||||
case LC_PIECE_SECTION_CONTROL_POINT_10:
|
||||
return (mState & LC_PIECE_CONTROL_POINT_10_FOCUSED) != 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -253,6 +286,20 @@ public:
|
|||
else
|
||||
mState &= ~LC_PIECE_CONTROL_POINT_8_FOCUSED;
|
||||
break;
|
||||
|
||||
case LC_PIECE_SECTION_CONTROL_POINT_9:
|
||||
if (Focused)
|
||||
mState |= (LC_PIECE_CONTROL_POINT_9_SELECTED | LC_PIECE_CONTROL_POINT_9_FOCUSED);
|
||||
else
|
||||
mState &= ~LC_PIECE_CONTROL_POINT_9_FOCUSED;
|
||||
break;
|
||||
|
||||
case LC_PIECE_SECTION_CONTROL_POINT_10:
|
||||
if (Focused)
|
||||
mState |= (LC_PIECE_CONTROL_POINT_10_SELECTED | LC_PIECE_CONTROL_POINT_10_FOCUSED);
|
||||
else
|
||||
mState &= ~LC_PIECE_CONTROL_POINT_10_FOCUSED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,6 +332,12 @@ public:
|
|||
if (mState & LC_PIECE_CONTROL_POINT_8_FOCUSED)
|
||||
return LC_PIECE_SECTION_CONTROL_POINT_8;
|
||||
|
||||
if (mState & LC_PIECE_CONTROL_POINT_9_FOCUSED)
|
||||
return LC_PIECE_SECTION_CONTROL_POINT_9;
|
||||
|
||||
if (mState & LC_PIECE_CONTROL_POINT_10_FOCUSED)
|
||||
return LC_PIECE_SECTION_CONTROL_POINT_10;
|
||||
|
||||
return LC_PIECE_SECTION_INVALID;
|
||||
}
|
||||
|
||||
|
@ -323,6 +376,12 @@ public:
|
|||
|
||||
case LC_PIECE_SECTION_CONTROL_POINT_8:
|
||||
return lcMul(mControlPoints[7].Transform, mModelWorld).GetTranslation();
|
||||
|
||||
case LC_PIECE_SECTION_CONTROL_POINT_9:
|
||||
return lcMul(mControlPoints[8].Transform, mModelWorld).GetTranslation();
|
||||
|
||||
case LC_PIECE_SECTION_CONTROL_POINT_10:
|
||||
return lcMul(mControlPoints[9].Transform, mModelWorld).GetTranslation();
|
||||
}
|
||||
|
||||
return lcVector3(0.0f, 0.0f, 0.0f);
|
||||
|
@ -408,6 +467,9 @@ public:
|
|||
void MovePivotPoint(const lcVector3& Distance);
|
||||
void RotatePivotPoint(const lcMatrix33& RotationMatrix);
|
||||
|
||||
bool CanAddControlPoint() const;
|
||||
bool CanRemoveControlPoint() const;
|
||||
|
||||
bool InsertControlPoint(const lcVector3& WorldStart, const lcVector3& WorldEnd);
|
||||
bool RemoveFocusedControlPoint();
|
||||
|
||||
|
|
|
@ -1083,9 +1083,9 @@ void View::DrawSelectMoveOverlay()
|
|||
lcPiece* Piece = (lcPiece*)Focus;
|
||||
quint32 Section = Piece->GetFocusSection();
|
||||
|
||||
if (Section >= LC_PIECE_SECTION_CONTROL_POINT_1 && Section <= LC_PIECE_SECTION_CONTROL_POINT_8 && Piece->mPieceInfo->GetSynthInfo() && Piece->mPieceInfo->GetSynthInfo()->IsCurve())
|
||||
if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST && Section <= LC_PIECE_SECTION_CONTROL_POINT_LAST && Piece->mPieceInfo->GetSynthInfo() && Piece->mPieceInfo->GetSynthInfo()->IsCurve())
|
||||
{
|
||||
int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1;
|
||||
int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST;
|
||||
float Strength = Piece->GetControlPoints()[ControlPointIndex].Scale;
|
||||
const float ScaleStart = 2.0f;
|
||||
float Length = ScaleStart + Strength / OverlayScale;
|
||||
|
@ -2122,7 +2122,7 @@ void View::UpdateTrackTool()
|
|||
lcPiece* Piece = (lcPiece*)Focus;
|
||||
quint32 Section = Piece->GetFocusSection();
|
||||
|
||||
if (Section >= LC_PIECE_SECTION_CONTROL_POINT_1 && Section <= LC_PIECE_SECTION_CONTROL_POINT_8)
|
||||
if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST && Section <= LC_PIECE_SECTION_CONTROL_POINT_LAST)
|
||||
ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1;
|
||||
}
|
||||
|
||||
|
@ -3122,7 +3122,7 @@ void View::OnMouseMove()
|
|||
lcPiece* Piece = (lcPiece*)Focus;
|
||||
quint32 Section = Piece->GetFocusSection();
|
||||
|
||||
if (Section >= LC_PIECE_SECTION_CONTROL_POINT_1 && Section <= LC_PIECE_SECTION_CONTROL_POINT_8)
|
||||
if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST && Section <= LC_PIECE_SECTION_CONTROL_POINT_LAST)
|
||||
{
|
||||
const float ScaleMax = 200.0f;
|
||||
const float OverlayScale = GetOverlayScale();
|
||||
|
|
|
@ -173,7 +173,7 @@ void lcQModelListDialog::on_ExportModel_clicked()
|
|||
|
||||
QString SaveFileName = QFileInfo(QDir(lcGetProfileString(LC_PROFILE_PROJECTS_PATH)), CurrentItem->text()).absoluteFilePath();
|
||||
|
||||
SaveFileName = QFileDialog::getSaveFileName(this, tr("Save Model"), SaveFileName, tr("Supported Files (*.ldr *.dat);;All Files (*.*)"));
|
||||
SaveFileName = QFileDialog::getSaveFileName(this, tr("Export Model"), SaveFileName, tr("Supported Files (*.ldr *.dat);;All Files (*.*)"));
|
||||
|
||||
if (SaveFileName.isEmpty())
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue