dialog_edit_module_for_BoardEditor.cpp 21.3 KB
Newer Older
1 2 3
/******************************************************************************
 * Module editor: Dialog box for editing module properties in the pcb editor. *
 ******************************************************************************/
charras's avatar
charras committed
4

5 6 7
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
8
 * Copyright (C) 2011 Jean-Pierre Charras
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 * Copyright (C) 2012 Dick Hollenbeck, dick@softplc.com
 * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */


31 32 33 34 35 36 37 38 39 40
#include <fctsys.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <pcbnew.h>
#include <appl_wxstruct.h>
#include <gestfich.h>
#include <3d_struct.h>
#include <3d_viewer.h>
#include <wxPcbStruct.h>
41
#include <base_units.h>
42 43 44 45 46

#include <class_module.h>
#include <class_text_mod.h>

#include <dialog_edit_module_for_BoardEditor.h>
47
#include <wildcards_and_files_ext.h>
charras's avatar
charras committed
48 49


50 51 52
DIALOG_MODULE_BOARD_EDITOR::DIALOG_MODULE_BOARD_EDITOR( PCB_EDIT_FRAME*  aParent,
                                                        MODULE*          aModule,
                                                        wxDC*            aDC ) :
charras's avatar
charras committed
53 54 55
    DIALOG_MODULE_BOARD_EDITOR_BASE( aParent )
{
    m_Parent = aParent;
56 57
    m_DC     = aDC;
    m_CurrentModule = aModule;
charras's avatar
charras committed
58

59 60 61 62
    // Give an icon
    wxIcon  icon;
    icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
    SetIcon( icon );
charras's avatar
charras committed
63 64 65 66

    InitModeditProperties();
    InitBoardProperties();

67
    m_sdbSizerStdButtonsOK->SetDefault();
charras's avatar
charras committed
68 69 70 71
    GetSizer()->SetSizeHints( this );
    Centre();
}

72

charras's avatar
charras committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
DIALOG_MODULE_BOARD_EDITOR::~DIALOG_MODULE_BOARD_EDITOR()
{
    for( unsigned ii = 0; ii < m_Shapes3D_list.size(); ii++ )
        delete m_Shapes3D_list[ii];

    m_Shapes3D_list.clear();

    delete m_ReferenceCopy;
    delete m_ValueCopy;
    delete m_3D_Scale;
    delete m_3D_Offset;
    delete m_3D_Rotation;
}


88
/* Creation of the panel properties of the module editor. */
89
void DIALOG_MODULE_BOARD_EDITOR::InitBoardProperties()
charras's avatar
charras committed
90
{
91
    PutValueInLocalUnits( *m_ModPositionX, m_CurrentModule->GetPosition().x );
92
    m_XPosUnit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
charras's avatar
charras committed
93

94
    PutValueInLocalUnits( *m_ModPositionY, m_CurrentModule->GetPosition().y );
95
    m_YPosUnit->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
charras's avatar
charras committed
96

97
    m_LayerCtrl->SetSelection(
dickelbeck's avatar
dickelbeck committed
98
         (m_CurrentModule->GetLayer() == LAYER_N_BACK) ? 1 : 0 );
charras's avatar
charras committed
99

100
    bool select = false;
101
    switch( int( m_CurrentModule->GetOrientation() ) )
102 103 104 105 106 107
    {
    case 0:
        m_OrientCtrl->SetSelection( 0 );
        break;

    case 900:
108
    case -2700:
109 110 111
        m_OrientCtrl->SetSelection( 1 );
        break;

112
    case -900:
113 114 115 116
    case 2700:
        m_OrientCtrl->SetSelection( 2 );
        break;

117
    case -1800:
118 119 120 121 122 123
    case 1800:
        m_OrientCtrl->SetSelection( 3 );
        break;

    default:
        m_OrientCtrl->SetSelection( 4 );
124
        select = true;
125 126
        break;
    }
charras's avatar
charras committed
127

128
    wxString msg;
129
    msg << m_CurrentModule->GetOrientation();
130 131 132
    m_OrientValue->SetValue( msg );
    m_OrientValue->Enable( select );

133
    // Initialize dialog relative to masks clearances
134 135 136
    m_NetClearanceUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
    m_SolderMaskMarginUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
    m_SolderPasteMarginUnits->SetLabel( GetAbbreviatedUnitsLabel( g_UserUnit ) );
137

138 139
    PutValueInLocalUnits( *m_NetClearanceValueCtrl, m_CurrentModule->GetLocalClearance() );
    PutValueInLocalUnits( *m_SolderMaskMarginCtrl, m_CurrentModule->GetLocalSolderMaskMargin() );
140 141 142

    // These 2 parameters are usually < 0, so prepare entering a negative
    // value, if current is 0
143 144
    PutValueInLocalUnits( *m_SolderPasteMarginCtrl, m_CurrentModule->GetLocalSolderPasteMargin() );

Dick Hollenbeck's avatar
Dick Hollenbeck committed
145
    if( m_CurrentModule->GetLocalSolderPasteMargin() == 0 )
146 147
        m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) +
                                           m_SolderPasteMarginCtrl->GetValue() );
148 149 150

    // Add solder paste margin ration in per cent
    // for the usual default value 0.0, display -0.0 (or -0,0 in some countries)
151
    msg.Printf( wxT( "%f" ),
Dick Hollenbeck's avatar
Dick Hollenbeck committed
152
                    m_CurrentModule->GetLocalSolderPasteMarginRatio() * 100.0 );
153

Dick Hollenbeck's avatar
Dick Hollenbeck committed
154
    if( m_CurrentModule->GetLocalSolderPasteMarginRatio() == 0.0 &&
155
        msg[0] == '0')  // Sometimes Printf adds a sign if the value is very small (0.0)
156
        m_SolderPasteMarginRatioCtrl->SetValue( wxT("-") + msg );
157
    else
158
        m_SolderPasteMarginRatioCtrl->SetValue( msg );
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178

    switch( m_CurrentModule->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;
    }
179
}
charras's avatar
charras committed
180 181


182
void DIALOG_MODULE_BOARD_EDITOR::OnCancelClick( wxCommandEvent& event )
charras's avatar
charras committed
183 184 185 186 187 188 189
{
    EndModal( -1 );
}


void DIALOG_MODULE_BOARD_EDITOR::GotoModuleEditor( wxCommandEvent& event )
{
Dick Hollenbeck's avatar
Dick Hollenbeck committed
190
    if( m_CurrentModule->GetTimeStamp() == 0 )    // Module Editor needs a non null timestamp
charras's avatar
charras committed
191
    {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
192
        m_CurrentModule->SetTimeStamp( GetNewTimeStamp() );
193
        m_Parent->OnModify();
charras's avatar
charras committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    }

    EndModal( 2 );
}


void DIALOG_MODULE_BOARD_EDITOR::ExchangeModule( wxCommandEvent& event )
{
    m_Parent->InstallExchangeModuleFrame( m_CurrentModule );

    // Warning: m_CurrentModule was deleted by exchange module
    m_Parent->SetCurItem( NULL );
    EndModal( 0 );
}


void DIALOG_MODULE_BOARD_EDITOR::ModuleOrientEvent( wxCommandEvent& event )
{
    switch( m_OrientCtrl->GetSelection() )
    {
    case 0:
215
        m_OrientValue->Enable( false );
charras's avatar
charras committed
216 217 218 219
        m_OrientValue->SetValue( wxT( "0" ) );
        break;

    case 1:
220
        m_OrientValue->Enable( false );
charras's avatar
charras committed
221 222 223 224
        m_OrientValue->SetValue( wxT( "900" ) );
        break;

    case 2:
225
        m_OrientValue->Enable( false );
charras's avatar
charras committed
226 227 228 229
        m_OrientValue->SetValue( wxT( "2700" ) );
        break;

    case 3:
230
        m_OrientValue->Enable( false );
charras's avatar
charras committed
231 232 233 234
        m_OrientValue->SetValue( wxT( "1800" ) );
        break;

    default:
235
        m_OrientValue->Enable( true );
charras's avatar
charras committed
236 237 238 239 240 241 242 243 244 245 246 247
        break;
    }
}


