// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkSILBuilder.h"

#include "vtkDataSetAttributes.h"
#include "vtkMutableDirectedGraph.h"
#include "vtkObjectFactory.h"
#include "vtkStringArray.h"
#include "vtkUnsignedCharArray.h"

VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkSILBuilder);
vtkCxxSetObjectMacro(vtkSILBuilder, SIL, vtkMutableDirectedGraph);
//------------------------------------------------------------------------------
vtkSILBuilder::vtkSILBuilder()
{
  this->NamesArray = nullptr;
  this->CrossEdgesArray = nullptr;
  this->SIL = nullptr;
  this->RootVertex = -1;
}

//------------------------------------------------------------------------------
vtkSILBuilder::~vtkSILBuilder()
{
  this->SetSIL(nullptr);
}

//------------------------------------------------------------------------------
void vtkSILBuilder::Initialize()
{
  this->SIL->Initialize();
  this->NamesArray = vtkStringArray::New();
  this->NamesArray->SetName("Names");
  this->CrossEdgesArray = vtkUnsignedCharArray::New();
  this->CrossEdgesArray->SetName("CrossEdges");
  this->SIL->GetVertexData()->AddArray(this->NamesArray);
  this->SIL->GetEdgeData()->AddArray(this->CrossEdgesArray);
  this->NamesArray->Delete();
  this->CrossEdgesArray->Delete();

  this->RootVertex = this->AddVertex("SIL");
}

//------------------------------------------------------------------------------
vtkIdType vtkSILBuilder::AddVertex(const char* name)
{
  vtkIdType vertex = this->SIL->AddVertex();
  this->NamesArray->InsertValue(vertex, name);
  return vertex;
}

//------------------------------------------------------------------------------
vtkIdType vtkSILBuilder::AddChildEdge(vtkIdType src, vtkIdType dst)
{
  vtkIdType id = this->SIL->AddEdge(src, dst).Id;
  this->CrossEdgesArray->InsertValue(id, 0);
  return id;
}

//------------------------------------------------------------------------------
vtkIdType vtkSILBuilder::AddCrossEdge(vtkIdType src, vtkIdType dst)
{
  vtkIdType id = this->SIL->AddEdge(src, dst).Id;
  this->CrossEdgesArray->InsertValue(id, 1);
  return id;
}

//------------------------------------------------------------------------------
void vtkSILBuilder::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}
VTK_ABI_NAMESPACE_END
