pinedit.cpp 31.3 KB
Newer Older
1 2 3
/***************************/
/*  EESchema - PinEdit.cpp */
/***************************/
plyatov's avatar
plyatov committed
4

5
#if defined (__GNUG__) && !defined (NO_GCC_PRAGMA)
plyatov's avatar
plyatov committed
6 7 8 9 10 11 12
#pragma implementation "pinedit-dialog.h"
#endif

#include "pinedit-dialog.h"

static int CodeOrient[4] =
{
13 14 15 16
    PIN_RIGHT,
    PIN_LEFT,
    PIN_UP,
    PIN_DOWN
plyatov's avatar
plyatov committed
17 18 19 20 21
};

#define NBSHAPES 7
static wxString shape_list[NBSHAPES] =
{
22 23
    _( "line" ),   _( "invert" ),    _( "clock" ), _( "clock inv" ),
    _( "low in" ), _( "low clock" ), _( "low out" )
plyatov's avatar
plyatov committed
24 25
};

26
int             CodeShape[NBSHAPES] =
plyatov's avatar
plyatov committed
27
{
28
    NONE, INVERT, CLOCK, CLOCK | INVERT, LOWLEVEL_IN, LOWLEVEL_IN | CLOCK, LOWLEVEL_OUT
plyatov's avatar
plyatov committed
29 30 31 32
};


