00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef PLOTTOOL_H_
00028 #define PLOTTOOL_H_
00029
00030 #include <graphics/GenericPlotter/PlotEventHandler.h>
00031 #include <graphics/GenericPlotter/PlotOptions.h>
00032 #include <graphics/GenericPlotter/PlotShape.h>
00033 #include <graphics/GenericPlotter/PlotAnnotation.h>
00034
00035 namespace casa {
00036
00037
00038 class PlotCanvas;
00039 class PlotFactory;
00040 class PlotPanToolNotifier;
00041 class PlotSelectToolNotifier;
00042 class PlotTrackerToolNotifier;
00043 class PlotZoomToolNotifier;
00044
00045
00046
00048
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 class PlotTool {
00064 friend class PlotCanvas;
00065 friend class PlotMouseToolGroup;
00066
00067 public:
00068
00069
00070 PlotTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
00071
00072
00073
00074 PlotTool(PlotAxis xAxis, PlotAxis yAxis,
00075 PlotCoordinate::System sys = PlotCoordinate::WORLD);
00076
00077
00078 virtual ~PlotTool();
00079
00080
00081
00082 virtual bool isActive() const;
00083
00084
00085 virtual void setActive(bool isActive = true);
00086
00087
00088
00089
00090 virtual bool isBlocking() const;
00091
00092
00093 virtual void setBlocking(bool blocking = true);
00094
00095
00096
00097 virtual PlotAxis getXAxis() const;
00098 virtual PlotAxis getYAxis() const;
00099
00100
00101
00102
00103 virtual PlotCoordinate::System getCoordinateSystem() const;
00104
00105
00106
00107 virtual bool lastEventWasHandled() const;
00108
00109
00110
00111
00112 virtual void reset() { }
00113
00114
00115
00116 protected:
00117
00118 PlotCanvas* m_canvas;
00119
00120
00121 PlotFactory* m_factory;
00122
00123
00124 bool m_active;
00125
00126
00127 bool m_blocking;
00128
00129
00130 PlotAxis m_xAxis, m_yAxis;
00131
00132
00133 PlotCoordinate::System m_coordSystem;
00134
00135
00136 bool m_lastEventHandled;
00137
00138
00139
00140 virtual PlotCanvas* canvas() const;
00141
00142
00143
00144 virtual PlotFactory* factory() const;
00145
00146
00147 virtual bool isAttached() const;
00148
00149
00150
00151 virtual void attach(PlotCanvas* canvas);
00152
00153
00154 virtual void detach();
00155 };
00156
00157 typedef CountedPtr<PlotTool> PlotToolPtr;
00158
00159
00160
00161
00162
00163
00164
00165 class PlotMouseTool : public virtual PlotTool,
00166 public virtual PlotSelectEventHandler,
00167 public virtual PlotClickEventHandler,
00168 public virtual PlotMousePressEventHandler,
00169 public virtual PlotMouseReleaseEventHandler,
00170 public virtual PlotMouseDragEventHandler,
00171 public virtual PlotMouseMoveEventHandler,
00172 public virtual PlotWheelEventHandler {
00173 public:
00174
00175 PlotMouseTool(PlotCoordinate::System coordSys = PlotCoordinate::WORLD) :
00176 PlotTool(coordSys) { }
00177
00178
00179 PlotMouseTool(PlotAxis xAxis, PlotAxis yAxis,
00180 PlotCoordinate::System coordSys = PlotCoordinate::WORLD) :
00181 PlotTool(xAxis, yAxis, coordSys) { }
00182
00183
00184 virtual ~PlotMouseTool() { }
00185
00186
00187
00188
00189 virtual void handleSelect(const PlotSelectEvent& event) {
00190 handleMouseEvent(event); }
00191 virtual void handleClick(const PlotClickEvent& event) {
00192 handleMouseEvent(event); }
00193 virtual void handleMousePress(const PlotMousePressEvent& event) {
00194 handleMouseEvent(event); }
00195 virtual void handleMouseRelease(const PlotMouseReleaseEvent& event) {
00196 handleMouseEvent(event); }
00197 virtual void handleMouseDrag(const PlotMouseDragEvent& event) {
00198 handleMouseEvent(event); }
00199 virtual void handleMouseMove(const PlotMouseMoveEvent& event) {
00200 handleMouseEvent(event); }
00201 virtual void handleWheel(const PlotWheelEvent& event) {
00202 handleMouseEvent(event); }
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 virtual void handleMouseEvent(const PlotEvent& event) = 0;
00213 };
00214 INHERITANCE_POINTER2(PlotMouseTool, PlotMouseToolPtr, PlotTool, PlotToolPtr)
00215
00216
00217
00218
00219
00220
00221
00222
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 enum ToolCode {
00234 SELECT_TOOL,
00235 SUBTRACT_TOOL,
00236 ZOOM_TOOL,
00237 PAN_TOOL,
00238 NONE_TOOL
00239 };
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 class PlotSelectTool : public virtual PlotMouseTool {
00255 public:
00256
00257 PlotSelectTool(PlotCoordinate::System system = PlotCoordinate::WORLD);
00258
00259
00260 PlotSelectTool(PlotAxis xAxis, PlotAxis yAxis,
00261 PlotCoordinate::System system = PlotCoordinate::WORLD);
00262
00263
00264 virtual ~PlotSelectTool();
00265
00266
00267
00268
00269 virtual void addNotifier(PlotSelectToolNotifier* notifier);
00270
00271
00272
00273 virtual void setSelectLine(PlotLinePtr line);
00274 virtual void setSubtractLine(PlotLinePtr line);
00275 virtual void setSelectLine(bool on = true);
00276
00277
00278
00279
00280 virtual void setDrawRects(bool on = true);
00281 virtual void setRectLine(PlotLinePtr line);
00282 virtual void setRectFill(PlotAreaFillPtr fill);
00283
00284
00285
00286
00287 virtual unsigned int numSelectedRects() const;
00288 virtual void getSelectedRects(
00289 vector<double>& upperLeftXs,
00290 vector<double>& upperLeftYs,
00291 vector<double>& lowerRightXs,
00292 vector<double>& lowerRightYs,
00293 PlotCoordinate::System system = PlotCoordinate::WORLD) const;
00294 virtual vector<PlotRegion> getSelectedRects(
00295 PlotCoordinate::System system = PlotCoordinate::WORLD) const;
00296 virtual void clearSelectedRects();
00297 virtual int getSelectedRectCount();
00298
00299
00300
00301 virtual void setActive(bool active = true);
00302
00303
00304 virtual void handleMouseEvent(const PlotEvent& event);
00305
00306 bool inSubtractionMode() { return m_subtraction_mode; }
00307
00308
00309
00310 bool m_subtraction_mode;
00311
00312
00313 protected:
00314
00315 vector<PlotSelectToolNotifier*> m_notifiers;
00316
00317
00318
00319 PlotLinePtr m_selLine;
00320 PlotLinePtr m_subLine;
00321
00322
00323 bool m_drawRects;
00324
00325
00326 PlotLinePtr m_rectLine;
00327
00328
00329 PlotAreaFillPtr m_rectFill;
00330
00331
00332 vector<PlotShapeRectanglePtr> m_rects;
00333
00334
00335
00336
00337 virtual void attach(PlotCanvas* canvas);
00338
00339
00340 virtual void detach();
00341 };
00342
00343
00344 INHERITANCE_POINTER(PlotSelectTool, PlotSelectToolPtr, PlotMouseTool,
00345 PlotMouseToolPtr, PlotTool, PlotToolPtr)
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 class PlotZoomTool : public virtual PlotMouseTool {
00367 public:
00368
00369 PlotZoomTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
00370
00371
00372 PlotZoomTool(PlotAxis xAxis, PlotAxis yAxis,
00373 PlotCoordinate::System sys = PlotCoordinate::WORLD);
00374
00375
00376 virtual ~PlotZoomTool();
00377
00378
00379
00380 virtual void addNotifier(PlotZoomToolNotifier* notifier);
00381
00382
00383
00384 virtual void setSelectLine(PlotLinePtr line);
00385 virtual void setSelectLine(bool on = true);
00386
00387
00388
00389 virtual vector<PlotRegion> getZoomStack(PlotCoordinate::System sytem =
00390 PlotCoordinate::WORLD) const;
00391
00392
00393 virtual unsigned int getStackIndex() const;
00394
00395
00396 virtual void setActive(bool active = true);
00397
00398
00399 virtual void handleMouseEvent(const PlotEvent& event);
00400
00401
00402 virtual void reset();
00403
00404 protected:
00405
00406 vector<PlotZoomToolNotifier*> m_notifiers;
00407
00408
00409 PlotLinePtr m_selLine;
00410
00411
00412 PlotAxesStack* m_stack;
00413
00414
00415
00416 virtual void attach(PlotCanvas* canvas);
00417
00418
00419 virtual void detach();
00420
00421
00422 virtual void notifyWatchers();
00423 };
00424 INHERITANCE_POINTER(PlotZoomTool, PlotZoomToolPtr, PlotMouseTool,
00425 PlotMouseToolPtr, PlotTool, PlotToolPtr)
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 class PlotPanTool : public virtual PlotMouseTool {
00441 public:
00442
00443 PlotPanTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
00444
00445
00446 PlotPanTool(PlotAxis xAxis, PlotAxis yAxis,
00447 PlotCoordinate::System sys = PlotCoordinate::WORLD);
00448
00449
00450 virtual ~PlotPanTool();
00451
00452
00453
00454 virtual void addNotifier(PlotPanToolNotifier* notifier);
00455
00456
00457 virtual vector<PlotRegion> getPanStack(PlotCoordinate::System system =
00458 PlotCoordinate::WORLD) const;
00459
00460
00461 virtual unsigned int getStackIndex() const;
00462
00463
00464 virtual void setActive(bool active = true);
00465
00466
00467 virtual void handleMouseEvent(const PlotEvent& event);
00468
00469
00470 virtual void reset();
00471
00472 protected:
00473
00474 vector<PlotPanToolNotifier*> m_notifiers;
00475
00476
00477 bool m_inDraggingMode;
00478
00479
00480 PlotCoordinate m_lastCoord;
00481
00482
00483 PlotAxesStack* m_stack;
00484
00485
00486
00487 virtual void attach(PlotCanvas* canvas);
00488
00489
00490 virtual void detach();
00491
00492
00493 virtual void notifyWatchers();
00494 };
00495 INHERITANCE_POINTER(PlotPanTool, PlotPanToolPtr, PlotMouseTool,
00496 PlotMouseToolPtr, PlotTool, PlotToolPtr)
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508 class PlotTrackerTool : public virtual PlotMouseTool {
00509 friend class PlotStandardMouseToolGroup;
00510
00511
00512 public:
00513
00514
00515
00516
00517 static String formattedString(const String& format, double x, double y,
00518 PlotCanvas* canvas, PlotAxis xAxis, PlotAxis yAxis);
00519
00520
00521
00522
00523
00524 PlotTrackerTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
00525
00526
00527 PlotTrackerTool(PlotAxis xAxis, PlotAxis yAxis,
00528 PlotCoordinate::System sys = PlotCoordinate::WORLD);
00529
00530
00531 virtual ~PlotTrackerTool();
00532
00533
00534
00535 virtual void addNotifier(PlotTrackerToolNotifier* notifier);
00536
00537
00538 virtual bool drawsText() const;
00539
00540
00541 virtual void setDrawText(bool draw = true);
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551 virtual void setFormat(const String& format);
00552
00553
00554 virtual String formattedString(double x, double y) {
00555 return formattedString(m_format, x, y, m_canvas, m_xAxis, m_yAxis); }
00556
00557
00558 virtual PlotAnnotationPtr getAnnotation();
00559
00560
00561 virtual PlotCoordinate getCoordinate(PlotCoordinate::System =
00562 PlotCoordinate::WORLD) const;
00563
00564
00565 virtual void setActive(bool active = true);
00566
00567
00568 virtual void handleMouseEvent(const PlotEvent& event);
00569
00570 int getSelectedRectCount() const;
00571 vector<PlotRegion> getSelectedRects() const;
00572
00573 protected:
00574
00575 vector<PlotTrackerToolNotifier*> m_notifiers;
00576
00577
00578 PlotAnnotationPtr m_annotation;
00579
00580
00581 bool m_drawText;
00582
00583
00584 String m_format;
00585
00586
00587 virtual void attach(PlotCanvas* canvas);
00588
00589
00590 virtual void detach();
00591
00592
00593 virtual void notifyWatchers();
00594
00595
00596
00597
00598
00599
00600 static const String FORMAT_DIVIDER;
00601 static const String FORMAT_X, FORMAT_Y;
00602 static const String FORMAT_PRECISION;
00603 static const String DEFAULT_FORMAT;
00604
00605 };
00606 INHERITANCE_POINTER(PlotTrackerTool, PlotTrackerToolPtr, PlotMouseTool,
00607 PlotMouseToolPtr, PlotTool, PlotToolPtr)
00608
00609
00610
00611
00613
00614
00615
00616
00617 class PlotSelectToolNotifier {
00618 friend class PlotSelectTool;
00619
00620 public:
00621 PlotSelectToolNotifier() { }
00622 virtual ~PlotSelectToolNotifier() { }
00623
00624 protected:
00625
00626 virtual void notifySelectionAdded(PlotSelectTool& tool) = 0;
00627 };
00628
00629
00630
00631
00632 class PlotZoomToolNotifier {
00633 friend class PlotZoomTool;
00634
00635 public:
00636 PlotZoomToolNotifier() { }
00637 virtual ~PlotZoomToolNotifier() { }
00638
00639 protected:
00640
00641 virtual void notifyZoomChanged(PlotZoomTool& tool) = 0;
00642 };
00643
00644
00645
00646
00647 class PlotPanToolNotifier {
00648 friend class PlotPanTool;
00649
00650 public:
00651 PlotPanToolNotifier() { }
00652 virtual ~PlotPanToolNotifier() { }
00653
00654 protected:
00655
00656 virtual void notifyPanChanged(PlotPanTool& tool) = 0;
00657 };
00658
00659
00660
00661
00662 class PlotTrackerToolNotifier {
00663 friend class PlotTrackerTool;
00664
00665 public:
00666 PlotTrackerToolNotifier() { }
00667 virtual ~PlotTrackerToolNotifier() { }
00668
00669 protected:
00670
00671 virtual void notifyTrackerChanged(PlotTrackerTool& tool) = 0;
00672 };
00673
00674
00676
00678
00679
00680
00681
00682 class PlotMouseToolGroup : public virtual PlotMouseTool {
00683 public:
00684
00685 PlotMouseToolGroup();
00686
00687
00688 virtual ~PlotMouseToolGroup();
00689
00690
00691 unsigned int numTools() const;
00692
00693
00694 vector<PlotMouseToolPtr> tools() const;
00695
00696
00697
00698
00699
00700
00701
00702 unsigned int addTool(PlotMouseToolPtr tool);
00703
00704
00705
00706 bool removeTool(PlotMouseToolPtr tool);
00707 bool removeTool(unsigned int index) { return removeTool(toolAt(index)); }
00708
00709
00710
00711 PlotMouseToolPtr toolAt(unsigned int index) const;
00712
00713
00714 unsigned int indexOf(PlotMouseToolPtr tool) const;
00715
00716
00717 bool containsTool(PlotMouseToolPtr tool) const {
00718 return indexOf(tool) < m_tools.size(); }
00719
00720
00721 PlotMouseToolPtr activeTool() const { return m_activeTool; }
00722
00723
00724
00725
00726
00727
00728 void setActiveTool(PlotMouseToolPtr tool, ToolCode toolcode=NONE_TOOL);
00729
00730
00731 void setActiveTool(unsigned int index, ToolCode c=NONE_TOOL) {
00732 setActiveTool(toolAt(index), c);
00733 }
00734
00735
00736 void setActive(bool isActive = true);
00737
00738
00739 void setBlocking(bool blocking = true);
00740
00741
00742 void handleMouseEvent(const PlotEvent& event);
00743
00744
00745
00746 void handleSelect(const PlotSelectEvent& event);
00747 void handleClick(const PlotClickEvent& event);
00748 void handleMousePress(const PlotMousePressEvent& event);
00749 void handleMouseRelease(const PlotMouseReleaseEvent& event);
00750 void handleMouseDrag(const PlotMouseDragEvent& event);
00751 void handleMouseMove(const PlotMouseMoveEvent& event);
00752 void handleWheel(const PlotWheelEvent& event);
00753
00754
00755
00756 PlotAxis getXAxis() const;
00757
00758
00759 PlotAxis getYAxis() const;
00760
00761
00762 PlotCoordinate::System getCoordinateSystem() const;
00763
00764
00765 bool lastEventWasHandled() const;
00766
00767
00768 void reset();
00769
00770 protected:
00771
00772 vector<PlotMouseToolPtr> m_tools;
00773
00774
00775 PlotMouseToolPtr m_activeTool;
00776
00777
00778 virtual void attach(PlotCanvas* canvas);
00779
00780
00781 virtual void detach();
00782 };
00783 INHERITANCE_POINTER(PlotMouseToolGroup, PlotMouseToolGroupPtr, PlotMouseTool,
00784 PlotMouseToolPtr, PlotTool, PlotToolPtr)
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794 class PlotStandardMouseToolGroup : public PlotMouseToolGroup {
00795 public:
00796
00797
00798
00799
00800
00801
00802 PlotStandardMouseToolGroup(ToolCode activeTool = NONE_TOOL,
00803 PlotCoordinate::System system = PlotCoordinate::WORLD);
00804
00805
00806
00807 PlotStandardMouseToolGroup(PlotAxis xAxis, PlotAxis yAxis,
00808 ToolCode activeTool = NONE_TOOL,
00809 PlotCoordinate::System system = PlotCoordinate::WORLD);
00810
00811
00812
00813 PlotStandardMouseToolGroup(PlotSelectToolPtr selectTool,
00814 PlotZoomToolPtr zoomTool,
00815 PlotPanToolPtr panTool,
00816 PlotTrackerToolPtr trackerTool,
00817 ToolCode activeTool = NONE_TOOL);
00818
00819
00820 ~PlotStandardMouseToolGroup();
00821
00822
00823
00824 void setActiveTool(ToolCode tool);
00825 ToolCode activeToolType() const;
00826
00827
00828
00829
00830 void turnTracker(bool on);
00831 bool trackerIsOn() const;
00832 void turnTrackerDrawText(bool on);
00833 bool trackerDrawsText() const;
00834
00835
00836 int getSelectedRectCount();
00837 vector<PlotRegion> getSelectedRects();
00838 void clearSelectedRects();
00839
00840
00841
00842
00843 PlotSelectToolPtr selectTool();
00844 PlotZoomToolPtr zoomTool();
00845 PlotPanToolPtr panTool();
00846 PlotTrackerToolPtr trackerTool();
00847
00848
00849
00850
00851
00852 void handleMouseEvent(const PlotEvent& event) {
00853 if(m_tracker->isActive()) m_tracker->handleMouseEvent(event);
00854 PlotMouseToolGroup::handleMouseEvent(event); }
00855
00856 void handleSelect(const PlotSelectEvent& event) {
00857 if(m_tracker->isActive()) m_tracker->handleSelect(event);
00858 PlotMouseToolGroup::handleSelect(event); }
00859
00860 void handleClick(const PlotClickEvent& event) {
00861 if(m_tracker->isActive()) m_tracker->handleClick(event);
00862 PlotMouseToolGroup::handleClick(event); }
00863
00864 void handleMousePress(const PlotMousePressEvent& event) {
00865 if(m_tracker->isActive()) m_tracker->handleMousePress(event);
00866 PlotMouseToolGroup::handleMousePress(event); }
00867
00868 void handleMouseRelease(const PlotMouseReleaseEvent& event) {
00869 if(m_tracker->isActive()) m_tracker->handleMouseRelease(event);
00870 PlotMouseToolGroup::handleMouseRelease(event); }
00871
00872 void handleMouseDrag(const PlotMouseDragEvent& event) {
00873 if(m_tracker->isActive()) m_tracker->handleMouseDrag(event);
00874 PlotMouseToolGroup::handleMouseDrag(event); }
00875
00876 void handleMouseMove(const PlotMouseMoveEvent& event) {
00877 if(m_tracker->isActive()) m_tracker->handleMouseMove(event);
00878 PlotMouseToolGroup::handleMouseMove(event); }
00879
00880 void handleWheel(const PlotWheelEvent& event) {
00881 if(m_tracker->isActive()) m_tracker->handleWheel(event);
00882 PlotMouseToolGroup::handleWheel(event); }
00883
00884
00885 protected:
00886
00887 void attach(PlotCanvas* canvas);
00888
00889
00890 void detach();
00891
00892 private:
00893
00894 PlotTrackerToolPtr m_tracker;
00895 };
00896 INHERITANCE_POINTER(PlotStandardMouseToolGroup, PlotStandardMouseToolGroupPtr,
00897 PlotMouseToolGroup, PlotMouseToolGroupPtr,
00898 PlotTool, PlotToolPtr)
00899
00900 }
00901
00902 #endif