]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_GlueDriver.cxx
Salome HOME
cd65a79fc71ac10499e666716f3ee531286dd314
[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
16 //=======================================================================
17 //function : GEOMImpl_GlueDriver
18 //purpose  :
19 //=======================================================================
20 GEOMImpl_GlueDriver::GEOMImpl_GlueDriver()
21 {
22 }
23
24 //=======================================================================
25 //function : GetID
26 //purpose  :
27 //=======================================================================
28 const Standard_GUID& GEOMImpl_GlueDriver::GetID()
29 {
30   static Standard_GUID aGlueDriver("FF1BBB63-5D14-4df2-980B-3A668264EA16");
31   return aGlueDriver;
32 }
33
34 //=======================================================================
35 //function : GlueFaces
36 //purpose  :
37 //=======================================================================
38 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
39                                              const Standard_Real theTolerance)
40 {
41   Standard_Integer iErr, iWrn;
42   TopoDS_Shape aRes;
43   GEOMAlgo_Gluer aGluer;
44
45   aGluer.SetShape(theShape);
46   aGluer.SetTolerance(theTolerance);
47   aGluer.SetCheckGeometry(Standard_True);
48
49   aGluer.Perform();
50
51   iErr = aGluer.ErrorStatus();
52   if (iErr) {
53     switch (iErr) {
54     case 2:
55       Standard_Failure::Raise("No vertices found in source shape");
56       break;
57     case 5:
58       Standard_Failure::Raise("Source shape is Null");
59       break;
60     case 6:
61       Standard_Failure::Raise("Result shape is Null");
62       break;
63     case 200:
64       Standard_Failure::Raise("Error occured during check of geometric coincidence");
65       break;
66     default:
67       {
68         // description of all errors see in GEOMAlgo_Gluer.cxx
69         TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
70         aMsg += TCollection_AsciiString(iErr);
71         Standard_Failure::Raise(aMsg.ToCString());
72         break;
73       }
74     }
75     return aRes;
76   }
77
78   iWrn = aGluer.WarningStatus();
79   if (iWrn) {
80     switch (iWrn) {
81     case 1:
82       MESSAGE("Some shapes can not be glued by faces");
83       break;
84     default:
85       // description of all warnings see in GEOMAlgo_Gluer.cxx
86       MESSAGE("Warning in GEOMAlgo_Gluer with code " << iWrn);
87       break;
88     }
89   }
90
91   aRes = aGluer.Result();
92
93   return aRes;
94 }
95
96 //=======================================================================
97 //function : Execute
98 //purpose  :
99 //=======================================================================
100 Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
101 {
102   if (Label().IsNull()) return 0;
103   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
104
105   GEOMImpl_IGlue aCI (aFunction);
106   Standard_Integer aType = aFunction->GetType();
107
108   TopoDS_Shape aShape;
109
110   if (aType == GLUE_FACES) {
111     Handle(GEOM_Function) aRefBase = aCI.GetBase();
112     TopoDS_Shape aShapeBase = aRefBase->GetValue();
113     if (aShapeBase.IsNull()) {
114       Standard_NullObject::Raise("Shape for gluing is null");
115     }
116
117     Standard_Real tol3d = aCI.GetTolerance();
118     aShape = GlueFaces(aShapeBase, tol3d);
119   } else {
120   }
121
122   if (aShape.IsNull()) return 0;
123
124   aFunction->SetValue(aShape);
125
126   log.SetTouched(Label());
127
128   return 1;
129 }
130
131 //=======================================================================
132 //function :  GEOMImpl_GlueDriver_Type_
133 //purpose  :
134 //=======================================================================
135 Standard_EXPORT Handle_Standard_Type& GEOMImpl_GlueDriver_Type_()
136 {
137
138   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
139   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
140   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
141   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
142   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
143   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
144
145
146   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
147   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_GlueDriver",
148                                                          sizeof(GEOMImpl_GlueDriver),
149                                                          1,
150                                                          (Standard_Address)_Ancestors,
151                                                          (Standard_Address)NULL);
152
153   return _aType;
154 }
155
156 //=======================================================================
157 //function : DownCast
158 //purpose  :
159 //=======================================================================
160 const Handle(GEOMImpl_GlueDriver) Handle(GEOMImpl_GlueDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
161 {
162   Handle(GEOMImpl_GlueDriver) _anOtherObject;
163
164   if (!AnObject.IsNull()) {
165      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_GlueDriver))) {
166        _anOtherObject = Handle(GEOMImpl_GlueDriver)((Handle(GEOMImpl_GlueDriver)&)AnObject);
167      }
168   }
169
170   return _anOtherObject ;
171 }