]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/PartSet/PartSet_WidgetPoint2d.cpp
Salome HOME
Add tools
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2d.cpp
index 1ffc4f4d234d66faf4fdb60b76450309d01eefec..d94afa5a0dc5c10b0018a0e933bf2347e743a49b 100644 (file)
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Point.h>
 
 #include <QGroupBox>
 #include <QGridLayout>
@@ -46,6 +50,7 @@
 
 const double MaxCoordinate = 1e12;
 
+static QStringList MyFeaturesForCoincedence;
 
 PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, 
                                              ModuleBase_IWorkshop* theWorkshop,
@@ -53,6 +58,12 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
                                              const std::string& theParentId)
  : ModuleBase_ModelWidget(theParent, theData, theParentId), myWorkshop(theWorkshop)
 {
+  if (MyFeaturesForCoincedence.isEmpty()) {
+    MyFeaturesForCoincedence << SketchPlugin_Line::ID().c_str()
+      << SketchPlugin_Arc::ID().c_str()
+      << SketchPlugin_Point::ID().c_str()
+      << SketchPlugin_Circle::ID().c_str();
+  }
   myLockApplyMgr = new PartSet_LockApplyMgr(theParent, myWorkshop);
 
   // the control should accept the focus, so the boolen flag is corrected to be true
@@ -160,7 +171,7 @@ bool PartSet_WidgetPoint2D::storeValueCustom() const
     return false;
   std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(attributeID()));
-  
+
   PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this;
   bool isBlocked = that->blockSignals(true);
   bool isImmutable = aPoint->setImmutable(true);
@@ -328,6 +339,8 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
           setPoint(aX, aY);
         }
         else {
+          if (getPoint2d(aView, aShape, aX, aY))
+            setPoint(aX, aY);
           setConstraintWith(aObject);
           emit vertexSelected();
           emit focusOutWidget(this);
@@ -346,11 +359,14 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
         // do not set a coincidence constraint in the attribute if the feature contains a point
         // with the same coordinates. It is important for line creation in order to do not set
         // the same constraints for the same points, oterwise the result line has zero length.
-        if (getPoint2d(aView, aShape, aX, aY))
+        if (getPoint2d(aView, aShape, aX, aY)) {
+          setPoint(aX, aY);
           PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
-        else if (aShape.ShapeType() == TopAbs_EDGE)
-          setConstraintWith(aObject);
-
+        }
+        else if (aShape.ShapeType() == TopAbs_EDGE) {
+          if (MyFeaturesForCoincedence.contains(myFeature->getKind().c_str()))
+            setConstraintWith(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
         // to some distance, but in the area of the highlighting of the point. Constraint
@@ -428,12 +444,12 @@ bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature,
   std::list<AttributePtr> anAttributes =
                                 myFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
   std::list<AttributePtr>::iterator anIter = anAttributes.begin();
-  for(; anIter != anAttributes.end(); anIter++) {
+  for(; anIter != anAttributes.end() && !aPointIsFound; anIter++) {
     AttributePoint2DPtr aPoint2DAttribute =
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIter);
     if (aPoint2DAttribute == aWidgetAttribute)
       continue;
-    if (aPoint2DAttribute.get()) {
+    if (aPoint2DAttribute.get() && aPoint2DAttribute->isInitialized()) {
       aPointIsFound = aPoint2DAttribute->pnt()->isEqual(aPnt2d);
     }
   }