KiCad PCB EDA Suite
test_gal_pixel_alignment.cpp
Go to the documentation of this file.
1#include <pcb_test_frame.h>
2#include <tool/tool_manager.h>
3
5#include <view/view.h>
6#include <view/view_item.h>
8
9#include <layer_ids.h>
10
11const VECTOR2D xform2( const MATRIX3x3D& minv, const VECTOR2D& p )
12{
13 auto t = minv * p;
14 return VECTOR2D((float)t.x, (float)t.y);
15}
16
17void screenSpaceLine( KIGFX::GAL* gal, const VECTOR2D& p0, const VECTOR2D& p1, double w )
18{
19 auto minv = gal->GetScreenWorldMatrix();
20
21 auto pa = xform2 ( minv, p0 );
22 auto pb = xform2 ( minv, p1 );
23
24#if 0
25 //shader->Deactivate();
26
27 m_currentManager->Reserve( 6 );
28 m_currentManager->Shader( SHADER_NONE );
29 m_currentManager->Color( m_strokeColor.r, m_strokeColor.g, m_strokeColor.b, m_strokeColor.a );
30
31 m_currentManager->Shader( SHADER_NONE ); m_currentManager->Vertex( pa.x, pa.y, m_layerDepth );
32 m_currentManager->Shader( SHADER_NONE ); m_currentManager->Vertex( pb.x, pb.y, m_layerDepth );
33 m_currentManager->Shader( SHADER_NONE ); m_currentManager->Vertex( pc.x, pc.y, m_layerDepth );
34 m_currentManager->Shader( SHADER_NONE ); m_currentManager->Vertex( pa.x, pa.y, m_layerDepth );
35 m_currentManager->Shader( SHADER_NONE ); m_currentManager->Vertex( pc.x, pc.y, m_layerDepth );
36 m_currentManager->Shader( SHADER_NONE ); m_currentManager->Vertex( pd.x, pd.y, m_layerDepth );
37 shader->Use();
38#endif
39
40 gal->SetLineWidth( w * minv.GetScale().x );
41 gal->DrawLine( pa, pb );
42
43
44}
45
46void screenSpaceCircle( KIGFX::GAL* gal, const VECTOR2D& p0, double r, double w )
47{
48 auto minv = gal->GetScreenWorldMatrix();
49
50 auto pa = xform2 ( minv, p0 );
51
52 gal->SetLineWidth( w * minv.GetScale().x );
53 gal->DrawCircle( pa, r * minv.GetScale().x );
54
55}
56
57
58class MY_DRAWING : public EDA_ITEM
59{
60public:
62 virtual ~MY_DRAWING(){};
63
64 wxString GetClass() const override
65 {
66 return wxT( "MyDrawing" );
67 }
68
69#ifdef DEBUG
70 virtual void Show( int nestLevel, std::ostream& os ) const override {}
71#endif
72
73 const BOX2I ViewBBox() const override
74 {
75 BOX2I bb;
76 bb.SetMaximum();
77 return bb;
78 }
79
80 virtual void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override
81 {
82 auto gal = aView->GetGAL();
84 gal->SetIsStroke( true );
85 gal->SetStrokeColor( COLOR4D::WHITE );
86
87 /* for( int i=0;i < 100; i++ )
88 {
89 gal->SetLineWidth( 10000 );
90 gal->DrawLine( VECTOR2I(0, i * 30000), VECTOR2I(1000000, i * 30000) );
91 gal->DrawLine( VECTOR2I(- 2000000 + i * 30000, 0), VECTOR2I(- 2000000 + i * 30000, 1000000) );
92 }
93
94 for( float alpha = 0.0; alpha <= 360.0; alpha += 6.0)
95 {
96 float ca = cos(alpha * M_PI / 180.0);
97 float sa = sin(alpha * M_PI / 180.0);
98 VECTOR2I p0(2000000, 0);
99 float r = 800000.0;
100 gal->DrawLine( p0, p0 + VECTOR2I( r*ca, r*sa));
101 }
102 */
103
104 int k = 0;
105 double w = 0.0;
106 //gal->Rotate( 1.0 / 3.0 * M_PI );
107 for(int step = 10; step < 80; step += 11, k+=100)
108 {
109 for (int i = 0; i < 100; i++)
110 {
111 /*auto p0 = VECTOR2D( k + 100, 100 + i * step );
112 auto p1 = VECTOR2D( k + 100 + step/2, 100 + i * step );
113 auto p2 = VECTOR2D( k + 100 + step/2, 100 + i * step + step/2 );
114 auto p3 = VECTOR2D( k + 100, 100 + i * step + step/2 );
115 auto p4 = VECTOR2D( k + 100, 100 + i * step + step );*/
116
117 auto p0 = VECTOR2D( k + 100, 100 + i * step );
118 auto p1 = VECTOR2D( k + 100 + step/2, 100 + i * step );
119 auto p2 = VECTOR2D( k + 100 + step/2, 100 + i * step + step/2 );
120 auto p3 = VECTOR2D( k + 100, 100 + i * step + step/2 );
121 // auto p4 = VECTOR2D( k + 100, 100 + i * step + step );
122
123
124 screenSpaceLine( gal, p0, p1 , w);
125 screenSpaceLine( gal, p3, p2 , w);
126
127 p0 += VECTOR2D(50, 0);
128 p1 += VECTOR2D(50, 0);
129 p2 += VECTOR2D(50, 0);
130 p3 += VECTOR2D(50, 0);
131
132 screenSpaceLine( gal, p0, p3 , w);
133 screenSpaceLine( gal, p1, p2 , w);
134
135
136 /* screenSpaceLine( gal, p1, p2 , w);
137 screenSpaceLine( gal, p2, p3 , w);
138 screenSpaceLine( gal, p3, p4 , w);
139
140 std::swap(p0.x, p0.y );
141 std::swap(p1.x, p1.y );
142 std::swap(p2.x, p2.y );
143 std::swap(p3.x, p3.y );
144 std::swap(p4.x, p4.y );
145
146 screenSpaceLine( gal, p0, p1 , w);
147 screenSpaceLine( gal, p1, p2 , w);
148 screenSpaceLine( gal, p2, p3 , w);
149 screenSpaceLine( gal, p3, p4 , w);*/
150 }
151 }
152
153 /*
154 for(int i=0;i < 1000; i++)
155 {
156 int k = 0;
157
158 for(double w=1.0; w<=8.0; w+=1.0, k += 50)
159 {
160 //screenSpaceLine( gal, VECTOR2D( k, i*step ), VECTOR2D( k, i*step ) + VECTOR2D( 50, 0 ), w );
161 //screenSpaceLine( gal, VECTOR2D( i*step, k ), VECTOR2D( i*step, k ) + VECTOR2D( 0, 50 ), w );
162 }
163
164
165 //gal->ScreenSpaceQuad( VECTOR2D( 250, 100 + i*8 ), VECTOR2D( 100, 2 ) );
166 //gal->ScreenSpaceQuad( VECTOR2D( 400, 100 + i*4 + 0.5 ), VECTOR2D( 100, 1 ) );
167 //gal->ScreenSpaceQuad( VECTOR2D( 550, 100 + i*8 + 0.5 ), VECTOR2D( 100, 2 ) );
168
169 }*/
170
171 for(int i = 1; i < 16; i+=1)
172 {
173 for(int j = 1; j < 16; j+=1)
174 {
175 gal->SetIsStroke( true );
176 gal->SetIsFill( false );
177 //screenSpaceCircle(gal, VECTOR2D(100 + i * 25, 100 + j * 25), (float)i/2.0, 1);
178 gal->SetIsStroke( false );
179 gal->SetIsFill( true );
180 //screenSpaceCircle(gal, VECTOR2D(100 + i * 25, 500 + 100 + j * 25), (float)i/2.0, 1);
181 }
182 }
183 }
184
185 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override
186 {
187 aLayers[0] = LAYER_GP_OVERLAY;
188 aCount = 1;
189 }
190};
191
192class MY_PCB_TEST_FRAME : public PCB_TEST_FRAME
193{
194public:
195 MY_PCB_TEST_FRAME( wxFrame* frame, const wxString& title,
196 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
197 long style = wxDEFAULT_FRAME_STYLE )
198 : PCB_TEST_FRAME( frame, title, pos, size, style, PCB_DRAW_PANEL_GAL::GAL_TYPE_OPENGL )
199 {
201 m_galPanel->GetView()->Add( new MY_DRAWING );
202 m_galPanel->GetView()->SetScale( 41.3526000000, VECTOR2D( 837362.6373626292, 1581684.9816849837 ) );
203
204 }
205
206 void registerTools();
207
209 {
210 }
211};
212
213wxFrame* CreateMainFrame( const std::string& aFileName )
214{
215 auto frame = new MY_PCB_TEST_FRAME( nullptr, wxT( "Test PCB Frame" ) );
216
217 if( aFileName != "" )
218 {
219 frame->LoadAndDisplayBoard( aFileName );
220 }
221
222 return frame;
223}
224
226{
227 m_toolManager->InitTools();
228 m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
229}
void SetMaximum()
Definition: box2.h:63
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
Abstract interface for drawing on a 2D-surface.
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
virtual void SetTarget(RENDER_TARGET aTarget)
Set the target for rendering.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:195
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
wxString GetClass() const override
Return the class name.
virtual void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override
Draw the parts of the object belonging to layer aLayer.
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
MY_PCB_TEST_FRAME(wxFrame *frame, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE)
@ MODEL_RELOAD
Model changes (required full reload)
Definition: tool_base.h:80
@ WHITE
Definition: color4d.h:48
E_SERIE r
Definition: eserie.cpp:41
@ LAYER_GP_OVERLAY
general purpose overlay
Definition: layer_ids.h:218
@ SHADER_NONE
Definition: vertex_common.h:47
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition: definitions.h:49
wxFrame * CreateMainFrame(const std::string &aFileName)
const VECTOR2D xform2(const MATRIX3x3D &minv, const VECTOR2D &p)
void screenSpaceCircle(KIGFX::GAL *gal, const VECTOR2D &p0, double r, double w)
void screenSpaceLine(KIGFX::GAL *gal, const VECTOR2D &p0, const VECTOR2D &p1, double w)
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617