Skip to content

Commit

Permalink
Road-Graph plugin added
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15068 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
stopa85 committed Jan 24, 2011
1 parent a85387d commit b3b85d7
Show file tree
Hide file tree
Showing 31 changed files with 3,186 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SUBDIRS (copyright_label
point_displacement_renderer
spatialquery
sqlanywhere
roadgraph
)

IF (WITH_SPATIALITE)
Expand Down
57 changes: 57 additions & 0 deletions src/plugins/roadgraph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

########################################################
# Files

SET (VRP_SRCS
roadgraphplugin.cpp
settingsdlg.cpp
units.cpp
utils.cpp
shortestpathwidget.cpp
linevectorlayersettings.cpp
linevectorlayerwidget.cpp
linevectorlayerdirector.cpp
simplegraphbuilder.cpp
exportdlg.cpp
)

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

SET (VRP_MOC_HDRS
roadgraphplugin.h
settingsdlg.h
shortestpathwidget.h
linevectorlayerwidget.h
exportdlg.h
)
SET (VRP_RCCS roadgraph.qrc)

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
../../core
../../gui
..
)
########################################################
# Build

QT4_WRAP_CPP (VRP_MOC_SRCS ${VRP_MOC_HDRS})

QT4_ADD_RESOURCES(VRP_RCC_SRCS ${VRP_RCCS})

ADD_LIBRARY (roadgraphplugin MODULE ${VRP_SRCS} ${VRP_MOC_SRCS} ${VRP_RCC_SRCS})


TARGET_LINK_LIBRARIES(roadgraphplugin
qgis_core
qgis_gui
)


########################################################
# Install

