1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File: ShHealOper_ShapeProcess.cxx
22 // Created: 14.04.04 10:58:04
23 // Author: Galina KULIKOVA
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>
41 //=======================================================================
42 //function : ShHealOper_ShapeProcess()
43 //purpose : Constructor
44 //=======================================================================
46 ShHealOper_ShapeProcess::ShHealOper_ShapeProcess ( ) :
47 myOperations(TCollection_AsciiString("ShHealing").ToCString(),
48 TCollection_AsciiString("ShapeProcess").ToCString())
50 //myResource = new Resource_Manager("ShHealing");
51 myPrefix = "ShapeProcess";
52 mySaveHistoryMode = Standard_False;
53 myLevel = TopAbs_FACE;
54 myDone = Standard_False;
57 //=======================================================================
58 //function : ShHealOper_ShapeProcess
60 //=======================================================================
62 ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (const TCollection_AsciiString& theNameResource,
63 const TCollection_AsciiString& thePrefix ) :
64 myOperations(theNameResource.ToCString(),thePrefix.ToCString())
66 //myResource = new Resource_Manager(theNameResource);
68 mySaveHistoryMode = Standard_False;
69 myLevel = TopAbs_FACE;
70 myDone = Standard_False;
73 //=======================================================================
76 //=======================================================================
77 void ShHealOper_ShapeProcess::Perform(const TopoDS_Shape& theOldShape,
78 TopoDS_Shape& theNewShape)
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);
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
94 theNewShape = myOperations.PrepareShape(anOldShape,mySaveHistoryMode,myLevel);
96 myMapModifications = myOperations.Map();
97 myDone = !anOldShape.IsSame(theNewShape);
99 Standard_Real aendTol =aSatol.Tolerance(theNewShape,0);
100 myDone = (fabs(ainitTol - aendTol) > Precision::Confusion());
103 //=======================================================================
104 //function : SetOperators
106 //=======================================================================
108 void ShHealOper_ShapeProcess::SetOperators(const TColStd_SequenceOfAsciiString& theSeqOperators)
111 TCollection_AsciiString anameParam(myPrefix);
113 anameParam += "exec.op";
114 TCollection_AsciiString aseq;
115 Standard_Integer i =1;
116 for( ; i <= theSeqOperators.Length(); i++) {
117 aseq += theSeqOperators.Value(i);
121 myOperations.Context()->ResourceManager()->SetResource(anameParam.ToCString(),aseq.ToCString());
123 //=======================================================================
124 //function : SetParameter
126 //=======================================================================
128 void ShHealOper_ShapeProcess::SetParameter(const TCollection_AsciiString& theNameParam,
129 const TCollection_AsciiString& theVal)
131 TCollection_AsciiString anameParam(myPrefix);
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());
141 myOperations.Context()->ResourceManager()->
142 SetResource(anameParam.ToCString(),theVal.ToCString());
145 //=======================================================================
146 //function : GetOperators
148 //=======================================================================
150 Standard_Boolean ShHealOper_ShapeProcess::GetOperators(TColStd_SequenceOfAsciiString& theSeqOperators)
152 TCollection_AsciiString nameSeq(myPrefix);
153 nameSeq +=".exec.op";
154 if(!myOperations.Context()->ResourceManager()->Find(nameSeq.ToCString()))
155 return Standard_False;
157 TCollection_AsciiString seqoper = myOperations.Context()->ResourceManager()->Value(nameSeq.ToCString());
160 TCollection_AsciiString anOper = seqoper.Token ( " \t,;", i );
161 if ( anOper.Length() <=0 ) break;
162 theSeqOperators.Append(anOper);
164 return (theSeqOperators.Length());
166 //=======================================================================
167 //function : GetParameter
169 //=======================================================================
171 Standard_Boolean ShHealOper_ShapeProcess::GetParameter(const TCollection_AsciiString& theNameParam,
172 TCollection_AsciiString& theVal)
174 TCollection_AsciiString namePar(myPrefix);
176 namePar += theNameParam;
177 if(!myOperations.Context()->ResourceManager()->Find(namePar.ToCString()))
178 return Standard_False;
180 theVal = myOperations.Context()->ResourceManager()->Value(namePar.ToCString());
181 return Standard_True;