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 14a684a96657ff7f13443ac8dc4ef9bff83ccc9a..3b67df9eb0a9063e23a7874fde696432fdaa9857 100644 (file)
 #include "Model_Data.h"
 
 #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);
 
@@ -25,24 +39,40 @@ void Model_AttributeSelectionList::append(
   if (owner()) {
     aNewAttr->setObject(owner());
   }
+  aNewAttr->setID(id());
   mySize->Set(aNewTag);
   aNewAttr->setValue(theContext, theSubShape);
   owner()->data()->sendAttributeUpdated(this);
 }
 
+void Model_AttributeSelectionList::append(std::string theNamingName)
+{
+  int aNewTag = mySize->Get() + 1;
+  TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
+
+  std::shared_ptr<Model_AttributeSelection> aNewAttr = 
+    std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
+  if (owner()) {
+    aNewAttr->setObject(owner());
+  }
+  mySize->Set(aNewTag);
+  aNewAttr->selectSubShape(selectionType(), theNamingName);
+  owner()->data()->sendAttributeUpdated(this);
+}
+
 int Model_AttributeSelectionList::size()
 {
   return mySize->Get();
 }
 
-int Model_AttributeSelectionList::selectionType()
+const std::string Model_AttributeSelectionList::selectionType() const
 {
-  return (int) mySelectionType->Get();
+  return TCollection_AsciiString(mySelectionType->Get()).ToCString();
 }
 
-void Model_AttributeSelectionList::setSelectionType(int theType)
+void Model_AttributeSelectionList::setSelectionType(const std::string& theType)
 {
-  mySelectionType->Set((double) theType);
+  mySelectionType->Set(theType.c_str());
 }
 
 std::shared_ptr<ModelAPI_AttributeSelection> 
@@ -72,13 +102,21 @@ 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;
   if (!myIsInitialized) {
     mySize = TDataStd_Integer::Set(theLabel, 0);
-    mySelectionType = TDataStd_Real::Set(theLabel, 0);
+    mySelectionType = TDataStd_Comment::Set(theLabel, "");
   } else { // recollect mySubs
-    theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType);
+    theLabel.FindAttribute(TDataStd_Comment::GetID(), mySelectionType);
   }
 }