Shapes for schematic.
ADDED arc, circle and rectangle shapes for schematic. Shapes support line styles and fill colors. CHANGED sheet background color in Edit Text & Graphics Properties to fill color (and it now affects shapes). Pushed STROKE_PARAMS down into common and moved all shapes to using it for stroke descriptions.7.0
-
BINbitmaps_png/png/via_sketch_24.png
-
BINbitmaps_png/png/via_sketch_dark_24.png
-
9common/CMakeLists.txt
-
3common/base_units.cpp
-
87common/eda_shape.cpp
-
1common/layer_id.cpp
-
7common/plotters/plotter.cpp
-
21common/render_settings.cpp
-
2common/settings/builtin_color_themes.h
-
1common/settings/color_settings.cpp
-
276common/stroke_params.cpp
-
10common/stroke_params.keywords
-
5eeschema/CMakeLists.txt
-
4eeschema/bus-wire-junction.cpp
-
47eeschema/dialogs/dialog_global_edit_text_and_graphics.cpp
-
12eeschema/dialogs/dialog_global_edit_text_and_graphics_base.cpp
-
6eeschema/dialogs/dialog_global_edit_text_and_graphics_base.fbp
-
4eeschema/dialogs/dialog_global_edit_text_and_graphics_base.h
-
13eeschema/dialogs/dialog_lib_shape_properties.cpp
-
24eeschema/dialogs/dialog_line_wire_bus_properties.cpp
-
113eeschema/dialogs/dialog_shape_properties.cpp
-
49eeschema/dialogs/dialog_shape_properties.h
-
146eeschema/dialogs/dialog_shape_properties_base.cpp
-
1099eeschema/dialogs/dialog_shape_properties_base.fbp
-
76eeschema/dialogs/dialog_shape_properties_base.h
-
4eeschema/dialogs/panel_eeschema_color_settings.cpp
-
2eeschema/ee_collectors.cpp
-
47eeschema/lib_shape.cpp
-
5eeschema/lib_shape.h
-
8eeschema/lib_symbol.cpp
-
3eeschema/menubar.cpp
-
61eeschema/sch_bus_entry.cpp
-
11eeschema/sch_bus_entry.h
-
3eeschema/sch_file_versions.h
-
59eeschema/sch_item.h
-
46eeschema/sch_line.cpp
-
28eeschema/sch_line.h
-
263eeschema/sch_painter.cpp
-
2eeschema/sch_painter.h
-
66eeschema/sch_plugins/altium/sch_altium_plugin.cpp
-
2eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp
-
10eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp
-
409eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp
-
5eeschema/sch_plugins/kicad/sch_sexpr_parser.h
-
133eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp
-
2eeschema/sch_plugins/kicad/sch_sexpr_plugin.h
-
26eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp
-
422eeschema/sch_shape.cpp
-
119eeschema/sch_shape.h
-
6eeschema/sch_symbol.cpp
-
2eeschema/sch_symbol.h
-
4eeschema/sch_text.cpp
-
1eeschema/sch_view.h
-
4eeschema/schematic.keywords
-
6eeschema/symbol_editor/menubar_symbol_editor.cpp
-
6eeschema/symbol_editor/symbol_edit_frame.cpp
-
6eeschema/symbol_editor/toolbars_symbol_editor.cpp
-
30eeschema/tools/ee_actions.cpp
-
6eeschema/tools/ee_actions.h
-
195eeschema/tools/ee_point_editor.cpp
-
37eeschema/tools/ee_selection_tool.cpp
-
172eeschema/tools/sch_drawing_tools.cpp
-
3eeschema/tools/sch_drawing_tools.h
-
42eeschema/tools/sch_edit_tool.cpp
-
4eeschema/tools/sch_editor_control.cpp
-
10eeschema/tools/sch_line_wire_bus_tool.cpp
-
31eeschema/tools/symbol_editor_drawing_tools.cpp
-
11include/board_item.h
-
29include/core/typeinfo.h
-
29include/eda_shape.h
-
1include/layer_ids.h
-
15include/plotters/plotter.h
-
12include/render_settings.h
-
145include/stroke_params.h
-
19libs/kimath/include/geometry/geometry_utils.h
-
13pcbnew/board_item.cpp
-
3pcbnew/convert_shape_list_to_polygon.cpp
-
12pcbnew/dialogs/dialog_global_edit_text_and_graphics.cpp
-
6pcbnew/dialogs/dialog_graphic_item_properties.cpp
-
16pcbnew/dialogs/dialog_pad_basicshapes_properties.cpp
-
3pcbnew/dialogs/dialog_pad_properties.cpp
-
15pcbnew/drc/drc_test_provider_edge_clearance.cpp
-
1pcbnew/drc/drc_test_provider_library_parity.cpp
-
2pcbnew/exporters/export_gencad.cpp
-
6pcbnew/fp_shape.cpp
-
2pcbnew/graphics_cleaner.cpp
-
24pcbnew/import_gfx/graphics_importer_pcbnew.cpp
-
2pcbnew/microwave/microwave_inductor.cpp
-
2pcbnew/microwave/microwave_polygon.cpp
-
14pcbnew/pad_custom_shape_functions.cpp
-
5pcbnew/pcb_shape.cpp
-
5pcbnew/pcb_shape.h
-
2pcbnew/pcbnew.cpp
-
4pcbnew/plot_brditems_plotter.cpp
-
42pcbnew/plugins/altium/altium_pcb.cpp
-
15pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp
-
12pcbnew/plugins/eagle/eagle_plugin.cpp
-
48pcbnew/plugins/fabmaster/import_fabmaster.cpp
-
6pcbnew/plugins/geda/gpcb_plugin.cpp
-
23pcbnew/plugins/kicad/pcb_parser.cpp
Before Width: 24 | Height: 24 | Size: 1.1 KiB After Width: 24 | Height: 24 | Size: 657 B |
Before Width: 24 | Height: 24 | Size: 1.1 KiB After Width: 24 | Height: 24 | Size: 666 B |
@ -0,0 +1,276 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2021 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 as published by the |
|||
* Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include <macros.h>
|
|||
#include <base_units.h>
|
|||
#include <string_utils.h>
|
|||
#include <eda_rect.h>
|
|||
#include <render_settings.h>
|
|||
#include <geometry/shape.h>
|
|||
#include <geometry/shape_segment.h>
|
|||
#include <geometry/shape_simple.h>
|
|||
#include <geometry/geometry_utils.h>
|
|||
#include <stroke_params.h>
|
|||
#include <trigo.h>
|
|||
|
|||
using namespace STROKEPARAMS_T; |
|||
|
|||
|
|||
void STROKE_PARAMS::Stroke( const SHAPE* aShape, PLOT_DASH_TYPE aLineStyle, int aWidth, |
|||
const KIGFX::RENDER_SETTINGS* aRenderSettings, |
|||
std::function<void( const wxPoint& a, const wxPoint& b )> aStroker ) |
|||
{ |
|||
double strokes[6]; |
|||
int wrapAround; |
|||
|
|||
switch( aLineStyle ) |
|||
{ |
|||
case PLOT_DASH_TYPE::DASH: |
|||
strokes[0] = aRenderSettings->GetDashLength( aWidth ); |
|||
strokes[1] = aRenderSettings->GetGapLength( aWidth ); |
|||
wrapAround = 2; |
|||
break; |
|||
case PLOT_DASH_TYPE::DOT: |
|||
strokes[0] = aRenderSettings->GetDotLength( aWidth ); |
|||
strokes[1] = aRenderSettings->GetGapLength( aWidth ); |
|||
wrapAround = 2; |
|||
break; |
|||
case PLOT_DASH_TYPE::DASHDOT: |
|||
strokes[0] = aRenderSettings->GetDashLength( aWidth ); |
|||
strokes[1] = aRenderSettings->GetGapLength( aWidth ); |
|||
strokes[2] = aRenderSettings->GetDotLength( aWidth ); |
|||
strokes[3] = aRenderSettings->GetGapLength( aWidth ); |
|||
wrapAround = 4; |
|||
break; |
|||
default: |
|||
UNIMPLEMENTED_FOR( lineTypeNames.at( aLineStyle ).name ); |
|||
} |
|||
|
|||
switch( aShape->Type() ) |
|||
{ |
|||
case SH_SIMPLE: |
|||
{ |
|||
const SHAPE_SIMPLE* poly = static_cast<const SHAPE_SIMPLE*>( aShape ); |
|||
|
|||
for( size_t ii = 0; ii < poly->GetSegmentCount(); ++ii ) |
|||
{ |
|||
SEG seg = poly->GetSegment( ii ); |
|||
SHAPE_SEGMENT line( seg.A, seg.B ); |
|||
STROKE_PARAMS::Stroke( &line, aLineStyle, aWidth, aRenderSettings, aStroker ); |
|||
} |
|||
} |
|||
break; |
|||
|
|||
case SH_SEGMENT: |
|||
{ |
|||
const SHAPE_SEGMENT* line = static_cast<const SHAPE_SEGMENT*>( aShape ); |
|||
|
|||
VECTOR2D start = line->GetSeg().A; |
|||
VECTOR2D end = line->GetSeg().B; |
|||
|
|||
EDA_RECT clip( (wxPoint)start, wxSize( end.x - start.x, end.y - start.y ) ); |
|||
clip.Normalize(); |
|||
|
|||
double theta = atan2( end.y - start.y, end.x - start.x ); |
|||
|
|||
for( size_t i = 0; i < 10000; ++i ) |
|||
{ |
|||
// Calculations MUST be done in doubles to keep from accumulating rounding
|
|||
// errors as we go.
|
|||
VECTOR2D next( start.x + strokes[ i % wrapAround ] * cos( theta ), |
|||
start.y + strokes[ i % wrapAround ] * sin( theta ) ); |
|||
|
|||
// Drawing each segment can be done rounded to ints.
|
|||
wxPoint a( KiROUND( start.x ), KiROUND( start.y ) ); |
|||
wxPoint b( KiROUND( next.x ), KiROUND( next.y ) ); |
|||
|
|||
if( ClipLine( &clip, a.x, a.y, b.x, b.y ) ) |
|||
break; |
|||
else if( i % 2 == 0 ) |
|||
aStroker( a, b ); |
|||
|
|||
start = next; |
|||
} |
|||
} |
|||
break; |
|||
|
|||
case SH_ARC: |
|||
{ |
|||
const SHAPE_ARC* arc = static_cast<const SHAPE_ARC*>( aShape ); |
|||
|
|||
double r = arc->GetRadius(); |
|||
double C = 2.0 * M_PI * r; |
|||
VECTOR2I center = arc->GetCenter(); |
|||
VECTOR2D startRadial( arc->GetP0() - center ); |
|||
double startAngle = 180.0 / M_PI * atan2( startRadial.y, startRadial.x ); |
|||
VECTOR2D endRadial( arc->GetP1() - center ); |
|||
double arcEndAngle = 180.0 / M_PI * atan2( endRadial.y, endRadial.x ); |
|||
|
|||
if( arcEndAngle == startAngle ) |
|||
arcEndAngle = startAngle + 360.0; // ring, not null
|
|||
|
|||
if( startAngle > arcEndAngle ) |
|||
{ |
|||
if( arcEndAngle < 0 ) |
|||
arcEndAngle = NormalizeAngleDegrees( arcEndAngle, 0.0, 360.0 ); |
|||
else |
|||
startAngle = NormalizeAngleDegrees( startAngle, -360.0, 0.0 ); |
|||
} |
|||
|
|||
wxASSERT( startAngle < arcEndAngle ); |
|||
|
|||
for( size_t i = 0; i < 10000 && startAngle < arcEndAngle; ++i ) |
|||
{ |
|||
double theta = 360.0 * strokes[ i % wrapAround ] / C; |
|||
double endAngle = std::min( startAngle + theta, arcEndAngle ); |
|||
|
|||
if( i % 2 == 0 ) |
|||
{ |
|||
wxPoint a( center.x + r * cos( startAngle * M_PI / 180.0 ), |
|||
center.y + r * sin( startAngle * M_PI / 180.0 ) ); |
|||
wxPoint b( center.x + r * cos( endAngle * M_PI / 180.0 ), |
|||
center.y + r * sin( endAngle * M_PI / 180.0 ) ); |
|||
|
|||
aStroker( a, b ); |
|||
} |
|||
|
|||
startAngle = endAngle; |
|||
} |
|||
} |
|||
break; |
|||
|
|||
case SH_CIRCLE: |
|||
// A circle is always filled; a ring is represented by a 360° arc.
|
|||
KI_FALLTHROUGH; |
|||
|
|||
default: |
|||
UNIMPLEMENTED_FOR( SHAPE_TYPE_asString( aShape->Type() ) ); |
|||
} |
|||
} |
|||
|
|||
|
|||
static wxString getLineStyleToken( PLOT_DASH_TYPE aStyle ) |
|||
{ |
|||
wxString token; |
|||
|
|||
switch( aStyle ) |
|||
{ |
|||
case PLOT_DASH_TYPE::DASH: token = "dash"; break; |
|||
case PLOT_DASH_TYPE::DOT: token = "dot"; break; |
|||
case PLOT_DASH_TYPE::DASHDOT: token = "dash_dot"; break; |
|||
case PLOT_DASH_TYPE::SOLID: token = "solid"; break; |
|||
case PLOT_DASH_TYPE::DEFAULT: token = "default"; break; |
|||
} |
|||
|
|||
return token; |
|||
} |
|||
|
|||
|
|||
void STROKE_PARAMS::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel ) const |
|||
{ |
|||
wxASSERT( aFormatter != nullptr ); |
|||
|
|||
aFormatter->Print( aNestLevel, "(stroke (width %s) (type %s) (color %d %d %d %s))", |
|||
FormatInternalUnits(GetWidth() ).c_str(), |
|||
TO_UTF8( getLineStyleToken( GetPlotStyle() ) ), |
|||
KiROUND( GetColor().r * 255.0 ), |
|||
KiROUND( GetColor().g * 255.0 ), |
|||
KiROUND( GetColor().b * 255.0 ), |
|||
Double2Str( GetColor().a ).c_str() ); |
|||
} |
|||
|
|||
|
|||
void STROKE_PARAMS_PARSER::ParseStroke( STROKE_PARAMS& aStroke ) |
|||
{ |
|||
for( T token = NextTok(); token != T_RIGHT; token = NextTok() ) |
|||
{ |
|||
if( token != T_LEFT ) |
|||
Expecting( T_LEFT ); |
|||
|
|||
token = NextTok(); |
|||
|
|||
switch( token ) |
|||
{ |
|||
case T_width: |
|||
aStroke.SetWidth( parseDouble( "stroke width" ) * m_iuPerMM ); |
|||
NeedRIGHT(); |
|||
break; |
|||
|
|||
case T_type: |
|||
{ |
|||
token = NextTok(); |
|||
|
|||
switch( token ) |
|||
{ |
|||
case T_dash: aStroke.SetPlotStyle( PLOT_DASH_TYPE::DASH ); break; |
|||
case T_dot: aStroke.SetPlotStyle( PLOT_DASH_TYPE::DOT ); break; |
|||
case T_dash_dot: aStroke.SetPlotStyle( PLOT_DASH_TYPE::DASHDOT ); break; |
|||
case T_solid: aStroke.SetPlotStyle( PLOT_DASH_TYPE::SOLID ); break; |
|||
case T_default: aStroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT ); break; |
|||
default: |
|||
Expecting( "solid, dash, dash_dot, dot or default" ); |
|||
} |
|||
|
|||
NeedRIGHT(); |
|||
break; |
|||
} |
|||
|
|||
case T_color: |
|||
{ |
|||
KIGFX::COLOR4D color; |
|||
|
|||
color.r = parseInt( "red" ) / 255.0; |
|||
color.g = parseInt( "green" ) / 255.0; |
|||
color.b = parseInt( "blue" ) / 255.0; |
|||
color.a = Clamp( parseDouble( "alpha" ), 0.0, 1.0 ); |
|||
|
|||
aStroke.SetColor( color ); |
|||
NeedRIGHT(); |
|||
break; |
|||
} |
|||
|
|||
default: |
|||
Expecting( "width, type, or color" ); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
int STROKE_PARAMS_PARSER::parseInt( const char* aText ) |
|||
{ |
|||
T token = NextTok(); |
|||
|
|||
if( token != T_NUMBER ) |
|||
Expecting( aText ); |
|||
|
|||
return atoi( CurText() ); |
|||
} |
|||
|
|||
|
|||
double STROKE_PARAMS_PARSER::parseDouble( const char* aText ) |
|||
{ |
|||
T token = NextTok(); |
|||
|
|||
if( token != T_NUMBER ) |
|||
Expecting( aText ); |
|||
|
|||
double val = strtod( CurText(), NULL ); |
|||
|
|||
return val; |
|||
} |
@ -0,0 +1,10 @@ |
|||
color |
|||
dash |
|||
dash_dot |
|||
dash_dot_dot |
|||
default |
|||
dot |
|||
solid |
|||
stroke |
|||
type |
|||
width |
@ -0,0 +1,113 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2021 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 |
|||
* 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 |
|||
*/ |
|||
|
|||
#include <widgets/color_swatch.h>
|
|||
#include <stroke_params.h>
|
|||
#include <sch_edit_frame.h>
|
|||
#include <sch_shape.h>
|
|||
#include <dialog_shape_properties.h>
|
|||
|
|||
|
|||
DIALOG_SHAPE_PROPERTIES::DIALOG_SHAPE_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_SHAPE* aShape ) : |
|||
DIALOG_SHAPE_PROPERTIES_BASE( aParent ), |
|||
m_shape( aShape ), |
|||
m_lineWidth( aParent, m_lineWidthLabel, m_lineWidthCtrl, m_lineWidthUnits, true ) |
|||
{ |
|||
SetTitle( wxString::Format( GetTitle(), aShape->ShowShape() ) ); |
|||
|
|||
m_helpLabel1->SetFont( KIUI::GetInfoFont( this ) ); |
|||
m_helpLabel2->SetFont( KIUI::GetInfoFont( this ) ); |
|||
|
|||
SetInitialFocus( m_lineWidthCtrl ); |
|||
|
|||
m_lineColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED ); |
|||
|
|||
for( const std::pair<const PLOT_DASH_TYPE, lineTypeStruct>& typeEntry : lineTypeNames ) |
|||
m_lineStyleCombo->Append( typeEntry.second.name, KiBitmap( typeEntry.second.bitmap ) ); |
|||
|
|||
m_lineStyleCombo->Append( DEFAULT_STYLE ); |
|||
|
|||
m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED ); |
|||
|
|||
// Required under wxGTK if we want to dismiss the dialog with the ESC key
|
|||
SetFocus(); |
|||
m_sdbSizerOK->SetDefault(); |
|||
|
|||
// Now all widgets have the size fixed, call FinishDialogSettings
|
|||
finishDialogSettings(); |
|||
} |
|||
|
|||
|
|||
bool DIALOG_SHAPE_PROPERTIES::TransferDataToWindow() |
|||
{ |
|||
if( !wxDialog::TransferDataToWindow() ) |
|||
return false; |
|||
|
|||
m_lineWidth.SetValue( m_shape->GetWidth() ); |
|||
m_lineColorSwatch->SetSwatchColor( m_shape->GetStroke().GetColor(), false ); |
|||
|
|||
int style = static_cast<int>( m_shape->GetStroke().GetPlotStyle() ); |
|||
|
|||
if( style == -1 ) |
|||
m_lineStyleCombo->SetStringSelection( DEFAULT_STYLE ); |
|||
else if( style < (int) lineTypeNames.size() ) |
|||
m_lineStyleCombo->SetSelection( style ); |
|||
else |
|||
wxFAIL_MSG( "Line type not found in the type lookup map" ); |
|||
|
|||
m_filledCtrl->SetValue( m_shape->IsFilled() ); |
|||
m_fillColorSwatch->SetSwatchColor( m_shape->GetFillColor(), false ); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
bool DIALOG_SHAPE_PROPERTIES::TransferDataFromWindow() |
|||
{ |
|||
if( !wxDialog::TransferDataFromWindow() ) |
|||
return false; |
|||
|
|||
STROKE_PARAMS stroke = m_shape->GetStroke(); |
|||
|
|||
if( !m_lineWidth.IsIndeterminate() ) |
|||
stroke.SetWidth( m_lineWidth.GetValue() ); |
|||
|
|||
auto it = lineTypeNames.begin(); |
|||
std::advance( it, m_lineStyleCombo->GetSelection() ); |
|||
|
|||
if( it == lineTypeNames.end() ) |
|||
stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT ); |
|||
else |
|||
stroke.SetPlotStyle( it->first ); |
|||
|
|||
stroke.SetColor( m_lineColorSwatch->GetSwatchColor() ); |
|||
|
|||
m_shape->SetStroke( stroke ); |
|||
|
|||
m_shape->SetFillMode( m_filledCtrl->GetValue() ? FILL_T::FILLED_WITH_COLOR : FILL_T::NO_FILL ); |
|||
m_shape->SetFillColor( m_fillColorSwatch->GetSwatchColor() ); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
@ -0,0 +1,49 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2021 KiCad Developers, see CHANGELOG.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 |
|||
* 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 |
|||
*/ |
|||
|
|||
#ifndef DIALOG_SHAPE_PROPERTIES_H |
|||
#define DIALOG_SHAPE_PROPERTIES_H |
|||
|
|||
|
|||
class SCH_SHAPE; |
|||
class SCH_EDIT_FRAME; |
|||
|
|||
|
|||
#include <dialog_shape_properties_base.h> |
|||
#include <widgets/unit_binder.h> |
|||
|
|||
|
|||
class DIALOG_SHAPE_PROPERTIES : public DIALOG_SHAPE_PROPERTIES_BASE |
|||
{ |
|||
public: |
|||
DIALOG_SHAPE_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_SHAPE* aShape ); |
|||
|
|||
bool TransferDataToWindow() override; |
|||
bool TransferDataFromWindow() override; |
|||
|
|||
private: |
|||
SCH_SHAPE* m_shape; |
|||
UNIT_BINDER m_lineWidth; |
|||
}; |
|||
|
|||
#endif // DIALOG_SHAPE_PROPERTIES_H |
@ -0,0 +1,146 @@ |
|||
///////////////////////////////////////////////////////////////////////////
|
|||
// C++ code generated with wxFormBuilder (version Oct 26 2018)
|
|||
// http://www.wxformbuilder.org/
|
|||
//
|
|||
// PLEASE DO *NOT* EDIT THIS FILE!
|
|||
///////////////////////////////////////////////////////////////////////////
|
|||
|
|||
#include "widgets/color_swatch.h"
|
|||
|
|||
#include "dialog_shape_properties_base.h"
|
|||
|
|||
///////////////////////////////////////////////////////////////////////////
|
|||
|
|||
BEGIN_EVENT_TABLE( DIALOG_SHAPE_PROPERTIES_BASE, DIALOG_SHIM ) |
|||
EVT_BUTTON( wxID_APPLY, DIALOG_SHAPE_PROPERTIES_BASE::_wxFB_resetDefaults ) |
|||
END_EVENT_TABLE() |
|||
|
|||
DIALOG_SHAPE_PROPERTIES_BASE::DIALOG_SHAPE_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) |
|||
{ |
|||
this->SetSizeHints( wxDefaultSize, wxDefaultSize ); |
|||
|
|||
wxBoxSizer* mainSizer; |
|||
mainSizer = new wxBoxSizer( wxVERTICAL ); |
|||
|
|||
wxFlexGridSizer* fgSizerGeneral; |
|||
fgSizerGeneral = new wxFlexGridSizer( 0, 3, 7, 0 ); |
|||
fgSizerGeneral->AddGrowableCol( 1 ); |
|||
fgSizerGeneral->SetFlexibleDirection( wxBOTH ); |
|||
fgSizerGeneral->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); |
|||
|
|||
m_lineWidthLabel = new wxStaticText( this, wxID_ANY, _("Line width:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_lineWidthLabel->Wrap( -1 ); |
|||
fgSizerGeneral->Add( m_lineWidthLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 3 ); |
|||
|
|||
m_lineWidthCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( -1,-1 ), 0 ); |
|||
fgSizerGeneral->Add( m_lineWidthCtrl, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxRIGHT, 3 ); |
|||
|
|||
m_lineWidthUnits = new wxStaticText( this, wxID_ANY, _("unit"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_lineWidthUnits->Wrap( -1 ); |
|||
m_lineWidthUnits->SetMinSize( wxSize( 40,-1 ) ); |
|||
|
|||
fgSizerGeneral->Add( m_lineWidthUnits, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 3 ); |
|||
|
|||
m_lineColorLabel = new wxStaticText( this, wxID_ANY, _("Line color:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_lineColorLabel->Wrap( -1 ); |
|||
fgSizerGeneral->Add( m_lineColorLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); |
|||
|
|||
m_panel1 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE|wxTAB_TRAVERSAL ); |
|||
wxBoxSizer* bSizer2; |
|||
bSizer2 = new wxBoxSizer( wxVERTICAL ); |
|||
|
|||
m_lineColorSwatch = new COLOR_SWATCH( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
bSizer2->Add( m_lineColorSwatch, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL, 5 ); |
|||
|
|||
|
|||
m_panel1->SetSizer( bSizer2 ); |
|||
m_panel1->Layout(); |
|||
bSizer2->Fit( m_panel1 ); |
|||
fgSizerGeneral->Add( m_panel1, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 2 ); |
|||
|
|||
|
|||
fgSizerGeneral->Add( 0, 0, 1, wxEXPAND, 5 ); |
|||
|
|||
m_lineStyleLabel = new wxStaticText( this, wxID_ANY, _("Line style:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_lineStyleLabel->Wrap( -1 ); |
|||
fgSizerGeneral->Add( m_lineStyleLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); |
|||
|
|||
m_lineStyleCombo = new wxBitmapComboBox( this, wxID_ANY, _("Combo!"), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); |
|||
m_lineStyleCombo->SetMinSize( wxSize( 240,-1 ) ); |
|||
|
|||
fgSizerGeneral->Add( m_lineStyleCombo, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxRIGHT, 3 ); |
|||
|
|||
|
|||
fgSizerGeneral->Add( 0, 0, 1, wxEXPAND, 5 ); |
|||
|
|||
|
|||
fgSizerGeneral->Add( 0, 0, 1, wxEXPAND|wxTOP|wxBOTTOM, 5 ); |
|||
|
|||
|
|||
fgSizerGeneral->Add( 0, 0, 1, wxEXPAND, 5 ); |
|||
|
|||
|
|||
fgSizerGeneral->Add( 0, 0, 1, wxEXPAND, 5 ); |
|||
|
|||
m_filledCtrl = new wxCheckBox( this, wxID_ANY, _("Filled shape"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
fgSizerGeneral->Add( m_filledCtrl, 0, wxALIGN_CENTER_VERTICAL, 5 ); |
|||
|
|||
|
|||
fgSizerGeneral->Add( 0, 0, 1, wxEXPAND, 5 ); |
|||
|
|||
|
|||
fgSizerGeneral->Add( 0, 0, 1, wxEXPAND, 5 ); |
|||
|
|||
m_fillColorLabel = new wxStaticText( this, wxID_ANY, _("Fill color:"), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_fillColorLabel->Wrap( -1 ); |
|||
fgSizerGeneral->Add( m_fillColorLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); |
|||
|
|||
m_panel11 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE|wxTAB_TRAVERSAL ); |
|||
wxBoxSizer* bSizer21; |
|||
bSizer21 = new wxBoxSizer( wxVERTICAL ); |
|||
|
|||
m_fillColorSwatch = new COLOR_SWATCH( m_panel11, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); |
|||
bSizer21->Add( m_fillColorSwatch, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL, 5 ); |
|||
|
|||
|
|||
m_panel11->SetSizer( bSizer21 ); |
|||
m_panel11->Layout(); |
|||
bSizer21->Fit( m_panel11 ); |
|||
fgSizerGeneral->Add( m_panel11, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); |
|||
|
|||
|
|||
mainSizer->Add( fgSizerGeneral, 1, wxEXPAND|wxTOP|wxBOTTOM|wxLEFT, 10 ); |
|||
|
|||
m_helpLabel1 = new wxStaticText( this, wxID_ANY, _("Set line width to 0 to use Schematic Editor line widths."), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_helpLabel1->Wrap( 333 ); |
|||
mainSizer->Add( m_helpLabel1, 0, wxTOP|wxRIGHT|wxLEFT, 10 ); |
|||
|
|||
m_helpLabel2 = new wxStaticText( this, wxID_ANY, _("Set line color to transparent to use Schematic Editor colors."), wxDefaultPosition, wxDefaultSize, 0 ); |
|||
m_helpLabel2->Wrap( -1 ); |
|||
mainSizer->Add( m_helpLabel2, 0, wxBOTTOM|wxRIGHT|wxLEFT, 10 ); |
|||
|
|||
m_staticline = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); |
|||
mainSizer->Add( m_staticline, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); |
|||
|
|||
m_sdbSizer = new wxStdDialogButtonSizer(); |
|||
m_sdbSizerOK = new wxButton( this, wxID_OK ); |
|||
m_sdbSizer->AddButton( m_sdbSizerOK ); |
|||
m_sdbSizerApply = new wxButton( this, wxID_APPLY ); |
|||
m_sdbSizer->AddButton( m_sdbSizerApply ); |
|||
m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); |
|||
m_sdbSizer->AddButton( m_sdbSizerCancel ); |
|||
m_sdbSizer->Realize(); |
|||
|
|||
mainSizer->Add( m_sdbSizer, 0, wxALL|wxALIGN_RIGHT, 5 ); |
|||
|
|||
|
|||
this->SetSizer( mainSizer ); |
|||
this->Layout(); |
|||
mainSizer->Fit( this ); |
|||
|
|||
this->Centre( wxBOTH ); |
|||
} |
|||
|
|||
DIALOG_SHAPE_PROPERTIES_BASE::~DIALOG_SHAPE_PROPERTIES_BASE() |
|||
{ |
|||
} |
1099
eeschema/dialogs/dialog_shape_properties_base.fbp
File diff suppressed because it is too large
View File
@ -0,0 +1,76 @@ |
|||
/////////////////////////////////////////////////////////////////////////// |
|||
// C++ code generated with wxFormBuilder (version Oct 26 2018) |
|||
// http://www.wxformbuilder.org/ |
|||
// |
|||
// PLEASE DO *NOT* EDIT THIS FILE! |
|||
/////////////////////////////////////////////////////////////////////////// |
|||
|
|||
#pragma once |
|||
|
|||
#include <wx/artprov.h> |
|||
#include <wx/xrc/xmlres.h> |
|||
#include <wx/intl.h> |
|||
class COLOR_SWATCH; |
|||
|
|||
#include "dialog_shim.h" |
|||
#include <wx/string.h> |
|||
#include <wx/stattext.h> |
|||
#include <wx/gdicmn.h> |
|||
#include <wx/font.h> |
|||
#include <wx/colour.h> |
|||
#include <wx/settings.h> |
|||
#include <wx/textctrl.h> |
|||
#include <wx/sizer.h> |
|||
#include <wx/panel.h> |
|||
#include <wx/bmpcbox.h> |
|||
#include <wx/checkbox.h> |
|||
#include <wx/statline.h> |
|||
#include <wx/button.h> |
|||
#include <wx/dialog.h> |
|||
|
|||
/////////////////////////////////////////////////////////////////////////// |
|||
|
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
/// Class DIALOG_SHAPE_PROPERTIES_BASE |
|||
/////////////////////////////////////////////////////////////////////////////// |
|||
class DIALOG_SHAPE_PROPERTIES_BASE : public DIALOG_SHIM |
|||
{ |
|||
DECLARE_EVENT_TABLE() |
|||
private: |
|||
|
|||
// Private event handlers |
|||
void _wxFB_resetDefaults( wxCommandEvent& event ){ resetDefaults( event ); } |
|||
|
|||
|
|||
protected: |
|||
wxStaticText* m_lineWidthLabel; |
|||
wxTextCtrl* m_lineWidthCtrl; |
|||
wxStaticText* m_lineWidthUnits; |
|||
wxStaticText* m_lineColorLabel; |
|||
wxPanel* m_panel1; |
|||
COLOR_SWATCH* m_lineColorSwatch; |
|||
wxStaticText* m_lineStyleLabel; |
|||
wxBitmapComboBox* m_lineStyleCombo; |
|||
wxCheckBox* m_filledCtrl; |
|||
wxStaticText* m_fillColorLabel; |
|||
wxPanel* m_panel11; |
|||
COLOR_SWATCH* m_fillColorSwatch; |
|||
wxStaticText* m_helpLabel1; |
|||
wxStaticText* m_helpLabel2; |
|||
wxStaticLine* m_staticline; |
|||
wxStdDialogButtonSizer* m_sdbSizer; |
|||
wxButton* m_sdbSizerOK; |
|||
wxButton* m_sdbSizerApply; |
|||
wxButton* m_sdbSizerCancel; |
|||
|
|||
// Virtual event handlers, overide them in your derived class |
|||
virtual void resetDefaults( wxCommandEvent& event ) { event.Skip(); } |
|||
|
|||
|
|||
public: |
|||
|
|||
DIALOG_SHAPE_PROPERTIES_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("%s Properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); |
|||
~DIALOG_SHAPE_PROPERTIES_BASE(); |
|||
|
|||
}; |
|||
|
@ -0,0 +1,422 @@ |
|||
/*
|
|||
* 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) 2004-2021 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 |
|||
* 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 |
|||
*/ |
|||
|
|||
#include <sch_draw_panel.h>
|
|||
#include <macros.h>
|
|||
#include <plotters/plotter.h>
|
|||
#include <base_units.h>
|
|||
#include <widgets/msgpanel.h>
|
|||
#include <bitmaps.h>
|
|||
#include <eda_draw_frame.h>
|
|||
#include <general.h>
|
|||
#include <sch_shape.h>
|
|||
|
|||
|
|||
SCH_SHAPE::SCH_SHAPE( SHAPE_T aShape, int aLineWidth, FILL_T aFillType ) : |
|||
SCH_ITEM( nullptr, SCH_SHAPE_T ), |
|||
EDA_SHAPE( aShape, aLineWidth, aFillType, true ) |
|||
{ |
|||
SetLayer( LAYER_NOTES ); |
|||
} |
|||
|
|||
|
|||
EDA_ITEM* SCH_SHAPE::Clone() const |
|||
{ |
|||
return new SCH_SHAPE( *this ); |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::SetStroke( const STROKE_PARAMS& aStroke ) |
|||
{ |
|||
m_stroke = aStroke; |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::Move( const wxPoint& aOffset ) |
|||
{ |
|||
move( aOffset ); |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::MirrorHorizontally( int aCenter ) |
|||
{ |
|||
flip( wxPoint( aCenter, 0 ), true ); |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::MirrorVertically( int aCenter ) |
|||
{ |
|||
flip( wxPoint( 0, aCenter ), false ); |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::Rotate( const wxPoint& aCenter ) |
|||
{ |
|||
rotate( aCenter, 900 ); |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::Plot( PLOTTER* aPlotter ) const |
|||
{ |
|||
int pen_size = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetMinPenWidth() ); |
|||
wxPoint center; |
|||
int radius; |
|||
int startAngle; |
|||
int endAngle; |
|||
|
|||
static std::vector<wxPoint> cornerList; |
|||
|
|||
if( GetShape() == SHAPE_T::POLY ) |
|||
{ |
|||
cornerList.clear(); |
|||
|
|||
for( const VECTOR2I& pt : m_poly.Outline( 0 ).CPoints() ) |
|||
cornerList.push_back( (wxPoint) pt ); |
|||
} |
|||
else if( GetShape() == SHAPE_T::ARC ) |
|||
{ |
|||
center = getCenter(); |
|||
radius = GetRadius(); |
|||
CalcArcAngles( startAngle, endAngle ); |
|||
} |
|||
|
|||
if( GetStroke().GetColor() == COLOR4D::UNSPECIFIED ) |
|||
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_NOTES ) ); |
|||
else |
|||
aPlotter->SetColor( GetStroke().GetColor() ); |
|||
|
|||
aPlotter->SetCurrentLineWidth( pen_size ); |
|||
aPlotter->SetDash( GetStroke().GetPlotStyle() ); |
|||
|
|||
switch( GetShape() ) |
|||
{ |
|||
case SHAPE_T::ARC: |
|||
// TODO: doesn't work for dash styles
|
|||
aPlotter->Arc( center, -endAngle, -startAngle, radius, FILL_T::NO_FILL, pen_size ); |
|||
break; |
|||
|
|||
case SHAPE_T::CIRCLE: |
|||
// TODO: doesn't work for dash styles
|
|||
aPlotter->Circle( GetStart(), GetRadius() * 2, FILL_T::NO_FILL, pen_size ); |
|||
break; |
|||
|
|||
case SHAPE_T::RECT: |
|||
{ |
|||
std::vector<wxPoint> pts = GetRectCorners(); |
|||
|
|||
aPlotter->MoveTo( pts[0] ); |
|||
aPlotter->LineTo( pts[1] ); |
|||
aPlotter->LineTo( pts[2] ); |
|||
aPlotter->LineTo( pts[3] ); |
|||
aPlotter->FinishTo( pts[0] ); |
|||
} |
|||
break; |
|||
|
|||
case SHAPE_T::POLY: |
|||
{ |
|||
aPlotter->MoveTo( cornerList[0] ); |
|||
|
|||
for( size_t ii = 1; ii < cornerList.size(); ++ii ) |
|||
aPlotter->LineTo( cornerList[ii] ); |
|||
|
|||
aPlotter->FinishTo( cornerList[0] ); |
|||
} |
|||
break; |
|||
|
|||
case SHAPE_T::BEZIER: |
|||
// TODO: doesn't work for dash styles
|
|||
aPlotter->PlotPoly( m_bezierPoints, FILL_T::NO_FILL, pen_size ); |
|||
break; |
|||
|
|||
default: |
|||
UNIMPLEMENTED_FOR( SHAPE_T_asString() ); |
|||
} |
|||
|
|||
aPlotter->SetDash( PLOT_DASH_TYPE::SOLID ); |
|||
|
|||
if( m_fill == FILL_T::FILLED_WITH_COLOR && GetFillColor() != COLOR4D::UNSPECIFIED ) |
|||
{ |
|||
aPlotter->SetColor( GetFillColor() ); |
|||
|
|||
switch( GetShape() ) |
|||
{ |
|||
case SHAPE_T::ARC: |
|||
aPlotter->Arc( center, -endAngle, -startAngle, radius, m_fill, 0 ); |
|||
break; |
|||
|
|||
case SHAPE_T::CIRCLE: |
|||
aPlotter->Circle( GetStart(), GetRadius() * 2, m_fill, 0 ); |
|||
break; |
|||
|
|||
case SHAPE_T::RECT: |
|||
aPlotter->Rect( GetStart(), GetEnd(), m_fill, 0 ); |
|||
break; |
|||
|
|||
case SHAPE_T::POLY: |
|||
aPlotter->PlotPoly( cornerList, m_fill, 0 ); |
|||
break; |
|||
|
|||
case SHAPE_T::BEZIER: |
|||
aPlotter->PlotPoly( m_bezierPoints, m_fill, 0 ); |
|||
break; |
|||
|
|||
default: |
|||
UNIMPLEMENTED_FOR( SHAPE_T_asString() ); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
int SCH_SHAPE::GetPenWidth() const |
|||
{ |
|||
// Historically 0 meant "default width" and negative numbers meant "don't stroke".
|
|||
if( GetWidth() < 0 && GetFillMode() != FILL_T::NO_FILL ) |
|||
return 0; |
|||
else |
|||
return std::max( GetWidth(), 1 ); |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) |
|||
{ |
|||
int penWidth = GetPenWidth(); |
|||
wxDC* DC = aSettings->GetPrintDC(); |
|||
wxPoint pt1 = GetStart(); |
|||
wxPoint pt2 = GetEnd(); |
|||
wxPoint c; |
|||
COLOR4D color; |
|||
|
|||
penWidth = std::max( penWidth, aSettings->GetDefaultPenWidth() ); |
|||
|
|||
unsigned ptCount = 0; |
|||
wxPoint* buffer = nullptr; |
|||
|
|||
if( GetShape() == SHAPE_T::POLY ) |
|||
{ |
|||
SHAPE_LINE_CHAIN poly = m_poly.Outline( 0 ); |
|||
|
|||
ptCount = poly.GetPointCount(); |
|||
buffer = new wxPoint[ ptCount ]; |
|||
|
|||
for( unsigned ii = 0; ii < ptCount; ++ii ) |
|||
buffer[ii] = (wxPoint) poly.CPoint( ii ); |
|||
} |
|||
else if( GetShape() == SHAPE_T::BEZIER ) |
|||
{ |
|||
ptCount = m_bezierPoints.size(); |
|||
buffer = new wxPoint[ ptCount ]; |
|||
|
|||
for( size_t ii = 0; ii < ptCount; ++ii ) |
|||
buffer[ii] = m_bezierPoints[ii]; |
|||
} |
|||
else if( GetShape() == SHAPE_T::ARC ) |
|||
{ |
|||
c = getCenter(); |
|||
int t1, t2; |
|||
|
|||
CalcArcAngles( t1, t2 ); |
|||
|
|||
if( NormalizeAngle180( t1 - t2 ) > 0 ) |
|||
std::swap( pt1, pt2 ); |
|||
} |
|||
|
|||
if( GetFillMode() == FILL_T::FILLED_WITH_COLOR ) |
|||
{ |
|||
color = GetFillColor(); |
|||
|
|||
switch( GetShape() ) |
|||
{ |
|||
case SHAPE_T::ARC: |
|||
GRFilledArc1( nullptr, DC, pt1, pt2, c, 0, color, color ); |
|||
break; |
|||
|
|||
case SHAPE_T::CIRCLE: |
|||
GRFilledCircle( nullptr, DC, pt1.x, pt1.y, GetRadius(), 0, color, color ); |
|||
break; |
|||
|
|||
case SHAPE_T::RECT: |
|||
GRFilledRect( nullptr, DC, pt1.x, pt1.y, pt2.x, pt2.y, 0, color, color ); |
|||
break; |
|||
|
|||
case SHAPE_T::POLY: |
|||
GRPoly( nullptr, DC, ptCount, buffer, true, 0, color, color ); |
|||
break; |
|||
|
|||
case SHAPE_T::BEZIER: |
|||
GRPoly( nullptr, DC, ptCount, buffer, true, 0, color, color ); |
|||
break; |
|||
|
|||
default: |
|||
UNIMPLEMENTED_FOR( SHAPE_T_asString() ); |
|||
} |
|||
} |
|||
|
|||
if( GetStroke().GetColor() == COLOR4D::UNSPECIFIED ) |
|||
color = aSettings->GetLayerColor( LAYER_NOTES ); |
|||
else |
|||
color = GetStroke().GetColor(); |
|||
|
|||
if( GetStroke().GetPlotStyle() <= PLOT_DASH_TYPE::FIRST_TYPE ) |
|||
{ |
|||
switch( GetShape() ) |
|||
{ |
|||
case SHAPE_T::ARC: |
|||
GRArc1( nullptr, DC, pt1, pt2, c, penWidth, color ); |
|||
break; |
|||
|
|||
case SHAPE_T::CIRCLE: |
|||
GRCircle( nullptr, DC, pt1.x, pt1.y, GetRadius(), penWidth, color ); |
|||
break; |
|||
|
|||
case SHAPE_T::RECT: |
|||
GRRect( nullptr, DC, pt1.x, pt1.y, pt2.x, pt2.y, penWidth, color ); |
|||
break; |
|||
|
|||
case SHAPE_T::POLY: |
|||
GRPoly( nullptr, DC, ptCount, buffer, false, penWidth, color, color ); |
|||
break; |
|||
|
|||
case SHAPE_T::BEZIER: |
|||
GRPoly( nullptr, DC, ptCount, buffer, false, penWidth, color, color ); |
|||
break; |
|||
|
|||
default: |
|||
UNIMPLEMENTED_FOR( SHAPE_T_asString() ); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
std::vector<SHAPE*> shapes = MakeEffectiveShapes( true ); |
|||
|
|||
for( SHAPE* shape : shapes ) |
|||
{ |
|||
STROKE_PARAMS::Stroke( shape, GetStroke().GetPlotStyle(), penWidth, aSettings, |
|||
[&]( const wxPoint& a, const wxPoint& b ) |
|||
{ |
|||
GRLine( nullptr, DC, a.x, a.y, b.x, b.y, penWidth, color ); |
|||
} ); |
|||
} |
|||
|
|||
for( SHAPE* shape : shapes ) |
|||
delete shape; |
|||
} |
|||
|
|||
delete[] buffer; |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) |
|||
{ |
|||
SCH_ITEM::GetMsgPanelInfo( aFrame, aList ); |
|||
|
|||
ShapeGetMsgPanelInfo( aFrame, aList ); |
|||
} |
|||
|
|||
|
|||
wxString SCH_SHAPE::GetSelectMenuText( EDA_UNITS aUnits ) const |
|||
{ |
|||
switch( GetShape() ) |
|||
{ |
|||
case SHAPE_T::ARC: |
|||
return wxString::Format( _( "Arc, radius %s" ), |
|||
MessageTextFromValue( aUnits, GetRadius() ) ); |
|||
|
|||
case SHAPE_T::CIRCLE: |
|||
return wxString::Format( _( "Circle, radius %s" ), |
|||
MessageTextFromValue( aUnits, GetRadius() ) ); |
|||
|
|||
case SHAPE_T::RECT: |
|||
return wxString::Format( _( "Rectangle, width %s height %s" ), |
|||
MessageTextFromValue( aUnits, std::abs( m_start.x - m_end.x ) ), |
|||
MessageTextFromValue( aUnits, std::abs( m_start.y - m_end.y ) ) ); |
|||
|
|||
case SHAPE_T::POLY: |
|||
return wxString::Format( _( "Polyline, %d points" ), |
|||
int( m_poly.Outline( 0 ).GetPointCount() ) ); |
|||
|
|||
case SHAPE_T::BEZIER: |
|||
return wxString::Format( _( "Bezier Curve, %d points" ), |
|||
int( m_bezierPoints.size() ) ); |
|||
|
|||
default: |
|||
UNIMPLEMENTED_FOR( SHAPE_T_asString() ); |
|||
return wxEmptyString; |
|||
} |
|||
} |
|||
|
|||
|
|||
BITMAPS SCH_SHAPE::GetMenuImage() const |
|||
{ |
|||
switch( GetShape() ) |
|||
{ |
|||
case SHAPE_T::SEGMENT: return BITMAPS::add_line; |
|||
case SHAPE_T::ARC: return BITMAPS::add_arc; |
|||
case SHAPE_T::CIRCLE: return BITMAPS::add_circle; |
|||
case SHAPE_T::RECT: return BITMAPS::add_rectangle; |
|||
case SHAPE_T::POLY: return BITMAPS::add_graphical_segments; |
|||
|
|||
default: |
|||
UNIMPLEMENTED_FOR( SHAPE_T_asString() ); |
|||
return BITMAPS::question_mark; |
|||
} |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::ViewGetLayers( int aLayers[], int& aCount ) const |
|||
{ |
|||
aCount = 3; |
|||
aLayers[0] = LAYER_NOTES; |
|||
aLayers[1] = LAYER_NOTES_BACKGROUND; |
|||
aLayers[2] = LAYER_SELECTION_SHADOWS; |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::AddPoint( const wxPoint& aPosition ) |
|||
{ |
|||
if( GetShape() == SHAPE_T::POLY ) |
|||
{ |
|||
if( m_poly.IsEmpty() ) |
|||
m_poly.NewOutline(); |
|||
|
|||
m_poly.Outline( 0 ).Append( aPosition, true ); |
|||
} |
|||
else |
|||
{ |
|||
UNIMPLEMENTED_FOR( SHAPE_T_asString() ); |
|||
} |
|||
} |
|||
|
|||
|
|||
void SCH_SHAPE::CalcArcAngles( int& aStartAngle, int& aEndAngle ) const |
|||
{ |
|||
double start; |
|||
double end; |
|||
|
|||
EDA_SHAPE::CalcArcAngles( start, end ); |
|||
|
|||
aStartAngle = KiROUND( start * 10.0 ); |
|||
aEndAngle = KiROUND( end * 10.0 ); |
|||
} |
|||
|
|||
|
@ -0,0 +1,119 @@ |
|||
/* |
|||
* 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) 2004-2021 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 |
|||
* 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 |
|||
*/ |
|||
|
|||
#ifndef SCH_SHAPE_H |
|||
#define SCH_SHAPE_H |
|||
|
|||
#include <sch_item.h> |
|||
#include <eda_shape.h> |
|||
|
|||
|
|||
class SCH_SHAPE : public SCH_ITEM, public EDA_SHAPE |
|||
{ |
|||
public: |
|||
SCH_SHAPE( SHAPE_T aShape, int aLineWidth = 0, FILL_T aFillType = FILL_T::NO_FILL ); |
|||
|
|||
// Do not create a copy constructor. The one generated by the compiler is adequate. |
|||
|
|||
~SCH_SHAPE() { } |
|||
|
|||
wxString GetClass() const override |
|||
{ |
|||
return wxT( "SCH_SHAPE" ); |
|||
} |
|||
|
|||
bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override |
|||
{ |
|||
return hitTest( aPosition, aAccuracy ); |
|||
} |
|||
|
|||
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override |
|||
{ |
|||
return hitTest( aRect, aContained, aAccuracy ); |
|||
} |
|||
|
|||
int GetPenWidth() const override; |
|||
|
|||
bool HasLineStroke() const override { return true; } |
|||
STROKE_PARAMS GetStroke() const override { return m_stroke; } |
|||
void SetStroke( const STROKE_PARAMS& aStroke ) override; |
|||
|
|||
PLOT_DASH_TYPE GetEffectiveLineStyle() const |
|||
{ |
|||
if( IsFilled() ) |
|||
return PLOT_DASH_TYPE::SOLID; |
|||
else if( m_stroke.GetPlotStyle() == PLOT_DASH_TYPE::DEFAULT ) |
|||
return PLOT_DASH_TYPE::DASH; |
|||
else |
|||
return m_stroke.GetPlotStyle(); |
|||
} |
|||
|
|||
const EDA_RECT GetBoundingBox() const override { return getBoundingBox(); } |
|||
|
|||
wxPoint GetPosition() const override { return getPosition(); } |
|||
void SetPosition( const wxPoint& aPos ) override { setPosition( aPos ); } |
|||
|
|||
wxPoint GetCenter() const { return getCenter(); } |
|||
|
|||
void CalcArcAngles( int& aStartAngle, int& aEndAngle ) const; |
|||
|
|||
void BeginEdit( const wxPoint& aStartPoint ) { beginEdit( aStartPoint ); } |
|||
bool ContinueEdit( const wxPoint& aPosition ) { return continueEdit( aPosition ); } |
|||
void CalcEdit( const wxPoint& aPosition ) { calcEdit( aPosition ); } |
|||
void EndEdit() { endEdit(); } |
|||
void SetEditState( int aState ) { setEditState( aState ); } |
|||
|
|||
void Move( const wxPoint& aOffset ) override; |
|||
|
|||
void MirrorHorizontally( int aCenter ) override; |
|||
void MirrorVertically( int aCenter ) override; |
|||
void Rotate( const wxPoint& aCenter ) override; |
|||
|
|||
void AddPoint( const wxPoint& aPosition ); |
|||
|
|||
void Plot( PLOTTER* aPlotter ) const override; |
|||
|
|||
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override; |
|||
|
|||
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override; |
|||
|
|||
BITMAPS GetMenuImage() const override; |
|||
|
|||
EDA_ITEM* Clone() const override; |
|||
|
|||
void ViewGetLayers( int aLayers[], int& aCount ) const override; |
|||
|
|||
#if defined(DEBUG) |
|||
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } |
|||
#endif |
|||
|
|||
private: |
|||
void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override; |
|||
|
|||
double getParentOrientation() const override { return 0.0; } |
|||
wxPoint getParentPosition() const override { return wxPoint(); } |
|||
}; |
|||
|
|||
|
|||
#endif // SCH_SHAPE_H |
@ -0,0 +1,145 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2021 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 |
|||
* 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 |
|||
*/ |
|||
|
|||
#ifndef STROKE_PARAMS_H |
|||
#define STROKE_PARAMS_H |
|||
|
|||
#include <map> |
|||
#include <bitmaps.h> |
|||
#include <gal/color4d.h> |
|||
#include <wx/translation.h> |
|||
#include <geometry/shape.h> |
|||
#include <stroke_params_lexer.h> |
|||
|
|||
class STROKE_PARAMS_LEXER; |
|||
|
|||
namespace KIGFX |
|||
{ |
|||
class RENDER_SETTINGS; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Dashed line types. |
|||
*/ |
|||
enum class PLOT_DASH_TYPE |
|||
{ |
|||
DEFAULT = -1, |
|||
SOLID = 0, |
|||
FIRST_TYPE = SOLID, |
|||
DASH, |
|||
DOT, |
|||
DASHDOT, |
|||
LAST_TYPE = DASHDOT |
|||
}; |
|||
|
|||
|
|||
struct lineTypeStruct |
|||
{ |
|||
wxString name; |
|||
const BITMAPS bitmap; |
|||
}; |
|||
|
|||
|
|||
/* |
|||
* Conversion map between PLOT_DASH_TYPE values and style names displayed |
|||
*/ |
|||
const std::map<PLOT_DASH_TYPE, struct lineTypeStruct> lineTypeNames = |
|||
{ |
|||
{ PLOT_DASH_TYPE::SOLID, { _( "Solid" ), BITMAPS::stroke_solid } }, |
|||
{ PLOT_DASH_TYPE::DASH, { _( "Dashed" ), BITMAPS::stroke_dash } }, |
|||
{ PLOT_DASH_TYPE::DOT, { _( "Dotted" ), BITMAPS::stroke_dot } }, |
|||
{ PLOT_DASH_TYPE::DASHDOT, { _( "Dash-Dot" ), BITMAPS::stroke_dashdot } } |
|||
}; |
|||
|
|||
|
|||
#define DEFAULT_STYLE _( "Default" ) |
|||
#define INDETERMINATE_STYLE _( "Leave unchanged" ) |
|||
|
|||
|
|||
/** |
|||
* Simple container to manage line stroke parameters. |
|||
*/ |
|||
class STROKE_PARAMS |
|||
{ |
|||
public: |
|||
STROKE_PARAMS( int aWidth = 0, PLOT_DASH_TYPE aPlotStyle = PLOT_DASH_TYPE::DEFAULT, |
|||
const KIGFX::COLOR4D& aColor = KIGFX::COLOR4D::UNSPECIFIED ) : |
|||
m_width( aWidth ), |
|||
m_plotstyle( aPlotStyle ), |
|||
m_color( aColor ) |
|||
{ |
|||
} |
|||
|
|||
int GetWidth() const { return m_width; } |
|||
void SetWidth( int aWidth ) { m_width = aWidth; } |
|||
|
|||
PLOT_DASH_TYPE GetPlotStyle() const { return m_plotstyle; } |
|||
void SetPlotStyle( PLOT_DASH_TYPE aPlotStyle ) { m_plotstyle = aPlotStyle; } |
|||
|
|||
KIGFX::COLOR4D GetColor() const { return m_color; } |
|||
void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; } |
|||
|
|||
bool operator!=( const STROKE_PARAMS& aOther ) |
|||
{ |
|||
return m_width != aOther.m_width |
|||
|| m_plotstyle != aOther.m_plotstyle |
|||
|| m_color != aOther.m_color; |
|||
} |
|||
|
|||
void Format( OUTPUTFORMATTER* out, int nestLevel ) const; |
|||
|
|||
// Helper functions |
|||
|
|||
static void Stroke( const SHAPE* aShape, PLOT_DASH_TYPE aLineStyle, int aWidth, |
|||
const KIGFX::RENDER_SETTINGS* aRenderSettings, |
|||
std::function<void( const wxPoint& a, const wxPoint& b )> aStroker ); |
|||
|
|||
private: |
|||
int m_width; |
|||
PLOT_DASH_TYPE m_plotstyle; |
|||
KIGFX::COLOR4D m_color; |
|||
}; |
|||
|
|||
|
|||
class STROKE_PARAMS_PARSER : public STROKE_PARAMS_LEXER |
|||
{ |
|||
public: |
|||
STROKE_PARAMS_PARSER( LINE_READER* aReader, int iuPerMM ) : |
|||
STROKE_PARAMS_LEXER( aReader ), |
|||
m_iuPerMM( iuPerMM ) |
|||
{ |
|||
} |
|||
|
|||
void ParseStroke( STROKE_PARAMS& aStroke ); |
|||
|
|||
private: |
|||
int parseInt( const char* aText ); |
|||
double parseDouble( const char* aText ); |
|||
|
|||
private: |
|||
int m_iuPerMM; |
|||
}; |
|||
|
|||
|
|||
#endif // STROKE_PARAMS_H |