2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_GlueDriver.hxx>
5 #include <GEOMImpl_IGlue.hxx>
6 #include <GEOMImpl_Types.hxx>
8 #include <GEOM_Object.hxx>
9 #include <GEOM_Function.hxx>
11 #include <GEOMAlgo_Gluer.hxx>
13 #include "utilities.h"
15 #include <TDataStd_IntegerArray.hxx>
18 #include <TopoDS_Shape.hxx>
19 #include <TopTools_ListOfShape.hxx>
20 #include <TopTools_IndexedMapOfShape.hxx>
21 #include <TopTools_ListIteratorOfListOfShape.hxx>
23 #include <Standard_NullObject.hxx>
24 #include <Standard_Failure.hxx>
26 #define MSG_BAD_TOLERANCE "Tolerance is too big"
27 #define MSG_BAD_ARG_SHAPE "Argument shape is not a compound of hexahedral solids"
29 //=======================================================================
30 //function : GEOMImpl_GlueDriver
32 //=======================================================================
33 GEOMImpl_GlueDriver::GEOMImpl_GlueDriver()
37 //=======================================================================
40 //=======================================================================
41 const Standard_GUID& GEOMImpl_GlueDriver::GetID()
43 static Standard_GUID aGlueDriver("FF1BBB63-5D14-4df2-980B-3A668264EA16");
47 //=======================================================================
48 //function : GlueFacesWithWarnings
50 //=======================================================================
51 TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& theShape,
52 const Standard_Real theTolerance,
53 TCollection_AsciiString& theWarning) const
55 Standard_Integer iErr, iWrn;
57 GEOMAlgo_Gluer aGluer;
59 aGluer.SetShape(theShape);
60 aGluer.SetTolerance(theTolerance);
61 aGluer.SetCheckGeometry(Standard_True);
65 iErr = aGluer.ErrorStatus();
69 Standard_Failure::Raise("No vertices found in source shape");
73 Standard_Failure::Raise(MSG_BAD_TOLERANCE " or " MSG_BAD_ARG_SHAPE);
76 Standard_Failure::Raise("Source shape is Null");
79 Standard_Failure::Raise("Result shape is Null");
82 Standard_Failure::Raise(MSG_BAD_TOLERANCE);
86 Standard_Failure::Raise(MSG_BAD_ARG_SHAPE);
89 Standard_Failure::Raise("Error occured during check of geometric coincidence");
93 // description of all errors see in GEOMAlgo_Gluer.cxx
94 TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
95 aMsg += TCollection_AsciiString(iErr);
96 Standard_Failure::Raise(aMsg.ToCString());
103 iWrn = aGluer.WarningStatus();
108 Standard_Integer nbAlone = aGluer.AloneShapes();
109 theWarning = TCollection_AsciiString(nbAlone);
110 theWarning += " solid(s) can not be glued by faces";
114 // description of all warnings see in GEOMAlgo_Gluer.cxx
115 theWarning = "Warning in GEOMAlgo_Gluer with code ";
116 theWarning += TCollection_AsciiString(iWrn);
121 aRes = aGluer.Result();
123 // Fill history to be used by GetInPlace functionality
124 TopTools_IndexedMapOfShape aResIndices;
125 TopExp::MapShapes(aRes, aResIndices);
127 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
129 // history for all argument shapes
130 TDF_LabelSequence aLabelSeq;
131 aFunction->GetDependency(aLabelSeq);
132 Standard_Integer nbArg = aLabelSeq.Length();
134 for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
136 TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
138 Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
139 TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
141 TopTools_IndexedMapOfShape anArgumentIndices;
142 TopExp::MapShapes(anArgumentShape, anArgumentIndices);
143 Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
145 // Find corresponding label in history
146 TDF_Label anArgumentHistoryLabel =
147 aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
149 for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
150 TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
151 const TopTools_ListOfShape& aModified = aGluer.Modified(anEntity);
152 Standard_Integer nbModified = aModified.Extent();
154 if (nbModified > 0) {
155 TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
156 Handle(TDataStd_IntegerArray) anAttr =
157 TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
159 TopTools_ListIteratorOfListOfShape itM (aModified);
160 for (int im = 1; itM.More(); itM.Next(), ++im) {
161 int id = aResIndices.FindIndex(itM.Value());
162 anAttr->SetValue(im, id);
171 //=======================================================================
172 //function : GlueFaces
174 //=======================================================================
175 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
176 const Standard_Real theTolerance)
178 Standard_Integer iErr, iWrn;
180 GEOMAlgo_Gluer aGluer;
182 aGluer.SetShape(theShape);
183 aGluer.SetTolerance(theTolerance);
184 aGluer.SetCheckGeometry(Standard_True);
188 iErr = aGluer.ErrorStatus();
192 Standard_Failure::Raise("No vertices found in source shape");
195 Standard_Failure::Raise("Source shape is Null");
198 Standard_Failure::Raise("Result shape is Null");
201 Standard_Failure::Raise("Error occured during check of geometric coincidence");
205 // description of all errors see in GEOMAlgo_Gluer.cxx
206 TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
207 aMsg += TCollection_AsciiString(iErr);
208 Standard_Failure::Raise(aMsg.ToCString());
215 iWrn = aGluer.WarningStatus();
219 MESSAGE("Some shapes can not be glued by faces");
222 // description of all warnings see in GEOMAlgo_Gluer.cxx
223 MESSAGE("Warning in GEOMAlgo_Gluer with code " << iWrn);
228 aRes = aGluer.Result();
233 //=======================================================================
236 //=======================================================================
237 Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
239 if (Label().IsNull()) return 0;
240 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
242 GEOMImpl_IGlue aCI (aFunction);
243 Standard_Integer aType = aFunction->GetType();
246 TCollection_AsciiString aWrn;
248 if (aType == GLUE_FACES) {
249 Handle(GEOM_Function) aRefBase = aCI.GetBase();
250 TopoDS_Shape aShapeBase = aRefBase->GetValue();
251 if (aShapeBase.IsNull()) {
252 Standard_NullObject::Raise("Shape for gluing is null");
255 Standard_Real tol3d = aCI.GetTolerance();
256 aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aWrn);
260 if (aShape.IsNull()) return 0;
262 aFunction->SetValue(aShape);
264 log.SetTouched(Label());
266 if (!aWrn.IsEmpty()) {
267 Standard_Failure::Raise(aWrn.ToCString());
273 //=======================================================================
274 //function : GEOMImpl_GlueDriver_Type_
276 //=======================================================================
277 Standard_EXPORT Handle_Standard_Type& GEOMImpl_GlueDriver_Type_()
280 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
281 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
282 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
283 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
284 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
285 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
288 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
289 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_GlueDriver",
290 sizeof(GEOMImpl_GlueDriver),
292 (Standard_Address)_Ancestors,
293 (Standard_Address)NULL);
298 //=======================================================================
299 //function : DownCast
301 //=======================================================================
302 const Handle(GEOMImpl_GlueDriver) Handle(GEOMImpl_GlueDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
304 Handle(GEOMImpl_GlueDriver) _anOtherObject;
306 if (!AnObject.IsNull()) {
307 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_GlueDriver))) {
308 _anOtherObject = Handle(GEOMImpl_GlueDriver)((Handle(GEOMImpl_GlueDriver)&)AnObject);
312 return _anOtherObject ;