3 #include "GEOMImpl_ChamferDriver.hxx"
4 #include "GEOMImpl_IChamfer.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOMImpl_ILocalOperations.hxx"
7 #include "GEOM_Function.hxx"
8 #include "GEOMImpl_Block6Explorer.hxx"
10 #include <BRep_Tool.hxx>
11 #include <BRepTools.hxx>
12 #include <BRepFilletAPI_MakeChamfer.hxx>
16 #include <TopoDS_Edge.hxx>
17 #include <TopoDS_Face.hxx>
18 #include <TopoDS_Shape.hxx>
19 #include <TopoDS_Iterator.hxx>
21 #include <TopExp_Explorer.hxx>
22 #include <TopTools_MapOfShape.hxx>
23 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
25 #include <Precision.hxx>
27 #include <StdFail_NotDone.hxx>
29 //=======================================================================
32 //=======================================================================
33 const Standard_GUID& GEOMImpl_ChamferDriver::GetID()
35 static Standard_GUID aChamferDriver("FF1BBB42-5D14-4df2-980B-3A668264EA16");
36 return aChamferDriver;
40 //=======================================================================
41 //function : GEOMImpl_ChamferDriver
43 //=======================================================================
44 GEOMImpl_ChamferDriver::GEOMImpl_ChamferDriver()
48 //=======================================================================
49 //function : isGoodForChamfer
51 //=======================================================================
52 static Standard_Boolean isGoodForChamfer (const TopoDS_Shape& theShape)
54 if (theShape.ShapeType() == TopAbs_SHELL ||
55 theShape.ShapeType() == TopAbs_SOLID ||
56 theShape.ShapeType() == TopAbs_COMPSOLID) {
60 if (theShape.ShapeType() == TopAbs_COMPOUND) {
61 TopTools_MapOfShape mapShape;
62 TopoDS_Iterator It (theShape, Standard_False, Standard_False);
63 for (; It.More(); It.Next()) {
64 if (mapShape.Add(It.Value())) {
65 if (!isGoodForChamfer(It.Value())) {
66 return Standard_False;
73 return Standard_False;
76 //=======================================================================
79 //=======================================================================
80 Standard_Integer GEOMImpl_ChamferDriver::Execute(TFunction_Logbook& log) const
82 if (Label().IsNull()) return 0;
83 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
85 GEOMImpl_IChamfer aCI (aFunction);
86 Standard_Integer aType = aFunction->GetType();
90 Handle(GEOM_Function) aRefShape = aCI.GetShape();
91 TopoDS_Shape aShapeBase = aRefShape->GetValue();
93 // Check the shape type. It have to be shell
94 // or solid, or compsolid, or compound of these shapes.
95 if (!isGoodForChamfer(aShapeBase)) {
96 StdFail_NotDone::Raise
97 ("Wrong shape. Must be shell or solid, or compsolid or compound of these shapes");
100 BRepFilletAPI_MakeChamfer fill (aShapeBase);
102 if (aType == CHAMFER_SHAPE_ALL) {
103 // symmetric chamfer on all edges
104 double aD = aCI.GetD();
105 TopTools_IndexedDataMapOfShapeListOfShape M;
106 GEOMImpl_Block6Explorer::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, M);
107 for (int i = 1; i <= M.Extent(); i++) {
108 TopoDS_Edge E = TopoDS::Edge(M.FindKey(i));
109 TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First());
110 if (!BRepTools::IsReallyClosed(E, F) &&
111 !BRep_Tool::Degenerated(E) &&
112 M.FindFromIndex(i).Extent() == 2)
115 } else if (aType == CHAMFER_SHAPE_EDGE) {
116 // chamfer on edges, common to two faces, with D1 on the first face
117 double aD1 = aCI.GetD1();
118 double aD2 = aCI.GetD2();
119 TopoDS_Shape aFace1, aFace2;
120 if (GEOMImpl_ILocalOperations::GetSubShape(aShapeBase, aCI.GetFace1(), aFace1) &&
121 GEOMImpl_ILocalOperations::GetSubShape(aShapeBase, aCI.GetFace2(), aFace2)) {
122 TopoDS_Face F = TopoDS::Face(aFace1);
124 // fill map of edges of the second face
125 TopTools_MapOfShape aMap;
126 TopExp_Explorer Exp2 (aFace2, TopAbs_EDGE);
127 for (; Exp2.More(); Exp2.Next()) {
128 aMap.Add(Exp2.Current());
131 // find edges of the first face, common with the second face
132 TopExp_Explorer Exp (aFace1, TopAbs_EDGE);
133 for (; Exp.More(); Exp.Next()) {
134 if (aMap.Contains(Exp.Current())) {
135 TopoDS_Edge E = TopoDS::Edge(Exp.Current());
136 if (!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E))
137 fill.Add(aD1, aD2, E, F);
141 } else if (aType == CHAMFER_SHAPE_FACES) {
142 // chamfer on all edges of the selected faces, with D1 on the selected face
143 // (on first selected face, if the edge belongs to two selected faces)
144 double aD1 = aCI.GetD1();
145 double aD2 = aCI.GetD2();
146 int aLen = aCI.GetLength();
148 TopTools_MapOfShape aMap;
149 TopTools_IndexedDataMapOfShapeListOfShape M;
150 GEOMImpl_Block6Explorer::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, M);
151 for (; ind <= aLen; ind++)
153 TopoDS_Shape aShapeFace;
154 if (GEOMImpl_ILocalOperations::GetSubShape
155 (aShapeBase, aCI.GetFace(ind), aShapeFace)) {
156 TopoDS_Face F = TopoDS::Face(aShapeFace);
157 TopExp_Explorer Exp (F, TopAbs_EDGE);
158 for (; Exp.More(); Exp.Next()) {
159 if (!aMap.Contains(Exp.Current())) {
160 TopoDS_Edge E = TopoDS::Edge(Exp.Current());
161 if (!BRepTools::IsReallyClosed(E, F) &&
162 !BRep_Tool::Degenerated(E) &&
163 M.FindFromKey(E).Extent() == 2)
164 fill.Add(aD1, aD2, E, F);
173 if (!fill.IsDone()) {
174 StdFail_NotDone::Raise("Chamfer can not be computed on the given shape with the given parameters");
176 aShape = fill.Shape();
178 if (aShape.IsNull()) return 0;
180 aFunction->SetValue(aShape);
182 log.SetTouched(Label());
188 //=======================================================================
189 //function : GEOMImpl_ChamferDriver_Type_
191 //=======================================================================
192 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ChamferDriver_Type_()
195 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
196 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
197 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
198 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
199 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
200 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
203 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
204 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ChamferDriver",
205 sizeof(GEOMImpl_ChamferDriver),
207 (Standard_Address)_Ancestors,
208 (Standard_Address)NULL);
213 //=======================================================================
214 //function : DownCast
216 //=======================================================================
217 const Handle(GEOMImpl_ChamferDriver) Handle(GEOMImpl_ChamferDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
219 Handle(GEOMImpl_ChamferDriver) _anOtherObject;
221 if (!AnObject.IsNull()) {
222 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ChamferDriver))) {
223 _anOtherObject = Handle(GEOMImpl_ChamferDriver)((Handle(GEOMImpl_ChamferDriver)&)AnObject);
227 return _anOtherObject ;