예제 #1
0
파일: Material.cpp 프로젝트: luk2010/GRE
MaterialVector MaterialManager::load(const std::string &filepath)
{
    if ( !filepath.empty() )
    {
        // We must find a MaterialLoader able to load this file.
        
        for ( auto it = iFactory.getLoaders().begin(); it != iFactory.getLoaders().end(); it++ )
        {
            MaterialLoader* loader = it->second.get();
            
            if ( loader )
            {
                if ( loader->isLoadable(filepath) )
                {
                    // Found a loader. Load the Materials.
                    
                    MaterialHolderList materials = loader->load(filepath);
                    
                    if ( !materials.empty() )
                    {
                        // Registers every Loader to the Manager and to the return Vector.
                        
                        MaterialVector ret;
                        
                        for ( MaterialHolder& holder : materials )
                        {
                            iMaterials.add(holder);
                            ret.push_back(Material(holder));
                        }
                        
                        return ret;
                    }
                    
                    else
                    {
#ifdef GreIsDebugMode
                        GreDebugPretty() << "File '" << filepath << "' doesn't seem to contain any Material." << std::endl;
#endif
                        return MaterialVector();
                    }
                }
            }
        }
        
#ifdef GreIsDebugMode
        GreDebugPretty() << "File '" << filepath << "' is not loadable by any MaterialLoader." << std::endl;
#endif
        return MaterialVector();
    }
    
    else
    {
#ifdef GreIsDebugMode
        GreDebugPretty() << "'filepath' is empty." << std::endl;
#endif
        return MaterialVector();
    }
}
예제 #2
0
TEST_F(ModelFixture, ConstructionWithInternalSource_Layers)
{
  Model model;

  // Create some materials
  StandardOpaqueMaterial exterior(model);
  AirGap air(model);
  StandardOpaqueMaterial interior(model);

  MaterialVector layers;
  layers.push_back(exterior);
  layers.push_back(air);
  layers.push_back(interior);

  ConstructionWithInternalSource construction(model);
  EXPECT_TRUE(construction.setLayers(layers));

  // Get layers
  MaterialVector testLayers = construction.layers();
  ASSERT_EQ(static_cast<unsigned>(3),testLayers.size());
  EXPECT_TRUE(testLayers[0] == exterior);
  EXPECT_TRUE(testLayers[1] == air);
  EXPECT_TRUE(testLayers[2] == interior);
}
TEST_F(ModelFixture, ConstructionWithInternalSource_FromLayers)
{
  Model model;

  // Create some materials
  StandardOpaqueMaterial exterior(model);
  StandardOpaqueMaterial interior(model);

  OpaqueMaterialVector layers;

  EXPECT_EQ(0, model.getModelObjects<ConstructionWithInternalSource>().size());

  EXPECT_EQ(0, layers.size());
  EXPECT_THROW((ConstructionWithInternalSource(layers)), std::exception);

  EXPECT_EQ(0, model.getModelObjects<ConstructionWithInternalSource>().size());

  layers.push_back(exterior);

  EXPECT_EQ(1u, layers.size());
  EXPECT_THROW((ConstructionWithInternalSource(layers)), std::exception);

  EXPECT_EQ(0, model.getModelObjects<ConstructionWithInternalSource>().size());

  layers.push_back(interior);

  EXPECT_EQ(2u, layers.size());
  ConstructionWithInternalSource construction(layers);
  EXPECT_EQ(2u, construction.numLayers());
  EXPECT_EQ(2u, construction.layers().size());
  EXPECT_EQ(1, construction.sourcePresentAfterLayerNumber());
  EXPECT_EQ(1, construction.temperatureCalculationRequestedAfterLayerNumber());
  EXPECT_EQ(1, construction.dimensionsForTheCTFCalculation());
  EXPECT_EQ(0.154, construction.tubeSpacing());

  // check that we can't mess up the construction
  EXPECT_FALSE(construction.setSourcePresentAfterLayerNumber(3));
  EXPECT_EQ(1, construction.sourcePresentAfterLayerNumber());
  EXPECT_FALSE(construction.setTemperatureCalculationRequestedAfterLayerNumber(3));
  EXPECT_EQ(1, construction.temperatureCalculationRequestedAfterLayerNumber());

  EXPECT_TRUE(construction.eraseLayer(1));
  EXPECT_EQ(1u, construction.numLayers());

  EXPECT_FALSE(construction.setLayers(MaterialVector()));
  EXPECT_EQ(1u, construction.numLayers());

  MaterialVector testLayers = construction.layers();
  ASSERT_EQ(static_cast<unsigned>(1),testLayers.size());
  EXPECT_TRUE(testLayers[0] == exterior);

  testLayers.push_back(interior);
  testLayers.push_back(exterior);

  EXPECT_TRUE(construction.setLayers(testLayers));
  EXPECT_EQ(3u, construction.numLayers());

  testLayers = construction.layers();
  ASSERT_EQ(static_cast<unsigned>(3),testLayers.size());
  EXPECT_TRUE(testLayers[0] == exterior);
  EXPECT_TRUE(testLayers[1] == interior);
  EXPECT_TRUE(testLayers[2] == exterior);

  EXPECT_TRUE(construction.setSourcePresentAfterLayerNumber(3));
  EXPECT_EQ(3, construction.sourcePresentAfterLayerNumber());
  EXPECT_TRUE(construction.setTemperatureCalculationRequestedAfterLayerNumber(3));
  EXPECT_EQ(3, construction.temperatureCalculationRequestedAfterLayerNumber());

  testLayers.clear();
  testLayers.push_back(interior);
  testLayers.push_back(exterior);

  EXPECT_TRUE(construction.setLayers(testLayers));
  EXPECT_EQ(2u, construction.numLayers());

  testLayers = construction.layers();
  ASSERT_EQ(static_cast<unsigned>(2),testLayers.size());
  EXPECT_TRUE(testLayers[0] == interior);
  EXPECT_TRUE(testLayers[1] == exterior);

  EXPECT_EQ(1, construction.sourcePresentAfterLayerNumber());
  EXPECT_EQ(1, construction.temperatureCalculationRequestedAfterLayerNumber());

  EXPECT_FALSE(construction.setSourcePresentAfterLayerNumber(3));
  EXPECT_EQ(1, construction.sourcePresentAfterLayerNumber());
  EXPECT_FALSE(construction.setTemperatureCalculationRequestedAfterLayerNumber(3));
  EXPECT_EQ(1, construction.temperatureCalculationRequestedAfterLayerNumber());

  while (layers.size() < 11) {
    layers.push_back(exterior);
  }
  EXPECT_THROW((ConstructionWithInternalSource(layers)), std::exception);
}