3 #include "GEOMImpl_GlueDriver.hxx"
4 #include "GEOMImpl_IGlue.hxx"
5 #include "GEOMImpl_Types.hxx"
7 #include "GEOM_Object.hxx"
8 #include "GEOM_Function.hxx"
10 #include "GEOMAlgo_Gluer.hxx"
12 #include "utilities.h"
14 #include <TDataStd_IntegerArray.hxx>
17 #include <TopoDS_Shape.hxx>
18 #include <TopTools_ListOfShape.hxx>
19 #include <TopTools_IndexedMapOfShape.hxx>
20 #include <TopTools_ListIteratorOfListOfShape.hxx>
22 #include <Standard_NullObject.hxx>
23 #include <Standard_Failure.hxx>
25 //=======================================================================
26 //function : GEOMImpl_GlueDriver
28 //=======================================================================
29 GEOMImpl_GlueDriver::GEOMImpl_GlueDriver()
33 //=======================================================================
36 //=======================================================================
37 const Standard_GUID& GEOMImpl_GlueDriver::GetID()
39 static Standard_GUID aGlueDriver("FF1BBB63-5D14-4df2-980B-3A668264EA16");
43 //=======================================================================
44 //function : GlueFacesWithWarnings
46 //=======================================================================
47 TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& theShape,
48 const Standard_Real theTolerance,
49 TCollection_AsciiString& theWarning) const
51 Standard_Integer iErr, iWrn;
53 GEOMAlgo_Gluer aGluer;
55 aGluer.SetShape(theShape);
56 aGluer.SetTolerance(theTolerance);
57 aGluer.SetCheckGeometry(Standard_True);
61 iErr = aGluer.ErrorStatus();
65 Standard_Failure::Raise("No vertices found in source shape");
68 Standard_Failure::Raise("Source shape is Null");
71 Standard_Failure::Raise("Result shape is Null");
74 Standard_Failure::Raise("Argument shape is not a compound of hexahedral solids");
77 Standard_Failure::Raise("Error occured during check of geometric coincidence");
81 // description of all errors see in GEOMAlgo_Gluer.cxx
82 TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
83 aMsg += TCollection_AsciiString(iErr);
84 Standard_Failure::Raise(aMsg.ToCString());
91 iWrn = aGluer.WarningStatus();
96 Standard_Integer nbAlone = aGluer.AloneShapes();
97 theWarning = TCollection_AsciiString(nbAlone);
98 theWarning += " solid(s) can not be glued by faces";
102 // description of all warnings see in GEOMAlgo_Gluer.cxx
103 theWarning = "Warning in GEOMAlgo_Gluer with code ";
104 theWarning += TCollection_AsciiString(iWrn);
109 aRes = aGluer.Result();
111 // Fill history to be used by GetInPlace functionality
112 TopTools_IndexedMapOfShape aResIndices;
113 TopExp::MapShapes(aRes, aResIndices);
115 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
117 // history for all argument shapes
118 TDF_LabelSequence aLabelSeq;
119 aFunction->GetDependency(aLabelSeq);
120 Standard_Integer nbArg = aLabelSeq.Length();
122 for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
124 TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
126 Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
127 TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
129 TopTools_IndexedMapOfShape anArgumentIndices;
130 TopExp::MapShapes(anArgumentShape, anArgumentIndices);
131 Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
133 // Find corresponding label in history
134 TDF_Label anArgumentHistoryLabel =
135 aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
137 for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
138 TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
139 const TopTools_ListOfShape& aModified = aGluer.Modified(anEntity);
140 Standard_Integer nbModified = aModified.Extent();
142 if (nbModified > 0) {
143 TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
144 Handle(TDataStd_IntegerArray) anAttr =
145 TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
147 TopTools_ListIteratorOfListOfShape itM (aModified);
148 for (int im = 1; itM.More(); itM.Next(), ++im) {
149 int id = aResIndices.FindIndex(itM.Value());
150 anAttr->SetValue(im, id);
159 //=======================================================================
160 //function : GlueFaces
162 //=======================================================================
163 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
164 const Standard_Real theTolerance)
166 Standard_Integer iErr, iWrn;
168 GEOMAlgo_Gluer aGluer;
170 aGluer.SetShape(theShape);
171 aGluer.SetTolerance(theTolerance);
172 aGluer.SetCheckGeometry(Standard_True);
176 iErr = aGluer.ErrorStatus();
180 Standard_Failure::Raise("No vertices found in source shape");
183 Standard_Failure::Raise("Source shape is Null");
186 Standard_Failure::Raise("Result shape is Null");
189 Standard_Failure::Raise("Error occured during check of geometric coincidence");
193 // description of all errors see in GEOMAlgo_Gluer.cxx
194 TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
195 aMsg += TCollection_AsciiString(iErr);
196 Standard_Failure::Raise(aMsg.ToCString());
203 iWrn = aGluer.WarningStatus();
207 MESSAGE("Some shapes can not be glued by faces");
210 // description of all warnings see in GEOMAlgo_Gluer.cxx
211 MESSAGE("Warning in GEOMAlgo_Gluer with code " << iWrn);
216 aRes = aGluer.Result();
221 //=======================================================================
224 //=======================================================================
225 Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
227 if (Label().IsNull()) return 0;
228 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
230 GEOMImpl_IGlue aCI (aFunction);
231 Standard_Integer aType = aFunction->GetType();
234 TCollection_AsciiString aWrn;
236 if (aType == GLUE_FACES) {
237 Handle(GEOM_Function) aRefBase = aCI.GetBase();
238 TopoDS_Shape aShapeBase = aRefBase->GetValue();
239 if (aShapeBase.IsNull()) {
240 Standard_NullObject::Raise("Shape for gluing is null");
243 Standard_Real tol3d = aCI.GetTolerance();
244 aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aWrn);
248 if (aShape.IsNull()) return 0;
250 aFunction->SetValue(aShape);
252 log.SetTouched(Label());
254 if (!aWrn.IsEmpty()) {
255 Standard_Failure::Raise(aWrn.ToCString());
261 //=======================================================================
262 //function : GEOMImpl_GlueDriver_Type_
264 //=======================================================================
265 Standard_EXPORT Handle_Standard_Type& GEOMImpl_GlueDriver_Type_()
268 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
269 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
270 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
271 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
272 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
273 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
276 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
277 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_GlueDriver",
278 sizeof(GEOMImpl_GlueDriver),
280 (Standard_Address)_Ancestors,
281 (Standard_Address)NULL);
286 //=======================================================================
287 //function : DownCast
289 //=======================================================================
290 const Handle(GEOMImpl_GlueDriver) Handle(GEOMImpl_GlueDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
292 Handle(GEOMImpl_GlueDriver) _anOtherObject;
294 if (!AnObject.IsNull()) {
295 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_GlueDriver))) {
296 _anOtherObject = Handle(GEOMImpl_GlueDriver)((Handle(GEOMImpl_GlueDriver)&)AnObject);
300 return _anOtherObject ;