From: mpv Date: Tue, 13 Dec 2016 07:31:36 +0000 (+0300) Subject: Added a unit test for Parts remove and duplicate API X-Git-Tag: before_porting_8.2.0~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f6dd26b25e43c4cb2675d45a2cf4bff71fe91dd0;p=modules%2Fshaper.git Added a unit test for Parts remove and duplicate API --- diff --git a/src/PartSetAPI/CMakeLists.txt b/src/PartSetAPI/CMakeLists.txt index 8d75a233a..2a112976e 100644 --- a/src/PartSetAPI/CMakeLists.txt +++ b/src/PartSetAPI/CMakeLists.txt @@ -1,6 +1,7 @@ ## Copyright (C) 2014-20xx CEA/DEN, EDF R&D INCLUDE(Common) +INCLUDE(UnitTest) SET(PROJECT_HEADERS PartSetAPI.h @@ -67,3 +68,5 @@ ENDIF(WIN32) INSTALL(TARGETS _PartSetAPI DESTINATION ${SHAPER_INSTALL_SWIG}) INSTALL(TARGETS PartSetAPI DESTINATION ${SHAPER_INSTALL_BIN}) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/PartSetAPI.py DESTINATION ${SHAPER_INSTALL_SWIG}) + +ADD_UNIT_TESTS(TestRemoveDuplicate.py) diff --git a/src/PartSetAPI/PartSetAPI_Part.cpp b/src/PartSetAPI/PartSetAPI_Part.cpp index 63b3def93..be1642584 100644 --- a/src/PartSetAPI/PartSetAPI_Part.cpp +++ b/src/PartSetAPI/PartSetAPI_Part.cpp @@ -9,7 +9,9 @@ #include "PartSetAPI_Part.h" //-------------------------------------------------------------------------------------- #include +#include #include +#include //-------------------------------------------------------------------------------------- #include #include @@ -47,15 +49,46 @@ PartPtr addPart(const std::shared_ptr & thePart) return PartPtr(new PartSetAPI_Part(aFeature)); } -PartPtr duplicatePart(const std::shared_ptr & thePart) +PartPtr duplicatePart(const ModelHighAPI_Interface& thePart) { - std::shared_ptr aFeature = thePart->addFeature(PartSetPlugin_Duplicate::ID()); - aFeature->execute(); - return PartPtr(new PartSetAPI_Part(aFeature)); + PartPtr aResult; + // only the active part is duplicated, so, activate it + FeaturePtr aPartFeature = thePart.feature(); + if (aPartFeature) { + // duplication of the current part is performed + DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument(); + aPartSet->setCurrentFeature(aPartFeature, false); + DocumentPtr aPartDoc = + std::dynamic_pointer_cast(aPartFeature->firstResult())->partDoc(); + if (aPartDoc.get()) { + ModelAPI_Session::get()->setActiveDocument(aPartDoc); + FeaturePtr aDuplicate = aPartDoc->addFeature(PartSetPlugin_Duplicate::ID()); + //aDuplicate->execute(); // it is executed at creation because it is action + FeaturePtr aNewPart = aPartSet->currentFeature(false); // a copy becomes a current + if (aNewPart.get()) { + aResult = PartPtr(new PartSetAPI_Part(aNewPart)); + DocumentPtr aNewDoc = std::dynamic_pointer_cast( + aNewPart->firstResult())->partDoc(); + ModelAPI_Session::get()->setActiveDocument(aNewDoc); + } + } + } + return aResult; } -void removePart(const std::shared_ptr & thePart) +void removePart(const ModelHighAPI_Interface& thePart) { - std::shared_ptr aFeature = thePart->addFeature(PartSetPlugin_Remove::ID()); - aFeature->execute(); + FeaturePtr aPartFeature = thePart.feature(); + if (aPartFeature) { + // duplication of the current part is performed + DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument(); + aPartSet->setCurrentFeature(aPartFeature, false); + DocumentPtr aPartDoc = + std::dynamic_pointer_cast(aPartFeature->firstResult())->partDoc(); + if (aPartDoc.get()) { + ModelAPI_Session::get()->setActiveDocument(aPartDoc); + aPartDoc->addFeature(PartSetPlugin_Remove::ID()); + ModelAPI_Session::get()->setActiveDocument(aPartSet); + } + } } diff --git a/src/PartSetAPI/PartSetAPI_Part.h b/src/PartSetAPI/PartSetAPI_Part.h index ccdcfdb5a..90977f01c 100644 --- a/src/PartSetAPI/PartSetAPI_Part.h +++ b/src/PartSetAPI/PartSetAPI_Part.h @@ -56,13 +56,13 @@ PartPtr addPart(const std::shared_ptr & thePartSet); * \brief Duplicate Part feature */ PARTSETAPI_EXPORT -PartPtr duplicatePart(const std::shared_ptr & thePart); +PartPtr duplicatePart(const ModelHighAPI_Interface& thePart); /**\ingroup CPPHighAPI * \brief Remove Part feature */ PARTSETAPI_EXPORT -void removePart(const std::shared_ptr & thePart); +void removePart(const ModelHighAPI_Interface& thePart); //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- diff --git a/src/PartSetAPI/Test/TestRemoveDuplicate.py b/src/PartSetAPI/Test/TestRemoveDuplicate.py new file mode 100644 index 000000000..466d310bf --- /dev/null +++ b/src/PartSetAPI/Test/TestRemoveDuplicate.py @@ -0,0 +1,51 @@ +# Created a Part Remove/Duplicate API functionality since from low level and python dump it is not +# tested: feature history infor is not stored. + +import model + +# prepare axis created by PartSet and Part points +model.begin() +PartSet = model.moduleDocument() +Part_1 = model.addPart(PartSet) +Part_1_doc = Part_1.document() +Point_2 = model.addPoint(Part_1_doc, 100, 50, 20) +Axis_4 = model.addAxis(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("VERTEX", "Point_1")) +model.do() + +# Duplicate this part twice, duplicate the first Copy also +Copy_1 = model.duplicatePart(Part_1) +Copy_2 = model.duplicatePart(Part_1) +Copy_3 = model.duplicatePart(Copy_1) +model.do() + +# check the intermediate result +assert PartSet.size("Parts") == 4 +i = 0 +for n in ["Part_1", "Part_3", "Part_2", "Part_4"]: + assert PartSet.object("Parts", i).data().name() == n + i = i + 1 + +# Remove the middle Part +model.removePart(Copy_2) +model.do() + +# check the intermediate result +assert PartSet.size("Parts") == 3 +i = 0 +for n in ["Part_1", "Part_2", "Part_4"]: + assert PartSet.object("Parts", i).data().name() == n + i = i + 1 + +# Remove a first copy +model.removePart(Copy_1) +model.end() + +# Undo the last remove +model.undo() + +# Check the result +assert PartSet.size("Parts") == 3 +i = 0 +for n in ["Part_1", "Part_2", "Part_4"]: + assert PartSet.object("Parts", i).data().name() == n + i = i + 1