Hello Dirk,

Attached are the two patches, one from Robert Helling
"0001-Distinguish-between-entered-and-calculated-waypoints.patch" and
the other by me built relative to Robert' patch.

Since, I could not apply patch from Robert onto current master, I went
back to the commit "7902af2" and applied his patch, and my patch is
built relative to his patch then. Is it possible to modify patches so
that they can be applied to the current master.

Thank you,
Lakshman
From 3dbdb57f5c5a64e1b6279af060bd13bab62b1607 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <[email protected]>
Date: Wed, 12 Mar 2014 16:49:42 +0100
Subject: [PATCH] Distinguish between entered and calculated waypoints

Signed-off-by: Robert C. Helling <[email protected]>
---
 dive.h                |  2 +-
 planner.c             | 11 ++++++-----
 qt-ui/diveplanner.cpp | 22 ++++++++++++++--------
 qt-ui/diveplanner.h   |  2 +-
 qt-ui/mainwindow.cpp  |  2 +-
 5 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/dive.h b/dive.h
index febc608..fe523b2 100644
--- a/dive.h
+++ b/dive.h
@@ -808,7 +808,7 @@ struct diveplan {
 	struct divedatapoint *dp;
 };
 
-struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he, int po2);
+struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he, int po2, bool entered);
 void get_gas_string(int o2, int he, char *buf, int len);
 struct divedatapoint *create_dp(int time_incr, int depth, int o2, int he, int po2);
 void dump_plan(struct diveplan *diveplan);
diff --git a/planner.c b/planner.c
index 5142b0e..9415567 100644
--- a/planner.c
+++ b/planner.c
@@ -382,9 +382,10 @@ void add_to_end_of_diveplan(struct diveplan *diveplan, struct divedatapoint *dp)
 		dp->time += lasttime;
 }
 
-struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he, int po2)
+struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he, int po2, bool entered)
 {
 	struct divedatapoint *dp = create_dp(duration, depth, o2, he, po2);
+	dp->entered = entered;
 	add_to_end_of_diveplan(diveplan, dp);
 	return (dp);
 }
@@ -620,7 +621,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b
 	/* if all we wanted was the dive just get us back to the surface */
 	if (!add_deco) {
 		transitiontime = depth / 75; /* this still needs to be made configurable */
-		plan_add_segment(diveplan, transitiontime, 0, o2, he, po2);
+		plan_add_segment(diveplan, transitiontime, 0, o2, he, po2, false);
 		/* re-create the dive */
 		delete_single_dive(dive_table.nr - 1);
 		*divep = dive = create_dive_from_plan(diveplan, error_string_p);
@@ -662,7 +663,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b
 #if DEBUG_PLAN & 2
 		printf("transitiontime %d:%02d to depth %5.2lfm\n", FRACTION(transitiontime, 60), stoplevels[stopidx] / 1000.0);
 #endif
-		plan_add_segment(diveplan, transitiontime, stoplevels[stopidx], o2, he, po2);
+		plan_add_segment(diveplan, transitiontime, stoplevels[stopidx], o2, he, po2, false);
 		/* re-create the dive */
 		delete_single_dive(dive_table.nr - 1);
 		*divep = dive = create_dive_from_plan(diveplan, error_string_p);
@@ -697,13 +698,13 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b
 		       stoplevels[stopidx] / 1000.0, ceiling / 1000.0);
 #endif
 		if (wait_time)
-			plan_add_segment(diveplan, wait_time, stoplevels[stopidx], o2, he, po2);
+			plan_add_segment(diveplan, wait_time, stoplevels[stopidx], o2, he, po2, false);
 		/* right now all the transitions are at 30ft/min - this needs to be configurable */
 		transitiontime = (stoplevels[stopidx] - stoplevels[stopidx - 1]) / 150;
 #if DEBUG_PLAN & 2
 		printf("transitiontime %d:%02d to depth %5.2lfm\n", FRACTION(transitiontime, 60), stoplevels[stopidx - 1] / 1000.0);
 #endif
