Salome HOME
bos #29468: Advanced geometry features: distance Edge-Edge & Face-Face
[modules/geom.git] / src / GEOM_I / GEOM_Object_i.cc
index 649e2fa2ea2a36d4479418c49afabbb6a478888c..2845379c1978992a416c8ffb51bd838cbf1ed4e6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // 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.
+// 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
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include <Standard_OStream.hxx>
-
-#include <GEOM_Object_i.hh>
-#include <GEOM_ISubShape.hxx>
-#include <GEOMImpl_Types.hxx>
+#include "GEOM_Object_i.hh"
 
-#include "utilities.h"
-#include <fstream>
-#include <sstream>
+#include "GEOM_ISubShape.hxx"
+#include "GEOMImpl_Types.hxx"
+#include "GEOM_BaseDriver.hxx"
 
+#include <utilities.h>
 #include <OpUtil.hxx>
 #include <Utils_ExceptHandlers.hxx>
-#include <TDF_Tool.hxx>
-#include <TDF_Label.hxx>
-#include <TCollection_AsciiString.hxx>
 
-#include <BRepTools_ShapeSet.hxx>
 #include <BRepTools.hxx>
+#include <BRepTools_ShapeSet.hxx>
+#include <Standard_OStream.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TDF_Label.hxx>
+#include <TDF_Tool.hxx>
+#include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
 #include <TopAbs.hxx>
 #include <TopoDS_Iterator.hxx>
 
-#ifdef WNT
+#include <fstream>
+#include <sstream>
+
+#include <Standard_Failure.hxx>
+#include <Standard_ErrorHandler.hxx>
+
+#ifdef _DEBUG_
+#include <typeinfo>
+#endif
+
+#ifdef WIN32
 #pragma warning( disable:4786 )
 #endif
 
 //=============================================================================
 
 GEOM_Object_i::GEOM_Object_i (PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine,
-                             Handle(GEOM_Object) theImpl)
-: SALOME::GenericObj_i( thePOA ), _engine(theEngine), _impl(theImpl)
+                             Handle(::GEOM_Object) theImpl) :
+  SALOME::GenericObj_i( thePOA ),
+  GEOM_BaseObject_i( thePOA, theEngine, theImpl ),
+  _impl( theImpl )
 {
 }
 
@@ -65,44 +76,7 @@ GEOM_Object_i::GEOM_Object_i (PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr
 
 GEOM_Object_i::~GEOM_Object_i()
 {
-  MESSAGE("GEOM_Object_i::~GEOM_Object_i");
-  GEOM_Engine::GetEngine()->RemoveObject(_impl);
-}
-
-
-//=============================================================================
-/*!
- *  GetEntry
- */
-//=============================================================================
-char* GEOM_Object_i::GetEntry()
-{
-  const TDF_Label& aLabel = _impl->GetEntry();
-  TCollection_AsciiString anEntry;
-  TDF_Tool::Entry(aLabel, anEntry);
-  const char* anEntstr = anEntry.ToCString();
-  return CORBA::string_dup(anEntstr);
-}
-
-//=============================================================================
-/*!
- *  GetStudyID
- */
-//=============================================================================
-CORBA::Long GEOM_Object_i::GetStudyID()
-{
-   return _impl->GetDocID();
-}
-
-
-//=============================================================================
-/*!
- *  GetType
- */
-//=============================================================================
-CORBA::Long GEOM_Object_i::GetType()
-{
-  return _impl->GetType();
+  //MESSAGE("GEOM_Object_i::~GEOM_Object_i");
 }
 
 //=============================================================================
@@ -185,28 +159,45 @@ GEOM::shape_type GEOM_Object_i::GetMaxShapeType()
   return getMinMaxShapeType( _impl->GetValue(), false );
 }
 
-//=============================================================================
+//================================================================================
 /*!
- *  SetName
+ * GetSubShapeName
  */
