bool Interactor2DVolumeEdit::ProcessMouseUpEvent( QMouseEvent* event, RenderView* renderview ) { // RenderView2D* view = ( RenderView2D* )renderview; UpdateCursor( event, renderview ); if ( m_bEditing ) { m_nMousePosX = event->x(); m_nMousePosY = event->y(); if ( event->button() != Qt::LeftButton || (m_nAction != EM_Polyline && m_nAction != EM_Livewire ) || m_dPolylinePoints.size() == 0 ) { m_bEditing = false; } LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( m_strLayerTypeName ); LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer(); // mri->SendBroadcast( "LayerEdited", mri ); return false; } else { return Interactor2D::ProcessMouseUpEvent( event, renderview ); } }
void PanelSurface::UpdateLayerList( Layer* layer ) { LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "Surface" ); int nIndex = lc->GetLayerIndex( layer ); std::vector<Layer*> layers = lc->GetLayers(); if ( nIndex != -1 ) { m_listBoxLayers->Clear(); int nSel = 0; for ( size_t i = 0; i < layers.size(); i++ ) { m_listBoxLayers->Append( wxString::FromAscii( layers[i]->GetName() ), layers[i] ); m_listBoxLayers->Check( i, layers[i]->IsVisible() ); if ( lc->GetActiveLayer() == layers[i] ) nSel = i; } m_listBoxLayers->SetSelection( nSel ); UpdateUI(); } }
bool Interactor2DRegionEdit::ProcessMouseMoveEvent( wxMouseEvent& event, RenderView* renderview ) { RenderView2D* view = ( RenderView2D* )renderview; if ( m_bEditing ) { UpdateCursor( event, view ); int posX = event.GetX(); int posY = event.GetY(); if ( m_nAction == EM_Freehand ) { LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" ); LayerMRI* mri = ( LayerMRI* )lc->GetActiveLayer(); double ras1[3], ras2[3]; view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras1 ); view->MousePositionToRAS( posX, posY, ras2 ); mri->SetVoxelByRAS( ras1, ras2, view->GetViewPlane(), !event.ShiftDown() ); } else if ( m_nAction == EM_Polyline ) { double ras[3]; view->MousePositionToRAS( posX, posY, ras ); view->GetCursor2D()->SetPosition2( ras ); view->GetCursor2D()->SetPosition( view->GetCursor2D()->GetPosition(), true ); view->NeedRedraw(); } m_nMousePosX = posX; m_nMousePosY = posY; return false; } else { return Interactor2D::ProcessMouseMoveEvent( event, renderview ); } }
bool Interactor2DVolumeEdit::ProcessMouseUpEvent( wxMouseEvent& event, RenderView* renderview ) { // RenderView2D* view = ( RenderView2D* )renderview; UpdateCursor( event, renderview ); if ( m_bEditing ) { m_nMousePosX = event.GetX(); m_nMousePosY = event.GetY(); if ( !event.LeftUp() || (m_nAction != EM_Polyline && m_nAction != EM_Livewire )|| m_dPolylinePoints.size() == 0 ) m_bEditing = false; LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( m_strLayerTypeName.c_str() ); LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer(); mri->SendBroadcast( "LayerEdited", mri ); return false; } else { return Interactor2D::ProcessMouseUpEvent( event, renderview ); } }
bool Interactor2DVolumeEdit::ProcessMouseDownEvent( QMouseEvent* event, RenderView* renderview ) { RenderView2D* view = ( RenderView2D* )renderview; if ( !view->hasFocus() ) { return Interactor2D::ProcessMouseDownEvent( event, renderview ); } if ( event->button() == Qt::LeftButton || ( event->button() == Qt::RightButton && (event->buttons() & Qt::LeftButton) ) ) { if ( (event->modifiers() & CONTROL_MODIFIER ) && (event->modifiers() & Qt::ShiftModifier) ) { return Interactor2D::ProcessMouseDownEvent( event, renderview ); } LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( m_strLayerTypeName ); LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer(); if ( (!mri || !mri->IsVisible()) ) //&& ( event->ControlDown() || m_nAction == EM_Polyline ) ) { emit Error( "LayerNotVisible", mri ); } else if ( !mri->IsEditable() ) //&& ( event->ControlDown() || m_nAction == EM_Polyline ) ) { emit Error( "LayerNotEditable", mri ); } else if ( m_strLayerTypeName == "MRI" && ((LayerMRI*)mri)->IsTransformed() ) { emit Error( "LayerNotEditableForTransformation", mri ); } else { m_nMousePosX = event->x(); m_nMousePosY = event->y(); double ras[3]; view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras ); bool bCondition = !(event->modifiers() & Qt::ShiftModifier) && !(event->buttons() & Qt::RightButton); if ( m_nAction == EM_Freehand ) //&& ( event->ControlDown() ) ) { mri->SaveForUndo( view->GetViewPlane() ); if ( event->modifiers() & CONTROL_MODIFIER ) { mri->FloodFillByRAS( ras, view->GetViewPlane(), bCondition ); } else { m_bEditing = true; mri->SetVoxelByRAS( ras, view->GetViewPlane(),bCondition ); } } else if ( m_nAction == EM_Fill ) //&& ( event->ControlDown() ) ) { mri->SaveForUndo( view->GetViewPlane() ); mri->FloodFillByRAS( ras, view->GetViewPlane(), bCondition ); } else if ( m_nAction == EM_Polyline || m_nAction == EM_Livewire ) { mri->SaveForUndo( view->GetViewPlane() ); if ( event->modifiers() & CONTROL_MODIFIER ) { mri->FloodFillByRAS( ras, view->GetViewPlane(), bCondition ); } else { m_bEditing = true; double ras2[3]; view->GetCursor2D()->ClearInterpolationPoints(); view->GetCursor2D()->GetPosition( ras2 ); view->GetCursor2D()->SetPosition( ras ); view->GetCursor2D()->SetPosition2( ras ); if ( m_dPolylinePoints.size() > 0 ) { if ( m_nAction == EM_Polyline ) { mri->SetVoxelByRAS( ras, ras2, view->GetViewPlane(), bCondition ); } else { mri->SetLiveWireByRAS( ras, ras2, view->GetViewPlane() ); } } else { // mri->SaveForUndo( view->GetViewPlane() ); m_dPolylinePoints.push_back( ras[0] ); m_dPolylinePoints.push_back( ras[1] ); m_dPolylinePoints.push_back( ras[2] ); view->GetCursor2D()->SetPosition( ras ); } view->grabMouse(); } } else if ( m_nAction == EM_ColorPicker && mri->IsTypeOf( "MRI" ) ) { if ( event->modifiers() & CONTROL_MODIFIER ) { mri->SaveForUndo( view->GetViewPlane() ); mri->FloodFillByRAS( ras, view->GetViewPlane(), bCondition ); } else { double dValue = ((LayerMRI*)mri)->GetVoxelValue( ras ); if ( dValue != 0 ) { mri->SetFillValue( (float)dValue ); } } } else if ( m_nAction == EM_Contour && mri->IsTypeOf( "MRI" ) ) { LayerMRI* mri_ref = (LayerMRI*)MainWindow::GetMainWindow()->GetBrushProperty()->GetReferenceLayer(); if ( !mri_ref ) { emit Error( "LayerReferenceNotSet" ); return false; } Contour2D* c2d = view->GetContour2D(); if ( (event->modifiers() & CONTROL_MODIFIER) && (event->modifiers() & Qt::AltModifier) ) { double dValue = mri_ref->GetVoxelValue( ras ); if ( dValue != 0 ) { m_bEditing = true; c2d->SetInput( mri_ref->GetSliceImageData( view->GetViewPlane() ), dValue, ras[view->GetViewPlane()], mri_ref->GetActiveFrame() ); c2d->SetVisible( true ); view->RequestRedraw(); } else if ( c2d->IsVisible() ) { m_bEditing = true; } } else if ( (event->modifiers() & CONTROL_MODIFIER) && !(event->modifiers() & Qt::AltModifier) ) { mri->SaveForUndo( view->GetViewPlane() ); ((LayerMRI*)mri)->FloodFillByContour2D( ras, c2d ); } else if ( event->modifiers() & Qt::ShiftModifier ) { m_bEditing = true; c2d->RemoveLine( ras, ras ); view->RequestRedraw(); } else { m_bEditing = true; c2d->AddLine( ras, ras ); view->RequestRedraw(); } } else { return Interactor2D::ProcessMouseDownEvent( event, renderview ); } } return false; } else if ( m_bEditing ) { m_bEditing = false; if ( m_nAction == EM_Polyline || m_nAction == EM_Livewire ) { if ( event->button() == Qt::MidButton ) { view->GetCursor2D()->Update(); view->RequestRedraw(); } else if ( event->button() == Qt::RightButton ) { if ( m_dPolylinePoints.size() > 0 && m_nAction == EM_Polyline ) { LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( m_strLayerTypeName ); LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer(); double ras1[3] = { m_dPolylinePoints[0], m_dPolylinePoints[1], m_dPolylinePoints[2] }; double ras2[3]; view->GetCursor2D()->GetPosition( ras2 ); view->GetCursor2D()->SetPosition2( ras2 ); view->GetCursor2D()->SetPosition( ras1 ); mri->SetVoxelByRAS( ras1, ras2, view->GetViewPlane(), !(event->modifiers() & Qt::ShiftModifier) ); } else { // mri->SetLiveWireByRAS( ras1, ras2, view->GetViewPlane() ); view->GetCursor2D()->Update(); view->RequestRedraw(); } } } m_dPolylinePoints.clear(); view->releaseMouse(); return false; } return Interactor2D::ProcessMouseDownEvent( event, renderview ); // pass down the event }
bool Interactor2DVolumeEdit::ProcessMouseMoveEvent( QMouseEvent* event, RenderView* renderview ) { RenderView2D* view = ( RenderView2D* )renderview; if ( m_bEditing ) { UpdateCursor( event, view ); int posX = event->x(); int posY = event->y(); LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( m_strLayerTypeName ); LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer(); if ( m_nAction == EM_Freehand ) { double ras1[3], ras2[3]; view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras1 ); view->MousePositionToRAS( posX, posY, ras2 ); mri->SetVoxelByRAS( ras1, ras2, view->GetViewPlane(), !(event->modifiers() & Qt::ShiftModifier) && !(event->buttons() & Qt::RightButton) ); } else if ( m_nAction == EM_Polyline || m_nAction == EM_Livewire ) { double ras[3]; view->MousePositionToRAS( posX, posY, ras ); view->GetCursor2D()->SetPosition2( ras ); if ( m_nAction == EM_Livewire ) { view->GetCursor2D()->SetInterpolationPoints( mri->GetLiveWirePointsByRAS( ras, view->GetCursor2D()->GetPosition(), view->GetViewPlane() ) ); } view->GetCursor2D()->SetPosition( view->GetCursor2D()->GetPosition(), true ); view->RequestRedraw(); } else if ( m_nAction == EM_Contour ) { LayerMRI* mri_ref = (LayerMRI*)MainWindow::GetMainWindow()->GetBrushProperty()->GetReferenceLayer(); Contour2D* c2d = view->GetContour2D(); if ( event->modifiers() & Qt::ShiftModifier ) { double ras1[3], ras2[3]; view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras1 ); view->MousePositionToRAS( posX, posY, ras2 ); c2d->RemoveLine( ras1, ras2 ); } else if ( (event->modifiers() & CONTROL_MODIFIER) && (event->modifiers() & Qt::AltModifier) ) { double scale = 0.2; if ( mri_ref ) { double dMin = mri_ref->GetProperty()->GetMinValue(); double dMax = mri_ref->GetProperty()->GetMaxValue(); scale = ( dMax - dMin ) * 0.0005; } c2d->SetContourValue( c2d->GetContourValue() + scale * ( posY - m_nMousePosY ) ); } else { double ras1[3], ras2[3]; view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras1 ); view->MousePositionToRAS( posX, posY, ras2 ); c2d->AddLine( ras1, ras2 ); } view->RequestRedraw(); } m_nMousePosX = posX; m_nMousePosY = posY; return false; } else { return Interactor2D::ProcessMouseMoveEvent( event, renderview ); } }
bool Interactor2DVolumeEdit::ProcessMouseDownEvent( wxMouseEvent& event, RenderView* renderview ) { RenderView2D* view = ( RenderView2D* )renderview; // UpdateCursor( event, view ); if ( event.LeftDown() || ( event.RightDown() && event.LeftIsDown() ) ) { if ( event.CmdDown() && event.ShiftDown() ) return Interactor2D::ProcessMouseDownEvent( event, renderview ); LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollectionManager()->GetLayerCollection( m_strLayerTypeName.c_str() ); LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer(); if ( (!mri || !mri->IsVisible()) ) //&& ( event.CmdDown() || m_nAction == EM_Polyline ) ) { SendBroadcast( m_strLayerTypeName + "NotVisible", this ); } else if ( !mri->IsEditable() ) //&& ( event.CmdDown() || m_nAction == EM_Polyline ) ) { SendBroadcast( m_strLayerTypeName + "NotEditable", this ); } else if ( m_strLayerTypeName == "MRI" && ((LayerMRI*)mri)->IsTransformed() ) { SendBroadcast( m_strLayerTypeName + "NotEditableForTransformation", this ); } else { m_nMousePosX = event.GetX(); m_nMousePosY = event.GetY(); double ras[3]; view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras ); if ( m_nAction == EM_Freehand ) //&& ( event.CmdDown() ) ) { mri->SaveForUndo( view->GetViewPlane() ); if ( event.CmdDown() ) { mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() ); } else { m_bEditing = true; mri->SetVoxelByRAS( ras, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() ); } } else if ( m_nAction == EM_Fill ) //&& ( event.CmdDown() ) ) { mri->SaveForUndo( view->GetViewPlane() ); mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() ); } else if ( m_nAction == EM_Polyline || m_nAction == EM_Livewire ) { mri->SaveForUndo( view->GetViewPlane() ); if ( event.CmdDown() ) { mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() ); } else { m_bEditing = true; double ras2[3]; view->GetCursor2D()->ClearInterpolationPoints(); view->GetCursor2D()->GetPosition( ras2 ); view->GetCursor2D()->SetPosition( ras ); view->GetCursor2D()->SetPosition2( ras ); if ( m_dPolylinePoints.size() > 0 ) { if ( m_nAction == EM_Polyline ) mri->SetVoxelByRAS( ras, ras2, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() ); else mri->SetLiveWireByRAS( ras, ras2, view->GetViewPlane() ); } else { // mri->SaveForUndo( view->GetViewPlane() ); m_dPolylinePoints.push_back( ras[0] ); m_dPolylinePoints.push_back( ras[1] ); m_dPolylinePoints.push_back( ras[2] ); view->GetCursor2D()->SetPosition( ras ); } if ( view->GetCapture() == view ) view->ReleaseMouse(); view->CaptureMouse(); } } else if ( m_nAction == EM_ColorPicker && mri->IsTypeOf( "MRI" ) ) { if ( event.CmdDown() ) { mri->SaveForUndo( view->GetViewPlane() ); mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() && !event.RightIsDown() ); } else { double dValue = ((LayerMRI*)mri)->GetVoxelValue( ras ); if ( dValue != 0 ) { mri->SetFillValue( (float)dValue ); mri->SendBroadcast( "LayerActorUpdated", mri ); } } } else if ( m_nAction == EM_Contour && mri->IsTypeOf( "MRI" ) ) { LayerMRI* mri_ref = (LayerMRI*)MainWindow::GetMainWindowPointer()->GetBrushProperty()->GetReferenceLayer(); if ( !mri_ref ) { SendBroadcast( m_strLayerTypeName + "ReferenceNotSet", this ); return false; } Contour2D* c2d = view->GetContour2D(); if ( event.CmdDown() && event.AltDown() ) { double dValue = mri_ref->GetVoxelValue( ras ); if ( dValue != 0 ) { m_bEditing = true; c2d->SetInput( mri_ref->GetSliceImageData( view->GetViewPlane() ), dValue, ras[view->GetViewPlane()], mri_ref->GetActiveFrame() ); c2d->SetVisible( true ); view->NeedRedraw(); } else if ( c2d->IsVisible() ) { m_bEditing = true; } } else if ( event.CmdDown() && !event.AltDown() ) { mri->SaveForUndo( view->GetViewPlane() ); ((LayerMRI*)mri)->FloodFillByContour2D( ras, c2d ); } else if ( event.ShiftDown() ) { m_bEditing = true; c2d->RemoveLine( ras, ras ); view->NeedRedraw(); } else { m_bEditing = true; c2d->AddLine( ras, ras ); view->NeedRedraw(); } } else return Interactor2D::ProcessMouseDownEvent( event, renderview ); } return false; } else if ( m_bEditing ) { m_bEditing = false; if ( m_nAction == EM_Polyline || m_nAction == EM_Livewire ) { if ( event.MiddleDown() ) { view->GetCursor2D()->Update(); view->NeedRedraw(); } else if ( event.RightDown() ) { if ( m_dPolylinePoints.size() > 0 && m_nAction == EM_Polyline ) { LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( m_strLayerTypeName.c_str() ); LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer(); double ras1[3] = { m_dPolylinePoints[0], m_dPolylinePoints[1], m_dPolylinePoints[2] }; double ras2[3]; view->GetCursor2D()->GetPosition( ras2 ); view->GetCursor2D()->SetPosition2( ras2 ); view->GetCursor2D()->SetPosition( ras1 ); mri->SetVoxelByRAS( ras1, ras2, view->GetViewPlane(), !event.ShiftDown() ); } else { // mri->SetLiveWireByRAS( ras1, ras2, view->GetViewPlane() ); view->GetCursor2D()->Update(); view->NeedRedraw(); } } } m_dPolylinePoints.clear(); if ( view->GetCapture() == view ) view->ReleaseMouse(); return false; } return Interactor2D::ProcessMouseDownEvent( event, renderview ); // pass down the event }
bool Interactor2DRegionEdit::ProcessMouseDownEvent( wxMouseEvent& event, RenderView* renderview ) { RenderView2D* view = ( RenderView2D* )renderview; // UpdateCursor( event, view ); if ( event.LeftDown() ) { // if ( event.CmdDown() ) // return Interactor2D::ProcessMouseDownEvent( event, renderview ); LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollectionManager()->GetLayerCollection( "MRI" ); LayerMRI* mri = ( LayerMRI* )lc->GetActiveLayer(); if ( (!mri || !mri->IsVisible()) ) //&& ( event.CmdDown() || m_nAction == EM_Polyline ) ) { SendBroadcast( "MRINotVisible", this ); } else if ( !mri->IsEditable() ) //&& ( event.CmdDown() || m_nAction == EM_Polyline ) ) { SendBroadcast( "MRINotEditable", this ); } else { m_nMousePosX = event.GetX(); m_nMousePosY = event.GetY(); double ras[3]; view->MousePositionToRAS( m_nMousePosX, m_nMousePosY, ras ); if ( m_nAction == EM_Freehand ) //&& ( event.CmdDown() ) ) { mri->SaveForUndo( view->GetViewPlane() ); if ( event.CmdDown() ) { mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() ); } else { m_bEditing = true; mri->SetVoxelByRAS( ras, view->GetViewPlane(), !event.ShiftDown() ); } } else if ( m_nAction == EM_Fill ) //&& ( event.CmdDown() ) ) { mri->SaveForUndo( view->GetViewPlane() ); mri->FloodFillByRAS( ras, view->GetViewPlane(), !event.ShiftDown() ); } else if ( m_nAction == EM_Polyline ) { m_bEditing = true; double ras2[3]; view->GetCursor2D()->GetPosition( ras2 ); view->GetCursor2D()->SetPosition( ras ); view->GetCursor2D()->SetPosition2( ras ); if ( m_dPolylinePoints.size() > 0 ) { mri->SetVoxelByRAS( ras, ras2, view->GetViewPlane(), !event.ShiftDown() ); } else { mri->SaveForUndo( view->GetViewPlane() ); m_dPolylinePoints.push_back( ras[0] ); m_dPolylinePoints.push_back( ras[1] ); m_dPolylinePoints.push_back( ras[2] ); } if ( view->GetCapture() == view ) view->ReleaseMouse(); view->CaptureMouse(); } else return Interactor2D::ProcessMouseDownEvent( event, renderview ); } return false; } else if ( m_bEditing ) { m_bEditing = false; if ( m_nAction == EM_Polyline ) { if ( event.MiddleDown() ) { view->GetCursor2D()->Update(); view->NeedRedraw(); } else if ( event.RightDown() ) { if ( m_dPolylinePoints.size() > 0 ) { LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" ); LayerMRI* mri = ( LayerMRI* )lc->GetActiveLayer(); double ras1[3] = { m_dPolylinePoints[0], m_dPolylinePoints[1], m_dPolylinePoints[2] }; double ras2[3]; view->GetCursor2D()->GetPosition( ras2 ); view->GetCursor2D()->SetPosition2( ras2 ); view->GetCursor2D()->SetPosition( ras1 ); mri->SetVoxelByRAS( ras1, ras2, view->GetViewPlane(), !event.ShiftDown() ); } } } m_dPolylinePoints.clear(); if ( view->GetCapture() == view ) view->ReleaseMouse(); return false; } return Interactor2D::ProcessMouseDownEvent( event, renderview ); // pass down the event }
bool Interactor2DMeasure::ProcessMouseDownEvent( QMouseEvent* event, RenderView* renderview ) { RenderView2D* view = ( RenderView2D* )renderview; // UpdateCursor( event, view ); if ( m_region && !m_bDrawing && !m_bEditing ) { m_region->Highlight( false ); } if ( event->button() == Qt::LeftButton ) { if ( ( event->modifiers() & CONTROL_MODIFIER ) && ( event->modifiers() & Qt::ShiftModifier ) ) { return Interactor2D::ProcessMouseDownEvent( event, renderview ); } LayerCollection* lc = MainWindow::GetMainWindow()->GetLayerCollection( "MRI" ); LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer(); if ( mri ) { m_nMousePosX = event->x(); m_nMousePosY = event->y(); if ( m_region && m_bDrawing ) // drawing { ((Region2DPolyline*)m_region)->AddPoint( m_nMousePosX, m_nMousePosY ); } else { Region2D* reg = view->GetRegion( m_nMousePosX, m_nMousePosY, &m_nPointIndex ); if ( !reg ) // new region { if ( m_nAction == MM_Line ) { Region2DLine* reg_line = new Region2DLine( view ); reg_line->SetLine( m_nMousePosX, m_nMousePosY, m_nMousePosX, m_nMousePosY ); view->AddRegion( reg_line ); m_region = reg_line; } else if ( m_nAction == MM_Spline || m_nAction == MM_Polyline ) { Region2DPolyline* reg_polyline = new Region2DPolyline( view, m_nAction == MM_Spline ); reg_polyline->AddPoint( m_nMousePosX, m_nMousePosY ); reg_polyline->AddPoint( m_nMousePosX, m_nMousePosY ); // add second point view->AddRegion( reg_polyline ); m_region = reg_polyline; } else if ( m_nAction == MM_Rectangle ) { Region2DRectangle* reg_rect = new Region2DRectangle( view ); reg_rect->SetRect( m_nMousePosX, m_nMousePosY, 1, 1 ); view->AddRegion( reg_rect ); m_region = reg_rect; } m_bDrawing = true; } else // editing { m_region = reg; m_bEditing = true; m_region->Highlight(); view->EmitRegionSelected( reg ); view->RequestRedraw(); } } return false; } } else if ( event->button() == Qt::RightButton ) { if ( m_bDrawing && m_region ) { m_bDrawing = false; m_bEditing = false; if ( m_nAction == MM_Spline || m_nAction == MM_Polyline ) { ((Region2DPolyline*)m_region)->RemoveLastPoint(); } view->RequestRedraw(); return false; } } return Interactor2D::ProcessMouseDownEvent( event, renderview ); // pass down the event }
bool Interactor2DMeasure::ProcessMouseDownEvent( wxMouseEvent& event, RenderView* renderview ) { RenderView2D* view = ( RenderView2D* )renderview; // UpdateCursor( event, view ); if ( m_region && !m_bDrawing && !m_bEditing ) m_region->Highlight( false ); if ( event.LeftDown() ) { if ( event.CmdDown() && event.ShiftDown() ) return Interactor2D::ProcessMouseDownEvent( event, renderview ); LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollectionManager()->GetLayerCollection( "MRI" ); LayerVolumeBase* mri = ( LayerVolumeBase* )lc->GetActiveLayer(); if ( mri ) { m_nMousePosX = event.GetX(); m_nMousePosY = event.GetY(); Region2D* reg = view->GetRegion( m_nMousePosX, m_nMousePosY, &m_nPointIndex ); if ( m_region && m_bDrawing ) { ((Region2DPolyline*)m_region)->AddPoint( m_nMousePosX, m_nMousePosY ); } else if ( !reg ) // drawing { if ( m_nAction == MM_Line ) { Region2DLine* reg_line = new Region2DLine( view ); reg_line->SetLine( m_nMousePosX, m_nMousePosY, m_nMousePosX, m_nMousePosY ); view->AddRegion( reg_line ); m_region = reg_line; } else if ( m_nAction == MM_Spline || m_nAction == MM_Polyline ) { Region2DPolyline* reg_polyline = new Region2DPolyline( view, m_nAction == MM_Spline ); reg_polyline->AddPoint( m_nMousePosX, m_nMousePosY ); reg_polyline->AddPoint( m_nMousePosX, m_nMousePosY ); // add second point view->AddRegion( reg_polyline ); m_region = reg_polyline; } else if ( m_nAction == MM_Rectangle ) { Region2DRectangle* reg_rect = new Region2DRectangle( view ); reg_rect->SetRect( m_nMousePosX, m_nMousePosY, 1, 1 ); view->AddRegion( reg_rect ); m_region = reg_rect; } m_bDrawing = true; } else // editing { m_region = reg; m_bEditing = true; m_region->Highlight(); view->SendBroadcast( "RegionSelected", m_region ); view->NeedRedraw(); } return false; } } else if ( event.RightDown() ) { if ( m_bDrawing && m_region ) { m_bDrawing = false; m_bEditing = false; if ( m_nAction == MM_Spline || m_nAction == MM_Polyline ) ((Region2DPolyline*)m_region)->RemoveLastPoint(); view->NeedRedraw(); return false; } } return Interactor2D::ProcessMouseDownEvent( event, renderview ); // pass down the event }