Salome HOME
Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Add frame (Export icon)
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2d.cpp
index 10f6de95fd65dc663d5e28d6d00fcbcab2f4ebed..3d8c89ad1871602e7608812c70376eb572a6ed4f 100644 (file)
@@ -31,6 +31,7 @@
 #include <GeomAPI_Pnt2d.h>
 
 #include <SketchPlugin_Feature.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
 
 #include <QGroupBox>
 #include <QGridLayout>
@@ -120,11 +121,16 @@ PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D()
 {
 }
 
-bool PartSet_WidgetPoint2D::setSelection(ModuleBase_ViewerPrs theValue)
+bool PartSet_WidgetPoint2D::setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition)
 {
+  if (thePosition < 0 || thePosition >= theValues.size())
+    return false;
+  ModuleBase_ViewerPrs aValue = theValues[thePosition];
+  thePosition++;
+
   Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
   bool isDone = false;
-  TopoDS_Shape aShape = theValue.shape();
+  TopoDS_Shape aShape = aValue.shape();
   double aX, aY;
   if (getPoint2d(aView, aShape, aX, aY)) {
     isDone = setPoint(aX, aY);
@@ -207,8 +213,7 @@ void PartSet_WidgetPoint2D::activateCustom()
 
   QIntList aModes;
   aModes << TopAbs_VERTEX;
-  if (isEditingMode())
-    aModes << TopAbs_EDGE;
+  aModes << TopAbs_EDGE;
   myWorkshop->moduleConnector()->activateSubShapesSelection(aModes);
 }
 
@@ -276,6 +281,25 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
       emit vertexSelected();
       emit focusOutWidget(this);
       return;
+    } else if (aShape.ShapeType() == TopAbs_EDGE) {
+      // Create point-edge coincedence
+      FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+      std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+
+      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
+          ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+      AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
+      std::shared_ptr<GeomDataAPI_Point2D> aThisPoint = 
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
+      aRef1->setAttr(aThisPoint);
+
+      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
+          ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
+      aRef2->setObject(aObject);
+      aFeature->execute();
+      emit vertexSelected();
+      emit focusOutWidget(this);
+      return;
     }
   }
   // End of Bug dependent fragment