Salome HOME
[bos #26505] EDF 24182 - picking elipse from sketch
[modules/shaper.git] / src / Model / Model_ResultBody.cpp
index 68e0c990d23fc93b4dfbfc62a44621f8091dd2ec..65b6875199c997886a06a605ee861c22e17bae7b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include <Model_ResultBody.h>
@@ -31,6 +30,8 @@
 #include <Events_Loop.h>
 #include <GeomAPI_ShapeIterator.h>
 #include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_Face.h>
+#include <GeomAPI_Pnt.h>
 
 #include <TopoDS_Shape.hxx>
 #include <TopExp_Explorer.hxx>
@@ -78,7 +79,8 @@ bool Model_ResultBody::generated(const GeomShapePtr& theNewShape,
 void Model_ResultBody::loadGeneratedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
                                            const GeomShapePtr& theOldShape,
                                            const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
-                                           const std::string& theName)
+                                           const std::string& theName,
+                                           const bool theSaveOldIfNotInTree)
 {
   if (mySubs.size()) { // consists of subs
     for (std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
@@ -86,10 +88,12 @@ void Model_ResultBody::loadGeneratedShapes(const std::shared_ptr<GeomAlgoAPI_Mak
          ++aSubIter)
     {
       const ResultBodyPtr& aSub = *aSubIter;
-      aSub->loadGeneratedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theName);
+      aSub->loadGeneratedShapes(
+        theAlgo, theOldShape, theShapeTypeToExplore, theName, theSaveOldIfNotInTree);
     }
   } else { // do for this directly
-    myBuilder->loadGeneratedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theName);
+    myBuilder->loadGeneratedShapes(
+      theAlgo, theOldShape, theShapeTypeToExplore, theName, theSaveOldIfNotInTree);
   }
 }
 
@@ -111,21 +115,36 @@ void Model_ResultBody::loadModifiedShapes(const std::shared_ptr<GeomAlgoAPI_Make
   }
 }
 
-int Model_ResultBody::numberOfSubs(bool forTree) const
+void Model_ResultBody::loadFirstLevel(GeomShapePtr theShape, const std::string& theName)
+{
+  if (mySubs.size()) { // consists of subs
+    for (std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
+      aSubIter != mySubs.cend();
+      ++aSubIter)
+    {
+      const ResultBodyPtr& aSub = *aSubIter;
+      aSub->loadFirstLevel(theShape, theName);
+    }
+  } else { // do for this directly
+    myBuilder->loadFirstLevel(theShape, theName);
+  }
+}
+
+int Model_ResultBody::numberOfSubs(bool /*forTree*/) const
 {
   return int(mySubs.size());
 }
 
-ResultBodyPtr Model_ResultBody::subResult(const int theIndex, bool forTree) const
+ResultBodyPtr Model_ResultBody::subResult(const int theIndex, bool /*forTree*/) const
 {
   if (theIndex >= int(mySubs.size()))
     return ResultBodyPtr();
   return mySubs.at(theIndex);
 }
 
-bool Model_ResultBody::isSub(ObjectPtr theObject, int& theIndex) const
+bool Model_ResultBody::isSub(ObjectPtr theResult, int& theIndex) const
 {
-  std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theObject);
+  std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theResult);
   if (aFound != mySubsMap.end()) {
     theIndex = aFound->second;
     return true;
@@ -155,10 +174,10 @@ bool Model_ResultBody::isConcealed()
   return myLastConcealed;
 }
 
-void Model_ResultBody::setIsConcealed(const bool theValue)
+void Model_ResultBody::setIsConcealed(const bool theValue, const bool theForced)
 {
   if (ModelAPI_ResultBody::isConcealed() != theValue) {
-    ModelAPI_ResultBody::setIsConcealed(theValue);
+    ModelAPI_ResultBody::setIsConcealed(theValue, theForced);
     updateConcealment();
   }
 }
@@ -216,6 +235,57 @@ void Model_ResultBody::updateConcealment()
   }
 }
 