-		plan_add_segment(diveplan, transitiontime, stoplevels[stopidx - 1], o2, he, po2);
+		plan_add_segment(diveplan, transitiontime, stoplevels[stopidx - 1], o2, he, po2, false);
 		/* re-create the dive */
 		delete_single_dive(dive_table.nr - 1);
 		*divep = dive = create_dive_from_plan(diveplan, error_string_p);
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index c5715f9..03b1a20 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -392,16 +392,16 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent *event)
 
 	int minutes = rint(timeLine->valueAt(mappedPos));
 	int milimeters = rint(depthLine->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
-	plannerModel->addStop(milimeters, minutes * 60, -1, 0, 0);
+	plannerModel->addStop(milimeters, minutes * 60, -1, 0, 0, true);
 }
 
 void DivePlannerPointsModel::createSimpleDive()
 {
 	//	plannerModel->addStop(0, 0, O2_IN_AIR, 0, 0);
-	plannerModel->addStop(M_OR_FT(15, 45), 1 * 60, O2_IN_AIR, 0, 0);
-	plannerModel->addStop(M_OR_FT(15, 45), 40 * 60, O2_IN_AIR, 0, 0);
-	plannerModel->addStop(M_OR_FT(5, 15), 42 * 60, O2_IN_AIR, 0, 0);
-	plannerModel->addStop(M_OR_FT(5, 15), 45 * 60, 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);
 }
 
 void DivePlannerPointsModel::loadFromDive(dive *d)
@@ -422,7 +422,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
 		if (s.time.seconds == 0)
 			continue;
 		get_gas_from_events(&backupDive.dc, lasttime, &o2, &he);
-		plannerModel->addStop(s.depth.mm, s.time.seconds, o2, he, 0);
+		plannerModel->addStop(s.depth.mm, s.time.seconds, o2, he, 0, true);
 		lasttime = s.time.seconds;
 	}
 }
@@ -521,12 +521,16 @@ void DivePlannerGraphics::drawProfile()
 			item->setPen(QPen(QBrush(Qt::red), 0));
 			scene()->addItem(item);
 			lines << item;
+			if (dp->depth)
+				qDebug() << "Time: " << dp->time / 60 << " depth: " << dp->depth / 1000;
 		}
 		lastx = xpos;
 		lasty = ypos;
 		poly.append(QPointF(lastx, lasty));
 	}
 
+	qDebug() << " ";
+
 	diveBg->setPolygon(poly);
 	QRectF b = poly.boundingRect();
 	QLinearGradient pat(
@@ -1186,7 +1190,7 @@ bool DivePlannerPointsModel::addGas(int o2, int he)
 	return false;
 }
 
-int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he, int ccpoint)
+int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he, int ccpoint, bool entered)
 {
 	int row = divepoints.count();
 	if (seconds == 0 && milimeters == 0 && row != 0) {
@@ -1253,6 +1257,7 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he,
 	point.o2 = o2;
 	point.he = he;
 	point.po2 = ccpoint;
+	point.entered = entered;
 	divepoints.append(point);
 	std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
 	endInsertRows();
@@ -1410,7 +1415,8 @@ void DivePlannerPointsModel::createTemporaryPlan()
 		divedatapoint p = at(i);
 		int deltaT = lastIndex != -1 ? p.time - at(lastIndex).time : p.time;
 		lastIndex = i;
-		plan_add_segment(&diveplan, deltaT, p.depth, p.o2, p.he, p.po2);
+		p.entered = true;
+		plan_add_segment(&diveplan, deltaT, p.depth, p.o2, p.he, p.po2, true);
 	}
 	char *cache = NULL;
 	tempDive = NULL;
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 4679d06..1393d9f 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -57,7 +57,7 @@ public:
 
 public
 slots:
-	int addStop(int millimeters = 0, int seconds = 0, int o2 = 0, int he = 0, int ccpoint = 0);
+	int addStop(int millimeters = 0, int seconds = 0, int o2 = 0, int he = 0, int ccpoint = 0, bool entered = true);
 	void addCylinder_clicked();
 	void setGFHigh(const int gfhigh);
 	void setGFLow(const int ghflow);
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 426e979..8ec4b69 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -76,7 +76,7 @@ MainWindow::MainWindow() : QMainWindow(),
 	ui.divePlannerWidget->settingsChanged();
 
 #ifndef ENABLE_PLANNER
-	ui.menuLog->removeAction(ui.actionDivePlanner);
+//	ui.menuLog->removeAction(ui.actionDivePlanner);
 #endif
 }
 
-- 
1.8.3.4 (Apple Git-47)

From 7484166ffb8ec9fdf75c2a0d242f75b7fdf1fb2e Mon Sep 17 00:00:00 2001
From: Lakshman Anumolu <[email protected]>
Date: Mon, 31 Mar 2014 23:24:33 -0500
Subject: [PATCH 2/2] Diveplan with entered and computed waypoints to UI

Recently Robert Helling provided a patch
"0001-Distinguish-between-entered-and-calculated-waypoints.patch"
in an attempt to distinguish between entered and calculated stops.
This patch is an independent (content wise) extension of the above
patch and is built relative to it which adds new table to display
computed waypoints in plan mode.

