1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_Tools.h
4 // Created: 28 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #include <PartSet_Tools.h>
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_AttributeRefList.h>
12 #include <ModelAPI_Document.h>
13 #include <ModelAPI_Session.h>
14 #include <ModelAPI_ResultConstruction.h>
16 #include <GeomDataAPI_Point.h>
17 #include <GeomDataAPI_Dir.h>
18 #include <GeomDataAPI_Point2D.h>
19 #include <GeomAPI_Pln.h>
20 #include <GeomAPI_Pnt2d.h>
21 #include <GeomAPI_Pnt.h>
22 #include <GeomAPI_Edge.h>
23 #include <GeomAPI_Vertex.h>
25 #include <GeomAPI_Dir.h>
26 #include <GeomAPI_XYZ.h>
28 #include <SketchPlugin_Feature.h>
29 #include <SketchPlugin_Sketch.h>
30 #include <SketchPlugin_ConstraintCoincidence.h>
31 #include <SketchPlugin_ConstraintDistance.h>
32 #include <SketchPlugin_ConstraintLength.h>
33 #include <SketchPlugin_ConstraintRadius.h>
34 #include <SketchPlugin_ConstraintRigid.h>
35 #include <SketchPlugin_Constraint.h>
36 #include <SketchPlugin_Circle.h>
37 #include <SketchPlugin_Arc.h>
38 #include <SketchPlugin_Line.h>
39 #include <SketchPlugin_Point.h>
41 #include <ModuleBase_ViewerPrs.h>
43 #include <V3d_View.hxx>
45 #include <gp_Circ.hxx>
46 #include <ProjLib.hxx>
48 #include <Geom_Line.hxx>
49 #include <GeomAPI_ProjectPointOnCurve.hxx>
50 #include <BRep_Tool.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Vertex.hxx>
59 const double PRECISION_TOLERANCE = 0.000001;
61 gp_Pnt PartSet_Tools::convertClickToPoint(QPoint thePoint, Handle(V3d_View) theView)
66 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
67 theView->Eye(XEye, YEye, ZEye);
69 theView->At(XAt, YAt, ZAt);
70 gp_Pnt EyePoint(XEye, YEye, ZEye);
71 gp_Pnt AtPoint(XAt, YAt, ZAt);
73 gp_Vec EyeVector(EyePoint, AtPoint);
74 gp_Dir EyeDir(EyeVector);
76 gp_Pln PlaneOfTheView = gp_Pln(AtPoint, EyeDir);
77 Standard_Real X, Y, Z;
78 theView->Convert(thePoint.x(), thePoint.y(), X, Y, Z);
79 gp_Pnt ConvertedPoint(X, Y, Z);
81 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
82 gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(),
87 void PartSet_Tools::convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
88 Handle(V3d_View) theView,
89 double& theX, double& theY)
94 AttributeDoublePtr anAttr;
95 std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
97 std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
98 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
100 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
101 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
102 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
103 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
104 std::shared_ptr<GeomAPI_XYZ> anY = aNorm->xyz()->cross(aX->xyz());
106 gp_Pnt anOriginPnt(anOrigin->x(), anOrigin->y(), anOrigin->z());
107 gp_Vec aVec(anOriginPnt, thePoint);
109 if (!theView.IsNull()) {
110 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
111 theView->Eye(XEye, YEye, ZEye);
113 theView->At(XAt, YAt, ZAt);
114 gp_Pnt EyePoint(XEye, YEye, ZEye);
115 gp_Pnt AtPoint(XAt, YAt, ZAt);
117 gp_Vec anEyeVec(EyePoint, AtPoint);
118 anEyeVec.Normalize();
120 std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
121 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
122 gp_Vec aNormalVec(aNormal->x(), aNormal->y(), aNormal->z());
124 double aDen = anEyeVec * aNormalVec;
125 double aLVec = aDen != 0 ? aVec * aNormalVec / aDen : DBL_MAX;
127 gp_Vec aDeltaVec = anEyeVec * aLVec;
128 aVec = aVec - aDeltaVec;
130 theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z();
131 theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
134 std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr theSketch)
136 std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
138 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
139 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
140 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
141 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
142 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
143 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
144 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
146 std::shared_ptr<GeomAPI_Pnt2d> aPnt2d =
147 std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
149 return aPnt2d->to3D(aC->pnt(), aX->dir(), aY);
152 ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
153 FeaturePtr theSketch,
154 const QList<ModuleBase_ViewerPrs>& theSelected,
155 const QList<ModuleBase_ViewerPrs>& theHighlighted)
157 // firstly it finds the feature in the list of highlight
158 ObjectPtr aDeltaObject = nearestFeature(thePoint, theView, theSketch, theHighlighted);
160 // secondly it finds the feature in the list of selected objects
161 aDeltaObject = nearestFeature(thePoint, theView, theSketch, theSelected);
166 ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
167 FeaturePtr theSketch,
168 const QList<ModuleBase_ViewerPrs>& thePresentations)
170 ObjectPtr aDeltaObject;
172 CompositeFeaturePtr aSketch =
173 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theSketch);
174 // 1. find it in the selected list by the selected point
177 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView);
178 PartSet_Tools::convertTo2D(aPoint, theSketch, theView, aX, anY);
181 double aMinDelta = -1;
182 ModuleBase_ViewerPrs aPrs;
183 foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
186 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
187 std::shared_ptr<SketchPlugin_Feature> aSketchFeature = std::dynamic_pointer_cast<
188 SketchPlugin_Feature>(aFeature);
189 if (!aSketchFeature || !aSketch->isSub(aSketchFeature))
192 double aDelta = aSketchFeature->distanceToPoint(
193 std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
194 if (aMinDelta < 0 || aMinDelta > aDelta) {
196 // TODO aDeltaObject = aPrs.result();
200 // 2. if the object is not found, returns the first selected sketch feature
201 if (!aDeltaObject && thePresentations.size() > 0) {
202 // there can be some highlighted objects, e.g. a result of boolean operation and a sketch point
203 foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
206 FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
207 if (aFeature && aSketch->isSub(aFeature))
208 aDeltaObject = aPrs.object();
214 std::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
216 return ModelAPI_Session::get()->moduleDocument();
219 std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::getFeaturePoint(FeaturePtr theFeature,
220 double theX, double theY)
222 std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
223 new GeomAPI_Pnt2d(theX, theY));
224 std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes =
225 theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
226 std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
227 aLast = anAttiributes.end();
228 std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
229 for (; anIt != aLast && !aFPoint; anIt++) {
230 std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = std::dynamic_pointer_cast<
231 GeomDataAPI_Point2D>(*anIt);
232 if (aCurPoint && aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())
239 void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue,
240 const std::string& theAttribute)
244 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
245 AttributeDoublePtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
246 aData->attribute(theAttribute));
248 anAttribute->setValue(theValue);
251 double PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& theAttribute,
257 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
258 AttributeDoublePtr anAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
259 aData->attribute(theAttribute));
261 aValue = anAttribute->value();
268 FeaturePtr PartSet_Tools::feature(FeaturePtr theFeature, const std::string& theAttribute,
269 const std::string& theKind)
275 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
276 std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
277 ModelAPI_AttributeRefAttr>(aData->attribute(theAttribute));
279 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->object());
280 if (!theKind.empty() && aFeature && aFeature->getKind() != theKind) {
281 aFeature = FeaturePtr();
287 void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch,
288 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
289 std::shared_ptr<GeomDataAPI_Point2D> thePoint2)
293 aFeature = theSketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
295 std::shared_ptr<ModelAPI_Document> aDoc = document();
296 aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
299 std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
301 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
302 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
303 aRef1->setAttr(thePoint1);
305 std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
306 ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
307 aRef2->setAttr(thePoint2);
309 if (aFeature) // TODO: generate an error if feature was not created
313 std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
314 findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY,
315 double theTolerance, const QList<FeaturePtr>& theIgnore)
317 std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
318 new GeomAPI_Pnt2d(theX, theY));
320 std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
321 for (int i = 0; i < theSketch->numberOfSubs(); i++) {
322 FeaturePtr aFeature = theSketch->subFeature(i);
323 if (!theIgnore.contains(aFeature)) {
324 anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
326 std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt;
327 for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) {
328 std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
329 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
330 double x = aCurPoint->x();
331 double y = aCurPoint->y();
332 if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < theTolerance)) {
338 return std::shared_ptr<GeomDataAPI_Point2D>();
342 void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
343 const std::string& theAttribute, double theClickedX,
346 // find a feature point by the selection mode
347 //std::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
348 std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
349 GeomDataAPI_Point2D>(theFeature->data()->attribute(theAttribute));
353 // get all sketch features. If the point with the given coordinates belong to any sketch feature,
354 // the constraint is created between the feature point and the found sketch point
355 std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
356 std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
357 ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
359 std::list<ObjectPtr> aFeatures = aRefList->list();
360 std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
361 std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
362 std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
363 new GeomAPI_Pnt2d(theClickedX, theClickedY));
364 for (; anIt != aLast; anIt++) {
365 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
366 if (theFeature == aFeature)
368 // find the given point in the feature attributes
369 anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
370 std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
371 aLast = anAttiributes.end();
372 std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
373 for (; anIt != aLast && !aFPoint; anIt++) {
374 std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
375 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
376 if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())) {
382 PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint);
386 std::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch)
388 std::shared_ptr<GeomAPI_Pln> aPlane;
390 std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
392 std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
393 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
394 std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
395 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
396 if (aNormal && anOrigin) {
397 double adX = aNormal->x();
398 double adY = aNormal->y();
399 double adZ = aNormal->z();
401 if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid
402 double aX = anOrigin->x();
403 double aY = anOrigin->y();
404 double aZ = anOrigin->z();
405 gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ));
406 double aA, aB, aC, aD;
407 aPln.Coefficients(aA, aB, aC, aD);
408 aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
415 std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
416 CompositeFeaturePtr theSketch)
418 std::shared_ptr<GeomAPI_Pnt> aPoint;
419 if (!theSketch || !thePoint2D)
422 DataPtr aData = theSketch->data();
423 std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
424 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
425 std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
426 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
427 std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
428 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
429 std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
431 return thePoint2D->to3D(aC->pnt(), aX->dir(), aY);
434 ResultPtr PartSet_Tools::findFixedObjectByExternal(const TopoDS_Shape& theShape,
435 const ObjectPtr& theObject,
436 CompositeFeaturePtr theSketch)
439 if (theShape.ShapeType() == TopAbs_EDGE) {
440 // Check that we already have such external edge
441 std::shared_ptr<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
442 aInEdge->setImpl(new TopoDS_Shape(theShape));
443 aResult = findExternalEdge(theSketch, aInEdge);
445 if (theShape.ShapeType() == TopAbs_VERTEX) {
446 std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
447 aInVert->setImpl(new TopoDS_Shape(theShape));
448 aResult = findExternalVertex(theSketch, aInVert);
453 ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape,
454 const ObjectPtr& theObject,
455 CompositeFeaturePtr theSketch)
457 if (theShape.ShapeType() == TopAbs_EDGE) {
458 Standard_Real aStart, aEnd;
459 Handle(V3d_View) aNullView;
460 FeaturePtr aMyFeature;
462 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aStart, aEnd);
463 GeomAdaptor_Curve aAdaptor(aCurve);
464 if (aAdaptor.GetType() == GeomAbs_Line) {
466 aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID());
467 } else if (aAdaptor.GetType() == GeomAbs_Circle) {
468 std::shared_ptr<GeomAPI_Edge> anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge);
469 anEdge->setImpl(new TopoDS_Shape(theShape));
470 if (anEdge->isArc()) {
472 aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID());
476 aMyFeature = theSketch->addFeature(SketchPlugin_Circle::ID());
480 DataPtr aData = aMyFeature->data();
481 AttributeSelectionPtr anAttr =
482 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
483 (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
485 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
486 if (anAttr && aRes) {
487 std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
488 anEdge->setImpl(new TopoDS_Shape(theShape));
490 anAttr->setValue(aRes, anEdge);
492 aMyFeature->execute();
495 FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
496 aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
497 setObject(aMyFeature->lastResult());
499 return aMyFeature->lastResult();
503 if (theShape.ShapeType() == TopAbs_VERTEX) {
504 FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID());
507 DataPtr aData = aMyFeature->data();
508 AttributeSelectionPtr anAttr =
509 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
510 (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
512 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
513 if (anAttr && aRes) {
514 std::shared_ptr<GeomAPI_Shape> aVert(new GeomAPI_Shape);
515 aVert->setImpl(new TopoDS_Shape(theShape));
517 anAttr->setValue(aRes, aVert);
518 aMyFeature->execute();
521 FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
522 aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
523 setObject(aMyFeature->lastResult());
525 return aMyFeature->lastResult();
532 bool PartSet_Tools::isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
533 const ModuleBase_ViewerPrs& thePrs)
535 foreach (ModuleBase_ViewerPrs aPrs, theSelected) {
536 if (aPrs.object() == thePrs.object())
542 ResultPtr PartSet_Tools::findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge)
544 for (int i = 0; i < theSketch->numberOfSubs(); i++) {
545 FeaturePtr aFeature = theSketch->subFeature(i);
546 std::shared_ptr<SketchPlugin_Feature> aSketchFea =
547 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
549 if (aSketchFea->isExternal()) {
550 std::list<ResultPtr> aResults = aSketchFea->results();
551 std::list<ResultPtr>::const_iterator aIt;
552 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
553 ResultConstructionPtr aRes =
554 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aIt);
556 std::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
558 if (theEdge->isEqual(aShape))
570 ResultPtr PartSet_Tools::findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert)
572 for (int i = 0; i < theSketch->numberOfSubs(); i++) {
573 FeaturePtr aFeature = theSketch->subFeature(i);
574 std::shared_ptr<SketchPlugin_Feature> aSketchFea =
575 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
577 if (aSketchFea->isExternal()) {
578 std::list<ResultPtr> aResults = aSketchFea->results();
579 std::list<ResultPtr>::const_iterator aIt;
580 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
581 ResultConstructionPtr aRes =
582 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aIt);
584 std::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
586 if (theVert->isEqual(aShape))
598 bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
599 Handle_V3d_View theView, double& theX, double& theY)
601 bool aHasVertex = false;
603 const TopoDS_Shape& aShape = thePrs.shape();
604 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX)
606 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
607 if (!aVertex.IsNull())
609 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
610 PartSet_Tools::convertTo2D(aPoint, theSketch, theView, theX, theY);
618 AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj,
619 const TopoDS_Shape theShape,
620 FeaturePtr theSketch)
623 AttributePtr anAttribute;
624 FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
626 if (theShape.ShapeType() == TopAbs_VERTEX) {
627 const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
628 if (!aVertex.IsNull()) {
629 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
630 std::shared_ptr<GeomAPI_Pnt> aValue = std::shared_ptr<GeomAPI_Pnt>(
631 new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
633 // find the given point in the feature attributes
634 std::list<AttributePtr> anAttiributes =
635 aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
636 std::list<AttributePtr>::const_iterator anIt = anAttiributes.begin(),
637 aLast = anAttiributes.end();
638 for (; anIt != aLast && !anAttribute; anIt++) {
639 std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
640 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
642 std::shared_ptr<GeomAPI_Pnt> aPnt = convertTo3D(aCurPoint->x(), aCurPoint->y(), theSketch);
643 if (aPnt && (aPnt->distance(aValue) < Precision::Confusion())) {
644 anAttribute = aCurPoint;