]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' into V9_3_BR
authorvsr <vsr@opencascade.com>
Wed, 3 Apr 2019 16:01:49 +0000 (19:01 +0300)
committervsr <vsr@opencascade.com>
Wed, 3 Apr 2019 16:01:49 +0000 (19:01 +0300)
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/GeomAPI/GeomAPI_Wire.cpp
src/Model/Model_AttributeSelection.cpp
src/ModelAPI/CMakeLists.txt
src/ModelAPI/Test/Test2901.py [new file with mode: 0644]
src/SketchPlugin/Test/TestMoveArc.py
src/XGUI/XGUI_Tools.cpp
src/XGUI/XGUI_Tools.h
src/XGUI/XGUI_Workshop.cpp

index a3e92eb67e8d27330482fa2b29aeeab7c49b24fc..30f690d1e241b26b1ace384424d33ca233688eee 100644 (file)
@@ -361,6 +361,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
         aXaoGroup->add(anElementID);
       }
     } catch (XAO::XAO_Exception& e) {
+      // LCOV_EXCL_START
       std::string msg = "An error occurred while exporting group " + aResultGroup->data()->name();
       msg += ".\n";
       msg += e.what();
@@ -368,6 +369,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
       msg += "=> skipping this group from XAO export.";
       Events_InfoMessage("ExportFeature", msg, this).send();
       aXao.removeGroup(aXaoGroup);
+      // LCOV_EXCL_STOP
     }
   }
 
@@ -456,6 +458,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
         }
       }
     } catch (XAO::XAO_Exception& e) {
+      // LCOV_EXCL_START
       std::string msg = "An error occurred while exporting field " + aResultField->data()->name();
       msg += ".\n";
       msg += e.what();
@@ -463,6 +466,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName)
       msg += "=> skipping this field from XAO export.";
       Events_InfoMessage("ExportFeature", msg, this).send();
       aXao.removeField(aXaoField);
+      // LCOV_EXCL_STOP
     }
   }
 
index addd4ccb6c166c390d2997d77dec8ca32c6a1288..2ca5925ab0540ba9205058814de7739166875dbf 100644 (file)
@@ -93,6 +93,8 @@ bool GeomAPI_Wire::isRectangle(std::list<GeomPointPtr>& thePoints) const
     const TopoDS_Edge& anEdge = anExp.Current();
     double aT1, aT2;
     Handle(Geom_Curve) aC3D = BRep_Tool::Curve(anEdge, aT1, aT2);
