Salome HOME
Update viewer after selection clear for OCCT 7.4.0.
[modules/shaper.git] / src / SketchAPI / SketchAPI_Translation.cpp
index 2d5eaa38cfa1fe4734c50ba273180bdf388b360b..3bb86f2c6c5daf28869bc5f23d5a7852d3791984 100644 (file)
@@ -1,11 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-// Name   : SketchAPI_Translation.cpp
-// Purpose:
+// 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
+// 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
 //
-// History:
-// 16/06/16 - Sergey POKHODENKO - Creation of the file
 
-//--------------------------------------------------------------------------------------
 #include "SketchAPI_Translation.h"
 #include <SketchAPI_SketchEntity.h>
 //--------------------------------------------------------------------------------------
@@ -46,7 +57,7 @@ SketchAPI_Translation::~SketchAPI_Translation()
 
 }
 
-std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Translation::translated() const
+std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Translation::translated() const
 {
   std::list<ObjectPtr> aList = translatedObjects()->list();
   // remove all initial features
@@ -74,6 +85,13 @@ void SketchAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
   AttributeIntegerPtr aNbCopies = numberOfObjects();
   bool isFullValue = valueType()->value() != "SingleValue";
 
+  // Check all attributes are already dumped. If not, store the constraint as postponed.
+  if (!theDumper.isDumped(aStart) || !theDumper.isDumped(aEnd) ||
+      !theDumper.isDumped(aTransObjects)) {
+    theDumper.postpone(aBase);
+    return;
+  }
+
   theDumper << aBase << " = " << aSketchName << ".addTranslation("
             << aTransObjects << ", " << aStart << ", " << aEnd << ", " << aNbCopies;
   if (isFullValue)
@@ -82,12 +100,32 @@ void SketchAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
 
   // Dump variables for a list of translated features
   theDumper << "[";
-  std::list<std::shared_ptr<ModelHighAPI_Interface> > aList = translated();
-  std::list<std::shared_ptr<ModelHighAPI_Interface> >::const_iterator anIt = aList.begin();
+  std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = translated();
+  std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
   for (; anIt != aList.end(); ++anIt) {
     if (anIt != aList.begin())
       theDumper << ", ";
-    theDumper << theDumper.name((*anIt)->feature(), false);
+    theDumper << (*anIt)->feature();
   }
   theDumper << "] = " << theDumper.name(aBase) << ".translated()" << std::endl;
+
+  // Set necessary "auxiliary" flag for translated features
+  // (flag is set if it differs to base entity)
+  std::list<ObjectPtr> aTransList = aTransObjects->list();
+  std::list<ObjectPtr>::const_iterator aTrIt = aTransList.begin();
+  anIt = aList.begin();
+  for (; aTrIt != aTransList.end(); ++aTrIt) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(*aTrIt);
+    if (!aFeature)
+      continue;
+    bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
+
+    for (int i = 1; i < aNbCopies->value(); ++i, ++anIt) {
+      aFeature = (*anIt)->feature();
+      bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
+      if (aFeatAux != aBaseAux)
+        theDumper << theDumper.name((*anIt)->feature(), false)
+                  << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;
+    }
+  }
 }