From feff22c2228d56cd75594e1a20d9a2181f9f9a6b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 25 May 2014 14:16:43 -0300 Subject: [PATCH 01/10] Planner: Re-enable using the new profile. This correctly enables the planner on the new profile, but it doesn't triggers the correct paint on the canvas. [Dirk Hohndel: remove other remnants of the disabled planner as well] Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- Documentation/Makefile | 8 ++------ Documentation/user-manual.txt | 4 ---- qt-ui/diveplanner.cpp | 2 -- qt-ui/maintab.cpp | 2 -- qt-ui/mainwindow.cpp | 4 +--- qt-ui/models.cpp | 6 ------ qt-ui/models.h | 2 -- qt-ui/profile/profilewidget2.cpp | 9 +++++++++ subsurface.pro | 10 +--------- 9 files changed, 13 insertions(+), 34 deletions(-) diff --git a/Documentation/Makefile b/Documentation/Makefile index 611bd2fb0..204aeb8e8 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -15,10 +15,6 @@ A2X = a2x BROWSER = firefox THEME = compact_subsurface PWD = $(realpath .) -ENABLE_PLANNER := 0 -ifeq ($(ENABLE_PLANNER), 1) -ENABLE_PLANNER_ATTR=-a ENABLE_PLANNER=$(ENABLE_PLANNER) -endif all: doc $(addprefix $(DOCNAME).,pdf text) @@ -33,11 +29,11 @@ $(OUT)$(DOCNAME).pdf: $(DOCSOURCE) $(OUT)$(HTMLDOC): $(DOCSOURCE) @echo "if asciidoc isn't found the html file included in the sources is copied" $(ASCIIDOC) -a toc -a toclevels=3 -a themedir=$(PWD) -a theme=$(THEME) -a stylesdir=$(PWD) \ - $(ENABLE_PLANNER_ATTR) -o $(OUT)$(HTMLDOC) $< || cp $(HTMLDOC).git $(OUT)$(HTMLDOC) + -o $(OUT)$(HTMLDOC) $< || cp $(HTMLDOC).git $(OUT)$(HTMLDOC) # Alternatively:: $(OUT)$(DOCNAME).xhtml: $(DOCSOURCE) - $(A2X) $(ENABLE_PLANNER_ATTR) --icons -f xhtml $< + $(A2X) --icons -f xhtml $< show: $(HTMLDOC) $(BROWSER) $< diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 748a8c21f..697df1190 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -1889,7 +1889,6 @@ language / country settings as the underlying OS. If this is for some reason undesirable users can uncheck this checkbox and pick a language / country combination from the list of included localizations. -ifdef::ENABLE_PLANNER[] [[S_DivePlanner]] == The Subsurface dive planner The dive planner is accessed by selecting _Log -> Plan Dive_ from the main menu. This @@ -1983,7 +1982,6 @@ there is no provision for any reserve gas. image::images/Planner2.jpg["FIGURE: Planning a dive: evaluation",align="center"] This part of the software is in active development. -endif::ENABLE_PLANNER[] == Description of the Subsurface Main Menu items @@ -2023,9 +2021,7 @@ from _www.Divelogs.de_. - <> - Manually add a new dive to the *Dive List* panel. - <> - Renumber the dives listed in the *Dive List* panel. -ifdef::ENABLE_PLANNER[] -_Plan Dive_ - This experimental feature allows planning of simple dives. -endif::ENABLE_PLANNER[] - <> - Group the dives in the *Dive List* panel into dive trips. - _Edit Device Names_ - Edit the names of dive computers. diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 3ffacdd2b..4fff79666 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -215,9 +215,7 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg QTableView *view = ui.cylinderTableWidget->view(); view->setColumnHidden(CylindersModel::START, true); view->setColumnHidden(CylindersModel::END, true); -#ifdef ENABLE_PLANNER view->setColumnHidden(CylindersModel::DEPTH, false); -#endif view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this)); connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addCylinder_clicked())); connect(ui.tableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addStop())); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 2bb261448..34be53a90 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -88,9 +88,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this)); ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this)); -#ifdef ENABLE_PLANNER ui.cylinders->view()->setColumnHidden(CylindersModel::DEPTH, true); -#endif completers.buddy = new QCompleter(&buddyModel, ui.buddy); completers.divemaster = new QCompleter(&diveMasterModel, ui.divemaster); completers.location = new QCompleter(&locationModel, ui.location); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 19a16a886..2bfeca64e 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -87,9 +87,6 @@ MainWindow::MainWindow() : QMainWindow(), ui.ListWidget->scrollTo(ui.ListWidget->model()->index(0, 0), QAbstractItemView::PositionAtCenter); ui.divePlannerWidget->settingsChanged(); -#ifndef ENABLE_PLANNER - ui.menuLog->removeAction(ui.actionDivePlanner); -#endif #ifdef NO_MARBLE ui.layoutWidget->hide(); ui.menuView->removeAction(ui.actionViewGlobe); @@ -318,6 +315,7 @@ void MainWindow::on_actionDivePlanner_triggered() break; } } + ui.newProfile->setPlanState(); ui.infoPane->setCurrentIndex(PLANNERWIDGET); } diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index dc9a7189a..5efcf5a34 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -67,9 +67,7 @@ CylindersModel::CylindersModel(QObject *parent) : current(0), rows(0) { // enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH}; setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("WorkPress") << tr("StartPress") << tr("EndPress") << trUtf8("O" UTF8_SUBSCRIPT_2 "%") << tr("He%") -#ifdef ENABLE_PLANNER << tr("Switch at") -#endif ); } @@ -145,11 +143,9 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const case HE: ret = percent_string(cyl->gasmix.he); break; -#ifdef ENABLE_PLANNER case DEPTH: ret = get_depth_string(cyl->depth, true); break; -#endif } break; case Qt::DecorationRole: @@ -263,13 +259,11 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in changed = true; } break; -#ifdef ENABLE_PLANNER case DEPTH: if (CHANGED()) { cyl->depth = string_to_depth(vString.toUtf8().data()); changed = true; } -#endif } dataChanged(index, index); if (addDiveMode) diff --git a/qt-ui/models.h b/qt-ui/models.h index 34d7d4827..17be8cbc9 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -102,9 +102,7 @@ public: END, O2, HE, -#ifdef ENABLE_PLANNER DEPTH, -#endif COLUMNS }; diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 2de64e71f..71a2f4856 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -773,6 +773,15 @@ void ProfileWidget2::setPlanState() setProfileState(); disconnectTemporaryConnections(); /* show the same stuff that the profile shows. */ + + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot())); + connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot())); + connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), + this, SLOT(pointInserted(const QModelIndex &, int, int))); + connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), + this, SLOT(pointsRemoved(const QModelIndex &, int, int))); + currentState = PLAN; /* enable the add state. */ setBackgroundBrush(QColor(Qt::green).light()); } diff --git a/subsurface.pro b/subsurface.pro index 83dea66a4..d7189377a 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -15,11 +15,6 @@ else: TARGET = subsurface VERSION = 4.1.0 -# enable or disable the dive planner -planner { - DEFINES += ENABLE_PLANNER -} - HEADERS = \ color.h \ deco.h \ @@ -237,10 +232,7 @@ QTTRANSLATIONS = \ qt_sv.qm \ qt_zh_TW.qm -# Should we enable the planner sections in the manual? -planner: ENABLE_PLANNER=1 -else: ENABLE_PLANNER=0 -doc.commands += $(CHK_DIR_EXISTS) $$OUT_PWD/Documentation || $(MKDIR) $$OUT_PWD/Documentation $$escape_expand(\\n\\t)$(MAKE) -C $$PWD/Documentation OUT=$$OUT_PWD/Documentation/ ENABLE_PLANNER=$$ENABLE_PLANNER doc +doc.commands += $(CHK_DIR_EXISTS) $$OUT_PWD/Documentation || $(MKDIR) $$OUT_PWD/Documentation $$escape_expand(\\n\\t)$(MAKE) -C $$PWD/Documentation OUT=$$OUT_PWD/Documentation/ doc all.depends += doc QMAKE_EXTRA_TARGETS += doc all From c4d022356ea9f128b71633d64dbb5f81a83bf1db Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 25 May 2014 15:12:00 -0300 Subject: [PATCH 02/10] Planner: states Add and Plan have a similar behavior So, the code is equal. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/profilewidget2.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 71a2f4856..c3e010c83 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -770,9 +770,17 @@ void ProfileWidget2::setPlanState() { if (currentState == PLAN) return; + setProfileState(); disconnectTemporaryConnections(); - /* show the same stuff that the profile shows. */ + //TODO: Move this method to another place, shouldn't be on mainwindow. + MainWindow::instance()->disableDcShortcuts(); + actionsForKeys[Qt::Key_Left]->setShortcut(Qt::Key_Left); + actionsForKeys[Qt::Key_Right]->setShortcut(Qt::Key_Right); + actionsForKeys[Qt::Key_Up]->setShortcut(Qt::Key_Up); + actionsForKeys[Qt::Key_Down]->setShortcut(Qt::Key_Down); + actionsForKeys[Qt::Key_Escape]->setShortcut(Qt::Key_Escape); + actionsForKeys[Qt::Key_Delete]->setShortcut(Qt::Key_Delete); DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot())); @@ -781,7 +789,7 @@ void ProfileWidget2::setPlanState() this, SLOT(pointInserted(const QModelIndex &, int, int))); connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(pointsRemoved(const QModelIndex &, int, int))); - + /* show the same stuff that the profile shows. */ currentState = PLAN; /* enable the add state. */ setBackgroundBrush(QColor(Qt::green).light()); } From dcd83817648ed227a4a3453923e29a662fa2cc67 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 25 May 2014 15:15:57 -0300 Subject: [PATCH 03/10] Planner: Move method down below to easy comparisson with another. Planner and add states are driving me nuts. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 48 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 2bfeca64e..801268a08 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -295,30 +295,6 @@ void MainWindow::enableDcShortcuts() ui.actionNextDC->setShortcut(Qt::Key_Right); } -void MainWindow::on_actionDivePlanner_triggered() -{ - int i; - struct dive *dive; - if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || - ui.InfoWidget->isEditing()) { - QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to plan a dive.")); - return; - } - disableDcShortcuts(); - DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); - DivePlannerPointsModel::instance()->clear(); - CylindersModel::instance()->clear(); - for_each_dive (i, dive) { - if (dive->selected) { - DivePlannerPointsModel::instance()->copyCylindersFrom(dive); - CylindersModel::instance()->copyFromDive(dive); - break; - } - } - ui.newProfile->setPlanState(); - ui.infoPane->setCurrentIndex(PLANNERWIDGET); -} - void MainWindow::showProfile() { enableDcShortcuts(); @@ -379,6 +355,30 @@ void MainWindow::on_actionEditDeviceNames_triggered() DiveComputerManagementDialog::instance()->show(); } +void MainWindow::on_actionDivePlanner_triggered() +{ + int i; + struct dive *dive; + if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || + ui.InfoWidget->isEditing()) { + QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to plan a dive.")); + return; + } + disableDcShortcuts(); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); + DivePlannerPointsModel::instance()->clear(); + CylindersModel::instance()->clear(); + for_each_dive (i, dive) { + if (dive->selected) { + DivePlannerPointsModel::instance()->copyCylindersFrom(dive); + CylindersModel::instance()->copyFromDive(dive); + break; + } + } + ui.newProfile->setPlanState(); + ui.infoPane->setCurrentIndex(PLANNERWIDGET); +} + void MainWindow::on_actionAddDive_triggered() { if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || From 777f04724717513c7a0e14b13aa66934328c8245 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 25 May 2014 15:19:36 -0300 Subject: [PATCH 04/10] Small code cleanup. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 25 ++++++++++++++++--------- qt-ui/mainwindow.h | 2 ++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 801268a08..a10dac2e4 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -355,15 +355,24 @@ void MainWindow::on_actionEditDeviceNames_triggered() DiveComputerManagementDialog::instance()->show(); } -void MainWindow::on_actionDivePlanner_triggered() +bool MainWindow::plannerStateClean() { - int i; - struct dive *dive; if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || ui.InfoWidget->isEditing()) { - QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to plan a dive.")); - return; + QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive.")); + return false; } + return true; +} + +void MainWindow::on_actionDivePlanner_triggered() +{ + if (!plannerStateClean()) + return; + + int i; + struct dive *dive; + disableDcShortcuts(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); DivePlannerPointsModel::instance()->clear(); @@ -381,11 +390,9 @@ void MainWindow::on_actionDivePlanner_triggered() void MainWindow::on_actionAddDive_triggered() { - if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || - ui.InfoWidget->isEditing()) { - QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive.")); + if(!plannerStateClean()) return; - } + dive_list()->rememberSelection(); dive_list()->unselectDives(); disableDcShortcuts(); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index a658fe3cc..667e3810a 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -172,6 +172,8 @@ private: void updateLastUsedDir(const QString &s); bool filesAsArguments; UpdateManager *updateManager; + + bool plannerStateClean(); }; #endif // MAINWINDOW_H From 58d5d5ca412287a4be65e27e2a774ba7731b7098 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 25 May 2014 15:36:34 -0300 Subject: [PATCH 05/10] Remove uneeded call. The disableDcShortcuts is called inside of the ProfileGraphics ( I actually think that this method should be moved to there ) Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index a10dac2e4..1062e43d8 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -373,7 +373,6 @@ void MainWindow::on_actionDivePlanner_triggered() int i; struct dive *dive; - disableDcShortcuts(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); DivePlannerPointsModel::instance()->clear(); CylindersModel::instance()->clear(); @@ -395,7 +394,6 @@ void MainWindow::on_actionAddDive_triggered() dive_list()->rememberSelection(); dive_list()->unselectDives(); - disableDcShortcuts(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); // now cheat - create one dive that we use to store the info tab data in From 9b9abd5f2a93b6155df6663b4b1577408e1acc56 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 25 May 2014 15:56:39 -0300 Subject: [PATCH 06/10] Created a function to create a fake dive for Add and Plan states. This function should likely to move to C in the future, I'm only adding this here because I'm changing this file so much ( already 4 rewrites of the function ) Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 32 ++++++++++++++++++++------------ qt-ui/mainwindow.h | 1 + 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 1062e43d8..827401a58 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "divelistview.h" #include "starwidget.h" @@ -365,6 +366,24 @@ bool MainWindow::plannerStateClean() return true; } +void MainWindow::createFakeDiveForAddAndPlan() +{ + // now cheat - create one dive that we use to store the info tab data in + //TODO: C-function create_temporary_dive ? + struct dive *dive = alloc_dive(); + dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset(); + dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file + + dive->latitude.udeg = 0; + dive->longitude.udeg = 0; + record_dive(dive); + // this isn't in the UI yet, so let's call the C helper function - we'll fix this up when + // accepting the dive + select_dive(get_divenr(dive)); + ui.InfoWidget->updateDiveInfo(selected_dive); +} + + void MainWindow::on_actionDivePlanner_triggered() { if (!plannerStateClean()) @@ -396,20 +415,9 @@ void MainWindow::on_actionAddDive_triggered() dive_list()->unselectDives(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); - // now cheat - create one dive that we use to store the info tab data in - //TODO: C-function create_temporary_dive ? - struct dive *dive = alloc_dive(); - dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset(); - dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file + createFakeDiveForAddAndPlan(); - dive->latitude.udeg = 0; - dive->longitude.udeg = 0; - record_dive(dive); - // this isn't in the UI yet, so let's call the C helper function - we'll fix this up when - // accepting the dive - select_dive(get_divenr(dive)); ui.InfoWidget->setCurrentIndex(0); - ui.InfoWidget->updateDiveInfo(selected_dive); ui.InfoWidget->addDiveStarted(); ui.infoPane->setCurrentIndex(MAINTAB); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 667e3810a..8bb62b933 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -174,6 +174,7 @@ private: UpdateManager *updateManager; bool plannerStateClean(); + void createFakeDiveForAddAndPlan(); }; #endif // MAINWINDOW_H From eec0b327a3bb5f2d27594693d79a5bc86439c1e2 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 25 May 2014 17:49:26 -0300 Subject: [PATCH 07/10] Make the planner show something. This is working in the wrong way, mostly because I'm setting the plannermodel to ADD state ( and the planner graphic to the correct PLAN state ), but I don't know why - when on PLAN state on the model, things just don't work. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 19 ++++++++++++++----- qt-ui/profile/profilewidget2.cpp | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 827401a58..ac02527cb 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -383,18 +383,19 @@ void MainWindow::createFakeDiveForAddAndPlan() ui.InfoWidget->updateDiveInfo(selected_dive); } - void MainWindow::on_actionDivePlanner_triggered() { - if (!plannerStateClean()) + if(!plannerStateClean()) return; - int i; - struct dive *dive; + dive_list()->rememberSelection(); + dive_list()->unselectDives(); - DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); DivePlannerPointsModel::instance()->clear(); CylindersModel::instance()->clear(); + int i; + struct dive *dive; for_each_dive (i, dive) { if (dive->selected) { DivePlannerPointsModel::instance()->copyCylindersFrom(dive); @@ -402,8 +403,16 @@ void MainWindow::on_actionDivePlanner_triggered() break; } } + createFakeDiveForAddAndPlan(); + + ui.InfoWidget->setCurrentIndex(0); + ui.infoPane->setCurrentIndex(MAINTAB); + ui.newProfile->setPlanState(); ui.infoPane->setCurrentIndex(PLANNERWIDGET); + DivePlannerPointsModel::instance()->clear(); + DivePlannerPointsModel::instance()->createSimpleDive(); + ui.ListWidget->reload(DiveTripModel::CURRENT); } void MainWindow::on_actionAddDive_triggered() diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index c3e010c83..28a07404f 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -363,7 +363,7 @@ void ProfileWidget2::plotDives(QList dives) //TODO: This is a temporary hack to help me understand the Planner. // It seems that each time the 'createTemporaryPlan' runs, a new // dive is created, and thus, we can plot that. hm... - if (currentState == ADD) { + if (currentState == ADD || currentState == PLAN) { DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); plannerModel->createTemporaryPlan(); if (!plannerModel->getDiveplan().dp) { @@ -509,7 +509,7 @@ void ProfileWidget2::plotDives(QList dives) prefs.animation = animSpeedBackup; } - if (currentState == ADD) { // TODO: figure a way to move this from here. + if (currentState == ADD || currentState == PLAN) { // TODO: figure a way to move this from here. repositionDiveHandlers(); DivePlannerPointsModel *model = DivePlannerPointsModel::instance(); model->deleteTemporaryPlan(); From 660235c9b7cc719f3ba11c2eecceec18fab3cb54 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 25 May 2014 15:28:55 -0700 Subject: [PATCH 08/10] Planner: Don't include the ascent in the default dive Allow to both create the full default dive or ownly the descent and bottom part (so the planner can deal with the ascent). Signed-off-by: Dirk Hohndel --- qt-ui/diveplanner.cpp | 8 +++++--- qt-ui/diveplanner.h | 2 +- qt-ui/mainwindow.cpp | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 4fff79666..a7f97ebe2 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -59,13 +59,15 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector &rows) endRemoveRows(); } -void DivePlannerPointsModel::createSimpleDive() +void DivePlannerPointsModel::createSimpleDive(bool planner) { // plannerModel->addStop(0, 0, O2_IN_AIR, 0, 0); plannerModel->addStop(M_OR_FT(15, 45), 1 * 60, O2_IN_AIR, 0, 0, true); plannerModel->addStop(M_OR_FT(15, 45), 40 * 60, O2_IN_AIR, 0, 0, true); - plannerModel->addStop(M_OR_FT(5, 15), 42 * 60, O2_IN_AIR, 0, 0, true); - plannerModel->addStop(M_OR_FT(5, 15), 45 * 60, O2_IN_AIR, 0, 0, true); + if (!planner) { + plannerModel->addStop(M_OR_FT(5, 15), 42 * 60, O2_IN_AIR, 0, 0, true); + plannerModel->addStop(M_OR_FT(5, 15), 45 * 60, O2_IN_AIR, 0, 0, true); + } } void DivePlannerPointsModel::loadFromDive(dive *d) diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 4aa5f0094..781d7c741 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -39,7 +39,7 @@ public: void removeSelectedPoints(const QVector &rows); void setPlanMode(Mode mode); bool isPlanner(); - void createSimpleDive(); + void createSimpleDive(bool planner = false); void clear(); Mode currentMode() const; bool setRecalc(bool recalc); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index ac02527cb..63abd1d30 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -411,7 +411,7 @@ void MainWindow::on_actionDivePlanner_triggered() ui.newProfile->setPlanState(); ui.infoPane->setCurrentIndex(PLANNERWIDGET); DivePlannerPointsModel::instance()->clear(); - DivePlannerPointsModel::instance()->createSimpleDive(); + DivePlannerPointsModel::instance()->createSimpleDive(true); ui.ListWidget->reload(DiveTripModel::CURRENT); } From 42c54e7b7e202edcc6a568c4e91f1e973af0e208 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 26 May 2014 13:23:52 -0700 Subject: [PATCH 09/10] Planner: copy samples and events for plan and add Signed-off-by: Dirk Hohndel --- qt-ui/diveplanner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index a7f97ebe2..9edaac56a 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -776,7 +776,7 @@ void DivePlannerPointsModel::createTemporaryPlan() #endif if (plannerModel->recalcQ()) plan(&diveplan, &cache, &tempDive, isPlanner()); - if (mode == ADD) { + if (mode == ADD || mode == PLAN) { // copy the samples and events, but don't overwrite the cylinders copy_samples(tempDive, current_dive); copy_events(tempDive, current_dive); From cf3701bbac2f593c6efe046ba15be55bc1360f5b Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 26 May 2014 13:25:50 -0700 Subject: [PATCH 10/10] Planner: convert assert into warning We need to make sure we let the user know about this in a more user friendly way... Signed-off-by: Dirk Hohndel --- planner.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/planner.c b/planner.c index d3b5f288c..cf274bb31 100644 --- a/planner.c +++ b/planner.c @@ -676,7 +676,8 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b /* We will break out when we hit the surface */ do { /* Ascend to next stop depth */ - assert(deco_allowed_depth(tissue_tolerance, diveplan->surface_pressure / 1000.0, dive, 1) < depth); + if (deco_allowed_depth(tissue_tolerance, diveplan->surface_pressure / 1000.0, dive, 1) < depth) + fprintf(stderr, "user provided way point above ceiling\n"); int deltad = ascend_velocity(depth, avg_depth, bottom_time) * TIMESTEP; if (ascend_velocity(depth, avg_depth, bottom_time) != last_ascend_rate) { plan_add_segment(diveplan, clock - previous_point_time, depth, o2, he, po2, false);