Commit a6484f1a authored by Maciej Suminski's avatar Maciej Suminski

Drawing tools used to crash when the drawing tool was interrupted - fixed.

parent b42091bc
...@@ -83,13 +83,16 @@ int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent ) ...@@ -83,13 +83,16 @@ int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent )
MODULE* module = m_board->m_Modules; MODULE* module = m_board->m_Modules;
EDGE_MODULE* line = new EDGE_MODULE( module ); EDGE_MODULE* line = new EDGE_MODULE( module );
while( drawSegment( S_SEGMENT, line ) ) while( drawSegment( S_SEGMENT, reinterpret_cast<DRAWSEGMENT*&>( line ) ) )
{ {
m_frame->OnModify(); if( line )
m_frame->SaveCopyInUndoList( module, UR_MODEDIT ); {
line->SetLocalCoord(); m_frame->OnModify();
line->SetParent( module ); m_frame->SaveCopyInUndoList( module, UR_MODEDIT );
module->GraphicalItems().PushFront( line ); line->SetLocalCoord();
line->SetParent( module );
module->GraphicalItems().PushFront( line );
}
line = new EDGE_MODULE( module ); line = new EDGE_MODULE( module );
} }
...@@ -102,9 +105,12 @@ int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent ) ...@@ -102,9 +105,12 @@ int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent )
while( drawSegment( S_SEGMENT, line ) ) while( drawSegment( S_SEGMENT, line ) )
{ {
m_board->Add( line ); if( line )
m_frame->OnModify(); {
m_frame->SaveCopyInUndoList( line, UR_NEW ); m_board->Add( line );
m_frame->OnModify();
m_frame->SaveCopyInUndoList( line, UR_NEW );
}
line = new DRAWSEGMENT; line = new DRAWSEGMENT;
} }
...@@ -126,13 +132,16 @@ int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent ) ...@@ -126,13 +132,16 @@ int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent )
MODULE* module = m_board->m_Modules; MODULE* module = m_board->m_Modules;
EDGE_MODULE* circle = new EDGE_MODULE( module ); EDGE_MODULE* circle = new EDGE_MODULE( module );
while( drawSegment( S_CIRCLE, circle ) ) while( drawSegment( S_CIRCLE, reinterpret_cast<DRAWSEGMENT*&>( circle ) ) )
{ {
m_frame->OnModify(); if( circle )
m_frame->SaveCopyInUndoList( module, UR_MODEDIT ); {
circle->SetLocalCoord(); m_frame->OnModify();
circle->SetParent( module ); m_frame->SaveCopyInUndoList( module, UR_MODEDIT );
module->GraphicalItems().PushFront( circle ); circle->SetLocalCoord();
circle->SetParent( module );
module->GraphicalItems().PushFront( circle );
}
circle = new EDGE_MODULE( module ); circle = new EDGE_MODULE( module );
} }
...@@ -145,9 +154,12 @@ int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent ) ...@@ -145,9 +154,12 @@ int DRAWING_TOOL::DrawCircle( TOOL_EVENT& aEvent )
while( drawSegment( S_CIRCLE, circle ) ) while( drawSegment( S_CIRCLE, circle ) )
{ {
m_board->Add( circle ); if( circle )
m_frame->OnModify(); {
m_frame->SaveCopyInUndoList( circle, UR_NEW ); m_board->Add( circle );
m_frame->OnModify();
m_frame->SaveCopyInUndoList( circle, UR_NEW );
}
circle = new DRAWSEGMENT; circle = new DRAWSEGMENT;
} }
...@@ -169,13 +181,16 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) ...@@ -169,13 +181,16 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
MODULE* module = m_board->m_Modules; MODULE* module = m_board->m_Modules;
EDGE_MODULE* arc = new EDGE_MODULE( module ); EDGE_MODULE* arc = new EDGE_MODULE( module );
while( drawArc( arc ) ) while( drawArc( reinterpret_cast<DRAWSEGMENT*&>( arc ) ) )
{ {
m_frame->OnModify(); if( arc )
m_frame->SaveCopyInUndoList( module, UR_MODEDIT ); {
arc->SetLocalCoord(); m_frame->OnModify();
arc->SetParent( module ); m_frame->SaveCopyInUndoList( module, UR_MODEDIT );
module->GraphicalItems().PushFront( arc ); arc->SetLocalCoord();
arc->SetParent( module );
module->GraphicalItems().PushFront( arc );
}
arc = new EDGE_MODULE( module ); arc = new EDGE_MODULE( module );
} }
...@@ -188,9 +203,12 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) ...@@ -188,9 +203,12 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
while( drawArc( arc ) ) while( drawArc( arc ) )
{ {
m_board->Add( arc ); if( arc )
m_frame->OnModify(); {
m_frame->SaveCopyInUndoList( arc, UR_NEW ); m_board->Add( arc );
m_frame->OnModify();
m_frame->SaveCopyInUndoList( arc, UR_NEW );
}
arc = new DRAWSEGMENT; arc = new DRAWSEGMENT;
} }
...@@ -939,7 +957,7 @@ int DRAWING_TOOL::SetAnchor( TOOL_EVENT& aEvent ) ...@@ -939,7 +957,7 @@ int DRAWING_TOOL::SetAnchor( TOOL_EVENT& aEvent )
} }
bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT* aGraphic ) bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic )
{ {
// Only two shapes are currently supported // Only two shapes are currently supported
assert( aShape == S_SEGMENT || aShape == S_CIRCLE ); assert( aShape == S_SEGMENT || aShape == S_CIRCLE );
...@@ -989,6 +1007,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT* aGraphic ) ...@@ -989,6 +1007,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT* aGraphic )
preview.Clear(); preview.Clear();
updatePreview = true; updatePreview = true;
delete aGraphic; delete aGraphic;
aGraphic = NULL;
break; break;
} }
...@@ -1049,7 +1068,8 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT* aGraphic ) ...@@ -1049,7 +1068,8 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT* aGraphic )
else // User has clicked twice in the same spot else // User has clicked twice in the same spot
{ // a clear sign that the current drawing is finished { // a clear sign that the current drawing is finished
delete aGraphic; // but only if at least one graphic was created delete aGraphic; // but only if at least one graphic was created
started = false; // otherwise - force user to draw more or cancel aGraphic = NULL; // otherwise - force user to draw more or cancel
started = false;
} }
preview.Clear(); preview.Clear();
...@@ -1081,7 +1101,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT* aGraphic ) ...@@ -1081,7 +1101,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT* aGraphic )
} }
bool DRAWING_TOOL::drawArc( DRAWSEGMENT* aGraphic ) bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic )
{ {
bool clockwise = true; // drawing direction of the arc bool clockwise = true; // drawing direction of the arc
double startAngle = 0.0f; // angle of the first arc line double startAngle = 0.0f; // angle of the first arc line
...@@ -1121,6 +1141,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT* aGraphic ) ...@@ -1121,6 +1141,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT* aGraphic )
preview.Clear(); preview.Clear();
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
delete aGraphic; delete aGraphic;
aGraphic = NULL;
break; break;
} }
......
...@@ -156,14 +156,14 @@ private: ...@@ -156,14 +156,14 @@ private:
///> be already created. The tool deletes the object if it is not added to a BOARD. ///> be already created. The tool deletes the object if it is not added to a BOARD.
///> @return False if the tool was cancelled before the origin was set or origin and end are ///> @return False if the tool was cancelled before the origin was set or origin and end are
///> the same point. ///> the same point.
bool drawSegment( int aShape, DRAWSEGMENT* aGraphic ); bool drawSegment( int aShape, DRAWSEGMENT*& aGraphic );
///> Starts drawing an arc. ///> Starts drawing an arc.
///> @param aGraphic is an object that is going to be used by the tool for drawing. It has to ///> @param aGraphic is an object that is going to be used by the tool for drawing. It has to
///> be already created. The tool deletes the object if it is not added to a BOARD. ///> be already created. The tool deletes the object if it is not added to a BOARD.
///> @return False if the tool was cancelled before the origin was set or origin and end are ///> @return False if the tool was cancelled before the origin was set or origin and end are
///> the same point. ///> the same point.
bool drawArc( DRAWSEGMENT* aGraphic ); bool drawArc( DRAWSEGMENT*& aGraphic );
///> Draws a polygon, that is added as a zone or a keepout area. ///> Draws a polygon, that is added as a zone or a keepout area.
///> @param aKeepout decides if the drawn polygon is a zone or a keepout area. ///> @param aKeepout decides if the drawn polygon is a zone or a keepout area.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment