4 #include "GEOMImpl_FillingDriver.hxx"
5 #include "GEOM_Function.hxx"
6 #include "GEOMImpl_IFilling.hxx"
7 #include "GEOMImpl_Types.hxx"
9 #include <BRep_Tool.hxx>
10 #include <BRepAlgo.hxx>
11 #include <BRepBuilderAPI_MakeFace.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <TopExp_Explorer.hxx>
18 #include <Geom_Curve.hxx>
19 #include <Geom_Surface.hxx>
20 #include <Geom_TrimmedCurve.hxx>
21 #include <Geom_BSplineSurface.hxx>
22 #include <GeomFill_Line.hxx>
23 #include <GeomFill_AppSurf.hxx>
24 #include <GeomFill_SectionGenerator.hxx>
26 #include <Precision.hxx>
27 #include <Standard_ConstructionError.hxx>
29 //=======================================================================
32 //=======================================================================
33 const Standard_GUID& GEOMImpl_FillingDriver::GetID()
35 static Standard_GUID aFillingDriver ("FF1BBB62-5D14-4df2-980B-3A668264EA16");
36 return aFillingDriver;
40 //=======================================================================
41 //function : GEOMImpl_FillingDriver
43 //=======================================================================
45 GEOMImpl_FillingDriver::GEOMImpl_FillingDriver()
49 //=======================================================================
52 //=======================================================================
53 Standard_Integer GEOMImpl_FillingDriver::Execute(TFunction_Logbook& log) const
55 if (Label().IsNull()) return 0;
56 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
57 if (aFunction.IsNull()) return 0;
59 if (aFunction->GetType() != BASIC_FILLING) return 0;
61 GEOMImpl_IFilling IF (aFunction);
62 Handle(GEOM_Function) aShapeFunction = IF.GetShape();
63 if (aShapeFunction.IsNull()) return 0;
64 TopoDS_Shape aShape = aShapeFunction->GetValue();
65 if (aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND) return 0;
67 Standard_Integer mindeg = IF.GetMinDeg();
68 Standard_Integer maxdeg = IF.GetMaxDeg();
69 Standard_Real tol3d = IF.GetTol2D();
70 Standard_Real tol2d = IF.GetTol3D();
71 Standard_Integer nbiter = IF.GetNbIter();
73 if (mindeg > maxdeg) {
74 Standard_RangeError::Raise("Minimal degree can not be more than maximal degree");
77 /* we verify the contents of the shape */
79 TopoDS_Shape Scurrent;
80 Standard_Real First, Last;
82 GeomFill_SectionGenerator Section;
84 Standard_Integer i = 0;
85 for (Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
86 Scurrent = Ex.Current() ;
87 if (Scurrent.IsNull() || Scurrent.ShapeType() != TopAbs_EDGE) return 0;
88 C = BRep_Tool::Curve(TopoDS::Edge(Scurrent), First, Last);
89 C = new Geom_TrimmedCurve(C, First, Last);
94 /* a 'tolerance' is used to compare 2 knots : see GeomFill_Generator.cdl */
95 Section.Perform(Precision::Confusion());
96 Handle(GeomFill_Line) Line = new GeomFill_Line(i);
98 GeomFill_AppSurf App (mindeg, maxdeg, tol3d, tol2d, nbiter); /* user parameters */
99 App.Perform(Line, Section);
101 if (!App.IsDone()) return 0;
102 Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots;
103 App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots);
104 Handle(Geom_BSplineSurface) GBS = new Geom_BSplineSurface
105 (App.SurfPoles(), App.SurfWeights(), App.SurfUKnots(), App.SurfVKnots(),
106 App.SurfUMults(), App.SurfVMults(), App.UDegree(), App.VDegree());
108 if (GBS.IsNull()) return 0;
109 aShape = BRepBuilderAPI_MakeFace(GBS);
111 /* We test the validity of resulting shape */
112 if (!BRepAlgo::IsValid((aShape))) {
113 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
117 aFunction->SetValue(aShape);
119 log.SetTouched(Label());
124 //=======================================================================
125 //function : GEOMImpl_FillingDriver_Type_
127 //=======================================================================
128 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FillingDriver_Type_()
131 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
132 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
133 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
134 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
135 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
136 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
139 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
140 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FillingDriver",
141 sizeof(GEOMImpl_FillingDriver),
143 (Standard_Address)_Ancestors,
144 (Standard_Address)NULL);
149 //=======================================================================
150 //function : DownCast
152 //=======================================================================
154 const Handle(GEOMImpl_FillingDriver) Handle(GEOMImpl_FillingDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
156 Handle(GEOMImpl_FillingDriver) _anOtherObject;
158 if (!AnObject.IsNull()) {
159 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FillingDriver))) {
160 _anOtherObject = Handle(GEOMImpl_FillingDriver)((Handle(GEOMImpl_FillingDriver)&)AnObject);
164 return _anOtherObject ;