Add Bezier curve (S_CURVE shape) support in DIALOG_GRAPHIC_ITEM_PROPERTIES.

Fix some issues related to S_CURVE shape support.
This commit is contained in:
jean-pierre charras 2018-07-22 14:50:35 +02:00
parent 3c6e8c4a40
commit 4cac974420
11 changed files with 1192 additions and 42 deletions

View File

@ -1,10 +1,10 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License

View File

@ -1,8 +1,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License

View File

@ -88,6 +88,7 @@ void EDGE_MODULE::SetLocalCoord()
RotatePoint( &m_Start0.x, &m_Start0.y, -angle );
RotatePoint( &m_End0.x, &m_End0.y, -angle );
RotatePoint( &m_Bezier0_C1.x, &m_Bezier0_C1.y, -angle );
RotatePoint( &m_Bezier0_C2.x, &m_Bezier0_C2.y, -angle );
}
@ -452,6 +453,8 @@ void EDGE_MODULE::Move( const wxPoint& aMoveVector )
// footprint position, orientation 0
for( auto iter = m_Poly.Iterate(); iter; iter++ )
*iter += VECTOR2I( aMoveVector );
break;
}
SetDrawCoord();

View File

@ -1,9 +1,9 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License

View File

@ -94,7 +94,7 @@ MODULE::MODULE( const MODULE& aModule ) :
m_CntRot180 = aModule.m_CntRot180;
m_LastEditTime = aModule.m_LastEditTime;
m_Link = aModule.m_Link;
m_Path = aModule.m_Path; //is this correct behavior?
m_Path = aModule.m_Path; // is this correct behavior?
m_LocalClearance = aModule.m_LocalClearance;
m_LocalSolderMaskMargin = aModule.m_LocalSolderMaskMargin;
@ -1180,34 +1180,19 @@ void MODULE::MoveAnchorPosition( const wxPoint& aMoveVector )
switch( item->Type() )
{
case PCB_MODULE_EDGE_T:
{
{
EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( item );
// Polygonal shape coordinates are specific:
// m_Start0 and m_End0 have no meaning. So we have to move corner positions
if( edge->GetShape() == S_POLYGON )
{
for( auto iter = edge->GetPolyShape().Iterate(); iter; iter++ )
{
(*iter) += VECTOR2I( moveVector );
}
}
else
{
edge->m_Start0 += moveVector;
edge->m_End0 += moveVector;
edge->SetDrawCoord();
edge->Move( moveVector );
}
break;
}
case PCB_MODULE_TEXT_T:
{
{
TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
text->SetPos0( text->GetPos0() + moveVector );
text->SetDrawCoord();
}
break;
}
default:
break;

View File

@ -54,6 +54,8 @@ private:
UNIT_BINDER m_endX, m_endY;
UNIT_BINDER m_angle;
UNIT_BINDER m_thickness;
UNIT_BINDER m_bezierCtrl1X, m_bezierCtrl1Y;
UNIT_BINDER m_bezierCtrl2X, m_bezierCtrl2Y;
wxFloatingPointValidator<double> m_AngleValidator;
double m_AngleValue;
@ -87,6 +89,10 @@ DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_BASE_EDIT_FR
m_endY( aParent, m_endYLabel, m_endYCtrl, m_endYUnits ),
m_angle( aParent, m_angleLabel, m_angleCtrl, m_angleUnits ),
m_thickness( aParent, m_thicknessLabel, m_thicknessCtrl, m_thicknessUnits, true ),
m_bezierCtrl1X( aParent, m_BezierPointC1XLabel, m_BezierC1X_Ctrl, m_BezierPointC1XUnit ),
m_bezierCtrl1Y( aParent, m_BezierPointC1YLabel, m_BezierC1Y_Ctrl, m_BezierPointC1YUnit ),
m_bezierCtrl2X( aParent, m_BezierPointC2XLabel, m_BezierC2X_Ctrl, m_BezierPointC2XUnit ),
m_bezierCtrl2Y( aParent, m_BezierPointC2YLabel, m_BezierC2Y_Ctrl, m_BezierPointC2YUnit ),
m_AngleValidator( 1, &m_AngleValue ),
m_AngleValue( 0.0 )
{
@ -135,6 +141,15 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow()
if( m_item->GetShape() != S_ARC )
m_angle.Show( false );
// Only a Bezeier curve has control points. So do not show these parameters for other shapes
if( m_item->GetShape() != S_CURVE )
{
m_bezierCtrl1X.Show( false );
m_bezierCtrl1Y.Show( false );
m_bezierCtrl2X.Show( false );
m_bezierCtrl2Y.Show( false );
}
// Change texts according to the segment shape:
switch( m_item->GetShape() )
{
@ -182,6 +197,12 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow()
m_endY.SetValue( m_item->GetEnd().y );
}
// For Bezier curve:
m_bezierCtrl1X.SetValue( m_item->GetBezControl1().x );
m_bezierCtrl1Y.SetValue( m_item->GetBezControl1().y );
m_bezierCtrl2X.SetValue( m_item->GetBezControl2().x );
m_bezierCtrl2Y.SetValue( m_item->GetBezControl2().y );
m_thickness.SetValue( m_item->GetWidth() );
// Configure the layers list selector
@ -245,10 +266,25 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow()
m_item->SetEndY( m_endY.GetValue() );
}
if( m_moduleItem )
// For Bezier curve: Set the two control points
if( m_item->GetShape() == S_CURVE )
{
m_item->SetBezControl1( wxPoint( m_bezierCtrl1X.GetValue(), m_bezierCtrl1Y.GetValue() ) );
m_item->SetBezControl2( wxPoint( m_bezierCtrl2X.GetValue(), m_bezierCtrl2Y.GetValue() ) );
}
if( m_moduleItem )
{ // We are editing a footprint.
// Init the item coordinates relative to the footprint anchor,
// that are coordinate references
m_moduleItem->SetStart0( m_moduleItem->GetStart() );
m_moduleItem->SetEnd0( m_moduleItem->GetEnd() );
if( m_moduleItem->GetShape() == S_CURVE )
{
m_moduleItem->SetBezier0_C1( wxPoint( m_bezierCtrl1X.GetValue(), m_bezierCtrl1Y.GetValue() ) );
m_moduleItem->SetBezier0_C2( wxPoint( m_bezierCtrl2X.GetValue(), m_bezierCtrl2Y.GetValue() ) );
}
}
m_item->SetWidth( m_thickness.GetValue() );
@ -259,6 +295,8 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow()
m_item->SetAngle( m_AngleValue * 10.0 );
}
m_item->RebuildBezierToSegmentsPointsList( m_item->GetWidth() );
commit.Push( _( "Modify drawing properties" ) );
if( m_DC )

View File

@ -1,8 +1,8 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 30 2017)
// C++ code generated with wxFormBuilder (version Aug 4 2017)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "pcb_layer_box_selector.h"
@ -70,6 +70,50 @@ DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE::DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE( wxWind
m_endYUnits->Wrap( -1 );
m_fgUpperLeftGridSizer->Add( m_endYUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_BezierPointC1XLabel = new wxStaticText( this, wxID_ANY, _("Bezier point C1 X:"), wxDefaultPosition, wxDefaultSize, 0 );
m_BezierPointC1XLabel->Wrap( -1 );
m_fgUpperLeftGridSizer->Add( m_BezierPointC1XLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
m_BezierC1X_Ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_fgUpperLeftGridSizer->Add( m_BezierC1X_Ctrl, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
m_BezierPointC1XUnit = new wxStaticText( this, wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
m_BezierPointC1XUnit->Wrap( -1 );
m_fgUpperLeftGridSizer->Add( m_BezierPointC1XUnit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_BezierPointC1YLabel = new wxStaticText( this, wxID_ANY, _("Bezier point C1 Y:"), wxDefaultPosition, wxDefaultSize, 0 );
m_BezierPointC1YLabel->Wrap( -1 );
m_fgUpperLeftGridSizer->Add( m_BezierPointC1YLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
m_BezierC1Y_Ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_fgUpperLeftGridSizer->Add( m_BezierC1Y_Ctrl, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
m_BezierPointC1YUnit = new wxStaticText( this, wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
m_BezierPointC1YUnit->Wrap( -1 );
m_fgUpperLeftGridSizer->Add( m_BezierPointC1YUnit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_BezierPointC2XLabel = new wxStaticText( this, wxID_ANY, _("Bezier point C2 X:"), wxDefaultPosition, wxDefaultSize, 0 );
m_BezierPointC2XLabel->Wrap( -1 );
m_fgUpperLeftGridSizer->Add( m_BezierPointC2XLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
m_BezierC2X_Ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_fgUpperLeftGridSizer->Add( m_BezierC2X_Ctrl, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
m_BezierPointC2XUnit = new wxStaticText( this, wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
m_BezierPointC2XUnit->Wrap( -1 );
m_fgUpperLeftGridSizer->Add( m_BezierPointC2XUnit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_BezierPointC2YLabel = new wxStaticText( this, wxID_ANY, _("Bezier point C2 Y:"), wxDefaultPosition, wxDefaultSize, 0 );
m_BezierPointC2YLabel->Wrap( -1 );
m_fgUpperLeftGridSizer->Add( m_BezierPointC2YLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
m_BezierC2Y_Ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_fgUpperLeftGridSizer->Add( m_BezierC2Y_Ctrl, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
m_BezierPointC2YUnit = new wxStaticText( this, wxID_ANY, _("Unit"), wxDefaultPosition, wxDefaultSize, 0 );
m_BezierPointC2YUnit->Wrap( -1 );
m_fgUpperLeftGridSizer->Add( m_BezierPointC2YUnit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
bUpperSizer->Add( m_fgUpperLeftGridSizer, 1, wxEXPAND|wxRIGHT, 30 );

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Dec 30 2017)
// C++ code generated with wxFormBuilder (version Aug 4 2017)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE_H__
@ -11,6 +11,7 @@
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
class DIALOG_SHIM;
class PCB_LAYER_BOX_SELECTOR;
#include "dialog_shim.h"
@ -36,7 +37,7 @@ class PCB_LAYER_BOX_SELECTOR;
class DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE : public DIALOG_SHIM
{
private:
protected:
wxFlexGridSizer* m_fgUpperLeftGridSizer;
wxStaticText* m_startXLabel;
@ -51,6 +52,18 @@ class DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE : public DIALOG_SHIM
wxStaticText* m_endYLabel;
wxTextCtrl* m_endYCtrl;
wxStaticText* m_endYUnits;
wxStaticText* m_BezierPointC1XLabel;
wxTextCtrl* m_BezierC1X_Ctrl;
wxStaticText* m_BezierPointC1XUnit;
wxStaticText* m_BezierPointC1YLabel;
wxTextCtrl* m_BezierC1Y_Ctrl;
wxStaticText* m_BezierPointC1YUnit;
wxStaticText* m_BezierPointC2XLabel;
wxTextCtrl* m_BezierC2X_Ctrl;
wxStaticText* m_BezierPointC2XUnit;
wxStaticText* m_BezierPointC2YLabel;
wxTextCtrl* m_BezierC2Y_Ctrl;
wxStaticText* m_BezierPointC2YUnit;
wxStaticText* m_angleLabel;
wxTextCtrl* m_angleCtrl;
wxStaticText* m_angleUnits;
@ -63,17 +76,17 @@ class DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE : public DIALOG_SHIM
wxStdDialogButtonSizer* m_StandardButtonsSizer;
wxButton* m_StandardButtonsSizerOK;
wxButton* m_StandardButtonsSizerCancel;
// Virtual event handlers, overide them in your derived class
virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
virtual void OnInitDlg( wxInitDialogEvent& event ) { event.Skip(); }
public:
DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Graphic Item Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxSYSTEM_MENU );
DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Graphic Item Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxSYSTEM_MENU );
~DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE();
};
#endif //__DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE_H__

View File

@ -72,6 +72,7 @@ static void clearModuleItemFlags( BOARD_ITEM* aItem )
aItem->ClearFlags();
}
bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule )
{
MODULE* newModule;

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013-2017 CERN
* Copyright (C) 2013-2018 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -74,6 +74,14 @@ enum CIRCLE_POINTS
CIRC_CENTER, CIRC_END
};
enum BEZIER_CURVE_POINTS
{
BEZIER_CURVE_START,
BEZIER_CURVE_CONTROL_POINT1,
BEZIER_CURVE_CONTROL_POINT2,
BEZIER_CURVE_END
};
enum DIMENSION_POINTS
{
DIM_CROSSBARO,
@ -86,7 +94,8 @@ class EDIT_POINTS_FACTORY
{
private:
static void buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points, const SHAPE_POLY_SET* aOutline, KIGFX::GAL* aGal )
static void buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points,
const SHAPE_POLY_SET* aOutline, KIGFX::GAL* aGal )
{
int cornersCount = aOutline->TotalVertices();
@ -168,10 +177,15 @@ public:
break;
case S_POLYGON:
{
buildForPolyOutline( points, &segment->GetPolyShape(), aGal );
break;
}
case S_CURVE:
points->AddPoint( segment->GetStart() );
points->AddPoint( segment->GetBezControl1() );
points->AddPoint( segment->GetBezControl2() );
points->AddPoint( segment->GetEnd() );
break;
default: // suppress warnings
break;
@ -490,6 +504,23 @@ void POINT_EDITOR::updateItem() const
break;
}
case S_CURVE:
if( isModified( m_editPoints->Point( BEZIER_CURVE_START ) ) )
segment->SetStart( wxPoint( m_editPoints->Point( BEZIER_CURVE_START ).GetPosition().x,
m_editPoints->Point( BEZIER_CURVE_START ).GetPosition().y ) );
else if( isModified( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ) ) )
segment->SetBezControl1( wxPoint( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).GetPosition().x,
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).GetPosition().y ) );
else if( isModified( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ) ) )
segment->SetBezControl2( wxPoint( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).GetPosition().x,
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).GetPosition().y ) );
else if( isModified( m_editPoints->Point( BEZIER_CURVE_END ) ) )
segment->SetEnd( wxPoint( m_editPoints->Point( BEZIER_CURVE_END ).GetPosition().x,
m_editPoints->Point( BEZIER_CURVE_END ).GetPosition().y ) );
segment->RebuildBezierToSegmentsPointsList( segment->GetWidth() );
break;
default: // suppress warnings
break;
}
@ -660,6 +691,13 @@ void POINT_EDITOR::updatePoints()
break;
}
case S_CURVE:
m_editPoints->Point( BEZIER_CURVE_START ).SetPosition( segment->GetStart() );
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).SetPosition( segment->GetBezControl1() );
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).SetPosition( segment->GetBezControl2() );
m_editPoints->Point( BEZIER_CURVE_END ).SetPosition( segment->GetEnd() );
break;
default: // suppress warnings
break;
}