]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Dump with geometrical selection
authorazv <azv@opencascade.com>
Wed, 15 Aug 2018 12:07:25 +0000 (15:07 +0300)
committerazv <azv@opencascade.com>
Thu, 30 Aug 2018 08:39:13 +0000 (11:39 +0300)
Provide dumping itself and selection of sub-shapes by the given point.

25 files changed:
src/ExchangePlugin/ExchangePlugin_Dump.cpp
src/ExchangePlugin/ExchangePlugin_Dump.h
src/ExchangePlugin/plugin-Exchange.xml
src/GeomAPI/GeomAPI_Edge.cpp
src/GeomAPI/GeomAPI_Edge.h
src/GeomAPI/GeomAPI_Face.cpp
src/GeomAPI/GeomAPI_Face.h
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h
src/GeomAPI/GeomAPI_Shell.cpp
src/GeomAPI/GeomAPI_Shell.h
src/GeomAPI/GeomAPI_Solid.cpp
src/GeomAPI/GeomAPI_Solid.h
src/GeomAPI/GeomAPI_Wire.cpp
src/GeomAPI/GeomAPI_Wire.h
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_AttributeSelectionList.h
src/ModelAPI/ModelAPI_AttributeSelection.h
src/ModelAPI/ModelAPI_AttributeSelectionList.h
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModelHighAPI/ModelHighAPI_Selection.h

index 67ee6aab0e03ace595d04be17d78092cfc85bdfe..dc74c54c4d184b11cf1bf8e797dfe5c6f4419890 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <ExchangePlugin_Dump.h>
 
+#include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Session.h>
@@ -40,8 +41,11 @@ ExchangePlugin_Dump::~ExchangePlugin_Dump()
 
 void ExchangePlugin_Dump::initAttributes()
 {
-  data()->addAttribute(ExchangePlugin_Dump::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(ExchangePlugin_Dump::FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
+
+  data()->addAttribute(GEOMETRIC_DUMP_ID(), ModelAPI_AttributeBoolean::typeId());
+  boolean(GEOMETRIC_DUMP_ID())->setValue(false);
 }
 
 void ExchangePlugin_Dump::execute()
@@ -62,6 +66,8 @@ void ExchangePlugin_Dump::dump(const std::string& theFileName)
 
   ModelHighAPI_Dumper* aDumper = ModelHighAPI_Dumper::getInstance();
   aDumper->clear();
+  aDumper->setSelectionByGeometry(boolean(GEOMETRIC_DUMP_ID())->value());
+
   DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
 
   int aFeaturesNb = aDoc->size(ModelAPI_Feature::group());
index a10d98610155a6f38ab478cf83afd18e31bcd3d0..591838dfe089d7fb36fdc6f951d9fde1382b9a58 100644 (file)
@@ -51,6 +51,12 @@ public:
     static const std::string MY_FILE_FORMAT_ID("file_format");
     return MY_FILE_FORMAT_ID;
   }
+  /// attribute name of flag dumping by geometric selection (not by naming)
+  inline static const std::string& GEOMETRIC_DUMP_ID()
+  {
+    static const std::string MY_GEOM_DUMP_ID("geometric_dump");
+    return MY_GEOM_DUMP_ID;
+  }
 
   /// Default constructor
   EXCHANGEPLUGIN_EXPORT ExchangePlugin_Dump();
index 30e7f7d45f6075c777f719d02cc7f61f84ca4e28..5bd7fb979d79642ee314d182b0afcdf27ef3ceb4 100755 (executable)
@@ -41,6 +41,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
           <validator id="ExchangePlugin_ExportFormat"
                      parameters="py:Python" />
         </export_file_selector>
+        <boolvalue id="geometric_dump" label="By geometric selection"/>
       </feature>
     </group>
   </workbench>
index b5d0de4b673c35ad38c0d532e3b8cbf8df7d87b3..cd3c08466eb0e937d30813ed62f194e239e1f5f8 100644 (file)
@@ -35,6 +35,7 @@
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 #include <ElCLib.hxx>
+#include <GCPnts_UniformAbscissa.hxx>
 #include <Geom_Curve.hxx>
 #include <Geom_Line.hxx>
 #include <Geom_Circle.hxx>
@@ -361,3 +362,25 @@ void GeomAPI_Edge::setLastPointTolerance(const double theTolerance)
   TopExp::Vertices(anEdge, aVFirst, aVLast);
   BRep_Builder().UpdateVertex(aVLast, theTolerance);
 }
