Salome HOME
Notebook: processed creation of objects dependent on another objects.
[modules/geom.git] / src / GEOM_I / GEOM_IGroupOperations_i.cc
index 3ff5c9bb63aac078e1641152ce09829468f09d5c..ec64e411c63b96c1b5ba983169713bb5ab00666f 100644 (file)
@@ -1,4 +1,25 @@
-using namespace std; 
+//  Copyright (C) 2007-2008  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
+//
+//  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 "GEOM_IGroupOperations_i.hh"
 
@@ -18,8 +39,8 @@ using namespace std;
  */
 //=============================================================================
 GEOM_IGroupOperations_i::GEOM_IGroupOperations_i (PortableServer::POA_ptr thePOA,
-                                                 GEOM::GEOM_Gen_ptr theEngine,
-                                                 ::GEOMImpl_IGroupOperations* theImpl)
+                                                  GEOM::GEOM_Gen_ptr theEngine,
+                                                  ::GEOMImpl_IGroupOperations* theImpl)
      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
 {
   MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
@@ -40,19 +61,19 @@ GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
 /*!
  *  CreateGroup
  */
-//============================================================================= 
-GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape, CORBA::Long theShapeType)
+//=============================================================================
+GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape,
+                                                           CORBA::Long theShapeType)
 {
   GEOM::GEOM_Object_var aGEOMObject;
 
   //Set a not done flag
   GetOperations()->SetNotDone();
 
-  if (theMainShape == NULL || theShapeType < 0) return aGEOMObject._retn();
+  if (theShapeType < 0) return aGEOMObject._retn();
 
   //Get the reference shape
-  Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
-
+  Handle(GEOM_Object) aShapeRef = GetObjectImpl(theMainShape);
   if (aShapeRef.IsNull()) return aGEOMObject._retn();
 
   //Create the Fillet
@@ -68,39 +89,146 @@ GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr
  *  AddObject
  */
 //=============================================================================
-void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId) 
+void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
 {
   //Set a not done flag
   GetOperations()->SetNotDone();
 
-  if (theGroup == NULL) return;
-
   //Get the reference group
-  Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
+  Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
   if (aGroupRef.IsNull()) return;
 
   GetOperations()->AddObject(aGroupRef, theSubShapeId);
-  return;
 }
 
 //=============================================================================
 /*!
  *  RemoveObject
  */
-//============================================================================= 
-void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId) 
+//=============================================================================
+void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
 {
   //Set a not done flag
   GetOperations()->SetNotDone();
 
-  if (theGroup == NULL) return;
-
   //Get the reference group
-  Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
+  Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
   if (aGroupRef.IsNull()) return;
 
   GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
+}
+
+//=============================================================================
+/*!
+ *  UnionList
+ */
+//=============================================================================
+void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
+                                         const GEOM::ListOfGO& theSubShapes)
+{
+  //Set a not done flag
+  GetOperations()->SetNotDone();
+
+  //Get the reference group
+  Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
+  if (aGroupRef.IsNull()) return;
+
+  //Get sub-shape to add
+  Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
 
+  int ind, aLen = theSubShapes.length();
+  for (ind = 0; ind < aLen; ind++) {
+    Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
+    if (aSh.IsNull()) return;
+    aSubShapes->Append(aSh);
+  }
+
+  //Perform the operation
+  GetOperations()->UnionList(aGroupRef, aSubShapes);
+}
+
+//=============================================================================
+/*!
+ *  DifferenceList
+ */
+//=============================================================================
+void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
+                                              const GEOM::ListOfGO& theSubShapes)
+{
+  //Set a not done flag
+  GetOperations()->SetNotDone();
+
+  //Get the reference group
+  Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
+  if (aGroupRef.IsNull()) return;
+
+  //Get sub-shape to remove
+  Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
+
+  int ind, aLen = theSubShapes.length();
+  for (ind = 0; ind < aLen; ind++) {
+    Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
+    if (aSh.IsNull()) return;
+    aSubShapes->Append(aSh);
+  }
+
+  //Perform the operation
+  GetOperations()->DifferenceList(aGroupRef, aSubShapes);
+}
+
+//=============================================================================
+/*!
+ *  UnionIDs
+ */
+//=============================================================================
+void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr   theGroup,
+                                        const GEOM::ListOfLong& theSubShapes)
+{
+  //Set a not done flag
+  GetOperations()->SetNotDone();
+
+  //Get the reference group
+  Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
+  if (aGroupRef.IsNull()) return;
+
+  //Get sub-shape to add
+  Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
+
+  int ind, aLen = theSubShapes.length();
+  for (ind = 0; ind < aLen; ind++) {
+    aSubShapes->Append(theSubShapes[ind]);
+  }
+
+  //Perform the operation
+  GetOperations()->UnionIDs(aGroupRef, aSubShapes);
+  return;
+}
+
+//=============================================================================
+/*!
+ *  DifferenceIDs
+ */
+//=============================================================================
+void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr   theGroup,
+                                             const GEOM::ListOfLong& theSubShapes)
+{
+  //Set a not done flag
+  GetOperations()->SetNotDone();
+
+  //Get the reference group
+  Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
+  if (aGroupRef.IsNull()) return;
+
+  //Get sub-shape to remove
+  Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
+
+  int ind, aLen = theSubShapes.length();
+  for (ind = 0; ind < aLen; ind++) {
+    aSubShapes->Append(theSubShapes[ind]);
+  }
+
+  //Perform the operation
+  GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
   return;
 }
 
@@ -108,17 +236,14 @@ void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA
 /*!
  *  GetType
  */
-//============================================================================= 
+//=============================================================================
 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
 {
   //Set a not done flag
   GetOperations()->SetNotDone();
 
-  if (theGroup == NULL) return -1;
-
   //Get the reference group
-  Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
-
+  Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
   if (aGroupRef.IsNull()) return -1;
 
   return GetOperations()->GetType(aGroupRef);
@@ -128,7 +253,7 @@ CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
 /*!
  *  GetMainShape
  */
-//============================================================================= 
+//=============================================================================
 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
 {
   GEOM::GEOM_Object_var aGEOMObject;
@@ -136,10 +261,8 @@ GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_pt
   //Set a not done flag
   GetOperations()->SetNotDone();
 
-  if (theGroup == NULL) return aGEOMObject._retn();
-
   //Get the reference group
-  Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
+  Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
   if (aGroupRef.IsNull()) return aGEOMObject._retn();
 
   Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
@@ -152,7 +275,7 @@ GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_pt
 /*!
  *  GetObjects
  */
-//============================================================================= 
+//=============================================================================
 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
 {
   GEOM::ListOfLong_var aList;
@@ -160,20 +283,17 @@ GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theG
   //Set a not done flag
   GetOperations()->SetNotDone();
 
-  if (theGroup == NULL) return aList._retn();
-
   //Get the reference group
-  Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
+  Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
   if (aGroupRef.IsNull()) return aList._retn();
 
-  aList = new GEOM::ListOfLong;    
+  aList = new GEOM::ListOfLong;
 
   Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
   if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
-    
+
   aList->length(aSeq->Length());
   for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
 
   return aList._retn();
 }
-