1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
/*=========================================================================
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.kitware.com/VolViewCopyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkVVPluginInterface.h"
#include "vtkKWFrameWithLabel.h"
#include "vtkObjectFactory.h"
#include "vtkVVPluginSelector.h"
#include "vtkKWEvent.h"
#include "vtkKWIcon.h"
#include "vtkVVWindow.h"
#include "vtkKWRenderWidgetPro.h"
#include "vtkKWVolumeWidget.h"
#include "vtkVVDataItemVolume.h"
#include "vtkKWImageWidget.h"
#include "vtkImageData.h"
#include "vtkVVSelectionFrame.h"
#include "vtkVVSelectionFrameLayoutManager.h"
#include "vtkVVWidgetInterface.h"
#include "vtkVVPaintbrushWidgetEditor.h"
#include "vtkKWEPaintbrushWidget.h"
#include "vtkKWEPaintbrushDrawing.h"
#include "vtkKWEPaintbrushRepresentation2D.h"
#include <vtksys/SystemTools.hxx>
//---------------------------------------------------------------------------
#define VTK_VV_PLUGIN_UIP_LABEL "Plugins"
//---------------------------------------------------------------------------
vtkStandardNewMacro(vtkVVPluginInterface);
vtkCxxRevisionMacro(vtkVVPluginInterface, "$Revision: 1.12 $");
//---------------------------------------------------------------------------
vtkVVPluginInterface::vtkVVPluginInterface()
{
this->SetName(VTK_VV_PLUGIN_UIP_LABEL);
// Plugins
this->PluginsFrame = 0;
// Some objects are instantiated here because observers will most likely be
// attached to them in the future.
this->Plugins = vtkVVPluginSelector::New();
this->PageId = -1;
}
//---------------------------------------------------------------------------
vtkVVPluginInterface::~vtkVVPluginInterface()
{
// Plugins
if (this->PluginsFrame)
{
this->PluginsFrame->Delete();
this->PluginsFrame = NULL;
}
if (this->Plugins)
{
this->Plugins->Delete();
this->Plugins = NULL;
}
}
// --------------------------------------------------------------------------
void vtkVVPluginInterface::Create()
{
if (this->IsCreated())
{
vtkErrorMacro("The panel is already created.");
return;
}
// Create the superclass instance (and set the application)
this->Superclass::Create();
ostrstream tk_cmd;
vtkKWWidget *page;
vtkKWFrame *frame;
// --------------------------------------------------------------
// Add a "Plugin" page
this->PageId = this->AddPage(NULL, this->GetName());
this->SetPageIconToPredefinedIcon(
this->PageId, vtkKWIcon::IconNuvola22x22ActionsMisc);
page = this->GetPageWidget(this->PageId);
// --------------------------------------------------------------
// Plugins : frame
if (!this->PluginsFrame)
{
this->PluginsFrame = vtkKWFrameWithLabel::New();
}
this->PluginsFrame->SetParent(this->GetPagesParentWidget());
this->PluginsFrame->LimitedEditionModeIconVisibilityOn();
this->PluginsFrame->Create();
this->PluginsFrame->SetLabelText("Plugins");
tk_cmd << "pack " << this->PluginsFrame->GetWidgetName()
<< " -side top -anchor nw -fill x -padx 2 -pady 2 "
<< " -in " << page->GetWidgetName() << endl;
frame = this->PluginsFrame->GetFrame();
// --------------------------------------------------------------
// Create the plugins UI
this->Plugins->SetParent(frame);
this->Plugins->SetWindow(this->Window);
this->Plugins->SetPluginInterface(this);
this->Plugins->Create();
tk_cmd << "pack " << this->Plugins->GetWidgetName()
<< " -side top -anchor n -expand y -fill x -padx 2 -pady 2" << endl;
// --------------------------------------------------------------
// Pack
tk_cmd << ends;
this->Script(tk_cmd.str());
tk_cmd.rdbuf()->freeze(0);
// Update according to the current Window
this->Update();
}
//---------------------------------------------------------------------------
void vtkVVPluginInterface::Update()
{
this->Superclass::Update();
if( !this->IsCreated() )
{
return;
}
// Check if we have data.
bool has_data = false;
if( this->Window )
{
vtkVVDataItemVolume *volume_data = vtkVVDataItemVolume::SafeDownCast(
this->Window->GetSelectedDataItem());
if( volume_data )
{
vtkImageData *image_data = volume_data->GetImageData();
if( image_data ) // Only for image data for now
{
has_data = true;
}
}
}
// Update the plugins based on new info.. This will set the "Undo" button
// as enabled/disabled or the 'Redo' button status etc..
if( has_data && this->Plugins )
{
this->Plugins->Update();
}
// If there is no input data, let's disable everything
if (!has_data && this->Plugins)
{
this->Plugins->SetEnabled(0);
}
}
//---------------------------------------------------------------------------
void vtkVVPluginInterface::UpdateEnableState()
{
this->Superclass::UpdateEnableState();
// Plugins
if (this->PluginsFrame)
{
this->PluginsFrame->SetEnabled(this->GetEnabled());
}
if (this->Plugins)
{
this->Plugins->SetEnabled(this->GetEnabled());
}
}
//----------------------------------------------------------------------------
void vtkVVPluginInterface::UpdateAccordingToImageData()
{
int nb_rw = this->Window->GetNumberOfRenderWidgetsUsingSelectedDataItem();
for (int i = 0; i < nb_rw; i++)
{
vtkKWRenderWidgetPro *rwp = vtkKWRenderWidgetPro::SafeDownCast(
this->Window->GetNthRenderWidgetUsingSelectedDataItem(i));
if (!rwp)
{
continue;
}
int mode = rwp->GetRenderMode();
rwp->SetRenderModeToDisabled();
// image_data ivar remains the same, but its contents have changed after
// the plugin is applied. Manually force the update.
rwp->UpdateAccordingToInput();
rwp->SetRenderMode(mode);
// Re-install any paintbrush widgets. We are screwed at the moment if the
// extents of the underlying image change.. Let's handle this later.
this->ReinstallPaintbrushWidgets(rwp);
rwp->Render();
}
this->Window->Update();
}
//----------------------------------------------------------------------------
void vtkVVPluginInterface
::ReinstallPaintbrushWidgets(vtkKWRenderWidget *rw)
{
// The datatype of the underlying image may have changed when running the
// plugin. This can wreck havoc with the paintbrush widgets, since these
// do a blending of the paintbrush with the underlying data - Hence if we
// switch the underlying data under the carpet, we need to do some magic.
// We will re-install the paintbrush pipeline.
vtkVVSelectionFrameLayoutManager *layoutMgr
= this->Window->GetDataSetWidgetLayoutManager();
if (vtkVVSelectionFrame *selFrame
= vtkVVSelectionFrame::SafeDownCast(
layoutMgr->GetContainingSelectionFrame(rw)))
{
const int nWidgets = selFrame->GetNumberOfInteractorWidgets();
for (int j = 0; j < nWidgets; j++)
{
if (vtkKWEPaintbrushWidget *w = vtkKWEPaintbrushWidget::SafeDownCast(
selFrame->GetNthInteractorWidget(j)))
{
if (w->GetEnabled())
{
if (vtkKWEPaintbrushRepresentation2D *rep2D =
vtkKWEPaintbrushRepresentation2D::SafeDownCast(w->GetRepresentation()))
{
rep2D->UnInstallPipeline();
rep2D->InstallPipeline();
// Repopulate the sketches since we may have modified the number of
// labels etc. Also collapse the history of all sketches in the
// drawing since the plugin could have modified the paintbrush data
// under the hood without going through the Paintbrush's Undo/Redo
// stack mechanism
rep2D->GetPaintbrushDrawing()->CreateSketches();
rep2D->GetPaintbrushDrawing()->CollapseHistory();
vtkVVWindow *win = vtkVVWindow::SafeDownCast(this->Window);
vtkVVWidgetInterface *wi = win->GetWidgetInterface();
if (!wi)
{
std::cout << "wi: " << wi << std::endl;
}
else if (!wi->GetPaintbrushWidgetEditor())
{
std::cout << "Paintbrush widget editor: " << wi->GetPaintbrushWidgetEditor() << std::endl;
}
else
{
wi->GetPaintbrushWidgetEditor()->PopulateSketchList();
}
}
}
}
}
}
}
//---------------------------------------------------------------------------
void vtkVVPluginInterface::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
|