void DIALOG_PLOT::Init_Dialog() { wxString msg; wxFileName fileName; m_config->Read( OPTKEY_PLOT_X_FINESCALE_ADJ, &m_XScaleAdjust ); m_config->Read( OPTKEY_PLOT_Y_FINESCALE_ADJ, &m_YScaleAdjust ); // m_PSWidthAdjust is stored in mm in user config double dtmp; m_config->Read( CONFIG_PS_FINEWIDTH_ADJ, &dtmp, 0 ); m_PSWidthAdjust = KiROUND( dtmp * IU_PER_MM ); // The reasonable width correction value must be in a range of // [-(MinTrackWidth-1), +(MinClearanceValue-1)] decimils. m_widthAdjustMinValue = -( m_board->GetDesignSettings().m_TrackMinWidth - 1 ); m_widthAdjustMaxValue = m_board->GetDesignSettings().GetSmallestClearanceValue() - 1; switch( m_plotOpts.GetFormat() ) { default: case PLOT_FORMAT_GERBER: m_plotFormatOpt->SetSelection( 0 ); break; case PLOT_FORMAT_POST: m_plotFormatOpt->SetSelection( 1 ); break; case PLOT_FORMAT_SVG: m_plotFormatOpt->SetSelection( 2 ); break; case PLOT_FORMAT_DXF: m_plotFormatOpt->SetSelection( 3 ); break; case PLOT_FORMAT_HPGL: m_plotFormatOpt->SetSelection( 4 ); break; case PLOT_FORMAT_PDF: m_plotFormatOpt->SetSelection( 5 ); break; } msg = StringFromValue( g_UserUnit, m_board->GetDesignSettings().m_SolderMaskMargin, true ); m_SolderMaskMarginCurrValue->SetLabel( msg ); msg = StringFromValue( g_UserUnit, m_board->GetDesignSettings().m_SolderMaskMinWidth, true ); m_SolderMaskMinWidthCurrValue->SetLabel( msg ); // Set units and value for HPGL pen size (this param in in mils). AddUnitSymbol( *m_textPenSize, g_UserUnit ); msg = StringFromValue( g_UserUnit, m_plotOpts.GetHPGLPenDiameter() * IU_PER_MILS ); m_HPGLPenSizeOpt->AppendText( msg ); AddUnitSymbol( *m_textDefaultPenSize, g_UserUnit ); msg = StringFromValue( g_UserUnit, m_plotOpts.GetLineWidth() ); m_linesWidth->AppendText( msg ); // Set units for PS global width correction. AddUnitSymbol( *m_textPSFineAdjustWidth, g_UserUnit ); m_useAuxOriginCheckBox->SetValue( m_plotOpts.GetUseAuxOrigin() ); // Test for a reasonable scale value. Set to 1 if problem if( m_XScaleAdjust < PLOT_MIN_SCALE || m_YScaleAdjust < PLOT_MIN_SCALE || m_XScaleAdjust > PLOT_MAX_SCALE || m_YScaleAdjust > PLOT_MAX_SCALE ) m_XScaleAdjust = m_YScaleAdjust = 1.0; msg.Printf( wxT( "%f" ), m_XScaleAdjust ); m_fineAdjustXscaleOpt->AppendText( msg ); msg.Printf( wxT( "%f" ), m_YScaleAdjust ); m_fineAdjustYscaleOpt->AppendText( msg ); // Test for a reasonable PS width correction value. Set to 0 if problem. if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue ) m_PSWidthAdjust = 0.; msg.Printf( wxT( "%f" ), To_User_Unit( g_UserUnit, m_PSWidthAdjust ) ); m_PSFineAdjustWidthOpt->AppendText( msg ); m_plotPSNegativeOpt->SetValue( m_plotOpts.GetNegative() ); m_forcePSA4OutputOpt->SetValue( m_plotOpts.GetA4Output() ); // Could devote a PlotOrder() function in place of UIOrder(). m_layerList = m_board->GetEnabledLayers().UIOrder(); // Populate the check list box by all enabled layers names for( LSEQ seq = m_layerList; seq; ++seq ) { LAYER_ID layer = *seq; int checkIndex = m_layerCheckListBox->Append( m_board->GetLayerName( layer ) ); if( m_plotOpts.GetLayerSelection()[layer] ) m_layerCheckListBox->Check( checkIndex ); } // Option for using proper Gerber extensions m_useGerberExtensions->SetValue( m_plotOpts.GetUseGerberProtelExtensions() ); // Option for including Gerber attributes (from Gerber X2 format) in the output m_useGerberX2Attributes->SetValue( m_plotOpts.GetUseGerberAttributes() ); // Option for including Gerber netlist info (from Gerber X2 format) in the output #ifdef KICAD_USE_GBR_NETATTRIBUTES m_useGerberNetAttributes->SetValue( m_plotOpts.GetIncludeGerberNetlistInfo() ); #else m_plotOpts.SetIncludeGerberNetlistInfo( false ); m_useGerberNetAttributes->SetValue( false ); #endif // Gerber precision for coordinates m_rbGerberFormat->SetSelection( m_plotOpts.GetGerberPrecision() == 5 ? 0 : 1 ); // Option for excluding contents of "Edges Pcb" layer m_excludeEdgeLayerOpt->SetValue( m_plotOpts.GetExcludeEdgeLayer() ); m_subtractMaskFromSilk->SetValue( m_plotOpts.GetSubtractMaskFromSilk() ); // Option to plot page references: m_plotSheetRef->SetValue( m_plotOpts.GetPlotFrameRef() ); // Option to allow pads on silkscreen layers m_plotPads_on_Silkscreen->SetValue( m_plotOpts.GetPlotPadsOnSilkLayer() ); // Options to plot texts on footprints m_plotModuleValueOpt->SetValue( m_plotOpts.GetPlotValue() ); m_plotModuleRefOpt->SetValue( m_plotOpts.GetPlotReference() ); m_plotInvisibleText->SetValue( m_plotOpts.GetPlotInvisibleText() ); // Options to plot pads and vias holes m_drillShapeOpt->SetSelection( m_plotOpts.GetDrillMarksType() ); // Scale option m_scaleOpt->SetSelection( m_plotOpts.GetScaleSelection() ); // Plot mode setPlotModeChoiceSelection( m_plotOpts.GetPlotMode() ); // Plot mirror option m_plotMirrorOpt->SetValue( m_plotOpts.GetMirror() ); // Put vias on mask layer m_plotNoViaOnMaskOpt->SetValue( m_plotOpts.GetPlotViaOnMaskLayer() ); // Output directory m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() ); // Update options values: wxCommandEvent cmd_event; SetPlotFormat( cmd_event ); OnSetScaleOpt( cmd_event ); }
/* * Display the type, shape, size and some other props to the Message panel */ void SCH_TEXT::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList ) { wxString msg; switch( Type() ) { case SCH_TEXT_T: msg = _( "Graphic Text" ); break; case SCH_LABEL_T: msg = _( "Label" ); break; case SCH_GLOBAL_LABEL_T: msg = _( "Global Label" ); break; case SCH_HIERARCHICAL_LABEL_T: msg = _( "Hierarchical Label" ); break; case SCH_SHEET_PIN_T: msg = _( "Hierarchical Sheet Pin" ); break; default: return; } aList.push_back( MSG_PANEL_ITEM( msg, GetShownText(), DARKCYAN ) ); switch( GetOrientation() ) { case 0: // horizontal text msg = _( "Horizontal" ); break; case 1: // Vert Orientation UP msg = _( "Vertical up" ); break; case 2: // invert horizontal text msg = _( "Horizontal invert" ); break; case 3: // Vert Orientation Down msg = _( "Vertical down" ); break; default: msg = wxT( "???" ); break; } aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg, BROWN ) ); wxString textStyle[] = { _( "Normal" ), _( "Italic" ), _( "Bold" ), _( "Bold Italic" ) }; int style = 0; if( m_Italic ) style = 1; if( m_Bold ) style += 2; aList.push_back( MSG_PANEL_ITEM( _( "Style" ), textStyle[style], BROWN ) ); // Display electricat type if it is relevant if( (Type() == SCH_GLOBAL_LABEL_T) || (Type() == SCH_HIERARCHICAL_LABEL_T ) || (Type() == SCH_SHEET_PIN_T ) ) { switch( GetShape() ) { case NET_INPUT: msg = _( "Input" ); break; case NET_OUTPUT: msg = _( "Output" ); break; case NET_BIDI: msg = _( "Bidirectional" ); break; case NET_TRISTATE: msg = _( "Tri-State" ); break; case NET_UNSPECIFIED: msg = _( "Passive" ); break; default: msg = wxT( "???" ); break; } aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, BLUE ) ); } // Display text size (X or Y value, with are the same value in Eeschema) msg = StringFromValue( g_UserUnit, m_Size.x, true ); aList.push_back( MSG_PANEL_ITEM( _( "Size" ), msg, RED ) ); }
bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, wxDC* aDC ) { if( aSheet == NULL ) return false; // Get the new texts DIALOG_SCH_SHEET_PROPS dlg( this ); wxString units = GetUnitsLabel( g_UserUnit ); dlg.SetFileName( aSheet->GetFileName() ); dlg.SetFileNameTextSize( StringFromValue( g_UserUnit, aSheet->GetFileNameSize() ) ); dlg.SetFileNameTextSizeUnits( units ); dlg.SetSheetName( aSheet->GetName() ); dlg.SetSheetNameTextSize( StringFromValue( g_UserUnit, aSheet->GetSheetNameSize() ) ); dlg.SetSheetNameTextSizeUnits( units ); dlg.SetSheetTimeStamp( wxString::Format( wxT("%8.8lX"), (unsigned long) aSheet->GetTimeStamp() ) ); /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier * versions for the flex grid sizer in wxGTK that prevents the last * column from being sized correctly. It doesn't cause any problems * on win32 so it doesn't need to wrapped in ugly #ifdef __WXGTK__ * #endif. * Still presen in wxWidgets 3.0.2 */ dlg.Layout(); dlg.Fit(); dlg.SetMinSize( dlg.GetSize() ); dlg.GetSizer()->Fit( &dlg ); if( dlg.ShowModal() == wxID_CANCEL ) return false; wxFileName fileName = dlg.GetFileName(); fileName.SetExt( SchematicFileExtension ); if( !fileName.IsOk() ) { DisplayError( this, _( "File name is not valid!" ) ); if( m_canvas ) m_canvas->Refresh(); return false; } // Duplicate sheet names are not valid. const SCH_SHEET* sheet = GetScreen()->GetSheet( dlg.GetSheetName() ); if( sheet && sheet != aSheet ) { DisplayError( this, wxString::Format( _( "A sheet named \"%s\" already exists." ), GetChars( dlg.GetSheetName() ) ) ); if( m_canvas ) m_canvas->Refresh(); return false; } wxString msg; wxString tmp; bool loadFromFile = false; SCH_SCREEN* useScreen = NULL; wxString newFilename = fileName.GetFullPath(); // Search for a schematic file having the same filename // already in use in the hierarchy or on disk, in order to reuse it. if( !g_RootSheet->SearchHierarchy( newFilename, &useScreen ) ) { // if user entered a relative path, allow that to stay, but do the // file existence test with an absolute (full) path. This transformation // is local to this scope, but is the same one used at load time later. wxString absolute = Prj().AbsolutePath( newFilename ); loadFromFile = wxFileExists( absolute ); } // Inside Eeschema, filenames are stored using unix notation newFilename.Replace( wxT("\\"), wxT("/") ); if( aSheet->GetScreen() == NULL ) // New sheet. { if( useScreen || loadFromFile ) // Load from existing file. { if( useScreen != NULL ) { msg.Printf( _( "A file named '%s' already exists in the current schematic hierarchy." ), GetChars( newFilename ) ); } else { msg.Printf( _( "A file named '%s' already exists." ), GetChars( newFilename ) ); } msg += _("\n\nDo you want to create a sheet with the contents of this file?" ); if( !IsOK( this, msg ) ) { if( m_canvas ) m_canvas->Refresh(); return false; } } else // New file. { aSheet->SetScreen( new SCH_SCREEN( &Kiway() ) ); aSheet->GetScreen()->SetFileName( newFilename ); } } else // Existing sheet. { bool isUndoable = true; bool renameFile = false; // We are always using here a case insensitive comparison // to avoid issues under Windows, although under Unix // filenames are case sensitive. // But many users create schematic under both Unix and Windows if( newFilename.CmpNoCase( aSheet->GetFileName() ) != 0 ) { // Sheet file name changes cannot be undone. isUndoable = false; msg = _( "Changing the sheet file name cannot be undone. " ); if( useScreen || loadFromFile ) // Load from existing file. { wxString tmp; if( useScreen != NULL ) { tmp.Printf( _( "A file named <%s> already exists in the current schematic hierarchy." ), GetChars( newFilename ) ); } else { tmp.Printf( _( "A file named <%s> already exists." ), GetChars( newFilename ) ); } msg += tmp; msg += _("\n\nDo you want to replace the sheet with the contents of this file?" ); if( !IsOK( this, msg ) ) return false; if( loadFromFile ) aSheet->SetScreen( NULL ); } else // Save to new file name. { if( aSheet->GetScreenCount() > 1 ) { msg += _( "This sheet uses shared data in a complex hierarchy.\n\n" ); msg += _( "Do you wish to convert it to a simple hierarchical sheet?" ); if( !IsOK( NULL, msg ) ) return false; } renameFile = true; } } aSheet->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); m_canvas->SetIgnoreMouseEvents( true ); if( isUndoable ) SaveCopyInUndoList( aSheet, UR_CHANGED ); if( renameFile ) { aSheet->GetScreen()->SetFileName( newFilename ); SaveEEFile( aSheet->GetScreen() ); // If the the associated screen is shared by more than one sheet, remove the // screen and reload the file to a new screen. Failure to do this will trash // the screen reference counting in complex hierarchies. if( aSheet->GetScreenCount() > 1 ) { aSheet->SetScreen( NULL ); loadFromFile = true; } } } aSheet->SetFileName( newFilename ); if( useScreen ) aSheet->SetScreen( useScreen ); else if( loadFromFile ) aSheet->Load( this ); aSheet->SetFileNameSize( ValueFromString( g_UserUnit, dlg.GetFileNameTextSize() ) ); aSheet->SetName( dlg.GetSheetName() ); aSheet->SetSheetNameSize( ValueFromString( g_UserUnit, dlg.GetSheetNameTextSize() ) ); if( aSheet->GetName().IsEmpty() ) aSheet->SetName( wxString::Format( wxT( "Sheet%8.8lX" ), aSheet->GetTimeStamp() ) ); m_canvas->MoveCursorToCrossHair(); m_canvas->SetIgnoreMouseEvents( false ); aSheet->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); OnModify(); return true; }
void DIALOG_PLOT::applyPlotSettings() { REPORTER& reporter = m_messagesPanel->Reporter(); PCB_PLOT_PARAMS tempOptions; tempOptions.SetExcludeEdgeLayer( m_excludeEdgeLayerOpt->GetValue() ); tempOptions.SetSubtractMaskFromSilk( m_subtractMaskFromSilk->GetValue() ); tempOptions.SetPlotFrameRef( m_plotSheetRef->GetValue() ); tempOptions.SetPlotPadsOnSilkLayer( m_plotPads_on_Silkscreen->GetValue() ); tempOptions.SetUseAuxOrigin( m_useAuxOriginCheckBox->GetValue() ); tempOptions.SetPlotValue( m_plotModuleValueOpt->GetValue() ); tempOptions.SetPlotReference( m_plotModuleRefOpt->GetValue() ); tempOptions.SetPlotInvisibleText( m_plotInvisibleText->GetValue() ); tempOptions.SetScaleSelection( m_scaleOpt->GetSelection() ); tempOptions.SetDrillMarksType( static_cast<PCB_PLOT_PARAMS::DrillMarksType> ( m_drillShapeOpt->GetSelection() ) ); tempOptions.SetMirror( m_plotMirrorOpt->GetValue() ); tempOptions.SetPlotMode( m_plotModeOpt->GetSelection() == 1 ? SKETCH : FILLED ); tempOptions.SetPlotViaOnMaskLayer( m_plotNoViaOnMaskOpt->GetValue() ); // Update settings from text fields. Rewrite values back to the fields, // since the values may have been constrained by the setters. // read HPLG pen size (this param is stored in mils) wxString msg = m_HPGLPenSizeOpt->GetValue(); int tmp = ValueFromString( g_UserUnit, msg ) / IU_PER_MILS; if( !tempOptions.SetHPGLPenDiameter( tmp ) ) { msg = StringFromValue( g_UserUnit, tempOptions.GetHPGLPenDiameter() * IU_PER_MILS ); m_HPGLPenSizeOpt->SetValue( msg ); msg.Printf( _( "HPGL pen size constrained." ) ); reporter.Report( msg, REPORTER::RPT_INFO ); } // Default linewidth msg = m_linesWidth->GetValue(); tmp = ValueFromString( g_UserUnit, msg ); if( !tempOptions.SetLineWidth( tmp ) ) { msg = StringFromValue( g_UserUnit, tempOptions.GetLineWidth() ); m_linesWidth->SetValue( msg ); msg.Printf( _( "Default line width constrained." ) ); reporter.Report( msg, REPORTER::RPT_INFO ); } // X scale double tmpDouble; msg = m_fineAdjustXscaleOpt->GetValue(); msg.ToDouble( &tmpDouble ); if( !setDouble( &m_XScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) ) { msg.Printf( wxT( "%f" ), m_XScaleAdjust ); m_fineAdjustXscaleOpt->SetValue( msg ); msg.Printf( _( "X scale constrained." ) ); reporter.Report( msg, REPORTER::RPT_INFO ); } ConfigBaseWriteDouble( m_config, OPTKEY_PLOT_X_FINESCALE_ADJ, m_XScaleAdjust ); // Y scale msg = m_fineAdjustYscaleOpt->GetValue(); msg.ToDouble( &tmpDouble ); if( !setDouble( &m_YScaleAdjust, tmpDouble, PLOT_MIN_SCALE, PLOT_MAX_SCALE ) ) { msg.Printf( wxT( "%f" ), m_YScaleAdjust ); m_fineAdjustYscaleOpt->SetValue( msg ); msg.Printf( _( "Y scale constrained." ) ); reporter.Report( msg, REPORTER::RPT_INFO ); } ConfigBaseWriteDouble( m_config, OPTKEY_PLOT_Y_FINESCALE_ADJ, m_YScaleAdjust ); // PS Width correction msg = m_PSFineAdjustWidthOpt->GetValue(); int itmp = ValueFromString( g_UserUnit, msg ); if( !setInt( &m_PSWidthAdjust, itmp, m_widthAdjustMinValue, m_widthAdjustMaxValue ) ) { msg = StringFromValue( g_UserUnit, m_PSWidthAdjust ); m_PSFineAdjustWidthOpt->SetValue( msg ); msg.Printf( _( "Width correction constrained. " "The reasonable width correction value must be in a range of " " [%+f; %+f] (%s) for current design rules. " ), To_User_Unit( g_UserUnit, m_widthAdjustMinValue ), To_User_Unit( g_UserUnit, m_widthAdjustMaxValue ), ( g_UserUnit == INCHES ) ? wxT( "\"" ) : wxT( "mm" ) ); reporter.Report( msg, REPORTER::RPT_WARNING ); } // Store m_PSWidthAdjust in mm in user config ConfigBaseWriteDouble( m_config, CONFIG_PS_FINEWIDTH_ADJ, (double)m_PSWidthAdjust / IU_PER_MM ); tempOptions.SetFormat( getPlotFormat() ); tempOptions.SetUseGerberProtelExtensions( m_useGerberExtensions->GetValue() ); tempOptions.SetUseGerberAttributes( m_useGerberX2Attributes->GetValue() ); tempOptions.SetIncludeGerberNetlistInfo( m_useGerberNetAttributes->GetValue() ); tempOptions.SetGerberPrecision( m_rbGerberFormat->GetSelection() == 0 ? 5 : 6 ); LSET selectedLayers; for( unsigned i = 0; i < m_layerList.size(); i++ ) { if( m_layerCheckListBox->IsChecked( i ) ) selectedLayers.set( m_layerList[i] ); } // Get a list of copper layers that aren't being used by inverting enabled layers. LSET disabledCopperLayers = LSET::AllCuMask() & ~m_board->GetEnabledLayers(); // Enable all of the disabled copper layers. // If someone enables more copper layers they will be selected by default. selectedLayers = selectedLayers | disabledCopperLayers; tempOptions.SetLayerSelection( selectedLayers ); tempOptions.SetNegative( m_plotPSNegativeOpt->GetValue() ); tempOptions.SetA4Output( m_forcePSA4OutputOpt->GetValue() ); // Set output directory and replace backslashes with forward ones wxString dirStr; dirStr = m_outputDirectoryName->GetValue(); dirStr.Replace( wxT( "\\" ), wxT( "/" ) ); tempOptions.SetOutputDirectory( dirStr ); if( m_plotOpts != tempOptions ) { m_parent->SetPlotSettings( tempOptions ); m_plotOpts = tempOptions; m_parent->OnModify(); } }
MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) { D_PAD* pad; int ll; wxString msg; m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); m_canvas->SetMouseCapture( NULL, NULL ); if( s_inductor_pattern.m_Flag == false ) { DisplayError( this, wxT( "Starting point not init.." ) ); return NULL; } s_inductor_pattern.m_Flag = false; s_inductor_pattern.m_End = GetCrossHairPosition(); wxPoint pt = s_inductor_pattern.m_End - s_inductor_pattern.m_Start; int min_len = KiROUND( EuclideanNorm( pt ) ); s_inductor_pattern.m_lenght = min_len; // Enter the desired length. msg = StringFromValue( g_UserUnit, s_inductor_pattern.m_lenght ); wxTextEntryDialog dlg( this, wxEmptyString, _( "Length of Trace:" ), msg ); if( dlg.ShowModal() != wxID_OK ) return NULL; // canceled by user msg = dlg.GetValue(); s_inductor_pattern.m_lenght = ValueFromString( g_UserUnit, msg ); // Control values (ii = minimum length) if( s_inductor_pattern.m_lenght < min_len ) { DisplayError( this, _( "Requested length < minimum length" ) ); return NULL; } // Calculate the elements. s_inductor_pattern.m_Width = GetDesignSettings().GetCurrentTrackWidth(); std::vector <wxPoint> buffer; ll = BuildCornersList_S_Shape( buffer, s_inductor_pattern.m_Start, s_inductor_pattern.m_End, s_inductor_pattern.m_lenght, s_inductor_pattern.m_Width ); if( !ll ) { DisplayError( this, _( "Requested length too large" ) ); return NULL; } // Generate footprint. the value is also used as footprint name. msg.Empty(); wxTextEntryDialog cmpdlg( this, wxEmptyString, _( "Component Value:" ), msg ); cmpdlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &msg ) ); if( ( cmpdlg.ShowModal() != wxID_OK ) || msg.IsEmpty() ) return NULL; // Aborted by user MODULE* module = CreateNewModule( msg ); // here the module is already in the BOARD, CreateNewModule() does that. module->SetFPID( FPID( std::string( "mw_inductor" ) ) ); module->SetAttributes( MOD_VIRTUAL | MOD_CMS ); module->ClearFlags(); module->SetPosition( s_inductor_pattern.m_End ); // Generate segments for( unsigned jj = 1; jj < buffer.size(); jj++ ) { EDGE_MODULE* PtSegm; PtSegm = new EDGE_MODULE( module ); PtSegm->SetStart( buffer[jj - 1] ); PtSegm->SetEnd( buffer[jj] ); PtSegm->SetWidth( s_inductor_pattern.m_Width ); PtSegm->SetLayer( module->GetLayer() ); PtSegm->SetShape( S_SEGMENT ); PtSegm->SetStart0( PtSegm->GetStart() - module->GetPosition() ); PtSegm->SetEnd0( PtSegm->GetEnd() - module->GetPosition() ); module->GraphicalItems().PushBack( PtSegm ); } // Place a pad on each end of coil. pad = new D_PAD( module ); module->Pads().PushFront( pad ); pad->SetPadName( wxT( "1" ) ); pad->SetPosition( s_inductor_pattern.m_End ); pad->SetPos0( pad->GetPosition() - module->GetPosition() ); pad->SetSize( wxSize( s_inductor_pattern.m_Width, s_inductor_pattern.m_Width ) ); pad->SetLayerSet( LSET( module->GetLayer() ) ); pad->SetAttribute( PAD_ATTRIB_SMD ); pad->SetShape( PAD_SHAPE_CIRCLE ); D_PAD* newpad = new D_PAD( *pad ); module->Pads().Insert( newpad, pad->Next() ); pad = newpad; pad->SetPadName( wxT( "2" ) ); pad->SetPosition( s_inductor_pattern.m_Start ); pad->SetPos0( pad->GetPosition() - module->GetPosition() ); // Modify text positions. SetMsgPanel( module ); wxPoint refPos( ( s_inductor_pattern.m_Start.x + s_inductor_pattern.m_End.x ) / 2, ( s_inductor_pattern.m_Start.y + s_inductor_pattern.m_End.y ) / 2 ); wxPoint valPos = refPos; refPos.y -= module->Reference().GetSize().y; module->Reference().SetPosition( refPos ); valPos.y += module->Value().GetSize().y; module->Value().SetPosition( valPos ); module->CalculateBoundingBox(); module->Draw( m_canvas, DC, GR_OR ); return module; }
MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) { int oX; D_PAD* pad; MODULE* module; wxString msg, cmp_name; int pad_count = 2; int angle = 0; // Ref and value text size (O = use board default value. // will be set to a value depending on the footprint size, if possible int text_size = 0; // Enter the size of the gap or stub int gap_size = GetDesignSettings().GetCurrentTrackWidth(); switch( shape_type ) { case 0: msg = _( "Gap" ); cmp_name = wxT( "muwave_gap" ); text_size = gap_size; break; case 1: msg = _( "Stub" ); cmp_name = wxT( "muwave_stub" ); text_size = gap_size; pad_count = 2; break; case 2: msg = _( "Arc Stub" ); cmp_name = wxT( "muwave_arcstub" ); pad_count = 1; break; default: msg = wxT( "???" ); break; } wxString value = StringFromValue( g_UserUnit, gap_size ); wxTextEntryDialog dlg( this, msg, _( "Create microwave module" ), value ); if( dlg.ShowModal() != wxID_OK ) { m_canvas->MoveCursorToCrossHair(); return NULL; // cancelled by user } value = dlg.GetValue(); gap_size = ValueFromString( g_UserUnit, value ); bool abort = false; if( shape_type == 2 ) { double fcoeff = 10.0, fval; msg.Printf( wxT( "%3.1f" ), angle / fcoeff ); wxTextEntryDialog angledlg( this, _( "Angle in degrees:" ), _( "Create microwave module" ), msg ); if( angledlg.ShowModal() != wxID_OK ) { m_canvas->MoveCursorToCrossHair(); return NULL; // cancelled by user } msg = angledlg.GetValue(); if( !msg.ToDouble( &fval ) ) { DisplayError( this, _( "Incorrect number, abort" ) ); abort = true; } angle = std::abs( KiROUND( fval * fcoeff ) ); if( angle > 1800 ) angle = 1800; } if( abort ) { m_canvas->MoveCursorToCrossHair(); return NULL; } module = CreateMuWaveBaseFootprint( cmp_name, text_size, pad_count ); pad = module->Pads(); switch( shape_type ) { case 0: //Gap : oX = -( gap_size + pad->GetSize().x ) / 2; pad->SetX0( oX ); pad->SetX( pad->GetPos0().x + pad->GetPosition().x ); pad = pad->Next(); pad->SetX0( oX + gap_size + pad->GetSize().x ); pad->SetX( pad->GetPos0().x + pad->GetPosition().x ); break; case 1: //Stub : pad->SetPadName( wxT( "1" ) ); pad = pad->Next(); pad->SetY0( -( gap_size + pad->GetSize().y ) / 2 ); pad->SetSize( wxSize( pad->GetSize().x, gap_size ) ); pad->SetY( pad->GetPos0().y + pad->GetPosition().y ); break; case 2: // Arc Stub created by a polygonal approach: { EDGE_MODULE* edge = new EDGE_MODULE( module ); module->GraphicalItems().PushFront( edge ); edge->SetShape( S_POLYGON ); edge->SetLayer( F_Cu ); int numPoints = (angle / 50) + 3; // Note: angles are in 0.1 degrees std::vector<wxPoint>& polyPoints = edge->GetPolyPoints(); polyPoints.reserve( numPoints ); edge->m_Start0.y = -pad->GetSize().y / 2; polyPoints.push_back( wxPoint( 0, 0 ) ); int theta = -angle / 2; for( int ii = 1; ii<numPoints - 1; ii++ ) { wxPoint pt( 0, -gap_size ); RotatePoint( &pt.x, &pt.y, theta ); polyPoints.push_back( pt ); theta += 50; if( theta > angle / 2 ) theta = angle / 2; } // Close the polygon: polyPoints.push_back( polyPoints[0] ); } break; default: break; } module->CalculateBoundingBox(); GetBoard()->m_Status_Pcb = 0; OnModify(); return module; }
MODULE* CreateMicrowaveInductor( PCB_EDIT_FRAME* aPcbFrame, wxString& aErrorMessage ) { /* Build a microwave inductor footprint. * - Length Mself.lng * - Extremities Mself.m_Start and Mself.m_End * We must determine: * Mself.nbrin = number of segments perpendicular to the direction * (The coil nbrin will demicercles + 1 + 2 1 / 4 circle) * Mself.lbrin = length of a strand * Mself.radius = radius of rounded parts of the coil * Mself.delta = segments extremities connection between him and the coil even * * The equations are * Mself.m_Size.x = 2 * Mself.radius + Mself.lbrin * Mself.m_Size.y * Mself.delta = 2 + 2 * Mself.nbrin * Mself.radius * Mself.lng = 2 * Mself.delta / / connections to the coil + (Mself.nbrin-2) * Mself.lbrin / / length of the strands except 1st and last + (Mself.nbrin 1) * (PI * Mself.radius) / / length of rounded * Mself.lbrin + / 2 - Melf.radius * 2) / / length of 1st and last bit * * The constraints are: * Nbrin >= 2 * Mself.radius < Mself.m_Size.x * Mself.m_Size.y = Mself.radius * 4 + 2 * Mself.raccord * Mself.lbrin> Mself.radius * 2 * * The calculation is conducted in the following way: * Initially: * Nbrin = 2 * Radius = 4 * m_Size.x (arbitrarily fixed value) * Then: * Increasing the number of segments to the desired length * (Radius decreases if necessary) */ D_PAD* pad; int ll; wxString msg; wxASSERT( s_inductor_pattern.m_Flag ); s_inductor_pattern.m_Flag = false; wxPoint pt = s_inductor_pattern.m_End - s_inductor_pattern.m_Start; int min_len = KiROUND( EuclideanNorm( pt ) ); s_inductor_pattern.m_length = min_len; // Enter the desired length. msg = StringFromValue( g_UserUnit, s_inductor_pattern.m_length ); wxTextEntryDialog dlg( NULL, wxEmptyString, _( "Length of Trace:" ), msg ); if( dlg.ShowModal() != wxID_OK ) return NULL; // canceled by user msg = dlg.GetValue(); s_inductor_pattern.m_length = ValueFromString( g_UserUnit, msg ); // Control values (ii = minimum length) if( s_inductor_pattern.m_length < min_len ) { aErrorMessage = _( "Requested length < minimum length" ); return NULL; } // Calculate the elements. std::vector <wxPoint> buffer; ll = BuildCornersList_S_Shape( buffer, s_inductor_pattern.m_Start, s_inductor_pattern.m_End, s_inductor_pattern.m_length, s_inductor_pattern.m_Width ); if( !ll ) { aErrorMessage = _( "Requested length too large" ); return NULL; } // Generate footprint. the value is also used as footprint name. msg.Empty(); wxTextEntryDialog cmpdlg( NULL, wxEmptyString, _( "Component Value:" ), msg ); cmpdlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &msg ) ); if( ( cmpdlg.ShowModal() != wxID_OK ) || msg.IsEmpty() ) return NULL; // Aborted by user MODULE* module = aPcbFrame->CreateNewModule( msg ); // here the module is already in the BOARD, CreateNewModule() does that. module->SetFPID( LIB_ID( std::string( "mw_inductor" ) ) ); module->SetAttributes( MOD_VIRTUAL | MOD_CMS ); module->ClearFlags(); module->SetPosition( s_inductor_pattern.m_End ); // Generate segments for( unsigned jj = 1; jj < buffer.size(); jj++ ) { EDGE_MODULE* PtSegm; PtSegm = new EDGE_MODULE( module ); PtSegm->SetStart( buffer[jj - 1] ); PtSegm->SetEnd( buffer[jj] ); PtSegm->SetWidth( s_inductor_pattern.m_Width ); PtSegm->SetLayer( module->GetLayer() ); PtSegm->SetShape( S_SEGMENT ); PtSegm->SetStart0( PtSegm->GetStart() - module->GetPosition() ); PtSegm->SetEnd0( PtSegm->GetEnd() - module->GetPosition() ); module->GraphicalItems().PushBack( PtSegm ); } // Place a pad on each end of coil. pad = new D_PAD( module ); module->Pads().PushFront( pad ); pad->SetPadName( wxT( "1" ) ); pad->SetPosition( s_inductor_pattern.m_End ); pad->SetPos0( pad->GetPosition() - module->GetPosition() ); pad->SetSize( wxSize( s_inductor_pattern.m_Width, s_inductor_pattern.m_Width ) ); pad->SetLayerSet( LSET( module->GetLayer() ) ); pad->SetAttribute( PAD_ATTRIB_SMD ); pad->SetShape( PAD_SHAPE_CIRCLE ); D_PAD* newpad = new D_PAD( *pad ); module->Pads().Insert( newpad, pad->Next() ); pad = newpad; pad->SetPadName( wxT( "2" ) ); pad->SetPosition( s_inductor_pattern.m_Start ); pad->SetPos0( pad->GetPosition() - module->GetPosition() ); // Modify text positions. wxPoint refPos( ( s_inductor_pattern.m_Start.x + s_inductor_pattern.m_End.x ) / 2, ( s_inductor_pattern.m_Start.y + s_inductor_pattern.m_End.y ) / 2 ); wxPoint valPos = refPos; refPos.y -= module->Reference().GetSize().y; module->Reference().SetPosition( refPos ); valPos.y += module->Value().GetSize().y; module->Value().SetPosition( valPos ); module->CalculateBoundingBox(); return module; }
/** * Function Append_Track_Width_List * creates a wxMenu * which shows the last used track widths and via diameters * @return a pointer to the menu */ static wxMenu* Append_Track_Width_List( BOARD* aBoard ) { wxString msg; wxMenu* trackwidth_menu; wxString value; trackwidth_menu = new wxMenu; trackwidth_menu->Append( ID_POPUP_PCB_SELECT_AUTO_WIDTH, _( "Auto Width" ), _( "Use the track width when starting on a track, otherwise the current track width" ), true ); if( aBoard->GetDesignSettings().m_UseConnectedTrackWidth ) trackwidth_menu->Check( ID_POPUP_PCB_SELECT_AUTO_WIDTH, true ); if( aBoard->GetDesignSettings().GetViaSizeIndex() != 0 || aBoard->GetDesignSettings().GetTrackWidthIndex() != 0 || aBoard->GetDesignSettings().m_UseConnectedTrackWidth ) trackwidth_menu->Append( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, _( "Use Netclass Values" ), _( "Use track and via sizes from their Netclass values" ), true ); for( unsigned ii = 0; ii < aBoard->GetDesignSettings().m_TrackWidthList.size(); ii++ ) { value = StringFromValue( g_UserUnit, aBoard->GetDesignSettings().m_TrackWidthList[ii], true ); msg.Printf( _( "Track %s" ), GetChars( value ) ); if( ii == 0 ) msg << _( " uses NetClass" ); trackwidth_menu->Append( ID_POPUP_PCB_SELECT_WIDTH1 + ii, msg, wxEmptyString, true ); } trackwidth_menu->AppendSeparator(); for( unsigned ii = 0; ii < aBoard->GetDesignSettings().m_ViasDimensionsList.size(); ii++ ) { value = StringFromValue( g_UserUnit, aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Diameter, true ); wxString drill = StringFromValue( g_UserUnit, aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Drill, true ); if( aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Drill <= 0 ) { msg.Printf( _( "Via %s" ), GetChars( value ) ); } else { msg.Printf( _( "Via %s, drill %s" ), GetChars( value ), GetChars( drill ) ); } if( ii == 0 ) msg << _( " uses NetClass" ); trackwidth_menu->Append( ID_POPUP_PCB_SELECT_VIASIZE1 + ii, msg, wxEmptyString, true ); } return trackwidth_menu; }
MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) { D_PAD* pad; int ll; wxString msg; m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); m_canvas->SetMouseCapture( NULL, NULL ); if( Self_On == 0 ) { DisplayError( this, wxT( "Starting point not init.." ) ); return NULL; } Self_On = 0; Mself.m_End = GetCrossHairPosition(); wxPoint pt = Mself.m_End - Mself.m_Start; int min_len = KiROUND( EuclideanNorm( pt ) ); Mself.lng = min_len; // Enter the desired length. msg = StringFromValue( g_UserUnit, Mself.lng ); wxTextEntryDialog dlg( this, _( "Length:" ), _( "Length" ), msg ); if( dlg.ShowModal() != wxID_OK ) return NULL; // canceled by user msg = dlg.GetValue(); Mself.lng = ValueFromString( g_UserUnit, msg ); // Control values (ii = minimum length) if( Mself.lng < min_len ) { DisplayError( this, _( "Requested length < minimum length" ) ); return NULL; } // Calculate the elements. Mself.m_Width = GetBoard()->GetCurrentTrackWidth(); std::vector <wxPoint> buffer; ll = BuildCornersList_S_Shape( buffer, Mself.m_Start, Mself.m_End, Mself.lng, Mself.m_Width ); if( !ll ) { DisplayError( this, _( "Requested length too large" ) ); return NULL; } // Generate module. MODULE* module; module = Create_1_Module( wxEmptyString ); if( module == NULL ) return NULL; // here the module is already in the BOARD, Create_1_Module() does that. module->SetFPID( FPID( std::string( "MuSelf" ) ) ); module->SetAttributes( MOD_VIRTUAL | MOD_CMS ); module->ClearFlags(); module->SetPosition( Mself.m_End ); // Generate segments for( unsigned jj = 1; jj < buffer.size(); jj++ ) { EDGE_MODULE* PtSegm; PtSegm = new EDGE_MODULE( module ); PtSegm->SetStart( buffer[jj - 1] ); PtSegm->SetEnd( buffer[jj] ); PtSegm->SetWidth( Mself.m_Width ); PtSegm->SetLayer( module->GetLayer() ); PtSegm->SetShape( S_SEGMENT ); PtSegm->SetStart0( PtSegm->GetStart() - module->GetPosition() ); PtSegm->SetEnd0( PtSegm->GetEnd() - module->GetPosition() ); module->GraphicalItems().PushBack( PtSegm ); } // Place a pad on each end of coil. pad = new D_PAD( module ); module->Pads().PushFront( pad ); pad->SetPadName( wxT( "1" ) ); pad->SetPosition( Mself.m_End ); pad->SetPos0( pad->GetPosition() - module->GetPosition() ); pad->SetSize( wxSize( Mself.m_Width, Mself.m_Width ) ); pad->SetLayerMask( GetLayerMask( module->GetLayer() ) ); pad->SetAttribute( PAD_SMD ); pad->SetShape( PAD_CIRCLE ); D_PAD* newpad = new D_PAD( *pad ); module->Pads().Insert( newpad, pad->Next() ); pad = newpad; pad->SetPadName( wxT( "2" ) ); pad->SetPosition( Mself.m_Start ); pad->SetPos0( pad->GetPosition() - module->GetPosition() ); // Modify text positions. SetMsgPanel( module ); wxPoint refPos( ( Mself.m_Start.x + Mself.m_End.x ) / 2, ( Mself.m_Start.y + Mself.m_End.y ) / 2 ); wxPoint valPos = refPos; refPos.y -= module->Reference().GetSize().y; module->Reference().SetTextPosition( refPos ); valPos.y += module->Value().GetSize().y; module->Value().SetTextPosition( valPos ); module->Reference().SetPos0( module->Reference().GetTextPosition() - module->GetPosition() ); module->Value().SetPos0( module->Value().GetTextPosition() - module->GetPosition() ); module->CalculateBoundingBox(); module->Draw( m_canvas, DC, GR_OR ); return module; }
void DIALOG_PRINT_USING_PRINTER::initValues( ) { wxString msg; BOARD* board = m_parent->GetBoard(); s_Parameters.m_PageSetupData = s_pageSetupData; // Create layer list. wxString layerKey; LSEQ seq = board->GetEnabledLayers().UIOrder(); for( ; seq; ++seq ) { LAYER_ID layer = *seq; m_BoxSelectLayer[layer] = new wxCheckBox( this, -1, board->GetLayerName( layer ) ); if( IsCopperLayer( layer ) ) m_CopperLayersBoxSizer->Add( m_BoxSelectLayer[layer], 0, wxGROW | wxALL, 1 ); else m_TechnicalLayersBoxSizer->Add( m_BoxSelectLayer[layer], 0, wxGROW | wxALL, 1 ); layerKey.Printf( OPTKEY_LAYERBASE, layer ); bool option; if( m_config->Read( layerKey, &option ) ) m_BoxSelectLayer[layer]->SetValue( option ); else { if( s_SelectedLayers[layer] ) m_BoxSelectLayer[layer]->SetValue( true ); } } // Option for excluding contents of "Edges Pcb" layer m_Exclude_Edges_Pcb->Show( true ); // Read the scale adjust option int scale_idx = 4; // default selected scale = ScaleList[4] = 1.000 if( m_config ) { m_config->Read( OPTKEY_PRINT_X_FINESCALE_ADJ, &s_Parameters.m_XScaleAdjust ); m_config->Read( OPTKEY_PRINT_Y_FINESCALE_ADJ, &s_Parameters.m_YScaleAdjust ); m_config->Read( OPTKEY_PRINT_SCALE, &scale_idx ); m_config->Read( OPTKEY_PRINT_PAGE_FRAME, &s_Parameters.m_Print_Sheet_Ref, 1); m_config->Read( OPTKEY_PRINT_MONOCHROME_MODE, &s_Parameters.m_Print_Black_and_White, 1); m_config->Read( OPTKEY_PRINT_PAGE_PER_LAYER, &s_Parameters.m_OptionPrintPage, 0); int tmp; m_config->Read( OPTKEY_PRINT_PADS_DRILL, &tmp, PRINT_PARAMETERS::SMALL_DRILL_SHAPE ); s_Parameters.m_DrillShapeOpt = (PRINT_PARAMETERS::DrillShapeOptT) tmp; // Test for a reasonnable scale value. Set to 1 if problem if( s_Parameters.m_XScaleAdjust < MIN_SCALE || s_Parameters.m_YScaleAdjust < MIN_SCALE || s_Parameters.m_XScaleAdjust > MAX_SCALE || s_Parameters.m_YScaleAdjust > MAX_SCALE ) s_Parameters.m_XScaleAdjust = s_Parameters.m_YScaleAdjust = 1.0; s_SelectedLayers = LSET(); for( seq.Rewind(); seq; ++seq ) { LAYER_ID layer = *seq; wxString layerKey; bool option; layerKey.Printf( OPTKEY_LAYERBASE, layer ); option = false; if( m_config->Read( layerKey, &option ) ) { m_BoxSelectLayer[layer]->SetValue( option ); if( option ) s_SelectedLayers.set( layer ); } } } m_ScaleOption->SetSelection( scale_idx ); scale_idx = m_ScaleOption->GetSelection(); s_Parameters.m_PrintScale = s_ScaleList[scale_idx]; m_Print_Mirror->SetValue(s_Parameters.m_PrintMirror); m_Exclude_Edges_Pcb->SetValue(m_ExcludeEdgeLayer); m_Print_Sheet_Ref->SetValue( s_Parameters.m_Print_Sheet_Ref ); // Options to plot pads and vias holes m_Drill_Shape_Opt->SetSelection( s_Parameters.m_DrillShapeOpt ); if( s_Parameters.m_Print_Black_and_White ) m_ModeColorOption->SetSelection( 1 ); else m_ModeColorOption->SetSelection( 0 ); m_PagesOption->SetSelection(s_Parameters.m_OptionPrintPage); s_Parameters.m_PenDefaultSize = g_DrawDefaultLineThickness; AddUnitSymbol( *m_TextPenWidth, g_UserUnit ); m_DialogPenWidth->SetValue( StringFromValue( g_UserUnit, s_Parameters.m_PenDefaultSize ) ); // Create scale adjust option msg.Printf( wxT( "%f" ), s_Parameters.m_XScaleAdjust ); m_FineAdjustXscaleOpt->SetValue( msg ); msg.Printf( wxT( "%f" ), s_Parameters.m_YScaleAdjust ); m_FineAdjustYscaleOpt->SetValue( msg ); bool enable = (s_Parameters.m_PrintScale == 1.0); m_FineAdjustXscaleOpt->Enable(enable); m_FineAdjustYscaleOpt->Enable(enable); }
void DIALOG_LABEL_EDITOR::InitDialog() { wxString msg; bool multiLine = false; if( m_CurrentText->IsMultilineAllowed() ) { m_textLabel = m_textLabelMultiLine; m_textLabelSingleLine->Show( false ); multiLine = true; } else { m_textLabel = m_textLabelSingleLine; m_textLabelMultiLine->Show( false ); wxTextValidator* validator = (wxTextValidator*) m_textLabel->GetValidator(); wxArrayString excludes; // Add invalid label characters to this list. excludes.Add( wxT( " " ) ); validator->SetExcludes( excludes ); } m_textLabel->SetValue( m_CurrentText->GetText() ); m_textLabel->SetFocus(); switch( m_CurrentText->Type() ) { case SCH_GLOBAL_LABEL_T: SetTitle( _( "Global Label Properties" ) ); break; case SCH_HIERARCHICAL_LABEL_T: SetTitle( _( "Hierarchical Label Properties" ) ); break; case SCH_LABEL_T: SetTitle( _( "Label Properties" ) ); break; case SCH_SHEET_PIN_T: SetTitle( _( "Hierarchical Sheet Pin Properties." ) ); break; default: SetTitle( _( "Text Properties" ) ); m_textLabel->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler ( DIALOG_LABEL_EDITOR::OnEnterKey ), NULL, this ); break; } const int MINTEXTWIDTH = 40; // M's are big characters, a few establish a lot of width int max_len = 0; if ( !multiLine ) { max_len = m_CurrentText->GetText().Length(); } else { // calculate the length of the biggest line // we cannot use the length of the entire text that has no meaning int curr_len = MINTEXTWIDTH; int imax = m_CurrentText->GetText().Length(); for( int count = 0; count < imax; count++ ) { if( m_CurrentText->GetText()[count] == '\n' || m_CurrentText->GetText()[count] == '\r' ) // new line { curr_len = 0; } else { curr_len++; if ( max_len < curr_len ) max_len = curr_len; } } } if( max_len < MINTEXTWIDTH ) max_len = MINTEXTWIDTH; wxString textWidth; textWidth.Append( 'M', MINTEXTWIDTH ); EnsureTextCtrlWidth( m_textLabel, &textWidth ); // Set validators m_TextOrient->SetSelection( m_CurrentText->GetOrientation() ); m_TextShape->SetSelection( m_CurrentText->GetShape() ); int style = 0; if( m_CurrentText->IsItalic() ) style = 1; if( m_CurrentText->IsBold() ) style += 2; m_TextStyle->SetSelection( style ); wxString units = ReturnUnitSymbol( g_UserUnit, wxT( "(%s)" ) ); msg.Printf( _( "H%s x W%s" ), GetChars( units ), GetChars( units ) ); m_staticSizeUnits->SetLabel( msg ); msg = StringFromValue( g_UserUnit, m_CurrentText->GetSize().x ); m_TextSize->SetValue( msg ); if( m_CurrentText->Type() != SCH_GLOBAL_LABEL_T && m_CurrentText->Type() != SCH_HIERARCHICAL_LABEL_T ) { m_TextShape->Show( false ); } m_sdbSizer1OK->SetDefault(); }
/** * Function ConvertOutlineToPolygon * build a polygon (with holes) from a DRAWSEGMENT list, which is expected to be * a outline, therefore a closed main outline with perhaps closed inner outlines. * These closed inner outlines are considered as holes in the main outline * @param aSegList the initial list of drawsegments (only lines, circles and arcs). * @param aPolygons will contain the complex polygon. * @param aTolerance is the max distance between points that is still accepted as connected (internal units) * @param aErrorText is a wxString to return error message. * @param aErrorLocation is the optional position of the error in the outline */ bool ConvertOutlineToPolygon( std::vector<DRAWSEGMENT*>& aSegList, SHAPE_POLY_SET& aPolygons, wxString* aErrorText, unsigned int aTolerance, wxPoint* aErrorLocation ) { if( aSegList.size() == 0 ) return true; wxString msg; // Make a working copy of aSegList, because the list is modified during calculations std::vector< DRAWSEGMENT* > segList = aSegList; DRAWSEGMENT* graphic; wxPoint prevPt; // Find edge point with minimum x, this should be in the outer polygon // which will define the perimeter Edge.Cuts polygon. wxPoint xmin = wxPoint( INT_MAX, 0 ); int xmini = 0; for( size_t i = 0; i < segList.size(); i++ ) { graphic = (DRAWSEGMENT*) segList[i]; switch( graphic->GetShape() ) { case S_SEGMENT: { if( graphic->GetStart().x < xmin.x ) { xmin = graphic->GetStart(); xmini = i; } if( graphic->GetEnd().x < xmin.x ) { xmin = graphic->GetEnd(); xmini = i; } } break; case S_ARC: // Freerouter does not yet understand arcs, so approximate // an arc with a series of short lines and put those // line segments into the !same! PATH. { wxPoint pstart = graphic->GetArcStart(); wxPoint center = graphic->GetCenter(); double angle = -graphic->GetAngle(); double radius = graphic->GetRadius(); int steps = GetArcToSegmentCount( radius, ARC_LOW_DEF, angle / 10.0 ); wxPoint pt; for( int step = 1; step<=steps; ++step ) { double rotation = ( angle * step ) / steps; pt = pstart; RotatePoint( &pt, center, rotation ); if( pt.x < xmin.x ) { xmin = pt; xmini = i; } } } break; case S_CIRCLE: { wxPoint pt = graphic->GetCenter(); // pt has minimum x point pt.x -= graphic->GetRadius(); // when the radius <= 0, this is a mal-formed circle. Skip it if( graphic->GetRadius() > 0 && pt.x < xmin.x ) { xmin = pt; xmini = i; } } break; case S_CURVE: { graphic->RebuildBezierToSegmentsPointsList( graphic->GetWidth() ); for( unsigned int jj = 0; jj < graphic->GetBezierPoints().size(); jj++ ) { wxPoint pt = graphic->GetBezierPoints()[jj]; if( pt.x < xmin.x ) { xmin = pt; xmini = i; } } } break; case S_POLYGON: { const auto poly = graphic->GetPolyShape(); MODULE* module = aSegList[0]->GetParentModule(); double orientation = module ? module->GetOrientation() : 0.0; VECTOR2I offset = module ? module->GetPosition() : VECTOR2I( 0, 0 ); for( auto iter = poly.CIterate(); iter; iter++ ) { auto pt = *iter; RotatePoint( pt, orientation ); pt += offset; if( pt.x < xmin.x ) { xmin.x = pt.x; xmin.y = pt.y; xmini = i; } } } break; default: break; } } // Grab the left most point, assume its on the board's perimeter, and see if we // can put enough graphics together by matching endpoints to formulate a cohesive // polygon. graphic = (DRAWSEGMENT*) segList[xmini]; // The first DRAWSEGMENT is in 'graphic', ok to remove it from 'items' segList.erase( segList.begin() + xmini ); // Output the Edge.Cuts perimeter as circle or polygon. if( graphic->GetShape() == S_CIRCLE ) { int steps = GetArcToSegmentCount( graphic->GetRadius(), ARC_LOW_DEF, 360.0 ); TransformCircleToPolygon( aPolygons, graphic->GetCenter(), graphic->GetRadius(), steps ); } else if( graphic->GetShape() == S_POLYGON ) { MODULE* module = graphic->GetParentModule(); // NULL for items not in footprints double orientation = module ? module->GetOrientation() : 0.0; VECTOR2I offset = module ? module->GetPosition() : VECTOR2I( 0, 0 ); aPolygons.NewOutline(); for( auto it = graphic->GetPolyShape().CIterate( 0 ); it; it++ ) { auto pt = *it; RotatePoint( pt, orientation ); pt += offset; aPolygons.Append( pt ); } } else { // Polygon start point. Arbitrarily chosen end of the // segment and build the poly from here. wxPoint startPt = wxPoint( graphic->GetEnd() ); prevPt = graphic->GetEnd(); aPolygons.NewOutline(); aPolygons.Append( prevPt ); // Do not append the other end point yet of this 'graphic', this first // 'graphic' might be an arc or a curve. for(;;) { switch( graphic->GetShape() ) { case S_SEGMENT: { wxPoint nextPt; // Use the line segment end point furthest away from // prevPt as we assume the other end to be ON prevPt or // very close to it. if( close_st( prevPt, graphic->GetStart(), graphic->GetEnd() ) ) nextPt = graphic->GetEnd(); else nextPt = graphic->GetStart(); aPolygons.Append( nextPt ); prevPt = nextPt; } break; case S_ARC: // We do not support arcs in polygons, so approximate // an arc with a series of short lines and put those // line segments into the !same! PATH. { wxPoint pstart = graphic->GetArcStart(); wxPoint pend = graphic->GetArcEnd(); wxPoint pcenter = graphic->GetCenter(); double angle = -graphic->GetAngle(); double radius = graphic->GetRadius(); int steps = GetArcToSegmentCount( radius, ARC_LOW_DEF, angle / 10.0 ); if( !close_enough( prevPt, pstart, aTolerance ) ) { wxASSERT( close_enough( prevPt, graphic->GetArcEnd(), aTolerance ) ); angle = -angle; std::swap( pstart, pend ); } wxPoint nextPt; for( int step = 1; step<=steps; ++step ) { double rotation = ( angle * step ) / steps; nextPt = pstart; RotatePoint( &nextPt, pcenter, rotation ); aPolygons.Append( nextPt ); } prevPt = nextPt; } break; case S_CURVE: // We do not support Bezier curves in polygons, so approximate // with a series of short lines and put those // line segments into the !same! PATH. { wxPoint nextPt; bool reverse = false; // Use the end point furthest away from // prevPt as we assume the other end to be ON prevPt or // very close to it. if( close_st( prevPt, graphic->GetStart(), graphic->GetEnd() ) ) nextPt = graphic->GetEnd(); else { nextPt = graphic->GetStart(); reverse = true; } if( reverse ) { for( int jj = graphic->GetBezierPoints().size()-1; jj >= 0; jj-- ) aPolygons.Append( graphic->GetBezierPoints()[jj] ); } else { for( size_t jj = 0; jj < graphic->GetBezierPoints().size(); jj++ ) aPolygons.Append( graphic->GetBezierPoints()[jj] ); } prevPt = nextPt; } break; default: if( aErrorText ) { msg.Printf( "Unsupported DRAWSEGMENT type %s.", BOARD_ITEM::ShowShape( graphic->GetShape() ) ); *aErrorText << msg << "\n"; } if( aErrorLocation ) *aErrorLocation = graphic->GetPosition(); return false; } // Get next closest segment. graphic = findPoint( prevPt, segList, aTolerance ); // If there are no more close segments, check if the board // outline polygon can be closed. if( !graphic ) { if( close_enough( startPt, prevPt, aTolerance ) ) { // Close the polygon back to start point // aPolygons.Append( startPt ); // not needed } else { if( aErrorText ) { msg.Printf( _( "Unable to find segment with an endpoint of (%s, %s)." ), StringFromValue( MILLIMETRES, prevPt.x, true ), StringFromValue( MILLIMETRES, prevPt.y, true ) ); *aErrorText << msg << "\n"; } if( aErrorLocation ) *aErrorLocation = prevPt; return false; } break; } } } while( segList.size() ) { // emit a signal layers keepout for every interior polygon left... int hole = aPolygons.NewHole(); graphic = (DRAWSEGMENT*) segList[0]; segList.erase( segList.begin() ); // Both circles and polygons on the edge cuts layer are closed items that // do not connect to other elements, so we process them independently if( graphic->GetShape() == S_POLYGON ) { MODULE* module = graphic->GetParentModule(); // NULL for items not in footprints double orientation = module ? module->GetOrientation() : 0.0; VECTOR2I offset = module ? module->GetPosition() : VECTOR2I( 0, 0 ); for( auto it = graphic->GetPolyShape().CIterate(); it; it++ ) { auto val = *it; RotatePoint( val, orientation ); val += offset; aPolygons.Append( val, -1, hole ); } } else if( graphic->GetShape() == S_CIRCLE ) { // make a circle by segments; wxPoint center = graphic->GetCenter(); double angle = 3600.0; wxPoint start = center; int radius = graphic->GetRadius(); int steps = GetArcToSegmentCount( radius, ARC_LOW_DEF, 360.0 ); wxPoint nextPt; start.x += radius; for( int step = 0; step < steps; ++step ) { double rotation = ( angle * step ) / steps; nextPt = start; RotatePoint( &nextPt.x, &nextPt.y, center.x, center.y, rotation ); aPolygons.Append( nextPt, -1, hole ); } } else { // Polygon start point. Arbitrarily chosen end of the // segment and build the poly from here. wxPoint startPt( graphic->GetEnd() ); prevPt = graphic->GetEnd(); aPolygons.Append( prevPt, -1, hole ); // do not append the other end point yet, this first 'graphic' might be an arc for(;;) { switch( graphic->GetShape() ) { case S_SEGMENT: { wxPoint nextPt; // Use the line segment end point furthest away from // prevPt as we assume the other end to be ON prevPt or // very close to it. if( close_st( prevPt, graphic->GetStart(), graphic->GetEnd() ) ) { nextPt = graphic->GetEnd(); } else { nextPt = graphic->GetStart(); } prevPt = nextPt; aPolygons.Append( prevPt, -1, hole ); } break; case S_ARC: // Freerouter does not yet understand arcs, so approximate // an arc with a series of short lines and put those // line segments into the !same! PATH. { wxPoint pstart = graphic->GetArcStart(); wxPoint pend = graphic->GetArcEnd(); wxPoint pcenter = graphic->GetCenter(); double angle = -graphic->GetAngle(); int radius = graphic->GetRadius(); int steps = GetArcToSegmentCount( radius, ARC_LOW_DEF, angle / 10.0 ); if( !close_enough( prevPt, pstart, aTolerance ) ) { wxASSERT( close_enough( prevPt, graphic->GetArcEnd(), aTolerance ) ); angle = -angle; std::swap( pstart, pend ); } wxPoint nextPt; for( int step = 1; step <= steps; ++step ) { double rotation = ( angle * step ) / steps; nextPt = pstart; RotatePoint( &nextPt, pcenter, rotation ); aPolygons.Append( nextPt, -1, hole ); } prevPt = nextPt; } break; case S_CURVE: // We do not support Bezier curves in polygons, so approximate // with a series of short lines and put those // line segments into the !same! PATH. { wxPoint nextPt; bool reverse = false; // Use the end point furthest away from // prevPt as we assume the other end to be ON prevPt or // very close to it. if( close_st( prevPt, graphic->GetStart(), graphic->GetEnd() ) ) nextPt = graphic->GetEnd(); else { nextPt = graphic->GetStart(); reverse = true; } if( reverse ) { for( int jj = graphic->GetBezierPoints().size()-1; jj >= 0; jj-- ) aPolygons.Append( graphic->GetBezierPoints()[jj], -1, hole ); } else { for( size_t jj = 0; jj < graphic->GetBezierPoints().size(); jj++ ) aPolygons.Append( graphic->GetBezierPoints()[jj], -1, hole ); } prevPt = nextPt; } break; default: if( aErrorText ) { msg.Printf( "Unsupported DRAWSEGMENT type %s.", BOARD_ITEM::ShowShape( graphic->GetShape() ) ); *aErrorText << msg << "\n"; } if( aErrorLocation ) *aErrorLocation = graphic->GetPosition(); return false; } // Get next closest segment. graphic = findPoint( prevPt, segList, aTolerance ); // If there are no more close segments, check if polygon // can be closed. if( !graphic ) { if( close_enough( startPt, prevPt, aTolerance ) ) { // Close the polygon back to start point // aPolygons.Append( startPt, -1, hole ); // not needed } else { if( aErrorText ) { msg.Printf( _( "Unable to find segment with an endpoint of (%s, %s)." ), StringFromValue( MILLIMETRES, prevPt.x, true ), StringFromValue( MILLIMETRES, prevPt.y, true ) ); *aErrorText << msg << "\n"; } if( aErrorLocation ) *aErrorLocation = prevPt; return false; } break; } } } } return true; }
void DIALOG_COPPER_ZONE::initDialog() { BOARD* board = m_Parent->GetBoard(); wxString msg; if( m_settings.m_Zone_45_Only ) m_OrientEdgesOpt->SetSelection( 1 ); m_FillModeCtrl->SetSelection( m_settings.m_FillMode ? 1 : 0 ); AddUnitSymbol( *m_ClearanceValueTitle, g_UserUnit ); msg = StringFromValue( g_UserUnit, m_settings.m_ZoneClearance ); m_ZoneClearanceCtrl->SetValue( msg ); AddUnitSymbol( *m_MinThicknessValueTitle, g_UserUnit ); msg = StringFromValue( g_UserUnit, m_settings.m_ZoneMinThickness ); m_ZoneMinThicknessCtrl->SetValue( msg ); switch( m_settings.GetPadConnection() ) { case PAD_ZONE_CONN_THT_THERMAL: // Thermals only for THT pads m_PadInZoneOpt->SetSelection( 2 ); break; case PAD_ZONE_CONN_NONE: // Pads are not covered m_PadInZoneOpt->SetSelection( 3 ); break; default: case PAD_ZONE_CONN_THERMAL: // Use thermal relief for pads m_PadInZoneOpt->SetSelection( 1 ); break; case PAD_ZONE_CONN_FULL: // pads are covered by copper m_PadInZoneOpt->SetSelection( 0 ); break; } // Antipad and spokes are significant only for thermals if( m_settings.GetPadConnection() != PAD_ZONE_CONN_THERMAL && m_settings.GetPadConnection() != PAD_ZONE_CONN_THT_THERMAL ) { m_AntipadSizeValue->Enable( false ); m_CopperWidthValue->Enable( false ); } else { m_AntipadSizeValue->Enable( true ); m_CopperWidthValue->Enable( true ); } m_PriorityLevelCtrl->SetValue( m_settings.m_ZonePriority ); AddUnitSymbol( *m_AntipadSizeText, g_UserUnit ); AddUnitSymbol( *m_CopperBridgeWidthText, g_UserUnit ); PutValueInLocalUnits( *m_AntipadSizeValue, m_settings.m_ThermalReliefGap ); PutValueInLocalUnits( *m_CopperWidthValue, m_settings.m_ThermalReliefCopperBridge ); m_cornerSmoothingChoice->SetSelection( m_settings.GetCornerSmoothingType() ); PutValueInLocalUnits( *m_cornerSmoothingCtrl, m_settings.GetCornerRadius() ); switch( m_settings.m_Zone_HatchingStyle ) { case CPolyLine::NO_HATCH: m_OutlineAppearanceCtrl->SetSelection( 0 ); break; case CPolyLine::DIAGONAL_EDGE: m_OutlineAppearanceCtrl->SetSelection( 1 ); break; case CPolyLine::DIAGONAL_FULL: m_OutlineAppearanceCtrl->SetSelection( 2 ); break; } m_ArcApproximationOpt->SetSelection( m_settings.m_ArcToSegmentsCount == ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF ? 1 : 0 ); // Create one column in m_LayerSelectionCtrl wxListItem column0; column0.SetId( 0 ); m_LayerSelectionCtrl->InsertColumn( 0, column0 ); wxImageList* imageList = new wxImageList( LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y ); m_LayerSelectionCtrl->AssignImageList( imageList, wxIMAGE_LIST_SMALL ); int ctrlWidth = 0; // Min width for m_LayerSelectionCtrl to show the layers names int imgIdx = 0; LSET cu_set = LSET::AllCuMask( board->GetCopperLayerCount() ); for( LSEQ cu_stack = cu_set.UIOrder(); cu_stack; ++cu_stack, imgIdx++ ) { LAYER_ID layer = *cu_stack; m_LayerId.push_back( layer ); msg = board->GetLayerName( layer ); msg.Trim(); EDA_COLOR_T layerColor = board->GetLayerColor( layer ); imageList->Add( makeLayerBitmap( layerColor ) ); int itemIndex = m_LayerSelectionCtrl->InsertItem( m_LayerSelectionCtrl->GetItemCount(), msg, imgIdx ); if( m_settings.m_CurrentZone_Layer == layer ) m_LayerSelectionCtrl->Select( itemIndex ); wxSize tsize( GetTextSize( msg, m_LayerSelectionCtrl ) ); ctrlWidth = std::max( ctrlWidth, tsize.x ); } // The most easy way to ensure the right size is to use wxLIST_AUTOSIZE // unfortunately this option does not work well both on // wxWidgets 2.8 ( column width too small), and // wxWidgets 2.9 ( column width too large) ctrlWidth += LAYER_BITMAP_SIZE_X + 25; // Add bitmap width + margin between bitmap and text m_LayerSelectionCtrl->SetColumnWidth( 0, ctrlWidth ); ctrlWidth += 25; // add small margin between text and window borders // and room for vertical scroll bar m_LayerSelectionCtrl->SetMinSize( wxSize( ctrlWidth, -1 ) ); wxString netNameDoNotShowFilter = wxT( "Net-*" ); if( m_Config ) { int opt = m_Config->Read( ZONE_NET_SORT_OPTION_KEY, 1l ); m_NetDisplayOption->SetSelection( opt ); m_Config->Read( ZONE_NET_FILTER_STRING_KEY, netNameDoNotShowFilter ); } else m_NetDisplayOption->SetSelection( 1 ); m_ShowNetNameFilter->SetValue( m_netNameShowFilter ); initListNetsParams(); // Build list of nets: m_DoNotShowNetNameFilter->SetValue( netNameDoNotShowFilter ); buildAvailableListOfNets(); wxCommandEvent event; OnCornerSmoothingModeChoice( event ); }