<commit_before>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "QmitkCreateSimulationAction.h"
#include <mitkIOUtil.h>
#include <mitkNodePredicateNot.h>
#include <mitkNodePredicateProperty.h>
#include <mitkIRenderingManager.h>
#include <mitkSimulationTemplate.h>
#include <algorithm>

static std::string CreateFileName(mitk::DataNode::Pointer dataNode)
{
  std::string path;
  dataNode->GetStringProperty("path", path);

  std::string name;
  dataNode->GetStringProperty("name", name);

  if (name.length() < 5)
  {
    name += ".scn";
  }
  else
  {
    std::string ext = name.substr(name.length() - 4);
    std::transform(ext.begin(), ext.end(), ext.begin(), tolower);

    if (ext != ".scn" && ext != ".xml")
      name += ".scn";
  }

  return path + "/" + name;
}

static void InitializeViews(mitk::DataStorage::Pointer dataStorage)
{
  mitk::NodePredicateNot::Pointer predicate = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false)));
  mitk::DataStorage::SetOfObjects::ConstPointer subset = dataStorage->GetSubset(predicate);
  mitk::TimeSlicedGeometry::Pointer geometry = dataStorage->ComputeBoundingGeometry3D(subset);

  mitk::RenderingManager::GetInstance()->InitializeViews(geometry);
}

QmitkCreateSimulationAction::QmitkCreateSimulationAction()
{
}

QmitkCreateSimulationAction::~QmitkCreateSimulationAction()
{
}

void QmitkCreateSimulationAction::Run(const QList<mitk::DataNode::Pointer>& selectedNodes)
{
  mitk::DataNode::Pointer dataNode;

  foreach(dataNode, selectedNodes)
  {
    if (dynamic_cast<mitk::SimulationTemplate*>(dataNode->GetData()) != NULL)
    {
      mitk::SimulationTemplate* simulationTemplate = static_cast<mitk::SimulationTemplate*>(dataNode->GetData());
      std::string contents = simulationTemplate->Bake();

      if (contents.empty())
      {
        MITK_ERROR << "Could not bake simulation template '" << dataNode->GetName() << "'!";
        continue;
      }

      std::string fileName = CreateFileName(dataNode);

      std::ofstream file(fileName);
      file << contents;
      file.close();

      std::vector<std::string> fileNames;
      fileNames.push_back(fileName);

      mitk::DataNode::Pointer simulationNode = mitk::IOUtil::LoadDataNode(fileName);

      if (simulationNode.IsNotNull())
      {
        m_DataStorage->Add(simulationNode, dataNode);
        InitializeViews(m_DataStorage);
      }
    }
  }
}

void QmitkCreateSimulationAction::SetDataStorage(mitk::DataStorage* dataStorage)<commit_msg>COMP: Another std string to char string fix.<commit_after>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "QmitkCreateSimulationAction.h"
#include <mitkIOUtil.h>
#include <mitkNodePredicateNot.h>
#include <mitkNodePredicateProperty.h>
#include <mitkIRenderingManager.h>
#include <mitkSimulationTemplate.h>
#include <algorithm>

static std::string CreateFileName(mitk::DataNode::Pointer dataNode)
{
  std::string path;
  dataNode->GetStringProperty("path", path);

  std::string name;
  dataNode->GetStringProperty("name", name);

  if (name.length() < 5)
  {
    name += ".scn";
  }
  else
  {
    std::string ext = name.substr(name.length() - 4);
    std::transform(ext.begin(), ext.end(), ext.begin(), tolower);

    if (ext != ".scn" && ext != ".xml")
      name += ".scn";
  }

  return path + "/" + name;
}

static void InitializeViews(mitk::DataStorage::Pointer dataStorage)
{
  mitk::NodePredicateNot::Pointer predicate = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false)));
  mitk::DataStorage::SetOfObjects::ConstPointer subset = dataStorage->GetSubset(predicate);
  mitk::TimeSlicedGeometry::Pointer geometry = dataStorage->ComputeBoundingGeometry3D(subset);

  mitk::RenderingManager::GetInstance()->InitializeViews(geometry);
}

QmitkCreateSimulationAction::QmitkCreateSimulationAction()
{
}

QmitkCreateSimulationAction::~QmitkCreateSimulationAction()
{
}

void QmitkCreateSimulationAction::Run(const QList<mitk::DataNode::Pointer>& selectedNodes)
{
  mitk::DataNode::Pointer dataNode;

  foreach(dataNode, selectedNodes)
  {
    if (dynamic_cast<mitk::SimulationTemplate*>(dataNode->GetData()) != NULL)
    {
      mitk::SimulationTemplate* simulationTemplate = static_cast<mitk::SimulationTemplate*>(dataNode->GetData());
      std::string contents = simulationTemplate->Bake();

      if (contents.empty())
      {
        MITK_ERROR << "Could not bake simulation template '" << dataNode->GetName() << "'!";
        continue;
      }

      std::string fileName = CreateFileName(dataNode);

      std::ofstream file(fileName.c_str());
      file << contents;
      file.close();

      std::vector<std::string> fileNames;
      fileNames.push_back(fileName);

      mitk::DataNode::Pointer simulationNode = mitk::IOUtil::LoadDataNode(fileName);

      if (simulationNode.IsNotNull())
      {
        m_DataStorage->Add(simulationNode, dataNode);
        InitializeViews(m_DataStorage);
      }
    }
  }
}

void QmitkCreateSimulationAction::SetDataStorage(mitk::DataStorage* dataStorage)
{'fraction_non_alphanumeric': 0.17389138016940708, 'fraction_numerical': 0.000996512207274539, 'mean_word_length': 5.312368972746331, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1568669', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1747, 'n_words': 334}