void DIALOG_MODULE_BOARD_EDITOR::InitModeditProperties()
{
    SetFocus();

    m_LastSelected3DShapeIndex = -1;

    /* Init 3D shape list */
248
    S3D_MASTER* draw3D = m_CurrentModule->Models();
charras's avatar
charras committed
249 250 251

    while( draw3D )
    {
252 253
        if( !draw3D->m_Shape3DName.IsEmpty() )
        {
254
            S3D_MASTER* draw3DCopy = new S3D_MASTER( NULL );
255 256
            draw3DCopy->Copy( draw3D );
            m_Shapes3D_list.push_back( draw3DCopy );
257
            m_3D_ShapeNameListBox->Append( draw3DCopy->m_Shape3DName );
258
        }
charras's avatar
charras committed
259 260 261
        draw3D = (S3D_MASTER*) draw3D->Next();
    }

262 263
    m_ReferenceCopy = new TEXTE_MODULE( NULL );
    m_ValueCopy     = new TEXTE_MODULE( NULL );
264 265
    m_ReferenceCopy->Copy( &m_CurrentModule->Reference() );
    m_ValueCopy->Copy( &m_CurrentModule->Value() );
266 267
    m_ReferenceCtrl->SetValue( m_ReferenceCopy->GetText() );
    m_ValueCtrl->SetValue( m_ValueCopy->GetText() );
charras's avatar
charras committed
268

269
    m_AttributsCtrl->SetItemToolTip( 0,
270 271
        _( "Use this attribute for most non SMD components\n"
            "Components with this option are not put in the footprint position list file" ) );
charras's avatar
charras committed
272
    m_AttributsCtrl->SetItemToolTip( 1,
273 274
         _( "Use this attribute for SMD components.\n"
            "Only components with this option are put in the footprint position list file" ) );
charras's avatar
charras committed
275
    m_AttributsCtrl->SetItemToolTip( 2,
276 277
        _( "Use this attribute for \"virtual\" components drawn on board\n"
           "(like a old ISA PC bus connector)" ) );
charras's avatar
charras committed
278 279

    /* Controls on right side of the dialog */
280
    switch( m_CurrentModule->GetAttributes() & 255 )
charras's avatar
charras committed
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
    {
    case 0:
        m_AttributsCtrl->SetSelection( 0 );
        break;

    case MOD_CMS:
        m_AttributsCtrl->SetSelection( 1 );
        break;

    case MOD_VIRTUAL:
        m_AttributsCtrl->SetSelection( 2 );
        break;

    default:
        m_AttributsCtrl->SetSelection( 0 );
        break;
    }

299
    m_AutoPlaceCtrl->SetSelection( (m_CurrentModule->IsLocked()) ? 1 : 0 );
300

301 302 303 304
    m_AutoPlaceCtrl->SetItemToolTip( 0,
                                    _( "Enable hotkey move commands and Auto Placement" ) );
    m_AutoPlaceCtrl->SetItemToolTip( 1,
                                    _( "Disable hotkey move commands and Auto Placement" ) );
305

306
    m_CostRot90Ctrl->SetValue( m_CurrentModule->GetPlacementCost90() );
charras's avatar
charras committed
307

308
    m_CostRot180Ctrl->SetValue( m_CurrentModule->GetPlacementCost180() );
charras's avatar
charras committed
309 310 311 312

    // Initialize 3D parameters

    wxBoxSizer* BoxSizer = new wxBoxSizer( wxVERTICAL );
313
    m_3D_Scale = new VERTEX_VALUE_CTRL( m_Panel3D, _( "Shape Scale:" ), BoxSizer );
charras's avatar
charras committed
314 315 316
    m_Sizer3DValues->Add( BoxSizer, 0, wxGROW | wxALL, 5 );

    BoxSizer    = new wxBoxSizer( wxVERTICAL );
317
    m_3D_Offset = new VERTEX_VALUE_CTRL( m_Panel3D, _( "Shape Offset (inch):" ), BoxSizer );
charras's avatar
charras committed
318 319 320
    m_Sizer3DValues->Add( BoxSizer, 0, wxGROW | wxALL, 5 );

    BoxSizer = new wxBoxSizer( wxVERTICAL );
321 322
    m_3D_Rotation = new VERTEX_VALUE_CTRL( m_Panel3D,
                                           _( "Shape Rotation (degrees):" ), BoxSizer );
charras's avatar
charras committed
323
    m_Sizer3DValues->Add( BoxSizer, 0, wxGROW | wxALL, 5 );
324 325 326 327 328 329 330 331

    // if m_3D_ShapeNameListBox is not empty, preselect first 3D shape
    if( m_3D_ShapeNameListBox->GetCount() > 0 )
    {
        m_LastSelected3DShapeIndex = 0;
        m_3D_ShapeNameListBox->SetSelection( m_LastSelected3DShapeIndex );
        Transfert3DValuesToDisplay( m_Shapes3D_list[m_LastSelected3DShapeIndex] );
    }
332 333 334 335

    // We have modified the UI, so call Fit() for m_Panel3D
    // to be sure the m_Panel3D sizers are initiliazed before opening the dialog
    m_Panel3D->GetSizer()->Fit( m_Panel3D );
charras's avatar
charras committed
336 337 338 339 340
}


