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>
7 #include <pcb_draw_panel_gal.h>
8 
10 
11 const 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 
17 void 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  currentManager->Reserve( 6 );
28  currentManager->Shader( SHADER_NONE );
29  currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a );
30 
31  currentManager->Shader( SHADER_NONE ); currentManager->Vertex( pa.x, pa.y, layerDepth );
32  currentManager->Shader( SHADER_NONE ); currentManager->Vertex( pb.x, pb.y, layerDepth );
33  currentManager->Shader( SHADER_NONE ); currentManager->Vertex( pc.x, pc.y, layerDepth );
34  currentManager->Shader( SHADER_NONE ); currentManager->Vertex( pa.x, pa.y, layerDepth );
35  currentManager->Shader( SHADER_NONE ); currentManager->Vertex( pc.x, pc.y, layerDepth );
36  currentManager->Shader( SHADER_NONE ); currentManager->Vertex( pd.x, pd.y, layerDepth );
37  shader->Use();
38 #endif
39 
40  gal->SetLineWidth( w * minv.GetScale().x );
41  gal->DrawLine( pa, pb );
42 
43 
44 }
45 
46 void 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 
58 class MY_DRAWING : public EDA_ITEM
59 {
60 public:
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 
193 {
194 public:
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  {
200  registerTools();
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 
213 wxFrame* 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 }
Model changes (required full reload)
Definition: tool_base.h:81
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
const VECTOR2D xform2(const MATRIX3x3D &minv, const VECTOR2D &p)
the 3d code uses this value
Definition: typeinfo.h:80
void screenSpaceCircle(KIGFX::GAL *gal, const VECTOR2D &p0, double r, double w)
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
unique_ptr< PCB_DRAW_PANEL_GAL > m_galPanel
MY_PCB_TEST_FRAME(wxFrame *frame, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE)
virtual void SetLineWidth(float aLineWidth)
Set the line width.
Auxiliary rendering target (noncached)
Definition: definitions.h:49
VIEW_ITEM class definition.
void screenSpaceLine(KIGFX::GAL *gal, const VECTOR2D &p0, const VECTOR2D &p1, double w)
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
void SetMaximum()
Definition: box2.h:72
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
virtual void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override
Function ViewDraw() Draws the parts of the object belonging to layer aLayer.
wxString GetClass() const override
Function GetClass returns the class name.
Board layer functions and definitions.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
Definition: colors.h:49
wxFrame * CreateMainFrame(const std::string &aFileName)
VIEW.
Definition: view.h:61
virtual void SetTarget(RENDER_TARGET aTarget)
Sets the target for rendering.
Class GAL is the abstract interface for drawing on a 2D-surface.