Salome HOME
1692: Correction for the next wrong case: edit Sketch_2, start Line, select 1st point...
[modules/shaper.git] / src / Model / Model_BodyBuilder.cpp
index 2d025aa88d1b1402f2d7d1f28f677072a7a125c0..56d22c8c16ad58faaa8d17cd1f29108238e67b48 100755 (executable)
@@ -235,6 +235,15 @@ void Model_BodyBuilder::storeModified(const std::shared_ptr<GeomAPI_Shape>& theO
           TDataStd_Name::Set(aSubBuilder.NamedShape()->Label(), aSolidName.c_str());
         }
       }
+    } else if(!aBuilder.NamedShape()->IsEmpty()) {
+      Handle(TDataStd_Name) anAttr;
+      if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
+        std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
+        if(!aName.empty()) {
+          std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
+          aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
+        }
+      }
     }
   }
 }
@@ -284,10 +293,9 @@ TNaming_Builder* Model_BodyBuilder::builder(const int theTag)
 
 void Model_BodyBuilder::buildName(const int theTag, const std::string& theName)
 {
-  std::string aName = data()->name() + "/" + theName; 
   std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
-  aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), aName);
-  TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(),aName.c_str());
+  //aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), theName);
+  TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(), theName.c_str());
 }
 void Model_BodyBuilder::generated(
   const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
@@ -316,8 +324,8 @@ void Model_BodyBuilder::generated(const std::shared_ptr<GeomAPI_Shape>& theOldSh
       TDF_Label aChildLabel = aLabel.FindChild(aTag);
       TNaming_Builder aBuilder(aChildLabel);
       aBuilder.Generated(anOldShape, anExp.Current());
-      TCollection_AsciiString aChildName = TCollection_AsciiString((data()->name() + "/" + theName + "_").c_str()) + aTag;
-      aDoc->addNamingName(aChildLabel, aChildName.ToCString());
+      TCollection_AsciiString aChildName = TCollection_AsciiString((theName + "_").c_str()) + aTag;
+      //aDoc->addNamingName(aChildLabel, aChildName.ToCString());
       TDataStd_Name::Set(aChildLabel, aChildName.ToCString());
       aTag++;
     }
@@ -370,13 +378,14 @@ void Model_BodyBuilder::loadAndOrientModifiedShapes (
   GeomAPI_DataMapOfShapeShape& theSubShapes,
   const bool theIsStoreSeparate)
 {
+  int anIndex = 1;
   int aTag = theTag;
+  bool isBuilt = !theName.empty();
   std::string aName = theName;
   std::ostringstream aStream;
-  int anIndex = 1;
+  GeomShapePtr aResultShape = shape();
   TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
   TopTools_MapOfShape aView;
-  bool isBuilt = theName.empty();
   TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
   for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
     const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
@@ -387,14 +396,16 @@ void Model_BodyBuilder::loadAndOrientModifiedShapes (
     theMS->modified(aRShape, aList);
     std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
     for (; anIt != aLast; anIt++) {
-      TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();    
+      TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
       if (theSubShapes.isBound(*anIt)) {
         std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
         aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
       }
-      if (!aRoot.IsSame (aNewShape)) {
+      GeomShapePtr aGeomNewShape(new GeomAPI_Shape());
+      aGeomNewShape->setImpl(new TopoDS_Shape(aNewShape));
+      if(!aRoot.IsSame(aNewShape) && aResultShape->isSubShape(aGeomNewShape)) {
         builder(aTag)->Modify(aRoot,aNewShape);
-        if(!isBuilt) {
+        if(isBuilt) {
           if(theIsStoreSeparate) {
             aStream.str(std::string());
             aStream.clear();
@@ -452,8 +463,8 @@ void Model_BodyBuilder::loadAndOrientGeneratedShapes (
           TDF_Label aChildLabel = aLabel.FindChild(aTag);
           TNaming_Builder aBuilder(aChildLabel);
           aBuilder.Generated(aRoot, anExp.Current());
-          TCollection_AsciiString aChildName = TCollection_AsciiString((data()->name() + "/" + theName + "_").c_str()) + aTag;
-          aDoc->addNamingName(aChildLabel, aChildName.ToCString());
+          TCollection_AsciiString aChildName = TCollection_AsciiString((theName + "_").c_str()) + aTag;
+          //aDoc->addNamingName(aChildLabel, aChildName.ToCString());
           TDataStd_Name::Set(aChildLabel, aChildName.ToCString());
           aTag++;
         }
@@ -708,23 +719,6 @@ void Model_BodyBuilder::loadDisconnectedEdges(
     }
   }
 
-  /*  TopTools_IndexedDataMapOfShapeListOfShape aDM;
-  TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aDM);
-  for(int i=1; i <= aDM.Extent(); i++) {
-  if(aDM.FindFromIndex(i).Extent() > 1) continue;
-  if (BRep_Tool::Degenerated(TopoDS::Edge(aDM.FindKey(i))))
-  continue;
-  builder(theTag)->Generated(aDM.FindKey(i));
-  TCollection_AsciiString aStr(theTag);
-  std::string aName = theName + aStr.ToCString();
-  buildName(theTag, aName);
-  #ifdef DEB_IMPORT
-  aName +=  + ".brep";
-  BRepTools::Write(aDM.FindKey(i), aName.c_str());
-  #endif
-  theTag++;
-  }
-  */
   TopTools_MapOfShape anEdgesToDelete;
   TopExp_Explorer anEx(aShape,TopAbs_EDGE); 
   std::string aName;