Compare commits

...

2 commits

5 changed files with 37 additions and 18 deletions

View file

@ -124,8 +124,6 @@ SurfaceType Part::surfaceFromFace(NormalId face) {
}
float Part::GetSurfaceParamA(Vector3 face) {
// printVec(face);
// printf("Enum: %d\n", faceFromNormal(face));
switch (faceFromNormal(face)) {
case Top: return topParamA;
case Bottom: return bottomParamA;

View file

@ -382,7 +382,6 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
initialAssembly = PartAssembly::FromSelection(gDataModel->GetService<Selection>());
initialFrame = initialAssembly.assemblyOrigin();
initialTransforms = PartAssembly::FromSelection(gDataModel->GetService<Selection>()).GetCurrentTransforms();
printf("%ld\n", initialTransforms.size());
isMouseDragging = true;
draggingHandle = handle;
startLinearTransform(evt);

View file

@ -108,9 +108,8 @@ MainWindow::MainWindow(QWidget *parent)
ui->actionUndo->setEnabled(false);
ui->actionRedo->setEnabled(false);
undoManager.SetUndoStateListener([&](bool canUndo, bool canRedo) {
ui->actionUndo->setEnabled(canUndo);
ui->actionRedo->setEnabled(canRedo);
undoManager.SetUndoStateListener([&]() {
updateToolbars();
});
}
@ -127,9 +126,10 @@ void MainWindow::closeEvent(QCloseEvent* evt) {
if (result == QMessageBox::Cancel) return evt->ignore();
if (result == QMessageBox::Save) {
std::optional<std::string> path;
if (!gDataModel->HasFile())
if (!gDataModel->HasFile()) {
path = openFileDialog("Openblocks Level (*.obl)", ".obl", QFileDialog::AcceptSave, QString::fromStdString("Save " + gDataModel->name));
if (!path || path == "") return evt->ignore();
if (!path || path == "") return evt->ignore();
}
gDataModel->SaveToFile(path);
}
@ -215,9 +215,10 @@ void MainWindow::connectActionHandlers() {
if (result == QMessageBox::Cancel) return;
if (result == QMessageBox::Save) {
std::optional<std::string> path;
if (!gDataModel->HasFile())
if (!gDataModel->HasFile()) {
path = openFileDialog("Openblocks Level (*.obl)", ".obl", QFileDialog::AcceptSave, QString::fromStdString("Save " + gDataModel->name));
if (!path || path == "") return;
if (!path || path == "") return;
}
gDataModel->SaveToFile(path);
}
@ -234,6 +235,11 @@ void MainWindow::connectActionHandlers() {
gDataModel->Init();
ui->explorerView->updateRoot(gDataModel);
// Reset running state
placeDocument->setRunState(RUN_STOPPED);
undoManager.Reset();
updateToolbars();
// Baseplate
gWorkspace()->AddChild(placeDocument->placeWidget->lastPart = Part::New({
.position = glm::vec3(0, -5, 0),
@ -249,9 +255,10 @@ void MainWindow::connectActionHandlers() {
connect(ui->actionSave, &QAction::triggered, this, [&]() {
std::optional<std::string> path;
if (!editModeDataModel->HasFile())
if (!editModeDataModel->HasFile()) {
path = openFileDialog("Openblocks Level (*.obl)", ".obl", QFileDialog::AcceptSave, QString::fromStdString("Save " + editModeDataModel->name));
if (!editModeDataModel->HasFile() && (!path || path == "")) return;
if (!path || path == "") return;
}
editModeDataModel->SaveToFile(path);
});
@ -279,6 +286,7 @@ void MainWindow::connectActionHandlers() {
// Reset running state
placeDocument->setRunState(RUN_STOPPED);
undoManager.Reset();
updateToolbars();
});
@ -495,9 +503,10 @@ void MainWindow::openFile(std::string path) {
if (result == QMessageBox::Cancel) return;
if (result == QMessageBox::Save) {
std::optional<std::string> path;
if (!gDataModel->HasFile())
if (!gDataModel->HasFile()) {
path = openFileDialog("Openblocks Level (*.obl)", ".obl", QFileDialog::AcceptSave, QString::fromStdString("Save " + gDataModel->name));
if (!path || path == "") return;
if (!path || path == "") return;
}
gDataModel->SaveToFile(path);
}
@ -546,6 +555,9 @@ void MainWindow::updateToolbars() {
ui->actionRunSimulation->setEnabled(placeDocument->runState() != RUN_RUNNING);
ui->actionPauseSimulation->setEnabled(placeDocument->runState() == RUN_RUNNING);
ui->actionStopSimulation->setEnabled(placeDocument->runState() != RUN_STOPPED);
ui->actionUndo->setEnabled(undoManager.CanUndo() && placeDocument->runState() == RUN_STOPPED);
ui->actionRedo->setEnabled(undoManager.CanRedo() && placeDocument->runState() == RUN_STOPPED);
}
std::optional<std::string> MainWindow::openFileDialog(QString filter, QString defaultExtension, QFileDialog::AcceptMode acceptMode, QString title) {

View file

@ -10,7 +10,7 @@ void UndoHistory::PushState(UndoState state) {
undoHistory.erase(undoHistory.begin(), undoHistory.begin()+maxBufferSize-(int)undoHistory.size()-1);
undoHistory.push_back(state);
undoStateListener(!undoHistory.empty(), !redoHistory.empty());
undoStateListener();
}
void UndoHistory::Undo() {
@ -38,7 +38,7 @@ void UndoHistory::Undo() {
}
processingUndo = false;
undoStateListener(!undoHistory.empty(), !redoHistory.empty());
undoStateListener();
}
void UndoHistory::Redo() {
@ -66,7 +66,14 @@ void UndoHistory::Redo() {
}
processingUndo = false;
undoStateListener(!undoHistory.empty(), !redoHistory.empty());
undoStateListener();
}
void UndoHistory::Reset() {
processingUndo = false;
undoHistory.clear();
redoHistory = {};
undoStateListener();
}
void UndoHistory::SetUndoStateListener(UndoStateChangedListener listener) {

View file

@ -38,7 +38,7 @@ struct UndoStateSelectionChanged {
typedef std::variant<UndoStatePropertyChanged, UndoStateInstanceCreated, UndoStateInstanceRemoved, UndoStateInstanceReparented, UndoStateSelectionChanged> UndoStateChange;
typedef std::vector<UndoStateChange> UndoState;
typedef std::function<void(bool canUndo, bool canRedo)> UndoStateChangedListener;
typedef std::function<void()> UndoStateChangedListener;
class UndoHistory {
// Ignore PushState requests
@ -53,6 +53,9 @@ public:
void PushState(UndoState);
void Undo();
void Redo();
void Reset();
inline bool CanUndo() { return !undoHistory.empty(); }
inline bool CanRedo() { return !redoHistory.empty(); }
void SetUndoStateListener(UndoStateChangedListener listener);
};