INSTALL(TARGETS roadgraphplugin
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

Binary file added src/plugins/roadgraph/about.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/plugins/roadgraph/coordinate_capture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions src/plugins/roadgraph/exportdlg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/***************************************************************************
* Copyright (C) 2010 by Sergey Yakushev *
* yakushevs@list.ru *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "exportdlg.h"
#include <qgscontexthelp.h>

//qt includes
#include <qlabel.h>
#include <qcombobox.h>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <qdialogbuttonbox.h>
#include <qmessagebox.h>


// Qgis includes
#include <qgsvectorlayer.h>
#include <qgsmaplayerregistry.h>
#include <qgsproviderregistry.h>
#include <qgsvectordataprovider.h>

//standard includes

RgExportDlg::RgExportDlg( QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
{
// create base widgets;
setWindowTitle( tr("Export feature") );
QVBoxLayout *v = new QVBoxLayout( this );

QHBoxLayout *h = new QHBoxLayout();
QLabel *l = new QLabel( tr("Select destination layer:"), this);
h->addWidget(l);
mcbLayers = new QComboBox( this );
h->addWidget(mcbLayers);
v->addLayout(h);

QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
connect(bb, SIGNAL(accepted()), this, SLOT(on_buttonBox_accepted()) );
connect(bb, SIGNAL(rejected()), this, SLOT(on_buttonBox_rejected()) );
v->addWidget(bb);

//fill list of layers
mcbLayers->insertItem( 0, tr("new temporary layer"), QVariant("-1") );

QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin();

for ( ; layer_it != mapLayers.end(); ++layer_it )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer_it.value() );
if ( !vl )
continue;
if ( vl->geometryType() != QGis::Line )
continue;
mcbLayers->insertItem( 0, vl->name(), QVariant( vl->getLayerID() ) );
}

} // RgSettingsDlg::RgSettingsDlg()

RgExportDlg::~RgExportDlg()
{
}

QgsVectorLayer* RgExportDlg::mapLayer() const
{
QgsVectorLayer* myLayer = NULL;
QString layerId = mcbLayers->itemData( mcbLayers->currentIndex() ).toString();

if ( layerId == QString("-1") )
{
// create a temporary layer
myLayer = new QgsVectorLayer( "LineString", "shortest path", "memory" );

QgsVectorDataProvider *prov = myLayer->dataProvider();
if ( prov == NULL)
return NULL;

QList<QgsField> attrList;
attrList.append( QgsField("one", QVariant::Int) );
prov->addAttributes( attrList );
QgsMapLayerRegistry::instance()->addMapLayer( myLayer );

}else
{
// retrun selected layer
myLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
}

return myLayer;
} // QgsVectorLayer* RgExportDlg::vectorLayer() const

void RgExportDlg::on_buttonBox_accepted()
{
accept();
} // void RgExportDlg::on_buttonBox_accepted()

void RgExportDlg::on_buttonBox_rejected()
{
reject();
}

void RgExportDlg::on_buttonBox_helpRequested()
{
QgsContextHelp::run( context_id );
}
54 changes: 54 additions & 0 deletions src/plugins/roadgraph/exportdlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/***************************************************************************
exportdlg.h
--------------------------------------
Date : 2010-11-29
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef ROADGRAPH_EXPORTDLG_H
#define ROADGRAPH_EXPORTDLG_H

#include <QDialog>

// forward declaration QT-classes
class QComboBox;

// forward declaration Qgis-classes

//forward declaration RoadGraph plugins classes
class QgsVectorLayer;

/**
@author Sergey Yakushev
*/
/**
* \class RgSettingsDlg
* \brief implement of export dialog
*/
class RgExportDlg : public QDialog
{
Q_OBJECT
public:
RgExportDlg( QWidget* parent = 0, Qt::WFlags fl = 0 );
~RgExportDlg();
public:
QgsVectorLayer* mapLayer() const;
private:
static const int context_id = 0;

private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_buttonBox_helpRequested();

private:
QComboBox *mcbLayers;
};
#endif
69 changes: 69 additions & 0 deletions src/plugins/roadgraph/graphbuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/***************************************************************************
graphbuilder.h
--------------------------------------
Date : 2010-10-22
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef ROADGRAPH_GRAPHBUILDER
#define ROADGRAPH_GRAPHBUILDER

#include "utils.h"

//QT4 includes

//QGIS includes
#include <qgspoint.h>
#include <qgscoordinatereferencesystem.h>

//forward declarations

/**
* \class RgGraphDirector
* \brief Determine making the graph
* contained the settings
*/
class RgGraphBuilder
{
public:
//! Destructor
virtual ~RgGraphBuilder()
{};
/**
* set source CRS
*/
virtual void setSourceCrs( const QgsCoordinateReferenceSystem& crs ) = 0;

/**
* set destionation CRS
*/
virtual void setDestinationCrs( const QgsCoordinateReferenceSystem& crs ) = 0;

/**
* add vertex
*/
virtual void addVertex( const QgsPoint& pt ) = 0;

/**
* add arc
*/
virtual void addArc( const QgsPoint& pt1, const QgsPoint& pt2, double speed ) = 0;

/**
* tie point
* @param pt maps point
* @param pt ok = false if tiePoint failed.
* @return Graph vertex corresponding pt.
* @note: graph can be modified
*/
virtual QgsPoint tiePoint( const QgsPoint &pt, bool &ok ) = 0;

};
#endif //GRAPHBUILDER
53 changes: 53 additions & 0 deletions src/plugins/roadgraph/graphdirector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/***************************************************************************
graphdirector.h
--------------------------------------
Date : 2010-10-18
Copyright : (C) 2010 by Yakushev Sergey
Email : YakushevS <at> list.ru
****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef ROADGRAPH_GRAPHDIRECTOR
#define ROADGRAPH_GRAPHDIRECTOR

//QT4 includes

//QGIS includes
#include <qgsrectangle.h>

//forward declarations
class RgSettings;
class RgGraphBuilder;

/**
* \class RgGraphDirector
* \brief Determine making the graph
* contained the settings
*/
class RgGraphDirector
{
public:
//! Destructor
virtual ~RgGraphDirector() { };

/**
* get adjacency matrix
*/
virtual void makeGraph( RgGraphBuilder * ) const = 0;

/**
* return pointer to my Settings
*/
virtual RgSettings* settings() = 0;

/**
* return Director name
*/
virtual QString name() const = 0;
};
#endif //GRAPHDIRECTOR
Loading

0 comments on commit b3b85d7

Please sign in to comment.