+void Model_ResultBody::addShapeColor( const std::wstring& theName,std::vector<int>& color) {
+
+  if (myColorsShape.find(theName) == myColorsShape.end())
+    myColorsShape[ theName ] =  color;
+}
+
+std::wstring Model_ResultBody::addShapeName(std::shared_ptr<GeomAPI_Shape> theshape,
+                                            const std::wstring& theName ){
+
+  int indice = 1;
+  std::wstringstream aName;
+  aName << theName;
+  while(myNamesShape.find(aName.str()) != myNamesShape.end() ){
+    aName.str(L"");
+    aName << theName << L"__" << indice;
+    indice++;
+  }
+  myNamesShape[ aName.str() ] = theshape;
+
+  return aName.str();
+}
+
+std::wstring Model_ResultBody::findShapeName(std::shared_ptr<GeomAPI_Shape> theShape){
+
+  TopoDS_Shape  aShape =  theShape->impl<TopoDS_Shape>();
+  for (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> >::iterator it =
+                                                                myNamesShape.begin();
+        it != myNamesShape.end();
+        ++it)
+  {
+    TopoDS_Shape curSelectedShape = (*it).second->impl<TopoDS_Shape>();
+    if ((aShape.IsSame(curSelectedShape)))  {
+      return (*it).first;
+    }
+  }
+  return  L"material not found" ;
+}
+
+void Model_ResultBody::setShapeName(
+                std::map< std::wstring, std::shared_ptr<GeomAPI_Shape>>& theShapeName,
+                std::map< std::wstring, std::vector<int>>& theColorsShape)
+{
+  myNamesShape = theShapeName;
+  myColorsShape = theColorsShape;
+}
+
+void Model_ResultBody::clearShapeNameAndColor(){
+  myNamesShape.clear();
+  myColorsShape.clear();
+}
+
 void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape,
                                   const bool theShapeChanged)
 {
@@ -245,13 +315,33 @@ void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisS
       aShape->setImpl(new TopoDS_Shape(aShapesIter.Value()));
       ResultBodyPtr aSub;
       if (mySubs.size() <= aSubIndex) { // it is needed to create a new sub-result
-        aSub = anObjects->createBody(this->data(), aSubIndex);
+        std::wstring thenameshape = L"";
+        // find shape name read
+        for (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> >::iterator it =
+                                                                            myNamesShape.begin();
+           it != myNamesShape.end();
+           ++it)
+        {
+            TopoDS_Shape curSelectedShape = (*it).second->impl<TopoDS_Shape>();
+            if (!(aShapesIter.Value().IsSame(curSelectedShape))) continue;
+            thenameshape = (*it).first;
+            break;
+        }
+        aSub = anObjects->createBody(this->data(), aSubIndex,thenameshape);
+        //finf color read
+        std::map< std::wstring, std::vector<int>>::iterator itColor =
+                                                          myColorsShape.find(thenameshape);
+        if (itColor != myColorsShape.end()){
+            ModelAPI_Tools::setColor(aSub,(*itColor).second);
+        }
+        aSub->setShapeName(myNamesShape,myColorsShape);
         mySubs.push_back(aSub);
         mySubsMap[aSub] = int(mySubs.size() - 1);
         if (isConcealed()) { // for issue #2579 note7
           aSub->ModelAPI_ResultBody::setIsConcealed(true);
           std::dynamic_pointer_cast<Model_ResultBody>(aSub)->updateConcealment();
         }
+
       } else { // just update shape of this result
         aSub = mySubs[aSubIndex];
       }
@@ -318,6 +408,16 @@ void Model_ResultBody::updateSubs(
   myHistoryCash.Clear();
 }
 
+void  Model_ResultBody::setTextureFile(const std::string & theTextureFile)
+{
+  ModelAPI_Result::setTextureFile(theTextureFile);
+  for( auto sub : mySubs){
+    sub->setTextureFile(theTextureFile);
+  }
+  for(auto map : mySubsMap){
+    map.first->setTextureFile(theTextureFile);
+  }
+}
 
 bool Model_ResultBody::isConnectedTopology()
 {
@@ -391,7 +491,7 @@ void Model_ResultBody::computeOldForSub(const GeomShapePtr& theSub,
     for (TopTools_MapOfShape::Iterator anOldIter(anOldSubs); anOldIter.More(); anOldIter.Next()) {
       TopoDS_Shape anOldShape = anOldIter.Value();
       if (anOldShape.ShapeType() == TopAbs_COMPOUND || anOldShape.ShapeType() == TopAbs_SHELL ||
-          anOldShape.ShapeType() == TopAbs_WIRE)
+          anOldShape.ShapeType() == TopAbs_WIRE || anOldShape.ShapeType() == TopAbs_COMPSOLID)
         continue; // container old-shapes are not supported by the history, may cause crash
       GeomShapePtr anOldSub(new GeomAPI_Shape);
       anOldSub->setImpl<TopoDS_Shape>(new TopoDS_Shape(anOldShape));