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 <BRepFilletAPI_MakeChamfer.hxx>
11 #include <BRep_Tool.hxx>
12 #include <BRepTools.hxx>
16 #include <TopoDS_Shape.hxx>
17 #include <TopoDS_Edge.hxx>
18 #include <TopoDS_Face.hxx>
19 #include <TopoDS_Iterator.hxx>
21 #include <TopExp_Explorer.hxx>
22 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
23 #include <TopTools_MapOfShape.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 //=======================================================================
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 // to do: check the shape type.
94 // It have to be shell, or solid, or compsolid, or compound of these shapes
95 if (!isGoodForChamfer(aShapeBase)) {
96 StdFail_NotDone::Raise("Wrong shape. Must be shell or solid, or compsolid or compound of these shapes");
99 BRepFilletAPI_MakeChamfer fill (aShapeBase);
101 if (aType == CHAMFER_SHAPE_ALL) {
102 // symmetric chamfer on all edges
103 double aD = aCI.GetD();
104 TopTools_IndexedDataMapOfShapeListOfShape M;
105 GEOMImpl_Block6Explorer::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, M);
106 for (int i = 1; i <= M.Extent(); i++) {
107 TopoDS_Edge E = TopoDS::Edge(M.FindKey(i));
108 TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First());
109 if (!BRepTools::IsReallyClosed(E, F) &&
110 !BRep_Tool::Degenerated(E) &&
111 M.FindFromIndex(i).Extent() == 2)
114 } else if (aType == CHAMFER_SHAPE_EDGE) {
115 // chamfer on edges, common to two faces, with D1 on the first face
116 double aD1 = aCI.GetD1();
117 double aD2 = aCI.GetD2();
118 TopoDS_Shape aFace1, aFace2;
119 if (GEOMImpl_ILocalOperations::GetSubShape(aShapeBase, aCI.GetFace1(), aFace1) &&
120 GEOMImpl_ILocalOperations::GetSubShape(aShapeBase, aCI.GetFace2(), aFace2)) {
121 TopoDS_Face F = TopoDS::Face(aFace1);
123 // fill map of edges of the second face
124 TopTools_MapOfShape aMap;
125 TopExp_Explorer Exp2 (aFace2, TopAbs_EDGE);
126 for (; Exp2.More(); Exp2.Next()) {
127 aMap.Add(Exp2.Current());
130 // find edges of the first face, common with the second face
131 TopExp_Explorer Exp (aFace1, TopAbs_EDGE);
132 for (Exp; Exp.More(); Exp.Next()) {
133 if (aMap.Contains(Exp.Current())) {
134 TopoDS_Edge E = TopoDS::Edge(Exp.Current());
135 if (!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E))
136 fill.Add(aD1, aD2, E, F);
140 } else if (aType == CHAMFER_SHAPE_FACES) {
141 // chamfer on all edges of the selected faces, with D1 on the selected face
142 // (on first selected face, if the edge belongs to two selected faces)
143 double aD1 = aCI.GetD1();
144 double aD2 = aCI.GetD2();
145 int aLen = aCI.GetLength();
147 TopTools_MapOfShape aMap;
148 TopTools_IndexedDataMapOfShapeListOfShape M;
149 GEOMImpl_Block6Explorer::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, M);
150 for (; ind <= aLen; ind++)
152 TopoDS_Shape aShapeFace;
153 if (GEOMImpl_ILocalOperations::GetSubShape
154 (aShapeBase, aCI.GetFace(ind), aShapeFace)) {
155 TopoDS_Face F = TopoDS::Face(aShapeFace);
156 TopExp_Explorer Exp (F, TopAbs_EDGE);
157 for (Exp; Exp.More(); Exp.Next()) {
158 if (!aMap.Contains(Exp.Current())) {
159 TopoDS_Edge E = TopoDS::Edge(Exp.Current());
160 if (!BRepTools::IsReallyClosed(E, F) &&
161 !BRep_Tool::Degenerated(E) &&
162 M.FindFromKey(E).Extent() == 2)
163 fill.Add(aD1, aD2, E, F);
172 if (!fill.IsDone()) {
173 StdFail_NotDone::Raise("Chamfer can not be computed on the given shape with the given parameters");
175 aShape = fill.Shape();
177 if (aShape.IsNull()) return 0;
179 aFunction->SetValue(aShape);
181 log.SetTouched(Label());
187 //=======================================================================
188 //function : GEOMImpl_ChamferDriver_Type_
190 //=======================================================================
191 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ChamferDriver_Type_()
194 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
195 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
196 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
197 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
198 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
199 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
202 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
203 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ChamferDriver",
204 sizeof(GEOMImpl_ChamferDriver),
206 (Standard_Address)_Ancestors,
207 (Standard_Address)NULL);
212 //=======================================================================
213 //function : DownCast
215 //=======================================================================
216 const Handle(GEOMImpl_ChamferDriver) Handle(GEOMImpl_ChamferDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
218 Handle(GEOMImpl_ChamferDriver) _anOtherObject;
220 if (!AnObject.IsNull()) {
221 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ChamferDriver))) {
222 _anOtherObject = Handle(GEOMImpl_ChamferDriver)((Handle(GEOMImpl_ChamferDriver)&)AnObject);
226 return _anOtherObject ;