-
Notifications
You must be signed in to change notification settings - Fork 1
/
qrap.cpp
964 lines (861 loc) · 31.4 KB
/
qrap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
/*
* QRAP Project
*
* Version : 0.1
* Date : 2008/04/01
* License : GNU GPLv3
* File : qrap.cpp
* Copyright : (c) University of Pretoria
* Author : Dirk van der Merwe
* : Magdaleen Ballot
* : email: magdaleen.ballot@up.ac.za
* Description : This is the main QRap plugin for QGIS. QRap is Radio
* Planning Tool.
*
**************************************************************************
* *
* 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 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; See the GNU General Public License for *
* more details *
* *
************************************************************************* */
#include "qrap.h"
//
// Qt4 Related Includes
#include <QAction>
#include <QToolBar>
#include <QMessageBox>
#ifdef WIN32
#define QGISEXTERN extern "C" __declspec( dllexport )
#else
#define QGISEXTERN extern "C"
#endif
//////////////////////////////////////////////////////////////////////
//
// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
//
//////////////////////////////////////////////////////////////////////
//**********************************************************************
/**
* Constructor for the plugin. The plugin is passed a pointer
* an interface object that provides access to exposed functions in QGIS.
* @param theQGisInterface - Pointer to the QGIS interface object
*/
static const QString pPluginIcon = ":/qrap/Coverage.png";
//static const char * const pIdent = "$Id: qrap.cpp 9327 2008-06-10 11:18:44Z magdaleen $";
static const QgisPlugin::PLUGINTYPE pPluginType = QgisPlugin::UI;
static const QString pCategory = QObject::tr( "Database" );
static const QString pName = QObject::tr("Q-Rap");
static const QString pDescription = QObject::tr("Radio Systems Planning Tool");
static const QString pPluginVersion = QObject::tr("Version 0.1");
//*************************************************************************
QRap::QRap(QgisInterface * theQgisInterface):
QgisPlugin( pName, pDescription, pCategory, pPluginVersion, pPluginType ),
// qgisMainWindow(theQgisInterface->mainWindow() ),
mQGisIface (theQgisInterface)
{
}
//************************************************************************
QRap::~QRap()
{
}
//
//*****************************************************************************
/*
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
* added to the plugin registry in the QGIS application.
*/
void QRap::initGui()
{
mToolBarPointer = 0;
printf("QRap::initGui\n");
mPoints.clear();
mMouseType = CLEAN;
// Create the action for tool
cout << "VOOR DataBase Connect" << endl;
openDatabaseConnection();
cout << "Na DataBase Connect" << endl;
cout << "Voor new Actions" << endl;
mQActionPointer = new QAction(QIcon(":/qrap/Data.png"),tr("Q-Rap Database Interface"), this);
mSiteAction = new QAction(QIcon(":/qrap/Site.png"),tr("Q-Rap: Place a Site"), this);
mSelectSiteAction = new QAction(QIcon(":/qrap/SiteSelect.png"),tr("Q-Rap: Select a Site"), this);
mDeleteSiteAction = new QAction(QIcon(":/qrap/SiteDelete.png"),tr("Q-Rap: Delete a Site"), this);
mLinkAction = new QAction(QIcon(":/qrap/Link.png"),tr("Q-Rap: Link Analysis"), this);
mSelectLinkAction = new QAction(QIcon(":/qrap/LinkSelect.png"),tr("Q-Rap: Select a Link"), this);
mDeleteLinkAction = new QAction(QIcon(":/qrap/LinkDelete.png"),tr("Q-Rap: Delete a Link"), this);
mMultiLinkAction = new QAction(QIcon(":/qrap/MultiLink.png"),tr("Q-Rap: Establish all Links possible in set of Sites"), this);
mRadioAction = new QAction(QIcon(":/qrap/Coverage.png"),tr("Q-Rap: Perform a Prediction"), this);
mMeasAnalysisAction = new QAction(QIcon(":/qrap/Measurements.png"),tr("Q-Rap: Compare measurements with predictions"), this);
mSpectralAction = new QAction(QIcon(":/qrap/Spectral.png"),tr("Q-Rap: Perform Spectral Interference Analysis"), this);
mPreferencesAction = new QAction(QIcon(":/qrap/Preferences.png"),tr("Q-Rap Preferences"), this);
mOptimisationAction = new QAction(QIcon(":/qrap/Optimisation.png"),tr("Q-Rap: Optimise link structure in selected area"), this);
// mImportExportAction = new QAction(QIcon(":/qrap/ImportExport.png"),tr("Import Export"),this);
// mHelpAction = new QAction(QIcon(":/qrap/Help.png"),tr("Q-Rap Help"), this);
cout << "Na new Actions" << endl;
// Connect the action to the run
connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));
connect(mSiteAction, SIGNAL(activated()), this, SLOT(PlaceSite()));
connect(mSelectSiteAction, SIGNAL(activated()), this, SLOT(SelectSite()));
connect(mDeleteSiteAction, SIGNAL(activated()), this, SLOT(DeleteSite()));
connect(mLinkAction, SIGNAL(activated()), this, SLOT(CreateLinkAnalysis()));
connect(mDeleteLinkAction, SIGNAL(activated()), this, SLOT(DeleteLink()));
connect(mMultiLinkAction, SIGNAL(activated()), this, SLOT(MultiLink()));
connect(mSelectLinkAction, SIGNAL(activated()), this, SLOT(SelectLink()));
connect(mRadioAction, SIGNAL(activated()), this, SLOT(Prediction()));
connect(mMeasAnalysisAction, SIGNAL(activated()), this, SLOT(Measurements()));
connect(mSpectralAction, SIGNAL(activated()), this, SLOT(SpectralAnalysis()));
connect(mPreferencesAction, SIGNAL(activated()), this, SLOT(Preferences()));
connect(mOptimisationAction, SIGNAL(activated()), this, SLOT(Optimise()));
// connect(mImportExportAction,SIGNAL(activated()), this, SLOT(ImportExport()));
// connect(mHelpAction,SIGNAL(activated()), this, SLOT(Help()));
cout << "Na Connect" << endl;
// Add the toolbar to the main window
mToolBarPointer = mQGisIface->addToolBar(tr("Q-Rap"));
mToolBarPointer->setIconSize(QSize(24,24));
mToolBarPointer->setObjectName("Q-Rap");
// Add the icon to the toolbar
mToolBarPointer->addAction(mSiteAction);
mToolBarPointer->addAction(mSelectSiteAction);
mToolBarPointer->addAction(mDeleteSiteAction);
mToolBarPointer->addAction(mLinkAction);
mToolBarPointer->addAction(mSelectLinkAction);
mToolBarPointer->addAction(mDeleteLinkAction);
mToolBarPointer->addAction(mRadioAction);
mToolBarPointer->addAction(mMultiLinkAction);
mToolBarPointer->addAction(mMeasAnalysisAction);
mToolBarPointer->addAction(mSpectralAction);
mToolBarPointer->addAction(mOptimisationAction);
mToolBarPointer->addAction(mPreferencesAction);
mToolBarPointer->addAction(mQActionPointer);
// mToolBarPointer->addAction(mImportExportAction);
// mToolBarPointer->addAction(mHelpAction);
mLoaded = true;
// openDatabaseConnection();
// cout << "Na DataBase Connect" << endl;
// mQGisIface->addToolBarIcon( mQActionPointer );
// mQGisIface->addPluginToMenu( tr( "Q-Rap Database" ), mQActionPointer );
Mouse = new MouseEvents(mQGisIface->mapCanvas());
cout << "Na Mouse" << endl;
connect(Mouse, SIGNAL(RightPoint(QgsPoint&)), this, SLOT(ReceivedRightPoint(QgsPoint&)));
connect(Mouse, SIGNAL(LeftPoint(QgsPoint&)), this, SLOT(ReceivedLeftPoint(QgsPoint&)));
}
//****************************************************************************************
//method defined in interface
void QRap::help()
{
}
//****************************************************************************************
// Unload the plugin by cleaning up the GUI
void QRap::unload()
{
if (mLoaded)
{
// remove the GUI
mToolBarPointer->removeAction(mSiteAction);
mToolBarPointer->removeAction(mSelectSiteAction);
mToolBarPointer->removeAction(mDeleteSiteAction);
mToolBarPointer->removeAction(mLinkAction);
mToolBarPointer->removeAction(mSelectLinkAction);
mToolBarPointer->removeAction(mDeleteLinkAction);
mToolBarPointer->removeAction(mRadioAction);
mToolBarPointer->removeAction(mMultiLinkAction);
mToolBarPointer->removeAction(mOptimisationAction);
mToolBarPointer->removeAction(mSpectralAction);
mToolBarPointer->removeAction(mPreferencesAction);
mToolBarPointer->removeAction(mMeasAnalysisAction);
mToolBarPointer->removeAction(mQActionPointer);
delete mQActionPointer;
delete mSelectSiteAction;
delete mDeleteSiteAction;
delete mSiteAction;
delete mRadioAction;
delete mLinkAction;
delete mSelectLinkAction;
delete mDeleteLinkAction;
delete mSpectralAction;
delete mMultiLinkAction;
delete mPreferencesAction;
delete mMeasAnalysisAction;
delete mToolBarPointer;
disconnect(Mouse);
// delete Mouse;
mLoaded =false;
}
cout << "QRap::unload(): leaving" << endl;
}
//////////////////////////////////////////////////////////////////////////
//
//
// THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
// YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
// MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
//
//
//////////////////////////////////////////////////////////////////////////
//************************************************************************
/**
* Required extern functions needed for every plugin
* These functions can be called prior to creating an instance
* of the plugin class
*/
// Class factory to return a new instance of the plugin class
QGISEXTERN QgisPlugin * classFactory(QgisInterface * theQgisInterfacePointer)
{
return new QRap(theQgisInterfacePointer);
}
//******************************************************************************
// Return the name of the plugin - note that we do not user class members as
// the class may not yet be insantiated when this method is called.
QGISEXTERN QString name()
{
return pName;
}
//*******************************************************************************
// Return the description
QGISEXTERN QString description()
{
return pDescription;
}
//********************************************************************************
// Return the type (either UI or MapLayer plugin)
QGISEXTERN int type()
{
return pPluginType;
}
//********************************************************************************
// Return the version number for the plugin
QGISEXTERN QString version()
{
return pPluginVersion;
}
//********************************************************************************
// Return the Icon for the plugin
QGISEXTERN QString icon()
{
return pPluginIcon;
}
//*******************************************************************************
// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
delete thePluginPointer;
}
//*****************************************************************************
bool QRap::openDatabaseConnection()
{
cout << "In QRap::openDatabaseConnection() " << endl;
/** \TODO: Get a place for settings.xml and structure.xml or find a way to set the location
*/
if (!gSettings.LoadFromFile("/usr/lib/qgis/plugins/settings.xml"))
{
cout << "Error while loading settings from settings.xml" << endl;
exit(1);
}
cout << "Na Load Settings file in QRap::openDatabaseConnection() " << endl;
LoginDialog* loginDialog;
loginDialog = new LoginDialog(0);
//********************************* Checking the default settings**/
if (loginDialog->exec()==0)
{
// get the values from the login dialog
// dbusername = loginDialog->getUserName();
// dbpassword = loginDialog->getPassword();
// gDb.Connect (dbusername, dbpassword,);
//Why was this happening twice ... probably part of Christo's junk ...
//***********************************************************************************
/*Christo du Plessis se junk
cout << "Voor new IdResolve in QRap::openDatabaseConnection() " << endl;
// resolve the host id using id resolve
IdResolve idr;
int ret,id;
cout << "Voor connectDB " << endl;
// connect to the local database
ret = idr.connectDB("localhost","Q-Rap", dbusername.c_str(),dbpassword.c_str());
if (!ret) {
QMessageBox::information(NULL,"Q-Rap","Failed to connect to the local database");
}
// retrieve the hostname
cout << "Voor getHostId " << endl;
id = idr.getHostId();
if (id<0) {
QMessageBox::information(NULL,"APP","No Machine Id registered with server. Register a machine id before inserting sites");
}
// set the machine id
gDb.globalMachineID = id;
// set the machine name (a string version of the same ID)
char buf[1024];
sprintf(buf,"%d",id);
machinename = string(buf);
printf("machinename: [%s]\n",machinename.c_str());
//einde van Christo se junk
*/
if (gDb.Connected())
{
if (gDb.GetSetting("Units") == "") gDb.SetSetting("Units","dBm");
if (gDb.GetSetting("RqSN") == "") gDb.SetSetting("RqSN","8");
if (gDb.GetSetting("RxMin") == "") gDb.SetSetting("RxMin","-110");
if (gDb.GetSetting("FadeMargin") == "") gDb.SetSetting("FadeMargin","3");
if (gDb.GetSetting("RqClco") == "") gDb.SetSetting("RqClco","9");
if (gDb.GetSetting("RqClad") == "") gDb.SetSetting("RqClad","-9");
if (gDb.GetSetting("RqEbNo") == "") gDb.SetSetting("RqEbNo","8");
if (gDb.GetSetting("kFactorServ") == "") gDb.SetSetting("kFactorServ","1");
if (gDb.GetSetting("kFactorInt") == "") gDb.SetSetting("kFactorInt","2.5");
if (gDb.GetSetting("DEMsource") == "") gDb.SetSetting("DEMsource","1");
if (gDb.GetSetting("DownLink") == "") gDb.SetSetting("DownLink","1");
if (gDb.GetSetting("ClutterSource") == "") gDb.SetSetting("ClutterSource","1");
if (gDb.GetSetting("UseClutter") == "") gDb.SetSetting("UseClutter","-1");
if (gDb.GetSetting("PlotResolution") == "") gDb.SetSetting("PlotResolution","90");
if (gDb.GetSetting("BTLDir") == "") gDb.SetSetting("BTLDir","Data/BTL/");
if (gDb.GetSetting("OutputDir") == "") gDb.SetSetting("OutputDir","Data/Output/");
if (gDb.GetSetting("SiteSelectSense") == "") gDb.SetSetting("SiteSelectSense","150");
cout << "QRap::openDatabaseConnection(): Done setting defaults " << endl;
}
else
{
QMessageBox::information(mQGisIface->mainWindow(), "Q-Rap", "Failing to connect to QRap-database. Q-Rap is a Radio Planning Tool that uses a PostgreSQL database. For more information on how to create the database see the manual.pdf $3.2. Also see http://www.QRap.org.za for more info. Removing Q-Rap plugin");
cout << "QRap::openDatabaseConnection(): else gDb.Connected() " << endl;
unload();
}
}
cout << "Verlaat openDatabaseConnection " << endl;
}
//*************************************************************************************
//* This actually calls the database interface
void QRap::run()
{
gMainWindow = new MainWindow(qgisMainWindow);
connect(gMainWindow, SIGNAL(SelectArea()),this, SLOT(SelectArea()));
gMainWindow->show();
mQGisIface->mapCanvas()->refresh();
}
//**************************************************************************************
void QRap::PlaceSite()
{
mMouseType = PLACESITE;
mQGisIface->mapCanvas()->setMapTool(Mouse);
}
//************************************************************************************
void QRap::Prediction()
{
mMouseType = AREA;
InitRubberBand(true);
}
//************************************************************************************
void QRap::CreateLinkAnalysis()
{
mMouseType = LINK1;
InitRubberBand(false);
}
//*************************************************************************************
void QRap::SpectralAnalysis()
{
mMouseType = SPECTRAL;
InitRubberBand(true);
}
//*************************************************************************************
void QRap::MultiLink()
{
mMouseType = MULTILINK;
InitRubberBand(true);
}
//*************************************************************************************
void QRap::ReceivedRightPoint(QgsPoint &Point)
{
if (mMouseType != CLEAN)
{
if (mMouseType == PLACESITE)
{
mMouseType = CLEAN;
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
}
if (mMouseType == SELECTLINK)
{
mMouseType = CLEAN;
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
}
if (mMouseType == DELETELINK)
{
mMouseType = CLEAN;
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
}
if (mMouseType == LINK1 || mMouseType == LINK2)
{
DesRubberBand();
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
}
if (mMouseType == AREA)
{
mPoints.append(Point);
mRubberBand->addPoint(Point);
DesRubberBand();
PerformPrediction();
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
mMouseType = CLEAN;
}
if (mMouseType == FILTERAREA)
{
mPoints.append(Point);
mRubberBand->addPoint(Point);
DesRubberBand();
FilterArea();
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
mMouseType = CLEAN;
}
if (mMouseType == SPECTRAL)
{
mPoints.append(Point);
mRubberBand->addPoint(Point);
DesRubberBand();
PerformSpectral();
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
mMouseType = CLEAN;
}
if (mMouseType == MULTILINK)
{
mPoints.append(Point);
mRubberBand->addPoint(Point);
DesRubberBand();
PerformMultiLink();
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
mMouseType = CLEAN;
}
if (mMouseType == OPTIMISATION)
{
mPoints.append(Point);
mRubberBand->addPoint(Point);
DesRubberBand();
PerformOptimisation();
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
mMouseType = CLEAN;
}
}
}
//******************************************************************************************
void QRap::ReceivedLeftPoint(QgsPoint &Point)
{
cout << " in QRap::ReceivedLeftPoint(QgsPoint &Point) " << endl;
if (mMouseType != CLEAN)
{
if (mMouseType == MOVESITE)
{
cout << " movesite " << endl;
QMessageBox::information(mQGisIface->mainWindow(), "Q-Rap", "Wait: getting height data at point");
MoveSiteDialog((Point.y()),(Point.x()));
mMouseType = CLEAN;
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
mQGisIface->mapCanvas()->refresh();
}
else if (mMouseType == PLACESITE)
{
cout << " placesite " << endl;
QMessageBox::information(mQGisIface->mainWindow(), "Q-Rap", "Wait: getting height data at point");
PlaceSiteDialog((Point.y()),(Point.x()),false);
if (mMouseType!=MOVESITE)
{
mMouseType = CLEAN;
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
mQGisIface->mapCanvas()->refresh();
}
}
else if (mMouseType == SELECTSITE)
{
cout << " selectsite " << endl;
PlaceSiteDialog((Point.y()),(Point.x()),true);
if (mMouseType!=MOVESITE)
{
mMouseType = CLEAN;
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
}
}
if (mMouseType == LINK2)
{
cout << " Link2 " << endl;
mPoints.append(Point);
mRubberBand->addPoint(Point);
DesRubberBand();
PerformLink();
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
}
if (mMouseType == LINK1)
{
cout << " Link1 " << endl;
mPoints.append(Point);
mRubberBand->addPoint(Point);
mMouseType = LINK2;
}
if (mMouseType == AREA)
{
cout << " Area " << endl;
mPoints.append(Point);
mRubberBand->addPoint(Point);
}
if (mMouseType == FILTERAREA)
{
cout << " Filter Area " << endl;
mPoints.append(Point);
mRubberBand->addPoint(Point);
}
if (mMouseType == SELECTLINK)
{
cout << " Select Link " << endl;
GetLink((Point.y()),(Point.x()));
mMouseType = CLEAN;
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
}
if (mMouseType == SPECTRAL)
{
cout << " spectral " << endl;
mPoints.append(Point);
mRubberBand->addPoint(Point);
}
if (mMouseType == MULTILINK)
{
cout << " multilink " << endl;
mPoints.append(Point);
mRubberBand->addPoint(Point);
}
if (mMouseType == OPTIMISATION)
{
cout << " optimisation " << endl;
mPoints.append(Point);
mRubberBand->addPoint(Point);
}
if (mMouseType == DELETESITE)
{
cout << "Deleting site we hope ..." << endl;
cDeleteObject *Delete = new cDeleteObject(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
cout << "After delete object constructer" << endl;
QString Lat = QString("%1").arg(Point.y());
QString Lon = QString("%1").arg(Point.x());
if (Delete->SetParameters(Lat,Lon,true,mQGisIface->mapCanvas()->scale()))
{
if (Delete->exec()==1)
{
mQGisIface->mapCanvas()->refresh();
}
}
mMouseType = CLEAN;
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
}
if (mMouseType == DELETELINK)
{
cout << " delete link " << endl;
cDeleteObject *Delete;
Delete = new cDeleteObject(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
QString Lat = QString("%1").arg(Point.y());
QString Lon = QString("%1").arg(Point.x());
if (Delete->SetParameters(Lat,Lon,false,mQGisIface->mapCanvas()->scale()))
{
if (Delete->exec()==1)
{
mQGisIface->mapCanvas()->refresh();
}
}
mMouseType = CLEAN;
mQGisIface->mapCanvas()->setCursor(Qt::OpenHandCursor);
}
}
else cout << " clean " << endl;
}
//*****************************************************************************************
void QRap::PlaceSiteDialog(double lat, double lon,bool IsOld)
{
QString Lat = QString("%1").arg(lat);
QString Lon = QString("%1").arg(lon);
mPlacedSite = new cPlaceSite(mQGisIface, mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
connect(mPlacedSite, SIGNAL(MoveSiteClicked()),this, SLOT(MoveSiteClicked()));
// place the site
if (mPlacedSite->SetParameters(Lat,Lon,IsOld,mQGisIface->mapCanvas()->scale()))
{
if (mPlacedSite->exec()==1)
{
mQGisIface->mapCanvas()->refresh();
}
}
}
//*****************************************************************************************
void QRap::MoveSiteDialog(double lat, double lon)
{
QString Lat = QString("%1").arg(lat);
QString Lon = QString("%1").arg(lon);
cout << " In QRap::MoveSiteDialog(double lat, double lon)" << endl;
// place the site
mPlacedSite->show();
mPlacedSite->ChangeLocation(Lat,Lon);
if (mPlacedSite->exec()==1)
{
mQGisIface->mapCanvas()->refresh();
}
}
//***************************************************************************************
void QRap::ReceiveMouseMove(QgsPoint &Point)
{
if (mMouseType != CLEAN || mMouseType!=PLACESITE)
{
mRubberBand->movePoint(Point);
}
}
//***************************************************************************************
void QRap::UpdateSiteLayer()
{
int LayerCount = mQGisIface->mapCanvas()->layerCount();
QString temp = QString("%1").arg(LayerCount);
QMessageBox::information(mQGisIface->mainWindow(), "Q-Rap", temp);
}
//****************************************************************************************
void QRap::InitRubberBand(bool IsArea)
{
mQGisIface->mapCanvas()->setMapTool(Mouse);
mPoints.clear();
mRubberBand = new QgsRubberBand(mQGisIface->mapCanvas(), IsArea);
connect(Mouse, SIGNAL(MouseMove(QgsPoint&)), this, SLOT(ReceiveMouseMove(QgsPoint&)));
mQGisIface->mapCanvas()->setCursor(Qt::CrossCursor);
int myRed = 180;//settings.value("/qgis/default_measure_color_red", 180).toInt();
int myGreen = 180;//settings.value("/qgis/default_measure_color_green", 180).toInt();
int myBlue = 180;//settings.value("/qgis/default_measure_color_blue", 180).toInt();
mRubberBand->setColor(QColor(myRed, myGreen, myBlue));
}
//*****************************************************************************************
void QRap::DesRubberBand()
{
cout << "mMouseType = CLEAN in QRap::DesRubberBand()" << endl;
mMouseType = CLEAN;
disconnect(Mouse, SIGNAL(MouseMove(QgsPoint&)), this, SLOT(ReceiveMouseMove(QgsPoint&)));
delete mRubberBand;
mQGisIface->mapCanvas()->setCursor(Qt::ArrowCursor);
}
//*****************************************************************************************
void QRap::SelectSite()
{
mMouseType = SELECTSITE;
mQGisIface->mapCanvas()->setMapTool(Mouse);
mQGisIface->mapCanvas()->setCursor(Qt::ArrowCursor);
}
//***********************************************************************************
void QRap::SelectLink()
{
mMouseType = SELECTLINK;
cout << " Set Select Link " << endl;
mQGisIface->mapCanvas()->setMapTool(Mouse);
mQGisIface->mapCanvas()->setCursor(Qt::ArrowCursor);
}
//************************************************************************************
void QRap::Preferences()
{
PreferencesDialog *Preferences = new PreferencesDialog();
Preferences->show();
}
//************************************************************************************
void QRap::Optimise()
{
mMouseType = OPTIMISATION;
InitRubberBand(true);
}
//************************************************************************************
void QRap::Measurements()
{
cMeasurementAnalysis *Measurements = new cMeasurementAnalysis();
Measurements->show();
}
//****************************************************************************************
void QRap::ImportExport()
{
printf("QRap::ImportExport\n");
// create a new menu
// cImportExportMenu *ifMenuDialog = new cImportExportMenu();
// set the db username and password
// ifMenuDialog->setDB(dbusername,dbpassword);
// ifMenuDialog->setMachine(machinename);
// show the menu
// ifMenuDialog->show();
}
//******************************************************************
void QRap::Help()
{
// launch the help file in evince
// system("evince /usr/share/doc/qrap/manual.pdf&");
}
//***************************************************************
void QRap::PerformLink()
{
cConfirmLink *ConfirmLink = new cConfirmLink(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
if (ConfirmLink->SetPoints(mPoints,mQGisIface->mapCanvas()->scale()))
{
cout << " In QRap::PerformLink(): SetPoints successful." << endl;
if (ConfirmLink->exec()==1)
{
cout << " In QRap::PerformLink(): ConfirmLink->exec()=1" << endl;
cLinkAnalysis *Plot = new cLinkAnalysis(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
Plot->DoAndSetUpDisplay(ConfirmLink->Units, ConfirmLink->Downlink, ConfirmLink->Frequency,
ConfirmLink->kFactor, ConfirmLink->PlotResolution,
ConfirmLink->DEMsource, ConfirmLink->ClutterSource, ConfirmLink->UseClutter,
ConfirmLink->TxID, ConfirmLink->RxID, ConfirmLink->mLinkName,
ConfirmLink->TxName, ConfirmLink->RxName,0);
if (Plot->exec())
{
mQGisIface->mapCanvas()->refresh();
}
}
}
cout << " In QRap::PerformLink(): Exiting." << endl;
}
/***************************************************************/
bool QRap::PerformPrediction()
{
cConfirmPrediction *ConfirmPrediction =
new cConfirmPrediction(mQGisIface, mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
if (ConfirmPrediction->SetPoints(mPoints))
{
if (ConfirmPrediction->exec()==1)
{
mQGisIface->mapCanvas()->refresh();
}//if accepted
}//if has sites
return true;
}
/***********************************************************/
void QRap::GetLink(double lat, double lon)
{
cout << "mMouseType = CLEAN in QRap::GetLink(double lat, double lon)" << endl;
mMouseType = CLEAN;
char Lat[33];
char Lon[33];
gcvt(lat,8,Lat);
gcvt(lon,8,Lon);
string query = "SELECT id, txinst,rxinst, linkname, frequency, kfactor ";
query += "FROM links WHERE line && ST_GeomFromText('POINT(";
query += Lon;
query += " ";
query += Lat;
query += ")',4326)";
if (!gDb.PerformRawSql(query))
{
cout << "In QRap::GetLink(...) Database link select failed"<< endl;
}
else
{
pqxx::result Li;
gDb.GetLastResult(Li);
if (Li.size()>0)
{
cout << "In QRap::GetLink(...) Database link select suceeded" << endl;
int ID =(int)atof(Li[0]["id"].c_str()) ;
int TxID =(int)atof(Li[0]["txinst"].c_str()) ;
int RxID = (int)atof(Li[0]["rxinst"].c_str());
double frequency = (double)atof(Li[0]["frequency"].c_str());
double kfactor = (double)atof(Li[0]["kfactor"].c_str());
string name = Li[0]["linkname"].c_str();
cout << name << endl;
cConfirmLink *ConfirmLink = new cConfirmLink(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
cout << "In QRap::GetLink(...) After constructor " << endl;
if (ConfirmLink->SetOldLink(ID,TxID,RxID,name,frequency, kfactor))
{
cout << "In QRap::GetLink(...) SetOldLink success " << endl;
if (ConfirmLink->exec()==1)
{
cLinkAnalysis *Plot = new cLinkAnalysis(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
Plot->DoAndSetUpDisplay(ConfirmLink->Units, ConfirmLink->Downlink, ConfirmLink->Frequency,
ConfirmLink->kFactor, ConfirmLink->PlotResolution,
ConfirmLink->DEMsource, ConfirmLink->ClutterSource, ConfirmLink->UseClutter,
ConfirmLink->TxID, ConfirmLink->RxID, ConfirmLink->mLinkName,
ConfirmLink->TxName, ConfirmLink->RxName, ID);
if (Plot->exec())
{
mQGisIface->mapCanvas()->refresh();
}
}
}
}
}
}
/************************************************************/
/*void QRap::ColourManager()
{
cColourManager *CM = new cColourManager(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
CM->show();
}*/
//**********************************************************************
void QRap::PerformSpectral()
{
cout << "voor new Confirmspectral in QRap::PerformSpectral()" << endl;
cConfirmSpectral ConfirmSpectral(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
cout << "voor ConfirmSpectral->SetPoints(mPoints) in QRap::PerformSpectral()" << endl;
if (ConfirmSpectral.SetPoints(mPoints))
{
cout << "voor ConfirmSpectral->exec() in QRap::PerformSpectral()" << endl;
if(ConfirmSpectral.exec()==1)
{
cSpectralAnalysis Plot(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
Plot.DoAndSetUpDisplay(ConfirmSpectral.mRx,ConfirmSpectral.mRadInst,
ConfirmSpectral.mFrequencySpacing, ConfirmSpectral.mkFactor);
if (Plot.exec())
{
mQGisIface->mapCanvas()->refresh();
}
}
}
}
//**********************************************************************
void QRap::PerformMultiLink()
{
cConfirmMultiLink ConfirmMultiLink(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
if (ConfirmMultiLink.SetPoints(mPoints))
{
if(ConfirmMultiLink.exec()==1)
{
mQGisIface->mapCanvas()->refresh();
}
}
}
//**********************************************************************
void QRap::PerformOptimisation()
{
Optimisation Optim(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
if ((Optim.SetPoints(mPoints))&&(Optim.LoadAntennas())&&(Optim.LoadCables())&&(Optim.LoadConnectors()))
{
if(Optim.exec()==1)
{
mQGisIface->mapCanvas()->refresh();
}
}
}
//**************************************************************
void QRap::DeleteLink()
{
mMouseType = DELETELINK;
mQGisIface->mapCanvas()->setMapTool(Mouse);
mQGisIface->mapCanvas()->setCursor(Qt::ArrowCursor);
}
//****************************************************************
void QRap::DeleteSite()
{
mMouseType = DELETESITE;
mQGisIface->mapCanvas()->setMapTool(Mouse);
mQGisIface->mapCanvas()->setCursor(Qt::ArrowCursor);
}
//********************************************************
void QRap::SelectArea()
{
mMouseType = FILTERAREA;
InitRubberBand(true);
}
//********************************************************
void QRap::MoveSiteClicked()
{
mPlacedSite->hide();
mQGisIface->mapCanvas()->setMapTool(Mouse);
mQGisIface->mapCanvas()->setCursor(Qt::CrossCursor);
mMouseType = MOVESITE;
}
//********************************************************
void QRap::FilterArea()
{
cFilterDialog* Filter = new cFilterDialog(mQGisIface->mainWindow(), QgisGui::ModalDialogFlags);
Filter->SetPoints(mPoints);
Filter->show();
}