/* Routines locales */
33 34 35
static void CreateImagePins( LibDrawPin* Pin );
static void AbortPinMove( WinEDA_DrawPanel* Panel, wxDC* DC );
static void DrawMovePin( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
plyatov's avatar
plyatov committed
36 37 38 39 40

/* Variables importees */

/* Variables locales */
static wxPoint OldPos, PinPreviousPos;
41 42 43 44 45 46 47 48 49
static int     LastPinType = PIN_INPUT,
               LastPinOrient   = PIN_RIGHT,
               LastPinShape    = NONE,
               LastPinSize          = 300,
               LastPinNameSize      = 50,
               LastPinNumSize       = 50,
               LastPinCommonConvert = FALSE,
               LastPinCommonUnit    = FALSE,
               LastPinNoDraw        = FALSE;
plyatov's avatar
plyatov committed
50 51 52 53 54


#include "pinedit-dialog.cpp"

/*************************************************************************/
55
void WinEDA_PinPropertiesFrame::PinPropertiesAccept( wxCommandEvent& event )
plyatov's avatar
plyatov committed
56
/*************************************************************************/
57

58
/* Met a jour les differents parametres pour le composant en cours d'�dition
59
 */
plyatov's avatar
plyatov committed
60
{
61 62 63 64 65 66 67 68
    wxString msg;

    LastPinType   = m_PinElectricalType->GetSelection();
    LastPinShape  = CodeShape[m_PinShape->GetSelection()];
    LastPinOrient = CodeOrient[m_PinOrient->GetSelection()];
    LastPinCommonConvert = m_CommonConvert->GetValue();
    LastPinCommonUnit    = m_CommonUnit->GetValue();
    LastPinNoDraw = m_NoDraw->GetValue();
69 70 71 72

    msg = m_PinSizeCtrl->GetValue();
    LastPinSize   = ReturnValueFromString( g_UnitMetric, msg, m_Parent->m_InternalUnits );

73 74
    msg = m_PinNameSizeCtrl->GetValue();
    LastPinNameSize = ReturnValueFromString( g_UnitMetric, msg, m_Parent->m_InternalUnits );
75

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    msg = m_PinNumSizeCtrl->GetValue();
    LastPinNumSize = ReturnValueFromString( g_UnitMetric, msg, m_Parent->m_InternalUnits );

    if( CurrentDrawItem )                           // Set Pin Name & Num
    {
        if( !(CurrentDrawItem->m_Flags & IS_NEW) )  // if IS_NEW, copy for undo is done before place
            m_Parent->SaveCopyInUndoList( CurrentLibEntry );
        LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;
        wxClientDC dc( m_Parent->DrawPanel );

        m_Parent->DrawPanel->PrepareGraphicContext( &dc );
        if( m_Parent->DrawPanel->ManageCurseur )  // Pin is moving
            m_Parent->DrawPanel->ManageCurseur( m_Parent->DrawPanel, &dc, FALSE );
        else
            DrawLibraryDrawStruct( m_Parent->DrawPanel, &dc, CurrentLibEntry,
charras's avatar
charras committed
91
                wxPoint(0, 0), CurrentPin, g_XorMode );
92 93 94 95 96 97 98 99 100 101 102 103 104 105

        SetPinName( m_PinNameCtrl->GetValue(), LastPinNameSize );
        msg = m_PinNumCtrl->GetValue(); if( msg.IsEmpty() )
            msg = wxT( "~" );
        SetPinNum( msg, LastPinNumSize );
        NewSizePin( LastPinSize );
        SetPinShape( LastPinShape );
        SetPinType( LastPinType );
        SetPinOrient( LastPinOrient );
        SetAttributsPin( TRUE, TRUE, TRUE );
        if( m_Parent->DrawPanel->ManageCurseur )
            m_Parent->DrawPanel->ManageCurseur( m_Parent->DrawPanel, &dc, FALSE );
        else
            DrawLibraryDrawStruct( m_Parent->DrawPanel, &dc, CurrentLibEntry,
charras's avatar
charras committed
106
                wxPoint(0, 0), CurrentPin, g_XorMode );
107 108 109 110 111 112
    }

    if( CurrentDrawItem )
        CurrentDrawItem->Display_Infos_DrawEntry( m_Parent );

    Close();
plyatov's avatar
plyatov committed
113 114 115 116
}


/*********************************************/
117
void WinEDA_LibeditFrame::InitEditOnePin()
plyatov's avatar
plyatov committed
118
/*********************************************/
119

120 121 122 123 124 125
/* Called when installing the edit pin dialog frame
 * Set pins flags (.m_Flags pins member) to ensure a correctins edition:
 * If 2 or more pins are on the same location (and the same orientation) they are all moved or resized.
 * This is usefull for components which have more than one part per package
 * In this case all parts can be edited at once.
 * Note: if the option "Edit Pin per Pin" (tool of the main toolbar) is activated, only the current part is edited
126
 */
plyatov's avatar
plyatov committed
127
{
128 129 130 131 132 133 134 135 136 137
    LibDrawPin* Pin;
    LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;

    if( CurrentLibEntry == NULL )
        return;
    if( CurrentPin == NULL )
        return;

    /* Marquage des pins a traiter,Si edition d'une pin non deja selectionnee */
    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
138
    for( ; Pin != NULL; Pin = Pin->Next() )
139 140 141 142 143 144 145 146
    {
        if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
            continue;
        if( Pin == CurrentPin )
            continue;
        if( (Pin->m_Pos == CurrentPin->m_Pos)
           && (Pin->m_Orient == CurrentPin->m_Orient)
           && ( !(CurrentPin->m_Flags & IS_NEW) )
147 148
           && (g_EditPinByPinIsOn == FALSE)     // This is set by the tool of the main toolbar
            )
149 150 151 152 153 154
            Pin->m_Flags |= IS_LINKED | IN_EDIT;
        else
            Pin->m_Flags = 0;
    }

    CurrentPin->Display_Infos_DrawEntry( this );
plyatov's avatar
plyatov committed
155 156 157 158
}


/*************************************************************/
159
static void AbortPinMove( WinEDA_DrawPanel* Panel, wxDC* DC )
plyatov's avatar
plyatov committed
160
/*************************************************************/
161

plyatov's avatar
plyatov committed
162
/* Used to abort the move pin command.
163
 */
plyatov's avatar
plyatov committed
164
{
165
    LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;
plyatov's avatar
plyatov committed
166

167 168
    if( CurrentPin  && ( CurrentPin->m_Flags & IS_NEW ) )
        DeleteOneLibraryDrawStruct( Panel, DC, CurrentLibEntry, CurrentPin, TRUE );
plyatov's avatar
plyatov committed
169

170 171 172 173
    /* clear edit flags */
    LibEDA_BaseStruct* item = CurrentLibEntry->m_Drawings;
    for( ; item != NULL; item = item->Next() )
        item->m_Flags = 0;
plyatov's avatar
plyatov committed
174

175 176 177 178 179
    Panel->ManageCurseur = NULL;
    Panel->ForceCloseManageCurseur = NULL;
    CurrentDrawItem = NULL;
    LibItemToRepeat = NULL;
    Panel->Refresh( true );
plyatov's avatar
plyatov committed
180 181 182 183
}


/********************************************/
184
void WinEDA_LibeditFrame::PlacePin( wxDC* DC )
plyatov's avatar
plyatov committed
185 186 187
/********************************************/
/* Routine de fin de deplacement de la pin selectionnee */
{
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    LibDrawPin* Pin;
    LibDrawPin* CurrentPin  = (LibDrawPin*) CurrentDrawItem;
    bool        ask_for_pin = TRUE;
    wxPoint     newpos;
    bool        status;

    if( CurrentPin == NULL )
        return;

    newpos.x = GetScreen()->m_Curseur.x;
    newpos.y = -GetScreen()->m_Curseur.y;

    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;

    // Tst for an other pin in same new position:
203
    for( ; Pin != NULL; Pin = Pin->Next() )
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
    {
        if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
            continue;
        if( Pin == CurrentPin )
            continue;
        if( newpos != Pin->m_Pos )
            continue;
        if( Pin->m_Flags )
            continue;
        if( ask_for_pin )
        {
            DrawPanel->m_IgnoreMouseEvents = TRUE;
            status = IsOK( this, _( "Occupied by other pin. Continue?" ) );
            DrawPanel->MouseToCursorSchema();
            DrawPanel->m_IgnoreMouseEvents = FALSE;
            if( !status )
                return;
            else
                ask_for_pin = FALSE;
        }
    }

    DrawPanel->ManageCurseur = NULL;
    DrawPanel->ForceCloseManageCurseur = NULL;
    GetScreen()->SetModify();

    CurrentPin->m_Pos = newpos;
    if( CurrentPin->m_Flags & IS_NEW )
    {
        LastPinOrient = CurrentPin->m_Orient;
        LastPinType   = CurrentPin->m_PinType;
        LastPinShape  = CurrentPin->m_PinShape;
        CreateImagePins( CurrentPin );
        LibItemToRepeat = CurrentPin;
    }

    /* Put linked pins in new position, and clear flags */
    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
242
    for( ; Pin != NULL; Pin = Pin->Next() )
243 244 245 246 247 248 249 250 251 252
    {
        if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
            continue;
        if( Pin->m_Flags == 0 )
            continue;
        Pin->m_Pos   = CurrentPin->m_Pos;
        Pin->m_Flags = 0;
    }

    DrawPanel->CursorOff( DC );
charras's avatar
charras committed
253
    DrawLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry, wxPoint(0, 0), CurrentPin,
254 255 256 257
        GR_DEFAULT_DRAWMODE );
    DrawPanel->CursorOn( DC );

    CurrentDrawItem = NULL;
plyatov's avatar
plyatov committed
258 259 260
};