/* Initialize 3D info displayed in dialog box from values in aStruct3DSource
 */
341 342
void DIALOG_MODULE_BOARD_EDITOR::Transfert3DValuesToDisplay(
    S3D_MASTER* aStruct3DSource )
charras's avatar
charras committed
343 344 345 346 347 348 349 350 351 352 353
{
    if( aStruct3DSource )
    {
        m_3D_Scale->SetValue( aStruct3DSource->m_MatScale );

        m_3D_Offset->SetValue( aStruct3DSource->m_MatPosition );

        m_3D_Rotation->SetValue( aStruct3DSource->m_MatRotation );
    }
    else
    {
354
        S3D_VERTEX dummy_vertex;
charras's avatar
charras committed
355 356 357 358 359
        dummy_vertex.x = dummy_vertex.y = dummy_vertex.z = 1.0;
        m_3D_Scale->SetValue( dummy_vertex );
    }
}

360

charras's avatar
charras committed
361 362 363
/** Copy 3D info displayed in dialog box to values in a item in m_Shapes3D_list
 * @param aIndexSelection = item index in m_Shapes3D_list
 */
364 365
void DIALOG_MODULE_BOARD_EDITOR::TransfertDisplayTo3DValues(
    int aIndexSelection  )
charras's avatar
charras committed
366
{
367
    if( aIndexSelection >= (int) m_Shapes3D_list.size() )
charras's avatar
charras committed
368 369
        return;

370
    S3D_MASTER* struct3DDest = m_Shapes3D_list[aIndexSelection];
charras's avatar
charras committed
371 372 373 374 375
    struct3DDest->m_MatScale    = m_3D_Scale->GetValue();
    struct3DDest->m_MatRotation = m_3D_Rotation->GetValue();
    struct3DDest->m_MatPosition = m_3D_Offset->GetValue();
}

376 377

void DIALOG_MODULE_BOARD_EDITOR::On3DShapeNameSelected( wxCommandEvent& event )
charras's avatar
charras committed
378 379 380 381
{
    if( m_LastSelected3DShapeIndex >= 0 )
        TransfertDisplayTo3DValues( m_LastSelected3DShapeIndex );
    m_LastSelected3DShapeIndex = m_3D_ShapeNameListBox->GetSelection();
382

383 384 385
    if( m_LastSelected3DShapeIndex < 0 )    // happens under wxGTK when
                                            // deleting an item in
                                            // m_3D_ShapeNameListBox wxListBox
386
        return;
387 388 389

    if( m_LastSelected3DShapeIndex >= (int) m_Shapes3D_list.size() )
    {
390
        wxMessageBox( wxT( "On3DShapeNameSelected() error" ) );
391 392 393
        m_LastSelected3DShapeIndex = -1;
        return;
    }
charras's avatar
charras committed
394 395 396
    Transfert3DValuesToDisplay( m_Shapes3D_list[m_LastSelected3DShapeIndex] );
}

397 398

void DIALOG_MODULE_BOARD_EDITOR::Add3DShape( wxCommandEvent& event )
charras's avatar
charras committed
399 400 401 402
{
    Browse3DLib( event );
}

403 404

