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
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.
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.
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
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>
39 //=======================================================================
40 //function : ShHealOper_ShapeProcess()
41 //purpose : Constructor
42 //=======================================================================
44 ShHealOper_ShapeProcess::ShHealOper_ShapeProcess ( ) :
45 myOperations(TCollection_AsciiString("ShHealing").ToCString(),
46 TCollection_AsciiString("ShapeProcess").ToCString())
48 //myResource = new Resource_Manager("ShHealing");
49 myPrefix = "ShapeProcess";
50 mySaveHistoryMode = Standard_False;
51 myLevel = TopAbs_FACE;
52 myDone = Standard_False;
55 //=======================================================================
56 //function : ShHealOper_ShapeProcess
58 //=======================================================================
60 ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (const TCollection_AsciiString& theNameResource,
61 const TCollection_AsciiString& thePrefix ) :
62 myOperations(theNameResource.ToCString(),thePrefix.ToCString())
64 //myResource = new Resource_Manager(theNameResource);
66 mySaveHistoryMode = Standard_False;
67 myLevel = TopAbs_FACE;
68 myDone = Standard_False;
71 //=======================================================================
74 //=======================================================================
75 void ShHealOper_ShapeProcess::Perform(const TopoDS_Shape& theOldShape,
76 TopoDS_Shape& theNewShape)
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);
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
92 theNewShape = myOperations.PrepareShape(anOldShape,mySaveHistoryMode,myLevel);
94 myMapModifications = myOperations.Map();
95 myDone = !anOldShape.IsSame(theNewShape);
97 Standard_Real aendTol =aSatol.Tolerance(theNewShape,0);
98 myDone = (fabs(ainitTol - aendTol) > Precision::Confusion());
101 //=======================================================================
102 //function : SetOperators
104 //=======================================================================
106 void ShHealOper_ShapeProcess::SetOperators(const TColStd_SequenceOfAsciiString& theSeqOperators)
109 TCollection_AsciiString anameParam(myPrefix);
111 anameParam += "exec.op";
112 TCollection_AsciiString aseq;
113 Standard_Integer i =1;
114 for( ; i <= theSeqOperators.Length(); i++) {
115 aseq += theSeqOperators.Value(i);
119 myOperations.Context()->ResourceManager()->SetResource(anameParam.ToCString(),aseq.ToCString());
121 //=======================================================================
122 //function : SetParameter
124 //=======================================================================
126 void ShHealOper_ShapeProcess::SetParameter(const TCollection_AsciiString& theNameParam,
127 const TCollection_AsciiString& theVal)
129 TCollection_AsciiString anameParam(myPrefix);
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());
139 myOperations.Context()->ResourceManager()->
140 SetResource(anameParam.ToCString(),theVal.ToCString());
143 //=======================================================================
144 //function : GetOperators
146 //=======================================================================
148 Standard_Boolean ShHealOper_ShapeProcess::GetOperators(TColStd_SequenceOfAsciiString& theSeqOperators)
150 TCollection_AsciiString nameSeq(myPrefix);
151 nameSeq +=".exec.op";
152 if(!myOperations.Context()->ResourceManager()->Find(nameSeq.ToCString()))
153 return Standard_False;
155 TCollection_AsciiString seqoper = myOperations.Context()->ResourceManager()->Value(nameSeq.ToCString());
158 TCollection_AsciiString anOper = seqoper.Token ( " \t,;", i );
159 if ( anOper.Length() <=0 ) break;
160 theSeqOperators.Append(anOper);
162 return (theSeqOperators.Length());
164 //=======================================================================
165 //function : GetParameter
167 //=======================================================================
169 Standard_Boolean ShHealOper_ShapeProcess::GetParameter(const TCollection_AsciiString& theNameParam,
170 TCollection_AsciiString& theVal)
172 TCollection_AsciiString namePar(myPrefix);
174 namePar += theNameParam;
175 if(!myOperations.Context()->ResourceManager()->Find(namePar.ToCString()))
176 return Standard_False;
178 theVal = myOperations.Context()->ResourceManager()->Value(namePar.ToCString());
179 return Standard_True;