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 #define MSG_BAD_TOLERANCE "Tolerance is too big"
26 #define MSG_BAD_ARG_SHAPE "Argument shape is not a compound of hexahedral solids"
28 //=======================================================================
29 //function : GEOMImpl_GlueDriver
31 //=======================================================================
32 GEOMImpl_GlueDriver::GEOMImpl_GlueDriver()
36 //=======================================================================
39 //=======================================================================
40 const Standard_GUID& GEOMImpl_GlueDriver::GetID()
42 static Standard_GUID aGlueDriver("FF1BBB63-5D14-4df2-980B-3A668264EA16");
46 //=======================================================================
47 //function : GlueFacesWithWarnings
49 //=======================================================================
50 TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesWithWarnings (const TopoDS_Shape& theShape,
51 const Standard_Real theTolerance,
52 TCollection_AsciiString& theWarning) const
54 Standard_Integer iErr, iWrn;
56 GEOMAlgo_Gluer aGluer;
58 aGluer.SetShape(theShape);
59 aGluer.SetTolerance(theTolerance);
60 aGluer.SetCheckGeometry(Standard_True);
64 iErr = aGluer.ErrorStatus();
68 Standard_Failure::Raise("No vertices found in source shape");
72 Standard_Failure::Raise(MSG_BAD_TOLERANCE " or " MSG_BAD_ARG_SHAPE);
75 Standard_Failure::Raise("Source shape is Null");
78 Standard_Failure::Raise("Result shape is Null");
81 Standard_Failure::Raise(MSG_BAD_TOLERANCE);
85 Standard_Failure::Raise(MSG_BAD_ARG_SHAPE);
88 Standard_Failure::Raise("Error occured during check of geometric coincidence");
92 // description of all errors see in GEOMAlgo_Gluer.cxx
93 TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
94 aMsg += TCollection_AsciiString(iErr);
95 Standard_Failure::Raise(aMsg.ToCString());
102 iWrn = aGluer.WarningStatus();
107 Standard_Integer nbAlone = aGluer.AloneShapes();
108 theWarning = TCollection_AsciiString(nbAlone);
109 theWarning += " solid(s) can not be glued by faces";
113 // description of all warnings see in GEOMAlgo_Gluer.cxx
114 theWarning = "Warning in GEOMAlgo_Gluer with code ";
115 theWarning += TCollection_AsciiString(iWrn);
120 aRes = aGluer.Result();
122 // Fill history to be used by GetInPlace functionality
123 TopTools_IndexedMapOfShape aResIndices;
124 TopExp::MapShapes(aRes, aResIndices);
126 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
128 // history for all argument shapes
129 TDF_LabelSequence aLabelSeq;
130 aFunction->GetDependency(aLabelSeq);
131 Standard_Integer nbArg = aLabelSeq.Length();
133 for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
135 TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
137 Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
138 TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
140 TopTools_IndexedMapOfShape anArgumentIndices;
141 TopExp::MapShapes(anArgumentShape, anArgumentIndices);
142 Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
144 // Find corresponding label in history
145 TDF_Label anArgumentHistoryLabel =
146 aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
148 for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
149 TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
150 const TopTools_ListOfShape& aModified = aGluer.Modified(anEntity);
151 Standard_Integer nbModified = aModified.Extent();
153 if (nbModified > 0) {
154 TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
155 Handle(TDataStd_IntegerArray) anAttr =
156 TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
158 TopTools_ListIteratorOfListOfShape itM (aModified);
159 for (int im = 1; itM.More(); itM.Next(), ++im) {
160 int id = aResIndices.FindIndex(itM.Value());
161 anAttr->SetValue(im, id);
170 //=======================================================================
171 //function : GlueFaces
173 //=======================================================================
174 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
175 const Standard_Real theTolerance)
177 Standard_Integer iErr, iWrn;
179 GEOMAlgo_Gluer aGluer;
181 aGluer.SetShape(theShape);
182 aGluer.SetTolerance(theTolerance);
183 aGluer.SetCheckGeometry(Standard_True);
187 iErr = aGluer.ErrorStatus();
191 Standard_Failure::Raise("No vertices found in source shape");
194 Standard_Failure::Raise("Source shape is Null");
197 Standard_Failure::Raise("Result shape is Null");
200 Standard_Failure::Raise("Error occured during check of geometric coincidence");
204 // description of all errors see in GEOMAlgo_Gluer.cxx
205 TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
206 aMsg += TCollection_AsciiString(iErr);
207 Standard_Failure::Raise(aMsg.ToCString());
214 iWrn = aGluer.WarningStatus();
218 MESSAGE("Some shapes can not be glued by faces");
221 // description of all warnings see in GEOMAlgo_Gluer.cxx
222 MESSAGE("Warning in GEOMAlgo_Gluer with code " << iWrn);
227 aRes = aGluer.Result();
232 //=======================================================================
235 //=======================================================================
236 Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
238 if (Label().IsNull()) return 0;
239 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
241 GEOMImpl_IGlue aCI (aFunction);
242 Standard_Integer aType = aFunction->GetType();
245 TCollection_AsciiString aWrn;
247 if (aType == GLUE_FACES) {
248 Handle(GEOM_Function) aRefBase = aCI.GetBase();
249 TopoDS_Shape aShapeBase = aRefBase->GetValue();
250 if (aShapeBase.IsNull()) {
251 Standard_NullObject::Raise("Shape for gluing is null");
254 Standard_Real tol3d = aCI.GetTolerance();
255 aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aWrn);
259 if (aShape.IsNull()) return 0;
261 aFunction->SetValue(aShape);
263 log.SetTouched(Label());
265 if (!aWrn.IsEmpty()) {
266 Standard_Failure::Raise(aWrn.ToCString());
272 //=======================================================================
273 //function : GEOMImpl_GlueDriver_Type_
275 //=======================================================================
276 Standard_EXPORT Handle_Standard_Type& GEOMImpl_GlueDriver_Type_()
279 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
280 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
281 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
282 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
283 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
284 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
287 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
288 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_GlueDriver",
289 sizeof(GEOMImpl_GlueDriver),
291 (Standard_Address)_Ancestors,
292 (Standard_Address)NULL);
297 //=======================================================================
298 //function : DownCast
300 //=======================================================================
301 const Handle(GEOMImpl_GlueDriver) Handle(GEOMImpl_GlueDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
303 Handle(GEOMImpl_GlueDriver) _anOtherObject;
305 if (!AnObject.IsNull()) {
306 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_GlueDriver))) {
307 _anOtherObject = Handle(GEOMImpl_GlueDriver)((Handle(GEOMImpl_GlueDriver)&)AnObject);
311 return _anOtherObject ;