2019-05-20 10:23:32 +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-05-05 13:21:56 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-20 10:23:32 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-02-22 23:47:17 +00:00
|
|
|
* the class DS_DATA_ITEM (and DS_DATA_ITEM_TEXT) defines
|
2021-05-30 22:56:24 +00:00
|
|
|
* a basic shape of a drawing sheet (frame references and title block)
|
2019-05-20 10:23:32 +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
|
2019-05-20 10:23:32 +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)
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
* The list of these items is stored in a DS_DATA_MODEL instance.
|
2019-05-20 10:23:32 +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
|
2019-05-20 10:23:32 +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
|
2019-05-20 10:23:32 +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).
|
2019-05-20 10:23:32 +00:00
|
|
|
*/
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_draw_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
2019-05-20 10:23:32 +00:00
|
|
|
#include <base_units.h>
|
|
|
|
#include <page_info.h>
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2020-10-14 02:46:39 +00:00
|
|
|
#include <gr_basic.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2020-10-14 11:29:36 +00:00
|
|
|
#include <render_settings.h>
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
// ============================ BASE CLASS ==============================
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DRAW_ITEM_BASE::ViewGetLayers( int aLayers[], int& aCount ) const
|
2019-05-24 13:37:55 +00:00
|
|
|
{
|
|
|
|
aCount = 1;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM* dataItem = GetPeer();
|
2019-05-24 13:37:55 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
if( !dataItem ) // No peer: this item is like a DS_DRAW_ITEM_PAGE
|
2019-06-07 10:42:28 +00:00
|
|
|
{
|
2021-02-22 16:37:43 +00:00
|
|
|
aLayers[0] = LAYER_DRAWINGSHEET;
|
2019-06-07 10:42:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-24 13:37:55 +00:00
|
|
|
if( dataItem->GetPage1Option() == FIRST_PAGE_ONLY )
|
2021-02-22 16:37:43 +00:00
|
|
|
aLayers[0] = LAYER_DRAWINGSHEET_PAGE1;
|
2019-05-24 13:37:55 +00:00
|
|
|
else if( dataItem->GetPage1Option() == SUBSEQUENT_PAGES )
|
2021-02-22 16:37:43 +00:00
|
|
|
aLayers[0] = LAYER_DRAWINGSHEET_PAGEn;
|
2019-05-24 13:37:55 +00:00
|
|
|
else
|
2021-02-22 16:37:43 +00:00
|
|
|
aLayers[0] = LAYER_DRAWINGSHEET;
|
2019-05-24 13:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
// A generic HitTest that can be used by some, but not all, sub-classes.
|
2022-08-31 09:33:46 +00:00
|
|
|
bool DS_DRAW_ITEM_BASE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I sel = aRect;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if ( aAccuracy )
|
|
|
|
sel.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return sel.Contains( GetBoundingBox() );
|
|
|
|
|
|
|
|
return sel.Intersects( GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void DS_DRAW_ITEM_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
|
|
|
|
std::vector<MSG_PANEL_ITEM>& aList )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2020-11-18 15:36:47 +00:00
|
|
|
wxString msg;
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM* dataItem = GetPeer();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
if( dataItem == nullptr ) // Is only a pure graphic item used in drawing sheet editor to
|
|
|
|
// handle the page limits
|
2019-06-07 10:42:28 +00:00
|
|
|
return;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
switch( dataItem->GetType() )
|
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
case DS_DATA_ITEM::DS_SEGMENT:
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Line" ), wxEmptyString );
|
2019-05-20 10:23:32 +00:00
|
|
|
break;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
case DS_DATA_ITEM::DS_RECT:
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Rectangle" ), wxEmptyString );
|
2019-05-20 10:23:32 +00:00
|
|
|
break;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
case DS_DATA_ITEM::DS_TEXT:
|
2023-05-05 13:21:56 +00:00
|
|
|
{
|
|
|
|
DS_DRAW_ITEM_TEXT* textItem = static_cast<DS_DRAW_ITEM_TEXT*>( this );
|
|
|
|
// Don't use GetShownText(); we want to see the variable references here
|
|
|
|
aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, textItem->GetText() ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
break;
|
2023-05-05 13:21:56 +00:00
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
case DS_DATA_ITEM::DS_POLYPOLYGON:
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Imported Shape" ), wxEmptyString );
|
2019-05-20 10:23:32 +00:00
|
|
|
break;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
case DS_DATA_ITEM::DS_BITMAP:
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Image" ), wxEmptyString );
|
2019-05-20 10:23:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( dataItem->GetPage1Option() )
|
|
|
|
{
|
2020-11-18 15:36:47 +00:00
|
|
|
case FIRST_PAGE_ONLY: msg = _( "First Page Only" ); break;
|
2019-05-20 10:23:32 +00:00
|
|
|
case SUBSEQUENT_PAGES: msg = _( "Subsequent Pages" ); break;
|
2020-11-18 15:36:47 +00:00
|
|
|
default: msg = _( "All Pages" ); break;
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "First Page Option" ), msg );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( unityScale, EDA_UNITS::UNSCALED,
|
2022-09-16 04:38:10 +00:00
|
|
|
dataItem->m_RepeatCount );
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Repeat Count" ), msg );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2022-09-19 09:25:20 +00:00
|
|
|
msg = EDA_UNIT_UTILS::UI::MessageTextFromValue( unityScale, EDA_UNITS::UNSCALED,
|
2022-09-16 04:38:10 +00:00
|
|
|
dataItem->m_IncrementLabel );
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Repeat Label Increment" ), msg );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "(%s, %s)" ),
|
2022-09-19 09:25:20 +00:00
|
|
|
aFrame->MessageTextFromValue( dataItem->m_IncrementVector.x ),
|
|
|
|
aFrame->MessageTextFromValue( dataItem->m_IncrementVector.y ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Repeat Position Increment" ), msg );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Comment" ), dataItem->m_Info );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================ TEXT ==============================
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void DS_DRAW_ITEM_TEXT::PrintWsItem( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2022-03-31 18:43:08 +00:00
|
|
|
COLOR4D color = GetTextColor();
|
|
|
|
|
|
|
|
if( color == COLOR4D::UNSPECIFIED )
|
|
|
|
color = aSettings->GetLayerColor( LAYER_DRAWINGSHEET );
|
|
|
|
|
|
|
|
Print( aSettings, aOffset, color, FILLED );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-27 15:30:12 +00:00
|
|
|
const BOX2I DS_DRAW_ITEM_TEXT::GetApproxBBox()
|
|
|
|
{
|
2023-05-27 17:53:04 +00:00
|
|
|
// A really dumb over-approximation because doing it for real (even with the stroke font)
|
|
|
|
// shows up large in profiles.
|
2023-05-27 15:30:12 +00:00
|
|
|
|
|
|
|
const TEXT_ATTRIBUTES& attrs = GetAttributes();
|
|
|
|
const wxString text = GetShownText( true );
|
|
|
|
BOX2I bbox( GetTextPos() );
|
|
|
|
|
2023-05-27 17:53:04 +00:00
|
|
|
bbox.SetWidth( (int) text.length() * attrs.m_Size.x * 1.3 );
|
|
|
|
bbox.SetHeight( attrs.m_Size.y );
|
2023-05-27 15:30:12 +00:00
|
|
|
|
|
|
|
switch( attrs.m_Halign )
|
|
|
|
{
|
|
|
|
case GR_TEXT_H_ALIGN_LEFT: break;
|
|
|
|
case GR_TEXT_H_ALIGN_CENTER: bbox.Offset( -bbox.GetWidth() / 2, 0 ); break;
|
|
|
|
case GR_TEXT_H_ALIGN_RIGHT: bbox.Offset( -bbox.GetWidth(), 0 ); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( GetAttributes().m_Valign )
|
|
|
|
{
|
|
|
|
case GR_TEXT_V_ALIGN_TOP: break;
|
|
|
|
case GR_TEXT_V_ALIGN_CENTER: bbox.Offset( 0, -bbox.GetHeight() / 2 ); break;
|
|
|
|
case GR_TEXT_V_ALIGN_BOTTOM: bbox.Offset( 0, -bbox.GetHeight() ); break;
|
|
|
|
}
|
|
|
|
|
2023-05-27 17:53:04 +00:00
|
|
|
bbox.Inflate( attrs.m_Size.x, attrs.m_Size.y / 2 );
|
2023-05-27 15:30:12 +00:00
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I DS_DRAW_ITEM_TEXT::GetBoundingBox() const
|
2019-05-24 20:10:44 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
return EDA_TEXT::GetTextBox();
|
2019-05-24 20:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool DS_DRAW_ITEM_TEXT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
return EDA_TEXT::TextHitTest( aPosition, aAccuracy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool DS_DRAW_ITEM_TEXT::HitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
return EDA_TEXT::TextHitTest( aRect, aContains, aAccuracy );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString DS_DRAW_ITEM_TEXT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2023-05-05 13:21:56 +00:00
|
|
|
return wxString::Format( _( "Text '%s'" ), KIUI::EllipsizeMenuText( GetText() ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-13 12:01:57 +00:00
|
|
|
// ============================ POLYGON =================================
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DRAW_ITEM_POLYPOLYGONS::PrintWsItem( const RENDER_SETTINGS* aSettings,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& aOffset )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2021-02-22 16:37:43 +00:00
|
|
|
COLOR4D color = aSettings->GetLayerColor( LAYER_DRAWINGSHEET );
|
2020-04-14 12:25:00 +00:00
|
|
|
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> points_moved;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-06-13 11:23:39 +00:00
|
|
|
for( int idx = 0; idx < m_Polygons.OutlineCount(); ++idx )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2019-06-13 11:23:39 +00:00
|
|
|
points_moved.clear();
|
|
|
|
SHAPE_LINE_CHAIN& outline = m_Polygons.Outline( idx );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-06-13 11:23:39 +00:00
|
|
|
for( int ii = 0; ii < outline.PointCount(); ii++ )
|
2020-04-14 12:25:00 +00:00
|
|
|
{
|
|
|
|
points_moved.emplace_back( outline.CPoint( ii ).x + aOffset.x,
|
|
|
|
outline.CPoint( ii ).y + aOffset.y );
|
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
GRPoly( DC, points_moved.size(), &points_moved[0], true, penWidth, color, color );
|
2019-06-13 11:23:39 +00:00
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void DS_DRAW_ITEM_POLYPOLYGONS::SetPosition( const VECTOR2I& aPos )
|
2019-06-13 12:01:57 +00:00
|
|
|
{
|
|
|
|
// Note: m_pos is the anchor point of the shape.
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I move_vect = aPos - m_pos;
|
2019-06-13 12:01:57 +00:00
|
|
|
m_pos = aPos;
|
|
|
|
|
|
|
|
// Move polygon corners to the new position:
|
|
|
|
m_Polygons.Move( move_vect );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I DS_DRAW_ITEM_POLYPOLYGONS::GetBoundingBox() const
|
2019-05-24 20:10:44 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
return m_Polygons.BBox();
|
2019-05-24 20:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool DS_DRAW_ITEM_POLYPOLYGONS::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2019-07-13 16:35:57 +00:00
|
|
|
return m_Polygons.Collide( aPosition, aAccuracy );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool DS_DRAW_ITEM_POLYPOLYGONS::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I sel = aRect;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if ( aAccuracy )
|
|
|
|
sel.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return sel.Contains( GetBoundingBox() );
|
|
|
|
|
|
|
|
// Fast test: if rect is outside the polygon bounding box, then they cannot intersect
|
|
|
|
if( !sel.Intersects( GetBoundingBox() ) )
|
|
|
|
return false;
|
|
|
|
|
2019-06-13 11:23:39 +00:00
|
|
|
for( int idx = 0; idx < m_Polygons.OutlineCount(); ++idx )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2019-06-13 11:23:39 +00:00
|
|
|
const SHAPE_LINE_CHAIN& outline = m_Polygons.COutline( idx );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < outline.PointCount(); ii++ )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I corner( outline.CPoint( ii ).x, outline.CPoint( ii ).y );
|
2019-06-13 11:23:39 +00:00
|
|
|
|
|
|
|
// Test if the point is within aRect
|
|
|
|
if( sel.Contains( corner ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Test if this edge intersects aRect
|
|
|
|
int ii_next = (ii+1) % outline.PointCount();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I next_corner( outline.CPoint( ii_next ).x, outline.CPoint( ii_next ).y );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-06-13 11:23:39 +00:00
|
|
|
if( sel.Intersects( corner, next_corner ) )
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString DS_DRAW_ITEM_POLYPOLYGONS::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2022-08-15 16:59:34 +00:00
|
|
|
return _( "Imported Shape" );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================ RECT ==============================
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void DS_DRAW_ITEM_RECT::PrintWsItem( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2021-02-22 16:37:43 +00:00
|
|
|
COLOR4D color = aSettings->GetLayerColor( LAYER_DRAWINGSHEET );
|
2020-04-14 12:25:00 +00:00
|
|
|
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
|
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
GRRect( DC, GetStart() + aOffset, GetEnd() + aOffset, penWidth, color );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I DS_DRAW_ITEM_RECT::GetBoundingBox() const
|
2019-05-24 20:10:44 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
return BOX2I( GetStart(), GetEnd() - GetStart() );
|
2019-05-24 20:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool DS_DRAW_ITEM_RECT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
int dist = aAccuracy + ( GetPenWidth() / 2 );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start = GetStart();
|
|
|
|
VECTOR2I end;
|
2019-05-20 10:23:32 +00:00
|
|
|
end.x = GetEnd().x;
|
|
|
|
end.y = start.y;
|
|
|
|
|
|
|
|
// Upper line
|
|
|
|
if( TestSegmentHit( aPosition, start, end, dist ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Right line
|
|
|
|
start = end;
|
|
|
|
end.y = GetEnd().y;
|
|
|
|
if( TestSegmentHit( aPosition, start, end, dist ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// lower line
|
|
|
|
start = end;
|
|
|
|
end.x = GetStart().x;
|
|
|
|
if( TestSegmentHit( aPosition, start, end, dist ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// left line
|
|
|
|
start = end;
|
|
|
|
end = GetStart();
|
|
|
|
if( TestSegmentHit( aPosition, start, end, dist ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool DS_DRAW_ITEM_RECT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2020-12-02 22:31:01 +00:00
|
|
|
{
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I sel = aRect;
|
2020-12-02 22:31:01 +00:00
|
|
|
|
|
|
|
if ( aAccuracy )
|
|
|
|
sel.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
|
|
|
return sel.Contains( GetBoundingBox() );
|
|
|
|
|
|
|
|
// For greedy we need to check each side of the rect as we're pretty much always inside the
|
2021-02-22 23:47:17 +00:00
|
|
|
// rect which defines the drawing-sheet frame.
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I side = GetBoundingBox();
|
2020-12-02 22:31:01 +00:00
|
|
|
side.SetHeight( 0 );
|
|
|
|
|
|
|
|
if( sel.Intersects( side ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
side.SetY( GetBoundingBox().GetBottom() );
|
|
|
|
|
|
|
|
if( sel.Intersects( side ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
side = GetBoundingBox();
|
|
|
|
side.SetWidth( 0 );
|
|
|
|
|
|
|
|
if( sel.Intersects( side ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
side.SetX( GetBoundingBox().GetRight() );
|
|
|
|
|
|
|
|
if( sel.Intersects( side ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString DS_DRAW_ITEM_RECT::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2020-09-19 16:12:00 +00:00
|
|
|
return wxString::Format( _( "Rectangle, width %s height %s" ),
|
2022-09-19 16:09:59 +00:00
|
|
|
aUnitsProvider->MessageTextFromValue( std::abs( GetStart().x - GetEnd().x ) ),
|
|
|
|
aUnitsProvider->MessageTextFromValue( std::abs( GetStart().y - GetEnd().y ) ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================ LINE ==============================
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void DS_DRAW_ITEM_LINE::PrintWsItem( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
wxDC* DC = aSettings->GetPrintDC();
|
2021-02-22 16:37:43 +00:00
|
|
|
COLOR4D color = aSettings->GetLayerColor( LAYER_DRAWINGSHEET );
|
2020-04-14 12:25:00 +00:00
|
|
|
int penWidth = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
|
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
GRLine( DC, GetStart() + aOffset, GetEnd() + aOffset, penWidth, color );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I DS_DRAW_ITEM_LINE::GetBoundingBox() const
|
2019-05-24 20:10:44 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
return BOX2I( GetStart(), GetEnd() - GetStart() );
|
2019-05-24 20:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool DS_DRAW_ITEM_LINE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
int mindist = aAccuracy + ( GetPenWidth() / 2 ) + 1;
|
2019-05-20 10:23:32 +00:00
|
|
|
return TestSegmentHit( aPosition, GetStart(), GetEnd(), mindist );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString DS_DRAW_ITEM_LINE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2020-09-19 16:12:00 +00:00
|
|
|
return wxString::Format( _( "Line, length %s" ),
|
2022-09-19 16:09:59 +00:00
|
|
|
aUnitsProvider->MessageTextFromValue( EuclideanNorm( GetStart() - GetEnd() ) ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============== BITMAP ================
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void DS_DRAW_ITEM_BITMAP::PrintWsItem( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM_BITMAP* bitmap = (DS_DATA_ITEM_BITMAP*) GetPeer();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2020-11-27 14:42:27 +00:00
|
|
|
if( !bitmap->m_ImageBitmap )
|
|
|
|
return;
|
|
|
|
|
2023-07-02 22:59:38 +00:00
|
|
|
bitmap->m_ImageBitmap->DrawBitmap( aSettings->GetPrintDC(), m_pos + aOffset,
|
|
|
|
aSettings->GetBackgroundColor() );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I DS_DRAW_ITEM_BITMAP::GetBoundingBox() const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
const DS_DATA_ITEM_BITMAP* bitmap = static_cast<const DS_DATA_ITEM_BITMAP*>( m_peer );
|
|
|
|
BOX2I bbox;
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2023-02-07 11:07:42 +00:00
|
|
|
if( bitmap && bitmap->m_ImageBitmap )
|
|
|
|
{
|
|
|
|
VECTOR2I bm_size = bitmap->m_ImageBitmap->GetSize();
|
|
|
|
bbox.SetSize( bm_size );
|
|
|
|
bbox.SetOrigin( m_pos.x - bm_size.x / 2, m_pos.y - bm_size.y / 2 );
|
|
|
|
}
|
2019-06-06 09:13:10 +00:00
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool DS_DRAW_ITEM_BITMAP::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2019-06-06 09:13:10 +00:00
|
|
|
{
|
2022-08-31 22:57:24 +00:00
|
|
|
BOX2I bbox = GetBoundingBox();
|
2019-06-06 09:13:10 +00:00
|
|
|
bbox.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
return bbox.Contains( aPosition );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool DS_DRAW_ITEM_BITMAP::HitTest( const BOX2I& aRect, bool aContains, int aAccuracy ) const
|
2019-06-06 09:13:10 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
return DS_DRAW_ITEM_BASE::HitTest( aRect, aContains, aAccuracy );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString DS_DRAW_ITEM_BITMAP::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2020-09-19 18:53:58 +00:00
|
|
|
return _( "Image" );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString DS_DRAW_ITEM_PAGE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2019-06-07 10:42:28 +00:00
|
|
|
{
|
2020-09-19 18:53:58 +00:00
|
|
|
return _( "Page Limits" );
|
2019-06-07 10:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I DS_DRAW_ITEM_PAGE::GetBoundingBox() const
|
2019-06-07 10:42:28 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I dummy;
|
2019-06-07 10:42:28 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
// We want this graphic item always visible. So gives the max size to the
|
2019-06-07 10:42:28 +00:00
|
|
|
// bounding box to avoid any clamping:
|
2022-08-31 09:15:42 +00:00
|
|
|
dummy.SetMaximum();
|
|
|
|
|
2019-06-07 10:42:28 +00:00
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
// ====================== DS_DRAW_ITEM_LIST ==============================
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DRAW_ITEM_LIST::BuildDrawItemsList( const PAGE_INFO& aPageInfo,
|
2021-02-22 16:37:43 +00:00
|
|
|
const TITLE_BLOCK& aTitleBlock )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
m_titleBlock = &aTitleBlock;
|
2023-01-18 01:16:57 +00:00
|
|
|
m_paperFormat = aPageInfo.GetType();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
// Build the basic layout shape, if the layout list is empty
|
2019-05-25 13:56:52 +00:00
|
|
|
if( model.GetCount() == 0 && !model.VoidListAllowed() )
|
2021-02-22 23:47:17 +00:00
|
|
|
model.LoadDrawingSheet();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2023-06-12 21:33:55 +00:00
|
|
|
model.SetupDrawEnvironment( aPageInfo, GetMilsToIUfactor() );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DATA_ITEM* wsItem : model.GetItems() )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
// Generate it only if the page option allows this
|
2020-10-18 20:30:37 +00:00
|
|
|
if( wsItem->GetPage1Option() == FIRST_PAGE_ONLY && !m_isFirstPage )
|
2019-05-20 10:23:32 +00:00
|
|
|
continue;
|
2020-10-18 20:30:37 +00:00
|
|
|
else if( wsItem->GetPage1Option() == SUBSEQUENT_PAGES && m_isFirstPage )
|
2019-05-20 10:23:32 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
wsItem->SyncDrawItems( this, nullptr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
/* Print the item list created by BuildDrawItemsList
|
2019-05-20 10:23:32 +00:00
|
|
|
* aDC = the current Device Context
|
|
|
|
* The not selected items are drawn first (most of items)
|
|
|
|
* The selected items are drawn after (usually 0 or 1)
|
|
|
|
* to be sure they are seen, even for overlapping items
|
|
|
|
*/
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DRAW_ITEM_LIST::Print( const RENDER_SETTINGS* aSettings )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
std::vector<DS_DRAW_ITEM_BASE*> second_items;
|
2020-01-10 04:28:48 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() )
|
2020-01-10 04:28:48 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == WSG_BITMAP_T )
|
2020-04-14 12:25:00 +00:00
|
|
|
item->PrintWsItem( aSettings );
|
2020-01-10 04:28:48 +00:00
|
|
|
else
|
|
|
|
second_items.push_back( item );
|
|
|
|
}
|
|
|
|
|
2022-07-29 21:02:35 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* item : second_items )
|
2020-04-14 12:25:00 +00:00
|
|
|
item->PrintWsItem( aSettings );
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|