modules.cpp 23.2 KB
Newer Older
1 2 3
/********************************************************/
/* Modification de la place, orient, nombre des MODULES */
/********************************************************/
4

5
/* Fichier MODULES.Cpp */
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

#include "fctsys.h"
#include "gr_basic.h"

#include "common.h"
#include "pcbnew.h"
#include "autorout.h"
#include "trigo.h"

#include "protos.h"

#include "drag.h"

/* fonctions externes */

/* Fonctions locales */
22 23
static int  ChangeSideMaskLayer( int masque );
static void Exit_Module( WinEDA_DrawPanel* Panel, wxDC* DC );
24 25

/* Variables locales : */
26 27
static int ModuleInitOrient;    // Lors des moves, val init de l'orient (pour annulation)
static int ModuleInitLayer;     // Lors des moves, val init de la couche (pour annulation)
28 29 30


/*************************************************************************/
31
void Show_Pads_On_Off( WinEDA_DrawPanel* panel, wxDC* DC, MODULE* module )
32
/**************************************************************************/
33

34
/* Fonction appelee lors de l'activation/desactivation de la visualisation
35 36 37
 *  des Pads du module en deplacement
 *  Effacement ou visu des Pads selon conditions initiales
 */
38
{
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    D_PAD* pt_pad;
    bool   pad_fill_tmp;

    if( module == 0 )
        return;

    pad_fill_tmp = DisplayOpt.DisplayPadFill;
    DisplayOpt.DisplayPadFill = FALSE; /* Trace en SKETCH */
    pt_pad = module->m_Pads;
    for( ; pt_pad != NULL; pt_pad = (D_PAD*) pt_pad->Pnext )
    {
        pt_pad->Draw( panel, DC, g_Offset_Module, GR_XOR );
    }

    DisplayOpt.DisplayPadFill = pad_fill_tmp;
54 55
}

56

57 58 59 60 61
/***************************************************************************/
/* Fonction appelee lors de l'activation/desactivation de la visualisation */
/*	du rastnest du module en deplacement									  */
/*	Effacement ou visu du rastnest selon conditions initiales			  */
/***************************************************************************/
62
void Rastnest_On_Off( WinEDA_DrawPanel* panel, wxDC* DC, MODULE* module )
63
{
64 65 66 67
    WinEDA_BasePcbFrame* frame = (WinEDA_BasePcbFrame*) panel->m_Parent;

    frame->build_ratsnest_module( DC, module );
    frame->trace_ratsnest_module( DC );
68 69
}

70

71
/***************************************************/
72
MODULE* WinEDA_BasePcbFrame::GetModuleByName()
73
/***************************************************/
74

75
/* Get a module name from user and return a pointer to the corresponding module
76
 */
77
{
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    wxString modulename;
    MODULE*  module = NULL;

    Get_Message( _( "Footprint name:" ), modulename, this );
    if( !modulename.IsEmpty() )
    {
        module = m_Pcb->m_Modules;
        while( module )
        {
            if( module->m_Reference->m_Text.CmpNoCase( modulename ) == 0 )
                break;
            module = module->Next();
        }
    }
    return module;
93 94
}

95

96
/**********************************************************************/
97
void WinEDA_PcbFrame::StartMove_Module( MODULE* module, wxDC* DC )
98 99
/**********************************************************************/
{
100 101 102
    if( module == NULL )
        return;

103
    SetCurItem( module );
104 105 106
    m_Pcb->m_Status_Pcb &= ~CHEVELU_LOCAL_OK;
    module->m_Flags |= IS_MOVED;
    ModuleInitOrient = module->m_Orient;
107
    ModuleInitLayer  = module->GetLayer();
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

    /* Effacement chevelu general si necessaire */
    if( g_Show_Ratsnest )
        DrawGeneralRatsnest( DC );

    if( g_DragSegmentList ) /* Anormal ! */
    {
        EraseDragListe();
    }

    if( g_Drag_Pistes_On )
    {
        Build_Drag_Liste( DrawPanel, DC, module );
    }

    m_Pcb->m_Status_Pcb     |= DO_NOT_SHOW_GENERAL_RASTNEST;
    DrawPanel->ManageCurseur = Montre_Position_Empreinte;
    DrawPanel->ForceCloseManageCurseur = Exit_Module;
    DrawPanel->m_AutoPAN_Request = TRUE;

    // effacement module a l'ecran:
    module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_XOR );

    // Reaffichage
    DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
