kicad/pcbnew/editmod.cpp

168 lines
4.3 KiB
C++
Raw Normal View History

/************************************************/
/* Module editor: Dialog box for editing module */
/* properties and characteristics */
/************************************************/
#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <module_editor_frame.h>
#include <trigo.h>
#include <3d_viewer.h>
#include <class_module.h>
#include <class_pad.h>
#include <class_edge_mod.h>
#include <dialog_edit_module_for_BoardEditor.h>
/*
* Show module property dialog.
*/
void PCB_EDIT_FRAME::InstallModuleOptionsFrame( MODULE* Module, wxDC* DC )
{
2009-08-11 10:27:21 +00:00
if( Module == NULL )
return;
#ifndef __WXMAC__
DIALOG_MODULE_BOARD_EDITOR* dialog = new DIALOG_MODULE_BOARD_EDITOR( this, Module, DC );
#else
// avoid Avoid "writes" in the dialog, creates errors with WxOverlay and NSView & Modal
// Raising an Exception - Fixes #764678
DIALOG_MODULE_BOARD_EDITOR* dialog = new DIALOG_MODULE_BOARD_EDITOR( this, Module, NULL );
#endif
2009-08-11 10:27:21 +00:00
int retvalue = dialog->ShowModal(); /* retvalue =
* -1 if abort,
* 0 if exchange module,
* 1 for normal edition
* and 2 for a goto editor command
*/
dialog->Destroy();
#ifdef __WXMAC__
// If something edited, push a refresh request
if (retvalue == 0 || retvalue == 1)
m_canvas->Refresh();
#endif
2009-08-11 10:27:21 +00:00
if( retvalue == 2 )
{
FOOTPRINT_EDIT_FRAME * editorFrame =
FOOTPRINT_EDIT_FRAME::GetActiveFootprintEditor();
if( editorFrame == NULL )
editorFrame = new FOOTPRINT_EDIT_FRAME( this );
editorFrame->Load_Module_From_BOARD( Module );
SetCurItem( NULL );
editorFrame->Show( true );
editorFrame->Iconize( false );
}
}
/*
* Move the footprint anchor position to the current cursor position.
*/
2012-02-19 04:02:19 +00:00
void FOOTPRINT_EDIT_FRAME::Place_Ancre( MODULE* aModule )
{
wxPoint moveVector;
2012-02-19 04:02:19 +00:00
if( aModule == NULL )
return;
2012-02-19 04:02:19 +00:00
moveVector = aModule->m_Pos - GetScreen()->GetCrossHairPosition();
2012-02-19 04:02:19 +00:00
aModule->m_Pos = GetScreen()->GetCrossHairPosition();
/* Update the relative coordinates:
* The coordinates are relative to the anchor point.
* Calculate deltaX and deltaY from the anchor. */
2012-02-19 04:02:19 +00:00
RotatePoint( &moveVector, -aModule->m_Orient );
2012-02-19 04:02:19 +00:00
// Update the pad coordinates.
for( D_PAD* pad = (D_PAD*) aModule->m_Pads; pad; pad = pad->Next() )
{
2012-02-19 04:02:19 +00:00
pad->SetPos0( pad->GetPos0() + moveVector );
}
2012-02-19 04:02:19 +00:00
// Update the draw element coordinates.
for( EDA_ITEM* item = aModule->m_Drawings; item; item = item->Next() )
{
switch( item->Type() )
{
case PCB_MODULE_EDGE_T:
#undef STRUCT
#define STRUCT ( (EDGE_MODULE*) item )
2009-08-11 10:27:21 +00:00
STRUCT->m_Start0 += moveVector;
STRUCT->m_End0 += moveVector;
break;
case PCB_MODULE_TEXT_T:
#undef STRUCT
#define STRUCT ( (TEXTE_MODULE*) item )
2011-12-12 08:37:05 +00:00
STRUCT->SetPos0( STRUCT->GetPos0() + moveVector );
break;
default:
break;
}
}
2012-02-19 04:02:19 +00:00
aModule->CalculateBoundingBox();
}
void FOOTPRINT_EDIT_FRAME::RemoveStruct( EDA_ITEM* Item )
{
if( Item == NULL )
return;
2007-09-01 12:00:30 +00:00
switch( Item->Type() )
{
case PCB_PAD_T:
DeletePad( (D_PAD*) Item, false );
break;
case PCB_MODULE_TEXT_T:
{
TEXTE_MODULE* text = (TEXTE_MODULE*) Item;
2011-12-12 08:37:05 +00:00
if( text->GetType() == TEXT_is_REFERENCE )
{
DisplayError( this, _( "Text is REFERENCE!" ) );
break;
}
2011-12-12 08:37:05 +00:00
if( text->GetType() == TEXT_is_VALUE )
{
DisplayError( this, _( "Text is VALUE!" ) );
break;
}
DeleteTextModule( text );
}
2009-08-11 10:27:21 +00:00
break;
case PCB_MODULE_EDGE_T:
Delete_Edge_Module( (EDGE_MODULE*) Item );
m_canvas->Refresh();
break;
case PCB_MODULE_T:
break;
default:
{
wxString Line;
Line.Printf( wxT( " Remove: draw item type %d unknown." ), Item->Type() );
DisplayError( this, Line );
}
2009-08-11 10:27:21 +00:00
break;
}
}