2013-05-24 08:59:40 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2013 Jean-Pierre Charras <jp.charras at wanadoo.fr>.
|
2023-06-12 21:33:55 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-05-24 08:59:40 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2013-06-07 09:49:36 +00:00
|
|
|
|
|
|
|
/*
|
2021-02-22 23:47:17 +00:00
|
|
|
* the class DS_DATA_ITEM (and derived) defines
|
2021-05-30 22:56:24 +00:00
|
|
|
* a basic shape of a drawing sheet (frame references and title block)
|
2013-06-07 09:49:36 +00:00
|
|
|
* Basic shapes are line, rect and texts
|
2021-02-22 23:47:17 +00:00
|
|
|
* the DS_DATA_ITEM coordinates units is the mm, and are relative to
|
2013-06-07 09:49:36 +00:00
|
|
|
* one of 4 page corners.
|
|
|
|
*
|
|
|
|
* These items cannot be drawn or plot "as this". they should be converted
|
2021-02-22 23:47:17 +00:00
|
|
|
* to a "draw list" (DS_DRAW_ITEM_BASE and derived items)
|
2013-06-07 09:49:36 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
* The list of these items is stored in a DS_DATA_MODEL instance.
|
2013-06-07 09:49:36 +00:00
|
|
|
*
|
|
|
|
* When building the draw list:
|
2021-02-22 23:47:17 +00:00
|
|
|
* the DS_DATA_MODEL is used to create a DS_DRAW_ITEM_LIST
|
2013-06-07 09:49:36 +00:00
|
|
|
* coordinates are converted to draw/plot coordinates.
|
|
|
|
* texts are expanded if they contain format symbols.
|
|
|
|
* Items with m_RepeatCount > 1 are created m_RepeatCount times
|
|
|
|
*
|
2021-02-22 23:47:17 +00:00
|
|
|
* the DS_DATA_MODEL is created only once.
|
2021-05-30 22:56:24 +00:00
|
|
|
* the DS_DRAW_ITEM_LIST is created each time the drawing sheet is plotted/drawn
|
2013-06-07 09:49:36 +00:00
|
|
|
*
|
2021-02-22 23:47:17 +00:00
|
|
|
* the DS_DATA_MODEL instance is created from a S expression which
|
2021-05-30 22:56:24 +00:00
|
|
|
* describes the drawing sheet (can be the default drawing sheet or a custom file).
|
2013-06-07 09:49:36 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
#include <gr_text.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2019-05-25 13:56:52 +00:00
|
|
|
#include <view/view.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <title_block.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
|
|
|
#include <drawing_sheet/ds_data_item.h>
|
|
|
|
#include <drawing_sheet/ds_draw_item.h>
|
|
|
|
#include <drawing_sheet/ds_painter.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
using KIGFX::COLOR4D;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM::DS_DATA_ITEM( DS_ITEM_TYPE aType )
|
2013-06-08 18:19:09 +00:00
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
m_pageOption = ALL_PAGES;
|
2013-07-19 18:27:22 +00:00
|
|
|
m_type = aType;
|
|
|
|
m_RepeatCount = 1;
|
|
|
|
m_IncrementLabel = 1;
|
|
|
|
m_LineWidth = 0;
|
2013-06-08 18:19:09 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM::~DS_DATA_ITEM()
|
2020-07-04 03:06:37 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* item : m_drawItems )
|
2020-07-04 03:06:37 +00:00
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_ITEM::SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2023-09-30 20:00:11 +00:00
|
|
|
int pensize = GetPenSizeIU();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if( pensize == 0 )
|
|
|
|
pensize = aCollector ? aCollector->GetDefaultPenSize() : 0;
|
|
|
|
|
2021-06-08 03:06:11 +00:00
|
|
|
std::map<size_t, EDA_ITEM_FLAGS> itemFlags;
|
2022-08-03 09:10:23 +00:00
|
|
|
DS_DRAW_ITEM_BASE* item = nullptr;
|
2019-05-24 10:11:18 +00:00
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
for( size_t i = 0; i < m_drawItems.size(); ++i )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2019-05-26 18:35:20 +00:00
|
|
|
item = m_drawItems[ i ];
|
|
|
|
itemFlags[ i ] = item->GetFlags();
|
2019-05-24 10:11:18 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
if( aCollector )
|
|
|
|
aCollector->Remove( item );
|
|
|
|
|
|
|
|
if( aView )
|
|
|
|
aView->Remove( item );
|
|
|
|
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_drawItems.clear();
|
|
|
|
|
2021-06-09 09:22:43 +00:00
|
|
|
for( int j = 0; j < m_RepeatCount; j++ )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2023-05-27 15:30:12 +00:00
|
|
|
if( j > 0 && !IsInsidePage( j ) )
|
2019-05-20 10:23:32 +00:00
|
|
|
continue;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
if( m_type == DS_SEGMENT )
|
2023-05-27 15:30:12 +00:00
|
|
|
item = new DS_DRAW_ITEM_LINE( this, j, GetStartPosIU( j ), GetEndPosIU( j ), pensize );
|
2021-02-22 23:47:17 +00:00
|
|
|
else if( m_type == DS_RECT )
|
2023-05-27 15:30:12 +00:00
|
|
|
item = new DS_DRAW_ITEM_RECT( this, j, GetStartPosIU( j ), GetEndPosIU( j ), pensize );
|
2020-01-11 00:09:08 +00:00
|
|
|
else
|
|
|
|
{
|
2023-01-22 14:41:33 +00:00
|
|
|
wxFAIL_MSG( wxS( "Unknown drawing sheet item type" ) );
|
2020-01-11 00:09:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
item->SetFlags( itemFlags[ j ] );
|
2019-05-24 10:11:18 +00:00
|
|
|
m_drawItems.push_back( item );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-05-24 10:11:18 +00:00
|
|
|
if( aCollector )
|
|
|
|
aCollector->Append( item );
|
|
|
|
|
|
|
|
if( aView )
|
|
|
|
aView->Add( item );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-30 20:00:11 +00:00
|
|
|
int DS_DATA_ITEM::GetPenSizeIU()
|
2019-05-25 13:56:52 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2019-05-25 13:56:52 +00:00
|
|
|
|
|
|
|
if( m_LineWidth != 0 )
|
|
|
|
return KiROUND( m_LineWidth * model.m_WSunits2Iu );
|
|
|
|
else
|
|
|
|
return KiROUND( model.m_DefaultLineWidth * model.m_WSunits2Iu );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-30 20:00:11 +00:00
|
|
|
void DS_DATA_ITEM::MoveToIU( const VECTOR2I& aPosition )
|
2013-06-08 18:19:09 +00:00
|
|
|
{
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D pos_mm;
|
2021-02-22 23:47:17 +00:00
|
|
|
pos_mm.x = aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
|
|
|
|
pos_mm.y = aPosition.y / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
|
2013-06-08 18:19:09 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
MoveTo( pos_mm );
|
2013-06-08 18:19:09 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-01-19 23:31:07 +00:00
|
|
|
void DS_DATA_ITEM::MoveTo( const VECTOR2D& aPosition )
|
2013-06-08 18:19:09 +00:00
|
|
|
{
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D vector = aPosition - GetStartPos();
|
|
|
|
VECTOR2D endpos = vector + GetEndPos();
|
2013-06-08 18:19:09 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
MoveStartPointTo( aPosition );
|
|
|
|
MoveEndPointTo( endpos );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* drawItem : m_drawItems )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2023-05-27 15:30:12 +00:00
|
|
|
drawItem->SetPosition( GetStartPosIU( drawItem->GetIndexInPeer() ) );
|
|
|
|
drawItem->SetEnd( GetEndPosIU( drawItem->GetIndexInPeer() ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
2013-06-08 18:19:09 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-01-19 23:31:07 +00:00
|
|
|
void DS_DATA_ITEM::MoveStartPointTo( const VECTOR2D& aPosition )
|
2013-06-08 18:19:09 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D position;
|
2013-06-08 18:19:09 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
// Calculate the position of the starting point
|
|
|
|
// relative to the reference corner
|
|
|
|
// aPosition is the position relative to the right top paper corner
|
|
|
|
switch( m_Pos.m_Anchor )
|
|
|
|
{
|
2016-07-11 19:48:46 +00:00
|
|
|
case RB_CORNER:
|
2019-05-25 13:56:52 +00:00
|
|
|
position = model.m_RB_Corner - aPosition;
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RT_CORNER:
|
2019-05-25 13:56:52 +00:00
|
|
|
position.x = model.m_RB_Corner.x - aPosition.x;
|
|
|
|
position.y = aPosition.y - model.m_LT_Corner.y;
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LB_CORNER:
|
2019-05-25 13:56:52 +00:00
|
|
|
position.x = aPosition.x - model.m_LT_Corner.x;
|
|
|
|
position.y = model.m_RB_Corner.y - aPosition.y;
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_CORNER:
|
2019-05-25 13:56:52 +00:00
|
|
|
position = aPosition - model.m_LT_Corner;
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
m_Pos.m_Pos = position;
|
2013-06-05 12:03:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2023-09-30 20:00:11 +00:00
|
|
|
void DS_DATA_ITEM::MoveStartPointToIU( const VECTOR2I& aPosition )
|
2013-05-24 08:59:40 +00:00
|
|
|
{
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D pos_mm( aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu,
|
|
|
|
aPosition.y / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu );
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
MoveStartPointTo( pos_mm );
|
2013-06-05 12:03:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-01-19 23:31:07 +00:00
|
|
|
void DS_DATA_ITEM::MoveEndPointTo( const VECTOR2D& aPosition )
|
2013-05-24 08:59:40 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D position;
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
// Calculate the position of the starting point
|
|
|
|
// relative to the reference corner
|
|
|
|
// aPosition is the position relative to the right top paper corner
|
|
|
|
switch( m_End.m_Anchor )
|
2013-06-05 12:03:16 +00:00
|
|
|
{
|
2016-07-11 19:48:46 +00:00
|
|
|
case RB_CORNER:
|
2019-05-25 13:56:52 +00:00
|
|
|
position = model.m_RB_Corner - aPosition;
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RT_CORNER:
|
2019-05-25 13:56:52 +00:00
|
|
|
position.x = model.m_RB_Corner.x - aPosition.x;
|
|
|
|
position.y = aPosition.y - model.m_LT_Corner.y;
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LB_CORNER:
|
2019-05-25 13:56:52 +00:00
|
|
|
position.x = aPosition.x - model.m_LT_Corner.x;
|
|
|
|
position.y = model.m_RB_Corner.y - aPosition.y;
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_CORNER:
|
2019-05-25 13:56:52 +00:00
|
|
|
position = aPosition - model.m_LT_Corner;
|
2016-07-11 19:48:46 +00:00
|
|
|
break;
|
2013-06-05 12:03:16 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
// Modify m_End only for items having 2 coordinates
|
|
|
|
switch( GetType() )
|
2013-06-05 12:03:16 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
case DS_SEGMENT:
|
|
|
|
case DS_RECT:
|
2016-07-11 19:48:46 +00:00
|
|
|
m_End.m_Pos = position;
|
|
|
|
break;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
2013-06-05 12:03:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2023-09-30 20:00:11 +00:00
|
|
|
void DS_DATA_ITEM::MoveEndPointToIU( const VECTOR2I& aPosition )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D pos_mm;
|
2021-02-22 23:47:17 +00:00
|
|
|
pos_mm.x = aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
|
|
|
|
pos_mm.y = aPosition.y / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
MoveEndPointTo( pos_mm );
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-01-19 23:31:07 +00:00
|
|
|
const VECTOR2D DS_DATA_ITEM::GetStartPos( int ii ) const
|
2013-05-24 08:59:40 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D pos( m_Pos.m_Pos.x + ( m_IncrementVector.x * ii ),
|
2019-05-25 13:56:52 +00:00
|
|
|
m_Pos.m_Pos.y + ( m_IncrementVector.y * ii ) );
|
2013-06-05 12:03:16 +00:00
|
|
|
|
|
|
|
switch( m_Pos.m_Anchor )
|
|
|
|
{
|
|
|
|
case RB_CORNER: // right bottom corner
|
2019-05-25 13:56:52 +00:00
|
|
|
pos = model.m_RB_Corner - pos;
|
2013-06-05 12:03:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RT_CORNER: // right top corner
|
2019-05-25 13:56:52 +00:00
|
|
|
pos.x = model.m_RB_Corner.x - pos.x;
|
|
|
|
pos.y = model.m_LT_Corner.y + pos.y;
|
2013-06-05 12:03:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LB_CORNER: // left bottom corner
|
2019-05-25 13:56:52 +00:00
|
|
|
pos.x = model.m_LT_Corner.x + pos.x;
|
|
|
|
pos.y = model.m_RB_Corner.y - pos.y;
|
2013-06-05 12:03:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_CORNER: // left top corner
|
2019-05-25 13:56:52 +00:00
|
|
|
pos = model.m_LT_Corner + pos;
|
2013-06-05 12:03:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2023-05-27 15:30:12 +00:00
|
|
|
const VECTOR2I DS_DATA_ITEM::GetStartPosIU( int ii ) const
|
2013-05-24 08:59:40 +00:00
|
|
|
{
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D pos = GetStartPos( ii ) * DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
|
2022-01-01 06:04:08 +00:00
|
|
|
return VECTOR2I( KiROUND( pos.x ), KiROUND( pos.y ) );
|
2013-06-05 12:03:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-01-19 23:31:07 +00:00
|
|
|
const VECTOR2D DS_DATA_ITEM::GetEndPos( int ii ) const
|
2013-05-24 08:59:40 +00:00
|
|
|
{
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D pos( m_End.m_Pos.x + ( m_IncrementVector.x * ii ),
|
|
|
|
m_End.m_Pos.y + ( m_IncrementVector.y * ii ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2013-06-05 12:03:16 +00:00
|
|
|
switch( m_End.m_Anchor )
|
|
|
|
{
|
2019-05-25 13:56:52 +00:00
|
|
|
case RB_CORNER: // right bottom corner
|
2021-02-22 23:47:17 +00:00
|
|
|
pos = DS_DATA_MODEL::GetTheInstance().m_RB_Corner - pos;
|
2019-05-25 13:56:52 +00:00
|
|
|
break;
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2019-05-25 13:56:52 +00:00
|
|
|
case RT_CORNER: // right top corner
|
2021-02-22 23:47:17 +00:00
|
|
|
pos.x = DS_DATA_MODEL::GetTheInstance().m_RB_Corner.x - pos.x;
|
|
|
|
pos.y = DS_DATA_MODEL::GetTheInstance().m_LT_Corner.y + pos.y;
|
2019-05-25 13:56:52 +00:00
|
|
|
break;
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2019-05-25 13:56:52 +00:00
|
|
|
case LB_CORNER: // left bottom corner
|
2021-02-22 23:47:17 +00:00
|
|
|
pos.x = DS_DATA_MODEL::GetTheInstance().m_LT_Corner.x + pos.x;
|
|
|
|
pos.y = DS_DATA_MODEL::GetTheInstance().m_RB_Corner.y - pos.y;
|
2019-05-25 13:56:52 +00:00
|
|
|
break;
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2019-05-25 13:56:52 +00:00
|
|
|
case LT_CORNER: // left top corner
|
2021-02-22 23:47:17 +00:00
|
|
|
pos = DS_DATA_MODEL::GetTheInstance().m_LT_Corner + pos;
|
2019-05-25 13:56:52 +00:00
|
|
|
break;
|
2013-06-05 12:03:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2023-05-27 15:30:12 +00:00
|
|
|
const VECTOR2I DS_DATA_ITEM::GetEndPosIU( int ii ) const
|
2013-05-24 08:59:40 +00:00
|
|
|
{
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D pos = GetEndPos( ii );
|
2021-02-22 23:47:17 +00:00
|
|
|
pos = pos * DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
|
2022-01-01 06:04:08 +00:00
|
|
|
return VECTOR2I( KiROUND( pos.x ), KiROUND( pos.y ) );
|
2013-06-05 12:03:16 +00:00
|
|
|
}
|
2013-05-24 08:59:40 +00:00
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
bool DS_DATA_ITEM::IsInsidePage( int ii ) const
|
2013-05-24 08:59:40 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2019-05-25 13:56:52 +00:00
|
|
|
|
2023-05-27 15:30:12 +00:00
|
|
|
for( const VECTOR2D& pos : { GetStartPos( ii ), GetEndPos( ii ) } )
|
2013-07-24 15:11:35 +00:00
|
|
|
{
|
2019-05-25 13:56:52 +00:00
|
|
|
if( model.m_RB_Corner.x < pos.x || model.m_LT_Corner.x > pos.x )
|
2013-07-24 15:11:35 +00:00
|
|
|
return false;
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2019-05-25 13:56:52 +00:00
|
|
|
if( model.m_RB_Corner.y < pos.y || model.m_LT_Corner.y > pos.y )
|
2013-07-24 15:11:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-06-05 12:03:16 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
const wxString DS_DATA_ITEM::GetClassName() const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
wxString name;
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
switch( GetType() )
|
|
|
|
{
|
2021-03-08 07:54:12 +00:00
|
|
|
case DS_TEXT: name = _( "Text" ); break;
|
|
|
|
case DS_SEGMENT: name = _( "Line" ); break;
|
|
|
|
case DS_RECT: name = _( "Rectangle" ); break;
|
|
|
|
case DS_POLYPOLYGON: name = _( "Imported Shape" ); break;
|
|
|
|
case DS_BITMAP: name = _( "Image" ); break;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
return name;
|
|
|
|
}
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM_POLYGONS::DS_DATA_ITEM_POLYGONS() :
|
|
|
|
DS_DATA_ITEM( DS_POLYPOLYGON )
|
2013-05-24 08:59:40 +00:00
|
|
|
{
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_ITEM_POLYGONS::SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-06-08 03:06:11 +00:00
|
|
|
std::map<int, EDA_ITEM_FLAGS> itemFlags;
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_BASE* item = nullptr;
|
2019-05-24 10:11:18 +00:00
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
for( size_t i = 0; i < m_drawItems.size(); ++i )
|
2019-05-24 10:11:18 +00:00
|
|
|
{
|
2019-05-26 18:35:20 +00:00
|
|
|
item = m_drawItems[ i ];
|
|
|
|
itemFlags[ i ] = item->GetFlags();
|
2019-05-24 10:11:18 +00:00
|
|
|
|
|
|
|
if( aCollector )
|
|
|
|
aCollector->Remove( item );
|
|
|
|
|
|
|
|
if( aView )
|
|
|
|
aView->Remove( item );
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
delete item;
|
2019-05-24 10:11:18 +00:00
|
|
|
}
|
2013-05-25 09:01:44 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
m_drawItems.clear();
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
for( int j = 0; j < m_RepeatCount; j++ )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2023-05-27 15:30:12 +00:00
|
|
|
if( j > 0 && !IsInsidePage( j ) )
|
2019-05-20 10:23:32 +00:00
|
|
|
continue;
|
2013-05-25 09:01:44 +00:00
|
|
|
|
2023-09-30 20:00:11 +00:00
|
|
|
int pensize = GetPenSizeIU();
|
2023-05-27 15:30:12 +00:00
|
|
|
auto poly_shape = new DS_DRAW_ITEM_POLYPOLYGONS( this, j, GetStartPosIU( j ), pensize );
|
2019-06-13 11:23:39 +00:00
|
|
|
poly_shape->SetFlags( itemFlags[ j ] );
|
|
|
|
m_drawItems.push_back( poly_shape );
|
|
|
|
|
|
|
|
// Transfer all outlines (basic polygons)
|
|
|
|
SHAPE_POLY_SET& polygons = poly_shape->GetPolygons();
|
2022-03-14 15:52:12 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
for( int kk = 0; kk < GetPolyCount(); kk++ )
|
|
|
|
{
|
2019-06-13 11:23:39 +00:00
|
|
|
// Create new outline
|
2019-05-20 10:23:32 +00:00
|
|
|
unsigned ist = GetPolyIndexStart( kk );
|
|
|
|
unsigned iend = GetPolyIndexEnd( kk );
|
|
|
|
|
2019-06-13 11:23:39 +00:00
|
|
|
polygons.NewOutline();
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
while( ist <= iend )
|
2023-09-30 20:00:11 +00:00
|
|
|
polygons.Append( GetCornerPositionIU( ist++, j ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
2019-06-13 11:23:39 +00:00
|
|
|
|
|
|
|
if( aCollector )
|
|
|
|
aCollector->Append( poly_shape );
|
|
|
|
|
|
|
|
if( aView )
|
|
|
|
aView->Add( poly_shape );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2023-09-30 20:00:11 +00:00
|
|
|
int DS_DATA_ITEM_POLYGONS::GetPenSizeIU()
|
2019-05-25 13:56:52 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
return KiROUND( m_LineWidth * DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu );
|
2019-05-25 13:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-16 21:15:20 +00:00
|
|
|
const VECTOR2D DS_DATA_ITEM_POLYGONS::GetCornerPosition( unsigned aIdx, int aRepeat ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2022-01-16 21:15:20 +00:00
|
|
|
VECTOR2D pos = m_Corners[aIdx];
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
// Rotation:
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( &pos.x, &pos.y, m_Orient );
|
2013-07-19 18:27:22 +00:00
|
|
|
pos += GetStartPos( aRepeat );
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_ITEM_POLYGONS::SetBoundingBox()
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
if( m_Corners.size() == 0 )
|
2013-05-24 08:59:40 +00:00
|
|
|
{
|
2013-07-19 18:27:22 +00:00
|
|
|
m_minCoord.x = m_maxCoord.x = 0.0;
|
|
|
|
m_minCoord.y = m_maxCoord.y = 0.0;
|
|
|
|
return;
|
|
|
|
}
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2022-01-16 21:15:20 +00:00
|
|
|
VECTOR2I pos;
|
2013-07-19 18:27:22 +00:00
|
|
|
pos = m_Corners[0];
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( &pos.x, &pos.y, m_Orient );
|
2013-07-19 18:27:22 +00:00
|
|
|
m_minCoord = m_maxCoord = pos;
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
for( unsigned ii = 1; ii < m_Corners.size(); ii++ )
|
|
|
|
{
|
|
|
|
pos = m_Corners[ii];
|
2022-01-16 21:15:20 +00:00
|
|
|
RotatePoint( &pos.x, &pos.y, m_Orient );
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
if( m_minCoord.x > pos.x )
|
|
|
|
m_minCoord.x = pos.x;
|
|
|
|
|
|
|
|
if( m_minCoord.y > pos.y )
|
|
|
|
m_minCoord.y = pos.y;
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
if( m_maxCoord.x < pos.x )
|
|
|
|
m_maxCoord.x = pos.x;
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
if( m_maxCoord.y < pos.y )
|
|
|
|
m_maxCoord.y = pos.y;
|
|
|
|
}
|
|
|
|
}
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
bool DS_DATA_ITEM_POLYGONS::IsInsidePage( int ii ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2019-05-25 13:56:52 +00:00
|
|
|
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D pos = GetStartPos( ii );
|
2013-07-19 18:27:22 +00:00
|
|
|
pos += m_minCoord; // left top pos of bounding box
|
2013-06-08 18:19:09 +00:00
|
|
|
|
2019-05-25 13:56:52 +00:00
|
|
|
if( model.m_LT_Corner.x > pos.x || model.m_LT_Corner.y > pos.y )
|
2013-07-19 18:27:22 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
pos = GetStartPos( ii );
|
2021-04-05 13:24:57 +00:00
|
|
|
pos += m_maxCoord; // right bottom pos of bounding box
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2019-05-25 13:56:52 +00:00
|
|
|
if( model.m_RB_Corner.x < pos.x || model.m_RB_Corner.y < pos.y )
|
2013-07-19 18:27:22 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2023-09-30 20:00:11 +00:00
|
|
|
const VECTOR2I DS_DATA_ITEM_POLYGONS::GetCornerPositionIU( unsigned aIdx, int aRepeat ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D pos = GetCornerPosition( aIdx, aRepeat );
|
2021-02-22 23:47:17 +00:00
|
|
|
pos = pos * DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
|
2022-01-01 06:04:08 +00:00
|
|
|
return VECTOR2I( int( pos.x ), int( pos.y ) );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM_TEXT::DS_DATA_ITEM_TEXT( const wxString& aTextBase ) :
|
|
|
|
DS_DATA_ITEM( DS_TEXT )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
m_TextBase = aTextBase;
|
|
|
|
m_IncrementLabel = 1;
|
2021-12-28 22:13:54 +00:00
|
|
|
m_Hjustify = GR_TEXT_H_ALIGN_LEFT;
|
|
|
|
m_Vjustify = GR_TEXT_V_ALIGN_CENTER;
|
2019-05-20 10:23:32 +00:00
|
|
|
m_Italic = false;
|
|
|
|
m_Bold = false;
|
2022-02-28 18:02:00 +00:00
|
|
|
m_Font = nullptr;
|
2022-03-31 18:43:08 +00:00
|
|
|
m_TextColor = COLOR4D::UNSPECIFIED;
|
2013-07-19 18:27:22 +00:00
|
|
|
m_Orient = 0.0;
|
2019-05-20 10:23:32 +00:00
|
|
|
m_LineWidth = 0.0; // 0 means use default value
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_ITEM_TEXT::SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2023-09-30 20:00:11 +00:00
|
|
|
int pensize = GetPenSizeIU();
|
2019-05-20 10:23:32 +00:00
|
|
|
bool multilines = false;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
if( DS_DATA_MODEL::GetTheInstance().m_EditMode )
|
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
m_FullText = m_TextBase;
|
2021-02-22 23:47:17 +00:00
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
else
|
|
|
|
{
|
2019-05-24 19:12:10 +00:00
|
|
|
m_FullText = aCollector ? aCollector->BuildFullText( m_TextBase ) : wxString();
|
2019-05-20 10:23:32 +00:00
|
|
|
multilines = ReplaceAntiSlashSequence();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pensize == 0 )
|
|
|
|
pensize = aCollector ? aCollector->GetDefaultPenSize() : 1;
|
|
|
|
|
|
|
|
SetConstrainedTextSize();
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I textsize;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
textsize.x = KiROUND( m_ConstrainedTextSize.x * DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu );
|
|
|
|
textsize.y = KiROUND( m_ConstrainedTextSize.y * DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if( m_Bold )
|
|
|
|
pensize = GetPenSizeForBold( std::min( textsize.x, textsize.y ) );
|
|
|
|
|
2021-06-08 03:06:11 +00:00
|
|
|
std::map<size_t, EDA_ITEM_FLAGS> itemFlags;
|
2022-02-28 18:02:00 +00:00
|
|
|
DS_DRAW_ITEM_TEXT* text = nullptr;
|
2019-05-24 10:11:18 +00:00
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
for( size_t i = 0; i < m_drawItems.size(); ++i )
|
2019-05-24 10:11:18 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
text = (DS_DRAW_ITEM_TEXT*) m_drawItems[ i ];
|
2019-05-26 18:35:20 +00:00
|
|
|
itemFlags[ i ] = text->GetFlags();
|
2019-05-24 10:11:18 +00:00
|
|
|
|
|
|
|
if( aCollector )
|
|
|
|
aCollector->Remove( text );
|
|
|
|
|
|
|
|
if( aView )
|
|
|
|
aView->Remove( text );
|
|
|
|
|
|
|
|
delete text;
|
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
m_drawItems.clear();
|
|
|
|
|
2021-06-09 09:22:43 +00:00
|
|
|
for( int j = 0; j < m_RepeatCount; ++j )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2019-05-26 18:35:20 +00:00
|
|
|
if( j > 0 && !IsInsidePage( j ) )
|
2019-05-20 10:23:32 +00:00
|
|
|
continue;
|
|
|
|
|
2023-06-16 14:55:17 +00:00
|
|
|
EDA_IU_SCALE iuscale = aCollector ? aCollector->GetIuScale()
|
|
|
|
: DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
|
|
|
|
|
2023-09-30 20:00:11 +00:00
|
|
|
text = new DS_DRAW_ITEM_TEXT( iuscale, this, j, m_FullText, GetStartPosIU( j ), textsize,
|
|
|
|
pensize, m_Font, m_Italic, m_Bold, m_TextColor );
|
2023-06-12 21:33:55 +00:00
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
text->SetFlags( itemFlags[ j ] );
|
2019-05-20 10:23:32 +00:00
|
|
|
m_drawItems.push_back( text );
|
|
|
|
|
|
|
|
if( aCollector )
|
|
|
|
aCollector->Append( text );
|
|
|
|
|
|
|
|
if( aView )
|
|
|
|
aView->Add( text );
|
|
|
|
|
2023-05-27 15:30:12 +00:00
|
|
|
text->SetHorizJustify( m_Hjustify );
|
2019-05-20 10:23:32 +00:00
|
|
|
text->SetVertJustify( m_Vjustify );
|
2022-01-13 23:30:52 +00:00
|
|
|
text->SetTextAngle( EDA_ANGLE( m_Orient, DEGREES_T ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
text->SetMultilineAllowed( multilines );
|
|
|
|
|
|
|
|
// Increment label for the next text (has no meaning for multiline texts)
|
|
|
|
if( m_RepeatCount > 1 && !multilines )
|
2023-05-27 15:30:12 +00:00
|
|
|
IncrementLabel( ( j + 1 ) * m_IncrementLabel );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2023-09-30 20:00:11 +00:00
|
|
|
int DS_DATA_ITEM_TEXT::GetPenSizeIU()
|
2019-05-25 13:56:52 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2019-05-25 13:56:52 +00:00
|
|
|
|
|
|
|
if( m_LineWidth != 0 )
|
|
|
|
return KiROUND( m_LineWidth * model.m_WSunits2Iu );
|
|
|
|
else
|
|
|
|
return KiROUND( model.m_DefaultTextThickness * model.m_WSunits2Iu );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_ITEM_TEXT::IncrementLabel( int aIncr )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
int last = m_TextBase.Len() -1;
|
|
|
|
|
|
|
|
wxChar lbchar = m_TextBase[last];
|
|
|
|
m_FullText = m_TextBase;
|
|
|
|
m_FullText.RemoveLast();
|
|
|
|
|
|
|
|
if( lbchar >= '0' && lbchar <= '9' )
|
|
|
|
// A number is expected:
|
|
|
|
m_FullText << (int)( aIncr + lbchar - '0' );
|
|
|
|
else
|
|
|
|
m_FullText << (wxChar) ( aIncr + lbchar );
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2013-08-18 15:49:04 +00:00
|
|
|
// Replace the '\''n' sequence by EOL
|
|
|
|
// and the sequence '\''\' by only one '\' in m_FullText
|
2015-03-25 13:07:05 +00:00
|
|
|
// if m_FullText is a multiline text (i.e.contains '\n') return true
|
2021-02-22 23:47:17 +00:00
|
|
|
bool DS_DATA_ITEM_TEXT::ReplaceAntiSlashSequence()
|
2013-08-18 15:49:04 +00:00
|
|
|
{
|
|
|
|
bool multiline = false;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < m_FullText.Len(); ii++ )
|
|
|
|
{
|
|
|
|
if( m_FullText[ii] == '\n' )
|
|
|
|
multiline = true;
|
|
|
|
|
|
|
|
else if( m_FullText[ii] == '\\' )
|
|
|
|
{
|
|
|
|
if( ++ii >= m_FullText.Len() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( m_FullText[ii] == '\\' )
|
|
|
|
{
|
|
|
|
// a double \\ sequence is replaced by a single \ char
|
|
|
|
m_FullText.Remove(ii, 1);
|
|
|
|
ii--;
|
|
|
|
}
|
|
|
|
else if( m_FullText[ii] == 'n' )
|
|
|
|
{
|
|
|
|
// Replace the "\n" sequence by a EOL char
|
|
|
|
multiline = true;
|
|
|
|
m_FullText[ii] = '\n';
|
|
|
|
m_FullText.Remove(ii-1, 1);
|
|
|
|
ii--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return multiline;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_ITEM_TEXT::SetConstrainedTextSize()
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
m_ConstrainedTextSize = m_TextSize;
|
|
|
|
|
|
|
|
if( m_ConstrainedTextSize.x == 0 )
|
2021-02-22 23:47:17 +00:00
|
|
|
m_ConstrainedTextSize.x = DS_DATA_MODEL::GetTheInstance().m_DefaultTextSize.x;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
if( m_ConstrainedTextSize.y == 0 )
|
2021-02-22 23:47:17 +00:00
|
|
|
m_ConstrainedTextSize.y = DS_DATA_MODEL::GetTheInstance().m_DefaultTextSize.y;
|
2024-05-03 21:12:08 +00:00
|
|
|
|
|
|
|
if( m_BoundingBoxSize.x > 0 || m_BoundingBoxSize.y > 0 )
|
|
|
|
{
|
|
|
|
// to know the X and Y size of the line, we should use EDA_TEXT::GetTextBox()
|
|
|
|
// but this function uses integers
|
|
|
|
// So, to avoid truncations with our unit in mm, use microns.
|
|
|
|
VECTOR2I size_micron;
|
|
|
|
#define FSCALE 1000.0
|
|
|
|
int linewidth = 0;
|
|
|
|
size_micron.x = KiROUND( m_ConstrainedTextSize.x * FSCALE );
|
|
|
|
size_micron.y = KiROUND( m_ConstrainedTextSize.y * FSCALE );
|
|
|
|
DS_DRAW_ITEM_TEXT dummy( unityScale, this, 0, m_FullText, VECTOR2I( 0, 0 ), size_micron,
|
|
|
|
linewidth, m_Font, m_Italic, m_Bold, m_TextColor );
|
|
|
|
dummy.SetMultilineAllowed( true );
|
|
|
|
dummy.SetHorizJustify( m_Hjustify ) ;
|
|
|
|
dummy.SetVertJustify( m_Vjustify );
|
|
|
|
dummy.SetTextAngle( EDA_ANGLE( m_Orient, DEGREES_T ) );
|
|
|
|
|
|
|
|
BOX2I rect = dummy.GetTextBox();
|
|
|
|
VECTOR2D size;
|
|
|
|
size.x = KiROUND( (int) rect.GetWidth() / FSCALE );
|
|
|
|
size.y = KiROUND( (int) rect.GetHeight() / FSCALE );
|
|
|
|
|
|
|
|
if( m_BoundingBoxSize.x > 0 && size.x > m_BoundingBoxSize.x )
|
|
|
|
m_ConstrainedTextSize.x *= m_BoundingBoxSize.x / size.x;
|
|
|
|
|
|
|
|
if( m_BoundingBoxSize.y > 0 && size.y > m_BoundingBoxSize.y )
|
|
|
|
m_ConstrainedTextSize.y *= m_BoundingBoxSize.y / size.y;
|
|
|
|
}
|
2013-05-24 08:59:40 +00:00
|
|
|
}
|
2013-08-18 15:49:04 +00:00
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_ITEM_BITMAP::SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2021-06-08 03:06:11 +00:00
|
|
|
std::map<size_t, EDA_ITEM_FLAGS> itemFlags;
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_BASE* item = nullptr;
|
2019-05-24 10:11:18 +00:00
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
for( size_t i = 0; i < m_drawItems.size(); ++i )
|
2019-05-24 10:11:18 +00:00
|
|
|
{
|
2019-05-26 18:35:20 +00:00
|
|
|
item = m_drawItems[ i ];
|
|
|
|
itemFlags[ i ] = item->GetFlags();
|
2019-05-24 10:11:18 +00:00
|
|
|
|
|
|
|
if( aCollector )
|
|
|
|
aCollector->Remove( item );
|
|
|
|
|
|
|
|
if( aView )
|
|
|
|
aView->Remove( item );
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
delete item;
|
2019-05-24 10:11:18 +00:00
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2020-11-29 10:54:50 +00:00
|
|
|
if( aCollector )
|
|
|
|
{
|
|
|
|
double pix_size_iu = aCollector->GetMilsToIUfactor() * 1000 / m_ImageBitmap->GetPPI();
|
|
|
|
m_ImageBitmap->SetPixelSizeIu( pix_size_iu );
|
|
|
|
}
|
|
|
|
|
2023-02-07 11:07:42 +00:00
|
|
|
if( !m_ImageBitmap->GetOriginalImageData() )
|
|
|
|
return;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
m_drawItems.clear();
|
|
|
|
|
2021-06-09 09:22:43 +00:00
|
|
|
for( int j = 0; j < m_RepeatCount; j++ )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2023-05-27 15:30:12 +00:00
|
|
|
if( j > 0 && !IsInsidePage( j ) )
|
2019-05-20 10:23:32 +00:00
|
|
|
continue;
|
|
|
|
|
2023-05-27 15:30:12 +00:00
|
|
|
DS_DRAW_ITEM_BITMAP* bitmap = new DS_DRAW_ITEM_BITMAP( this, j, GetStartPosIU( j ) );
|
2020-11-28 09:53:26 +00:00
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
bitmap->SetFlags( itemFlags[ j ] );
|
2019-05-20 10:23:32 +00:00
|
|
|
m_drawItems.push_back( bitmap );
|
|
|
|
|
|
|
|
if( aCollector )
|
|
|
|
aCollector->Append( bitmap );
|
|
|
|
|
|
|
|
if( aView )
|
|
|
|
aView->Add( bitmap );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
int DS_DATA_ITEM_BITMAP::GetPPI() const
|
2013-10-19 10:29:54 +00:00
|
|
|
{
|
|
|
|
if( m_ImageBitmap )
|
2016-07-11 19:48:46 +00:00
|
|
|
return m_ImageBitmap->GetPPI() / m_ImageBitmap->GetScale();
|
2013-10-19 10:29:54 +00:00
|
|
|
|
|
|
|
return 300;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_ITEM_BITMAP::SetPPI( int aBitmapPPI )
|
2013-10-19 10:29:54 +00:00
|
|
|
{
|
|
|
|
if( m_ImageBitmap )
|
2016-07-11 19:48:46 +00:00
|
|
|
m_ImageBitmap->SetScale( (double) m_ImageBitmap->GetPPI() / aBitmapPPI );
|
2013-10-19 10:29:54 +00:00
|
|
|
}
|