diff --git a/qa/common/mocks.cpp b/qa/common/mocks.cpp new file mode 100644 index 0000000000..1be8d9685f --- /dev/null +++ b/qa/common/mocks.cpp @@ -0,0 +1,327 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 + */ + +/** + * @file pcbnew.cpp + * @brief Pcbnew main program. + */ + +#ifdef KICAD_SCRIPTING + #include + #include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include <3d_viewer.h> +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "pcb_tool.h" +#include +#include + +bool g_Drc_On = true; +bool g_AutoDeleteOldTrack = true; +bool g_Raccord_45_Auto = true; +bool g_Alternate_Track_Posture = false; +bool g_Track_45_Only_Allowed = true; // True to allow horiz, vert. and 45deg only tracks +bool g_Segments_45_Only; // True to allow horiz, vert. and 45deg only graphic segments +bool g_TwoSegmentTrackBuild = true; + +PCB_LAYER_ID g_Route_Layer_TOP; +PCB_LAYER_ID g_Route_Layer_BOTTOM; +int g_MagneticPadOption; +int g_MagneticTrackOption; + +wxPoint g_Offset_Module; // module offset used when moving a footprint + +/* Name of the document footprint list + * usually located in share/modules/footprints_doc + * this is of the responsibility to users to create this file + * if they want to have a list of footprints + */ +wxString g_DocModulesFileName = wxT( "footprints_doc/footprints.pdf" ); + +/* + * Used in track creation, a list of track segments currently being created, + * with the newest track at the end of the list, sorted by new-ness. e.g. use + * TRACK->Back() to get the next older track, TRACK->Next() to get the next + * newer track. + */ +DLIST g_CurrentTrackList; + +bool g_DumpZonesWhenFilling = false; + +static struct IFACE : public KIFACE_I +{ + // Of course all are overloads, implementations of the KIFACE. + + IFACE( const char* aName, KIWAY::FACE_T aType ) : + KIFACE_I( aName, aType ) + {} + + bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) + { + return true; + } + + void OnKifaceEnd() {} + + wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) + { + assert( false ); + return nullptr; + } + + /** + * Function IfaceOrAddress + * return a pointer to the requested object. The safest way to use this + * is to retrieve a pointer to a static instance of an interface, similar to + * how the KIFACE interface is exported. But if you know what you are doing + * use it to retrieve anything you want. + * + * @param aDataId identifies which object you want the address of. + * + * @return void* - and must be cast into the know type. + */ + void* IfaceOrAddress( int aDataId ) + { + return NULL; + } +} +kiface( "pcb_test_frame", KIWAY::FACE_PCB ); + +static struct PGM_TEST_FRAME : public PGM_BASE +{ + bool OnPgmInit(); + + void OnPgmExit() + { + Kiway.OnKiwayEnd(); + + // Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl + // earlier than wxApp and earlier than static destruction would. + PGM_BASE::Destroy(); + } + + void MacOpenFile( const wxString& aFileName ) override + { + wxFileName filename( aFileName ); + + if( filename.FileExists() ) + { + #if 0 + // this pulls in EDA_DRAW_FRAME type info, which we don't want in + // the single_top link image. + KIWAY_PLAYER* frame = dynamic_cast( App().GetTopWindow() ); + #else + KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow(); + #endif + + if( frame ) + frame->OpenProjectFiles( std::vector( 1, aFileName ) ); + } + } +} +program; + +PGM_BASE& Pgm() +{ + return program; +} + + +KIFACE_I& Kiface() +{ + return kiface; +} + + +FP_LIB_TABLE GFootprintTable; + +void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset ) +{ +} + + +// Initialize static member variables +wxString DIALOG_FIND::prevSearchString; +bool DIALOG_FIND::warpMouse = true; + + +DIALOG_FIND::DIALOG_FIND( PCB_BASE_FRAME* aParent ) : DIALOG_FIND_BASE( aParent ) +{ +} + + +void DIALOG_FIND::OnInitDialog( wxInitDialogEvent& event ) +{ +} + + +void DIALOG_FIND::EnableWarp( bool aEnabled ) +{ +} + + +void DIALOG_FIND::onButtonCloseClick( wxCommandEvent& aEvent ) +{ +} + + +void DIALOG_FIND::onButtonFindItemClick( wxCommandEvent& aEvent ) +{ +} + + +void DIALOG_FIND::onButtonFindMarkerClick( wxCommandEvent& aEvent ) +{ +} + + +void DIALOG_FIND::onClose( wxCloseEvent& aEvent ) +{ +} + + +DIALOG_FIND_BASE::DIALOG_FIND_BASE( wxWindow* parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos, + const wxSize& size, + long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ +} + + +DIALOG_FIND_BASE::~DIALOG_FIND_BASE() +{ +} + + +MODULE* PCB_BASE_FRAME::GetFootprintFromBoardByReference() +{ + return nullptr; +} + + +TOOL_ACTION PCB_ACTIONS::selectionModified( "pcbnew.InteractiveEdit.ModifiedSelection", + AS_GLOBAL, 0, + "", "", nullptr, AF_NOTIFY ); + +TOOL_ACTION PCB_ACTIONS::flip( "pcbnew.InteractiveEdit.flip", + AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_FLIP_ITEM ), + _( "Flip" ), _( "Flips selected item(s)" ), nullptr ); + + +TOOL_ACTION PCB_ACTIONS::properties( "pcbnew.InteractiveEdit.properties", + AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT_ITEM ), + _( "Properties" ), _( "Displays item properties dialog" ), nullptr ); + +TOOL_ACTION PCB_ACTIONS::highlightNet( "pcbnew.EditorControl.highlightNet", + AS_GLOBAL, 0, + "", "" ); + + +DIALOG_BLOCK_OPTIONS_BASE::DIALOG_BLOCK_OPTIONS_BASE( wxWindow* parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos, + const wxSize& size, + long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ +} + + +DIALOG_BLOCK_OPTIONS_BASE::~DIALOG_BLOCK_OPTIONS_BASE() +{ +} + + +TOOL_ACTION PCB_ACTIONS::rotateCw( "pcbnew.InteractiveEdit.rotateCw", + AS_GLOBAL, MD_SHIFT + 'R', + _( "Rotate Clockwise" ), _( "Rotates selected item(s) clockwise" ), + nullptr, AF_NONE, (void*) -1 ); + +TOOL_ACTION PCB_ACTIONS::rotateCcw( "pcbnew.InteractiveEdit.rotateCcw", + AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ROTATE_ITEM ), + _( "Rotate Counterclockwise" ), _( "Rotates selected item(s) counterclockwise" ), + nullptr, AF_NONE, (void*) 1 ); + +DIALOG_BLOCK_OPTIONS::DIALOG_BLOCK_OPTIONS( PCB_BASE_FRAME* aParent, + OPTIONS& aOptions, bool aShowLegacyOptions, + const wxString& aTitle ) : + DIALOG_BLOCK_OPTIONS_BASE( aParent, -1, aTitle ), + m_options( aOptions ) +{ +} + + +void DIALOG_BLOCK_OPTIONS::checkBoxClicked( wxCommandEvent& aEvent ) +{ +} + + +void DIALOG_BLOCK_OPTIONS::ExecuteCommand( wxCommandEvent& event ) +{ +} + + +void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ) +{ +} diff --git a/qa/common/pcb_test_frame.cpp b/qa/common/pcb_test_frame.cpp new file mode 100644 index 0000000000..a36b925300 --- /dev/null +++ b/qa/common/pcb_test_frame.cpp @@ -0,0 +1,230 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013-2017 CERN + * @author Tomasz Wlostowski + * + * 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 + */ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "pcb_test_frame.h" + +IMPLEMENT_APP( GAL_TEST_APP ) + +using namespace KIGFX; + +bool GAL_TEST_APP::OnInit() +{ + if( !wxApp::OnInit() ) + return false; + + // Create the main frame window + auto frame = CreateMainFrame( (const char*) m_filename.c_str() ); + + return frame != nullptr; +} + + +void GAL_TEST_APP::OnInitCmdLine( wxCmdLineParser& parser ) +{ + parser.AddOption( "f", wxEmptyString, "Open board file" ); + wxApp::OnInitCmdLine( parser ); +} + + +bool GAL_TEST_APP::OnCmdLineParsed( wxCmdLineParser& parser ) +{ + wxString filename; + + if( parser.Found( "f", &filename ) ) + { + m_filename = filename; + } + + return true; +} + + +class TEST_ACTIONS : public ACTIONS +{ +public: + + virtual ~TEST_ACTIONS() {}; + + virtual boost::optional TranslateLegacyId( int aId ) + { + return boost::none; + } + + void RegisterAllTools( TOOL_MANAGER* aToolManager ) + { + } +}; + +void PCB_TEST_FRAME::OnMenuFileOpen( wxCommandEvent& WXUNUSED( event ) ) +{ +} + + +void PCB_TEST_FRAME::OnMotion( wxMouseEvent& aEvent ) +{ + aEvent.Skip(); +} + + +void PCB_TEST_FRAME::SetBoard( BOARD* b ) +{ + m_board.reset( b ); + m_board->GetConnectivity()->Build( m_board.get() ); + m_galPanel->DisplayBoard( m_board.get() ); + m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(), + m_galPanel->GetViewControls(), nullptr ); + + m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); +} + + +BOARD* PCB_TEST_FRAME::LoadAndDisplayBoard( const std::string& filename ) +{ + PLUGIN::RELEASER pi( new PCB_IO ); + BOARD* brd = nullptr; + + try + { + brd = pi->Load( wxString( filename.c_str() ), NULL, NULL ); + } + catch( const IO_ERROR& ioe ) + { + wxString msg = wxString::Format( _( "Error loading board.\n%s" ), + ioe.Problem() ); + + printf( "%s\n", (const char*) msg.mb_str() ); + return nullptr; + } + + SetBoard( brd ); + + return brd; +} + + +PCB_TEST_FRAME::PCB_TEST_FRAME( wxFrame* frame, const wxString& title, const wxPoint& pos, + const wxSize& size, long style ) : + wxFrame( frame, wxID_ANY, title, pos, size, style ) +{ + // Make a menubar + wxMenu* fileMenu = new wxMenu; + + fileMenu->Append( wxID_OPEN, wxT( "&Open..." ) ); + fileMenu->AppendSeparator(); + fileMenu->Append( wxID_EXIT, wxT( "E&xit" ) ); + wxMenuBar* menuBar = new wxMenuBar; + menuBar->Append( fileMenu, wxT( "&File" ) ); + SetMenuBar( menuBar ); + + Show( true ); + Maximize(); + Raise(); + + KIGFX::GAL_DISPLAY_OPTIONS options; + + m_galPanel.reset( new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, + 0 ), wxDefaultSize, options, EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ) ); + + m_galPanel->SetEvtHandlerEnabled( true ); + m_galPanel->SetFocus(); + m_galPanel->Show( true ); + m_galPanel->Raise(); + m_galPanel->StartDrawing(); + + auto gal = m_galPanel->GetGAL(); + + gal->SetGridVisibility( true ); + gal->SetGridSize( VECTOR2D( 100000.0, 100000.0 ) ); + gal->SetGridOrigin( VECTOR2D( 0.0, 0.0 ) ); + + m_galPanel->Connect( wxEVT_MOTION, + wxMouseEventHandler( PCB_TEST_FRAME::OnMotion ), NULL, this ); + + m_galPanel->GetViewControls()->ShowCursor( true ); + + m_toolManager.reset( new TOOL_MANAGER ); + m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(), + m_galPanel->GetViewControls(), nullptr ); + + m_pcbActions.reset( new TEST_ACTIONS() ); + m_toolDispatcher.reset( new TOOL_DISPATCHER( m_toolManager.get(), m_pcbActions.get() ) ); + + m_toolManager->RegisterTool( new SELECTION_TOOL ); + + m_toolManager->InitTools(); + m_galPanel->SetEventDispatcher( m_toolDispatcher.get() ); + m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" ); + + SetBoard( new BOARD ); +} + + +PCB_TEST_FRAME::~PCB_TEST_FRAME() +{ +} + + +// Intercept menu commands +void PCB_TEST_FRAME::OnExit( wxCommandEvent& WXUNUSED( event ) ) +{ + // true is to force the frame to close + Close( true ); +} diff --git a/qa/common/pcb_test_frame.h b/qa/common/pcb_test_frame.h new file mode 100644 index 0000000000..a95e78a334 --- /dev/null +++ b/qa/common/pcb_test_frame.h @@ -0,0 +1,91 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013-2017 CERN + * @author Tomasz Wlostowski + * + * 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 + */ + +#ifndef __PCB_TEST_FRAME_H +#define __PCB_TEST_FRAME_H + +#include +#include + +#include + +using std::unique_ptr; + +class PCB_DRAW_PANEL_GAL; +class BOARD; + +class TOOL_MANAGER; +class TOOL_DISPATCHER; +class ACTIONS; + + +namespace KIGFX { + class VIEW; +}; + +// Define a new application type +class GAL_TEST_APP : public wxApp +{ +public: + virtual bool OnInit(); + + virtual void OnInitCmdLine(wxCmdLineParser& parser); + virtual bool OnCmdLineParsed(wxCmdLineParser& parser); + +private: + wxString m_filename; +}; + +class PCB_TEST_FRAME : public wxFrame +{ +public: + PCB_TEST_FRAME(wxFrame *frame, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE); + + virtual ~PCB_TEST_FRAME(); + + void SetBoard( BOARD * b); + BOARD* LoadAndDisplayBoard ( const std::string& filename ); + +protected: + + virtual void OnExit(wxCommandEvent& event); + virtual void OnMotion( wxMouseEvent& aEvent ); + virtual void OnMenuFileOpen( wxCommandEvent& WXUNUSED(event) ); + + void buildView(); + + unique_ptr < PCB_DRAW_PANEL_GAL > m_galPanel; + unique_ptr < BOARD > m_board; + unique_ptr < TOOL_MANAGER > m_toolManager; + unique_ptr < TOOL_DISPATCHER > m_toolDispatcher; + unique_ptr < ACTIONS > m_pcbActions; +}; + +wxFrame* CreateMainFrame( const std::string& aFileName ); + +#endif diff --git a/qa/pcb_test_window/CMakeLists.txt b/qa/pcb_test_window/CMakeLists.txt new file mode 100644 index 0000000000..f073d00846 --- /dev/null +++ b/qa/pcb_test_window/CMakeLists.txt @@ -0,0 +1,82 @@ + +# +# This program source code file is part of KiCad, a free EDA CAD application. +# +# Copyright (C) 2017 CERN +# @author Alejandro GarcĂ­a Montoro +# +# 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 + +find_package(Boost COMPONENTS unit_test_framework REQUIRED) +find_package( wxWidgets 3.0.0 COMPONENTS gl aui adv html core net base xml stc REQUIRED ) + +add_definitions(-DBOOST_TEST_DYN_LINK -DPCBNEW) + +add_executable(test_window + test.cpp + ../common/pcb_test_frame.cpp + ../common/mocks.cpp + ../../common/base_units.cpp + ../../pcbnew/tools/pcb_tool.cpp + ../../pcbnew/tools/selection.cpp + ../../pcbnew/tools/selection_tool.cpp + ../../pcbnew/tools/tool_event_utils.cpp + #../../pcbnew/tools/outline_editor.cpp +) + +include_directories( + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/3d-viewer + ${CMAKE_SOURCE_DIR}/common + ${CMAKE_SOURCE_DIR}/pcbnew + ${CMAKE_SOURCE_DIR}/pcbnew/router + ${CMAKE_SOURCE_DIR}/pcbnew/tools + ${CMAKE_SOURCE_DIR}/pcbnew/dialogs + ${CMAKE_SOURCE_DIR}/polygon + ${CMAKE_SOURCE_DIR}/common/geometry + ${CMAKE_SOURCE_DIR}/qa/common + ${Boost_INCLUDE_DIR} +) + +target_link_libraries( test_window + polygon + pnsrouter + common + pcbcommon + bitmaps + polygon + pnsrouter + common + pcbcommon + bitmaps + polygon + pnsrouter + common + pcbcommon + bitmaps + polygon + pnsrouter + common + pcbcommon + bitmaps + ${Boost_FILESYSTEM_LIBRARY} + ${Boost_SYSTEM_LIBRARY} + ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} + ${wxWidgets_LIBRARIES} +) diff --git a/qa/pcb_test_window/test.cpp b/qa/pcb_test_window/test.cpp new file mode 100644 index 0000000000..46f793da02 --- /dev/null +++ b/qa/pcb_test_window/test.cpp @@ -0,0 +1,40 @@ +#include +// #include +#include + +class OED_TEST_FRAME : public PCB_TEST_FRAME +{ +public: + OED_TEST_FRAME( wxFrame* frame, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE ) : + PCB_TEST_FRAME( frame, title, pos, size, style ) + { + registerTools(); + } + + void registerTools(); + + virtual ~OED_TEST_FRAME() {} +}; + +wxFrame* CreateMainFrame( const std::string& aFileName ) +{ + auto frame = new OED_TEST_FRAME( nullptr, wxT( "Outline Editor Test" ) ); + + if( aFileName != "" ) + { + frame->LoadAndDisplayBoard( aFileName ); + } + + return frame; +} + +void OED_TEST_FRAME::registerTools() +{ +// m_toolManager->RegisterTool( new OUTLINE_EDITOR ); + m_toolManager->InitTools(); + m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); +}