]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_FillingDriver.cxx
Salome HOME
fe46ecd2684d39e8e7d3fa2690aa9afc43543b07
[modules/geom.git] / src / GEOMImpl / GEOMImpl_FillingDriver.cxx
1
2 using namespace std;
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>
10 #include <TopAbs.hxx>
11 #include <TopoDS.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>
22
23 //=======================================================================
24 //function : GetID
25 //purpose  :
26 //======================================================================= 
27 const Standard_GUID& GEOMImpl_FillingDriver::GetID()
28 {
29   static Standard_GUID aFillingDriver("FF1BBB62-5D14-4df2-980B-3A668264EA16");
30   return aFillingDriver; 
31 }
32
33
34 //=======================================================================
35 //function : GEOMImpl_FillingDriver
36 //purpose  : 
37 //=======================================================================
38
39 GEOMImpl_FillingDriver::GEOMImpl_FillingDriver() 
40 {
41 }
42
43 //=======================================================================
44 //function : Execute
45 //purpose  :
46 //======================================================================= 
47 Standard_Integer GEOMImpl_FillingDriver::Execute(TFunction_Logbook& log) const
48 {
49   if (Label().IsNull()) return 0;
50   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); 
51   if(aFunction.IsNull()) return 0;
52
53   if(aFunction->GetType() != BASIC_FILLING) return 0;
54
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;
60
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();
66   
67   /* we verify the contents of the shape */
68   TopExp_Explorer Ex ;
69   TopoDS_Shape Scurrent ;       
70   Standard_Real First, Last ;
71   Handle(Geom_Curve) C ;
72   GeomFill_SectionGenerator Section ;
73   
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);
80     Section.AddCurve(C) ;
81     i++ ;
82   }
83     
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) ;
87   
88   GeomFill_AppSurf App(mindeg, maxdeg, tol3d, tol2d, nbiter) ; /* user parameters */
89   App.Perform(Line, Section) ;
90   
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());
95     
96   if( GBS.IsNull() ) return 0;
97   aShape  = BRepBuilderAPI_MakeFace(GBS) ;    
98   
99   /* We test the validity of resulting shape */
100   if( !BRepAlgo::IsValid((aShape)) )  return 0;
101   
102   aFunction->SetValue(aShape);   
103
104   log.SetTouched(Label());
105   return 1;    
106 }
107
108
109 //=======================================================================
110 //function :  GEOMImpl_FillingDriver_Type_
111 //purpose  :
112 //======================================================================= 
113 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FillingDriver_Type_()
114 {
115
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);
122  
123
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),
127                                                          1,
128                                                          (Standard_Address)_Ancestors,
129                                                          (Standard_Address)NULL);
130
131   return _aType;
132 }
133
134 //=======================================================================
135 //function : DownCast
136 //purpose  :
137 //======================================================================= 
138
139 const Handle(GEOMImpl_FillingDriver) Handle(GEOMImpl_FillingDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
140 {
141   Handle(GEOMImpl_FillingDriver) _anOtherObject;
142
143   if (!AnObject.IsNull()) {
144      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FillingDriver))) {
145        _anOtherObject = Handle(GEOMImpl_FillingDriver)((Handle(GEOMImpl_FillingDriver)&)AnObject);
146      }
147   }
148
149   return _anOtherObject ;
150 }
151
152