KiCad PCB EDA Suite
class_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 CLASS_WORKSHEET_DATA_ITEM_H
31 #define CLASS_WORKSHEET_DATA_ITEM_H
32 
33 #include <math/vector2d.h>
34 #include <eda_text.h>
35 #include <class_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 {
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 
208  static int GetMarkerSizeUi()
209  {
210  return KiROUND( 0.5 * m_WSunits2Iu );
211  }
212 
217  void MoveTo( DPOINT aPosition );
218 
223  void MoveToUi( wxPoint aPosition );
224 
229  void MoveStartPointTo( DPOINT aPosition );
230 
235  void MoveStartPointToUi( wxPoint aPosition );
236 
237 
244  void MoveEndPointTo( DPOINT aPosition );
245 
252  void MoveEndPointToUi( wxPoint aPosition );
253 
258  virtual bool IsInsidePage( int ii ) const;
259 
260  const wxString GetClassName() const;
261 
265  bool IsSelected() { return (m_flags & SELECTED_STATE) != 0; }
266 
272  void SetSelected( bool aState )
273  {
274  if( aState )
275  m_flags |= SELECTED_STATE;
276  else
277  m_flags &= ~SELECTED_STATE;
278  }
279 
280  bool UseAltColor() {return m_flags & USE_ALT_COLOR; }
281 
283  {
284  if( IsSelected() )
285  return m_SelectedColor;
286 
287  if( UseAltColor() )
288  return m_AltColor;
289 
290  return m_Color;
291  }
292 };
293 
294 
296 {
297 public:
298  double m_Orient; // Orientation in degrees
299  std::vector<DPOINT> m_Corners; // corner list
300 
301 private:
302  std::vector<unsigned> m_polyIndexEnd; // index of the last point of each polygon
303  DPOINT m_minCoord; // min coord of corners, relative to m_Pos
304  DPOINT m_maxCoord; // max coord of corners, relative to m_Pos
305 
306 public:
308 
309  virtual int GetPenSizeUi() override
310  {
311  return KiROUND( m_LineWidth * m_WSunits2Iu );
312  }
313 
317  virtual bool HasEndPoint() override { return false; }
318 
323  void AppendCorner( const DPOINT& aCorner )
324  {
325  m_Corners.push_back( aCorner );
326  }
327 
333  {
334  m_polyIndexEnd.push_back( m_Corners.size() -1 );
335  }
336 
340  int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
341 
346  unsigned GetPolyIndexStart( unsigned aContour) const
347  {
348  if( aContour == 0 )
349  return 0;
350  else
351  return m_polyIndexEnd[aContour-1] + 1;
352  }
353 
358  unsigned GetPolyIndexEnd( unsigned aContour) const
359  {
360  return m_polyIndexEnd[aContour];
361  }
362 
367  const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
368 
373  const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const;
374 
378  void SetBoundingBox();
379 
380  bool IsInsidePage( int ii ) const override;
381 };
382 
383 
385 {
386 public:
387  wxString m_TextBase; // The basic text, with format symbols
388  wxString m_FullText; // The expanded text, shown on screen
389  double m_Orient; // Orientation in degrees
393  DSIZE m_BoundingBoxSize; // When not null, this is the max
394  // size of the full text.
395  // the text size will be modified
396  // to keep the full text insite this
397  // bound.
398  DSIZE m_ConstrainedTextSize; // Actual text size, if constrained by
399  // the m_BoundingBoxSize constraint
400 
401 
402 public:
403  WORKSHEET_DATAITEM_TEXT( const wxString& aTextBase );
404 
408  virtual bool HasEndPoint() override { return false; }
409 
410  virtual int GetPenSizeUi() override
411  {
412  if( m_LineWidth )
413  return KiROUND( m_LineWidth * m_WSunits2Iu );
414  else
415  return KiROUND( m_DefaultTextThickness * m_WSunits2Iu );
416  }
417 
422  void MoveTo( DPOINT aPosition );
423 
429 
439  void IncrementLabel( int aIncr );
440 
449  void SetConstrainedTextSize();
450 
451 
458 
462  bool IsBold() { return (m_flags & USE_BOLD) != 0; }
463 
469  void SetBold( bool aState )
470  {
471  if( aState )
472  m_flags |= USE_BOLD;
473  else
474  m_flags &= ~USE_BOLD;
475  }
476 
480  bool IsItalic() const { return (m_flags & USE_ITALIC) != 0; }
481 
487  void SetItalic( bool aState )
488  {
489  if( aState )
490  m_flags |= USE_ITALIC;
491  else
492  m_flags &= ~USE_ITALIC;
493  }
494 };
495 
496 
497 class BITMAP_BASE;
499 {
500 public:
502 
503 public:
506  {
507  m_ImageBitmap = aImage;
508  }
509 
513  virtual bool HasEndPoint() override { return false; }
514 
518  int GetPPI() const;
519 
524  void SetPPI( int aBitmapPPI );
525 
533  void SetPixelScaleFactor();
534 };
535 
536 
537 #endif // CLASS_WORKSHEET_DATA_ITEM_H
#define USE_BOLD
POINT_COORD(DPOINT aPos, enum corner_anchor aAnchor=RB_CORNER)
void TransfertSetupToGraphicText(WS_DRAW_ITEM_TEXT *aGText)
transfert the text justification and orientation to aGText
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:47
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
void SetBoundingBox()
calculate the bounding box of the set polygons
const DPOINT GetStartPos(int ii=0) const
virtual bool HasEndPoint() override
bool IsInsidePage(int ii) const override
void MoveEndPointTo(DPOINT aPosition)
move the ending point of the item to a new position has meaning only for items defined by 2 points (s...
void AppendCorner(const DPOINT &aCorner)
add a corner in corner list
virtual bool IsInsidePage(int ii) const
Definition of base KiCad text object.
WORKSHEET_DATAITEM(WS_ItemType aType)
const wxPoint GetStartPosUi(int ii=0) const
virtual bool HasEndPoint() override
void IncrementLabel(int aIncr)
Try to build text wihich is an increment of m_TextBase has meaning only if m_TextBase is a basic text...
This class handle bitmap images in KiCad.
void MoveStartPointTo(DPOINT aPosition)
move the starting point of the item to a new position
WORKSHEET_DATAITEM_TEXT(const wxString &aTextBase)
void SetItalic(bool aState)
Function SetItalic Toggles on/off the italic option flag.
void MoveToUi(wxPoint aPosition)
move item to a new position
#define USE_ITALIC
void SetPixelScaleFactor()
set the pixel scale factor of the bitmap this factor depend on the application internal unit and the ...
void SetSelected(bool aState)
Function SetSelected Toggles on/off the selected flag (used in edition functions. ...
void SetEnd(double aPosx, double aPosy, enum corner_anchor aAnchor=RB_CORNER)
WORKSHEET_DATAITEM_BITMAP(BITMAP_BASE *aImage)
unsigned GetPolyIndexStart(unsigned aContour) const
void MoveTo(DPOINT aPosition)
move item to a new position
const wxPoint GetEndPosUi(int ii=0) const
void SetPPI(int aBitmapPPI)
adjust the PPI of the bitmap
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:54
const wxPoint GetCornerPositionUi(unsigned aIdx, int aRepeat=0) const
const DPOINT GetEndPos(int ii=0) const
static double m_DefaultTextThickness
void SetConstrainedTextSize()
Calculates m_ConstrainedTextSize from m_TextSize to keep the X size and the full Y size of the text s...
WS_ItemType GetType() const
void SetStart(double aPosx, double aPosy, enum corner_anchor aAnchor=RB_CORNER)
void SetBold(bool aState)
Function SetBold Toggles on/off the bold option flag.
unsigned GetPolyIndexEnd(unsigned aContour) const
void CloseContour()
Closes the current contour, by storing the index of the last corner of the current polygon in m_polyI...
#define SELECTED_STATE
virtual int GetPenSizeUi() override
void MoveEndPointToUi(wxPoint aPosition)
move the ending point of the item to a new position has meaning only for items defined by 2 points (s...
void SetPage1Option(int aChoice)
Set the option for page 1.
void MoveStartPointToUi(wxPoint aPosition)
move the starting point of the item to a new position
#define USE_ALT_COLOR
bool ReplaceAntiSlashSequence()
Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\' inside m_FullText...
void MoveTo(DPOINT aPosition)
move item to a new position
const wxString GetClassName() const
const DPOINT GetCornerPosition(unsigned aIdx, int aRepeat=0) const
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39