+    if (aC3D.IsNull())
+      continue;
     while (aC3D->IsKind(aTrimmedCurveType))
       aC3D = Handle(Geom_TrimmedCurve)::DownCast(aC3D)->BasisCurve();
     if (!aC3D.IsNull() && aC3D->IsKind(aLineType)) {
index 2aa1f2ee9e51759c3a21738fb7ded23946672d4f..e540e3e6663edc3f0f7d5f1c25663fdea320252f 100644 (file)
@@ -1415,7 +1415,14 @@ void Model_AttributeSelection::updateInHistory(bool& theRemove)
   if (!aContData.get() || !aContData->isValid())
     return;
   TDF_Label aContLab = aContData->shapeLab(); // named shape where the selected context is located
+
+  // checking this may be just a reference to another context (same shape), so use that label
   Handle(TNaming_NamedShape) aContNS;
+  Handle(TDF_Reference) aRefAttr;
+  while(!aContLab.FindAttribute(TNaming_NamedShape::GetID(), aContNS) &&
+        aContLab.FindAttribute(TDF_Reference::GetID(), aRefAttr))
+    aContLab = aRefAttr->Get();
+
   if (!aContLab.FindAttribute(TNaming_NamedShape::GetID(), aContNS)) {
     bool aFoundNewContext = true;
     ResultPtr aNewContext = aContext;
index 18ebdcfc49d0f9e8fb18a6bc787a1f60edb36a21..dbb19965cad7914ae46dc31101d158177bad3d68 100644 (file)
@@ -244,4 +244,5 @@ ADD_UNIT_TESTS(TestConstants.py
                Test2627.py
                Test2859.py
                Test2873.py
+               Test2901.py
 )
diff --git a/src/ModelAPI/Test/Test2901.py b/src/ModelAPI/Test/Test2901.py
new file mode 100644 (file)
index 0000000..b93d358
--- /dev/null
@@ -0,0 +1,127 @@
+# 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
+#
+
+# -*- coding: utf-8 -*-
+
+from SketchAPI import *
+from ModelAPI import *
+from GeomAPI import *
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+model.addParameter(Part_1_doc, "l", "200")
+model.addParameter(Part_1_doc, "b", "100")
+model.addParameter(Part_1_doc, "h", "25")
+model.addParameter(Part_1_doc, "r", "25")
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(200, 0, 0, 0)
+SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
+SketchPoint_1 = SketchProjection_1.createdFeature()
+SketchLine_2 = Sketch_1.addLine(0, 0, 0, 100)
+SketchLine_3 = Sketch_1.addLine(0, 100, 200, 100)
+SketchLine_4 = Sketch_1.addLine(200, 100, 200, 0)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
+SketchConstraintCoincidence_1.setName("SketchConstraintCoincidence_2")
+SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+SketchConstraintCoincidence_2.setName("SketchConstraintCoincidence_3")
+SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
+SketchConstraintCoincidence_3.setName("SketchConstraintCoincidence_4")
+SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
+SketchConstraintCoincidence_4.setName("SketchConstraintCoincidence_5")
+SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
+SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
+SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
+SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
+SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), "l")
+SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), "b")
+SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_2.startPoint(), SketchAPI_Point(SketchPoint_1).coordinates())
+SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_6")
+SketchCircle_1 = Sketch_1.addCircle(50, 50, 25)
+SketchCircle_2 = Sketch_1.addCircle(150, 50, 25)
+SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], "r")
+SketchConstraintEqual_1 = Sketch_1.setEqual(SketchCircle_1.results()[1], SketchCircle_2.results()[1])
+SketchConstraintDistance_1 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_2.result(), "l/4", True)
+SketchConstraintDistance_2 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_1.result(), "b/2", True)
+SketchLine_5 = Sketch_1.addLine(50, 50, 150, 50)
+SketchLine_5.setAuxiliary(True)
+SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_5.startPoint())
+SketchConstraintCoincidence_6.setName("SketchConstraintCoincidence_7")
+SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchCircle_2.center(), SketchLine_5.endPoint())
+SketchConstraintCoincidence_7.setName("SketchConstraintCoincidence_8")
+SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_5.result())
+SketchConstraintDistance_3 = Sketch_1.setDistance(SketchLine_5.endPoint(), SketchLine_4.result(), "l/4", True)
+model.do()
+Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), "h", 0)
+Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/YOZ"), 100, False)
+Partition_1 = model.addPartition(Part_1_doc, [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("FACE", "Plane_1")])
+Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Extrusion_1_1_1/Generated_Face&Sketch_1/SketchLine_2")])
+Group_1.setName("Inlet")
+Group_1.result().setName("Inlet")
+Group_2 = model.addGroup(Part_1_doc, [model.selection("FACE", "Extrusion_1_1_1/Generated_Face&Sketch_1/SketchLine_4")])
+Group_2.setName("Outlet")
+Group_2.result().setName("Outlet")
+Group_3_objects = [model.selection("FACE", "Partition_1_1_1/Modified_Face&Extrusion_1_1_1/To_Face"), model.selection("FACE", "Partition_1_1_1/Modified_Face&Sketch_1/SketchLine_1"), model.selection("FACE", "Partition_1_1_1/Modified_Face&Extrusion_1_1_1/From_Face"), model.selection("FACE", "Partition_1_1_1/Modified_Face&Sketch_1/SketchLine_3"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Sketch_1/SketchLine_3"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Extrusion_1_1_1/From_Face"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Sketch_1/SketchLine_1"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Extrusion_1_1_1/To_Face")]
+Group_3 = model.addGroup(Part_1_doc, Group_3_objects)
+Group_3.setName("Wall")
+Group_3.result().setName("Wall")
+Group_4 = model.addGroup(Part_1_doc, [model.selection("SOLID", "Partition_1_1_3"), model.selection("SOLID", "Partition_1_1_4")])
+Group_4.setName("Cylinders")
+Group_4.result().setName("Cylinders")
+Group_4.result().setColor(170, 0, 0)
+Group_5 = model.addGroup(Part_1_doc, [model.selection("SOLID", "Partition_1_1_1"), model.selection("SOLID", "Partition_1_1_2")])
+Group_5.setName("Fluide")
+Group_5.result().setName("Fluide")
+Group_5.result().setColor(0, 0, 255)
+Group_6 = model.addGroup(Part_1_doc, [model.selection("FACE", "Extrusion_1_1_2/Generated_Face&Sketch_1/SketchCircle_1_2"), model.selection("FACE", "Extrusion_1_1_3/Generated_Face&Sketch_1/SketchCircle_2_2")])
+Group_6.setName("Faces_cyl")
+Group_6.result().setName("Faces_cyl")
+Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOY"), 10, False)
+Partition_2 = model.addPartition(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1"), model.selection("FACE", "Plane_2")])
+model.do()
+# move groups after the latest partitiion
+Part_1_doc.moveFeature(Group_1.feature(), Partition_2.feature())
+Part_1_doc.moveFeature(Group_2.feature(), Group_1.feature())
+Part_1_doc.moveFeature(Group_3.feature(), Group_2.feature())
+Part_1_doc.moveFeature(Group_4.feature(), Group_3.feature())
+Part_1_doc.moveFeature(Group_5.feature(), Group_4.feature())
+Part_1_doc.moveFeature(Group_6.feature(), Group_5.feature())
+model.end()
+
+# check groups are correct: group name, number of elements, elements type
+Group_Info = [
+(Group_1, 2, GeomAPI_Shape.FACE), # Inlet
+(Group_2, 2, GeomAPI_Shape.FACE), # Outlet
+(Group_3, 12, GeomAPI_Shape.FACE), # Wall
+(Group_4, 4, GeomAPI_Shape.SOLID), # Cylinders
+(Group_5, 4, GeomAPI_Shape.SOLID), # Fluide
+(Group_6, 4, GeomAPI_Shape.FACE)] # Faces_cyl
+
+aFactory = ModelAPI_Session.get().validators()
+for group in Group_Info:
+  selectionList = group[0].feature().selectionList("group_list")
+  assert(selectionList.size() == group[1])
+  assert(aFactory.validate(group[0].feature()))
+  for i in range(group[1]):
+    assert(group[0].groupList().value(i).value().shapeType() == group[2])
+
+assert(model.checkPythonDump())
index 621538e032c14eb5c0e445c6366f749156f0222d..b66678599f6c82dad13397e88e8f1f061177123b 100644 (file)
@@ -251,8 +251,7 @@ class TestMoveArc(unittest.TestCase):
     self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
     model.do()
     self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
-    self.assertNotEqual(self.myArc.center().x(), self.myCenter[0])
-    self.assertNotEqual(self.myArc.center().y(), self.myCenter[1])
+    self.assertTrue(fabs(self.myArc.center().x() - self.myCenter[0]) > 1.e-5 or fabs(self.myArc.center().y() - self.myCenter[1]) > 1.e-5)
 
   def test_move_center_of_arc_fixed_radius(self):
     """ Test 17. Movement of center of the arc with fixed radius
index a5b71682cb16afe3f23ad1a75316fc0990646c3f..cb66e1837fdaf24eb62da0d0f3ce818caf4f65e2 100644 (file)
 #include <sstream>
 #include <string>
 
+#ifndef WIN32
+# include <sys/stat.h>
+# include <dirent.h>
+# include <unistd.h>
+# define _separator_ '/'
+#else
+#include <io.h>
+#define F_OK 0
+#define access _access
+# include <windows.h>
+# define _separator_ '\\'
+#endif
+
 namespace XGUI_Tools {
 //******************************************************************
 QString dir(const QString& path, bool isAbs)
@@ -276,4 +289,97 @@ QString generateName(const ModuleBase_ViewerPrsPtr& thePrs)
   return aName;
 }
 
+std::wstring strToWStr(const std::string& theStr) {
+  size_t aLen = theStr.size();
+  std::wstring aResult(aLen, L'#');
+  mbstowcs(&aResult[0], theStr.c_str(), aLen);
+  return aResult;
+}
+
+std::string getTmpDirByPath( const std::string& theTmpPath)
+{
+  std::string aTmpDir = theTmpPath;
+  if (aTmpDir == "" || access(aTmpDir.c_str() , F_OK) != 0) {
+#ifdef WIN32
+    char *Tmp_dir = getenv("TEMP");
+    if (Tmp_dir == NULL) {
+      Tmp_dir = getenv("TMP");
+      if (Tmp_dir == NULL)
+        aTmpDir = "C:\\";
+      else
+        aTmpDir = Tmp_dir;
+    }
+    else
+      aTmpDir = Tmp_dir;
+#else
+    aTmpDir = "/tmp/";
+#endif
+  }
+
+  if (aTmpDir.back() != _separator_)
+    aTmpDir += _separator_;
+
+  srand((unsigned int)time( NULL ));
+  //Get a random number to present a name of a sub directory
+  int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0));
+  char buffer[127];
+  sprintf(buffer, "%d", aRND);
+  std::string aSubDir(buffer);
+  if (aSubDir.size() <= 1)
+    aSubDir = "123049876";
+
+  aTmpDir += aSubDir; //Get RND sub directory
+
+  std::string aDir = aTmpDir;
+
+  for(aRND = 0; access(aDir.c_str() , F_OK) == 0; aRND++) {
+    sprintf( buffer, "%d", aRND );
+    aDir = aTmpDir + buffer;  //Build a unique directory name
+  }
+  if (aDir.back() != _separator_)
+    aDir += _separator_;
+
+#ifdef WIN32
+  CreateDirectory(strToWStr(aDir).c_str(), NULL);
+#else
+  mkdir( aDir.c_str(), 0x1ff );
+#endif
+
+  return aDir;
+}
+
+std::string getTmpDirByEnv( const char* thePathEnv)
+{
+  char* aVal = thePathEnv[0] == 0 ? 0 : getenv(thePathEnv);
+  std::string dir = aVal ? aVal : "";
+  return getTmpDirByPath(dir).c_str();
+}
+
+void removeTemporaryFiles(const std::string& theDirectory,
+  const std::list<std::string>& theFiles)
+{
+  std::string aDirName = theDirectory;
+
+  std::list<std::string>::const_iterator aFilesIter = theFiles.cbegin();
+  for(; aFilesIter != theFiles.cend(); aFilesIter++) {
+    const std::string& aFile = *aFilesIter;
+    if(access(aFile.c_str() , F_OK) != 0)
+      continue;
+
+#ifdef WIN32
+    DeleteFile(strToWStr(aFile).c_str());
+#else
+    unlink(aFile.c_str());
+#endif
+  }
+
+  if(access(aDirName.c_str() , F_OK) == 0) {
+#ifdef WIN32
+    RemoveDirectory(strToWStr(aDirName).c_str());
+#else
+    rmdir(aDirName.c_str());
+#endif
+  }
+}
+
 }
index 2bcb3322855347ec12cc5611ed4e4e403eefe389..54928254e89cc8a1b7080711c9278d3a7dacd592 100644 (file)
@@ -127,6 +127,14 @@ XGUI_EXPORT XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop);
 /// \param thePrs a presentation
 /// \return string value
 XGUI_EXPORT QString generateName(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
+
+/// Creates and returns the temporary directory (with random name) using the environment variable
+/// path to location of such directories,
+std::string getTmpDirByEnv( const char* thePathEnv);
+
+/// Removes files and directory where they are located
+void removeTemporaryFiles(const std::string& theDirectory,
+  const std::list<std::string>& theFiles);
 };
 
 #endif
index f1d5d4f36d807306b3be36e33e9210da6e10f1e1..b42e4d003c5285fa3ed96fee4a55056cf46a70a3 100644 (file)
@@ -1073,15 +1073,23 @@ bool XGUI_Workshop::onSave()
     aMgr->blockAutoUpdate(false);
 
   std::list<std::string> aFiles;
-  saveDocument(myTmpDir.path(), aFiles);
-  if (!XGUI_CompressFiles::compress(myCurrentFile, aFiles))
-    return false;
+  // issue #2899: create a temporary directory, save and then remove it
+#ifdef HAVE_SALOME
+  std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("SALOME_TMP_DIR");
+#else
+  std::string aTmpDir = XGUI_Tools::getTmpDirByEnv("");
+#endif
+  saveDocument(QString(aTmpDir.c_str()), aFiles);
+  bool aResult = XGUI_CompressFiles::compress(myCurrentFile, aFiles);
+  XGUI_Tools::removeTemporaryFiles(aTmpDir, aFiles);
 
-  updateCommandStatus();
+  if (aResult) {
+    updateCommandStatus();
 #ifndef HAVE_SALOME
     myMainWindow->setModifiedState(false);
 #endif
-  return true;
+  }
+  return aResult;
 }
 
 //******************************************************