Salome HOME
Interfaces to be used by Import feature.
[modules/shaper.git] / src / Model / Model_ResultBody.cpp
index 1fad264d8122ff265b11deea8178ad15d0ce9bce..f4a37d35316ac21749b73464e9d5e847ec469295 100644 (file)
@@ -8,8 +8,13 @@
 #include <TNaming_NamedShape.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TDF_ChildIterator.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.hxx>
 #include <GeomAPI_Shape.h>
-
+#include <GeomAlgoAPI_MakeShape.h>
+// DEB
+//#include <TCollection_AsciiString.hxx>
+//#include <TDF_Tool.hxx>
 Model_ResultBody::Model_ResultBody()
 {
   setIsConcealed(false);
@@ -20,12 +25,8 @@ void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
   boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
   if (aData) {
     TDF_Label& aShapeLab = aData->shapeLab();
-    // remove the previous history
-    clean();
-    aShapeLab.ForgetAttribute(TNaming_NamedShape::GetID());
-    for(TDF_ChildIterator anIter(aShapeLab); anIter.More(); anIter.Next()) {
-      anIter.Value().ForgetAllAttributes();
-    }
+    // clean builders
+    clean();   
     // store the new shape as primitive
     TNaming_Builder aBuilder(aShapeLab);
     if (!theShape)
@@ -38,6 +39,50 @@ void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
   }
 }
 
+void Model_ResultBody::storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+                                         const boost::shared_ptr<GeomAPI_Shape>& theToShape)
+{
+  boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+  if (aData) {
+    TDF_Label& aShapeLab = aData->shapeLab();
+    // clean builders
+    clean();   
+    // store the new shape as primitive
+    TNaming_Builder aBuilder(aShapeLab);
+    if (!theFromShape || !theToShape)
+      return;  // bad shape
+    TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
+    if (aShapeBasis.IsNull())
+      return;  // null shape inside
+       TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
+    if (aShapeNew.IsNull())
+      return;  // null shape inside
+    aBuilder.Generated(aShapeBasis, aShapeNew);
+  }
+}
+
+void Model_ResultBody::storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+                                         const boost::shared_ptr<GeomAPI_Shape>& theNewShape)
+{
+  boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+  if (aData) {
+    TDF_Label& aShapeLab = aData->shapeLab();
+    // clean builders
+    clean();   
+    // store the new shape as primitive
+    TNaming_Builder aBuilder(aShapeLab);
+    if (!theOldShape || !theNewShape)
+      return;  // bad shape
+    TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
+    if (aShapeOld.IsNull())
+      return;  // null shape inside
+       TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
+    if (aShapeNew.IsNull())
+      return;  // null shape inside
+    aBuilder.Generated(aShapeOld, aShapeNew);
+  }
+}
+
 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
 {
   boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
@@ -56,16 +101,12 @@ boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
   return boost::shared_ptr<GeomAPI_Shape>();
 }
 
-boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
-{
-  return myOwner;
-}
-
 void Model_ResultBody::clean()
 {
   std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
   for(; aBuilder != myBuilders.end(); aBuilder++)
     delete *aBuilder;
+  myBuilders.clear();
 }
 
 Model_ResultBody::~Model_ResultBody()
@@ -75,12 +116,15 @@ Model_ResultBody::~Model_ResultBody()
 
 TNaming_Builder* Model_ResultBody::builder(const int theTag)
 {
-  if (myBuilders.size() < (unsigned int)theTag) {
+  if (myBuilders.size() <= (unsigned int)theTag) {
     myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
   }
   if (!myBuilders[theTag]) {
     boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
     myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
+       //TCollection_AsciiString entry;//
+       //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
+       //cout << "Label = " <<entry.ToCString() <<endl;
   }
   return myBuilders[theTag];
 }
@@ -115,3 +159,97 @@ void Model_ResultBody::deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldSha
   TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
   builder(theTag)->Delete(aShape);
 }
+
+void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag)
+{
+  TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
+  TopTools_MapOfShape aView;
+  TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
+  for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
+    const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
+    if (!aView.Add(aRoot)) continue;
+       boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
+       aRShape->setImpl((new TopoDS_Shape(aRoot)));
+    if (theMS->isDeleted (aRShape)) {
+               builder(theTag)->Delete(aRoot);
+    }
+  }
+}
+
+void Model_ResultBody::loadAndOrientModifiedShapes (
+                                                  GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag,
+                                               GeomAPI_DataMapOfShapeShape& theSubShapes)
+{
+  TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
+  TopTools_MapOfShape aView;
+  TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
+  for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+    const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+    if (!aView.Add(aRoot)) continue;
+       ListOfShape aList;
+       boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
+       aRShape->setImpl((new TopoDS_Shape(aRoot)));
+       theMS->modified(aRShape, aList);
+       std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
+    for (; anIt != aLast; anIt++) {
+      TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();    
+         if (theSubShapes.isBound(*anIt)) {
+               boost::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
+               aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
+      }
+      if (!aRoot.IsSame (aNewShape)) 
+                 builder(theTag)->Modify(aRoot,aNewShape);
+    }
+  }
+}
+
+void Model_ResultBody::loadAndOrientGeneratedShapes (
+                                                  GeomAlgoAPI_MakeShape* theMS,
+                                               boost::shared_ptr<GeomAPI_Shape>  theShapeIn,
+                                               const int  theKindOfShape,
+                                               const int  theTag,
+                                               GeomAPI_DataMapOfShapeShape& theSubShapes)
+{
+  TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
+  TopTools_MapOfShape aView;
+  TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
+  for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+    const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+    if (!aView.Add(aRoot)) continue;
+       ListOfShape aList;
+       boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
+       aRShape->setImpl((new TopoDS_Shape(aRoot)));
+       theMS->generated(aRShape, aList);
+       std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
+    for (; anIt != aLast; anIt++) {
+      TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();    
+         if (theSubShapes.isBound(*anIt)) {
+               boost::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
+               aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
+      }
+      if (!aRoot.IsSame (aNewShape)) 
+                 builder(theTag)->Generated(aRoot,aNewShape);
+    }
+  }
+}
+
+void Model_ResultBody::loadFirstLevel(boost::shared_ptr<GeomAPI_Shape> theShapeIn,int&  theTag)
+{
+
+}
+
+void Model_ResultBody::loadDisconnectedEdges(boost::shared_ptr<GeomAPI_Shape> theShapeIn,int&  theTag)
+{
+
+}
+
+void Model_ResultBody::loadDisconnectedVertexes(boost::shared_ptr<GeomAPI_Shape> theShapeIn,int&  theTag)
+{
+
+}
\ No newline at end of file