KiCad PCB EDA Suite
worksheet_dataitem.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2014 KiCad Developers, see CHANGELOG.TXT for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #ifndef WORKSHEET_DATA_ITEM_H
31 #define WORKSHEET_DATA_ITEM_H
32 
33 #include <math/vector2d.h>
34 #include <eda_text.h>
35 #include <bitmap_base.h>
36 
37 class WS_DRAW_ITEM_TEXT; // Forward declaration
38 
39 #define TB_DEFAULT_TEXTSIZE 1.5 // default worksheet text size in mm
40 
41 // Text attributes set in m_flags (ORed bits)
42 #define USE_BOLD 1 // has meaning for texts
43 #define USE_THICK_LINE 1 // equivalent to bold for lines
44 #define USE_ITALIC (1<<1) // has meaning for texts
45 #define USE_ALT_COLOR (1<<2)
46 #define SELECTED_STATE (1<<3) // When set, use the hight light color to draw item
47 #define NEW_ITEM (1<<4) // Set for new items which can be deleted
48  // by an abort command
49 #define LOCATE_STARTPOINT (1<<5) // Used in locate function:set by locate function
50  // if the start point is located
51 #define LOCATE_ENDPOINT (1<<6) // Used in locate function:set by locate function
52  // if the end point is located
53 #define PAGE1OPTION (3<<7) // flag to manage items drawn or not drawn only
54  // on page 1: NONE = item on all pages
55 #define PAGE1OPTION_NONE (0<<7) // NONE = item on all pages
56 #define PAGE1OPTION_PAGE1ONLY (1<<7) // = item only on page 1
57 #define PAGE1OPTION_NOTONPAGE1 (2<<7) // = item on all pages but page 1
58 
59 // A coordinate is relative to a page corner.
60 // Any of the 4 corners can be a reference.
61 // The default is the right bottom corner
63 {
64  RB_CORNER, // right bottom corner
65  RT_CORNER, // right top corner
66  LB_CORNER, // left bottom corner
67  LT_CORNER, // left top corner
68 };
69 
70 // a coordinate point
71 // The position is always relative to the corner anchor
72 // Note the coordinate is from the anchor point
73 // to the opposite corner.
75 {
76 public:
78  int m_Anchor;
79 public:
80  POINT_COORD() { m_Anchor = RB_CORNER; }
81  POINT_COORD( DPOINT aPos, enum corner_anchor aAnchor = RB_CORNER )
82  {
83  m_Pos = aPos;
84  m_Anchor = aAnchor;
85  }
86 };
87 
88 
89 // Work sheet structure type definitions.
90 // Basic items are:
91 // * segment and rect (defined by 2 points)
92 // * text (defined by a coordinate), the text and its justifications
93 // * poly polygon defined by a coordinate, and a set of list of corners
94 // ( because we use it for logos, there are more than one polygon
95 // in this description
97 {
98 public:
99  enum WS_ItemType {
104  WS_BITMAP
105  };
106 
107 protected:
109  int m_flags;
110 
111 public:
112  wxString m_Name; // a item name used in page layout
113  // editor to identify items
114  wxString m_Info; // a comment, only useful in page
115  // layout editor
118  double m_LineWidth;
119  int m_RepeatCount; // repeat count for duplicate items
120  DPOINT m_IncrementVector; // For duplicate items: move vector
121  // for position increment
123 
124  // These variables are static, because these values are common to all
125  // instances of WORKSHEET_DATAITEM.
126  // They are default or common values.
127  static double m_WSunits2Iu; // conversion factor between
128  // ws units (mils) and draw/plot units
129  static DPOINT m_RB_Corner; // cordinates of the right bottom corner
130  // (ws units)
131  static DPOINT m_LT_Corner; // cordinates of the left top corner
132  // (ws units)
133  static double m_DefaultLineWidth; // Default line width,
134  // when not defined inside a line
135  // or a rect
136  static DSIZE m_DefaultTextSize; // Default text size,
137  // when not defined inside a tbtext
138  static double m_DefaultTextThickness; // Default text thickness,
139  // when not defined inside a tbtext
140  static bool m_SpecialMode; // Used in page layout editor
141  // When set to true, base texts
142  // instead of full texts are displayed
143  static COLOR4D m_Color; // the default color to draw items
144  static COLOR4D m_AltColor; // an alternate color to draw items
145  static COLOR4D m_SelectedColor; // the color to draw selected items
146  // (used in page layout editor
147 
148 
149 public:
151 
152  virtual ~WORKSHEET_DATAITEM() {}
153 
154  void SetStart( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER )
155  {
156  m_Pos.m_Pos.x = aPosx;
157  m_Pos.m_Pos.y = aPosy;
158  m_Pos.m_Anchor = aAnchor;
159  }
160 
161  void SetEnd( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER )
162  {
163  m_End.m_Pos.x = aPosx;
164  m_End.m_Pos.y = aPosy;
165  m_End.m_Anchor = aAnchor;
166  }
167 
168  // Accessors:
169  WS_ItemType GetType() const { return m_type; }
170  int GetFlags() const { return m_flags; }
171  void SetFlags( int aMask ) { m_flags |= aMask; }
172  void ClearFlags( int aMask ) { m_flags &= ~aMask; }
173 
178  virtual bool HasEndPoint() { return true; }
179 
185  int GetPage1Option();
186 
193  void SetPage1Option( int aChoice );
194 
195  // Coordinate handling
196  const wxPoint GetStartPosUi( int ii = 0 ) const;
197  const wxPoint GetEndPosUi( int ii = 0 ) const;
198  const DPOINT GetStartPos( int ii = 0 ) const;
199  const DPOINT GetEndPos( int ii = 0 ) const;
200  virtual int GetPenSizeUi()
201  {
202  if( m_LineWidth )
203  return KiROUND( m_LineWidth * m_WSunits2Iu );
204  else
205  return KiROUND( m_DefaultLineWidth * m_WSunits2Iu );
206  }
207 
213  static int GetMarkerSizeUi( double aZoomScale = 1.0 )
214  {
215  #define MARKER_DRAW_SIZE 0.5 // Is a value choosen for a suitable size on screen
216  return KiROUND( MARKER_DRAW_SIZE * m_WSunits2Iu * aZoomScale );
217  }
218 
223  void MoveTo( DPOINT aPosition );
224 
229  void MoveToUi( wxPoint aPosition );
230 
235  void MoveStartPointTo( DPOINT aPosition );
236 
241  void MoveStartPointToUi( wxPoint aPosition );
242 
243 
250  void MoveEndPointTo( DPOINT aPosition );
251 
258  void MoveEndPointToUi( wxPoint aPosition );
259 
264  virtual bool IsInsidePage( int ii ) const;
265 
266  const wxString GetClassName() const;
267 
271  bool IsSelected() { return (m_flags & SELECTED_STATE) != 0; }
272 
278  void SetSelected( bool aState )
279  {
280  if( aState )
281  m_flags |= SELECTED_STATE;
282  else
283  m_flags &= ~SELECTED_STATE;
284  }
285 
286  bool UseAltColor() {return m_flags & USE_ALT_COLOR; }
287 
289  {
290  if( IsSelected() )
291  return m_SelectedColor;
292 
293  if( UseAltColor() )
294  return m_AltColor;
295 
296  return m_Color;
297  }
298 };
299 
300 
302 {
303 public:
304  double m_Orient; // Orientation in degrees
305  std::vector<DPOINT> m_Corners; // corner list
306 
307 private:
308  std::vector<unsigned> m_polyIndexEnd; // index of the last point of each polygon
309  DPOINT m_minCoord; // min coord of corners, relative to m_Pos
310  DPOINT m_maxCoord; // max coord of corners, relative to m_Pos
311 
312 public:
314 
315  virtual int GetPenSizeUi() override
316  {
317  return KiROUND( m_LineWidth * m_WSunits2Iu );
318  }
319 
323  virtual bool HasEndPoint() override { return false; }
324 
329  void AppendCorner( const DPOINT& aCorner )
330  {
331  m_Corners.push_back( aCorner );
332  }
333 
339  {
340  m_polyIndexEnd.push_back( m_Corners.size() -1 );
341  }
342 
346  int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
347 
352  unsigned GetPolyIndexStart( unsigned aContour) const
353  {
354  if( aContour == 0 )
355  return 0;
356  else
357  return m_polyIndexEnd[aContour-1] + 1;
358  }
359 
364  unsigned GetPolyIndexEnd( unsigned aContour) const
365  {
366  return m_polyIndexEnd[aContour];
367  }
368 
373  const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
374 
379  const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const;
380 
384  void SetBoundingBox();
385 
386  bool IsInsidePage( int ii ) const override;
387 };
388 
389 
391 {
392 public:
393  wxString m_TextBase; // The basic text, with format symbols
394  wxString m_FullText; // The expanded text, shown on screen
395  double m_Orient; // Orientation in degrees
399  DSIZE m_BoundingBoxSize; // When not null, this is the max
400  // size of the full text.
401  // the text size will be modified
402  // to keep the full text insite this
403  // bound.
404  DSIZE m_ConstrainedTextSize; // Actual text size, if constrained by
405  // the m_BoundingBoxSize constraint
406 
407 
408 public:
409  WORKSHEET_DATAITEM_TEXT( const wxString& aTextBase );
410 
414  virtual bool HasEndPoint() override { return false; }
415 
416  virtual int GetPenSizeUi() override
417  {
418  if( m_LineWidth )
419  return KiROUND( m_LineWidth * m_WSunits2Iu );
420  else
421  return KiROUND( m_DefaultTextThickness * m_WSunits2Iu );
422  }
423 
428  void MoveTo( DPOINT aPosition );
429 
434  void TransfertSetupToGraphicText( WS_DRAW_ITEM_TEXT* aGText );
435 
445  void IncrementLabel( int aIncr );
446 
455  void SetConstrainedTextSize();
456 
457 
463  bool ReplaceAntiSlashSequence();
464 
468  bool IsBold() { return (m_flags & USE_BOLD) != 0; }
469 
475  void SetBold( bool aState )
476  {
477  if( aState )
478  m_flags |= USE_BOLD;
479  else
480  m_flags &= ~USE_BOLD;
481  }
482 
486  bool IsItalic() const { return (m_flags & USE_ITALIC) != 0; }
487 
493  void SetItalic( bool aState )
494  {
495  if( aState )
496  m_flags |= USE_ITALIC;
497  else
498  m_flags &= ~USE_ITALIC;
499  }
500 };
501 
502 
503 class BITMAP_BASE;
505 {
506 public:
508 
509 public:
511  : WORKSHEET_DATAITEM( WS_BITMAP )
512  {
513  m_ImageBitmap = aImage;
514  }
515 
519  virtual bool HasEndPoint() override { return false; }
520 
524  int GetPPI() const;
525 
530  void SetPPI( int aBitmapPPI );
531 
539  void SetPixelScaleFactor();
540 };
541 
542 
543 #endif // WORKSHEET_DATA_ITEM_H
POINT_COORD(DPOINT aPos, enum corner_anchor aAnchor=RB_CORNER)
static DSIZE m_DefaultTextSize
static COLOR4D m_SelectedColor
virtual int GetPenSizeUi()
EDA_TEXT_HJUSTIFY_T m_Hjustify
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:62
virtual bool HasEndPoint()
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
EDA_TEXT_VJUSTIFY_T m_Vjustify
virtual bool HasEndPoint() override
static double m_WSunits2Iu
virtual bool HasEndPoint() override
void ClearFlags(int aMask)
static DPOINT m_LT_Corner
void AppendCorner(const DPOINT &aCorner)
add a corner in corner list
Definition of base KiCad text object.
#define USE_BOLD
virtual bool HasEndPoint() override
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:46
static COLOR4D m_Color
void SetItalic(bool aState)
Function SetItalic Toggles on/off the italic option flag.
static DPOINT m_RB_Corner
void SetFlags(int aMask)
void SetSelected(bool aState)
Function SetSelected Toggles on/off the selected flag (used in editing functions) ...
void SetEnd(double aPosx, double aPosy, enum corner_anchor aAnchor=RB_CORNER)
WORKSHEET_DATAITEM_BITMAP(BITMAP_BASE *aImage)
unsigned GetPolyIndexStart(unsigned aContour) const
static COLOR4D m_AltColor
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:69
static double m_DefaultTextThickness
static double m_DefaultLineWidth
virtual int GetPenSizeUi() override
std::vector< unsigned > m_polyIndexEnd
WS_ItemType GetType() const
void SetStart(double aPosx, double aPosy, enum corner_anchor aAnchor=RB_CORNER)
#define MARKER_DRAW_SIZE
void SetBold(bool aState)
Function SetBold Toggles on/off the bold option flag.
unsigned GetPolyIndexEnd(unsigned aContour) const
#define SELECTED_STATE
void CloseContour()
Closes the current contour, by storing the index of the last corner of the current polygon in m_polyI...
corner_anchor
virtual int GetPenSizeUi() override
#define USE_ALT_COLOR
#define USE_ITALIC
static int GetMarkerSizeUi(double aZoomScale=1.0)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39