+
+GeomPointPtr GeomAPI_Edge::middlePoint() const
+{
+  GeomPointPtr aMiddlePoint;
+
+  const TopoDS_Edge& anEdge = impl<TopoDS_Edge>();
+  if (anEdge.IsNull())
+    return aMiddlePoint;
+  double aFirst, aLast;
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+  if (aCurve.IsNull())
+    return aMiddlePoint;
+
+  static const int NB_POINTS = 3;
+  GeomAdaptor_Curve aCurveAdaptor(aCurve, aFirst, aLast);
+  GCPnts_UniformAbscissa anAlgo(aCurveAdaptor, NB_POINTS);
+  if (anAlgo.IsDone()) {
+    gp_Pnt aPnt = aCurveAdaptor.Value(anAlgo.Parameter(2));
+    aMiddlePoint = GeomPointPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+  }
+  return aMiddlePoint;
+}
index ac5973d9bca882b6e7e8c63ca22981321b907460..a375b100ee5586f887442cad012059c43c5a3c93 100644 (file)
@@ -117,6 +117,10 @@ public:
 
   GEOMAPI_EXPORT
   void setLastPointTolerance(const double theTolerance);
+
+  /// Return middle point on the edge
+  GEOMAPI_EXPORT
+  virtual std::shared_ptr<GeomAPI_Pnt> middlePoint() const;
 };
 
 //! Pointer on attribute object
index 270118fcdcfce18498c30e12406839cbab8aaf47..ff5dbba27f32b2260d9445ac14b01070c39f5efc 100644 (file)
@@ -31,6 +31,7 @@
 #include <BOPTools_AlgoTools.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepAdaptor_Surface.hxx>
+#include <BRepGProp_Face.hxx>
 #include <BRepTools.hxx>
 #include <Geom_Surface.hxx>
 #include <Geom_SphericalSurface.hxx>
@@ -231,3 +232,24 @@ std::shared_ptr<GeomAPI_Torus> GeomAPI_Face::getTorus() const
   }
   return aTorus;
 }
+
+GeomPointPtr GeomAPI_Face::middlePoint() const
+{
+  GeomPointPtr anInnerPoint;
+
+  const TopoDS_Face& aFace = impl<TopoDS_Face>();
+  if (aFace.IsNull())
+    return anInnerPoint;
+
+  BRepGProp_Face aProp(aFace);
+  double aUMin, aUMax, aVMin, aVMax;
+  aProp.Bounds(aUMin, aUMax, aVMin, aVMax);
+
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+  if (aSurf.IsNull())
+    return anInnerPoint;
+
+  gp_Pnt aPnt = aSurf->Value((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5);
+  anInnerPoint = GeomPointPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+  return anInnerPoint;
+}
index 3e654e91622fd183f0f36268b0e58dd5ff5f0de5..c50e980d03e55e67be44bdd12626504e53b6d3e2 100644 (file)
@@ -67,6 +67,9 @@ public:
 
   /// Returns torus if the face is based on the toroidal surface
   GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Torus> getTorus() const;
+
+  /// Return inner point in the face
+  GEOMAPI_EXPORT virtual std::shared_ptr<GeomAPI_Pnt> middlePoint() const;
 };
 
 //! Pointer on attribute object
index 4cde5e7361172393638f9787bf1a8a9012eda14e..c686bbf77ad6c1f70b68ddaf88317dac9dbb2ab8 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "GeomAPI_Shape.h"
 
+#include <GeomAPI_Pnt.h>
 #include <GeomAPI_Vertex.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Wire.h>
@@ -571,6 +572,41 @@ bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmi
   return true;
 }
 
