5 // -----------------------------------------------------------------------------------------------------------
6 // WX headers inclusion.
7 // For compilers that support precompilation, includes <wx/wx.h>.
8 // -----------------------------------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------------------------------------
19 //------------------------------------------------------------------------------------------------------------
25 #include "pColorPoint.h"
26 #include "LogicalColorBar.h"
27 //#include "DegradeRectangle.h"
29 #include "wx/colordlg.h"
36 * Attribute that determines the width of each color point
38 #define FIGURE_WIDTH 3
40 BEGIN_DECLARE_EVENT_TYPES()
41 DECLARE_EVENT_TYPE( wxEVT_ADDED_POINT, -1 )
42 DECLARE_EVENT_TYPE( wxEVT_REMOVED_POINT, -1 )
43 DECLARE_EVENT_TYPE( wxEVT_MOVED_POINT, -1 )
44 DECLARE_EVENT_TYPE( wxEVT_CHANGED_POINT, -1 )
45 DECLARE_EVENT_TYPE( wxEVT_ON_COLOR_BAR, -1 )
46 END_DECLARE_EVENT_TYPES()
49 //-------------------------------------------------------------------------------------------------------------
51 //-------------------------------------------------------------------------------------------------------------
52 /** Command IDs used by pColorPoint */
55 cntID_ADD_COLOR_POINT = 6000,
56 cntID_DEL_COLOR_POINT,
57 cntID_CHANGE_COLOR_POINT,
58 cntID_DEGRADE_CONTROL,
63 cntID_TRIANGLES_RIGHT,
67 /** file pColorBar.h */
68 class MARACASVISULIB_EXPORTS pColorBar :public wxScrolledWindow{
71 //------------------------------------------------------------------------------------------------------------
72 // Constructors & Destructors
73 //------------------------------------------------------------------------------------------------------------
75 * Creates a colorBar instance
76 * param *parent Container event listener window
77 * param _w Width of the color bar drawing area
78 * param _h Height of the color bar drawing area
79 * param _bar_orientation VERTICAL (false) or HORIZONTAL (true) direction to set
81 pColorBar (wxWindow *parent, int _w, int _h, bool _bar_orientation);
85 //------------------------------------------------------------------------------------------------------------
86 // Color bar proccessed events methods
87 //------------------------------------------------------------------------------------------------------------
88 void OnSize( wxSizeEvent &WXUNUSED(event) );
91 * Reacts to the mouse movement inside the color bar for moving the clicked color point in the x-axis.
92 * Informs the result of the handled event like a wxCommandEvent wxEVT_MOVED_POINT if a point was moved.
93 * param event The mouse actioned event
95 void onMouseMove ( wxMouseEvent& event );
97 * Reacts to the event of drawing the bar and draws it
98 * param &WXUNUSED(event) The correspondig wxPaintEvent actioned event
100 void onPaint ( wxPaintEvent &WXUNUSED(event) );
103 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
104 * Informs the result of the handled event like a wxCommandEvent wxEVT_ADDED_POINT if the point was inserted succesfully.
105 * param & anEvent The wxCommandEvent actioned event
107 void onAddColorPoint ( wxCommandEvent& anEvent );
110 * Reacts to the cntID_DEL_POINT wxCommandEvent and deletes a color degrade point of the color bar.
111 * Informs the result of the handled event like a wxCommandEvent wxEVT_REMOVED_POINT if the point was succesfully removed.
112 * param & anEvent The wxCommandEvent actioned event
114 void onDeleteColorPoint ( wxCommandEvent& anEvent );
117 * Reacts to the cntID_CHANGE_COLOR_POINT wxCommandEvent and changes the assigned color to the selected color degrade point of the color bar.
118 * Informs the result of the handled event like a wxCommandEvent wxEVT_CHANGED_POINT if the point was succesfully removed.
119 * param & anEvent The wxCommandEvent actioned event
121 void onChangeColourSelectedPoint ( wxCommandEvent& anEvent );
124 * Reacts to the cntID_TRIANGLES_UP wxCommandEvent and changes the assigned figure to -triangles up- for the color points of the color bar.
125 * param & anEvent The wxCommandEvent actioned event
127 void onTrianglesUp_Figure ( wxCommandEvent& anEvent );
129 * Reacts to the cntID_TRIANGLES_DOWN wxCommandEvent and changes the assigned figure to -triangles down- for the color points of the color bar.
130 * param & anEvent The wxCommandEvent actioned event
132 void onTrianglesDown_Figure ( wxCommandEvent& anEvent );
134 * Reacts to the cntID_TRIANGLES_LEFT wxCommandEvent and changes the assigned figure to -triangles left- for the color points of the color bar.
135 * param & anEvent The wxCommandEvent actioned event
137 void onTrianglesLeft_Figure ( wxCommandEvent& anEvent );
139 * Reacts to the cntID_TRIANGLES_RIGHT wxCommandEvent and changes the assigned figure to -triangles right- for the color points of the color bar.
140 * param & anEvent The wxCommandEvent actioned event
142 void onTrianglesRight_Figure ( wxCommandEvent& anEvent );
144 * Reacts to the cntID_RECTANGLES wxCommandEvent and changes the assigned figure to -rectangles- for the color points of the color bar.
145 * param & anEvent The wxCommandEvent actioned event
147 void onRectangles_Figure ( wxCommandEvent& anEvent );
150 * Reacts to the cntID_DEGRADE_CONTROL wxCommandEvent and turns on/off the degrade in the color bar.
151 * param & anEvent The wxCommandEvent actioned event
153 void onDegradeControl ( wxCommandEvent& anEvent );
156 * Reacts to the wxEVT_RIGHT_DCLICK wxMouseEvent and adds a color degrade point to the color bar.
157 * Informs the result of the handled event like a wxCommandEvent wxEVT_ADDED_POINT if the point was succesfully inserted.
158 * param & event The wxMouseEvent actioned event
160 void onLeftButtonDClick (wxMouseEvent& event);
163 * Shows the popup menu
165 void onShowPopupMenu (wxMouseEvent& event);
168 //------------------------------------------------------------------------------------------------------------
170 //------------------------------------------------------------------------------------------------------------
174 * param activeNow The new state
176 void setActiveStateTo (bool activeNow);
179 * Gets the active state of the bar
180 * return activeState The actual state
186 * Gets the real-x value to draw a vertical line
187 * return realX_vertical_line The real x value for the vertical line
189 int getRealX_vertical_line();
192 * Sets the real-x value to draw a vertical line
193 * param realX_vertical_line The new real x value for the vertical line
195 void setRealX_vertical_line(int newReal_x);
199 * Method that reinitiates attributes of the color bar to the given points
200 * param minRealValue The minimum represented value (real value)
201 * param maxRealValue The maximum represented value (real value)
203 void reinitiateColorBar(double minRealValue, double maxRealValue);
206 * Method that reinitiates attributes of the color bar and set the points given by parameter
207 * param newPointsList Pointer to the list of the new points
209 void reinitiateColorBarTo (std::vector<pColorPoint *> pointsVector);
212 *Method that sets a copy of the points of the color bar to the given pointer parameter
213 * param pointsList The list for getting the points
215 void getPointsListWithTemps (std::vector<pColorPoint*> &pointsVector);
218 * 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
219 * includes the teporal points created
220 * param pointsVector The list for getting the points
222 void getAddedColorsPointsList (std::vector<pColorPoint*>& pointsVector);
225 * Adds a color degrade point to the color bar.
226 * param xRealValue The real xValue of the point
227 * param theColour The assigned color for the point
228 * param temporalStart Indicates if the inserted point is the temporal startShowing point
229 * param temporalEnd Indicates if the inserted point is the temporal startShowing point
230 * return Returns true if the point was succesfully inserted.
232 bool addColorPoint (double xRealValue, wxColour theColour/*, bool temporalStart=false, bool temporalEnd=false*/);
235 * Delets a color degrade point to the color bar.
236 * param xRealValue The real xValue of the point to delete
237 * return Returns true if the point was succesfully inserted.
239 bool deleteColorPoint (double xRealValue);
242 * Changes the color degrade point color value.
243 * Informs the result of the handled event like a wxCommandEvent wxEVT_CHANGED_COLOR_POINT if the point changed its colour.
244 * param clickedValue The x-coord pixel value of the point to which the color change interests
245 * return Returns true if the color point was succesfully updated.
247 bool changeColor ( int clickedValue );
250 * Repaints the color bar in direction mode of the orientation assigned
251 * param createTempPoints True for creating temporal points for start and end when a visible range changes
253 void repaintView ( );
256 * Forces the refresh view of the color bar
258 void RefreshForce ();
260 void Refresh(bool eraseBackground = true, const wxRect* rect = NULL);
263 * Draws the color bar with its degrades
264 * param recentlyChangedOrientation indicates if the orientation has been changed before calling this method
266 void drawColorBar ( bool recentlyChangedOrientation);
269 * Changes the figure of the color points according to the parameter
270 * param theFigure Is the corresponding number for identifying the figure
271 * RECTANGLE = 4,TRIANGLE LEFT = -4, TRIANGLE RIGHT = -6, TRIANGLE UP = -8, TRIANGLE DOWN = -2
273 void changeFigure(int theFigure);
275 * Changes the figure number of edges used for the degreade color points to the indicated one by parameter
276 * param figEdges Is the constant that represents the figure number of edges (TRIANGLE | RECTANGLE)
278 void changePointsFigure_Edges (int figEdges);
281 * Gets the constant that represents the figure number of edges used for the degreade color points
282 * return figureEdges Is the constant that represents the figure number of edges (TRIANGLE | RECTANGLE)
284 int getPointsFigure_Edges ();
287 * Sets the height of the drawing bar area
288 * param _h The height to set
290 void setHeight (int _h);
293 * Sets the height of the drawing bar area
294 * return _h The height to get
299 * Sets the width of the drawing bar area
300 * param _w The width to set
302 void setWidth (int _w);
305 * Gets the width of the drawing bar area
306 * param width The width to get
311 * Sets the height of the containing rectangle bar
312 * param _h The height to set
314 void setBarHeight (int _h);
317 * Gets the height of the containing rectangle bar
318 * return bar_height The height to get
323 * Sets the width of the containing rectangle bar
324 * param _w The width to set
326 void setBarWidth (int _w);
329 * Gets the width of the containing rectangle bar
330 * return bar_width The width to get
335 * Sets the orientation of the color bar
336 * param _orientation The orientation to set VERTICAL = false, HORIZONTAL = true
338 void setOrientation (bool _orientation);
341 * Gets the orientation of the color bar
342 * return bar_orientation The bar orientation assigned
344 bool getOrientation ();
347 * Sets the collection of color points
348 * param _points The new points to set, each one of data type pColorPoint ( xValue, wxColour_assigned)
350 void setPoints (std::vector<pColorPoint *> _points);
353 * Gets the last clickedX pixel coord inside the bar.
354 * return clickedX The x-coord pixel value
359 * Sets the last clickedX pixel coord inside the bar.
360 * param xCoordPixel The x-coord value to set
362 void setClickedX(int xCoordPixel);
365 * Gets the last clickedY pixel coord inside the bar.
366 * return clickedY The y-coord pixel value
371 * Sets the last clickedY pixel coord inside the bar.
372 * param yCoordPixel The y-coord pixel value to set
374 void setClickedY(int yCoordPixel);
377 * Gets the real x value for a givex x-pixel value using the rule real_x = (x_pixel * (maxX_represented_Tshow - minXRepresented) ) / bar_width
378 * param x_Pixel The pixel value to convert into real value with respect to the x scale
379 * return realX The real-x value corresponding to the xPixel
381 double convertToRealValue ( int x_Pixel );
384 * 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)
385 * param x_Pixel The pixel value to convert into real value with respect to the x scale
386 * return realX The real-x value corresponding to the xPixel
388 int convertToPixelValue ( double x_real );
391 * Gets the selected color and updates the state of the okSelectedColor
392 * return selectedColor Is the selected rbg color
394 wxColour getSelectedColour();
397 * Sets the represented minimum and maximunm values
398 * param minRealValue The minimum represented value (real value)
399 * param maxRealValue The maximum represented value (real value)
401 void setRepresentedValues ( double minRealValue, double maxRealValue);
404 * Gets the data of the last point moving
405 * return pointData Is a pColorPoint with the data of las moved color
407 pColorPoint * getLastMovedColorPoint();
410 * Sets the gap values for the color bar bitmap
411 * param gap_x Gap in x
412 * param gap_y Gap in y
414 void setGapValues (int gap_x, int gap_y);
417 * Sets the degrade state of the color bar
418 * param newState The degrade stare to set
420 void setDegradeState(bool newState);
423 * Sets the visible range of the bar and repaints the bar according to it, the min value must be less than the max value.
424 * param minToShow Is the minimum value to show in the colorbar
425 * param maxToShow Is the maximum value to show in the colorbar
427 void setVisibleRange(int minToShow, int maxToShow);
430 * Gets the degrade state of the color bar
431 * return doingDegrade is the actual degrade state of the bar
433 bool getDegradeState();
436 * Sets the state of static or not for the limit color points
437 * pamar areStatic Is the state to set for the limits
439 void setStaticLimitsTo(bool areStatic);
442 * Gets the state of static or not for the limit color points
443 * return staticLimits Is the state for limits
445 bool getStaticLimits();
448 * Sets the device start drawing left-superior (pixel) start point and draws automatically the color bar
449 * param deviceStart_x Pixel start for x-coord
450 * param deviceStart_y Pixel start for y-coord
452 void setDeviceBlitStart ( wxCoord deviceStart_x, wxCoord deviceStart_y );
455 * Clears the temporal color points of the list
457 void clearTemporalColors();
460 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
461 * return deviceEndMargin The value asigned to the right margin
467 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
468 * param newDeviceEnd_pixels The new pixel value to asign to the right margin in pixels
470 void setDeviceEndX(int newDeviceEnd_pixels);
474 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
475 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
477 void setDeviceEndMargin(int newDeviceEnd_pixels);
480 * Method that creates and send the given id-event to the event handler
481 * param theEventType Is the event id type identification for generating the event
483 void createAndSendEvent(WXTYPE theEventType);
487 * Returns the number of points that the bar color has
490 int getColorPointsSize();
493 Get the RGB values of the color point that is in the
496 void getDataAt(int index, double& x,int& red,int& green,int& blue);
500 * Sets the guide line color
501 * param theNwGuideLineColor The color to set to the guideLineColor
503 void setGuideLineColour(wxColour theNwGuideLineColor);
506 * Gets the guide line color
507 * return guideLineColor The color of the guideLine
509 wxColour getGuideLineColour();
512 * Sets the background color
513 * param theNwBackColor The color to set to the colourParent
515 void setBackGroundColour(wxColour theNwBackColor);
518 * Gets the background color
519 * return colourParent The color of the background
521 wxColour getBackGroundColour();
524 * Gets the min value of the color bar
526 double getMinValue();
529 * Gets the max value of the color bar
531 double getMaxValue();
534 * Updates the colors of the first nonTemporal point in the list and the last nonTemporal point
535 * That logically corresponds always to the the first and last nodes of the color bar
537 void updateExtremeColors();
539 void onLeftClicDown(wxMouseEvent& event );
541 void onLeftClickUp(wxMouseEvent& event );
543 void updatePointsToDraw();
545 //------------------------------------------------------------------------------------------------------------
546 // Attributes declaration
547 //------------------------------------------------------------------------------------------------------------
557 * Represents the logical bar instance
559 LogicalColorBar * _logicalBar;
562 * Represents the margin gap on x
567 * Represents the margin gap on x
571 * Represents the height of the color bar drawing area
575 * Represents the width of the color bar drawing area
580 * Represents the height of the bar
585 * Represents the width of the bar
590 * Represents the collection of degrade definition points
592 std::deque<pColorPoint *> showedColorPoints;
595 * The orientation of the rectangule is true when is horizontal, false for vertical
597 //bool bar_orientation;
600 * The points figure orientation UP, DOWN, LEFT, or RIGTH
602 int points_orientation;
605 * 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
607 int minX_represented_Tshow;
610 * 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
612 int maxX_represented_Tshow;
615 * 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
617 int temporalMinXToShow;
620 * 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
622 int temporalMaxXToShow;
625 * Indicates the first node to show
627 pColorPoint * startNode_show;
630 * Indicates the last node to show
632 pColorPoint * lastNode_show;
635 * Indicates the amount of temporal initial color points
637 int accumTemporalPoints;
640 * Represents the state of viewing a range
645 * Is the constant that represents the figure number of edges (TRIANGLE | RECTANGLE)
649 * Represents the last clickedX coord inside the bar.
654 * Represents the last clickedY coord inside the bar.
659 * Represents the movind index of the last moving point in the colorPoints list
661 int movingPointIndex;
664 * Indicates if in the last colour selection the ok button was clicked
666 bool okSelectedColor;
669 * Represents the statc or movable state of limit start and end color points, default value true for static
674 * Indicates the last node moving in the coloPoints list
676 pColorPoint * movingNodePoint;
678 // pDegradeRectangle * degrade;
681 * Is the bitmap for the bar color
683 wxBitmap * colorBar_Bitmap;
685 * Is the bitmap of the information associated to the bar color
687 wxBitmap * information_Bitmap;
689 * Represents the state of doing or not the degrade in the bar (default value true for doing degrade)
694 * Represents that the minimum value for the visible range has been found in the original color points
699 * Represents that the maximum value for the visible range has been found in the original color points
704 * X-Coord for left-superior device visible drawing
706 wxCoord deviceStart_x;
709 * Y-Coord for left-superior device visible drawing
711 wxCoord deviceStart_y;
714 * X-Coord for left-superior device margin, important for horizontal view
716 wxCoord deviceEndMargin;
719 * Y-Coord for left-superior device margin, important for vertical view
723 * Represents the active state of the bar
727 int avaliablePointToMove;
730 * Represents the real-x value to draw a vertical line
732 int realX_vertical_line;
735 * Represents the color of the dot-line use as guides. The default color is RED.
737 wxColour guideLineColor;
740 * Represents the color of the backGround. Default color is the parent color.
742 wxColour colourParent;
745 * The color bar pop menu
749 * The figure changes submenu
751 wxMenu * changesMenu;
754 DECLARE_CLASS(pColorBar)
755 // any class wishing to process wxWindows events must use this macro
756 DECLARE_EVENT_TABLE()