From: Nicolas RECHATIN Date: Fri, 30 Jul 2021 14:28:51 +0000 (+0200) Subject: test Implementing error cases for volumes X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4e708fa6231dcecabe5fc47f39040c5745f488ae;p=modules%2Fshaper.git test Implementing error cases for volumes --- diff --git a/src/OperaAPI/OperaAPI_Volume.cpp b/src/OperaAPI/OperaAPI_Volume.cpp index a06cdf7cc..b216ec67e 100644 --- a/src/OperaAPI/OperaAPI_Volume.cpp +++ b/src/OperaAPI/OperaAPI_Volume.cpp @@ -16,12 +16,17 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // - #include "OperaAPI_Volume.h" + + #include +#include #include +#include // std::wstring_convert +#include // std::codecvt_utf8 + //================================================================================================== OperaAPI_Volume::OperaAPI_Volume(const std::shared_ptr& theFeature) : ModelHighAPI_Interface(theFeature) @@ -29,6 +34,7 @@ OperaAPI_Volume::OperaAPI_Volume(const std::shared_ptr& theFea initialize(); } + //================================================================================================== OperaAPI_Volume::OperaAPI_Volume(const std::shared_ptr& theFeature, const ModelHighAPI_Double& theMedium, @@ -36,7 +42,12 @@ OperaAPI_Volume::OperaAPI_Volume(const std::shared_ptr& theFea : ModelHighAPI_Interface(theFeature) { if(initialize()) { - fillAttribute(OperaPlugin_Volume::MEDIUM(), medium()); + + std::wstring w_medium = theMedium.string(); + std::wstring_convert,wchar_t> cv; + std::string medium_str = cv.to_bytes(w_medium); + + fillAttribute(medium_str, medium()); setObjectList(theObjectList); } } @@ -48,7 +59,6 @@ OperaAPI_Volume::~OperaAPI_Volume() {} void OperaAPI_Volume::setMedium(const ModelHighAPI_Double& theMedium) { fillAttribute(OperaPlugin_Volume::MEDIUM(), medium()); - execute(); } @@ -56,7 +66,6 @@ void OperaAPI_Volume::setMedium(const ModelHighAPI_Double& theMedium) void OperaAPI_Volume::setObjectList(const std::list& theObjectList) { fillAttribute(theObjectList, volumeList()); - execute(); } diff --git a/src/OperaPlugin/Test/TestVolume.py b/src/OperaPlugin/Test/TestVolume.py index e199da673..bd6d2bccf 100755 --- a/src/OperaPlugin/Test/TestVolume.py +++ b/src/OperaPlugin/Test/TestVolume.py @@ -31,8 +31,9 @@ partSet = model.moduleDocument() Part_1 = model.addPart(partSet) Part_1_doc = Part_1.document() -### Create a box +### Create two box (one for error case) Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) ### Create a cylinder Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) @@ -41,12 +42,12 @@ Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Or Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 10) ### Create a volume from the box -Volume_1 = model.addVolume(Part_1_doc, "dede", [model.selection("SOLID", "Box_1_1")]) +Volume_1 = model.addVolume(Part_1_doc, "Air", [model.selection("SOLID", "Box_1_1")]) ### Create a volume from the cylinder and the sphere -Volume_2 = model.addVolume(Part_1_doc, "frgt", [model.selection("SOLID", "Cylinder_1_1"), model.selection("SOLID", "Sphere_1_1")]) +Volume_2 = model.addVolume(Part_1_doc, "Concrete", [model.selection("SOLID", "Cylinder_1_1"), model.selection("SOLID", "Sphere_1_1")]) -# Checks +#Checks from GeomAPI import GeomAPI_Shape model.testNbResults(Volume_1, 1) @@ -60,6 +61,21 @@ model.testNbSubResults(Volume_2, [0, 0]) model.testNbSubShapes(Volume_2, GeomAPI_Shape.SOLID, [1, 1]) model.testNbSubShapes(Volume_2, GeomAPI_Shape.FACE, [3, 1]) +### Create a volume with no medium +Volume_3 = model.addVolume(Part_1_doc, "", [model.selection("SOLID", "Box_2_1")]) +model.testNbResults(Volume_3, 0) +assert(Volume_3.feature().error() == "Error: Medium cannot be empty.") + +### Create a volume with no shapes +Volume_4 = model.addVolume(Part_1_doc, "Error", []) +model.testNbResults(Volume_4, 0) +assert(Volume_4.feature().error() == "Attribute \"volume_list\" is not initialized.") + +### Create a volume with bad shapes +Volume_5 = model.addVolume(Part_1_doc, "Bad Shape", [model.selection("VERTEX", "PartSet/Origin")]) +model.testNbResults(Volume_5, 0) +assert(Volume_5.feature().error() == "It does not contain element with acceptable shape type. The type should be one of the next: solid") + #========================================================================= # End of test #========================================================================= diff --git a/src/OperaPlugin/icons/Volume.png b/src/OperaPlugin/icons/Volume.png new file mode 100644 index 000000000..2b0757b05 Binary files /dev/null and b/src/OperaPlugin/icons/Volume.png differ