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