]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Dump with geometrical selection
authorazv <azv@opencascade.com>
Tue, 21 Aug 2018 13:34:38 +0000 (16:34 +0300)
committerazv <azv@opencascade.com>
Thu, 30 Aug 2018 08:39:22 +0000 (11:39 +0300)
Correct selection of center of circle / focus of ellipse

src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelectionList.cpp
src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp
src/ModelGeomAlgo/ModelGeomAlgo_Shape.h
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Tools.cpp
src/ModelHighAPI/ModelHighAPI_Tools.h

index 787cc116f1e5157935113c841030387f421f56da..70e3643013db59909594a328c3ef0982a11a4425 100644 (file)
@@ -1097,6 +1097,7 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType,
   }
   ResultPtr aFoundResult;
   GeomShapePtr aFoundSubShape;
+  int aFoundCenterType;
 
   // collect features from PartSet and the current part
   SessionPtr aSession = ModelAPI_Session::get();
@@ -1124,12 +1125,17 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType,
       continue;
 
     // process results of the current feature to find appropriate sub-shape
+    aFoundCenterType = (int)ModelAPI_AttributeSelection::NOT_CENTER;
     if (ModelGeomAlgo_Shape::findSubshapeByPoint(*anIt, thePoint, aType,
-                                                 aFoundResult, aFoundSubShape)) {
+                                                 aFoundResult, aFoundSubShape, aFoundCenterType)) {
       if (aSelectionIndex > 0)
         --aSelectionIndex; // skip this shape, because one of the previous is selected
       else {
-        setValue(aFoundResult, aFoundSubShape);
+        if (aFoundCenterType == (int)ModelAPI_AttributeSelection::NOT_CENTER)
+          setValue(aFoundResult, aFoundSubShape);
+        else
+          setValueCenter(aFoundResult, aFoundSubShape->edge(),
+                         (ModelAPI_AttributeSelection::CenterType)aFoundCenterType);
         return;
       }
     }
index 7575ca2f91bb0237a965e3d38927b3fb5dc1f96b..c7e852221b97f19e24806334046fffb993baa8b5 100644 (file)
@@ -110,8 +110,6 @@ void Model_AttributeSelectionList::append(const GeomPointPtr& thePoint, const st
   aNewAttr->setID(id());
   mySize->Set(aNewTag);
   aNewAttr->selectSubShape(theType, thePoint);
-  if (selectionType().empty())
-    setSelectionType(aNewAttr->value()->shapeTypeStr());
   owner()->data()->sendAttributeUpdated(this);
 }
 
index f5fe49d129033927821fb6a8725fd47e8b18cd3d..05929ba1c882a6bdee15a686a3b613ef6b409b13 100644 (file)
 
 #include "ModelGeomAlgo_Shape.h"
 
+#include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultConstruction.h>
 
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_Ellipse.h>
 #include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_Pnt.h>
 
@@ -83,16 +86,56 @@ namespace ModelGeomAlgo_Shape
     return GeomShapePtr();
   }
 
+  // Find circular/elliptical edge, which center/focus coincide with the given point
+  static GeomShapePtr findEdgeByCenter(const GeomShapePtr& theBaseShape,
+                                       const GeomPointPtr& theCenter,
+                                       const double theTolerance,
+                                       int& theCenterType)
+  {
+    theCenterType = (int)ModelAPI_AttributeSelection::NOT_CENTER;
+    std::list<GeomShapePtr> anEdges = theBaseShape->subShapes(GeomAPI_Shape::EDGE);
+    for (std::list<GeomShapePtr>::const_iterator anIt = anEdges.begin();
+         anIt != anEdges.end(); ++anIt) {
+      GeomEdgePtr anEdge = (*anIt)->edge();
+      if (!anEdge)
+        continue;
+
+      if (anEdge->isCircle()) {
+        GeomCirclePtr aCircle = anEdge->circle();
+        if (aCircle->center()->distance(theCenter) < theTolerance) {
+          theCenterType = (int)ModelAPI_AttributeSelection::CIRCLE_CENTER;
+          return *anIt;
+        }
+      }
+      else if (anEdge->isEllipse()) {
+        GeomEllipsePtr anEllipse = anEdge->ellipse();
+        if (anEllipse->firstFocus()->distance(theCenter) < theTolerance)
+          theCenterType = (int)ModelAPI_AttributeSelection::ELLIPSE_FIRST_FOCUS;
+        else if (anEllipse->secondFocus()->distance(theCenter) < theTolerance)
+          theCenterType = (int)ModelAPI_AttributeSelection::ELLIPSE_SECOND_FOCUS;
+
+        if (theCenterType != (int)ModelAPI_AttributeSelection::NOT_CENTER)
+          return *anIt;
+      }
+    }
+
+    // not found
+    return GeomShapePtr();
+  }
+
   bool findSubshapeByPoint(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                            const std::shared_ptr<GeomAPI_Pnt>& thePoint,
                            const GeomAPI_Shape::ShapeType& theShapeType,
                            std::shared_ptr<ModelAPI_Result>& theResult,
-                           std::shared_ptr<GeomAPI_Shape>& theSubshape)
+                           std::shared_ptr<GeomAPI_Shape>& theSubshape,
+                           int& theCenterType)
   {
     static const double TOLERANCE = 1.e-7;
 
     theResult = ResultPtr();
     theSubshape = GeomShapePtr();
+    theCenterType = (int)ModelAPI_AttributeSelection::NOT_CENTER;
+
     const std::list<ResultPtr>& aResults = theFeature->results();
     for (std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
          aResIt != aResults.end(); ++aResIt) {
@@ -161,6 +204,16 @@ namespace ModelGeomAlgo_Shape
         theSubshape = GeomShapePtr();
         break;
       }
+
+      // another special case: the center of circle or the focus of ellipse is selected;
+      // return the corresponding edge and a status of the center
+      if (theShapeType == GeomAPI_Shape::VERTEX) {
+        theSubshape = findEdgeByCenter(aCurShape, thePoint, TOLERANCE, theCenterType);
+        if (theSubshape) {
+          theResult = *aResIt;
+          break;
+        }
+      }
     }
 
     // one more special case: a vertex selected is a sketch point;