/***********************************************************/
261
void WinEDA_PinPropertiesFrame::SetPinOrient( int neworient )
plyatov's avatar
plyatov committed
262 263 264
/***********************************************************/
/* Routine de Rotation de la pin courante*/
{
265 266 267 268 269 270 271 272 273 274 275 276 277 278
    LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;
    LibDrawPin* Pin, * RefPin = CurrentPin;

    if( CurrentLibEntry == NULL )
        return;
    if( RefPin == NULL )
        return;

    m_Parent->GetScreen()->SetModify();

    /* Rotation */
    RefPin->m_Orient = neworient;

    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
279
    for( ; Pin != NULL; Pin = Pin->Next() )
280 281 282 283 284 285 286
    {
        if( Pin->m_Flags == 0 )
            continue;
        Pin->m_Orient = RefPin->m_Orient;
        if( CurrentPin == NULL )
            Pin->m_Flags = 0;
    }
plyatov's avatar
plyatov committed
287 288 289 290
}


/*************************************************/
291
void WinEDA_LibeditFrame::StartMovePin( wxDC* DC )
plyatov's avatar
plyatov committed
292
/*************************************************/
293

plyatov's avatar
plyatov committed
294
/* Prepare le deplacement d'une pin :
295 296 297
  * Localise la pin pointee par le curseur, et si elle existe active
  * la fonction de gestion curseur ( DrawMovePin() ).
 */
plyatov's avatar
plyatov committed
298
{
299 300 301 302 303 304
    LibDrawPin* Pin;
    LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;
    wxPoint     startPos;

    /* Marquage des pins a traiter */
    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
305
    for( ; Pin != NULL; Pin = Pin->Next() )
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    {
        Pin->m_Flags = 0;
        if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
            continue;
        if( Pin == CurrentPin )
            continue;
        if( (Pin->m_Pos == CurrentPin->m_Pos) && (Pin->m_Orient == CurrentPin->m_Orient)
           && (g_EditPinByPinIsOn == FALSE ) )
            Pin->m_Flags |= IS_LINKED | IS_MOVED;
    }

    CurrentPin->m_Flags |= IS_LINKED | IS_MOVED;
    PinPreviousPos = OldPos = CurrentPin->m_Pos;

    startPos.x = OldPos.x;
    startPos.y = -OldPos.y;
    DrawPanel->CursorOff( DC );
    GetScreen()->m_Curseur = startPos;
    DrawPanel->MouseToCursorSchema();

    CurrentPin->Display_Infos_DrawEntry( this );
    DrawPanel->ManageCurseur = DrawMovePin;
    DrawPanel->ForceCloseManageCurseur = AbortPinMove;

    DrawPanel->CursorOn( DC );
plyatov's avatar
plyatov committed
331 332 333 334 335 336 337
}


