Salome HOME
Incorrect dumping of parts with user-defined names (issue #1804)
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
index 5cb16e6b0b6bd737b5dc2a4b2bd82917e2f02d82..729424d96c72ea9d2d66c9f98df966a727dd7950 100755 (executable)
@@ -107,12 +107,55 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const AttributePtr& theAttribut
   return true;
 }
 
+static bool isCoincident(FeaturePtr theFeature1, FeaturePtr theFeature2)
+{
+  AttributePtr aFeature1PointAttr[2];
+  if(theFeature1->getKind() == SketchPlugin_Line::ID()) {
+    aFeature1PointAttr[0] = theFeature1->attribute(SketchPlugin_Line::START_ID());
+    aFeature1PointAttr[1] = theFeature1->attribute(SketchPlugin_Line::END_ID());
+  } else if(theFeature1->getKind() == SketchPlugin_Arc::ID()) {
+    aFeature1PointAttr[0] = theFeature1->attribute(SketchPlugin_Arc::START_ID());
+    aFeature1PointAttr[1] = theFeature1->attribute(SketchPlugin_Arc::END_ID());
+  }
+
+  std::set<AttributePtr> aRefsList = theFeature1->data()->refsToMe();
+  for(std::set<AttributePtr>::const_iterator aRefIt = aRefsList.begin();
+      aRefIt != aRefsList.end();
+      ++aRefIt) {
+    // Find constraint 
+    FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
+    if(aRefFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
+      continue;
+    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
+    AttributePtr anAttr = aRefAttr->attr();
+    if(anAttr != aFeature1PointAttr[0] && anAttr != aFeature1PointAttr[1])
+      continue;
+
+    // Get coincides from constraint.
+    std::set<FeaturePtr> aCoinsides;
+    SketchPlugin_Tools::findCoincidences(aRefFeature,
+                                         SketchPlugin_ConstraintCoincidence::ENTITY_A(),
+                                         aCoinsides);
+    SketchPlugin_Tools::findCoincidences(aRefFeature,
+                                         SketchPlugin_ConstraintCoincidence::ENTITY_B(),
+                                         aCoinsides);
+
+    if(aCoinsides.find(theFeature2) != aCoinsides.end()) {
+      return true;
+    }
+  }
+
+  return false;
+}
 
 static bool hasCoincidentPoint(FeaturePtr theFeature1, FeaturePtr theFeature2)
 {
-  FeaturePtr aCoincidenceFeature = SketchPlugin_ConstraintCoincidence::findCoincidenceFeature
-                                                                  (theFeature1, theFeature2);
-  return aCoincidenceFeature.get() != NULL;
+  if(theFeature1->getKind() == SketchPlugin_Circle::ID() ||
+      theFeature2->getKind() == SketchPlugin_Circle::ID()) {
+    return false;
+  }
+
+  return (isCoincident(theFeature1, theFeature2) && isCoincident(theFeature2, theFeature1));
 }
 
 bool SketchPlugin_TangentAttrValidator::isValid(const AttributePtr& theAttribute, 
@@ -648,9 +691,9 @@ bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribut
       aFirstEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFirstFeature->attribute(anEndAttr))->pnt();
       aSecondStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(aStartAttr))->pnt();
       aSecondEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSecondFeature->attribute(anEndAttr))->pnt();
-      double aCheck1 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) -
+      double aCheck1 = fabs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondStartPnt->y() - aFirstStartPnt->y()) -
         (aSecondStartPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
-      double aCheck2 = abs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) -
+      double aCheck2 = fabs((aFirstEndPnt->x() - aFirstStartPnt->x()) * (aSecondEndPnt->y() - aFirstStartPnt->y()) -
         (aSecondEndPnt->x() - aFirstStartPnt->x()) * (aFirstEndPnt->y() - aFirstStartPnt->y()));
       if(aCheck1 < 1.e-7 && aCheck2 < 1.e-7) {
         return false;
@@ -863,7 +906,7 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
     std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
     
-    std::set<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+    std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
     std::map<std::shared_ptr<GeomDataAPI_Point2D>, std::shared_ptr<GeomAPI_Pnt> > aPointToAttributes;
     ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
                                                 aX->dir(), aDirY, aPoints, aPointToAttributes);
@@ -891,13 +934,16 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
   AttributeSelectionPtr aFeatureAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
   std::shared_ptr<GeomAPI_Edge> anEdge;
-  if(aFeatureAttr && aFeatureAttr->value() && aFeatureAttr->value()->isEdge()) {
-    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->value()));
-  } else if(aFeatureAttr->context() && aFeatureAttr->context()->shape() &&
-            aFeatureAttr->context()->shape()->isEdge()) {
-    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->context()->shape()));
+  if (aFeatureAttr.get()) {
+    GeomShapePtr aVal = aFeatureAttr->value();
+    ResultPtr aRes = aFeatureAttr->context();
+    if(aFeatureAttr->value() && aFeatureAttr->value()->isEdge()) {
+      anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->value()));
+    } else if(aFeatureAttr->context() && aFeatureAttr->context()->shape() &&
+              aFeatureAttr->context()->shape()->isEdge()) {
+      anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aFeatureAttr->context()->shape()));
+    }
   }
-
   if (!anEdge) {
     theError = "The attribute %1 should be an edge";
     theError.arg(theAttribute->id());