133 134
}

135

136
/**************************************************/
137
void Exit_Module( WinEDA_DrawPanel* Panel, wxDC* DC )
138 139 140
/***************************************************/
/* fonction de sortie de l'application */
{
141 142 143 144 145
    DRAG_SEGM*           pt_drag;
    TRACK*               pt_segm;
    MODULE*              module;
    WinEDA_BasePcbFrame* pcbframe = (WinEDA_BasePcbFrame*) Panel->m_Parent;

146
    module = (MODULE*) pcbframe->m_CurrentScreen->GetCurItem();
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    pcbframe->m_Pcb->m_Status_Pcb &= ~CHEVELU_LOCAL_OK;

    if( module )
    {
        // effacement module a l'ecran:
        DrawModuleOutlines( Panel, DC, module );
        /* restitution de l'empreinte si move ou effacement copie*/
        if( module->m_Flags & IS_MOVED )
        {
            /* Move en cours : remise a l'etat d'origine */
            if( g_Drag_Pistes_On )
            {
                /* Effacement des segments dragges */
                pt_drag = g_DragSegmentList;
                for( ; pt_drag != NULL; pt_drag = pt_drag->Pnext )
                {
                    pt_segm = pt_drag->m_Segm;
                    pt_segm->Draw( Panel, DC, GR_XOR );
                }
            }

            /* Remise en etat d'origine des segments dragges */
            pt_drag = g_DragSegmentList;
            for( ; pt_drag != NULL; pt_drag = pt_drag->Pnext )
            {
                pt_segm = pt_drag->m_Segm; pt_segm->SetState( EDIT, OFF );
                pt_drag->SetInitialValues();
                pt_segm->Draw( Panel, DC, GR_OR );
            }

            EraseDragListe();
            module->m_Flags = 0;
        }

        if( module->m_Flags & IS_NEW )
        {
183
            module ->DeleteStructure();
184 185 186 187 188 189 190 191 192 193 194
            module = NULL;
            pcbframe->m_Pcb->m_Status_Pcb = 0;
            pcbframe->build_liste_pads();
        }
    }

    /* Reaffichage du module a l'ecran */
    if( module )
    {
        if( ModuleInitOrient != module->m_Orient )
            pcbframe->Rotate_Module( NULL, module, ModuleInitOrient, FALSE );
195
        if( ModuleInitLayer != module->GetLayer() )
196 197 198 199 200 201
            pcbframe->Change_Side_Module( module, NULL );
        module->Draw( Panel, DC, wxPoint( 0, 0 ), GR_OR );
    }
    g_Drag_Pistes_On     = FALSE;
    Panel->ManageCurseur = NULL;
    Panel->ForceCloseManageCurseur = NULL;
202
    pcbframe->SetCurItem( NULL );
203 204 205 206
}


/**********************************************************/
207
MODULE* WinEDA_BasePcbFrame::Copie_Module( MODULE* module )
208 209 210
/**********************************************************/
/* copie le module "module" en position courante */
{
211
    MODULE* newmodule;
212

213 214
    if( module == NULL )
        return NULL;
215

216
    m_CurrentScreen->SetModify();
217

218 219 220 221 222 223 224
    /* Duplication du module */
    m_Pcb->m_Status_Pcb = 0;
    newmodule = new MODULE( m_Pcb );
    newmodule->Copy( module );
    newmodule->m_Parent = m_Pcb;
    newmodule->AddToChain( module );
    newmodule->m_Flags = IS_NEW;
225

226
    build_liste_pads();
227

228 229 230
    newmodule->Display_Infos( this );
    m_Pcb->m_Status_Pcb &= ~CHEVELU_LOCAL_OK;
    return newmodule;
231 232
}

233

234
/**********************************************************************************/
235
void Montre_Position_Empreinte( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
236
/**********************************************************************************/
237

238
/* redessin du contour de l'empreinte  lors des deplacements de la souris
239
 */
240
{
241
    MODULE* module = (MODULE*) panel->m_Parent->m_CurrentScreen->GetCurItem();
242

243 244
    if(  module == NULL )
        return;
245

246 247 248 249 250
    /* efface ancienne position */
    if( erase )
    {
        DrawModuleOutlines( panel, DC, module );
    }
251

252 253 254 255
    /* Redessine le module a la nouvelle place */
    g_Offset_Module.x = module->m_Pos.x - panel->m_Parent->m_CurrentScreen->m_Curseur.x;
    g_Offset_Module.y = module->m_Pos.y - panel->m_Parent->m_CurrentScreen->m_Curseur.y;
    DrawModuleOutlines( panel, DC, module );
256

257
    Dessine_Segments_Dragges( panel, DC );
258 259 260 261
}


/**************************************************************/
262
bool WinEDA_PcbFrame::Delete_Module( MODULE* module, wxDC* DC )
263
/**************************************************************/
264

265
/*
266 267 268 269
 *  Commande Delete Module :
 *  Suppression d'une empreinte
 *  les pointeurs divers sont mis a jour
 */
270
{
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
    EDA_BaseStruct* PtBack, * PtNext;
    wxString        msg;

    /* Si l'empreinte est selectee , on ne peut pas l'effacer ! */
    if( module == NULL )
        return FALSE;

    /* Confirmation de l'effacement */
    module->Display_Infos( this );

    msg << _( "Delete Module" ) << wxT( " " ) << module->m_Reference->m_Text
        << wxT( "  (" ) << _( "Value " ) << module->m_Value->m_Text
        << wxT( ") ?" );
    if( !IsOK( this, msg ) )
    {
        return FALSE;
    }

    m_CurrentScreen->SetModify();

    /* Erase rastnest if needed */
    if( g_Show_Ratsnest )
        DrawGeneralRatsnest( DC );

    /* Effacement du module a l'ecran */
    if( DC )
        module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_XOR );

    /* Suppression du chainage */
    PtBack = module->Pback;
    PtNext = module->Pnext;
    if( PtBack == (EDA_BaseStruct*) m_Pcb )
    {
        m_Pcb->m_Modules = (MODULE*) PtNext;
    }
    else
    {
        PtBack->Pnext = PtNext;
    }
    if( PtNext )
        PtNext->Pback = PtBack;

    /* Sauvegarde en buffer des undelete */
    SaveItemEfface( module, 1 );

    m_Pcb->m_Status_Pcb = 0;
    build_liste_pads();
    ReCompile_Ratsnest_After_Changes( DC );
    return TRUE;
320 321
}

322

323
/**********************************************************************/
324
void WinEDA_BasePcbFrame::Change_Side_Module( MODULE* Module, wxDC* DC )
325 326 327
/**********************************************************************/

/* Change de cote un composant : il y a inversion MIROIR autour de l'axe X
328 329 330 331
 *  Le changement n'est fait que si la couche est
 *      - CUIVRE ou CMP
 *      Si DC == NULL, il n'y a pas de redessin du composant et du chevelu
 */
332
{
333 334 335 336 337 338 339
    D_PAD*          pt_pad;
    TEXTE_MODULE*   pt_texte;
    EDGE_MODULE*    pt_edgmod;
    EDA_BaseStruct* PtStruct;

    if( Module == NULL )
        return;
340
    if( (Module->GetLayer() != CMP_N) && (Module->GetLayer() != COPPER_LAYER_N) )
341 342 343 344 345 346 347 348 349 350 351 352 353
        return;

    m_CurrentScreen->SetModify();

    if( !(Module->m_Flags & IS_MOVED) )
    {
        m_Pcb->m_Status_Pcb &= ~( LISTE_CHEVELU_OK | CONNEXION_OK);
        if( DC )
            Module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_XOR );

        /* Effacement chevelu general si necessaire */
        if( DC && g_Show_Ratsnest )
            DrawGeneralRatsnest( DC );
354

355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
        /* Init des variables utilisees dans la routine Dessine_Drag_segment() */
        g_Offset_Module.x = 0;
        g_Offset_Module.y = 0;
    }
    else    // Module en deplacement
    {
        /* efface empreinte ( vue en contours) si elle a ete deja dessinee */
        if( DC )
        {
            DrawModuleOutlines( DrawPanel, DC, Module );
            Dessine_Segments_Dragges( DrawPanel, DC );
        }
    }

    /* mise a jour du Flag de l'empreinte et des couches des contours et textes */