/******************************************************************************/
/* Routine de deplacement de la Pin courante selon position du curseur souris */
/* Routine normalement appelee par la routine de gestion du curseur			 */
/******************************************************************************/
338
static void DrawMovePin( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
plyatov's avatar
plyatov committed
339
{
340 341 342 343 344 345 346
    LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;
    wxPoint     pinpos = CurrentPin->m_Pos;

    /* Erase pin in old position */
    if( erase || (CurrentPin->m_Flags & IS_NEW) )
    {
        CurrentPin->m_Pos = PinPreviousPos;
charras's avatar
charras committed
347 348
        DrawLibraryDrawStruct( panel, DC, CurrentLibEntry, wxPoint(0, 0),
            CurrentPin, g_XorMode );
349 350 351 352 353
    }

    /* Redraw pin in new position */
    CurrentPin->m_Pos.x = panel->GetScreen()->m_Curseur.x;
    CurrentPin->m_Pos.y = -panel->GetScreen()->m_Curseur.y;
charras's avatar
charras committed
354
    DrawLibraryDrawStruct( panel, DC, CurrentLibEntry, wxPoint(0, 0), CurrentPin, g_XorMode );
355 356 357 358 359 360 361

    PinPreviousPos = CurrentPin->m_Pos;

    /* Keep the original position for existing pin (for Undo command)
      * and the current position for a new pin */
    if( (CurrentPin->m_Flags & IS_NEW) == 0 )
        CurrentPin->m_Pos = pinpos;
plyatov's avatar
plyatov committed
362 363 364 365
}


/**********************************************************/
366
void WinEDA_PinPropertiesFrame::SetPinShape( int newshape )
plyatov's avatar
plyatov committed
367
/**********************************************************/
368

plyatov's avatar
plyatov committed
369
/* Changement de la forme de la pin courante.
370 371 372
  * Le changement est egalement fait sur les autres pins correspondantes
  * des autres unites de la seule forme convert courante
 */
plyatov's avatar
plyatov committed
373
{
374 375 376 377 378 379 380 381 382 383
    LibDrawPin* Pin;
    LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;

    if( CurrentPin )
    {
        CurrentPin->m_PinShape = newshape;
        m_Parent->GetScreen()->SetModify();
        CurrentPin->Display_Infos_DrawEntry( m_Parent );

        Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
384
        for( ; Pin != NULL; Pin = Pin->Next() )
385 386 387 388 389 390 391 392 393 394
        {
            if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
                continue;
            if( Pin->m_Flags == 0 )
                continue;
            if( Pin->m_Convert != CurrentPin->m_Convert )
                continue;
            Pin->m_PinShape = newshape;
        }
    }
plyatov's avatar
plyatov committed
395 396 397 398
}


/******************************************************/
399
void WinEDA_PinPropertiesFrame::SetPinType( int newtype )
plyatov's avatar
plyatov committed
400
/******************************************************/
401

plyatov's avatar
plyatov committed
402
/* Changement du type electrique de la pin courante.
403 404 405
  * Le changement est egalement fait sur les autres pins correspondantes
  * des autres unites du boitier
 */
plyatov's avatar
plyatov committed
406
{
407 408 409 410 411 412 413 414 415 416
    LibDrawPin* Pin;
    LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;

    if( CurrentPin == NULL )
        return;

    CurrentPin->m_PinType = newtype;
    m_Parent->GetScreen()->SetModify();

    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
417
    for( ; Pin != NULL; Pin = Pin->Next() )
418 419 420 421 422 423 424
    {
        if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
            continue;
        if( Pin->m_Flags == 0 )
            continue;
        Pin->m_PinType = newtype;
    }
plyatov's avatar
plyatov committed
425 426
}

427

plyatov's avatar
plyatov committed
428
/********************************************************************************/
429
void WinEDA_PinPropertiesFrame::SetPinName( const wxString& newname, int newsize )
plyatov's avatar
plyatov committed
430
/********************************************************************************/
431

plyatov's avatar
plyatov committed
432
/* Met a jour le nom et la taille de ce nom de la pin courante
433 434 435
  * si newname == NULL, pas de changement de nom
  * si newsize < 0 : pas de changement de taille
 */
plyatov's avatar
plyatov committed
436
{
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
    LibDrawPin* Pin;
    LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;
    wxString    buf;

    buf = newname;
    buf.Replace( wxT( " " ), wxT( "_" ) );

    if( newsize >= 0 )
        CurrentPin->m_PinNameSize = newsize;

    CurrentPin->m_PinName = buf;

    m_Parent->GetScreen()->SetModify();

    /* Traitement des autres pins */
    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
453
    for( ; Pin != NULL; Pin = Pin->Next() )
454 455 456 457 458 459 460 461 462
    {
        if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
            continue;
        if( (Pin->m_Flags & IS_LINKED) == 0 )
            continue;
        if( newsize >= 0 )
            Pin->m_PinNameSize = newsize;
        Pin->m_PinName = buf;
    }
plyatov's avatar
plyatov committed
463 464
}

465

plyatov's avatar
plyatov committed
466
/******************************************************************************/
467
void WinEDA_PinPropertiesFrame::SetPinNum( const wxString& newnum, int newsize )
plyatov's avatar
plyatov committed
468
/******************************************************************************/
469

plyatov's avatar
plyatov committed
470
/* Changement du numero de la pin courante.
471 472 473 474 475
  * Le changement est egalement fait sur les autres pins correspondantes
  * a la forme convertie
  * Si newnum == NULL: pas de changement de numero
  * Si newsize < 0 ) pase de changement de taille
 */
plyatov's avatar
plyatov committed
476
{
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
    LibDrawPin* Pin;
    LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;
    wxString    buf;

    buf = newnum;
    buf.Replace( wxT( " " ), wxT( "_" ) );

    if( CurrentPin == NULL )
        return;

    CurrentPin->m_PinNum = 0;

    if( newsize >= 0 )
        CurrentPin->m_PinNumSize = newsize;
    CurrentPin->SetPinNumFromString( buf );
    m_Parent->GetScreen()->SetModify();

    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
495
    for( ; Pin != NULL; Pin = Pin->Next() )
496 497 498 499 500 501 502 503 504 505 506 507
    {
        if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
            continue;
        if( (Pin->m_Flags & IS_LINKED) == 0 )
            continue;
        if( Pin->m_Unit != CurrentPin->m_Unit )
            continue;
        if( newsize >= 0 )
            Pin->m_PinNumSize = newsize;
        if( newnum )
            Pin->m_PinNum = CurrentPin->m_PinNum;
    }
plyatov's avatar
plyatov committed
508 509 510 511
}


/*************************************************/
512 513 514
void WinEDA_LibeditFrame::DeletePin( wxDC*                   DC,
                                     EDA_LibComponentStruct* LibEntry,
                                     LibDrawPin*             Pin )
plyatov's avatar
plyatov committed
515
/*************************************************/
516

plyatov's avatar
plyatov committed
517
/* Routine d'effacement de la pin pointee par la souris
518 519 520 521
  * Si g_EditPinByPinIsOn == FALSE :
  *     toutes les pins de meme coordonnee seront effacees.
  * Sinon seule la pin de l'unite en convert courante sera effacee
 */
plyatov's avatar
plyatov committed
522
{
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
    LibEDA_BaseStruct* DrawItem;
    wxPoint            PinPos;

    if( LibEntry == NULL )
        return;
    if( Pin == NULL )
        return;

    PinPos = Pin->m_Pos;
    DeleteOneLibraryDrawStruct( DrawPanel, DC, LibEntry, Pin, TRUE );

    /* Effacement des autres pins de meme coordonnees */
    if( g_EditPinByPinIsOn == FALSE )
    {
        DrawItem = LibEntry->m_Drawings;
        for( ; DrawItem != NULL; )
        {
            if( DrawItem->Type() != COMPONENT_PIN_DRAW_TYPE )
            {
542 543
                DrawItem = DrawItem->Next();
                continue;
544 545 546 547 548 549 550 551 552
            }
            Pin      = (LibDrawPin*) DrawItem;
            DrawItem = DrawItem->Next();
            if( Pin->m_Pos != PinPos )
                continue;
            DeleteOneLibraryDrawStruct( DrawPanel, DC, LibEntry, Pin, 0 );
        }
    }
    GetScreen()->SetModify();
plyatov's avatar
plyatov committed
553 554 555 556
}


/*********************************************/
557
void WinEDA_LibeditFrame::CreatePin( wxDC* DC )
plyatov's avatar
plyatov committed
558 559 560
/*********************************************/
/* Creation d'une nouvelle pin */
{
561
    LibEDA_BaseStruct* DrawItem;
charras's avatar
charras committed
562
    LibDrawPin*        CurrentPin;
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605

    if( CurrentLibEntry == NULL )
        return;

    /* Effacement des flags */
    DrawItem = CurrentLibEntry->m_Drawings;
    for( ; DrawItem != NULL; DrawItem = DrawItem->Next() )
        DrawItem->m_Flags = 0;

    CurrentPin = new LibDrawPin();

    CurrentDrawItem = CurrentPin;
    if( CurrentPin == NULL )
        return;
    CurrentPin->m_Flags   = IS_NEW;
    CurrentPin->m_Unit    = CurrentUnit;
    CurrentPin->m_Convert = CurrentConvert;

    /* Marquage des pins a traiter */
    if( g_EditPinByPinIsOn == FALSE )
        CurrentPin->m_Flags |= IS_LINKED;

    CurrentPin->m_Pos.x       = GetScreen()->m_Curseur.x;
    CurrentPin->m_Pos.y       = -GetScreen()->m_Curseur.y;
    CurrentPin->m_PinLen      = LastPinSize;
    CurrentPin->m_Orient      = LastPinOrient;
    CurrentPin->m_PinType     = LastPinType;
    CurrentPin->m_PinShape    = LastPinShape;
    CurrentPin->m_PinNameSize = LastPinNameSize;
    CurrentPin->m_PinNumSize  = LastPinNumSize;
    if( LastPinCommonConvert )
        CurrentPin->m_Convert = 0;
    else
        CurrentPin->m_Convert = CurrentConvert;
    if( LastPinCommonUnit )
        CurrentPin->m_Unit = 0;
    else
        CurrentPin->m_Unit = CurrentUnit;
    if( LastPinNoDraw )
        CurrentPin->m_Attributs |= PINNOTDRAW;
    else
        CurrentPin->m_Attributs &= ~PINNOTDRAW;

606
    CurrentPin->SetNext( CurrentLibEntry->m_Drawings );
607 608 609 610 611
    CurrentLibEntry->m_Drawings = CurrentPin;
    CurrentLibEntry->SortDrawItems();

    if( DC )
        DrawLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry,
charras's avatar
charras committed
612
            wxPoint(0, 0), CurrentPin, g_XorMode );
613 614 615 616 617 618 619 620 621 622 623 624 625

    DrawPanel->m_IgnoreMouseEvents = TRUE;
    InstallPineditFrame( this, DC, wxPoint( -1, -1 ) );
    DrawPanel->MouseToCursorSchema();
    DrawPanel->m_IgnoreMouseEvents = FALSE;

    PinPreviousPos = CurrentPin->m_Pos;

    DrawPanel->ManageCurseur = DrawMovePin;
    DrawPanel->ForceCloseManageCurseur = AbortPinMove;

    CurrentPin->Display_Infos_DrawEntry( this );
    GetScreen()->SetModify();
plyatov's avatar
plyatov committed
626 627 628 629
}


