Back to index

salome-geom  6.5.0
GEOM_IHealingOperations_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 <list>
00026 
00027 #include "GEOM_IHealingOperations_i.hh"
00028 #include "GEOM_Engine.hxx"
00029 #include "GEOM_Object.hxx"
00030 
00031 #include "utilities.h"
00032 #include "OpUtil.hxx"
00033 #include "Utils_ExceptHandlers.hxx"
00034 #include <Basics_Utils.hxx>
00035 
00036 #include <TColStd_HSequenceOfTransient.hxx>
00037 
00038 //=============================================================================
00042 //=============================================================================
00043 
00044 GEOM_IHealingOperations_i::GEOM_IHealingOperations_i (PortableServer::POA_ptr thePOA,
00045                                                       GEOM::GEOM_Gen_ptr theEngine,
00046                                                       ::GEOMImpl_IHealingOperations* theImpl)
00047 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
00048 {
00049   MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
00050 }
00051 
00052 //=============================================================================
00056 //=============================================================================
00057 
00058 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
00059 {
00060   MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
00061 }
00062 
00063 //=============================================================================
00067 //=============================================================================
00068 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
00069                                           (const GEOM::short_array& theInArray)
00070 {
00071   Handle(TColStd_HArray1OfInteger) anOutArray;
00072   int n = theInArray.length();
00073   if ( n <= 0 )
00074     return anOutArray;
00075   anOutArray = new TColStd_HArray1OfInteger( 1, n );
00076   for (int i = 0; i < n; i++)
00077     anOutArray->SetValue( i+1, theInArray[i] );
00078   return anOutArray;
00079 }
00080 
00081 //=============================================================================
00085 //=============================================================================
00086 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
00087                                          (const GEOM::string_array& theInArray)
00088 {
00089   Handle(TColStd_HArray1OfExtendedString) anOutArray;
00090   int n = theInArray.length();
00091   if ( n <= 0 )
00092     return anOutArray;
00093   anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
00094   char* str;
00095   for ( int i = 0; i < n; i++ )
00096   {
00097     str = CORBA::string_dup( theInArray[i] );
00098     anOutArray->SetValue( i+1, TCollection_ExtendedString( str ) );
00099   }
00100   return anOutArray;
00101 }
00102 
00103 //=============================================================================
00107 //=============================================================================
00108 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
00109                                                                const GEOM::string_array& theOperations,
00110                                                                const GEOM::string_array& theParams,
00111                                                                const GEOM::string_array& theValues)
00112 {
00113   Kernel_Utils::Localizer loc;
00114 
00115   GEOM::GEOM_Object_var aGEOMObject;
00116 
00117   // Set a not done flag
00118   GetOperations()->SetNotDone();
00119 
00120   // Check if theOperations has more than 0 elements and theParams and theValues have the same length
00121   //if (theOperations.length() <= 0 || theParams.length() != theValues.length())
00122   //  return aGEOMObject._retn();
00123 
00124   // Get the object itself
00125   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00126   if (anObject.IsNull())
00127     return aGEOMObject._retn();
00128 
00129   // Perform
00130   Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
00131     Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
00132   if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
00133     return aGEOMObject._retn();
00134 
00135   return GetObject( aNewObject );
00136 }
00137 
00138 //=============================================================================
00142 //=============================================================================
00143 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
00144                                                           GEOM::string_array_out theParams,
00145                                                           GEOM::string_array_out theValues)
00146 {
00147   GEOM::string_array_var anOpArray = new GEOM::string_array();
00148   GEOM::string_array_var aParArray = new GEOM::string_array();
00149   GEOM::string_array_var aValArray = new GEOM::string_array();
00150 
00151   // retrieve the values as stl-lists
00152   std::list<std::string> operationsList, paramsList, valuesList;
00153   GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
00154   const int opSize = operationsList.size(),
00155   parSize = paramsList.size(),
00156   valSize = valuesList.size();
00157 
00158   if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
00159     // allocate the CORBA arrays, sizes == returned lists' sizes
00160     anOpArray->length(opSize);
00161     aParArray->length(parSize);
00162     aValArray->length(valSize);
00163 
00164     // fill the local CORBA arrays with values from lists
00165     std::list<std::string>::iterator opIt, parIt, valIt;
00166     int i = 0;
00167     for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
00168       anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
00169 
00170     for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
00171           parIt != paramsList.end(); i++, ++parIt,++valIt ) {
00172       aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
00173       aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
00174     }
00175   }
00176 
00177   // initialize out-parameters with local arrays
00178   theOperations = anOpArray._retn();
00179   theParams = aParArray._retn();
00180   theValues = aValArray._retn();
00181 }
00182 
00183 //=============================================================================
00187 //=============================================================================
00188 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
00189                                                        GEOM::string_array_out theParams,
00190                                                        GEOM::string_array_out theValues)
00191 {
00192   GEOM::string_array_var aParArray = new GEOM::string_array();
00193   GEOM::string_array_var aValArray = new GEOM::string_array();
00194 
00195   // retrieve the values as stl-lists
00196   std::list<std::string> paramsList, valuesList;
00197   if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
00198     const int parSize = paramsList.size(), valSize = valuesList.size();
00199 
00200     if ( parSize == valSize ) {
00201       aParArray->length(parSize);
00202       aValArray->length(valSize);
00203 
00204       // fill the local CORBA arrays with values from lists
00205       std::list<std::string>::iterator parIt, valIt;
00206       int i;
00207       for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
00208             parIt != paramsList.end(); i++, ++parIt,++valIt ) {
00209         aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
00210         aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
00211       }
00212     }
00213   }
00214 
00215   // initialize out-parameters with local arrays
00216   theParams = aParArray._retn();
00217   theValues = aValArray._retn();
00218 }
00219 
00220 //=============================================================================
00224 //=============================================================================
00225 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
00226                                                                 const GEOM::short_array& theFaces)
00227 {
00228   GEOM::GEOM_Object_var aGEOMObject;
00229 
00230   // Set a not done flag
00231   GetOperations()->SetNotDone();
00232 
00233   // Get the object itself
00234   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00235   if (anObject.IsNull())
00236     return aGEOMObject._retn();
00237 
00238   // if theFaces is empty - it's OK, it means that ALL faces must be removed
00239 
00240   // Perform
00241   Handle(GEOM_Object) aNewObject =
00242     GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
00243   if (!GetOperations()->IsDone() || aNewObject.IsNull())
00244     return aGEOMObject._retn();
00245 
00246   return  GetObject( aNewObject );
00247 }
00248 
00249 //=============================================================================
00253 //=============================================================================
00254 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
00255                                                                const GEOM::short_array& theWires,
00256                                                                CORBA::Boolean isCommonVertex)
00257 {
00258   GEOM::GEOM_Object_var aGEOMObject;
00259 
00260   // Set a not done flag
00261   GetOperations()->SetNotDone();
00262 
00263   // Get the object itself
00264   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00265   if (anObject.IsNull())
00266     return aGEOMObject._retn();
00267 
00268   // Perform
00269   Handle(GEOM_Object) aNewObject =
00270     GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
00271   if (!GetOperations()->IsDone() || aNewObject.IsNull())
00272     return aGEOMObject._retn();
00273 
00274   return GetObject(aNewObject);
00275 }
00276 
00277 //=============================================================================
00281 //=============================================================================
00282 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
00283                                                                  const GEOM::short_array& theWires)
00284 {
00285   GEOM::GEOM_Object_var aGEOMObject;
00286 
00287   // Set a not done flag
00288   GetOperations()->SetNotDone();
00289 
00290   // Get the object itself
00291   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00292   if (anObject.IsNull())
00293     return aGEOMObject._retn();
00294 
00295   // if theWires is empty - it's OK, it means that ALL wires should be removed
00296 
00297   // Perform
00298   Handle(GEOM_Object) aNewObject =
00299     GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
00300   if (!GetOperations()->IsDone() || aNewObject.IsNull())
00301     return aGEOMObject._retn();
00302 
00303   return GetObject(aNewObject);
00304 }
00305 
00306 //=============================================================================
00310 //=============================================================================
00311 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
00312                                                             const GEOM::short_array& theWires)
00313 {
00314   GEOM::GEOM_Object_var aGEOMObject;
00315 
00316   // Set a not done flag
00317   GetOperations()->SetNotDone();
00318 
00319   // Get the object itself
00320   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00321   if (anObject.IsNull())
00322     return aGEOMObject._retn();
00323 
00324   // if theWires is empty - it's OK, it means that ALL wires should be removed
00325 
00326   // Perform
00327   Handle(GEOM_Object) aNewObject =
00328     GetOperations()->FillHoles( anObject, Convert( theWires ) );
00329   if (!GetOperations()->IsDone() || aNewObject.IsNull())
00330     return aGEOMObject._retn();
00331 
00332   return GetObject(aNewObject);
00333 }
00334 
00335 //=============================================================================
00339 //=============================================================================
00340 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
00341                                                       CORBA::Double theTolerance)
00342 {
00343   GEOM::GEOM_Object_var aGEOMObject;
00344 
00345   // Set a not done flag
00346   GetOperations()->SetNotDone();
00347 
00348   // Check parameters
00349   if (theTolerance < 0)
00350     return aGEOMObject._retn();
00351 
00352   // Get the object itself
00353   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00354   if (anObject.IsNull())
00355     return aGEOMObject._retn();
00356 
00357   // Perform
00358   Handle(GEOM_Object) aNewObject =
00359     GetOperations()->Sew( anObject, theTolerance );
00360   if (!GetOperations()->IsDone() || aNewObject.IsNull())
00361     return aGEOMObject._retn();
00362 
00363   return GetObject(aNewObject);
00364 }
00365 
00366 //=============================================================================
00370 //=============================================================================
00371 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
00372                                                              CORBA::Short theIndex,
00373                                                              CORBA::Double theValue,
00374                                                              CORBA::Boolean isByParameter)
00375 {
00376   GEOM::GEOM_Object_var aGEOMObject;
00377 
00378   // Set a not done flag
00379   GetOperations()->SetNotDone();
00380 
00381   // Check parameters
00382   if (theValue < 0 || theValue > 1)
00383     return aGEOMObject._retn();
00384 
00385   // Get the object itself
00386   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00387   if (anObject.IsNull())
00388     return aGEOMObject._retn();
00389 
00390   // Perform
00391   Handle(GEOM_Object) aNewObject =
00392     GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
00393   if (!GetOperations()->IsDone() || aNewObject.IsNull())
00394     return aGEOMObject._retn();
00395 
00396   return GetObject(aNewObject);
00397 }
00398 
00399 //=============================================================================
00403 //=============================================================================
00404 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
00405                                                             GEOM::ListOfGO_out theClosedWires,
00406                                                             GEOM::ListOfGO_out theOpenWires )
00407 {
00408   theClosedWires = new GEOM::ListOfGO;
00409   theOpenWires = new GEOM::ListOfGO;
00410 
00411   // Set a not done flag
00412   GetOperations()->SetNotDone();
00413 
00414   // Get the object itself
00415   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00416   if (anObject.IsNull())
00417     return false;
00418 
00419   Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
00420   Handle(TColStd_HSequenceOfTransient) anOpen  = new TColStd_HSequenceOfTransient();
00421   bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
00422 
00423   if ( !GetOperations()->IsDone() || !res )
00424     return false;
00425 
00426   int i, n = aClosed->Length();
00427   theClosedWires->length( n );
00428   for ( i = 1; i <= n; i++ )
00429     (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
00430 
00431   n = anOpen->Length();
00432   theOpenWires->length( n );
00433   for ( i = 1, n = anOpen->Length(); i <= n; i++ )
00434     (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
00435 
00436   return true;
00437 }
00438 
00439 
00440 //=============================================================================
00444 //=============================================================================
00445 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
00446 {
00447   GEOM::GEOM_Object_var aGEOMObject;
00448 
00449   // Set a not done flag
00450   GetOperations()->SetNotDone();
00451 
00452   // Check parameters
00453   if ( CORBA::is_nil(theObject) )
00454     return aGEOMObject._retn();
00455 
00456   aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
00457 
00458   // Get the object itself
00459   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00460   if (anObject.IsNull())
00461     return aGEOMObject._retn();
00462 
00463   // Perform
00464 //  Handle(GEOM_Object) aNewObject =
00465     GetOperations()->ChangeOrientation( anObject );
00466 //  if (!GetOperations()->IsDone() || aNewObject.IsNull())
00467 //    return aGEOMObject._retn();
00468 
00469   //return GetObject(aNewObject);
00470   return aGEOMObject._retn();
00471 }
00472 
00473 
00474 //=============================================================================
00478 //=============================================================================
00479 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
00480 {
00481   GEOM::GEOM_Object_var aGEOMObject;
00482 
00483   // Set a not done flag
00484   GetOperations()->SetNotDone();
00485 
00486   // Get the object itself
00487   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00488   if (anObject.IsNull())
00489     return aGEOMObject._retn();
00490 
00491   // Perform
00492   Handle(GEOM_Object) aNewObject =
00493     GetOperations()->ChangeOrientationCopy( anObject );
00494   if (!GetOperations()->IsDone() || aNewObject.IsNull())
00495     return aGEOMObject._retn();
00496 
00497   return GetObject(aNewObject);
00498 }
00499 
00500 //=============================================================================
00504 //=============================================================================
00505 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject,
00506                                                                  CORBA::Double theTolerance)
00507 {
00508   GEOM::GEOM_Object_var aGEOMObject;
00509 
00510   // Set a not done flag
00511   GetOperations()->SetNotDone();
00512 
00513   // Get the object itself
00514   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
00515   if (anObject.IsNull())
00516     return aGEOMObject._retn();
00517 
00518   // Perform
00519   Handle(GEOM_Object) aNewObject =
00520     GetOperations()->LimitTolerance(anObject, theTolerance);
00521   if (!GetOperations()->IsDone() || aNewObject.IsNull())
00522     return aGEOMObject._retn();
00523 
00524   return GetObject(aNewObject);
00525 }