diff --git a/common/camera.cpp b/common/camera.cpp index 536d6838..f4da2ebc 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -56,6 +56,19 @@ lcCamera::~lcCamera() { } +void lcCamera::CopyProperties(const lcCamera& Other) +{ + m_fovy = Other.m_fovy; + m_zNear = Other.m_zNear; + m_zFar = Other.m_zFar; + + mPosition = Other.mPosition; + mTargetPosition = Other.mTargetPosition; + mUpVector = Other.mUpVector; + + SetOrtho(Other.IsOrtho()); +} + QString lcCamera::GetCameraTypeString(lcCameraType CameraType) { switch (CameraType) diff --git a/common/camera.h b/common/camera.h index 7c35778d..2b1802e6 100644 --- a/common/camera.h +++ b/common/camera.h @@ -48,7 +48,7 @@ class lcCamera : public lcObject public: lcCamera(bool Simple); lcCamera(float ex, float ey, float ez, float tx, float ty, float tz); - ~lcCamera(); + virtual ~lcCamera(); lcCamera(const lcCamera&) = delete; lcCamera(lcCamera&&) = delete; @@ -59,6 +59,8 @@ public: static QStringList GetCameraTypeStrings(); static lcViewpoint GetViewpoint(const QString& ViewpointName); + void CopyProperties(const lcCamera& Other); + QString GetName() const override { return mName; diff --git a/common/lc_lxf.cpp b/common/lc_lxf.cpp index 11038045..892e45eb 100644 --- a/common/lc_lxf.cpp +++ b/common/lc_lxf.cpp @@ -179,7 +179,7 @@ bool lcImportLXFMLFile(const QString& FileData, std::vector& Pieces, s lcVector4(-WorldMatrix[2][0], WorldMatrix[2][1], WorldMatrix[2][2], 0.0f), lcVector4(WorldMatrix[3][0] * 25.0f, -WorldMatrix[3][1] * 25.0f, -WorldMatrix[3][2] * 25.0f, 1.0f)); lcPiece* Piece = new lcPiece(nullptr); - Piece->SetPieceInfo(Info, QString(), false); + Piece->SetPieceInfo(Info, QString(), false, true); Piece->Initialize(lcMatrix44LDrawToLeoCAD(WorldMatrix), 1); Piece->SetColorCode(ColorCode); Pieces.push_back(Piece); diff --git a/common/lc_model.cpp b/common/lc_model.cpp index d6663842..f8985962 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -331,6 +331,15 @@ void lcModel::UpdatePieceInfo(std::vector& UpdatedModels) mPieceInfo->SetBoundingBox(Min, Max); } +lcCamera* lcModel::GetCamera(const QString& Name) const +{ + for (const std::unique_ptr& Camera : mCameras) + if (Camera->GetName() == Name) + return Camera.get(); + + return nullptr; +} + void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly, lcStep LastStep) const { const QLatin1String LineEnding("\r\n"); @@ -737,7 +746,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project) lcVector4(-Matrix[4], -Matrix[6], Matrix[5], 0.0f), lcVector4(Matrix[12], Matrix[14], -Matrix[13], 1.0f)); Piece->SetFileLine(mFileLines.size()); - Piece->SetPieceInfo(Info, PartId, false); + Piece->SetPieceInfo(Info, PartId, false, true); Piece->Initialize(Transform, CurrentStep); Piece->SetColorCode(ColorCode); Piece->VerifyControlPoints(ControlPoints); @@ -1073,7 +1082,7 @@ bool lcModel::LoadInventory(const QByteArray& Inventory) while (Quantity--) { lcPiece* Piece = new lcPiece(nullptr); - Piece->SetPieceInfo(Info, QString(), false); + Piece->SetPieceInfo(Info, QString(), false, true); Piece->Initialize(lcMatrix44Identity(), 1); Piece->SetColorCode(ColorCode); AddPiece(Piece); @@ -1714,6 +1723,167 @@ void lcModel::RunSelectionAction(const lcModelActionSelection* ModelActionSelect } } +void lcModel::BeginMouseToolAction(lcTool Tool, lcView* View) +{ + std::unique_ptr ModelActionMouseTool = std::make_unique(Tool); + + switch (Tool) + { + case lcTool::Insert: + case lcTool::PointLight: + case lcTool::SpotLight: + case lcTool::DirectionalLight: + case lcTool::AreaLight: + break; + +// case lcTool::Camera: +// SaveCheckpoint(tr("New Camera")); +// break; + + case lcTool::Select: + break; + + case lcTool::Move: + case lcTool::Rotate: + ModelActionMouseTool->SaveSelectionStartState(this); + break; + + case lcTool::Eraser: + case lcTool::Paint: + case lcTool::ColorPicker: + break; + + case lcTool::Zoom: + case lcTool::Pan: + case lcTool::RotateView: + case lcTool::Roll: + ModelActionMouseTool->SetCameraStartState(View->GetCamera()); + break; + + case lcTool::ZoomRegion: + break; + + case lcTool::Count: + break; + } + + mActionSequence.emplace_back(std::move(ModelActionMouseTool)); +} + +void lcModel::EndMouseToolAction(lcTool Tool, lcView* View, const QString& Description) +{ + if (mActionSequence.empty()) + return; + + lcModelActionMouseTool* ModelActionMouseTool = dynamic_cast(mActionSequence.back().get()); + + if (!ModelActionMouseTool || Tool != ModelActionMouseTool->GetTool()) + return; + + switch (Tool) + { + case lcTool::Insert: + case lcTool::PointLight: + case lcTool::SpotLight: + case lcTool::DirectionalLight: + case lcTool::AreaLight: + break; + +// case lcTool::Camera: +// SaveCheckpoint(tr("New Camera")); +// break; + + case lcTool::Select: + break; + + case lcTool::Move: + case lcTool::Rotate: + ModelActionMouseTool->SaveSelectionEndState(this); + break; + + case lcTool::Eraser: + case lcTool::Paint: + case lcTool::ColorPicker: + break; + + case lcTool::Zoom: + case lcTool::Pan: + case lcTool::RotateView: + case lcTool::Roll: + ModelActionMouseTool->SetCameraEndState(View->GetCamera()); + break; + + case lcTool::ZoomRegion: + break; + + case lcTool::Count: + break; + } + + RecordSelectionAction(lcModelActionSelectionMode::Set); + EndActionSequence(Description); +} + +void lcModel::RunMouseToolAction(const lcModelActionMouseTool* ModelActionMouseTool, bool Apply) +{ + if (!ModelActionMouseTool) + return; + + lcTool Tool = ModelActionMouseTool->GetTool(); + + switch (Tool) + { + case lcTool::Insert: + case lcTool::PointLight: + case lcTool::SpotLight: + case lcTool::DirectionalLight: + case lcTool::AreaLight: + break; + +// case lcTool::Camera: +// SaveCheckpoint(tr("New Camera")); +// break; + + case lcTool::Select: + break; + + case lcTool::Move: + case lcTool::Rotate: + if (Apply) + ModelActionMouseTool->LoadSelectionEndState(this); + else + ModelActionMouseTool->LoadSelectionStartState(this); + SetCurrentStep(mCurrentStep); + break; + + case lcTool::Eraser: + case lcTool::Paint: + case lcTool::ColorPicker: + break; + + case lcTool::Zoom: + case lcTool::Pan: + case lcTool::RotateView: + case lcTool::Roll: + if (lcCamera* Camera = GetCamera(ModelActionMouseTool->GetCameraName())) + { + const QByteArray& State = Apply ? ModelActionMouseTool->GetEndState() : ModelActionMouseTool->GetStartState(); + QDataStream Stream(const_cast(&State), QIODevice::ReadOnly); + + Camera->LoadKeyFrames(Stream); + + SetCurrentStep(mCurrentStep); + } + break; + + case lcTool::ZoomRegion: + break; + + case lcTool::Count: + break; + } +} + void lcModel::RecordAddPiecesAction(const std::vector& PieceInfoTransforms, lcModelActionAddPieceSelectionMode SelectionMode) { std::unique_ptr ModelActionAddPieces = std::make_unique(mCurrentStep, SelectionMode); @@ -2168,6 +2338,8 @@ void lcModel::PerformActionSequence(const std::vector(ModelAction)) RunSelectionAction(ModelActionSelection, Apply); + else if (const lcModelActionMouseTool* ModelActionMouseTool = dynamic_cast(ModelAction)) + RunMouseToolAction(ModelActionMouseTool, Apply); else if (const lcModelActionAddPieces* ModelActionAddPieces = dynamic_cast(ModelAction)) RunAddPiecesAction(ModelActionAddPieces, Apply); else if (const lcModelActionAddLight* ModelActionAddLight = dynamic_cast(ModelAction)) @@ -2215,8 +2387,11 @@ void lcModel::EndActionSequence(const QString& Description) gMainWindow->UpdateUndoRedo(!mUndoHistory.empty() ? mUndoHistory.front()->Description : nullptr, !mRedoHistory.empty() ? mRedoHistory.front()->Description : nullptr); } -void lcModel::CancelActionSequence() +void lcModel::RevertActionSequence() { + PerformActionSequence(mActionSequence, false); + + mActionSequence.clear(); } void lcModel::SaveCheckpoint(const QString& ) @@ -3328,7 +3503,7 @@ void lcModel::InlineSelectedModels() if (ColorIndex == gDefaultColor) ColorIndex = Piece->GetColorIndex(); - NewPiece->SetPieceInfo(ModelPiece->mPieceInfo, ModelPiece->GetID(), true); + NewPiece->SetPieceInfo(ModelPiece->mPieceInfo, ModelPiece->GetID(), true, true); NewPiece->Initialize(lcMul(ModelPiece->mModelWorld, Piece->mModelWorld), Piece->GetStepShow()); NewPiece->SetColorIndex(ColorIndex); NewPiece->UpdatePosition(mCurrentStep); @@ -3916,7 +4091,7 @@ void lcModel::EndPropertyEdit(lcObjectPropertyId PropertyId, bool Accept) { if (!Accept) { - CancelActionSequence(); + RevertActionSequence(); return; } @@ -4858,7 +5033,7 @@ void lcModel::FindReplacePiece(bool SearchForward, bool FindAll, bool Replace) Piece->SetColorIndex(Params.ReplaceColorIndex); if (ReplacePieceInfo) - Piece->SetPieceInfo(Params.ReplacePieceInfo, QString(), true); + Piece->SetPieceInfo(Params.ReplacePieceInfo, QString(), true, true); }; size_t StartIndex = mPieces.size() - 1; @@ -4979,17 +5154,68 @@ void lcModel::RedoAction() gMainWindow->UpdateUndoRedo(!mUndoHistory.empty() ? mUndoHistory.front()->Description : nullptr, !mRedoHistory.empty() ? mRedoHistory.front()->Description : nullptr); } -void lcModel::BeginMouseTool() +void lcModel::BeginMouseTool(lcTool Tool, lcView* View) { + switch (Tool) + { + case lcTool::Insert: + case lcTool::PointLight: + case lcTool::SpotLight: + case lcTool::DirectionalLight: + case lcTool::AreaLight: + break; + +// case lcTool::Camera: +// { +// lcVector3 Position = GetCameraLightInsertPosition(); +// lcVector3 Target = Position + lcVector3(0.1f, 0.1f, 0.1f); +// ActiveModel->BeginCameraTool(Position, Target); +// } +// break; + + case lcTool::Select: + break; + + case lcTool::Move: + case lcTool::Rotate: + BeginActionSequence(); + RecordSelectionAction(lcModelActionSelectionMode::Set); + BeginMouseToolAction(Tool, View); + break; + + case lcTool::Eraser: + case lcTool::Paint: + case lcTool::ColorPicker: + break; + + case lcTool::Pan: + case lcTool::Zoom: + case lcTool::RotateView: + case lcTool::Roll: + if (!View->GetCamera()->IsSimple()) + { + BeginActionSequence(); + RecordSelectionAction(lcModelActionSelectionMode::Set); + BeginMouseToolAction(Tool, View); + } + break; + + case lcTool::ZoomRegion: + break; + + case lcTool::Count: + break; + } + mMouseToolDistance = lcVector3(0.0f, 0.0f, 0.0f); mMouseToolFirstMove = true; } -void lcModel::EndMouseTool(lcTool Tool, bool Accept) +void lcModel::EndMouseTool(lcTool Tool, lcView* View, bool Accept) { if (!Accept) { - CancelActionSequence(); + RevertActionSequence(); return; } @@ -5002,19 +5228,19 @@ void lcModel::EndMouseTool(lcTool Tool, bool Accept) case lcTool::AreaLight: break; - case lcTool::Camera: - SaveCheckpoint(tr("New Camera")); - break; +// case lcTool::Camera: +// SaveCheckpoint(tr("New Camera")); +// break; case lcTool::Select: break; case lcTool::Move: - SaveCheckpoint(tr("Move")); + EndMouseToolAction(Tool, View, tr("Move")); break; case lcTool::Rotate: - SaveCheckpoint(tr("Rotate")); + EndMouseToolAction(Tool, View, tr("Rotate")); break; case lcTool::Eraser: @@ -5023,23 +5249,23 @@ void lcModel::EndMouseTool(lcTool Tool, bool Accept) break; case lcTool::Zoom: - if (!gMainWindow->GetActiveView()->GetCamera()->IsSimple()) - SaveCheckpoint(tr("Zoom")); + if (!View->GetCamera()->IsSimple()) + EndMouseToolAction(Tool, View, tr("Zoom")); break; case lcTool::Pan: - if (!gMainWindow->GetActiveView()->GetCamera()->IsSimple()) - SaveCheckpoint(tr("Pan")); + if (!View->GetCamera()->IsSimple()) + EndMouseToolAction(Tool, View, tr("Pan")); break; case lcTool::RotateView: - if (!gMainWindow->GetActiveView()->GetCamera()->IsSimple()) - SaveCheckpoint(tr("Orbit")); + if (!View->GetCamera()->IsSimple()) + EndMouseToolAction(Tool, View, tr("Orbit")); break; case lcTool::Roll: - if (!gMainWindow->GetActiveView()->GetCamera()->IsSimple()) - SaveCheckpoint(tr("Roll")); + if (!View->GetCamera()->IsSimple()) + EndMouseToolAction(Tool, View, tr("Roll")); break; case lcTool::ZoomRegion: diff --git a/common/lc_model.h b/common/lc_model.h index 150f1940..b64c98e3 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -6,6 +6,7 @@ enum class lcObjectPropertyId; class lcModelAction; class lcModelActionSelection; +class lcModelActionMouseTool; class lcModelActionAddPieces; class lcModelActionAddLight; class lcModelActionGroupPieces; @@ -168,6 +169,8 @@ public: return mCameras; } + lcCamera* GetCamera(const QString& Name) const; + const std::vector>& GetLights() const { return mLights; @@ -351,8 +354,8 @@ public: return mMouseToolDistance; } - void BeginMouseTool(); - void EndMouseTool(lcTool Tool, bool Accept); + void BeginMouseTool(lcTool Tool, lcView* View); + void EndMouseTool(lcTool Tool, lcView* View, bool Accept); void InsertPieceToolClicked(const std::vector& PieceInfoTransforms); void InsertLightToolClicked(const lcVector3& Position, lcLightType LightType); void BeginCameraTool(const lcVector3& Position, const lcVector3& Target); @@ -407,6 +410,9 @@ protected: void RecordSelectionAction(lcModelActionSelectionMode ModelActionSelectionMode); void RunSelectionAction(const lcModelActionSelection* ModelActionSelection, bool Apply); + void BeginMouseToolAction(lcTool Tool, lcView* View); + void EndMouseToolAction(lcTool Tool, lcView* View, const QString& Description); + void RunMouseToolAction(const lcModelActionMouseTool* ModelActionMouseTool, bool Apply); void RecordAddPiecesAction(const std::vector& PieceInfoTransforms, lcModelActionAddPieceSelectionMode SelectionMode); void RunAddPiecesAction(const lcModelActionAddPieces* ModelActionAddPieces, bool Apply); void RecordAddLightAction(const lcVector3& Position, lcLightType LightType); @@ -423,7 +429,7 @@ protected: void PerformActionSequence(const std::vector>& ActionSequence, bool Apply); void BeginActionSequence(); void EndActionSequence(const QString& Description); - void CancelActionSequence(); + void RevertActionSequence(); void SaveCheckpoint(const QString& Description); void LoadCheckPoint(lcModelHistoryEntry* CheckPoint, bool Apply); diff --git a/common/lc_modelaction.cpp b/common/lc_modelaction.cpp index 91a317cd..58319f62 100644 --- a/common/lc_modelaction.cpp +++ b/common/lc_modelaction.cpp @@ -107,6 +107,105 @@ std::tuple, lcObject*, uint32_t> lcModelActionSelection:: return { SelectedObjects, FocusObject, mFocusSection }; } +lcModelActionMouseTool::lcModelActionMouseTool(lcTool Tool) + : mTool( Tool ) +{ +} + +void lcModelActionMouseTool::SetCameraStartState(const lcCamera* Camera) +{ + QDataStream Stream(&mStartState, QIODevice::WriteOnly); + + Camera->SaveKeyFrames(Stream); + + mCameraName = Camera->GetName(); +} + +void lcModelActionMouseTool::SetCameraEndState(const lcCamera* Camera) +{ + QDataStream Stream(&mEndState, QIODevice::WriteOnly); + + Camera->SaveKeyFrames(Stream); +} + +void lcModelActionMouseTool::SaveSelectionStartState(const lcModel* Model) +{ + SaveSelectionState(Model, mStartState); +} + +void lcModelActionMouseTool::LoadSelectionStartState(lcModel* Model) const +{ + LoadSelectionState(Model, mStartState); +} + +void lcModelActionMouseTool::LoadSelectionEndState(lcModel* Model) const +{ + LoadSelectionState(Model, mEndState); +} + +void lcModelActionMouseTool::SaveSelectionEndState(const lcModel* Model) +{ + SaveSelectionState(Model, mEndState); +} + +void lcModelActionMouseTool::SaveSelectionState(const lcModel* Model, QByteArray& State) +{ + QTextStream Stream(&State, QIODevice::WriteOnly); + + Model->SaveLDraw(Stream, false, 0); +} + +void lcModelActionMouseTool::LoadSelectionState(lcModel* Model, const QByteArray& State) +{ + QBuffer Buffer(const_cast(&State)); + Buffer.open(QIODevice::ReadOnly); + + std::unique_ptr SavedModel = std::make_unique(QString(), Model->GetProject(), false); + SavedModel->LoadLDraw(Buffer, Model->GetProject()); + + const std::vector>& Pieces = Model->GetPieces(); + const std::vector>& SavedPieces = SavedModel->GetPieces(); + + if (Pieces.size() != SavedPieces.size()) + return; + + for (size_t PieceIndex = 0; PieceIndex < Pieces.size(); PieceIndex++) + { + lcPiece* Piece = Pieces[PieceIndex].get(); + + if (Piece->IsSelected()) + Piece->CopyProperties(*SavedPieces[PieceIndex].get()); + } + + const std::vector>& Cameras = Model->GetCameras(); + const std::vector>& SavedCameras = SavedModel->GetCameras(); + + if (Cameras.size() != SavedCameras.size()) + return; + + for (size_t CameraIndex = 0; CameraIndex < Cameras.size(); CameraIndex++) + { + lcCamera* Camera = Cameras[CameraIndex].get(); + + if (Camera->IsSelected()) + Camera->CopyProperties(*SavedCameras[CameraIndex].get()); + } + + const std::vector>& Lights = Model->GetLights(); + const std::vector>& SavedLights = SavedModel->GetLights(); + + if (Lights.size() != SavedLights.size()) + return; + + for (size_t LightIndex = 0; LightIndex < Lights.size(); LightIndex++) + { + lcLight* Light = Lights[LightIndex].get(); + + if (Light->IsSelected()) + Light->CopyProperties(*SavedLights[LightIndex].get()); + } +} + lcModelActionAddPieces::lcModelActionAddPieces(lcStep Step, lcModelActionAddPieceSelectionMode SelectionMode) : mStep(Step), mSelectionMode(SelectionMode) { diff --git a/common/lc_modelaction.h b/common/lc_modelaction.h index a0b46700..8b800e70 100644 --- a/common/lc_modelaction.h +++ b/common/lc_modelaction.h @@ -5,6 +5,7 @@ struct lcInsertPieceInfo; enum class lcObjectType; enum class lcLightType; +enum class lcTool; class lcModelAction { @@ -45,6 +46,50 @@ protected: lcModelActionSelectionMode mMode = lcModelActionSelectionMode::Clear; }; +class lcModelActionMouseTool : public lcModelAction +{ +public: + lcModelActionMouseTool(lcTool Tool); + virtual ~lcModelActionMouseTool() = default; + + void SaveSelectionStartState(const lcModel* Model); + void LoadSelectionStartState(lcModel* Model) const; + void SaveSelectionEndState(const lcModel* Model); + void LoadSelectionEndState(lcModel* Model) const; + + void SetCameraStartState(const lcCamera* Camera); + void SetCameraEndState(const lcCamera* Camera); + + const QByteArray& GetStartState() const + { + return mStartState; + } + + const QByteArray& GetEndState() const + { + return mEndState; + } + + lcTool GetTool() const + { + return mTool; + } + + const QString& GetCameraName() const + { + return mCameraName; + } + +protected: + static void SaveSelectionState(const lcModel* Model, QByteArray& State); + static void LoadSelectionState(lcModel* Model, const QByteArray& State); + + lcTool mTool; + QString mCameraName; + QByteArray mStartState; + QByteArray mEndState; +}; + enum class lcModelActionAddPieceSelectionMode { FocusLast, diff --git a/common/lc_objectproperty.cpp b/common/lc_objectproperty.cpp index 1a2e7850..def6ac03 100644 --- a/common/lc_objectproperty.cpp +++ b/common/lc_objectproperty.cpp @@ -321,13 +321,17 @@ void lcObjectProperty::SaveToDataStream(QDataStream& Stream) const size_t KeyCount = mKeys.size(); size_t DataSize = KeyCount * sizeof(lcObjectPropertyKey); - Stream.writeRawData(reinterpret_cast(&KeyCount), sizeof(KeyCount)); + Stream.writeRawData(reinterpret_cast(&mValue), sizeof(mValue)); + Stream.writeRawData(reinterpret_cast(&KeyCount), sizeof(KeyCount)); Stream.writeRawData(reinterpret_cast(mKeys.data()), DataSize); } template bool lcObjectProperty::LoadFromDataStream(QDataStream& Stream) { + if (Stream.readRawData(reinterpret_cast(&mValue), sizeof(mValue)) != sizeof(mValue)) + return false; + size_t KeyCount; if (Stream.readRawData(reinterpret_cast(&KeyCount), sizeof(KeyCount)) != sizeof(KeyCount)) diff --git a/common/lc_view.cpp b/common/lc_view.cpp index 842b7b2f..3f08632d 100644 --- a/common/lc_view.cpp +++ b/common/lc_view.cpp @@ -2276,7 +2276,7 @@ void lcView::StartPanGesture() lcModel* ActiveModel = GetActiveModel(); StartPan(mWidth / 2, mHeight / 2); - ActiveModel->BeginMouseTool(); + ActiveModel->BeginMouseTool(lcTool::Pan, this); } void lcView::UpdatePanGesture(int dx, int dy) @@ -2336,7 +2336,7 @@ void lcView::EndPanGesture(bool Accept) { lcModel* ActiveModel = GetActiveModel(); - ActiveModel->EndMouseTool(lcTool::Pan, Accept); + ActiveModel->EndMouseTool(lcTool::Pan, this, Accept); } void lcView::StartTracking(lcTrackButton TrackButton) @@ -2370,7 +2370,7 @@ void lcView::StartTracking(lcTrackButton TrackButton) case lcTool::Move: case lcTool::Rotate: - ActiveModel->BeginMouseTool(); + ActiveModel->BeginMouseTool(Tool, this); break; case lcTool::Eraser: @@ -2380,13 +2380,13 @@ void lcView::StartTracking(lcTrackButton TrackButton) case lcTool::Pan: StartPan(mMouseX, mMouseY); - ActiveModel->BeginMouseTool(); + ActiveModel->BeginMouseTool(Tool, this); break; case lcTool::Zoom: case lcTool::RotateView: case lcTool::Roll: - ActiveModel->BeginMouseTool(); + ActiveModel->BeginMouseTool(Tool, this); break; case lcTool::ZoomRegion: @@ -2417,7 +2417,7 @@ void lcView::StopTracking(bool Accept) case lcTool::DirectionalLight: case lcTool::AreaLight: case lcTool::Camera: - ActiveModel->EndMouseTool(Tool, Accept); + ActiveModel->EndMouseTool(Tool, this, Accept); break; case lcTool::Select: @@ -2436,7 +2436,7 @@ void lcView::StopTracking(bool Accept) case lcTool::Move: case lcTool::Rotate: - ActiveModel->EndMouseTool(Tool, Accept); + ActiveModel->EndMouseTool(Tool, this, Accept); break; case lcTool::Eraser: @@ -2448,7 +2448,7 @@ void lcView::StopTracking(bool Accept) case lcTool::Pan: case lcTool::RotateView: case lcTool::Roll: - ActiveModel->EndMouseTool(Tool, Accept); + ActiveModel->EndMouseTool(Tool, this, Accept); break; case lcTool::ZoomRegion: diff --git a/common/light.cpp b/common/light.cpp index a8c6bcd0..0886b009 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -31,6 +31,29 @@ lcLight::lcLight(const lcVector3& Position, lcLightType LightType) UpdatePosition(1); } +void lcLight::CopyProperties(const lcLight& Other) +{ + mLightType = Other.mLightType; + mCastShadow = Other.mCastShadow; + mPosition = Other.mPosition; + mRotation = Other.mRotation; + mColor = Other.mColor; + mBlenderPower = Other.mBlenderPower; + mBlenderRadius = Other.mBlenderRadius; + mBlenderAngle = Other.mBlenderAngle; + mPOVRayPower = Other.mPOVRayPower; + mPOVRayFadeDistance = Other.mPOVRayFadeDistance; + mPOVRayFadePower = Other.mPOVRayFadePower; + mSpotConeAngle = Other.mSpotConeAngle; + mSpotPenumbraAngle = Other.mSpotPenumbraAngle; + mPOVRaySpotTightness = Other.mPOVRaySpotTightness; + mAreaShape = Other.mAreaShape; + mAreaSizeX = Other.mAreaSizeX; + mAreaSizeY = Other.mAreaSizeY; + mPOVRayAreaGridX = Other.mPOVRayAreaGridX; + mPOVRayAreaGridY = Other.mPOVRayAreaGridY; +} + QString lcLight::GetLightTypeString(lcLightType LightType) { switch (LightType) diff --git a/common/light.h b/common/light.h index fd1193a7..e0fdae29 100644 --- a/common/light.h +++ b/common/light.h @@ -47,6 +47,8 @@ public: static QString GetAreaShapeString(lcLightAreaShape LightAreaShape); static QStringList GetAreaShapeStrings(); + void CopyProperties(const lcLight& Other); + bool IsPointLight() const { return mLightType == lcLightType::Point; diff --git a/common/piece.cpp b/common/piece.cpp index e7e1b82e..ef6ef940 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -21,7 +21,7 @@ constexpr float LC_PIECE_CONTROL_POINT_SIZE = 10.0f; lcPiece::lcPiece(PieceInfo* Info) : lcObject(lcObjectType::Piece) { - SetPieceInfo(Info, QString(), true); + SetPieceInfo(Info, QString(), true, true); mColorIndex = gDefaultColor; mColorCode = 16; mStepShow = 1; @@ -33,7 +33,7 @@ lcPiece::lcPiece(PieceInfo* Info) lcPiece::lcPiece(const lcPiece& Other) : lcObject(lcObjectType::Piece) { - SetPieceInfo(Other.mPieceInfo, Other.mID, true); + SetPieceInfo(Other.mPieceInfo, Other.mID, true, true); mHidden = Other.mHidden; mSelected = Other.mSelected; mColorIndex = Other.mColorIndex; @@ -63,7 +63,29 @@ lcPiece::~lcPiece() delete mMesh; } -void lcPiece::SetPieceInfo(PieceInfo* Info, const QString& ID, bool Wait) +void lcPiece::CopyProperties(const lcPiece& Other) +{ + SetPieceInfo(Other.mPieceInfo, Other.mID, true, false); + + mPosition = Other.mPosition; + mRotation = Other.mRotation; + + mColorIndex = Other.mColorIndex; + mColorCode = Other.mColorCode; + + mStepShow = Other.mStepShow; + mStepHide = Other.mStepHide; + + mPivotPointValid = Other.mPivotPointValid; + mPivotMatrix = Other.mPivotMatrix; + + mControlPoints = Other.mControlPoints; + mTrainTrackConnections = Other.mTrainTrackConnections; + + UpdateMesh(); +} + +void lcPiece::SetPieceInfo(PieceInfo* Info, const QString& ID, bool Wait, bool UpdateSynthInfo) { lcPiecesLibrary* Library = lcGetPiecesLibrary(); @@ -79,15 +101,19 @@ void lcPiece::SetPieceInfo(PieceInfo* Info, const QString& ID, bool Wait) mID.clear(); mControlPoints.clear(); + delete mMesh; mMesh = nullptr; - const lcSynthInfo* SynthInfo = mPieceInfo ? mPieceInfo->GetSynthInfo() : nullptr; - - if (SynthInfo) + if (UpdateSynthInfo) { - SynthInfo->GetDefaultControlPoints(mControlPoints); - UpdateMesh(); + const lcSynthInfo* SynthInfo = mPieceInfo ? mPieceInfo->GetSynthInfo() : nullptr; + + if (SynthInfo) + { + SynthInfo->GetDefaultControlPoints(mControlPoints); + UpdateMesh(); + } } } @@ -98,7 +124,7 @@ bool lcPiece::SetPieceId(PieceInfo* Info) lcPiecesLibrary* Library = lcGetPiecesLibrary(); Library->ReleasePieceInfo(mPieceInfo); - SetPieceInfo(Info, QString(), true); + SetPieceInfo(Info, QString(), true, true); return true; } @@ -313,7 +339,7 @@ bool lcPiece::FileLoad(lcFile& file) strcat(name, ".dat"); PieceInfo* pInfo = lcGetPiecesLibrary()->FindPiece(name, nullptr, true, false); - SetPieceInfo(pInfo, QString(), true); + SetPieceInfo(pInfo, QString(), true, true); // 11 (0.77) if (version < 11) diff --git a/common/piece.h b/common/piece.h index b66c3851..bc2d6b85 100644 --- a/common/piece.h +++ b/common/piece.h @@ -28,12 +28,14 @@ class lcPiece : public lcObject public: lcPiece(PieceInfo* Info); lcPiece(const lcPiece& Other); - ~lcPiece(); + virtual ~lcPiece(); lcPiece(lcPiece&&) = delete; lcPiece& operator=(const lcPiece&) = delete; lcPiece& operator=(lcPiece&&) = delete; + void CopyProperties(const lcPiece& Other); + bool IsSelected() const override { return mSelected; @@ -182,7 +184,7 @@ public: void Initialize(const lcMatrix44& WorldMatrix, lcStep Step); const lcBoundingBox& GetBoundingBox() const; void CompareBoundingBox(lcVector3& Min, lcVector3& Max) const; - void SetPieceInfo(PieceInfo* Info, const QString& ID, bool Wait); + void SetPieceInfo(PieceInfo* Info, const QString& ID, bool Wait, bool UpdateSynthInfo); bool SetPieceId(PieceInfo* Info); bool FileLoad(lcFile& file);