Update to leozide/master

This commit is contained in:
cambrialas 2024-11-09 09:23:56 +01:00
parent 3c3da579c5
commit 511aaf7dd4
15 changed files with 4 additions and 956 deletions

View file

@ -1369,13 +1369,6 @@ const lcCommand gCommands[] =
QT_TRANSLATE_NOOP("Status", "Add a new minifig to the model"),
""
},
// LC_PIECE_TRAIN_TRACK_WIZARD
{
QT_TRANSLATE_NOOP("Action", "Piece.TrainTrackSystemWizard"),
QT_TRANSLATE_NOOP("Menu", "Train track network wizard..."),
QT_TRANSLATE_NOOP("Status", "Add a new train track network to the model"),
"Ctrl+T"
},
// LC_PIECE_ARRAY
{
QT_TRANSLATE_NOOP("Action", "Piece.Array"),

View file

@ -211,7 +211,6 @@ enum lcCommandId
LC_PIECE_ROTATE_PLUSZ,
LC_PIECE_ROTATE_MINUSZ,
LC_PIECE_MINIFIG_WIZARD,
LC_PIECE_TRAIN_TRACK_WIZARD,
LC_PIECE_ARRAY,
LC_PIECE_VIEW_SELECTED_MODEL,
LC_PIECE_MOVE_SELECTION_TO_MODEL,

View file

@ -557,7 +557,6 @@ void lcMainWindow::CreateMenus()
PieceMenu->addAction(mActions[LC_PIECE_PAINT_SELECTED]);
PieceMenu->addAction(mActions[LC_PIECE_ARRAY]);
PieceMenu->addAction(mActions[LC_PIECE_MINIFIG_WIZARD]);
PieceMenu->addAction(mActions[LC_PIECE_TRAIN_TRACK_WIZARD]);
PieceMenu->addAction(mActions[LC_PIECE_RESET_PIVOT_POINT]);
PieceMenu->addAction(mActions[LC_PIECE_REMOVE_KEY_FRAMES]);
PieceMenu->addSeparator();
@ -2987,11 +2986,6 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
ActiveModel->ShowMinifigDialog();
break;
case LC_PIECE_TRAIN_TRACK_WIZARD:
if (ActiveModel)
ActiveModel->ShowTrainTrackSystemDialog();
break;
case LC_PIECE_ARRAY:
if (ActiveModel)
ActiveModel->ShowArrayDialog();

View file

@ -15,11 +15,9 @@
#include "pieceinf.h"
#include "lc_view.h"
#include "minifig.h"
#include "traintracksystem.h"
#include "lc_arraydialog.h"
#include "lc_qselectdialog.h"
#include "lc_minifigdialog.h"
#include "lc_traintracksystemdialog.h"
#include "lc_groupdialog.h"
#include "lc_qeditgroupsdialog.h"
#include "lc_qpropertiesdialog.h"
@ -4718,44 +4716,6 @@ void lcModel::SetMinifig(const lcMinifig& Minifig)
SetSelectionAndFocus(Pieces, nullptr, 0, false);
}
void lcModel::ShowTrainTrackSystemDialog()
{
lcTrainTrackSystemDialog Dialog(gMainWindow);
if (Dialog.exec() != QDialog::Accepted)
return;
gMainWindow->GetActiveView()->MakeCurrent();
lcGroup* Group = AddGroup(tr("TrainTrackSystem #"), nullptr);
std::vector<lcPiece* > trackSystemPieces = Dialog.mTrainTrackSystem->GetPieces();
for (lcPiece* Piece : trackSystemPieces)
{
Piece->SetGroup(Group);
AddPiece(Piece);
Piece->UpdatePosition(mCurrentStep);
}
gMainWindow->UpdateTimeline(false, false);
SaveCheckpoint(tr("Train track system"));
}
void lcModel::SetTrainTrackSystem(const std::vector<lcPiece*>& Pieces)
{
DeleteModel();
std::vector<lcObject*> mPieces;
mPieces.reserve(Pieces.size());
for (lcPiece* Piece : Pieces)
{
AddPiece(Piece);
Piece->UpdatePosition(1);
mPieces.emplace_back(Piece);
}
}
void lcModel::SetPreviewPieceInfo(PieceInfo* Info, int ColorIndex)
{
DeleteModel();

View file

@ -250,7 +250,6 @@ public:
}
void SetMinifig(const lcMinifig& Minifig);
void SetTrainTrackSystem(const std::vector<lcPiece*>& Pieces);
void SetPreviewPieceInfo(PieceInfo* Info, int ColorIndex);
void Cut();
@ -374,7 +373,6 @@ public:
void ShowSelectByNameDialog();
void ShowArrayDialog();
void ShowMinifigDialog();
void ShowTrainTrackSystemDialog();
void UpdateInterface();
protected:

View file

@ -147,23 +147,6 @@ void lcPartSelectionListModel::SetCategory(int CategoryIndex)
SetFilter(mFilter);
}
void lcPartSelectionListModel::SetParts(std::vector<PieceInfo*> partsList)
{
beginResetModel();
ReleaseThumbnails();
mParts.clear();
mParts.resize(partsList.size());
for (unsigned long PartIdx = 0; PartIdx < partsList.size(); PartIdx++) {
mParts[PartIdx].Info = partsList[PartIdx];
}
endResetModel();
SetFilter(mFilter);
}
void lcPartSelectionListModel::SetModelsCategory()
{
beginResetModel();
@ -531,14 +514,6 @@ void lcPartSelectionListView::SetCategory(lcPartCategoryType Type, int Index)
setCurrentIndex(mListModel->index(0, 0));
}
void lcPartSelectionListView::SetParts(std::vector<PieceInfo*> partsList)
{
mListModel->SetParts(partsList);
if(mListModel->rowCount()>0)
setCurrentIndex(mListModel->index(0, 0));
}
void lcPartSelectionListView::SetCurrentPart(PieceInfo* Info)
{
QModelIndex Index = mListModel->GetPieceInfoIndex(Info);

View file

@ -117,7 +117,6 @@ public:
void ToggleColorLocked();
void ToggleListMode();
void SetCategory(int CategoryIndex);
void SetParts(std::vector<PieceInfo*> partsList);
void SetModelsCategory();
void SetPaletteCategory(int SetIndex);
void SetCurrentModelCategory();
@ -156,7 +155,6 @@ public:
void startDrag(Qt::DropActions SupportedActions) override;
void SetCategory(lcPartCategoryType Type, int Index);
void SetParts(std::vector<PieceInfo*> partsList);
void SetCurrentPart(PieceInfo* Info);
PieceInfo* GetCurrentPart() const

View file

@ -1,224 +0,0 @@
#include "lc_traintracksystemdialog.h"
#include "ui_lc_traintracksystemdialog.h"
#include "lc_viewwidget.h"
#include "lc_mainwindow.h"
#include "pieceinf.h"
#include "lc_view.h"
#include "piece.h"
#include "camera.h"
#include "lc_partselectionwidget.h"
lcTrainTrackSystemDialog::lcTrainTrackSystemDialog(QWidget* Parent)
: QDialog(Parent), ui(new Ui::lcTrainTrackSystemDialog)
{
gMainWindow->SetTool(lcTool::Pan);
editor_state = LC_TTS_STATE_INSERT;
ui->setupUi(this);
QGridLayout* PreviewLayout = new QGridLayout(ui->trainTrackSystemFrame);
PreviewLayout->setContentsMargins(0, 0, 0, 0);
mTrainTrackSystem = new TrainTrackSystem();
SetInitialTrainTrackSystem();
mView = new lcView(lcViewType::View, mTrainTrackSystem->GetModel());
lcViewWidget* ViewWidget = new lcViewWidget(nullptr, mView);
ViewWidget->setMinimumWidth(1600);
connect(ViewWidget, &lcViewWidget::mousePressOnPiece, this, &lcTrainTrackSystemDialog::mousePressOnPiece);
connect(ViewWidget, &lcViewWidget::mouseRelease, this, &lcTrainTrackSystemDialog::mouseRelease);
PreviewLayout->addWidget(ViewWidget);
mView->MakeCurrent();
QGridLayout* PartSelector = new QGridLayout(ui->partSelector);
PartSelector->setContentsMargins(0, 0, 0, 0);
mPartsWidget = new lcPartSelectionListView(nullptr, nullptr);
PartSelector->addWidget(mPartsWidget);
mPartsWidget->SetParts(mTrainTrackSystem->getTrackTypes());
mView->GetCamera()->SetViewpoint(lcVector3(0.0f, 0.0f, 90.0f));
mView->ZoomExtents();
}
lcTrainTrackSystemDialog::~lcTrainTrackSystemDialog()
{
delete mTrainTrackSystem;
delete ui;
}
void lcTrainTrackSystemDialog::mousePressOnPiece(lcPiece* pieceClickedOn) {
if(pieceClickedOn != nullptr) {
if(mTrainTrackSystem->findTrackTypeByString(pieceClickedOn->mPieceInfo->mFileName) == -1) {
PieceInfo* piecePartlistInf = mPartsWidget->GetCurrentPart();
insertTrackType = mTrainTrackSystem->findTrackTypeByString(piecePartlistInf->mFileName);
if(selectedFromTrackSection == nullptr) {
std::vector<TrainTrackSection*> trackSections = mTrainTrackSystem->GetTrackSections();
int found_con_no = 0;
for(TrainTrackSection* trackSection : trackSections) {
found_con_no = trackSection->FindConnectionNumber(pieceClickedOn->GetRotationCenter());
if(found_con_no != -1) {
selectedFromTrackSection = trackSection;
selectedFromConnectionNo = found_con_no;
break;
}
}
}
if(selectedFromTrackSection != nullptr) {
selectedToConnectionNo = 0;
newSectionInserted = true;
mTrainTrackSystem->addTrackSection(selectedFromTrackSection, selectedFromConnectionNo, insertTrackType, selectedToConnectionNo);
mTrainTrackSystem->SetModel();
mView->Redraw();
}
}
else {
if(mTrainTrackSystem->deleteTrackSection(pieceClickedOn) == true) {
mTrainTrackSystem->SetModel();
mView->Redraw();
}
}
}
}
void lcTrainTrackSystemDialog::mouseRelease() {
selectedFromTrackSection = nullptr;
newSectionInserted = false;
}
void lcTrainTrackSystemDialog::keyPressEvent(QKeyEvent *event) {
if(selectedFromTrackSection == nullptr) {
lcModel* activeModel = mView->GetActiveModel();
const std::vector<std::unique_ptr<lcPiece>>& Pieces = activeModel->GetPieces();
for (const std::unique_ptr<lcPiece>& Piece : Pieces) {
if (Piece->IsFocused()) {
std::vector<TrainTrackSection*> trackSections = mTrainTrackSystem->GetTrackSections();
int found_con_no = 0;
for(TrainTrackSection* trackSection : trackSections) {
found_con_no = trackSection->FindConnectionNumber(Piece->GetRotationCenter());
if(found_con_no != -1) {
selectedFromTrackSection = trackSection;
selectedFromConnectionNo = found_con_no;
break;
}
}
break;
}
}
}
if(selectedFromTrackSection != nullptr) {
bool updateSection = true;
switch(event->key()) {
case Qt::Key_S: {
insertTrackType = LC_TTS_STRAIGHT;
selectedToConnectionNo = 0;
break;
}
case Qt::Key_C: {
insertTrackType = LC_TTS_CURVED;
selectedToConnectionNo = 0;
break;
}
case Qt::Key_X: {
insertTrackType = LC_TTS_CROSS;
selectedToConnectionNo = 0;
break;
}
case Qt::Key_L: {
insertTrackType = LC_TTS_LEFT_BRANCH;
selectedToConnectionNo = 0;
break;
}
case Qt::Key_R: {
insertTrackType = LC_TTS_RIGHT_BRANCH;
selectedToConnectionNo = 0;
break;
}
case Qt::Key_Right: {
if(newSectionInserted == true) {
std::vector<TrainTrackSection*> trackSections = mTrainTrackSystem->GetTrackSections();
TrainTrackSection* newTrackSection = trackSections[trackSections.size() - 1];
selectedToConnectionNo++;
if(selectedToConnectionNo >= newTrackSection->GetNoOfConnections())
selectedToConnectionNo = 0;
}
break;
}
case Qt::Key_Insert: {
selectedFromTrackSection = nullptr;
selectedFromConnectionNo = -1;
newSectionInserted = false;
insertTrackType = LC_TTS_STRAIGHT;
selectedToConnectionNo = 0;
updateSection = false;
break;
}
default: {
updateSection = false;
}
}
if(updateSection == true) {
if(newSectionInserted == true) {
std::vector<TrainTrackSection*>* trackSections = mTrainTrackSystem->GetTrackSectionsPtr();
trackSections->erase(trackSections->begin() + trackSections->size() - 1);
}
mTrainTrackSystem->addTrackSection(selectedFromTrackSection, selectedFromConnectionNo, insertTrackType, selectedToConnectionNo);
mTrainTrackSystem->SetModel();
mView->Redraw();
newSectionInserted = true;
}
}
}
void lcTrainTrackSystemDialog::SetInitialTrainTrackSystem()
{
int colorIndex = 8;
int mCurrentStep = 1;
mTrainTrackSystem->setColorIndex(colorIndex);
mTrainTrackSystem->setCurrentStep(mCurrentStep);
mTrainTrackSystem->addFirstTrackSection(lcMatrix44Identity(),LC_TTS_STRAIGHT); //Idx: 0
}

View file

@ -1,62 +0,0 @@
#pragma once
#include "traintracksystem.h"
#include "lc_partselectionwidget.h"
class lcQColorPicker;
enum LC_TTS_EDITOR_STATES {
LC_TTS_STATE_INSERT,
LC_TTS_STATE_ROTATE,
LC_TTS_STATE_NUMITEMS
};
namespace Ui
{
class lcTrainTrackSystemDialog;
}
class lcTrainTrackSystemDialog : public QDialog
{
Q_OBJECT
public:
explicit lcTrainTrackSystemDialog(QWidget* Parent);
~lcTrainTrackSystemDialog();
//MinifigWizard* mMinifigWizard;
TrainTrackSystem* mTrainTrackSystem;
public slots:
void mousePressOnPiece(lcPiece* piece);
void mouseRelease();
protected:
Ui::lcTrainTrackSystemDialog* ui;
//void mousePressEvent(QMouseEvent* Event) override;
//bool eventFilter(QObject* Object, QEvent* Event) override;'
void keyPressEvent(QKeyEvent *event) override;
enum LC_TTS_EDITOR_STATES editor_state;
lcView* mView;
private:
lcPartSelectionListView* mPartsWidget;
TrainTrackSection* selectedFromTrackSection = nullptr;
int selectedFromConnectionNo = -1;
bool newSectionInserted = false;
enum LC_TTS_TYPES insertTrackType;
int selectedToConnectionNo = 0;
enum LC_TTS_TYPES selectedTrackTypeId;
void SetInitialTrainTrackSystem();
};

View file

@ -1,86 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>lcTrainTrackSystemDialog</class>
<widget class="QDialog" name="lcTrainTrackSystemDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>2000</width>
<height>1000</height>
</rect>
</property>
<property name="windowTitle">
<string>Train track system Wizard</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QFrame" name="partSelector">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
<widget class="QFrame" name="trainTrackSystemFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>lcTrainTrackSystemDialog</receiver>
<slot>accept()</slot>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>lcTrainTrackSystemDialog</receiver>
<slot>reject()</slot>
</connection>
</connections>
</ui>

View file

@ -11,8 +11,6 @@
#include "lc_mesh.h"
#include "lc_profile.h"
#include "lc_previewwidget.h"
#include "pieceinf.h"
#include "object.h"
lcViewWidget::lcViewWidget(QWidget* Parent, lcView* View)
: QOpenGLWidget(Parent), mView(View)
@ -130,24 +128,10 @@ void lcViewWidget::mousePressEvent(QMouseEvent* MouseEvent)
switch (MouseEvent->button())
{
case Qt::LeftButton: {
//Emit piece, if the button is pressed on a piece
lcObjectSection ObjectSection = mView->FindObjectUnderPointer(false, false);
lcObject* Object = ObjectSection.Object;
if (Object)
{
if (Object->IsPiece())
{
lcPiece* Piece = (lcPiece*)Object;
emit mousePressOnPiece(Piece);
}
}
mView->OnLeftButtonDown();
case Qt::LeftButton:
mView->OnLeftButtonDown();
break;
}
case Qt::MiddleButton:
mView->OnMiddleButtonDown();
break;
@ -171,9 +155,7 @@ void lcViewWidget::mousePressEvent(QMouseEvent* MouseEvent)
void lcViewWidget::mouseReleaseEvent(QMouseEvent* MouseEvent)
{
emit mouseRelease();
float DeviceScale = GetDeviceScale();
float DeviceScale = GetDeviceScale();
mView->SetMousePosition(MouseEvent->x() * DeviceScale, mView->GetHeight() - MouseEvent->y() * DeviceScale - 1);
mView->SetMouseModifiers(MouseEvent->modifiers());

View file

@ -13,10 +13,6 @@ public:
QSize sizeHint() const override;
signals:
void mousePressOnPiece(lcPiece* piece);
void mouseRelease();
protected:
float GetDeviceScale() const
{

View file

@ -1,365 +0,0 @@
#include "piece.h"
#include "traintracksystem.h"
#include "lc_model.h"
#include "lc_application.h"
#include "lc_library.h"
#include <QString>
TrainTrackConnectionPoint::TrainTrackConnectionPoint(float angle, float x, float y) {
this->angle = angle;
xy_coordinate.x = x;
xy_coordinate.y = y;
}
void TrainTrackType::Load(lcPiecesLibrary* Library, char const* filename) {
pieceInfo = Library->FindPiece(filename, nullptr, false, false);
}
void TrainTrackType::AddConnection(TrainTrackConnectionPoint *connectionPoint) {
connectionPoints.push_back(connectionPoint);
}
TrainTrackConnectionPoint* TrainTrackType::GetConnection(int index) {
return connectionPoints[index];
}
std::vector<TrainTrackConnectionPoint *>& TrainTrackType::GetConnections() {
return connectionPoints;
}
int TrainTrackType::GetNoOfConnections() {
return connectionPoints.size();
}
TrainTrackSection::TrainTrackSection(TrainTrackType *trackType, enum LC_TTS_TYPES trackTypeId, lcMatrix44 location, int mCurrentStep, int mColorIndex) {
this->trackType = trackType;
this->trackTypeId = trackTypeId;
this->location = location;
this->mCurrentStep = mCurrentStep;
this->mColorIndex = mColorIndex;
}
lcMatrix44 TrainTrackSection::GetConnectionLocation(int connectionNo) {
lcMatrix44 mat44;
lcMatrix44 matOffset;
TrainTrackConnectionPoint* connection = trackType->GetConnections()[connectionNo];
mat44 = lcMatrix44Identity();
mat44 = lcMatrix44RotationZ(LC_DTOR * connection->angle);
matOffset = lcMatrix44Identity();
matOffset.SetTranslation(lcVector3(connection->xy_coordinate.x, connection->xy_coordinate.y,0));
matOffset = lcMul(mat44, matOffset);
return lcMul(matOffset,location);
}
int TrainTrackSection::GetNoOfConnections() {
return trackType->GetNoOfConnections();
}
int TrainTrackSection::FindConnectionNumber(lcVector3 v3searchLocation) {
float precisionErrorNumber = 0.001;
lcMatrix44 matOffset;
for(int con_no = 0; con_no < trackType->GetNoOfConnections(); con_no++) {
lcMatrix44 matSelection = GetConnectionLocation(con_no);
matOffset = lcMatrix44Identity();
matOffset.SetTranslation(lcVector3(-10, 0, 8));
lcVector3 v3Selection = lcMul(matOffset,matSelection).GetTranslation();
if(abs(v3Selection.x - v3searchLocation.x) < precisionErrorNumber &&
abs(v3Selection.y - v3searchLocation.y) < precisionErrorNumber &&
abs(v3Selection.z - v3searchLocation.z) < precisionErrorNumber)
{
return con_no;
}
}
return -1;
}
const char* TrainTrackSystem::mTrackTypeFilenames[LC_TTS_NUMITEMS] =
{
"74746.dat", // LC_TTS_STRAIGHT,
"74747.dat", // LC_TTS_CURVED,
"32087.dat", // LC_TTS_CROSS,
"2861c04.dat", // LC_TTS_LEFT_BRANCH,
"2859c04.dat" // LC_TTS_RIGHT_BRANCH
};
TrainTrackSystem::TrainTrackSystem()
: mModel(new lcModel(QString(), nullptr, false))
{
lcPiecesLibrary* Library = lcGetPiecesLibrary();
float xHalfBendOff = sin(LC_DTOR * 11.25) * 800;
float yHalfBendOff = ((cos(LC_DTOR * 11.25) * 800) - 800);
float x_left_branch = 320 + 320 + 0 + (-(sin(LC_DTOR * 22.5)*800));
float y_left_branch = 0 + 0 + 320 + ((cos(LC_DTOR * 22.5)*800)-800);
float x_right_branch = 320 + 320 + 0 + (-(sin(LC_DTOR * 22.5)*800));
float y_right_branch = 0 + 0 - 320 - ((cos(LC_DTOR * 22.5)*800)-800);
TrainTrackType *trackType;
trainTrackTypes.reserve(LC_TTS_NUMITEMS);
// straight
trackType = new TrainTrackType();
trackType->Load(Library,mTrackTypeFilenames[LC_TTS_STRAIGHT]);
trackType->AddConnection(new TrainTrackConnectionPoint(0,160,0));
trackType->AddConnection(new TrainTrackConnectionPoint(180,-160,0));
trainTrackTypes[LC_TTS_STRAIGHT] = trackType;
// curved
trackType = new TrainTrackType();
trackType->Load(Library,mTrackTypeFilenames[LC_TTS_CURVED]);
trackType->AddConnection(new TrainTrackConnectionPoint(-11.25,xHalfBendOff,yHalfBendOff));
trackType->AddConnection(new TrainTrackConnectionPoint(-168.75,-xHalfBendOff,yHalfBendOff));
trainTrackTypes[LC_TTS_CURVED] = trackType;
// Crossing
trackType = new TrainTrackType();
trackType->Load(Library,mTrackTypeFilenames[LC_TTS_CROSS]);
trackType->AddConnection(new TrainTrackConnectionPoint(0,160,0));
trackType->AddConnection(new TrainTrackConnectionPoint(90,0,160));
trackType->AddConnection(new TrainTrackConnectionPoint(180,-160,0));
trackType->AddConnection(new TrainTrackConnectionPoint(-90,0,-160));
trainTrackTypes[LC_TTS_CROSS] = trackType;
// Left branch
trackType = new TrainTrackType();
trackType->Load(Library,mTrackTypeFilenames[LC_TTS_LEFT_BRANCH]);
trackType->AddConnection(new TrainTrackConnectionPoint(0,320,0));
trackType->AddConnection(new TrainTrackConnectionPoint(22.50,x_left_branch,y_left_branch));
trackType->AddConnection(new TrainTrackConnectionPoint(180,-320,0));
trainTrackTypes[LC_TTS_LEFT_BRANCH] = trackType;
// Right branch
trackType = new TrainTrackType();
trackType->Load(Library,mTrackTypeFilenames[LC_TTS_RIGHT_BRANCH]);
trackType->AddConnection(new TrainTrackConnectionPoint(0,320,0));
trackType->AddConnection(new TrainTrackConnectionPoint(180,-320,0));
trackType->AddConnection(new TrainTrackConnectionPoint(-22.50,x_right_branch,y_right_branch));
trainTrackTypes[LC_TTS_RIGHT_BRANCH] = trackType;
// Create map for lookup track type by name
for(int i = 0; i < LC_TTS_NUMITEMS; i++) trackTypesByName.insert({mTrackTypeFilenames[i], static_cast<LC_TTS_TYPES>(i)});
}
TrainTrackSystem::~TrainTrackSystem() {}
void TrainTrackSystem::setColorIndex(int mColorIndex) {
this->mColorIndex = mColorIndex;
}
void TrainTrackSystem::setCurrentStep(int mCurrentStep) {
this->mCurrentStep = mCurrentStep;
}
void TrainTrackSystem::addFirstTrackSection(lcMatrix44 position, enum LC_TTS_TYPES trackTypeId) {
TrainTrackType* trainTrackType = trainTrackTypes[trackTypeId];
trackSections.push_back(new TrainTrackSection(trainTrackType, trackTypeId,position, mCurrentStep, mColorIndex));
}
void TrainTrackSystem::addTrackSection(int fromTrackSectionIdx, int fromTrackSectionConnectionIdx, enum LC_TTS_TYPES toTrackType, int toTrackTypeConnectionIdx)
{
TrainTrackSection* fromTrackSection = trackSections[fromTrackSectionIdx];
TrainTrackType* fromTrack = trainTrackTypes[fromTrackSection->trackTypeId];
TrainTrackConnectionPoint * fromConnectIdx = fromTrack->GetConnection(fromTrackSectionConnectionIdx);
TrainTrackType* toTrack = trainTrackTypes[toTrackType];
TrainTrackConnectionPoint * toConnectIdx = toTrack->GetConnection(toTrackTypeConnectionIdx);
lcMatrix44 currentLocation = fromTrackSection->location;
lcMatrix44 mat44;
lcMatrix44 matOffset;
// calculate position on exiting connection point
mat44 = lcMatrix44Identity();
mat44 = lcMatrix44RotationZ(LC_DTOR * fromConnectIdx->angle);
matOffset = lcMatrix44Identity();
matOffset.SetTranslation(lcVector3(fromConnectIdx->xy_coordinate.x, fromConnectIdx->xy_coordinate.y,0));
matOffset = lcMul(mat44, matOffset);
currentLocation = lcMul(matOffset,currentLocation);
// calculate position on entering new track section
mat44 = lcMatrix44Identity();
mat44 = lcMatrix44RotationZ(LC_DTOR * (180 - toConnectIdx->angle));
matOffset = lcMatrix44Identity();
matOffset.SetTranslation(lcVector3(-toConnectIdx->xy_coordinate.x, -toConnectIdx->xy_coordinate.y,0));
matOffset = lcMul(matOffset,mat44);
currentLocation = lcMul(matOffset,currentLocation);
trackSections.push_back(new TrainTrackSection(toTrack, toTrackType,currentLocation, mCurrentStep, mColorIndex));
}
void TrainTrackSystem::addTrackSection(TrainTrackSection* fromTrackSection, int fromTrackSectionConnectionIdx, enum LC_TTS_TYPES toTrackType, int toTrackTypeConnectionIdx)
{
TrainTrackType* fromTrack = trainTrackTypes[fromTrackSection->trackTypeId];
TrainTrackConnectionPoint * fromConnectIdx = fromTrack->GetConnection(fromTrackSectionConnectionIdx);
TrainTrackType* toTrack = trainTrackTypes[toTrackType];
TrainTrackConnectionPoint * toConnectIdx = toTrack->GetConnection(toTrackTypeConnectionIdx);
lcMatrix44 currentLocation = fromTrackSection->location;
lcMatrix44 mat44;
lcMatrix44 matOffset;
// calculate position on exiting connection point
mat44 = lcMatrix44Identity();
mat44 = lcMatrix44RotationZ(LC_DTOR * fromConnectIdx->angle);
matOffset = lcMatrix44Identity();
matOffset.SetTranslation(lcVector3(fromConnectIdx->xy_coordinate.x, fromConnectIdx->xy_coordinate.y,0));
matOffset = lcMul(mat44, matOffset);
currentLocation = lcMul(matOffset,currentLocation);
// calculate position on entering new track section
mat44 = lcMatrix44Identity();
mat44 = lcMatrix44RotationZ(LC_DTOR * (180 - toConnectIdx->angle));
matOffset = lcMatrix44Identity();
matOffset.SetTranslation(lcVector3(-toConnectIdx->xy_coordinate.x, -toConnectIdx->xy_coordinate.y,0));
matOffset = lcMul(matOffset,mat44);
currentLocation = lcMul(matOffset,currentLocation);
trackSections.push_back(new TrainTrackSection(toTrack, toTrackType,currentLocation, mCurrentStep, mColorIndex));
}
bool TrainTrackSystem::deleteTrackSection(lcPiece* piece)
{
float precisionErrorNumber = 0.001;
lcVector3 vec3PieceDel = piece->GetRotationCenter();
for(unsigned long i = 0; i < trackSections.size(); i++) {
lcVector3 vec3PieceCur = trackSections[i]->location.GetTranslation();
if(abs(vec3PieceDel.x - vec3PieceCur.x) < precisionErrorNumber &&
abs(vec3PieceDel.y - vec3PieceCur.y) < precisionErrorNumber &&
abs(vec3PieceDel.z - vec3PieceCur.z) < precisionErrorNumber)
{
trackSections.erase(trackSections.begin() + i);
return true;
}
}
return false;
}
std::vector<PieceInfo *> TrainTrackSystem::getTrackTypes()
{
std::vector<PieceInfo*> trackTypes;
for(int i = 0; i < LC_TTS_NUMITEMS; i++) {
trackTypes.push_back(trainTrackTypes[i]->pieceInfo);
}
return trackTypes;
}
std::vector<TrainTrackSection*> TrainTrackSystem::GetTrackSections()
{
return trackSections;
}
std::vector<TrainTrackSection*>* TrainTrackSystem::GetTrackSectionsPtr()
{
return &trackSections;
}
std::vector<lcPiece*> TrainTrackSystem::GetPieces()
{
std::vector<lcPiece*> pieces;
PieceInfo* pieceInfo;
lcPiecesLibrary* Library = lcGetPiecesLibrary();
PieceInfo* pieceInfoSel = Library->FindPiece("3023.dat", nullptr, false, false);
TrainTrackSection* trackSection;
lcPiece* piece;
for(unsigned long i = 0; i < trackSections.size(); i++)
{
trackSection = trackSections[i];
pieceInfo = trainTrackTypes[trackSection->trackTypeId]->pieceInfo;
piece = new lcPiece(pieceInfo);
piece->Initialize(trackSection->location, trackSection->mCurrentStep);
piece->SetColorIndex(trackSection->mColorIndex);
pieces.push_back(piece);
// Add 1 x 2 plate on each connecton point, for detect selection
lcMatrix44 mat44;
lcMatrix44 matOffset;
for(int con_no = 0; con_no < trackSection->GetNoOfConnections(); con_no++)
{
mat44 = trackSection->GetConnectionLocation(con_no);
matOffset = lcMatrix44Identity();
matOffset.SetTranslation(lcVector3(-10, 0, 8));
mat44 = lcMul(matOffset,mat44);
matOffset = lcMatrix44Identity();
matOffset = lcMatrix44RotationZ(LC_DTOR * 90);
mat44 = lcMul(matOffset,mat44);
piece = new lcPiece(pieceInfoSel);
piece->Initialize(mat44, trackSection->mCurrentStep);
piece->SetColorIndex(trackSection->mColorIndex);
//pieces.Add(piece);
pieces.push_back(piece);
}
}
return pieces;
}
lcModel* TrainTrackSystem::GetModel()
{
std::vector<lcPiece*> trackSystem = this->GetPieces();
mModel->SetTrainTrackSystem(trackSystem);
return mModel.get();
}
void TrainTrackSystem::SetModel()
{
std::vector<lcPiece*> trackSystem = this->GetPieces();
mModel->SetTrainTrackSystem(trackSystem);
}
LC_TTS_TYPES TrainTrackSystem::findTrackTypeByString(const char *tracktypeName)
{
std::string str_search = tracktypeName;
std::map<std::string ,LC_TTS_TYPES>::iterator search = trackTypesByName.find(str_search);
if (search != trackTypesByName.end()) {
return search->second;
}
return static_cast<LC_TTS_TYPES>(-1);
}

View file

@ -1,105 +0,0 @@
#pragma once
#include "lc_library.h"
#include <vector>
#include <map>
#include <string>
#include <memory>
enum LC_TTS_TYPES {
LC_TTS_STRAIGHT,
LC_TTS_CURVED,
LC_TTS_CROSS,
LC_TTS_LEFT_BRANCH,
LC_TTS_RIGHT_BRANCH,
LC_TTS_NUMITEMS
};
class TrainTrackConnectionPoint {
public:
TrainTrackConnectionPoint(float angle, float x, float y);
float angle;
lcVector2 xy_coordinate;
};
class TrainTrackType {
public:
void Load(lcPiecesLibrary* Library, char const* filename);
void AddConnection(TrainTrackConnectionPoint *connectionPoint);
TrainTrackConnectionPoint *GetConnection(int index);
//lcArray<TrainTrackConnectionPoint *>& GetConnections();
std::vector<TrainTrackConnectionPoint *>& GetConnections();
PieceInfo* pieceInfo;
int GetNoOfConnections();
private:
char const* filename;
//lcArray<TrainTrackConnectionPoint *> connectionPoints;
std::vector<TrainTrackConnectionPoint *> connectionPoints;
};
class TrainTrackSection {
public:
TrainTrackSection(TrainTrackType *trackType, enum LC_TTS_TYPES trackTypeId, lcMatrix44 location, int mCurrentStep, int mColorIndex);
lcMatrix44 GetConnectionLocation(int connectionNo);
int GetNoOfConnections();
int FindConnectionNumber(lcVector3 searchLocation);
TrainTrackType *trackType;
enum LC_TTS_TYPES trackTypeId;
lcMatrix44 location;
int mCurrentStep;
int mColorIndex;
};
class TrainTrackSystem
{
public:
TrainTrackSystem();
~TrainTrackSystem();
void setColorIndex(int colorIndex);
void setCurrentStep(int mCurrentStep);
void addFirstTrackSection(lcMatrix44 position, enum LC_TTS_TYPES trackTypeId);
void addTrackSection(int fromTrackSectionIdx, int fromTrackSectionConnectionIdx, enum LC_TTS_TYPES toTrackType, int toTrackTypeConnectionIdx);
void addTrackSection(TrainTrackSection* fromTrackSection, int fromTrackSectionConnectionIdx, enum LC_TTS_TYPES toTrackType, int toTrackTypeConnectionIdx);
bool deleteTrackSection(lcPiece* piece);
//lcArray<PieceInfo*> getTrackTypes();
std::vector<PieceInfo *> getTrackTypes();
//lcArray<TrainTrackSection*> GetTrackSections();
std::vector<TrainTrackSection *> GetTrackSections();
//lcArray<TrainTrackSection*>* GetTrackSectionsPtr();
std::vector<TrainTrackSection *>* GetTrackSectionsPtr();
//lcArray<lcPiece* > GetPieces();
std::vector<lcPiece *> GetPieces();
lcModel* GetModel();
void SetModel();
LC_TTS_TYPES findTrackTypeByString(const char *tracktypeName);
private:
//lcArray<TrainTrackType*> trainTrackTypes;
std::vector<TrainTrackType *> trainTrackTypes;
static const char* mTrackTypeFilenames[LC_TTS_NUMITEMS];
//lcArray<TrainTrackSection*> trackSections;
std::vector<TrainTrackSection *> trackSections;
int mColorIndex;
int mCurrentStep;
std::unique_ptr<lcModel> mModel;
std::map<std::string ,LC_TTS_TYPES> trackTypesByName;
};

View file

@ -170,7 +170,6 @@ SOURCES += \
common/image.cpp \
common/light.cpp \
common/minifig.cpp \
common/traintracksystem.cpp \
common/object.cpp \
common/piece.cpp \
common/pieceinf.cpp \
@ -204,7 +203,6 @@ SOURCES += \
common/lc_mesh.cpp \
common/lc_meshloader.cpp \
common/lc_minifigdialog.cpp \
common/lc_traintracksystemdialog.cpp \
common/lc_model.cpp \
common/lc_modellistdialog.cpp \
common/lc_objectproperty.cpp \
@ -245,7 +243,6 @@ HEADERS += \
common/image.h \
common/light.h \
common/minifig.h \
common/traintracksystem.h \
common/object.h \
common/piece.h \
common/pieceinf.h \
@ -281,7 +278,6 @@ HEADERS += \
common/lc_mesh.h \
common/lc_meshloader.h \
common/lc_minifigdialog.h \
common/lc_traintracksystemdialog.h \
common/lc_model.h \
common/lc_modellistdialog.h \
common/lc_objectproperty.h \
@ -329,7 +325,6 @@ FORMS += \
common/lc_categorydialog.ui \
common/lc_groupdialog.ui \
common/lc_minifigdialog.ui \
common/lc_traintracksystemdialog.ui \
common/lc_modellistdialog.ui \
common/lc_pagesetupdialog.ui \
common/lc_partpalettedialog.ui