Get rid of PageLayout globals so drawing the preview doesn't mess up the document.

This commit is contained in:
Jeff Young 2019-05-25 14:56:52 +01:00
parent bdd44ce88c
commit 248089c934
14 changed files with 213 additions and 298 deletions

View File

@ -238,6 +238,7 @@ set( COMMON_WIDGET_SRCS
set( COMMON_PAGE_LAYOUT_SRCS
page_layout/ws_data_item.cpp
page_layout/ws_data_model.cpp
page_layout/ws_data_model_io.cpp
page_layout/page_layout_default_description.cpp
page_layout/ws_draw_item.cpp
page_layout/page_layout_reader_keywords.cpp

View File

@ -127,7 +127,11 @@ DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS( EDA_DRAW_FRAME* parent, wxSize aMa
m_tb = m_parent->GetTitleBlock();
m_customFmt = false;
m_localPrjConfigChanged = false;
m_pagelayout = NULL;
m_pagelayout = new WS_DATA_MODEL;
wxString serialization;
WS_DATA_MODEL::GetTheInstance().SaveInString( serialization );
m_pagelayout->SetPageLayout( TO_UTF8( serialization ) );
m_PickDate->SetValue( wxDateTime::Now() );

View File

@ -180,18 +180,18 @@ void PAGE_LAYOUT_READER_PARSER::parseSetup( WS_DATA_MODEL* aLayout )
break;
case T_linewidth:
WS_DATA_ITEM::m_DefaultLineWidth = parseDouble();
aLayout->m_DefaultLineWidth = parseDouble();
NeedRIGHT();
break;
case T_textsize:
WS_DATA_ITEM::m_DefaultTextSize.x = parseDouble();
WS_DATA_ITEM::m_DefaultTextSize.y = parseDouble();
aLayout->m_DefaultTextSize.x = parseDouble();
aLayout->m_DefaultTextSize.y = parseDouble();
NeedRIGHT();
break;
case T_textlinewidth:
WS_DATA_ITEM::m_DefaultTextThickness = parseDouble();
aLayout->m_DefaultTextThickness = parseDouble();
NeedRIGHT();
break;

View File

@ -2,7 +2,7 @@
* 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>.
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
*
* This program is free software; you can redistribute it and/or
@ -52,25 +52,15 @@
#include <fctsys.h>
#include <draw_graphic_text.h>
#include <eda_rect.h>
#include <view/view.h>
#include <ws_painter.h>
#include <title_block.h>
#include <ws_draw_item.h>
#include <ws_data_item.h>
#include <view/view.h>
#include <ws_data_model.h>
using KIGFX::COLOR4D;
// Static members of class WS_DATA_ITEM:
double WS_DATA_ITEM::m_WSunits2Iu = 1000.0;
DPOINT WS_DATA_ITEM::m_RB_Corner;
DPOINT WS_DATA_ITEM::m_LT_Corner;
double WS_DATA_ITEM::m_DefaultLineWidth = 0.0;
DSIZE WS_DATA_ITEM::m_DefaultTextSize( TB_DEFAULT_TEXTSIZE, TB_DEFAULT_TEXTSIZE );
double WS_DATA_ITEM::m_DefaultTextThickness = 0.0;
bool WS_DATA_ITEM::m_SpecialMode = false;
// The constructor:
WS_DATA_ITEM::WS_DATA_ITEM( WS_ITEM_TYPE aType )
{
@ -130,6 +120,17 @@ void WS_DATA_ITEM::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aV
}
int WS_DATA_ITEM::GetPenSizeUi()
{
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
if( m_LineWidth != 0 )
return KiROUND( m_LineWidth * model.m_WSunits2Iu );
else
return KiROUND( model.m_DefaultLineWidth * model.m_WSunits2Iu );
}
// move item to aPosition
// starting point is moved to aPosition
// the Ending point is moved to a position which keeps the item size
@ -139,8 +140,8 @@ void WS_DATA_ITEM::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aV
void WS_DATA_ITEM::MoveToUi( wxPoint aPosition )
{
DPOINT pos_mm;
pos_mm.x = aPosition.x / m_WSunits2Iu;
pos_mm.y = aPosition.y / m_WSunits2Iu;
pos_mm.x = aPosition.x / WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
pos_mm.y = aPosition.y / WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
MoveTo( pos_mm );
}
@ -171,6 +172,7 @@ void WS_DATA_ITEM::MoveTo( DPOINT aPosition )
*/
void WS_DATA_ITEM::MoveStartPointTo( DPOINT aPosition )
{
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
DPOINT position;
// Calculate the position of the starting point
@ -179,21 +181,21 @@ void WS_DATA_ITEM::MoveStartPointTo( DPOINT aPosition )
switch( m_Pos.m_Anchor )
{
case RB_CORNER:
position = m_RB_Corner - aPosition;
position = model.m_RB_Corner - aPosition;
break;
case RT_CORNER:
position.x = m_RB_Corner.x - aPosition.x;
position.y = aPosition.y - m_LT_Corner.y;
position.x = model.m_RB_Corner.x - aPosition.x;
position.y = aPosition.y - model.m_LT_Corner.y;
break;
case LB_CORNER:
position.x = aPosition.x - m_LT_Corner.x;
position.y = m_RB_Corner.y - aPosition.y;
position.x = aPosition.x - model.m_LT_Corner.x;
position.y = model.m_RB_Corner.y - aPosition.y;
break;
case LT_CORNER:
position = aPosition - m_LT_Corner;
position = aPosition - model.m_LT_Corner;
break;
}
@ -206,9 +208,8 @@ void WS_DATA_ITEM::MoveStartPointTo( DPOINT aPosition )
*/
void WS_DATA_ITEM::MoveStartPointToUi( wxPoint aPosition )
{
DPOINT pos_mm;
pos_mm.x = aPosition.x / m_WSunits2Iu;
pos_mm.y = aPosition.y / m_WSunits2Iu;
DPOINT pos_mm( aPosition.x / WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu,
aPosition.y / WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu );
MoveStartPointTo( pos_mm );
}
@ -222,6 +223,7 @@ void WS_DATA_ITEM::MoveStartPointToUi( wxPoint aPosition )
*/
void WS_DATA_ITEM::MoveEndPointTo( DPOINT aPosition )
{
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
DPOINT position;
// Calculate the position of the starting point
@ -230,21 +232,21 @@ void WS_DATA_ITEM::MoveEndPointTo( DPOINT aPosition )
switch( m_End.m_Anchor )
{
case RB_CORNER:
position = m_RB_Corner - aPosition;
position = model.m_RB_Corner - aPosition;
break;
case RT_CORNER:
position.x = m_RB_Corner.x - aPosition.x;
position.y = aPosition.y - m_LT_Corner.y;
position.x = model.m_RB_Corner.x - aPosition.x;
position.y = aPosition.y - model.m_LT_Corner.y;
break;
case LB_CORNER:
position.x = aPosition.x - m_LT_Corner.x;
position.y = m_RB_Corner.y - aPosition.y;
position.x = aPosition.x - model.m_LT_Corner.x;
position.y = model.m_RB_Corner.y - aPosition.y;
break;
case LT_CORNER:
position = aPosition - m_LT_Corner;
position = aPosition - model.m_LT_Corner;
break;
}
@ -270,8 +272,8 @@ void WS_DATA_ITEM::MoveEndPointTo( DPOINT aPosition )
void WS_DATA_ITEM::MoveEndPointToUi( wxPoint aPosition )
{
DPOINT pos_mm;
pos_mm.x = aPosition.x / m_WSunits2Iu;
pos_mm.y = aPosition.y / m_WSunits2Iu;
pos_mm.x = aPosition.x / WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
pos_mm.y = aPosition.y / WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
MoveEndPointTo( pos_mm );
}
@ -279,28 +281,28 @@ void WS_DATA_ITEM::MoveEndPointToUi( wxPoint aPosition )
const DPOINT WS_DATA_ITEM::GetStartPos( int ii ) const
{
DPOINT pos;
pos.x = m_Pos.m_Pos.x + ( m_IncrementVector.x * ii );
pos.y = m_Pos.m_Pos.y + ( m_IncrementVector.y * ii );
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
DPOINT pos( m_Pos.m_Pos.x + ( m_IncrementVector.x * ii ),
m_Pos.m_Pos.y + ( m_IncrementVector.y * ii ) );
switch( m_Pos.m_Anchor )
{
case RB_CORNER: // right bottom corner
pos = m_RB_Corner - pos;
pos = model.m_RB_Corner - pos;
break;
case RT_CORNER: // right top corner
pos.x = m_RB_Corner.x - pos.x;
pos.y = m_LT_Corner.y + pos.y;
pos.x = model.m_RB_Corner.x - pos.x;
pos.y = model.m_LT_Corner.y + pos.y;
break;
case LB_CORNER: // left bottom corner
pos.x = m_LT_Corner.x + pos.x;
pos.y = m_RB_Corner.y - pos.y;
pos.x = model.m_LT_Corner.x + pos.x;
pos.y = model.m_RB_Corner.y - pos.y;
break;
case LT_CORNER: // left top corner
pos = m_LT_Corner + pos;
pos = model.m_LT_Corner + pos;
break;
}
@ -310,36 +312,34 @@ const DPOINT WS_DATA_ITEM::GetStartPos( int ii ) const
const wxPoint WS_DATA_ITEM::GetStartPosUi( int ii ) const
{
DPOINT pos = GetStartPos( ii );
pos = pos * m_WSunits2Iu;
return wxPoint( KiROUND( pos.x ), KiROUND( pos.y ) );
DPOINT pos = GetStartPos( ii ) * WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
return (wxPoint) pos;
}
const DPOINT WS_DATA_ITEM::GetEndPos( int ii ) const
{
DPOINT pos;
pos.x = m_End.m_Pos.x + ( m_IncrementVector.x * ii );
pos.y = m_End.m_Pos.y + ( m_IncrementVector.y * ii );
DPOINT pos( m_End.m_Pos.x + ( m_IncrementVector.x * ii ),
m_End.m_Pos.y + ( m_IncrementVector.y * ii ) );
switch( m_End.m_Anchor )
{
case RB_CORNER: // right bottom corner
pos = m_RB_Corner - pos;
pos = WS_DATA_MODEL::GetTheInstance().m_RB_Corner - pos;
break;
case RT_CORNER: // right top corner
pos.x = m_RB_Corner.x - pos.x;
pos.y = m_LT_Corner.y + pos.y;
pos.x = WS_DATA_MODEL::GetTheInstance().m_RB_Corner.x - pos.x;
pos.y = WS_DATA_MODEL::GetTheInstance().m_LT_Corner.y + pos.y;
break;
case LB_CORNER: // left bottom corner
pos.x = m_LT_Corner.x + pos.x;
pos.y = m_RB_Corner.y - pos.y;
pos.x = WS_DATA_MODEL::GetTheInstance().m_LT_Corner.x + pos.x;
pos.y = WS_DATA_MODEL::GetTheInstance().m_RB_Corner.y - pos.y;
break;
case LT_CORNER: // left top corner
pos = m_LT_Corner + pos;
pos = WS_DATA_MODEL::GetTheInstance().m_LT_Corner + pos;
break;
}
@ -350,21 +350,23 @@ const DPOINT WS_DATA_ITEM::GetEndPos( int ii ) const
const wxPoint WS_DATA_ITEM::GetEndPosUi( int ii ) const
{
DPOINT pos = GetEndPos( ii );
pos = pos * m_WSunits2Iu;
pos = pos * WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
return wxPoint( KiROUND( pos.x ), KiROUND( pos.y ) );
}
bool WS_DATA_ITEM::IsInsidePage( int ii ) const
{
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
DPOINT pos = GetStartPos( ii );
for( int kk = 0; kk < 1; kk++ )
{
if( m_RB_Corner.x < pos.x || m_LT_Corner.x > pos.x )
if( model.m_RB_Corner.x < pos.x || model.m_LT_Corner.x > pos.x )
return false;
if( m_RB_Corner.y < pos.y || m_LT_Corner.y > pos.y )
if( model.m_RB_Corner.y < pos.y || model.m_LT_Corner.y > pos.y )
return false;
pos = GetEndPos( ii );
@ -398,8 +400,7 @@ WS_DATA_ITEM_POLYGONS::WS_DATA_ITEM_POLYGONS() :
}
void WS_DATA_ITEM_POLYGONS::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector,
KIGFX::VIEW* aView )
void WS_DATA_ITEM_POLYGONS::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView )
{
std::map<int, STATUS_FLAGS> itemFlags;
WS_DRAW_ITEM_BASE* item = nullptr;
@ -450,6 +451,12 @@ void WS_DATA_ITEM_POLYGONS::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector,
}
int WS_DATA_ITEM_POLYGONS::GetPenSizeUi()
{
return KiROUND( m_LineWidth * WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu );
}
const DPOINT WS_DATA_ITEM_POLYGONS::GetCornerPosition( unsigned aIdx, int aRepeat ) const
{
DPOINT pos = m_Corners[aIdx];
@ -497,16 +504,18 @@ void WS_DATA_ITEM_POLYGONS::SetBoundingBox()
bool WS_DATA_ITEM_POLYGONS::IsInsidePage( int ii ) const
{
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
DPOINT pos = GetStartPos( ii );
pos += m_minCoord; // left top pos of bounding box
if( m_LT_Corner.x > pos.x || m_LT_Corner.y > pos.y )
if( model.m_LT_Corner.x > pos.x || model.m_LT_Corner.y > pos.y )
return false;
pos = GetStartPos( ii );
pos += m_maxCoord; // rignt bottom pos of bounding box
if( m_RB_Corner.x < pos.x || m_RB_Corner.y < pos.y )
if( model.m_RB_Corner.x < pos.x || model.m_RB_Corner.y < pos.y )
return false;
return true;
@ -516,7 +525,7 @@ bool WS_DATA_ITEM_POLYGONS::IsInsidePage( int ii ) const
const wxPoint WS_DATA_ITEM_POLYGONS::GetCornerPositionUi( unsigned aIdx, int aRepeat ) const
{
DPOINT pos = GetCornerPosition( aIdx, aRepeat );
pos = pos * m_WSunits2Iu;
pos = pos * WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
return wxPoint( int(pos.x), int(pos.y) );
}
@ -540,7 +549,7 @@ void WS_DATA_ITEM_TEXT::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIE
int pensize = GetPenSizeUi();
bool multilines = false;
if( m_SpecialMode )
if( WS_DATA_MODEL::GetTheInstance().m_SpecialMode )
m_FullText = m_TextBase;
else
{
@ -554,8 +563,8 @@ void WS_DATA_ITEM_TEXT::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIE
SetConstrainedTextSize();
wxSize textsize;
textsize.x = KiROUND( m_ConstrainedTextSize.x * WS_DATA_ITEM::m_WSunits2Iu );
textsize.y = KiROUND( m_ConstrainedTextSize.y * WS_DATA_ITEM::m_WSunits2Iu );
textsize.x = KiROUND( m_ConstrainedTextSize.x * WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu );
textsize.y = KiROUND( m_ConstrainedTextSize.y * WS_DATA_MODEL::GetTheInstance().m_WSunits2Iu );
if( m_Bold )
pensize = GetPenSizeForBold( std::min( textsize.x, textsize.y ) );
@ -607,6 +616,17 @@ void WS_DATA_ITEM_TEXT::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIE
}
int WS_DATA_ITEM_TEXT::GetPenSizeUi()
{
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
if( m_LineWidth != 0 )
return KiROUND( m_LineWidth * model.m_WSunits2Iu );
else
return KiROUND( model.m_DefaultTextThickness * model.m_WSunits2Iu );
}
void WS_DATA_ITEM_TEXT::IncrementLabel( int aIncr )
{
int last = m_TextBase.Len() -1;
@ -666,10 +686,10 @@ void WS_DATA_ITEM_TEXT::SetConstrainedTextSize()
m_ConstrainedTextSize = m_TextSize;
if( m_ConstrainedTextSize.x == 0 )
m_ConstrainedTextSize.x = m_DefaultTextSize.x;
m_ConstrainedTextSize.x = WS_DATA_MODEL::GetTheInstance().m_DefaultTextSize.x;
if( m_ConstrainedTextSize.y == 0 )
m_ConstrainedTextSize.y = m_DefaultTextSize.y;
m_ConstrainedTextSize.y = WS_DATA_MODEL::GetTheInstance().m_DefaultTextSize.y;
if( m_BoundingBoxSize.x || m_BoundingBoxSize.y )
{
@ -742,26 +762,6 @@ void WS_DATA_ITEM_BITMAP::SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::V
}
/* set the pixel scale factor of the bitmap
* this factor depend on the application internal unit
* and the PPI bitmap factor
* the pixel scale factor should be initialized before drawing the bitmap
*/
void WS_DATA_ITEM_BITMAP::SetPixelScaleFactor()
{
if( m_ImageBitmap )
{
// m_WSunits2Iu is the page layout unit to application internal unit
// i.e. the mm to to application internal unit
// however the bitmap definition is always known in pixels per inches
double scale = m_WSunits2Iu * 25.4 / m_ImageBitmap->GetPPI();
m_ImageBitmap->SetPixelScaleFactor( scale );
}
}
/* return the PPI of the bitmap
*/
int WS_DATA_ITEM_BITMAP::GetPPI() const
{
if( m_ImageBitmap )
@ -771,8 +771,6 @@ int WS_DATA_ITEM_BITMAP::GetPPI() const
}
/*adjust the PPI of the bitmap
*/
void WS_DATA_ITEM_BITMAP::SetPPI( int aBitmapPPI )
{
if( m_ImageBitmap )

View File

@ -58,7 +58,12 @@
static WS_DATA_MODEL wksTheInstance;
static WS_DATA_MODEL* wksAltInstance;
WS_DATA_MODEL::WS_DATA_MODEL()
WS_DATA_MODEL::WS_DATA_MODEL() :
m_WSunits2Iu( 1000.0 ),
m_DefaultLineWidth( 0.0 ),
m_DefaultTextSize( TB_DEFAULT_TEXTSIZE, TB_DEFAULT_TEXTSIZE ),
m_DefaultTextThickness( 0.0 ),
m_SpecialMode( false )
{
m_allowVoidList = false;
m_leftMargin = 10.0; // the left page margin in mm
@ -90,27 +95,23 @@ void WS_DATA_MODEL::SetAltInstance( WS_DATA_MODEL* aLayout )
}
void WS_DATA_MODEL::SetLeftMargin( double aMargin )
void WS_DATA_MODEL::SetupDrawEnvironment( const PAGE_INFO& aPageInfo, double aMilsToIU )
{
m_leftMargin = aMargin; // the left page margin in mm
}
#define MILS_TO_MM (25.4/1000)
m_WSunits2Iu = aMilsToIU / MILS_TO_MM;
void WS_DATA_MODEL::SetRightMargin( double aMargin )
{
m_rightMargin = aMargin; // the right page margin in mm
}
// Left top corner position
DPOINT lt_corner;
lt_corner.x = GetLeftMargin();
lt_corner.y = GetTopMargin();
m_LT_Corner = lt_corner;
void WS_DATA_MODEL::SetTopMargin( double aMargin )
{
m_topMargin = aMargin; // the top page margin in mm
}
void WS_DATA_MODEL::SetBottomMargin( double aMargin )
{
m_bottomMargin = aMargin; // the bottom page margin in mm
// Right bottom corner position
DPOINT rb_corner;
rb_corner.x = ( aPageInfo.GetSizeMils().x * MILS_TO_MM ) - GetRightMargin();
rb_corner.y = ( aPageInfo.GetSizeMils().y * MILS_TO_MM ) - GetBottomMargin();
m_RB_Corner = rb_corner;
}

View File

@ -8,6 +8,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013-2016 CERN
* Copyright (C) 2019 Kicad Developers, see AUTHORS.txt for contributors.
*
* @author Jean-Pierre Charras, jp.charras at wanadoo.fr
*
@ -63,15 +64,13 @@ protected:
virtual ~WS_DATA_MODEL_IO() {}
public:
void Format( WS_DATA_MODEL* aPageLayout ) const;
void Format( WS_DATA_MODEL* aModel ) const;
void Format( WS_DATA_ITEM* aItem, int aNestLevel ) const;
void Format( WS_DATA_MODEL* aModel, WS_DATA_ITEM* aItem, int aNestLevel ) const;
private:
void format( WS_DATA_MODEL* aPageLayout ) const;
void format( WS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const;
void format( WS_DATA_ITEM* aItem, int aNestLevel ) const;
void format( WS_DATA_MODEL* aModel, WS_DATA_ITEM* aItem, int aNestLevel ) const;
void format( WS_DATA_ITEM_POLYGONS* aItem, int aNestLevel )
const;
void format( WS_DATA_ITEM_BITMAP* aItem, int aNestLevel ) const;
@ -156,7 +155,7 @@ void WS_DATA_MODEL::SaveInString( wxString& aOutputString )
}
void WS_DATA_MODEL_IO::Format( WS_DATA_ITEM* aItem, int aNestLevel ) const
void WS_DATA_MODEL_IO::Format( WS_DATA_MODEL* aModel, WS_DATA_ITEM* aItem, int aNestLevel ) const
{
switch( aItem->GetType() )
{
@ -166,7 +165,7 @@ void WS_DATA_MODEL_IO::Format( WS_DATA_ITEM* aItem, int aNestLevel ) const
case WS_DATA_ITEM::WS_SEGMENT:
case WS_DATA_ITEM::WS_RECT:
format( aItem, aNestLevel );
format( aModel, aItem, aNestLevel );
break;
case WS_DATA_ITEM::WS_POLYPOLYGON:
@ -194,12 +193,12 @@ void WS_DATA_MODEL_IO::Format( WS_DATA_MODEL* aPageLayout ) const
// Write default values:
m_out->Print( nestLevel, "(%s ", getTokenName( T_setup ) );
m_out->Print( 0, "(textsize %s %s)",
double2Str( WS_DATA_ITEM::m_DefaultTextSize.x ).c_str(),
double2Str( WS_DATA_ITEM::m_DefaultTextSize.y ).c_str() );
double2Str( aPageLayout->m_DefaultTextSize.x ).c_str(),
double2Str( aPageLayout->m_DefaultTextSize.y ).c_str() );
m_out->Print( 0, "(linewidth %s)",
double2Str( WS_DATA_ITEM::m_DefaultLineWidth ).c_str() );
double2Str( aPageLayout->m_DefaultLineWidth ).c_str() );
m_out->Print( 0, "(textlinewidth %s)",
double2Str( WS_DATA_ITEM::m_DefaultTextThickness ).c_str() );
double2Str( aPageLayout->m_DefaultTextThickness ).c_str() );
m_out->Print( 0, "\n" );
// Write margin values
@ -217,7 +216,7 @@ void WS_DATA_MODEL_IO::Format( WS_DATA_MODEL* aPageLayout ) const
for( unsigned ii = 0; ii < aPageLayout->GetCount(); ii++ )
{
WS_DATA_ITEM* item = aPageLayout->GetItem( ii );
Format( item, nestLevel );
Format( aPageLayout, item, nestLevel );
}
m_out->Print( 0, ")\n" );
@ -304,7 +303,7 @@ void WS_DATA_MODEL_IO::format( WS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const
m_out->Print( 0, ")\n" );
}
void WS_DATA_MODEL_IO::format( WS_DATA_ITEM* aItem, int aNestLevel ) const
void WS_DATA_MODEL_IO::format( WS_DATA_MODEL* aModel, WS_DATA_ITEM* aItem, int aNestLevel ) const
{
if( aItem->GetType() == WS_DATA_ITEM::WS_RECT )
m_out->Print( aNestLevel, "(%s", getTokenName( T_rect ) );
@ -318,7 +317,7 @@ void WS_DATA_MODEL_IO::format( WS_DATA_ITEM* aItem, int aNestLevel ) const
formatCoordinate( getTokenName( T_end ), aItem->m_End );
formatOptions( aItem );
if( aItem->m_LineWidth && aItem->m_LineWidth != aItem->m_DefaultLineWidth )
if( aItem->m_LineWidth && aItem->m_LineWidth != aModel->m_DefaultLineWidth )
m_out->Print( 0, " (linewidth %s)", double2Str( aItem->m_LineWidth ).c_str() );
formatRepeatParameters( aItem );

View File

@ -396,47 +396,21 @@ wxString WS_DRAW_ITEM_BITMAP::GetSelectMenuText( EDA_UNITS_T aUnits ) const
// ============================ LIST ==============================
#define MILS_TO_MM (25.4/1000)
void WS_DRAW_ITEM_LIST::SetupDrawEnvironment( const PAGE_INFO& aPageInfo )
{
WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance();
// Left top corner position
DPOINT lt_corner;
lt_corner.x = pglayout.GetLeftMargin();
lt_corner.y = pglayout.GetTopMargin();
WS_DATA_ITEM::m_LT_Corner = lt_corner;
// Right bottom corner position
DPOINT rb_corner;
rb_corner.x = ( aPageInfo.GetSizeMils().x * MILS_TO_MM ) - pglayout.GetRightMargin();
rb_corner.y = ( aPageInfo.GetSizeMils().y * MILS_TO_MM ) - pglayout.GetBottomMargin();
WS_DATA_ITEM::m_RB_Corner = rb_corner;
}
void WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList( const PAGE_INFO& aPageInfo,
const TITLE_BLOCK& aTitleBlock )
{
WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance();
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
m_titleBlock = &aTitleBlock;
m_paperFormat = &aPageInfo.GetType();
wxPoint LTmargin( Mm2mils( pglayout.GetLeftMargin() ), Mm2mils( pglayout.GetTopMargin() ) );
wxPoint RBmargin( Mm2mils( pglayout.GetRightMargin() ), Mm2mils( pglayout.GetBottomMargin() ) );
// Build the basic layout shape, if the layout list is empty
if( pglayout.GetCount() == 0 && !pglayout.VoidListAllowed() )
pglayout.SetPageLayout();
if( model.GetCount() == 0 && !model.VoidListAllowed() )
model.SetPageLayout();
WS_DATA_ITEM::m_WSunits2Iu = m_milsToIu / MILS_TO_MM;
model.SetupDrawEnvironment( aPageInfo, m_milsToIu );
SetupDrawEnvironment( aPageInfo );
for( WS_DATA_ITEM* wsItem : pglayout.GetItems() )
for( WS_DATA_ITEM* wsItem : model.GetItems() )
{
// Generate it only if the page option allows this
if( wsItem->GetPage1Option() == FIRST_PAGE_ONLY && m_sheetNumber != 1 )

View File

@ -115,29 +115,6 @@ public:
// for position increment
int m_IncrementLabel;
// These variables are static, because these values are common to all
// instances of WS_DATA_ITEM.
// They are default or common values.
//==============================================================================
// JEY TODO: these globals are death when we try to generate the page setttings preview...
// move them to member variables of WS_DATA_MODEL
//==============================================================================
static double m_WSunits2Iu; // conversion factor between
// ws units (mils) and draw/plot units
static DPOINT m_RB_Corner; // cordinates of the right bottom corner
// (ws units)
static DPOINT m_LT_Corner; // cordinates of the left top corner
// (ws units)
static double m_DefaultLineWidth; // Default line width,
// when not defined inside a line
// or a rect
static DSIZE m_DefaultTextSize; // Default text size,
// when not defined inside a tbtext
static double m_DefaultTextThickness; // Default text thickness,
// when not defined inside a tbtext
static bool m_SpecialMode; // Used in page layout editor
// When set to true, base texts
// instead of full texts are displayed
public:
WS_DATA_ITEM( WS_ITEM_TYPE aType );
@ -168,8 +145,6 @@ public:
* @return true if the item has a end point (segment; rect)
* of false (text, polugon)
*/
virtual bool HasEndPoint() { return true; }
PAGE_OPTION GetPage1Option() const { return m_pageOption; }
void SetPage1Option( PAGE_OPTION aChoice ) { m_pageOption = aChoice; }
@ -178,13 +153,8 @@ public:
const wxPoint GetEndPosUi( int ii = 0 ) const;
const DPOINT GetStartPos( int ii = 0 ) const;
const DPOINT GetEndPos( int ii = 0 ) const;
virtual int GetPenSizeUi()
{
if( m_LineWidth )
return KiROUND( m_LineWidth * m_WSunits2Iu );
else
return KiROUND( m_DefaultLineWidth * m_WSunits2Iu );
}
virtual int GetPenSizeUi();
/**
* move item to a new position
@ -253,15 +223,7 @@ public:
void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
virtual int GetPenSizeUi() override
{
return KiROUND( m_LineWidth * m_WSunits2Iu );
}
/**
* @return false (no end point)
*/
virtual bool HasEndPoint() override { return false; }
virtual int GetPenSizeUi() override;
/**
* add a corner in corner list
@ -353,18 +315,7 @@ public:
void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
/**
* @return false (no end point)
*/
virtual bool HasEndPoint() override { return false; }
virtual int GetPenSizeUi() override
{
if( m_LineWidth )
return KiROUND( m_LineWidth * m_WSunits2Iu );
else
return KiROUND( m_DefaultTextThickness * m_WSunits2Iu );
}
virtual int GetPenSizeUi() override;
/**
* move item to a new position
@ -418,30 +369,8 @@ public:
void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
/**
* @return false (no end point)
*/
virtual bool HasEndPoint() override { return false; }
/**
* @return the PPI of the bitmap
*/
int GetPPI() const;
/**
* adjust the PPI of the bitmap
* @param aBitmapPPI = the ned PPI for the bitmap
*/
void SetPPI( int aBitmapPPI );
/**
* set the pixel scale factor of the bitmap
* this factor depend on the application internal unit
* and the pixel per inch bitmap factor
* the pixel scale factor is the pixel size to application internal unit
* and should be initialized before printing or drawing the bitmap
*/
void SetPixelScaleFactor();
};

View File

@ -39,18 +39,30 @@
class WS_DATA_MODEL
{
std::vector <WS_DATA_ITEM*> m_list;
bool m_allowVoidList; // If false, the default page layout
// will be loaded the first time
// WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList
bool m_allowVoidList; // If false, the default page layout will be loaded the
// first time WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList
// is run (useful mainly for page layout editor)
double m_leftMargin; // the left page margin in mm
double m_rightMargin; // the right page margin in mm
double m_topMargin; // the top page margin in mm
double m_bottomMargin; // the bottom page margin in mm
public:
double m_WSunits2Iu; // conversion factor between
// ws units (mils) and draw/plot units
DPOINT m_RB_Corner; // cordinates of the right bottom corner (in mm)
DPOINT m_LT_Corner; // cordinates of the left top corner (in mm)
double m_DefaultLineWidth; // Used when object line width is 0
DSIZE m_DefaultTextSize; // Used when object text size is 0
double m_DefaultTextThickness; // Used when object text stroke width is 0
bool m_SpecialMode; // Used in page layout editor to toggle variable substition
public:
WS_DATA_MODEL();
~WS_DATA_MODEL() {ClearList(); }
~WS_DATA_MODEL()
{
ClearList();
}
/**
* static function: returns the instance of WS_DATA_MODEL used in the application
@ -66,14 +78,18 @@ public:
// Accessors:
double GetLeftMargin() { return m_leftMargin; }
double GetRightMargin() { return m_rightMargin; }
double GetTopMargin() { return m_topMargin; }
double GetBottomMargin() { return m_bottomMargin; }
void SetLeftMargin( double aMargin ) { m_leftMargin = aMargin; }
void SetLeftMargin( double aMargin );
void SetRightMargin( double aMargin );
void SetTopMargin( double aMargin );
void SetBottomMargin( double aMargin );
double GetRightMargin() { return m_rightMargin; }
void SetRightMargin( double aMargin ) { m_rightMargin = aMargin; }
double GetTopMargin() { return m_topMargin; }
void SetTopMargin( double aMargin ) { m_topMargin = aMargin; }
double GetBottomMargin() { return m_bottomMargin; }
void SetBottomMargin( double aMargin ) { m_bottomMargin = aMargin; }
void SetupDrawEnvironment( const PAGE_INFO& aPageInfo, double aMilsToIU );
/**
* In Kicad applications, a page layout description is needed

View File

@ -439,11 +439,6 @@ public:
*aList = m_graphicList;
}
/**
* Sets up the WORKSHEET_DATAITEM globals for generating drawItems.
*/
static void SetupDrawEnvironment( const PAGE_INFO& aPageInfo );
/**
* Draws the item list created by BuildWorkSheetGraphicList
* @param aClipBox = the clipping rect, or NULL if no clipping

View File

@ -21,7 +21,7 @@ set( PL_EDITOR_SRCS
pl_editor_screen.cpp
pl_editor_layout.cpp
files.cpp
page_layout_writer.cpp
../common/page_layout/ws_data_model_io.cpp
pl_editor_frame.cpp
pl_editor_undo_redo.cpp
properties_frame.cpp

View File

@ -71,13 +71,14 @@ void PL_DRAW_PANEL_GAL::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector<MSG_PAN
void PL_DRAW_PANEL_GAL::DisplayWorksheet()
{
PL_SELECTION_TOOL* selTool = m_edaFrame->GetToolManager()->GetTool<PL_SELECTION_TOOL>();
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
selTool->GetSelection().Clear();
m_view->Clear();
WS_DRAW_ITEM_LIST::SetupDrawEnvironment( m_edaFrame->GetPageSettings() );
model.SetupDrawEnvironment( m_edaFrame->GetPageSettings(), Mils2iu( 1 ) );
for( WS_DATA_ITEM* dataItem : WS_DATA_MODEL::GetTheInstance().GetItems() )
for( WS_DATA_ITEM* dataItem : model.GetItems() )
dataItem->SyncDrawItems( nullptr, m_view );
selTool->RebuildSelection();

View File

@ -92,7 +92,7 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_hotkeysDescrList = PlEditorHotkeysDescr;
m_originSelectChoice = 0;
SetDrawBgColor( WHITE ); // default value, user option (WHITE/BLACK)
WS_DATA_ITEM::m_SpecialMode = true;
WS_DATA_MODEL::GetTheInstance().m_SpecialMode = true;
SetShowPageLimits( true );
m_AboutTitle = "PlEditor";
@ -321,7 +321,7 @@ void PL_EDITOR_FRAME::OnSelectCoordOriginCorner( wxCommandEvent& event )
void PL_EDITOR_FRAME::OnSelectTitleBlockDisplayMode( wxCommandEvent& event )
{
WS_DATA_ITEM::m_SpecialMode = (event.GetId() == ID_SHOW_PL_EDITOR_MODE);
WS_DATA_MODEL::GetTheInstance().m_SpecialMode = (event.GetId() == ID_SHOW_PL_EDITOR_MODE);
HardRedraw();
}
@ -373,13 +373,13 @@ void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
void PL_EDITOR_FRAME::OnUpdateTitleBlockDisplayNormalMode( wxUpdateUIEvent& event )
{
event.Check( WS_DATA_ITEM::m_SpecialMode == false );
event.Check( WS_DATA_MODEL::GetTheInstance().m_SpecialMode == false );
}
void PL_EDITOR_FRAME::OnUpdateTitleBlockDisplaySpecialMode( wxUpdateUIEvent& event )
{
event.Check( WS_DATA_ITEM::m_SpecialMode == true );
event.Check( WS_DATA_MODEL::GetTheInstance().m_SpecialMode == true );
}
@ -505,9 +505,7 @@ void PL_EDITOR_FRAME::UpdateStatusBar()
// Display Zoom level:
EDA_DRAW_FRAME::UpdateStatusBar();
// coordinate origin can be the paper Top Left corner,
// or each of 4 page corners
// We know the origin, and the orientation of axis
// coordinate origin can be the paper Top Left corner, or each of 4 page corners
wxPoint originCoord;
int Xsign = 1;
int Ysign = 1;

View File

@ -70,63 +70,62 @@ wxSize PROPERTIES_FRAME::GetMinSize() const
// Data transfert from general properties to widgets
void PROPERTIES_FRAME::CopyPrmsFromGeneralToPanel()
{
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
wxString msg;
// Set default parameters
msg.Printf( wxT("%.3f"), WS_DATA_ITEM::m_DefaultLineWidth );
msg.Printf( wxT("%.3f"), model.m_DefaultLineWidth );
m_textCtrlDefaultLineWidth->SetValue( msg );
msg.Printf( wxT("%.3f"), WS_DATA_ITEM::m_DefaultTextSize.x );
msg.Printf( wxT("%.3f"), model.m_DefaultTextSize.x );
m_textCtrlDefaultTextSizeX->SetValue( msg );
msg.Printf( wxT("%.3f"), WS_DATA_ITEM::m_DefaultTextSize.y );
msg.Printf( wxT("%.3f"), model.m_DefaultTextSize.y );
m_textCtrlDefaultTextSizeY->SetValue( msg );
msg.Printf( wxT("%.3f"), WS_DATA_ITEM::m_DefaultTextThickness );
msg.Printf( wxT("%.3f"), model.m_DefaultTextThickness );
m_textCtrlDefaultTextThickness->SetValue( msg );
// Set page margins values
WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance();
msg.Printf( wxT("%.3f"), pglayout.GetRightMargin() );
msg.Printf( wxT("%.3f"), model.GetRightMargin() );
m_textCtrlRightMargin->SetValue( msg );
msg.Printf( wxT("%.3f"), pglayout.GetBottomMargin() );
msg.Printf( wxT("%.3f"), model.GetBottomMargin() );
m_textCtrlDefaultBottomMargin->SetValue( msg );
msg.Printf( wxT("%.3f"), pglayout.GetLeftMargin() );
msg.Printf( wxT("%.3f"), model.GetLeftMargin() );
m_textCtrlLeftMargin->SetValue( msg );
msg.Printf( wxT("%.3f"), pglayout.GetTopMargin() );
msg.Printf( wxT("%.3f"), model.GetTopMargin() );
m_textCtrlTopMargin->SetValue( msg );
}
// Data transfert from widgets to general properties
bool PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral()
{
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
wxString msg;
// Import default parameters from widgets
msg = m_textCtrlDefaultLineWidth->GetValue();
WS_DATA_ITEM::m_DefaultLineWidth = DoubleValueFromString( UNSCALED_UNITS, msg );
model.m_DefaultLineWidth = DoubleValueFromString( UNSCALED_UNITS, msg );
msg = m_textCtrlDefaultTextSizeX->GetValue();
WS_DATA_ITEM::m_DefaultTextSize.x = DoubleValueFromString( UNSCALED_UNITS, msg );
model.m_DefaultTextSize.x = DoubleValueFromString( UNSCALED_UNITS, msg );
msg = m_textCtrlDefaultTextSizeY->GetValue();
WS_DATA_ITEM::m_DefaultTextSize.y = DoubleValueFromString( UNSCALED_UNITS, msg );
model.m_DefaultTextSize.y = DoubleValueFromString( UNSCALED_UNITS, msg );
msg = m_textCtrlDefaultTextThickness->GetValue();
WS_DATA_ITEM::m_DefaultTextThickness = DoubleValueFromString( UNSCALED_UNITS, msg );
model.m_DefaultTextThickness = DoubleValueFromString( UNSCALED_UNITS, msg );
// Get page margins values
WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance();
msg = m_textCtrlRightMargin->GetValue();
pglayout.SetRightMargin( DoubleValueFromString( UNSCALED_UNITS, msg ) );
model.SetRightMargin( DoubleValueFromString( UNSCALED_UNITS, msg ) );
msg = m_textCtrlDefaultBottomMargin->GetValue();
pglayout.SetBottomMargin( DoubleValueFromString( UNSCALED_UNITS, msg ) );
model.SetBottomMargin( DoubleValueFromString( UNSCALED_UNITS, msg ) );
// cordinates of the left top corner are the left and top margins
msg = m_textCtrlLeftMargin->GetValue();
pglayout.SetLeftMargin( DoubleValueFromString( UNSCALED_UNITS, msg ) );
model.SetLeftMargin( DoubleValueFromString( UNSCALED_UNITS, msg ) );
msg = m_textCtrlTopMargin->GetValue();
pglayout.SetTopMargin( DoubleValueFromString( UNSCALED_UNITS, msg ) );
model.SetTopMargin( DoubleValueFromString( UNSCALED_UNITS, msg ) );
return true;
}
@ -316,11 +315,11 @@ void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event )
void PROPERTIES_FRAME::OnSetDefaultValues( wxCommandEvent& event )
{
WS_DATA_ITEM::m_DefaultTextSize =
DSIZE( TB_DEFAULT_TEXTSIZE, TB_DEFAULT_TEXTSIZE );
// default thickness in mm
WS_DATA_ITEM::m_DefaultLineWidth = 0.15;
WS_DATA_ITEM::m_DefaultTextThickness = 0.15;
WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
model.m_DefaultTextSize = DSIZE( TB_DEFAULT_TEXTSIZE, TB_DEFAULT_TEXTSIZE );
model.m_DefaultLineWidth = 0.15;
model.m_DefaultTextThickness = 0.15;
CopyPrmsFromGeneralToPanel();
m_parent->GetCanvas()->Refresh();