index e2fa4a1753a1e4992cc21cfbebf469752ac7e4e2..fbba1bb25762625dbeca000d14fa7dd517e4d372 100644 (file)
@@ -47,13 +47,15 @@ namespace ModelGeomAlgo_Shape {
   /// \param[in]  theShapeType  type of the selected shape
   /// \param[out] theResult     applicable result
   /// \param[out] theSubshape   sub-shape of the found result
+  /// \param[out] theCenterType type of the point if it is a center of circle or a focus of ellipse
   /// \return \c true if the result and its applicable sub-shape are found
   MODELGEOMALGO_EXPORT bool findSubshapeByPoint(
                               const std::shared_ptr<ModelAPI_Feature>& theFeature,
                               const std::shared_ptr<GeomAPI_Pnt>& thePoint,
                               const GeomAPI_Shape::ShapeType& theShapeType,
                               std::shared_ptr<ModelAPI_Result>& theResult,
-                              std::shared_ptr<GeomAPI_Shape>& theSubshape);
+                              std::shared_ptr<GeomAPI_Shape>& theSubshape,
+                              int& theCenterType);
 }
 
 #endif
index d9169c62901dc4f7adeef301227679982d7c7e34..d5c22c97fec29d192132fca0684b9edfee1f1257 100644 (file)
@@ -1020,7 +1020,9 @@ static int possibleSelectionsByPoint(const GeomPointPtr& thePoint,
 
     ResultPtr aResult;
     GeomShapePtr aSubshape;
-    if (ModelGeomAlgo_Shape::findSubshapeByPoint(*aFIt, thePoint, theType, aResult, aSubshape))
+    int theCenterType;
+    if (ModelGeomAlgo_Shape::findSubshapeByPoint(*aFIt, thePoint, theType,
+                                                 aResult, aSubshape, theCenterType))
       ++aNbPossibleSelections;
   }
   return aNbPossibleSelections;
index f11d8c09902f42f2e2e36c8b0968ff4b96a4ac49..901ed0f6745b7c87f3c225b3cf6123cb3b0206c1 100644 (file)
@@ -195,10 +195,8 @@ void fillAttribute(const std::list<ModelHighAPI_Selection> & theValue,
 
   if(!theValue.empty()) {
     const ModelHighAPI_Selection& aSelection = theValue.front();
-    std::string aSelectionType = aSelection.shapeType();
-    GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aSelectionType);
-    if (aType != GeomAPI_Shape::SHAPE || aSelectionType == "SHAPE")
-      theAttribute->setSelectionType(aSelectionType);
+    GeomAPI_Shape::ShapeType aSelectionType = getShapeType(aSelection);
+    theAttribute->setSelectionType(strByShapeType(aSelectionType));
   }
 
   for (auto it = theValue.begin(); it != theValue.end(); ++it)
@@ -281,6 +279,41 @@ GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr)
   return aShapeType;
 }
 
+std::string strByShapeType(GeomAPI_Shape::ShapeType theShapeType)
+{
+  std::string aShapeTypeStr;
+  switch (theShapeType) {
+  case GeomAPI_Shape::COMPOUND:
+    aShapeTypeStr = "COMPOUND";
+    break;
+  case GeomAPI_Shape::COMPSOLID:
+    aShapeTypeStr = "COMPSOLID";
+    break;
+  case GeomAPI_Shape::SOLID:
+    aShapeTypeStr = "SOLID";
+    break;
+  case GeomAPI_Shape::SHELL:
+    aShapeTypeStr = "SHELL";
+    break;
+  case GeomAPI_Shape::FACE:
+    aShapeTypeStr = "FACE";
+    break;
+  case GeomAPI_Shape::WIRE:
+    aShapeTypeStr = "WIRE";
+    break;
+  case GeomAPI_Shape::EDGE:
+    aShapeTypeStr = "EDGE";
+    break;
+  case GeomAPI_Shape::VERTEX:
+    aShapeTypeStr = "VERTEX";
+    break;
+  default:
+    aShapeTypeStr = "SHAPE";
+    break;
+  }
+  return aShapeTypeStr;
+}
+
 //==================================================================================================
 GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection)
 {
index e3bea33054a4bd87f559ddc20184e10dbd8048fb..aa5286d84b46dbcb5a1393ad9aaa899761a25327 100644 (file)
@@ -156,6 +156,9 @@ void fillAttribute(const ModelHighAPI_Double & theX,
 MODELHIGHAPI_EXPORT
 GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr);
 
+MODELHIGHAPI_EXPORT
+std::string strByShapeType(GeomAPI_Shape::ShapeType theShapeType);
+
 MODELHIGHAPI_EXPORT
 GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection);