Salome HOME
56503fbb4ef8ccb122fa83e607c20e127fe4a703
[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 //=======================================================================
33 //function : ShHealOper_ShapeProcess()
34 //purpose  : Constructor
35 //=======================================================================
36
37 ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (  ) :
38        myOperations(TCollection_AsciiString("ShHealing").ToCString(),
39                     TCollection_AsciiString("ShapeProcess").ToCString())
40 {
41    //myResource = new Resource_Manager("ShHealing");
42    myPrefix = "ShapeProcess";
43    mySaveHistoryMode = Standard_False;
44    myLevel = TopAbs_FACE;
45    myDone = Standard_False;
46 }
47
48 //=======================================================================
49 //function : ShHealOper_ShapeProcess
50 //purpose  : 
51 //=======================================================================
52
53 ShHealOper_ShapeProcess::ShHealOper_ShapeProcess (const TCollection_AsciiString& theNameResource,
54                                                   const TCollection_AsciiString& thePrefix ) :
55        myOperations(theNameResource.ToCString(),thePrefix.ToCString())
56 {
57   //myResource = new Resource_Manager(theNameResource);
58   myPrefix = thePrefix;
59   mySaveHistoryMode = Standard_False;
60   myLevel = TopAbs_FACE;
61   myDone = Standard_False;
62 }
63
64 //=======================================================================
65 //function : Perform
66 //purpose  : 
67 //=======================================================================
68 void ShHealOper_ShapeProcess::Perform(const TopoDS_Shape& theOldShape, 
69                                            TopoDS_Shape& theNewShape)
70 {
71   
72   myMapModifications.Clear();
73   //ShapeProcessAPI_ApplySequence aOperations(myResource,myPrefix.ToCString());
74   //myDone = Standard_False;
75   myOperations.ClearMap();
76   
77   theNewShape = myOperations.PrepareShape(theOldShape,mySaveHistoryMode,myLevel);
78   if(mySaveHistoryMode)
79     myMapModifications = myOperations.Map();
80   myDone = !theOldShape.IsSame(theNewShape);
81 }
82 //=======================================================================
83 //function : SetOperators
84 //purpose  : 
85 //=======================================================================
86
87 void ShHealOper_ShapeProcess::SetOperators(const TColStd_SequenceOfAsciiString& theSeqOperators)
88 {
89   
90   TCollection_AsciiString anameParam(myPrefix);
91   anameParam += ".";
92   anameParam += "exec.op";
93   TCollection_AsciiString aseq;
94   Standard_Integer i =1;
95   for( ; i <= theSeqOperators.Length(); i++) {
96     aseq += theSeqOperators.Value(i);
97     aseq += " ";
98   }
99     
100   myOperations.Context()->ResourceManager()->SetResource(anameParam.ToCString(),aseq.ToCString());
101 }
102 //=======================================================================
103 //function : SetParameter
104 //purpose  : 
105 //=======================================================================
106
107 void  ShHealOper_ShapeProcess::SetParameter(const TCollection_AsciiString& theNameParam,
108                                     const TCollection_AsciiString& theVal)
109 {
110   TCollection_AsciiString anameParam(myPrefix);
111   anameParam += ".";
112   anameParam+= theNameParam;
113   if(theVal.IsIntegerValue())
114     myOperations.Context()->ResourceManager()->
115       SetResource(anameParam.ToCString(),theVal.IntegerValue());
116   else if(theVal.IsRealValue())
117     myOperations.Context()->ResourceManager()->
118       SetResource(anameParam.ToCString(),theVal.RealValue());
119   else
120     myOperations.Context()->ResourceManager()->
121       SetResource(anameParam.ToCString(),theVal.ToCString());
122
123 }
124 //=======================================================================
125 //function : GetOperators
126 //purpose  : 
127 //=======================================================================
128
129 Standard_Boolean ShHealOper_ShapeProcess::GetOperators(TColStd_SequenceOfAsciiString& theSeqOperators)
130 {
131   TCollection_AsciiString nameSeq(myPrefix);
132   nameSeq +=".exec.op";
133   if(!myOperations.Context()->ResourceManager()->Find(nameSeq.ToCString()))
134     return Standard_False;
135   
136   TCollection_AsciiString seqoper = myOperations.Context()->ResourceManager()->Value(nameSeq.ToCString());
137   Standard_Integer i;
138   for ( i=1; ; i++ ) {
139     TCollection_AsciiString anOper = seqoper.Token ( " \t,;", i );
140     if ( anOper.Length() <=0 ) break;
141     theSeqOperators.Append(anOper);
142   }
143   return (theSeqOperators.Length());
144 }
145 //=======================================================================
146 //function : GetParameter
147 //purpose  : 
148 //=======================================================================
149
150 Standard_Boolean ShHealOper_ShapeProcess::GetParameter(const TCollection_AsciiString& theNameParam,
151                                        TCollection_AsciiString& theVal)
152 {
153   TCollection_AsciiString namePar(myPrefix);
154   namePar += ".";
155   namePar += theNameParam;
156   if(!myOperations.Context()->ResourceManager()->Find(namePar.ToCString()))
157     return Standard_False;
158   
159   theVal = myOperations.Context()->ResourceManager()->Value(namePar.ToCString());
160   return Standard_True;
161 }