370
    Module->SetLayer( ChangeSideNumLayer( Module->GetLayer() ) );
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386

    /* Inversion miroir de l'orientation */
    Module->m_Orient = -Module->m_Orient;
    NORMALIZE_ANGLE_POS( Module->m_Orient );

    /* Inversion miroir + layers des pastilles */
    pt_pad = Module->m_Pads;
    for( ; pt_pad != NULL; pt_pad = (D_PAD*) pt_pad->Pnext )
    {
        pt_pad->m_Pos.y      -= Module->m_Pos.y;
        pt_pad->m_Pos.y       = -pt_pad->m_Pos.y;
        pt_pad->m_Pos.y      += Module->m_Pos.y;
        pt_pad->m_Pos0.y      = -pt_pad->m_Pos0.y;
        pt_pad->m_Offset.y    = -pt_pad->m_Offset.y;
        pt_pad->m_DeltaSize.y = -pt_pad->m_DeltaSize.y;
        NEGATE_AND_NORMALIZE_ANGLE_POS( pt_pad->m_Orient );
387

388 389 390 391 392 393 394 395 396 397 398 399
        /* change cote pour pastilles surfaciques */
        pt_pad->m_Masque_Layer = ChangeSideMaskLayer( pt_pad->m_Masque_Layer );
    }

    /* Inversion miroir de la Reference et mise en miroir : */
    pt_texte = Module->m_Reference;
    pt_texte->m_Pos.y -= Module->m_Pos.y;
    pt_texte->m_Pos.y  = -pt_texte->m_Pos.y;
    pt_texte->m_Pos.y += Module->m_Pos.y;
    pt_texte->m_Pos0.y = pt_texte->m_Pos0.y;
    pt_texte->m_Miroir = 1;
    NEGATE_AND_NORMALIZE_ANGLE_POS( pt_texte->m_Orient );
400 401
    pt_texte->SetLayer( Module->GetLayer() );
    pt_texte->SetLayer( ChangeSideNumLayer( pt_texte->GetLayer() ) );
402

403
    if( Module->GetLayer() == COPPER_LAYER_N )
404
        pt_texte->SetLayer( SILKSCREEN_N_CU );
405

406 407
    if( Module->GetLayer() == CMP_N )
        pt_texte->SetLayer( SILKSCREEN_N_CMP );
408

409
    if( (Module->GetLayer() == SILKSCREEN_N_CU)
410
       || (Module->GetLayer() == ADHESIVE_N_CU) || (Module->GetLayer() == COPPER_LAYER_N) )
411 412 413 414 415 416 417 418 419 420
        pt_texte->m_Miroir = 0;

    /* Inversion miroir de la Valeur et mise en miroir : */
    pt_texte = Module->m_Value;
    pt_texte->m_Pos.y -= Module->m_Pos.y;
    pt_texte->m_Pos.y  = -pt_texte->m_Pos.y;
    pt_texte->m_Pos.y += Module->m_Pos.y;
    pt_texte->m_Pos0.y = pt_texte->m_Pos0.y;
    pt_texte->m_Miroir = 1;
    NEGATE_AND_NORMALIZE_ANGLE_POS( pt_texte->m_Orient );
421 422
    pt_texte->SetLayer( Module->GetLayer() );
    pt_texte->SetLayer( ChangeSideNumLayer( pt_texte->GetLayer() ) );
423

424
    if( Module->GetLayer() == COPPER_LAYER_N )
425
        pt_texte->SetLayer( SILKSCREEN_N_CU );
426

427 428
    if( Module->GetLayer() == CMP_N )
        pt_texte->SetLayer( SILKSCREEN_N_CMP );
429

430
    if( (Module->GetLayer() == SILKSCREEN_N_CU)
431
       || (Module->GetLayer() == ADHESIVE_N_CU) || (Module->GetLayer() == COPPER_LAYER_N) )
432 433 434 435 436 437
        pt_texte->m_Miroir = 0;

    /* Inversion miroir des dessins de l'empreinte : */
    PtStruct = Module->m_Drawings;
    for( ; PtStruct != NULL; PtStruct = PtStruct->Pnext )
    {
438
        switch( PtStruct->Type() )
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
        {
        case TYPEEDGEMODULE:
            pt_edgmod = (EDGE_MODULE*) PtStruct;
            pt_edgmod->m_Start.y -= Module->m_Pos.y;
            pt_edgmod->m_Start.y  = -pt_edgmod->m_Start.y;
            pt_edgmod->m_Start.y += Module->m_Pos.y;
            pt_edgmod->m_End.y   -= Module->m_Pos.y;
            pt_edgmod->m_End.y    = -pt_edgmod->m_End.y;
            pt_edgmod->m_End.y   += Module->m_Pos.y;
            /* inversion des coords locales */
            pt_edgmod->m_Start0.y = -pt_edgmod->m_Start0.y;
            pt_edgmod->m_End0.y   = -pt_edgmod->m_End0.y;
            if( pt_edgmod->m_Shape == S_ARC )
            {
                pt_edgmod->m_Angle = -pt_edgmod->m_Angle;
            }

456
            pt_edgmod->SetLayer( ChangeSideNumLayer( pt_edgmod->GetLayer() ) );
457 458 459 460 461 462 463 464 465 466 467 468
            break;

        case TYPETEXTEMODULE:
            /* Inversion miroir de la position et mise en miroir : */
            pt_texte = (TEXTE_MODULE*) PtStruct;
            pt_texte->m_Pos.y -= Module->m_Pos.y;
            pt_texte->m_Pos.y  = -pt_texte->m_Pos.y;
            pt_texte->m_Pos.y += Module->m_Pos.y;
            pt_texte->m_Pos0.y = pt_texte->m_Pos0.y;
            pt_texte->m_Miroir = 1;
            NEGATE_AND_NORMALIZE_ANGLE_POS( pt_texte->m_Orient );

469 470
            pt_texte->SetLayer( Module->GetLayer() ); 
            pt_texte->SetLayer( ChangeSideNumLayer( pt_texte->GetLayer() ) );
471

472
            if( Module->GetLayer() == COPPER_LAYER_N )
473
                pt_texte->SetLayer( SILKSCREEN_N_CU );
474

475 476
            if( Module->GetLayer() == CMP_N )
                pt_texte->SetLayer( SILKSCREEN_N_CMP );
477

478 479
            if(  Module->GetLayer() == SILKSCREEN_N_CU
              || Module->GetLayer() == ADHESIVE_N_CU
480
              || Module->GetLayer() == COPPER_LAYER_N )
481
            {
482
                pt_texte->m_Miroir = 0;
483
            }
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501

            break;

        default:
            DisplayError( this, wxT( "Unknown Draw Type" ) ); break;
        }
    }

    /* calcul du rectangle d'encadrement */
    Module->Set_Rectangle_Encadrement();

    Module->Display_Infos( this );

    if( !(Module->m_Flags & IS_MOVED) ) /* Inversion simple */
    {
        if( DC )
        {
            Module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
502
            
503 504 505 506 507 508 509 510 511 512 513 514 515
            /* affichage chevelu general si necessaire */
            ReCompile_Ratsnest_After_Changes( DC );
        }
    }
    else
    {
        if( DC )
        {
            DrawModuleOutlines( DrawPanel, DC, Module );
            Dessine_Segments_Dragges( DrawPanel, DC );
        }
        m_Pcb->m_Status_Pcb &= ~CHEVELU_LOCAL_OK;
    }
516 517 518 519
}


/*********************************************/
520
static int ChangeSideMaskLayer( int masque )
521
/*********************************************/
522

523
/* Routine de recalcul du masque-layer lors des
524 525 526
 *  echanges cote cu/cmp pour les couches CU/CMP specialisees
 *  (cuivre, serigr., pate , soudure)
 */
