Salome HOME
Issue #1393 Angle constraint : incorrect angle displayed. solution: do not select...
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2d.cpp
index 8543f3143a8f1497c1e8cce4358270865d37853a..a2c0245033bddbf26d787e7d2d61bba0607907e8 100644 (file)
@@ -17,6 +17,8 @@
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_IViewWindow.h>
 #include <ModuleBase_ISelection.h>
+#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_WidgetValidator.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -115,6 +117,22 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
   ModuleBase_Tools::zeroMargins(aLayout);
   aLayout->addWidget(myGroupBox);
   setLayout(aLayout);
+
+  myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
+}
+
+bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
+{
+  bool aValid = true;
+  /*if (getValidState(theValue, aValid)) {
+    return aValid;
+  }
+  aValid = isValidSelectionCustom(theValue);
+  if (aValid)
+    aValid = isValidSelectionForAttribute(theValue, attribute());
+
+  storeValidState(theValue, aValid);
+  */return aValid;
 }
 
 bool PartSet_WidgetPoint2D::resetCustom()
@@ -147,26 +165,27 @@ PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D()
 {
 }
 
-bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
                                          const bool theToValidate)
 {
   bool isDone = false;
   if (theValues.empty())
     return isDone;
 
-  ModuleBase_ViewerPrs aValue = theValues.takeFirst();
-  TopoDS_Shape aShape = aValue.shape();
-  if (!aShape.IsNull()) {
+  ModuleBase_ViewerPrsPtr aValue = theValues.takeFirst();
+  GeomShapePtr aShape = aValue->shape();
+  if (aShape.get() && !aShape->isNull()) {
     Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
     double aX, aY;
-    if (getPoint2d(aView, aShape, aX, aY)) {
+    const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
+    if (getPoint2d(aView, aTDShape, aX, aY)) {
       isDone = setPoint(aX, aY);
       PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
     }
   }
   else if (canBeActivatedByMove()) {
     if (feature()->getKind() == SketchPlugin_Line::ID()) {
-      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aValue.object());
+      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aValue->object());
       // Initialize new line with first point equal to end of previous
       if (aFeature.get()) {
         std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
@@ -512,13 +531,7 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
             setPoint(aX, aY);
           }
           setValueState(Stored); // in case of edge selection, Apply state should also be updated
-
-          FeaturePtr anObjectFeature = ModelAPI_Feature::feature(aObject);
-          std::string anAuxiliaryAttribute = SketchPlugin_SketchEntity::AUXILIARY_ID();
-          AttributeBooleanPtr anAuxiliaryAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
-                                            anObjectFeature->data()->attribute(anAuxiliaryAttribute));
-          if (anAuxiliaryAttr.get())
-            isAuxiliaryFeature = anAuxiliaryAttr->value();
+          isAuxiliaryFeature = PartSet_Tools::isAuxiliarySketchEntity(aObject);
         }
         // it is important to perform updateObject() in order to the current value is 
         // processed by Sketch Solver. Test case: line is created from a previous point