Salome HOME
Issue #2157: Create fillet : special behavior with origin
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
index e5b194c900346ad1130a81e1fad46ad338f9fe8f..f922ce8eac2b2b0e9be1c51a2e3f6284cfb0cd46 100755 (executable)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        SketchPlugin_Validators.cpp
-// Created:     01 Aug 2014
-// Author:      Vitaly SMETANNIKOV
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "SketchPlugin_Validators.h"
 
@@ -487,6 +501,24 @@ static bool hasSameTangentFeature(const std::set<AttributePtr>& theRefsList,
   return false;
 }
 
+static bool isPointPointCoincidence(const FeaturePtr& theCoincidence)
+{
+  AttributeRefAttrPtr aRefAttr[2] = {
+      theCoincidence->refattr(SketchPlugin_Constraint::ENTITY_A()),
+      theCoincidence->refattr(SketchPlugin_Constraint::ENTITY_B())
+  };
+
+  bool arePoints = true;
+  for (int i = 0; i < 2 && arePoints; ++i) {
+    if (aRefAttr[i]->isObject()) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr[i]->object());
+      arePoints = aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID();
+    } else
+      arePoints = aRefAttr[i]->attr().get() != NULL;
+  }
+  return arePoints;
+}
+
 bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribute,
                                                  const std::list<std::string>& theArguments,
                                                  Events_InfoMessage& theError) const
@@ -514,23 +546,24 @@ bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribut
     std::shared_ptr<ModelAPI_Attribute> aAttr = (*anIt);
     FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
     if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+      if (!isPointPointCoincidence(aConstrFeature))
+        continue;
+
       AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
         aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
       AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
         aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
-      if(anAttrRefA.get() && !anAttrRefA->isObject()) {
-        AttributePtr anAttrA = anAttrRefA->attr();
-        if(aPointAttribute == anAttrA) {
-          aConstraintCoincidence = aConstrFeature;
-          break;
-        }
+
+      AttributePtr anAttrA = anAttrRefA->attr();
+      if(aPointAttribute == anAttrA) {
+        aConstraintCoincidence = aConstrFeature;
+        break;
       }
-      if(anAttrRefB.get() && !anAttrRefB->isObject()) {
-        AttributePtr anAttrB = anAttrRefB->attr();
-        if(aPointAttribute == anAttrB) {
-          aConstraintCoincidence = aConstrFeature;
-          break;
-        }
+
+      AttributePtr anAttrB = anAttrRefB->attr();
+      if(aPointAttribute == anAttrB) {
+        aConstraintCoincidence = aConstrFeature;
+        break;
       }
     }
   }
@@ -544,18 +577,20 @@ bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribut
   std::set<FeaturePtr> aCoinsides;
   SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
                                         SketchPlugin_ConstraintCoincidence::ENTITY_A(),
-                                        aCoinsides);
+                                        aCoinsides,
+                                        true);
   SketchPlugin_Tools::findCoincidences(aConstraintCoincidence,
                                         SketchPlugin_ConstraintCoincidence::ENTITY_B(),
-                                        aCoinsides);
+                                        aCoinsides,
+                                        true);
 
-  // Remove points from set of coincides.
+  // Remove points and external lines from set of coincides.
   std::set<FeaturePtr> aNewSetOfCoincides;
   for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin();
       anIt != aCoinsides.end(); ++anIt) {
     std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
       std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(*anIt);
-    if(aSketchEntity.get() && aSketchEntity->isCopy()) {
+    if(aSketchEntity.get() && (aSketchEntity->isCopy() || aSketchEntity->isExternal())) {
       continue;
     }
     if((*anIt)->getKind() != SketchPlugin_Line::ID() &&
@@ -1140,8 +1175,7 @@ bool SketchPlugin_CirclePassedPointValidator::isValid(
     return true;
 
   if (aCenterRef->isObject()) {
-    FeaturePtr aCenterFeature = ModelAPI_Feature::feature(aCenterRef->object());
-    if (aCenterFeature == aPassedFeature) {
+    if (aCenterRef->object() == aPassedRef->object()) {
       theError = aErrorMessage;
       return false;
     }
@@ -1442,7 +1476,10 @@ bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
 
   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
   if(aResult.get()) {
-    GeomShapePtr aShape = toInfiniteEdge(aResult->shape());
+    GeomShapePtr aShape = aResult->shape();
+    if (!aShape->isEdge())
+      return true;
+    aShape = toInfiniteEdge(aShape);
     if(aShape.get() && !aShape->isNull()) {
       if(anArcShape->isIntersect(aShape)) {
         return true;
@@ -1457,7 +1494,10 @@ bool SketchPlugin_ArcEndPointIntersectionValidator::isValid(
         anIt != aResults.cend();
         ++anIt)
     {
-      GeomShapePtr aShape = toInfiniteEdge((*anIt)->shape());
+      GeomShapePtr aShape = (*anIt)->shape();
+      if (!aShape->isEdge())
+        return true;
+      aShape = toInfiniteEdge(aShape);
       if(aShape.get() && !aShape->isNull()) {
         if(anArcShape->isIntersect(aShape)) {
           return true;