Commit 4d284e34 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

ENH: Move to use vtkStdString in charts API.

Change-Id: I5479ca46ebbe1e0eb95e9f21f4ba8f0b172545e1
parent befcaa27
......@@ -54,7 +54,7 @@ public:
// functions as a double to generate a color.
virtual void SetInput(vtkImageData *data, vtkIdType z = 0);
virtual void SetInput(vtkTable*) { }
virtual void SetInput(vtkTable*, const char*, const char*) { }
virtual void SetInput(vtkTable*, const vtkStdString&, const vtkStdString&) { }
// Description:
// Get the input table used by the plot.
......
......@@ -57,7 +57,6 @@ vtkAxis::vtkAxis()
this->TitleProperties->SetJustificationToCentered();
this->Minimum = 0.0;
this->Maximum = 6.66;
this->Title = NULL;
this->LogScale = false;
this->GridVisible = true;
this->LabelsVisible = true;
......@@ -84,7 +83,6 @@ vtkAxis::vtkAxis()
//-----------------------------------------------------------------------------
vtkAxis::~vtkAxis()
{
this->SetTitle(NULL);
this->TitleProperties->Delete();
this->LabelProperties->Delete();
this->Pen->Delete();
......@@ -400,6 +398,22 @@ void vtkAxis::SetRange(double minimum, double maximum)
this->SetMaximum(maximum);
}
//-----------------------------------------------------------------------------
void vtkAxis::SetTitle(const vtkStdString &title)
{
if (this->Title != title)
{
this->Title = title;
this->Modified();
}
}
//-----------------------------------------------------------------------------
vtkStdString vtkAxis::GetTitle()
{
return this->Title;
}
//-----------------------------------------------------------------------------
void vtkAxis::SetPrecision(int precision)
{
......
......@@ -26,6 +26,7 @@
#include "vtkContextItem.h"
#include "vtkSmartPointer.h" // For vtkSmartPointer
#include "vtkVector.h" // For position variables
#include "vtkStdString.h" // For vtkStdString ivars
class vtkContext2D;
class vtkPen;
......@@ -116,8 +117,8 @@ public:
// Description:
// Get/set the title text of the axis.
vtkSetStringMacro(Title);
vtkGetStringMacro(Title);
virtual void SetTitle(const vtkStdString &title);
virtual vtkStdString GetTitle();
// Description:
// Get the vtkTextProperty that governs how the axis title is displayed.
......@@ -287,7 +288,7 @@ protected:
vtkTextProperty* LabelProperties; // Text properties for the labels.
double Minimum; // Minimum value of the axis
double Maximum; // Maximum values of the axis
char* Title; // The text label drawn on the axis
vtkStdString Title; // The text label drawn on the axis
vtkTextProperty* TitleProperties; // Text properties for the axis title
bool LogScale; // Should the axis use a log scale
bool GridVisible; // Whether the grid for the axis should be drawn
......
......@@ -34,7 +34,6 @@ vtkStandardNewMacro(vtkBlockItem);
//-----------------------------------------------------------------------------
vtkBlockItem::vtkBlockItem()
{
this->Label = NULL;
this->MouseOver = false;
this->MouseButtonPressed = vtkContextMouseEvent::NO_BUTTON;
this->scalarFunction = NULL;
......@@ -47,7 +46,6 @@ vtkBlockItem::vtkBlockItem()
//-----------------------------------------------------------------------------
vtkBlockItem::~vtkBlockItem()
{
this->SetLabel(NULL);
}
//-----------------------------------------------------------------------------
......@@ -176,6 +174,23 @@ bool vtkBlockItem::MouseButtonReleaseEvent(const vtkContextMouseEvent &)
return true;
}
//-----------------------------------------------------------------------------
void vtkBlockItem::SetLabel(const vtkStdString &label)
{
if (this->Label != label)
{
this->Label = label;
this->Modified();
}
}
//-----------------------------------------------------------------------------
vtkStdString vtkBlockItem::GetLabel()
{
return this->Label;
}
//-----------------------------------------------------------------------------
void vtkBlockItem::SetScalarFunctor(double (*ScalarFunction)(double, double))
{
this->scalarFunction = ScalarFunction;
......
......@@ -23,6 +23,7 @@
#define __vtkBlockItem_h
#include "vtkContextItem.h"
#include "vtkStdString.h" // For vtkStdString ivars
class vtkContext2D;
......@@ -66,11 +67,11 @@ public:
// Description:
// Set the block label.
vtkSetStringMacro(Label);
virtual void SetLabel(const vtkStdString &label);
// Description:
// Get the block label.
vtkGetStringMacro(Label);
virtual vtkStdString GetLabel();
// Description:
// Set the dimensions of the block, elements 0 and 1 are the x and y
......@@ -99,7 +100,7 @@ protected:
float LastPosition[2];
char *Label;
vtkStdString Label;
bool MouseOver;
int MouseButtonPressed;
......
......@@ -44,7 +44,6 @@ vtkChart::vtkChart()
this->Point2[0] = 0;
this->Point2[1] = 0;
this->ShowLegend = false;
this->Title = NULL;
this->TitleProperties = vtkTextProperty::New();
this->TitleProperties->SetJustificationToCentered();
this->TitleProperties->SetColor(0.0, 0.0, 0.0);
......@@ -57,7 +56,6 @@ vtkChart::vtkChart()
//-----------------------------------------------------------------------------
vtkChart::~vtkChart()
{
this->SetTitle(NULL);
this->TitleProperties->Delete();
if (this->AnnotationLink)
{
......@@ -151,6 +149,22 @@ bool vtkChart::GetShowLegend()
return this->ShowLegend;
}
//-----------------------------------------------------------------------------
void vtkChart::SetTitle(const vtkStdString &title)
{
if (this->Title != title)
{
this->Title = title;
this->Modified();
}
}
//-----------------------------------------------------------------------------
vtkStdString vtkChart::GetTitle()
{
return this->Title;
}
//-----------------------------------------------------------------------------
bool vtkChart::CalculatePlotTransform(vtkAxis *x, vtkAxis *y,
vtkTransform2D *transform)
......
......@@ -23,6 +23,7 @@
#include "vtkContextItem.h"
#include "vtkVector.h" // For vtkRectf
#include "vtkStdString.h" // For vtkStdString ivars
class vtkTransform2D;
class vtkContextScene;
......@@ -136,8 +137,8 @@ public:
// Description:
// Get/set the title text of the chart.
vtkSetStringMacro(Title);
vtkGetStringMacro(Title);
virtual void SetTitle(const vtkStdString &title);
virtual vtkStdString GetTitle();
// Description:
// Get the vtkTextProperty that governs how the chart title is displayed.
......@@ -220,7 +221,7 @@ protected:
// Description:
// The title of the chart
char* Title;
vtkStdString Title;
// Description:
// The text properties associated with the chart
......
......@@ -229,14 +229,14 @@ bool vtkChartParallelCoordinates::Paint(vtkContext2D *painter)
}
//-----------------------------------------------------------------------------
void vtkChartParallelCoordinates::SetColumnVisibility(const char* name,
void vtkChartParallelCoordinates::SetColumnVisibility(const vtkStdString& name,
bool visible)
{
if (visible)
{
for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i)
{
if (strcmp(this->VisibleColumns->GetValue(i).c_str(), name) == 0)
if (this->VisibleColumns->GetValue(i) == name)
{
// Already there, nothing more needs to be done
return;
......@@ -252,7 +252,7 @@ void vtkChartParallelCoordinates::SetColumnVisibility(const char* name,
// Remove the value if present
for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i)
{
if (strcmp(this->VisibleColumns->GetValue(i).c_str(), name) == 0)
if (this->VisibleColumns->GetValue(i) == name)
{
// Move all the later elements down by one, and reduce the size
while (i < this->VisibleColumns->GetNumberOfTuples()-1)
......@@ -292,11 +292,11 @@ void vtkChartParallelCoordinates::SetColumnVisibilityAll(bool visible)
}
//-----------------------------------------------------------------------------
bool vtkChartParallelCoordinates::GetColumnVisibility(const char* name)
bool vtkChartParallelCoordinates::GetColumnVisibility(const vtkStdString& name)
{
for (vtkIdType i = 0; i < this->VisibleColumns->GetNumberOfTuples(); ++i)
{
if (strcmp(this->VisibleColumns->GetValue(i).c_str(), name) == 0)
if (this->VisibleColumns->GetValue(i) == name)
{
return true;
}
......
......@@ -24,6 +24,7 @@
#include "vtkChart.h"
class vtkIdTypeArray;
class vtkStdString;
class vtkStringArray;
class vtkPlotParallelCoordinates;
......@@ -49,7 +50,7 @@ public:
// Description:
// Set the visibility of the specified column.
void SetColumnVisibility(const char* name, bool visible);
void SetColumnVisibility(const vtkStdString& name, bool visible);
// Description:
// Set the visibility of all columns (true will make them all visible, false
......@@ -58,7 +59,7 @@ public:
// Description:
// Get the visibility of the specified column.
bool GetColumnVisibility(const char* name);
bool GetColumnVisibility(const vtkStdString& name);
// Description:
// Get a list of the columns, and the order in which they are displayed.
......
......@@ -23,9 +23,8 @@
#include "vtkIdTypeArray.h"
#include "vtkContextMapper2D.h"
#include "vtkObjectFactory.h"
#include "vtkStringArray.h"
#include "vtkStdString.h"
#include "vtkStringArray.h"
vtkCxxSetObjectMacro(vtkPlot, Selection, vtkIdTypeArray);
vtkCxxSetObjectMacro(vtkPlot, XAxis, vtkAxis);
......@@ -134,7 +133,7 @@ float vtkPlot::GetWidth()
}
//-----------------------------------------------------------------------------
void vtkPlot::SetLabel(const char *label)
void vtkPlot::SetLabel(const vtkStdString& label)
{
vtkStringArray *labels = vtkStringArray::New();
labels->InsertNextValue(label);
......@@ -144,7 +143,7 @@ void vtkPlot::SetLabel(const char *label)
//-----------------------------------------------------------------------------
const char *vtkPlot::GetLabel()
vtkStdString vtkPlot::GetLabel()
{
return this->GetLabel(0);
}
......@@ -164,7 +163,7 @@ void vtkPlot::SetLabels(vtkStringArray *labels)
}
//-----------------------------------------------------------------------------
vtkStringArray *vtkPlot::GetLabels()
vtkStringArray * vtkPlot::GetLabels()
{
// If the label string is empty, return the y column name
if (this->Labels)
......@@ -202,7 +201,7 @@ int vtkPlot::GetNumberOfLabels()
}
//-----------------------------------------------------------------------------
const char *vtkPlot::GetLabel(vtkIdType index)
vtkStdString vtkPlot::GetLabel(vtkIdType index)
{
vtkStringArray *labels = this->GetLabels();
if (labels && index >= 0 && index < labels->GetNumberOfValues())
......@@ -211,7 +210,7 @@ const char *vtkPlot::GetLabel(vtkIdType index)
}
else
{
return NULL;
return vtkStdString();
}
}
//-----------------------------------------------------------------------------
......@@ -222,15 +221,15 @@ void vtkPlot::SetInput(vtkTable *table)
}
//-----------------------------------------------------------------------------
void vtkPlot::SetInput(vtkTable *table, const char *xColumn,
const char *yColumn)
void vtkPlot::SetInput(vtkTable *table, const vtkStdString &xColumn,
const vtkStdString &yColumn)
{
if (!xColumn || !yColumn)
if (xColumn.empty() || yColumn.empty())
{
vtkErrorMacro(<< "Called with null arguments for X or Y column.")
}
vtkDebugMacro(<< "Setting input, X column = \"" << vtkstd::string(xColumn)
<< "\", " << "Y column = \"" << vtkstd::string(yColumn) << "\"");
vtkDebugMacro(<< "Setting input, X column = \"" << xColumn.c_str()
<< "\", " << "Y column = \"" << yColumn.c_str() << "\"");
this->Data->SetInput(table);
this->Data->SetInputArrayToProcess(0, 0, 0,
......@@ -258,7 +257,7 @@ vtkTable* vtkPlot::GetInput()
}
//-----------------------------------------------------------------------------
void vtkPlot::SetInputArray(int index, const char *name)
void vtkPlot::SetInputArray(int index, const vtkStdString &name)
{
this->Data->SetInputArrayToProcess(index, 0, 0,
vtkDataObject::FIELD_ASSOCIATION_ROWS,
......
......@@ -96,11 +96,11 @@ public:
// Description:
// Set a single label on this plot.
void SetLabel(const char *label);
void SetLabel(const vtkStdString &label);
// Description:
// Get the single label of this plot.
const char *GetLabel();
vtkStdString GetLabel();
// Description:
// Set the plot labels.
......@@ -116,7 +116,7 @@ public:
// Description:
// Get the label at the specified index.
const char *GetLabel(vtkIdType index);
vtkStdString GetLabel(vtkIdType index);
// Description:
// Get the data object that the plot will draw.
......@@ -136,8 +136,8 @@ public:
// This is a convenience function to set the input table and the x, y column
// for the plot.
virtual void SetInput(vtkTable *table);
virtual void SetInput(vtkTable *table, const char *xColumn,
const char *yColumn);
virtual void SetInput(vtkTable *table, const vtkStdString &xColumn,
const vtkStdString &yColumn);
void SetInput(vtkTable *table, vtkIdType xColumn, vtkIdType yColumn);
// Description:
......@@ -145,10 +145,10 @@ public:
virtual vtkTable* GetInput();
// Description:
// Convenience function to set the input arrays. For most mappers index 0
// Convenience function to set the input arrays. For most plots index 0
// is the x axis, and index 1 is the y axis. The name is the name of the
// column in the vtkTable.
virtual void SetInputArray(int index, const char *name);
virtual void SetInputArray(int index, const vtkStdString &name);
virtual void SetSelection(vtkIdTypeArray *id);
vtkGetObjectMacro(Selection, vtkIdTypeArray);
......@@ -172,8 +172,8 @@ public:
// Description:
// A General setter/getter that should be overridden. It can silently drop
// options, case is important
void SetProperty(const vtkStdString& property, const vtkVariant& var);
vtkVariant GetProperty(const vtkStdString& property);
virtual void SetProperty(const vtkStdString &property, const vtkVariant &var);
virtual vtkVariant GetProperty(const vtkStdString &property);
//ETX
//BTX
......
......@@ -472,7 +472,7 @@ int vtkPlotBar::GetNearestPoint(const vtkVector2f& point,
}
//-----------------------------------------------------------------------------
vtkStringArray *vtkPlotBar::GetLabels()
vtkStringArray * vtkPlotBar::GetLabels()
{
// If the label string is empty, return the y column name
if (this->Labels)
......@@ -513,9 +513,9 @@ void vtkPlotBar::SetGroupName(const vtkStdString &name)
}
}
const char * vtkPlotBar::GetGroupName()
vtkStdString vtkPlotBar::GetGroupName()
{
return this->Private->GroupName.empty() ? NULL : this->Private->GroupName;
return this->Private->GroupName;
}
//-----------------------------------------------------------------------------
......@@ -568,15 +568,15 @@ void vtkPlotBar::PrintSelf(ostream &os, vtkIndent indent)
//-----------------------------------------------------------------------------
void vtkPlotBar::SetInputArray(int index, const char *name)
void vtkPlotBar::SetInputArray(int index, const vtkStdString &name)
{
if (index == 0 || index == 1)
{
vtkPlot::SetInputArray(index,name);
vtkPlot::SetInputArray(index, name);
}
else
{
this->Private->AdditionalSeries[index] = std::string(name);
this->Private->AdditionalSeries[index] = name;
}
this->AutoLabels = 0; // No longer valid
}
......
......@@ -79,7 +79,7 @@ public:
// Description:
// When used to set additional arrays, stacked bars are created.
virtual void SetInputArray(int index, const char *name);
virtual void SetInputArray(int index, const vtkStdString &name);
// Description:
// Set the color series to use if this becomes a stacked bar plot.
......@@ -99,7 +99,7 @@ public:
// Description:
// Get the group name of the bar char - can be displayed on the X axis.
virtual const char * GetGroupName();
virtual vtkStdString GetGroupName();
//BTX
// Description:
......
......@@ -69,7 +69,6 @@ vtkPlotParallelCoordinates::vtkPlotParallelCoordinates()
this->LookupTable = 0;
this->Colors = 0;
this->ScalarVisibility = 0;
strcpy(this->ColorArrayName, "");
}
//-----------------------------------------------------------------------------
......@@ -462,7 +461,7 @@ void vtkPlotParallelCoordinates::CreateDefaultLookupTable()
}
//-----------------------------------------------------------------------------
void vtkPlotParallelCoordinates::SelectColorArray(const char *arrayName)
void vtkPlotParallelCoordinates::SelectColorArray(const vtkStdString &arrayName)
{
vtkTable *table = this->Data->GetInput();
if (!table)
......@@ -470,26 +469,31 @@ void vtkPlotParallelCoordinates::SelectColorArray(const char *arrayName)
vtkDebugMacro(<< "SelectColorArray called with no input table set.");
return;
}
if (strcmp(this->ColorArrayName, arrayName) == 0)
if (this->ColorArrayName == arrayName)
{
return;
}
for (vtkIdType c = 0; c < table->GetNumberOfColumns(); ++c)
{
const char *name = table->GetColumnName(c);
if (strcmp(name, arrayName) == 0)
if (table->GetColumnName(c) == arrayName)
{
strcpy(this->ColorArrayName, arrayName);
this->ColorArrayName = arrayName;
this->Modified();
return;
}
}
vtkDebugMacro(<< "SelectColorArray called with invalid column name.");
strcpy(this->ColorArrayName, "");
this->ColorArrayName = "";
this->Modified();
return;
}
//-----------------------------------------------------------------------------
vtkStdString vtkPlotParallelCoordinates::GetColorArrayName()
{
return this->ColorArrayName;
}
//-----------------------------------------------------------------------------
void vtkPlotParallelCoordinates::SelectColorArray(vtkIdType arrayNum)
{
......@@ -508,14 +512,13 @@ void vtkPlotParallelCoordinates::SelectColorArray(vtkIdType arrayNum)
}
else
{
const char *arrayName = table->GetColumnName(arrayNum);
if (strcmp(this->ColorArrayName, arrayName) == 0)
if (this->ColorArrayName == table->GetColumnName(arrayNum))
{
return;
}
else
{
strcpy(this->ColorArrayName, arrayName);
this->ColorArrayName = table->GetColumnName(arrayNum);
this->Modified();
}
}
......
......@@ -13,8 +13,8 @@
=========================================================================*/
// .NAME vtkPlotParallelCoordinates - Class for drawing an XY plot given two columns from a
// vtkTable.
// .NAME vtkPlotParallelCoordinates - Class for drawing a parallel coordinate
// plot given columns from a vtkTable.
//
// .SECTION Description
//
......@@ -24,6 +24,7 @@
#include "vtkPlot.h"
#include "vtkScalarsToColors.h" // For VTK_COLOR_MODE_DEFAULT and _MAP_SCALARS
#include "vtkStdString.h" // For vtkStdString ivars
class vtkChartParallelCoordinates;
class vtkTable;
......@@ -82,7 +83,8 @@ public:
// Description:
// This is a convenience function to set the input table.
virtual void SetInput(vtkTable *table);
virtual void SetInput(vtkTable *table, const char*, const char*)
virtual void SetInput(vtkTable *table, const vtkStdString&,
const vtkStdString&)
{
this->SetInput(table);
}
......@@ -108,7 +110,11 @@ public:
// you can specify which array to use for coloring using these methods.
// The lookup table will decide how to convert vectors to colors.
void SelectColorArray(vtkIdType arrayNum);
void SelectColorArray(const char* arrayName);
void SelectColorArray(const vtkStdString &arrayName);
// Description:
// Get the array name to color by.
vtkStdString GetColorArrayName();
//BTX
protected:
......@@ -133,7 +139,7 @@ protected:
vtkScalarsToColors *LookupTable;
vtkUnsignedCharArray *Colors;
int ScalarVisibility;
char ColorArrayName[256];
vtkStdString ColorArrayName;
private:
vtkPlotParallelCoordinates(const vtkPlotParallelCoordinates &); // Not implemented.
......
......@@ -908,7 +908,7 @@ void vtkPlotPoints::SelectColorArray(vtkIdType arrayNum)
}
//-----------------------------------------------------------------------------
const char* vtkPlotPoints::GetColorArrayName()
vtkStdString vtkPlotPoints::GetColorArrayName()
{
return this->ColorArrayName;
}
......
......@@ -96,7 +96,7 @@ public:
// Description:
// Get the array name to color by.
const char* GetColorArrayName();
vtkStdString GetColorArrayName();
//BTX
// Description:
......