void EDA_3D_CANVAS::calcBBox() { BOARD* pcb = GetBoard(); m_fastAABBox.Reset(); for( MODULE* module = pcb->m_Modules; module; module = module->Next() ) { CBBOX tmpFastAABBox; // Compute the transformation matrix for this module based on translation, rotation and orientation. float zpos = GetPrm3DVisu().GetModulesZcoord3DIU( module->IsFlipped() ); wxPoint pos = module->GetPosition(); glm::mat4 fullTransformMatrix; fullTransformMatrix = glm::translate( glm::mat4(), S3D_VERTEX( (float)(pos.x * GetPrm3DVisu().m_BiuTo3Dunits), (float)(-pos.y * GetPrm3DVisu().m_BiuTo3Dunits), zpos ) ); if( module->GetOrientation() ) fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians( (float)(module->GetOrientation() / 10.0f) ), S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); if( module->IsFlipped() ) { fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians( 180.0f ), S3D_VERTEX( 0.0f, 1.0f, 0.0f ) ); fullTransformMatrix = glm::rotate( fullTransformMatrix, glm::radians( 180.0f ), S3D_VERTEX( 0.0f, 0.0f, 1.0f ) ); } // Compute a union bounding box for all the shapes of the model S3D_MASTER* shape3D = module->Models(); for( ; shape3D; shape3D = shape3D->Next() ) { if( shape3D->Is3DType( S3D_MASTER::FILE3D_VRML ) ) tmpFastAABBox.Union( shape3D->getFastAABBox() ); } tmpFastAABBox.ApplyTransformationAA( fullTransformMatrix ); m_fastAABBox.Union( tmpFastAABBox ); } // Create a board bounding box based on board size wxSize brd_size = getBoardSize(); wxPoint brd_center_pos = getBoardCenter(); float xsize = brd_size.x; float ysize = brd_size.y; float scale = GetPrm3DVisu().m_BiuTo3Dunits; float xmin = (brd_center_pos.x - xsize / 2.0) * scale; float xmax = (brd_center_pos.x + xsize / 2.0) * scale; float ymin = (brd_center_pos.y - ysize / 2.0) * scale; float ymax = (brd_center_pos.y + ysize / 2.0) * scale; float zmin = GetPrm3DVisu().GetLayerZcoordBIU( B_Adhes ) * scale; float zmax = GetPrm3DVisu().GetLayerZcoordBIU( F_Adhes ) * scale; m_boardAABBox = CBBOX( S3D_VERTEX(xmin, ymin, zmin), S3D_VERTEX(xmax, ymax, zmax) ); // Add BB board with BB models and scale it a bit m_fastAABBox.Union( m_boardAABBox ); m_fastAABBox_Shadow = m_fastAABBox; m_fastAABBox_Shadow.Scale( SHADOW_BOUNDING_BOX_SCALE ); }
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 Module" ), 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 ); 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; }
bool DIALOG_TEXT_PROPERTIES::TransferDataToWindow() { if( m_SingleLineText->IsShown() ) { m_SingleLineText->SetValue( m_edaText->GetText() ); if( m_modText && m_modText->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE ) SelectReferenceNumber( static_cast<wxTextEntry*>( m_SingleLineText ) ); else m_SingleLineText->SetSelection( -1, -1 ); } else if( m_MultiLineText->IsShown() ) { m_MultiLineText->SetValue( m_edaText->GetText() ); m_MultiLineText->SetSelection( -1, -1 ); } else if (m_DimensionText->IsShown() ) { m_DimensionText->SetValue( m_edaText->GetText() ); m_DimensionText->SetSelection( -1, -1 ); DIMENSION* dimension = (DIMENSION*) m_item; EDA_UNITS_T units; bool useMils; dimension->GetUnits( units, useMils ); m_DimensionUnitsOpt->SetSelection( units == MILLIMETRES ? 2 : useMils ? 1 : 0 ); } if( m_item->Type() == PCB_MODULE_TEXT_T && m_modText ) { MODULE* module = dynamic_cast<MODULE*>( m_modText->GetParent() ); wxString msg; if( module ) { msg.Printf( _("Footprint %s (%s), %s, rotated %.1f deg"), module->GetReference(), module->GetValue(), module->IsFlipped() ? _( "back side (mirrored)" ) : _( "front side" ), module->GetOrientation() / 10.0 ); } m_statusLine->SetLabel( msg ); } else { m_statusLine->Show( false ); } if( m_LayerSelectionCtrl->SetLayerSelection( m_item->GetLayer() ) < 0 ) { wxMessageBox( _( "This item was on a non-existing or forbidden layer.\n" "It has been moved to the first allowed layer." ) ); m_LayerSelectionCtrl->SetSelection( 0 ); } m_textWidth.SetValue( m_edaText->GetTextSize().x ); m_textHeight.SetValue( m_edaText->GetTextSize().y ); m_thickness.SetValue( m_edaText->GetThickness() ); m_posX.SetValue( m_edaText->GetTextPos().x ); m_posY.SetValue( m_edaText->GetTextPos().y ); m_Visible->SetValue( m_edaText->IsVisible() ); m_Italic->SetValue( m_edaText->IsItalic() ); EDA_TEXT_HJUSTIFY_T hJustify = m_edaText->GetHorizJustify(); m_JustifyChoice->SetSelection( (int) hJustify + 1 ); m_OrientValue = m_edaText->GetTextAngleDegrees(); m_Mirrored->SetValue( m_edaText->IsMirrored() ); if( m_modText ) m_KeepUpright->SetValue( m_modText->IsKeepUpright() ); return DIALOG_TEXT_PROPERTIES_BASE::TransferDataToWindow(); }