/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. #include <ShHealOper_ShapeProcess.hxx>
  25. #include <ShapeProcessAPI_ApplySequence.hxx>
  26. #include <ShapeProcess_Context.hxx>
  27. #include <TCollection_AsciiString.hxx>
  28. #include <Resource_Manager.hxx>
  29. #include <TopoDS_Shape.hxx>
  30. #include <TopAbs_ShapeEnum.hxx>
  31. #include <TopTools_DataMapOfShapeShape.hxx>
  32. #include <ShapeProcess_ShapeContext.hxx>
  33. #include <ShapeAnalysis_ShapeTolerance.hxx>
  34. #include <Precision.hxx>
  35. #include <BRep_Builder.hxx>
  36. #include <TopoDS_Iterator.hxx>
  37. #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
  38. #include <TNaming_CopyShape.hxx>
  39. //=======================================================================
  40. //function : ShHealOper_ShapeProcess()
  41. //purpose : Constructor
  42. //=======================================================================
  43. ShHealOper_ShapeProcess::ShHealOper_ShapeProcess ( ) :
  44. myOperations(TCollection_AsciiString("ShHealing").ToCString(),
  45. TCollection_AsciiString("ShapeProcess").ToCString())
  46. {
  47. //myResource = new Resource_Manager("ShHealing");
  48. myPrefix = "ShapeProcess";
  49. mySaveHistoryMode = Standard_False;
  50. myLevel = TopAbs_FACE;
  51. myDone = Standard_False;
  52. }
  53. //=======================================================================
  54. //function : ShHealOper_ShapeProcess
  55. //purpose :
  56. //=======================================================================
  57. ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (const TCollection_AsciiString& theNameResource,
  58. const TCollection_AsciiString& thePrefix ) :
  59. myOperations(theNameResource.ToCString(),thePrefix.ToCString())
  60. {
  61. //myResource = new Resource_Manager(theNameResource);
  62. myPrefix = thePrefix;
  63. mySaveHistoryMode = Standard_False;
  64. myLevel = TopAbs_FACE;
  65. myDone = Standard_False;
  66. }
  67. //=======================================================================
  68. //function : Perform
  69. //purpose :
  70. //=======================================================================
  71. void ShHealOper_ShapeProcess::Perform(const TopoDS_Shape& theOldShape,
  72. TopoDS_Shape& theNewShape)
  73. {
  74. myMapModifications.Clear();
  75. //ShapeProcessAPI_ApplySequence aOperations(myResource,myPrefix.ToCString());
  76. //myDone = Standard_False;
  77. myOperations.ClearMap();
  78. ShapeAnalysis_ShapeTolerance aSatol;
  79. Standard_Real ainitTol = aSatol.Tolerance(theOldShape,0);
  80. // PAL6487: san -- preserve the original shape from being modified
  81. TopoDS_Shape anOldShape;
  82. TColStd_IndexedDataMapOfTransientTransient aMap;
  83. TNaming_CopyShape::CopyTool(theOldShape, aMap, anOldShape);
  84. // PAL6487: san -- preserve the original shape from being modified
  85. theNewShape = myOperations.PrepareShape(anOldShape,mySaveHistoryMode,myLevel);
  86. if(mySaveHistoryMode)
  87. myMapModifications = myOperations.Map();
  88. myDone = !anOldShape.IsSame(theNewShape);
  89. if(!myDone) {
  90. Standard_Real aendTol =aSatol.Tolerance(theNewShape,0);
  91. myDone = (fabs(ainitTol - aendTol) > Precision::Confusion());
  92. }
  93. }
  94. //=======================================================================
  95. //function : SetOperators
  96. //purpose :
  97. //=======================================================================
  98. void ShHealOper_ShapeProcess::SetOperators(const TColStd_SequenceOfAsciiString& theSeqOperators)
  99. {
  100. TCollection_AsciiString anameParam(myPrefix);
  101. anameParam += ".";
  102. anameParam += "exec.op";
  103. TCollection_AsciiString aseq;
  104. Standard_Integer i =1;
  105. for( ; i <= theSeqOperators.Length(); i++) {
  106. aseq += theSeqOperators.Value(i);
  107. aseq += " ";
  108. }
  109. myOperations.Context()->ResourceManager()->SetResource(anameParam.ToCString(),aseq.ToCString());
  110. }
  111. //=======================================================================
  112. //function : SetParameter
  113. //purpose :
  114. //=======================================================================
  115. void ShHealOper_ShapeProcess::SetParameter(const TCollection_AsciiString& theNameParam,
  116. const TCollection_AsciiString& theVal)
  117. {
  118. TCollection_AsciiString anameParam(myPrefix);
  119. anameParam += ".";
  120. anameParam+= theNameParam;
  121. if(theVal.IsIntegerValue())
  122. myOperations.Context()->ResourceManager()->
  123. SetResource(anameParam.ToCString(),theVal.IntegerValue());
  124. else if(theVal.IsRealValue())
  125. myOperations.Context()->ResourceManager()->
  126. SetResource(anameParam.ToCString(),theVal.RealValue());
  127. else
  128. myOperations.Context()->ResourceManager()->
  129. SetResource(anameParam.ToCString(),theVal.ToCString());
  130. }
  131. //=======================================================================
  132. //function : GetOperators
  133. //purpose :
  134. //=======================================================================
  135. Standard_Boolean ShHealOper_ShapeProcess::GetOperators(TColStd_SequenceOfAsciiString& theSeqOperators)
  136. {
  137. TCollection_AsciiString nameSeq(myPrefix);
  138. nameSeq +=".exec.op";
  139. if(!myOperations.Context()->ResourceManager()->Find(nameSeq.ToCString()))
  140. return Standard_False;
  141. TCollection_AsciiString seqoper = myOperations.Context()->ResourceManager()->Value(nameSeq.ToCString());
  142. Standard_Integer i;
  143. for ( i=1; ; i++ ) {
  144. TCollection_AsciiString anOper = seqoper.Token ( " \t,;", i );
  145. if ( anOper.Length() <=0 ) break;
  146. theSeqOperators.Append(anOper);
  147. }
  148. return (theSeqOperators.Length());
  149. }
  150. //=======================================================================
  151. //function : GetParameter
  152. //purpose :
  153. //=======================================================================
  154. Standard_Boolean ShHealOper_ShapeProcess::GetParameter(const TCollection_AsciiString& theNameParam,
  155. TCollection_AsciiString& theVal)
  156. {
  157. TCollection_AsciiString namePar(myPrefix);
  158. namePar += ".";
  159. namePar += theNameParam;
  160. if(!myOperations.Context()->ResourceManager()->Find(namePar.ToCString()))
  161. return Standard_False;
  162. theVal = myOperations.Context()->ResourceManager()->Value(namePar.ToCString());
  163. return Standard_True;
  164. }