Back to index

salome-geom  6.5.0
GEOM_IGroupOperations_i.cc
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <Standard_Stream.hxx>
00024 
00025 #include "GEOM_IGroupOperations_i.hh"
00026 
00027 #include "utilities.h"
00028 #include "OpUtil.hxx"
00029 #include "Utils_ExceptHandlers.hxx"
00030 
00031 #include "GEOM_Engine.hxx"
00032 #include "GEOM_Object.hxx"
00033 
00034 #include <TColStd_HArray1OfInteger.hxx>
00035 #include <TopAbs.hxx>
00036 
00037 //=============================================================================
00041 //=============================================================================
00042 GEOM_IGroupOperations_i::GEOM_IGroupOperations_i (PortableServer::POA_ptr thePOA,
00043                                                   GEOM::GEOM_Gen_ptr theEngine,
00044                                                   ::GEOMImpl_IGroupOperations* theImpl)
00045      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
00046 {
00047   MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
00048 }
00049 
00050 //=============================================================================
00054 //=============================================================================
00055 GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
00056 {
00057   MESSAGE("GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i");
00058 }
00059 
00060 
00061 //=============================================================================
00065 //=============================================================================
00066 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape,
00067                                                            CORBA::Long theShapeType)
00068 {
00069   GEOM::GEOM_Object_var aGEOMObject;
00070 
00071   //Set a not done flag
00072   GetOperations()->SetNotDone();
00073 
00074   if (theShapeType < 0) return aGEOMObject._retn();
00075 
00076   //Get the reference shape
00077   Handle(GEOM_Object) aShapeRef = GetObjectImpl(theMainShape);
00078   if (aShapeRef.IsNull()) return aGEOMObject._retn();
00079 
00080   //Create the Fillet
00081   Handle(GEOM_Object) anObject = GetOperations()->CreateGroup(aShapeRef, (TopAbs_ShapeEnum)theShapeType);
00082   if (!GetOperations()->IsDone() || anObject.IsNull())
00083     return aGEOMObject._retn();
00084 
00085   return GetObject(anObject);
00086 }
00087 
00088 //=============================================================================
00092 //=============================================================================
00093 void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
00094 {
00095   //Set a not done flag
00096   GetOperations()->SetNotDone();
00097 
00098   //Get the reference group
00099   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
00100   if (aGroupRef.IsNull()) return;
00101 
00102   GetOperations()->AddObject(aGroupRef, theSubShapeId);
00103 }
00104 
00105 //=============================================================================
00109 //=============================================================================
00110 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
00111 {
00112   //Set a not done flag
00113   GetOperations()->SetNotDone();
00114 
00115   //Get the reference group
00116   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
00117   if (aGroupRef.IsNull()) return;
00118 
00119   GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
00120 }
00121 
00122 //=============================================================================
00126 //=============================================================================
00127 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
00128                                          const GEOM::ListOfGO& theSubShapes)
00129 {
00130   //Set a not done flag
00131   GetOperations()->SetNotDone();
00132 
00133   //Get the reference group
00134   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
00135   if (aGroupRef.IsNull()) return;
00136 
00137   //Get sub-shape to add
00138   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
00139 
00140   int ind, aLen = theSubShapes.length();
00141   for (ind = 0; ind < aLen; ind++) {
00142     Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
00143     if (aSh.IsNull()) return;
00144     aSubShapes->Append(aSh);
00145   }
00146 
00147   //Perform the operation
00148   GetOperations()->UnionList(aGroupRef, aSubShapes);
00149 }
00150 
00151 //=============================================================================
00155 //=============================================================================
00156 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
00157                                               const GEOM::ListOfGO& theSubShapes)
00158 {
00159   //Set a not done flag
00160   GetOperations()->SetNotDone();
00161 
00162   //Get the reference group
00163   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
00164   if (aGroupRef.IsNull()) return;
00165 
00166   //Get sub-shape to remove
00167   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
00168 
00169   int ind, aLen = theSubShapes.length();
00170   for (ind = 0; ind < aLen; ind++) {
00171     Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
00172     if (aSh.IsNull()) return;
00173     aSubShapes->Append(aSh);
00174   }
00175 
00176   //Perform the operation
00177   GetOperations()->DifferenceList(aGroupRef, aSubShapes);
00178 }
00179 
00180 //=============================================================================
00184 //=============================================================================
00185 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr   theGroup,
00186                                         const GEOM::ListOfLong& theSubShapes)
00187 {
00188   //Set a not done flag
00189   GetOperations()->SetNotDone();
00190 
00191   //Get the reference group
00192   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
00193   if (aGroupRef.IsNull()) return;
00194 
00195   //Get sub-shape to add
00196   Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
00197 
00198   int ind, aLen = theSubShapes.length();
00199   for (ind = 0; ind < aLen; ind++) {
00200     aSubShapes->Append(theSubShapes[ind]);
00201   }
00202 
00203   //Perform the operation
00204   GetOperations()->UnionIDs(aGroupRef, aSubShapes);
00205   return;
00206 }
00207 
00208 //=============================================================================
00212 //=============================================================================
00213 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr   theGroup,
00214                                              const GEOM::ListOfLong& theSubShapes)
00215 {
00216   //Set a not done flag
00217   GetOperations()->SetNotDone();
00218 
00219   //Get the reference group
00220   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
00221   if (aGroupRef.IsNull()) return;
00222 
00223   //Get sub-shape to remove
00224   Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
00225 
00226   int ind, aLen = theSubShapes.length();
00227   for (ind = 0; ind < aLen; ind++) {
00228     aSubShapes->Append(theSubShapes[ind]);
00229   }
00230 
00231   //Perform the operation
00232   GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
00233   return;
00234 }
00235 
00236 //=============================================================================
00240 //=============================================================================
00241 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
00242 {
00243   //Set a not done flag
00244   GetOperations()->SetNotDone();
00245 
00246   //Get the reference group
00247   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
00248   if (aGroupRef.IsNull()) return -1;
00249 
00250   return GetOperations()->GetType(aGroupRef);
00251 }
00252 
00253 //=============================================================================
00257 //=============================================================================
00258 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
00259 {
00260   GEOM::GEOM_Object_var aGEOMObject;
00261 
00262   //Set a not done flag
00263   GetOperations()->SetNotDone();
00264 
00265   //Get the reference group
00266   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
00267   if (aGroupRef.IsNull()) return aGEOMObject._retn();
00268 
00269   Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
00270   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
00271 
00272   return GetObject(anObject);
00273 }
00274 
00275 //=============================================================================
00279 //=============================================================================
00280 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
00281 {
00282   GEOM::ListOfLong_var aList;
00283 
00284   //Set a not done flag
00285   GetOperations()->SetNotDone();
00286 
00287   //Get the reference group
00288   Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
00289   if (aGroupRef.IsNull()) return aList._retn();
00290 
00291   aList = new GEOM::ListOfLong;
00292 
00293   Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
00294   if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
00295 
00296   aList->length(aSeq->Length());
00297   for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
00298 
00299   return aList._retn();
00300 }