@@ -66,6 +66,33 @@ void writePolyline( struct Map_info* map, int type, QgsPolyline polyline, struct
6666 Vect_write_line ( map, type, line, cats );
6767}
6868
69+ void exitIfCanceled ( QDataStream& stdinStream, bool isPolygon,
70+ const QString & tmpName, struct Map_info * tmpMap,
71+ const QString & finalName, struct Map_info * finalMap )
72+ {
73+ bool isCanceled;
74+ stdinStream >> isCanceled;
75+ if ( !isCanceled )
76+ {
77+ return ;
78+ }
79+ if ( isPolygon )
80+ {
81+ Vect_close ( tmpMap );
82+ Vect_delete ( tmpName.toUtf8 ().data () );
83+ }
84+ Vect_close ( finalMap );
85+ Vect_delete ( finalName.toUtf8 ().data () );
86+ G_warning ( " import canceled -> maps deleted" );
87+ exit ( EXIT_SUCCESS );
88+ }
89+
90+ // G_set_percent_routine only works in GRASS >= 7
91+ // int percent_routine (int)
92+ // {
93+ // TODO: use it to interrupt cleaning functions
94+ // }
95+
6996int main ( int argc, char **argv )
7097{
7198 struct Option *mapOption;
@@ -91,6 +118,7 @@ int main( int argc, char **argv )
91118 QGis::WkbType wkbFlatType = QGis::flatType ( wkbType );
92119 bool isPolygon = QGis::singleType ( wkbFlatType ) == QGis::WKBPolygon;
93120
121+ QString finalName = QString ( mapOption->answer );
94122 struct Map_info finalMap, tmpMap;
95123 Vect_open_new ( &finalMap, mapOption->answer , 0 );
96124 struct Map_info * map = &finalMap;
@@ -148,6 +176,7 @@ int main( int argc, char **argv )
148176 qint32 featureCount = 0 ;
149177 while ( true )
150178 {
179+ exitIfCanceled ( stdinStream, isPolygon, tmpName, &tmpMap, finalName, &finalMap );
151180 stdinStream >> feature;
152181 if ( !feature.isValid () )
153182 {
@@ -279,6 +308,7 @@ int main( int argc, char **argv )
279308 // read once more to assign centroids to polygons
280309 while ( true )
281310 {
311+ exitIfCanceled ( stdinStream, isPolygon, tmpName, &tmpMap, finalName, &finalMap );
282312 stdinStream >> feature;
283313 if ( !feature.isValid () )
284314 {
0 commit comments