]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for the issue #17917 Error during export to GEOM of a PartSet with groups
authormpv <mpv@opencascade.com>
Thu, 31 Oct 2019 15:23:09 +0000 (18:23 +0300)
committervsv <vsv@opencascade.com>
Wed, 6 Nov 2019 08:27:42 +0000 (11:27 +0300)
The problem was related to the Placement of parts feature - it adds additional transformation to all results and groups.

src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h
src/GeomAPI/GeomAPI_Trsf.h
src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.cpp
src/Model/Model_ResultPart.cpp
src/Model/Model_ResultPart.h
src/ModelAPI/ModelAPI_ResultPart.h

index bf677c743730ed28aecade2876c3acdfd2e9c675..4eedccc2604e1078446fe24cbd99dbde9ea37b5a 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_Trsf.h>
 
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
@@ -313,6 +314,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
   std::list<GeomShapePtr> aShapes;
   std::list<ResultPtr> aResults;
   std::list<DocumentPtr> aDocuments; /// documents of Parts selected and used in export
+  std::map<DocumentPtr, GeomTrsfPtr> aDocTrsf; /// translation of the part
 
   AttributeSelectionListPtr aSelection = selectionList(SELECTION_LIST_ID());
   bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
@@ -336,6 +338,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
             return;
           } else {
             aDocuments.push_back(aPartDoc);
+            aDocTrsf[aPartDoc] = aResPart->summaryTrsf();
           }
         }
       }
@@ -414,7 +417,10 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
       try {
         GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
         for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
-          int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupResExplorer.current());
+          GeomShapePtr aGroupShape = aGroupResExplorer.current();
+          if (aDocTrsf.find(*aDoc) != aDocTrsf.end())
+            aGroupShape->move(aDocTrsf[*aDoc]);
+          int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupShape);
           if (aReferenceID == 0) // selected value does not found in the exported shape
             continue;
           std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
index 99b27729f3164da58edf98701a7085655256b136..a0c9061d78a4f1a7cf0eea160ce47db96f211fbc 100644 (file)
@@ -26,6 +26,7 @@
 #include <GeomAPI_Face.h>
 #include <GeomAPI_Shell.h>
 #include <GeomAPI_Solid.h>
+#include <GeomAPI_Trsf.h>
 
 #include <BRep_Tool.hxx>
 #include <BRepAlgoAPI_Section.hxx>
@@ -699,6 +700,12 @@ void GeomAPI_Shape::translate(const std::shared_ptr<GeomAPI_Dir> theDir, const d
   setImpl(new TopoDS_Shape(aResult));
 }
 
