]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_GlueDriver.cxx
Salome HOME
PAL7508. Correct behaviour of GetShapesOnPlane().
[modules/geom.git] / src / GEOMImpl / GEOMImpl_GlueDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_GlueDriver.hxx"
4 #include "GEOMImpl_IGlue.hxx"
5 #include "GEOMImpl_Types.hxx"
6
7 #include "GEOM_Function.hxx"
8
9 #include "GEOMAlgo_Gluer.hxx"
10
11 #include "utilities.h"
12
13 #include <TopoDS_Shape.hxx>
14 #include <Standard_NullObject.hxx>
15 #include <Standard_Failure.hxx>
16
17 //=======================================================================
18 //function : GEOMImpl_GlueDriver
19 //purpose  :
20 //=======================================================================
21 GEOMImpl_GlueDriver::GEOMImpl_GlueDriver()
22 {
23 }
24
25 //=======================================================================
26 //function : GetID
27 //purpose  :
28 //=======================================================================
29 const Standard_GUID& GEOMImpl_GlueDriver::GetID()
30 {
31   static Standard_GUID aGlueDriver("FF1BBB63-5D14-4df2-980B-3A668264EA16");
32   return aGlueDriver;
33 }
34
35 //=======================================================================
36 //function : GlueFacesWithWarnings
37 //purpose  :
38 //=======================================================================
39 TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& theShape,
40                                                          const Standard_Real theTolerance,
41                                                          TCollection_AsciiString& theWarning) const
42 {
43   Standard_Integer iErr, iWrn;
44   TopoDS_Shape aRes;
45   GEOMAlgo_Gluer aGluer;
46
47   aGluer.SetShape(theShape);
48   aGluer.SetTolerance(theTolerance);
49   aGluer.SetCheckGeometry(Standard_True);
50
51   aGluer.Perform();
52
53   iErr = aGluer.ErrorStatus();
54   if (iErr) {
55     switch (iErr) {
56     case 2:
57       Standard_Failure::Raise("No vertices found in source shape");
58       break;
59     case 5:
60       Standard_Failure::Raise("Source shape is Null");
61       break;
62     case 6:
63       Standard_Failure::Raise("Result shape is Null");
64       break;
65     case 200:
66       Standard_Failure::Raise("Error occured during check of geometric coincidence");
67       break;
68     default:
69       {
70         // description of all errors see in GEOMAlgo_Gluer.cxx
71         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
72         aMsg += TCollection_AsciiString(iErr);
73         Standard_Failure::Raise(aMsg.ToCString());
74         break;
75       }
76     }
77     return aRes;
78   }
79
80   iWrn = aGluer.WarningStatus();
81   if (iWrn) {
82     switch (iWrn) {
83     case 1:
84       {
85         Standard_Integer nbAlone = aGluer.AloneShapes();
86         theWarning = TCollection_AsciiString(nbAlone);
87         theWarning += " solid(s) can not be glued by faces";
88       }
89       break;
90     default:
91       // description of all warnings see in GEOMAlgo_Gluer.cxx
92       theWarning = "Warning in GEOMAlgo_Gluer with code ";
93       theWarning += TCollection_AsciiString(iWrn);
94       break;
95     }
96   }
97
98   aRes = aGluer.Result();
99
100   return aRes;
101 }
102
103 //=======================================================================
104 //function : GlueFaces
105 //purpose  :
106 //=======================================================================
107 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
108                                              const Standard_Real theTolerance)
109 {
110   Standard_Integer iErr, iWrn;
111   TopoDS_Shape aRes;
112   GEOMAlgo_Gluer aGluer;
113
114   aGluer.SetShape(theShape);
115   aGluer.SetTolerance(theTolerance);
116   aGluer.SetCheckGeometry(Standard_True);
117
118   aGluer.Perform();
119
120   iErr = aGluer.ErrorStatus();
121   if (iErr) {
122     switch (iErr) {
123     case 2:
124       Standard_Failure::Raise("No vertices found in source shape");
125       break;
126     case 5:
127       Standard_Failure::Raise("Source shape is Null");
128       break;
129     case 6:
130       Standard_Failure::Raise("Result shape is Null");
131       break;
132     case 200:
133       Standard_Failure::Raise("Error occured during check of geometric coincidence");
134       break;
135     default:
136       {
137         // description of all errors see in GEOMAlgo_Gluer.cxx
138         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
139         aMsg += TCollection_AsciiString(iErr);
140         Standard_Failure::Raise(aMsg.ToCString());
141         break;
142       }
143     }
144     return aRes;
145   }
146
147   iWrn = aGluer.WarningStatus();
148   if (iWrn) {
149     switch (iWrn) {
150     case 1:
151       MESSAGE("Some shapes can not be glued by faces");
152       break;
153     default:
154       // description of all warnings see in GEOMAlgo_Gluer.cxx
155       MESSAGE("Warning in GEOMAlgo_Gluer with code " << iWrn);
156       break;
157     }
158   }
159
160   aRes = aGluer.Result();
161
162   return aRes;
163 }
164
165 //=======================================================================
166 //function : Execute
167 //purpose  :
168 //=======================================================================
169 Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
170 {
171   if (Label().IsNull()) return 0;
172   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
173
174   GEOMImpl_IGlue aCI (aFunction);
175   Standard_Integer aType = aFunction->GetType();
176
177   TopoDS_Shape aShape;
178   TCollection_AsciiString aWrn;
179
180   if (aType == GLUE_FACES) {
181     Handle(GEOM_Function) aRefBase = aCI.GetBase();
182     TopoDS_Shape aShapeBase = aRefBase->GetValue();
183     if (aShapeBase.IsNull()) {
184       Standard_NullObject::Raise("Shape for gluing is null");
185     }
186
187     Standard_Real tol3d = aCI.GetTolerance();
188     aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aWrn);
189   } else {
190   }
191
192   if (aShape.IsNull()) return 0;
193
194   aFunction->SetValue(aShape);
195
196   log.SetTouched(Label());
197
198   if (!aWrn.IsEmpty()) {
199     Standard_Failure::Raise(aWrn.ToCString());
200   }
201
202   return 1;
203 }
204
205 //=======================================================================
206 //function :  GEOMImpl_GlueDriver_Type_
207 //purpose  :
208 //=======================================================================
209 Standard_EXPORT Handle_Standard_Type& GEOMImpl_GlueDriver_Type_()
210 {
211
212   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
213   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
214   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
215   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
216   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
217   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
218
219
220   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
221   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_GlueDriver",
222                                                          sizeof(GEOMImpl_GlueDriver),
223                                                          1,
224                                                          (Standard_Address)_Ancestors,
225                                                          (Standard_Address)NULL);
226
227   return _aType;
228 }
229
230 //=======================================================================
231 //function : DownCast
232 //purpose  :
233 //=======================================================================
234 const Handle(GEOMImpl_GlueDriver) Handle(GEOMImpl_GlueDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
235 {
236   Handle(GEOMImpl_GlueDriver) _anOtherObject;
237
238   if (!AnObject.IsNull()) {
239      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_GlueDriver))) {
240        _anOtherObject = Handle(GEOMImpl_GlueDriver)((Handle(GEOMImpl_GlueDriver)&)AnObject);
241      }
242   }
243
244   return _anOtherObject ;
245 }