KiCad PCB EDA Suite
DS_DATA_ITEM_TEXT Class Reference

#include <ds_data_item.h>

Inheritance diagram for DS_DATA_ITEM_TEXT:
DS_DATA_ITEM

Public Types

enum  DS_ITEM_TYPE {
  DS_TEXT , DS_SEGMENT , DS_RECT , DS_POLYPOLYGON ,
  DS_BITMAP
}
 

Public Member Functions

 DS_DATA_ITEM_TEXT (const wxString &aTextBase)
 
void SyncDrawItems (DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
 
virtual int GetPenSizeUi () override
 
void IncrementLabel (int aIncr)
 Try to build text which is an increment of m_TextBase has meaning only if m_TextBase is a basic text (one char) If the basic char is a digit, build a number If the basic char is a letter, use the letter with ASCII code aIncr + (basic char ascc code) More...
 
void SetConstrainedTextSize ()
 Calculate m_ConstrainedTextSize from m_TextSize to keep the X size and the full Y size of the text smaller than m_BoundingBoxSize if m_BoundingBoxSize.x or m_BoundingBoxSize.y > 0 if m_BoundingBoxSize.x or m_BoundingBoxSize.y == 0 the corresponding text size is not constrained. More...
 
bool ReplaceAntiSlashSequence ()
 Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\' inside m_FullText. More...
 
const std::vector< DS_DRAW_ITEM_BASE * > & GetDrawItems () const
 
void SetStart (double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor=RB_CORNER)
 
void SetEnd (double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor=RB_CORNER)
 
DS_ITEM_TYPE GetType () const
 
PAGE_OPTION GetPage1Option () const
 
void SetPage1Option (PAGE_OPTION aChoice)
 
const VECTOR2I GetStartPosUi (int ii=0) const
 
const VECTOR2I GetEndPosUi (int ii=0) const
 
const VECTOR2D GetStartPos (int ii=0) const
 
const VECTOR2D GetEndPos (int ii=0) const
 
void MoveTo (const VECTOR2D &aPosition)
 Move item to a new position. More...
 
void MoveToUi (const VECTOR2I &aPosition)
 Move item to a new position. More...
 
void MoveStartPointTo (const VECTOR2D &aPosition)
 Move the starting point of the item to a new position. More...
 
void MoveStartPointToUi (const VECTOR2I &aPosition)
 Move the starting point of the item to a new position. More...
 
void MoveEndPointTo (const VECTOR2D &aPosition)
 Move the ending point of the item to a new position. More...
 
void MoveEndPointToUi (const VECTOR2I &aPosition)
 Move the ending point of the item to a new position. More...
 
virtual bool IsInsidePage (int ii) const
 
const wxString GetClassName () const
 

Public Attributes

wxString m_TextBase
 
wxString m_FullText
 
double m_Orient
 
GR_TEXT_H_ALIGN_T m_Hjustify
 
GR_TEXT_V_ALIGN_T m_Vjustify
 
bool m_Italic
 
bool m_Bold
 
KIFONT::FONTm_Font
 
VECTOR2D m_TextSize
 
KIGFX::COLOR4D m_TextColor
 
VECTOR2D m_BoundingBoxSize
 
VECTOR2D m_ConstrainedTextSize
 
wxString m_Name
 
wxString m_Info
 
POINT_COORD m_Pos
 
POINT_COORD m_End
 
double m_LineWidth
 
int m_RepeatCount
 
VECTOR2D m_IncrementVector
 
int m_IncrementLabel
 

Protected Attributes

DS_ITEM_TYPE m_type
 
PAGE_OPTION m_pageOption
 
std::vector< DS_DRAW_ITEM_BASE * > m_drawItems
 

Detailed Description

Definition at line 297 of file ds_data_item.h.

Member Enumeration Documentation

◆ DS_ITEM_TYPE

Enumerator
DS_TEXT 
DS_SEGMENT 
DS_RECT 
DS_POLYPOLYGON 
DS_BITMAP 

Definition at line 98 of file ds_data_item.h.

Constructor & Destructor Documentation

◆ DS_DATA_ITEM_TEXT()

DS_DATA_ITEM_TEXT::DS_DATA_ITEM_TEXT ( const wxString &  aTextBase)

Definition at line 520 of file ds_data_item.cpp.

520 :
522{
523 m_TextBase = aTextBase;
527 m_Italic = false;
528 m_Bold = false;
529 m_Font = nullptr;
530 m_TextColor = COLOR4D::UNSPECIFIED;
531 m_Orient = 0.0;
532 m_LineWidth = 0.0; // 0 means use default value
533}
KIFONT::FONT * m_Font
Definition: ds_data_item.h:342
GR_TEXT_H_ALIGN_T m_Hjustify
Definition: ds_data_item.h:338
KIGFX::COLOR4D m_TextColor
Definition: ds_data_item.h:344
GR_TEXT_V_ALIGN_T m_Vjustify
Definition: ds_data_item.h:339
DS_DATA_ITEM(DS_ITEM_TYPE aType)
double m_LineWidth
Definition: ds_data_item.h:202
int m_IncrementLabel
Definition: ds_data_item.h:205
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_CENTER

References GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER, m_Bold, m_Font, m_Hjustify, DS_DATA_ITEM::m_IncrementLabel, m_Italic, DS_DATA_ITEM::m_LineWidth, m_Orient, m_TextBase, m_TextColor, and m_Vjustify.

Member Function Documentation

◆ GetClassName()

const wxString DS_DATA_ITEM::GetClassName ( ) const
inherited

Definition at line 363 of file ds_data_item.cpp.

364{
365 wxString name;
366
367 switch( GetType() )
368 {
369 case DS_TEXT: name = _( "Text" ); break;
370 case DS_SEGMENT: name = _( "Line" ); break;
371 case DS_RECT: name = _( "Rectangle" ); break;
372 case DS_POLYPOLYGON: name = _( "Imported Shape" ); break;
373 case DS_BITMAP: name = _( "Image" ); break;
374 }
375
376 return name;
377}
const char * name
Definition: DXF_plotter.cpp:56
DS_ITEM_TYPE GetType() const
Definition: ds_data_item.h:128
#define _(s)

References _, DS_DATA_ITEM::DS_BITMAP, DS_DATA_ITEM::DS_POLYPOLYGON, DS_DATA_ITEM::DS_RECT, DS_DATA_ITEM::DS_SEGMENT, DS_DATA_ITEM::DS_TEXT, DS_DATA_ITEM::GetType(), and name.

Referenced by PROPERTIES_FRAME::CopyPrmsFromItemToPanel().

◆ GetDrawItems()

◆ GetEndPos()

const VECTOR2D DS_DATA_ITEM::GetEndPos ( int  ii = 0) const
inherited

Definition at line 304 of file ds_data_item.cpp.

305{
306 VECTOR2D pos( m_End.m_Pos.x + ( m_IncrementVector.x * ii ),
307 m_End.m_Pos.y + ( m_IncrementVector.y * ii ) );
308
309 switch( m_End.m_Anchor )
310 {
311 case RB_CORNER: // right bottom corner
313 break;
314
315 case RT_CORNER: // right top corner
318 break;
319
320 case LB_CORNER: // left bottom corner
323 break;
324
325 case LT_CORNER: // left top corner
327 break;
328 }
329
330 return pos;
331}
VECTOR2D m_IncrementVector
Definition: ds_data_item.h:204
POINT_COORD m_End
Definition: ds_data_item.h:201
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
VECTOR2D m_RB_Corner
VECTOR2D m_LT_Corner
VECTOR2D m_Pos
Definition: ds_data_item.h:80
@ RB_CORNER
Definition: ds_data_item.h:49
@ RT_CORNER
Definition: ds_data_item.h:50
@ LT_CORNER
Definition: ds_data_item.h:52
@ LB_CORNER
Definition: ds_data_item.h:51

References DS_DATA_MODEL::GetTheInstance(), LB_CORNER, LT_CORNER, POINT_COORD::m_Anchor, DS_DATA_ITEM::m_End, DS_DATA_ITEM::m_IncrementVector, DS_DATA_MODEL::m_LT_Corner, POINT_COORD::m_Pos, DS_DATA_MODEL::m_RB_Corner, RB_CORNER, RT_CORNER, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DS_DATA_ITEM::GetEndPosUi(), DS_DATA_ITEM::IsInsidePage(), and DS_DATA_ITEM::MoveTo().

◆ GetEndPosUi()

const VECTOR2I DS_DATA_ITEM::GetEndPosUi ( int  ii = 0) const
inherited

Definition at line 334 of file ds_data_item.cpp.

335{
336 VECTOR2D pos = GetEndPos( ii );
338 return VECTOR2I( KiROUND( pos.x ), KiROUND( pos.y ) );
339}
const VECTOR2D GetEndPos(int ii=0) const
double m_WSunits2Iu
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590

References DS_DATA_ITEM::GetEndPos(), DS_DATA_MODEL::GetTheInstance(), KiROUND(), DS_DATA_MODEL::m_WSunits2Iu, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DS_DATA_ITEM::MoveTo(), DS_DATA_ITEM::SyncDrawItems(), and PL_POINT_EDITOR::updateItem().

◆ GetPage1Option()

PAGE_OPTION DS_DATA_ITEM::GetPage1Option ( ) const
inlineinherited
Returns
true if the item has a end point (segment; rect) of false (text, polygon).

Definition at line 133 of file ds_data_item.h.

133{ return m_pageOption; }
PAGE_OPTION m_pageOption
Definition: ds_data_item.h:209

References DS_DATA_ITEM::m_pageOption.

Referenced by PROPERTIES_FRAME::CopyPrmsFromItemToPanel(), DS_DATA_MODEL_IO::formatOptions(), DS_DRAW_ITEM_BASE::GetMsgPanelInfo(), and DS_DRAW_ITEM_BASE::ViewGetLayers().

◆ GetPenSizeUi()

int DS_DATA_ITEM_TEXT::GetPenSizeUi ( )
overridevirtual

Reimplemented from DS_DATA_ITEM.

Definition at line 610 of file ds_data_item.cpp.

611{
613
614 if( m_LineWidth != 0 )
615 return KiROUND( m_LineWidth * model.m_WSunits2Iu );
616 else
617 return KiROUND( model.m_DefaultTextThickness * model.m_WSunits2Iu );
618}
Handle the graphic items list to draw/plot the frame and title block.
Definition: ds_data_model.h:39
double m_DefaultTextThickness

References DS_DATA_MODEL::GetTheInstance(), KiROUND(), DS_DATA_MODEL::m_DefaultTextThickness, DS_DATA_ITEM::m_LineWidth, and DS_DATA_MODEL::m_WSunits2Iu.

Referenced by SyncDrawItems().

◆ GetStartPos()

const VECTOR2D DS_DATA_ITEM::GetStartPos ( int  ii = 0) const
inherited

Definition at line 266 of file ds_data_item.cpp.

267{
269 VECTOR2D pos( m_Pos.m_Pos.x + ( m_IncrementVector.x * ii ),
270 m_Pos.m_Pos.y + ( m_IncrementVector.y * ii ) );
271
272 switch( m_Pos.m_Anchor )
273 {
274 case RB_CORNER: // right bottom corner
275 pos = model.m_RB_Corner - pos;
276 break;
277
278 case RT_CORNER: // right top corner
279 pos.x = model.m_RB_Corner.x - pos.x;
280 pos.y = model.m_LT_Corner.y + pos.y;
281 break;
282
283 case LB_CORNER: // left bottom corner
284 pos.x = model.m_LT_Corner.x + pos.x;
285 pos.y = model.m_RB_Corner.y - pos.y;
286 break;
287
288 case LT_CORNER: // left top corner
289 pos = model.m_LT_Corner + pos;
290 break;
291 }
292
293 return pos;
294}
POINT_COORD m_Pos
Definition: ds_data_item.h:200

References DS_DATA_MODEL::GetTheInstance(), LB_CORNER, LT_CORNER, POINT_COORD::m_Anchor, DS_DATA_ITEM::m_IncrementVector, DS_DATA_MODEL::m_LT_Corner, POINT_COORD::m_Pos, DS_DATA_ITEM::m_Pos, DS_DATA_MODEL::m_RB_Corner, RB_CORNER, RT_CORNER, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DS_DATA_ITEM_POLYGONS::GetCornerPosition(), DS_DATA_ITEM::GetStartPosUi(), DS_DATA_ITEM::IsInsidePage(), DS_DATA_ITEM_POLYGONS::IsInsidePage(), and DS_DATA_ITEM::MoveTo().

◆ GetStartPosUi()

◆ GetType()

◆ IncrementLabel()

void DS_DATA_ITEM_TEXT::IncrementLabel ( int  aIncr)

Try to build text which is an increment of m_TextBase has meaning only if m_TextBase is a basic text (one char) If the basic char is a digit, build a number If the basic char is a letter, use the letter with ASCII code aIncr + (basic char ascc code)

Parameters
aIncr= the increment value return the incremented label in m_FullText

Definition at line 621 of file ds_data_item.cpp.

622{
623 int last = m_TextBase.Len() -1;
624
625 wxChar lbchar = m_TextBase[last];
627 m_FullText.RemoveLast();
628
629 if( lbchar >= '0' && lbchar <= '9' )
630 // A number is expected:
631 m_FullText << (int)( aIncr + lbchar - '0' );
632 else
633 m_FullText << (wxChar) ( aIncr + lbchar );
634}

References m_FullText, and m_TextBase.

Referenced by SyncDrawItems().

◆ IsInsidePage()

bool DS_DATA_ITEM::IsInsidePage ( int  ii) const
virtualinherited
Returns
true if the item is inside the rectangle defined by the 4 corners, false otherwise.

Reimplemented in DS_DATA_ITEM_POLYGONS.

Definition at line 342 of file ds_data_item.cpp.

343{
345
346 VECTOR2D pos = GetStartPos( ii );
347
348 for( int kk = 0; kk < 1; kk++ )
349 {
350 if( model.m_RB_Corner.x < pos.x || model.m_LT_Corner.x > pos.x )
351 return false;
352
353 if( model.m_RB_Corner.y < pos.y || model.m_LT_Corner.y > pos.y )
354 return false;
355
356 pos = GetEndPos( ii );
357 }
358
359 return true;
360}

References DS_DATA_ITEM::GetEndPos(), DS_DATA_ITEM::GetStartPos(), DS_DATA_MODEL::GetTheInstance(), DS_DATA_MODEL::m_LT_Corner, DS_DATA_MODEL::m_RB_Corner, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DS_DATA_ITEM::SyncDrawItems(), SyncDrawItems(), and DS_DATA_ITEM_BITMAP::SyncDrawItems().

◆ MoveEndPointTo()

void DS_DATA_ITEM::MoveEndPointTo ( const VECTOR2D aPosition)
inherited

Move the ending point of the item to a new position.

This has meaning only for items defined by 2 points (segments and rectangles).

Parameters
aPositionis the new position of the ending point, in mm.

Definition at line 213 of file ds_data_item.cpp.

214{
216 VECTOR2D position;
217
218 // Calculate the position of the starting point
219 // relative to the reference corner
220 // aPosition is the position relative to the right top paper corner
221 switch( m_End.m_Anchor )
222 {
223 case RB_CORNER:
224 position = model.m_RB_Corner - aPosition;
225 break;
226
227 case RT_CORNER:
228 position.x = model.m_RB_Corner.x - aPosition.x;
229 position.y = aPosition.y - model.m_LT_Corner.y;
230 break;
231
232 case LB_CORNER:
233 position.x = aPosition.x - model.m_LT_Corner.x;
234 position.y = model.m_RB_Corner.y - aPosition.y;
235 break;
236
237 case LT_CORNER:
238 position = aPosition - model.m_LT_Corner;
239 break;
240 }
241
242 // Modify m_End only for items having 2 coordinates
243 switch( GetType() )
244 {
245 case DS_SEGMENT:
246 case DS_RECT:
247 m_End.m_Pos = position;
248 break;
249
250 default:
251 break;
252 }
253}

References DS_DATA_ITEM::DS_RECT, DS_DATA_ITEM::DS_SEGMENT, DS_DATA_MODEL::GetTheInstance(), DS_DATA_ITEM::GetType(), LB_CORNER, LT_CORNER, POINT_COORD::m_Anchor, DS_DATA_ITEM::m_End, DS_DATA_MODEL::m_LT_Corner, POINT_COORD::m_Pos, DS_DATA_MODEL::m_RB_Corner, RB_CORNER, RT_CORNER, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DS_DATA_ITEM::MoveEndPointToUi(), and DS_DATA_ITEM::MoveTo().

◆ MoveEndPointToUi()

void DS_DATA_ITEM::MoveEndPointToUi ( const VECTOR2I aPosition)
inherited

Move the ending point of the item to a new position.

This has meaning only for items defined by 2 points (segments and rectangles).

Parameters
aPositionis the new position of the ending point in graphic units

Definition at line 256 of file ds_data_item.cpp.

257{
258 VECTOR2D pos_mm;
259 pos_mm.x = aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
260 pos_mm.y = aPosition.y / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
261
262 MoveEndPointTo( pos_mm );
263}
void MoveEndPointTo(const VECTOR2D &aPosition)
Move the ending point of the item to a new position.

References DS_DATA_MODEL::GetTheInstance(), DS_DATA_MODEL::m_WSunits2Iu, DS_DATA_ITEM::MoveEndPointTo(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PL_POINT_EDITOR::updateItem().

◆ MoveStartPointTo()

void DS_DATA_ITEM::MoveStartPointTo ( const VECTOR2D aPosition)
inherited

Move the starting point of the item to a new position.

Parameters
aPositionthe new position of the starting point, in mm.

Definition at line 171 of file ds_data_item.cpp.

172{
174 VECTOR2D position;
175
176 // Calculate the position of the starting point
177 // relative to the reference corner
178 // aPosition is the position relative to the right top paper corner
179 switch( m_Pos.m_Anchor )
180 {
181 case RB_CORNER:
182 position = model.m_RB_Corner - aPosition;
183 break;
184
185 case RT_CORNER:
186 position.x = model.m_RB_Corner.x - aPosition.x;
187 position.y = aPosition.y - model.m_LT_Corner.y;
188 break;
189
190 case LB_CORNER:
191 position.x = aPosition.x - model.m_LT_Corner.x;
192 position.y = model.m_RB_Corner.y - aPosition.y;
193 break;
194
195 case LT_CORNER:
196 position = aPosition - model.m_LT_Corner;
197 break;
198 }
199
200 m_Pos.m_Pos = position;
201}

References DS_DATA_MODEL::GetTheInstance(), LB_CORNER, LT_CORNER, POINT_COORD::m_Anchor, DS_DATA_MODEL::m_LT_Corner, POINT_COORD::m_Pos, DS_DATA_ITEM::m_Pos, DS_DATA_MODEL::m_RB_Corner, RB_CORNER, RT_CORNER, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DS_DATA_ITEM::MoveStartPointToUi(), and DS_DATA_ITEM::MoveTo().

◆ MoveStartPointToUi()

void DS_DATA_ITEM::MoveStartPointToUi ( const VECTOR2I aPosition)
inherited

Move the starting point of the item to a new position.

Parameters
aPositionis the new position of item in graphic units.

Definition at line 204 of file ds_data_item.cpp.

205{
208
209 MoveStartPointTo( pos_mm );
210}
void MoveStartPointTo(const VECTOR2D &aPosition)
Move the starting point of the item to a new position.

References DS_DATA_MODEL::GetTheInstance(), DS_DATA_MODEL::m_WSunits2Iu, DS_DATA_ITEM::MoveStartPointTo(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PL_DRAWING_TOOLS::PlaceItem(), and PL_POINT_EDITOR::updateItem().

◆ MoveTo()

void DS_DATA_ITEM::MoveTo ( const VECTOR2D aPosition)
inherited

Move item to a new position.

Parameters
aPositionthe new position of item, in mm.

Definition at line 155 of file ds_data_item.cpp.

156{
157 VECTOR2D vector = aPosition - GetStartPos();
158 VECTOR2D endpos = vector + GetEndPos();
159
160 MoveStartPointTo( aPosition );
161 MoveEndPointTo( endpos );
162
163 for( DS_DRAW_ITEM_BASE* drawItem : m_drawItems )
164 {
165 drawItem->SetPosition( GetStartPosUi( drawItem->GetIndexInPeer() ) );
166 drawItem->SetEnd( GetEndPosUi( drawItem->GetIndexInPeer() ) );
167 }
168}
const VECTOR2I GetStartPosUi(int ii=0) const
const VECTOR2I GetEndPosUi(int ii=0) const
Base class to handle basic graphic items.
Definition: ds_draw_item.h:59

References DS_DATA_ITEM::GetEndPos(), DS_DATA_ITEM::GetEndPosUi(), DS_DATA_ITEM::GetStartPos(), DS_DATA_ITEM::GetStartPosUi(), DS_DATA_ITEM::m_drawItems, DS_DATA_ITEM::MoveEndPointTo(), and DS_DATA_ITEM::MoveStartPointTo().

Referenced by DS_DATA_ITEM::MoveToUi().

◆ MoveToUi()

void DS_DATA_ITEM::MoveToUi ( const VECTOR2I aPosition)
inherited

Move item to a new position.

Parameters
aPositionthe new position of the starting point in graphic units.

Definition at line 145 of file ds_data_item.cpp.

146{
147 VECTOR2D pos_mm;
148 pos_mm.x = aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
149 pos_mm.y = aPosition.y / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
150
151 MoveTo( pos_mm );
152}
void MoveTo(const VECTOR2D &aPosition)
Move item to a new position.

References DS_DATA_MODEL::GetTheInstance(), DS_DATA_MODEL::m_WSunits2Iu, DS_DATA_ITEM::MoveTo(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PL_DRAWING_TOOLS::DrawShape(), and PL_EDIT_TOOL::moveItem().

◆ ReplaceAntiSlashSequence()

bool DS_DATA_ITEM_TEXT::ReplaceAntiSlashSequence ( )

Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\' inside m_FullText.

Returns
true if the EOL symbol is found or is inserted (multiline text).

Definition at line 640 of file ds_data_item.cpp.

641{
642 bool multiline = false;
643
644 for( unsigned ii = 0; ii < m_FullText.Len(); ii++ )
645 {
646 if( m_FullText[ii] == '\n' )
647 multiline = true;
648
649 else if( m_FullText[ii] == '\\' )
650 {
651 if( ++ii >= m_FullText.Len() )
652 break;
653
654 if( m_FullText[ii] == '\\' )
655 {
656 // a double \\ sequence is replaced by a single \ char
657 m_FullText.Remove(ii, 1);
658 ii--;
659 }
660 else if( m_FullText[ii] == 'n' )
661 {
662 // Replace the "\n" sequence by a EOL char
663 multiline = true;
664 m_FullText[ii] = '\n';
665 m_FullText.Remove(ii-1, 1);
666 ii--;
667 }
668 }
669 }
670
671 return multiline;
672}

References m_FullText.

Referenced by PROPERTIES_FRAME::CopyPrmsFromItemToPanel(), and SyncDrawItems().

◆ SetConstrainedTextSize()

void DS_DATA_ITEM_TEXT::SetConstrainedTextSize ( )

Calculate m_ConstrainedTextSize from m_TextSize to keep the X size and the full Y size of the text smaller than m_BoundingBoxSize if m_BoundingBoxSize.x or m_BoundingBoxSize.y > 0 if m_BoundingBoxSize.x or m_BoundingBoxSize.y == 0 the corresponding text size is not constrained.

Definition at line 675 of file ds_data_item.cpp.

676{
678
679 if( m_ConstrainedTextSize.x == 0 )
681
682 if( m_ConstrainedTextSize.y == 0 )
684
686 {
687 // to know the X and Y size of the line, we should use
688 // EDA_TEXT::GetTextBox()
689 // but this function uses integers
690 // So, to avoid truncations with our unit in mm, use microns.
691 VECTOR2I size_micron;
692 #define FSCALE 1000.0
693 int linewidth = 0;
694 size_micron.x = KiROUND( m_ConstrainedTextSize.x * FSCALE );
695 size_micron.y = KiROUND( m_ConstrainedTextSize.y * FSCALE );
696 DS_DRAW_ITEM_TEXT dummy( this, 0, m_FullText, VECTOR2I( 0, 0 ), size_micron, linewidth,
698 dummy.SetMultilineAllowed( true );
699 dummy.SetHorizJustify( m_Hjustify ) ;
700 dummy.SetVertJustify( m_Vjustify );
701 dummy.SetTextAngle( EDA_ANGLE( m_Orient, DEGREES_T ) );
702
703 BOX2I rect = dummy.GetTextBox();
704 VECTOR2D size;
705 size.x = rect.GetWidth() / FSCALE;
706 size.y = rect.GetHeight() / FSCALE;
707
708 if( m_BoundingBoxSize.x && size.x > m_BoundingBoxSize.x )
710
711 if( m_BoundingBoxSize.y && size.y > m_BoundingBoxSize.y )
713 }
714}
coord_type GetHeight() const
Definition: box2.h:188
coord_type GetWidth() const
Definition: box2.h:187
VECTOR2D m_BoundingBoxSize
Definition: ds_data_item.h:345
VECTOR2D m_ConstrainedTextSize
Definition: ds_data_item.h:348
VECTOR2D m_DefaultTextSize
A graphic text.
Definition: ds_draw_item.h:303
#define FSCALE
@ DEGREES_T
Definition: eda_angle.h:31
std::vector< FAB_LAYER_COLOR > dummy

References DEGREES_T, dummy, FSCALE, BOX2< Vec >::GetHeight(), DS_DATA_MODEL::GetTheInstance(), BOX2< Vec >::GetWidth(), KiROUND(), m_Bold, m_BoundingBoxSize, m_ConstrainedTextSize, DS_DATA_MODEL::m_DefaultTextSize, m_Font, m_FullText, m_Hjustify, m_Italic, m_Orient, m_TextColor, m_TextSize, m_Vjustify, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SyncDrawItems().

◆ SetEnd()

void DS_DATA_ITEM::SetEnd ( double  aPosx,
double  aPosy,
enum CORNER_ANCHOR  aAnchor = RB_CORNER 
)
inlineinherited

Definition at line 121 of file ds_data_item.h.

122 {
123 m_End.m_Pos.x = aPosx;
124 m_End.m_Pos.y = aPosy;
125 m_End.m_Anchor = aAnchor;
126 }

References POINT_COORD::m_Anchor, DS_DATA_ITEM::m_End, POINT_COORD::m_Pos, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ SetPage1Option()

void DS_DATA_ITEM::SetPage1Option ( PAGE_OPTION  aChoice)
inlineinherited

◆ SetStart()

void DS_DATA_ITEM::SetStart ( double  aPosx,
double  aPosy,
enum CORNER_ANCHOR  aAnchor = RB_CORNER 
)
inlineinherited

Definition at line 114 of file ds_data_item.h.

115 {
116 m_Pos.m_Pos.x = aPosx;
117 m_Pos.m_Pos.y = aPosy;
118 m_Pos.m_Anchor = aAnchor;
119 }

References POINT_COORD::m_Anchor, POINT_COORD::m_Pos, DS_DATA_ITEM::m_Pos, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ SyncDrawItems()

void DS_DATA_ITEM_TEXT::SyncDrawItems ( DS_DRAW_ITEM_LIST aCollector,
KIGFX::VIEW aView 
)
overridevirtual

Reimplemented from DS_DATA_ITEM.

Definition at line 536 of file ds_data_item.cpp.

537{
538 int pensize = GetPenSizeUi();
539 bool multilines = false;
540
541 if( DS_DATA_MODEL::GetTheInstance().m_EditMode )
542 {
544 }
545 else
546 {
547 m_FullText = aCollector ? aCollector->BuildFullText( m_TextBase ) : wxString();
548 multilines = ReplaceAntiSlashSequence();
549 }
550
551 if( pensize == 0 )
552 pensize = aCollector ? aCollector->GetDefaultPenSize() : 1;
553
555 VECTOR2I textsize;
556
559
560 if( m_Bold )
561 pensize = GetPenSizeForBold( std::min( textsize.x, textsize.y ) );
562
563 std::map<size_t, EDA_ITEM_FLAGS> itemFlags;
564 DS_DRAW_ITEM_TEXT* text = nullptr;
565
566 for( size_t i = 0; i < m_drawItems.size(); ++i )
567 {
569 itemFlags[ i ] = text->GetFlags();
570
571 if( aCollector )
572 aCollector->Remove( text );
573
574 if( aView )
575 aView->Remove( text );
576
577 delete text;
578 }
579
580 m_drawItems.clear();
581
582 for( int j = 0; j < m_RepeatCount; ++j )
583 {
584 if( j > 0 && !IsInsidePage( j ) )
585 continue;
586
587 text = new DS_DRAW_ITEM_TEXT( this, j, m_FullText, GetStartPosUi( j ), textsize, pensize,
589 text->SetFlags( itemFlags[ j ] );
590 m_drawItems.push_back( text );
591
592 if( aCollector )
593 aCollector->Append( text );
594
595 if( aView )
596 aView->Add( text );
597
598 text->SetHorizJustify( m_Hjustify ) ;
599 text->SetVertJustify( m_Vjustify );
600 text->SetTextAngle( EDA_ANGLE( m_Orient, DEGREES_T ) );
601 text->SetMultilineAllowed( multilines );
602
603 // Increment label for the next text (has no meaning for multiline texts)
604 if( m_RepeatCount > 1 && !multilines )
605 IncrementLabel(( j + 1 ) * m_IncrementLabel );
606 }
607}
bool ReplaceAntiSlashSequence()
Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\' inside m_FullText.
virtual int GetPenSizeUi() override
void IncrementLabel(int aIncr)
Try to build text which is an increment of m_TextBase has meaning only if m_TextBase is a basic text ...
void SetConstrainedTextSize()
Calculate m_ConstrainedTextSize from m_TextSize to keep the X size and the full Y size of the text sm...
virtual bool IsInsidePage(int ii) const
int GetDefaultPenSize() const
Definition: ds_draw_item.h:445
wxString BuildFullText(const wxString &aTextbase)
Definition: ds_painter.cpp:113
void Append(DS_DRAW_ITEM_BASE *aItem)
Definition: ds_draw_item.h:472
void Remove(DS_DRAW_ITEM_BASE *aItem)
Definition: ds_draw_item.h:477
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:316
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:349
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40

References KIGFX::VIEW::Add(), DS_DRAW_ITEM_LIST::Append(), DS_DRAW_ITEM_LIST::BuildFullText(), DEGREES_T, DS_DRAW_ITEM_LIST::GetDefaultPenSize(), GetPenSizeForBold(), GetPenSizeUi(), DS_DATA_ITEM::GetStartPosUi(), DS_DATA_MODEL::GetTheInstance(), IncrementLabel(), DS_DATA_ITEM::IsInsidePage(), KiROUND(), m_Bold, m_ConstrainedTextSize, DS_DATA_ITEM::m_drawItems, m_Font, m_FullText, m_Hjustify, DS_DATA_ITEM::m_IncrementLabel, m_Italic, m_Orient, DS_DATA_ITEM::m_RepeatCount, m_TextBase, m_TextColor, m_Vjustify, DS_DATA_MODEL::m_WSunits2Iu, DS_DRAW_ITEM_LIST::Remove(), KIGFX::VIEW::Remove(), ReplaceAntiSlashSequence(), SetConstrainedTextSize(), text, VECTOR2< T >::x, and VECTOR2< T >::y.

Member Data Documentation

◆ m_Bold

◆ m_BoundingBoxSize

◆ m_ConstrainedTextSize

VECTOR2D DS_DATA_ITEM_TEXT::m_ConstrainedTextSize

Definition at line 348 of file ds_data_item.h.

Referenced by SetConstrainedTextSize(), and SyncDrawItems().

◆ m_drawItems

◆ m_End

◆ m_Font

◆ m_FullText

wxString DS_DATA_ITEM_TEXT::m_FullText

◆ m_Hjustify

◆ m_IncrementLabel

◆ m_IncrementVector

◆ m_Info

◆ m_Italic

◆ m_LineWidth

◆ m_Name

◆ m_Orient

◆ m_pageOption

PAGE_OPTION DS_DATA_ITEM::m_pageOption
protectedinherited

◆ m_Pos

◆ m_RepeatCount

◆ m_TextBase

◆ m_TextColor

◆ m_TextSize

◆ m_type

DS_ITEM_TYPE DS_DATA_ITEM::m_type
protectedinherited

◆ m_Vjustify


The documentation for this class was generated from the following files: