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("Error occured during check of geometric coincidence");
78 // description of all errors see in GEOMAlgo_Gluer.cxx
79 TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
80 aMsg += TCollection_AsciiString(iErr);
81 Standard_Failure::Raise(aMsg.ToCString());
88 iWrn = aGluer.WarningStatus();
93 Standard_Integer nbAlone = aGluer.AloneShapes();
94 theWarning = TCollection_AsciiString(nbAlone);
95 theWarning += " solid(s) can not be glued by faces";
99 // description of all warnings see in GEOMAlgo_Gluer.cxx
100 theWarning = "Warning in GEOMAlgo_Gluer with code ";
101 theWarning += TCollection_AsciiString(iWrn);
106 aRes = aGluer.Result();
108 // Fill history to be used by GetInPlace functionality
109 TopTools_IndexedMapOfShape aResIndices;
110 TopExp::MapShapes(aRes, aResIndices);
112 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
114 // history for all argument shapes
115 TDF_LabelSequence aLabelSeq;
116 aFunction->GetDependency(aLabelSeq);
117 Standard_Integer nbArg = aLabelSeq.Length();
119 for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
121 TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
123 Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
124 TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
126 TopTools_IndexedMapOfShape anArgumentIndices;
127 TopExp::MapShapes(anArgumentShape, anArgumentIndices);
128 Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
130 // Find corresponding label in history
131 TDF_Label anArgumentHistoryLabel =
132 aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
134 for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
135 TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
136 const TopTools_ListOfShape& aModified = aGluer.Modified(anEntity);
137 Standard_Integer nbModified = aModified.Extent();
139 if (nbModified > 0) {
140 TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
141 Handle(TDataStd_IntegerArray) anAttr =
142 TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
144 TopTools_ListIteratorOfListOfShape itM (aModified);
145 for (int im = 1; itM.More(); itM.Next(), ++im) {
146 int id = aResIndices.FindIndex(itM.Value());
147 anAttr->SetValue(im, id);
156 //=======================================================================
157 //function : GlueFaces
159 //=======================================================================
160 TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
161 const Standard_Real theTolerance)
163 Standard_Integer iErr, iWrn;
165 GEOMAlgo_Gluer aGluer;
167 aGluer.SetShape(theShape);
168 aGluer.SetTolerance(theTolerance);
169 aGluer.SetCheckGeometry(Standard_True);
173 iErr = aGluer.ErrorStatus();
177 Standard_Failure::Raise("No vertices found in source shape");
180 Standard_Failure::Raise("Source shape is Null");
183 Standard_Failure::Raise("Result shape is Null");
186 Standard_Failure::Raise("Error occured during check of geometric coincidence");
190 // description of all errors see in GEOMAlgo_Gluer.cxx
191 TCollection_AsciiString aMsg ("Error in GEOMAlgo_Gluer with code ");
192 aMsg += TCollection_AsciiString(iErr);
193 Standard_Failure::Raise(aMsg.ToCString());
200 iWrn = aGluer.WarningStatus();
204 MESSAGE("Some shapes can not be glued by faces");
207 // description of all warnings see in GEOMAlgo_Gluer.cxx
208 MESSAGE("Warning in GEOMAlgo_Gluer with code " << iWrn);
213 aRes = aGluer.Result();
218 //=======================================================================
221 //=======================================================================
222 Standard_Integer GEOMImpl_GlueDriver::Execute(TFunction_Logbook& log) const
224 if (Label().IsNull()) return 0;
225 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
227 GEOMImpl_IGlue aCI (aFunction);
228 Standard_Integer aType = aFunction->GetType();
231 TCollection_AsciiString aWrn;
233 if (aType == GLUE_FACES) {
234 Handle(GEOM_Function) aRefBase = aCI.GetBase();
235 TopoDS_Shape aShapeBase = aRefBase->GetValue();
236 if (aShapeBase.IsNull()) {
237 Standard_NullObject::Raise("Shape for gluing is null");
240 Standard_Real tol3d = aCI.GetTolerance();
241 aShape = GlueFacesWithWarnings(aShapeBase, tol3d, aWrn);
245 if (aShape.IsNull()) return 0;
247 aFunction->SetValue(aShape);
249 log.SetTouched(Label());
251 if (!aWrn.IsEmpty()) {
252 Standard_Failure::Raise(aWrn.ToCString());
258 //=======================================================================
259 //function : GEOMImpl_GlueDriver_Type_
261 //=======================================================================
262 Standard_EXPORT Handle_Standard_Type& GEOMImpl_GlueDriver_Type_()
265 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
266 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
267 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
268 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
269 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
270 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
273 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
274 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_GlueDriver",
275 sizeof(GEOMImpl_GlueDriver),
277 (Standard_Address)_Ancestors,
278 (Standard_Address)NULL);
283 //=======================================================================
284 //function : DownCast
286 //=======================================================================
287 const Handle(GEOMImpl_GlueDriver) Handle(GEOMImpl_GlueDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
289 Handle(GEOMImpl_GlueDriver) _anOtherObject;
291 if (!AnObject.IsNull()) {
292 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_GlueDriver))) {
293 _anOtherObject = Handle(GEOMImpl_GlueDriver)((Handle(GEOMImpl_GlueDriver)&)AnObject);
297 return _anOtherObject ;