Salome HOME
Change icons for chamfer
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroArc.cpp
index cae5ca0f4da4dfbc086b9c61673a22a820ed208b..3e6327e08ef04fc5a9bc844f1018048a0014266d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  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
 //
 // 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
+// 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>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "SketchPlugin_MacroArc.h"
@@ -309,40 +308,40 @@ void SketchPlugin_MacroArc::execute()
   // Create constraints.
   std::string anArcType = string(ARC_TYPE())->value();
   if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
-    SketchPlugin_Tools::createConstraint(this,
+    SketchPlugin_Tools::createCoincidenceOrTangency(this,
                                          CENTER_POINT_REF_ID(),
                                          anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
                                          ObjectPtr(),
                                          false);
-    SketchPlugin_Tools::createConstraint(this,
+    SketchPlugin_Tools::createCoincidenceOrTangency(this,
                                          START_POINT_REF_ID(),
                                          anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
                                          ObjectPtr(),
                                          false);
-    SketchPlugin_Tools::createConstraint(this,
+    SketchPlugin_Tools::createCoincidenceOrTangency(this,
                                          END_POINT_REF_ID(),
                                          anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
                                          ObjectPtr(),
                                          false);
   } else if(anArcType == ARC_TYPE_BY_THREE_POINTS()) {
-    SketchPlugin_Tools::createConstraint(this,
+    SketchPlugin_Tools::createCoincidenceOrTangency(this,
                                          START_POINT_REF_ID(),
                                          anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
                                          ObjectPtr(),
                                          false);
-    SketchPlugin_Tools::createConstraint(this,
+    SketchPlugin_Tools::createCoincidenceOrTangency(this,
                                          END_POINT_REF_ID(),
                                          anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
                                          ObjectPtr(),
                                          false);
-    SketchPlugin_Tools::createConstraint(this,
+    SketchPlugin_Tools::createCoincidenceOrTangency(this,
                                          PASSED_POINT_REF_ID(),
                                          AttributePtr(),
                                          anArcFeature->lastResult(),
                                          true);
   } else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
     // constraints for tangent arc
-    SketchPlugin_Tools::createConstraint(this,
+    SketchPlugin_Tools::createCoincidenceOrTangency(this,
                                          TANGENT_POINT_ID(),
                                          anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
                                          ObjectPtr(),
@@ -355,7 +354,7 @@ void SketchPlugin_MacroArc::execute()
     AttributeRefAttrPtr aRefAttrB = aTangent->refattr(SketchPlugin_Constraint::ENTITY_B());
     aRefAttrB->setObject(anArcFeature->lastResult());
     // constraint for end point
-    SketchPlugin_Tools::createConstraint(this,
+    SketchPlugin_Tools::createCoincidenceOrTangency(this,
                                          END_POINT_REF_ID(),
                                          anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
                                          ObjectPtr(),
@@ -373,6 +372,7 @@ void SketchPlugin_MacroArc::execute()
   Events_Loop::loop()->send(aMessage);
 }
 
+// LCOV_EXCL_START
 std::string SketchPlugin_MacroArc::processEvent(const std::shared_ptr<Events_Message>& theMessage)
 {
   std::string aFilledAttributeName;
@@ -436,14 +436,11 @@ std::string SketchPlugin_MacroArc::processEvent(const std::shared_ptr<Events_Mes
               aRefAttr->setAttr(anAttribute);
             }
             else if (anObject.get()) {
-              // if presentation of previous reentrant macro arc is used, the object is invalid,
-              // we should use result of previous feature of the message(Arc)
-              if (!anObject->data()->isValid()) {
-                FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
-                if (aCreatedFeature.get())
-                  anObject = aCreatedFeature->lastResult();
-              }
-              aRefAttr->setObject(anObject);
+              // if attribute is NULL, only object is defined, it should be processed outside
+              // the feature because it might be an external feature, that will be
+              // removed/created again after restart operation
+              // #2468 - Crash when sketching circles successively on a repetition
+              aFilledAttributeName = ARC_TYPE();
             }
           }
         }
@@ -453,6 +450,7 @@ std::string SketchPlugin_MacroArc::processEvent(const std::shared_ptr<Events_Mes
   }
   return aFilledAttributeName;
 }
+// LCOV_EXCL_STOP
 
 FeaturePtr SketchPlugin_MacroArc::createArcFeature()
 {
@@ -494,6 +492,9 @@ void SketchPlugin_MacroArc::fillByCenterAndTwoPassed()
     return;
 
   GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
+  // avoid degerated arc, when the center and the start points are equal
+  if (!aCircleForArc.implPtr<void*>())
+    return;
 
   bool aWasBlocked = data()->blockSendAttributeUpdated(true);
   // check the end point is referred to another feature