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