-//=============================================================================
-void GEOM_Object_i::SetName(const char* theName)
-{
-  _impl->SetName(theName);
-}
-
-
-//=============================================================================
-/*!
- *  GetName
- */
-//=============================================================================
-char* GEOM_Object_i::GetName()
-{
-  char* aName = _impl->GetName();
-  if (aName)
-    return aName; // this is already copy of pointer (see implementation of _impl)
-  return CORBA::string_dup("");
+//================================================================================
+
+char* GEOM_Object_i::GetSubShapeName(CORBA::Long subID)
+{
+  CORBA::String_var name("");
+
+  Handle(::GEOM_Function) aMainFun = _impl->GetLastFunction();
+  if ( aMainFun.IsNull() ) return name._retn();
+
+  const TDataStd_ListOfExtendedString& aListEntries = aMainFun->GetSubShapeReferences();
+  TDataStd_ListIteratorOfListOfExtendedString anIt( aListEntries );
+  for (; anIt.More(); anIt.Next())
+  {
+    TCollection_AsciiString anEntry = anIt.Value();
+    Handle(::GEOM_BaseObject) anObj =
+      GEOM_Engine::GetEngine()->GetObject( anEntry.ToCString(), false );
+    if ( anObj.IsNull() ) continue;
+
+    TCollection_AsciiString aSubName = anObj->GetName();
+    if ( aSubName.IsEmpty() ) continue;
+
+    Handle(::GEOM_Function) aFun = anObj->GetLastFunction();
+    if ( aFun.IsNull() ) continue;
+  
+    GEOM_ISubShape ISS( aFun );
+    Handle(TColStd_HArray1OfInteger) subIDs = ISS.GetIndices();
+    if ( subIDs.IsNull() || subIDs->Length() != 1 ) continue;
+
+    if ( subIDs->Value( subIDs->Lower() ) == subID )
+    {
+      name = aSubName.ToCString();
+      break;
+    }
+  }
+  return name._retn();
 }
 
 //=============================================================================
@@ -323,91 +314,6 @@ CORBA::Long GEOM_Object_i::GetMarkerTexture()
   return _impl->GetMarkerTexture();
 }
 
-
-//=============================================================================
-/*!
- *  SetStudyEntry
- */
-//=============================================================================
-void GEOM_Object_i::SetStudyEntry(const char* theEntry)
-{
-  _impl->SetAuxData(theEntry);
-}
-
-
-//=============================================================================
-/*!
- *  GetStudyEntry
- */
-//=============================================================================
-char* GEOM_Object_i::GetStudyEntry()
-{
-  TCollection_AsciiString anEntry = _impl->GetAuxData();
-  if(!anEntry.IsEmpty()) return CORBA::string_dup(anEntry.ToCString());
-  return CORBA::string_dup("");
-}
-
-
-//=============================================================================
-/*!
- *  GetDependency
- */
-//=============================================================================
-GEOM::ListOfGO* GEOM_Object_i::GetDependency()
-{
-  GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
-  aList->length(0);
-
-  Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllDependency();
-  if (aSeq.IsNull()) return aList._retn();
-  int aLength = aSeq->Length();
-  if (aLength == 0) return aList._retn();
-
-  aList->length(aLength);
-
-  TCollection_AsciiString anEntry;
-
-  for (int i = 1; i<=aLength; i++) {
-    Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
-    if (anObj.IsNull()) continue;
-    TDF_Tool::Entry(anObj->GetEntry(), anEntry);
-    GEOM::GEOM_Object_var obj = _engine->GetObject(anObj->GetDocID(), anEntry.ToCString());
-    aList[i-1] = obj;
-  }
-
-  return aList._retn();
-}
-
-//=============================================================================
-/*!
- * GetLastDependency
- */
-//=============================================================================
-GEOM::ListOfGO* GEOM_Object_i::GetLastDependency()
-{
-  GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
-  aList->length(0);
-
-  Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetLastDependency();
-  if (aSeq.IsNull()) return aList._retn();
-  int aLength = aSeq->Length();
-  if (aLength == 0) return aList._retn();
-
-  aList->length(aLength);
-
-  TCollection_AsciiString anEntry;
-
-  for (int i = 1; i<=aLength; i++) {
-     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
-     if (anObj.IsNull()) continue;
-     TDF_Tool::Entry(anObj->GetEntry(), anEntry);
-     GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
-     aList[i-1] = obj;
-  }
-
-  return aList._retn();
-}
-
 //=================================================================================
 // function : GetShapeStream
 // Transfer resulting shape to client as sequence of bytes
