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 a81a7f2c5a3c870da653d926d1fb402d05abe3b7..3d8c89ad1871602e7608812c70376eb572a6ed4f 100644 (file)
@@ -31,6 +31,7 @@
 #include <GeomAPI_Pnt2d.h>
 
 #include <SketchPlugin_Feature.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
 
 #include <QGroupBox>
 #include <QGridLayout>
@@ -54,6 +55,8 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
                                               const std::string& theParentId)
     : ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
+  // the control should accept the focus, so the boolen flag is corrected to be true
+  myIsObligatory = true;
   //myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
   QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
   myGroupBox = new QGroupBox(aPageName, theParent);
@@ -110,6 +113,7 @@ void PartSet_WidgetPoint2D::reset()
     // locking of the validating state.
     ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0);
     ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0);
+    storeValueCustom();
   }
 }
 
@@ -117,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);
@@ -204,8 +213,7 @@ void PartSet_WidgetPoint2D::activateCustom()
 
   QIntList aModes;
   aModes << TopAbs_VERTEX;
-  if (isEditingMode())
-    aModes << TopAbs_EDGE;
+  aModes << TopAbs_EDGE;
   myWorkshop->moduleConnector()->activateSubShapesSelection(aModes);
 }
 
@@ -241,6 +249,10 @@ bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView,
 
 void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  // the contex menu release by the right button should not be processed by this widget
+  if (theEvent->button() != Qt::LeftButton)
+    return;
+
   XGUI_Selection* aSelection = myWorkshop->selector()->selection();
   Handle(V3d_View) aView = theWnd->v3dView();
   // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
@@ -255,8 +267,11 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
     if (aSelectedFeature.get() != NULL) {
       std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
               std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
-      if ((!aSPFeature) && (!aShape.IsNull()))
-        PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+      if ((!aSPFeature) && (!aShape.IsNull())) {
+        ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
+        if (!aFixedObject.get())
+          aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+      }
     }
     double aX, aY;
     if (getPoint2d(aView, aShape, aX, aY)) {
@@ -266,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