Salome HOME
RNC: IMP EDF 1542: Added the functionnality MakeVertexOnCurveByLength that allows...
[modules/geom.git] / src / GEOM_I / GEOM_IGroupOperations_i.cc
index 25ca4a6616f59c281531f05a4d9ccdd29c5a8164..e3cdcb2dc5674efc9687b3c2141eae162cf4f4ec 100644 (file)
@@ -1,3 +1,25 @@
+//  Copyright (C) 2007-2010  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 +40,8 @@
  */
 //=============================================================================
 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 +62,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,40 +90,33 @@ 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);
-
-  return;
 }
 
 //=============================================================================
@@ -110,16 +125,13 @@ void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA
  */
 //=============================================================================
 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
-                                        const GEOM::ListOfGO& theSubShapes) 
+                                         const GEOM::ListOfGO& theSubShapes)
 {
   //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;
 
   //Get sub-shape to add
@@ -127,16 +139,13 @@ void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
 
   int ind, aLen = theSubShapes.length();
   for (ind = 0; ind < aLen; ind++) {
-    if (theSubShapes[ind] == NULL) return;
-    Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
-      (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
+    Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
     if (aSh.IsNull()) return;
     aSubShapes->Append(aSh);
   }
 
   //Perform the operation
   GetOperations()->UnionList(aGroupRef, aSubShapes);
-  return;
 }
 
 //=============================================================================
@@ -145,16 +154,13 @@ void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
  */
 //=============================================================================
 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
-                                             const GEOM::ListOfGO& theSubShapes) 
+                                              const GEOM::ListOfGO& theSubShapes)
 {
   //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;
 
   //Get sub-shape to remove
@@ -162,16 +168,13 @@ void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
 
   int ind, aLen = theSubShapes.length();
   for (ind = 0; ind < aLen; ind++) {
-    if (theSubShapes[ind] == NULL) return;
-    Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
-      (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
+    Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
     if (aSh.IsNull()) return;
     aSubShapes->Append(aSh);
   }
 
   //Perform the operation
   GetOperations()->DifferenceList(aGroupRef, aSubShapes);
-  return;
 }
 
 //=============================================================================
@@ -180,16 +183,13 @@ void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
  */
 //=============================================================================
 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr   theGroup,
-                                       const GEOM::ListOfLong& theSubShapes) 
+                                        const GEOM::ListOfLong& theSubShapes)
 {
   //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;
 
   //Get sub-shape to add
@@ -211,16 +211,13 @@ void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr   theGroup,
  */
 //=============================================================================
 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr   theGroup,
-                                            const GEOM::ListOfLong& theSubShapes) 
+                                             const GEOM::ListOfLong& theSubShapes)
 {
   //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;
 
   //Get sub-shape to remove
@@ -240,17 +237,14 @@ void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr   theGroup,
 /*!
  *  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);
@@ -260,7 +254,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;
@@ -268,10 +262,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);
@@ -284,7 +276,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;
@@ -292,20 +284,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();
 }
-