void DIALOG_MODULE_BOARD_EDITOR::Remove3DShape( wxCommandEvent& event )
charras's avatar
charras committed
405 406 407 408 409 410 411 412
{
    if( m_LastSelected3DShapeIndex >= 0 )
        TransfertDisplayTo3DValues( m_LastSelected3DShapeIndex );

    int ii = m_3D_ShapeNameListBox->GetSelection();
    if( ii < 0 )
        return;

413 414
    m_Shapes3D_list.erase( m_Shapes3D_list.begin() + ii );
    m_3D_ShapeNameListBox->Delete( ii );
charras's avatar
charras committed
415

416
    if( m_3D_ShapeNameListBox->GetCount() == 0 )
charras's avatar
charras committed
417 418 419 420
        Transfert3DValuesToDisplay( NULL );
    else
    {
        m_LastSelected3DShapeIndex = 0;
421
        m_3D_ShapeNameListBox->SetSelection( m_LastSelected3DShapeIndex );
422 423
        Transfert3DValuesToDisplay(
            m_Shapes3D_list[m_LastSelected3DShapeIndex] );
charras's avatar
charras committed
424 425 426 427 428 429 430 431 432 433 434 435 436
    }
}


void DIALOG_MODULE_BOARD_EDITOR::Browse3DLib( wxCommandEvent& event )
{
    wxString fullfilename, shortfilename;
    wxString fullpath;

    fullpath = wxGetApp().ReturnLastVisitedLibraryPath( LIB3D_PATH );
#ifdef __WINDOWS__
    fullpath.Replace( wxT( "/" ), wxT( "\\" ) );
#endif
437

charras's avatar
charras committed
438
    fullfilename = EDA_FileSelector( _( "3D Shape:" ),
439 440
                                     fullpath,
                                     wxEmptyString,
441 442
                                     wxEmptyString,
                                     wxGetTranslation( Shapes3DFileWildcard ),
charras's avatar
charras committed
443 444
                                     this,
                                     wxFD_OPEN,
445
                                     true
charras's avatar
charras committed
446 447
                                     );

448
    if( fullfilename.IsEmpty() )
charras's avatar
charras committed
449 450 451 452 453 454 455 456 457
        return;

    wxFileName fn = fullfilename;
    wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );

    /* If the file path is already in the library search paths
     * list, just add the library name to the list.  Otherwise, add
     * the library name with the full or relative path.
     * the relative path, when possible is preferable,
458 459
     * because it preserve use of default libraries paths, when the path is a
     * sub path of these default paths
charras's avatar
charras committed
460
     */
461 462
    shortfilename =
        wxGetApp().ReturnFilenameWithRelativePathInLibPath( fullfilename );
charras's avatar
charras committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

    wxFileName aux = shortfilename;
    if( aux.IsAbsolute() )
    {   // Absolute path, ask if the user wants a relative one
        int diag = wxMessageBox(
            _( "Use a relative path?" ),
            _( "Path type" ),
            wxYES_NO | wxICON_QUESTION, this );

        if( diag == wxYES )
        {   // Make it relative
            aux.MakeRelativeTo( wxT(".") );
            shortfilename = aux.GetPathWithSep() + aux.GetFullName();
        }
    }

479
    S3D_MASTER* new3DShape = new S3D_MASTER( NULL );
480 481 482 483
#ifdef __WINDOWS__
    // Store filename in Unix notation
    shortfilename.Replace( wxT( "\\" ), wxT( "/" ) );
#endif
charras's avatar
charras committed
484 485 486 487 488 489 490 491
    new3DShape->m_Shape3DName = shortfilename;
    m_Shapes3D_list.push_back( new3DShape );
    m_3D_ShapeNameListBox->Append( shortfilename );

    if( m_LastSelected3DShapeIndex >= 0 )
        TransfertDisplayTo3DValues( m_LastSelected3DShapeIndex );

    m_LastSelected3DShapeIndex = m_3D_ShapeNameListBox->GetCount() - 1;
492
    m_3D_ShapeNameListBox->SetSelection( m_LastSelected3DShapeIndex );
charras's avatar
charras committed
493 494 495 496 497 498
    Transfert3DValuesToDisplay( m_Shapes3D_list[m_LastSelected3DShapeIndex] );
}