+GeomPointPtr GeomAPI_Shape::middlePoint() const
+{
+  GeomPointPtr aMiddlePoint;
+
+  switch (shapeType()) {
+  case VERTEX:
+    aMiddlePoint = vertex()->point();
+    break;
+  case EDGE:
+    aMiddlePoint = edge()->middlePoint();
+    break;
+  case WIRE:
+    aMiddlePoint = wire()->middlePoint();
+    break;
+  case FACE:
+    aMiddlePoint = face()->middlePoint();
+    break;
+  case SHELL:
+    aMiddlePoint = shell()->middlePoint();
+    break;
+  case SOLID:
+    aMiddlePoint = solid()->middlePoint();
+    break;
+  default: {
+      // get middle point as center of the bounding box
+      double aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
+      computeSize(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
+      aMiddlePoint = GeomPointPtr(new GeomAPI_Pnt(
+          (aMinX + aMaxX) * 0.5, (aMinY + aMaxY) * 0.5, (aMinZ + aMaxZ) * 0.5));
+    }
+  }
+
+  return aMiddlePoint;
+}
+
 std::string GeomAPI_Shape::getShapeStream() const
 {
   std::ostringstream aStream;
index 4091f5911daf398359f7699c1fc7c567ea133e8c..a70574aa4e44fb3fc54429c0e28fe4dbbec835f5 100644 (file)
@@ -27,6 +27,7 @@
 #include <memory>
 #include <list>
 
+class GeomAPI_Pnt;
 class GeomAPI_Vertex;
 class GeomAPI_Edge;
 class GeomAPI_Wire;
@@ -181,6 +182,10 @@ public:
   bool computeSize(double& theXmin, double& theYmin, double& theZmin,
                    double& theXmax, double& theYmax, double& theZmax) const;
 
+  /// Return middle point on the shape
+  GEOMAPI_EXPORT
+  virtual std::shared_ptr<GeomAPI_Pnt> middlePoint() const;
+
   /// Returns the shape as BRep stream
   GEOMAPI_EXPORT
   std::string getShapeStream() const;
index 5b7713a96a4e7f5bae799e120cc4d4fd5229cd51..baab4a1a9fd9cfb12db13622f5dbc75803655aaa 100644 (file)
@@ -32,6 +32,8 @@
 #include "GeomAPI_XYZ.h"
 
 #include <BRep_Builder.hxx>
+#include <BRepGProp.hxx>
+#include <GProp_GProps.hxx>
 #include <Precision.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
@@ -365,3 +367,20 @@ std::shared_ptr<GeomAPI_Box> GeomAPI_Shell::getParallelepiped() const
                                   aPlanes[anIndex].myHeight));
   return aBox;
 }
+
+//=================================================================================================
+GeomPointPtr GeomAPI_Shell::middlePoint() const
+{
+  GeomPointPtr anInnerPoint;
+
+  const TopoDS_Shell& aShell = impl<TopoDS_Shell>();
+  if (aShell.IsNull())
+    return anInnerPoint;
+
+  GProp_GProps aProps;
+  BRepGProp::SurfaceProperties(aShell, aProps, 1.e-4);
+
+  gp_Pnt aPnt = aProps.CentreOfMass();
+  anInnerPoint = GeomPointPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+  return anInnerPoint;
+}
index 91b6a313bac5677850270e87b8e93bf2b1d7a5e0..d92f6900033760e8ff5db08aab5a0e44226ac60d 100644 (file)
@@ -59,6 +59,9 @@ public:
 
   /// Returns box if the shell consists of 6 rectangular faces composing a box
   GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Box> getParallelepiped() const;
+
+  /// Return middle point on the shell
+  GEOMAPI_EXPORT virtual std::shared_ptr<GeomAPI_Pnt> middlePoint() const;
 };
 
 typedef std::shared_ptr<GeomAPI_Shell> GeomShellPtr;
index 0f377f2c24f9fbd83f116c1528abd70f5d2d608d..f128d3d65cf894dbe57aa0097fd7a958062b7891 100644 (file)
@@ -33,6 +33,8 @@
 #include "GeomAPI_XYZ.h"
 
 #include <BRep_Builder.hxx>
