Salome HOME
Fix for the issue #2246 : Naming incorrect after translation.
[modules/shaper.git] / src / SketchAPI / SketchAPI_Constraint.cpp
index 617a0bfa62485d90f16239ea548cbce261122ba0..b777eaddeecc77df2e07e95d17b28ae53f8305b6 100644 (file)
@@ -1,8 +1,22 @@
-// Name   : SketchAPI_Constraint.cpp
-// Purpose: 
+// 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>
 //
-// History:
-// 08/08/16 - Artem ZHIDKOV - Creation of the file
 
 #include "SketchAPI_Constraint.h"
 
@@ -24,6 +38,7 @@
 #include <SketchPlugin_ConstraintRigid.h>
 #include <SketchPlugin_ConstraintTangent.h>
 #include <SketchPlugin_ConstraintVertical.h>
+#include <SketchPlugin_SketchEntity.h>
 
 #include <SketcherPrs_Tools.h>
 
@@ -128,42 +143,41 @@ static std::string angleTypeToString(int theAngleType)
 void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const
 {
   FeaturePtr aBase = feature();
-  ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(aBase);
-  if (!aConstraint)
-    return; // dump constraints only
+  const std::string& aSetter = constraintTypeToSetter(aBase->getKind());
+  if (aSetter.empty())
+    return; // incorrect constraint type
 
   // do not need to dump "Fixed" constraint for external object
-  if (aConstraint->getKind() == SketchPlugin_ConstraintRigid::ID()) {
-    AttributeRefAttrPtr aRefAttr = aConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
-    std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
-        std::dynamic_pointer_cast<SketchPlugin_Feature>(
-        ModelAPI_Feature::feature(aRefAttr->object()));
-    if (!aSketchFeature || aSketchFeature->isExternal())
+  if (aBase->getKind() == SketchPlugin_ConstraintRigid::ID()) {
+    AttributeRefAttrPtr aRefAttr = aBase->refattr(SketchPlugin_Constraint::ENTITY_A());
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+    if (!aFeature)
+      return;
+    AttributeSelectionPtr aAttr =
+      aFeature->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+    if (aAttr && aAttr->context().get() != NULL && !aAttr->isInvalid())
       return;
   }
 
-  const std::string& aSetter = constraintTypeToSetter(aConstraint->getKind());
-  if (aSetter.empty())
-    return; // incorrect constraint type
-  bool isAngle = aConstraint->getKind() == SketchPlugin_ConstraintAngle::ID();
+  bool isAngle = aBase->getKind() == SketchPlugin_ConstraintAngle::ID();
   std::string aSetterSuffix;
   if (isAngle)
-    aSetterSuffix = angleTypeToString(aConstraint->integer(
+    aSetterSuffix = angleTypeToString(aBase->integer(
                     SketchPlugin_ConstraintAngle::TYPE_ID())->value());
 
-  const std::string& aSketchName = theDumper.parentName(aConstraint);
+  const std::string& aSketchName = theDumper.parentName(aBase);
   theDumper << aBase << " = " << aSketchName << "." << aSetter << aSetterSuffix << "(";
 
   bool isFirstAttr = true;
   for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
-    AttributeRefAttrPtr aRefAttr = aConstraint->refattr(SketchPlugin_Constraint::ATTRIBUTE(i));
+    AttributeRefAttrPtr aRefAttr = aBase->refattr(SketchPlugin_Constraint::ATTRIBUTE(i));
     if (aRefAttr && aRefAttr->isInitialized()) {
       theDumper << (isFirstAttr ? "" : ", ") << aRefAttr;
       isFirstAttr = false;
     }
   }
 
-  AttributeDoublePtr aValueAttr = aConstraint->real(
+  AttributeDoublePtr aValueAttr = aBase->real(
       isAngle ? SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() :SketchPlugin_Constraint::VALUE());
   if (aValueAttr && aValueAttr->isInitialized())
     theDumper << ", " << aValueAttr;