diff --git a/qa/drc_proto/drc_proto_test.cpp b/qa/drc_proto/drc_proto_test.cpp index 9949b3c2f7..10b851e6d5 100644 --- a/qa/drc_proto/drc_proto_test.cpp +++ b/qa/drc_proto/drc_proto_test.cpp @@ -34,32 +34,162 @@ #include #include +class CONSOLE_LOG +{ +public: + enum COLOR { + RED = 0, + GREEN, + DEFAULT + }; + + CONSOLE_LOG() {}; + + void PrintProgress( const wxString& aMessage ) + { + if( m_lastLineIsProgressBar ) + eraseLastLine(); + + printf("%s", (const char *) aMessage.c_str() ); + fflush(stdout); + + m_lastLineIsProgressBar = true; + } + + + void Print( const wxString& aMessage ) + { + if( m_lastLineIsProgressBar ) + eraseLastLine(); + + printf("%s", (const char *) aMessage.c_str() ); + fflush(stdout); + + m_lastLineIsProgressBar = false; + } + + + void SetColor( COLOR color ) + { + std::map colorMap = + { + { RED, "\033[0;31m" }, + { GREEN, "\033[0;32m" }, + { DEFAULT, "\033[0;37m" } + }; + + printf( "%s", (const char*) colorMap[ color ].c_str() ); + fflush(stdout); + } + + +private: + void eraseLastLine() + { + printf("\r\033[K"); + fflush(stdout); + } + + bool m_lastLineIsProgressBar = false; + std::mutex m_lock; +}; + +class CONSOLE_PROGRESS_REPORTER : public PROGRESS_REPORTER +{ +public: + CONSOLE_PROGRESS_REPORTER( CONSOLE_LOG* log ) : + PROGRESS_REPORTER( 0 ), + m_log( log ) {}; + ~CONSOLE_PROGRESS_REPORTER() {}; + + virtual void SetCurrentProgress( double aProgress ) override + { + PROGRESS_REPORTER::SetCurrentProgress( aProgress ); + updateUI(); + } + +private: + virtual bool updateUI() override + { + m_log->SetColor( CONSOLE_LOG::GREEN ); + m_log->PrintProgress( wxString::Format( " | %s : %.02f%%", m_rptMessage, (double) m_progress / (double) m_maxProgress * 100.0 ) ); + return true; + } + + CONSOLE_LOG* m_log; +}; + +class CONSOLE_MSG_REPORTER : public REPORTER +{ +public: + CONSOLE_MSG_REPORTER( CONSOLE_LOG *log ) : + m_log(log) + {}; + ~CONSOLE_MSG_REPORTER() {}; + + + virtual REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override + { + switch( aSeverity ) + { + case RPT_SEVERITY_ERROR: + m_log->SetColor( CONSOLE_LOG::RED ); + m_log->Print("ERROR | "); + default: + m_log->SetColor( CONSOLE_LOG::DEFAULT ); + m_log->Print(" | "); + } + + m_log->SetColor( CONSOLE_LOG::DEFAULT ); + m_log->Print( aText + "\n" ); + return *this; + } + + virtual bool HasMessage() const override + { + return true; + } + +private: + CONSOLE_LOG* m_log; +}; + int main( int argc, char *argv[] ) { - - wxLogTrace("DUPA", "Debug Test!\n"); - PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); propMgr.Rebuild(); - STDOUT_REPORTER msgReporter; - - auto brd = KI_TEST::ReadBoardFromFileOrStream(argv[1]); - - test::DRC_ENGINE drcEngine( brd.get(), &brd->GetDesignSettings() ); - - drcEngine.SetLogReporter( &msgReporter ); - - try - { - drcEngine.LoadRules( wxString( argv[2] ) ); - } - catch( PARSE_ERROR& err ) + + if( argc < 2 ) { + printf("usage: %s board_file.kicad_pcb [drc-rules-file]\n", argv[0] ); return -1; } + auto brd = KI_TEST::ReadBoardFromFileOrStream( argv[1] ); + + test::DRC_ENGINE drcEngine( brd.get(), &brd->GetDesignSettings() ); + + CONSOLE_LOG consoleLog; + + drcEngine.SetLogReporter( new CONSOLE_MSG_REPORTER ( &consoleLog ) ); + drcEngine.SetProgressReporter( new CONSOLE_PROGRESS_REPORTER ( &consoleLog ) ); + + if( argc > 2 ) + { + try + { + drcEngine.LoadRules( wxString( argv[2] ) ); + } + catch( PARSE_ERROR& err ) + { + return -1; + } + } + drcEngine.RunTests(); + auto report = drcEngine.GetReport(); + return 0; }