+void GeomAPI_Shape::move(const std::shared_ptr<GeomAPI_Trsf> theTransformation)
+{
+  TopoDS_Shape aResult = MY_SHAPE->Moved(theTransformation->impl<gp_Trsf>());
+  setImpl(new TopoDS_Shape(aResult));
+}
+
 bool GeomAPI_Shape::isSelfIntersected(const int theLevelOfCheck) const
 {
   BOPAlgo_CheckerSI aCSI;  // checker of self-interferences
index 2202d022664622308452afc0ec41863a2f40dfab..7c3a2a6cc513ca93e36928b5067f86f6042ac2c8 100644 (file)
@@ -33,6 +33,7 @@ class GeomAPI_Wire;
 class GeomAPI_Face;
 class GeomAPI_Shell;
 class GeomAPI_Solid;
+class GeomAPI_Trsf;
 
 /**\class GeomAPI_Shape
  * \ingroup DataModel
@@ -205,6 +206,10 @@ public:
   GEOMAPI_EXPORT
   void translate(const std::shared_ptr<GeomAPI_Dir> theDir, const double theOffset);
 
+  /// Moves the shape with the given transformation matrix.
+  GEOMAPI_EXPORT
+    void move(const std::shared_ptr<GeomAPI_Trsf> theTransformation);
+
   /// Returns type of shapes in the compound.
   // If shapes are of different type then it will return SHAPE type
   GEOMAPI_EXPORT ShapeType typeOfCompoundShapes() const;
index 80b492f09de163abb3b8fdf9a921981d51ab4090..84539eca682595d640b9a0f9f40370df5e3ac2bb 100644 (file)
@@ -95,5 +95,8 @@ class GeomAPI_Trsf : public GeomAPI_Interface
   GEOMAPI_EXPORT void setSymmetry(const std::shared_ptr<GeomAPI_Ax2> thePlane);
 };
 
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Trsf> GeomTrsfPtr;
+
 #endif
 
index 6df743c509174546d72c566a057cdf6fde150391..bb241e6afeb92d3c2b1dc8a8ba1df77e69059e02 100644 (file)
@@ -22,6 +22,7 @@
 #include <TopoDS_Compound.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
 
 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_CompoundBuilder::compound(
     std::list<std::shared_ptr<GeomAPI_Shape> > theShapes)
@@ -41,6 +42,20 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_CompoundBuilder::compound(
   return aRes;
 }
 
+// Returns true if transformations are equal with the given precision
+static bool isEqual(const gp_Trsf& theT1, const gp_Trsf& theT2, const double thePrecision)
+{
+  for(int aRow = 1; aRow < 4; aRow++) {
+    for(int aCol = 1; aCol < 5; aCol++) {
+      double aDiff = theT1.Value(aRow, aCol) - theT2.Value(aRow, aCol);
+      if (aDiff < 0) aDiff = -aDiff;
+      if (aDiff > thePrecision)
+        return false;
+    }
+  }
+  return true;
+}
+
 int GeomAlgoAPI_CompoundBuilder::id(
       std::shared_ptr<GeomAPI_Shape> theContext, std::shared_ptr<GeomAPI_Shape> theSub)
 {
@@ -51,6 +66,18 @@ int GeomAlgoAPI_CompoundBuilder::id(
     TopTools_IndexedMapOfShape aSubShapesMap;
     TopExp::MapShapes(aMainShape, aSubShapesMap);
     anID = aSubShapesMap.FindIndex(aSubShape);
+    if (anID == 0) { // try to search shape with the same location if TopLoc_Location is different
+      TopExp_Explorer anExp(aMainShape, aSubShape.ShapeType());
+      for(; anExp.More(); anExp.Next()) {
+        if (anExp.Current().TShape() == aSubShape.TShape()) {
+          const TopLoc_Location aLoc1 = anExp.Current().Location();
+          if (isEqual(aLoc1.Transformation(), aSubShape.Location().Transformation(), 1.e-7)) {
+            anID = aSubShapesMap.FindIndex(anExp.Current());
+            break;
+          }
+        }
+      }
+    }
   }
 
   return anID;
index b8fb440d742ac10ce1390ccb52057722e993008a..7bbadba0dc02d707400574092a5cd23bdafb39df 100644 (file)
@@ -415,3 +415,10 @@ void Model_ResultPart::setTrsf(std::shared_ptr<ModelAPI_Result> theThis,
   static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   ModelAPI_EventCreator::get()->sendUpdated(theThis, EVENT_DISP); // flush is in preview-update
 }
+
+std::shared_ptr<GeomAPI_Trsf> Model_ResultPart::summaryTrsf()
+{
+  GeomTrsfPtr aResult(new GeomAPI_Trsf);
+  aResult->setImpl<gp_Trsf>(new gp_Trsf(sumTrsf()));
+  return aResult;
+}
index 4be75fc07dfe526c190a045b383ab313a02f0b62..fff44ed1c04531e540200fe8d6391d9b2777e916 100644 (file)
@@ -85,6 +85,8 @@ class Model_ResultPart : public ModelAPI_ResultPart
   /// Applies the additional transformation of the part
   MODEL_EXPORT virtual void setTrsf(std::shared_ptr<ModelAPI_Result> theThis,
     const std::shared_ptr<GeomAPI_Trsf>& theTransformation);
+  /// Returns the summary transformations of all references to the origin
+  MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Trsf> summaryTrsf();
 
   /// Returns the parameters of color definition in the resources config manager
   MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
index bb49d51881de73ff435cd2a90bd7cd38784dcc7e..4a4756be5c732fe809d452c238f0529e99ca8111 100644 (file)
@@ -82,6 +82,9 @@ class ModelAPI_ResultPart : public ModelAPI_Result
   virtual void setTrsf(std::shared_ptr<ModelAPI_Result> theThis,
     const std::shared_ptr<GeomAPI_Trsf>& theTransformation) = 0;
 
+  /// Returns the summary transformations of all references to the origin
+  virtual std::shared_ptr<GeomAPI_Trsf> summaryTrsf() = 0;
+
   /// Returns the shape by the name in the part
   virtual std::shared_ptr<GeomAPI_Shape> shapeInPart(
     const std::string& theName, const std::string& theType, int& theIndex) = 0;