Back to index

salome-geom  6.5.0
GEOM_IBooleanOperations_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_IBooleanOperations_i.hh"
00026 
00027 #include "utilities.h"
00028 #include "OpUtil.hxx"
00029 
00030 #include "GEOM_Engine.hxx"
00031 #include "GEOM_Object.hxx"
00032 
00033 #include <TColStd_HArray1OfInteger.hxx>
00034 
00035 //=============================================================================
00039 //=============================================================================
00040 GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i (PortableServer::POA_ptr thePOA,
00041                                                       GEOM::GEOM_Gen_ptr theEngine,
00042                                                       ::GEOMImpl_IBooleanOperations* theImpl)
00043 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
00044 {
00045   MESSAGE("GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i");
00046 }
00047 
00048 //=============================================================================
00052 //=============================================================================
00053 GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i()
00054 {
00055   MESSAGE("GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i");
00056 }
00057 
00058 
00059 //=============================================================================
00063 //=============================================================================
00064 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean
00065                                                  (GEOM::GEOM_Object_ptr theShape1,
00066                                                   GEOM::GEOM_Object_ptr theShape2,
00067                                                   CORBA::Long           theOp)
00068 {
00069   GEOM::GEOM_Object_var aGEOMObject;
00070 
00071   //Set a not done flag
00072   GetOperations()->SetNotDone();
00073 
00074   //Get the reference shapes
00075   Handle(GEOM_Object) aSh1 = GetObjectImpl(theShape1);
00076   Handle(GEOM_Object) aSh2 = GetObjectImpl(theShape2);
00077 
00078   if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
00079 
00080   // Make Boolean
00081   Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
00082   if (!GetOperations()->IsDone() || anObject.IsNull())
00083     return aGEOMObject._retn();
00084 
00085   return GetObject(anObject);
00086 }
00087 
00088 //=============================================================================
00092 //=============================================================================
00093 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
00094                                       (const GEOM::ListOfGO&   theShapes,
00095                                        const GEOM::ListOfGO&   theTools,
00096                                        const GEOM::ListOfGO&   theKeepIns,
00097                                        const GEOM::ListOfGO&   theRemoveIns,
00098                                        CORBA::Short            theLimit,
00099                                        CORBA::Boolean          theRemoveWebs,
00100                                        const GEOM::ListOfLong& theMaterials,
00101                                        CORBA::Short theKeepNonlimitShapes)
00102 {
00103   GEOM::GEOM_Object_var aGEOMObject;
00104 
00105   //Set a not done flag
00106   GetOperations()->SetNotDone();
00107 
00108   int ind, aLen;
00109   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
00110   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
00111   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
00112   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
00113   Handle(TColStd_HArray1OfInteger) aMaterials;
00114 
00115   //Get the shapes
00116   aLen = theShapes.length();
00117   for (ind = 0; ind < aLen; ind++) {
00118     Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
00119     if (aSh.IsNull()) return aGEOMObject._retn();
00120     aShapes->Append(aSh);
00121   }
00122 
00123   //Get the tools
00124   aLen = theTools.length();
00125   for (ind = 0; ind < aLen; ind++) {
00126     Handle(GEOM_Object) aSh = GetObjectImpl(theTools[ind]);
00127     if (aSh.IsNull()) return aGEOMObject._retn();
00128     aTools->Append(aSh);
00129   }
00130 
00131   //Get the keep inside shapes
00132   aLen = theKeepIns.length();
00133   for (ind = 0; ind < aLen; ind++) {
00134     Handle(GEOM_Object) aSh = GetObjectImpl(theKeepIns[ind]);
00135     if (aSh.IsNull()) return aGEOMObject._retn();
00136     aKeepIns->Append(aSh);
00137   }
00138 
00139   //Get the remove inside shapes
00140   aLen = theRemoveIns.length();
00141   for (ind = 0; ind < aLen; ind++) {
00142     Handle(GEOM_Object) aSh = GetObjectImpl(theRemoveIns[ind]);
00143     if (aSh.IsNull()) return aGEOMObject._retn();
00144     aRemIns->Append(aSh);
00145   }
00146 
00147   //Get the materials
00148   aLen = theMaterials.length();
00149   if ( aLen ) {
00150     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
00151     for (ind = 0; ind < aLen; ind++) {
00152       aMaterials->SetValue(ind+1, theMaterials[ind]);
00153     }
00154   }
00155 
00156   // Make Partition
00157   Handle(GEOM_Object) anObject =
00158     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
00159                                    theLimit, theRemoveWebs, aMaterials,
00160                                    theKeepNonlimitShapes,
00161                                    /*PerformSelfIntersections*/Standard_True);
00162   if (!GetOperations()->IsDone() || anObject.IsNull())
00163     return aGEOMObject._retn();
00164 
00165   return GetObject(anObject);
00166 }
00167 
00168 //=============================================================================
00172 //=============================================================================
00173 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
00174                                       (const GEOM::ListOfGO&   theShapes,
00175                                        const GEOM::ListOfGO&   theTools,
00176                                        const GEOM::ListOfGO&   theKeepIns,
00177                                        const GEOM::ListOfGO&   theRemoveIns,
00178                                        CORBA::Short            theLimit,
00179                                        CORBA::Boolean          theRemoveWebs,
00180                                        const GEOM::ListOfLong& theMaterials,
00181                                        CORBA::Short theKeepNonlimitShapes)
00182 {
00183   GEOM::GEOM_Object_var aGEOMObject;
00184 
00185   //Set a not done flag
00186   GetOperations()->SetNotDone();
00187 
00188   int ind, aLen;
00189   Handle(TColStd_HSequenceOfTransient) aShapes  = new TColStd_HSequenceOfTransient;
00190   Handle(TColStd_HSequenceOfTransient) aTools   = new TColStd_HSequenceOfTransient;
00191   Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
00192   Handle(TColStd_HSequenceOfTransient) aRemIns  = new TColStd_HSequenceOfTransient;
00193   Handle(TColStd_HArray1OfInteger) aMaterials;
00194 
00195   //Get the shapes
00196   aLen = theShapes.length();
00197   for (ind = 0; ind < aLen; ind++) {
00198     Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
00199     if (aSh.IsNull()) return aGEOMObject._retn();
00200     aShapes->Append(aSh);
00201   }
00202 
00203   //Get the tools
00204   aLen = theTools.length();
00205   for (ind = 0; ind < aLen; ind++) {
00206     Handle(GEOM_Object) aSh = GetObjectImpl(theTools[ind]);
00207     if (aSh.IsNull()) return aGEOMObject._retn();
00208     aTools->Append(aSh);
00209   }
00210 
00211   //Get the keep inside shapes
00212   aLen = theKeepIns.length();
00213   for (ind = 0; ind < aLen; ind++) {
00214     Handle(GEOM_Object) aSh = GetObjectImpl(theKeepIns[ind]);
00215     if (aSh.IsNull()) return aGEOMObject._retn();
00216     aKeepIns->Append(aSh);
00217   }
00218 
00219   //Get the remove inside shapes
00220   aLen = theRemoveIns.length();
00221   for (ind = 0; ind < aLen; ind++) {
00222     Handle(GEOM_Object) aSh = GetObjectImpl(theRemoveIns[ind]);
00223     if (aSh.IsNull()) return aGEOMObject._retn();
00224     aRemIns->Append(aSh);
00225   }
00226 
00227   //Get the materials
00228   aLen = theMaterials.length();
00229   if ( aLen ) {
00230     aMaterials = new TColStd_HArray1OfInteger (1, aLen);
00231     for (ind = 0; ind < aLen; ind++) {
00232       aMaterials->SetValue(ind+1, theMaterials[ind]);
00233     }
00234   }
00235 
00236   // Make Partition
00237   Handle(GEOM_Object) anObject =
00238     GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
00239                                    theLimit, theRemoveWebs, aMaterials,
00240                                    theKeepNonlimitShapes,
00241                                    /*PerformSelfIntersections*/Standard_False);
00242   if (!GetOperations()->IsDone() || anObject.IsNull())
00243     return aGEOMObject._retn();
00244 
00245   return GetObject(anObject);
00246 }
00247 
00248 //=============================================================================
00252 //=============================================================================
00253 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
00254                                                  (GEOM::GEOM_Object_ptr theShape,
00255                                                   GEOM::GEOM_Object_ptr thePlane)
00256 {
00257   GEOM::GEOM_Object_var aGEOMObject;
00258 
00259   //Set a not done flag
00260   GetOperations()->SetNotDone();
00261 
00262   //Get the reference shapes
00263   Handle(GEOM_Object) aSh = GetObjectImpl(theShape);
00264   Handle(GEOM_Object) aPl = GetObjectImpl(thePlane);
00265 
00266   if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
00267 
00268   // Make Half Partition
00269   Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
00270   if (!GetOperations()->IsDone() || anObject.IsNull())
00271     return aGEOMObject._retn();
00272 
00273   return GetObject(anObject);
00274 }