Back to index

salome-geom  6.5.0
ShHealOper_ShapeProcess.cxx
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 // File:      ShHealOper_ShapeProcess.cxx
00024 // Created:   14.04.04 10:58:04
00025 // Author:    Galina KULIKOVA
00026 //
00027 #include <ShHealOper_ShapeProcess.hxx>
00028 #include <ShapeProcessAPI_ApplySequence.hxx>
00029 #include <ShapeProcess_Context.hxx>
00030 #include <TCollection_AsciiString.hxx>
00031 #include <Resource_Manager.hxx>
00032 #include <TopoDS_Shape.hxx>
00033 #include <TopAbs_ShapeEnum.hxx>
00034 #include <TopTools_DataMapOfShapeShape.hxx>
00035 #include <ShapeProcess_ShapeContext.hxx>
00036 #include <ShapeAnalysis_ShapeTolerance.hxx>
00037 #include <Precision.hxx>
00038 #include <BRep_Builder.hxx>
00039 #include <TopoDS_Iterator.hxx>
00040 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
00041 #include <TNaming_CopyShape.hxx>
00042 
00043 //=======================================================================
00044 //function : ShHealOper_ShapeProcess()
00045 //purpose  : Constructor
00046 //=======================================================================
00047 
00048 ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (  ) :
00049        myOperations(TCollection_AsciiString("ShHealing").ToCString(),
00050                     TCollection_AsciiString("ShapeProcess").ToCString())
00051 {
00052    //myResource = new Resource_Manager("ShHealing");
00053    myPrefix = "ShapeProcess";
00054    mySaveHistoryMode = Standard_False;
00055    myLevel = TopAbs_FACE;
00056    myDone = Standard_False;
00057 }
00058 
00059 //=======================================================================
00060 //function : ShHealOper_ShapeProcess
00061 //purpose  : 
00062 //=======================================================================
00063 
00064 ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (const TCollection_AsciiString& theNameResource,
00065                                                   const TCollection_AsciiString& thePrefix ) :
00066        myOperations(theNameResource.ToCString(),thePrefix.ToCString())
00067 {
00068   //myResource = new Resource_Manager(theNameResource);
00069   myPrefix = thePrefix;
00070   mySaveHistoryMode = Standard_False;
00071   myLevel = TopAbs_FACE;
00072   myDone = Standard_False;
00073 }
00074 
00075 //=======================================================================
00076 //function : Perform
00077 //purpose  : 
00078 //=======================================================================
00079 void ShHealOper_ShapeProcess::Perform(const TopoDS_Shape& theOldShape, 
00080                                            TopoDS_Shape& theNewShape)
00081 {
00082   
00083   myMapModifications.Clear();
00084   //ShapeProcessAPI_ApplySequence aOperations(myResource,myPrefix.ToCString());
00085   //myDone = Standard_False;
00086   myOperations.ClearMap();
00087   ShapeAnalysis_ShapeTolerance aSatol;
00088   Standard_Real ainitTol = aSatol.Tolerance(theOldShape,0);
00089 
00090   // PAL6487: san -- preserve the original shape from being modified
00091   TopoDS_Shape anOldShape;
00092   TColStd_IndexedDataMapOfTransientTransient aMap;
00093   TNaming_CopyShape::CopyTool(theOldShape, aMap, anOldShape);
00094   // PAL6487: san -- preserve the original shape from being modified
00095 
00096   theNewShape = myOperations.PrepareShape(anOldShape,mySaveHistoryMode,myLevel);
00097   if(mySaveHistoryMode)
00098     myMapModifications = myOperations.Map();
00099   myDone = !anOldShape.IsSame(theNewShape);
00100   if(!myDone) {
00101     Standard_Real aendTol =aSatol.Tolerance(theNewShape,0);
00102     myDone = (fabs(ainitTol - aendTol) > Precision::Confusion()); 
00103   }
00104 }
00105 //=======================================================================
00106 //function : SetOperators
00107 //purpose  : 
00108 //=======================================================================
00109 
00110 void ShHealOper_ShapeProcess::SetOperators(const TColStd_SequenceOfAsciiString& theSeqOperators)
00111 {
00112   
00113   TCollection_AsciiString anameParam(myPrefix);
00114   anameParam += ".";
00115   anameParam += "exec.op";
00116   TCollection_AsciiString aseq;
00117   Standard_Integer i =1;
00118   for( ; i <= theSeqOperators.Length(); i++) {
00119     aseq += theSeqOperators.Value(i);
00120     aseq += " ";
00121   }
00122     
00123   myOperations.Context()->ResourceManager()->SetResource(anameParam.ToCString(),aseq.ToCString());
00124 }
00125 //=======================================================================
00126 //function : SetParameter
00127 //purpose  : 
00128 //=======================================================================
00129 
00130 void  ShHealOper_ShapeProcess::SetParameter(const TCollection_AsciiString& theNameParam,
00131                                     const TCollection_AsciiString& theVal)
00132 {
00133   TCollection_AsciiString anameParam(myPrefix);
00134   anameParam += ".";
00135   anameParam+= theNameParam;
00136   if(theVal.IsIntegerValue())
00137     myOperations.Context()->ResourceManager()->
00138       SetResource(anameParam.ToCString(),theVal.IntegerValue());
00139   else if(theVal.IsRealValue())
00140     myOperations.Context()->ResourceManager()->
00141       SetResource(anameParam.ToCString(),theVal.RealValue());
00142   else
00143     myOperations.Context()->ResourceManager()->
00144       SetResource(anameParam.ToCString(),theVal.ToCString());
00145 
00146 }
00147 //=======================================================================
00148 //function : GetOperators
00149 //purpose  : 
00150 //=======================================================================
00151 
00152 Standard_Boolean ShHealOper_ShapeProcess::GetOperators(TColStd_SequenceOfAsciiString& theSeqOperators)
00153 {
00154   TCollection_AsciiString nameSeq(myPrefix);
00155   nameSeq +=".exec.op";
00156   if(!myOperations.Context()->ResourceManager()->Find(nameSeq.ToCString()))
00157     return Standard_False;
00158   
00159   TCollection_AsciiString seqoper = myOperations.Context()->ResourceManager()->Value(nameSeq.ToCString());
00160   Standard_Integer i;
00161   for ( i=1; ; i++ ) {
00162     TCollection_AsciiString anOper = seqoper.Token ( " \t,;", i );
00163     if ( anOper.Length() <=0 ) break;
00164     theSeqOperators.Append(anOper);
00165   }
00166   return (theSeqOperators.Length());
00167 }
00168 //=======================================================================
00169 //function : GetParameter
00170 //purpose  : 
00171 //=======================================================================
00172 
00173 Standard_Boolean ShHealOper_ShapeProcess::GetParameter(const TCollection_AsciiString& theNameParam,
00174                                        TCollection_AsciiString& theVal)
00175 {
00176   TCollection_AsciiString namePar(myPrefix);
00177   namePar += ".";
00178   namePar += theNameParam;
00179   if(!myOperations.Context()->ResourceManager()->Find(namePar.ToCString()))
00180     return Standard_False;
00181   
00182   theVal = myOperations.Context()->ResourceManager()->Value(namePar.ToCString());
00183   return Standard_True;
00184 }