/*********************************************************/
630 631
void WinEDA_PinPropertiesFrame::SetAttributsPin( bool draw,
                                                 bool unit, bool convert )
plyatov's avatar
plyatov committed
632 633
/*********************************************************/

634 635 636 637 638 639 640 641 642 643 644 645 646
/*  si draw == TRUE
  * - Ajuste le flag visible / invisible (.U.Pin.Flags bit 0 ) de la pin
  * editee
 *
  * si unit == TRUE
  * - Modifie l'attribut Commun / Particulier U.Pin.Unit = 0 ou Num Unite
  * de la pin editee
 *
  * si convert == TRUE
  * - Modifie l'attribut Commun / Particulier U.Pin.Convert = 0 ou Num Unite
  * de la pin editee
 *
 */
plyatov's avatar
plyatov committed
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 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 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
    LibEDA_BaseStruct* DrawItem;
    LibDrawPin*        Pin, * CurrentPin = (LibDrawPin*) CurrentDrawItem;

    if( CurrentPin == NULL )
        return;

    m_Parent->GetScreen()->SetModify();

    if( unit  )
    {
        if( LastPinCommonUnit )
            CurrentPin->m_Unit = 0;
        else
            CurrentPin->m_Unit = CurrentUnit;

        Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;

        if( CurrentPin->m_Unit == 0 )
        {
            DrawItem = CurrentLibEntry->m_Drawings;
            for( ; DrawItem != NULL; )
            {
                Pin      = (LibDrawPin*) DrawItem;
                DrawItem = DrawItem->Next();
                if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
                    continue;
                if( Pin->m_Flags == 0 )
                    continue;
                if( Pin == CurrentPin )
                    continue;
                if( CurrentPin->m_Convert && (CurrentPin->m_Convert != Pin->m_Convert) )
                    continue;
                if( CurrentPin->m_Pos != Pin->m_Pos )
                    continue;
                if( Pin->m_Orient != CurrentPin->m_Orient )
                    continue;
                DeleteOneLibraryDrawStruct( m_Parent->DrawPanel, NULL,
                    CurrentLibEntry, Pin, 0 );
            }
        }
    }   // end if unit

    if( convert )
    {
        if( LastPinCommonConvert )
            CurrentPin->m_Convert = 0;
        else
            CurrentPin->m_Convert = CurrentConvert;

        if( CurrentPin->m_Convert == 0 )    /* Effacement des pins redondantes */
        {
            DrawItem = CurrentLibEntry->m_Drawings;
            for( ; DrawItem != NULL; )
            {
                Pin = (LibDrawPin*) DrawItem; DrawItem = DrawItem->Next();
                if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
                    continue;
                if( Pin->m_Flags == 0 )
                    continue;
                if( Pin == CurrentPin )
                    continue;
                if( CurrentPin->m_Unit && (CurrentPin->m_Unit != Pin->m_Unit) )
                    continue;
                if( CurrentPin->m_Pos != Pin->m_Pos )
                    continue;
                if( Pin->m_Orient != CurrentPin->m_Orient )
                    continue;
                DeleteOneLibraryDrawStruct( m_Parent->DrawPanel, NULL,
                    CurrentLibEntry, Pin, 0 );
            }
        }
    }       // end if convert

    if( draw )
    {
        if( LastPinNoDraw )
            CurrentPin->m_Attributs |= PINNOTDRAW;
        else
            CurrentPin->m_Attributs &= ~PINNOTDRAW;

        Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
729
        for( ; Pin != NULL; Pin = Pin->Next() )
730 731 732 733 734 735 736 737
        {
            if( Pin->m_Flags == 0 )
                continue;
            Pin->m_Attributs &= ~PINNOTDRAW;
            if( CurrentPin->m_Attributs & PINNOTDRAW )
                Pin->m_Attributs |= PINNOTDRAW;
        }
    }
