KiCad PCB EDA Suite
MWAVE Namespace Reference

Classes

struct  INDUCTOR_PATTERN
 Parameters for construction of a microwave inductor. More...
 

Functions

MODULECreateMicrowaveInductor (INDUCTOR_PATTERN &aPattern, PCB_EDIT_FRAME *aPcbFrame, wxString &aErrorMessage)
 Creates an S-shaped coil footprint for microwave applications. More...
 

Function Documentation

MODULE * MWAVE::CreateMicrowaveInductor ( INDUCTOR_PATTERN aPattern,
PCB_EDIT_FRAME aPcbFrame,
wxString &  aErrorMessage 
)

Creates an S-shaped coil footprint for microwave applications.

Definition at line 264 of file microwave_inductor.cpp.

References PCB_BASE_FRAME::AddModuleToBoard(), BuildCornersList_S_Shape(), MODULE::CalculateBoundingBox(), EDA_ITEM::ClearFlags(), PCB_BASE_FRAME::CreateNewModule(), EuclideanNorm(), DRAWSEGMENT::GetEnd(), BOARD_ITEM::GetLayer(), MODULE::GetPosition(), D_PAD::GetPosition(), DRAWSEGMENT::GetStart(), EDA_TEXT::GetTextSize(), EDA_DRAW_FRAME::GetUserUnits(), MODULE::GraphicalItemsList(), DLIST< T >::Insert(), KiROUND(), MWAVE::INDUCTOR_PATTERN::m_End, MWAVE::INDUCTOR_PATTERN::m_length, MWAVE::INDUCTOR_PATTERN::m_Start, MWAVE::INDUCTOR_PATTERN::m_Width, MOD_CMS, MOD_VIRTUAL, D_PAD::Next(), PAD_ATTRIB_SMD, PAD_SHAPE_CIRCLE, MODULE::PadsList(), DLIST< T >::PushBack(), DLIST< T >::PushFront(), MODULE::Reference(), S_SEGMENT, D_PAD::SetAttribute(), MODULE::SetAttributes(), DRAWSEGMENT::SetEnd(), EDGE_MODULE::SetEnd0(), MODULE::SetFPID(), BOARD_ITEM::SetLayer(), D_PAD::SetLayerSet(), D_PAD::SetName(), D_PAD::SetPos0(), TEXTE_MODULE::SetPosition(), MODULE::SetPosition(), D_PAD::SetPosition(), DRAWSEGMENT::SetShape(), D_PAD::SetShape(), D_PAD::SetSize(), DRAWSEGMENT::SetStart(), EDGE_MODULE::SetStart0(), WX_TEXT_ENTRY_DIALOG::SetTextValidator(), DRAWSEGMENT::SetWidth(), StringFromValue(), MODULE::Value(), ValueFromString(), wxPoint::x, and wxPoint::y.

Referenced by PCB_EDIT_FRAME::Begin_Self(), and MICROWAVE_TOOL::createInductorBetween().

