Commit 45c5a3de authored by Maciej Suminski's avatar Maciej Suminski

Placing modules with a minor bug.

parent ba1867fe
...@@ -569,24 +569,7 @@ void PCB_EDIT_FRAME::ViewReloadBoard( const BOARD* aBoard ) const ...@@ -569,24 +569,7 @@ void PCB_EDIT_FRAME::ViewReloadBoard( const BOARD* aBoard ) const
// Load modules and its additional elements // Load modules and its additional elements
for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) for( MODULE* module = aBoard->m_Modules; module; module = module->Next() )
{ {
// Load module's pads module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) );
for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
{
view->Add( pad );
}
// Load module's drawing (mostly silkscreen)
for( BOARD_ITEM* drawing = module->GraphicalItems().GetFirst(); drawing;
drawing = drawing->Next() )
{
view->Add( drawing );
}
// Load module's texts (name and value)
view->Add( &module->Reference() );
view->Add( &module->Value() );
// Add the module itself
view->Add( module ); view->Add( module );
} }
......
...@@ -80,3 +80,7 @@ TOOL_ACTION COMMON_ACTIONS::drawDimension( "pcbnew.InteractiveDrawing.dimension" ...@@ -80,3 +80,7 @@ TOOL_ACTION COMMON_ACTIONS::drawDimension( "pcbnew.InteractiveDrawing.dimension"
TOOL_ACTION COMMON_ACTIONS::placeTarget( "pcbnew.InteractiveDrawing.placeTarget", TOOL_ACTION COMMON_ACTIONS::placeTarget( "pcbnew.InteractiveDrawing.placeTarget",
AS_GLOBAL, 'C', AS_GLOBAL, 'C',
"Add layer alignment target", "Add layer alignment target" ); "Add layer alignment target", "Add layer alignment target" );
TOOL_ACTION COMMON_ACTIONS::placeModule( "pcbnew.InteractiveDrawing.placeModule",
AS_GLOBAL, 'V',
"Add modules", "Add modules" );
...@@ -74,4 +74,7 @@ public: ...@@ -74,4 +74,7 @@ public:
/// Activation of the drawing tool (placing a TARGET) /// Activation of the drawing tool (placing a TARGET)
static TOOL_ACTION placeTarget; static TOOL_ACTION placeTarget;
/// Activation of the drawing tool (placing a MODULE)
static TOOL_ACTION placeModule;
}; };
...@@ -26,16 +26,20 @@ ...@@ -26,16 +26,20 @@
#include "common_actions.h" #include "common_actions.h"
#include <wxPcbStruct.h> #include <wxPcbStruct.h>
#include <confirm.h>
#include <view/view_group.h> #include <view/view_group.h>
#include <view/view_controls.h> #include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h>
#include <tool/tool_manager.h>
#include <class_board.h> #include <class_board.h>
#include <class_drawsegment.h> #include <class_drawsegment.h>
#include <class_pcb_text.h> #include <class_pcb_text.h>
#include <class_dimension.h> #include <class_dimension.h>
#include <class_mire.h> #include <class_mire.h>
#include <gal/graphics_abstraction_layer.h> #include <class_module.h>
#include <tool/tool_manager.h> #include <class_netinfo.h> // TODO to be removed if we do not need the flags
#include <confirm.h>
DRAWING_TOOL::DRAWING_TOOL() : DRAWING_TOOL::DRAWING_TOOL() :
TOOL_INTERACTIVE( "pcbnew.InteractiveDrawing" ) TOOL_INTERACTIVE( "pcbnew.InteractiveDrawing" )
...@@ -570,6 +574,8 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent ) ...@@ -570,6 +574,8 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
target->SetLayer( EDGE_N ); target->SetLayer( EDGE_N );
target->SetWidth( board->GetDesignSettings().m_EdgeSegmentWidth ); target->SetWidth( board->GetDesignSettings().m_EdgeSegmentWidth );
target->SetSize( Millimeter2iu( 5 ) ); target->SetSize( Millimeter2iu( 5 ) );
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() );
target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
// Add a VIEW_GROUP that serves as a preview for the new item // Add a VIEW_GROUP that serves as a preview for the new item
KIGFX::VIEW_GROUP preview( view ); KIGFX::VIEW_GROUP preview( view );
...@@ -630,6 +636,85 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent ) ...@@ -630,6 +636,85 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
} }
int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
{
KIGFX::VIEW* view = getView();
KIGFX::VIEW_CONTROLS* controls = getViewControls();
BOARD* board = getModel<BOARD>( PCB_T );
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
MODULE* module = editFrame->LoadModuleFromLibrary( wxEmptyString,
editFrame->GetFootprintLibraryTable(), true, NULL );
if( module == NULL )
{
setTransitions();
return 0;
}
// Init the new item attributes
VECTOR2D cursorPos = view->ToWorld( controls->GetCursorPosition() );
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX::VIEW_GROUP preview( view );
preview.Add( module );
module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW_GROUP::Add ), &preview ) );
view->Add( &preview );
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
controls->SetSnapping( true );
Activate();
// Main loop: keep receiving events
while( OPT_TOOL_EVENT evt = Wait() )
{
cursorPos = view->ToWorld( controls->GetCursorPosition() );
if( evt->IsCancel() )
{
board->Delete( module );
break;
}
else if( evt->Category() == TC_COMMAND )
{
if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
{
module->Rotate( module->GetPosition(), getEditFrame<PCB_EDIT_FRAME>()->GetRotationAngle() );
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
{
module->Flip( module->GetPosition() );
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
}
else if( evt->IsClick( BUT_LEFT ) )
{
module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) );
view->Add( module );
module->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
break;
}
else if( evt->IsMotion() )
{
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
}
controls->SetSnapping( false );
controls->SetAutoPan( false );
view->Remove( &preview );
setTransitions();
return 0;
}
void DRAWING_TOOL::setTransitions() void DRAWING_TOOL::setTransitions()
{ {
Go( &DRAWING_TOOL::DrawLine, COMMON_ACTIONS::drawLine.MakeEvent() ); Go( &DRAWING_TOOL::DrawLine, COMMON_ACTIONS::drawLine.MakeEvent() );
...@@ -638,4 +723,5 @@ void DRAWING_TOOL::setTransitions() ...@@ -638,4 +723,5 @@ void DRAWING_TOOL::setTransitions()
Go( &DRAWING_TOOL::DrawText, COMMON_ACTIONS::drawText.MakeEvent() ); Go( &DRAWING_TOOL::DrawText, COMMON_ACTIONS::drawText.MakeEvent() );
Go( &DRAWING_TOOL::DrawDimension, COMMON_ACTIONS::drawDimension.MakeEvent() ); Go( &DRAWING_TOOL::DrawDimension, COMMON_ACTIONS::drawDimension.MakeEvent() );
Go( &DRAWING_TOOL::PlaceTarget, COMMON_ACTIONS::placeTarget.MakeEvent() ); Go( &DRAWING_TOOL::PlaceTarget, COMMON_ACTIONS::placeTarget.MakeEvent() );
Go( &DRAWING_TOOL::PlaceModule, COMMON_ACTIONS::placeModule.MakeEvent() );
} }
...@@ -61,6 +61,8 @@ public: ...@@ -61,6 +61,8 @@ public:
int PlaceTarget( TOOL_EVENT& aEvent ); int PlaceTarget( TOOL_EVENT& aEvent );
int PlaceModule( TOOL_EVENT& aEvent );
private: private:
///> Starts drawing a selected shape. ///> Starts drawing a selected shape.
int draw( STROKE_T aShape ); int draw( STROKE_T aShape );
......
...@@ -61,6 +61,7 @@ void PCB_EDIT_FRAME::setupTools() ...@@ -61,6 +61,7 @@ void PCB_EDIT_FRAME::setupTools()
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawText ); m_toolManager->RegisterAction( &COMMON_ACTIONS::drawText );
m_toolManager->RegisterAction( &COMMON_ACTIONS::drawDimension ); m_toolManager->RegisterAction( &COMMON_ACTIONS::drawDimension );
m_toolManager->RegisterAction( &COMMON_ACTIONS::placeTarget ); m_toolManager->RegisterAction( &COMMON_ACTIONS::placeTarget );
m_toolManager->RegisterAction( &COMMON_ACTIONS::placeModule );
// Register tools // Register tools
m_toolManager->RegisterTool( new SELECTION_TOOL ); m_toolManager->RegisterTool( new SELECTION_TOOL );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment