Make ITEM_MODIFICATION_ROUTINE status messages more general and easier to call

This commit is contained in:
John Beard 2023-09-30 21:38:40 +01:00
parent b18fd12694
commit b6cd7e3b4a
3 changed files with 45 additions and 30 deletions

View File

@ -1386,10 +1386,9 @@ int EDIT_TOOL::ModifyLines( const TOOL_EVENT& aEvent )
commit.Push( pairwise_line_routine->GetCommitDescription() );
if( pairwise_line_routine->GetSuccesses() == 0 )
frame()->ShowInfoBarMsg( pairwise_line_routine->GetCompleteFailureMessage() );
else if( pairwise_line_routine->GetFailures() > 0 )
frame()->ShowInfoBarMsg( pairwise_line_routine->GetSomeFailuresMessage() );
if (const std::optional<wxString> msg = pairwise_line_routine->GetStatusMessage()) {
frame()->ShowInfoBarMsg( *msg );
}
return 0;
}

View File

@ -63,15 +63,20 @@ wxString LINE_FILLET_ROUTINE::GetCommitDescription() const
return _( "Fillet Lines" );
}
wxString LINE_FILLET_ROUTINE::GetCompleteFailureMessage() const
std::optional<wxString> LINE_FILLET_ROUTINE::GetStatusMessage() const
{
return _( "Unable to fillet the selected lines." );
if( GetSuccesses() == 0 )
{
return _( "Unable to fillet the selected lines." );
}
else if( GetFailures() > 0 )
{
return _( "Some of the lines could not be filleted." );
}
return std::nullopt;
}
wxString LINE_FILLET_ROUTINE::GetSomeFailuresMessage() const
{
return _( "Some of the lines could not be filleted." );
}
void LINE_FILLET_ROUTINE::ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB )
{
@ -168,15 +173,20 @@ wxString LINE_CHAMFER_ROUTINE::GetCommitDescription() const
return _( "Chamfer Lines" );
}
wxString LINE_CHAMFER_ROUTINE::GetCompleteFailureMessage() const
std::optional<wxString> LINE_CHAMFER_ROUTINE::GetStatusMessage() const
{
return _( "Unable to chamfer the selected lines." );
if( GetSuccesses() == 0 )
{
return _( "Unable to chamfer the selected lines." );
}
else if( GetFailures() > 0 )
{
return _( "Some of the lines could not be chamfered." );
}
return std::nullopt;
}
wxString LINE_CHAMFER_ROUTINE::GetSomeFailuresMessage() const
{
return _( "Some of the lines could not be chamfered." );
}
void LINE_CHAMFER_ROUTINE::ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB )
{
@ -230,15 +240,20 @@ wxString LINE_EXTENSION_ROUTINE::GetCommitDescription() const
return _( "Extend Lines to Meet" );
}
wxString LINE_EXTENSION_ROUTINE::GetCompleteFailureMessage() const
std::optional<wxString> LINE_EXTENSION_ROUTINE::GetStatusMessage() const
{
return _( "Unable to extend the selected lines to meet." );
if( GetSuccesses() == 0 )
{
return _( "Unable to extend the selected lines to meet." );
}
else if( GetFailures() > 0 )
{
return _( "Some of the lines could not be extended to meet." );
}
return std::nullopt;
}
wxString LINE_EXTENSION_ROUTINE::GetSomeFailuresMessage() const
{
return _( "Some of the lines could not be extended to meet." );
}
void LINE_EXTENSION_ROUTINE::ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB )
{

View File

@ -164,8 +164,12 @@ public:
virtual wxString GetCommitDescription() const = 0;
virtual wxString GetCompleteFailureMessage() const = 0;
virtual wxString GetSomeFailuresMessage() const = 0;
/**
* @brief Get a status message to show when the routine is complete
*
* Usually this will be an error or nothing.
*/
virtual std::optional<wxString> GetStatusMessage() const = 0;
protected:
/**
@ -246,8 +250,7 @@ public:
}
wxString GetCommitDescription() const override;
wxString GetCompleteFailureMessage() const override;
wxString GetSomeFailuresMessage() const override;
std::optional<wxString> GetStatusMessage() const override;
void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
@ -269,8 +272,7 @@ public:
}
wxString GetCommitDescription() const override;
wxString GetCompleteFailureMessage() const override;
wxString GetSomeFailuresMessage() const override;
std::optional<wxString> GetStatusMessage() const override;
void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
@ -290,8 +292,7 @@ public:
}
wxString GetCommitDescription() const override;
wxString GetCompleteFailureMessage() const override;
wxString GetSomeFailuresMessage() const override;
std::optional<wxString> GetStatusMessage() const override;
void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
};