void DIALOG_MODULE_BOARD_EDITOR::OnOkClick( wxCommandEvent& event )
{
499
    wxPoint  modpos;
500
    wxString msg;
charras's avatar
charras committed
501

502
    if( m_CurrentModule->GetFlags() == 0 )    // this is a simple edition, we
503
                                              // must create an undo entry
charras's avatar
charras committed
504 505 506 507
        m_Parent->SaveCopyInUndoList( m_CurrentModule, UR_CHANGED );

    if( m_DC )
    {
508 509
        m_Parent->GetCanvas()->CrossHairOff( m_DC );
        m_CurrentModule->Draw( m_Parent->GetCanvas(), m_DC, GR_XOR );
charras's avatar
charras committed
510 511
    }

512
    // Init Fields (should be first, because they can be moved or/and flipped later):
513 514
    m_CurrentModule->Reference().Copy( m_ReferenceCopy );
    m_CurrentModule->Value().Copy( m_ValueCopy );
515

516
    // Initialize masks clearances
517 518 519
    m_CurrentModule->SetLocalClearance( ReturnValueFromTextCtrl( *m_NetClearanceValueCtrl ) );
    m_CurrentModule->SetLocalSolderMaskMargin( ReturnValueFromTextCtrl( *m_SolderMaskMarginCtrl ) );
    m_CurrentModule->SetLocalSolderPasteMargin( ReturnValueFromTextCtrl( *m_SolderPasteMarginCtrl ) );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
520

521
    double dtmp = 0.0;
522 523
    msg = m_SolderPasteMarginRatioCtrl->GetValue();
    msg.ToDouble( &dtmp );
524

525 526 527 528 529 530 531
    // A -50% margin ratio means no paste on a pad, the ratio must be >= -50%
    if( dtmp < -50.0 )
        dtmp = -50.0;
    // A margin ratio is always <= 0
    // 0 means use full pad copper area
    if( dtmp > 0.0 )
        dtmp = 0.0;
532

Dick Hollenbeck's avatar
Dick Hollenbeck committed
533
    m_CurrentModule->SetLocalSolderPasteMarginRatio( dtmp / 100 );
534

535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
    switch( m_ZoneConnectionChoice->GetSelection() )
    {
    default:
    case 0:
        m_CurrentModule->SetZoneConnection( UNDEFINED_CONNECTION );
        break;

    case 1:
        m_CurrentModule->SetZoneConnection( PAD_IN_ZONE );
        break;

    case 2:
        m_CurrentModule->SetZoneConnection( THERMAL_PAD );
        break;

    case 3:
        m_CurrentModule->SetZoneConnection( PAD_NOT_IN_ZONE );
        break;
    }

charras's avatar
charras committed
555
    // Set Module Position
556 557
    modpos.x = ReturnValueFromTextCtrl( *m_ModPositionX );
    modpos.y = ReturnValueFromTextCtrl( *m_ModPositionY );
558
    m_CurrentModule->SetPosition( modpos );
559
    m_CurrentModule->SetLocked( m_AutoPlaceCtrl->GetSelection() == 1 );
charras's avatar
charras committed
560 561 562 563

    switch( m_AttributsCtrl->GetSelection() )
    {
    case 0:
564
        m_CurrentModule->SetAttributes( 0 );
charras's avatar
charras committed
565 566 567
        break;

    case 1:
568
        m_CurrentModule->SetAttributes( MOD_CMS );
charras's avatar
charras committed
569 570 571
        break;

    case 2:
572
        m_CurrentModule->SetAttributes( MOD_VIRTUAL );
charras's avatar
charras committed
573 574 575
        break;
    }

576 577
    m_CurrentModule->SetPlacementCost90( m_CostRot90Ctrl->GetValue() );
    m_CurrentModule->SetPlacementCost180( m_CostRot180Ctrl->GetValue() );
charras's avatar
charras committed
578

579 580 581 582 583 584 585
    /* Now, set orientation. must be made after others changes,
     * because rotation changes fields positions on board according to the new orientation
     * (relative positions are not modified)
     */
    long orient = 0;
    msg = m_OrientValue->GetValue();
    msg.ToLong( &orient );
586

587 588 589
    if( m_CurrentModule->GetOrientation() != orient )
        m_CurrentModule->Rotate( m_CurrentModule->GetPosition(),
                                 orient - m_CurrentModule->GetOrientation() );
590 591

    // Set component side, that also have effect on the fields positions on board
592
    bool change_layer = false;
593 594 595
    if( m_LayerCtrl->GetSelection() == 0 )     // layer req = COMPONENT
    {
        if( m_CurrentModule->GetLayer() == LAYER_N_BACK )
596
            change_layer = true;
597 598
    }
    else if( m_CurrentModule->GetLayer() == LAYER_N_FRONT )
599
        change_layer = true;
600 601

    if( change_layer )
602
        m_CurrentModule->Flip( m_CurrentModule->GetPosition() );
603

charras's avatar
charras committed
604
    /* Update 3D shape list */
605
    int         ii = m_3D_ShapeNameListBox->GetSelection();
606

607
    if( ii >= 0 )
charras's avatar
charras committed
608
        TransfertDisplayTo3DValues( ii  );
609

610
    S3D_MASTER* draw3D = m_CurrentModule->Models();
611

charras's avatar
charras committed
612 613
    for( unsigned ii = 0; ii < m_Shapes3D_list.size(); ii++ )
    {
614
        S3D_MASTER* draw3DCopy = m_Shapes3D_list[ii];
615

charras's avatar
charras committed
616 617
        if( draw3DCopy->m_Shape3DName.IsEmpty() )
            continue;
618

charras's avatar
charras committed
619 620 621
        if( draw3D == NULL )
        {
            draw3D = new S3D_MASTER( draw3D );
622
            m_CurrentModule->Models().Append( draw3D );
charras's avatar
charras committed
623 624 625 626 627 628 629 630 631 632 633 634
        }

        draw3D->m_Shape3DName = draw3DCopy->m_Shape3DName;
        draw3D->m_MatScale    = draw3DCopy->m_MatScale;
        draw3D->m_MatRotation = draw3DCopy->m_MatRotation;
        draw3D->m_MatPosition = draw3DCopy->m_MatPosition;

        draw3D = draw3D->Next();
    }

    // Remove old extra 3D shapes
    S3D_MASTER* nextdraw3D;
635

charras's avatar
charras committed
636 637 638
    for( ; draw3D != NULL; draw3D = nextdraw3D )
    {
        nextdraw3D = (S3D_MASTER*) draw3D->Next();
639
        delete m_CurrentModule->Models().Remove( draw3D );
charras's avatar
charras committed
640 641 642
    }

    // Fill shape list with one void entry, if no entry
643 644
    if( m_CurrentModule->Models() == NULL )
        m_CurrentModule->Models().PushBack( new S3D_MASTER( m_CurrentModule ) );
charras's avatar
charras committed
645 646


647
    m_CurrentModule->CalculateBoundingBox();
charras's avatar
charras committed
648

649
    m_Parent->OnModify();
charras's avatar
charras committed
650 651 652 653 654

    EndModal( 1 );

    if( m_DC )
    {
655 656
        m_CurrentModule->Draw( m_Parent->GetCanvas(), m_DC, GR_OR );
        m_Parent->GetCanvas()->CrossHairOn( m_DC );
charras's avatar
charras committed
657 658 659 660
    }
}