+#include <BRepGProp.hxx>
+#include <GProp_GProps.hxx>
 #include <Precision.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS_Wire.hxx>
@@ -298,3 +300,20 @@ std::shared_ptr<GeomAPI_Box> GeomAPI_Solid::getParallelepiped() const
     aBox = aShells.front()->shell()->getParallelepiped();
   return aBox;
 }
+
+//==================================================================================================
+GeomPointPtr GeomAPI_Solid::middlePoint() const
+{
+  GeomPointPtr anInnerPoint;
+
+  const TopoDS_Solid& aSolid = impl<TopoDS_Solid>();
+  if (aSolid.IsNull())
+    return anInnerPoint;
+
+  GProp_GProps aProps;
+  BRepGProp::SurfaceProperties(aSolid, aProps, 1.e-4);
+
+  gp_Pnt aPnt = aProps.CentreOfMass();
+  anInnerPoint = GeomPointPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+  return anInnerPoint;
+}
index a81828c8efdb3dc05893b55f178c77400d782c7b..12519db242eddba875fdb454aa904f9ccc91a685 100644 (file)
@@ -59,6 +59,9 @@ public:
 
   /// Returns box if the solid is bounded by 6 rectangular faces composing a box
   GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Box> getParallelepiped() const;
+
+  /// Return inner point in the solid
+  GEOMAPI_EXPORT virtual std::shared_ptr<GeomAPI_Pnt> middlePoint() const;
 };
 
 typedef std::shared_ptr<GeomAPI_Solid> GeomSolidPtr;
index 32df6d6bbc55e39207ade979d5e3e2810ec063e2..bcbaf3e946be37bff95143533d3635145f0dd2c8 100644 (file)
@@ -113,3 +113,20 @@ bool GeomAPI_Wire::isRectangle(std::list<GeomPointPtr>& thePoints) const
   }
   return true;
 }
+
+//==================================================================================================
+GeomPointPtr GeomAPI_Wire::middlePoint() const
+{
+  // find middle edge in the wire
+  std::list<GeomShapePtr> aSubs = subShapes(EDGE);
+  size_t aNbSubs = aSubs.size();
+  if (aNbSubs == 0)
+    return GeomPointPtr();
+
+  aNbSubs /= 2;
+  for (; aNbSubs > 0; --aNbSubs)
+    aSubs.pop_front();
+
+  // compute middle point on the middle edge
+  return aSubs.front()->middlePoint();
+}
index c79283d8e71628df4aa2ecbd597b3f24f31cec5f..4b244296dee3a2c79c62024c070f1203f3175796 100644 (file)
@@ -47,6 +47,9 @@ public:
   /// Returns \c true if the wire is a rectangle
   /// \param[out] thePoints  corners of the rectangle
   GEOMAPI_EXPORT bool isRectangle(std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints) const;
+
+  /// Return middle point on the wire
+  GEOMAPI_EXPORT virtual std::shared_ptr<GeomAPI_Pnt> middlePoint() const;
 };
 
 typedef std::shared_ptr<GeomAPI_Wire> GeomWirePtr;
index d93f02ed321692bde6ef69be5a1ff09ac47de9a8..72fff493f6b380c846efc0562dd475b5dd9d4a8e 100644 (file)
@@ -38,6 +38,7 @@
 #include <ModelAPI_Validator.h>
 #include <Events_InfoMessage.h>
 #include <GeomAPI_Edge.h>
+#include <GeomAPI_Pnt.h>
 #include <GeomAPI_Vertex.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
@@ -1065,6 +1066,89 @@ void Model_AttributeSelection::selectSubShape(
   reset();
 }
 