527
{
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
    int newmasque;

    newmasque = masque & ~(CUIVRE_LAYER | CMP_LAYER |
                           SILKSCREEN_LAYER_CU | SILKSCREEN_LAYER_CMP |
                           ADHESIVE_LAYER_CU | ADHESIVE_LAYER_CMP |
                           SOLDERMASK_LAYER_CU | SOLDERMASK_LAYER_CMP |
                           SOLDERPASTE_LAYER_CU | SOLDERPASTE_LAYER_CMP |
                           ADHESIVE_LAYER_CU | ADHESIVE_LAYER_CMP);

    if( masque & CUIVRE_LAYER )
        newmasque |= CMP_LAYER;
    if( masque & CMP_LAYER )
        newmasque |= CUIVRE_LAYER;

    if( masque & SILKSCREEN_LAYER_CU )
        newmasque |= SILKSCREEN_LAYER_CMP;
    if( masque & SILKSCREEN_LAYER_CMP )
        newmasque |= SILKSCREEN_LAYER_CU;

    if( masque & ADHESIVE_LAYER_CU )
        newmasque |= ADHESIVE_LAYER_CMP;
    if( masque & ADHESIVE_LAYER_CMP )
        newmasque |= ADHESIVE_LAYER_CU;

    if( masque & SOLDERMASK_LAYER_CU )
        newmasque |= SOLDERMASK_LAYER_CMP;
    if( masque & SOLDERMASK_LAYER_CMP )
        newmasque |= SOLDERMASK_LAYER_CU;

    if( masque & SOLDERPASTE_LAYER_CU )
        newmasque |= SOLDERPASTE_LAYER_CMP;
    if( masque & SOLDERPASTE_LAYER_CMP )
        newmasque |= SOLDERPASTE_LAYER_CU;

    if( masque & ADHESIVE_LAYER_CU )
        newmasque |= ADHESIVE_LAYER_CMP;
    if( masque & ADHESIVE_LAYER_CMP )
        newmasque |= ADHESIVE_LAYER_CU;

    return newmasque;
}
569 570


571 572 573
/*************************************/
int ChangeSideNumLayer( int oldlayer )
/*************************************/
574

575 576 577 578 579 580
/* Routine de recalcul du numero de couche lors des
 *  echanges cote cu/cmp pour les couches CU/CMP specialisees
 *  (cuivre, serigr., pate , soudure)
 */
{
    int newlayer;
581

582 583
    switch( oldlayer )
    {
584
    case COPPER_LAYER_N:
585
        newlayer = CMP_N; break;
586

587
    case CMP_N:
588
        newlayer = COPPER_LAYER_N; break;
589

590 591
    case SILKSCREEN_N_CU:
        newlayer = SILKSCREEN_N_CMP; break;
592

593 594
    case SILKSCREEN_N_CMP:
        newlayer = SILKSCREEN_N_CU; break;
595

596 597
    case ADHESIVE_N_CU:
        newlayer = ADHESIVE_N_CMP; break;
598

599 600
    case ADHESIVE_N_CMP:
        newlayer = ADHESIVE_N_CU; break;
601

602 603
    case SOLDERMASK_N_CU:
        newlayer = SOLDERMASK_N_CMP; break;
604

605 606
    case SOLDERMASK_N_CMP:
        newlayer = SOLDERMASK_N_CU; break;
607

608 609
    case SOLDERPASTE_N_CU:
        newlayer = SOLDERPASTE_N_CMP; break;
610

611 612
    case SOLDERPASTE_N_CMP:
        newlayer = SOLDERPASTE_N_CU; break;
613

614 615 616
    default:
        newlayer = oldlayer;
    }
617

618
    return newlayer;
619 620
}

621

622
/*****************************************************************/
623
void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC )
624
/*****************************************************************/
625

626
/* Place a l'endroit pointe par la souris le module deja existant selectionne
627 628 629 630 631 632 633
 *  auparavant.
 *  Entree: module = num du module a replacer
 *          DC ( si NULL: pas d'affichage a l'�ran
 *  Sortie :
 *          mise a jour des nouvelles coord des differents elements du module
 *          affichage a l'ecran du module
 */