plyatov's avatar
plyatov committed
738 739 740 741
}


/******************************************************/
742
void WinEDA_PinPropertiesFrame::NewSizePin( int newsize )
plyatov's avatar
plyatov committed
743 744
/******************************************************/

745 746 747 748 749
/* Fonction permettant la mise aux dimensions courantes:
  * - longueur, dimension des textes
  * de la pin courante
 *
 */
plyatov's avatar
plyatov committed
750
{
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
    LibDrawPin* RefPin, * Pin = (LibDrawPin*) CurrentDrawItem;

    if( CurrentLibEntry == NULL )
        return;
    if( Pin == NULL )
        return;

    m_Parent->GetScreen()->SetModify();

    Pin->m_PinLen = newsize;

    Pin->Display_Infos_DrawEntry( m_Parent );

    RefPin = Pin;

    if( g_EditPinByPinIsOn == FALSE )
    {
        Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
769
        for( ; Pin != NULL; Pin = Pin->Next() )
770 771 772 773 774 775 776 777 778 779 780
        {
            if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
                continue;
            if( Pin->m_Pos != RefPin->m_Pos )
                continue;
            if( Pin->m_Orient != RefPin->m_Orient )
                continue;
            if( Pin->m_Convert == RefPin->m_Convert )
                Pin->m_PinLen = newsize;
        }
    }
plyatov's avatar
plyatov committed
781 782
}

