Salome HOME
Fix for compilation errors on Linux
[modules/shaper.git] / src / Model / Model_BodyBuilder.cpp
index 0efc177974662432e046e31a3bcbb562d2f2456c..22a621d622344e8b42ea4841bd2e1e3324505513 100755 (executable)
@@ -12,6 +12,7 @@
 #include <TNaming_Builder.hxx>
 #include <TNaming_NamedShape.hxx>
 #include <TNaming_Iterator.hxx>
+#include <TNaming_Tool.hxx>
 #include <TDataStd_Name.hxx>
 #include <TDataStd_Integer.hxx>
 #include <TopoDS.hxx>
@@ -86,6 +87,8 @@ static void evolutionToSelectionRec(TDF_Label theLab, const bool theFlag) {
       aBuilder.Delete(aPairsIter->first);
     } else if (anEvol == TNaming_PRIMITIVE) {
       aBuilder.Generated(aPairsIter->second);
+    } else if (anEvol == TNaming_SELECTED) {
+      aBuilder.Select(aPairsIter->first, aPairsIter->second);
     }
   }
   // recursive call for all sub-labels
@@ -213,6 +216,22 @@ void Model_BodyBuilder::storeModified(const std::shared_ptr<GeomAPI_Shape>& theO
     }
   }
 }
+
+void  Model_BodyBuilder::storeWithoutNaming(const std::shared_ptr<GeomAPI_Shape>& theShape)
+{
+  std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
+  if (aData) {
+    clean();   
+    if (!theShape.get())
+      return; // bad shape
+    TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+    if (aShape.IsNull())
+      return;  // null shape inside
+    TNaming_Builder aBuilder(aData->shapeLab());
+    aBuilder.Select(aShape, aShape);
+  }
+}
+
 void Model_BodyBuilder::clean()
 {
   std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
@@ -732,6 +751,11 @@ std::shared_ptr<GeomAPI_Shape> Model_BodyBuilder::shape()
     Handle(TNaming_NamedShape) aName;
     if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
       TopoDS_Shape aShape = aName->Get();
+      if (aShape.IsNull())
+        std::cout<<"Model_BodyBuilder::shape returns empty shape "<<std::endl;
+      else 
+        std::cout<<"Model_BodyBuilder::shape returns shape "<<&(*(aShape.TShape()))<<" with type "
+          <<aShape.ShapeType()<<std::endl;
       if (!aShape.IsNull()) {
         std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
         aRes->setImpl(new TopoDS_Shape(aShape));
@@ -741,3 +765,21 @@ std::shared_ptr<GeomAPI_Shape> Model_BodyBuilder::shape()
   }
   return std::shared_ptr<GeomAPI_Shape>();
 }
+
+bool Model_BodyBuilder::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
+{
+  if (theShape.get()) {
+    TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();  
+    std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
+    if (aData) {
+      TDF_Label& aShapeLab = aData->shapeLab();
+      Handle(TNaming_NamedShape) aName;
+      if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
+        TopoDS_Shape aLatest = TNaming_Tool::CurrentShape(aName);
+        if (aLatest.IsEqual(aShape))
+          return true;
+      }
+    }
+  }
+  return false;
+}