3 #include "GEOMImpl_FillingDriver.hxx"
4 #include "GEOM_Function.hxx"
5 #include "GEOMImpl_IFilling.hxx"
6 #include "GEOMImpl_Types.hxx"
7 #include <BRepBuilderAPI_MakeFace.hxx>
8 #include <TopoDS_Shape.hxx>
9 #include <TopExp_Explorer.hxx>
12 #include <BRep_Tool.hxx>
13 #include <Geom_Surface.hxx>
14 #include <Geom_Curve.hxx>
15 #include <Geom_TrimmedCurve.hxx>
16 #include <Geom_BSplineSurface.hxx>
17 #include <GeomFill_SectionGenerator.hxx>
18 #include <GeomFill_Line.hxx>
19 #include <GeomFill_AppSurf.hxx>
20 #include <Precision.hxx>
21 #include <BRepAlgo.hxx>
23 //=======================================================================
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_FillingDriver::GetID()
29 static Standard_GUID aFillingDriver("FF1BBB62-5D14-4df2-980B-3A668264EA16");
30 return aFillingDriver;
34 //=======================================================================
35 //function : GEOMImpl_FillingDriver
37 //=======================================================================
39 GEOMImpl_FillingDriver::GEOMImpl_FillingDriver()
43 //=======================================================================
46 //=======================================================================
47 Standard_Integer GEOMImpl_FillingDriver::Execute(TFunction_Logbook& log) const
49 if (Label().IsNull()) return 0;
50 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51 if(aFunction.IsNull()) return 0;
53 if(aFunction->GetType() != BASIC_FILLING) return 0;
55 GEOMImpl_IFilling IF(aFunction);
56 Handle(GEOM_Function) aShapeFunction = IF.GetShape();
57 if(aShapeFunction.IsNull()) return 0;
58 TopoDS_Shape aShape = aShapeFunction->GetValue() ;
59 if( aShape.IsNull() || aShape.ShapeType() != TopAbs_COMPOUND ) return 0;
61 Standard_Integer mindeg = IF.GetMinDeg();
62 Standard_Integer maxdeg = IF.GetMaxDeg();
63 Standard_Real tol3d = IF.GetTol2D();
64 Standard_Real tol2d = IF.GetTol3D();
65 Standard_Integer nbiter = IF.GetNbIter();
67 /* we verify the contents of the shape */
69 TopoDS_Shape Scurrent ;
70 Standard_Real First, Last ;
71 Handle(Geom_Curve) C ;
72 GeomFill_SectionGenerator Section ;
74 Standard_Integer i = 0 ;
75 for(Ex.Init(aShape, TopAbs_EDGE); Ex.More(); Ex.Next()) {
76 Scurrent = Ex.Current() ;
77 if( Scurrent.IsNull() || Scurrent.ShapeType() != TopAbs_EDGE) return 0;
78 C = BRep_Tool::Curve(TopoDS::Edge(Scurrent), First, Last);
79 C = new Geom_TrimmedCurve(C, First, Last);
84 /* a 'tolerance' is used to compare 2 knots : see GeomFill_Generator.cdl */
85 Section.Perform( Precision::Confusion() ) ;
86 Handle(GeomFill_Line) Line = new GeomFill_Line(i) ;
88 GeomFill_AppSurf App(mindeg, maxdeg, tol3d, tol2d, nbiter) ; /* user parameters */
89 App.Perform(Line, Section) ;
91 if (!App.IsDone()) return 0;
92 Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots;
93 App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots);
94 Handle(Geom_BSplineSurface) GBS = new Geom_BSplineSurface(App.SurfPoles(), App.SurfWeights(), App.SurfUKnots(), App.SurfVKnots(), App.SurfUMults(), App.SurfVMults(), App.UDegree(), App.VDegree());
96 if( GBS.IsNull() ) return 0;
97 aShape = BRepBuilderAPI_MakeFace(GBS) ;
99 /* We test the validity of resulting shape */
100 if( !BRepAlgo::IsValid((aShape)) ) return 0;
102 aFunction->SetValue(aShape);
104 log.SetTouched(Label());
109 //=======================================================================
110 //function : GEOMImpl_FillingDriver_Type_
112 //=======================================================================
113 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FillingDriver_Type_()
116 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
117 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
118 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
119 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
120 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
121 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
124 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
125 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FillingDriver",
126 sizeof(GEOMImpl_FillingDriver),
128 (Standard_Address)_Ancestors,
129 (Standard_Address)NULL);
134 //=======================================================================
135 //function : DownCast
137 //=======================================================================
139 const Handle(GEOMImpl_FillingDriver) Handle(GEOMImpl_FillingDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
141 Handle(GEOMImpl_FillingDriver) _anOtherObject;
143 if (!AnObject.IsNull()) {
144 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FillingDriver))) {
145 _anOtherObject = Handle(GEOMImpl_FillingDriver)((Handle(GEOMImpl_FillingDriver)&)AnObject);
149 return _anOtherObject ;