PageRenderTime 58ms CodeModel.GetById 15ms app.highlight 37ms RepoModel.GetById 2ms app.codeStats 0ms

/src/contrib/geom-5.1.2.7/src/ShHealOper/ShHealOper_ShapeProcess.cpp

http://pythonocc.googlecode.com/
C++ | 182 lines | 107 code | 18 blank | 57 comment | 10 complexity | 3e4407e8fde64965f3e471b6f903efce MD5 | raw file
  1// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
  2// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
  3// 
  4// This library is free software; you can redistribute it and/or
  5// modify it under the terms of the GNU Lesser General Public
  6// License as published by the Free Software Foundation; either 
  7// version 2.1 of the License.
  8// 
  9// This library is distributed in the hope that it will be useful 
 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 12// Lesser General Public License for more details.
 13//
 14// You should have received a copy of the GNU Lesser General Public  
 15// License along with this library; if not, write to the Free Software 
 16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 17//
 18// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 19//
 20//
 21// File:      ShHealOper_ShapeProcess.cxx
 22// Created:   14.04.04 10:58:04
 23// Author:    Galina KULIKOVA
 24
 25#include <ShHealOper_ShapeProcess.hxx>
 26#include <ShapeProcessAPI_ApplySequence.hxx>
 27#include <ShapeProcess_Context.hxx>
 28#include <TCollection_AsciiString.hxx>
 29#include <Resource_Manager.hxx>
 30#include <TopoDS_Shape.hxx>
 31#include <TopAbs_ShapeEnum.hxx>
 32#include <TopTools_DataMapOfShapeShape.hxx>
 33#include <ShapeProcess_ShapeContext.hxx>
 34#include <ShapeAnalysis_ShapeTolerance.hxx>
 35#include <Precision.hxx>
 36#include <BRep_Builder.hxx>
 37#include <TopoDS_Iterator.hxx>
 38#include <TColStd_IndexedDataMapOfTransientTransient.hxx>
 39#include <TNaming_CopyShape.hxx>
 40
 41//=======================================================================
 42//function : ShHealOper_ShapeProcess()
 43//purpose  : Constructor
 44//=======================================================================
 45
 46ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (  ) :
 47       myOperations(TCollection_AsciiString("ShHealing").ToCString(),
 48                    TCollection_AsciiString("ShapeProcess").ToCString())
 49{
 50   //myResource = new Resource_Manager("ShHealing");
 51   myPrefix = "ShapeProcess";
 52   mySaveHistoryMode = Standard_False;
 53   myLevel = TopAbs_FACE;
 54   myDone = Standard_False;
 55}
 56
 57//=======================================================================
 58//function : ShHealOper_ShapeProcess
 59//purpose  : 
 60//=======================================================================
 61
 62ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (const TCollection_AsciiString& theNameResource,
 63                                                  const TCollection_AsciiString& thePrefix ) :
 64       myOperations(theNameResource.ToCString(),thePrefix.ToCString())
 65{
 66  //myResource = new Resource_Manager(theNameResource);
 67  myPrefix = thePrefix;
 68  mySaveHistoryMode = Standard_False;
 69  myLevel = TopAbs_FACE;
 70  myDone = Standard_False;
 71}
 72
 73//=======================================================================
 74//function : Perform
 75//purpose  : 
 76//=======================================================================
 77void ShHealOper_ShapeProcess::Perform(const TopoDS_Shape& theOldShape, 
 78                                           TopoDS_Shape& theNewShape)
 79{
 80  
 81  myMapModifications.Clear();
 82  //ShapeProcessAPI_ApplySequence aOperations(myResource,myPrefix.ToCString());
 83  //myDone = Standard_False;
 84  myOperations.ClearMap();
 85  ShapeAnalysis_ShapeTolerance aSatol;
 86  Standard_Real ainitTol = aSatol.Tolerance(theOldShape,0);
 87
 88  // PAL6487: san -- preserve the original shape from being modified
 89  TopoDS_Shape anOldShape;
 90  TColStd_IndexedDataMapOfTransientTransient aMap;
 91  TNaming_CopyShape::CopyTool(theOldShape, aMap, anOldShape);
 92  // PAL6487: san -- preserve the original shape from being modified
 93
 94  theNewShape = myOperations.PrepareShape(anOldShape,mySaveHistoryMode,myLevel);
 95  if(mySaveHistoryMode)
 96    myMapModifications = myOperations.Map();
 97  myDone = !anOldShape.IsSame(theNewShape);
 98  if(!myDone) {
 99    Standard_Real aendTol =aSatol.Tolerance(theNewShape,0);
100    myDone = (fabs(ainitTol - aendTol) > Precision::Confusion()); 
101  }
102}
103//=======================================================================
104//function : SetOperators
105//purpose  : 
106//=======================================================================
107
108void ShHealOper_ShapeProcess::SetOperators(const TColStd_SequenceOfAsciiString& theSeqOperators)
109{
110  
111  TCollection_AsciiString anameParam(myPrefix);
112  anameParam += ".";
113  anameParam += "exec.op";
114  TCollection_AsciiString aseq;
115  Standard_Integer i =1;
116  for( ; i <= theSeqOperators.Length(); i++) {
117    aseq += theSeqOperators.Value(i);
118    aseq += " ";
119  }
120    
121  myOperations.Context()->ResourceManager()->SetResource(anameParam.ToCString(),aseq.ToCString());
122}
123//=======================================================================
124//function : SetParameter
125//purpose  : 
126//=======================================================================
127
128void  ShHealOper_ShapeProcess::SetParameter(const TCollection_AsciiString& theNameParam,
129                                    const TCollection_AsciiString& theVal)
130{
131  TCollection_AsciiString anameParam(myPrefix);
132  anameParam += ".";
133  anameParam+= theNameParam;
134  if(theVal.IsIntegerValue())
135    myOperations.Context()->ResourceManager()->
136      SetResource(anameParam.ToCString(),theVal.IntegerValue());
137  else if(theVal.IsRealValue())
138    myOperations.Context()->ResourceManager()->
139      SetResource(anameParam.ToCString(),theVal.RealValue());
140  else
141    myOperations.Context()->ResourceManager()->
142      SetResource(anameParam.ToCString(),theVal.ToCString());
143
144}
145//=======================================================================
146//function : GetOperators
147//purpose  : 
148//=======================================================================
149
150Standard_Boolean ShHealOper_ShapeProcess::GetOperators(TColStd_SequenceOfAsciiString& theSeqOperators)
151{
152  TCollection_AsciiString nameSeq(myPrefix);
153  nameSeq +=".exec.op";
154  if(!myOperations.Context()->ResourceManager()->Find(nameSeq.ToCString()))
155    return Standard_False;
156  
157  TCollection_AsciiString seqoper = myOperations.Context()->ResourceManager()->Value(nameSeq.ToCString());
158  Standard_Integer i;
159  for ( i=1; ; i++ ) {
160    TCollection_AsciiString anOper = seqoper.Token ( " \t,;", i );
161    if ( anOper.Length() <=0 ) break;
162    theSeqOperators.Append(anOper);
163  }
164  return (theSeqOperators.Length());
165}
166//=======================================================================
167//function : GetParameter
168//purpose  : 
169//=======================================================================
170
171Standard_Boolean ShHealOper_ShapeProcess::GetParameter(const TCollection_AsciiString& theNameParam,
172                                       TCollection_AsciiString& theVal)
173{
174  TCollection_AsciiString namePar(myPrefix);
175  namePar += ".";
176  namePar += theNameParam;
177  if(!myOperations.Context()->ResourceManager()->Find(namePar.ToCString()))
178    return Standard_False;
179  
180  theVal = myOperations.Context()->ResourceManager()->Value(namePar.ToCString());
181  return Standard_True;
182}