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
|
/*=========================================================================
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 "XML/vtkXMLVVWindowBaseReader.h"
#include "vtkObjectFactory.h"
#include "vtkXMLDataElement.h"
#include "vtkKWProgressGauge.h"
#include "vtkKWMessageDialog.h"
#include "vtkKWOpenFileProperties.h"
#include "vtkKW2DRenderWidget.h"
#include "vtkVVApplication.h"
#include "vtkVVDataItemPool.h"
#include "vtkVVFileInstance.h"
#include "vtkVVFileInstancePool.h"
#include "vtkVVSelectionFrameLayoutManager.h"
#include "vtkVVSnapshot.h"
#include "vtkVVSnapshotPool.h"
#include "vtkVVWindowBase.h"
#include "XML/vtkXMLVVFileInstancePoolReader.h"
#include "XML/vtkXMLVVDataItemPoolReader.h"
#include "XML/vtkXMLKWImageWidgetWriter.h"
#include <vtksys/SystemTools.hxx>
#include <vtksys/stl/string>
vtkStandardNewMacro(vtkXMLVVWindowBaseReader);
vtkCxxRevisionMacro(vtkXMLVVWindowBaseReader, "$Revision: 1.23 $");
//----------------------------------------------------------------------------
const char* vtkXMLVVWindowBaseReader::GetRootElementName()
{
return "VVWindowBase";
}
//----------------------------------------------------------------------------
int vtkXMLVVWindowBaseReader::Parse(vtkXMLDataElement *elem)
{
if (!this->Superclass::Parse(elem))
{
return 0;
}
vtkVVWindowBase *obj = vtkVVWindowBase::SafeDownCast(this->Object);
if (!obj)
{
vtkWarningMacro(<< "The VVWindowBase is not set!");
return 0;
}
// Get Attributes
#if 0
int ival;
if (elem->GetScalarAttribute("SupportVolumeWidget", ival))
{
obj->SetSupportVolumeWidget(ival);
}
if (elem->GetScalarAttribute("SupportObliqueProbeWidget", ival))
{
obj->SetSupportObliqueProbeWidget(ival);
}
if (elem->GetScalarAttribute("SupportLightboxWidget", ival))
{
obj->SetSupportLightboxWidget(ival);
}
if (elem->GetScalarAttribute("MaximumNumberOfSimultaneousDataItems", ival))
{
obj->SetMaximumNumberOfSimultaneousDataItems(ival);
}
#endif
// Get nested elements
int i, j;
//obj->CloseAllDataItems();
//obj->CloseAllFileInstances();
obj->GetProgressGauge()->SetValue(5.0);
// First retrieve the file(s) to load in a temporary pool
// Set the application here, so as to allow us to query the authentication
// method from the application and apply it to the files before loading them.
vtkVVFileInstancePool *temp_pool = vtkVVFileInstancePool::New();
temp_pool->SetApplication(obj->GetApplication());
vtkXMLVVFileInstancePoolReader *fip_xmlr =
vtkXMLVVFileInstancePoolReader::SafeDownCast(temp_pool->GetNewXMLReader());
fip_xmlr->ParseInElement(elem);
fip_xmlr->Delete();
obj->GetProgressGauge()->SetValue(10.0);
// Now remove from the current pool those files that we don't need anymore
// and add the new files to the current pool.
vtkVVFileInstancePool *pool = obj->GetFileInstancePool();
if (pool)
{
int done = 0, released = 0;
while (!done)
{
done = 1;
for (i = 0; i < pool->GetNumberOfFileInstances(); i++)
{
vtkVVFileInstance *file = pool->GetNthFileInstance(i);
if (!temp_pool->HasSimilarFileInstance(file))
{
obj->ReleaseFileInstance(file);
released++;
done = 0;
break;
}
}
}
if (released)
{
obj->Update(); // needed for more memory to be de-allocated
}
for (i = 0; i < temp_pool->GetNumberOfFileInstances(); i++)
{
vtkVVFileInstance *file = temp_pool->GetNthFileInstance(i);
int nb_similar = pool->GetNumberOfSimilarFileInstances(file);
int same_file_found = 0;
for (j = 0; j < nb_similar; j++)
{
vtkVVFileInstance *candidate =
pool->GetNthSimilarFileInstance(j, file);
if (!strcmp(candidate->GetName(), file->GetName()))
{
same_file_found = 1;
break;
}
}
if (!same_file_found)
{
pool->AddFileInstance(file);
}
}
}
temp_pool->RemoveAllFileInstances();
obj->GetProgressGauge()->SetValue(20.0);
// Load the data
vtksys_stl::string not_loaded;
for (i = 0; i < pool->GetNumberOfFileInstances(); i++)
{
vtkVVFileInstance *file = pool->GetNthFileInstance(i);
file->SetApplication(obj->GetApplication()); // Propagate the application.
if (!file->GetDataItemPool()->GetNumberOfDataItems() &&
!file->Load() &&
!file->LoadFromURIs())
{
if (not_loaded.size())
{
not_loaded += "\n\n";
}
not_loaded += file->GetFileName();
temp_pool->AddFileInstance(file); // can't remove directly while looping
}
else
{
for (j = 0; j < file->GetDataItemPool()->GetNumberOfDataItems(); j++)
{
vtkVVDataItem *item = file->GetDataItemPool()->GetNthDataItem(j);
if (!obj->GetDataItemPool()->HasDataItem(item))
{
obj->GetDataItemPool()->AddDataItem(item);
}
}
}
obj->GetProgressGauge()->SetValue(
20.0 + ((double)(i+1) / (double)pool->GetNumberOfFileInstances() * 50));
}
for (i = 0; i < temp_pool->GetNumberOfFileInstances(); i++)
{
pool->RemoveFileInstance(temp_pool->GetNthFileInstance(i));
}
temp_pool->Delete();
obj->GetProgressGauge()->SetValue(70.0);
if (not_loaded.size())
{
not_loaded =
"The following file(s) could not be loaded:\n\n" + not_loaded + "\n\n" +
"Please make sure that the paths are correct and accessible to the "
"current user. If you are trying to read a session file that was "
"created on a different machine but know where the corresponding data "
"files are located on the current machine, try moving the session file "
"to the same directory as the data files.";
vtkKWMessageDialog::PopupMessage(
obj->GetApplication(), NULL, "Load Data Error", not_loaded.c_str(),
vtkKWMessageDialog::ErrorIcon);
}
// At this point we have loaded the data, and vtkVVDataItem have been
// created automatically, reference from both each
// vtkVVFileInstance::DataItemPool and the vtkVVWindowBase::DataItemPool.
// Let's unserialize the DataItemPool in UpdateMode, so that the references
// are not changed (i.e. no new DataItem is created), but the current
// DataItem are updated with the value in the session (by checking for
// instances with the same name)
vtkXMLVVDataItemPoolReader *dip_xmlr =
vtkXMLVVDataItemPoolReader::SafeDownCast(
obj->GetDataItemPool()->GetNewXMLReader());
dip_xmlr->UpdateModeOn();
dip_xmlr->ParseInElement(elem);
dip_xmlr->Delete();
// DO NOT ADD ANY PROGRESS REPORT BETWEEN HERE AND THE END OF THE
// LAYOUT MANAGER DESERIALIZATION.
// Doing so would trigger an "update idletask" which would give a change
// to the layout manager to put each of the below widget on screen. We
// do not want that, we want the final layout directly, without flickering
// or slowdown.
// Add the default render widgets
for (i = 0; i < pool->GetNumberOfFileInstances(); i++)
{
vtkVVFileInstance *file = pool->GetNthFileInstance(i);
// Add all render widgets
if (!file->HasRenderWidgetInWindow(obj))
{
file->AddDefaultRenderWidgets(obj);
}
}
// Read the Widget Layout Manager
vtkVVSelectionFrameLayoutManager *mgr = obj->GetDataSetWidgetLayoutManager();
if (mgr)
{
vtkXMLObjectReader *xmlr = mgr->GetNewXMLReader();
xmlr->ParseInElement(elem);
xmlr->Delete();
// If some data was not loaded, try to avoid "holes" in the manager by
// adjusting the resolution automatically (this may show many more
// widgets than intended in the session, but that's OK).
if (not_loaded.size())
{
mgr->AdjustResolution();
}
}
// Retrieve the snapshots
obj->GetProgressGauge()->SetValue(90.0);
vtkVVSnapshotPool *snapshot_pool = obj->GetSnapshotPool();
if (snapshot_pool)
{
vtkXMLObjectReader *xmlr = snapshot_pool->GetNewXMLReader();
xmlr->ParseInElement(elem);
xmlr->Delete();
}
obj->GetProgressGauge()->SetValue(100.0);
obj->GetProgressGauge()->SetValue(0.0);
return 1;
}
//----------------------------------------------------------------------------
void vtkXMLVVWindowBaseReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
|