Compare commits

..

No commits in common. "6f66b9540e82540478727c9f1f706640f5b2cfb3" and "ed5aa597adeae3889a79599f0d25b1e39f4517b0" have entirely different histories.

5 changed files with 18 additions and 37 deletions

View file

@ -124,6 +124,8 @@ 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,6 +382,7 @@ 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,8 +108,9 @@ MainWindow::MainWindow(QWidget *parent)
ui->actionUndo->setEnabled(false);
ui->actionRedo->setEnabled(false);
undoManager.SetUndoStateListener([&]() {
updateToolbars();
undoManager.SetUndoStateListener([&](bool canUndo, bool canRedo) {
ui->actionUndo->setEnabled(canUndo);
ui->actionRedo->setEnabled(canRedo);
});
}
@ -126,10 +127,9 @@ 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,10 +215,9 @@ 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);
}
@ -235,11 +234,6 @@ 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),
@ -255,10 +249,9 @@ 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 (!path || path == "") return;
}
if (!editModeDataModel->HasFile() && (!path || path == "")) return;
editModeDataModel->SaveToFile(path);
});
@ -286,7 +279,6 @@ void MainWindow::connectActionHandlers() {
// Reset running state
placeDocument->setRunState(RUN_STOPPED);
undoManager.Reset();
updateToolbars();
});
@ -503,10 +495,9 @@ 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);
}
@ -555,9 +546,6 @@ 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();
undoStateListener(!undoHistory.empty(), !redoHistory.empty());
}
void UndoHistory::Undo() {
@ -38,7 +38,7 @@ void UndoHistory::Undo() {
}
processingUndo = false;
undoStateListener();
undoStateListener(!undoHistory.empty(), !redoHistory.empty());
}
void UndoHistory::Redo() {
@ -66,14 +66,7 @@ void UndoHistory::Redo() {
}
processingUndo = false;
undoStateListener();
}
void UndoHistory::Reset() {
processingUndo = false;
undoHistory.clear();
redoHistory = {};
undoStateListener();
undoStateListener(!undoHistory.empty(), !redoHistory.empty());
}
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()> UndoStateChangedListener;
typedef std::function<void(bool canUndo, bool canRedo)> UndoStateChangedListener;
class UndoHistory {
// Ignore PushState requests
@ -53,9 +53,6 @@ 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);
};