Skip to content

Commit 3d7a4ca

Browse files
committedMay 25, 2011
modify RoadGraphPlugin for works with QGIS'api. Fix some bug
1 parent 8560e4d commit 3d7a4ca

21 files changed

+177
-1118
lines changed
 

‎src/analysis/network/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ SET(QGIS_NETWORK_ANALYSIS_SRCS
1313

1414
INCLUDE_DIRECTORIES(BEFORE raster)
1515

16-
SET(QGIS_ANALYSIS_MOC_HDRS
17-
qgslinevectorlayerdirector.cpp
16+
SET(QGIS_NETWORK_ANALYSIS_MOC_HDRS
17+
qgsgraphdirector.h
1818
)
1919

20-
QT4_WRAP_CPP(QGIS_NETWORK_ANALYSIS_MOC_SRCS ${QGIS_ANALYSIS_MOC_HDRS})
20+
QT4_WRAP_CPP(QGIS_NETWORK_ANALYSIS_MOC_SRCS ${QGIS_NETWORK_ANALYSIS_MOC_HDRS})
2121

2222

2323
INCLUDE_DIRECTORIES(
2424
${CMAKE_CURRENT_SOURCE_DIR}
2525
${CMAKE_CURRENT_SOURCE_DIR}../../core/
26-
interpolation
26+
${CMAKE_CURRENT_SOURCE_DIR}../../core/spatialindex
2727
${PROJ_INCLUDE_DIR}
2828
${GEOS_INCLUDE_DIR}
2929
${GDAL_INCLUDE_DIR}

‎src/analysis/network/qgsdistanceedgeproperter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
***************************************************************************/
1111

1212
//QGIS includes
13-
#include <qgsdistanceedgeproperter.h>
13+
#include "qgsdistanceedgeproperter.h"
1414

1515
QVariant QgsDistanceEdgeProperter::property( double distance, const QgsFeature& f ) const
1616
{

‎src/analysis/network/qgsedgeproperter.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,4 @@ class ANALYSIS_EXPORT QgsEdgeProperter
4949
virtual QVariant property( double distance, const QgsFeature& f ) const
5050
{ return QVariant(); }
5151
};
52-
53-
class ANALYSIS_EXPORT QgsEdgeDistanceProperter : public QgsEdgeProperter
54-
{
55-
public:
56-
virtual QVariant property( double distance, const QgsFeature& ) const
57-
{
58-
return QVariant( distance );
59-
}
60-
};
6152
#endif //QGSEDGEPROPERTYH

‎src/analysis/network/qgsgraphbuilderintr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ANALYSIS_EXPORT QgsGraphBuilderInterface
4242
* @param topologyTolerance sqrt distance between source point as one graph vertex
4343
*/
4444
QgsGraphBuilderInterface( const QgsCoordinateReferenceSystem& crs, const QgsDistanceArea& da, bool ctfEnabled = true, double topologyTolerance = 0.0) :
45-
mCrs( crs ), mDa( da ), mCtfEnabled ( ctfEnabled ), mTopologyTolerance( topologyTolerance )
45+
mCrs( crs ), mCtfEnabled ( ctfEnabled ), mTopologyTolerance( topologyTolerance )
4646
{
4747
mDa.setSourceCrs( mCrs.srsid() );
4848
}

‎src/plugins/roadgraph/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@ SET (VRP_SRCS
66
roadgraphplugin.cpp
77
settingsdlg.cpp
88
units.cpp
9-
utils.cpp
109
shortestpathwidget.cpp
1110
linevectorlayersettings.cpp
1211
linevectorlayerwidget.cpp
13-
linevectorlayerdirector.cpp
14-
simplegraphbuilder.cpp
1512
exportdlg.cpp
16-
graphbuilder.cpp
13+
speedproperter.cpp
1714
)
1815

1916
#SET ([pluginlcasename]_UIS [pluginlcasename]guibase.ui)
2017

2118
SET (VRP_MOC_HDRS
22-
graphdirector.h
2319
roadgraphplugin.h
2420
settingsdlg.h
2521
shortestpathwidget.h
@@ -32,8 +28,9 @@ INCLUDE_DIRECTORIES(
3228
${CMAKE_CURRENT_BINARY_DIR}
3329
${GEOS_INCLUDE_DIR}
3430
../../core
35-
../../core/spatialindex/
31+
../../core/spatialindex
3632
../../gui
33+
../../analysis/network
3734
..
3835
)
3936
########################################################
@@ -49,6 +46,7 @@ ADD_LIBRARY (roadgraphplugin MODULE ${VRP_SRCS} ${VRP_MOC_SRCS} ${VRP_RCC_SRCS})
4946
TARGET_LINK_LIBRARIES(roadgraphplugin
5047
qgis_core
5148
qgis_gui
49+
qgis_networkanalysis
5250
)
5351

5452

‎src/plugins/roadgraph/graphbuilder.cpp

Lines changed: 0 additions & 45 deletions
This file was deleted.

‎src/plugins/roadgraph/graphbuilder.h

Lines changed: 0 additions & 73 deletions
This file was deleted.

‎src/plugins/roadgraph/graphdirector.h

Lines changed: 0 additions & 63 deletions
This file was deleted.

‎src/plugins/roadgraph/linevectorlayerdirector.cpp

Lines changed: 0 additions & 258 deletions
This file was deleted.

‎src/plugins/roadgraph/linevectorlayerdirector.h

Lines changed: 0 additions & 90 deletions
This file was deleted.

‎src/plugins/roadgraph/linevectorlayerwidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ RgLineVectorLayerSettingsWidget::RgLineVectorLayerSettingsWidget( RgLineVectorLa
132132
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer_it.value() );
133133
if ( !vl )
134134
continue;
135-
if ( vl->geometryType() != QGis::Line )
136-
continue;
135+
// if ( vl->geometryType() != QGis::Line )
136+
// continue;
137137
mcbLayers->insertItem( 0, vl->name() );
138138
}
139139

‎src/plugins/roadgraph/roadgraphplugin.cpp

Lines changed: 28 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@
2727
#include <qgsvectorlayer.h>
2828
#include <qgsvectordataprovider.h>
2929

30+
#include <qgslinevectorlayerdirector.h>
31+
#include <qgsgraphbuilder.h>
32+
#include <qgsgraph.h>
33+
#include <qgsdistanceedgeproperter.h>
34+
3035
// Road grap plugin includes
3136
#include "roadgraphplugin.h"
3237
#include "shortestpathwidget.h"
3338
#include "settingsdlg.h"
39+
#include "speedproperter.h"
40+
#include "units.h"
3441

35-
#include "linevectorlayerdirector.h"
3642
#include "linevectorlayersettings.h"
37-
#include "simplegraphbuilder.h"
43+
3844
//
3945
// Qt4 Related Includes
4046
//
@@ -43,7 +49,6 @@
4349
#include <QLabel>
4450
#include <QLocale>
4551
#include <QToolBar>
46-
#include <QPainter>
4752
#include <QPushButton>
4853
#include <QDockWidget>
4954
#include <QVBoxLayout>
@@ -97,31 +102,21 @@ void RoadGraphPlugin::initGui()
97102

98103
// Create the action for tool
99104
mQSettingsAction = new QAction( QIcon( ":/roadgraph/road.png" ), tr( "Road graph settings" ), this );
100-
mQShowDirectionAction = new QAction( QIcon( ":/roadgraph/showdirect.png" ), tr( "Show road's direction" ), this );
101105
mInfoAction = new QAction( QIcon( ":/roadgraph/about.png" ), tr( "About" ), this );
102106

103107
// Set the what's this text
104108
mQSettingsAction->setWhatsThis( tr( "Road graph plugin settings" ) );
105-
mQShowDirectionAction->setWhatsThis( tr( "Roads direction viewer" ) );
106-
mInfoAction->setWhatsThis( tr( "About Road graph plugin" ) );
107-
108-
mQShowDirectionAction->setCheckable( true );
109+
mInfoAction->setWhatsThis( tr( "About Road graph plugin" ) );
109110

110111
setGuiElementsToDefault();
111112

112113
// Connect the action to slots
113114
connect( mQSettingsAction, SIGNAL( triggered() ), this, SLOT( property() ) );
114-
connect( mQShowDirectionAction, SIGNAL( triggered() ), this, SLOT( onShowDirection() ) );
115115
connect( mInfoAction, SIGNAL( triggered() ), SLOT( about() ) );
116116

117-
// Add the icons to the toolbar
118-
mQGisIface->addToolBarIcon( mQShowDirectionAction );
119-
120117
mQGisIface->addPluginToMenu( tr( "Road graph" ), mQSettingsAction );
121-
mQGisIface->addPluginToMenu( tr( "Road graph" ), mQShowDirectionAction );
122118
mQGisIface->addPluginToMenu( tr( "Road graph" ), mInfoAction );
123119

124-
connect( mQGisIface->mapCanvas(), SIGNAL( renderComplete( QPainter* ) ), this, SLOT( render( QPainter* ) ) );
125120
connect( mQGisIface, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
126121
connect( mQGisIface, SIGNAL( newProjectCreated() ), this, SLOT( newProject() ) );
127122
connect( mQGisIface, SIGNAL( projectRead() ), mQShortestPathDock, SLOT( clear() ) );
@@ -136,18 +131,13 @@ void RoadGraphPlugin::unload()
136131
{
137132
// remove the GUI
138133
mQGisIface->removePluginMenu( tr( "Road graph" ), mQSettingsAction );
139-
mQGisIface->removePluginMenu( tr( "Road graph" ), mQShowDirectionAction );
140134
mQGisIface->removePluginMenu( tr( "Road graph" ), mInfoAction );
141-
142-
mQGisIface->removeToolBarIcon( mQShowDirectionAction );
143-
135+
144136
// disconnect
145-
disconnect( mQGisIface->mapCanvas(), SIGNAL( renderComplete( QPainter* ) ), this, SLOT( render( QPainter* ) ) );
146137
disconnect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
147138
disconnect( mQGisIface->mainWindow(), SIGNAL( newProject() ), this, SLOT( newProject() ) );
148139

149140
delete mQSettingsAction;
150-
delete mQShowDirectionAction;
151141
delete mQShortestPathDock;
152142
} // RoadGraphPlugin::unload()
153143

@@ -261,7 +251,7 @@ QgisInterface* RoadGraphPlugin::iface()
261251
return mQGisIface;
262252
}
263253

264-
const RgGraphDirector* RoadGraphPlugin::director() const
254+
const QgsGraphDirector* RoadGraphPlugin::director() const
265255
{
266256
QString layerId;
267257
QgsVectorLayer *layer = NULL;
@@ -277,73 +267,29 @@ const RgGraphDirector* RoadGraphPlugin::director() const
277267
}
278268
if ( layer == NULL )
279269
return NULL;
280-
281-
QgsVectorDataProvider *provider = dynamic_cast< QgsVectorDataProvider* >( layer->dataProvider() );
282-
if ( provider == NULL )
283-
return NULL;
284-
285-
RgLineVectorLayerDirector * director =
286-
new RgLineVectorLayerDirector( layerId,
270+
if ( layer->geometryType() == QGis::Line )
271+
{
272+
QgsVectorDataProvider *provider = dynamic_cast< QgsVectorDataProvider* >( layer->dataProvider() );
273+
if ( provider == NULL )
274+
return NULL;
275+
SpeedUnit speedUnit = SpeedUnit::byName( mSettings->mSpeedUnitName );
276+
277+
QgsLineVectorLayerDirector * director =
278+
new QgsLineVectorLayerDirector( layerId,
287279
provider->fieldNameIndex( mSettings->mDirection ),
288280
mSettings->mFirstPointToLastPointDirectionVal,
289281
mSettings->mLastPointToFirstPointDirectionVal,
290282
mSettings->mBothDirectionVal,
291-
mSettings->mDefaultDirection,
292-
mSettings->mSpeedUnitName,
293-
provider->fieldNameIndex( mSettings->mSpeed ),
294-
mSettings->mDefaultSpeed );
295-
296-
return director;
283+
mSettings->mDefaultDirection
284+
);
285+
director->addProperter( new QgsDistanceEdgeProperter() );
286+
director->addProperter( new RgSpeedProperter( provider->fieldNameIndex( mSettings->mSpeed ),
287+
mSettings->mDefaultSpeed, speedUnit.multipler() ) );
288+
return director;
289+
}
290+
return NULL;
297291
}
298-
void RoadGraphPlugin::render( QPainter *painter )
299-
{
300-
if ( !mQShowDirectionAction->isChecked() )
301-
return;
302-
303-
const RgGraphDirector *graphDirector = director();
304292

305-
if ( graphDirector == NULL )
306-
return;
307-
308-
RgSimpleGraphBuilder builder( mQGisIface->mapCanvas()->mapRenderer()->destinationCrs(),
309-
mQGisIface->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
310-
QVector< QgsPoint > null;
311-
graphDirector->makeGraph( &builder , null, null );
312-
AdjacencyMatrix m = builder.adjacencyMatrix();
313-
314-
AdjacencyMatrix::iterator it1;
315-
AdjacencyMatrixString::iterator it2;
316-
for ( it1 = m.begin(); it1 != m.end(); ++it1 )
317-
{
318-
for ( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
319-
{
320-
QgsPoint p1 = mQGisIface->mapCanvas()->getCoordinateTransform()->transform( it1->first );
321-
QgsPoint p2 = mQGisIface->mapCanvas()->getCoordinateTransform()->transform( it2->first );
322-
double x1 = p1.x(),
323-
y1 = p1.y(),
324-
x2 = p2.x(),
325-
y2 = p2.y();
326-
327-
double length = sqrt( pow( x2 - x1, 2.0 ) + pow( y2 - y1, 2.0 ) );
328-
double Cos = ( x2 - x1 ) / length;
329-
double Sin = ( y2 - y1 ) / length;
330-
double centerX = ( x1 + x2 ) / 2;
331-
double centerY = ( y1 + y2 ) / 2;
332-
double r = mArrowSize;
333-
334-
QPointF pt1( centerX - Sin*r, centerY + Cos*r );
335-
QPointF pt2( centerX + Sin*r, centerY - Cos*r );
336-
337-
QVector<QPointF> tmp;
338-
tmp.resize( 3 );
339-
tmp[0] = QPointF( centerX + Cos * r * 2, centerY + Sin * r * 2 );
340-
tmp[1] = pt1;
341-
tmp[2] = pt2;
342-
painter->drawPolygon( tmp );
343-
}
344-
}
345-
delete graphDirector;
346-
}// RoadGraphPlugin::render()
347293
QString RoadGraphPlugin::timeUnitName()
348294
{
349295
return mTimeUnitName;

‎src/plugins/roadgraph/roadgraphplugin.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class QgisInterface;
3030
class QDockWidget;
3131

3232
//forward declarations RoadGraph plugins classes
33-
class RgGraphDirector;
33+
class QgsGraphDirector;
3434
class RgShortestPathWidget;
3535
class RgLineVectorLayerSettings;
3636

@@ -59,7 +59,7 @@ class RoadGraphPlugin: public QObject, public QgisPlugin
5959
/**
6060
* return pointer to graph director
6161
*/
62-
const RgGraphDirector* director() const;
62+
const QgsGraphDirector* director() const;
6363

6464
/**
6565
* get time unit name
@@ -131,11 +131,6 @@ class RoadGraphPlugin: public QObject, public QgisPlugin
131131
*/
132132
QAction * mQSettingsAction;
133133

134-
/**
135-
* pointer ot the direction show action
136-
*/
137-
QAction * mQShowDirectionAction;
138-
139134
/**
140135
* pointer ot the about action
141136
*/
@@ -166,8 +161,6 @@ class RoadGraphPlugin: public QObject, public QgisPlugin
166161
*/
167162
double mTopologyToleranceFactor;
168163

169-
private:
170-
static const int mArrowSize = 5;
171164
};
172165

173166
#endif //ROADGRAPHPLUGIN

‎src/plugins/roadgraph/shortestpathwidget.cpp

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
#include <qgsapplication.h>
3939
#include <qgsvectorlayer.h>
4040

41+
#include <qgsgraphdirector.h>
42+
#include <qgsgraphbuilder.h>
43+
#include <qgsgraph.h>
44+
#include <qgsgraphanalyzer.h>
45+
4146
// roadgraph plugin includes
4247
#include "roadgraphplugin.h"
4348
#include "shortestpathwidget.h"
44-
#include "utils.h"
45-
#include "simplegraphbuilder.h"
46-
#include "graphdirector.h"
4749
#include "exportdlg.h"
4850
#include "units.h"
4951
#include "settings.h"
@@ -228,21 +230,22 @@ void RgShortestPathWidget::setBackPoint( const QgsPoint& pt )
228230
mrbBackPoint->show();
229231
}
230232

231-
bool RgShortestPathWidget::getPath( AdjacencyMatrix& matrix, QgsPoint& p1, QgsPoint& p2 )
233+
bool RgShortestPathWidget::getPath( QgsGraph* shortestTree, QgsPoint& p1, QgsPoint& p2 )
232234
{
233235
if ( mFrontPointLineEdit->text().isNull() || mBackPointLineEdit->text().isNull() )
234236
{
235237
QMessageBox::critical( this, tr( "Point not selected" ), tr( "First, select start and stop points." ) );
236238
return false;
237239
}
238240

239-
RgSimpleGraphBuilder builder(
240-
mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
241-
mPlugin->iface()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled(),
241+
QgsDistanceArea da;
242+
QgsGraphBuilder builder(
243+
mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
244+
da,
245+
mPlugin->iface()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled(),
242246
mPlugin->topologyToleranceFactor() );
243-
244247
{
245-
const RgGraphDirector *director = mPlugin->director();
248+
const QgsGraphDirector *director = mPlugin->director();
246249
if ( director == NULL )
247250
{
248251
QMessageBox::critical( this, tr( "Plugin isn't configured" ), tr( "Plugin isn't configured!" ) );
@@ -256,8 +259,8 @@ bool RgShortestPathWidget::getPath( AdjacencyMatrix& matrix, QgsPoint& p1, QgsPo
256259

257260
points.push_back( mFrontPoint );
258261
points.push_back( mBackPoint );
259-
260262
director->makeGraph( &builder, points, tiedPoint );
263+
261264
p1 = tiedPoint[ 0 ];
262265
p2 = tiedPoint[ 1 ];
263266
// not need
@@ -274,16 +277,20 @@ bool RgShortestPathWidget::getPath( AdjacencyMatrix& matrix, QgsPoint& p1, QgsPo
274277
QMessageBox::critical( this, tr( "Tie point failed" ), tr( "Stop point doesn't tie to the road!" ) );
275278
return false;
276279
}
277-
AdjacencyMatrix m = builder.adjacencyMatrix();
278-
279-
DijkstraFinder::OptimizationCriterion criterion = DijkstraFinder::byCost;
280-
if ( mCriterionName->currentIndex() == 1 )
281-
criterion = DijkstraFinder::byTime;
282-
283-
DijkstraFinder f( m, criterion );
284-
285-
matrix = f.find( p1, p2 );
286-
if ( matrix.find( p1 ) == matrix.end() )
280+
QgsGraph* graph = builder.graph();
281+
QVector< int > pointIdx(0,0);
282+
QVector< double > pointCost(0,0.0);
283+
284+
int startVertexIdx = graph->findVertex( p1 );
285+
int criterionNum = 0;
286+
if ( mCriterionName->currentIndex() > 0 )
287+
criterionNum = 1;
288+
289+
QgsGraphAnalyzer::shortestpath( graph, startVertexIdx, criterionNum, pointIdx, pointCost, shortestTree );
290+
291+
delete graph;
292+
293+
if ( shortestTree->findVertex( p2 ) == -1 )
287294
{
288295
QMessageBox::critical( this, tr( "Path not found" ), tr( "Path not found" ) );
289296
return false;
@@ -294,29 +301,39 @@ bool RgShortestPathWidget::getPath( AdjacencyMatrix& matrix, QgsPoint& p1, QgsPo
294301
void RgShortestPathWidget::findingPath()
295302
{
296303
QgsPoint p1, p2;
297-
AdjacencyMatrix path;
298-
if ( !getPath( path, p1, p2 ) )
304+
QgsGraph path;
305+
306+
if ( !getPath( &path, p1, p2) )
299307
return;
300-
308+
301309
mrbPath->reset( false );
302310
double time = 0.0;
303311
double cost = 0.0;
304-
305-
AdjacencyMatrix::iterator it = path.find( p1 );
306-
if ( it == path.end() )
307-
return;
308-
mrbPath->addPoint( it->first );
309-
310-
while ( it != path.end() )
312+
313+
int startVertexIdx = path.findVertex( p1 );
314+
int stopVertexIdx = path.findVertex( p2 );
315+
QList< QgsPoint > p;
316+
while( startVertexIdx != stopVertexIdx )
311317
{
312-
AdjacencyMatrixString::iterator it2 = it->second.begin();
313-
if ( it2 == it->second.end() )
318+
QgsGraphEdgeList l = path.vertex( stopVertexIdx ).inEdges();
319+
if ( l.empty() )
314320
break;
315-
mrbPath->addPoint( it2->first );
316-
time += it2->second.mTime;
317-
cost += it2->second.mCost;
318-
it = path.find( it2->first );
321+
const QgsGraphEdge& e = path.edge( l.front() );
322+
323+
cost += e.property(0).toDouble();
324+
time += e.property(1).toDouble();
325+
326+
p.push_front( path.vertex( e.in() ).point() );
327+
328+
stopVertexIdx = e.out();
319329
}
330+
p.push_front( p1 );
331+
QList< QgsPoint>::iterator it;
332+
for ( it = p.begin(); it != p.end(); ++it )
333+
{
334+
mrbPath->addPoint( *it );
335+
}
336+
320337
Unit timeUnit = Unit::byName( mPlugin->timeUnitName() );
321338
Unit distanceUnit = Unit::byName( mPlugin->distanceUnitName() );
322339

@@ -339,12 +356,12 @@ void RgShortestPathWidget::clear()
339356

340357
void RgShortestPathWidget::exportPath()
341358
{
342-
RgExportDlg dlg( this );
359+
/* RgExportDlg dlg( this );
343360
if ( !dlg.exec() )
344361
return;
345362
346363
QgsPoint p1, p2;
347-
AdjacencyMatrix path;
364+
QgsGraph path;
348365
if ( !getPath( path, p1, p2 ) )
349366
return;
350367
@@ -355,12 +372,6 @@ void RgShortestPathWidget::exportPath()
355372
QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
356373
vl->crs() );
357374
358-
QVector< QgsPoint > points;
359-
AdjacencyMatrix::iterator it = path.find( p1 );
360-
if ( it == path.end() )
361-
return;
362-
points.append( ct.transform( it->first ) );
363-
364375
while ( it != path.end() )
365376
{
366377
AdjacencyMatrixString::iterator it2 = it->second.begin();
@@ -377,7 +388,7 @@ void RgShortestPathWidget::exportPath()
377388
vl->updateExtents();
378389
379390
mPlugin->iface()->mapCanvas()->update();
380-
391+
*/
381392
}
382393

383394
void RgShortestPathWidget::helpRequested()

‎src/plugins/roadgraph/shortestpathwidget.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#ifndef ROADGRAPHPLUGIN_SHORTESTPATHDLG_H
1313
#define ROADGRAPHPLUGIN_SHORTESTPATHDLG_H
1414

15-
#include "utils.h"
16-
1715
// QT includes
1816
#include <QDockWidget>
1917

@@ -34,6 +32,8 @@ class QgsMapCanvas;
3432

3533
class RoadGraphPlugin;
3634

35+
class QgsGraph;
36+
3737
/**
3838
@author Sergey Yakushev
3939
*/
@@ -105,7 +105,7 @@ class RgShortestPathWidget : public QDockWidget
105105
/**
106106
* retrun path as a graph
107107
*/
108-
bool getPath( AdjacencyMatrix &m, QgsPoint& p1, QgsPoint& p2 );
108+
bool getPath( QgsGraph *, QgsPoint& p1, QgsPoint& p2 );
109109

110110
/**
111111
* This line edit show front points coordinates

‎src/plugins/roadgraph/simplegraphbuilder.cpp

Lines changed: 0 additions & 64 deletions
This file was deleted.

‎src/plugins/roadgraph/simplegraphbuilder.h

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/***************************************************************************
2+
* Copyright (C) 2009 by Sergey Yakushev *
3+
* yakushevs@list.ru *
4+
* *
5+
* This is file implements Units classes *
6+
* *
7+
* This program is free software; you can redistribute it and/or modify *
8+
* it under the terms of the GNU General Public License as published by *
9+
* the Free Software Foundation; either version 2 of the License, or *
10+
* (at your option) any later version. *
11+
***************************************************************************/
12+
13+
#include "speedproperter.h"
14+
15+
RgSpeedProperter::RgSpeedProperter( int attributeId, double defaultValue, double toMetricFactor )
16+
{
17+
mAttributeId = attributeId;
18+
mDefaultValue = defaultValue;
19+
mToMetricFactor = toMetricFactor;
20+
}
21+
22+
QVariant RgSpeedProperter::property( double distance, const QgsFeature& f ) const
23+
{
24+
const QgsAttributeMap& map = f.attributeMap();
25+
QgsAttributeMap::const_iterator it = map.find( mAttributeId );
26+
27+
if ( it == map.end() )
28+
return QVariant( distance/(mDefaultValue*mToMetricFactor) );
29+
30+
double val = distance/(it->toDouble()*mToMetricFactor);
31+
if ( val <= 0.0 )
32+
return QVariant( distance/(mDefaultValue/mToMetricFactor) );
33+
34+
return QVariant( val );
35+
}
36+
37+
QgsAttributeList RgSpeedProperter::requiredAttributes() const
38+
{
39+
QgsAttributeList l;
40+
l.push_back( mAttributeId );
41+
return l;
42+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/***************************************************************************
2+
* Copyright (C) 2011 by Sergey Yakushev *
3+
* yakushevs@list.ru *
4+
* *
5+
* This is file define vrp plugins time, distance and speed units *
6+
* classes *
7+
* *
8+
* This program is free software; you can redistribute it and/or modify *
9+
* it under the terms of the GNU General Public License as published by *
10+
* the Free Software Foundation; either version 2 of the License, or *
11+
* (at your option) any later version. *
12+
***************************************************************************/
13+
14+
#ifndef ROADGRAPH_SPEEDPROPERTER_H
15+
#define ROADGRAPH_SPEEDPROPERTER_H
16+
17+
#include <qgsedgeproperter.h>
18+
19+
class RgSpeedProperter : public QgsEdgeProperter
20+
{
21+
public:
22+
RgSpeedProperter( int attributeId, double defaultValue, double toMetricFactor );
23+
24+
QVariant property( double distance, const QgsFeature& f ) const;
25+
26+
QgsAttributeList requiredAttributes() const;
27+
private:
28+
int mAttributeId;
29+
double mDefaultValue;
30+
double mToMetricFactor;
31+
32+
};
33+
34+
#endif

‎src/plugins/roadgraph/utils.cpp

Lines changed: 0 additions & 166 deletions
This file was deleted.

‎src/plugins/roadgraph/utils.h

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.