783

plyatov's avatar
plyatov committed
784
/********************************************/
785
static void CreateImagePins( LibDrawPin* Pin )
plyatov's avatar
plyatov committed
786
/********************************************/
787

plyatov's avatar
plyatov committed
788
/* Creation des autres pins pour les autres unites et pour convert, apres
789 790
  * creation d'une pin
 */
plyatov's avatar
plyatov committed
791
{
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
    int         ii, CreateConv = FALSE;
    LibDrawPin* NewPin;

    if( g_EditPinByPinIsOn )
        return;

    if( g_AsDeMorgan && (Pin->m_Convert != 0 ) )
        CreateConv = TRUE;

    /* Creation de la pin " convert " pour la part courante */
    if( CreateConv == TRUE )
    {
        NewPin = Pin->GenCopy();
        if( Pin->m_Convert > 1 )
            NewPin->m_Convert = 1;
        else
            NewPin->m_Convert = 2;
809
        NewPin->SetNext( CurrentLibEntry->m_Drawings );
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
        CurrentLibEntry->m_Drawings = NewPin;
    }

    for( ii = 1; ii <= CurrentLibEntry->m_UnitCount; ii++ )
    {
        if( ii == CurrentUnit )
            continue;                       /* Deja fait */
        if( Pin->m_Unit == 0 )
            continue;                       /* Pin commune a toutes les unites */

        /* Creation pour la representation "normale" */
        NewPin = Pin->GenCopy();
        if( CurrentConvert != 0 )
            NewPin->m_Convert = 1;
        NewPin->m_Unit = ii;
825
        NewPin->SetNext( CurrentLibEntry->m_Drawings );
826 827 828 829 830 831 832 833 834 835
        CurrentLibEntry->m_Drawings = NewPin;

        /* Creation pour la representation "Convert" */
        if( CreateConv == FALSE )
            continue;

        NewPin = Pin->GenCopy();
        NewPin->m_Convert = 2;
        if( Pin->m_Unit != 0 )
            NewPin->m_Unit = ii;
836
        NewPin->SetNext( CurrentLibEntry->m_Drawings );
837 838
        CurrentLibEntry->m_Drawings = NewPin;
    }
plyatov's avatar
plyatov committed
839 840 841 842
}


/*************************************************/
843 844
void WinEDA_LibeditFrame::GlobalSetPins( wxDC* DC,
                                         LibDrawPin* MasterPin, int id )
plyatov's avatar
plyatov committed
845 846
/*************************************************/

847 848 849 850 851 852
/*  Depending on "id":
  * - Change pin text size (name or num) (range 10 .. 1000 mil)
  * - Change pin lenght.
 *
  * If Pin is selected ( .m_flag == IS_SELECTED ) only the other selected pis are modified
 */
plyatov's avatar
plyatov committed
853
{
854 855 856 857 858 859 860 861 862 863 864
    LibDrawPin* Pin;
    bool        selected = (MasterPin->m_Selected & IS_SELECTED) != 0;

    if( (CurrentLibEntry == NULL) || (MasterPin == NULL) )
        return;
    if( MasterPin->Type() != COMPONENT_PIN_DRAW_TYPE )
        return;

    GetScreen()->SetModify();

    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
865
    for( ; Pin != NULL; Pin = Pin->Next() )
866 867 868 869 870 871 872 873 874 875
    {
        if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
            continue;
        if( (Pin->m_Convert) && (Pin->m_Convert != CurrentConvert) )
            continue;

        // Is it the "selected mode" ?
        if( selected && (Pin->m_Selected & IS_SELECTED) == 0 )
            continue;

charras's avatar
charras committed
876
        DrawLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry, wxPoint(0, 0), Pin, g_XorMode );
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892

        switch( id )
        {
        case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM:
            Pin->m_PinNumSize = MasterPin->m_PinNumSize;
            break;

        case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM:
            Pin->m_PinNameSize = MasterPin->m_PinNameSize;
            break;

        case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM:
            Pin->m_PinLen = MasterPin->m_PinLen;
            break;
        }

charras's avatar
charras committed
893
        DrawLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry, wxPoint(0, 0), Pin, GR_DEFAULT_DRAWMODE );
894
    }
plyatov's avatar
plyatov committed
895 896 897 898
}


