1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: ShHealOper_ShapeProcess.cxx
23 // Created: 14.04.04 10:58:04
24 // Author: Galina KULIKOVA
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>
42 //=======================================================================
43 //function : ShHealOper_ShapeProcess()
44 //purpose : Constructor
45 //=======================================================================
47 ShHealOper_ShapeProcess::ShHealOper_ShapeProcess ( ) :
48 myOperations(TCollection_AsciiString("ShHealing").ToCString(),
49 TCollection_AsciiString("ShapeProcess").ToCString())
51 //myResource = new Resource_Manager("ShHealing");
52 myPrefix = "ShapeProcess";
53 mySaveHistoryMode = Standard_False;
54 myLevel = TopAbs_FACE;
55 myDone = Standard_False;
58 //=======================================================================
59 //function : ShHealOper_ShapeProcess
61 //=======================================================================
63 ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (const TCollection_AsciiString& theNameResource,
64 const TCollection_AsciiString& thePrefix ) :
65 myOperations(theNameResource.ToCString(),thePrefix.ToCString())
67 //myResource = new Resource_Manager(theNameResource);
69 mySaveHistoryMode = Standard_False;
70 myLevel = TopAbs_FACE;
71 myDone = Standard_False;
74 //=======================================================================
77 //=======================================================================
78 void ShHealOper_ShapeProcess::Perform(const TopoDS_Shape& theOldShape,
79 TopoDS_Shape& theNewShape)
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);
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
95 theNewShape = myOperations.PrepareShape(anOldShape,mySaveHistoryMode,myLevel);
97 myMapModifications = myOperations.Map();
98 myDone = !anOldShape.IsSame(theNewShape);
100 Standard_Real aendTol =aSatol.Tolerance(theNewShape,0);
101 myDone = (fabs(ainitTol - aendTol) > Precision::Confusion());
104 //=======================================================================
105 //function : SetOperators
107 //=======================================================================
109 void ShHealOper_ShapeProcess::SetOperators(const TColStd_SequenceOfAsciiString& theSeqOperators)
112 TCollection_AsciiString anameParam(myPrefix);
114 anameParam += "exec.op";
115 TCollection_AsciiString aseq;
116 Standard_Integer i =1;
117 for( ; i <= theSeqOperators.Length(); i++) {
118 aseq += theSeqOperators.Value(i);
122 myOperations.Context()->ResourceManager()->SetResource(anameParam.ToCString(),aseq.ToCString());
124 //=======================================================================
125 //function : SetParameter
127 //=======================================================================
129 void ShHealOper_ShapeProcess::SetParameter(const TCollection_AsciiString& theNameParam,
130 const TCollection_AsciiString& theVal)
132 TCollection_AsciiString anameParam(myPrefix);
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());
142 myOperations.Context()->ResourceManager()->
143 SetResource(anameParam.ToCString(),theVal.ToCString());
146 //=======================================================================
147 //function : GetOperators
149 //=======================================================================
151 Standard_Boolean ShHealOper_ShapeProcess::GetOperators(TColStd_SequenceOfAsciiString& theSeqOperators)
153 TCollection_AsciiString nameSeq(myPrefix);
154 nameSeq +=".exec.op";
155 if(!myOperations.Context()->ResourceManager()->Find(nameSeq.ToCString()))
156 return Standard_False;
158 TCollection_AsciiString seqoper = myOperations.Context()->ResourceManager()->Value(nameSeq.ToCString());
161 TCollection_AsciiString anOper = seqoper.Token ( " \t,;", i );
162 if ( anOper.Length() <=0 ) break;
163 theSeqOperators.Append(anOper);
165 return (theSeqOperators.Length());
167 //=======================================================================
168 //function : GetParameter
170 //=======================================================================
172 Standard_Boolean ShHealOper_ShapeProcess::GetParameter(const TCollection_AsciiString& theNameParam,
173 TCollection_AsciiString& theVal)
175 TCollection_AsciiString namePar(myPrefix);
177 namePar += theNameParam;
178 if(!myOperations.Context()->ResourceManager()->Find(namePar.ToCString()))
179 return Standard_False;
181 theVal = myOperations.Context()->ResourceManager()->Value(namePar.ToCString());
182 return Standard_True;