Salome HOME
PAL8395: Fix pb. with bug2extraEdges.py
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ScaleDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_ScaleDriver.hxx"
4 #include "GEOMImpl_IScale.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRepBuilderAPI_Transform.hxx>
9 #include <BRep_Tool.hxx>
10 #include <TopoDS.hxx>
11 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Vertex.hxx>
13 #include <TopAbs.hxx>
14 #include <TopExp.hxx>
15
16 #include <Precision.hxx>
17 #include <gp_Pnt.hxx>
18
19 //=======================================================================
20 //function : GetID
21 //purpose  :
22 //======================================================================= 
23 const Standard_GUID& GEOMImpl_ScaleDriver::GetID()
24 {
25   static Standard_GUID aScaleDriver("FF1BBB52-5D14-4df2-980B-3A668264EA16");
26   return aScaleDriver; 
27 }
28
29
30 //=======================================================================
31 //function : GEOMImpl_ScaleDriver
32 //purpose  : 
33 //=======================================================================
34 GEOMImpl_ScaleDriver::GEOMImpl_ScaleDriver() 
35 {
36 }
37
38 //=======================================================================
39 //function : Execute
40 //purpose  :
41 //======================================================================= 
42 Standard_Integer GEOMImpl_ScaleDriver::Execute(TFunction_Logbook& log) const
43 {
44   if (Label().IsNull()) return 0;    
45   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
46
47   GEOMImpl_IScale aCI (aFunction);
48   Standard_Integer aType = aFunction->GetType();
49
50   TopoDS_Shape aShape;
51
52   if (aType == SCALE_SHAPE || aType == SCALE_SHAPE_COPY) {
53     Handle(GEOM_Function) aRefShape = aCI.GetShape();
54     Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
55     TopoDS_Shape aShapeBase = aRefShape->GetValue();
56     TopoDS_Shape aShapePnt  = aRefPoint->GetValue();
57     if (aShapeBase.IsNull() || aShapePnt.IsNull()) return 0;
58     if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0;
59
60     gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
61     gp_Trsf aTrsf;
62     aTrsf.SetScale(aP, aCI.GetFactor());
63     BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
64     aShape = aBRepTrsf.Shape();
65   } else {
66   }
67
68   if (aShape.IsNull()) return 0;
69
70   aFunction->SetValue(aShape);
71
72   log.SetTouched(Label()); 
73
74   return 1;    
75 }
76
77
78 //=======================================================================
79 //function :  GEOMImpl_ScaleDriver_Type_
80 //purpose  :
81 //======================================================================= 
82 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ScaleDriver_Type_()
83 {
84
85   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
86   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
87   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
88   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
89   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
90   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
91  
92
93   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
94   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ScaleDriver",
95                                                          sizeof(GEOMImpl_ScaleDriver),
96                                                          1,
97                                                          (Standard_Address)_Ancestors,
98                                                          (Standard_Address)NULL);
99
100   return _aType;
101 }
102
103 //=======================================================================
104 //function : DownCast
105 //purpose  :
106 //======================================================================= 
107 const Handle(GEOMImpl_ScaleDriver) Handle(GEOMImpl_ScaleDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
108 {
109   Handle(GEOMImpl_ScaleDriver) _anOtherObject;
110
111   if (!AnObject.IsNull()) {
112      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ScaleDriver))) {
113        _anOtherObject = Handle(GEOMImpl_ScaleDriver)((Handle(GEOMImpl_ScaleDriver)&)AnObject);
114      }
115   }
116
117   return _anOtherObject ;
118 }