diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index f80862e264..7ccb9764c2 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -32,6 +32,7 @@ set(GAL_SRCS # Common part drawpanel_gal.cpp painter.cpp + worksheet_item.cpp gal/graphics_abstraction_layer.cpp gal/stroke_font.cpp gal/color4d.cpp @@ -156,17 +157,17 @@ set(COMMON_SRCS system/fcontext.s - tool/tool_base.cpp - tool/tool_manager.cpp - tool/tool_dispatcher.cpp - tool/tool_event.cpp - tool/tool_interactive.cpp - tool/context_menu.cpp - - geometry/seg.cpp - geometry/shape_line_chain.cpp - geometry/shape_collisions.cpp - ) + tool/tool_base.cpp + tool/tool_manager.cpp + tool/tool_dispatcher.cpp + tool/tool_event.cpp + tool/tool_interactive.cpp + tool/context_menu.cpp + + geometry/seg.cpp + geometry/shape_line_chain.cpp + geometry/shape_collisions.cpp +) add_library(common STATIC ${COMMON_SRCS}) diff --git a/common/drawframe.cpp b/common/drawframe.cpp index 9c0e500778..b0f27cc002 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -981,18 +981,16 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) // Switch to GAL rendering if( !m_galCanvasActive ) { - // Set up grid settings - gal->SetGridVisibility( IsGridVisible() ); - gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) ); - gal->SetGridOrigin( VECTOR2D( screen->GetGridOrigin() ) ); - gal->SetGridOriginMarkerSize( 15 ); - gal->SetGridDrawThreshold( 10 ); - // Set up viewport double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() ); view->SetScale( zoom ); view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); } + + // Set up grid settings + gal->SetGridVisibility( IsGridVisible() ); + gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) ); + gal->SetGridOrigin( VECTOR2D( screen->GetGridOrigin() ) ); } else { diff --git a/common/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index 9363e099f6..7087d1e86d 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -90,9 +90,10 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin Connect( wxEVT_CHAR_HOOK, wxEventHandler( EDA_DRAW_PANEL_GAL::skipEvent ) ); Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); - Connect( wxEVT_ENTER_WINDOW, wxEventHandler (EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); + Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); + Connect( TOOL_DISPATCHER::EVT_REFRESH_MOUSE, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), + NULL, this ); - m_refreshTimer.SetOwner( this ); Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this ); @@ -108,7 +109,7 @@ EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL() if( m_viewControls ) delete m_viewControls; - if( m_view ) + if( m_view ) delete m_view; if( m_gal ) @@ -130,7 +131,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) ); m_gal->ClearScreen(); - m_view->PrepareTargets(); + m_view->ClearTargets(); // Grid has to be redrawn only when the NONCACHED target is redrawn if( m_view->IsTargetDirty( KiGfx::TARGET_NONCACHED ) ) m_gal->DrawGrid(); @@ -164,19 +165,22 @@ void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent ) void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect ) { - if(m_pendingRefresh) + if( m_pendingRefresh ) return; wxLongLong t = wxGetLocalTimeMillis(); wxLongLong delta = t - m_lastRefresh; - if(t >= MinRefreshPeriod) + if( delta >= MinRefreshPeriod ) { wxPaintEvent redrawEvent; wxPostEvent( this, redrawEvent ); m_pendingRefresh = true; - } else { - m_refreshTimer.Start ( (MinRefreshPeriod - t).ToLong(), true ); + } + else + { + // One shot timer + m_refreshTimer.Start( ( MinRefreshPeriod - delta ).ToLong(), true ); m_pendingRefresh = true; } } @@ -236,16 +240,17 @@ void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) m_eventDispatcher->DispatchWxEvent( aEvent ); } - if(m_view->IsDirty()) - Refresh(); + Refresh(); } -void EDA_DRAW_PANEL_GAL::onEnter ( wxEvent& aEvent ) +void EDA_DRAW_PANEL_GAL::onEnter( wxEvent& aEvent ) { + // Getting focus is necessary in order to receive key events properly SetFocus(); } + void EDA_DRAW_PANEL_GAL::skipEvent( wxEvent& aEvent ) { // This is necessary for CHAR_HOOK event to generate KEY_UP and KEY_DOWN events diff --git a/common/gal/color4d.cpp b/common/gal/color4d.cpp index bf93cfb736..b9f6557204 100644 --- a/common/gal/color4d.cpp +++ b/common/gal/color4d.cpp @@ -30,9 +30,9 @@ using namespace KiGfx; COLOR4D::COLOR4D( EDA_COLOR_T aColor ) { - r = g_ColorRefs[aColor].m_Red; - g = g_ColorRefs[aColor].m_Green; - b = g_ColorRefs[aColor].m_Blue; + r = g_ColorRefs[aColor].m_Red / 255.0; + g = g_ColorRefs[aColor].m_Green / 255.0; + b = g_ColorRefs[aColor].m_Blue / 255.0; a = 1.0; } @@ -59,91 +59,102 @@ const bool COLOR4D::operator!=( const COLOR4D& aColor ) return a != aColor.a || r != aColor.r || g != aColor.g || b != aColor.b; } -void COLOR4D::ToHSV(double& out_h, double& out_s, double& out_v) const + +void COLOR4D::ToHSV( double& aOutH, double& aOutS, double& aOutV ) const { - double min, max, delta; + double min, max, delta; min = r < g ? r : g; - min = min < b ? min : b; + min = min < b ? min : b; max = r > g ? r : g; - max = max > b ? max : b; + max = max > b ? max : b; - out_v = max; // v + aOutV = max; // v delta = max - min; - - if( max > 0.0 ) { - out_s = (delta / max); // s - } else { + + if( max > 0.0 ) + { + aOutS = ( delta / max ); // s + } + else + { // r = g = b = 0 // s = 0, v is undefined - out_s = 0.0; - out_h = NAN; // its now undefined + aOutS = 0.0; + aOutH = NAN; // its now undefined return; } - if( r >= max ) // > is bogus, just keeps compilor happy - out_h = ( g - b ) / delta; // between yellow & magenta - else - if( g >= max ) - out_h = 2.0 + ( b - r ) / delta; // between cyan & yellow - else - out_h = 4.0 + ( r - g ) / delta; // between magenta & cyan - out_h *= 60.0; // degrees + if( r >= max ) // > is bogus, just keeps compiler happy + aOutH = ( g - b ) / delta; // between yellow & magenta + else if( g >= max ) + aOutH = 2.0 + ( b - r ) / delta; // between cyan & yellow + else + aOutH = 4.0 + ( r - g ) / delta; // between magenta & cyan - if( out_h < 0.0 ) - out_h += 360.0; + aOutH *= 60.0; // degrees + + if( aOutH < 0.0 ) + aOutH += 360.0; } -void COLOR4D::FromHSV(double in_h, double in_s, double in_v) -{ - double hh, p, q, t, ff; - long i; - if(in_s <= 0.0) { // < is bogus, just shuts up warnings - r = in_v; - g = in_v; - b = in_v; +void COLOR4D::FromHSV( double aInH, double aInS, double aInV ) +{ + double hh, p, q, t, ff; + long i; + + if( aInS <= 0.0 ) // < is bogus, just shuts up warnings + { + r = aInV; + g = aInV; + b = aInV; return; } - hh = in_h; - if(hh >= 360.0) hh = 0.0; - hh /= 60.0; - i = (long)hh; - ff = hh - i; - p = in_v * (1.0 - in_s); - q = in_v * (1.0 - (in_s * ff)); - t = in_v * (1.0 - (in_s * (1.0 - ff))); - switch(i) { + hh = aInH; + if( hh >= 360.0 ) + hh = 0.0; + hh /= 60.0; + + i = (long) hh; + ff = hh - i; + + p = aInV * ( 1.0 - aInS ); + q = aInV * ( 1.0 - ( aInS * ff ) ); + t = aInV * ( 1.0 - ( aInS * ( 1.0 - ff ) ) ); + + switch (i) + { case 0: - r = in_v; + r = aInV; g = t; b = p; break; case 1: r = q; - g = in_v; + g = aInV; b = p; break; case 2: r = p; - g = in_v; + g = aInV; b = t; break; case 3: r = p; g = q; - b = in_v; + b = aInV; break; case 4: r = t; g = p; - b = in_v; + b = aInV; break; case 5: default: - r = in_v; + r = aInV; g = p; b = q; break; @@ -151,12 +162,13 @@ void COLOR4D::FromHSV(double in_h, double in_s, double in_v) } + COLOR4D& COLOR4D::Saturate( double aFactor ) { double h, s, v; - ToHSV(h, s, v); - FromHSV(h, aFactor, 1.0); + ToHSV( h, s, v ); + FromHSV( h, aFactor, 1.0 ); return *this; } - \ No newline at end of file + diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index 50e3d5723d..0282e69327 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -29,7 +29,6 @@ #include #include - using namespace KiGfx; GAL::GAL() : @@ -41,19 +40,21 @@ GAL::GAL() : SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) ); SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); SetZoomFactor( 1.0 ); - SetDepthRange( VECTOR2D( -2048, 2047 ) ); + SetDepthRange( VECTOR2D( GAL::MIN_DEPTH, GAL::MAX_DEPTH ) ); SetFlip( false, false ); SetLineWidth( 1.0 ); // Set grid defaults SetGridVisibility( true ); SetGridStyle( GRID_STYLE_LINES ); + SetGridOriginMarkerSize( 15 ); + SetGridDrawThreshold( 10 ); SetCoarseGrid( 10 ); SetGridLineWidth( 0.5 ); // Initialize the cursor shape SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); - SetCursorSize( 20 ); + SetCursorSize( 15 ); SetCursorEnabled( true ); strokeFont.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize ); @@ -112,7 +113,7 @@ void GAL::DrawGrid() // Draw the origin marker double origSize = static_cast( gridOriginMarkerSize ) / worldScale; - SetLayerDepth( 0.0 ); + SetLayerDepth( GAL::GRID_DEPTH ); SetIsFill( false ); SetIsStroke( true ); SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); diff --git a/common/gal/opengl/cached_container.cpp b/common/gal/opengl/cached_container.cpp index ea718530ce..12682d858f 100644 --- a/common/gal/opengl/cached_container.cpp +++ b/common/gal/opengl/cached_container.cpp @@ -42,7 +42,7 @@ using namespace KiGfx; CACHED_CONTAINER::CACHED_CONTAINER( unsigned int aSize ) : - VERTEX_CONTAINER( aSize ) + VERTEX_CONTAINER( aSize ), m_item( NULL ) { // In the beginning there is only free space m_freeChunks.insert( Chunk( aSize, 0 ) ); @@ -51,35 +51,45 @@ CACHED_CONTAINER::CACHED_CONTAINER( unsigned int aSize ) : void CACHED_CONTAINER::SetItem( VERTEX_ITEM* aItem ) { - if( aItem == NULL ) - { - wxASSERT( m_item != NULL ); + wxASSERT( aItem != NULL ); - // Finishing the item - if( m_itemSize < m_chunkSize ) - { - // There is some not used but reserved memory left, so we should return it to the pool - int itemOffset = m_item->GetOffset(); + m_item = aItem; + m_itemSize = m_item->GetSize(); + m_chunkSize = m_itemSize; - // Add the not used memory back to the pool - m_freeChunks.insert( Chunk( m_chunkSize - m_itemSize, itemOffset + m_itemSize ) ); - m_freeSpace += ( m_chunkSize - m_itemSize ); - // mergeFreeChunks(); - } - - m_item = NULL; - } + if( m_itemSize == 0 ) + m_items.insert( m_item ); // The item was not stored before else - { - m_item = aItem; - m_itemSize = m_item->GetSize(); - m_chunkSize = m_itemSize; + m_chunkOffset = m_item->GetOffset(); - if( m_itemSize == 0 ) - m_items.insert( m_item ); // The item was not stored before - else - m_chunkOffset = m_item->GetOffset(); +#if CACHED_CONTAINER_TEST > 1 + wxLogDebug( wxT( "Adding/editing item 0x%08lx (size %d)" ), (long) m_item, m_itemSize ); +#endif +} + + +void CACHED_CONTAINER::FinishItem() +{ + wxASSERT( m_item != NULL ); + wxASSERT( m_item->GetSize() == m_itemSize ); + + // Finishing the previously edited item + if( m_itemSize < m_chunkSize ) + { + // There is some not used but reserved memory left, so we should return it to the pool + int itemOffset = m_item->GetOffset(); + + // Add the not used memory back to the pool + m_freeChunks.insert( Chunk( m_chunkSize - m_itemSize, itemOffset + m_itemSize ) ); + m_freeSpace += ( m_chunkSize - m_itemSize ); + // mergeFreeChunks(); // veery slow and buggy } + +#if CACHED_CONTAINER_TEST > 1 + wxLogDebug( wxT( "Finishing item 0x%08lx (size %d)" ), (long) m_item, m_itemSize ); + test(); + m_item = NULL; // electric fence +#endif } @@ -109,6 +119,7 @@ VERTEX* CACHED_CONTAINER::Allocate( unsigned int aSize ) VERTEX* reserved = &m_vertices[m_chunkOffset + m_itemSize]; m_itemSize += aSize; + // Now the item officially possesses the memory chunk m_item->setSize( m_itemSize ); // The content has to be updated @@ -117,16 +128,40 @@ VERTEX* CACHED_CONTAINER::Allocate( unsigned int aSize ) #if CACHED_CONTAINER_TEST > 1 test(); #endif +#if CACHED_CONTAINER_TEST > 2 + showFreeChunks(); + showReservedChunks(); +#endif return reserved; } -void CACHED_CONTAINER::Erase() +void CACHED_CONTAINER::Delete( VERTEX_ITEM* aItem ) { - wxASSERT( m_item != NULL ); + wxASSERT( aItem != NULL ); + wxASSERT( m_items.find( aItem ) != m_items.end() ); - freeItem( m_item ); + int size = aItem->GetSize(); + int offset = aItem->GetOffset(); + +#if CACHED_CONTAINER_TEST > 1 + wxLogDebug( wxT( "Removing 0x%08lx (size %d offset %d)" ), (long) aItem, size, offset ); +#endif + + // Insert a free memory chunk entry in the place where item was stored + if( size > 0 ) + { + m_freeChunks.insert( Chunk( size, offset ) ); + m_freeSpace += size; + // Indicate that the item is not stored in the container anymore + aItem->setSize( 0 ); + } + m_items.erase( aItem ); + +#if CACHED_CONTAINER_TEST > 1 + test(); +#endif // Dynamic memory freeing, there is no point in holding // a large amount of memory when there is no use for it @@ -176,10 +211,10 @@ VERTEX* CACHED_CONTAINER::GetVertices( const VERTEX_ITEM* aItem ) const unsigned int CACHED_CONTAINER::reallocate( unsigned int aSize ) { + wxASSERT( aSize > 0 ); + #if CACHED_CONTAINER_TEST > 2 - wxLogDebug( wxT( "Resize 0x%08x to %d" ), (int) m_item, aSize ); - showFreeChunks(); - showReservedChunks(); + wxLogDebug( wxT( "Resize 0x%08lx from %d to %d" ), (long) m_item, m_itemSize, aSize ); #endif // Is there enough space to store vertices? @@ -203,7 +238,7 @@ unsigned int CACHED_CONTAINER::reallocate( unsigned int aSize ) return UINT_MAX; } - // Look for the free space of at least given size + // Look for the free space chunk of at least given size FreeChunkMap::iterator newChunk = m_freeChunks.lower_bound( aSize ); if( newChunk == m_freeChunks.end() ) @@ -240,6 +275,7 @@ unsigned int CACHED_CONTAINER::reallocate( unsigned int aSize ) m_itemSize * VertexSize ); // Free the space previously used by the chunk + wxASSERT( m_itemSize > 0 ); m_freeChunks.insert( Chunk( m_itemSize, m_chunkOffset ) ); m_freeSpace += m_itemSize; } @@ -254,15 +290,10 @@ unsigned int CACHED_CONTAINER::reallocate( unsigned int aSize ) } m_freeSpace -= aSize; - // mergeFreeChunks(); + // mergeFreeChunks(); // veery slow and buggy m_item->setOffset( chunkOffset ); -#if CACHED_CONTAINER_TEST > 2 - showFreeChunks(); - showReservedChunks(); -#endif - return chunkOffset; } @@ -271,11 +302,10 @@ bool CACHED_CONTAINER::defragment( VERTEX* aTarget ) { #if CACHED_CONTAINER_TEST > 0 wxLogDebug( wxT( "Defragmenting" ) ); -#endif -#ifdef __WXDEBUG__ + prof_counter totalTime; prof_start( &totalTime, false ); -#endif /* __WXDEBUG__ */ +#endif if( aTarget == NULL ) { @@ -313,14 +343,15 @@ bool CACHED_CONTAINER::defragment( VERTEX* aTarget ) // Now there is only one big chunk of free memory m_freeChunks.clear(); + wxASSERT( m_freeSpace > 0 ); m_freeChunks.insert( Chunk( m_freeSpace, m_currentSize - m_freeSpace ) ); -#ifdef __WXDEBUG__ +#if CACHED_CONTAINER_TEST > 0 prof_end( &totalTime ); wxLogDebug( wxT( "Defragmented the container storing %d vertices / %.1f ms" ), m_currentSize - m_freeSpace, (double) totalTime.value / 1000.0 ); -#endif /* __WXDEBUG__ */ +#endif return true; } @@ -331,10 +362,10 @@ void CACHED_CONTAINER::mergeFreeChunks() if( m_freeChunks.size() <= 1 ) // There are no chunks that can be merged return; -#ifdef __WXDEBUG__ +#ifdef CACHED_CONTAINER_TEST > 0 prof_counter totalTime; prof_start( &totalTime, false ); -#endif /* __WXDEBUG__ */ +#endif // Reversed free chunks map - this one stores chunk size with its offset as the key std::list freeChunks; @@ -375,11 +406,11 @@ void CACHED_CONTAINER::mergeFreeChunks() // Add the last one m_freeChunks.insert( std::make_pair( size, offset ) ); -#ifdef __WXDEBUG__ +#ifdef CACHED_CONTAINER_TEST > 0 prof_end( &totalTime ); wxLogDebug( wxT( "Merged free chunks / %.1f ms" ), (double) totalTime.value / 1000.0 ); -#endif /* __WXDEBUG__ */ +#endif test(); } @@ -387,6 +418,8 @@ void CACHED_CONTAINER::mergeFreeChunks() bool CACHED_CONTAINER::resizeContainer( unsigned int aNewSize ) { + wxASSERT( aNewSize != m_currentSize ); + #if CACHED_CONTAINER_TEST > 0 wxLogDebug( wxT( "Resizing container from %d to %d" ), m_currentSize, aNewSize ); #endif @@ -413,6 +446,7 @@ bool CACHED_CONTAINER::resizeContainer( unsigned int aNewSize ) // We have to correct freeChunks after defragmentation m_freeChunks.clear(); + wxASSERT( aNewSize - reservedSpace() > 0 ); m_freeChunks.insert( Chunk( aNewSize - reservedSpace(), reservedSpace() ) ); } else @@ -439,21 +473,6 @@ bool CACHED_CONTAINER::resizeContainer( unsigned int aNewSize ) } -void CACHED_CONTAINER::freeItem( VERTEX_ITEM* aItem ) -{ - int size = aItem->GetSize(); - int offset = aItem->GetOffset(); - - // Insert a free memory chunk entry in the place where item was stored - m_freeChunks.insert( Chunk( size, offset ) ); - m_freeSpace += size; - m_items.erase( aItem ); - - // Indicate that the item is not stored in the container anymore - aItem->setSize( 0 ); -} - - unsigned int CACHED_CONTAINER::getPowerOf2( unsigned int aNumber ) const { unsigned int power = 1; @@ -476,6 +495,7 @@ void CACHED_CONTAINER::showFreeChunks() { unsigned int offset = getChunkOffset( *it ); unsigned int size = getChunkSize( *it ); + wxASSERT( size > 0 ); wxLogDebug( wxT( "[0x%08x-0x%08x] (size %d)" ), offset, offset + size - 1, size ); @@ -494,9 +514,10 @@ void CACHED_CONTAINER::showReservedChunks() VERTEX_ITEM* item = *it; unsigned int offset = item->GetOffset(); unsigned int size = item->GetSize(); + wxASSERT( size > 0 ); - wxLogDebug( wxT( "[0x%08x-0x%08x] @ 0x%08x (size %d)" ), - offset, offset + size - 1, (int) item, size ); + wxLogDebug( wxT( "[0x%08x-0x%08x] @ 0x%08lx (size %d)" ), + offset, offset + size - 1, (long) item, size ); } } diff --git a/common/gal/opengl/noncached_container.cpp b/common/gal/opengl/noncached_container.cpp index f7eb3f897a..9c2ab066f8 100644 --- a/common/gal/opengl/noncached_container.cpp +++ b/common/gal/opengl/noncached_container.cpp @@ -82,11 +82,6 @@ VERTEX* NONCACHED_CONTAINER::Allocate( unsigned int aSize ) } -void NONCACHED_CONTAINER::Erase() -{ -} - - void NONCACHED_CONTAINER::Clear() { m_freePtr = 0; diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 4d40e28978..07b5238cf1 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -233,8 +233,11 @@ void OPENGL_GAL::DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoin drawLineQuad( aStartPoint, aEndPoint ); // Line caps - drawFilledSemiCircle( aStartPoint, lineWidth / 2, lineAngle + M_PI / 2 ); - drawFilledSemiCircle( aEndPoint, lineWidth / 2, lineAngle - M_PI / 2 ); + if( lineWidth > 1.0 ) + { + drawFilledSemiCircle( aStartPoint, lineWidth / 2, lineAngle + M_PI / 2 ); + drawFilledSemiCircle( aEndPoint, lineWidth / 2, lineAngle - M_PI / 2 ); + } } @@ -638,6 +641,7 @@ int OPENGL_GAL::BeginGroup() void OPENGL_GAL::EndGroup() { + cachedManager.FinishItem(); isGrouping = false; } @@ -662,6 +666,7 @@ void OPENGL_GAL::ChangeGroupDepth( int aGroupNumber, int aDepth ) void OPENGL_GAL::DeleteGroup( int aGroupNumber ) { + // Frees memory in the container as well groups.erase( aGroupNumber ); } diff --git a/common/gal/opengl/vertex_manager.cpp b/common/gal/opengl/vertex_manager.cpp index 876a793241..65a80826f7 100644 --- a/common/gal/opengl/vertex_manager.cpp +++ b/common/gal/opengl/vertex_manager.cpp @@ -88,10 +88,15 @@ void VERTEX_MANAGER::SetItem( VERTEX_ITEM& aItem ) const } +void VERTEX_MANAGER::FinishItem() const +{ + m_container->FinishItem(); +} + + void VERTEX_MANAGER::FreeItem( VERTEX_ITEM& aItem ) const { - m_container->SetItem( &aItem ); - m_container->Erase(); + m_container->Delete( &aItem ); } diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index 7eaef89d57..8c7f70131d 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -1488,12 +1488,12 @@ bool ColorIsLight( EDA_COLOR_T aColor ) EDA_COLOR_T ColorFindNearest( const wxColour &aColor ) { - EDA_COLOR_T candidate = BLACK; + return ColorFindNearest( aColor.Red(), aColor.Green(), aColor.Blue() ); +} - // These are ints because we will subtract them later - int r = aColor.Red(); - int g = aColor.Green(); - int b = aColor.Blue(); +EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB ) +{ + EDA_COLOR_T candidate = BLACK; /* Find the 'nearest' color in the palette. This is fun. There is a gazilion of metrics for the color space and no one of the @@ -1511,11 +1511,11 @@ EDA_COLOR_T ColorFindNearest( const wxColour &aColor ) for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) ) { const StructColors &c = g_ColorRefs[trying]; - int distance = (r - c.m_Red) * (r - c.m_Red) + - (g - c.m_Green) * (g - c.m_Green) + - (b - c.m_Blue) * (b - c.m_Blue); - if( distance < nearest_distance && c.m_Red >= r && - c.m_Green >= g && c.m_Blue >= b ) + int distance = (aR - c.m_Red) * (aR - c.m_Red) + + (aG - c.m_Green) * (aG - c.m_Green) + + (aB - c.m_Blue) * (aB - c.m_Blue); + if( distance < nearest_distance && c.m_Red >= aR && + c.m_Green >= aG && c.m_Blue >= aB ) { nearest_distance = distance; candidate = trying; diff --git a/common/painter.cpp b/common/painter.cpp index 5787b5427c..ddff0c9820 100644 --- a/common/painter.cpp +++ b/common/painter.cpp @@ -32,13 +32,14 @@ using namespace KiGfx; RENDER_SETTINGS::RENDER_SETTINGS() { // Set the default initial values - m_highlightFactor = 0.5; - m_selectFactor = 0.5; - m_layerOpacity = 0.8; - m_highlightEnabled = false; - m_hiContrastEnabled = false; - m_hiContrastFactor = 0.2; - m_outlineWidth = 1; + m_highlightFactor = 0.5; + m_selectFactor = 0.5; + m_layerOpacity = 0.8; + m_highlightEnabled = false; + m_hiContrastEnabled = false; + m_hiContrastFactor = 0.2; + m_outlineWidth = 1; + m_worksheetLineWidth = 100000; // Store the predefined colors used in KiCad in format used by GAL for( int i = 0; i < NBCOLORS; i++ ) @@ -64,14 +65,13 @@ void RENDER_SETTINGS::update() PAINTER::PAINTER( GAL* aGal ) : - m_gal( aGal ), m_settings( NULL ), m_brightenedColor( 0.0, 1.0, 0.0, 0.9 ) + m_gal( aGal ), m_brightenedColor( 0.0, 1.0, 0.0, 0.9 ) { } PAINTER::~PAINTER() { - delete m_settings; } @@ -91,7 +91,7 @@ void PAINTER::DrawBrightened( const VIEW_ITEM* aItem ) m_gal->PushDepth(); m_gal->SetLayerDepth( -1.0 ); - // Draw semitransparent box that marks items as brightened + // Draw an outline that marks items as brightened m_gal->SetIsStroke( true ); m_gal->SetLineWidth( 100000.0 ); m_gal->SetStrokeColor( m_brightenedColor ); diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index 98925eb704..951351017a 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -47,7 +47,7 @@ public: else if( type == wxEVT_COMMAND_MENU_SELECTED ) evt = TOOL_EVENT( TC_Command, TA_ContextMenuChoice, aEvent.GetId() ); - if(m_menu->m_tool) + if( m_menu->m_tool ) m_menu->m_tool->GetManager()->ProcessEvent( evt ); } diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 06702b6817..03ff9ef9b3 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -41,6 +41,8 @@ using boost::optional; +const wxEventType TOOL_DISPATCHER::EVT_REFRESH_MOUSE = wxNewEventType(); + struct TOOL_DISPATCHER::ButtonState { ButtonState( TOOL_MouseButtons aButton, const wxEventType& aDownEvent, @@ -119,14 +121,16 @@ int TOOL_DISPATCHER::decodeModifiers( const wxKeyboardState* aState ) const return mods; } -wxPoint TOOL_DISPATCHER::getCurrentMousePos() -{ - wxPoint msp = wxGetMousePosition() ; - wxPoint winp = m_editFrame->GetGalCanvas()->GetScreenPosition(); - return wxPoint(msp.x - winp.x, msp.y - winp.y); +wxPoint TOOL_DISPATCHER::getCurrentMousePos() const +{ + wxPoint msp = wxGetMousePosition(); + wxPoint winp = m_editFrame->GetGalCanvas()->GetScreenPosition(); + + return wxPoint( msp.x - winp.x, msp.y - winp.y ); } + bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ) { ButtonState* st = m_buttons[aIndex]; @@ -157,7 +161,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti { wxLongLong t = wxGetLocalTimeMillis(); - if( t - st->downTimestamp < DragTimeThreshold || + if( t - st->downTimestamp < DragTimeThreshold && st->dragMaxDelta < DragDistanceThreshold ) isClick = true; else @@ -181,7 +185,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti wxLongLong t = wxGetLocalTimeMillis(); - if( t - st->downTimestamp > DragTimeThreshold && st->dragMaxDelta > DragDistanceThreshold ) + if( t - st->downTimestamp > DragTimeThreshold || st->dragMaxDelta > DragDistanceThreshold ) { evt = TOOL_EVENT( TC_Mouse, TA_MouseDrag, args ); evt->SetMouseDragOrigin( st->dragOrigin ); @@ -213,13 +217,11 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) if( type == wxEVT_MOTION || type == wxEVT_MOUSEWHEEL || type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP || - type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP ) + type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP || + type == EVT_REFRESH_MOUSE ) { - wxMouseEvent* me = static_cast( &aEvent ); - - pos = getView()->ToWorld ( getCurrentMousePos() ); - if( pos != m_lastMousePos ) + if( pos != m_lastMousePos || type == EVT_REFRESH_MOUSE ) { motion = true; m_lastMousePos = pos; @@ -262,7 +264,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) } -void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent &aEvent ) +void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent& aEvent ) { bool activateTool = false; std::string toolName; diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 268130bc3b..9e0b4ac621 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -82,13 +82,25 @@ struct TOOL_MANAGER::TOOL_STATE TOOL_MANAGER::TOOL_MANAGER() : - m_model (NULL), - m_view (NULL) + m_model( NULL ), m_view( NULL ) { } +TOOL_MANAGER::~TOOL_MANAGER() +{ + std::map::iterator it, it_end; + + for( it = m_toolState.begin(), it_end = m_toolState.end(); it != it_end; ++it ) + { + delete it->second->cofunc; // delete cofunction + delete it->second; // delete TOOL_STATE + delete it->first; // delete the tool itself + } +} + + void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool ) { TOOL_STATE* st = new TOOL_STATE; @@ -282,13 +294,13 @@ bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent ) if( st->contextMenuTrigger != CMENU_OFF ) { - if(st->contextMenuTrigger == CMENU_BUTTON && !aEvent.IsClick( MB_Right ) ) + if( st->contextMenuTrigger == CMENU_BUTTON && !aEvent.IsClick( MB_Right ) ) break; st->pendingWait = true; st->waitEvents = TOOL_EVENT( TC_Any, TA_Any ); - if(st->contextMenuTrigger == CMENU_NOW) + if( st->contextMenuTrigger == CMENU_NOW ) st->contextMenuTrigger = CMENU_OFF; GetEditFrame()->PopupMenu( st->contextMenu->GetMenu() ); diff --git a/common/view/view.cpp b/common/view/view.cpp index f8ba2db28f..4409806c3c 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -41,7 +41,7 @@ using namespace KiGfx; VIEW::VIEW( bool aIsDynamic ) : - m_enableOrderModifier( false ), + m_enableOrderModifier( true ), m_scale( 1.0 ), m_painter( NULL ), m_gal( NULL ), @@ -80,7 +80,6 @@ void VIEW::AddLayer( int aLayer, bool aDisplayOnly ) m_layers[aLayer].items = new VIEW_RTREE(); m_layers[aLayer].renderingOrder = aLayer; m_layers[aLayer].enabled = true; - m_layers[aLayer].isDirty = false; m_layers[aLayer].displayOnly = aDisplayOnly; m_layers[aLayer].target = TARGET_CACHED; } @@ -100,7 +99,7 @@ void VIEW::Add( VIEW_ITEM* aItem ) { VIEW_LAYER& l = m_layers[layers[i]]; l.items->Insert( aItem ); - l.isDirty = true; + MarkTargetDirty( l.target ); } if( m_dynamic ) @@ -120,7 +119,6 @@ void VIEW::Remove( VIEW_ITEM* aItem ) { VIEW_LAYER& l = m_layers[layers[i]]; l.items->Remove( aItem ); - l.isDirty = true; } } @@ -370,7 +368,7 @@ struct VIEW::updateItemsColor void operator()( VIEW_ITEM* aItem ) { // Obtain the color that should be used for coloring the item - const COLOR4D color = painter->GetColor( aItem, layer ); + const COLOR4D color = painter->GetSettings()->GetColor( aItem, layer ); int group = aItem->getGroup( layer ); if( group >= 0 ) @@ -415,6 +413,8 @@ void VIEW::UpdateAllLayersColor() updateItemsColor visitor( l->id, m_painter, m_gal ); l->items->Query( r, visitor ); } + + MarkDirty(); } @@ -525,6 +525,8 @@ void VIEW::UpdateAllLayersOrder() { ChangeLayerDepth( l.first, l.second.renderingOrder ); } + + MarkDirty(); } @@ -564,8 +566,6 @@ void VIEW::redrawRect( const BOX2I& aRect ) m_gal->SetLayerDepth( l->renderingOrder ); l->items->Query( aRect, drawFunc ); } - - l->isDirty = false; } } @@ -586,7 +586,7 @@ void VIEW::draw( VIEW_ITEM* aItem, int aLayer, bool aImmediate ) const group = m_gal->BeginGroup(); aItem->setGroup( aLayer, group ); if( !m_painter->Draw( aItem, aLayer ) ) - aItem->ViewDraw( aLayer, m_gal, BOX2I() ); // Alternative drawing method + aItem->ViewDraw( aLayer, m_gal ); // Alternative drawing method m_gal->EndGroup(); } } @@ -594,7 +594,7 @@ void VIEW::draw( VIEW_ITEM* aItem, int aLayer, bool aImmediate ) const { // Immediate mode if( !m_painter->Draw( aItem, aLayer ) ) - aItem->ViewDraw( aLayer, m_gal, BOX2I() ); // Alternative drawing method + aItem->ViewDraw( aLayer, m_gal ); // Alternative drawing method } // Draws a bright contour around the item @@ -672,7 +672,8 @@ struct VIEW::recacheLayer { int group = gal->BeginGroup(); aItem->setGroup( layer, group ); - view->m_painter->Draw( static_cast( aItem ), layer ); + if( !view->m_painter->Draw( aItem, layer ) ) + aItem->ViewDraw( layer, gal ); // Alternative drawing method gal->EndGroup(); } else @@ -709,7 +710,7 @@ void VIEW::Clear() } -void VIEW::PrepareTargets() +void VIEW::ClearTargets() { if( IsTargetDirty( TARGET_CACHED ) || IsTargetDirty( TARGET_NONCACHED ) ) { @@ -810,8 +811,7 @@ void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags ) } // Mark those layers as dirty, so the VIEW will be refreshed - m_layers[layerId].isDirty = true; - MarkTargetDirty( m_layers[layerId].target ); // TODO remove? + MarkTargetDirty( m_layers[layerId].target ); } } @@ -836,7 +836,7 @@ void VIEW::updateItemColor( VIEW_ITEM* aItem, int aLayer ) wxASSERT( (unsigned) aLayer < m_layers.size() ); // Obtain the color that should be used for coloring the item on the specific layerId - const COLOR4D color = m_painter->GetColor( aItem, aLayer ); + const COLOR4D color = m_painter->GetSettings()->GetColor( aItem, aLayer ); int group = aItem->getGroup( aLayer ); // Change the color, only if it has group assigned @@ -871,7 +871,7 @@ void VIEW::updateBbox( VIEW_ITEM* aItem ) VIEW_LAYER& l = m_layers[layers[i]]; l.items->Remove( aItem ); l.items->Insert( aItem ); - l.isDirty = true; + MarkTargetDirty( l.target ); } } @@ -915,7 +915,7 @@ void VIEW::RecacheAllItems( bool aImmediately ) m_gal->SetLayerDepth( l->renderingOrder ); recacheLayer visitor( this, m_gal, l->id, aImmediately ); l->items->Query( r, visitor ); - l->isDirty = true; + MarkTargetDirty( l->target ); } } @@ -936,12 +936,5 @@ bool VIEW::IsTargetDirty( int aTarget ) const if( m_dirtyTargets[aTarget] ) return true; - // Check if any of layers belonging to the target is dirty - BOOST_FOREACH( VIEW_LAYER* l, m_orderedLayers ) - { - if( l->target == aTarget && l->isDirty ) - return true; - } - return false; } diff --git a/common/view/view_group.cpp b/common/view/view_group.cpp index 2e3c72af69..dfaf595c5c 100644 --- a/common/view/view_group.cpp +++ b/common/view/view_group.cpp @@ -70,6 +70,7 @@ void VIEW_GROUP::Clear() m_items.clear(); } + void VIEW_GROUP::FreeItems() { BOOST_FOREACH( VIEW_ITEM* item, m_items ) @@ -79,6 +80,7 @@ void VIEW_GROUP::FreeItems() m_items.clear(); } + unsigned int VIEW_GROUP::GetSize() const { return m_items.size(); @@ -93,7 +95,7 @@ const BOX2I VIEW_GROUP::ViewBBox() const } -void VIEW_GROUP::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const +void VIEW_GROUP::ViewDraw( int aLayer, GAL* aGal ) const { PAINTER* painter = m_view->GetPainter(); @@ -111,7 +113,7 @@ void VIEW_GROUP::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) co aGal->SetLayerDepth( m_view->GetLayerOrder( layers[i] ) ); if( !painter->Draw( item, layers[i] ) ) - item->ViewDraw( layers[i], aGal, aVisibleArea ); // Alternative drawing method + item->ViewDraw( layers[i], aGal ); // Alternative drawing method } } } diff --git a/common/view/view_item.cpp b/common/view/view_item.cpp index 4104d06c1a..d7e563109b 100644 --- a/common/view/view_item.cpp +++ b/common/view/view_item.cpp @@ -48,17 +48,12 @@ void VIEW_ITEM::ViewSetVisible( bool aIsVisible ) } -void VIEW_ITEM::ViewUpdate( int aUpdateFlags, bool aForceImmediateRedraw ) +void VIEW_ITEM::ViewUpdate( int aUpdateFlags ) { if( !m_view ) return; m_view->invalidateItem( this, aUpdateFlags ); - - if( aForceImmediateRedraw ) - { - m_view->Redraw(); - } } @@ -142,9 +137,3 @@ void VIEW_ITEM::deleteGroups() m_groups = NULL; m_groupsSize = 0; } - - -bool VIEW_ITEM::storesGroups() const -{ - return ( m_groupsSize > 0 ); -} diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 5cbc97f9cf..1349948501 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -28,6 +28,7 @@ #include #include #include +#include using namespace KiGfx; @@ -196,7 +197,10 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) dir = m_view->ToWorld( dir, false ); m_view->SetCenter( m_view->GetCenter() + dir * m_autoPanSpeed ); - m_view->MakeDirty(); + + // Notify tools that the cursor position has changed in the world coordinates + wxCommandEvent moveEvent( TOOL_DISPATCHER::EVT_REFRESH_MOUSE ); + wxPostEvent( m_parentPanel, moveEvent ); } break; diff --git a/common/worksheet.cpp b/common/worksheet.cpp index 4e2b1d116c..75f65b25cc 100644 --- a/common/worksheet.cpp +++ b/common/worksheet.cpp @@ -101,7 +101,7 @@ void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWi } -wxString EDA_DRAW_FRAME::GetScreenDesc() +wxString EDA_DRAW_FRAME::GetScreenDesc() const { // Virtual function. In basic class, returns // an empty string. diff --git a/common/worksheet_item.cpp b/common/worksheet_item.cpp new file mode 100644 index 0000000000..9845e48f92 --- /dev/null +++ b/common/worksheet_item.cpp @@ -0,0 +1,205 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Maciej Suminski + * + * 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 worksheet_item.cpp + * @brief Class that handles properties and drawing of worksheet layout. + */ + +#include +#include +#include +#include +#include +#include + +using namespace KiGfx; + +WORKSHEET_ITEM::WORKSHEET_ITEM( const std::string& aFileName, const std::string& aSheetName, + const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ) : + EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type + m_fileName( aFileName ), m_sheetName( aSheetName ), + m_titleBlock( aTitleBlock ), m_pageInfo( aPageInfo ), m_sheetNumber( 1 ), m_sheetCount( 1 ) {} + + +void WORKSHEET_ITEM::SetPageInfo( const PAGE_INFO* aPageInfo ) +{ + m_pageInfo = aPageInfo; + ViewUpdate( GEOMETRY ); +} + + +void WORKSHEET_ITEM::SetTitleBlock( const TITLE_BLOCK* aTitleBlock ) +{ + m_titleBlock = aTitleBlock; + ViewUpdate( GEOMETRY ); +} + + +const BOX2I WORKSHEET_ITEM::ViewBBox() const +{ + BOX2I bbox; + + if( m_pageInfo != NULL ) + { + bbox.SetOrigin( VECTOR2I( 0, 0 ) ); + bbox.SetEnd( VECTOR2I( m_pageInfo->GetWidthMils() * 25400, + m_pageInfo->GetHeightMils() * 25400 ) ); + } + else + { + bbox.SetMaximum(); + } + + return bbox; +} + + +void WORKSHEET_ITEM::ViewDraw( int aLayer, GAL* aGal ) const +{ + RENDER_SETTINGS* settings = m_view->GetPainter()->GetSettings(); + wxString fileName( m_fileName ); + wxString sheetName( m_sheetName ); + WS_DRAW_ITEM_LIST drawList; + + drawList.SetPenSize( settings->GetWorksheetLineWidth() ); + // Sorry, but I don't get this multi #ifdef from include/convert_to_biu.h, so here goes a magic + // number. IU_PER_MILS should be 25400 (as in a different compilation unit), but somehow + // it equals 1 in this case.. + drawList.SetMilsToIUfactor( 25400 /* IU_PER_MILS */ ); + drawList.SetSheetNumber( m_sheetNumber ); + drawList.SetSheetCount( m_sheetCount ); + drawList.SetFileName( fileName ); + drawList.SetSheetName( sheetName ); + + COLOR4D color = settings->GetColor( this, aLayer ); + EDA_COLOR_T edaColor = ColorFindNearest( color.r * 255, color.g * 255, color.b * 255 ); + drawList.BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock, edaColor, edaColor ); + + // Draw gray line that outlines the sheet size + drawBorder( aGal ); + + // Draw all the components that make the page layout + WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); + while( item ) + { + switch( item->GetType() ) + { + case WS_DRAW_ITEM_BASE::wsg_line: + draw( static_cast( item ), aGal ); + break; + + case WS_DRAW_ITEM_BASE::wsg_rect: + draw( static_cast( item ), aGal ); + break; + + case WS_DRAW_ITEM_BASE::wsg_poly: + draw( static_cast( item ), aGal ); + break; + + case WS_DRAW_ITEM_BASE::wsg_text: + draw( static_cast( item ), aGal ); + break; + } + + item = drawList.GetNext(); + } +} + + +void WORKSHEET_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const +{ + aCount = 1; + aLayers[0] = ITEM_GAL_LAYER( WORKSHEET ); +} + + +void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_LINE* aItem, GAL* aGal ) const +{ + aGal->SetIsStroke( true ); + aGal->SetIsFill( false ); + aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) ); + aGal->SetLineWidth( aItem->GetPenWidth() ); + aGal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) ); +} + + +void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_RECT* aItem, GAL* aGal ) const +{ + aGal->SetIsStroke( true ); + aGal->SetIsFill( false ); + aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) ); + aGal->SetLineWidth( aItem->GetPenWidth() ); + aGal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) ); +} + + +void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_POLYGON* aItem, GAL* aGal ) const +{ + std::deque corners; + BOOST_FOREACH( wxPoint point, aItem->m_Corners ) + { + corners.push_back( VECTOR2D( point ) ); + } + + if( aItem->IsFilled() ) + { + aGal->SetFillColor( COLOR4D( aItem->GetColor() ) ); + aGal->SetIsFill( true ); + aGal->SetIsStroke( false ); + aGal->DrawPolygon( corners ); + } + else + { + aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) ); + aGal->SetIsFill( false ); + aGal->SetIsStroke( true ); + aGal->SetLineWidth( aItem->GetPenWidth() ); + aGal->DrawPolyline( corners ); + } +} + + +void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const +{ + VECTOR2D position( aItem->GetTextPosition().x, aItem->GetTextPosition().y ); + + aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) ); + aGal->SetLineWidth( aItem->GetThickness() ); + aGal->SetTextAttributes( aItem ); + aGal->StrokeText( std::string( aItem->GetText().mb_str() ), position, 0.0 ); +} + + +void WORKSHEET_ITEM::drawBorder( GAL* aGal ) const +{ + VECTOR2D origin = VECTOR2D( 0.0, 0.0 ); + VECTOR2D end = VECTOR2D( m_pageInfo->GetWidthMils() * 25400, + m_pageInfo->GetHeightMils() * 25400 ); + + aGal->SetIsStroke( true ); + aGal->SetIsFill( false ); + aGal->SetStrokeColor( COLOR4D( 0.5, 0.5, 0.5, 1.0 ) ); + aGal->DrawRectangle( origin, end ); +} diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 926d2d6080..2dfb3045b9 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -188,7 +188,7 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( wxWindow void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemDeselected( wxListEvent& event ) { - D( printf( "OnListItemDeselected()\n" ); ) + DBG( printf( "OnListItemDeselected()\n" ); ) if( !m_skipCopyFromPanel ) { @@ -200,7 +200,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemDeselected( wxListEvent& even void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemSelected( wxListEvent& event ) { - D( printf( "OnListItemSelected()\n" ); ) + DBG( printf( "OnListItemSelected()\n" ); ) // remember the selected row, statically s_SelectedRow = event.GetIndex(); @@ -448,7 +448,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::moveUpButtonHandler( wxCommandEvent& ev // and in the fieldListCtrl SCH_FIELD tmp = m_FieldsBuf[fieldNdx - 1]; - D( printf( "tmp.m_Text=\"%s\" tmp.m_Name=\"%s\"\n", + DBG( printf( "tmp.m_Text=\"%s\" tmp.m_Name=\"%s\"\n", TO_UTF8( tmp.GetText() ), TO_UTF8( tmp.GetName( false ) ) ); ) m_FieldsBuf[fieldNdx - 1] = m_FieldsBuf[fieldNdx]; @@ -866,12 +866,12 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel() if( mirror == CMP_MIRROR_X ) { mirrorRadioBox->SetSelection( 1 ); - D( printf( "mirror=X,1\n" ); ) + DBG( printf( "mirror=X,1\n" ); ) } else if( mirror == CMP_MIRROR_Y ) { mirrorRadioBox->SetSelection( 2 ); - D( printf( "mirror=Y,2\n" ); ) + DBG( printf( "mirror=Y,2\n" ); ) } else mirrorRadioBox->SetSelection( 0 ); @@ -891,7 +891,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel() // Show the "Parts Locked" option? if( !m_LibEntry || !m_LibEntry->UnitsLocked() ) { - D( printf( "partsAreLocked->false\n" ); ) + DBG( printf( "partsAreLocked->false\n" ); ) partsAreLockedLabel->Show( false ); } diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp index d4f5b2159e..8fe7d7c2a5 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp @@ -472,7 +472,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() // fixed fields: for( int i=0; im_Name ) ); ) + DBG( printf( "add template:%s\n", TO_UTF8( it->m_Name ) ); ) fld.SetName( it->m_Name ); fld.SetText( it->m_Value ); // empty? ok too. @@ -509,7 +509,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() } else { - D( printf( "match template:%s\n", TO_UTF8( libField->GetName() ) ); ) + DBG( printf( "match template:%s\n", TO_UTF8( libField->GetName() ) ); ) fld = *libField; // copy values from component, m_Name too } @@ -525,7 +525,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() if( !buf ) { - D( printf( "add cmp:%s\n", TO_UTF8( cmp->GetName() ) ); ) + DBG( printf( "add cmp:%s\n", TO_UTF8( cmp->GetName() ) ); ) m_FieldsBuf.push_back( *cmp ); } } @@ -721,11 +721,11 @@ bool DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copyPanelToSelectedField() if( field.GetId() >= MANDATORY_FIELDS ) { wxString name = fieldNameTextCtrl->GetValue(); - D( printf("name:%s\n", TO_UTF8( name ) ); ) + DBG( printf("name:%s\n", TO_UTF8( name ) ); ) field.SetName( name ); } - D( printf("setname:%s\n", TO_UTF8( field.GetName() ) ); ) + DBG( printf("setname:%s\n", TO_UTF8( field.GetName() ) ); ) setRowItem( fieldNdx, field ); // update fieldListCtrl diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 832a2b274f..2cd3e3931e 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -292,7 +292,7 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event ) for( unsigned i=0; i=0 && m_id < MANDATORY_FIELDS ) { - D(printf( "trying to set a MANDATORY_FIELD's name\n" );) + DBG(printf( "trying to set a MANDATORY_FIELD's name\n" );) return; } diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index fbb16a245b..3b2ae8b74a 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -417,7 +417,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam wxFileName tmpFile = aFullFileName; tmpFile.SetExt( INTERMEDIATE_NETLIST_EXT ); - D(printf("tmpFile:'%s'\n", TO_UTF8( tmpFile.GetFullPath() ) );) + DBG(printf("tmpFile:'%s'\n", TO_UTF8( tmpFile.GetFullPath() ) );) ret = helper.WriteGENERICNetList( tmpFile.GetFullPath() ); if( !ret ) @@ -435,7 +435,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam tmpFile.GetFullPath(), aFullFileName ); - D(printf("commandLine:'%s'\n", TO_UTF8( commandLine ) );) + DBG(printf("commandLine:'%s'\n", TO_UTF8( commandLine ) );) ProcessExecute( commandLine, wxEXEC_SYNC ); diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 653709f516..b295d8ec04 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -324,7 +324,7 @@ SCH_SCREEN* SCH_EDIT_FRAME::GetScreen() const } -wxString SCH_EDIT_FRAME::GetScreenDesc() +wxString SCH_EDIT_FRAME::GetScreenDesc() const { wxString s = m_CurrentSheet->PathHumanReadable(); diff --git a/eeschema/template_fieldnames.cpp b/eeschema/template_fieldnames.cpp index c3c1730659..92ef9a90e9 100644 --- a/eeschema/template_fieldnames.cpp +++ b/eeschema/template_fieldnames.cpp @@ -151,7 +151,7 @@ int TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName ) { if( m_Fields[i].m_Name == aFieldName.m_Name ) { - D( printf( "inserting template fieldname:'%s' at %d\n", + DBG( printf( "inserting template fieldname:'%s' at %d\n", TO_UTF8( aFieldName.m_Name ), i ); ) m_Fields[i] = aFieldName; @@ -159,7 +159,7 @@ int TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName ) } } - // D(printf("appending template fieldname:'%s'\n", aFieldName.m_Name.utf8_str() );) + // DBG(printf("appending template fieldname:'%s'\n", aFieldName.m_Name.utf8_str() );) // the name is legal and not previously added to the config container, append // it and return its index within the container. diff --git a/gerbview/class_aperture_macro.cpp b/gerbview/class_aperture_macro.cpp index 28dabd5e19..3ea87648e1 100644 --- a/gerbview/class_aperture_macro.cpp +++ b/gerbview/class_aperture_macro.cpp @@ -409,7 +409,7 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, case AMP_UNKNOWN: default: - D( printf( "AM_PRIMITIVE::DrawBasicShape() err: unknown prim id %d\n",primitive_id) ); + DBG( printf( "AM_PRIMITIVE::DrawBasicShape() err: unknown prim id %d\n",primitive_id) ); break; } } diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index d65cc3bafa..e35c94bd2e 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -167,7 +167,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, if( m_GerbMetric ) conv_scale /= 25.4; -// D( printf( "%22s: Command <%c%c>\n", __func__, (command >> 8) & 0xFF, command & 0xFF ); ) +// DBG( printf( "%22s: Command <%c%c>\n", __func__, (command >> 8) & 0xFF, command & 0xFF ); ) switch( command ) { @@ -521,7 +521,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, m_ImageNegative = true; else m_ImageNegative = false; - D( printf( "%22s: IMAGE_POLARITY m_ImageNegative=%s\n", __func__, + DBG( printf( "%22s: IMAGE_POLARITY m_ImageNegative=%s\n", __func__, m_ImageNegative ? "true" : "false" ); ) break; @@ -531,7 +531,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, else GetLayerParams().m_LayerNegative = false; - D( printf( "%22s: LAYER_POLARITY m_LayerNegative=%s\n", __func__, + DBG( printf( "%22s: LAYER_POLARITY m_LayerNegative=%s\n", __func__, GetLayerParams().m_LayerNegative ? "true" : "false" ); ) break; diff --git a/include/colors.h b/include/colors.h index 7074b68abb..4cca37efa9 100644 --- a/include/colors.h +++ b/include/colors.h @@ -139,6 +139,14 @@ EDA_COLOR_T ColorByName( const wxChar *aName ); /// Find the nearest color match EDA_COLOR_T ColorFindNearest( const wxColour &aColor ); +/** + * Find the nearest color match + * @param aR is the red component of the color to be matched (in range 0-255) + * @param aG is the green component of the color to be matched (in range 0-255) + * @param aG is the blue component of the color to be matched (in range 0-255) + */ +EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB ); + /** * Check if a color is light i.e. if black would be more readable than * white on it diff --git a/include/gal/color4d.h b/include/gal/color4d.h index 2ee0ddfc41..5d0ca571a3 100644 --- a/include/gal/color4d.h +++ b/include/gal/color4d.h @@ -28,6 +28,7 @@ #define COLOR4D_H_ #include +#include namespace KiGfx { @@ -55,6 +56,10 @@ public: COLOR4D( double aRed, double aGreen, double aBlue, double aAlpha ) : r( aRed ), g( aGreen ), b( aBlue ), a( aAlpha ) { + assert( r >= 0.0 && r <= 1.0 ); + assert( g >= 0.0 && g <= 1.0 ); + assert( b >= 0.0 && b <= 1.0 ); + assert( a >= 0.0 && a <= 1.0 ); } /** @@ -82,6 +87,8 @@ public: */ COLOR4D& Brighten( double aFactor ) { + assert( aFactor >= 0.0 && aFactor <= 1.0 ); + r = r * ( 1.0 - aFactor ) + aFactor; g = g * ( 1.0 - aFactor ) + aFactor; b = b * ( 1.0 - aFactor ) + aFactor; @@ -97,6 +104,8 @@ public: */ COLOR4D& Darken( double aFactor ) { + assert( aFactor >= 0.0 && aFactor <= 1.0 ); + r = r * ( 1.0 - aFactor ); g = g * ( 1.0 - aFactor ); b = b * ( 1.0 - aFactor ); @@ -131,6 +140,8 @@ public: */ COLOR4D Brightened( double aFactor ) const { + assert( aFactor >= 0.0 && aFactor <= 1.0 ); + return COLOR4D( r * ( 1.0 - aFactor ) + aFactor, g * ( 1.0 - aFactor ) + aFactor, b * ( 1.0 - aFactor ) + aFactor, @@ -145,6 +156,8 @@ public: */ COLOR4D Darkened( double aFactor ) const { + assert( aFactor >= 0.0 && aFactor <= 1.0 ); + return COLOR4D( r * ( 1.0 - aFactor ), g * ( 1.0 - aFactor ), b * ( 1.0 - aFactor ), @@ -172,9 +185,25 @@ public: return ( r * 0.299 + g * 0.587 + b * 0.117 ); } - void ToHSV(double& out_h, double& out_s, double& out_v) const; - void FromHSV(double in_h, double in_s, double in_v); + /** + * Function ToHSV() + * Converts current color (stored in RGB) to HSV format. + * + * @param aOutH is conversion result for hue component. + * @param aOutS is conversion result for saturation component. + * @param aOutV is conversion result for value component. + */ + void ToHSV( double& aOutH, double& aOutS, double& aOutV ) const; + /** + * Function FromHSV() + * Changes currently used color to the one given by hue, saturation and value parameters. + * + * @param aOutH is hue component. + * @param aOutS is saturation component. + * @param aOutV is value component. + */ + void FromHSV( double aInH, double aInS, double aInV ); /// @brief Equality operator, are two colors equal const bool operator==( const COLOR4D& aColor ); diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 2b87606de0..77cb3c48a8 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -818,6 +818,9 @@ public: depthStack.pop(); } + /// Depth level on which the grid is drawn + static const int GRID_DEPTH = 1024; + protected: std::stack depthStack; ///< Stored depth values VECTOR2D screenSize; ///< Screen size in screen coordinates @@ -884,6 +887,9 @@ protected: * @param aCursorSize is the size of the cursor. */ virtual void initCursor( int aCursorSize ) = 0; + + static const int MIN_DEPTH = -2048; + static const int MAX_DEPTH = 2047; }; } // namespace KiGfx diff --git a/include/gal/opengl/cached_container.h b/include/gal/opengl/cached_container.h index 6409d34356..d770f9bc46 100644 --- a/include/gal/opengl/cached_container.h +++ b/include/gal/opengl/cached_container.h @@ -36,10 +36,8 @@ #include #include -#ifdef __WXDEBUG__ // Debug messages verbosity level -// #define CACHED_CONTAINER_TEST 2 -#endif +//#define CACHED_CONTAINER_TEST 1 namespace KiGfx { @@ -54,11 +52,14 @@ public: ///< @copydoc VERTEX_CONTAINER::SetItem() virtual void SetItem( VERTEX_ITEM* aItem ); + ///< @copydoc VERTEX_CONTAINER::FinishItem() + virtual void FinishItem(); + ///< @copydoc VERTEX_CONTAINER::Allocate() virtual VERTEX* Allocate( unsigned int aSize ); - ///< @copydoc VERTEX_CONTAINER::Erase() - virtual void Erase(); + ///< @copydoc VERTEX_CONTAINER::Delete() + virtual void Delete( VERTEX_ITEM* aItem ); ///< @copydoc VERTEX_CONTAINER::Clear() virtual void Clear(); @@ -130,14 +131,6 @@ protected: */ virtual bool resizeContainer( unsigned int aNewSize ); - /** - * Function freeItem() - * frees the space occupied by the item and returns it to the free space pool. - * - * @param aItem is the item to be freed. - */ - virtual void freeItem( VERTEX_ITEM* aItem ); - /** * Function getPowerOf2() * returns the nearest power of 2, bigger than aNumber. @@ -170,7 +163,7 @@ private: } /// Debug & test functions -#ifdef CACHED_CONTAINER_TEST +#if CACHED_CONTAINER_TEST > 0 void showFreeChunks(); void showReservedChunks(); void test(); diff --git a/include/gal/opengl/noncached_container.h b/include/gal/opengl/noncached_container.h index 0ff2f20a27..3cb6d1bf85 100644 --- a/include/gal/opengl/noncached_container.h +++ b/include/gal/opengl/noncached_container.h @@ -50,8 +50,8 @@ public: ///< @copydoc VERTEX_CONTAINER::Allocate() virtual VERTEX* Allocate( unsigned int aSize ); - ///< @copydoc VERTEX_CONTAINER::Erase() - virtual void Erase(); + ///< @copydoc VERTEX_CONTAINER::Delete() + void Delete( VERTEX_ITEM* aItem ) {}; ///< @copydoc VERTEX_CONTAINER::Clear() virtual void Clear(); diff --git a/include/gal/opengl/vertex_container.h b/include/gal/opengl/vertex_container.h index efca90b2f8..fb2a404846 100644 --- a/include/gal/opengl/vertex_container.h +++ b/include/gal/opengl/vertex_container.h @@ -54,6 +54,12 @@ public: */ virtual void SetItem( VERTEX_ITEM* aItem ) = 0; + /** + * Function FinishItem() + * does the cleaning after adding an item. + */ + virtual void FinishItem() {}; + /** * Function Allocate() * returns allocated space (possibly resizing the reserved memory chunk or allocating a new @@ -66,10 +72,12 @@ public: virtual VERTEX* Allocate( unsigned int aSize ) = 0; /** - * Function Erase() - * erases all vertices associated with the current item (set by SetItem()). + * Function Delete() + * erases the selected item. + * + * @param aItem is the item to be erased. */ - virtual void Erase() = 0; + virtual void Delete( VERTEX_ITEM* aItem ) = 0; /** * Function Clear() diff --git a/include/gal/opengl/vertex_manager.h b/include/gal/opengl/vertex_manager.h index bacb99867e..79f9dbd64b 100644 --- a/include/gal/opengl/vertex_manager.h +++ b/include/gal/opengl/vertex_manager.h @@ -232,6 +232,12 @@ public: */ void SetItem( VERTEX_ITEM& aItem ) const; + /** + * Function FinishItem() + * does the cleaning after adding an item. + */ + void FinishItem() const; + /** * Function FreeItem() * frees the memory occupied by the item, so it is no longer stored in the container. diff --git a/include/layers_id_colors_and_visibility.h b/include/layers_id_colors_and_visibility.h index 3ab011d3b5..6959ad3fd7 100644 --- a/include/layers_id_colors_and_visibility.h +++ b/include/layers_id_colors_and_visibility.h @@ -241,6 +241,7 @@ enum PCB_VISIBLE PADS_NETNAMES_VISIBLE, SELECTION, + WORKSHEET, GP_OVERLAY, // General purpose overlay END_PCB_VISIBLE_LIST // sentinel @@ -290,7 +291,8 @@ const LAYER_NUM GalLayerOrder[] = ITEM_GAL_LAYER( LAYER_1_NETNAMES_VISIBLE ), LAYER_N_BACK, ADHESIVE_N_BACK, SOLDERPASTE_N_BACK, SILKSCREEN_N_BACK, - ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ) + ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ), + ITEM_GAL_LAYER( WORKSHEET ) }; /** diff --git a/include/math/box2.h b/include/math/box2.h index 8d506bf62d..4390b8e7f4 100644 --- a/include/math/box2.h +++ b/include/math/box2.h @@ -68,7 +68,7 @@ public: m_Size( aSize ) { Normalize(); - } + } void SetMaximum() { @@ -418,10 +418,10 @@ public: { ecoord_type x2 = m_Pos.x + m_Size.x; ecoord_type y2 = m_Pos.y + m_Size.y; - ecoord_type xdiff = std::max(aP.x < m_Pos.x ? m_Pos.x - aP.x : m_Pos.x - x2, (ecoord_type)0); - ecoord_type ydiff = std::max(aP.y < m_Pos.y ? m_Pos.y - aP.y : m_Pos.y - y2, (ecoord_type)0); + ecoord_type xdiff = std::max( aP.x < m_Pos.x ? m_Pos.x - aP.x : m_Pos.x - x2, (ecoord_type)0 ); + ecoord_type ydiff = std::max( aP.y < m_Pos.y ? m_Pos.y - aP.y : m_Pos.y - y2, (ecoord_type)0 ); return xdiff * xdiff + ydiff * ydiff; - } + } ecoord_type Distance( const Vec& aP ) const { diff --git a/include/math/vector2d.h b/include/math/vector2d.h index 8c09602c60..44b72c515a 100644 --- a/include/math/vector2d.h +++ b/include/math/vector2d.h @@ -54,7 +54,7 @@ template <> struct VECTOR2_TRAITS { typedef int64_t extended_type; - static const extended_type ECOORD_MAX = 0x7fffffffffffffffULL; + static const extended_type ECOORD_MAX = 0x7fffffffffffffffULL; static const extended_type ECOORD_MIN = 0x8000000000000000ULL; }; diff --git a/include/painter.h b/include/painter.h index d546981369..1cbd2df94b 100644 --- a/include/painter.h +++ b/include/painter.h @@ -32,7 +32,8 @@ #include #include - +#include +#include class EDA_ITEM; class COLORS_DESIGN_SETTINGS; @@ -113,6 +114,21 @@ public: m_hiContrastEnabled = aEnabled; } + /** + * Function GetColor + * Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer + * using currently used render settings. + * @param aItem is the VIEW_ITEM. + * @param aLayer is the layer. + * @return The color. + */ + virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0; + + float GetWorksheetLineWidth() const + { + return m_worksheetLineWidth; + } + protected: /** * Function update @@ -137,6 +153,7 @@ protected: float m_selectFactor; ///< Specifies how color of selected items is changed float m_layerOpacity; ///< Determines opacity of all layers float m_outlineWidth; ///< Line width used when drawing outlines + float m_worksheetLineWidth; ///< Line width used when drawing worksheet /// Map of colors that were usually used for display std::map m_legacyColorMap; @@ -177,10 +194,7 @@ public: */ virtual void ApplySettings( RENDER_SETTINGS* aSettings ) { - if( m_settings ) - delete m_settings; - - m_settings = aSettings; + m_settings.reset( aSettings ); } /** @@ -195,9 +209,9 @@ public: * Returns pointer to current settings that are going to be used when drawing items. * @return Current rendering settings. */ - virtual RENDER_SETTINGS* GetSettings() + virtual RENDER_SETTINGS* GetSettings() const { - return m_settings; + return m_settings.get(); } /** @@ -217,23 +231,13 @@ public: */ virtual void DrawBrightened( const VIEW_ITEM* aItem ); - /** - * Function GetColor - * Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer - * using currently used render settings. - * @param aItem is the VIEW_ITEM. - * @param aLayer is the layer. - * @return The color. - */ - virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) = 0; - protected: /// Instance of graphic abstraction layer that gives an interface to call /// commands used to draw (eg. DrawLine, DrawCircle, etc.) GAL* m_gal; /// Colors and display modes settings that are going to be used when drawing items. - RENDER_SETTINGS* m_settings; + boost::shared_ptr m_settings; /// Color of brightened item frame COLOR4D m_brightenedColor; diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index a9d28f1b96..f5b7bacae0 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -65,6 +65,9 @@ public: virtual void DispatchWxEvent( wxEvent& aEvent ); virtual void DispatchWxCommand( wxCommandEvent& aEvent ); + /// Event that forces mouse move event in the dispatcher + static const wxEventType EVT_REFRESH_MOUSE; + private: static const int MouseButtonCount = 3; static const int DragTimeThreshold = 300; @@ -73,7 +76,7 @@ private: bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ); bool handlePopupMenu( wxEvent& aEvent ); - wxPoint getCurrentMousePos(); + wxPoint getCurrentMousePos() const; int decodeModifiers( const wxKeyboardState* aState ) const; diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index 1033a2f51a..592624c321 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -229,6 +229,16 @@ public: return m_keyCode; } + bool IsKeyUp() const + { + return m_actions == TA_KeyUp; + } + + bool IsKeyDown() const + { + return m_actions == TA_KeyDown; + } + void Ignore(); void SetMouseDragOrigin( const VECTOR2D &aP ) diff --git a/include/view/view.h b/include/view/view.h index dbbdd60744..5013fdaf91 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -377,10 +377,10 @@ public: void UpdateAllLayersOrder(); /** - * Function PrepareTargets() + * Function ClearTargets() * Clears targets that are marked as dirty. */ - void PrepareTargets(); + void ClearTargets(); /** * Function Redraw() @@ -443,9 +443,13 @@ public: return ( m_layers.at( aLayer ).target == TARGET_CACHED ); } - void MakeDirty() + /** + * Function MarkDirty() + * Forces redraw of view on the next rendering. + */ + void MarkDirty() { - for(int i = 0; i < TARGETS_NUMBER; i++) + for( int i = 0; i < TARGETS_NUMBER; ++i ) m_dirtyTargets[i] = true; } @@ -455,7 +459,6 @@ private: struct VIEW_LAYER { bool enabled; ///* is the layer to be rendered? - bool isDirty; ///* does it contain any dirty items (updated since last redraw) bool displayOnly; ///* is the layer display only? VIEW_RTREE* items; ///* R-tree indexing all items on this layer. int renderingOrder; ///* rendering order of this layer diff --git a/include/view/view_group.h b/include/view/view_group.h index 1f50da5046..18f5f5a9b6 100644 --- a/include/view/view_group.h +++ b/include/view/view_group.h @@ -107,9 +107,8 @@ public: * * @param aLayer is the layer which should be drawn. * @param aGal is the GAL that should be used for drawing. - * @param aVisibleArea is limiting the drawing area. */ - virtual void ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const; + virtual void ViewDraw( int aLayer, GAL* aGal ) const; /** * Function ViewGetLayers() @@ -120,9 +119,6 @@ public: */ virtual void ViewGetLayers( int aLayers[], int& aCount ) const; - /// @copydoc VIEW_ITEM::ViewUpdate() - //virtual void ViewUpdate( int aUpdateFlags, bool aForceImmediateRedraw ); - /** * Function SetLayer() * Sets layer used to draw the group. @@ -134,8 +130,18 @@ public: m_layer = aLayer; } + /** + * Function FreeItems() + * Frees all the items that were added to the group. + */ void FreeItems(); + /** + * Function GetView() + * Returns pointer to the VIEW instance used by items. + * + * @return Pointer to the VIEW instance. + */ KiGfx::VIEW *GetView() const { return m_view; diff --git a/include/view/view_item.h b/include/view/view_item.h index 49f0b7d492..8004c4264b 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -70,8 +70,7 @@ public: ALL = 0xff }; - VIEW_ITEM() : m_view( NULL ), m_visible( true ), m_groups( NULL ), - m_groupsSize( 0 ) {} + VIEW_ITEM() : m_view( NULL ), m_visible( true ), m_groups( NULL ), m_groupsSize( 0 ) {} /** * Destructor. For dynamic views, removes the item from the view. @@ -101,11 +100,8 @@ public: * * @param aLayer: current drawing layer * @param aGal: pointer to the GAL device we are drawing on - * @param aVisibleArea: area (in world space coordinates) that is relevant for drawing. For - * example, when drawing a bitmap, one can clip the blitting area to aVisibleArea, reducing - * drawing time. */ - virtual void ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const { }; + virtual void ViewDraw( int aLayer, GAL* aGal ) const {}; /** * Function ViewGetLayers() @@ -155,10 +151,8 @@ public: * this item has changed. For static views calling has no effect. * * @param aUpdateFlags: how much the object has changed - * @param aForceImmediateRedraw: when true, the VIEW is redrawn immediately, - * otherwise, it will be redrawn upon next call of VIEW::Update() */ - virtual void ViewUpdate( int aUpdateFlags = ALL, bool aForceImmediateRedraw = false ); + virtual void ViewUpdate( int aUpdateFlags = ALL ); /** * Function ViewRelease() @@ -241,7 +235,10 @@ protected: * * @returns true in case it is cached at least for one layer. */ - virtual bool storesGroups() const; + inline virtual bool storesGroups() const + { + return ( m_groupsSize > 0 ); + } /// Stores layer numbers used by the item. std::bitset m_layers; @@ -258,7 +255,7 @@ protected: m_layers.reset(); for( int i = 0; i < aCount; ++i ) - m_layers.set(aLayers[i]); + m_layers.set( aLayers[i] ); } }; diff --git a/include/worksheet_item.h b/include/worksheet_item.h new file mode 100644 index 0000000000..b26ec01085 --- /dev/null +++ b/include/worksheet_item.h @@ -0,0 +1,163 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Maciej Suminski + * + * 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 worksheet_item.h + * @brief Class that handles properties and drawing of worksheet layout. + */ + +#ifndef WORKSHEET_ITEM_H +#define WORKSHEET_ITEM_H + +#include + +class BOARD; +class PAGE_INFO; +class TITLE_BLOCK; +class WS_DRAW_ITEM_LINE; +class WS_DRAW_ITEM_RECT; +class WS_DRAW_ITEM_POLYGON; +class WS_DRAW_ITEM_TEXT; + +namespace KiGfx +{ +class GAL; + +class WORKSHEET_ITEM : public EDA_ITEM +{ +public: + WORKSHEET_ITEM( const std::string& aFileName, const std::string& aSheetName, + const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ); + ~WORKSHEET_ITEM() {} + + /** + * Function SetFileName() + * Sets the file name displayed in the title block. + * + * @param aFileName is the new file name. + */ + void SetFileName( const std::string& aFileName ) + { + m_fileName = aFileName; + ViewUpdate( GEOMETRY ); + } + + /** + * Function SetSheetName() + * Sets the sheet name displayed in the title block. + * + * @param aSheetName is the new sheet name. + */ + void SetSheetName( const std::string& aSheetName ) + { + m_sheetName = aSheetName; + ViewUpdate( GEOMETRY ); + } + + /** + * Function SetPageInfo() + * Changes the PAGE_INFO object used to draw the worksheet. + * + * @param aPageInfo is the new PAGE_INFO object. + */ + void SetPageInfo( const PAGE_INFO* aPageInfo ); + + /** + * Function SetTitleBlock() + * Changes the TITLE_BLOCK object used to draw the worksheet. + * + * @param aTitleBlock is the new TITLE_BLOCK object. + */ + void SetTitleBlock( const TITLE_BLOCK* aTitleBlock ); + + /** + * Function SetSheetNumber() + * Changes the sheet number displayed in the title block. + * + * @param aSheetNumber is the new sheet number. + */ + void SetSheetNumber( int aSheetNumber ) + { + m_sheetNumber = aSheetNumber; + ViewUpdate( GEOMETRY ); + + } + + /** + * Function SetSheetCount() + * Changes the sheets count number displayed in the title block. + * + * @param aSheetCount is the new sheets count number. + */ + void SetSheetCount( int aSheetCount ) + { + m_sheetCount = aSheetCount; + ViewUpdate( GEOMETRY ); + } + + /// @copydoc VIEW_ITEM::ViewBBox() + const BOX2I ViewBBox() const; + + /// @copydoc VIEW_ITEM::ViewDraw() + void ViewDraw( int aLayer, GAL* aGal ) const; + + /// @copydoc VIEW_ITEM::ViewGetLayers() + void ViewGetLayers( int aLayers[], int& aCount ) const; + + /// @copydoc EDA_ITEM::Show() + void Show( int x, std::ostream& st ) const + { + } + +protected: + /// File name displayed in the title block + std::string m_fileName; + + /// Sheet name displayed in the title block + std::string m_sheetName; + + /// Title block that contains properties of the title block displayed in the worksheet. + const TITLE_BLOCK* m_titleBlock; + + /// Worksheet page information. + const PAGE_INFO* m_pageInfo; + + /// Sheet number displayed in the title block. + int m_sheetNumber; + + /// Sheets count number displayed in the title block. + int m_sheetCount; + + // Functions for drawing items that makes a worksheet + void draw( const WS_DRAW_ITEM_LINE* aItem, GAL* aGal ) const; + void draw( const WS_DRAW_ITEM_RECT* aItem, GAL* aGal ) const; + void draw( const WS_DRAW_ITEM_POLYGON* aItem, GAL* aGal ) const; + void draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const; + + /// Draws a border that determines the page size. + void drawBorder( GAL* aGal ) const; +}; +} + +#endif /* WORKSHEET_ITEM_H */ diff --git a/include/worksheet_shape_builder.h b/include/worksheet_shape_builder.h index a7d4644172..a29ddfe55e 100644 --- a/include/worksheet_shape_builder.h +++ b/include/worksheet_shape_builder.h @@ -108,9 +108,9 @@ public: } // Accessors: - int GetPenWidth() { return m_penWidth; } - const wxPoint& GetStart() { return m_start; } - const wxPoint& GetEnd() { return m_end; } + int GetPenWidth() const { return m_penWidth; } + const wxPoint& GetStart() const { return m_start; } + const wxPoint& GetEnd() const { return m_end; } /** The function to draw a WS_DRAW_ITEM_LINE */ @@ -158,9 +158,9 @@ public: } // Accessors: - int GetPenWidth() { return m_penWidth; } - bool IsFilled() { return m_fill; } - const wxPoint& GetPosition() { return m_pos; } + int GetPenWidth() const { return m_penWidth; } + bool IsFilled() const { return m_fill; } + const wxPoint& GetPosition() const { return m_pos; } /** The function to draw a WS_DRAW_ITEM_POLYGON */ diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index 874349dfd0..fdaaa1f767 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -95,8 +95,8 @@ protected: /// main window. wxAuiToolBar* m_auxiliaryToolBar; - TOOL_MANAGER *m_toolManager; - TOOL_DISPATCHER *m_toolDispatcher; + TOOL_MANAGER* m_toolManager; + TOOL_DISPATCHER* m_toolDispatcher; void updateGridSelectBox(); void updateZoomSelectBox(); diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 8607c835f7..bcd4194409 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -356,7 +356,7 @@ public: */ void OnModify(); - virtual wxString GetScreenDesc(); + virtual wxString GetScreenDesc() const; void InstallConfigFrame( wxCommandEvent& event ); diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 29a65a34e5..2110eb75d9 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -118,6 +118,7 @@ protected: // to know the footprint name of components. void setupTools(); + void destroyTools(); void onGenericCommand( wxCommandEvent& aEvent ); // we'll use lower case function names for private member functions. @@ -135,21 +136,13 @@ protected: * will change the currently active layer to \a aLayer and also * update the PCB_LAYER_WIDGET. */ - void setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true ) - { - ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; - - setHighContrastLayer( aLayer ); - - if( doLayerWidgetUpdate ) - syncLayerWidgetLayer(); - } + void setCurrentLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true ); /** * Function getActiveLayer * returns the active layer */ - LAYER_NUM getActiveLayer() + LAYER_NUM getCurrentLayer() { return ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer; } @@ -160,6 +153,12 @@ protected: */ void setHighContrastLayer( LAYER_NUM aLayer ); + /** + * Function setTopLayer + * moves the selected layer to the top, so it is displayed above all others. + */ + void setTopLayer( LAYER_NUM aLayer ); + /** * Function syncLayerWidgetLayer * updates the currently layer "selection" within the PCB_LAYER_WIDGET. diff --git a/include/wxstruct.h b/include/wxstruct.h index 6cdd0fec65..d5dfd47842 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -499,7 +499,7 @@ public: EDA_DRAW_PANEL* GetCanvas() { return m_canvas; } - virtual wxString GetScreenDesc(); + virtual wxString GetScreenDesc() const; /** * Function GetScreen diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index e3c298a2c1..9692ba9738 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -202,6 +203,20 @@ void PCB_BASE_FRAME::ViewReloadBoard( const BOARD* aBoard ) const view->Add( zone ); } + // Add an entry for the worksheet layout + KiGfx::WORKSHEET_ITEM* worksheet = new KiGfx::WORKSHEET_ITEM( + std::string( aBoard->GetFileName().mb_str() ), + std::string( GetScreenDesc().mb_str() ), + &GetPageSettings(), &GetTitleBlock() ); + BASE_SCREEN* screen = GetScreen(); + if( screen != NULL ) + { + worksheet->SetSheetNumber( GetScreen()->m_ScreenNumber ); + worksheet->SetSheetCount( GetScreen()->m_NumberOfScreens ); + } + + view->Add( worksheet ); + view->RecacheAllItems( true ); if( m_galCanvasActive ) @@ -828,7 +843,7 @@ void PCB_BASE_FRAME::LoadSettings() { // Copper layers are required for netname layers view->SetRequired( GetNetnameLayer( layer ), layer ); - view->SetLayerTarget( layer, KiGfx::TARGET_NONCACHED ); + view->SetLayerTarget( layer, KiGfx::TARGET_CACHED ); } else if( IsNetnameLayer( layer ) ) { diff --git a/pcbnew/class_pcb_layer_widget.cpp b/pcbnew/class_pcb_layer_widget.cpp index 07b46f4fa9..e334c05d59 100644 --- a/pcbnew/class_pcb_layer_widget.cpp +++ b/pcbnew/class_pcb_layer_widget.cpp @@ -183,7 +183,7 @@ void PCB_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event ) if( IsCopperLayer( layer ) ) { bool loc_visible = visible; - if( force_active_layer_visible && (layer == myframe->getActiveLayer() ) ) + if( force_active_layer_visible && (layer == myframe->getCurrentLayer() ) ) loc_visible = true; cb->SetValue( loc_visible ); @@ -354,7 +354,7 @@ bool PCB_LAYER_WIDGET::OnLayerSelect( LAYER_NUM aLayer ) { // the layer change from the PCB_LAYER_WIDGET can be denied by returning // false from this function. - myframe->setActiveLayer( aLayer, false ); + myframe->setCurrentLayer( aLayer, false ); if( m_alwaysShowActiveCopperLayer ) OnLayerSelected(); diff --git a/pcbnew/deltrack.cpp b/pcbnew/deltrack.cpp index 2a77f9faec..6833543db9 100644 --- a/pcbnew/deltrack.cpp +++ b/pcbnew/deltrack.cpp @@ -53,7 +53,7 @@ TRACK* PCB_EDIT_FRAME::Delete_Segment( wxDC* DC, TRACK* aTrack ) { if( g_CurrentTrackList.GetCount() > 0 ) { - LAYER_NUM previous_layer = getActiveLayer(); + LAYER_NUM previous_layer = getCurrentLayer(); DBG( g_CurrentTrackList.VerifyListIntegrity(); ) @@ -86,7 +86,7 @@ TRACK* PCB_EDIT_FRAME::Delete_Segment( wxDC* DC, TRACK* aTrack ) // Correct active layer which could change if a via // has been erased - setActiveLayer( previous_layer ); + setCurrentLayer( previous_layer ); UpdateStatusBar(); diff --git a/pcbnew/dialogs/dialog_general_options.cpp b/pcbnew/dialogs/dialog_general_options.cpp index 37854ac88f..2d10c8d6ea 100644 --- a/pcbnew/dialogs/dialog_general_options.cpp +++ b/pcbnew/dialogs/dialog_general_options.cpp @@ -238,8 +238,8 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) // Apply new display options to the GAL canvas (this is faster than recaching) settings->LoadDisplayOptions( DisplayOpt ); - setHighContrastLayer( getActiveLayer() ); - m_galCanvas->GetView()->EnableTopLayer( state ); + setHighContrastLayer( getCurrentLayer() ); +// m_galCanvas->GetView()->EnableTopLayer( state ); if( m_galCanvasActive ) m_galCanvas->Refresh(); diff --git a/pcbnew/dialogs/dialog_global_deletion.cpp b/pcbnew/dialogs/dialog_global_deletion.cpp index 3048f5b7c0..7812296232 100644 --- a/pcbnew/dialogs/dialog_global_deletion.cpp +++ b/pcbnew/dialogs/dialog_global_deletion.cpp @@ -37,7 +37,7 @@ DIALOG_GLOBAL_DELETION::DIALOG_GLOBAL_DELETION( PCB_EDIT_FRAME* parent ) void PCB_EDIT_FRAME::InstallPcbGlobalDeleteFrame( const wxPoint& pos ) { DIALOG_GLOBAL_DELETION dlg( this ); - dlg.SetCurrentLayer( getActiveLayer() ); + dlg.SetCurrentLayer( getCurrentLayer() ); dlg.ShowModal(); } diff --git a/pcbnew/dialogs/dialog_layers_setup.cpp b/pcbnew/dialogs/dialog_layers_setup.cpp index d06f501394..ab8f18c97e 100644 --- a/pcbnew/dialogs/dialog_layers_setup.cpp +++ b/pcbnew/dialogs/dialog_layers_setup.cpp @@ -669,11 +669,11 @@ void PCB_EDIT_FRAME::InstallDialogLayerSetup() if( dlg.ShowModal() == wxID_CANCEL ) return; - wxLogDebug( wxT( "Current layer selected %d." ), getActiveLayer() ); + wxLogDebug( wxT( "Current layer selected %d." ), getCurrentLayer() ); // If the current active layer was removed, find the next avaiable layer to set as the // active layer. - if( !( GetLayerMask( getActiveLayer() ) & GetBoard()->GetEnabledLayers() ) ) + if( !( GetLayerMask( getCurrentLayer() ) & GetBoard()->GetEnabledLayers() ) ) { for( LAYER_NUM i = FIRST_LAYER; i < NB_LAYERS; ++i ) { @@ -684,14 +684,14 @@ void PCB_EDIT_FRAME::InstallDialogLayerSetup() if( GetLayerMask( tmp ) & GetBoard()->GetEnabledLayers() ) { - wxLogDebug( wxT( "Setting current layer to %d." ), getActiveLayer() ); - setActiveLayer( tmp, true ); + wxLogDebug( wxT( "Setting current layer to %d." ), getCurrentLayer() ); + setCurrentLayer( tmp, true ); break; } } } else { - setActiveLayer( getActiveLayer(), true ); + setCurrentLayer( getCurrentLayer(), true ); } } diff --git a/pcbnew/dimension.cpp b/pcbnew/dimension.cpp index 391addb6f9..bf72fdfc8a 100644 --- a/pcbnew/dimension.cpp +++ b/pcbnew/dimension.cpp @@ -245,7 +245,7 @@ DIMENSION* PCB_EDIT_FRAME::EditDimension( DIMENSION* aDimension, wxDC* aDC ) aDimension = new DIMENSION( GetBoard() ); aDimension->SetFlags( IS_NEW ); - aDimension->SetLayer( getActiveLayer() ); + aDimension->SetLayer( getCurrentLayer() ); aDimension->m_crossBarO = aDimension->m_crossBarF = pos; aDimension->m_featureLineDO = aDimension->m_featureLineDF = pos; diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 47e60041ba..65974bc83b 100755 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -917,10 +917,10 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_PCB_SELECT_LAYER: - itmp = SelectLayer( getActiveLayer(), UNDEFINED_LAYER, UNDEFINED_LAYER ); + itmp = SelectLayer( getCurrentLayer(), UNDEFINED_LAYER, UNDEFINED_LAYER ); if( itmp >= 0 ) - setActiveLayer( itmp ); + setCurrentLayer( itmp ); m_canvas->MoveCursorToCrossHair(); break; @@ -930,19 +930,19 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_PCB_SELECT_NO_CU_LAYER: - itmp = SelectLayer( getActiveLayer(), FIRST_NON_COPPER_LAYER, UNDEFINED_LAYER ); + itmp = SelectLayer( getCurrentLayer(), FIRST_NON_COPPER_LAYER, UNDEFINED_LAYER ); if( itmp >= 0 ) - setActiveLayer( itmp ); + setCurrentLayer( itmp ); m_canvas->MoveCursorToCrossHair(); break; case ID_POPUP_PCB_SELECT_CU_LAYER: - itmp = SelectLayer( getActiveLayer(), UNDEFINED_LAYER, LAST_COPPER_LAYER ); + itmp = SelectLayer( getCurrentLayer(), UNDEFINED_LAYER, LAST_COPPER_LAYER ); if( itmp >= 0 ) - setActiveLayer( itmp ); + setCurrentLayer( itmp ); break; @@ -952,7 +952,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_TOOLBARH_PCB_SELECT_LAYER: - setActiveLayer( m_SelLayerBox->GetLayerSelection() ); + setCurrentLayer( m_SelLayerBox->GetLayerSelection() ); if( DisplayOpt.ContrastModeDisplay ) m_canvas->Refresh( true ); @@ -1240,7 +1240,7 @@ void PCB_EDIT_FRAME::RemoveStruct( BOARD_ITEM* Item, wxDC* DC ) void PCB_EDIT_FRAME::SwitchLayer( wxDC* DC, LAYER_NUM layer ) { - LAYER_NUM curLayer = getActiveLayer(); + LAYER_NUM curLayer = getCurrentLayer(); // Check if the specified layer matches the present layer if( layer == curLayer ) @@ -1282,7 +1282,7 @@ void PCB_EDIT_FRAME::SwitchLayer( wxDC* DC, LAYER_NUM layer ) GetScreen()->m_Route_Layer_TOP = curLayer; GetScreen()->m_Route_Layer_BOTTOM = layer; - setActiveLayer( curLayer ); + setCurrentLayer( curLayer ); if( Other_Layer_Route( (TRACK*) GetScreen()->GetCurItem(), DC ) ) { @@ -1303,7 +1303,7 @@ void PCB_EDIT_FRAME::SwitchLayer( wxDC* DC, LAYER_NUM layer ) // and a non-copper layer, or vice-versa? // ... - setActiveLayer( layer ); + setCurrentLayer( layer ); if( DisplayOpt.ContrastModeDisplay ) RefreshCanvas(); diff --git a/pcbnew/editedge.cpp b/pcbnew/editedge.cpp index acc881c687..1bc862c958 100644 --- a/pcbnew/editedge.cpp +++ b/pcbnew/editedge.cpp @@ -246,7 +246,7 @@ DRAWSEGMENT* PCB_EDIT_FRAME::Begin_DrawSegment( DRAWSEGMENT* Segment, STROKE_T s s_large = GetDesignSettings().m_DrawSegmentWidth; - if( getActiveLayer() == EDGE_N ) + if( getCurrentLayer() == EDGE_N ) { s_large = GetDesignSettings().m_EdgeSegmentWidth; } @@ -255,7 +255,7 @@ DRAWSEGMENT* PCB_EDIT_FRAME::Begin_DrawSegment( DRAWSEGMENT* Segment, STROKE_T s { SetCurItem( Segment = new DRAWSEGMENT( GetBoard() ) ); Segment->SetFlags( IS_NEW ); - Segment->SetLayer( getActiveLayer() ); + Segment->SetLayer( getCurrentLayer() ); Segment->SetWidth( s_large ); Segment->SetShape( shape ); Segment->SetAngle( 900 ); diff --git a/pcbnew/editrack-part2.cpp b/pcbnew/editrack-part2.cpp index e36a3a92a1..40c5f73eb3 100644 --- a/pcbnew/editrack-part2.cpp +++ b/pcbnew/editrack-part2.cpp @@ -52,10 +52,10 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) if( aTrack == NULL ) { - if( getActiveLayer() != ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ) - setActiveLayer( ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ); + if( getCurrentLayer() != ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ) + setCurrentLayer( ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ); else - setActiveLayer(((PCB_SCREEN*)GetScreen())->m_Route_Layer_BOTTOM ); + setCurrentLayer(((PCB_SCREEN*)GetScreen())->m_Route_Layer_BOTTOM ); UpdateStatusBar(); return true; @@ -109,7 +109,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) via->SetLayerPair( LAYER_N_BACK, LAYER_N_FRONT ); via->SetDrill( GetBoard()->GetCurrentViaDrill() ); - LAYER_NUM first_layer = getActiveLayer(); + LAYER_NUM first_layer = getCurrentLayer(); LAYER_NUM last_layer; // prepare switch to new active layer: @@ -172,7 +172,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) return false; } - setActiveLayer( last_layer ); + setCurrentLayer( last_layer ); TRACK* lastNonVia = g_CurrentTrackSegment; @@ -194,7 +194,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) */ // set the layer to the new value - track->SetLayer( getActiveLayer() ); + track->SetLayer( getCurrentLayer() ); /* the start point is the via position and the end point is the cursor * which also is on the via (will change when moving mouse) diff --git a/pcbnew/hotkeys_board_editor.cpp b/pcbnew/hotkeys_board_editor.cpp index 30b07f55b2..eeedca4df2 100644 --- a/pcbnew/hotkeys_board_editor.cpp +++ b/pcbnew/hotkeys_board_editor.cpp @@ -243,7 +243,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit break; case HK_SWITCH_LAYER_TO_PREVIOUS: - ll = getActiveLayer(); + ll = getCurrentLayer(); if( (ll <= LAYER_N_BACK) || (ll > LAYER_N_FRONT) ) break; @@ -259,7 +259,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit break; case HK_SWITCH_LAYER_TO_NEXT: - ll = getActiveLayer(); + ll = getCurrentLayer(); if( (ll < LAYER_N_BACK) || (ll >= LAYER_N_FRONT) ) break; @@ -365,7 +365,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit break; case HK_BACK_SPACE: - if( /*m_ID_current_state == ID_TRACK_BUTT &&*/ (getActiveLayer() <= LAYER_N_FRONT) ) + if( /*m_ID_current_state == ID_TRACK_BUTT &&*/ (getCurrentLayer() <= LAYER_N_FRONT) ) { if( !itemCurrentlyEdited ) { @@ -572,7 +572,7 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC ) switch( GetToolId() ) { case ID_TRACK_BUTT: - if( getActiveLayer() > LAYER_N_FRONT ) + if( getCurrentLayer() > LAYER_N_FRONT ) return false; if( ItemFree ) @@ -941,7 +941,7 @@ bool PCB_EDIT_FRAME::OnHotkeyPlaceItem( wxDC* aDC ) */ TRACK * PCB_EDIT_FRAME::OnHotkeyBeginRoute( wxDC* aDC ) { - if( getActiveLayer() > LAYER_N_FRONT ) + if( getCurrentLayer() > LAYER_N_FRONT ) return NULL; bool itemCurrentlyEdited = (GetCurItem() && GetCurItem()->GetFlags()); diff --git a/pcbnew/onleftclick.cpp b/pcbnew/onleftclick.cpp index f655b1a6a0..62e11ddacb 100644 --- a/pcbnew/onleftclick.cpp +++ b/pcbnew/onleftclick.cpp @@ -243,7 +243,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) if( GetToolId() == ID_PCB_ARC_BUTT ) shape = S_ARC; - if( IsCopperLayer( getActiveLayer() ) ) + if( IsCopperLayer( getCurrentLayer() ) ) { DisplayError( this, _( "Graphic not allowed on Copper layers" ) ); break; @@ -267,7 +267,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) break; case ID_TRACK_BUTT: - if( !IsCopperLayer( getActiveLayer() ) ) + if( !IsCopperLayer( getCurrentLayer() ) ) { DisplayError( this, _( "Tracks on Copper layers only " ) ); break; @@ -367,7 +367,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) break; case ID_PCB_DIMENSION_BUTT: - if( IsCopperLayer( getActiveLayer() ) ) + if( IsCopperLayer( getCurrentLayer() ) ) { DisplayError( this, _( "Dimension not allowed on Copper layers" ) ); break; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index d2dcc6eeaf..6810f5049f 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -75,6 +75,7 @@ void PCB_RENDER_SETTINGS::ImportLegacyColors( COLORS_DESIGN_SETTINGS* aSettings m_layerColors[ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE )] = COLOR4D( 0.8, 0.8, 0.8, 0.7 ); m_layerColors[ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE )] = COLOR4D( 0.8, 0.8, 0.8, 0.7 ); m_layerColors[ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE )] = COLOR4D( 0.8, 0.8, 0.8, 0.7 ); + m_layerColors[ITEM_GAL_LAYER( WORKSHEET )] = COLOR4D( 0.5, 0.0, 0.0, 1.0 ); // Netnames for copper layers for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) @@ -137,6 +138,41 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions ) } +const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const +{ + int netCode = -1; + + if( aItem ) + { + if( static_cast( aItem )->IsSelected() ) + { + return m_layerColorsSel[aLayer]; + } + + // Try to obtain the netcode for the item + const BOARD_CONNECTED_ITEM* item = dynamic_cast( aItem ); + if( item ) + netCode = item->GetNet(); + } + + // Return grayish color for non-highlighted layers in the high contrast mode + if( m_hiContrastEnabled && m_activeLayers.count( aLayer ) == 0 ) + return m_hiContrastColor; + + // Single net highlight mode + if( m_highlightEnabled ) + { + if( netCode == m_highlightNetcode ) + return m_layerColorsHi[aLayer]; + else + return m_layerColorsDark[aLayer]; + } + + // No special modificators enabled + return m_layerColors[aLayer]; +} + + void PCB_RENDER_SETTINGS::update() { // Calculate darkened/highlighted variants of layer colors @@ -153,51 +189,20 @@ void PCB_RENDER_SETTINGS::update() } -PCB_PAINTER::PCB_PAINTER( GAL* aGal ) : - PAINTER( aGal ) -{ -} - - -const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer ) -{ - int netCode = -1; - - if( aItem ) - { - if( static_cast( aItem )->IsSelected() ) - { - return m_pcbSettings->m_layerColorsSel[aLayer]; - } - - // Try to obtain the netcode for the item - const BOARD_CONNECTED_ITEM* item = dynamic_cast( aItem ); - if( item ) - netCode = item->GetNet(); - } - - // Return grayish color for non-highlighted layers in the high contrast mode - if( m_pcbSettings->m_hiContrastEnabled && m_pcbSettings->m_activeLayers.count( aLayer ) == 0 ) - return m_pcbSettings->m_hiContrastColor; - - // Single net highlight mode - if( m_pcbSettings->m_highlightEnabled ) - { - if( netCode == m_pcbSettings->m_highlightNetcode ) - return m_pcbSettings->m_layerColorsHi[aLayer]; - else - return m_pcbSettings->m_layerColorsDark[aLayer]; - } - - // No special modificators enabled - return m_pcbSettings->m_layerColors[aLayer]; -} - const COLOR4D& PCB_RENDER_SETTINGS::GetLayerColor( int aLayer ) const { return m_layerColors[aLayer]; } + +PCB_PAINTER::PCB_PAINTER( GAL* aGal ) : + PAINTER( aGal ) +{ + m_settings.reset( new PCB_RENDER_SETTINGS() ); + m_pcbSettings = (PCB_RENDER_SETTINGS*) m_settings.get(); +} + + bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) { const BOARD_ITEM* item = static_cast( aItem ); @@ -284,8 +289,8 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) double textSize = std::min( static_cast( width ), length / netName.length() ); // Set a proper color for the label - color = GetColor( aTrack, aTrack->GetLayer() ); - COLOR4D labelColor = GetColor( NULL, aLayer ); + color = m_pcbSettings->GetColor( aTrack, aTrack->GetLayer() ); + COLOR4D labelColor = m_pcbSettings->GetColor( NULL, aLayer ); if( color.GetBrightness() > 0.5 ) m_gal->SetStrokeColor( labelColor.Inverted() ); @@ -305,7 +310,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) else if( IsCopperLayer( aLayer )) { // Draw a regular track - color = GetColor( aTrack, aLayer ); + color = m_pcbSettings->GetColor( aTrack, aLayer ); m_gal->SetStrokeColor( color ); m_gal->SetIsStroke( true ); @@ -344,7 +349,7 @@ void PCB_PAINTER::draw( const SEGVIA* aVia, int aLayer ) else return; - color = GetColor( aVia, aLayer ); + color = m_pcbSettings->GetColor( aVia, aLayer ); if( m_pcbSettings->m_sketchModeSelect[VIAS_VISIBLE] ) { @@ -423,8 +428,8 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) m_gal->SetMirrored( false ); // Set a proper color for the label - color = GetColor( aPad, aPad->GetLayer() ); - COLOR4D labelColor = GetColor( NULL, aLayer ); + color = m_pcbSettings->GetColor( aPad, aPad->GetLayer() ); + COLOR4D labelColor = m_pcbSettings->GetColor( NULL, aLayer ); if( color.GetBrightness() > 0.5 ) m_gal->SetStrokeColor( labelColor.Inverted() ); @@ -470,7 +475,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) } // Pad drawing - color = GetColor( aPad, aLayer ); + color = m_pcbSettings->GetColor( aPad, aLayer ); if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] ) { // Outline mode @@ -623,7 +628,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment ) { - COLOR4D color = GetColor( NULL, aSegment->GetLayer() ); + COLOR4D color = m_pcbSettings->GetColor( NULL, aSegment->GetLayer() ); m_gal->SetIsFill( false ); m_gal->SetIsStroke( true ); @@ -712,7 +717,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer ) if( aText->GetText().Length() == 0 ) return; - COLOR4D strokeColor = GetColor( NULL, aText->GetLayer() ); + COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aText->GetLayer() ); VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); double orientation = aText->GetOrientation() * M_PI / 1800.0; @@ -736,8 +741,8 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) if( aText->GetLength() == 0 ) return; - COLOR4D strokeColor = GetColor( NULL, aLayer ); - VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y); + COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aLayer ); + VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); double orientation = aText->GetDrawRotation() * M_PI / 1800.0; m_gal->SetStrokeColor( strokeColor ); @@ -751,7 +756,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) void PCB_PAINTER::draw( const ZONE_CONTAINER* aZone ) { - COLOR4D color = GetColor( NULL, aZone->GetLayer() ); + COLOR4D color = m_pcbSettings->GetColor( NULL, aZone->GetLayer() ); std::deque corners; PCB_RENDER_SETTINGS::DisplayZonesMode displayMode = m_pcbSettings->m_displayZoneMode; @@ -828,7 +833,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) else { int layer = aDimension->GetLayer(); - COLOR4D strokeColor = GetColor( NULL, layer ); + COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, layer ); m_gal->SetStrokeColor( strokeColor ); m_gal->SetIsFill( false ); @@ -854,7 +859,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) void PCB_PAINTER::draw( const PCB_TARGET* aTarget ) { - COLOR4D strokeColor = GetColor( NULL, aTarget->GetLayer() ); + COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aTarget->GetLayer() ); VECTOR2D position( aTarget->GetPosition() ); double size, radius; diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index a51324500f..2e106f2b93 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -27,6 +27,7 @@ #define __CLASS_PCB_PAINTER_H #include +#include #include class EDA_ITEM; @@ -85,8 +86,11 @@ public: */ void LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions ); - const COLOR4D& GetLayerColor ( int aLayer ) const; - + /// @copydoc RENDER_SETTINGS::GetColor() + virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const; + + const COLOR4D& GetLayerColor( int aLayer ) const; + protected: /// @copydoc RENDER_SETTINGS::Update() void update(); @@ -129,13 +133,11 @@ public: PAINTER::ApplySettings( aSettings ); // Store PCB specific render settings - m_pcbSettings = dynamic_cast( aSettings ); + m_pcbSettings = (PCB_RENDER_SETTINGS*) m_settings.get(); //dynamic_cast( aSettings ); } - /// @copydoc PAINTER::GetColor() - virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ); - protected: + /// Just a properly casted pointer to settings PCB_RENDER_SETTINGS* m_pcbSettings; // Drawing functions for various types of PCB-specific items diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 0f909fce26..bf15c21989 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -120,9 +120,9 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) // menu Config /* Tom's hacks start */ - EVT_MENU ( ID_SELECTION_TOOL, PCB_EDIT_FRAME::onGenericCommand ) + EVT_MENU ( ID_SELECTION_TOOL, PCB_EDIT_FRAME::onGenericCommand ) EVT_TOOL ( ID_SELECTION_TOOL, PCB_EDIT_FRAME::onGenericCommand ) - EVT_MENU ( ID_PNS_ROUTER_TOOL, PCB_EDIT_FRAME::onGenericCommand ) + EVT_MENU ( ID_PNS_ROUTER_TOOL, PCB_EDIT_FRAME::onGenericCommand ) EVT_TOOL ( ID_PNS_ROUTER_TOOL, PCB_EDIT_FRAME::onGenericCommand ) /* Tom's hacks end */ @@ -487,6 +487,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, PCB_EDIT_FRAME::~PCB_EDIT_FRAME() { + destroyTools(); m_RecordingMacros = -1; for( int i = 0; i < 10; i++ ) @@ -729,7 +730,7 @@ void PCB_EDIT_FRAME::SetGridColor(EDA_COLOR_T aColor) bool PCB_EDIT_FRAME::IsMicroViaAcceptable( void ) { int copperlayercnt = GetBoard()->GetCopperLayerCount( ); - LAYER_NUM currLayer = getActiveLayer(); + LAYER_NUM currLayer = getCurrentLayer(); if( !GetDesignSettings().m_MicroViasAllowed ) return false; // Obvious.. @@ -753,55 +754,102 @@ void PCB_EDIT_FRAME::setHighContrastLayer( LAYER_NUM aLayer ) KiGfx::VIEW* view = m_galCanvas->GetView(); KiGfx::RENDER_SETTINGS* rSettings = view->GetPainter()->GetSettings(); - if( DisplayOpt.ContrastModeDisplay ) + setTopLayer( aLayer ); + + rSettings->ClearActiveLayers(); + rSettings->SetActiveLayer( aLayer ); + + if( IsCopperLayer( aLayer ) ) { - view->ClearTopLayers(); - view->SetTopLayer( aLayer ); + // Bring some other layers to the front in case of copper layers and make them colored + // fixme do not like the idea of storing the list of layers here, + // should be done in some other way I guess.. + LAYER_NUM layers[] = { + GetNetnameLayer( aLayer ), ITEM_GAL_LAYER( VIAS_VISIBLE ), + ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ), + ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ), + ITEM_GAL_LAYER( SELECTION ) + }; - rSettings->ClearActiveLayers(); - rSettings->SetActiveLayer( aLayer ); + for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) + rSettings->SetActiveLayer( layers[i] ); - if( IsCopperLayer( aLayer ) ) + // Pads should be shown too + if( aLayer == FIRST_COPPER_LAYER ) { - // Bring some other layers to the front in case of copper layers and make them colored - LAYER_NUM layers[] = { - GetNetnameLayer( aLayer ), ITEM_GAL_LAYER( VIAS_VISIBLE ), - ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ), - ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ) - }; + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); + } + else if( aLayer == LAST_COPPER_LAYER ) + { + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); + } + } - for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) - { - view->SetTopLayer( layers[i] ); - rSettings->SetActiveLayer( layers[i] ); - } + view->UpdateAllLayersColor(); +} - // Pads should be shown too - if( aLayer == FIRST_COPPER_LAYER ) - { - view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); - view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); - rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); - rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); - } - else if( aLayer == LAST_COPPER_LAYER ) - { - view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); - view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); - rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); - rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); - } + +void PCB_EDIT_FRAME::setTopLayer( LAYER_NUM aLayer ) +{ + // Set display settings for high contrast mode + KiGfx::VIEW* view = m_galCanvas->GetView(); + + view->ClearTopLayers(); + view->SetTopLayer( aLayer ); + + if( IsCopperLayer( aLayer ) ) + { + // Bring some other layers to the front in case of copper layers and make them colored + // fixme do not like the idea of storing the list of layers here, + // should be done in some other way I guess.. + LAYER_NUM layers[] = { + GetNetnameLayer( aLayer ), ITEM_GAL_LAYER( VIAS_VISIBLE ), + ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ), + ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ), + ITEM_GAL_LAYER( SELECTION ) + }; + + for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) + { + view->SetTopLayer( layers[i] ); } - view->UpdateAllLayersOrder(); - view->UpdateAllLayersColor(); + // Pads should be shown too + if( aLayer == FIRST_COPPER_LAYER ) + { + view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); + view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); + } + else if( aLayer == LAST_COPPER_LAYER ) + { + view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); + view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); + } } + + view->UpdateAllLayersOrder(); +} + + +void PCB_EDIT_FRAME::setCurrentLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate ) +{ + ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; + + setHighContrastLayer( aLayer ); + + if( doLayerWidgetUpdate ) + syncLayerWidgetLayer(); + + if( m_galCanvasActive ) + m_galCanvas->Refresh(); } void PCB_EDIT_FRAME::syncLayerWidgetLayer() { - m_Layers->SelectLayer( getActiveLayer() ); + m_Layers->SelectLayer( getCurrentLayer() ); m_Layers->OnLayerSelected(); } diff --git a/pcbnew/tool_pcb.cpp b/pcbnew/tool_pcb.cpp index 5b6fe3b95f..533106bf9b 100644 --- a/pcbnew/tool_pcb.cpp +++ b/pcbnew/tool_pcb.cpp @@ -105,7 +105,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator() previous_Route_Layer_BOTTOM_color, previous_via_color; /* get colors, and redraw bitmap button only on changes */ - active_layer_color = GetBoard()->GetLayerColor(getActiveLayer()); + active_layer_color = GetBoard()->GetLayerColor(getCurrentLayer()); if( previous_active_layer_color != active_layer_color ) { diff --git a/pcbnew/toolbars_update_user_interface.cpp b/pcbnew/toolbars_update_user_interface.cpp index 23d850d2b1..bd77618169 100644 --- a/pcbnew/toolbars_update_user_interface.cpp +++ b/pcbnew/toolbars_update_user_interface.cpp @@ -96,7 +96,7 @@ void PCB_EDIT_FRAME::OnUpdateSelectViaSize( wxUpdateUIEvent& aEvent ) void PCB_EDIT_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent ) { - m_SelLayerBox->SetLayerSelection( getActiveLayer() ); + m_SelLayerBox->SetLayerSelection( getCurrentLayer() ); } diff --git a/pcbnew/tools/move_tool.cpp b/pcbnew/tools/move_tool.cpp index f0783f6a40..f7839211c1 100644 --- a/pcbnew/tools/move_tool.cpp +++ b/pcbnew/tools/move_tool.cpp @@ -61,7 +61,7 @@ void MOVE_TOOL::Reset() } // the tool launches upon reception of activate ("pcbnew.InteractiveMove") - Go( &MOVE_TOOL::Main, TOOL_EVENT( TC_Command, TA_ActivateTool, GetName() ) ); //"pcbnew.InteractiveMove")); + Go( &MOVE_TOOL::Main, TOOL_EVENT( TC_Command, TA_ActivateTool, GetName() ) ); } diff --git a/pcbnew/tools/move_tool.h b/pcbnew/tools/move_tool.h index 1022230a69..1645237527 100644 --- a/pcbnew/tools/move_tool.h +++ b/pcbnew/tools/move_tool.h @@ -89,7 +89,8 @@ private: void RestorePosition() { - item->SetPosition( wxPoint( position.x, position.y ) ); + wxPoint curPosition = item->GetPosition(); + item->Move( wxPoint( position.x - curPosition.x, position.y - curPosition.y ) ); } void RestoreVisibility() diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index a4fa49d7db..9d2457c5ec 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -40,18 +40,25 @@ void PCB_EDIT_FRAME::setupTools() { - // create the manager and dispatcher. Route draw panel events to the dispatcher. + // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, this ); m_galCanvas->SetEventDispatcher( m_toolDispatcher ); - // register our selection tool. + // Register tools. m_toolManager->RegisterTool( new SELECTION_TOOL ); m_toolManager->RegisterTool( new ROUTER_TOOL ); m_toolManager->RegisterTool( new MOVE_TOOL ); } +void PCB_EDIT_FRAME::destroyTools() +{ + delete m_toolDispatcher; + delete m_toolManager; +} + + void PCB_EDIT_FRAME::onGenericCommand( wxCommandEvent &aEvent ) { m_toolDispatcher->DispatchWxCommand( aEvent ); diff --git a/pcbnew/tools/selection_area.cpp b/pcbnew/tools/selection_area.cpp index 5c30de222c..33d73d6d68 100644 --- a/pcbnew/tools/selection_area.cpp +++ b/pcbnew/tools/selection_area.cpp @@ -47,7 +47,7 @@ void SELECTION_AREA::ViewGetLayers( int aLayers[], int& aCount ) const } -void SELECTION_AREA::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const +void SELECTION_AREA::ViewDraw( int aLayer, GAL* aGal ) const { aGal->SetLineWidth( 1.0 ); aGal->SetStrokeColor( COLOR4D( 1.0, 1.0, 0.4, 1.0 ) ); diff --git a/pcbnew/tools/selection_area.h b/pcbnew/tools/selection_area.h index 8cc380b4ab..50db94f927 100644 --- a/pcbnew/tools/selection_area.h +++ b/pcbnew/tools/selection_area.h @@ -50,7 +50,7 @@ public: virtual const BOX2I ViewBBox() const; - void ViewDraw( int aLayer, KiGfx::GAL* aGal, const BOX2I& aVisibleArea ) const; + void ViewDraw( int aLayer, KiGfx::GAL* aGal ) const; void ViewGetLayers( int aLayers[], int& aCount ) const; void SetOrigin ( VECTOR2I aOrigin ) @@ -63,7 +63,7 @@ public: m_end = aEnd; } - void Show( int x, std::ostream& st) const + void Show( int x, std::ostream& st ) const { } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 63689482b5..cd1a4be5a1 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -111,8 +111,28 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) } else { - // Now user wants to drag the selected items - m_toolMgr->InvokeTool( "pcbnew.InteractiveMove" ); + bool runTool = false; + + // Check if dragging event started within the currently selected items bounding box + std::set::iterator it, it_end; + for( it = m_selectedItems.begin(), it_end = m_selectedItems.end(); it != it_end; ++it ) + { + BOX2I itemBox = (*it)->ViewBBox(); + itemBox.Inflate( 500000 ); // Give some margin for gripping an item + + if( itemBox.Contains( evt->Position() ) ) + { + // Click event occurred within a selected item bounding box + // -> user wants to drag selected items + runTool = true; + break; + } + } + + if( runTool ) + m_toolMgr->InvokeTool( "pcbnew.InteractiveMove" ); + else + clearSelection(); } } else if( dragging ) @@ -184,9 +204,26 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere ) break; default: - item = disambiguationMenu( &collector ); - if( item ) - toggleSelection( item ); + // Remove footprints, they have to be selected by clicking on area that does not + // contain anything but footprint + for( int i = 0; i < collector.GetCount(); ++i ) + { + BOARD_ITEM* boardItem = ( collector )[i]; + if( boardItem->Type() == PCB_MODULE_T ) + collector.Remove( i ); + } + + // Let's see if there is still disambiguation in selection.. + if( collector.GetCount() == 1 ) + { + toggleSelection( collector[0] ); + } + else + { + item = disambiguationMenu( &collector ); + if( item ) + toggleSelection( item ); + } break; } } @@ -306,7 +343,7 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) for( int i = 0; i < limit; ++i ) { wxString text; - BOARD_ITEM *item = ( *aCollector )[i]; + BOARD_ITEM* item = ( *aCollector )[i]; text = item->GetSelectMenuText(); m_menu->Add( text, i ); } diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp index 8973ffccb3..05d57bd5bb 100644 --- a/pcbnew/zones_by_polygon.cpp +++ b/pcbnew/zones_by_polygon.cpp @@ -518,7 +518,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) if( !GetBoard()->m_CurrentZoneContour ) { if( GetToolId() == ID_PCB_KEEPOUT_AREA_BUTT && - getActiveLayer() >= FIRST_NON_COPPER_LAYER ) + getCurrentLayer() >= FIRST_NON_COPPER_LAYER ) { DisplayError( this, _( "Error: a keepout area is allowed only on copper layers" ) ); @@ -537,7 +537,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) ZONE_EDIT_T edited; // Init zone params to reasonable values - zone->SetLayer( getActiveLayer() ); + zone->SetLayer( getCurrentLayer() ); // Prompt user for parameters: m_canvas->SetIgnoreMouseEvents( true ); @@ -602,7 +602,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) return 0; // Switch active layer to the selected zone layer - setActiveLayer( zoneInfo.m_CurrentZone_Layer ); + setCurrentLayer( zoneInfo.m_CurrentZone_Layer ); SetZoneSettings( zoneInfo ); } @@ -612,7 +612,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) // zone (add cutout or similar zone) zoneInfo.m_CurrentZone_Layer = s_CurrentZone->GetLayer(); - setActiveLayer( s_CurrentZone->GetLayer() ); + setCurrentLayer( s_CurrentZone->GetLayer() ); zoneInfo << *s_CurrentZone;