Salome HOME
Issue #555 Make a number of shifted/rotated copies - selected object does not appear...
[modules/shaper.git] / src / Model / Model_AttributeSelectionList.cpp
index 000ba2b0d5565b4a9e11c06097c124e26a7f6529..3b67df9eb0a9063e23a7874fde696432fdaa9857 100644 (file)
 #include <TDF_ChildIterator.hxx>
 #include <TopAbs_ShapeEnum.hxx>
 
+#include <TopoDS.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Edge.hxx>
+#include <BRep_Tool.hxx>
+
 using namespace std;
 
 void Model_AttributeSelectionList::append(
     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
 {
+  // do not use the degenerated edge as a shape, a list is not incremented in this case
+  if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) {
+    const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
+    if (aSubShape.ShapeType() == TopAbs_EDGE && BRep_Tool::Degenerated(TopoDS::Edge(aSubShape))) {
+      return;
+    }
+  }
+
   int aNewTag = mySize->Get() + 1;
   TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
 
@@ -26,6 +39,7 @@ void Model_AttributeSelectionList::append(
   if (owner()) {
     aNewAttr->setObject(owner());
   }
+  aNewAttr->setID(id());
   mySize->Set(aNewTag);
   aNewAttr->setValue(theContext, theSubShape);
   owner()->data()->sendAttributeUpdated(this);
@@ -88,6 +102,14 @@ void Model_AttributeSelectionList::clear()
   }
 }
 
+bool Model_AttributeSelectionList::isInitialized()
+{
+  if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo
+    return false;
+  }
+  return ModelAPI_AttributeSelectionList::isInitialized();
+}
+
 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
 {
   myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;