Salome HOME
PAL12608: Add possibility to check geometry of a shape.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ILocalOperations.cxx
index 5df5db4589968e23d758e4ab8244083b5e15fd3d..96bb393b5c6eb273430a048512674d8a57b4a374 100644 (file)
@@ -1,22 +1,46 @@
-using namespace std;
-
-#include "GEOMImpl_ILocalOperations.hxx"
-
-#include "GEOM_Function.hxx"
-#include "GEOMImpl_Types.hxx"
-
-#include "GEOMImpl_FilletDriver.hxx"
-#include "GEOMImpl_ChamferDriver.hxx"
-
-#include "GEOMImpl_IFillet.hxx"
-#include "GEOMImpl_IChamfer.hxx"
-
-#include "GEOMImpl_IArchimede.hxx"
-#include "GEOMImpl_ArchimedeDriver.hxx"
+// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 
+// 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.
+// 
+// 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
+//
+#include <Standard_Stream.hxx>
+
+#include <GEOMImpl_ILocalOperations.hxx>
+
+#include <GEOM_Function.hxx>
+#include <GEOM_PythonDump.hxx>
+
+#include <GEOMImpl_Types.hxx>
+
+#include <GEOMImpl_FilletDriver.hxx>
+#include <GEOMImpl_ChamferDriver.hxx>
+
+#include <GEOMImpl_IFillet.hxx>
+#include <GEOMImpl_IChamfer.hxx>
+
+#include <GEOMImpl_IArchimede.hxx>
+#include <GEOMImpl_ArchimedeDriver.hxx>
+
+#include <GEOMImpl_Gen.hxx>
+#include <GEOMImpl_IShapesOperations.hxx>
 
 #include "utilities.h"
-#include "OpUtil.hxx"
-#include "Utils_ExceptHandlers.hxx"
+#include <OpUtil.hxx>
+#include <Utils_ExceptHandlers.hxx>
 
 #include <TFunction_DriverTable.hxx>
 #include <TFunction_Driver.hxx>
@@ -94,14 +118,8 @@ Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletAll
   }
 
   //Make a Python command
-  TCollection_AsciiString anEntry, aDescr("");
-  TDF_Tool::Entry(aFillet->GetEntry(), anEntry);
-  aDescr = anEntry + " = ILocalOperations.MakeFilletAll(";
-  TDF_Tool::Entry(theShape->GetEntry(), anEntry);
-  aDescr += (anEntry+", ");
-  aDescr += (TCollection_AsciiString(theR)+")");
-
-  aFunction->SetDescription(aDescr);
+  GEOM::TPythonDump(aFunction) << aFillet << " = geompy.MakeFilletAll("
+                               << theShape << ", " << theR << ")";
 
   SetErrorCode(OK);
   return aFillet;
@@ -158,22 +176,16 @@ Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdges
   }
 
   //Make a Python command
-  TCollection_AsciiString anEntry, aDescr("");
-  TDF_Tool::Entry(aFillet->GetEntry(), anEntry);
-  aDescr = anEntry + " = ILocalOperations.MakeFilletEdges(";
-  TDF_Tool::Entry(theShape->GetEntry(), anEntry);
-  aDescr += (anEntry+", ");
-  aDescr += (TCollection_AsciiString(theR)+", [");
+  GEOM::TPythonDump pd (aFunction);
+  pd << aFillet << " = geompy.MakeFillet(" << theShape
+    << ", " << theR << ", geompy.ShapeType[\"EDGE\"], [";
+
   it = theEdges.begin();
-  aDescr += (TCollection_AsciiString(*it)+", ");
-  it++;
-  for (; it != theEdges.end(); it++) {
-    aDescr += ", ";
-    aDescr += TCollection_AsciiString(*it);
+  pd << (*it++);
+  while (it != theEdges.end()) {
+    pd << ", " << (*it++);
   }
-  aDescr += "])";
-
-  aFunction->SetDescription(aDescr);
+  pd << "])";
 
   SetErrorCode(OK);
   return aFillet;
@@ -230,22 +242,16 @@ Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFaces
   }
 
   //Make a Python command
-  TCollection_AsciiString anEntry, aDescr("");
-  TDF_Tool::Entry(aFillet->GetEntry(), anEntry);
-  aDescr = anEntry + " = ILocalOperations.MakeFilletFaces(";
-  TDF_Tool::Entry(theShape->GetEntry(), anEntry);
-  aDescr += (anEntry+", ");
-  aDescr += (TCollection_AsciiString(theR)+", [");
+  GEOM::TPythonDump pd (aFunction);
+  pd << aFillet << " = geompy.MakeFillet(" << theShape
+    << ", " << theR << ", geompy.ShapeType[\"FACE\"], [";
+
   it = theFaces.begin();
-  aDescr += (TCollection_AsciiString(*it)+", ");
-  it++;
-  for (; it != theFaces.end(); it++) {
-    aDescr += ", ";
-    aDescr += TCollection_AsciiString(*it);
+  pd << (*it++);
+  while (it != theFaces.end()) {
+    pd << ", " << (*it++);
   }
-  aDescr += "])";
-
-  aFunction->SetDescription(aDescr);
+  pd << "])";
 
   SetErrorCode(OK);
   return aFillet;
@@ -293,15 +299,8 @@ Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Objec
   }
 
   //Make a Python command
-  TCollection_AsciiString anEntry, aDescr("");
-  TDF_Tool::Entry(aChamfer->GetEntry(), anEntry);
-  aDescr += anEntry;
-  aDescr += " = ILocalOperations.MakeChamferAll(";
-  TDF_Tool::Entry(theShape->GetEntry(), anEntry);
-  aDescr += (anEntry+", ");
-  aDescr += (TCollection_AsciiString(theD)+")");
-
-  aFunction->SetDescription(aDescr);
+  GEOM::TPythonDump(aFunction) << aChamfer << " = geompy.MakeChamferAll("
+                               << theShape << ", " << theD << ")";
 
   SetErrorCode(OK);
   return aChamfer;
@@ -354,18 +353,9 @@ Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
   }
 
   //Make a Python command
-  TCollection_AsciiString anEntry, aDescr("");
-  TDF_Tool::Entry(aChamfer->GetEntry(), anEntry);
-  aDescr += anEntry;
-  aDescr += " = ILocalOperations.MakeChamferEdge(";
-  TDF_Tool::Entry(theShape->GetEntry(), anEntry);
-  aDescr += (anEntry+", ");
-  aDescr += (TCollection_AsciiString(theD1)+", ");
-  aDescr += (TCollection_AsciiString(theD2)+", ");
-  aDescr += (TCollection_AsciiString(theFace1)+", ");
-  aDescr += (TCollection_AsciiString(theFace2)+")");
-
-  aFunction->SetDescription(aDescr);
+  GEOM::TPythonDump(aFunction) << aChamfer
+    << " = geompy.MakeChamferEdge(" << theShape << ", " << theD1
+      << ", " << theD2 << ", " << theFace1 << ", " << theFace2 << ")";
 
   SetErrorCode(OK);
   return aChamfer;
@@ -424,24 +414,16 @@ Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
   }
 
   //Make a Python command
-  TCollection_AsciiString anEntry, aDescr("");
-  TDF_Tool::Entry(aChamfer->GetEntry(), anEntry);
-  aDescr += anEntry;
-  aDescr += " = ILocalOperations.MakeChamferFaces(";
-  TDF_Tool::Entry(theShape->GetEntry(), anEntry);
-  aDescr += (anEntry+", ");
-  aDescr += (TCollection_AsciiString(theD1)+", ");
-  aDescr += (TCollection_AsciiString(theD2)+", [");
+  GEOM::TPythonDump pd (aFunction);
+  pd << aChamfer << " = geompy.MakeChamferFaces(" << theShape
+    << ", " << theD1 << ", " << theD2 << ", [";
+
   it = theFaces.begin();
-  aDescr += (TCollection_AsciiString(*it)+", ");
-  it++;
-  for (; it != theFaces.end(); it++) {
-    aDescr += ", ";
-    aDescr += TCollection_AsciiString(*it);
+  pd << (*it++);
+  while (it != theFaces.end()) {
+    pd << ", " << (*it++);
   }
-  aDescr += "])";
-
-  aFunction->SetDescription(aDescr);
+  pd << "])";
 
   SetErrorCode(OK);
   return aChamfer;
@@ -493,17 +475,9 @@ Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object
   }
 
   //Make a Python command
-  TCollection_AsciiString anEntry, aDescr("");
-  TDF_Tool::Entry(aChamfer->GetEntry(), anEntry);
-  aDescr += anEntry;
-  aDescr += " = ILocalOperations.MakeArchimede(";
-  TDF_Tool::Entry(theShape->GetEntry(), anEntry);
-  aDescr += (anEntry+", ");
-  aDescr += (TCollection_AsciiString(theWeight)+", ");
-  aDescr += (TCollection_AsciiString(theWaterDensity)+", ");
-  aDescr += (TCollection_AsciiString(theMeshingDeflection)+")");
-
-  aFunction->SetDescription(aDescr);
+  GEOM::TPythonDump(aFunction) << aChamfer
+    << " = geompy.Archimede(" << theShape << ", " << theWeight << ", "
+      << theWaterDensity << ", " << theMeshingDeflection << ")";
 
   SetErrorCode(OK);
   return aChamfer;
@@ -538,17 +512,17 @@ Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object
 {
   SetErrorCode(KO);
 
-  TopoDS_Shape aShape = theShape->GetValue();
-  TopoDS_Shape aSubShape = theSubShape->GetValue();
-
-  if (aShape.IsNull() || aSubShape.IsNull()) return -1;
+  Standard_Integer anInd = -1;
+  GEOM_Engine* anEngine = GetEngine();
+  //GEOMImpl_Gen* aGen = dynamic_cast<GEOMImpl_Gen*>(anEngine);
+  GEOMImpl_Gen* aGen = (GEOMImpl_Gen*)anEngine;
 
-  TopTools_IndexedMapOfShape anIndices;
-  TopExp::MapShapes(aShape, anIndices);
-  if (anIndices.Contains(aSubShape)) {
-    SetErrorCode(OK);
-    return anIndices.FindIndex(aSubShape);
+  if (aGen) {
+    GEOMImpl_IShapesOperations* anIShapesOperations =
+      aGen->GetIShapesOperations(GetDocID());
+    anInd = anIShapesOperations->GetSubShapeIndex(theShape, theSubShape);
+    SetErrorCode(anIShapesOperations->GetErrorCode());
   }
 
-  return -1;
+  return anInd;
 }