2004-07-12 15:25:37 +00:00
|
|
|
/***************************************************************************
|
2004-07-29 12:49:13 +00:00
|
|
|
qgsgrassedit.h - GRASS Edit
|
2004-07-12 15:25:37 +00:00
|
|
|
-------------------
|
|
|
|
begin : March, 2004
|
|
|
|
copyright : (C) 2004 by Radim Blazek
|
|
|
|
email : blazek@itc.it
|
|
|
|
***************************************************************************/
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* 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 QGSGRASSEDIT_H
|
|
|
|
#define QGSGRASSEDIT_H
|
|
|
|
|
2004-10-26 17:28:03 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2005-03-04 16:08:26 +00:00
|
|
|
class QString;
|
2005-03-30 16:54:16 +00:00
|
|
|
class QCloseEvent;
|
2005-03-04 16:08:26 +00:00
|
|
|
|
2004-07-12 15:25:37 +00:00
|
|
|
#include <qpointarray.h>
|
|
|
|
#include <qcursor.h>
|
|
|
|
#include <qpen.h>
|
|
|
|
#include <qpainter.h>
|
|
|
|
|
|
|
|
// Must be here, so that it is included to moc file
|
2004-07-29 12:49:13 +00:00
|
|
|
#include "../../src/qgisapp.h"
|
2004-07-12 15:25:37 +00:00
|
|
|
#include "../../src/qgspoint.h"
|
|
|
|
#include "../../src/qgisiface.h"
|
2004-12-30 02:52:37 +00:00
|
|
|
#include "../../src/qgsmaptopixel.h"
|
2004-07-12 15:25:37 +00:00
|
|
|
|
|
|
|
class QgsGrassProvider;
|
|
|
|
#include "qgsgrasseditbase.h"
|
2004-07-29 12:49:13 +00:00
|
|
|
#include "qgsgrassselect.h"
|
|
|
|
#include "qgsgrassattributes.h"
|
2004-07-12 15:25:37 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int field;
|
|
|
|
int maxCat;
|
|
|
|
} MaxCat;
|
|
|
|
|
|
|
|
/*! \class QgsGrassEdit
|
|
|
|
* \brief GRASS vector edit.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class QgsGrassEdit: public QgsGrassEditBase
|
|
|
|
{
|
|
|
|
Q_OBJECT;
|
|
|
|
|
|
|
|
public:
|
|
|
|
//! Tools
|
|
|
|
enum EditTools {
|
|
|
|
NONE,
|
|
|
|
NEW_POINT,
|
|
|
|
NEW_LINE,
|
|
|
|
NEW_BOUNDARY,
|
|
|
|
NEW_CENTROID,
|
|
|
|
MOVE_VERTEX,
|
|
|
|
ADD_VERTEX,
|
|
|
|
DELETE_VERTEX,
|
|
|
|
SPLIT_LINE,
|
|
|
|
MOVE_LINE,
|
|
|
|
DELETE_LINE,
|
|
|
|
EDIT_CATS,
|
|
|
|
EDIT_ATTRIBUTES
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Icons
|
|
|
|
enum Icons {
|
|
|
|
ICON_NONE,
|
|
|
|
ICON_CROSS,
|
|
|
|
ICON_X,
|
|
|
|
ICON_BOX
|
|
|
|
};
|
|
|
|
|
|
|
|
// Symbology codes */
|
|
|
|
enum SymbCode {
|
|
|
|
SYMB_BACKGROUND,
|
|
|
|
SYMB_HIGHLIGHT,
|
|
|
|
SYMB_DYNAMIC,
|
|
|
|
SYMB_POINT,
|
|
|
|
SYMB_LINE,
|
|
|
|
SYMB_BOUNDARY_0, /* No areas */
|
|
|
|
SYMB_BOUNDARY_1, /* 1 area */
|
|
|
|
SYMB_BOUNDARY_2, /* 2 areas */
|
|
|
|
SYMB_CENTROID_IN, /* Centroid in area */
|
|
|
|
SYMB_CENTROID_OUT, /* Centroid outside area */
|
|
|
|
SYMB_CENTROID_DUPL, /* Duplicate centroid in area */
|
|
|
|
SYMB_NODE_0, /* Node without lines (points or centroids) */
|
|
|
|
SYMB_NODE_1, /* Node with 1 line */
|
|
|
|
SYMB_NODE_2, /* Node with 2 lines */
|
|
|
|
SYMB_COUNT /* MUST BE LAST, number of symbology layers */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum CatMode {
|
|
|
|
CAT_MODE_NEXT = 0,
|
|
|
|
CAT_MODE_MANUAL,
|
|
|
|
CAT_MODE_NOCAT
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Constructor
|
2004-07-29 12:49:13 +00:00
|
|
|
QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
|
|
|
|
QWidget * parent = 0, const char * name = 0, WFlags f = 0 );
|
2004-07-12 15:25:37 +00:00
|
|
|
|
2005-09-27 16:14:53 +00:00
|
|
|
QgsGrassEdit ( QgisApp *qgisApp, QgisIface *iface,
|
|
|
|
QgsGrassProvider *provider,
|
|
|
|
QWidget * parent = 0, const char * name = 0, WFlags f = 0 );
|
|
|
|
|
|
|
|
// Shared by constructors
|
|
|
|
void init ();
|
|
|
|
|
2004-07-12 15:25:37 +00:00
|
|
|
//! Destructor
|
|
|
|
~QgsGrassEdit();
|
|
|
|
|
|
|
|
//! Close editing
|
|
|
|
bool isValid (void);
|
|
|
|
|
|
|
|
//! Close editing
|
|
|
|
static bool isRunning (void);
|
|
|
|
|
|
|
|
//! Set new tool and close old one if any
|
|
|
|
void startTool (int);
|
|
|
|
|
2004-07-29 12:49:13 +00:00
|
|
|
//! Add category to selected line
|
|
|
|
void addCat ( int line );
|
|
|
|
|
|
|
|
//! Delete category from selected line
|
|
|
|
void deleteCat ( int line, int field, int cat );
|
|
|
|
|
|
|
|
//! Add attributes to current mAttributes
|
|
|
|
void addAttributes ( int field, int cat );
|
|
|
|
|
|
|
|
//! Increase max cat
|
|
|
|
void increaseMaxCat ( void );
|
|
|
|
|
2004-07-12 15:25:37 +00:00
|
|
|
public slots:
|
|
|
|
// TODO: once available in QGIS, use only one reciver for all signals
|
|
|
|
|
|
|
|
//! Mouse event receiver
|
|
|
|
void mouseEventReceiverMove ( QgsPoint & );
|
|
|
|
|
|
|
|
//! Mouse event receiver
|
2005-03-04 16:08:26 +00:00
|
|
|
void mouseEventReceiverClick ( QgsPoint &p, Qt::ButtonState button );
|
2004-07-12 15:25:37 +00:00
|
|
|
|
|
|
|
//! Called when rendering is finished
|
|
|
|
void postRender ( QPainter * );
|
|
|
|
|
|
|
|
// Slots to start tools (is it possible to pass tool to startTool() directly from GUI ?)
|
|
|
|
void newPoint (void); // digitize new point
|
|
|
|
void newLine (void); // digitize new line
|
|
|
|
void newBoundary (void); // digitize new boundary
|
|
|
|
void newCentroid (void); // digitize new centroid
|
|
|
|
void moveVertex (void); // move vertex of existing line/boundary
|
|
|
|
void addVertex (void); // add new vertex to existing line/boundary
|
|
|
|
void deleteVertex (void); // delete vertex of existing line/boundary
|
|
|
|
void splitLine (void); // split existing line/boundary
|
|
|
|
void moveLine (void); // move existing line/boundary
|
|
|
|
void deleteLine (void); // delete existing line/boundary
|
|
|
|
void editCats (void); // edit element categories
|
|
|
|
void editAttributes (void); // edit element attributes
|
|
|
|
|
|
|
|
//! Category mode was changed
|
|
|
|
void catModeChanged ( void );
|
|
|
|
|
|
|
|
//! Field was changed
|
|
|
|
void fieldChanged ( void );
|
|
|
|
|
|
|
|
//! Close editing
|
|
|
|
void closeEdit (void);
|
|
|
|
|
2004-07-30 16:24:26 +00:00
|
|
|
void changeSymbology( QListViewItem * item, const QPoint & pnt, int col );
|
|
|
|
|
2004-08-02 15:56:28 +00:00
|
|
|
// The type of column was changed
|
|
|
|
void columnTypeChanged ( int row, int col );
|
|
|
|
|
2005-03-30 16:54:16 +00:00
|
|
|
// ! Close event
|
|
|
|
void closeEvent(QCloseEvent *e);
|
|
|
|
|
2004-07-12 15:25:37 +00:00
|
|
|
private:
|
|
|
|
//! Editing is already running
|
|
|
|
static bool mRunning;
|
|
|
|
|
|
|
|
//! Point / node size (later make editable array of Sizes)
|
|
|
|
int mSize;
|
|
|
|
|
|
|
|
//! Display all lines and nodes
|
|
|
|
void displayMap (void);
|
|
|
|
|
|
|
|
//! Set point array to icon
|
|
|
|
void setIconPoints ( QPointArray &points, int type, int size );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display icon
|
|
|
|
* @param x x coordinate in map units
|
|
|
|
* @param y y coordinate in map units
|
|
|
|
* @param type ICON_CROSS, ICON_X
|
|
|
|
* @param size size in pixels, should be odd number
|
|
|
|
*/
|
|
|
|
void displayIcon (double x, double y, const QPen & pen, int type, int size, QPainter *painter = 0);
|
|
|
|
|
|
|
|
//! Last dynamicaly drawn points
|
2005-04-06 11:50:23 +00:00
|
|
|
struct line_pnts *mLastDynamicPoints;
|
|
|
|
//QPointArray mLastDynamicPoints;
|
2004-07-12 15:25:37 +00:00
|
|
|
|
|
|
|
//! Last dynamicaly drawn icon type
|
|
|
|
int mLastDynamicIcon;
|
|
|
|
double mLastDynamicIconX;
|
|
|
|
double mLastDynamicIconY;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display dynamic drawing (XOR)
|
|
|
|
* Old drawing (in mLastDynamicPoints) is deleted first, and new one is drawn and
|
|
|
|
* mLastDynamicPoints is set to Points.
|
|
|
|
* SYMB_DYNAMIC color is used
|
|
|
|
*/
|
|
|
|
void displayDynamic ( struct line_pnts *Points );
|
|
|
|
|
|
|
|
/** Display dynamic icon */
|
|
|
|
void displayDynamic ( double x, double y, int type, int size );
|
|
|
|
|
|
|
|
/* Display dynamic points + icon */
|
|
|
|
void displayDynamic ( struct line_pnts *Points, double x, double y, int type, int size );
|
|
|
|
|
|
|
|
/* Display last dynamic points + icon */
|
|
|
|
void displayLastDynamic ( void ) ;
|
|
|
|
|
|
|
|
/** Erase dynamic */
|
|
|
|
void eraseDynamic ( void );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display map element (lines and points)
|
|
|
|
* @param line line number
|
|
|
|
*/
|
|
|
|
void displayElement (int line, const QPen & pen, int size, QPainter *painter = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Erase element and its nodes using SYMB_BACKGROUD
|
|
|
|
* @param line line number
|
|
|
|
*/
|
|
|
|
void eraseElement ( int line );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display one node
|
|
|
|
* @param painter pointer to painter or 0
|
|
|
|
* @param node node number
|
|
|
|
* @param size size in pixels, should be odd number
|
|
|
|
*/
|
|
|
|
void displayNode ( int node, const QPen & pen, int size, QPainter *painter = 0);
|
|
|
|
|
|
|
|
//! Status: true - active vector was successfully opened for editing
|
|
|
|
bool mValid;
|
|
|
|
|
2004-07-29 12:49:13 +00:00
|
|
|
//! QGIS application
|
|
|
|
QgisApp *mQgisApp;
|
|
|
|
|
2004-07-12 15:25:37 +00:00
|
|
|
//! Pointer to the QGIS interface object
|
|
|
|
QgisIface *mIface;
|
|
|
|
|
|
|
|
//! Pointer to canvas
|
|
|
|
QgsMapCanvas *mCanvas;
|
|
|
|
|
|
|
|
//! Pointer to vector provider
|
|
|
|
QgsGrassProvider *mProvider;
|
|
|
|
|
|
|
|
//! Current tool (EditTools)
|
|
|
|
int mTool;
|
|
|
|
|
|
|
|
//! If tool is not closed and another QGIS tool is selected, suspend is set to true.
|
|
|
|
// GRASS Edit will continue if the same tool is selected later.
|
|
|
|
bool mSuspend;
|
|
|
|
|
|
|
|
//! Currently digitized line points,
|
|
|
|
// points of currently mooving line (original coordinates)
|
|
|
|
struct line_pnts *mEditPoints;
|
|
|
|
|
|
|
|
//! Working structure for line points
|
|
|
|
struct line_pnts *mPoints;
|
|
|
|
|
|
|
|
//! Working category structure
|
|
|
|
struct line_cats *mCats;
|
|
|
|
|
|
|
|
//! Vector of maximum used category values for each field
|
|
|
|
std::vector<MaxCat> mMaxCats;
|
|
|
|
|
|
|
|
//! Canvas pixmap
|
|
|
|
QPixmap *mPixmap;
|
|
|
|
|
|
|
|
//! Transformation
|
2004-12-30 02:52:37 +00:00
|
|
|
QgsMapToPixel *mTransform;
|
2004-07-12 15:25:37 +00:00
|
|
|
|
|
|
|
//! Last point where user clicked (map units)
|
|
|
|
QgsPoint mLastPoint;
|
|
|
|
|
|
|
|
//! Selected line or 0
|
|
|
|
int mSelectedLine;
|
|
|
|
|
|
|
|
//! Selected segment or vertex (first is 0) (MOVE_VERTEX, ADD_VERTEX, DELETE_VERTEX)
|
|
|
|
int mSelectedPart;
|
|
|
|
|
|
|
|
//! Appand a new vertex at the end (not insert into existing segment)
|
|
|
|
bool mAddVertexEnd;
|
|
|
|
|
|
|
|
//! Vector of symbology codes for lines, indexes of lines start at 1, always resize nlines+1
|
|
|
|
std::vector<int> mLineSymb;
|
|
|
|
|
|
|
|
//! Vector of symbology codes for nodes, indexes of nodes start at 1, always resize nnodes+1
|
|
|
|
std::vector<int> mNodeSymb;
|
|
|
|
|
|
|
|
//! Vector of pens for symbology codes
|
|
|
|
std::vector<QPen> mSymb;
|
|
|
|
|
2004-07-30 16:24:26 +00:00
|
|
|
//! Display this type
|
|
|
|
std::vector<bool> mSymbDisplay;
|
|
|
|
|
|
|
|
//! Symbology name
|
|
|
|
std::vector<QString> mSymbName;
|
|
|
|
|
2004-07-12 15:25:37 +00:00
|
|
|
/**
|
|
|
|
* Read line symbology from map
|
|
|
|
* @return symbology code
|
|
|
|
*/
|
|
|
|
int lineSymbFromMap ( int line );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read node symbology from map
|
|
|
|
* @return symbology code
|
|
|
|
*/
|
|
|
|
int nodeSymbFromMap ( int node );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set symbology of updated lines and nodes from map
|
|
|
|
*/
|
|
|
|
void updateSymb ( void );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display updated lines and nodes
|
|
|
|
*/
|
|
|
|
void displayUpdated ( void );
|
|
|
|
|
2004-07-29 12:49:13 +00:00
|
|
|
/** Write new element. Current field category is taken.
|
|
|
|
* return line number
|
|
|
|
*/
|
|
|
|
int writeLine ( int type, struct line_pnts *Points );
|
2004-07-12 15:25:37 +00:00
|
|
|
|
|
|
|
/** Get Current threshold in map units */
|
|
|
|
double threshold ( void );
|
|
|
|
|
|
|
|
/** Snap to nearest node in current threshold */
|
|
|
|
void snap ( QgsPoint & point );
|
|
|
|
void snap ( double *x, double *y);
|
|
|
|
|
2004-07-29 12:49:13 +00:00
|
|
|
/** Attributes */
|
|
|
|
QgsGrassAttributes *mAttributes;
|
|
|
|
|
|
|
|
void restorePosition(void);
|
|
|
|
|
|
|
|
void saveWindowLocation(void);
|
2004-08-02 15:56:28 +00:00
|
|
|
|
|
|
|
// Set attribute table
|
|
|
|
void setAttributeTable(int field);
|
|
|
|
|
|
|
|
// Change attribute table
|
|
|
|
void attributeTableFieldChanged(void);
|
|
|
|
|
|
|
|
// Add column
|
|
|
|
void addColumn(void);
|
|
|
|
|
|
|
|
// Alter table
|
|
|
|
void alterTable(void);
|
|
|
|
|
2005-03-04 16:08:26 +00:00
|
|
|
// Pront which should be displayed in status bar when mouse is in canvas
|
|
|
|
QString mCanvasPrompt;
|
|
|
|
|
|
|
|
// Set prompt for mouse buttons
|
|
|
|
void setCanvasPropmt ( QString left, QString mid, QString rigth);
|
2005-09-27 16:14:53 +00:00
|
|
|
|
|
|
|
// New map, add new layers on exit
|
|
|
|
bool mNewMap;
|
2004-07-12 15:25:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // QGSGRASSEDIT_H
|