661
void DIALOG_MODULE_BOARD_EDITOR::OnEditReference( wxCommandEvent& event )
charras's avatar
charras committed
662
{
663
    wxPoint tmp = m_Parent->GetScreen()->GetCrossHairPosition();
664

665
    m_Parent->GetScreen()->SetCrossHairPosition( m_ReferenceCopy->GetTextPosition() );
666
    m_ReferenceCopy->SetParent( m_CurrentModule );
charras's avatar
charras committed
667
    m_Parent->InstallTextModOptionsFrame( m_ReferenceCopy, NULL );
668
    m_Parent->GetScreen()->SetCrossHairPosition( tmp );
669
    m_ReferenceCtrl->SetValue( m_ReferenceCopy->GetText() );
charras's avatar
charras committed
670 671
}

672 673

void DIALOG_MODULE_BOARD_EDITOR::OnEditValue( wxCommandEvent& event )
charras's avatar
charras committed
674
{
675
    wxPoint tmp = m_Parent->GetScreen()->GetCrossHairPosition();
676

677
    m_Parent->GetScreen()->SetCrossHairPosition( m_ValueCopy->GetTextPosition() );
678
    m_ValueCopy->SetParent( m_CurrentModule );
charras's avatar
charras committed
679
    m_Parent->InstallTextModOptionsFrame( m_ValueCopy, NULL );
680
    m_Parent->GetScreen()->SetCrossHairPosition( tmp );
681
    m_ValueCtrl->SetValue( m_ValueCopy->GetText() );
charras's avatar
charras committed
682
}