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