266 {
267  /* Build a microwave inductor footprint.
268  * - Length Mself.lng
269  * - Extremities Mself.m_Start and Mself.m_End
270  * We must determine:
271  * Mself.nbrin = number of segments perpendicular to the direction
272  * (The coil nbrin will demicercles + 1 + 2 1 / 4 circle)
273  * Mself.lbrin = length of a strand
274  * Mself.radius = radius of rounded parts of the coil
275  * Mself.delta = segments extremities connection between him and the coil even
276  *
277  * The equations are
278  * Mself.m_Size.x = 2 * Mself.radius + Mself.lbrin
279  * Mself.m_Size.y * Mself.delta = 2 + 2 * Mself.nbrin * Mself.radius
280  * Mself.lng = 2 * Mself.delta / / connections to the coil
281  + (Mself.nbrin-2) * Mself.lbrin / / length of the strands except 1st and last
282  + (Mself.nbrin 1) * (PI * Mself.radius) / / length of rounded
283  * Mself.lbrin + / 2 - Melf.radius * 2) / / length of 1st and last bit
284  *
285  * The constraints are:
286  * Nbrin >= 2
287  * Mself.radius < Mself.m_Size.x
288  * Mself.m_Size.y = Mself.radius * 4 + 2 * Mself.raccord
289  * Mself.lbrin> Mself.radius * 2
290  *
291  * The calculation is conducted in the following way:
292  * Initially:
293  * Nbrin = 2
294  * Radius = 4 * m_Size.x (arbitrarily fixed value)
295  * Then:
296  * Increasing the number of segments to the desired length
297  * (Radius decreases if necessary)
298  */
299 
300  D_PAD* pad;
301  int ll;
302  wxString msg;
303 
304  auto pt = inductorPattern.m_End - inductorPattern.m_Start;
305  int min_len = KiROUND( EuclideanNorm( pt ) );
306  inductorPattern.m_length = min_len;
307 
308  // Enter the desired length.
309  msg = StringFromValue( aPcbFrame->GetUserUnits(), inductorPattern.m_length, true );
310  WX_TEXT_ENTRY_DIALOG dlg( aPcbFrame, _( "Length of Trace:" ), wxEmptyString, msg );
311 
312  if( dlg.ShowModal() != wxID_OK )
313  return nullptr; // canceled by user
314 
315  msg = dlg.GetValue();
316  inductorPattern.m_length = ValueFromString( aPcbFrame->GetUserUnits(), msg );
317 
318  // Control values (ii = minimum length)
319  if( inductorPattern.m_length < min_len )
320  {
321  aErrorMessage = _( "Requested length < minimum length" );
322  return nullptr;
323  }
324 
325  // Calculate the elements.
326  std::vector <wxPoint> buffer;
327  ll = BuildCornersList_S_Shape( buffer, inductorPattern.m_Start,
328  inductorPattern.m_End, inductorPattern.m_length,
329  inductorPattern.m_Width );
330 
331  if( !ll )
332  {
333  aErrorMessage = _( "Requested length too large" );
334  return nullptr;
335  }
336 
337  // Generate footprint. the value is also used as footprint name.
338  msg = "L";
339  WX_TEXT_ENTRY_DIALOG cmpdlg( aPcbFrame, _( "Component Value:" ), wxEmptyString, msg );
340  cmpdlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &msg ) );
341 
342  if( ( cmpdlg.ShowModal() != wxID_OK ) || msg.IsEmpty() )
343  return nullptr; // Aborted by user
344 
345  MODULE* module = aPcbFrame->CreateNewModule( msg );
346  aPcbFrame->AddModuleToBoard( module );
347 
348  module->SetFPID( LIB_ID( wxEmptyString, wxT( "mw_inductor" ) ) );
349  module->SetAttributes( MOD_VIRTUAL | MOD_CMS );
350  module->ClearFlags();
351  module->SetPosition( inductorPattern.m_End );
352 
353  // Generate segments
354  for( unsigned jj = 1; jj < buffer.size(); jj++ )
355  {
356  EDGE_MODULE* PtSegm;
357  PtSegm = new EDGE_MODULE( module );
358  PtSegm->SetStart( buffer[jj - 1] );
359  PtSegm->SetEnd( buffer[jj] );
360  PtSegm->SetWidth( inductorPattern.m_Width );
361  PtSegm->SetLayer( module->GetLayer() );
362  PtSegm->SetShape( S_SEGMENT );
363  PtSegm->SetStart0( PtSegm->GetStart() - module->GetPosition() );
364  PtSegm->SetEnd0( PtSegm->GetEnd() - module->GetPosition() );
365  module->GraphicalItemsList().PushBack( PtSegm );
366  }
367 
368  // Place a pad on each end of coil.
369  pad = new D_PAD( module );
370 
371  module->PadsList().PushFront( pad );
372 
373  pad->SetName( "1" );
374  pad->SetPosition( inductorPattern.m_End );
375  pad->SetPos0( pad->GetPosition() - module->GetPosition() );
376 
377  pad->SetSize( wxSize( inductorPattern.m_Width, inductorPattern.m_Width ) );
378 
379  pad->SetLayerSet( LSET( module->GetLayer() ) );
381  pad->SetShape( PAD_SHAPE_CIRCLE );
382 
383  D_PAD* newpad = new D_PAD( *pad );
384 
385  module->PadsList().Insert( newpad, pad->Next() );
386 
387  pad = newpad;
388  pad->SetName( "2" );
389  pad->SetPosition( inductorPattern.m_Start );
390  pad->SetPos0( pad->GetPosition() - module->GetPosition() );
391 
392  // Modify text positions.
393  wxPoint refPos( ( inductorPattern.m_Start.x + inductorPattern.m_End.x ) / 2,
394  ( inductorPattern.m_Start.y + inductorPattern.m_End.y ) / 2 );
395 
396  wxPoint valPos = refPos;
397 
398  refPos.y -= module->Reference().GetTextSize().y;
399  module->Reference().SetPosition( refPos );
400  valPos.y += module->Value().GetTextSize().y;
401  module->Value().SetPosition( valPos );
402 
403  module->CalculateBoundingBox();
404  return module;
405 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
void SetEnd0(const wxPoint &aPoint)
TEXTE_MODULE & Reference()
Definition: class_module.h:510
void SetShape(STROKE_T aShape)
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
virtual void AddModuleToBoard(MODULE *module)
Adds the given module to the board.
void PushFront(T *aNewElement)
Function PushFront puts aNewElement at front of list sequence.
Definition: dlist.h:240
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void CalculateBoundingBox()
Function CalculateBoundingBox calculates the bounding box in board coordinates.
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
Set for modules listed in the automatic insertion list (usually SMD footprints)
Definition: class_module.h:77
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:219
usual segment : line with rounded ends
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:409
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
MODULE * CreateNewModule(const wxString &aModuleName)
Function CreateNewModule Creates a new module or footprint, at position 0,0 The new module contains o...
Class FILE_NAME_CHAR_VALIDATOR.
Definition: validators.h:63
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
Class LSET is a set of PCB_LAYER_IDs.
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
void SetName(const wxString &aName)
Set the pad name (sometimes called pad number, although it can be an array reference like AA12)...
Definition: class_pad.h:182
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:509
void SetPos0(const wxPoint &aPos)
Definition: class_pad.h:262
EDA_UNITS_T GetUserUnits() const override
Function GetUserUnits returns the user units currently in use.
Definition: draw_frame.h:266
D_PAD * Next() const
Definition: class_pad.h:160
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
static int BuildCornersList_S_Shape(std::vector< wxPoint > &aBuffer, const wxPoint &aStartPoint, const wxPoint &aEndPoint, int aLength, int aWidth)
Function BuildCornersList_S_Shape Create a path like a S-shaped coil.
virtual void SetPosition(const wxPoint &aPos) override
void SetPosition(const wxPoint &aPos) override
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:409
void SetStart(const wxPoint &aStart)
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:401
Virtual component: when created by copper shapes on board (Like edge card connectors, mounting hole...)
Definition: class_module.h:79
void SetStart0(const wxPoint &aPoint)
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:217
void SetEnd(const wxPoint &aEnd)
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
wxString StringFromValue(EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:210
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:166
DLIST< D_PAD > & PadsList()
Definition: class_module.h:163
const wxSize & GetTextSize() const
Definition: eda_text.h:228
const wxPoint GetPosition() const override
Definition: class_pad.h:220
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
const wxPoint GetPosition() const override
Definition: class_module.h:184
void SetFPID(const LIB_ID &aFPID)
Definition: class_module.h:194
void Insert(T *aNewElement, T *aElementAfterMe)
Function Insert puts aNewElement just in front of aElementAfterMe in the list sequence.
Definition: dlist.h:200
void SetAttributes(int aAttributes)
Definition: class_module.h:227
void SetWidth(int aWidth)