2017-02-23 06:23:17 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-01-27 22:15:38 +00:00
|
|
|
* Copyright (C) 2017-2021 Kicad Developers, see change_log.txt for contributors.
|
2017-02-23 06:23:17 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-04-01 17:24:31 +00:00
|
|
|
#include <bitmaps.h>
|
2017-02-23 06:23:17 +00:00
|
|
|
#include <board_commit.h>
|
2020-11-14 18:11:28 +00:00
|
|
|
#include <board_item.h>
|
2020-04-01 17:24:31 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2017-02-23 06:23:17 +00:00
|
|
|
#include <confirm.h>
|
2020-04-01 17:24:31 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
#include <microwave/microwave_tool.h>
|
2017-02-23 06:23:17 +00:00
|
|
|
#include <preview_items/two_point_geom_manager.h>
|
|
|
|
#include <preview_items/centreline_rect_item.h>
|
2020-04-01 17:24:31 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <view/view.h>
|
2017-02-23 06:23:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
MICROWAVE_TOOL::MICROWAVE_TOOL() :
|
2019-05-12 11:49:58 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.MicrowaveTool" )
|
2017-02-23 06:23:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MICROWAVE_TOOL::~MICROWAVE_TOOL()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void MICROWAVE_TOOL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-24 15:27:05 +00:00
|
|
|
int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent )
|
2017-02-23 06:23:17 +00:00
|
|
|
{
|
2017-04-22 15:46:31 +00:00
|
|
|
struct MICROWAVE_PLACER : public INTERACTIVE_PLACER_BASE
|
2017-05-29 18:47:21 +00:00
|
|
|
{
|
2020-04-01 17:24:31 +00:00
|
|
|
MICROWAVE_PLACER( MICROWAVE_TOOL* aTool, MICROWAVE_FOOTPRINT_SHAPE aType ) :
|
|
|
|
m_tool( aTool ),
|
2019-07-01 21:01:33 +00:00
|
|
|
m_itemType( aType )
|
|
|
|
{ };
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~MICROWAVE_PLACER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
std::unique_ptr<BOARD_ITEM> CreateItem() override
|
2017-05-29 18:47:21 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
switch( m_itemType )
|
2017-04-22 15:46:31 +00:00
|
|
|
{
|
2020-04-01 17:24:31 +00:00
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::GAP:
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::STUB:
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::STUB_ARC:
|
2020-11-13 15:15:52 +00:00
|
|
|
return std::unique_ptr<FOOTPRINT>( m_tool->createFootprint( m_itemType ) );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
|
|
|
case MICROWAVE_FOOTPRINT_SHAPE::FUNCTION_SHAPE:
|
2020-11-13 15:15:52 +00:00
|
|
|
return std::unique_ptr<FOOTPRINT>( m_tool->createPolygonShape() );
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
default:
|
2020-11-13 15:15:52 +00:00
|
|
|
return std::unique_ptr<FOOTPRINT>();
|
2019-07-01 21:01:33 +00:00
|
|
|
};
|
2017-04-22 15:46:31 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
|
|
|
|
private:
|
2020-04-01 17:24:31 +00:00
|
|
|
MICROWAVE_TOOL* m_tool;
|
|
|
|
MICROWAVE_FOOTPRINT_SHAPE m_itemType;
|
2017-02-23 06:23:17 +00:00
|
|
|
};
|
|
|
|
|
2020-04-01 17:24:31 +00:00
|
|
|
MICROWAVE_PLACER placer( this, aEvent.Parameter<MICROWAVE_FOOTPRINT_SHAPE>() );
|
2019-06-24 15:27:05 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer,
|
|
|
|
_( "Place microwave feature" ),
|
2019-07-01 21:01:33 +00:00
|
|
|
IPO_REPEAT | IPO_ROTATE | IPO_FLIP );
|
2017-02-23 06:23:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const COLOR4D inductorAreaFill( 0.3, 0.3, 0.5, 0.3 );
|
|
|
|
static const COLOR4D inductorAreaStroke( 0.4, 1.0, 1.0, 1.0 );
|
|
|
|
static const double inductorAreaStrokeWidth = 1.0;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Aspect of the preview rectangle - this is hardcoded in the
|
|
|
|
///< microwave backend for now
|
2017-02-23 06:23:17 +00:00
|
|
|
static const double inductorAreaAspect = 0.5;
|
|
|
|
|
|
|
|
|
|
|
|
int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
using namespace KIGFX::PREVIEW;
|
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
KIGFX::VIEW& view = *getView();
|
2017-02-23 06:23:17 +00:00
|
|
|
KIGFX::VIEW_CONTROLS& controls = *getViewControls();
|
2020-11-19 20:08:58 +00:00
|
|
|
PCB_EDIT_FRAME& frame = *getEditFrame<PCB_EDIT_FRAME>();
|
2017-02-23 06:23:17 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
frame.PushTool( tool );
|
2017-02-23 06:23:17 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
auto setCursor =
|
|
|
|
[&]()
|
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
frame.GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
|
|
|
|
};
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
Activate();
|
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
|
|
|
controls.ShowCursor( true );
|
|
|
|
controls.CaptureCursor( false );
|
|
|
|
controls.SetAutoPan( false );
|
2020-10-08 02:47:01 +00:00
|
|
|
// Set initial cursor
|
|
|
|
setCursor();
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
bool originSet = false;
|
|
|
|
TWO_POINT_GEOMETRY_MANAGER tpGeomMgr;
|
|
|
|
CENTRELINE_RECT_ITEM previewRect( tpGeomMgr, inductorAreaAspect );
|
|
|
|
|
|
|
|
previewRect.SetFillColor( inductorAreaFill );
|
|
|
|
previewRect.SetStrokeColor( inductorAreaStroke );
|
|
|
|
previewRect.SetLineWidth( inductorAreaStrokeWidth );
|
|
|
|
view.Add( &previewRect );
|
|
|
|
|
2017-02-23 06:23:17 +00:00
|
|
|
while( auto evt = Wait() )
|
|
|
|
{
|
2020-10-08 02:47:01 +00:00
|
|
|
setCursor();
|
2017-02-23 06:23:17 +00:00
|
|
|
VECTOR2I cursorPos = controls.GetCursorPosition();
|
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
auto cleanup =
|
|
|
|
[&] ()
|
|
|
|
{
|
|
|
|
originSet = false;
|
|
|
|
controls.CaptureCursor( false );
|
|
|
|
controls.SetAutoPan( false );
|
|
|
|
view.SetVisible( &previewRect, false );
|
|
|
|
view.Update( &previewRect, KIGFX::GEOMETRY );
|
|
|
|
};
|
2019-07-01 21:01:33 +00:00
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
2017-02-23 06:23:17 +00:00
|
|
|
{
|
2019-06-24 15:27:05 +00:00
|
|
|
if( originSet )
|
2019-07-01 21:01:33 +00:00
|
|
|
cleanup();
|
|
|
|
else
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
frame.PopTool( tool );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2019-06-24 15:27:05 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( originSet )
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
if( evt->IsMoveTool() )
|
2017-02-23 06:23:17 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
2017-02-23 06:23:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
frame.PopTool( tool );
|
2019-06-24 15:27:05 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2017-02-23 06:23:17 +00:00
|
|
|
}
|
|
|
|
// A click or drag starts
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( !originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsDrag( BUT_LEFT ) ) )
|
2017-02-23 06:23:17 +00:00
|
|
|
{
|
|
|
|
tpGeomMgr.SetOrigin( cursorPos );
|
|
|
|
tpGeomMgr.SetEnd( cursorPos );
|
|
|
|
|
|
|
|
originSet = true;
|
|
|
|
controls.CaptureCursor( true );
|
|
|
|
controls.SetAutoPan( true );
|
|
|
|
}
|
|
|
|
// another click after origin set is the end
|
|
|
|
// left up is also the end, as you'll only get that after a drag
|
2019-06-24 15:27:05 +00:00
|
|
|
else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
|
2017-02-23 06:23:17 +00:00
|
|
|
{
|
|
|
|
// second click, we're done:
|
|
|
|
// delegate to the point-to-point inductor creator function
|
|
|
|
createInductorBetween( tpGeomMgr.GetOrigin(), tpGeomMgr.GetEnd() );
|
|
|
|
|
|
|
|
// start again if needed
|
|
|
|
originSet = false;
|
2018-09-12 11:22:01 +00:00
|
|
|
controls.CaptureCursor( false );
|
|
|
|
controls.SetAutoPan( false );
|
2017-02-23 06:23:17 +00:00
|
|
|
|
|
|
|
view.SetVisible( &previewRect, false );
|
|
|
|
view.Update( &previewRect, KIGFX::GEOMETRY );
|
|
|
|
}
|
|
|
|
// any move or drag once the origin was set updates
|
|
|
|
// the end point
|
2019-06-24 15:27:05 +00:00
|
|
|
else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
|
2017-02-23 06:23:17 +00:00
|
|
|
{
|
2021-09-02 22:32:15 +00:00
|
|
|
tpGeomMgr.SetAngleSnap( Is45Limited() );
|
2017-02-23 06:23:17 +00:00
|
|
|
tpGeomMgr.SetEnd( cursorPos );
|
|
|
|
|
|
|
|
view.SetVisible( &previewRect, true );
|
|
|
|
view.Update( &previewRect, KIGFX::GEOMETRY );
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
2019-05-19 21:04:04 +00:00
|
|
|
m_menu.ShowContextMenu( selection() );
|
2017-02-23 06:23:17 +00:00
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
else
|
2020-11-19 20:08:58 +00:00
|
|
|
{
|
2019-07-26 18:16:44 +00:00
|
|
|
evt->SetPassEvent();
|
2020-11-19 20:08:58 +00:00
|
|
|
}
|
2017-02-23 06:23:17 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 20:08:58 +00:00
|
|
|
view.Remove( &previewRect );
|
|
|
|
|
|
|
|
frame.GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2018-09-12 11:22:01 +00:00
|
|
|
controls.CaptureCursor( false );
|
|
|
|
controls.SetAutoPan( false );
|
2017-02-23 06:23:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-01 17:24:31 +00:00
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void MICROWAVE_TOOL::setTransitions()
|
2017-02-23 06:23:17 +00:00
|
|
|
{
|
|
|
|
Go( &MICROWAVE_TOOL::addMicrowaveFootprint, PCB_ACTIONS::microwaveCreateGap.MakeEvent() );
|
|
|
|
Go( &MICROWAVE_TOOL::addMicrowaveFootprint, PCB_ACTIONS::microwaveCreateStub.MakeEvent() );
|
|
|
|
Go( &MICROWAVE_TOOL::addMicrowaveFootprint, PCB_ACTIONS::microwaveCreateStubArc.MakeEvent() );
|
2021-01-27 22:15:38 +00:00
|
|
|
Go( &MICROWAVE_TOOL::addMicrowaveFootprint,
|
|
|
|
PCB_ACTIONS::microwaveCreateFunctionShape.MakeEvent() );
|
2017-02-23 06:23:17 +00:00
|
|
|
|
|
|
|
Go( &MICROWAVE_TOOL::drawMicrowaveInductor, PCB_ACTIONS::microwaveCreateLine.MakeEvent() );
|
|
|
|
}
|