From abfa841a98d395587d6d5f33c456e98670ea6b77 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Tue, 1 Nov 2011 03:05:56 -0500 Subject: [PATCH] sweet editor now shows GAL canvas --- new/CMakeLists.txt | 59 +++++++++++++++++++++---------- new/sch_canvas.cpp | 18 +++++++--- new/sch_canvas.h | 9 ++--- new/sweet_edit.cpp | 72 +++++++++++++++++++++++++++++++------- new/sweet_editor_panel.cpp | 4 +-- new/sweet_editor_panel.fbp | 26 +++++++------- 6 files changed, 132 insertions(+), 56 deletions(-) diff --git a/new/CMakeLists.txt b/new/CMakeLists.txt index 9843b90215..bc535f3ec8 100644 --- a/new/CMakeLists.txt +++ b/new/CMakeLists.txt @@ -27,7 +27,7 @@ if( 1 ) project(kicad-new) - cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR) + cmake_minimum_required( VERSION 2.8 FATAL_ERROR ) set( PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../ ) @@ -49,22 +49,6 @@ if( 1 ) check_find_package_result( wxWidgets_FOUND "wxWidgets" ) - find_library( gal_LIBRARY "libgal.a" - PATHS - "${CMAKE_CURRENT_SOURCE_DIR}/../../kicad-gal/build" - "${CMAKE_CURRENT_SOURCE_DIR}/../../../kicad-gal/build" - DOC - "Where is the static GAL library" - ) - - find_path( gal_ROOT NAMES "README.txt" - PATHS - "${CMAKE_CURRENT_SOURCE_DIR}/../../kicad-gal" - "${CMAKE_CURRENT_SOURCE_DIR}/../../../kicad-gal" - DOC - "Where is the base include directory for the GAL library" - ) - # make config.h include( PerformFeatureChecks ) perform_feature_checks() @@ -168,7 +152,46 @@ if( MINGW ) endif() target_link_libraries( test_sch_lib_table sweet ) -include_directories ( "${gal_ROOT}" ) + +if( 1 ) + + find_library( gal_LIBRARY "libgal.a" + PATHS + "${CMAKE_CURRENT_SOURCE_DIR}/../../kicad-gal/build" + "${CMAKE_CURRENT_SOURCE_DIR}/../../../kicad-gal/build" + DOC + "Where is the static GAL library" + ) + find_path( gal_ROOT NAMES "README.txt" + PATHS + "${CMAKE_CURRENT_SOURCE_DIR}/../../kicad-gal" + "${CMAKE_CURRENT_SOURCE_DIR}/../../../kicad-gal" + DOC + "Where is the base include directory for the GAL library" + ) + +else() + + # we build the GAL library, therefore we know where it is, no need to find_library() it. + set( gal_ROOT "${CMAKE_CURRENT_BINARY_DIR}/gal-src" ) + set( gal_LIBRARY "${CMAKE_CURRENT_BINARY_DIR}/gal-src/libgal.a" ) + + + include( ExternalProject ) + ExternalProject_Add( ki_gal + # skip the install step, build in source, use from source + SOURCE_DIR "${gal_ROOT}" + STAMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/gal-stamps" + TIMEOUT 120 + DOWNLOAD_COMMAND bzr export ${gal_ROOT} lp:~kicad-testing-committers/kicad/kicad-gal + CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${gal_ROOT} + BUILD_IN_SOURCE 1 + BUILD_COMMAND make + INSTALL_COMMAND "" + ) +endif() + +include_directories( "${gal_ROOT}" ) # Find pkg-config in order find cairo. find_package( PkgConfig REQUIRED ) diff --git a/new/sch_canvas.cpp b/new/sch_canvas.cpp index 2c6ae6c64e..f8418cb023 100644 --- a/new/sch_canvas.cpp +++ b/new/sch_canvas.cpp @@ -31,8 +31,10 @@ namespace SCH { CANVAS::CANVAS( wxWindow* aParent ) : - OPENGL_GAL( aParent, wxDefaultSize ) + OPENGL_GAL( aParent, NULL, this ) // I am my own PaintListener { + Connect( EVT_GAL_REDRAW, wxCommandEventHandler( CANVAS::onRedraw ) ); + // Set the world unit length SetWorldUnitLength( 0.01 ); @@ -63,9 +65,18 @@ CANVAS::CANVAS( wxWindow* aParent ) : } -void CANVAS::Paint() +void CANVAS::onRedraw( wxCommandEvent& event ) { -/* + D(printf( "%s:\n", __FUNCTION__ );) + + PaintScene(); +} + + +void CANVAS::PaintScene() +{ + D(printf("%s:\n", __FUNCTION__ );) + BeginDrawing(); SetBackgroundColor( COLOR4D( 0, 0, 0, 1.0 ) ); @@ -80,7 +91,6 @@ void CANVAS::Paint() Flush(); EndDrawing(); -*/ } diff --git a/new/sch_canvas.h b/new/sch_canvas.h index 38484259d9..06726d44a5 100644 --- a/new/sch_canvas.h +++ b/new/sch_canvas.h @@ -38,16 +38,11 @@ class CANVAS : public OPENGL_GAL protected: PART* part; ///< which PART to draw + void onRedraw( wxCommandEvent& event ); public: CANVAS( wxWindow* aParent ); - /** - * Function Paint (overloaded) - * redraws the entire window, overloads OPENGL_GAL::Paint() - */ - void Paint(); - /** * Function SetPart * sets the PART to draw, returns the previous PART. @@ -58,6 +53,8 @@ public: part = aPart; return ret; } + + void PaintScene(); }; diff --git a/new/sweet_edit.cpp b/new/sweet_edit.cpp index 194e69d6c7..5737b434a9 100644 --- a/new/sweet_edit.cpp +++ b/new/sweet_edit.cpp @@ -68,30 +68,27 @@ private: bool m_isReady; bool m_isPanning; - GRAPHICS_ABSTRACTION_LAYER* m_gal; + SCH::CANVAS* m_gal; wxSize m_screenSize; VECTOR2D m_worldSize; + VECTOR2D m_startMousePoint; + VECTOR2D m_startLookAtPoint; /* double m_alpha; - VECTOR2D m_startMousePoint; - VECTOR2D m_startLookAtPoint; MATRIX3x3D m_startMatrix; STROKE_FONT m_font; */ // Event handlers - /* - void OnTimerEvent( wxTimerEvent &event ); void OnMotion( wxMouseEvent& event ); void OnMouseWheel( wxMouseEvent& event ); - void OnRedraw( wxCommandEvent& event ); void OnRightDown( wxMouseEvent& event ); void OnRightUp( wxMouseEvent& event ); - */ +// void OnRedraw( wxCommandEvent& event ); }; @@ -100,17 +97,24 @@ SWEET_FRAME::SWEET_FRAME( wxWindow* parent, wxWindowID id, const wxString& title wxFrame( parent, id, title, pos, size ), m_screenSize( size.x, size.y ) { - new SWEET_EDITOR_PANEL( this, wxID_ANY, wxPoint( 0, 0 ), wxSize( -1, -1 ), 0 ); + m_isPanning = false; - // Connect( wxEVT_TIMER, wxTimerEventHandler( SWEET_FRAME::OnTimerEvent ) ); + SWEET_EDITOR_PANEL* panel = + new SWEET_EDITOR_PANEL( this, wxID_ANY, wxPoint( 0, 0 ), wxSize( -1, -1 ), 0 ); + + m_gal = (SCH::CANVAS*) panel->FindWindowByName( wxT( "GLCanvas" ), panel ); + + wxASSERT( m_gal ); + + m_gal->SetMouseListener( this ); - /* - Connect( EVT_GAL_REDRAW, wxCommandEventHandler( SWEET_FRAME::OnRedraw ) ); Connect( wxEVT_MOTION, wxMouseEventHandler( SWEET_FRAME::OnMotion ) ); Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( SWEET_FRAME::OnMouseWheel ) ); Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( SWEET_FRAME::OnRightDown ) ); Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( SWEET_FRAME::OnRightUp ) ); -*/ + +// Connect( EVT_GAL_REDRAW, wxCommandEventHandler( SWEET_FRAME::OnRedraw ) ); + /* // Set the world unit length @@ -140,8 +144,50 @@ SWEET_FRAME::~SWEET_FRAME() } +void SWEET_FRAME::OnMotion( wxMouseEvent& event ) +{ + VECTOR2D mousePoint( event.GetX(), event.GetY() ); - // void PaintScene(); + if( event.Dragging() ) + { + if( m_isPanning ) + { + MATRIX3x3D matrix = m_gal->GetWorldScreenMatrix().Inverse(); + VECTOR2D delta = matrix.GetScale().x * ( m_startMousePoint - mousePoint ); + + m_gal->SetLookAtPoint( m_startLookAtPoint + delta ); + + m_gal->PaintScene(); + } + } + else + { + m_gal->DrawCursor( mousePoint ); + } +} + + +void SWEET_FRAME::OnMouseWheel( wxMouseEvent& event ) +{ + double zoomScale = ( event.GetWheelRotation() > 0.0 ) ? 1.1 : 0.9; + + m_gal->SetZoomFactor( m_gal->GetZoomFactor() * zoomScale ); + m_gal->PaintScene(); +} + + +void SWEET_FRAME::OnRightDown( wxMouseEvent& event ) +{ + m_isPanning = true; + m_startMousePoint = VECTOR2D( event.GetX(), event.GetY() ); + m_startLookAtPoint = m_gal->GetLookAtPoint(); +} + + +void SWEET_FRAME::OnRightUp( wxMouseEvent& event ) +{ + m_isPanning = false; +} static const wxCmdLineEntryDesc g_cmdLineDesc[] = { diff --git a/new/sweet_editor_panel.cpp b/new/sweet_editor_panel.cpp index 14f90152ff..d5668bcbb5 100644 --- a/new/sweet_editor_panel.cpp +++ b/new/sweet_editor_panel.cpp @@ -36,13 +36,13 @@ SWEET_EDITOR_PANEL::SWEET_EDITOR_PANEL( wxWindow* parent, wxWindowID id, const w m_scrolledTextWindow->SetSizer( m_scrolledTextSizer ); m_scrolledTextWindow->Layout(); m_scrolledTextSizer->Fit( m_scrolledTextWindow ); - m_gal_scrolled_window = new wxScrolledWindow( m_splitter3, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); + m_gal_scrolled_window = new wxScrolledWindow( m_splitter3, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE|wxHSCROLL|wxVSCROLL ); m_gal_scrolled_window->SetScrollRate( 5, 5 ); wxStaticBoxSizer* m_gal_sizer; m_gal_sizer = new wxStaticBoxSizer( new wxStaticBox( m_gal_scrolled_window, wxID_ANY, _("Visual Part") ), wxVERTICAL ); m_gal = new SCH::CANVAS( m_gal_scrolled_window ); - m_gal_sizer->Add( m_gal, 0, wxALL, 5 ); + m_gal_sizer->Add( m_gal, 1, wxEXPAND, 5 ); m_gal_scrolled_window->SetSizer( m_gal_sizer ); m_gal_scrolled_window->Layout(); diff --git a/new/sweet_editor_panel.fbp b/new/sweet_editor_panel.fbp index 1e378a11f8..29fd265df5 100644 --- a/new/sweet_editor_panel.fbp +++ b/new/sweet_editor_panel.fbp @@ -462,7 +462,7 @@ - + wxID_ANY Sweet @@ -470,11 +470,11 @@ wxVERTICAL none - + 5 wxALL|wxEXPAND 1 - + 1 1 1 @@ -564,8 +564,8 @@ - - + + 1 1 1 @@ -621,7 +621,7 @@ - wxHSCROLL|wxVSCROLL + wxFULL_REPAINT_ON_RESIZE|wxHSCROLL|wxVSCROLL @@ -645,7 +645,7 @@ - + wxID_ANY Visual Part @@ -653,11 +653,11 @@ wxVERTICAL none - + 5 - wxALL - 0 - + wxEXPAND + 1 + 1 1 1 @@ -672,7 +672,7 @@ 1 m_gal = new SCH::CANVAS( m_gal_scrolled_window ); - 1 + 0 SCH::CANVAS* m_gal; 0 Dock @@ -716,7 +716,7 @@ - + wxFULL_REPAINT_ON_RESIZE