1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
27 #ifndef __pCOLOR_BAR__
28 #define __pCOLOR_BAR__
30 // -----------------------------------------------------------------------------------------------------------
31 // WX headers inclusion.
32 // For compilers that support precompilation, includes <wx/wx.h>.
33 // -----------------------------------------------------------------------------------------------------------
34 #include <wx/wxprec.h>
42 //------------------------------------------------------------------------------------------------------------
44 //------------------------------------------------------------------------------------------------------------
50 #include "pColorPoint.h"
51 #include "LogicalColorBar.h"
52 //#include "DegradeRectangle.h"
54 #include "wx/colordlg.h"
61 * Attribute that determines the width of each color point
63 #define FIGURE_WIDTH 3
65 BEGIN_DECLARE_EVENT_TYPES()
66 DECLARE_EVENT_TYPE( wxEVT_ADDED_POINT, -1 )
67 DECLARE_EVENT_TYPE( wxEVT_REMOVED_POINT, -1 )
68 DECLARE_EVENT_TYPE( wxEVT_MOVED_POINT, -1 )
69 DECLARE_EVENT_TYPE( wxEVT_CHANGED_POINT, -1 )
70 DECLARE_EVENT_TYPE( wxEVT_ON_COLOR_BAR, -1 )
71 END_DECLARE_EVENT_TYPES()
74 //-------------------------------------------------------------------------------------------------------------
76 //-------------------------------------------------------------------------------------------------------------
77 /** Command IDs used by pColorPoint */
80 cntID_ADD_COLOR_POINT = 6000,
81 cntID_DEL_COLOR_POINT,
82 cntID_CHANGE_COLOR_POINT,
83 cntID_DEGRADE_CONTROL,
88 cntID_TRIANGLES_RIGHT,
92 /** file pColorBar.h */
93 class creaMaracasVisu_EXPORT pColorBar :public wxScrolledWindow{
96 //------------------------------------------------------------------------------------------------------------
97 // Constructors & Destructors
98 //------------------------------------------------------------------------------------------------------------
100 * Creates a colorBar instance
101 * param *parent Container event listener window
102 * param _w Width of the color bar drawing area
103 * param _h Height of the color bar drawing area
104 * param _bar_orientation VERTICAL (false) or HORIZONTAL (true) direction to set
106 pColorBar (wxWindow *parent, int _w, int _h, bool _bar_orientation);
110 //------------------------------------------------------------------------------------------------------------
111 // Color bar proccessed events methods
112 //------------------------------------------------------------------------------------------------------------
113 void OnSize( wxSizeEvent &WXUNUSED(event) );
116 * Reacts to the mouse movement inside the color bar for moving the clicked color point in the x-axis.
117 * Informs the result of the handled event like a wxCommandEvent wxEVT_MOVED_POINT if a point was moved.
118 * param event The mouse actioned event
120 void onMouseMove ( wxMouseEvent& event );
122 * Reacts to the event of drawing the bar and draws it
123 * param &WXUNUSED(event) The correspondig wxPaintEvent actioned event
125 void onPaint ( wxPaintEvent &WXUNUSED(event) );
128 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
129 * Informs the result of the handled event like a wxCommandEvent wxEVT_ADDED_POINT if the point was inserted succesfully.
130 * param & anEvent The wxCommandEvent actioned event
132 void onAddColorPoint ( wxCommandEvent& anEvent );
135 * Reacts to the cntID_DEL_POINT wxCommandEvent and deletes a color degrade point of the color bar.
136 * Informs the result of the handled event like a wxCommandEvent wxEVT_REMOVED_POINT if the point was succesfully removed.
137 * param & anEvent The wxCommandEvent actioned event
139 void onDeleteColorPoint ( wxCommandEvent& anEvent );
142 * Reacts to the cntID_CHANGE_COLOR_POINT wxCommandEvent and changes the assigned color to the selected color degrade point of the color bar.
143 * Informs the result of the handled event like a wxCommandEvent wxEVT_CHANGED_POINT if the point was succesfully removed.
144 * param & anEvent The wxCommandEvent actioned event
146 void onChangeColourSelectedPoint ( wxCommandEvent& anEvent );
149 * Reacts to the cntID_TRIANGLES_UP wxCommandEvent and changes the assigned figure to -triangles up- for the color points of the color bar.
150 * param & anEvent The wxCommandEvent actioned event
152 void onTrianglesUp_Figure ( wxCommandEvent& anEvent );
154 * Reacts to the cntID_TRIANGLES_DOWN wxCommandEvent and changes the assigned figure to -triangles down- for the color points of the color bar.
155 * param & anEvent The wxCommandEvent actioned event
157 void onTrianglesDown_Figure ( wxCommandEvent& anEvent );
159 * Reacts to the cntID_TRIANGLES_LEFT wxCommandEvent and changes the assigned figure to -triangles left- for the color points of the color bar.
160 * param & anEvent The wxCommandEvent actioned event
162 void onTrianglesLeft_Figure ( wxCommandEvent& anEvent );
164 * Reacts to the cntID_TRIANGLES_RIGHT wxCommandEvent and changes the assigned figure to -triangles right- for the color points of the color bar.
165 * param & anEvent The wxCommandEvent actioned event
167 void onTrianglesRight_Figure ( wxCommandEvent& anEvent );
169 * Reacts to the cntID_RECTANGLES wxCommandEvent and changes the assigned figure to -rectangles- for the color points of the color bar.
170 * param & anEvent The wxCommandEvent actioned event
172 void onRectangles_Figure ( wxCommandEvent& anEvent );
175 * Reacts to the cntID_DEGRADE_CONTROL wxCommandEvent and turns on/off the degrade in the color bar.
176 * param & anEvent The wxCommandEvent actioned event
178 void onDegradeControl ( wxCommandEvent& anEvent );
181 * Reacts to the wxEVT_RIGHT_DCLICK wxMouseEvent and adds a color degrade point to the color bar.
182 * Informs the result of the handled event like a wxCommandEvent wxEVT_ADDED_POINT if the point was succesfully inserted.
183 * param & event The wxMouseEvent actioned event
185 void onLeftButtonDClick (wxMouseEvent& event);
188 * Shows the popup menu
190 void onShowPopupMenu (wxMouseEvent& event);
193 //------------------------------------------------------------------------------------------------------------
195 //------------------------------------------------------------------------------------------------------------
199 * param activeNow The new state
201 void setActiveStateTo (bool activeNow);
204 * Gets the active state of the bar
205 * return activeState The actual state
211 * Gets the real-x value to draw a vertical line
212 * return realX_vertical_line The real x value for the vertical line
214 int getRealX_vertical_line();
217 * Sets the real-x value to draw a vertical line
218 * param realX_vertical_line The new real x value for the vertical line
220 void setRealX_vertical_line(int newReal_x);
224 * Method that reinitiates attributes of the color bar to the given points
225 * param minRealValue The minimum represented value (real value)
226 * param maxRealValue The maximum represented value (real value)
228 void reinitiateColorBar(double minRealValue, double maxRealValue);
231 * Method that reinitiates attributes of the color bar and set the points given by parameter
232 * param newPointsList Pointer to the list of the new points
234 void reinitiateColorBarTo (std::vector<pColorPoint *> pointsVector);
237 *Method that sets a copy of the points of the color bar to the given pointer parameter
238 * param pointsList The list for getting the points
240 void getPointsListWithTemps (std::vector<pColorPoint*> &pointsVector);
243 * Method that sets a copy of the points of the color bar to the given pointer parameter, and sets the default values to the needeed attributes, it doesn't
244 * includes the teporal points created
245 * param pointsVector The list for getting the points
247 void getAddedColorsPointsList (std::vector<pColorPoint*>& pointsVector);
250 * Adds a color degrade point to the color bar.
251 * param xRealValue The real xValue of the point
252 * param theColour The assigned color for the point
253 * param temporalStart Indicates if the inserted point is the temporal startShowing point
254 * param temporalEnd Indicates if the inserted point is the temporal startShowing point
255 * return Returns true if the point was succesfully inserted.
257 bool addColorPoint (double xRealValue, wxColour theColour/*, bool temporalStart=false, bool temporalEnd=false*/);
260 * Delets a color degrade point to the color bar.
261 * param xRealValue The real xValue of the point to delete
262 * return Returns true if the point was succesfully inserted.
264 bool deleteColorPoint (double xRealValue);
267 * Changes the color degrade point color value.
268 * Informs the result of the handled event like a wxCommandEvent wxEVT_CHANGED_COLOR_POINT if the point changed its colour.
269 * param clickedValue The x-coord pixel value of the point to which the color change interests
270 * return Returns true if the color point was succesfully updated.
272 bool changeColor ( int clickedValue );
275 * Repaints the color bar in direction mode of the orientation assigned
276 * param createTempPoints True for creating temporal points for start and end when a visible range changes
278 void repaintView ( );
281 * Forces the refresh view of the color bar
283 void RefreshForce ();
285 void Refresh(bool eraseBackground = true, const wxRect* rect = NULL);
288 * Draws the color bar with its degrades
289 * param recentlyChangedOrientation indicates if the orientation has been changed before calling this method
291 void drawColorBar ( bool recentlyChangedOrientation);
294 * Changes the figure of the color points according to the parameter
295 * param theFigure Is the corresponding number for identifying the figure
296 * RECTANGLE = 4,TRIANGLE LEFT = -4, TRIANGLE RIGHT = -6, TRIANGLE UP = -8, TRIANGLE DOWN = -2
298 void changeFigure(int theFigure);
300 * Changes the figure number of edges used for the degreade color points to the indicated one by parameter
301 * param figEdges Is the constant that represents the figure number of edges (TRIANGLE | RECTANGLE)
303 void changePointsFigure_Edges (int figEdges);
306 * Gets the constant that represents the figure number of edges used for the degreade color points
307 * return figureEdges Is the constant that represents the figure number of edges (TRIANGLE | RECTANGLE)
309 int getPointsFigure_Edges ();
312 * Sets the height of the drawing bar area
313 * param _h The height to set
315 void setHeight (int _h);
318 * Sets the height of the drawing bar area
319 * return _h The height to get
324 * Sets the width of the drawing bar area
325 * param _w The width to set
327 void setWidth (int _w);
330 * Gets the width of the drawing bar area
331 * param width The width to get
336 * Sets the height of the containing rectangle bar
337 * param _h The height to set
339 void setBarHeight (int _h);
342 * Gets the height of the containing rectangle bar
343 * return bar_height The height to get
348 * Sets the width of the containing rectangle bar
349 * param _w The width to set
351 void setBarWidth (int _w);
354 * Gets the width of the containing rectangle bar
355 * return bar_width The width to get
360 * Sets the orientation of the color bar
361 * param _orientation The orientation to set VERTICAL = false, HORIZONTAL = true
363 void setOrientation (bool _orientation);
366 * Gets the orientation of the color bar
367 * return bar_orientation The bar orientation assigned
369 bool getOrientation ();
372 * Sets the collection of color points
373 * param _points The new points to set, each one of data type pColorPoint ( xValue, wxColour_assigned)
375 void setPoints (std::vector<pColorPoint *> _points);
378 * Gets the last clickedX pixel coord inside the bar.
379 * return clickedX The x-coord pixel value
384 * Sets the last clickedX pixel coord inside the bar.
385 * param xCoordPixel The x-coord value to set
387 void setClickedX(int xCoordPixel);
390 * Gets the last clickedY pixel coord inside the bar.
391 * return clickedY The y-coord pixel value
396 * Sets the last clickedY pixel coord inside the bar.
397 * param yCoordPixel The y-coord pixel value to set
399 void setClickedY(int yCoordPixel);
402 * Gets the real x value for a givex x-pixel value using the rule real_x = (x_pixel * (maxX_represented_Tshow - minXRepresented) ) / bar_width
403 * param x_Pixel The pixel value to convert into real value with respect to the x scale
404 * return realX The real-x value corresponding to the xPixel
406 double convertToRealValue ( int x_Pixel );
409 * Gets the x-pixel value for a given x_real value using the rule x_pixel = (x_real * bar_width)/(maxX_represented_Tshow - minX_represented_Tshow)
410 * param x_Pixel The pixel value to convert into real value with respect to the x scale
411 * return realX The real-x value corresponding to the xPixel
413 int convertToPixelValue ( double x_real );
416 * Gets the selected color and updates the state of the okSelectedColor
417 * return selectedColor Is the selected rbg color
419 wxColour getSelectedColour();
422 * Sets the represented minimum and maximunm values
423 * param minRealValue The minimum represented value (real value)
424 * param maxRealValue The maximum represented value (real value)
426 void setRepresentedValues ( double minRealValue, double maxRealValue);
429 * Gets the data of the last point moving
430 * return pointData Is a pColorPoint with the data of las moved color
432 pColorPoint * getLastMovedColorPoint();
435 * Sets the gap values for the color bar bitmap
436 * param gap_x Gap in x
437 * param gap_y Gap in y
439 void setGapValues (int gap_x, int gap_y);
442 * Sets the degrade state of the color bar
443 * param newState The degrade stare to set
445 void setDegradeState(bool newState);
448 * Sets the visible range of the bar and repaints the bar according to it, the min value must be less than the max value.
449 * param minToShow Is the minimum value to show in the colorbar
450 * param maxToShow Is the maximum value to show in the colorbar
452 void setVisibleRange(int minToShow, int maxToShow);
455 * Gets the degrade state of the color bar
456 * return doingDegrade is the actual degrade state of the bar
458 bool getDegradeState();
461 * Sets the state of static or not for the limit color points
462 * pamar areStatic Is the state to set for the limits
464 void setStaticLimitsTo(bool areStatic);
467 * Gets the state of static or not for the limit color points
468 * return staticLimits Is the state for limits
470 bool getStaticLimits();
473 * Sets the device start drawing left-superior (pixel) start point and draws automatically the color bar
474 * param deviceStart_x Pixel start for x-coord
475 * param deviceStart_y Pixel start for y-coord
477 void setDeviceBlitStart ( wxCoord deviceStart_x, wxCoord deviceStart_y );
480 * Clears the temporal color points of the list
482 void clearTemporalColors();
485 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
486 * return deviceEndMargin The value asigned to the right margin
492 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
493 * param newDeviceEnd_pixels The new pixel value to asign to the right margin in pixels
495 void setDeviceEndX(int newDeviceEnd_pixels);
499 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
500 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
502 void setDeviceEndMargin(int newDeviceEnd_pixels);
505 * Method that creates and send the given id-event to the event handler
506 * param theEventType Is the event id type identification for generating the event
508 void createAndSendEvent(WXTYPE theEventType);
512 * Returns the number of points that the bar color has
515 int getColorPointsSize();
518 Get the RGB values of the color point that is in the
521 void getDataAt(int index, double& x,int& red,int& green,int& blue);
525 * Sets the guide line color
526 * param theNwGuideLineColor The color to set to the guideLineColor
528 void setGuideLineColour(wxColour theNwGuideLineColor);
531 * Gets the guide line color
532 * return guideLineColor The color of the guideLine
534 wxColour getGuideLineColour();
537 * Sets the background color
538 * param theNwBackColor The color to set to the colourParent
540 void setBackGroundColour(wxColour theNwBackColor);
543 * Gets the background color
544 * return colourParent The color of the background
546 wxColour getBackGroundColour();
549 * Gets the min value of the color bar
551 double getMinValue();
554 * Gets the max value of the color bar
556 double getMaxValue();
559 * Updates the colors of the first nonTemporal point in the list and the last nonTemporal point
560 * That logically corresponds always to the the first and last nodes of the color bar
562 void updateExtremeColors();
564 void onLeftClicDown(wxMouseEvent& event );
566 void onLeftClickUp(wxMouseEvent& event );
568 void updatePointsToDraw();
570 //------------------------------------------------------------------------------------------------------------
571 // Attributes declaration
572 //------------------------------------------------------------------------------------------------------------
582 * Represents the logical bar instance
584 LogicalColorBar * _logicalBar;
587 * Represents the margin gap on x
592 * Represents the margin gap on x
596 * Represents the height of the color bar drawing area
600 * Represents the width of the color bar drawing area
605 * Represents the height of the bar
610 * Represents the width of the bar
615 * Represents the collection of degrade definition points
617 std::deque<pColorPoint *> showedColorPoints;
620 * The orientation of the rectangule is true when is horizontal, false for vertical
622 //bool bar_orientation;
625 * The points figure orientation UP, DOWN, LEFT, or RIGTH
627 int points_orientation;
630 * The minimum represented real value used for calculating the scaling for point by the rule real_x = (x_pixel * (maxX_represented_Tshow_Tshow - minX_represented_Tshow) ) / bar_width
632 int minX_represented_Tshow;
635 * The maximum represented real value used for calculating the scaling for point by the rule real_x = (x_pixel * (maxX_represented_Tshow_Tshow - minXRepresented_Tshow) ) / bar_width
637 int maxX_represented_Tshow;
640 * The minimum represented real value used for calculating the scaling for point by the rule real_x = (x_pixel * (maxX_represented_Tshow_Tshow - minX_represented_Tshow) ) / bar_width
642 int temporalMinXToShow;
645 * The maximum represented real value used for calculating the scaling for point by the rule real_x = (x_pixel * (maxX_represented_Tshow_Tshow - minXRepresented_Tshow) ) / bar_width
647 int temporalMaxXToShow;
650 * Indicates the first node to show
652 pColorPoint * startNode_show;
655 * Indicates the last node to show
657 pColorPoint * lastNode_show;
660 * Indicates the amount of temporal initial color points
662 int accumTemporalPoints;
665 * Represents the state of viewing a range
670 * Is the constant that represents the figure number of edges (TRIANGLE | RECTANGLE)
674 * Represents the last clickedX coord inside the bar.
679 * Represents the last clickedY coord inside the bar.
684 * Represents the movind index of the last moving point in the colorPoints list
686 int movingPointIndex;
689 * Indicates if in the last colour selection the ok button was clicked
691 bool okSelectedColor;
694 * Represents the statc or movable state of limit start and end color points, default value true for static
699 * Indicates the last node moving in the coloPoints list
701 pColorPoint * movingNodePoint;
703 // pDegradeRectangle * degrade;
706 * Is the bitmap for the bar color
708 wxBitmap * colorBar_Bitmap;
710 * Is the bitmap of the information associated to the bar color
712 wxBitmap * information_Bitmap;
714 * Represents the state of doing or not the degrade in the bar (default value true for doing degrade)
719 * Represents that the minimum value for the visible range has been found in the original color points
724 * Represents that the maximum value for the visible range has been found in the original color points
729 * X-Coord for left-superior device visible drawing
731 wxCoord deviceStart_x;
734 * Y-Coord for left-superior device visible drawing
736 wxCoord deviceStart_y;
739 * X-Coord for left-superior device margin, important for horizontal view
741 wxCoord deviceEndMargin;
744 * Y-Coord for left-superior device margin, important for vertical view
748 * Represents the active state of the bar
752 int avaliablePointToMove;
755 * Represents the real-x value to draw a vertical line
757 int realX_vertical_line;
760 * Represents the color of the dot-line use as guides. The default color is RED.
762 wxColour guideLineColor;
765 * Represents the color of the backGround. Default color is the parent color.
767 wxColour colourParent;
770 * The color bar pop menu
774 * The figure changes submenu
776 wxMenu * changesMenu;
779 DECLARE_CLASS(pColorBar)
780 // any class wishing to process wxWindows events must use this macro
781 DECLARE_EVENT_TABLE()