Implement algorithm of fetching free points.
// find minimal distance between the plane and the curve
GeomAPI_ExtremaCurveSurface anExtrema(aCurve, aPlane);
double aTolerance = BRep_Tool::Tolerance(TopoDS::Edge(aShape));
- if (anExtrema.LowerDistance() < aTolerance) {
+ if (anExtrema.NbExtrema() > 0 &&
+ anExtrema.LowerDistance() < aTolerance) {
// distance is lower than tolerance => tangent case
gp_Pnt aPntC, aPntS;
anExtrema.NearestPoints(aPntC, aPntS);
SET(PROJECT_LIBRARIES
ModelAPI
ModelHighAPI
+ SketcherPrs
)
INCLUDE_DIRECTORIES(
ADD_UNIT_TESTS(
TestSketch.py
+ TestFreePoints.py
)
# ADD_SUBDIRECTORY (Test)
// std::list -> []
%template(InterfaceList) std::list<std::shared_ptr<ModelHighAPI_Interface> >;
%template(EntityList) std::list<std::shared_ptr<SketchAPI_SketchEntity> >;
+%template(SketchPointList) std::list<std::shared_ptr<SketchAPI_Point> >;
%typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr<ModelAPI_Feature>, const std::shared_ptr<ModelAPI_Feature> & {
std::shared_ptr<ModelAPI_Feature> * temp_feature;
}
+//--------------------------------------------------------------------------------------
+std::list< std::shared_ptr<SketchAPI_Point> > SketchAPI_Sketch::getFreePoints()
+{
+ std::list< std::shared_ptr<SketchAPI_Point> > aFreePoints;
+ std::list<ResultPtr> aPoints = SketcherPrs_Tools::getFreePoints(compositeFeature());
+ for (std::list<ResultPtr>::iterator anIt = aPoints.begin(); anIt != aPoints.end(); ++anIt) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ PointPtr aPoint(new SketchAPI_Point(aFeature));
+ aFreePoints.push_back(aPoint);
+ }
+ return aFreePoints;
+}
+
//--------------------------------------------------------------------------------------
std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(
double theX, double theY)
SKETCHAPI_EXPORT
void setExternal(std::shared_ptr<ModelAPI_Object> thePlaneObject);
+ /// List points not connected by constraints with other sketch entitites
+ SKETCHAPI_EXPORT
+ std::list< std::shared_ptr<SketchAPI_Point> > getFreePoints();
+
/// Add point
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Point> addPoint(
--- /dev/null
+# Copyright (C) 2019 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# 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
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from SketchAPI import *
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
+SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False)
+SketchLine_1 = SketchProjection_1.createdFeature()
+SketchCircle_1 = Sketch_1.addCircle(46.22261352148133, 0, 23.58244120674807)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_1.center())
+model.do()
+Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchPoint_1 = Sketch_2.addPoint(-17.08115772475531, -35.96860682980034)
+SketchLine_2 = Sketch_2.addLine(-21.65537897222015, 0.8259975132940123, 39.97043562830241, -43.0039721165161)
+SketchPoint_2 = Sketch_2.addPoint(15.99061885657872, -44.35579681082369)
+SketchConstraintDistance_1 = Sketch_2.setDistance(SketchPoint_2.coordinates(), SketchLine_2.result(), 15, True)
+SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), True)
+SketchPoint_3 = SketchProjection_2.createdFeature()
+SketchIntersectionPoint_1 = Sketch_2.addIntersectionPoint(model.selection("EDGE", "Sketch_1/SketchCircle_1_2"), False)
+[SketchPoint_4, SketchPoint_5] = SketchIntersectionPoint_1.intersectionPoints()
+SketchConstraintDistance_2 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_4).coordinates(), SketchLine_2.result(), 25, True)
+model.do()
+
+FreePoints1 = Sketch_1.getFreePoints()
+assert(len(FreePoints1) == 0)
+
+FreePoints2 = Sketch_2.getFreePoints()
+assert(len(FreePoints2) == 3)
+
+model.end()
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Events.h>
return aPointAttr;
}
+//*************************************************************************************
+std::list<ResultPtr> getFreePoints(const CompositeFeaturePtr& theSketch)
+{
+ std::list<ResultPtr> aFreePoints;
+ if (!theSketch)
+ return aFreePoints;
+
+ AttributeRefListPtr aFeatures = theSketch->reflist(SketchPlugin_Sketch::FEATURES_ID());
+ if (!aFeatures)
+ return aFreePoints;
+ std::list<ObjectPtr> anObjects = aFeatures->list();
+ for (std::list<ObjectPtr>::iterator anObjIt = anObjects.begin();
+ anObjIt != anObjects.end(); ++anObjIt) {
+ FeaturePtr aCurrent = ModelAPI_Feature::feature(*anObjIt);
+ if (aCurrent && aCurrent->getKind() == SketchPlugin_Point::ID()) {
+ // check point is not referred by any constraints
+ const std::set<AttributePtr>& aRefs = aCurrent->data()->refsToMe();
+ std::set<AttributePtr>::iterator aRIt = aRefs.begin();
+ for (; aRIt != aRefs.end(); ++aRIt) {
+ FeaturePtr aRefFeat = ModelAPI_Feature::feature((*aRIt)->owner());
+ std::shared_ptr<SketchPlugin_Constraint> aRefConstr =
+ std::dynamic_pointer_cast<SketchPlugin_Constraint>(aRefFeat);
+ if (aRefConstr)
+ break;
+ }
+ if (aRIt == aRefs.end())
+ aFreePoints.push_back(aCurrent->lastResult());
+ }
+ }
+ return aFreePoints;
+}
+
//*************************************************************************************
FeaturePtr getFeatureLine(DataPtr theData,
const std::string& theAttribute)
#include <ModelAPI_Object.h>
#include <ModelAPI_Attribute.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Result.h>
#include <string>
#include <Events_Loop.h>
const std::string& theAttribute,
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+ /// Collect all sketch points which are not connected with other entities.
+ /// \param theSketch sketch feature
+ /// \return list of results of SketchPlugin_Point features
+ SKETCHERPRS_EXPORT std::list<ResultPtr> getFreePoints(const CompositeFeaturePtr& theSketch);
+
/// Returns value of dimension arrows size
SKETCHERPRS_EXPORT double getArrowSize();