+
+// Check the point is within shape's bounding box
+static bool isPointWithinBB(const GeomPointPtr& thePoint, const GeomShapePtr& theShape)
+{
+  double aXMin, aXMax, aYMin, aYMax, aZMin, aZMax;
+  theShape->computeSize(aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
+  return thePoint->x() >= aXMin - Precision::Confusion() &&
+         thePoint->x() <= aXMax + Precision::Confusion() &&
+         thePoint->y() >= aYMin - Precision::Confusion() &&
+         thePoint->y() <= aYMax + Precision::Confusion() &&
+         thePoint->z() >= aZMin - Precision::Confusion() &&
+         thePoint->z() <= aZMax + Precision::Confusion();
+}
+
+// Select sub-shape of the given type, which contains the given point
+static GeomShapePtr findSubShape(const GeomShapePtr& theShape,
+                                   const GeomAPI_Shape::ShapeType& theType,
+                                   const GeomPointPtr& thePoint)
+{
+  std::list<GeomShapePtr> aSubs = theShape->subShapes(theType);
+  for (std::list<GeomShapePtr>::const_iterator aSubIt = aSubs.begin();
+    aSubIt != aSubs.end(); ++aSubIt) {
+    if ((*aSubIt)->middlePoint()->distance(thePoint) < Precision::Confusion())
+      return *aSubIt;
+  }
+
+  // not found
+  return GeomShapePtr();
+}
+
+void Model_AttributeSelection::selectSubShape(const std::string& theType,
+                                              const GeomPointPtr& thePoint)
+{
+  if (theType.empty() || !thePoint)
+    return;
+
+  GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(theType);
+  GeomShapePtr aFoundSubShape;
+
+  std::list<FeaturePtr> aFeatures = owner()->document()->allFeatures();
+  // Process results of all features from the last to the first
+  // to find appropriate sub-shape
+  for (std::list<FeaturePtr>::const_reverse_iterator anIt = aFeatures.rbegin();
+       anIt != aFeatures.rend(); ++anIt) {
+    const std::list<ResultPtr>& aResults = (*anIt)->results();
+    for (std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
+         aResIt != aResults.end(); ++aResIt) {
+      GeomShapePtr aCurShape = (*aResIt)->shape();
+      // first of all, check the point is within bounding box of the result
+      if (!isPointWithinBB(thePoint, aCurShape))
+        continue;
+      // now, process all sub-shapes of the given type and check their inner points
+      aFoundSubShape = findSubShape(aCurShape, aType, thePoint);
+      if (aFoundSubShape) {
+        setValue(*aResIt, aFoundSubShape);
+        return;
+      }
+
+      // special case for ResultConstruction if the FACE is selected
+      ResultConstructionPtr aResConstr =
+          std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aResIt);
+      if (aResConstr && aType >= GeomAPI_Shape::FACE) {
+        int aNbFaces = aResConstr->facesNum();
+        for (int aFaceInd = 0; aFaceInd < aNbFaces; ++aFaceInd) {
+          GeomFacePtr aCurFace = aResConstr->face(aFaceInd);
+          // check the point is within bounding box of the face
+          if (!isPointWithinBB(thePoint, aCurFace))
+            continue;
+          aFoundSubShape = findSubShape(aCurFace, aType, thePoint);
+          if (aFoundSubShape) {
+            setValue(*aResIt, aFoundSubShape);
+            return;
+          }
+        }
+      }
+    }
+  }
+
+  TDF_Label aSelLab = selectionLabel();
+  setInvalidIfFalse(aSelLab, false);
+  reset();
+}
+
 int Model_AttributeSelection::Id()
 {
   int anID = 0;
index 9267748a7d33a4e182726643cbb3d2404f94f320..ac31cb3357c0628bcfa0d7a2ddb3f0485d200fb7 100644 (file)
@@ -108,6 +108,10 @@ public:
   MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
                                            const std::string& theSubShapeName);
 
+  /// Selects sub-shape by its inner point
+  MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
+                                           const std::shared_ptr<GeomAPI_Pnt>& thePoint);
+
   /// Returns true if attribute was  initialized by some value
   MODEL_EXPORT virtual bool isInitialized();
 
index bc1c7f1172376ea7164b04ee6d2664a132d494ac..c7e852221b97f19e24806334046fffb993baa8b5 100644 (file)
@@ -24,6 +24,7 @@
 #include "Model_Events.h"
 #include "Model_Data.h"
 