/************************************************************************/
899
void WinEDA_LibeditFrame::RepeatPinItem( wxDC* DC, LibDrawPin* SourcePin )
plyatov's avatar
plyatov committed
900
/************************************************************************/
901
/* Creation d'une nouvelle pin par copie de la pr�c�dente ( fct REPEAT) */
plyatov's avatar
plyatov committed
902
{
903 904 905 906 907 908 909 910 911 912 913 914
    LibDrawPin* Pin;
    wxString    msg;
    int         ox = 0, oy = 0;

    if( CurrentLibEntry == NULL )
        return;
    if( SourcePin == NULL )
        return;
    if( SourcePin->Type() != COMPONENT_PIN_DRAW_TYPE )
        return;

    Pin = SourcePin->GenCopy();
915
    Pin->SetNext( CurrentLibEntry->m_Drawings );
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
    CurrentLibEntry->m_Drawings = Pin;
    Pin->m_Flags = IS_NEW;

    Pin->m_Pos.x += g_RepeatStep.x; ox = Pin->m_Pos.x;
    Pin->m_Pos.y += -g_RepeatStep.y; oy = Pin->m_Pos.y; // ici axe Y comme en math
    /*** Increment du numero de label ***/
    IncrementLabelMember( Pin->m_PinName );

    Pin->ReturnPinStringNum( msg );
    IncrementLabelMember( msg );
    Pin->SetPinNumFromString( msg );

    CurrentDrawItem = Pin;

    /* Marquage des pins a traiter */
    if( g_EditPinByPinIsOn == FALSE )
        Pin->m_Flags |= IS_LINKED;

    wxPoint savepos = GetScreen()->m_Curseur;
    DrawPanel->CursorOff( DC );
    GetScreen()->m_Curseur.x = Pin->m_Pos.x;
    GetScreen()->m_Curseur.y = -Pin->m_Pos.y;
    PlacePin( DC );
    GetScreen()->m_Curseur = savepos;

plyatov's avatar
plyatov committed
941
//	DrawPanel->MouseToCursorSchema();
942
    DrawPanel->CursorOn( DC );
plyatov's avatar
plyatov committed
943

944 945
    Pin->Display_Infos_DrawEntry( this );
    GetScreen()->SetModify();
plyatov's avatar
plyatov committed
946 947
}

948 949

int sort_by_pin_number( const void* ref, const void* tst )
plyatov's avatar
plyatov committed
950
{
951 952 953 954
    const LibDrawPin* Ref = *(LibDrawPin**) ref;
    const LibDrawPin* Tst = *(LibDrawPin**) tst;

    return Ref->m_PinNum - Tst->m_PinNum;
plyatov's avatar
plyatov committed
955
}
956 957


plyatov's avatar
plyatov committed
958
/***************************************************************/
959
bool WinEDA_LibeditFrame::TestPins( EDA_LibComponentStruct* LibEntry )
plyatov's avatar
plyatov committed
960
/***************************************************************/
961

plyatov's avatar
plyatov committed
962 963
// Test des pins ( duplicates...)
{
964 965 966 967
    int             nb_pins, ii, error;
    LibDrawPin*     Pin;
    LibDrawPin**    PinList;
    wxString        msg;
968 969 970 971 972 973

    if( CurrentLibEntry == NULL )
        return FALSE;

    // Construction de la liste des pins:
    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
974
    for( nb_pins = 0; Pin != NULL; Pin = Pin->Next() )
975 976 977 978 979 980 981
    {
        if( Pin->Type() == COMPONENT_PIN_DRAW_TYPE )
            nb_pins++;
    }

    PinList = (LibDrawPin**) MyZMalloc( (nb_pins + 1) * sizeof(LibDrawPin*) );
    Pin = (LibDrawPin*) CurrentLibEntry->m_Drawings;
982
    for( ii = 0; Pin != NULL; Pin = Pin->Next() )
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
    {
        if( Pin->Type() == COMPONENT_PIN_DRAW_TYPE )
            PinList[ii++] = Pin;
    }

    // Classement des pins par numero de pin
    qsort( PinList, nb_pins, sizeof(LibDrawPin*), sort_by_pin_number );

    // Controle des duplicates:
    error = 0;
    for( ii = 1; ii < nb_pins; ii++ )
    {
        wxString    aux_msg, StringPinNum;
        LibDrawPin* curr_pin = PinList[ii];
        Pin = PinList[ii - 1];
998

999 1000
        if( Pin->m_PinNum != curr_pin->m_PinNum )
            continue;
1001

1002 1003
        if( Pin->m_Convert != curr_pin->m_Convert )
            continue;
1004

1005 1006
        if( Pin->m_Unit != curr_pin->m_Unit )
            continue;
1007

1008 1009 1010 1011 1012 1013
        error++;
        curr_pin->ReturnPinStringNum( StringPinNum );
        msg.Printf( _( "Duplicate Pin %4.4s (Pin %s loc %d, %d, and Pin %s loc %d, %d)" ),
            StringPinNum.GetData(),
            curr_pin->m_PinName.GetData(), curr_pin->m_Pos.x, -curr_pin->m_Pos.y,
            Pin->m_PinName.GetData(), Pin->m_Pos.x, -Pin->m_Pos.y );
1014

1015 1016 1017 1018 1019
        if( CurrentLibEntry->m_UnitCount > 1 )
        {
            aux_msg.Printf( _( "  Part %d" ), curr_pin->m_Unit );
            msg += aux_msg;
        }
1020

1021 1022 1023 1024 1025 1026 1027
        if( g_AsDeMorgan )
        {
            if( curr_pin->m_Convert )
                msg += _( "  Convert" );
            else
                msg += _( "  Normal" );
        }
1028

1029 1030 1031 1032 1033
        DisplayError( this, msg );
    }

    free( PinList );
    return error ? TRUE : FALSE;
plyatov's avatar
plyatov committed
1034
}