diff --git a/GUI/Models/DomainObjectBuilder.cpp b/GUI/Models/DomainObjectBuilder.cpp index 63421e3c8ee704f6961e2b3e555fabf81f9ddd0f..12e92b67728a0d2d031e4468fc939fc5b1ea61d2 100644 --- a/GUI/Models/DomainObjectBuilder.cpp +++ b/GUI/Models/DomainObjectBuilder.cpp @@ -24,25 +24,22 @@ std::unique_ptr<MultiLayer> GUI::Model::DomainObjectBuilder::buildMultiLayer(const SessionItem& multilayer_item) { auto P_multilayer = GUI::Transform::ToDomain::createMultiLayer(multilayer_item); - QVector<SessionItem*> children = multilayer_item.children(); - for (int i = 0; i < children.size(); ++i) { - if (children[i]->hasModelType<LayerItem>()) { - auto P_layer = buildLayer(*children[i]); - auto roughnessItem = children[i]->getGroupItem(LayerItem::P_ROUGHNESS); - ASSERT(roughnessItem); - auto P_roughness = GUI::Transform::ToDomain::createLayerRoughness(*roughnessItem); - if (P_layer) { - if (P_roughness) - P_multilayer->addLayerWithTopRoughness(*P_layer, *P_roughness); - else - P_multilayer->addLayer(*P_layer); - } + for (LayerItem* child : multilayer_item.childrenOfType<LayerItem>()) { + auto P_layer = buildLayer(*child); + auto roughnessItem = child->getGroupItem(LayerItem::P_ROUGHNESS); + ASSERT(roughnessItem); + auto P_roughness = GUI::Transform::ToDomain::createLayerRoughness(*roughnessItem); + if (P_layer) { + if (P_roughness) + P_multilayer->addLayerWithTopRoughness(*P_layer, *P_roughness); + else + P_multilayer->addLayer(*P_layer); } } return P_multilayer; } -std::unique_ptr<Layer> GUI::Model::DomainObjectBuilder::buildLayer(const SessionItem& item) +std::unique_ptr<Layer> GUI::Model::DomainObjectBuilder::buildLayer(const LayerItem& item) { auto P_layer = GUI::Transform::ToDomain::createLayer(item); QVector<SessionItem*> children = item.children(); diff --git a/GUI/Models/DomainObjectBuilder.h b/GUI/Models/DomainObjectBuilder.h index da29bd4f67c43ac0bdb4f8d20edf715f13e4b63b..c1a3dfb27f14b7074baf20b7f7c97ced52cf604f 100644 --- a/GUI/Models/DomainObjectBuilder.h +++ b/GUI/Models/DomainObjectBuilder.h @@ -19,6 +19,7 @@ class MultiLayer; class Layer; +class LayerItem; class Instrument; class ParticleLayout; class IInterferenceFunction; @@ -29,7 +30,7 @@ class ICoordSystem; namespace GUI::Model::DomainObjectBuilder { std::unique_ptr<MultiLayer> buildMultiLayer(const SessionItem& multilayer_item); -std::unique_ptr<Layer> buildLayer(const SessionItem& item); +std::unique_ptr<Layer> buildLayer(const LayerItem& item); std::unique_ptr<ParticleLayout> buildParticleLayout(const SessionItem& item); std::unique_ptr<IInterferenceFunction> buildInterferenceFunction(const SessionItem& item); std::unique_ptr<Instrument> buildInstrument(const InstrumentItem& instrumentItem); diff --git a/GUI/Models/GUIDomainSampleVisitor.cpp b/GUI/Models/GUIDomainSampleVisitor.cpp index f8225d0775a614d0ed5ee40065c661b76ab9fdf7..c3bbf4527575e101b1d90be523a4aa9bcb5c1af2 100644 --- a/GUI/Models/GUIDomainSampleVisitor.cpp +++ b/GUI/Models/GUIDomainSampleVisitor.cpp @@ -110,7 +110,7 @@ void GUIDomainSampleVisitor::visit(const Layer* sample) const LayerInterface* top_interface = layer_index == 0 ? nullptr : multilayer->layerInterface(layer_index - 1); - SessionItem* layer_item = m_sampleModel->insertItem<LayerItem>(parent); + LayerItem* layer_item = m_sampleModel->insertItem<LayerItem>(parent); layer_item->setItemValue(LayerItem::P_MATERIAL, createMaterialFromDomain(sample->material()).variant()); diff --git a/GUI/Models/LayerItem.cpp b/GUI/Models/LayerItem.cpp index 4bacc9de6dd26d10da87760b12229d0de58f6d8e..51dd593b99367929a6f325b047d1f765f2fa55b1 100644 --- a/GUI/Models/LayerItem.cpp +++ b/GUI/Models/LayerItem.cpp @@ -62,6 +62,26 @@ QVector<SessionItem*> LayerItem::materialPropertyItems() return result; } +double LayerItem::thickness() const +{ + return getItemValue(P_THICKNESS).toDouble(); +} + +void LayerItem::setThickness(double thickness) +{ + setItemValue(P_THICKNESS, thickness); +} + +SessionItem* LayerItem::thicknessItem() const +{ + return getItem(P_THICKNESS); +} + +bool LayerItem::isThicknessPropertyName(const QString& name) +{ + return name == P_THICKNESS; +} + void LayerItem::updateAppearance(SessionItem* new_parent) { if (!new_parent) { diff --git a/GUI/Models/LayerItem.h b/GUI/Models/LayerItem.h index efd2f7fdcab12867167b35fce1636013a17d6b50..3ce5de9ca2faa318ea65eaaeba42ee8693822ff2 100644 --- a/GUI/Models/LayerItem.h +++ b/GUI/Models/LayerItem.h @@ -18,8 +18,10 @@ #include "GUI/Models/SessionGraphicsItem.h" class BA_CORE_API_ LayerItem : public SessionGraphicsItem { -public: +private: static const QString P_THICKNESS; + +public: static const QString P_ROUGHNESS; static const QString P_MATERIAL; static const QString P_NSLICES; @@ -31,6 +33,11 @@ public: QVector<SessionItem*> materialPropertyItems(); + double thickness() const; + void setThickness(double thickness); + SessionItem* thicknessItem() const; + static bool isThicknessPropertyName(const QString& name); + private: void updateAppearance(SessionItem* new_parent); }; diff --git a/GUI/Models/MultiLayerItem.cpp b/GUI/Models/MultiLayerItem.cpp index a9755a84cf6b6f2c58bcf2d51af9ad52da37fd91..9cef2b1ad38f42580ea3368492695a8a8fe067f3 100644 --- a/GUI/Models/MultiLayerItem.cpp +++ b/GUI/Models/MultiLayerItem.cpp @@ -52,7 +52,7 @@ QVector<SessionItem*> MultiLayerItem::materialPropertyItems() void MultiLayerItem::updateLayers() { - QVector<SessionItem*> list = getChildrenOfType(LayerItem::M_TYPE); + QVector<LayerItem*> list = childrenOfType<LayerItem>(); for (auto it = list.begin(); it != list.end(); ++it) { if (it == list.begin()) (*it)->getItem(LayerItem::P_ROUGHNESS)->setEnabled(false); @@ -60,10 +60,10 @@ void MultiLayerItem::updateLayers() (*it)->getItem(LayerItem::P_ROUGHNESS)->setEnabled(true); if (it == list.begin() || it == (list.end() - 1)) { - (*it)->getItem(LayerItem::P_THICKNESS)->setEnabled(false); - (*it)->setItemValue(LayerItem::P_THICKNESS, 0.0); + (*it)->thicknessItem()->setEnabled(false); + (*it)->setThickness(0.0); } else { - (*it)->getItem(LayerItem::P_THICKNESS)->setEnabled(true); + (*it)->thicknessItem()->setEnabled(true); } } } diff --git a/GUI/Models/TransformFromDomain.cpp b/GUI/Models/TransformFromDomain.cpp index cc05c19f5f3d2a7d663d30dc9764dfb6ea143254..36a2b619b306600f00a8e934ceb3fae69340b76b 100644 --- a/GUI/Models/TransformFromDomain.cpp +++ b/GUI/Models/TransformFromDomain.cpp @@ -161,10 +161,10 @@ void GUI::Transform::FromDomain::setRadialParaCrystalItem( setPositionVariance(item, sample); } -void GUI::Transform::FromDomain::setLayerItem(SessionItem* layerItem, const Layer* layer, +void GUI::Transform::FromDomain::setLayerItem(LayerItem* layerItem, const Layer* layer, const LayerInterface* top_interface) { - layerItem->setItemValue(LayerItem::P_THICKNESS, layer->thickness()); + layerItem->setThickness(layer->thickness()); layerItem->setGroupProperty(LayerItem::P_ROUGHNESS, LayerZeroRoughnessItem::M_TYPE); layerItem->setItemValue(LayerItem::P_NSLICES, (int)layer->numberOfSlices()); diff --git a/GUI/Models/TransformFromDomain.h b/GUI/Models/TransformFromDomain.h index d22cf81d358f41a7b29dbc003c2e16d09c938f9d..ae185a52b2565b7ca0965575dc299deec1315131 100644 --- a/GUI/Models/TransformFromDomain.h +++ b/GUI/Models/TransformFromDomain.h @@ -37,6 +37,7 @@ class InterferenceFunctionRadialParaCrystal; class InterferenceFunctionRadialParaCrystalItem; class Layer; class LayerInterface; +class LayerItem; class LayerBasicRoughnessItem; class LayerRoughness; class ParameterDistribution; @@ -77,7 +78,7 @@ void setHardDiskItem(InterferenceFunctionHardDiskItem* item, void setRadialParaCrystalItem(InterferenceFunctionRadialParaCrystalItem* item, const InterferenceFunctionRadialParaCrystal& sample); -void setLayerItem(SessionItem* layer_item, const Layer* layer, const LayerInterface* top_interface); +void setLayerItem(LayerItem* layer_item, const Layer* layer, const LayerInterface* top_interface); void setRoughnessItem(LayerBasicRoughnessItem* item, const LayerRoughness& sample); diff --git a/GUI/Models/TransformToDomain.cpp b/GUI/Models/TransformToDomain.cpp index 86656413f8917e8df3567cb062dedb9194438fb6..703c8ece2c5c674f8c5d17079f778cfa75bc5a8d 100644 --- a/GUI/Models/TransformToDomain.cpp +++ b/GUI/Models/TransformToDomain.cpp @@ -70,10 +70,9 @@ std::unique_ptr<MultiLayer> GUI::Transform::ToDomain::createMultiLayer(const Ses return P_multilayer; } -std::unique_ptr<Layer> GUI::Transform::ToDomain::createLayer(const SessionItem& item) +std::unique_ptr<Layer> GUI::Transform::ToDomain::createLayer(const LayerItem& item) { - auto P_layer = std::make_unique<Layer>(*createDomainMaterial(item), - item.getItemValue(LayerItem::P_THICKNESS).toDouble()); + auto P_layer = std::make_unique<Layer>(*createDomainMaterial(item),item.thickness()); P_layer->setNumberOfSlices(item.getItemValue(LayerItem::P_NSLICES).toUInt()); return P_layer; } diff --git a/GUI/Models/TransformToDomain.h b/GUI/Models/TransformToDomain.h index 03c288bb1c44b0f0944c9a03834a2b95b3cbfbe0..77fb11b047b692f1e20c0a4a03657c7f5a109028 100644 --- a/GUI/Models/TransformToDomain.h +++ b/GUI/Models/TransformToDomain.h @@ -30,6 +30,7 @@ class AngularSpecScan; class BeamDistributionItem; class BeamItem; class GISASSimulation; +class LayerItem; class Material; class MaterialItemContainer; class SessionItem; @@ -39,7 +40,7 @@ namespace GUI::Transform::ToDomain { std::unique_ptr<Material> createDomainMaterial(const SessionItem& item); std::unique_ptr<IParticle> createIParticle(const SessionItem& item); -std::unique_ptr<Layer> createLayer(const SessionItem& item); +std::unique_ptr<Layer> createLayer(const LayerItem& item); std::unique_ptr<LayerRoughness> createLayerRoughness(const SessionItem& item); std::unique_ptr<MultiLayer> createMultiLayer(const SessionItem& item); std::unique_ptr<ParticleLayout> createParticleLayout(const SessionItem& item); diff --git a/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.cpp b/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.cpp index e82ac5ac2954e580c598214f7c37f6ff995f0b2b..f52f787e7b197b554727c4b9060dfe3bc2b7e61c 100644 --- a/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.cpp +++ b/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.cpp @@ -52,7 +52,7 @@ void RealSpaceBuilder::populate(RealSpaceModel* model, const SessionItem& item, populateMultiLayer(model, item, sceneGeometry); else if (item.hasModelType<LayerItem>()) - populateLayer(model, item, sceneGeometry); + populateLayer(model, dynamic_cast<const LayerItem&>(item), sceneGeometry); else if (item.modelType() == "ParticleLayout") populateLayout(model, item, sceneGeometry); @@ -75,7 +75,7 @@ void RealSpaceBuilder::populateMultiLayer(RealSpaceModel* model, const SessionIt { double total_height(0.0); int index(0); - for (auto layer : item.getItems(MultiLayerItem::T_LAYERS)) { + for (auto layer : item.items<LayerItem>(MultiLayerItem::T_LAYERS)) { bool isTopLayer = index == 0; populateLayer(model, *layer, sceneGeometry, @@ -88,7 +88,7 @@ void RealSpaceBuilder::populateMultiLayer(RealSpaceModel* model, const SessionIt } } -void RealSpaceBuilder::populateLayer(RealSpaceModel* model, const SessionItem& layerItem, +void RealSpaceBuilder::populateLayer(RealSpaceModel* model, const LayerItem& layerItem, const SceneGeometry& sceneGeometry, const QVector3D& origin, const bool isTopLayer) { diff --git a/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.h b/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.h index 45130177a70d1ccdeb9f956492cdf0263c84bc7b..327fb45727e7872933fff73cb752e1512f44f1d8 100644 --- a/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.h +++ b/GUI/Views/RealSpaceWidgets/RealSpaceBuilder.h @@ -20,6 +20,7 @@ #include <QWidget> class SessionItem; +class LayerItem; class RealSpaceModel; class Shape3D; class SceneGeometry; @@ -43,7 +44,7 @@ public: void populateMultiLayer(RealSpaceModel* model, const SessionItem& item, const SceneGeometry& sceneGeometry, const QVector3D& origin = {}); - void populateLayer(RealSpaceModel* model, const SessionItem& layerItem, + void populateLayer(RealSpaceModel* model, const LayerItem& layerItem, const SceneGeometry& sceneGeometry, const QVector3D& origin = {}, const bool isTopLayer = false); diff --git a/GUI/Views/RealSpaceWidgets/TransformTo3D.cpp b/GUI/Views/RealSpaceWidgets/TransformTo3D.cpp index 9bd45c26d8ea77e4576c79089210bfa759a521b3..3b6589357e68e9f7f08d3ac97750e1f4c4089f44 100644 --- a/GUI/Views/RealSpaceWidgets/TransformTo3D.cpp +++ b/GUI/Views/RealSpaceWidgets/TransformTo3D.cpp @@ -34,7 +34,7 @@ bool isBottomLayer(const SessionItem& layerItem) } } // namespace -double GUI::View::TransformTo3D::visualLayerThickness(const SessionItem& layerItem, +double GUI::View::TransformTo3D::visualLayerThickness(const LayerItem& layerItem, const SceneGeometry& sceneGeometry) { ASSERT(layerItem.hasModelType<LayerItem>()); @@ -45,17 +45,15 @@ double GUI::View::TransformTo3D::visualLayerThickness(const SessionItem& layerIt else if (isBottomLayer(layerItem)) thickness = sceneGeometry.layer_bottom_thickness(); else - thickness = layerItem.getItemValue(LayerItem::P_THICKNESS).toDouble(); + thickness = layerItem.thickness(); return thickness == 0.0 ? sceneGeometry.layer_min_thickness() : thickness; } std::unique_ptr<GUI::RealSpace::Layer> -GUI::View::TransformTo3D::createLayer(const SessionItem& layerItem, +GUI::View::TransformTo3D::createLayer(const LayerItem& layerItem, const SceneGeometry& sceneGeometry, const QVector3D& origin) { - ASSERT(layerItem.hasModelType<LayerItem>()); - double thickness = GUI::View::TransformTo3D::visualLayerThickness(layerItem, sceneGeometry); double s2 = sceneGeometry.layer_size(); diff --git a/GUI/Views/RealSpaceWidgets/TransformTo3D.h b/GUI/Views/RealSpaceWidgets/TransformTo3D.h index cf3996c330ea3a5604cf261d5e1f4d74c0b483e1..d0ba15b288573d4aa8af3446f64dbf5b2ab9c5e4 100644 --- a/GUI/Views/RealSpaceWidgets/TransformTo3D.h +++ b/GUI/Views/RealSpaceWidgets/TransformTo3D.h @@ -20,6 +20,7 @@ #include "GUI/ba3d/model/particles.h" #include <memory> +class LayerItem; class SessionItem; class SceneGeometry; class IFormFactor; @@ -28,9 +29,9 @@ class IFormFactor; namespace GUI::View::TransformTo3D { -double visualLayerThickness(const SessionItem& layerItem, const SceneGeometry& sceneGeometry); +double visualLayerThickness(const LayerItem& layerItem, const SceneGeometry& sceneGeometry); -std::unique_ptr<GUI::RealSpace::Layer> createLayer(const SessionItem& layerItem, +std::unique_ptr<GUI::RealSpace::Layer> createLayer(const LayerItem& layerItem, const SceneGeometry& sceneGeometry, const QVector3D& origin = {}); diff --git a/GUI/Views/SampleDesigner/ILayerView.cpp b/GUI/Views/SampleDesigner/ILayerView.cpp index 11bf4a2f0f3b24fe89a32e9d0b34b989291bcd07..fa3b4146ace8b28fbc6ac2b5186491d157df75f2 100644 --- a/GUI/Views/SampleDesigner/ILayerView.cpp +++ b/GUI/Views/SampleDesigner/ILayerView.cpp @@ -50,7 +50,7 @@ ILayerView::ILayerView(QGraphicsItem* parent) : ConnectableView(parent) //! Propagates change of 'Thickness' dynamic property to screen thickness of ILayerView. void ILayerView::onPropertyChange(const QString& propertyName) { - if (propertyName == LayerItem::P_THICKNESS) { + if (LayerItem::isThicknessPropertyName(propertyName)) { updateHeight(); } else if (propertyName == LayerItem::P_MATERIAL) { updateColor(); @@ -62,9 +62,8 @@ void ILayerView::onPropertyChange(const QString& propertyName) void ILayerView::updateHeight() { - if (m_item->isTag(LayerItem::P_THICKNESS)) { - m_rect.setHeight(DesignerHelper::nanometerToScreen( - m_item->getItemValue(LayerItem::P_THICKNESS).toDouble())); + if (LayerItem* item = dynamic_cast<LayerItem*>(m_item)) { + m_rect.setHeight(DesignerHelper::nanometerToScreen(item->thickness())); setPortCoordinates(); update(); emit heightChanged(); diff --git a/Tests/UnitTests/GUI/TestMapperForItem.cpp b/Tests/UnitTests/GUI/TestMapperForItem.cpp index 19c8e5cb196eed4a4010f498918aa6d972e2751d..d4015851cb4daa0d90cf8753b4f9a0ad8a6bf36c 100644 --- a/Tests/UnitTests/GUI/TestMapperForItem.cpp +++ b/Tests/UnitTests/GUI/TestMapperForItem.cpp @@ -138,7 +138,7 @@ TEST_F(TestMapperForItem, test_onPropertyChange) setItem(layer, &w); EXPECT_TRUE(m_mapped_item == layer); - layer->setItemValue(LayerItem::P_THICKNESS, 1.0); + layer->setThickness(1.0); EXPECT_EQ(w.m_onPropertyChangeCount, 1); EXPECT_EQ(w.m_onChildPropertyChangeCount, 0); EXPECT_EQ(w.m_onParentChangeCount, 0); @@ -146,7 +146,7 @@ TEST_F(TestMapperForItem, test_onPropertyChange) EXPECT_EQ(w.m_onSiblingsChangeCount, 0); EXPECT_TRUE(w.m_reported_items.isEmpty()); EXPECT_TRUE((w.m_reported_names.size() == 1) - && (w.m_reported_names[0] == LayerItem::P_THICKNESS)); + && LayerItem::isThicknessPropertyName(w.m_reported_names[0])); // Mapper is looking on child; set property of parent; setItem(layer, &w); @@ -163,7 +163,7 @@ TEST_F(TestMapperForItem, test_onPropertyChange) // Mapper is looking on parent; set property of child; setItem(multilayer, &w); EXPECT_TRUE(m_mapped_item == multilayer); - layer->setItemValue(LayerItem::P_THICKNESS, 2.0); + layer->setThickness(2.0); EXPECT_EQ(w.m_onPropertyChangeCount, 0); EXPECT_EQ(w.m_onChildPropertyChangeCount, 1); EXPECT_EQ(w.m_onParentChangeCount, 0); @@ -171,7 +171,7 @@ TEST_F(TestMapperForItem, test_onPropertyChange) EXPECT_EQ(w.m_onSiblingsChangeCount, 0); EXPECT_TRUE((w.m_reported_items.size() == 1) && (w.m_reported_items[0] == layer)); EXPECT_TRUE((w.m_reported_names.size() == 1) - && (w.m_reported_names[0] == LayerItem::P_THICKNESS)); + && LayerItem::isThicknessPropertyName(w.m_reported_names[0])); // Mapper is looking on parent; set property of parent; setItem(multilayer, &w); @@ -259,7 +259,7 @@ TEST_F(TestMapperForItem, test_Subscription) // Mapper is looking on child; set property of child setItem(layer, &w, true); EXPECT_TRUE(m_mapped_item == layer); - layer->setItemValue(LayerItem::P_THICKNESS, 1.0); + layer->setThickness(1.0); EXPECT_EQ(w.m_onPropertyChangeCount, 1); EXPECT_EQ(w.m_onChildPropertyChangeCount, 0); EXPECT_EQ(w.m_onParentChangeCount, 0); @@ -267,14 +267,14 @@ TEST_F(TestMapperForItem, test_Subscription) EXPECT_EQ(w.m_onSiblingsChangeCount, 0); EXPECT_TRUE(w.m_reported_items.isEmpty()); EXPECT_TRUE((w.m_reported_names.size() == 1) - && (w.m_reported_names[0] == LayerItem::P_THICKNESS)); + && LayerItem::isThicknessPropertyName(w.m_reported_names[0])); - layer->setItemValue(LayerItem::P_THICKNESS, 2.0); + layer->setThickness(2.0); EXPECT_EQ(w.m_onPropertyChangeCount, 2); // unsubscribe widget and check that it doesn't react on item value change w.unsubscribe(m_mapper.get()); - layer->setItemValue(LayerItem::P_THICKNESS, 3.0); + layer->setThickness(3.0); EXPECT_EQ(w.m_onPropertyChangeCount, 2); } @@ -292,12 +292,12 @@ TEST_F(TestMapperForItem, test_TwoWidgetsSubscription) EXPECT_EQ(w1.m_onPropertyChangeCount, 0); EXPECT_EQ(w2.m_onPropertyChangeCount, 0); - layer->setItemValue(LayerItem::P_THICKNESS, 1.0); + layer->setThickness(1.0); EXPECT_EQ(w1.m_onPropertyChangeCount, 1); EXPECT_EQ(w2.m_onPropertyChangeCount, 1); w1.unsubscribe(m_mapper.get()); - layer->setItemValue(LayerItem::P_THICKNESS, 2.0); + layer->setThickness(2.0); EXPECT_EQ(w1.m_onPropertyChangeCount, 1); EXPECT_EQ(w2.m_onPropertyChangeCount, 2); } diff --git a/Tests/UnitTests/GUI/TestModelUtils.cpp b/Tests/UnitTests/GUI/TestModelUtils.cpp index 9479c2cc9461f2c87740ccb769a8302f28135740..181d4316c134d2774ba1f6663416a5df99081abc 100644 --- a/Tests/UnitTests/GUI/TestModelUtils.cpp +++ b/Tests/UnitTests/GUI/TestModelUtils.cpp @@ -95,8 +95,8 @@ TEST_F(TestModelUtils, test_iterateIf) { SessionModel model("TestModel"); auto multilayer = model.insertItem<MultiLayerItem>(); - SessionItem* layer = model.insertItem<LayerItem>(multilayer); - SessionItem* thicknessItem = layer->getItem(LayerItem::P_THICKNESS); + LayerItem* layer = model.insertItem<LayerItem>(multilayer); + SessionItem* thicknessItem = layer->thicknessItem(); layer->setVisible(true); EXPECT_TRUE(modelContainsItem(&model, layer)); diff --git a/Tests/UnitTests/GUI/TestMultiLayerItem.cpp b/Tests/UnitTests/GUI/TestMultiLayerItem.cpp index 89bb95f01c0571d31958f30ccad88a5fb730092e..473f8808b9813113a06d6b714a43466c416ec4e7 100644 --- a/Tests/UnitTests/GUI/TestMultiLayerItem.cpp +++ b/Tests/UnitTests/GUI/TestMultiLayerItem.cpp @@ -20,12 +20,12 @@ TEST_F(TestMultiLayerItem, test_twoLayerSystem) auto bottom = model.insertItem<LayerItem>(multilayer); // Thickness property should be disabled for top and bottom layers - EXPECT_FALSE(top->getItem(LayerItem::P_THICKNESS)->isEnabled()); - EXPECT_FALSE(bottom->getItem(LayerItem::P_THICKNESS)->isEnabled()); + EXPECT_FALSE(top->thicknessItem()->isEnabled()); + EXPECT_FALSE(bottom->thicknessItem()->isEnabled()); // Thickness value should be 0.0 for top and bottom layers - EXPECT_EQ(top->getItemValue(LayerItem::P_THICKNESS).toDouble(), 0.0); - EXPECT_EQ(bottom->getItemValue(LayerItem::P_THICKNESS).toDouble(), 0.0); + EXPECT_EQ(top->thickness(), 0.0); + EXPECT_EQ(bottom->thickness(), 0.0); // Roughness group property should be disabled for top, and enabled for bottom layers EXPECT_FALSE(top->getItem(LayerItem::P_ROUGHNESS)->isEnabled()); @@ -52,14 +52,14 @@ TEST_F(TestMultiLayerItem, test_threeLayerSystem) auto bottom = model.insertItem<LayerItem>(multilayer); // Thickness property should be disabled for top and bottom layers and enabled for middle - EXPECT_FALSE(top->getItem(LayerItem::P_THICKNESS)->isEnabled()); - EXPECT_TRUE(middle->getItem(LayerItem::P_THICKNESS)->isEnabled()); - EXPECT_FALSE(bottom->getItem(LayerItem::P_THICKNESS)->isEnabled()); + EXPECT_FALSE(top->thicknessItem()->isEnabled()); + EXPECT_TRUE(middle->thicknessItem()->isEnabled()); + EXPECT_FALSE(bottom->thicknessItem()->isEnabled()); // Thickness value should be 0.0 for top and bottom layers - EXPECT_EQ(top->getItemValue(LayerItem::P_THICKNESS).toDouble(), 0.0); - EXPECT_EQ(middle->getItemValue(LayerItem::P_THICKNESS).toDouble(), 0.0); - EXPECT_EQ(bottom->getItemValue(LayerItem::P_THICKNESS).toDouble(), 0.0); + EXPECT_EQ(top->thickness(), 0.0); + EXPECT_EQ(middle->thickness(), 0.0); + EXPECT_EQ(bottom->thickness(), 0.0); // Roughness group property should be disabled for top, and enabled for other layers EXPECT_FALSE(top->getItem(LayerItem::P_ROUGHNESS)->isEnabled()); @@ -90,12 +90,12 @@ TEST_F(TestMultiLayerItem, test_movingMiddleLayerOnTop) auto bottom = model.insertItem<LayerItem>(multilayer); const double thickness = 10.0; - middle->setItemValue(LayerItem::P_THICKNESS, thickness); + middle->setThickness(thickness); // Thickness property should be disabled for top and bottom layers and enabled for middle - EXPECT_FALSE(top->getItem(LayerItem::P_THICKNESS)->isEnabled()); - EXPECT_TRUE(middle->getItem(LayerItem::P_THICKNESS)->isEnabled()); - EXPECT_FALSE(bottom->getItem(LayerItem::P_THICKNESS)->isEnabled()); + EXPECT_FALSE(top->thicknessItem()->isEnabled()); + EXPECT_TRUE(middle->thicknessItem()->isEnabled()); + EXPECT_FALSE(bottom->thicknessItem()->isEnabled()); // Roughness group property should be disabled for top, and enabled for other layers EXPECT_FALSE(top->getItem(LayerItem::P_ROUGHNESS)->isEnabled()); @@ -103,9 +103,9 @@ TEST_F(TestMultiLayerItem, test_movingMiddleLayerOnTop) EXPECT_TRUE(bottom->getItem(LayerItem::P_ROUGHNESS)->isEnabled()); // Thickness value should be 0.0 for top and bottom layers - EXPECT_EQ(top->getItemValue(LayerItem::P_THICKNESS).toDouble(), 0.0); - EXPECT_EQ(middle->getItemValue(LayerItem::P_THICKNESS).toDouble(), thickness); - EXPECT_EQ(bottom->getItemValue(LayerItem::P_THICKNESS).toDouble(), 0.0); + EXPECT_EQ(top->thickness(), 0.0); + EXPECT_EQ(middle->thickness(), thickness); + EXPECT_EQ(bottom->thickness(), 0.0); // Moving middle layer to top model.moveItem(middle, multilayer, 0, MultiLayerItem::T_LAYERS); @@ -114,13 +114,13 @@ TEST_F(TestMultiLayerItem, test_movingMiddleLayerOnTop) EXPECT_EQ(top, multilayer->childrenOfType<LayerItem>().at(1)); // Thickness and roughness of middle layer should be disabled now - EXPECT_FALSE(middle->getItem(LayerItem::P_THICKNESS)->isEnabled()); + EXPECT_FALSE(middle->thicknessItem()->isEnabled()); EXPECT_FALSE(middle->getItem(LayerItem::P_ROUGHNESS)->isEnabled()); // And, thickness of middle should become 0 to stress the fact that it become top - EXPECT_EQ(middle->getItemValue(LayerItem::P_THICKNESS).toDouble(), 0.0); + EXPECT_EQ(middle->thickness(), 0.0); // Thickness and roughness of former top layer should be enabled now, since it is in the middle - EXPECT_TRUE(top->getItem(LayerItem::P_THICKNESS)->isEnabled()); + EXPECT_TRUE(top->thicknessItem()->isEnabled()); EXPECT_TRUE(top->getItem(LayerItem::P_ROUGHNESS)->isEnabled()); }