@@ -453,7 +359,7 @@ GEOM::ListOfLong* GEOM_Object_i::GetSubShapeIndices()
   GEOM::ListOfLong_var anIndices = new GEOM::ListOfLong;
 
   if(!_impl->IsMainShape()) {
-    Handle(GEOM_Function) aFunction = _impl->GetLastFunction(); //Get Sub-shape function (always the first (and last)  one)
+    Handle(::GEOM_Function) aFunction = _impl->GetLastFunction(); //Get Sub-shape function (always the first (and last)  one)
     if(aFunction.IsNull()) return anIndices._retn();
     GEOM_ISubShape ISS(aFunction);
     Handle(TColStd_HArray1OfInteger) anArray = ISS.GetIndices();
@@ -478,7 +384,7 @@ GEOM::GEOM_Object_ptr GEOM_Object_i::GetMainShape()
 {
   GEOM::GEOM_Object_var obj;
   if(!_impl->IsMainShape()) {
-    Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get Sub-shape function (always the first (and last)  one)
+    Handle(::GEOM_Function) aFunction = _impl->GetFunction(1); //Get Sub-shape function (always the first (and last)  one)
     if(aFunction.IsNull()) return obj._retn();
     GEOM_ISubShape ISS(aFunction);
 
@@ -488,7 +394,8 @@ GEOM::GEOM_Object_ptr GEOM_Object_i::GetMainShape()
     if(aLabel.IsNull()) return obj._retn();
     TCollection_AsciiString anEntry;
     TDF_Tool::Entry(aLabel, anEntry);
-    return _engine->GetObject(_impl->GetDocID(), anEntry.ToCString());
+    return GEOM::GEOM_Object::_narrow
+      ( _engine->GetObject( anEntry.ToCString()) );
   }
 
   return obj._retn();
@@ -499,25 +406,20 @@ bool GEOM_Object_i::IsShape()
   return !_impl->GetValue().IsNull() && _impl->GetType() != GEOM_MARKER;
 }
 
-bool GEOM_Object_i::IsSame(GEOM::GEOM_Object_ptr other)
+bool GEOM_Object_i::IsSame(GEOM::GEOM_BaseObject_ptr other)
 {
-  TopoDS_Shape thisShape  = _impl->GetValue();
-  TopoDS_Shape otherShape;
-  if ( !CORBA::is_nil( other ) ) {
-    Handle(GEOM_Object) otherObject = GEOM_Engine::GetEngine()->GetObject( other->GetStudyID(), other->GetEntry(), false );
-    if ( !otherObject.IsNull() )
-      otherShape = otherObject->GetValue();
-  }
-  return thisShape.IsSame( otherShape );
-}
+  bool result = false;
 
-void GEOM_Object_i::SetParameters(const char* theParameters)
-{
-  _impl->SetParameters((char*)theParameters);
-}
-
-char* GEOM_Object_i::GetParameters()
-{
-  return CORBA::string_dup(_impl->GetParameters().ToCString());
+  GEOM::GEOM_Object_var shapePtr = GEOM::GEOM_Object::_narrow( other );
+  if ( !CORBA::is_nil( shapePtr ) ) {
+    CORBA::String_var entry = shapePtr->GetEntry();
+    Handle(::GEOM_Object) otherObject = Handle(::GEOM_Object)::DownCast
+      ( GEOM_Engine::GetEngine()->GetObject( entry, false ));
+    if ( !otherObject.IsNull() ) {
+      TopoDS_Shape thisShape  = _impl->GetValue();
+      TopoDS_Shape otherShape = otherObject->GetValue();
+      result = !thisShape.IsNull() && !otherShape.IsNull() && thisShape.IsSame( otherShape );
+    }
+  }
+  return result;
 }
-