3 #include "GEOMImpl_GlueDriver.hxx"
4 #include "GEOMImpl_IGlue.hxx"
5 #include "GEOMImpl_Types.hxx"
7 #include "GEOM_Function.hxx"
9 #include "GEOMAlgo_Gluer.hxx"
11 #include "utilities.h"
13 #include <TopoDS_Shape.hxx>
14 #include <Standard_NullObject.hxx>
15 #include <Standard_Failure.hxx>
17 //=======================================================================
18 //function : GEOMImpl_GlueDriver
20 //=======================================================================
21 GEOMImpl_GlueDriver::GEOMImpl_GlueDriver()
25 //=======================================================================
28 //=======================================================================
29 const Standard_GUID& GEOMImpl_GlueDriver::GetID()
31 static Standard_GUID aGlueDriver("FF1BBB63-5D14-4df2-980B-3A668264EA16");
35 //=======================================================================
36 //function : GlueFacesWithWarnings
38 //=======================================================================
39 TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& theShape,
40 const Standard_Real theTolerance,
41 TCollection_AsciiString& theWarning) const
43 Standard_Integer iErr, iWrn;
45 GEOMAlgo_Gluer aGluer;
47 aGluer.SetShape(theShape);
48 aGluer.SetTolerance(theTolerance);
49 aGluer.SetCheckGeometry(Standard_True);
53 iErr = aGluer.ErrorStatus();
57 Standard_Failure::Raise("No vertices found in source shape");
60 Standard_Failure::Raise("Source shape is Null");
63 Standard_Failure::Raise("Result shape is Null");
66 Standard_Failure::Raise("Error occured during check of geometric coincidence");
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());
80 iWrn = aGluer.WarningStatus();
85 Standard_Integer nbAlone = aGluer.AloneShapes();
86 theWarning = TCollection_AsciiString(nbAlone);
87 theWarning += " solid(s) can not be glued by faces";
91 // description of all warnings see in GEOMAlgo_Gluer.cxx
92 theWarning = "Warning in GEOMAlgo_Gluer with code ";
93 theWarning += TCollection_AsciiString(iWrn);
98 aRes = aGluer.Result();
103 //=======================================================================
104 //function : GlueFaces
106 //=======================================================================
107 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
108 const Standard_Real theTolerance)
110 Standard_Integer iErr, iWrn;
112 GEOMAlgo_Gluer aGluer;
114 aGluer.SetShape(theShape);
115 aGluer.SetTolerance(theTolerance);
116 aGluer.SetCheckGeometry(Standard_True);
120 iErr = aGluer.ErrorStatus();
124 Standard_Failure::Raise("No vertices found in source shape");
127 Standard_Failure::Raise("Source shape is Null");
130 Standard_Failure::Raise("Result shape is Null");
133 Standard_Failure::Raise("Error occured during check of geometric coincidence");
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());
147 iWrn = aGluer.WarningStatus();
151 MESSAGE("Some shapes can not be glued by faces");
154 // description of all warnings see in GEOMAlgo_Gluer.cxx
155 MESSAGE("Warning in GEOMAlgo_Gluer with code " << iWrn);
160 aRes = aGluer.Result();
165 //=======================================================================
168 //=======================================================================
169 Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
171 if (Label().IsNull()) return 0;
172 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
174 GEOMImpl_IGlue aCI (aFunction);
175 Standard_Integer aType = aFunction->GetType();
178 TCollection_AsciiString aWrn;
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");
187 Standard_Real tol3d = aCI.GetTolerance();
188 aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aWrn);
192 if (aShape.IsNull()) return 0;
194 aFunction->SetValue(aShape);
196 log.SetTouched(Label());
198 if (!aWrn.IsEmpty()) {
199 Standard_Failure::Raise(aWrn.ToCString());
205 //=======================================================================
206 //function : GEOMImpl_GlueDriver_Type_
208 //=======================================================================
209 Standard_EXPORT Handle_Standard_Type& GEOMImpl_GlueDriver_Type_()
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);
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),
224 (Standard_Address)_Ancestors,
225 (Standard_Address)NULL);
230 //=======================================================================
231 //function : DownCast
233 //=======================================================================
234 const Handle(GEOMImpl_GlueDriver) Handle(GEOMImpl_GlueDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
236 Handle(GEOMImpl_GlueDriver) _anOtherObject;
238 if (!AnObject.IsNull()) {
239 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_GlueDriver))) {
240 _anOtherObject = Handle(GEOMImpl_GlueDriver)((Handle(GEOMImpl_GlueDriver)&)AnObject);
244 return _anOtherObject ;