634
{
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
    TRACK*     pt_segm;
    DRAG_SEGM* pt_drag;
    wxPoint    newpos;

    if( module == 0 )
        return;

    m_CurrentScreen->SetModify();
    m_Pcb->m_Status_Pcb &= ~( LISTE_CHEVELU_OK | CONNEXION_OK);

    if( g_Show_Module_Ratsnest && (m_Pcb->m_Status_Pcb & LISTE_PAD_OK) && DC )
        trace_ratsnest_module( DC );

    newpos = m_CurrentScreen->m_Curseur;

    module->SetPosition( newpos );
    if( DC )
        module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );

    /* Tracage des segments dragges et liberation memoire */
    if( g_DragSegmentList )
    {
        pt_drag = g_DragSegmentList;
        for( ; pt_drag != NULL; pt_drag = pt_drag->Pnext )
        {
            pt_segm = pt_drag->m_Segm;
            pt_segm->SetState( EDIT, OFF );
            if( DC )
                pt_segm->Draw( DrawPanel, DC, GR_OR );
        }

        EraseDragListe();
    }

    /* affichage chevelu general si necessaire */
    ReCompile_Ratsnest_After_Changes( DC );

    module->Display_Infos( this );

    DrawPanel->ManageCurseur = NULL;
    DrawPanel->ForceCloseManageCurseur = NULL;
    module->m_Flags  = 0;
    g_Drag_Pistes_On = FALSE;
678 679 680 681
}


/***********************************************************************/
682 683
void WinEDA_BasePcbFrame::Rotate_Module( wxDC* DC, MODULE* module,
                                         int angle, bool incremental )
684
/***********************************************************************/
685

686
/*
687 688 689 690 691 692
 *  Fait tourner l'empreinte de angle degres, dans le sens < 0.
 *  Si incremental == TRUE, la rotation est faite a partir de la derniere orientation,
 *  sinon le module est mis dans l'orientation absolue angle.
 *  Si DC == NULL, le composant n'est pas redessine.
 *  Sinon, il est efface, tourne et redessine
 */
693
{
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
    if( module == NULL )
        return;

    m_CurrentScreen->SetModify();

    /* efface ancienne position */
    if( !(module->m_Flags & IS_MOVED) ) /* Rotation simple */
    {
        if( DC )
        {
            module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_XOR );
            /* Reaffichage chevelu general si necessaire */
            if( g_Show_Ratsnest )
                DrawGeneralRatsnest( DC );
        }
    }
    else
    {
        /* reaffiche module en mouvement */
        if( DC )
        {
            DrawModuleOutlines( DrawPanel, DC, module );
            Dessine_Segments_Dragges( DrawPanel, DC );
        }
    }

    m_Pcb->m_Status_Pcb &= ~(LISTE_CHEVELU_OK | CONNEXION_OK);

    if( incremental )
        module->SetOrientation( module->m_Orient + angle );
    else
        module->SetOrientation( angle );

    module->Display_Infos( this );

    if( DC )
    {
        if( !(module->m_Flags & IS_MOVED) ) /* Rotation simple */
        {
            module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
734
            
735 736 737 738 739 740 741 742 743 744
            /* Reaffichage chevelu general si necessaire */
            ReCompile_Ratsnest_After_Changes( DC );
        }
        else
        {
            /* reaffiche module en mouvement */
            DrawModuleOutlines( DrawPanel, DC, module );
            Dessine_Segments_Dragges( DrawPanel, DC );
        }
    }
745 746 747 748 749 750 751
}


/*************************************************/
/* Redessine en mode XOR la silouhette du module */
/*************************************************/

752
void DrawModuleOutlines( WinEDA_DrawPanel* panel, wxDC* DC, MODULE* module )
753
{
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
    int    pad_fill_tmp;
    D_PAD* pt_pad;

    if( module == NULL )
        return;
    module->DrawEdgesOnly( panel, DC, g_Offset_Module, GR_XOR );

    if( g_Show_Pads_Module_in_Move )
    {
        pad_fill_tmp = DisplayOpt.DisplayPadFill;
        DisplayOpt.DisplayPadFill = SKETCH;  /* Trace en SKETCH en deplacement */

        pt_pad = module->m_Pads;
        for( ; pt_pad != NULL; pt_pad = (D_PAD*) pt_pad->Pnext )
        {
            pt_pad->Draw( panel, DC, g_Offset_Module, GR_XOR );
        }

        DisplayOpt.DisplayPadFill = pad_fill_tmp;
    }

    if( g_Show_Module_Ratsnest && panel )
    {
        WinEDA_BasePcbFrame* frame = (WinEDA_BasePcbFrame*) panel->m_Parent;
        frame->build_ratsnest_module( DC, module );
        frame->trace_ratsnest_module( DC );
    }
781
}