+#include <GeomAPI_Pnt.h>
 #include <GeomAPI_Shape.h>
 
 #include <TDF_AttributeIterator.hxx>
@@ -78,7 +79,7 @@ void Model_AttributeSelectionList::append(
 }
 
 void Model_AttributeSelectionList::append(
-  const std::string theNamingName, const std::string& theType)
+  const std::string& theNamingName, const std::string& theType)
 {
   int aNewTag = mySize->Get() + 1;
   TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
@@ -95,6 +96,23 @@ void Model_AttributeSelectionList::append(
   owner()->data()->sendAttributeUpdated(this);
 }
 
+void Model_AttributeSelectionList::append(const GeomPointPtr& thePoint, const std::string& theType)
+{
+  int aNewTag = mySize->Get() + 1;
+  TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
+
+  std::shared_ptr<Model_AttributeSelection> aNewAttr =
+    std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
+  if (owner()) {
+    aNewAttr->setObject(owner());
+    aNewAttr->setParent(this);
+  }
+  aNewAttr->setID(id());
+  mySize->Set(aNewTag);
+  aNewAttr->selectSubShape(theType, thePoint);
+  owner()->data()->sendAttributeUpdated(this);
+}
+
 void Model_AttributeSelectionList::removeTemporaryValues()
 {
   if (myTmpAttr.get()) {
index 289534c62e340b5a03004332e73c51e7b7846d04..d582447c3ea7d9bd2ebd09f6e6f525c459bf7006 100644 (file)
@@ -57,7 +57,11 @@ public:
 
   /// Adds the new reference to the end of the list by the naming name of the selected shape
   /// The type of shape is taken from the current selection type if the given is empty
-  MODEL_EXPORT virtual void append(const std::string theNamingName, const std::string& theType="");
+  MODEL_EXPORT virtual void append(const std::string& theNamingName, const std::string& theType="");
+
+  /// Adds the new reference to the end of the list by inner point on the selected shape
+  MODEL_EXPORT virtual void append(const std::shared_ptr<GeomAPI_Pnt>& thePoint,
+                                   const std::string& theType);
 
   /// Reset temporary stored values
   virtual void removeTemporaryValues();
index 5343ecfbd6052b338771bccb2f2a443ae2f8e5e4..9829bde7981cc73f8efa15b205a43dd53197a3e3 100644 (file)
@@ -25,6 +25,7 @@
 #include <ModelAPI_Result.h>
 
 class GeomAPI_Edge;
+class GeomAPI_Pnt;
 
 /**\class ModelAPI_AttributeSelection
  * \ingroup DataModel
@@ -103,6 +104,10 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
   /// Selects sub-shape by the textual Name
   virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName) = 0;
 
+  /// Selects sub-shape by its inner point
+  virtual void selectSubShape(const std::string& theType,
+                              const std::shared_ptr<GeomAPI_Pnt>& thePoint) = 0;
+
   /// Returns true if recompute of selection become impossible
   virtual bool isInvalid() = 0;
 
index 454d9e34cf41874c6c3f14347f4fa4b4c5f955bb..69e45b2e7220d15a14b7197b06be0806ca5607ec 100644 (file)
@@ -24,6 +24,7 @@
 #include "ModelAPI_AttributeSelection.h"
 #include <ModelAPI_Result.h>
 
+class GeomAPI_Pnt;
 class GeomAPI_Shape;
 
 /**\class ModelAPI_AttributeSelectionList
@@ -46,7 +47,11 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
 
   /// Adds the new reference to the end of the list by the naming name of the selected shape
   /// The type of shape is taken from the current selection type if the given is empty
-  virtual void append(const std::string theNamingName, const std::string& theType = "") = 0;
+  virtual void append(const std::string& theNamingName, const std::string& theType = "") = 0;
+
+  /// Adds the new reference to the end of the list by inner point on the selected shape
+  virtual void append(const std::shared_ptr<GeomAPI_Pnt>& thePoint,
+                      const std::string& theType) = 0;
 
   /// Reset temporary stored values
   virtual void removeTemporaryValues() = 0;
index 8bc41417be4434a04555ce2e0e807a020e4416ce..496979d17a570efb8a9f60136597a63e4a0df180 100644 (file)
@@ -64,6 +64,7 @@ static int gCompositeStackDepth = 0;
 ModelHighAPI_Dumper* ModelHighAPI_Dumper::mySelf = 0;
 
 ModelHighAPI_Dumper::ModelHighAPI_Dumper()
+  : myGeometricalSelection(false)
 {
   clear();
 }
@@ -954,8 +955,12 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
     return *this;
   }
 
-  myDumpBuffer << "\"" << aShape->shapeTypeStr() << "\", \"" <<
-    theAttrSelect->namingName() << "\")";
+  myDumpBuffer << "\"" << aShape->shapeTypeStr() << "\", ";
+  if (myGeometricalSelection)
+    *this << aShape->middlePoint();
+  else
+    myDumpBuffer << "\"" << theAttrSelect->namingName() << "\"";
+  myDumpBuffer << ")";
   return *this;
 }
 
@@ -993,8 +998,7 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
       } else {
         isAdded = true;
       }
-      myDumpBuffer << "model.selection(\"" <<
-        aShape->shapeTypeStr() << "\", \"" << anAttribute->namingName() << "\")";
+      *this << anAttribute;
     }
 
     myDumpBuffer << "]";
index c1539528664403583f12984fc77eaf7a71a22be6..8cb9c5457eb0998048ed12f93aa17d42eb70dbc5 100644 (file)
@@ -86,6 +86,11 @@ public:
   /// Destructor
   virtual ~ModelHighAPI_Dumper() {}
 
+  /// Set/unset flag to dump selection attributes by geometrical properties:
+  /// inner point in the selected shape
+  void setSelectionByGeometry(bool theDumpByGeom = true)
+  { myGeometricalSelection = theDumpByGeom; }
+
   /// Dump given document into the file
   /// \return \c true, if succeed
   MODELHIGHAPI_EXPORT
@@ -355,6 +360,8 @@ private:
   std::list<EntityPtr> myPostponed; ///< list of postponed entities (sketch constraints or folders)
   bool myDumpPostponedInProgress; ///< processing postponed is in progress
 
+  bool myGeometricalSelection; ///< dump selection not by naming, but by coordinates of inner point
+
 protected:
   /// list of entities, used by other features but not dumped yet
   std::set<EntityPtr> myNotDumpedEntities;
index c87b99fe9a078dd0e9c81a09ef52869521e35872..7738eb38f0ac3b207cd173063cf264809de51419 100644 (file)
@@ -27,6 +27,8 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultBody.h>
 
+
+#include <GeomAPI_Pnt.h>
 //--------------------------------------------------------------------------------------
 
 //--------------------------------------------------------------------------------------
@@ -49,6 +51,13 @@ ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
 {
 }
 
+ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
+                                               const GeomPointPtr& theSubShapeInnerPoint)
+: myVariantType(VT_TypeInnerPointPair)
+, myTypeInnerPointPair(theType, theSubShapeInnerPoint)
+{
+}
+
 ModelHighAPI_Selection::~ModelHighAPI_Selection()
 {
 }
@@ -64,13 +73,17 @@ void ModelHighAPI_Selection::fillAttribute(
       return;
     case VT_TypeSubShapeNamePair:
       theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second);
-      if(theAttribute->isInvalid()) {
-        FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
-        aFeature->setError(
-          std::string("Error: attribute \"") + theAttribute->id() + std::string("\" is invalid."));
-      }
+      break;
+    case VT_TypeInnerPointPair:
+      theAttribute->selectSubShape(myTypeInnerPointPair.first, myTypeInnerPointPair.second);
       return;
   }
+
+  if (theAttribute->isInvalid()) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+    aFeature->setError(
+      std::string("Error: attribute \"") + theAttribute->id() + std::string("\" is invalid."));
+  }
 }
 
 //--------------------------------------------------------------------------------------
@@ -86,6 +99,10 @@ void ModelHighAPI_Selection::appendToList(
       // Note: the reverse order (first - type, second - sub-shape name)
       theAttribute->append(myTypeSubShapeNamePair.second, myTypeSubShapeNamePair.first);
       return;
+    case VT_TypeInnerPointPair:
+      // Note: the reverse order (first - type, second - selected point)
+      theAttribute->append(myTypeInnerPointPair.second, myTypeInnerPointPair.first);
+      return;
   }
 }
 
@@ -107,6 +124,12 @@ TypeSubShapeNamePair ModelHighAPI_Selection::typeSubShapeNamePair() const
   return myTypeSubShapeNamePair;
 }
 
+//==================================================================================================
+TypeInnerPointPair ModelHighAPI_Selection::typeInnerPointPair() const
+{
+  return myTypeInnerPointPair;
+}
+
 //==================================================================================================
 std::string ModelHighAPI_Selection::shapeType() const
 {
@@ -115,6 +138,7 @@ std::string ModelHighAPI_Selection::shapeType() const
     return myResultSubShapePair.second.get() ? myResultSubShapePair.second->shapeTypeStr() :
                                                myResultSubShapePair.first->shape()->shapeTypeStr();
   case VT_TypeSubShapeNamePair: return myTypeSubShapeNamePair.first;
+  case VT_TypeInnerPointPair: return myTypeInnerPointPair.first;
   }
 
   return "SHAPE";
index 21da1cdfe188790a4c1f30c6876c21c378f9472d..c63d1565007f217baf6aaa5ea91c36f2ee28c7df 100644 (file)
@@ -28,6 +28,7 @@
 #include <string>
 #include <utility>
 //--------------------------------------------------------------------------------------
+class GeomAPI_Pnt;
 class GeomAPI_Shape;
 class ModelAPI_AttributeSelection;
 class ModelAPI_AttributeSelectionList;
@@ -36,6 +37,7 @@ class ModelAPI_Result;
 typedef std::pair<std::shared_ptr<ModelAPI_Result>, std::shared_ptr<GeomAPI_Shape> >
   ResultSubShapePair;
 typedef std::pair<std::string, std::string> TypeSubShapeNamePair;
+typedef std::pair<std::string, std::shared_ptr<GeomAPI_Pnt> > TypeInnerPointPair;
 //--------------------------------------------------------------------------------------
 /**\class ModelHighAPI_Selection
  * \ingroup CPPHighAPI
@@ -47,7 +49,8 @@ public:
   enum VariantType {
     VT_Empty,
     VT_ResultSubShapePair,
-    VT_TypeSubShapeNamePair
+    VT_TypeSubShapeNamePair,
+    VT_TypeInnerPointPair
   };
 
 public:
@@ -64,6 +67,12 @@ public:
   MODELHIGHAPI_EXPORT
   ModelHighAPI_Selection(const std::string& theType,
                          const std::string& theSubShapeName);
+
+  /// Constructor for sub-shape by inner point coordinates
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Selection(const std::string& theType,
+                         const std::shared_ptr<GeomAPI_Pnt>& theSubShapeInnerPoint);
+
   /// Destructor
   MODELHIGHAPI_EXPORT
   virtual ~ModelHighAPI_Selection();
@@ -88,6 +97,10 @@ public:
   MODELHIGHAPI_EXPORT
   virtual TypeSubShapeNamePair typeSubShapeNamePair() const;
 
+  /// \return pair of sub-shape type and inner point to identify sub-shape.
+  MODELHIGHAPI_EXPORT
+  virtual TypeInnerPointPair typeInnerPointPair() const;
+
   /// \return shape type.
   MODELHIGHAPI_EXPORT
   virtual std::string shapeType() const;
@@ -124,6 +137,7 @@ private:
   VariantType myVariantType;
   ResultSubShapePair myResultSubShapePair;
   TypeSubShapeNamePair myTypeSubShapeNamePair;
+  TypeInnerPointPair myTypeInnerPointPair;
 };
 
 //--------------------------------------------------------------------------------------