NOTE: I couldnot apply the above patch from Robert onto the current
master, hence I am writing this patch for the commit 7902af2.

Currently table includes only two columns "Comp. Depth" and "Comp.
Duration", which can extended to show further information.

This is only a start to the UI interaction in PLAN mode.
In addition to this there are many TODO things that diveplan feature
demands

TODO:
1. Show more details through "Computed Waypoints" table.
2. Remove tooltip from "Computed Waypoints" table widget.
3. Make contents in "Computed Waypoints" table widget non-editable.
4. Fix error when trying to save dive plan without using cylinder data.
5. Make dive plan editable after saving it.
6. Improvise dive planner graphics window.

Signed-off-by: Lakshman Anumolu <[email protected]>
---
 qt-ui/diveplanner.cpp | 128 +++++++++++++++++++++++++++++++++++++++++++++++++-
 qt-ui/diveplanner.h   |  37 +++++++++++++++
 qt-ui/diveplanner.ui  |  18 ++++++-
 3 files changed, 181 insertions(+), 2 deletions(-)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 03b1a20..ad950f2 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -42,6 +42,124 @@ QString dpGasToStr(const divedatapoint &p)
 	return gasToStr(p.o2, p.he);
 }
 
+static DivePlannerDisplay *plannerDisplay = DivePlannerDisplay::instance();
+
+DivePlannerDisplay::DivePlannerDisplay(QObject *parent) : QAbstractTableModel(parent)
+{
+}
+
+DivePlannerDisplay *DivePlannerDisplay::instance()
+{
+	static QScopedPointer<DivePlannerDisplay> self(new DivePlannerDisplay());
+	return self.data();
+}
+
+int DivePlannerDisplay::size()
+{
+	return computedPoints.size();
+}
+
+int DivePlannerDisplay::columnCount(const QModelIndex &parent) const
+{
+	return COLUMNS;
+}
+
+QVariant DivePlannerDisplay::data(const QModelIndex &index, int role) const
+{
+	if (role == Qt::DisplayRole) {
+		computedPoint p = computedPoints.at(index.row());
+		switch (index.column()) {
+		case COMPUTED_DEPTH:
+			return rint(get_depth_units(p.computedDepth, NULL, NULL));
+		case COMPUTED_DURATION:
+			return p.computedTime / 60;
+		}
+	} else if (role == Qt::DecorationRole) {
+		switch (index.column()) {
+		}
+	} else if (role == Qt::FontRole) {
+		return defaultModelFont();
+	}
+	return QVariant();
+}
+
+bool DivePlannerDisplay::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+	if (role == Qt::EditRole) {
+		computedPoint &p = computedPoints[index.row()];
+		switch (index.column()) {
+		case COMPUTED_DEPTH:
+			p.computedDepth = units_to_depth(value.toInt());
+			break;
+		case COMPUTED_DURATION:
+			p.computedTime = value.toInt() * 60;
+			break;
+		}
+	}
+	return QAbstractItemModel::setData(index, value, role);
+}
+
+QVariant DivePlannerDisplay::headerData(int section, Qt::Orientation orientation, int role) const
+{
+	if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
+		switch (section) {
+		case COMPUTED_DEPTH:
+			return tr("Comp. Depth");
+		case COMPUTED_DURATION:
+			return tr("Comp. Duration");
+		}
+	} else if (role == Qt::FontRole) {
+		return defaultModelFont();
+	}
+	return QVariant();
+}
+
+Qt::ItemFlags DivePlannerDisplay::flags(const QModelIndex &index) const
+{
+	return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
+}
+
+int DivePlannerDisplay::rowCount(const QModelIndex &parent) const
+{
+	return computedPoints.size();
+}
+
+struct computedPoint DivePlannerDisplay::at(int row)
+{
+	return computedPoints.at(row);
+}
+
+void DivePlannerDisplay::clear()
+{
+	if (rowCount() > 0) {
+		beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
+		computedPoints.clear();
+		endRemoveRows();
+	}
+}
+
+void DivePlannerDisplay::removeStops()
+{
+	if (rowCount() > 0) {
+		beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
+		endRemoveRows();
+	}
+}
+
+void DivePlannerDisplay::addStops()
+{
+	int rows = computedPoints.size();
+	if (rows > 0) {
+		beginInsertRows(QModelIndex(), 0, rows - 1);
+		endInsertRows();
+	}
+}
+
+void DivePlannerDisplay::insertPoint(const struct computedPoint &p)
+{
+	computedPoints.append(p);
+}
+
 static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
 
 DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent),
@@ -511,6 +629,7 @@ void DivePlannerGraphics::drawProfile()
 	QPolygonF poly;
 	poly.append(QPointF(lastx, lasty));
 
+	plannerDisplay->clear();
 	for (dp = diveplan.dp; dp != NULL; dp = dp->next) {
 		if (dp->time == 0) // magic entry for available tank
 			continue;
@@ -521,8 +640,11 @@ void DivePlannerGraphics::drawProfile()
 			item->setPen(QPen(QBrush(Qt::red), 0));
 			scene()->addItem(item);
 			lines << item;
-			if (dp->depth)
+			if (dp->depth) {
 				qDebug() << "Time: " << dp->time / 60 << " depth: " << dp->depth / 1000;
+				computedPoint p(dp->time, dp->depth);
+				plannerDisplay->insertPoint(p);
+			}
 		}
 		lastx = xpos;
 		lasty = ypos;
@@ -530,6 +652,7 @@ void DivePlannerGraphics::drawProfile()
 	}
 
 	qDebug() << " ";
+	plannerDisplay->addStops();
 
 	diveBg->setPolygon(poly);
 	QRectF b = poly.boundingRect();
@@ -937,6 +1060,8 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
 	ui.tableWidget->setTitle(tr("Dive Planner Points"));
 	ui.tableWidget->setModel(DivePlannerPointsModel::instance());
 	ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
+	ui.tableWidgetComp->setTitle(tr("Computed Waypoints"));
+	ui.tableWidgetComp->setModel(DivePlannerDisplay::instance());
 	ui.cylinderTableWidget->setTitle(tr("Available Gases"));
 	ui.cylinderTableWidget->setModel(CylindersModel::instance());
 	QTableView *view = ui.cylinderTableWidget->view();
@@ -956,6 +1081,7 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
 		GasSelectionModel::instance(), SLOT(repopulate()));
 
 	ui.tableWidget->setBtnToolTip(tr("add dive data point"));
+	ui.tableWidgetComp->setBtnToolTip(tr("This does nothing, and should be removed"));
 	connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
 	connect(ui.ATMPressure, SIGNAL(textChanged(QString)), this, SLOT(atmPressureChanged(QString)));
 	connect(ui.bottomSAC, SIGNAL(textChanged(QString)), this, SLOT(bottomSacChanged(QString)));
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 1393d9f..84ac4a8 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -12,6 +12,43 @@
 class QListView;
 class QModelIndex;
 
+struct computedPoint {
+	int computedTime;
+	unsigned int computedDepth;
+	computedPoint(int computedTime_, unsigned int computedDepth_) {
+		computedTime = computedTime_;
+		computedDepth = computedDepth_;
+	};
+	computedPoint() {};
+};
+
+class DivePlannerDisplay : public QAbstractTableModel {
+	Q_OBJECT
+private:
+	explicit DivePlannerDisplay(QObject *parent = 0);
+	QVector<computedPoint> computedPoints;
+
+public:
+	static DivePlannerDisplay *instance();
+	enum Sections {
+		COMPUTED_DEPTH,
+		COMPUTED_DURATION,
+		COLUMNS
+	};
+	virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+	virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+	virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+	virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+	virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+	virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+	void clear();
+	computedPoint at(int row);
+	int size();
+	void removeStops();
+	void addStops();
+	void insertPoint(const struct computedPoint &p);
+};
+
 class DivePlannerPointsModel : public QAbstractTableModel {
 	Q_OBJECT
 public:
diff --git a/qt-ui/diveplanner.ui b/qt-ui/diveplanner.ui
index 558be06..986f1b9 100644
--- a/qt-ui/diveplanner.ui
+++ b/qt-ui/diveplanner.ui
@@ -142,7 +142,7 @@
          </property>
         </widget>
        </item>
-       <item row="8" column="0" colspan="2">
+       <item row="8" column="0" colspan="1">
         <widget class="TableView" name="tableWidget" native="true">
          <property name="sizePolicy">
           <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
@@ -158,6 +158,22 @@
          </property>
         </widget>
        </item>
+       <item row="8" column="1" colspan="1">
+	<widget class="TableView" name="tableWidgetComp" native="true">
+	 <property name="sizePolicy">
+	  <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+	   <horstretch>0</horstretch>
+	   <verstretch>0</verstretch>
+	  </sizepolicy>
+	 </property>
+	 <property name="minimumSize">
+	  <size>
+	   <width>0</width>
+	   <height>50</height>
+	  </size>
+	 </property>
+	</widget>
+       </item>
        <item row="9" column="0" colspan="2">
         <widget class="QDialogButtonBox" name="buttonBox">
          <property name="standardButtons">
-- 
1.8.3.2

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to