MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, FP_LIB_TABLE* aTable, bool aUseFootprintViewer, wxDC* aDC ) { MODULE* module = NULL; wxPoint curspos = GetCrossHairPosition(); wxString moduleName, keys; wxString libName = aLibrary; bool allowWildSeach = true; static wxArrayString HistoryList; static wxString lastComponentName; // Ask for a component name or key words DIALOG_GET_COMPONENT dlg( this, HistoryList, _( "Load Footprint" ), aUseFootprintViewer ); dlg.SetComponentName( lastComponentName ); if( dlg.ShowModal() == wxID_CANCEL ) return NULL; if( dlg.m_GetExtraFunction ) { // SelectFootprintFromLibBrowser() returns the "full" footprint name, i.e. // <lib_name>/<footprint name> or FPID format "lib_name:fp_name:rev#" moduleName = SelectFootprintFromLibBrowser(); } else { moduleName = dlg.GetComponentName(); } if( moduleName.IsEmpty() ) // Cancel command { m_canvas->MoveCursorToCrossHair(); return NULL; } if( dlg.IsKeyword() ) // Selection by keywords { allowWildSeach = false; keys = moduleName; moduleName = SelectFootprint( this, libName, wxEmptyString, keys, aTable ); if( moduleName.IsEmpty() ) // Cancel command { m_canvas->MoveCursorToCrossHair(); return NULL; } } else if( moduleName.Contains( wxT( "?" ) ) || moduleName.Contains( wxT( "*" ) ) ) // Selection wild card { allowWildSeach = false; moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, aTable ); if( moduleName.IsEmpty() ) { m_canvas->MoveCursorToCrossHair(); return NULL; // Cancel command. } } FPID fpid; wxCHECK_MSG( fpid.Parse( moduleName ) < 0, NULL, wxString::Format( wxT( "Could not parse FPID string '%s'." ), GetChars( moduleName ) ) ); try { module = loadFootprint( fpid ); } catch( const IO_ERROR& ioe ) { wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ), fpid.Format().c_str(), GetChars( ioe.errorText ) ); } if( !module && allowWildSeach ) // Search with wild card { allowWildSeach = false; wxString wildname = wxChar( '*' ) + moduleName + wxChar( '*' ); moduleName = wildname; moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, aTable ); if( moduleName.IsEmpty() ) { m_canvas->MoveCursorToCrossHair(); return NULL; // Cancel command. } else { FPID fpid; wxCHECK_MSG( fpid.Parse( moduleName ) < 0, NULL, wxString::Format( wxT( "Could not parse FPID string '%s'." ), GetChars( moduleName ) ) ); try { module = loadFootprint( fpid ); } catch( const IO_ERROR& ioe ) { wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ), fpid.Format().c_str(), GetChars( ioe.errorText ) ); } } } SetCrossHairPosition( curspos ); m_canvas->MoveCursorToCrossHair(); if( module ) { GetBoard()->Add( module, ADD_APPEND ); lastComponentName = moduleName; AddHistoryComponentName( HistoryList, moduleName ); module->SetFlags( IS_NEW ); module->SetLink( 0 ); if( IsGalCanvasActive() ) module->SetPosition( wxPoint( 0, 0 ) ); // cursor in GAL may not be initialized at the moment else module->SetPosition( curspos ); module->SetTimeStamp( GetNewTimeStamp() ); GetBoard()->m_Status_Pcb = 0; // Put it on FRONT layer, // (Can be stored flipped if the lib is an archive built from a board) if( module->IsFlipped() ) module->Flip( module->GetPosition() ); // Place it in orientation 0, // even if it is not saved with orientation 0 in lib // (Can happen if the lib is an archive built from a board) Rotate_Module( NULL, module, 0, false ); RecalculateAllTracksNetcode(); if( aDC ) module->Draw( m_canvas, aDC, GR_OR ); } return module; }
/** * Function PickModule * find the "best" module place * The criteria are: * - Maximum ratsnest with modules already placed * - Max size, and number of pads max */ static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) { MODULE* Module; std::vector <MODULE*> moduleList; // Build sorted footprints list (sort by decreasing size ) Module = pcbframe->GetBoard()->m_Modules; for( ; Module != NULL; Module = Module->Next() ) { Module->CalculateBoundingBox(); moduleList.push_back( Module ); } sort( moduleList.begin(), moduleList.end(), Tri_PlaceModules ); for( unsigned ii = 0; ii < moduleList.size(); ii++ ) { Module = moduleList[ii]; Module->SetFlag( 0 ); if( !Module->NeedsPlaced() ) continue; pcbframe->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK; pcbframe->SetMsgPanel( Module ); pcbframe->build_ratsnest_module( Module ); // Calculate external ratsnest. for( unsigned ii = 0; ii < pcbframe->GetBoard()->m_LocalRatsnest.size(); ii++ ) { if( ( pcbframe->GetBoard()->m_LocalRatsnest[ii].m_Status & LOCAL_RATSNEST_ITEM ) == 0 ) Module->IncrementFlag(); } } pcbframe->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK; sort( moduleList.begin(), moduleList.end(), sortFootprintsByRatsnestSize ); // Search for "best" module. MODULE* bestModule = NULL; MODULE* altModule = NULL; for( unsigned ii = 0; ii < moduleList.size(); ii++ ) { Module = moduleList[ii]; if( !Module->NeedsPlaced() ) continue; altModule = Module; if( Module->GetFlag() == 0 ) continue; bestModule = Module; break; } if( bestModule ) return bestModule; else return altModule; }
void DIALOG_GENDRILL::InitDisplayParams() { wxString msg; m_Choice_Unit->SetSelection( m_UnitDrillIsInch ? 1 : 0 ); m_Choice_Zeros_Format->SetSelection( m_ZerosFormat ); UpdatePrecisionOptions(); m_Check_Minimal->SetValue( m_MinimalHeader ); if( m_DrillOriginIsAuxAxis ) m_Choice_Drill_Offset->SetSelection( 1 ); m_Check_Mirror->SetValue( m_Mirror ); m_Check_Merge_PTH_NPTH->SetValue( m_Merge_PTH_NPTH ); m_Choice_Drill_Map->SetSelection( m_mapFileType ); m_ViaDrillValue->SetLabel( _( "Use Netclass values" ) ); m_MicroViaDrillValue->SetLabel( _( "Use Netclass values" ) ); // See if we have some buried vias or/and microvias, and display // microvias drill value if so m_throughViasCount = 0; m_microViasCount = 0; m_blindOrBuriedViasCount = 0; for( TRACK* track = m_parent->GetBoard()->m_Track; track != NULL; track = track->Next() ) { const VIA *via = dynamic_cast<const VIA*>( track ); if( via ) { switch( via->GetViaType() ) { case VIA_THROUGH: m_throughViasCount++; break; case VIA_MICROVIA: m_microViasCount++; break; case VIA_BLIND_BURIED: m_blindOrBuriedViasCount++; break; default: break; } } } m_MicroViaDrillValue->Enable( m_microViasCount ); // Count plated pad holes and not plated pad holes: m_platedPadsHoleCount = 0; m_notplatedPadsHoleCount = 0; for( MODULE* module = m_parent->GetBoard()->m_Modules; module; module = module->Next() ) { for( D_PAD* pad = module->Pads(); pad != NULL; pad = pad->Next() ) { if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE ) { if( pad->GetDrillSize().x != 0 ) { if( pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ) m_notplatedPadsHoleCount++; else m_platedPadsHoleCount++; } } else { if( pad->GetDrillSize().x != 0 && pad->GetDrillSize().y != 0 ) { if( pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ) m_notplatedPadsHoleCount++; else m_platedPadsHoleCount++; } } } } // Display hole counts: msg = m_PlatedPadsCountInfoMsg->GetLabel(); msg << wxT( " " ) << m_platedPadsHoleCount; m_PlatedPadsCountInfoMsg->SetLabel( msg ); msg = m_NotPlatedPadsCountInfoMsg->GetLabel(); msg << wxT( " " ) << m_notplatedPadsHoleCount; m_NotPlatedPadsCountInfoMsg->SetLabel( msg ); msg = m_ThroughViasInfoMsg->GetLabel(); msg << wxT( " " ) << m_throughViasCount; m_ThroughViasInfoMsg->SetLabel( msg ); msg = m_MicroViasInfoMsg->GetLabel(); msg << wxT( " " ) << m_microViasCount; m_MicroViasInfoMsg->SetLabel( msg ); msg = m_BuriedViasInfoMsg->GetLabel(); msg << wxT( " " ) << m_blindOrBuriedViasCount; m_BuriedViasInfoMsg->SetLabel( msg ); // Output directory m_outputDirectoryName->SetValue( m_plotOpts.GetOutputDirectory() ); }
void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, const wxString& aCmpFileName, REPORTER* aReporter, bool aChangeFootprints, bool aDeleteUnconnectedTracks, bool aDeleteExtraFootprints, bool aSelectByTimeStamp, bool aDeleteSinglePadNets, bool aIsDryRun ) { wxString msg; NETLIST netlist; KIGFX::VIEW* view = GetGalCanvas()->GetView(); BOARD* board = GetBoard(); netlist.SetIsDryRun( aIsDryRun ); netlist.SetFindByTimeStamp( aSelectByTimeStamp ); netlist.SetDeleteExtraFootprints( aDeleteExtraFootprints ); netlist.SetReplaceFootprints( aChangeFootprints ); try { std::auto_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader( &netlist, aNetlistFileName, aCmpFileName ) ); if( !netlistReader.get() ) { msg.Printf( _( "Cannot open netlist file \"%s\"." ), GetChars( aNetlistFileName ) ); wxMessageBox( msg, _( "Netlist Load Error." ), wxOK | wxICON_ERROR, this ); return; } SetLastNetListRead( aNetlistFileName ); netlistReader->LoadNetlist(); loadFootprints( netlist, aReporter ); } catch( const IO_ERROR& ioe ) { msg.Printf( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() ); wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR ); return; } // Clear undo and redo lists to avoid inconsistencies between lists if( !netlist.IsDryRun() ) GetScreen()->ClearUndoRedoList(); if( !netlist.IsDryRun() ) { // Remove old modules for( MODULE* module = board->m_Modules; module; module = module->Next() ) { module->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); view->Remove( module ); } } // Clear selection, just in case a selected item has to be removed m_toolManager->RunAction( COMMON_ACTIONS::selectionClear, true ); netlist.SortByReference(); board->ReplaceNetlist( netlist, aDeleteSinglePadNets, aReporter ); // If it was a dry run, nothing has changed so we're done. if( netlist.IsDryRun() ) return; OnModify(); SetCurItem( NULL ); // Reload modules for( MODULE* module = board->m_Modules; module; module = module->Next() ) { module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); view->Add( module ); module->ViewUpdate(); } if( aDeleteUnconnectedTracks && board->m_Track ) { // Remove erroneous tracks. This should probably pushed down to the #BOARD object. RemoveMisConnectedTracks(); } // Rebuild the board connectivity: if( IsGalCanvasActive() ) board->GetRatsnest()->ProcessBoard(); Compile_Ratsnest( NULL, true ); SetMsgPanel( board ); m_canvas->Refresh(); }
void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) { BOARD_ITEM* item = GetCurItem(); m_canvas->CrossHairOff( DC ); if( GetToolId() == ID_NO_TOOL_SELECTED ) { if( item && item->GetFlags() ) // Move item command in progress { switch( item->Type() ) { case PCB_MODULE_TEXT_T: PlaceTexteModule( static_cast<TEXTE_MODULE*>( item ), DC ); break; case PCB_MODULE_EDGE_T: SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); Place_EdgeMod( static_cast<EDGE_MODULE*>( item ) ); break; case PCB_PAD_T: PlacePad( static_cast<D_PAD*>( item ), DC ); break; default: { wxString msg; msg.Printf( wxT( "WinEDA_ModEditFrame::OnLeftClick err:Struct %d, m_Flag %X" ), item->Type(), item->GetFlags() ); DisplayError( this, msg ); item->ClearFlags(); break; } } } else { if( !wxGetKeyState( WXK_SHIFT ) && !wxGetKeyState( WXK_ALT ) && !wxGetKeyState( WXK_CONTROL ) ) item = ModeditLocateAndDisplay(); SetCurItem( item ); } } item = GetCurItem(); bool no_item_edited = item == NULL || item->GetFlags() == 0; switch( GetToolId() ) { case ID_NO_TOOL_SELECTED: break; case ID_MODEDIT_CIRCLE_TOOL: case ID_MODEDIT_ARC_TOOL: case ID_MODEDIT_LINE_TOOL: if( no_item_edited ) { STROKE_T shape = S_SEGMENT; if( GetToolId() == ID_MODEDIT_CIRCLE_TOOL ) shape = S_CIRCLE; if( GetToolId() == ID_MODEDIT_ARC_TOOL ) shape = S_ARC; SetCurItem( Begin_Edge_Module( (EDGE_MODULE*) NULL, DC, shape ) ); } else if( item->IsNew() ) { if( ( (EDGE_MODULE*) item )->GetShape() == S_CIRCLE ) { End_Edge_Module( (EDGE_MODULE*) item ); SetCurItem( NULL ); m_canvas->Refresh(); } else if( ( (EDGE_MODULE*) item )->GetShape() == S_ARC ) { End_Edge_Module( (EDGE_MODULE*) item ); SetCurItem( NULL ); m_canvas->Refresh(); } else if( ( (EDGE_MODULE*) item )->GetShape() == S_SEGMENT ) { SetCurItem( Begin_Edge_Module( (EDGE_MODULE*) item, DC, S_SEGMENT ) ); } else { wxMessageBox( wxT( "ProcessCommand error: unknown shape" ) ); } } break; case ID_MODEDIT_DELETE_TOOL: if( ! no_item_edited ) // Item in edit, cannot delete it break; item = ModeditLocateAndDisplay(); if( item && item->Type() != PCB_MODULE_T ) // Cannot delete the module itself { SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); RemoveStruct( item ); SetCurItem( NULL ); } break; case ID_MODEDIT_ANCHOR_TOOL: { MODULE* module = GetBoard()->m_Modules; if( module == NULL // No module loaded || (module->GetFlags() != 0) ) break; SaveCopyInUndoList( module, UR_MODEDIT ); // set the new relative internal local coordinates of footprint items wxPoint moveVector = module->GetPosition() - GetCrossHairPosition(); module->MoveAnchorPosition( moveVector ); // Usually, we do not need to change twice the anchor position, // so deselect the active tool SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); SetCurItem( NULL ); m_canvas->Refresh(); } break; case ID_MODEDIT_PLACE_GRID_COORD: m_canvas->DrawGridAxis( DC, GR_XOR, GetBoard()->GetGridOrigin() ); SetGridOrigin( GetCrossHairPosition() ); m_canvas->DrawGridAxis( DC, GR_COPY, GetBoard()->GetGridOrigin() ); GetScreen()->SetModify(); break; case ID_MODEDIT_TEXT_TOOL: if( GetBoard()->m_Modules == NULL ) break; SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); CreateTextModule( GetBoard()->m_Modules, DC ); break; case ID_MODEDIT_PAD_TOOL: if( GetBoard()->m_Modules ) { SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); AddPad( GetBoard()->m_Modules, true ); } break; default: DisplayError( this, wxT( "FOOTPRINT_EDIT_FRAME::ProcessCommand error" ) ); SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); } m_canvas->CrossHairOn( DC ); }
void EDIT_TOOL::remove( BOARD_ITEM* aItem ) { BOARD* board = getModel<BOARD>(); switch( aItem->Type() ) { case PCB_MODULE_T: { MODULE* module = static_cast<MODULE*>( aItem ); module->ClearFlags(); module->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, getView(), _1 ) ); // Module itself is deleted after the switch scope is finished // list of pads is rebuild by BOARD::BuildListOfNets() // Clear flags to indicate, that the ratsnest, list of nets & pads are not valid anymore board->m_Status_Pcb = 0; } break; // Default removal procedure case PCB_MODULE_TEXT_T: { TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( aItem ); switch( text->GetType() ) { case TEXTE_MODULE::TEXT_is_REFERENCE: DisplayError( getEditFrame<PCB_BASE_FRAME>(), _( "Cannot delete component reference." ) ); return; case TEXTE_MODULE::TEXT_is_VALUE: DisplayError( getEditFrame<PCB_BASE_FRAME>(), _( "Cannot delete component value." ) ); return; case TEXTE_MODULE::TEXT_is_DIVERS: // suppress warnings break; } if( m_editModules ) { MODULE* module = static_cast<MODULE*>( aItem->GetParent() ); module->SetLastEditTime(); board->m_Status_Pcb = 0; // it is done in the legacy view aItem->DeleteStructure(); } return; } case PCB_PAD_T: case PCB_MODULE_EDGE_T: { MODULE* module = static_cast<MODULE*>( aItem->GetParent() ); module->SetLastEditTime(); board->m_Status_Pcb = 0; // it is done in the legacy view if( !m_editModules ) { getView()->Remove( aItem ); board->Remove( aItem ); } aItem->DeleteStructure(); return; } case PCB_LINE_T: // a segment not on copper layers case PCB_TEXT_T: // a text on a layer case PCB_TRACE_T: // a track segment (segment on a copper layer) case PCB_VIA_T: // a via (like track segment on a copper layer) case PCB_DIMENSION_T: // a dimension (graphic item) case PCB_TARGET_T: // a target (graphic item) case PCB_MARKER_T: // a marker used to show something case PCB_ZONE_T: // SEG_ZONE items are now deprecated case PCB_ZONE_AREA_T: break; default: // other types do not need to (or should not) be handled assert( false ); return; } getView()->Remove( aItem ); board->Remove( aItem ); }
void DIALOG_PAD_PROPERTIES::PadPropertiesAccept( wxCommandEvent& event ) { if( !padValuesOK() ) return; bool rastnestIsChanged = false; int isign = m_isFlipped ? -1 : 1; transferDataToPad( &m_padMaster ); if( m_currentPad ) // Set current Pad parameters { wxSize size; MODULE* module = m_currentPad->GetParent(); m_parent->SaveCopyInUndoList( module, UR_CHANGED ); module->SetLastEditTime(); // redraw the area where the pad was, without pad (delete pad on screen) m_currentPad->SetFlags( DO_NOT_DRAW ); m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() ); m_currentPad->ClearFlags( DO_NOT_DRAW ); // Update values m_currentPad->SetShape( m_padMaster.GetShape() ); m_currentPad->SetAttribute( m_padMaster.GetAttribute() ); if( m_currentPad->GetPosition() != m_padMaster.GetPosition() ) { m_currentPad->SetPosition( m_padMaster.GetPosition() ); rastnestIsChanged = true; } // compute the pos 0 value, i.e. pad position for module with orientation = 0 // i.e. relative to module origin (module position) wxPoint pt = m_currentPad->GetPosition() - module->GetPosition(); RotatePoint( &pt, -module->GetOrientation() ); m_currentPad->SetPos0( pt ); m_currentPad->SetOrientation( m_padMaster.GetOrientation() * isign + module->GetOrientation() ); m_currentPad->SetSize( m_padMaster.GetSize() ); size = m_padMaster.GetDelta(); size.y *= isign; m_currentPad->SetDelta( size ); m_currentPad->SetDrillSize( m_padMaster.GetDrillSize() ); m_currentPad->SetDrillShape( m_padMaster.GetDrillShape() ); wxPoint offset = m_padMaster.GetOffset(); offset.y *= isign; m_currentPad->SetOffset( offset ); m_currentPad->SetPadToDieLength( m_padMaster.GetPadToDieLength() ); if( m_currentPad->GetLayerMask() != m_padMaster.GetLayerMask() ) { rastnestIsChanged = true; m_currentPad->SetLayerMask( m_padMaster.GetLayerMask() ); } if( m_isFlipped ) m_currentPad->SetLayerMask( FlipLayerMask( m_currentPad->GetLayerMask() ) ); m_currentPad->SetPadName( m_padMaster.GetPadName() ); if( m_currentPad->GetNetname() != m_padMaster.GetNetname() ) { if( m_padMaster.GetNetname().IsEmpty() ) { rastnestIsChanged = true; m_currentPad->SetNet( 0 ); m_currentPad->SetNetname( wxEmptyString ); } else { const NETINFO_ITEM* net = m_board->FindNet( m_padMaster.GetNetname() ); if( net ) { rastnestIsChanged = true; m_currentPad->SetNetname( m_padMaster.GetNetname() ); m_currentPad->SetNet( net->GetNet() ); } else DisplayError( NULL, _( "Unknown netname, netname not changed" ) ); } } m_currentPad->SetLocalClearance( m_padMaster.GetLocalClearance() ); m_currentPad->SetLocalSolderMaskMargin( m_padMaster.GetLocalSolderMaskMargin() ); m_currentPad->SetLocalSolderPasteMargin( m_padMaster.GetLocalSolderPasteMargin() ); m_currentPad->SetLocalSolderPasteMarginRatio( m_padMaster.GetLocalSolderPasteMarginRatio() ); m_currentPad->SetZoneConnection( m_padMaster.GetZoneConnection() ); m_currentPad->SetThermalWidth( m_padMaster.GetThermalWidth() ); m_currentPad->SetThermalGap( m_padMaster.GetThermalGap() ); module->CalculateBoundingBox(); m_parent->SetMsgPanel( m_currentPad ); // redraw the area where the pad was m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() ); m_parent->OnModify(); } EndModal( wxID_OK ); if( rastnestIsChanged ) // The net ratsnest must be recalculated m_board->m_Status_Pcb = 0; }
void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRedoCommand, bool aRebuildRatsnet ) { BOARD_ITEM* item; bool not_found = false; bool reBuild_ratsnest = false; KIGFX::VIEW* view = GetGalCanvas()->GetView(); RN_DATA* ratsnest = GetBoard()->GetRatsnest(); // Undo in the reverse order of list creation: (this can allow stacked changes // like the same item can be changes and deleted in the same complex command bool build_item_list = true; // if true the list of existing items must be rebuilt for( int ii = aList->GetCount() - 1; ii >= 0 ; ii-- ) { item = (BOARD_ITEM*) aList->GetPickedItem( ii ); wxASSERT( item ); /* Test for existence of item on board. * It could be deleted, and no more on board: * - if a call to SaveCopyInUndoList was forgotten in Pcbnew * - in zones outlines, when a change in one zone merges this zone with an other * This test avoids a Pcbnew crash * Obviously, this test is not made for deleted items */ UNDO_REDO_T status = aList->GetPickedItemStatus( ii ); if( status != UR_DELETED ) { if( build_item_list ) // Build list of existing items, for integrity test TestForExistingItem( GetBoard(), NULL ); build_item_list = false; if( !TestForExistingItem( GetBoard(), item ) ) { // Remove this non existent item aList->RemovePicker( ii ); ii++; // the current item was removed, ii points now the next item // decrement it because it will be incremented later not_found = true; continue; } } item->ClearFlags(); // see if we must rebuild ratsnets and pointers lists switch( item->Type() ) { case PCB_MODULE_T: case PCB_ZONE_AREA_T: case PCB_TRACE_T: case PCB_VIA_T: reBuild_ratsnest = true; break; default: break; } switch( aList->GetPickedItemStatus( ii ) ) { case UR_CHANGED: /* Exchange old and new data for each item */ { BOARD_ITEM* image = (BOARD_ITEM*) aList->GetPickedItemLink( ii ); // Remove all pads/drawings/texts, as they become invalid // for the VIEW after SwapData() called for modules if( item->Type() == PCB_MODULE_T ) { MODULE* oldModule = static_cast<MODULE*>( item ); oldModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); } ratsnest->Remove( item ); item->SwapData( image ); // Update all pads/drawings/texts, as they become invalid // for the VIEW after SwapData() called for modules if( item->Type() == PCB_MODULE_T ) { MODULE* newModule = static_cast<MODULE*>( item ); newModule->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); } ratsnest->Add( item ); item->ClearFlags( SELECTED ); item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); } break; case UR_NEW: /* new items are deleted */ aList->SetPickedItemStatus( UR_DELETED, ii ); GetBoard()->Remove( item ); if( item->Type() == PCB_MODULE_T ) { MODULE* module = static_cast<MODULE*>( item ); module->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); } view->Remove( item ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); break; case UR_DELETED: /* deleted items are put in List, as new items */ aList->SetPickedItemStatus( UR_NEW, ii ); GetBoard()->Add( item ); if( item->Type() == PCB_MODULE_T ) { MODULE* module = static_cast<MODULE*>( item ); module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1) ); } view->Add( item ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); build_item_list = true; break; case UR_MOVED: item->Move( aRedoCommand ? aList->m_TransformPoint : -aList->m_TransformPoint ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); ratsnest->Update( item ); break; case UR_ROTATED: item->Rotate( aList->m_TransformPoint, aRedoCommand ? m_rotationAngle : -m_rotationAngle ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); ratsnest->Update( item ); break; case UR_ROTATED_CLOCKWISE: item->Rotate( aList->m_TransformPoint, aRedoCommand ? -m_rotationAngle : m_rotationAngle ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); ratsnest->Update( item ); break; case UR_FLIPPED: item->Flip( aList->m_TransformPoint ); item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); ratsnest->Update( item ); break; default: { wxString msg; msg.Printf( wxT( "PutDataInPreviousState() error (unknown code %X)" ), aList->GetPickedItemStatus( ii ) ); wxMessageBox( msg ); } break; } } if( not_found ) wxMessageBox( wxT( "Incomplete undo/redo operation: some items not found" ) ); // Rebuild pointers and ratsnest that can be changed. if( reBuild_ratsnest && aRebuildRatsnet ) { if( IsGalCanvasActive() ) ratsnest->Recalculate(); else Compile_Ratsnest( NULL, true ); } }
// Redraw the BOARD items but not cursors, axis or grid void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset ) { /* The order of drawing is flexible on some systems and not on others. For * OSes which use OR to draw, the order is not important except for the * effect of the highlight and its relationship to markers. See comment * below. * This order independence comes from the fact that a binary OR operation is * commutative in nature. * However on the OSX, the OR operation is not used, and so this sequence * below is chosen to give MODULEs the highest visible priority. */ /* Draw all tracks and zones. As long as dark colors are used for the * tracks, Then the OR draw mode should show tracks underneath other * tracks. But a white track will cover any other color since it has * more bits to OR in. */ for( TRACK* track = m_Track; track; track = track->Next() ) { track->Draw( aPanel, DC, aDrawMode ); } for( SEGZONE* zone = m_Zone; zone; zone = zone->Next() ) { zone->Draw( aPanel, DC, aDrawMode ); } // Draw the graphic items for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() ) { if( item->IsMoving() ) continue; switch( item->Type() ) { case PCB_DIMENSION_T: case PCB_TEXT_T: case PCB_TARGET_T: case PCB_LINE_T: item->Draw( aPanel, DC, aDrawMode ); break; default: break; } } // Draw areas (i.e. zones) for( int ii = 0; ii < GetAreaCount(); ii++ ) { ZONE_CONTAINER* zone = GetArea( ii ); // Areas must be drawn here only if not moved or dragged, // because these areas are drawn by ManageCursor() in a specific manner if( ( zone->GetFlags() & (IN_EDIT | IS_DRAGGED | IS_MOVED) ) == 0 ) { zone->Draw( aPanel, DC, aDrawMode ); zone->DrawFilledArea( aPanel, DC, aDrawMode ); } } for( MODULE* module = m_Modules; module; module = module->Next() ) { bool display = true; LAYER_MSK layerMask = ALL_CU_LAYERS; if( module->IsMoving() ) continue; if( !IsElementVisible( PCB_VISIBLE( MOD_FR_VISIBLE ) ) ) { if( module->GetLayer() == LAYER_N_FRONT ) display = false; layerMask &= ~LAYER_FRONT; } if( !IsElementVisible( PCB_VISIBLE( MOD_BK_VISIBLE ) ) ) { if( module->GetLayer() == LAYER_N_BACK ) display = false; layerMask &= ~LAYER_BACK; } if( display ) module->Draw( aPanel, DC, aDrawMode ); else Trace_Pads_Only( aPanel, DC, module, 0, 0, layerMask, aDrawMode ); } if( IsHighLightNetON() ) DrawHighLight( aPanel, DC, GetHighLightNetCode() ); // draw the BOARD's markers last, otherwise the high light will erase any marker on a pad for( unsigned i = 0; i < m_markers.size(); ++i ) { m_markers[i]->Draw( aPanel, DC, aDrawMode ); } }
void PCB_BASE_FRAME::ResetModuleTextSizes( const wxString & aFilter, bool aRef, bool aValue, bool aOthers ) { MODULE* module; BOARD_ITEM* boardItem; ITEM_PICKER itemWrapper( NULL, UR_CHANGED ); PICKED_ITEMS_LIST undoItemList; unsigned int ii; // Prepare undo list for( module = GetBoard()->m_Modules; module; module = module->Next() ) { itemWrapper.SetItem( module ); if( ! aFilter.IsEmpty() ) { if( ! WildCompareString( aFilter, FROM_UTF8( module->GetFPID().Format().c_str() ), false ) ) continue; } if( aRef ) { TEXTE_MODULE *item = &module->Reference(); if( item->GetSize() != GetDesignSettings().m_ModuleTextSize || item->GetThickness() != GetDesignSettings().m_ModuleTextWidth ) { undoItemList.PushItem( itemWrapper ); } } if( aValue ) { TEXTE_MODULE *item = &module->Value(); if( item->GetSize() != GetDesignSettings().m_ModuleTextSize || item->GetThickness() != GetDesignSettings().m_ModuleTextWidth ) { undoItemList.PushItem( itemWrapper ); } } if( aOthers ) { // Go through all other module text fields for( boardItem = module->GraphicalItems(); boardItem; boardItem = boardItem->Next() ) { if( boardItem->Type() == PCB_MODULE_TEXT_T ) { TEXTE_MODULE *item = static_cast<TEXTE_MODULE*>( boardItem ); if( item->GetSize() != GetDesignSettings().m_ModuleTextSize || item->GetThickness() != GetDesignSettings().m_ModuleTextWidth ) { undoItemList.PushItem( itemWrapper ); } } } } } // Exit if there's nothing to do if( !undoItemList.GetCount() ) return; SaveCopyInUndoList( undoItemList, UR_CHANGED ); // Apply changes to modules in the undo list for( ii = 0; ii < undoItemList.GetCount(); ii++ ) { module = (MODULE*) undoItemList.GetPickedItem( ii ); if( aRef ) { module->Reference().SetThickness( GetDesignSettings().m_ModuleTextWidth ); module->Reference().SetSize( GetDesignSettings().m_ModuleTextSize ); } if( aValue ) { module->Value().SetThickness( GetDesignSettings().m_ModuleTextWidth ); module->Value().SetSize( GetDesignSettings().m_ModuleTextSize ); } if( aOthers ) { for( boardItem = module->GraphicalItems(); boardItem; boardItem = boardItem->Next() ) { if( boardItem->Type() == PCB_MODULE_TEXT_T ) { TEXTE_MODULE *item = static_cast<TEXTE_MODULE*>( boardItem ); item->SetThickness( GetDesignSettings().m_ModuleTextWidth ); item->SetSize( GetDesignSettings().m_ModuleTextSize ); } } } } OnModify(); }
MODULE * WinEDA_PcbFrame::Create_MuWaveComponent(wxDC * DC, int shape_type) /***************************************************************************/ /* Create a module "GAP" or "STUB" This a "gap" or "stub" used in micro wave designs This modue has 2 pads: SMD, rectangular, H size = V size = current track width. the "gap" is isolation created between this 2 pads */ { int gap_size, oX, ii; float fcoeff; D_PAD* pt_pad; MODULE * Module; wxString msg, cmp_name; int pad_count = 2; int angle = 0; bool abort; /* Entree de la longueur desiree du gap*/ gap_size = g_DesignSettings.m_CurrentTrackWidth; // Valeur raisonnable switch ( shape_type ) { case 0: msg = _("Gap"); cmp_name = wxT("GAP"); break; case 1: msg = _("Stub"); cmp_name = wxT("STUB"); pad_count = 2; break; case 2: msg = _("Arc Stub"); cmp_name = wxT("ASTUB"); pad_count = 1; break; default: msg = wxT("???"); break; } DrawPanel->m_IgnoreMouseEvents = TRUE; wxString value; if( UnitMetric) { fcoeff = 10000.0/25.4 ; value.Printf( wxT("%2.4f"),gap_size / fcoeff); msg += _(" (mm):"); abort = Get_Message(msg,value, this); } else { fcoeff = 10000.0 ; value.Printf( wxT("%2.3f"),gap_size / fcoeff); msg += _(" (inch):"); abort = Get_Message(msg, value, this); } double fval; if ( ! value.ToDouble(&fval) ) { DisplayError(this, _("Incorrect number, abort")); abort = TRUE; } gap_size = ABS( (int) round( fval * fcoeff )); if ( ! abort && (shape_type == 2) ) { fcoeff = 10.0 ; value.Printf( wxT("%3.1f"),angle / fcoeff); msg = _("Angle (0.1deg):"); abort = Get_Message(msg, value, this); if ( ! value.ToDouble(&fval) ) { DisplayError(this, _("Incorrect number, abort")); abort = TRUE; } angle = ABS( (int) round( fval * fcoeff )); if ( angle > 1800 ) angle = 1800; } if (abort) { DrawPanel->MouseToCursorSchema(); DrawPanel->m_IgnoreMouseEvents = FALSE; return NULL; } Module = Create_MuWaveBasicShape(NULL, cmp_name, pad_count); pt_pad = Module->m_Pads; switch ( shape_type ) { case 0: //Gap : oX = pt_pad->m_Pos0.x = - (gap_size + pt_pad->m_Size.x) / 2; pt_pad->m_Pos.x += pt_pad->m_Pos0.x; pt_pad = (D_PAD *) pt_pad->Pnext; pt_pad->m_Pos0.x = oX + gap_size + pt_pad->m_Size.x; pt_pad->m_Pos.x += pt_pad->m_Pos0.x; break; case 1: //Stub : pt_pad->SetPadName( wxT("1")); pt_pad = (D_PAD *) pt_pad->Pnext; pt_pad->m_Pos0.y = -(gap_size + pt_pad->m_Size.y) /2; pt_pad->m_Size.y = gap_size; pt_pad->m_Pos.y += pt_pad->m_Pos0.y; break; case 2: //Arc Stub : { EDGE_MODULE * edge; int * ptr, theta; ii = angle / 50; edge = new EDGE_MODULE(Module); Module->m_Drawings = edge; edge->Pback = Module; edge->m_Shape = S_POLYGON; edge->m_Layer = LAYER_CMP_N; edge->m_PolyCount = ii + 3; edge->m_PolyList = (int*) MyMalloc( edge->m_PolyCount * 2 * sizeof(int) ); ptr = edge->m_PolyList; edge->m_Start0.y = - pt_pad->m_Size.y / 2; * ptr = 0; ptr++; * ptr = 0; ptr++; theta = - angle/2; for ( ii = 1; ii < edge->m_PolyCount - 1; ii ++) { int x, y; x = 0; y = - gap_size; RotatePoint(&x, &y, theta); * ptr = x; ptr++; *ptr = y; ptr++; theta += 50; if ( theta > angle/2) theta = angle/2; } *ptr = edge->m_PolyList[0]; ptr++; *ptr = edge->m_PolyList[1]; break; } default: break; } Module->Set_Rectangle_Encadrement(); Module->Draw(DrawPanel, DC, wxPoint(0,0), GR_OR) ; DrawPanel->MouseToCursorSchema(); DrawPanel->m_IgnoreMouseEvents = FALSE; m_Pcb->m_Status_Pcb = 0 ; m_CurrentScreen->SetModify(); return Module; }
bool PCB_EDIT_FRAME::AppendBoardFile( const wxString& aFullFileName, int aCtl ) { IO_MGR::PCB_FILE_T pluginType = plugin_type( aFullFileName, aCtl ); PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) ); // keep trace of existing items, in order to know what are the new items // (for undo command for instance) // Tracks are inserted, not append, so mark existing tracks to know what are // the new tracks for( TRACK* track = GetBoard()->m_Track; track; track = track->Next() ) track->SetFlags( FLAG0 ); // Other items are append to the item list, so keep trace to the // last existing item is enough MODULE* module = GetBoard()->m_Modules.GetLast(); BOARD_ITEM* drawing = GetBoard()->m_Drawings.GetLast(); int zonescount = GetBoard()->GetAreaCount(); // Keep also the count of copper layers, because we can happen boards // with different copper layers counts, // and the enabled layers int initialCopperLayerCount = GetBoard()->GetCopperLayerCount(); LSET initialEnabledLayers = GetBoard()->GetEnabledLayers(); try { PROPERTIES props; char xbuf[30]; char ybuf[30]; // EAGLE_PLUGIN can use this info to center the BOARD, but it does not yet. sprintf( xbuf, "%d", GetPageSizeIU().x ); sprintf( ybuf, "%d", GetPageSizeIU().y ); props["page_width"] = xbuf; props["page_height"] = ybuf; GetDesignSettings().m_NetClasses.Clear(); pi->Load( aFullFileName, GetBoard(), &props ); } catch( const IO_ERROR& ioe ) { for( TRACK* track = GetBoard()->m_Track; track; track = track->Next() ) track->ClearFlags( FLAG0 ); wxString msg = wxString::Format( _( "Error loading board.\n%s" ), GetChars( ioe.What() ) ); DisplayError( this, msg ); return false; } // Now prepare a block move command to place the new items, and // prepare the undo command. BLOCK_SELECTOR& blockmove = GetScreen()->m_BlockLocate; HandleBlockBegin( NULL, BLOCK_PRESELECT_MOVE, wxPoint( 0, 0) ); PICKED_ITEMS_LIST& blockitemsList = blockmove.GetItems(); PICKED_ITEMS_LIST undoListPicker; ITEM_PICKER picker( NULL, UR_NEW ); EDA_RECT bbox; // the new items bounding box, for block move bool bboxInit = true; // true until the bounding box is initialized for( TRACK* track = GetBoard()->m_Track; track; track = track->Next() ) { if( track->GetFlags() & FLAG0 ) { track->ClearFlags( FLAG0 ); continue; } track->SetFlags( IS_MOVED ); picker.SetItem( track ); undoListPicker.PushItem( picker ); blockitemsList.PushItem( picker ); if( bboxInit ) bbox = track->GetBoundingBox(); else bbox.Merge( track->GetBoundingBox() ); bboxInit = false; } if( module ) module = module->Next(); else module = GetBoard()->m_Modules; for( ; module; module = module->Next() ) { module->SetFlags( IS_MOVED ); picker.SetItem( module ); undoListPicker.PushItem( picker ); blockitemsList.PushItem( picker ); if( bboxInit ) bbox = module->GetBoundingBox(); else bbox.Merge( module->GetBoundingBox() ); bboxInit = false; } if( drawing ) drawing = drawing->Next(); else drawing = GetBoard()->m_Drawings; for( ; drawing; drawing = drawing->Next() ) { drawing->SetFlags( IS_MOVED ); picker.SetItem( drawing ); undoListPicker.PushItem( picker ); blockitemsList.PushItem( picker ); if( bboxInit ) bbox = drawing->GetBoundingBox(); else bbox.Merge( drawing->GetBoundingBox() ); bboxInit = false; } for( ZONE_CONTAINER* zone = GetBoard()->GetArea( zonescount ); zone; zone = GetBoard()->GetArea( zonescount ) ) { zone->SetFlags( IS_MOVED ); picker.SetItem( zone ); undoListPicker.PushItem( picker ); blockitemsList.PushItem( picker ); zonescount++; if( bboxInit ) bbox = zone->GetBoundingBox(); else bbox.Merge( zone->GetBoundingBox() ); bboxInit = false; } SaveCopyInUndoList( undoListPicker, UR_NEW ); // we should not ask PLUGINs to do these items: int copperLayerCount = GetBoard()->GetCopperLayerCount(); if( copperLayerCount > initialCopperLayerCount ) GetBoard()->SetCopperLayerCount( copperLayerCount ); // Enable all used layers, and make them visible: LSET enabledLayers = GetBoard()->GetEnabledLayers(); enabledLayers |= initialEnabledLayers; GetBoard()->SetEnabledLayers( enabledLayers ); GetBoard()->SetVisibleLayers( enabledLayers ); ReCreateLayerBox(); ReFillLayerWidget(); if( IsGalCanvasActive() ) static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->SyncLayersVisibility( GetBoard() ); GetBoard()->BuildListOfNets(); GetBoard()->SynchronizeNetsAndNetClasses(); SetStatusText( wxEmptyString ); BestZoom(); // Finish block move command: wxPoint cpos = GetNearestGridPosition( bbox.Centre() ); blockmove.SetOrigin( bbox.GetOrigin() ); blockmove.SetSize( bbox.GetSize() ); blockmove.SetLastCursorPosition( cpos ); HandleBlockEnd( NULL ); return true; }
void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos ) { VECTOR2I origin; switch( aItem->Type() ) { case PCB_MODULE_T: { MODULE* mod = static_cast<MODULE*>( aItem ); addAnchor( mod->GetPosition(), ORIGIN | SNAPPABLE, mod ); for( D_PAD* pad = mod->Pads(); pad; pad = pad->Next() ) addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad ); break; } case PCB_PAD_T: { D_PAD* pad = static_cast<D_PAD*>( aItem ); addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad ); break; } case PCB_MODULE_EDGE_T: case PCB_LINE_T: { DRAWSEGMENT* dseg = static_cast<DRAWSEGMENT*>( aItem ); VECTOR2I start = dseg->GetStart(); VECTOR2I end = dseg->GetEnd(); //LAYER_ID layer = dseg->GetLayer(); switch( dseg->GetShape() ) { case S_CIRCLE: { int r = ( start - end ).EuclideanNorm(); addAnchor( start, ORIGIN | SNAPPABLE, dseg ); addAnchor( start + VECTOR2I( -r, 0 ), OUTLINE | SNAPPABLE, dseg ); addAnchor( start + VECTOR2I( r, 0 ), OUTLINE | SNAPPABLE, dseg ); addAnchor( start + VECTOR2I( 0, -r ), OUTLINE | SNAPPABLE, dseg ); addAnchor( start + VECTOR2I( 0, r ), OUTLINE | SNAPPABLE, dseg ); break; } case S_ARC: { origin = dseg->GetCenter(); addAnchor( dseg->GetArcStart(), CORNER | SNAPPABLE, dseg ); addAnchor( dseg->GetArcEnd(), CORNER | SNAPPABLE, dseg ); addAnchor( origin, ORIGIN | SNAPPABLE, dseg ); break; } case S_SEGMENT: { origin.x = start.x + ( start.x - end.x ) / 2; origin.y = start.y + ( start.y - end.y ) / 2; addAnchor( start, CORNER | SNAPPABLE, dseg ); addAnchor( end, CORNER | SNAPPABLE, dseg ); addAnchor( origin, ORIGIN, dseg ); break; } default: { origin = dseg->GetStart(); addAnchor( origin, ORIGIN | SNAPPABLE, dseg ); break; } } break; } case PCB_TRACE_T: { TRACK* track = static_cast<TRACK*>( aItem ); VECTOR2I start = track->GetStart(); VECTOR2I end = track->GetEnd(); origin.x = start.x + ( start.x - end.x ) / 2; origin.y = start.y + ( start.y - end.y ) / 2; addAnchor( start, CORNER | SNAPPABLE, track ); addAnchor( end, CORNER | SNAPPABLE, track ); addAnchor( origin, ORIGIN, track); break; } case PCB_VIA_T: addAnchor( aItem->GetPosition(), CORNER | SNAPPABLE, aItem ); break; case PCB_ZONE_AREA_T: { const CPolyLine* outline = static_cast<const ZONE_CONTAINER*>( aItem )->Outline(); int cornersCount = outline->GetCornersCount(); SHAPE_LINE_CHAIN lc; lc.SetClosed( true ); for( int i = 0; i < cornersCount; ++i ) { const VECTOR2I p ( outline->GetPos( i ) ); addAnchor( p, CORNER, aItem ); lc.Append( p ); } addAnchor( lc.NearestPoint( aRefPos ), OUTLINE, aItem ); break; } case PCB_MODULE_TEXT_T: case PCB_TEXT_T: addAnchor( aItem->GetPosition(), ORIGIN, aItem ); default: break; } }
bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule ) { MODULE* newModule; PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false ); if( frame == NULL ) // happens if no board editor opened return false; if( aModule == NULL ) { if( ! frame->GetBoard() || ! frame->GetBoard()->m_Modules ) return false; aModule = SelectFootprint( frame->GetBoard() ); } if( aModule == NULL ) return false; SetCurItem( NULL ); Clear_Pcb( false ); GetBoard()->m_Status_Pcb = 0; newModule = new MODULE( *aModule ); newModule->SetParent( GetBoard() ); newModule->SetLink( aModule->GetTimeStamp() ); aModule = newModule; newModule->ClearFlags(); newModule->RunOnChildren( boost::bind( &clearModuleItemFlags, _1 ) ); GetBoard()->Add( newModule ); // Clear references to any net info, because the footprint editor // does know any thing about nets handled by the current edited board. // Morever we do not want to save any reference to an unknown net when // saving the footprint in lib cache // so we force the ORPHANED dummy net info for all pads newModule->ClearAllNets(); SetCrossHairPosition( wxPoint( 0, 0 ) ); PlaceModule( newModule, NULL ); newModule->SetPosition( wxPoint( 0, 0 ) ); // cursor in GAL may not be initialized at the moment // Put it on FRONT layer, // because this is the default in ModEdit, and in libs if( newModule->GetLayer() != F_Cu ) newModule->Flip( newModule->GetPosition() ); // Put it in orientation 0, // because this is the default orientation in ModEdit, and in libs Rotate_Module( NULL, newModule, 0, false ); GetScreen()->ClrModify(); Zoom_Automatique( false ); if( IsGalCanvasActive() ) updateView(); return true; }
void PCB_PAD::AddToBoard() { PCB_PAD_SHAPE* padShape; int i; int width = 0; int height = 0; if( m_objType == wxT( 'V' ) ) // via { // choose one of the shapes for( i = 0; i < (int) m_shapes.GetCount(); i++ ) { padShape = m_shapes[i]; if( padShape->m_width > 0 && padShape->m_height > 0 ) { if( padShape->m_KiCadLayer == F_Cu || padShape->m_KiCadLayer == B_Cu ) { width = padShape->m_width; height = padShape->m_height; break; } } } if( width == 0 || height == 0 ) THROW_IO_ERROR( wxT( "pad or via with zero size" ) ); if( IsCopperLayer( m_KiCadLayer ) ) { VIA* via = new VIA( m_board ); m_board->m_Track.Append( via ); via->SetTimeStamp( 0 ); via->SetPosition( wxPoint( m_positionX, m_positionY ) ); via->SetEnd( wxPoint( m_positionX, m_positionY ) ); via->SetWidth( height ); via->SetViaType( VIA_THROUGH ); via->SetLayerPair( F_Cu, B_Cu ); via->SetDrill( m_hole ); via->SetLayer( m_KiCadLayer ); via->SetNetCode( m_netCode ); } } else // pad { MODULE* module = new MODULE( m_board ); m_board->Add( module, ADD_APPEND ); m_name.text = m_defaultPinDes; module->SetPosition( wxPoint( m_positionX, m_positionY ) ); AddToModule( module, 0, true ); } }
/** * Function PlaceCells * Initialize the matrix routing by setting obstacles for each occupied cell * a cell set to HOLE is an obstacle for tracks and vias * a cell set to VIA_IMPOSSIBLE is an obstacle for vias only. * a cell set to CELL_is_EDGE is a frontier. * Tracks and vias having the same net code as net_code are skipped * (htey do not are obstacles) * * For single-sided Routing 1: * BOTTOM side is used, and Route_Layer_BOTTOM = Route_Layer_TOP * * If flag == FORCE_PADS: all pads will be put in matrix as obstacles. */ void PlaceCells( BOARD* aPcb, int net_code, int flag ) { int ux0 = 0, uy0 = 0, ux1, uy1, dx, dy; int marge, via_marge; LAYER_MSK layerMask; // use the default NETCLASS? NETCLASS* nc = aPcb->m_NetClasses.GetDefault(); int trackWidth = nc->GetTrackWidth(); int clearance = nc->GetClearance(); int viaSize = nc->GetViaDiameter(); marge = clearance + (trackWidth / 2); via_marge = clearance + (viaSize / 2); // Place PADS on matrix routing: for( unsigned i = 0; i < aPcb->GetPadCount(); ++i ) { D_PAD* pad = aPcb->GetPad( i ); if( net_code != pad->GetNet() || (flag & FORCE_PADS) ) { ::PlacePad( pad, HOLE, marge, WRITE_CELL ); } ::PlacePad( pad, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); } // Place outlines of modules on matrix routing, if they are on a copper layer // or on the edge layer TRACK tmpSegm( NULL ); // A dummy track used to create segments. for( MODULE* module = aPcb->m_Modules; module; module = module->Next() ) { for( BOARD_ITEM* item = module->GraphicalItems(); item; item = item->Next() ) { switch( item->Type() ) { case PCB_MODULE_EDGE_T: { EDGE_MODULE* edge = (EDGE_MODULE*) item; tmpSegm.SetLayer( edge->GetLayer() ); if( tmpSegm.GetLayer() == EDGE_N ) tmpSegm.SetLayer( UNDEFINED_LAYER ); tmpSegm.SetStart( edge->GetStart() ); tmpSegm.SetEnd( edge->GetEnd() ); tmpSegm.SetShape( edge->GetShape() ); tmpSegm.SetWidth( edge->GetWidth() ); tmpSegm.m_Param = edge->GetAngle(); tmpSegm.SetNet( -1 ); TraceSegmentPcb( &tmpSegm, HOLE, marge, WRITE_CELL ); TraceSegmentPcb( &tmpSegm, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); } break; default: break; } } } // Place board outlines and texts on copper layers: for( BOARD_ITEM* item = aPcb->m_Drawings; item; item = item->Next() ) { switch( item->Type() ) { case PCB_LINE_T: { DRAWSEGMENT* DrawSegm; int type_cell = HOLE; DrawSegm = (DRAWSEGMENT*) item; tmpSegm.SetLayer( DrawSegm->GetLayer() ); if( DrawSegm->GetLayer() == EDGE_N ) { tmpSegm.SetLayer( UNDEFINED_LAYER ); type_cell |= CELL_is_EDGE; } tmpSegm.SetStart( DrawSegm->GetStart() ); tmpSegm.SetEnd( DrawSegm->GetEnd() ); tmpSegm.SetShape( DrawSegm->GetShape() ); tmpSegm.SetWidth( DrawSegm->GetWidth() ); tmpSegm.m_Param = DrawSegm->GetAngle(); tmpSegm.SetNet( -1 ); TraceSegmentPcb( &tmpSegm, type_cell, marge, WRITE_CELL ); } break; case PCB_TEXT_T: { TEXTE_PCB* PtText; PtText = (TEXTE_PCB*) item; if( PtText->GetText().Length() == 0 ) break; EDA_RECT textbox = PtText->GetTextBox( -1 ); ux0 = textbox.GetX(); uy0 = textbox.GetY(); dx = textbox.GetWidth(); dy = textbox.GetHeight(); /* Put bounding box (rectangle) on matrix */ dx /= 2; dy /= 2; ux1 = ux0 + dx; uy1 = uy0 + dy; ux0 -= dx; uy0 -= dy; layerMask = GetLayerMask( PtText->GetLayer() ); TraceFilledRectangle( ux0 - marge, uy0 - marge, ux1 + marge, uy1 + marge, PtText->GetOrientation(), layerMask, HOLE, WRITE_CELL ); TraceFilledRectangle( ux0 - via_marge, uy0 - via_marge, ux1 + via_marge, uy1 + via_marge, PtText->GetOrientation(), layerMask, VIA_IMPOSSIBLE, WRITE_OR_CELL ); } break; default: break; } } /* Put tracks and vias on matrix */ for( TRACK* track = aPcb->m_Track; track; track = track->Next() ) { if( net_code == track->GetNet() ) continue; TraceSegmentPcb( track, HOLE, marge, WRITE_CELL ); TraceSegmentPcb( track, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); } }
/** * Function Inspect * is the examining function within the INSPECTOR which is passed to the * Iterate function. Searches and collects all the objects that the old * function PcbGeneralLocateAndDisplay() would find, except that it keeps all * that it finds and does not do any displaying. * * @param testItem An EDA_ITEM to examine. * @param testData The const void* testData, not used here. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testData ) { BOARD_ITEM* item = (BOARD_ITEM*) testItem; MODULE* module = NULL; D_PAD* pad = NULL; bool pad_through = false; SEGVIA* via = NULL; MARKER_PCB* marker = NULL; #if 0 // debugging static int breakhere = 0; switch( item->Type() ) { case PCB_PAD_T: { MODULE* m = (MODULE*) item->GetParent(); if( m->GetReference() == wxT( "Y2" ) ) { breakhere++; } } break; case PCB_VIA_T: breakhere++; break; case PCB_TRACE_T: breakhere++; break; case PCB_ZONE_T: breakhere++; break; case PCB_TEXT_T: breakhere++; break; case PCB_LINE_T: breakhere++; break; case PCB_DIMENSION_T: breakhere++; break; case PCB_MODULE_TEXT_T: { TEXTE_MODULE* tm = (TEXTE_MODULE*) item; if( tm->GetText() == wxT( "10uH" ) ) { breakhere++; } } break; case PCB_MODULE_T: { MODULE* m = (MODULE*) item; if( m->GetReference() == wxT( "C98" ) ) { breakhere++; } } break; case PCB_MARKER_T: breakhere++; break; default: breakhere++; break; } #endif switch( item->Type() ) { case PCB_PAD_T: // there are pad specific visibility controls. // Criterias to select a pad is: // for smd pads: the module parent must be seen, and pads on the corresponding // board side must be seen // if pad is a thru hole, then it can be visible when its parent module is not. // for through pads: pads on Front or Back board sides must be seen pad = (D_PAD*) item; if( (pad->GetAttribute() != PAD_SMD) && (pad->GetAttribute() != PAD_CONN) ) // a hole is present, so multiple layers { // proceed to the common tests below, but without the parent module test, // by leaving module==NULL, but having pad != null pad_through = true; } else // smd, so use pads test after module test { module = (MODULE*) item->GetParent(); } break; case PCB_VIA_T: // vias are on many layers, so layer test is specific via = (SEGVIA*) item; break; case PCB_TRACE_T: break; case PCB_ZONE_T: break; case PCB_ZONE_AREA_T: break; case PCB_TEXT_T: break; case PCB_LINE_T: break; case PCB_DIMENSION_T: break; case PCB_TARGET_T: break; case PCB_MODULE_TEXT_T: module = (MODULE*) item->GetParent(); if( m_Guide->IgnoreMTextsMarkedNoShow() && !( (TEXTE_MODULE*) item )->IsVisible() ) goto exit; if( module ) { if( m_Guide->IgnoreMTextsOnCopper() && module->GetLayer()==LAYER_N_BACK ) goto exit; if( m_Guide->IgnoreMTextsOnCmp() && module->GetLayer()==LAYER_N_FRONT ) goto exit; if( m_Guide->IgnoreModulesVals() && item == &module->Value() ) goto exit; if( m_Guide->IgnoreModulesRefs() && item == &module->Reference() ) goto exit; } break; case PCB_MODULE_T: module = (MODULE*) item; break; case PCB_MARKER_T: marker = (MARKER_PCB*) item; break; default: break; } // common tests: if( module ) // true from case PCB_PAD_T, PCB_MODULE_TEXT_T, or PCB_MODULE_T { if( m_Guide->IgnoreModulesOnCu() && module->GetLayer()==LAYER_N_BACK ) goto exit; if( m_Guide->IgnoreModulesOnCmp() && module->GetLayer()==LAYER_N_FRONT ) goto exit; } // Pads are not sensitive to the layer visibility controls. // They all have their own separate visibility controls // skip them if not visible if( pad ) { if( m_Guide->IgnorePads() ) goto exit; if( ! pad_through ) { if( m_Guide->IgnorePadsOnFront() && pad->IsOnLayer(LAYER_N_FRONT ) ) goto exit; if( m_Guide->IgnorePadsOnBack() && pad->IsOnLayer(LAYER_N_BACK ) ) goto exit; } } if( marker ) { // Markers are not sensitive to the layer if( marker->HitTest( m_RefPos ) ) Append( item ); goto exit; } if( item->IsOnLayer( m_Guide->GetPreferredLayer() ) || m_Guide->IgnorePreferredLayer() ) { LAYER_NUM layer = item->GetLayer(); // Modules and their subcomponents: text and pads are not sensitive to the layer // visibility controls. They all have their own separate visibility controls // for vias, GetLayer() has no meaning, but IsOnLayer() works fine if( via || module || pad || m_Guide->IsLayerVisible( layer ) || !m_Guide->IgnoreNonVisibleLayers() ) { if( !m_Guide->IsLayerLocked( layer ) || !m_Guide->IgnoreLockedLayers() ) { if( !item->IsLocked() || !m_Guide->IgnoreLockedItems() ) { if( item->HitTest( m_RefPos ) ) { Append( item ); goto exit; } } } } } if( m_Guide->IncludeSecondary() ) { // for now, "secondary" means "tolerate any layer". It has // no effect on other criteria, since there is a separate "ignore" control for // those in the COLLECTORS_GUIDE LAYER_NUM layer = item->GetLayer(); // Modules and their subcomponents: text and pads are not sensitive to the layer // visibility controls. They all have their own separate visibility controls if( via || module || pad || m_Guide->IsLayerVisible( layer ) || !m_Guide->IgnoreNonVisibleLayers() ) { if( !m_Guide->IsLayerLocked( layer ) || !m_Guide->IgnoreLockedLayers() ) { if( !item->IsLocked() || !m_Guide->IgnoreLockedItems() ) { if( item->HitTest( m_RefPos ) ) { Append2nd( item ); goto exit; } } } } } exit: return SEARCH_CONTINUE; // always when collecting }
int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) { MODULE* module = NULL; KIGFX::VIEW* view = getView(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); BOARD* board = getModel<BOARD>(); // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( view ); view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); controls->ShowCursor( true ); controls->SetSnapping( true ); controls->SetAutoPan( true ); controls->CaptureCursor( true ); Activate(); m_frame->SetToolID( ID_PCB_MODULE_BUTT, wxCURSOR_HAND, _( "Add module" ) ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { if( module ) { board->Delete( module ); // it was added by LoadModuleFromLibrary() module = NULL; preview.Clear(); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); controls->ShowCursor( true ); } else break; if( evt->IsActivate() ) // now finish unconditionally break; } else if( module && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { module->Rotate( module->GetPosition(), m_frame->GetRotationAngle() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { module->Flip( module->GetPosition() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { if( !module ) { // Init the new item attributes module = m_frame->LoadModuleFromLibrary( wxEmptyString, m_frame->Prj().PcbFootprintLibs(), true, NULL ); if( module == NULL ) continue; controls->ShowCursor( false ); module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Add all the drawable parts to preview preview.Add( module ); module->RunOnChildren( boost::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else { module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); view->Add( module ); module->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); m_frame->SaveCopyInUndoList( module, UR_NEW ); // Remove from preview preview.Remove( module ); module->RunOnChildren( boost::bind( &KIGFX::VIEW_GROUP::Remove, &preview, _1 ) ); module = NULL; // to indicate that there is no module that we currently modify controls->ShowCursor( true ); } } else if( module && evt->IsMotion() ) { module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } controls->ShowCursor( false ); controls->SetSnapping( false ); controls->SetAutoPan( false ); controls->CaptureCursor( false ); view->Remove( &preview ); setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; }
void DIALOG_PAD_PROPERTIES::initValues() { wxString msg; double angle; // Setup layers names from board // Should be made first, before calling m_rbCopperLayersSel->SetSelection() m_rbCopperLayersSel->SetString( 0, m_board->GetLayerName( LAYER_N_FRONT ) ); m_rbCopperLayersSel->SetString( 1, m_board->GetLayerName( LAYER_N_BACK ) ); m_PadLayerAdhCmp->SetLabel( m_board->GetLayerName( ADHESIVE_N_FRONT ) ); m_PadLayerAdhCu->SetLabel( m_board->GetLayerName( ADHESIVE_N_BACK ) ); m_PadLayerPateCmp->SetLabel( m_board->GetLayerName( SOLDERPASTE_N_FRONT ) ); m_PadLayerPateCu->SetLabel( m_board->GetLayerName( SOLDERPASTE_N_BACK ) ); m_PadLayerSilkCmp->SetLabel( m_board->GetLayerName( SILKSCREEN_N_FRONT ) ); m_PadLayerSilkCu->SetLabel( m_board->GetLayerName( SILKSCREEN_N_BACK ) ); m_PadLayerMaskCmp->SetLabel( m_board->GetLayerName( SOLDERMASK_N_FRONT ) ); m_PadLayerMaskCu->SetLabel( m_board->GetLayerName( SOLDERMASK_N_BACK ) ); m_PadLayerECO1->SetLabel( m_board->GetLayerName( ECO1_N ) ); m_PadLayerECO2->SetLabel( m_board->GetLayerName( ECO2_N ) ); m_PadLayerDraft->SetLabel( m_board->GetLayerName( DRAW_N ) ); m_isFlipped = false; if( m_currentPad ) { MODULE* module = m_currentPad->GetParent(); if( module->GetLayer() == LAYER_N_BACK ) { m_isFlipped = true; m_staticModuleSideValue->SetLabel( _( "Back side (footprint is mirrored)" ) ); } msg.Printf( wxT( "%.1f" ), module->GetOrientation() / 10.0 ); m_staticModuleRotValue->SetLabel( msg ); } if( m_isFlipped ) { wxPoint pt = m_dummyPad->GetOffset(); NEGATE( pt.y ); m_dummyPad->SetOffset( pt ); wxSize sz = m_dummyPad->GetDelta(); NEGATE( sz.y ); m_dummyPad->SetDelta( sz ); // flip pad's layers m_dummyPad->SetLayerMask( FlipLayerMask( m_dummyPad->GetLayerMask() ) ); } m_staticTextWarningPadFlipped->Show(m_isFlipped); m_PadNumCtrl->SetValue( m_dummyPad->GetPadName() ); m_PadNetNameCtrl->SetValue( m_dummyPad->GetNetname() ); // Display current unit name in dialog: m_PadPosX_Unit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_PadPosY_Unit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_PadDrill_X_Unit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_PadDrill_Y_Unit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_PadShapeSizeX_Unit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_PadShapeSizeY_Unit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_PadShapeOffsetX_Unit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_PadShapeOffsetY_Unit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_PadShapeDelta_Unit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_PadLengthDie_Unit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); // Display current pad masks clearances units m_NetClearanceUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_SolderMaskMarginUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_SolderPasteMarginUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_ThermalWidthUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); m_ThermalGapUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) ); // Display current pad parameters units: PutValueInLocalUnits( *m_PadPosition_X_Ctrl, m_dummyPad->GetPosition().x ); PutValueInLocalUnits( *m_PadPosition_Y_Ctrl, m_dummyPad->GetPosition().y ); PutValueInLocalUnits( *m_PadDrill_X_Ctrl, m_dummyPad->GetDrillSize().x ); PutValueInLocalUnits( *m_PadDrill_Y_Ctrl, m_dummyPad->GetDrillSize().y ); PutValueInLocalUnits( *m_ShapeSize_X_Ctrl, m_dummyPad->GetSize().x ); PutValueInLocalUnits( *m_ShapeSize_Y_Ctrl, m_dummyPad->GetSize().y ); PutValueInLocalUnits( *m_ShapeOffset_X_Ctrl, m_dummyPad->GetOffset().x ); PutValueInLocalUnits( *m_ShapeOffset_Y_Ctrl, m_dummyPad->GetOffset().y ); if( m_dummyPad->GetDelta().x ) { PutValueInLocalUnits( *m_ShapeDelta_Ctrl, m_dummyPad->GetDelta().x ); m_trapDeltaDirChoice->SetSelection( 0 ); } else { PutValueInLocalUnits( *m_ShapeDelta_Ctrl, m_dummyPad->GetDelta().y ); m_trapDeltaDirChoice->SetSelection( 1 ); } PutValueInLocalUnits( *m_LengthPadToDieCtrl, m_dummyPad->GetPadToDieLength() ); PutValueInLocalUnits( *m_NetClearanceValueCtrl, m_dummyPad->GetLocalClearance() ); PutValueInLocalUnits( *m_SolderMaskMarginCtrl, m_dummyPad->GetLocalSolderMaskMargin() ); PutValueInLocalUnits( *m_ThermalWidthCtrl, m_dummyPad->GetThermalWidth() ); PutValueInLocalUnits( *m_ThermalGapCtrl, m_dummyPad->GetThermalGap() ); // These 2 parameters are usually < 0, so prepare entering a negative value, if current is 0 PutValueInLocalUnits( *m_SolderPasteMarginCtrl, m_dummyPad->GetLocalSolderPasteMargin() ); if( m_dummyPad->GetLocalSolderPasteMargin() == 0 ) m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() ); msg.Printf( wxT( "%f" ), m_dummyPad->GetLocalSolderPasteMarginRatio() * 100.0 ); if( m_dummyPad->GetLocalSolderPasteMarginRatio() == 0.0 && msg[0] == '0' ) // Sometimes Printf adds a sign if the value is small m_SolderPasteMarginRatioCtrl->SetValue( wxT( "-" ) + msg ); else m_SolderPasteMarginRatioCtrl->SetValue( msg ); switch( m_dummyPad->GetZoneConnection() ) { default: case UNDEFINED_CONNECTION: m_ZoneConnectionChoice->SetSelection( 0 ); break; case PAD_IN_ZONE: m_ZoneConnectionChoice->SetSelection( 1 ); break; case THERMAL_PAD: m_ZoneConnectionChoice->SetSelection( 2 ); break; case PAD_NOT_IN_ZONE: m_ZoneConnectionChoice->SetSelection( 3 ); break; } if( m_currentPad ) { MODULE* module = m_currentPad->GetParent(); angle = m_currentPad->GetOrientation() - module->GetOrientation(); if( m_isFlipped ) NEGATE( angle ); m_dummyPad->SetOrientation( angle ); } angle = m_dummyPad->GetOrientation(); NORMALIZE_ANGLE_180( angle ); // ? normalizing is in D_PAD::SetOrientation() // Set layers used by this pad: : setPadLayersList( m_dummyPad->GetLayerMask() ); // Pad Orient switch( int( angle ) ) { case 0: m_PadOrient->SetSelection( 0 ); break; case 900: m_PadOrient->SetSelection( 1 ); break; case -900: m_PadOrient->SetSelection( 2 ); break; case 1800: case -1800: m_PadOrient->SetSelection( 3 ); break; default: m_PadOrient->SetSelection( 4 ); break; } switch( m_dummyPad->GetShape() ) { default: case PAD_CIRCLE: m_PadShape->SetSelection( 0 ); break; case PAD_OVAL: m_PadShape->SetSelection( 1 ); break; case PAD_RECT: m_PadShape->SetSelection( 2 ); break; case PAD_TRAPEZOID: m_PadShape->SetSelection( 3 ); break; } msg.Printf( wxT( "%g" ), angle ); m_PadOrientCtrl->SetValue( msg ); // Type of pad selection m_PadType->SetSelection( 0 ); for( unsigned ii = 0; ii < NBTYPES; ii++ ) { if( CodeType[ii] == m_dummyPad->GetAttribute() ) { m_PadType->SetSelection( ii ); break; } } // Enable/disable Pad name,and pad length die // (disable for NPTH pads (mechanical pads) bool enable = m_dummyPad->GetAttribute() != PAD_HOLE_NOT_PLATED; m_PadNumCtrl->Enable( enable ); m_PadNetNameCtrl->Enable( enable ); m_LengthPadToDieCtrl->Enable( enable ); if( m_dummyPad->GetDrillShape() != PAD_OVAL ) m_DrillShapeCtrl->SetSelection( 0 ); else m_DrillShapeCtrl->SetSelection( 1 ); // Update some dialog widgets state (Enable/disable options): wxCommandEvent cmd_event; setPadLayersList( m_dummyPad->GetLayerMask() ); OnDrillShapeSelected( cmd_event ); OnPadShapeSelection( cmd_event ); }
void ZONE_FILLER::buildZoneFeatureHoleList( const ZONE_CONTAINER* aZone, SHAPE_POLY_SET& aFeatures ) const { int segsPerCircle; double correctionFactor; // Set the number of segments in arc approximations if( aZone->GetArcSegmentCount() == ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF ) segsPerCircle = ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF; else segsPerCircle = ARC_APPROX_SEGMENTS_COUNT_LOW_DEF; /* calculates the coeff to compensate radius reduction of holes clearance * due to the segment approx. * For a circle the min radius is radius * cos( 2PI / s_CircleToSegmentsCount / 2) * s_Correction is 1 /cos( PI/s_CircleToSegmentsCount ) */ correctionFactor = 1.0 / cos( M_PI / (double) segsPerCircle ); aFeatures.RemoveAllContours(); int outline_half_thickness = aZone->GetMinThickness() / 2; // When removing holes, the holes must be expanded by outline_half_thickness // to take in account the thickness of the zone outlines int zone_clearance = aZone->GetClearance() + outline_half_thickness; // When holes are created by non copper items (edge cut items), use only // the m_ZoneClearance parameter (zone clearance with no netclass clearance) int zone_to_edgecut_clearance = aZone->GetZoneClearance() + outline_half_thickness; /* store holes (i.e. tracks and pads areas as polygons outlines) * in a polygon list */ /* items ouside the zone bounding box are skipped * the bounding box is the zone bounding box + the biggest clearance found in Netclass list */ EDA_RECT item_boundingbox; EDA_RECT zone_boundingbox = aZone->GetBoundingBox(); int biggest_clearance = m_board->GetDesignSettings().GetBiggestClearanceValue(); biggest_clearance = std::max( biggest_clearance, zone_clearance ); zone_boundingbox.Inflate( biggest_clearance ); /* * First : Add pads. Note: pads having the same net as zone are left in zone. * Thermal shapes will be created later if necessary */ /* Use a dummy pad to calculate hole clearance when a pad is not on all copper layers * and this pad has a hole * This dummy pad has the size and shape of the hole * Therefore, this dummy pad is a circle or an oval. * A pad must have a parent because some functions expect a non null parent * to find the parent board, and some other data */ MODULE dummymodule( m_board ); // Creates a dummy parent D_PAD dummypad( &dummymodule ); for( MODULE* module = m_board->m_Modules; module; module = module->Next() ) { D_PAD* nextpad; for( D_PAD* pad = module->PadsList(); pad != NULL; pad = nextpad ) { nextpad = pad->Next(); // pad pointer can be modified by next code, so // calculate the next pad here if( !pad->IsOnLayer( aZone->GetLayer() ) ) { /* Test for pads that are on top or bottom only and have a hole. * There are curious pads but they can be used for some components that are * inside the board (in fact inside the hole. Some photo diodes and Leds are * like this) */ if( pad->GetDrillSize().x == 0 && pad->GetDrillSize().y == 0 ) continue; // Use a dummy pad to calculate a hole shape that have the same dimension as // the pad hole dummypad.SetSize( pad->GetDrillSize() ); dummypad.SetOrientation( pad->GetOrientation() ); dummypad.SetShape( pad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ? PAD_SHAPE_OVAL : PAD_SHAPE_CIRCLE ); dummypad.SetPosition( pad->GetPosition() ); pad = &dummypad; } // Note: netcode <=0 means not connected item if( ( pad->GetNetCode() != aZone->GetNetCode() ) || ( pad->GetNetCode() <= 0 ) ) { int item_clearance = pad->GetClearance() + outline_half_thickness; item_boundingbox = pad->GetBoundingBox(); item_boundingbox.Inflate( item_clearance ); if( item_boundingbox.Intersects( zone_boundingbox ) ) { int clearance = std::max( zone_clearance, item_clearance ); // PAD_SHAPE_CUSTOM can have a specific keepout, to avoid to break the shape if( pad->GetShape() == PAD_SHAPE_CUSTOM && pad->GetCustomShapeInZoneOpt() == CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL ) { // the pad shape in zone can be its convex hull or // the shape itself SHAPE_POLY_SET outline( pad->GetCustomShapeAsPolygon() ); outline.Inflate( KiROUND( clearance * correctionFactor ), segsPerCircle ); pad->CustomShapeAsPolygonToBoardPosition( &outline, pad->GetPosition(), pad->GetOrientation() ); if( pad->GetCustomShapeInZoneOpt() == CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL ) { std::vector<wxPoint> convex_hull; BuildConvexHull( convex_hull, outline ); aFeatures.NewOutline(); for( unsigned ii = 0; ii < convex_hull.size(); ++ii ) aFeatures.Append( convex_hull[ii] ); } else aFeatures.Append( outline ); } else pad->TransformShapeWithClearanceToPolygon( aFeatures, clearance, segsPerCircle, correctionFactor ); } continue; } // Pads are removed from zone if the setup is PAD_ZONE_CONN_NONE // or if they have a custom shape, because a thermal relief will break // the shape if( aZone->GetPadConnection( pad ) == PAD_ZONE_CONN_NONE || pad->GetShape() == PAD_SHAPE_CUSTOM ) { int gap = zone_clearance; int thermalGap = aZone->GetThermalReliefGap( pad ); gap = std::max( gap, thermalGap ); item_boundingbox = pad->GetBoundingBox(); item_boundingbox.Inflate( gap ); if( item_boundingbox.Intersects( zone_boundingbox ) ) { // PAD_SHAPE_CUSTOM has a specific keepout, to avoid to break the shape // the pad shape in zone can be its convex hull or the shape itself if( pad->GetShape() == PAD_SHAPE_CUSTOM && pad->GetCustomShapeInZoneOpt() == CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL ) { // the pad shape in zone can be its convex hull or // the shape itself SHAPE_POLY_SET outline( pad->GetCustomShapeAsPolygon() ); outline.Inflate( KiROUND( gap * correctionFactor ), segsPerCircle ); pad->CustomShapeAsPolygonToBoardPosition( &outline, pad->GetPosition(), pad->GetOrientation() ); std::vector<wxPoint> convex_hull; BuildConvexHull( convex_hull, outline ); aFeatures.NewOutline(); for( unsigned ii = 0; ii < convex_hull.size(); ++ii ) aFeatures.Append( convex_hull[ii] ); } else pad->TransformShapeWithClearanceToPolygon( aFeatures, gap, segsPerCircle, correctionFactor ); } } } } /* Add holes (i.e. tracks and vias areas as polygons outlines) * in cornerBufferPolysToSubstract */ for( auto track : m_board->Tracks() ) { if( !track->IsOnLayer( aZone->GetLayer() ) ) continue; if( track->GetNetCode() == aZone->GetNetCode() && ( aZone->GetNetCode() != 0) ) continue; int item_clearance = track->GetClearance() + outline_half_thickness; item_boundingbox = track->GetBoundingBox(); if( item_boundingbox.Intersects( zone_boundingbox ) ) { int clearance = std::max( zone_clearance, item_clearance ); track->TransformShapeWithClearanceToPolygon( aFeatures, clearance, segsPerCircle, correctionFactor ); } } /* Add module edge items that are on copper layers * Pcbnew allows these items to be on copper layers in microwave applictions * This is a bad thing, but must be handled here, until a better way is found */ for( auto module : m_board->Modules() ) { for( auto item : module->GraphicalItems() ) { if( !item->IsOnLayer( aZone->GetLayer() ) && !item->IsOnLayer( Edge_Cuts ) ) continue; if( item->Type() != PCB_MODULE_EDGE_T ) continue; item_boundingbox = item->GetBoundingBox(); if( item_boundingbox.Intersects( zone_boundingbox ) ) { int zclearance = zone_clearance; if( item->IsOnLayer( Edge_Cuts ) ) // use only the m_ZoneClearance, not the clearance using // the netclass value, because we do not have a copper item zclearance = zone_to_edgecut_clearance; ( (EDGE_MODULE*) item )->TransformShapeWithClearanceToPolygon( aFeatures, zclearance, segsPerCircle, correctionFactor ); } } } // Add graphic items (copper texts) and board edges // Currently copper texts have no net, so only the zone_clearance // is used. for( auto item : m_board->Drawings() ) { if( item->GetLayer() != aZone->GetLayer() && item->GetLayer() != Edge_Cuts ) continue; int zclearance = zone_clearance; if( item->GetLayer() == Edge_Cuts ) // use only the m_ZoneClearance, not the clearance using // the netclass value, because we do not have a copper item zclearance = zone_to_edgecut_clearance; switch( item->Type() ) { case PCB_LINE_T: ( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon( aFeatures, zclearance, segsPerCircle, correctionFactor ); break; case PCB_TEXT_T: ( (TEXTE_PCB*) item )->TransformBoundingBoxWithClearanceToPolygon( aFeatures, zclearance ); break; default: break; } } // Add zones outlines having an higher priority and keepout for( int ii = 0; ii < m_board->GetAreaCount(); ii++ ) { ZONE_CONTAINER* zone = m_board->GetArea( ii ); // If the zones share no common layers if( !aZone->CommonLayerExists( zone->GetLayerSet() ) ) continue; if( !zone->GetIsKeepout() && zone->GetPriority() <= aZone->GetPriority() ) continue; if( zone->GetIsKeepout() && !zone->GetDoNotAllowCopperPour() ) continue; // A highter priority zone or keepout area is found: remove this area item_boundingbox = zone->GetBoundingBox(); if( !item_boundingbox.Intersects( zone_boundingbox ) ) continue; // Add the zone outline area. // However if the zone has the same net as the current zone, // do not add any clearance. // the zone will be connected to the current zone, but filled areas // will use different parameters (clearance, thermal shapes ) bool same_net = aZone->GetNetCode() == zone->GetNetCode(); bool use_net_clearance = true; int min_clearance = zone_clearance; // Do not forget to make room to draw the thick outlines // of the hole created by the area of the zone to remove int holeclearance = zone->GetClearance() + outline_half_thickness; // The final clearance is obviously the max value of each zone clearance min_clearance = std::max( min_clearance, holeclearance ); if( zone->GetIsKeepout() || same_net ) { // Just take in account the fact the outline has a thickness, so // the actual area to substract is inflated to take in account this fact min_clearance = outline_half_thickness; use_net_clearance = false; } zone->TransformOutlinesShapeWithClearanceToPolygon( aFeatures, min_clearance, use_net_clearance ); } // Remove thermal symbols for( auto module : m_board->Modules() ) { for( auto pad : module->Pads() ) { // Rejects non-standard pads with tht-only thermal reliefs if( aZone->GetPadConnection( pad ) == PAD_ZONE_CONN_THT_THERMAL && pad->GetAttribute() != PAD_ATTRIB_STANDARD ) continue; if( aZone->GetPadConnection( pad ) != PAD_ZONE_CONN_THERMAL && aZone->GetPadConnection( pad ) != PAD_ZONE_CONN_THT_THERMAL ) continue; if( !pad->IsOnLayer( aZone->GetLayer() ) ) continue; if( pad->GetNetCode() != aZone->GetNetCode() ) continue; item_boundingbox = pad->GetBoundingBox(); int thermalGap = aZone->GetThermalReliefGap( pad ); item_boundingbox.Inflate( thermalGap, thermalGap ); if( item_boundingbox.Intersects( zone_boundingbox ) ) { CreateThermalReliefPadPolygon( aFeatures, *pad, thermalGap, aZone->GetThermalReliefCopperBridge( pad ), aZone->GetMinThickness(), segsPerCircle, correctionFactor, s_thermalRot ); } } } }
void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter ) throw( IO_ERROR, PARSE_ERROR ) { wxString msg; FPID lastFPID; COMPONENT* component; MODULE* module = 0; MODULE* fpOnBoard; if( aNetlist.IsEmpty() || Prj().PcbFootprintLibs()->IsEmpty() ) return; aNetlist.SortByFPID(); for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ ) { component = aNetlist.GetComponent( ii ); #if ALLOW_PARTIAL_FPID // The FPID is ok as long as there is a footprint portion coming // from eeschema. if( !component->GetFPID().GetFootprintName().size() ) #else if( component->GetFPID().empty() ) #endif { if( aReporter ) { msg.Printf( _( "No footprint defined for component '%s'.\n" ), GetChars( component->GetReference() ) ); aReporter->Report( msg, REPORTER::ERROR ); } continue; } // Check if component footprint is already on BOARD and only load the footprint from // the library if it's needed. Nickname can be blank. if( aNetlist.IsFindByTimeStamp() ) fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetTimeStamp(), true ); else fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetReference() ); bool footprintMisMatch = fpOnBoard && fpOnBoard->GetFPID() != component->GetFPID(); if( footprintMisMatch && !aNetlist.GetReplaceFootprints() ) { if( aReporter ) { msg.Printf( _( "Component '%s' has footprint '%s' and should be '%s'\n" ), GetChars( component->GetReference() ), GetChars( fpOnBoard->GetFPID().Format() ), GetChars( component->GetFPID().Format() ) ); aReporter->Report( msg, REPORTER::WARNING ); } continue; } if( !aNetlist.GetReplaceFootprints() ) footprintMisMatch = false; bool loadFootprint = (fpOnBoard == NULL) || footprintMisMatch; if( loadFootprint && (component->GetFPID() != lastFPID) ) { module = NULL; #if ALLOW_PARTIAL_FPID // The FPID is ok as long as there is a footprint portion coming // the library if it's needed. Nickname can be blank. if( !component->GetFPID().GetFootprintName().size() ) #else if( !component->GetFPID().IsValid() ) #endif { if( aReporter ) { msg.Printf( _( "Component '%s' footprint ID '%s' is not " "valid.\n" ), GetChars( component->GetReference() ), GetChars( component->GetFPID().Format() ) ); aReporter->Report( msg, REPORTER::ERROR ); } continue; } // loadFootprint() can find a footprint with an empty nickname in fpid. module = PCB_BASE_FRAME::loadFootprint( component->GetFPID() ); if( module ) { lastFPID = component->GetFPID(); } else { if( aReporter ) { wxString msg; msg.Printf( _( "Component '%s' footprint '%s' was not found in " "any libraries in the footprint library table.\n" ), GetChars( component->GetReference() ), GetChars( component->GetFPID().GetFootprintName() ) ); aReporter->Report( msg, REPORTER::ERROR ); } continue; } } else { // Footprint already loaded from a library, duplicate it (faster) if( module == NULL ) continue; // Module does not exist in any library. module = new MODULE( *module ); } if( loadFootprint && module != NULL ) component->SetModule( module ); } }
void DialogEditModuleText::initDlg( ) { SetFocus(); wxString msg; if( m_module ) { wxString format = m_ModuleInfoText->GetLabel(); msg.Printf( format, GetChars( m_module->GetReference() ), GetChars( m_module->GetValue() ), m_module->GetOrientation() / 10.0 ); } else { msg.Empty(); } m_ModuleInfoText->SetLabel( msg ); switch( m_currentText->GetType() ) { case TEXTE_MODULE::TEXT_is_VALUE: m_TextDataTitle->SetLabel( _( "Value:" ) ); break; case TEXTE_MODULE::TEXT_is_DIVERS: m_TextDataTitle->SetLabel( _( "Text:" ) ); break; default: m_TextDataTitle->SetLabel( _( "Reference:" ) ); break; } m_Name->SetValue( m_currentText->GetText() ); m_Style->SetSelection( m_currentText->IsItalic() ? 1 : 0 ); AddUnitSymbol( *m_SizeXTitle ); PutValueInLocalUnits( *m_TxtSizeCtrlX, m_currentText->GetSize().x ); AddUnitSymbol( *m_SizeYTitle ); PutValueInLocalUnits( *m_TxtSizeCtrlY, m_currentText->GetSize().y ); AddUnitSymbol( *m_PosXTitle ); PutValueInLocalUnits( *m_TxtPosCtrlX, m_currentText->GetPos0().x ); AddUnitSymbol( *m_PosYTitle ); PutValueInLocalUnits( *m_TxtPosCtrlY, m_currentText->GetPos0().y ); AddUnitSymbol( *m_WidthTitle ); PutValueInLocalUnits( *m_TxtWidthCtlr, m_currentText->GetThickness() ); double text_orient = m_currentText->GetOrientation(); NORMALIZE_ANGLE_90( text_orient ); if( (text_orient != 0) ) m_Orient->SetSelection( 1 ); if( !m_currentText->IsVisible() ) m_Show->SetSelection( 1 );; }
int kml_document(FILE *fp) { CLASS *oclass, *openclass=NULL; MODULE *mod; char buffer[1024]; time_t now = time(NULL); kml_write("%s"," <Document>\n"); kml_write(" <name>%s</name>\n", global_modelname); kml_write(" <description>GridLAB-D results for %s</description>\n", convert_from_timestamp(global_clock,buffer,sizeof(buffer))?buffer:"unknown date/time"); /* for each module */ for (mod=module_get_first(); mod!=NULL; mod=mod->next) { if (mod->kmldump) mod->kmldump(kml_write,NULL); /* dump styles */ } /* scan each class in the model */ for (oclass=class_get_first_class(); oclass!=NULL; oclass=oclass->next) { OBJECT *obj; /* scan each object in the model */ for (obj=object_get_first(); obj!=NULL; obj=obj->next) { int has_location = !(isnan(obj->latitude) || isnan(obj->longitude)); MODULE *mod; /* class does not match current object */ if (obj->oclass!=oclass) continue; /* first instance of this class needs folder */ else if (openclass==NULL) { kml_write(" <Folder><name>Class %s</name>\n", oclass->name); kml_write(" <description>Module %s",oclass->module->name); if (oclass->module->minor!=0 || oclass->module->major!=0) kml_write(" (V%d.%02d)",oclass->module->major,oclass->module->minor); kml_write("</description>\n",oclass->module->name); openclass=oclass; } /* module overrides KML output */ mod = (MODULE*)(obj->oclass->module); if (mod->kmldump!=NULL) (*(mod->kmldump))(kml_write,obj); else if (has_location) { /* basic KML output of published variables */ PROPERTY *prop; kml_write(" <Placemark>\n"); if (obj->name) kml_write(" <name>%s</name>\n", obj->name); else kml_write(" <name>%s %d</name>\n", obj->oclass->name, obj->id); kml_write(" <description>\n"); kml_write(" <![CDATA[\n"); kml_write(" <TABLE><TR>\n"); for (prop=oclass->pmap;prop!=NULL && prop->oclass==oclass; prop=prop->next) { char *value = object_property_to_string(obj,prop->name, buffer, 1023); if (value!=NULL) kml_write("<TR><TH ALIGN=LEFT>%s</TH><TD ALIGN=RIGHT>%s</TD></TR>", prop->name, value); } kml_write(" </TR></TABLE>\n"); kml_write(" ]]>\n"); kml_write(" </description>\n"); kml_write(" <Point>\n"); kml_write(" <coordinates>%f,%f</coordinates>\n",obj->longitude,obj->latitude); kml_write(" </Point>\n"); kml_write(" </Placemark>\n"); } } /* close folder if any */ if (openclass!=NULL) { kml_write(" </Folder>\n"); openclass=NULL; } } kml_write(" </Document>\n"); return 0; }
void DialogEditModuleText::OnOkClick( wxCommandEvent& event ) { wxString msg; if ( m_module) m_parent->SaveCopyInUndoList( m_module, UR_CHANGED ); #ifndef USE_WX_OVERLAY if( m_dc ) //Erase old text on screen { m_currentText->Draw( m_parent->GetCanvas(), m_dc, GR_XOR, (m_currentText->IsMoving()) ? MoveVector : wxPoint( 0, 0 ) ); } #endif m_currentText->SetText( m_Name->GetValue() ); m_currentText->SetItalic( m_Style->GetSelection() == 1 ); wxPoint tmp; msg = m_TxtPosCtrlX->GetValue(); tmp.x = ValueFromString( g_UserUnit, msg ); msg = m_TxtPosCtrlY->GetValue(); tmp.y = ValueFromString( g_UserUnit, msg ); m_currentText->SetPos0( tmp ); wxSize textSize( wxSize( ValueFromString( g_UserUnit, m_TxtSizeCtrlX->GetValue() ), ValueFromString( g_UserUnit, m_TxtSizeCtrlY->GetValue() ) ) ); // Test for a reasonnable size: if( textSize.x < TEXTS_MIN_SIZE ) textSize.x = TEXTS_MIN_SIZE; if( textSize.y < TEXTS_MIN_SIZE ) textSize.y = TEXTS_MIN_SIZE; m_currentText->SetSize( textSize ), msg = m_TxtWidthCtlr->GetValue(); int width = ValueFromString( g_UserUnit, msg ); // Test for a reasonnable width: if( width <= 1 ) width = 1; int maxthickness = Clamp_Text_PenSize(width, m_currentText->GetSize() ); if( width > maxthickness ) { DisplayError( NULL, _( "The text thickness is too large for the text size. It will be clamped" ) ); width = maxthickness; } m_currentText->SetThickness( width ); m_currentText->SetVisible( m_Show->GetSelection() == 0 ); int text_orient = (m_Orient->GetSelection() == 0) ? 0 : 900; m_currentText->SetOrientation( text_orient ); m_currentText->SetDrawCoord(); #ifndef USE_WX_OVERLAY if( m_dc ) // Display new text { m_currentText->Draw( m_parent->GetCanvas(), m_dc, GR_XOR, (m_currentText->IsMoving()) ? MoveVector : wxPoint( 0, 0 ) ); } #else m_parent->Refresh(); #endif m_parent->OnModify(); if( m_module ) m_module->SetLastEditTime(); EndModal(1); }
bool SELECTION_TOOL::selectable( const BOARD_ITEM* aItem ) const { // Is high contrast mode enabled? bool highContrast = getView()->GetPainter()->GetSettings()->GetHighContrast(); if( highContrast ) { bool onActive = false; // Is the item on any of active layers? int layers[KIGFX::VIEW::VIEW_MAX_LAYERS], layers_count; // Filter out items that do not belong to active layers const std::set<unsigned int>& activeLayers = getView()->GetPainter()-> GetSettings()->GetActiveLayers(); aItem->ViewGetLayers( layers, layers_count ); for( int i = 0; i < layers_count; ++i ) { if( activeLayers.count( layers[i] ) > 0 ) // Item is on at least one of the active layers { onActive = true; break; } } if( !onActive ) // We do not want to select items that are in the background return false; } BOARD* board = getModel<BOARD>(); switch( aItem->Type() ) { case PCB_VIA_T: { // For vias it is enough if only one of layers is visible LAYER_ID top, bottom; static_cast<const VIA*>( aItem )->LayerPair( &top, &bottom ); return board->IsLayerVisible( top ) || board->IsLayerVisible( bottom ); } break; case PCB_MODULE_T: if( aItem->IsOnLayer( F_Cu ) && board->IsElementVisible( MOD_FR_VISIBLE ) ) return !m_editModules; if( aItem->IsOnLayer( B_Cu ) && board->IsElementVisible( MOD_BK_VISIBLE ) ) return !m_editModules; return false; break; case PCB_MODULE_TEXT_T: if( m_multiple && !m_editModules ) return false; return aItem->ViewIsVisible() && board->IsLayerVisible( aItem->GetLayer() ); // These are not selectable case PCB_MODULE_EDGE_T: case PCB_PAD_T: { if( m_multiple && !m_editModules ) return false; MODULE* mod = static_cast<const D_PAD*>( aItem )->GetParent(); if( mod && mod->IsLocked() ) return false; break; } case NOT_USED: case TYPE_NOT_INIT: return false; default: // Suppress warnings break; } // All other items are selected only if the layer on which they exist is visible return board->IsLayerVisible( aItem->GetLayer() ); }
bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC ) { BOARD_ITEM* item = GetCurItem(); bool ItemFree = (item == NULL) || (item->GetFlags() == 0); switch( GetToolId() ) { case ID_TRACK_BUTT: if( !IsCopperLayer ( GetActiveLayer() ) ) return false; if( ItemFree ) { item = PcbGeneralLocateAndDisplay(); if( item && !item->IsTrack() ) return false; Delete_Track( aDC, (TRACK*) item ); } else if( item->IsTrack( ) ) { // simple lines for debugger: TRACK* track = (TRACK*) item; track = Delete_Segment( aDC, track ); SetCurItem( track ); OnModify(); return true; } break; case ID_PCB_MODULE_BUTT: if( ItemFree ) { wxPoint pos = RefPos( false ); MODULE* module = GetBoard()->GetFootprint( pos, UNDEFINED_LAYER, false ); if( module == NULL || module->IsLocked() ) return false; RemoveStruct( module, aDC ); } else return false; break; default: if( ItemFree ) { item = PcbGeneralLocateAndDisplay(); // Shouldn't there be a check for locked tracks and vias here? if( item == NULL || (item->Type() == PCB_MODULE_T && (MODULE*)item->IsLocked()) ) return false; RemoveStruct( item, aDC ); } else return false; } OnModify(); SetCurItem( NULL ); return true; }
void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) { MODULE* currModule = NULL; wxPoint PosOK; wxPoint memopos; int error; LAYER_NUM lay_tmp_TOP, lay_tmp_BOTTOM; // Undo: init list PICKED_ITEMS_LIST newList; newList.m_Status = UR_CHANGED; ITEM_PICKER picker( NULL, UR_CHANGED ); if( GetBoard()->m_Modules == NULL ) return; m_canvas->SetAbortRequest( false ); switch( place_mode ) { case PLACE_1_MODULE: currModule = Module; if( currModule == NULL ) return; currModule->SetIsPlaced( false ); currModule->SetNeedsPlaced( false ); break; case PLACE_OUT_OF_BOARD: break; case PLACE_ALL: if( !IsOK( this, _( "Footprints NOT LOCKED will be moved" ) ) ) return; break; case PLACE_INCREMENTAL: if( !IsOK( this, _( "Footprints NOT PLACED will be moved" ) ) ) return; break; } memopos = CurrPosition; lay_tmp_BOTTOM = g_Route_Layer_BOTTOM; lay_tmp_TOP = g_Route_Layer_TOP; RoutingMatrix.m_GridRouting = (int) GetScreen()->GetGridSize().x; // Ensure Board.m_GridRouting has a reasonable value: if( RoutingMatrix.m_GridRouting < Millimeter2iu( 0.25 ) ) RoutingMatrix.m_GridRouting = Millimeter2iu( 0.25 ); // Compute module parameters used in auto place if( genPlacementRoutingMatrix( GetBoard(), m_messagePanel ) == 0 ) return; int moduleCount = 0; Module = GetBoard()->m_Modules; for( ; Module != NULL; Module = Module->Next() ) { Module->SetNeedsPlaced( false ); switch( place_mode ) { case PLACE_1_MODULE: if( currModule == Module ) { // Module will be placed, add to undo. picker.SetItem( currModule ); newList.PushItem( picker ); Module->SetNeedsPlaced( true ); } break; case PLACE_OUT_OF_BOARD: Module->SetIsPlaced( false ); if( Module->IsLocked() ) break; if( !RoutingMatrix.m_BrdBox.Contains( Module->GetPosition() ) ) { // Module will be placed, add to undo. picker.SetItem( Module ); newList.PushItem( picker ); Module->SetNeedsPlaced( true ); } break; case PLACE_ALL: Module->SetIsPlaced( false ); if( Module->IsLocked() ) break; // Module will be placed, add to undo. picker.SetItem( Module ); newList.PushItem( picker ); Module->SetNeedsPlaced( true ); break; case PLACE_INCREMENTAL: if( Module->IsLocked() ) { Module->SetIsPlaced( false ); break; } if( !Module->NeedsPlaced() ) { // Module will be placed, add to undo. picker.SetItem( Module ); newList.PushItem( picker ); Module->SetNeedsPlaced( true ); } break; } if( Module->NeedsPlaced() ) // Erase from screen { moduleCount++; Module->Draw( m_canvas, DC, GR_XOR ); } else { genModuleOnRoutingMatrix( Module ); } } // Undo command: prepare list if( newList.GetCount() ) SaveCopyInUndoList( newList, UR_CHANGED ); int cnt = 0; wxString msg; while( ( Module = PickModule( this, DC ) ) != NULL ) { // Display some info about activity, module placement can take a while: msg.Printf( _( "Place module %d of %d" ), cnt, moduleCount ); SetStatusText( msg ); double initialOrient = Module->GetOrientation(); // Display fill area of interest, barriers, penalties. drawPlacementRoutingMatrix( GetBoard(), DC ); error = getOptimalModulePlacement( this, Module, DC ); double bestScore = MinCout; double bestRotation = 0.0; int rotAllowed; PosOK = CurrPosition; if( error == ESC ) goto end_of_tst; // Try orientations 90, 180, 270 degrees from initial orientation rotAllowed = Module->GetPlacementCost180(); if( rotAllowed != 0 ) { Rotate_Module( DC, Module, 1800.0, true ); error = getOptimalModulePlacement( this, Module, DC ); MinCout *= OrientPenality[rotAllowed]; if( bestScore > MinCout ) // This orientation is better. { PosOK = CurrPosition; bestScore = MinCout; bestRotation = 1800.0; } else { Rotate_Module( DC, Module, initialOrient, false ); } if( error == ESC ) goto end_of_tst; } // Determine if the best orientation of a module is 90. rotAllowed = Module->GetPlacementCost90(); if( rotAllowed != 0 ) { Rotate_Module( DC, Module, 900.0, true ); error = getOptimalModulePlacement( this, Module, DC ); MinCout *= OrientPenality[rotAllowed]; if( bestScore > MinCout ) // This orientation is better. { PosOK = CurrPosition; bestScore = MinCout; bestRotation = 900.0; } else { Rotate_Module( DC, Module, initialOrient, false ); } if( error == ESC ) goto end_of_tst; } // Determine if the best orientation of a module is -90. if( rotAllowed != 0 ) { Rotate_Module( DC, Module, 2700.0, true ); error = getOptimalModulePlacement( this, Module, DC ); MinCout *= OrientPenality[rotAllowed]; if( bestScore > MinCout ) // This orientation is better. { PosOK = CurrPosition; bestScore = MinCout; bestRotation = 2700.0; } else { Rotate_Module( DC, Module, initialOrient, false ); } if( error == ESC ) goto end_of_tst; } end_of_tst: if( error == ESC ) break; // Place module. CurrPosition = GetCrossHairPosition(); SetCrossHairPosition( PosOK ); PlaceModule( Module, DC ); bestRotation += initialOrient; if( bestRotation != Module->GetOrientation() ) Rotate_Module( DC, Module, bestRotation, false ); SetCrossHairPosition( CurrPosition ); Module->CalculateBoundingBox(); genModuleOnRoutingMatrix( Module ); Module->SetIsPlaced( true ); Module->SetNeedsPlaced( false ); } CurrPosition = memopos; RoutingMatrix.UnInitRoutingMatrix(); g_Route_Layer_TOP = lay_tmp_TOP; g_Route_Layer_BOTTOM = lay_tmp_BOTTOM; Module = GetBoard()->m_Modules; for( ; Module != NULL; Module = Module->Next() ) { Module->CalculateBoundingBox(); } GetBoard()->m_Status_Pcb = 0; Compile_Ratsnest( DC, true ); m_canvas->ReDraw( DC, true ); }
bool PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosition, EDA_ITEM* aItem ) { if( aHotkeyCode == 0 ) return false; bool itemCurrentlyEdited = GetCurItem() && GetCurItem()->GetFlags(); MODULE* module = NULL; int evt_type = 0; //Used to post a wxCommandEvent on demand PCB_SCREEN* screen = GetScreen(); DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)GetDisplayOptions(); /* Convert lower to upper case * (the usual toupper function has problem with non ascii codes like function keys */ if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') ) aHotkeyCode += 'A' - 'a'; EDA_HOTKEY* HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, common_Hotkey_List ); if( HK_Descr == NULL ) HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, board_edit_Hotkey_List ); if( HK_Descr == NULL ) return false; int hk_id = HK_Descr->m_Idcommand; // Create a wxCommandEvent that will be posted in some hot keys functions wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); LAYER_NUM ll; switch( hk_id ) { default: case HK_NOT_FOUND: return false; case HK_LEFT_CLICK: OnLeftClick( aDC, aPosition ); break; case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events OnLeftClick( aDC, aPosition ); OnLeftDClick( aDC, aPosition ); break; case HK_SWITCH_TRACK_WIDTH_TO_NEXT: if( GetCanvas()->IsMouseCaptured() ) GetCanvas()->CallMouseCapture( aDC, wxDefaultPosition, false ); if( GetDesignSettings().GetTrackWidthIndex() < GetDesignSettings().m_TrackWidthList.size() - 1 ) GetDesignSettings().SetTrackWidthIndex( GetDesignSettings().GetTrackWidthIndex() + 1 ); else GetDesignSettings().SetTrackWidthIndex( 0 ); if( GetCanvas()->IsMouseCaptured() ) GetCanvas()->CallMouseCapture( aDC, wxDefaultPosition, false ); break; case HK_SWITCH_TRACK_WIDTH_TO_PREVIOUS: if( GetCanvas()->IsMouseCaptured() ) GetCanvas()->CallMouseCapture( aDC, wxDefaultPosition, false ); if( GetDesignSettings().GetTrackWidthIndex() <= 0 ) GetDesignSettings().SetTrackWidthIndex( GetDesignSettings().m_TrackWidthList.size() -1 ); else GetDesignSettings().SetTrackWidthIndex( GetDesignSettings().GetTrackWidthIndex() - 1 ); if( GetCanvas()->IsMouseCaptured() ) GetCanvas()->CallMouseCapture( aDC, wxDefaultPosition, false ); break; case HK_SWITCH_GRID_TO_FASTGRID1: SetFastGrid1(); break; case HK_SWITCH_GRID_TO_FASTGRID2: SetFastGrid2(); break; case HK_SWITCH_GRID_TO_NEXT: SetNextGrid(); break; case HK_SWITCH_GRID_TO_PREVIOUS: SetPrevGrid(); break; case HK_SWITCH_LAYER_TO_PREVIOUS: ll = GetActiveLayer(); if( !IsCopperLayer( ll ) ) break; if( ll == F_Cu ) ll = B_Cu; else if( ll == B_Cu ) ll = ToLAYER_ID( GetBoard()->GetCopperLayerCount() - 2 ); else ll = ll - 1; SwitchLayer( aDC, ToLAYER_ID( ll ) ); break; case HK_SWITCH_LAYER_TO_NEXT: ll = GetActiveLayer(); if( !IsCopperLayer( ll ) ) break; if( ll == B_Cu ) ll = F_Cu; else if( ++ll >= GetBoard()->GetCopperLayerCount() - 1 ) ll = B_Cu; SwitchLayer( aDC, ToLAYER_ID( ll ) ); break; case HK_SWITCH_LAYER_TO_COMPONENT: SwitchLayer( aDC, F_Cu ); break; case HK_SWITCH_LAYER_TO_COPPER: SwitchLayer( aDC, B_Cu ); break; case HK_SWITCH_LAYER_TO_INNER1: SwitchLayer( aDC, In1_Cu ); break; case HK_SWITCH_LAYER_TO_INNER2: SwitchLayer( aDC, In2_Cu ); break; case HK_SWITCH_LAYER_TO_INNER3: SwitchLayer( aDC, In3_Cu ); break; case HK_SWITCH_LAYER_TO_INNER4: SwitchLayer( aDC, In4_Cu ); break; case HK_SWITCH_LAYER_TO_INNER5: SwitchLayer( aDC, In5_Cu ); break; case HK_SWITCH_LAYER_TO_INNER6: SwitchLayer( aDC, In6_Cu ); break; case HK_HELP: // Display Current hotkey list DisplayHotkeyList( this, g_Board_Editor_Hokeys_Descr ); break; case HK_ZOOM_IN: evt_type = ID_POPUP_ZOOM_IN; break; case HK_ZOOM_OUT: evt_type = ID_POPUP_ZOOM_OUT; break; case HK_ZOOM_REDRAW: evt_type = ID_ZOOM_REDRAW; break; case HK_ZOOM_AUTO: evt_type = ID_ZOOM_PAGE; break; case HK_ZOOM_CENTER: evt_type = ID_POPUP_ZOOM_CENTER; break; case HK_ADD_MODULE: evt_type = ID_PCB_MODULE_BUTT; break; case HK_UNDO: case HK_REDO: if( !itemCurrentlyEdited ) { wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, HK_Descr->m_IdMenuEvent ); wxPostEvent( this, event ); } break; case HK_RESET_LOCAL_COORD: // Set the relative coord GetScreen()->m_O_Curseur = GetCrossHairPosition(); break; case HK_SET_GRID_ORIGIN: SetGridOrigin( GetCrossHairPosition() ); OnModify(); // because grid origin is saved in board, show as modified m_canvas->Refresh(); break; case HK_RESET_GRID_ORIGIN: SetGridOrigin( wxPoint( 0,0 ) ); OnModify(); // because grid origin is saved in board, show as modified m_canvas->Refresh(); break; case HK_SWITCH_UNITS: evt_type = (g_UserUnit == INCHES) ? ID_TB_OPTIONS_SELECT_UNIT_MM : ID_TB_OPTIONS_SELECT_UNIT_INCH; break; case HK_SWITCH_TRACK_DISPLAY_MODE: displ_opts->m_DisplayPcbTrackFill = !displ_opts->m_DisplayPcbTrackFill; m_canvas->Refresh(); break; case HK_DELETE: OnHotkeyDeleteItem( aDC ); break; case HK_BACK_SPACE: if( IsCopperLayer( GetActiveLayer() ) ) { if( !itemCurrentlyEdited ) { // no track is currently being edited - select a segment and remove it. // @todo: possibly? pass the HK command code to PcbGeneralLocateAndDisplay() // so it can restrict its search to specific item types. BOARD_ITEM * item = PcbGeneralLocateAndDisplay(); // don't let backspace delete modules!! if( item && item->IsTrack() ) { Delete_Segment( aDC, (TRACK*) item ); SetCurItem( NULL ); } OnModify(); } else if( GetCurItem()->IsTrack() ) { // then an element is being edited - remove the last segment. // simple lines for debugger: TRACK* track = (TRACK*) GetCurItem(); track = Delete_Segment( aDC, track ); SetCurItem( track ); OnModify(); } } break; case HK_GET_AND_MOVE_FOOTPRINT: if( !itemCurrentlyEdited ) evt_type = ID_POPUP_PCB_GET_AND_MOVE_MODULE_REQUEST; break; case HK_FIND_ITEM: if( !itemCurrentlyEdited ) evt_type = ID_FIND_ITEMS; break; case HK_LOAD_BOARD: if( !itemCurrentlyEdited ) evt_type = ID_LOAD_FILE ; break; case HK_SAVE_BOARD: if( !itemCurrentlyEdited ) evt_type = ID_SAVE_BOARD; break; case HK_ADD_MICROVIA: // Place a micro via if a track is in progress if( GetToolId() != ID_TRACK_BUTT ) return true; if( !itemCurrentlyEdited ) // no track in progress: nothing to do break; if( GetCurItem()->Type() != PCB_TRACE_T ) // Should not occur return true; if( !GetCurItem()->IsNew() ) return true; // place micro via and switch layer if( IsMicroViaAcceptable() ) evt_type = ID_POPUP_PCB_PLACE_MICROVIA; break; case HK_ADD_BLIND_BURIED_VIA: case HK_ADD_THROUGH_VIA: // Switch to alternate layer and Place a via if a track is in progress if( GetBoard()->GetDesignSettings().m_BlindBuriedViaAllowed && hk_id == HK_ADD_BLIND_BURIED_VIA ) GetBoard()->GetDesignSettings().m_CurrentViaType = VIA_BLIND_BURIED; else GetBoard()->GetDesignSettings().m_CurrentViaType = VIA_THROUGH; if( !itemCurrentlyEdited ) // no track in progress: switch layer only { Other_Layer_Route( NULL, aDC ); if( displ_opts->m_ContrastModeDisplay ) m_canvas->Refresh(); break; } if( GetToolId() != ID_TRACK_BUTT ) return true; if( GetCurItem()->Type() != PCB_TRACE_T ) return true; if( !GetCurItem()->IsNew() ) return true; evt_type = hk_id == HK_ADD_BLIND_BURIED_VIA ? ID_POPUP_PCB_PLACE_BLIND_BURIED_VIA : ID_POPUP_PCB_PLACE_THROUGH_VIA; break; case HK_SEL_LAYER_AND_ADD_THROUGH_VIA: case HK_SEL_LAYER_AND_ADD_BLIND_BURIED_VIA: if( GetCurItem() == NULL || !GetCurItem()->IsNew() || GetCurItem()->Type() != PCB_TRACE_T ) break; evt_type = hk_id == HK_SEL_LAYER_AND_ADD_BLIND_BURIED_VIA ? ID_POPUP_PCB_SELECT_CU_LAYER_AND_PLACE_BLIND_BURIED_VIA : ID_POPUP_PCB_SELECT_CU_LAYER_AND_PLACE_THROUGH_VIA; break; case HK_SWITCH_TRACK_POSTURE: /* change the position of initial segment when creating new tracks * switch from _/ to -\ . */ evt_type = ID_POPUP_PCB_SWITCH_TRACK_POSTURE ; break; case HK_DRAG_TRACK_KEEP_SLOPE: OnHotkeyMoveItem( HK_DRAG_TRACK_KEEP_SLOPE ); break; case HK_PLACE_ITEM: OnHotkeyPlaceItem( aDC ); break; case HK_ADD_NEW_TRACK: // Start new track, if possible OnHotkeyBeginRoute( aDC ); break; case HK_EDIT_ITEM: // Edit board item OnHotkeyEditItem( HK_EDIT_ITEM ); break; case HK_EDIT_MODULE_WITH_MODEDIT: // Edit module with module editor OnHotkeyEditItem( HK_EDIT_MODULE_WITH_MODEDIT ); break; // Footprint edition: case HK_LOCK_UNLOCK_FOOTPRINT: // toggle module "MODULE_is_LOCKED" status: // get any module, locked or not locked and toggle its locked status if( !itemCurrentlyEdited ) { wxPoint pos = RefPos( true ); module = GetBoard()->GetFootprint( pos, screen->m_Active_Layer, true ); } else if( GetCurItem()->Type() == PCB_MODULE_T ) { module = (MODULE*) GetCurItem(); } if( module ) { SetCurItem( module ); module->SetLocked( !module->IsLocked() ); OnModify(); SetMsgPanel( module ); } break; case HK_DRAG_ITEM: // Start drag module or track segment OnHotkeyMoveItem( HK_DRAG_ITEM ); break; case HK_MOVE_ITEM: // Start move item OnHotkeyMoveItem( HK_MOVE_ITEM ); break; case HK_COPY_ITEM: evt_type = OnHotkeyCopyItem(); break; case HK_ROTATE_ITEM: // Rotation OnHotkeyRotateItem( HK_ROTATE_ITEM ); break; case HK_FLIP_ITEM: OnHotkeyFlipItem( HK_FLIP_ITEM ); break; case HK_MOVE_ITEM_EXACT: case HK_DUPLICATE_ITEM: case HK_DUPLICATE_ITEM_AND_INCREMENT: case HK_CREATE_ARRAY: OnHotkeyDuplicateOrArrayItem( HK_Descr->m_Idcommand ); break; case HK_SWITCH_HIGHCONTRAST_MODE: // switch to high contrast mode and refresh the canvas displ_opts->m_ContrastModeDisplay = !displ_opts->m_ContrastModeDisplay; m_canvas->Refresh(); break; case HK_CANVAS_CAIRO: evt_type = ID_MENU_CANVAS_CAIRO; break; case HK_CANVAS_OPENGL: evt_type = ID_MENU_CANVAS_OPENGL; break; case HK_CANVAS_LEGACY: evt_type = ID_MENU_CANVAS_LEGACY; break; case HK_ZONE_FILL_OR_REFILL: evt_type = ID_POPUP_PCB_FILL_ALL_ZONES; break; case HK_ZONE_REMOVE_FILLED: evt_type = ID_POPUP_PCB_REMOVE_FILLED_AREAS_IN_ALL_ZONES; break; } if( evt_type != 0 ) { wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED ); evt.SetEventObject( this ); evt.SetId( evt_type ); GetEventHandler()->ProcessEvent( evt ); } return true; }
void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue, int aError, bool ignoreLineWidth ) const { // The full width of the lines to create: int linewidth = ignoreLineWidth ? 0 : m_Width; linewidth += 2 * aClearanceValue; // Creating a reliable clearance shape for circles and arcs is not so easy, due to // the error created by segment approximation. // for a circle this is not so hard: create a polygon from a circle slightly bigger: // thickness = linewidth + s_error_max, and radius = initial radius + s_error_max/2 // giving a shape with a suitable internal radius and external radius // For an arc this is more tricky: TODO switch( m_Shape ) { case S_CIRCLE: TransformRingToPolygon( aCornerBuffer, GetCenter(), GetRadius(), aError, linewidth ); break; case S_ARC: TransformArcToPolygon( aCornerBuffer, GetCenter(), GetArcStart(), m_Angle, aError, linewidth ); break; case S_SEGMENT: TransformOvalClearanceToPolygon( aCornerBuffer, m_Start, m_End, linewidth, aError ); break; case S_POLYGON: if( IsPolyShapeValid() ) { // The polygon is expected to be a simple polygon // not self intersecting, no hole. MODULE* module = GetParentModule(); // NULL for items not in footprints double orientation = module ? module->GetOrientation() : 0.0; wxPoint offset; if( module ) offset = module->GetPosition(); // Build the polygon with the actual position and orientation: std::vector< wxPoint> poly; poly = BuildPolyPointsList(); for( unsigned ii = 0; ii < poly.size(); ii++ ) { RotatePoint( &poly[ii], orientation ); poly[ii] += offset; } // If the polygon is not filled, treat it as a closed set of lines if( !IsPolygonFilled() ) { for( size_t ii = 1; ii < poly.size(); ii++ ) { TransformOvalClearanceToPolygon( aCornerBuffer, poly[ii - 1], poly[ii], linewidth, aError ); } TransformOvalClearanceToPolygon( aCornerBuffer, poly.back(), poly.front(), linewidth, aError ); break; } // Generate polygons for the outline + clearance // This code is compatible with a polygon with holes linked to external outline // by overlapping segments. // Insert the initial polygon: aCornerBuffer.NewOutline(); for( unsigned ii = 0; ii < poly.size(); ii++ ) aCornerBuffer.Append( poly[ii].x, poly[ii].y ); if( linewidth ) // Add thick outlines { wxPoint corner1( poly[poly.size()-1] ); for( unsigned ii = 0; ii < poly.size(); ii++ ) { wxPoint corner2( poly[ii] ); if( corner2 != corner1 ) { TransformRoundedEndsSegmentToPolygon( aCornerBuffer, corner1, corner2, aError, linewidth ); } corner1 = corner2; } } } break; case S_CURVE: // Bezier curve { std::vector<wxPoint> ctrlPoints = { m_Start, m_BezierC1, m_BezierC2, m_End }; BEZIER_POLY converter( ctrlPoints ); std::vector< wxPoint> poly; converter.GetPoly( poly, m_Width ); for( unsigned ii = 1; ii < poly.size(); ii++ ) { TransformRoundedEndsSegmentToPolygon( aCornerBuffer, poly[ii - 1], poly[ii], aError, linewidth ); } } break; default: break; } }
void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, const wxPoint& offset ) { int ux0, uy0, dx, dy, radius, StAngle, EndAngle; LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer; MODULE* module = (MODULE*) m_Parent; if( !module ) return; BOARD* brd = GetBoard( ); if( brd->IsLayerVisible( m_Layer ) == false ) return; EDA_COLOR_T color = brd->GetLayerColor( m_Layer ); DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)panel->GetDisplayOptions(); if(( draw_mode & GR_ALLOW_HIGHCONTRAST ) && displ_opts && displ_opts->m_ContrastModeDisplay ) { if( !IsOnLayer( curr_layer ) ) ColorTurnToDarkDarkGray( &color ); } ux0 = m_Start.x - offset.x; uy0 = m_Start.y - offset.y; dx = m_End.x - offset.x; dy = m_End.y - offset.y; GRSetDrawMode( DC, draw_mode ); bool filled = displ_opts ? displ_opts->m_DisplayModEdgeFill : FILLED; if( IsCopperLayer( m_Layer ) ) filled = displ_opts ? displ_opts->m_DisplayPcbTrackFill : FILLED; switch( m_Shape ) { case S_SEGMENT: if( filled ) GRLine( panel->GetClipBox(), DC, ux0, uy0, dx, dy, m_Width, color ); else // SKETCH Mode GRCSegm( panel->GetClipBox(), DC, ux0, uy0, dx, dy, m_Width, color ); break; case S_CIRCLE: radius = KiROUND( Distance( ux0, uy0, dx, dy ) ); if( filled ) { GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius, m_Width, color ); } else // SKETCH Mode { GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius + (m_Width / 2), color ); GRCircle( panel->GetClipBox(), DC, ux0, uy0, radius - (m_Width / 2), color ); } break; case S_ARC: radius = KiROUND( Distance( ux0, uy0, dx, dy ) ); StAngle = ArcTangente( dy - uy0, dx - ux0 ); EndAngle = StAngle + m_Angle; if( !panel->GetPrintMirrored() ) { if( StAngle > EndAngle ) std::swap( StAngle, EndAngle ); } else // Mirrored mode: arc orientation is reversed { if( StAngle < EndAngle ) std::swap( StAngle, EndAngle ); } if( filled ) { GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle, radius, m_Width, color ); } else // SKETCH Mode { GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle, radius + (m_Width / 2), color ); GRArc( panel->GetClipBox(), DC, ux0, uy0, StAngle, EndAngle, radius - (m_Width / 2), color ); } break; case S_POLYGON: { // We must compute absolute coordinates from m_PolyPoints // which are relative to module position, orientation 0 std::vector<wxPoint> points = m_PolyPoints; for( unsigned ii = 0; ii < points.size(); ii++ ) { wxPoint& pt = points[ii]; RotatePoint( &pt.x, &pt.y, module->GetOrientation() ); pt += module->GetPosition() - offset; } GRPoly( panel->GetClipBox(), DC, points.size(), &points[0], true, m_Width, color, color ); } break; default: break; } }