Commit 355784ccd3da86f73be0292569a4de9b4c66cc49
1 parent
68794cab
Exists in
master
and in
67 other branches
Show and hidding ball reference only when necessary
Showing
1 changed file
with
41 additions
and
18 deletions
Show diff stats
invesalius/data/viewer_volume.py
| ... | ... | @@ -110,7 +110,9 @@ class Viewer(wx.Panel): |
| 110 | 110 | self.repositioned_coronal_plan = 0 |
| 111 | 111 | self.added_actor = 0 |
| 112 | 112 | |
| 113 | + self._mode_cross = False | |
| 113 | 114 | self._to_show_ball = 0 |
| 115 | + self._ball_ref_visibility = False | |
| 114 | 116 | |
| 115 | 117 | def __bind_events(self): |
| 116 | 118 | Publisher.subscribe(self.LoadActor, |
| ... | ... | @@ -227,15 +229,22 @@ class Viewer(wx.Panel): |
| 227 | 229 | self.ball_actor.SetMapper(mapper) |
| 228 | 230 | self.ball_actor.SetProperty(p) |
| 229 | 231 | |
| 232 | + def RemoveBallReference(self): | |
| 233 | + self._ball_ref_visibility = False | |
| 234 | + if self.ball_reference: | |
| 235 | + self.ren.RemoveActor(self.ball_actor) | |
| 236 | + | |
| 230 | 237 | def ActivateBallReference(self, pubsub_evt): |
| 238 | + self._mode_cross = True | |
| 239 | + self._ball_ref_visibility = True | |
| 231 | 240 | if self._to_show_ball: |
| 232 | 241 | if not self.ball_reference: |
| 233 | 242 | self.CreateBallReference() |
| 234 | 243 | self.ren.AddActor(self.ball_actor) |
| 235 | 244 | |
| 236 | 245 | def DeactivateBallReference(self, pubsub_evt): |
| 237 | - if self.ball_reference: | |
| 238 | - self.ren.RemoveActor(self.ball_actor) | |
| 246 | + self._mode_cross = False | |
| 247 | + self.RemoveBallReference() | |
| 239 | 248 | |
| 240 | 249 | def OnShowSurface(self, pubsub_evt): |
| 241 | 250 | index, value = pubsub_evt.data |
| ... | ... | @@ -243,7 +252,8 @@ class Viewer(wx.Panel): |
| 243 | 252 | self._to_show_ball += 1 |
| 244 | 253 | else: |
| 245 | 254 | self._to_show_ball -= 1 |
| 246 | - print "to show ball", self._to_show_ball | |
| 255 | + self._check_and_set_ball_visibility() | |
| 256 | + print "OnShowSurface: to show ball", self._to_show_ball | |
| 247 | 257 | |
| 248 | 258 | def SetBallReferencePosition(self, pubsub_evt): |
| 249 | 259 | x, y, z = pubsub_evt.data |
| ... | ... | @@ -338,6 +348,8 @@ class Viewer(wx.Panel): |
| 338 | 348 | self.ren.RemoveVolume(volumes.GetLastProp()) |
| 339 | 349 | self.interactor.Render() |
| 340 | 350 | self._to_show_ball -= 1 |
| 351 | + self._check_and_set_ball_visibility() | |
| 352 | + print "RemoveVolume: to show ball", self._to_show_ball | |
| 341 | 353 | |
| 342 | 354 | def RemoveActors(self, pubsub_evt): |
| 343 | 355 | "Remove a list of actors" |
| ... | ... | @@ -621,17 +633,20 @@ class Viewer(wx.Panel): |
| 621 | 633 | self.text.SetValue("WL: %d WW: %d"%(wl, ww)) |
| 622 | 634 | |
| 623 | 635 | def OnShowRaycasting(self, pubsub_evt): |
| 624 | - self.raycasting_volume = True | |
| 625 | - self._to_show_ball += 1 | |
| 626 | - print "to show ball", self._to_show_ball | |
| 627 | - if self.on_wl: | |
| 628 | - self.text.Show() | |
| 636 | + if not self.raycasting_volume: | |
| 637 | + self.raycasting_volume = True | |
| 638 | + self._to_show_ball += 1 | |
| 639 | + self._check_and_set_ball_visibility() | |
| 640 | + print "OnShowRaycasting: to show ball", self._to_show_ball | |
| 641 | + if self.on_wl: | |
| 642 | + self.text.Show() | |
| 629 | 643 | |
| 630 | 644 | def OnHideRaycasting(self, pubsub_evt): |
| 631 | 645 | self.raycasting_volume = False |
| 632 | 646 | self.text.Hide() |
| 633 | 647 | self._to_show_ball -= 1 |
| 634 | - print "to show ball", self._to_show_ball | |
| 648 | + self._check_and_set_ball_visibility() | |
| 649 | + print "OnHideRaycasting: to show ball", self._to_show_ball | |
| 635 | 650 | |
| 636 | 651 | def OnSize(self, evt): |
| 637 | 652 | self.UpdateRender() |
| ... | ... | @@ -661,7 +676,8 @@ class Viewer(wx.Panel): |
| 661 | 676 | #self.ShowOrientationCube() |
| 662 | 677 | self.interactor.Render() |
| 663 | 678 | self._to_show_ball += 1 |
| 664 | - print "to show ball", self._to_show_ball | |
| 679 | + self._check_and_set_ball_visibility() | |
| 680 | + print "LoadActor: to show ball", self._to_show_ball | |
| 665 | 681 | |
| 666 | 682 | def RemoveActor(self, pubsub_evt): |
| 667 | 683 | utils.debug("RemoveActor") |
| ... | ... | @@ -669,8 +685,9 @@ class Viewer(wx.Panel): |
| 669 | 685 | ren = self.ren |
| 670 | 686 | ren.RemoveActor(actor) |
| 671 | 687 | self.interactor.Render() |
| 672 | - #self._to_show_ball -= 1 | |
| 673 | - #print "to show ball", self._to_show_ball | |
| 688 | + self._to_show_ball -= 1 | |
| 689 | + self._check_and_set_ball_visibility() | |
| 690 | + print "to show ball", self._to_show_ball | |
| 674 | 691 | |
| 675 | 692 | def RemoveAllActor(self, pubsub_evt): |
| 676 | 693 | utils.debug("RemoveAllActor") |
| ... | ... | @@ -712,10 +729,12 @@ class Viewer(wx.Panel): |
| 712 | 729 | |
| 713 | 730 | def UnloadVolume(self, pubsub_evt): |
| 714 | 731 | volume = pubsub_evt.data |
| 715 | - self._to_show_ball -= 1 | |
| 716 | 732 | self.ren.RemoveVolume(volume) |
| 717 | 733 | del volume |
| 718 | - print "to show ball", self._to_show_ball | |
| 734 | + self.raycasting_volume = False | |
| 735 | + self._to_show_ball -= 1 | |
| 736 | + self._check_and_set_ball_visibility() | |
| 737 | + print "UnloadVolume: to show ball", self._to_show_ball | |
| 719 | 738 | |
| 720 | 739 | def OnSetViewAngle(self, evt_pubsub): |
| 721 | 740 | view = evt_pubsub.data |
| ... | ... | @@ -854,10 +873,14 @@ class Viewer(wx.Panel): |
| 854 | 873 | self.SetViewAngle(const.VOL_ISO) |
| 855 | 874 | self.repositioned_coronal_plan = 1 |
| 856 | 875 | |
| 857 | - def _verify_necessity_ball_ref(self): | |
| 858 | - pass | |
| 859 | - | |
| 860 | - | |
| 876 | + def _check_and_set_ball_visibility(self): | |
| 877 | + if self._mode_cross: | |
| 878 | + if self._to_show_ball > 0 and not self._ball_ref_visibility: | |
| 879 | + self.ActivateBallReference(None) | |
| 880 | + self.interactor.Render() | |
| 881 | + elif not self._to_show_ball and self._ball_ref_visibility: | |
| 882 | + self.RemoveBallReference() | |
| 883 | + self.interactor.Render() | |
| 861 | 884 | |
| 862 | 885 | |
| 863 | 886 | class SlicePlane: | ... | ... |