## Copyright (C) 2014-20xx CEA/DEN, EDF R&D
INCLUDE(Common)
+INCLUDE(UnitTest)
SET(PROJECT_HEADERS
PartSetAPI.h
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)
#include "PartSetAPI_Part.h"
//--------------------------------------------------------------------------------------
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Selection.h>
//--------------------------------------------------------------------------------------
#include <PartSetPlugin_Duplicate.h>
#include <PartSetPlugin_Remove.h>
return PartPtr(new PartSetAPI_Part(aFeature));
}
-PartPtr duplicatePart(const std::shared_ptr<ModelAPI_Document> & thePart)
+PartPtr duplicatePart(const ModelHighAPI_Interface& thePart)
{
- std::shared_ptr<ModelAPI_Feature> 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<ModelAPI_ResultPart>(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<ModelAPI_ResultPart>(
+ aNewPart->firstResult())->partDoc();
+ ModelAPI_Session::get()->setActiveDocument(aNewDoc);
+ }
+ }
+ }
+ return aResult;
}
-void removePart(const std::shared_ptr<ModelAPI_Document> & thePart)
+void removePart(const ModelHighAPI_Interface& thePart)
{
- std::shared_ptr<ModelAPI_Feature> 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<ModelAPI_ResultPart>(aPartFeature->firstResult())->partDoc();
+ if (aPartDoc.get()) {
+ ModelAPI_Session::get()->setActiveDocument(aPartDoc);
+ aPartDoc->addFeature(PartSetPlugin_Remove::ID());
+ ModelAPI_Session::get()->setActiveDocument(aPartSet);
+ }
+ }
}
* \brief Duplicate Part feature
*/
PARTSETAPI_EXPORT
-PartPtr duplicatePart(const std::shared_ptr<ModelAPI_Document> & thePart);
+PartPtr duplicatePart(const ModelHighAPI_Interface& thePart);
/**\ingroup CPPHighAPI
* \brief Remove Part feature
*/
PARTSETAPI_EXPORT
-void removePart(const std::shared_ptr<ModelAPI_Document> & thePart);
+void removePart(const ModelHighAPI_Interface& thePart);
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
--- /dev/null
+# 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