From: azv Date: Wed, 15 Aug 2018 12:07:25 +0000 (+0300) Subject: Dump with geometrical selection X-Git-Tag: V9_2_0a1~91 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=647319412937f3b52b49c24435bdf7895a433e53;p=modules%2Fshaper.git Dump with geometrical selection Provide dumping itself and selection of sub-shapes by the given point. --- diff --git a/src/ExchangePlugin/ExchangePlugin_Dump.cpp b/src/ExchangePlugin/ExchangePlugin_Dump.cpp index 67ee6aab0..dc74c54c4 100644 --- a/src/ExchangePlugin/ExchangePlugin_Dump.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Dump.cpp @@ -20,6 +20,7 @@ #include +#include #include #include #include @@ -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()); diff --git a/src/ExchangePlugin/ExchangePlugin_Dump.h b/src/ExchangePlugin/ExchangePlugin_Dump.h index a10d98610..591838dfe 100644 --- a/src/ExchangePlugin/ExchangePlugin_Dump.h +++ b/src/ExchangePlugin/ExchangePlugin_Dump.h @@ -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(); diff --git a/src/ExchangePlugin/plugin-Exchange.xml b/src/ExchangePlugin/plugin-Exchange.xml index 30e7f7d45..5bd7fb979 100755 --- a/src/ExchangePlugin/plugin-Exchange.xml +++ b/src/ExchangePlugin/plugin-Exchange.xml @@ -41,6 +41,7 @@ email : webmaster.salome@opencascade.com + diff --git a/src/GeomAPI/GeomAPI_Edge.cpp b/src/GeomAPI/GeomAPI_Edge.cpp index b5d0de4b6..cd3c08466 100644 --- a/src/GeomAPI/GeomAPI_Edge.cpp +++ b/src/GeomAPI/GeomAPI_Edge.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -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(); + 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; +} diff --git a/src/GeomAPI/GeomAPI_Edge.h b/src/GeomAPI/GeomAPI_Edge.h index ac5973d9b..a375b100e 100644 --- a/src/GeomAPI/GeomAPI_Edge.h +++ b/src/GeomAPI/GeomAPI_Edge.h @@ -117,6 +117,10 @@ public: GEOMAPI_EXPORT void setLastPointTolerance(const double theTolerance); + + /// Return middle point on the edge + GEOMAPI_EXPORT + virtual std::shared_ptr middlePoint() const; }; //! Pointer on attribute object diff --git a/src/GeomAPI/GeomAPI_Face.cpp b/src/GeomAPI/GeomAPI_Face.cpp index 270118fcd..ff5dbba27 100644 --- a/src/GeomAPI/GeomAPI_Face.cpp +++ b/src/GeomAPI/GeomAPI_Face.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -231,3 +232,24 @@ std::shared_ptr GeomAPI_Face::getTorus() const } return aTorus; } + +GeomPointPtr GeomAPI_Face::middlePoint() const +{ + GeomPointPtr anInnerPoint; + + const TopoDS_Face& aFace = impl(); + 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; +} diff --git a/src/GeomAPI/GeomAPI_Face.h b/src/GeomAPI/GeomAPI_Face.h index 3e654e916..c50e980d0 100644 --- a/src/GeomAPI/GeomAPI_Face.h +++ b/src/GeomAPI/GeomAPI_Face.h @@ -67,6 +67,9 @@ public: /// Returns torus if the face is based on the toroidal surface GEOMAPI_EXPORT std::shared_ptr getTorus() const; + + /// Return inner point in the face + GEOMAPI_EXPORT virtual std::shared_ptr middlePoint() const; }; //! Pointer on attribute object diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 4cde5e736..c686bbf77 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -20,6 +20,7 @@ #include "GeomAPI_Shape.h" +#include #include #include #include @@ -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; diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 4091f5911..a70574aa4 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -27,6 +27,7 @@ #include #include +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 middlePoint() const; + /// Returns the shape as BRep stream GEOMAPI_EXPORT std::string getShapeStream() const; diff --git a/src/GeomAPI/GeomAPI_Shell.cpp b/src/GeomAPI/GeomAPI_Shell.cpp index 5b7713a96..baab4a1a9 100644 --- a/src/GeomAPI/GeomAPI_Shell.cpp +++ b/src/GeomAPI/GeomAPI_Shell.cpp @@ -32,6 +32,8 @@ #include "GeomAPI_XYZ.h" #include +#include +#include #include #include #include @@ -365,3 +367,20 @@ std::shared_ptr GeomAPI_Shell::getParallelepiped() const aPlanes[anIndex].myHeight)); return aBox; } + +//================================================================================================= +GeomPointPtr GeomAPI_Shell::middlePoint() const +{ + GeomPointPtr anInnerPoint; + + const TopoDS_Shell& aShell = impl(); + 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; +} diff --git a/src/GeomAPI/GeomAPI_Shell.h b/src/GeomAPI/GeomAPI_Shell.h index 91b6a313b..d92f69000 100644 --- a/src/GeomAPI/GeomAPI_Shell.h +++ b/src/GeomAPI/GeomAPI_Shell.h @@ -59,6 +59,9 @@ public: /// Returns box if the shell consists of 6 rectangular faces composing a box GEOMAPI_EXPORT std::shared_ptr getParallelepiped() const; + + /// Return middle point on the shell + GEOMAPI_EXPORT virtual std::shared_ptr middlePoint() const; }; typedef std::shared_ptr GeomShellPtr; diff --git a/src/GeomAPI/GeomAPI_Solid.cpp b/src/GeomAPI/GeomAPI_Solid.cpp index 0f377f2c2..f128d3d65 100644 --- a/src/GeomAPI/GeomAPI_Solid.cpp +++ b/src/GeomAPI/GeomAPI_Solid.cpp @@ -33,6 +33,8 @@ #include "GeomAPI_XYZ.h" #include +#include +#include #include #include #include @@ -298,3 +300,20 @@ std::shared_ptr GeomAPI_Solid::getParallelepiped() const aBox = aShells.front()->shell()->getParallelepiped(); return aBox; } + +//================================================================================================== +GeomPointPtr GeomAPI_Solid::middlePoint() const +{ + GeomPointPtr anInnerPoint; + + const TopoDS_Solid& aSolid = impl(); + 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; +} diff --git a/src/GeomAPI/GeomAPI_Solid.h b/src/GeomAPI/GeomAPI_Solid.h index a81828c8e..12519db24 100644 --- a/src/GeomAPI/GeomAPI_Solid.h +++ b/src/GeomAPI/GeomAPI_Solid.h @@ -59,6 +59,9 @@ public: /// Returns box if the solid is bounded by 6 rectangular faces composing a box GEOMAPI_EXPORT std::shared_ptr getParallelepiped() const; + + /// Return inner point in the solid + GEOMAPI_EXPORT virtual std::shared_ptr middlePoint() const; }; typedef std::shared_ptr GeomSolidPtr; diff --git a/src/GeomAPI/GeomAPI_Wire.cpp b/src/GeomAPI/GeomAPI_Wire.cpp index 32df6d6bb..bcbaf3e94 100644 --- a/src/GeomAPI/GeomAPI_Wire.cpp +++ b/src/GeomAPI/GeomAPI_Wire.cpp @@ -113,3 +113,20 @@ bool GeomAPI_Wire::isRectangle(std::list& thePoints) const } return true; } + +//================================================================================================== +GeomPointPtr GeomAPI_Wire::middlePoint() const +{ + // find middle edge in the wire + std::list 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(); +} diff --git a/src/GeomAPI/GeomAPI_Wire.h b/src/GeomAPI/GeomAPI_Wire.h index c79283d8e..4b244296d 100644 --- a/src/GeomAPI/GeomAPI_Wire.h +++ b/src/GeomAPI/GeomAPI_Wire.h @@ -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 >& thePoints) const; + + /// Return middle point on the wire + GEOMAPI_EXPORT virtual std::shared_ptr middlePoint() const; }; typedef std::shared_ptr GeomWirePtr; diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index d93f02ed3..72fff493f 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -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 aSubs = theShape->subShapes(theType); + for (std::list::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 aFeatures = owner()->document()->allFeatures(); + // Process results of all features from the last to the first + // to find appropriate sub-shape + for (std::list::const_reverse_iterator anIt = aFeatures.rbegin(); + anIt != aFeatures.rend(); ++anIt) { + const std::list& aResults = (*anIt)->results(); + for (std::list::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(*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; diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 9267748a7..ac31cb335 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -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& thePoint); + /// Returns true if attribute was initialized by some value MODEL_EXPORT virtual bool isInitialized(); diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index bc1c7f117..c7e852221 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -24,6 +24,7 @@ #include "Model_Events.h" #include "Model_Data.h" +#include #include #include @@ -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 aNewAttr = + std::shared_ptr(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()) { diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h index 289534c62..d582447c3 100644 --- a/src/Model/Model_AttributeSelectionList.h +++ b/src/Model/Model_AttributeSelectionList.h @@ -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& thePoint, + const std::string& theType); /// Reset temporary stored values virtual void removeTemporaryValues(); diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index 5343ecfbd..9829bde79 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -25,6 +25,7 @@ #include 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& thePoint) = 0; + /// Returns true if recompute of selection become impossible virtual bool isInvalid() = 0; diff --git a/src/ModelAPI/ModelAPI_AttributeSelectionList.h b/src/ModelAPI/ModelAPI_AttributeSelectionList.h index 454d9e34c..69e45b2e7 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelectionList.h +++ b/src/ModelAPI/ModelAPI_AttributeSelectionList.h @@ -24,6 +24,7 @@ #include "ModelAPI_AttributeSelection.h" #include +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& thePoint, + const std::string& theType) = 0; /// Reset temporary stored values virtual void removeTemporaryValues() = 0; diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 8bc41417b..496979d17 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -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 << "]"; diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index c15395286..8cb9c5457 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -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 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 myNotDumpedEntities; diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp index c87b99fe9..7738eb38f 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -27,6 +27,8 @@ #include #include + +#include //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- @@ -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"; diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.h b/src/ModelHighAPI/ModelHighAPI_Selection.h index 21da1cdfe..c63d15650 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.h +++ b/src/ModelHighAPI/ModelHighAPI_Selection.h @@ -28,6 +28,7 @@ #include #include //-------------------------------------------------------------------------------------- +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 > ResultSubShapePair; typedef std::pair TypeSubShapeNamePair; +typedef std::pair > 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& 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; }; //--------------------------------------------------------------------------------------