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